assimp vertex collection now checks for the presence of normals/texcoords. started implementing skeletal animation scene conversion
This commit is contained in:
parent
d2b67e6e7e
commit
a0513ab83c
|
@ -22,6 +22,9 @@ void CollectVerticesInMesh(
|
||||||
AssimpVertices &texCoordsBucket,
|
AssimpVertices &texCoordsBucket,
|
||||||
AssimpVertexIndices &indexMapping)
|
AssimpVertexIndices &indexMapping)
|
||||||
{
|
{
|
||||||
|
bool hasTexCoords = mesh->HasTextureCoords(0);
|
||||||
|
bool hasNormals = mesh->HasNormals();
|
||||||
|
|
||||||
indexMapping.resize(mesh->mNumVertices);
|
indexMapping.resize(mesh->mNumVertices);
|
||||||
|
|
||||||
for (unsigned int i = 0; i < mesh->mNumVertices; ++i)
|
for (unsigned int i = 0; i < mesh->mNumVertices; ++i)
|
||||||
|
@ -41,11 +44,17 @@ void CollectVerticesInMesh(
|
||||||
|
|
||||||
// also copy the normal and tex coord into the appropriate buckets
|
// also copy the normal and tex coord into the appropriate buckets
|
||||||
// TODO: check if mesh has normals and/or tex coords first!
|
// TODO: check if mesh has normals and/or tex coords first!
|
||||||
|
if (hasNormals)
|
||||||
|
{
|
||||||
aiVector3D normal = mesh->mNormals[i];
|
aiVector3D normal = mesh->mNormals[i];
|
||||||
normalsBucket.push_back(normal);
|
normalsBucket.push_back(normal);
|
||||||
|
}
|
||||||
|
if (hasTexCoords)
|
||||||
|
{
|
||||||
aiVector3D texCoord = mesh->mTextureCoords[0][i];
|
aiVector3D texCoord = mesh->mTextureCoords[0][i];
|
||||||
texCoordsBucket.push_back(texCoord);
|
texCoordsBucket.push_back(texCoord);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// stating the obvious so when i come back here and read this, i know instantly
|
// stating the obvious so when i come back here and read this, i know instantly
|
||||||
// what the fuck is going on (sad, I know):
|
// what the fuck is going on (sad, I know):
|
||||||
|
|
|
@ -1,5 +1,97 @@
|
||||||
#include "convert.h"
|
#include "convert.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <exception>
|
||||||
|
|
||||||
|
#include "mesh.h"
|
||||||
|
#include "../assimputils/utils.h"
|
||||||
|
|
||||||
void ConvertSkeletalAnimated(const std::string &outfile, const aiScene *scene)
|
void ConvertSkeletalAnimated(const std::string &outfile, const aiScene *scene)
|
||||||
{
|
{
|
||||||
|
FILE *fp = fopen(outfile.c_str(), "wb");
|
||||||
|
if (fp == NULL)
|
||||||
|
throw std::exception("Error creating output file.");
|
||||||
|
|
||||||
|
WriteMeshHeader(fp);
|
||||||
|
|
||||||
|
// basic mesh info
|
||||||
|
AssimpVertices vertices;
|
||||||
|
AssimpVertices normals;
|
||||||
|
AssimpVertices texCoords;
|
||||||
|
AssimpVerticesMap vertexIndicesMap;
|
||||||
|
CollectAllMeshVertices(scene, vertices, normals, texCoords, vertexIndicesMap);
|
||||||
|
WriteVertices(vertices, fp);
|
||||||
|
WriteNormals(normals, fp);
|
||||||
|
WriteTexCoords(texCoords, fp);
|
||||||
|
|
||||||
|
// materials
|
||||||
|
std::vector<MeshMaterial> materials;
|
||||||
|
for (unsigned int i = 0; i < scene->mNumMaterials; ++i)
|
||||||
|
{
|
||||||
|
MeshMaterial material = MeshMaterial(scene->mMaterials[i]);
|
||||||
|
materials.push_back(material);
|
||||||
|
}
|
||||||
|
WriteMaterials(materials, fp);
|
||||||
|
|
||||||
|
// triangles
|
||||||
|
std::vector<MeshTriangle> triangles;
|
||||||
|
for (unsigned int i = 0; i < scene->mNumMeshes; ++i)
|
||||||
|
{
|
||||||
|
aiMesh *mesh = scene->mMeshes[i];
|
||||||
|
for (unsigned int j = 0; j < mesh->mNumFaces; ++j)
|
||||||
|
{
|
||||||
|
aiFace *face = &mesh->mFaces[j];
|
||||||
|
|
||||||
|
MeshTriangle triangle;
|
||||||
|
triangle.vertices[0] = vertexIndicesMap[i][face->mIndices[0]];
|
||||||
|
triangle.vertices[1] = vertexIndicesMap[i][face->mIndices[1]];
|
||||||
|
triangle.vertices[2] = vertexIndicesMap[i][face->mIndices[2]];
|
||||||
|
triangle.subMesh = i;
|
||||||
|
|
||||||
|
triangles.push_back(triangle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WriteTriangles(triangles, fp);
|
||||||
|
|
||||||
|
// sub meshes
|
||||||
|
std::vector<SubMesh> subMeshes;
|
||||||
|
for (unsigned int i = 0; i < scene->mNumMeshes; ++i)
|
||||||
|
{
|
||||||
|
aiMesh *mesh = scene->mMeshes[i];
|
||||||
|
SubMesh subMesh;
|
||||||
|
|
||||||
|
subMesh.name = std::string(mesh->mName.data, mesh->mName.length);
|
||||||
|
subMesh.material = mesh->mMaterialIndex;
|
||||||
|
subMesh.numTriangles = mesh->mNumFaces;
|
||||||
|
|
||||||
|
subMeshes.push_back(subMesh);
|
||||||
|
}
|
||||||
|
WriteSubMeshes(subMeshes, fp);
|
||||||
|
|
||||||
|
// joints
|
||||||
|
// foreach joint:
|
||||||
|
// - name
|
||||||
|
// - parentindex (or name?)
|
||||||
|
// - position (vec3d)
|
||||||
|
// - rotation (vec3d or quat?)
|
||||||
|
|
||||||
|
// joints to vertices mapping
|
||||||
|
// foreach vertex:
|
||||||
|
// - jointindex
|
||||||
|
// - weight
|
||||||
|
|
||||||
|
// joint keyframes
|
||||||
|
// foreach keyframe:
|
||||||
|
// foreach joint:
|
||||||
|
// - position (vec3d)
|
||||||
|
// - rotation (vec3d or quat?)
|
||||||
|
|
||||||
|
// animation sequences
|
||||||
|
// foreach sequence:
|
||||||
|
// - name
|
||||||
|
// - start frame index
|
||||||
|
// - end frame index
|
||||||
|
|
||||||
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue