diff --git a/.gitignore b/.gitignore index 3f571c0..27f54db 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,9 @@ - -*.sdf -*.opensdf -*.user -*.suo -/*.dll -Debug/ -Release/ -ipch/ + +*.sdf +*.opensdf +*.user +*.suo +/*.dll +Debug/ +Release/ +ipch/ diff --git a/AssimpToMesh.sln b/AssimpToMesh.sln index 0de759f..3a95254 100644 --- a/AssimpToMesh.sln +++ b/AssimpToMesh.sln @@ -1,20 +1,20 @@ - -Microsoft Visual Studio Solution File, Format Version 11.00 -# Visual Studio 2010 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AssimpToMesh", "AssimpToMesh\AssimpToMesh.vcxproj", "{1706D477-F8C1-4CD9-A9F6-06A9D903FD3C}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {1706D477-F8C1-4CD9-A9F6-06A9D903FD3C}.Debug|Win32.ActiveCfg = Debug|Win32 - {1706D477-F8C1-4CD9-A9F6-06A9D903FD3C}.Debug|Win32.Build.0 = Debug|Win32 - {1706D477-F8C1-4CD9-A9F6-06A9D903FD3C}.Release|Win32.ActiveCfg = Release|Win32 - {1706D477-F8C1-4CD9-A9F6-06A9D903FD3C}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AssimpToMesh", "AssimpToMesh\AssimpToMesh.vcxproj", "{1706D477-F8C1-4CD9-A9F6-06A9D903FD3C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1706D477-F8C1-4CD9-A9F6-06A9D903FD3C}.Debug|Win32.ActiveCfg = Debug|Win32 + {1706D477-F8C1-4CD9-A9F6-06A9D903FD3C}.Debug|Win32.Build.0 = Debug|Win32 + {1706D477-F8C1-4CD9-A9F6-06A9D903FD3C}.Release|Win32.ActiveCfg = Release|Win32 + {1706D477-F8C1-4CD9-A9F6-06A9D903FD3C}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/AssimpToMesh/AssimpToMesh.vcxproj b/AssimpToMesh/AssimpToMesh.vcxproj index a0566f3..9604751 100644 --- a/AssimpToMesh/AssimpToMesh.vcxproj +++ b/AssimpToMesh/AssimpToMesh.vcxproj @@ -1,107 +1,107 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - - {1706D477-F8C1-4CD9-A9F6-06A9D903FD3C} - Win32Proj - AssimpToMesh - - - - Application - true - Unicode - - - Application - false - true - Unicode - - - - - - - - - - - - - true - E:\assimp--2.0.863-sdk\include;$(IncludePath) - E:\assimp--2.0.863-sdk\lib\assimp_debug-dll_win32;$(LibraryPath) - - - false - E:\assimp--2.0.863-sdk\include;$(IncludePath) - E:\assimp--2.0.863-sdk\lib\assimp_release-dll_win32;$(LibraryPath) - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;%(PreprocessorDefinitions) - - - Console - true - assimp.lib;%(AdditionalDependencies) - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;%(PreprocessorDefinitions) - - - Console - true - true - true - assimp.lib;%(AdditionalDependencies) - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + Debug + Win32 + + + Release + Win32 + + + + {1706D477-F8C1-4CD9-A9F6-06A9D903FD3C} + Win32Proj + AssimpToMesh + + + + Application + true + Unicode + + + Application + false + true + Unicode + + + + + + + + + + + + + true + E:\assimp--2.0.863-sdk\include;$(IncludePath) + E:\assimp--2.0.863-sdk\lib\assimp_debug-dll_win32;$(LibraryPath) + + + false + E:\assimp--2.0.863-sdk\include;$(IncludePath) + E:\assimp--2.0.863-sdk\lib\assimp_release-dll_win32;$(LibraryPath) + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;%(PreprocessorDefinitions) + + + Console + true + assimp.lib;%(AdditionalDependencies) + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;%(PreprocessorDefinitions) + + + Console + true + true + true + assimp.lib;%(AdditionalDependencies) + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/AssimpToMesh/AssimpToMesh.vcxproj.filters b/AssimpToMesh/AssimpToMesh.vcxproj.filters index ace3169..b1fe21f 100644 --- a/AssimpToMesh/AssimpToMesh.vcxproj.filters +++ b/AssimpToMesh/AssimpToMesh.vcxproj.filters @@ -1,75 +1,75 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + \ No newline at end of file diff --git a/AssimpToMesh/src/assimputils/assimpgeometry.cpp b/AssimpToMesh/src/assimputils/assimpgeometry.cpp index e1c43e2..dffd2e8 100644 --- a/AssimpToMesh/src/assimputils/assimpgeometry.cpp +++ b/AssimpToMesh/src/assimputils/assimpgeometry.cpp @@ -1,82 +1,82 @@ -#include "utils.h" - -// determine if a vertex is already contained in the bucket, if so matchingIndex will contain the index of the matching vertex -bool FindVertex(const aiVector3D &vertex, const AssimpVertices &bucket, unsigned int &matchingIndex) -{ - for (unsigned int i = 0; i < bucket.size(); ++i) - { - if (vertex == bucket[i]) - { - matchingIndex = i; - return true; - } - } - - return false; -} - -void CollectVerticesInMesh( - const aiMesh *mesh, - AssimpVertices &verticesBucket, - AssimpVertices &normalsBucket, - AssimpVertices &texCoordsBucket, - AssimpVertexIndices &indexMapping) -{ - bool hasTexCoords = mesh->HasTextureCoords(0); - bool hasNormals = mesh->HasNormals(); - - indexMapping.resize(mesh->mNumVertices); - - for (unsigned int i = 0; i < mesh->mNumVertices; ++i) - { - unsigned int matchingIndex = 0; - aiVector3D vertex = mesh->mVertices[i]; - - // TODO: this seems to not work quite so well... might have something to do with the - // fact that ASSIMP is already taking care of duplicate vertices and indexing as - // appropriate? the problem seems to be only with tex coords though.... - //if (!FindVertex(vertex, verticesBucket, matchingIndex)) - if (true) - { - // vertex isn't in the bucket already, add it, and then record mapping between the mesh vertex index and the bucket vertex index - verticesBucket.push_back(vertex); - matchingIndex = verticesBucket.size() - 1; - - // also copy the normal and tex coord into the appropriate buckets - // TODO: check if mesh has normals and/or tex coords first! - if (hasNormals) - { - aiVector3D normal = mesh->mNormals[i]; - normalsBucket.push_back(normal); - } - if (hasTexCoords) - { - aiVector3D texCoord = mesh->mTextureCoords[0][i]; - texCoordsBucket.push_back(texCoord); - } - } - - // stating the obvious so when i come back here and read this, i know instantly - // what the fuck is going on (sad, I know): - // i = index into mesh's separate vertices list - // matchingIndex = index into bucket's vertices list - indexMapping[i] = matchingIndex; - } -} - -void CollectAllMeshVertices( - const aiScene *scene, - AssimpVertices &verticesBucket, - AssimpVertices &normalsBucket, - AssimpVertices &texCoordsBucket, - AssimpVerticesMap &indexMapping) -{ - for (unsigned int i = 0; i < scene->mNumMeshes; ++i) - { - aiMesh *mesh = scene->mMeshes[i]; - AssimpVertexIndices indexes; - CollectVerticesInMesh(mesh, verticesBucket, normalsBucket, texCoordsBucket, indexes); - - indexMapping[i] = indexes; - } -} +#include "utils.h" + +// determine if a vertex is already contained in the bucket, if so matchingIndex will contain the index of the matching vertex +bool FindVertex(const aiVector3D &vertex, const AssimpVertices &bucket, unsigned int &matchingIndex) +{ + for (unsigned int i = 0; i < bucket.size(); ++i) + { + if (vertex == bucket[i]) + { + matchingIndex = i; + return true; + } + } + + return false; +} + +void CollectVerticesInMesh( + const aiMesh *mesh, + AssimpVertices &verticesBucket, + AssimpVertices &normalsBucket, + AssimpVertices &texCoordsBucket, + AssimpVertexIndices &indexMapping) +{ + bool hasTexCoords = mesh->HasTextureCoords(0); + bool hasNormals = mesh->HasNormals(); + + indexMapping.resize(mesh->mNumVertices); + + for (unsigned int i = 0; i < mesh->mNumVertices; ++i) + { + unsigned int matchingIndex = 0; + aiVector3D vertex = mesh->mVertices[i]; + + // TODO: this seems to not work quite so well... might have something to do with the + // fact that ASSIMP is already taking care of duplicate vertices and indexing as + // appropriate? the problem seems to be only with tex coords though.... + //if (!FindVertex(vertex, verticesBucket, matchingIndex)) + if (true) + { + // vertex isn't in the bucket already, add it, and then record mapping between the mesh vertex index and the bucket vertex index + verticesBucket.push_back(vertex); + matchingIndex = verticesBucket.size() - 1; + + // also copy the normal and tex coord into the appropriate buckets + // TODO: check if mesh has normals and/or tex coords first! + if (hasNormals) + { + aiVector3D normal = mesh->mNormals[i]; + normalsBucket.push_back(normal); + } + if (hasTexCoords) + { + aiVector3D texCoord = mesh->mTextureCoords[0][i]; + texCoordsBucket.push_back(texCoord); + } + } + + // stating the obvious so when i come back here and read this, i know instantly + // what the fuck is going on (sad, I know): + // i = index into mesh's separate vertices list + // matchingIndex = index into bucket's vertices list + indexMapping[i] = matchingIndex; + } +} + +void CollectAllMeshVertices( + const aiScene *scene, + AssimpVertices &verticesBucket, + AssimpVertices &normalsBucket, + AssimpVertices &texCoordsBucket, + AssimpVerticesMap &indexMapping) +{ + for (unsigned int i = 0; i < scene->mNumMeshes; ++i) + { + aiMesh *mesh = scene->mMeshes[i]; + AssimpVertexIndices indexes; + CollectVerticesInMesh(mesh, verticesBucket, normalsBucket, texCoordsBucket, indexes); + + indexMapping[i] = indexes; + } +} diff --git a/AssimpToMesh/src/assimputils/assimpsceneinfo.cpp b/AssimpToMesh/src/assimputils/assimpsceneinfo.cpp index 211191b..35f7c8e 100644 --- a/AssimpToMesh/src/assimputils/assimpsceneinfo.cpp +++ b/AssimpToMesh/src/assimputils/assimpsceneinfo.cpp @@ -1,25 +1,25 @@ -#include "utils.h" - -bool IsSceneAnimated(const aiScene *scene) -{ - return scene->HasAnimations(); -} - -bool IsSceneSkeletal(const aiScene *scene) -{ - for (unsigned int i = 0; i < scene->mNumMeshes; ++i) - { - if (scene->mMeshes[i]->HasBones()) - return true; - } - - return false; -} - -bool IsSceneStatic(const aiScene *scene) -{ - if (IsSceneAnimated(scene) || IsSceneSkeletal(scene)) - return false; - else - return true; -} +#include "utils.h" + +bool IsSceneAnimated(const aiScene *scene) +{ + return scene->HasAnimations(); +} + +bool IsSceneSkeletal(const aiScene *scene) +{ + for (unsigned int i = 0; i < scene->mNumMeshes; ++i) + { + if (scene->mMeshes[i]->HasBones()) + return true; + } + + return false; +} + +bool IsSceneStatic(const aiScene *scene) +{ + if (IsSceneAnimated(scene) || IsSceneSkeletal(scene)) + return false; + else + return true; +} diff --git a/AssimpToMesh/src/assimputils/types.h b/AssimpToMesh/src/assimputils/types.h index bc7eb9d..f26a8fa 100644 --- a/AssimpToMesh/src/assimputils/types.h +++ b/AssimpToMesh/src/assimputils/types.h @@ -1,13 +1,13 @@ -#ifndef __ASSIMPUTILS_TYPES_H_INCLUDED__ -#define __ASSIMPUTILS_TYPES_H_INCLUDED__ - -#include -#include -#include - -typedef std::vector AssimpVertices; - -typedef std::vector AssimpVertexIndices; -typedef std::map AssimpVerticesMap; - -#endif +#ifndef __ASSIMPUTILS_TYPES_H_INCLUDED__ +#define __ASSIMPUTILS_TYPES_H_INCLUDED__ + +#include +#include +#include + +typedef std::vector AssimpVertices; + +typedef std::vector AssimpVertexIndices; +typedef std::map AssimpVerticesMap; + +#endif diff --git a/AssimpToMesh/src/assimputils/utils.h b/AssimpToMesh/src/assimputils/utils.h index 307f05e..c85fd94 100644 --- a/AssimpToMesh/src/assimputils/utils.h +++ b/AssimpToMesh/src/assimputils/utils.h @@ -1,38 +1,38 @@ -#ifndef __ASSIMPUTILS_UTILS_H_INCLUDED__ -#define __ASSIMPUTILS_UTILS_H_INCLUDED__ - -#include -#include - -#include -#include - -#include "types.h" - -bool IsSceneAnimated(const aiScene *scene); -bool IsSceneSkeletal(const aiScene *scene); -bool IsSceneStatic(const aiScene *scene); - -/** - * This will go through each mesh in the scene, and store all the vertices it - * finds into one common bucket, building up a mapping as it goes so that, - * we can easily determine what mesh index and vertex index as stored by ASSIMP - * corresponds to what vertex in the common bucket. That is, after this, given: - * - * aiScene *scene = ... - * aiMesh *mesh = scene->mMeshes[meshIndex]; - * unsigned int bucketIndex = mesh->mVertices[3]; - * ... and/or ... - * unsigned int bucketIndex = mesh->mFaces[10]->mIndices[0]; - * aiVector3D vertex = bucket[bucketIndex]; - * - * where "bucketIndex" is the index into one of the bucket lists - */ -void CollectAllMeshVertices( - const aiScene *scene, - AssimpVertices &verticesBucket, - AssimpVertices &normalsBucket, - AssimpVertices &texCoordsBucket, - AssimpVerticesMap &indexMapping); - -#endif +#ifndef __ASSIMPUTILS_UTILS_H_INCLUDED__ +#define __ASSIMPUTILS_UTILS_H_INCLUDED__ + +#include +#include + +#include +#include + +#include "types.h" + +bool IsSceneAnimated(const aiScene *scene); +bool IsSceneSkeletal(const aiScene *scene); +bool IsSceneStatic(const aiScene *scene); + +/** + * This will go through each mesh in the scene, and store all the vertices it + * finds into one common bucket, building up a mapping as it goes so that, + * we can easily determine what mesh index and vertex index as stored by ASSIMP + * corresponds to what vertex in the common bucket. That is, after this, given: + * + * aiScene *scene = ... + * aiMesh *mesh = scene->mMeshes[meshIndex]; + * unsigned int bucketIndex = mesh->mVertices[3]; + * ... and/or ... + * unsigned int bucketIndex = mesh->mFaces[10]->mIndices[0]; + * aiVector3D vertex = bucket[bucketIndex]; + * + * where "bucketIndex" is the index into one of the bucket lists + */ +void CollectAllMeshVertices( + const aiScene *scene, + AssimpVertices &verticesBucket, + AssimpVertices &normalsBucket, + AssimpVertices &texCoordsBucket, + AssimpVerticesMap &indexMapping); + +#endif diff --git a/AssimpToMesh/src/convert/convert.h b/AssimpToMesh/src/convert/convert.h index 08ecadb..6fa8250 100644 --- a/AssimpToMesh/src/convert/convert.h +++ b/AssimpToMesh/src/convert/convert.h @@ -1,10 +1,10 @@ -#ifndef __CONVERT_CONVERT_H_INCLUDED__ -#define __CONVERT_CONVERT_H_INCLUDED__ - -#include -#include - -void ConvertStatic(const std::string &outfile, const aiScene *scene); -void ConvertSkeletalAnimated(const std::string &outfile, const aiScene *scene); - -#endif +#ifndef __CONVERT_CONVERT_H_INCLUDED__ +#define __CONVERT_CONVERT_H_INCLUDED__ + +#include +#include + +void ConvertStatic(const std::string &outfile, const aiScene *scene); +void ConvertSkeletalAnimated(const std::string &outfile, const aiScene *scene); + +#endif diff --git a/AssimpToMesh/src/convert/mesh.h b/AssimpToMesh/src/convert/mesh.h index a536fe5..f959287 100644 --- a/AssimpToMesh/src/convert/mesh.h +++ b/AssimpToMesh/src/convert/mesh.h @@ -1,24 +1,24 @@ -#ifndef __CONVERT_MESH_H_INCLUDED__ -#define __CONVERT_MESH_H_INCLUDED__ - -#include -#include -#include -#include "../assimputils/types.h" -#include "meshmaterial.h" -#include "meshtriangle.h" -#include "submesh.h" -#include "meshjoint.h" - -void WriteMeshHeader(FILE *fp); -void WriteVertices(const AssimpVertices &vertices, FILE *fp); -void WriteNormals(const AssimpVertices &normals, FILE *fp); -void WriteTexCoords(const AssimpVertices &texCoords, FILE *fp); -void WriteMaterials(const std::vector &materials, FILE *fp); -void WriteTriangles(const std::vector &triangles, FILE *fp); -void WriteSubMeshes(const std::vector &subMeshes, FILE *fp); -void WriteJoints(const std::vector &joints, FILE *fp); -void WriteJointToVertexMap(const std::vector &vertexToJointMap, FILE *fp); -void WriteJointKeyFrames(const std::vector &jointKeyFrames, FILE *fp); - -#endif +#ifndef __CONVERT_MESH_H_INCLUDED__ +#define __CONVERT_MESH_H_INCLUDED__ + +#include +#include +#include +#include "../assimputils/types.h" +#include "meshmaterial.h" +#include "meshtriangle.h" +#include "submesh.h" +#include "meshjoint.h" + +void WriteMeshHeader(FILE *fp); +void WriteVertices(const AssimpVertices &vertices, FILE *fp); +void WriteNormals(const AssimpVertices &normals, FILE *fp); +void WriteTexCoords(const AssimpVertices &texCoords, FILE *fp); +void WriteMaterials(const std::vector &materials, FILE *fp); +void WriteTriangles(const std::vector &triangles, FILE *fp); +void WriteSubMeshes(const std::vector &subMeshes, FILE *fp); +void WriteJoints(const std::vector &joints, FILE *fp); +void WriteJointToVertexMap(const std::vector &vertexToJointMap, FILE *fp); +void WriteJointKeyFrames(const std::vector &jointKeyFrames, FILE *fp); + +#endif diff --git a/AssimpToMesh/src/convert/meshjoint.h b/AssimpToMesh/src/convert/meshjoint.h index a77101a..16820c3 100644 --- a/AssimpToMesh/src/convert/meshjoint.h +++ b/AssimpToMesh/src/convert/meshjoint.h @@ -1,30 +1,30 @@ -#ifndef __CONVERT_MESHJOINT_H_INCLUDED__ -#define __CONVERT_MESHJOINT_H_INCLUDED__ - -#include -#include -#include -#include -#include - -struct MeshJoint -{ - std::string name; - std::string parentName; - aiVector3D localPosition; - aiQuaternion localRotation; - aiVector3D offsetPosition; - aiQuaternion offsetRotation; -}; - -struct MeshJointKeyFrame -{ - aiVector3D position; - aiQuaternion rotation; -}; - -typedef std::vector JointKeyFrames; - -int32_t GetIndexOf(const std::vector &joints, const std::string &name); - -#endif +#ifndef __CONVERT_MESHJOINT_H_INCLUDED__ +#define __CONVERT_MESHJOINT_H_INCLUDED__ + +#include +#include +#include +#include +#include + +struct MeshJoint +{ + std::string name; + std::string parentName; + aiVector3D localPosition; + aiQuaternion localRotation; + aiVector3D offsetPosition; + aiQuaternion offsetRotation; +}; + +struct MeshJointKeyFrame +{ + aiVector3D position; + aiQuaternion rotation; +}; + +typedef std::vector JointKeyFrames; + +int32_t GetIndexOf(const std::vector &joints, const std::string &name); + +#endif diff --git a/AssimpToMesh/src/convert/meshmaterial.h b/AssimpToMesh/src/convert/meshmaterial.h index 9ce4848..7846aaa 100644 --- a/AssimpToMesh/src/convert/meshmaterial.h +++ b/AssimpToMesh/src/convert/meshmaterial.h @@ -1,71 +1,71 @@ -#ifndef __CONVERT_MESHMATERIAL_H_INCLUDED__ -#define __CONVERT_MESHMATERIAL_H_INCLUDED__ - -#include -#include - -struct MeshMaterial -{ - MeshMaterial() - { - } - - MeshMaterial(const aiMaterial *source) - { - aiString name; - aiString textureFile; - aiColor3D ambient; - aiColor3D diffuse; - aiColor3D specular; - aiColor3D emissive; - float shininess; - float opacity; - - source->Get(AI_MATKEY_NAME, name); - source->Get(AI_MATKEY_COLOR_AMBIENT, ambient); - source->Get(AI_MATKEY_COLOR_DIFFUSE, diffuse); - source->Get(AI_MATKEY_COLOR_SPECULAR, specular); - source->Get(AI_MATKEY_COLOR_EMISSIVE, emissive); - source->Get(AI_MATKEY_SHININESS, shininess); - source->Get(AI_MATKEY_OPACITY, opacity); - - // TODO: need something better then this, but based on my (limited) testing - // diffuse texture seems to be the most common - source->Get(AI_MATKEY_TEXTURE_DIFFUSE(0), textureFile); - - this->name = std::string(name.data, name.length); - - this->texture = std::string(textureFile.data, textureFile.length); - - this->ambient[0] = ambient.r; - this->ambient[1] = ambient.g; - this->ambient[2] = ambient.b; - - this->diffuse[0] = diffuse.r; - this->diffuse[1] = diffuse.g; - this->diffuse[2] = diffuse.b; - - this->specular[0] = specular.r; - this->specular[1] = specular.g; - this->specular[2] = specular.b; - - this->emissive[0] = emissive.r; - this->emissive[1] = emissive.g; - this->emissive[2] = emissive.b; - - this->shininess = shininess; - - this->opacity = opacity; - } - - std::string name; - std::string texture; - float ambient[3]; - float diffuse[3]; - float specular[3]; - float emissive[3]; - float shininess; - float opacity; -}; - -#endif +#ifndef __CONVERT_MESHMATERIAL_H_INCLUDED__ +#define __CONVERT_MESHMATERIAL_H_INCLUDED__ + +#include +#include + +struct MeshMaterial +{ + MeshMaterial() + { + } + + MeshMaterial(const aiMaterial *source) + { + aiString name; + aiString textureFile; + aiColor3D ambient; + aiColor3D diffuse; + aiColor3D specular; + aiColor3D emissive; + float shininess; + float opacity; + + source->Get(AI_MATKEY_NAME, name); + source->Get(AI_MATKEY_COLOR_AMBIENT, ambient); + source->Get(AI_MATKEY_COLOR_DIFFUSE, diffuse); + source->Get(AI_MATKEY_COLOR_SPECULAR, specular); + source->Get(AI_MATKEY_COLOR_EMISSIVE, emissive); + source->Get(AI_MATKEY_SHININESS, shininess); + source->Get(AI_MATKEY_OPACITY, opacity); + + // TODO: need something better then this, but based on my (limited) testing + // diffuse texture seems to be the most common + source->Get(AI_MATKEY_TEXTURE_DIFFUSE(0), textureFile); + + this->name = std::string(name.data, name.length); + + this->texture = std::string(textureFile.data, textureFile.length); + + this->ambient[0] = ambient.r; + this->ambient[1] = ambient.g; + this->ambient[2] = ambient.b; + + this->diffuse[0] = diffuse.r; + this->diffuse[1] = diffuse.g; + this->diffuse[2] = diffuse.b; + + this->specular[0] = specular.r; + this->specular[1] = specular.g; + this->specular[2] = specular.b; + + this->emissive[0] = emissive.r; + this->emissive[1] = emissive.g; + this->emissive[2] = emissive.b; + + this->shininess = shininess; + + this->opacity = opacity; + } + + std::string name; + std::string texture; + float ambient[3]; + float diffuse[3]; + float specular[3]; + float emissive[3]; + float shininess; + float opacity; +}; + +#endif diff --git a/AssimpToMesh/src/convert/meshtriangle.h b/AssimpToMesh/src/convert/meshtriangle.h index 5c1824c..4b429d6 100644 --- a/AssimpToMesh/src/convert/meshtriangle.h +++ b/AssimpToMesh/src/convert/meshtriangle.h @@ -1,12 +1,12 @@ -#ifndef __CONVERT_MESHTRIANGLE_H_INCLUDED__ -#define __CONVERT_MESHTRIANGLE_H_INCLUDED__ - -#include - -struct MeshTriangle -{ - uint32_t vertices[3]; - uint32_t subMesh; -}; - -#endif +#ifndef __CONVERT_MESHTRIANGLE_H_INCLUDED__ +#define __CONVERT_MESHTRIANGLE_H_INCLUDED__ + +#include + +struct MeshTriangle +{ + uint32_t vertices[3]; + uint32_t subMesh; +}; + +#endif diff --git a/AssimpToMesh/src/convert/meshutils.cpp b/AssimpToMesh/src/convert/meshutils.cpp index 6bd5325..7287445 100644 --- a/AssimpToMesh/src/convert/meshutils.cpp +++ b/AssimpToMesh/src/convert/meshutils.cpp @@ -1,321 +1,321 @@ -#include "mesh.h" - -#include -#include - -void WriteMeshHeader(FILE *fp) -{ - fputs("MESH", fp); - uint8_t version = 1; - fwrite(&version, 1, 1, fp); -} - -void WriteVertices(const AssimpVertices &vertices, FILE *fp) -{ - uint32_t count = vertices.size(); - if (count == 0) - return; - - uint32_t size = - (sizeof(float) * 3) * // x y, z - vertices.size() - + 4; // chunk size - - fputs("VTX", fp); - fwrite(&size, 4, 1, fp); - fwrite(&count, 4, 1, fp); - - for (uint32_t i = 0; i < count; ++i) - { - fwrite(&vertices[i].x, sizeof(float), 1, fp); - fwrite(&vertices[i].y, sizeof(float), 1, fp); - fwrite(&vertices[i].z, sizeof(float), 1, fp); - } -} - -void WriteNormals(const AssimpVertices &normals, FILE *fp) -{ - uint32_t count = normals.size(); - if (count == 0) - return; - - uint32_t size = - (sizeof(float) * 3) * // x y, z - normals.size() - + 4; // chunk size - - fputs("NRL", fp); - fwrite(&size, 4, 1, fp); - fwrite(&count, 4, 1, fp); - - for (uint32_t i = 0; i < count; ++i) - { - fwrite(&normals[i].x, sizeof(float), 1, fp); - fwrite(&normals[i].y, sizeof(float), 1, fp); - fwrite(&normals[i].z, sizeof(float), 1, fp); - } -} - -void WriteTexCoords(const AssimpVertices &texCoords, FILE *fp) -{ - uint32_t count = texCoords.size(); - if (count == 0) - return; - - uint32_t size = - (sizeof(float) * 2) * // u, v - texCoords.size() - + 4; // count - - fputs("TXT", fp); - fwrite(&size, 4, 1, fp); - fwrite(&count, 4, 1, fp); - - for (uint32_t i = 0; i < count; ++i) - { - fwrite(&texCoords[i].x, sizeof(float), 1, fp); - fwrite(&texCoords[i].y, sizeof(float), 1, fp); - } -} - -void WriteMaterials(const std::vector &materials, FILE *fp) -{ - uint32_t count = materials.size(); - if (count == 0) - return; - - uint32_t size = 4 + // count - ( - ( - (sizeof(float) * 3) + // ambient - (sizeof(float) * 3) + // diffuse - (sizeof(float) * 3) + // specular - (sizeof(float) * 3) + // emissive - sizeof(float) + // shininess - sizeof(float) // opacity - ) * count - ); - - // add up all the variable length string sizes for the material names and texture filenames - for (uint32_t i = 0; i < count; ++i) - { - size += materials[i].name.length() + 1; // include null terminator - size += materials[i].texture.length() + 1; // ditto - } - - fputs("MTL", fp); - fwrite(&size, 4, 1, fp); - fwrite(&count, 4, 1, fp); - - for (uint32_t i = 0; i < count; ++i) - { - const MeshMaterial *m = &materials[i]; - - fwrite(m->name.c_str(), m->name.length(), 1, fp); - char ch = '\0'; - fwrite(&ch, 1, 1, fp); - - fwrite(m->texture.c_str(), m->texture.length(), 1, fp); - fwrite(&ch, 1, 1, fp); - - fwrite(&m->ambient[0], sizeof(float), 1, fp); - fwrite(&m->ambient[1], sizeof(float), 1, fp); - fwrite(&m->ambient[2], sizeof(float), 1, fp); - - fwrite(&m->diffuse[0], sizeof(float), 1, fp); - fwrite(&m->diffuse[1], sizeof(float), 1, fp); - fwrite(&m->diffuse[2], sizeof(float), 1, fp); - - fwrite(&m->specular[0], sizeof(float), 1, fp); - fwrite(&m->specular[1], sizeof(float), 1, fp); - fwrite(&m->specular[2], sizeof(float), 1, fp); - - fwrite(&m->emissive[0], sizeof(float), 1, fp); - fwrite(&m->emissive[1], sizeof(float), 1, fp); - fwrite(&m->emissive[2], sizeof(float), 1, fp); - - fwrite(&m->shininess, sizeof(float), 1, fp); - - fwrite(&m->opacity, sizeof(float), 1, fp); - } -} - -void WriteTriangles(const std::vector &triangles, FILE *fp) -{ - uint32_t count = triangles.size(); - if (count == 0) - return; - - uint32_t size = 4; // count - size += - ( - (4 * 3) // vertex indices - + 4 // material index - ) * count; - - fputs("TRI", fp); - fwrite(&size, 4, 1, fp); - fwrite(&count, 4, 1, fp); - - for (uint32_t i = 0; i < count; ++i) - { - const MeshTriangle *t = &triangles[i]; - - fwrite(&t->vertices[0], 4, 1, fp); - fwrite(&t->vertices[1], 4, 1, fp); - fwrite(&t->vertices[2], 4, 1, fp); - - fwrite(&t->subMesh, 4, 1, fp); - } -} - -void WriteSubMeshes(const std::vector &subMeshes, FILE *fp) -{ - uint32_t count = subMeshes.size(); - if (count == 0) - return; - - uint32_t size = 4 + // count - 4 + // material index - 4; // count of triangles - - // add up all the variable length string sizes for the submesh names - for (uint32_t i = 0; i < count; ++i) - size += subMeshes[i].name.length() + 1; // include null terminator - - fputs("GRP", fp); - fwrite(&size, 4, 1, fp); - fwrite(&count, 4, 1, fp); - for (uint32_t i = 0; i < count; ++i) - { - const SubMesh *m = &subMeshes[i]; - - fwrite(m->name.c_str(), m->name.length(), 1, fp); - char c = '\0'; - fwrite(&c, 1, 1, fp); - - fwrite(&m->material, 4, 1, fp); - fwrite(&m->numTriangles, 4, 1, fp); - } -} - -void WriteJoints(const std::vector &joints, FILE *fp) -{ - uint32_t count = joints.size(); - if (count == 0) - return; - - uint32_t size = 4 + // count - ( - 4 + // parent joint index - (sizeof(float) * 3) + // local position (x, y, z) - (sizeof(float) * 4) + // local rotation (x, y, z, w) - (sizeof(float) * 3) + // offset position (x, y, z) - (sizeof(float) * 4) // offset rotation (x, y, z, w) - ) * count; - - // add up all the variable length joint names - for (uint32_t i = 0; i < count; ++i) - size += joints[i].name.length() + 1; // include null terminator - - fputs("JNT", fp); - fwrite(&size, 4, 1, fp); - fwrite(&count, 4, 1, fp); - for (uint32_t i = 0; i < count; ++i) - { - const MeshJoint *j = &joints[i]; - - fwrite(j->name.c_str(), j->name.length(), 1, fp); - char c = '\0'; - fwrite(&c, 1, 1, fp); - - int32_t parentIndex = GetIndexOf(joints, j->parentName); - fwrite(&parentIndex, 4, 1, fp); - - fwrite(&j->localPosition.x, sizeof(float), 1, fp); - fwrite(&j->localPosition.y, sizeof(float), 1, fp); - fwrite(&j->localPosition.z, sizeof(float), 1, fp); - - fwrite(&j->localRotation.x, sizeof(float), 1, fp); - fwrite(&j->localRotation.y, sizeof(float), 1, fp); - fwrite(&j->localRotation.z, sizeof(float), 1, fp); - fwrite(&j->localRotation.w, sizeof(float), 1, fp); - - fwrite(&j->offsetPosition.x, sizeof(float), 1, fp); - fwrite(&j->offsetPosition.y, sizeof(float), 1, fp); - fwrite(&j->offsetPosition.z, sizeof(float), 1, fp); - - fwrite(&j->offsetRotation.x, sizeof(float), 1, fp); - fwrite(&j->offsetRotation.y, sizeof(float), 1, fp); - fwrite(&j->offsetRotation.z, sizeof(float), 1, fp); - fwrite(&j->offsetRotation.w, sizeof(float), 1, fp); - } -} - -void WriteJointToVertexMap(const std::vector &vertexToJointMap, FILE *fp) -{ - uint32_t count = vertexToJointMap.size(); - if (count == 0) - return; - - uint32_t size = 4 + // count - (4 * count); // num vertices - - fputs("JTV", fp); - fwrite(&size, 4, 1, fp); - fwrite(&count, 4, 1, fp); - for (uint32_t i = 0; i < count; ++i) - { - uint32_t jointIndex = vertexToJointMap[i]; - fwrite(&jointIndex, 4, 1, fp); - } -} - -void WriteJointKeyFrames(const std::vector &jointKeyFrames, FILE *fp) -{ - uint32_t numJoints = jointKeyFrames.size(); - if (numJoints == 0) - return; - - uint32_t numFrames = jointKeyFrames[0].size(); - - uint32_t size = 4 + // num frames - ( - ( - (sizeof(float) * 3) + // position (x, y, z) - (sizeof(float) * 4) // rotation (x, y, z, w) - ) * numJoints // for each joint - ) * numFrames; // for each frame - - fputs("JKF", fp); - fwrite(&size, 4, 1, fp); - fwrite(&numFrames, 4, 1, fp); - for (uint32_t i = 0; i < numJoints; ++i) - { - for (uint32_t j = 0; j < numFrames; ++j) - { - const MeshJointKeyFrame *frame = &jointKeyFrames[i][j]; - - fwrite(&frame->position.x, sizeof(float), 1, fp); - fwrite(&frame->position.y, sizeof(float), 1, fp); - fwrite(&frame->position.z, sizeof(float), 1, fp); - - fwrite(&frame->rotation.x, sizeof(float), 1, fp); - fwrite(&frame->rotation.y, sizeof(float), 1, fp); - fwrite(&frame->rotation.z, sizeof(float), 1, fp); - fwrite(&frame->rotation.w, sizeof(float), 1, fp); - } - } -} - - -int32_t GetIndexOf(const std::vector &joints, const std::string &name) -{ - for (uint32_t i = 0; i < joints.size(); ++i) - { - if (joints[i].name == name) - return i; - } - - return -1; -} +#include "mesh.h" + +#include +#include + +void WriteMeshHeader(FILE *fp) +{ + fputs("MESH", fp); + uint8_t version = 1; + fwrite(&version, 1, 1, fp); +} + +void WriteVertices(const AssimpVertices &vertices, FILE *fp) +{ + uint32_t count = vertices.size(); + if (count == 0) + return; + + uint32_t size = + (sizeof(float) * 3) * // x y, z + vertices.size() + + 4; // chunk size + + fputs("VTX", fp); + fwrite(&size, 4, 1, fp); + fwrite(&count, 4, 1, fp); + + for (uint32_t i = 0; i < count; ++i) + { + fwrite(&vertices[i].x, sizeof(float), 1, fp); + fwrite(&vertices[i].y, sizeof(float), 1, fp); + fwrite(&vertices[i].z, sizeof(float), 1, fp); + } +} + +void WriteNormals(const AssimpVertices &normals, FILE *fp) +{ + uint32_t count = normals.size(); + if (count == 0) + return; + + uint32_t size = + (sizeof(float) * 3) * // x y, z + normals.size() + + 4; // chunk size + + fputs("NRL", fp); + fwrite(&size, 4, 1, fp); + fwrite(&count, 4, 1, fp); + + for (uint32_t i = 0; i < count; ++i) + { + fwrite(&normals[i].x, sizeof(float), 1, fp); + fwrite(&normals[i].y, sizeof(float), 1, fp); + fwrite(&normals[i].z, sizeof(float), 1, fp); + } +} + +void WriteTexCoords(const AssimpVertices &texCoords, FILE *fp) +{ + uint32_t count = texCoords.size(); + if (count == 0) + return; + + uint32_t size = + (sizeof(float) * 2) * // u, v + texCoords.size() + + 4; // count + + fputs("TXT", fp); + fwrite(&size, 4, 1, fp); + fwrite(&count, 4, 1, fp); + + for (uint32_t i = 0; i < count; ++i) + { + fwrite(&texCoords[i].x, sizeof(float), 1, fp); + fwrite(&texCoords[i].y, sizeof(float), 1, fp); + } +} + +void WriteMaterials(const std::vector &materials, FILE *fp) +{ + uint32_t count = materials.size(); + if (count == 0) + return; + + uint32_t size = 4 + // count + ( + ( + (sizeof(float) * 3) + // ambient + (sizeof(float) * 3) + // diffuse + (sizeof(float) * 3) + // specular + (sizeof(float) * 3) + // emissive + sizeof(float) + // shininess + sizeof(float) // opacity + ) * count + ); + + // add up all the variable length string sizes for the material names and texture filenames + for (uint32_t i = 0; i < count; ++i) + { + size += materials[i].name.length() + 1; // include null terminator + size += materials[i].texture.length() + 1; // ditto + } + + fputs("MTL", fp); + fwrite(&size, 4, 1, fp); + fwrite(&count, 4, 1, fp); + + for (uint32_t i = 0; i < count; ++i) + { + const MeshMaterial *m = &materials[i]; + + fwrite(m->name.c_str(), m->name.length(), 1, fp); + char ch = '\0'; + fwrite(&ch, 1, 1, fp); + + fwrite(m->texture.c_str(), m->texture.length(), 1, fp); + fwrite(&ch, 1, 1, fp); + + fwrite(&m->ambient[0], sizeof(float), 1, fp); + fwrite(&m->ambient[1], sizeof(float), 1, fp); + fwrite(&m->ambient[2], sizeof(float), 1, fp); + + fwrite(&m->diffuse[0], sizeof(float), 1, fp); + fwrite(&m->diffuse[1], sizeof(float), 1, fp); + fwrite(&m->diffuse[2], sizeof(float), 1, fp); + + fwrite(&m->specular[0], sizeof(float), 1, fp); + fwrite(&m->specular[1], sizeof(float), 1, fp); + fwrite(&m->specular[2], sizeof(float), 1, fp); + + fwrite(&m->emissive[0], sizeof(float), 1, fp); + fwrite(&m->emissive[1], sizeof(float), 1, fp); + fwrite(&m->emissive[2], sizeof(float), 1, fp); + + fwrite(&m->shininess, sizeof(float), 1, fp); + + fwrite(&m->opacity, sizeof(float), 1, fp); + } +} + +void WriteTriangles(const std::vector &triangles, FILE *fp) +{ + uint32_t count = triangles.size(); + if (count == 0) + return; + + uint32_t size = 4; // count + size += + ( + (4 * 3) // vertex indices + + 4 // material index + ) * count; + + fputs("TRI", fp); + fwrite(&size, 4, 1, fp); + fwrite(&count, 4, 1, fp); + + for (uint32_t i = 0; i < count; ++i) + { + const MeshTriangle *t = &triangles[i]; + + fwrite(&t->vertices[0], 4, 1, fp); + fwrite(&t->vertices[1], 4, 1, fp); + fwrite(&t->vertices[2], 4, 1, fp); + + fwrite(&t->subMesh, 4, 1, fp); + } +} + +void WriteSubMeshes(const std::vector &subMeshes, FILE *fp) +{ + uint32_t count = subMeshes.size(); + if (count == 0) + return; + + uint32_t size = 4 + // count + 4 + // material index + 4; // count of triangles + + // add up all the variable length string sizes for the submesh names + for (uint32_t i = 0; i < count; ++i) + size += subMeshes[i].name.length() + 1; // include null terminator + + fputs("GRP", fp); + fwrite(&size, 4, 1, fp); + fwrite(&count, 4, 1, fp); + for (uint32_t i = 0; i < count; ++i) + { + const SubMesh *m = &subMeshes[i]; + + fwrite(m->name.c_str(), m->name.length(), 1, fp); + char c = '\0'; + fwrite(&c, 1, 1, fp); + + fwrite(&m->material, 4, 1, fp); + fwrite(&m->numTriangles, 4, 1, fp); + } +} + +void WriteJoints(const std::vector &joints, FILE *fp) +{ + uint32_t count = joints.size(); + if (count == 0) + return; + + uint32_t size = 4 + // count + ( + 4 + // parent joint index + (sizeof(float) * 3) + // local position (x, y, z) + (sizeof(float) * 4) + // local rotation (x, y, z, w) + (sizeof(float) * 3) + // offset position (x, y, z) + (sizeof(float) * 4) // offset rotation (x, y, z, w) + ) * count; + + // add up all the variable length joint names + for (uint32_t i = 0; i < count; ++i) + size += joints[i].name.length() + 1; // include null terminator + + fputs("JNT", fp); + fwrite(&size, 4, 1, fp); + fwrite(&count, 4, 1, fp); + for (uint32_t i = 0; i < count; ++i) + { + const MeshJoint *j = &joints[i]; + + fwrite(j->name.c_str(), j->name.length(), 1, fp); + char c = '\0'; + fwrite(&c, 1, 1, fp); + + int32_t parentIndex = GetIndexOf(joints, j->parentName); + fwrite(&parentIndex, 4, 1, fp); + + fwrite(&j->localPosition.x, sizeof(float), 1, fp); + fwrite(&j->localPosition.y, sizeof(float), 1, fp); + fwrite(&j->localPosition.z, sizeof(float), 1, fp); + + fwrite(&j->localRotation.x, sizeof(float), 1, fp); + fwrite(&j->localRotation.y, sizeof(float), 1, fp); + fwrite(&j->localRotation.z, sizeof(float), 1, fp); + fwrite(&j->localRotation.w, sizeof(float), 1, fp); + + fwrite(&j->offsetPosition.x, sizeof(float), 1, fp); + fwrite(&j->offsetPosition.y, sizeof(float), 1, fp); + fwrite(&j->offsetPosition.z, sizeof(float), 1, fp); + + fwrite(&j->offsetRotation.x, sizeof(float), 1, fp); + fwrite(&j->offsetRotation.y, sizeof(float), 1, fp); + fwrite(&j->offsetRotation.z, sizeof(float), 1, fp); + fwrite(&j->offsetRotation.w, sizeof(float), 1, fp); + } +} + +void WriteJointToVertexMap(const std::vector &vertexToJointMap, FILE *fp) +{ + uint32_t count = vertexToJointMap.size(); + if (count == 0) + return; + + uint32_t size = 4 + // count + (4 * count); // num vertices + + fputs("JTV", fp); + fwrite(&size, 4, 1, fp); + fwrite(&count, 4, 1, fp); + for (uint32_t i = 0; i < count; ++i) + { + uint32_t jointIndex = vertexToJointMap[i]; + fwrite(&jointIndex, 4, 1, fp); + } +} + +void WriteJointKeyFrames(const std::vector &jointKeyFrames, FILE *fp) +{ + uint32_t numJoints = jointKeyFrames.size(); + if (numJoints == 0) + return; + + uint32_t numFrames = jointKeyFrames[0].size(); + + uint32_t size = 4 + // num frames + ( + ( + (sizeof(float) * 3) + // position (x, y, z) + (sizeof(float) * 4) // rotation (x, y, z, w) + ) * numJoints // for each joint + ) * numFrames; // for each frame + + fputs("JKF", fp); + fwrite(&size, 4, 1, fp); + fwrite(&numFrames, 4, 1, fp); + for (uint32_t i = 0; i < numJoints; ++i) + { + for (uint32_t j = 0; j < numFrames; ++j) + { + const MeshJointKeyFrame *frame = &jointKeyFrames[i][j]; + + fwrite(&frame->position.x, sizeof(float), 1, fp); + fwrite(&frame->position.y, sizeof(float), 1, fp); + fwrite(&frame->position.z, sizeof(float), 1, fp); + + fwrite(&frame->rotation.x, sizeof(float), 1, fp); + fwrite(&frame->rotation.y, sizeof(float), 1, fp); + fwrite(&frame->rotation.z, sizeof(float), 1, fp); + fwrite(&frame->rotation.w, sizeof(float), 1, fp); + } + } +} + + +int32_t GetIndexOf(const std::vector &joints, const std::string &name) +{ + for (uint32_t i = 0; i < joints.size(); ++i) + { + if (joints[i].name == name) + return i; + } + + return -1; +} diff --git a/AssimpToMesh/src/convert/skeletalanimated.cpp b/AssimpToMesh/src/convert/skeletalanimated.cpp index aa4dbcc..1321173 100644 --- a/AssimpToMesh/src/convert/skeletalanimated.cpp +++ b/AssimpToMesh/src/convert/skeletalanimated.cpp @@ -1,147 +1,147 @@ -#include "convert.h" - -#include -#include -#include - -#include "mesh.h" -#include "../assimputils/utils.h" - -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 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 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 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); - - // TODO: cheating for now, but according to the ASSIMP doc's, there could be - // models which have nodes that are not used by any bones, but still - // affect the skeleton pose, because child nodes *are* used by bones - // and so, any parent node transformations will apply and need to be - // carried down the chain. None of the test models I'm using have this - // type of node structure, so I'm ignoring it for now :) - - // collect basic skeleton/joint info - std::vector joints; - std::vector vertexToJointMap; - vertexToJointMap.resize(vertices.size()); - for (unsigned int i = 0; i < scene->mNumMeshes; ++i) - { - aiMesh *mesh = scene->mMeshes[i]; - for (unsigned int j = 0; j < mesh->mNumBones; ++j) - { - aiBone *bone = mesh->mBones[j]; - aiNode *node = scene->mRootNode->FindNode(bone->mName); - aiNode *parentNode = node->mParent; - - MeshJoint joint; - joint.name = std::string(bone->mName.data, bone->mName.length); - if (strcmp(parentNode->mName.data, "$dummy_root") == 0) - joint.parentName = ""; - else - joint.parentName = std::string(parentNode->mName.data, parentNode->mName.length); - - aiMatrix4x4 transform = node->mTransformation * bone->mOffsetMatrix; - node->mTransformation.DecomposeNoScaling(joint.localRotation, joint.localPosition); - bone->mOffsetMatrix.DecomposeNoScaling(joint.offsetRotation, joint.offsetPosition); - - // assumption: sum of all bone->mNumWeights is always == vertices.size() - for (unsigned int k = 0; k < bone->mNumWeights; ++k) - { - aiVertexWeight *weight = &bone->mWeights[k]; - unsigned int index = vertexIndicesMap[i][weight->mVertexId]; - vertexToJointMap[index] = j; - } - - joints.push_back(joint); - } - } - WriteJoints(joints, fp); - WriteJointToVertexMap(vertexToJointMap, fp); - - // TODO: this collection process is dumb at the moment. assumes each bone - // has the same number of frames as all the other ones. also, every - // test model i've used so far puts all the frames into a single - // animation (usually without a name even). so this is, for now, only - // looking at the first aiAnimation object. ALSO, because i'm REALLY - // lazy, the animations aiNodeAnim objects are assumed to be in the - // same order as the bones were collected in :) - // collect joint keyframes - std::vector meshFrames; - aiAnimation *animation = scene->mAnimations[0]; - for (unsigned int i = 0; i < animation->mNumChannels; ++i) - { - aiNodeAnim *nodeAnim = animation->mChannels[i]; - JointKeyFrames jointFrames; - - for (unsigned int j = 0; j < nodeAnim->mNumPositionKeys; ++j) - { - // TODO: should really get the times too - MeshJointKeyFrame frame; - frame.position = nodeAnim->mPositionKeys[j].mValue; - frame.rotation = nodeAnim->mRotationKeys[j].mValue; - - jointFrames.push_back(frame); - } - - meshFrames.push_back(jointFrames); - } - WriteJointKeyFrames(meshFrames, fp); - - fclose(fp); -} +#include "convert.h" + +#include +#include +#include + +#include "mesh.h" +#include "../assimputils/utils.h" + +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 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 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 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); + + // TODO: cheating for now, but according to the ASSIMP doc's, there could be + // models which have nodes that are not used by any bones, but still + // affect the skeleton pose, because child nodes *are* used by bones + // and so, any parent node transformations will apply and need to be + // carried down the chain. None of the test models I'm using have this + // type of node structure, so I'm ignoring it for now :) + + // collect basic skeleton/joint info + std::vector joints; + std::vector vertexToJointMap; + vertexToJointMap.resize(vertices.size()); + for (unsigned int i = 0; i < scene->mNumMeshes; ++i) + { + aiMesh *mesh = scene->mMeshes[i]; + for (unsigned int j = 0; j < mesh->mNumBones; ++j) + { + aiBone *bone = mesh->mBones[j]; + aiNode *node = scene->mRootNode->FindNode(bone->mName); + aiNode *parentNode = node->mParent; + + MeshJoint joint; + joint.name = std::string(bone->mName.data, bone->mName.length); + if (strcmp(parentNode->mName.data, "$dummy_root") == 0) + joint.parentName = ""; + else + joint.parentName = std::string(parentNode->mName.data, parentNode->mName.length); + + aiMatrix4x4 transform = node->mTransformation * bone->mOffsetMatrix; + node->mTransformation.DecomposeNoScaling(joint.localRotation, joint.localPosition); + bone->mOffsetMatrix.DecomposeNoScaling(joint.offsetRotation, joint.offsetPosition); + + // assumption: sum of all bone->mNumWeights is always == vertices.size() + for (unsigned int k = 0; k < bone->mNumWeights; ++k) + { + aiVertexWeight *weight = &bone->mWeights[k]; + unsigned int index = vertexIndicesMap[i][weight->mVertexId]; + vertexToJointMap[index] = j; + } + + joints.push_back(joint); + } + } + WriteJoints(joints, fp); + WriteJointToVertexMap(vertexToJointMap, fp); + + // TODO: this collection process is dumb at the moment. assumes each bone + // has the same number of frames as all the other ones. also, every + // test model i've used so far puts all the frames into a single + // animation (usually without a name even). so this is, for now, only + // looking at the first aiAnimation object. ALSO, because i'm REALLY + // lazy, the animations aiNodeAnim objects are assumed to be in the + // same order as the bones were collected in :) + // collect joint keyframes + std::vector meshFrames; + aiAnimation *animation = scene->mAnimations[0]; + for (unsigned int i = 0; i < animation->mNumChannels; ++i) + { + aiNodeAnim *nodeAnim = animation->mChannels[i]; + JointKeyFrames jointFrames; + + for (unsigned int j = 0; j < nodeAnim->mNumPositionKeys; ++j) + { + // TODO: should really get the times too + MeshJointKeyFrame frame; + frame.position = nodeAnim->mPositionKeys[j].mValue; + frame.rotation = nodeAnim->mRotationKeys[j].mValue; + + jointFrames.push_back(frame); + } + + meshFrames.push_back(jointFrames); + } + WriteJointKeyFrames(meshFrames, fp); + + fclose(fp); +} diff --git a/AssimpToMesh/src/convert/static.cpp b/AssimpToMesh/src/convert/static.cpp index a014321..c218828 100644 --- a/AssimpToMesh/src/convert/static.cpp +++ b/AssimpToMesh/src/convert/static.cpp @@ -1,73 +1,73 @@ -#include "convert.h" - -#include -#include -#include - -#include "mesh.h" -#include "../assimputils/utils.h" - -void ConvertStatic(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 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 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 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); - - fclose(fp); -} +#include "convert.h" + +#include +#include +#include + +#include "mesh.h" +#include "../assimputils/utils.h" + +void ConvertStatic(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 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 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 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); + + fclose(fp); +} diff --git a/AssimpToMesh/src/convert/submesh.h b/AssimpToMesh/src/convert/submesh.h index d9edc7f..24a4494 100644 --- a/AssimpToMesh/src/convert/submesh.h +++ b/AssimpToMesh/src/convert/submesh.h @@ -1,14 +1,14 @@ -#ifndef __CONVERT_SUBMESH_H_INCLUDED__ -#define __CONVERT_SUBMESH_H_INCLUDED__ - -#include -#include - -struct SubMesh -{ - std::string name; - uint32_t material; - uint32_t numTriangles; -}; - -#endif +#ifndef __CONVERT_SUBMESH_H_INCLUDED__ +#define __CONVERT_SUBMESH_H_INCLUDED__ + +#include +#include + +struct SubMesh +{ + std::string name; + uint32_t material; + uint32_t numTriangles; +}; + +#endif diff --git a/AssimpToMesh/src/main.cpp b/AssimpToMesh/src/main.cpp index 1bcf52f..6eb4884 100644 --- a/AssimpToMesh/src/main.cpp +++ b/AssimpToMesh/src/main.cpp @@ -1,142 +1,142 @@ -#include -#include -#include - -#include -#include -#include - -#include "utils/utils.h" -#include "assimputils/utils.h" -#include "convert/convert.h" -#include "nodetree/nodetree.h" - -int main(int argc, char *argv[]) -{ - printf("ASSIMP-to-MESH Converter.\n"); - - if (argc == 1) - { - printf("Usage: assimptomesh.exe [--describe=txtfile] [--out=outputfile] inputfile\n\n"); - return 0; - } - - // input file is always the last argument - std::string file = argv[argc - 1]; - - std::string outputFile; - std::string describeFile; - - // find any options - for (int i = 1; i < argc - 1; ++i) - { - std::string arg = argv[i]; - - if (arg.substr(0, 11) == "--describe=") - { - if (arg.length() == 11) - { - printf("Missing description output filename.\n"); - return 1; - } - describeFile = arg.substr(11); - } - - else if (arg.substr(0, 6) == "--out=") - { - if (arg.length() == 6) - { - printf("Missing output filename.\n"); - return 1; - } - outputFile = arg.substr(6); - } - } - - // attempt to load the input file - printf("Input file: %s\n", file.c_str()); - Assimp::Importer importer; - const aiScene *scene = importer.ReadFile(file, - aiProcess_JoinIdenticalVertices | - aiProcess_GenSmoothNormals | - aiProcess_Triangulate | - aiProcess_RemoveRedundantMaterials | - aiProcess_SortByPType | - aiProcess_OptimizeMeshes | - aiProcess_OptimizeGraph | - aiProcess_GenUVCoords | - aiProcess_TransformUVCoords | - aiProcess_FlipUVs | - aiProcess_FindInvalidData - ); - - if (!scene) - { - printf("Failed to load input file: %s\n\n", importer.GetErrorString()); - return 1; - } - printf("Scene loaded.\n"); - - // input file loaded, now get the output filename (if not provided via command line) - if (outputFile.length() == 0) - { - outputFile = GetMeshFilenameFromInput(file); - if (outputFile.length() == 0) - { - printf("Unable to determine output mesh filename from the input file name.\n\n"); - return 1; - } - } - printf("Output file: %s\n", outputFile.c_str()); - - // optionally show info about the entire scene before doing the conversion - if (describeFile.length() > 0) - { - try - { - Walk(scene, describeFile); - } - catch (std::exception &ex) - { - printf("Error: %s\n", ex.what()); - return 1; - } - } - - // attempt conversion using an appropriate converter based on what kind of scene it is - if (IsSceneStatic(scene)) - { - printf("Using static converter.\n"); - try - { - ConvertStatic(outputFile, scene); - } - catch (std::exception &ex) - { - printf("Error: %s\n", ex.what()); - return 1; - } - printf("Convert complete.\n"); - } - else if (IsSceneAnimated(scene) && IsSceneSkeletal(scene)) - { - printf("Using skeletal animation converter.\n"); - try - { - ConvertSkeletalAnimated(outputFile, scene); - } - catch (std::exception &ex) - { - printf("Error: %s\n", ex.what()); - return 1; - } - printf("Convert complete.\n"); - } - else - { - printf("Unknown scene format.\n"); - return 1; - } - - return 0; -} +#include +#include +#include + +#include +#include +#include + +#include "utils/utils.h" +#include "assimputils/utils.h" +#include "convert/convert.h" +#include "nodetree/nodetree.h" + +int main(int argc, char *argv[]) +{ + printf("ASSIMP-to-MESH Converter.\n"); + + if (argc == 1) + { + printf("Usage: assimptomesh.exe [--describe=txtfile] [--out=outputfile] inputfile\n\n"); + return 0; + } + + // input file is always the last argument + std::string file = argv[argc - 1]; + + std::string outputFile; + std::string describeFile; + + // find any options + for (int i = 1; i < argc - 1; ++i) + { + std::string arg = argv[i]; + + if (arg.substr(0, 11) == "--describe=") + { + if (arg.length() == 11) + { + printf("Missing description output filename.\n"); + return 1; + } + describeFile = arg.substr(11); + } + + else if (arg.substr(0, 6) == "--out=") + { + if (arg.length() == 6) + { + printf("Missing output filename.\n"); + return 1; + } + outputFile = arg.substr(6); + } + } + + // attempt to load the input file + printf("Input file: %s\n", file.c_str()); + Assimp::Importer importer; + const aiScene *scene = importer.ReadFile(file, + aiProcess_JoinIdenticalVertices | + aiProcess_GenSmoothNormals | + aiProcess_Triangulate | + aiProcess_RemoveRedundantMaterials | + aiProcess_SortByPType | + aiProcess_OptimizeMeshes | + aiProcess_OptimizeGraph | + aiProcess_GenUVCoords | + aiProcess_TransformUVCoords | + aiProcess_FlipUVs | + aiProcess_FindInvalidData + ); + + if (!scene) + { + printf("Failed to load input file: %s\n\n", importer.GetErrorString()); + return 1; + } + printf("Scene loaded.\n"); + + // input file loaded, now get the output filename (if not provided via command line) + if (outputFile.length() == 0) + { + outputFile = GetMeshFilenameFromInput(file); + if (outputFile.length() == 0) + { + printf("Unable to determine output mesh filename from the input file name.\n\n"); + return 1; + } + } + printf("Output file: %s\n", outputFile.c_str()); + + // optionally show info about the entire scene before doing the conversion + if (describeFile.length() > 0) + { + try + { + Walk(scene, describeFile); + } + catch (std::exception &ex) + { + printf("Error: %s\n", ex.what()); + return 1; + } + } + + // attempt conversion using an appropriate converter based on what kind of scene it is + if (IsSceneStatic(scene)) + { + printf("Using static converter.\n"); + try + { + ConvertStatic(outputFile, scene); + } + catch (std::exception &ex) + { + printf("Error: %s\n", ex.what()); + return 1; + } + printf("Convert complete.\n"); + } + else if (IsSceneAnimated(scene) && IsSceneSkeletal(scene)) + { + printf("Using skeletal animation converter.\n"); + try + { + ConvertSkeletalAnimated(outputFile, scene); + } + catch (std::exception &ex) + { + printf("Error: %s\n", ex.what()); + return 1; + } + printf("Convert complete.\n"); + } + else + { + printf("Unknown scene format.\n"); + return 1; + } + + return 0; +} diff --git a/AssimpToMesh/src/nodetree/nodetree.cpp b/AssimpToMesh/src/nodetree/nodetree.cpp index 7e9d56c..3965849 100644 --- a/AssimpToMesh/src/nodetree/nodetree.cpp +++ b/AssimpToMesh/src/nodetree/nodetree.cpp @@ -1,266 +1,266 @@ -#include "nodetree.h" - -#include -#include - -void WalkNode(const aiNode *node); -void ShowMeshInfo(const aiMesh *mesh, const aiScene *scene); -void ShowMaterialInfo(const aiMaterial *material); -void ShowMaterialTextureInfo(const aiMaterial *material, aiTextureType type, const std::string &typeText); -void ShowAnimationInfo(const aiAnimation *animation); - -unsigned int g_level; -FILE *g_fp = NULL; - -std::string GetIndentString() -{ - std::string indent; - for (unsigned int i = 0; i < g_level; ++i) - indent += " "; - return indent; -} - -void Walk(const aiScene *scene, const std::string &filename) -{ - g_level = 0; - - g_fp = fopen(filename.c_str(), "w"); - if (g_fp == NULL) - throw std::exception("Error creating description output file."); - - fprintf(g_fp, "\n*** GENERAL SCENE INFO ***\n\n"); - fprintf(g_fp, "HasAnimations: %s\n", scene->HasAnimations() ? "yes" : "no"); - fprintf(g_fp, "HasMaterials: %s\n", scene->HasMaterials() ? "yes" : "no"); - fprintf(g_fp, "HasMeshes: %s\n", scene->HasMeshes() ? "yes" : "no"); - fprintf(g_fp, "mNumAnimations: %d\n", scene->mNumAnimations); - fprintf(g_fp, "mNumMaterials: %d\n", scene->mNumMaterials); - fprintf(g_fp, "mNumMeshes: %d\n", scene->mNumMeshes); - fprintf(g_fp, "\n"); - - if (scene->mNumMaterials > 0) - { - fprintf(g_fp, "\n*** MATERIALS ***\n\n"); - - for (unsigned int i = 0; i < scene->mNumMaterials; ++i) - { - fprintf(g_fp, "[%d]:\n", i); - ShowMaterialInfo(scene->mMaterials[i]); - } - } - - fprintf(g_fp, "\n*** MESHES ***\n\n"); - - for (unsigned int i = 0; i < scene->mNumMeshes; ++i) - { - fprintf(g_fp, "[%d]\n", i); - ShowMeshInfo(scene->mMeshes[i], scene); - } - - fprintf(g_fp, "\n*** NODES ***\n"); - WalkNode(scene->mRootNode); - - if (scene->mNumAnimations > 0) - { - fprintf(g_fp, "\n*** ANIMATIONS ***\n\n"); - - for (unsigned int i = 0; i < scene->mNumAnimations; ++i) - { - fprintf(g_fp, "[%d]:\n", i); - ShowAnimationInfo(scene->mAnimations[i]); - } - } - - fclose(g_fp); - g_fp = NULL; -} - -void WalkNode(const aiNode *node) -{ - ++g_level; - fprintf(g_fp, "\n"); - - std::string indent = GetIndentString(); - - aiQuaternion rotation; - aiVector3D scaling; - aiVector3D position; - node->mTransformation.Decompose(scaling, rotation, position); - - fprintf(g_fp, "%sName: %s\n", indent.c_str(), node->mName.data); - fprintf(g_fp, "%smNumChildren: %d\n", indent.c_str(), node->mNumChildren); - fprintf(g_fp, "%smNumMeshes: %d", indent.c_str(), node->mNumMeshes); - if (node->mNumMeshes > 0) - { - fprintf(g_fp, " ["); - for (unsigned int i = 0; i < node->mNumMeshes; ++i) - { - if (i > 0) - fprintf(g_fp, ", "); - fprintf(g_fp, "%d", node->mMeshes[i]); - } - fprintf(g_fp, "]"); - } - fprintf(g_fp, "\n"); - fprintf(g_fp, "%smTransformation:\n", indent.c_str()); - fprintf(g_fp, "%s - Rotation: %f, %f, %f, %f\n", indent.c_str(), rotation.x, rotation.y, rotation.z, rotation.w); - fprintf(g_fp, "%s - Scaling: %f, %f, %f\n", indent.c_str(), scaling.x, scaling.y, scaling.z); - fprintf(g_fp, "%s - Position: %f, %f, %f\n", indent.c_str(), position.x, position.y, position.z); - - for (unsigned int i = 0; i < node->mNumChildren; ++i) - WalkNode(node->mChildren[i]); - - --g_level; -} - -void ShowMeshInfo(const aiMesh *mesh, const aiScene *scene) -{ - fprintf(g_fp, " Name: %s\n", mesh->mName.data); - fprintf(g_fp, " HasBones: %s\n", mesh->HasBones() ? "yes" : "no"); - fprintf(g_fp, " HasFaces: %s\n", mesh->HasFaces() ? "yes" : "no"); - fprintf(g_fp, " HasNormals: %s\n", mesh->HasNormals() ? "yes" : "no"); - fprintf(g_fp, " HasPositions: %s\n", mesh->HasPositions() ? "yes" : "no"); - fprintf(g_fp, " HasTangentsAndBitangents: %s\n", mesh->HasTangentsAndBitangents() ? "yes" : "no"); - fprintf(g_fp, " HasTextureCoords: %s, %s, %s, %s\n", - (mesh->HasTextureCoords(0) ? "yes" : "no"), - (mesh->HasTextureCoords(1) ? "yes" : "no"), - (mesh->HasTextureCoords(2) ? "yes" : "no"), - (mesh->HasTextureCoords(3) ? "yes" : "no") - ); - fprintf(g_fp, " HasVertexColors: %s, %s, %s, %s\n", - (mesh->HasVertexColors(0) ? "yes" : "no"), - (mesh->HasVertexColors(1) ? "yes" : "no"), - (mesh->HasVertexColors(2) ? "yes" : "no"), - (mesh->HasVertexColors(3) ? "yes" : "no") - ); - fprintf(g_fp, " mMaterialIndex: %d\n", mesh->mMaterialIndex); - fprintf(g_fp, " mNumFaces: %d\n", mesh->mNumFaces); - fprintf(g_fp, " mPrimitiveTypes: %d - (All Triangles? %s)\n", mesh->mPrimitiveTypes, mesh->mPrimitiveTypes == aiPrimitiveType_TRIANGLE ? "yes" : "no"); - fprintf(g_fp, " mNumVertices: %d\n", mesh->mNumVertices); - fprintf(g_fp, " mNumUVComponents: %d, %d, %d, %d\n", mesh->mNumUVComponents[0], mesh->mNumUVComponents[1], mesh->mNumUVComponents[2], mesh->mNumUVComponents[3]); - fprintf(g_fp, " mNumBones: %d\n", mesh->mNumBones); - fprintf(g_fp, " mNumAnimMeshes: %d\n", mesh->mNumAnimMeshes); - fprintf(g_fp, " mBones:\n"); - for (unsigned int i = 0; i < mesh->mNumBones; ++i) - { - aiBone *bone = mesh->mBones[i]; - - aiQuaternion rotation; - aiVector3D scaling; - aiVector3D position; - bone->mOffsetMatrix.Decompose(scaling, rotation, position); - - aiString parentName = "[null]"; - aiNode *boneNode = scene->mRootNode->FindNode(bone->mName); - if (boneNode != NULL) - { - aiNode *parent = boneNode->mParent; - if (parent != NULL) - parentName = parent->mName; - } - - fprintf(g_fp, " [%d]\n", i); - fprintf(g_fp, " Name: %s\n", bone->mName.data); - fprintf(g_fp, " Parent Name: %s\n", parentName.data); - fprintf(g_fp, " mNumWeights: %d\n", bone->mNumWeights); - fprintf(g_fp, " mOffsetMatrix:\n"); - fprintf(g_fp, " - Rotation: %f, %f, %f, %f\n", rotation.x, rotation.y, rotation.z, rotation.w); - fprintf(g_fp, " - Scaling: %f, %f, %f\n", scaling.x, scaling.y, scaling.z); - fprintf(g_fp, " - Position: %f, %f, %f\n", position.x, position.y, position.z); - } -} - -void ShowMaterialInfo(const aiMaterial *material) -{ - aiString name; - aiString textureFile; - aiColor3D ambient; - aiColor3D diffuse; - aiColor3D specular; - aiColor3D emissive; - float shininess; - float opacity; - - material->Get(AI_MATKEY_NAME, name); - material->Get(AI_MATKEY_COLOR_AMBIENT, ambient); - material->Get(AI_MATKEY_COLOR_DIFFUSE, diffuse); - material->Get(AI_MATKEY_COLOR_SPECULAR, specular); - material->Get(AI_MATKEY_COLOR_EMISSIVE, emissive); - material->Get(AI_MATKEY_SHININESS, shininess); - material->Get(AI_MATKEY_OPACITY, opacity); - - fprintf(g_fp, " Name: %s\n", name.data); - fprintf(g_fp, " Ambient: %f, %f, %f\n", ambient.r, ambient.g, ambient.b); - fprintf(g_fp, " Diffuse: %f, %f, %f\n", diffuse.r, diffuse.g, diffuse.b); - fprintf(g_fp, " Specular: %f, %f, %f\n", specular.r, specular.g, specular.b); - fprintf(g_fp, " Emissive: %f, %f, %f\n", emissive.r, emissive.g, emissive.b); - fprintf(g_fp, " Shininess: %f\n", shininess); - fprintf(g_fp, " Opacity: %f\n", opacity); - - ShowMaterialTextureInfo(material, aiTextureType_NONE, "aiTextureType_NONE"); - ShowMaterialTextureInfo(material, aiTextureType_DIFFUSE, "aiTextureType_DIFFUSE"); - ShowMaterialTextureInfo(material, aiTextureType_SPECULAR, "aiTextureType_SPECULAR"); - ShowMaterialTextureInfo(material, aiTextureType_AMBIENT, "aiTextureType_AMBIENT"); - ShowMaterialTextureInfo(material, aiTextureType_EMISSIVE, "aiTextureType_EMISSIVE"); - ShowMaterialTextureInfo(material, aiTextureType_HEIGHT, "aiTextureType_HEIGHT"); - ShowMaterialTextureInfo(material, aiTextureType_NORMALS, "aiTextureType_NORMALS"); - ShowMaterialTextureInfo(material, aiTextureType_SHININESS, "aiTextureType_SHININESS"); - ShowMaterialTextureInfo(material, aiTextureType_OPACITY, "aiTextureType_OPACITY"); - ShowMaterialTextureInfo(material, aiTextureType_DISPLACEMENT, "aiTextureType_DISPLACEMENT"); - ShowMaterialTextureInfo(material, aiTextureType_LIGHTMAP, "aiTextureType_LIGHTMAP"); - ShowMaterialTextureInfo(material, aiTextureType_REFLECTION, "aiTextureType_REFLECTION"); - ShowMaterialTextureInfo(material, aiTextureType_UNKNOWN, "aiTextureType_UNKNOWN"); -} - -void ShowMaterialTextureInfo(const aiMaterial *material, aiTextureType type, const std::string &typeText) -{ - aiString textureFile; - - unsigned int count = material->GetTextureCount(type); - if (count > 0) - { - fprintf(g_fp, " %s: %d\n", typeText.c_str(), count); - for (unsigned int i = 0; i < count; ++i) - { - material->Get(AI_MATKEY_TEXTURE(type, i), textureFile); - fprintf(g_fp, " %s\n", textureFile.data); - } - } -} - -void ShowAnimationInfo(const aiAnimation *animation) -{ - fprintf(g_fp, " Name: %s\n", animation->mName.data); - fprintf(g_fp, " mDuration: %f\n", animation->mDuration); - fprintf(g_fp, " mTicksPerSecond: %f\n", animation->mTicksPerSecond); - fprintf(g_fp, " mNumChannels: %d\n", animation->mNumChannels); - fprintf(g_fp, " mChannels:\n"); - for (unsigned int i = 0; i < animation->mNumChannels; ++i) - { - aiNodeAnim *channel = animation->mChannels[i]; - - fprintf(g_fp, " [%d]:\n", i); - fprintf(g_fp, " Name: %s\n", channel->mNodeName.data); - fprintf(g_fp, " mNumPositionKeys: %d\n", channel->mNumPositionKeys); - fprintf(g_fp, " mNumRotationKeys: %d\n", channel->mNumRotationKeys); - fprintf(g_fp, " mNumScalingKeys: %d\n", channel->mNumScalingKeys); - fprintf(g_fp, " mPositionKeys:\n"); - for (unsigned int i = 0; i < channel->mNumPositionKeys; ++i) - fprintf(g_fp, " [%d] %f, %f, %f\n", i, channel->mPositionKeys[i].mValue.x, channel->mPositionKeys[i].mValue.y, channel->mPositionKeys[i].mValue.z); - fprintf(g_fp, " mRotationKeys:\n"); - for (unsigned int i = 0; i < channel->mNumPositionKeys; ++i) - fprintf(g_fp, " [%d] %f, %f, %f\n", i, channel->mRotationKeys[i].mValue.x, channel->mRotationKeys[i].mValue.y, channel->mRotationKeys[i].mValue.z, channel->mRotationKeys[i].mValue.w); - fprintf(g_fp, " mScalingKeys:\n"); - for (unsigned int i = 0; i < channel->mNumScalingKeys; ++i) - fprintf(g_fp, " [%d] %f, %f, %f\n", i, channel->mScalingKeys[i].mValue.x, channel->mScalingKeys[i].mValue.y, channel->mScalingKeys[i].mValue.z); - } - fprintf(g_fp, " mNumMeshChannels: %d\n", animation->mNumMeshChannels); - fprintf(g_fp, " mMeshChannels:\n"); - for (unsigned int i = 0; i < animation->mNumMeshChannels; ++i) - { - aiMeshAnim *channel = animation->mMeshChannels[i]; - - fprintf(g_fp, " [%d]:\n", i); - fprintf(g_fp, " Name: %s\n", channel->mName.data); - fprintf(g_fp, " mNumKeys: %d\n", channel->mNumKeys); - } -} +#include "nodetree.h" + +#include +#include + +void WalkNode(const aiNode *node); +void ShowMeshInfo(const aiMesh *mesh, const aiScene *scene); +void ShowMaterialInfo(const aiMaterial *material); +void ShowMaterialTextureInfo(const aiMaterial *material, aiTextureType type, const std::string &typeText); +void ShowAnimationInfo(const aiAnimation *animation); + +unsigned int g_level; +FILE *g_fp = NULL; + +std::string GetIndentString() +{ + std::string indent; + for (unsigned int i = 0; i < g_level; ++i) + indent += " "; + return indent; +} + +void Walk(const aiScene *scene, const std::string &filename) +{ + g_level = 0; + + g_fp = fopen(filename.c_str(), "w"); + if (g_fp == NULL) + throw std::exception("Error creating description output file."); + + fprintf(g_fp, "\n*** GENERAL SCENE INFO ***\n\n"); + fprintf(g_fp, "HasAnimations: %s\n", scene->HasAnimations() ? "yes" : "no"); + fprintf(g_fp, "HasMaterials: %s\n", scene->HasMaterials() ? "yes" : "no"); + fprintf(g_fp, "HasMeshes: %s\n", scene->HasMeshes() ? "yes" : "no"); + fprintf(g_fp, "mNumAnimations: %d\n", scene->mNumAnimations); + fprintf(g_fp, "mNumMaterials: %d\n", scene->mNumMaterials); + fprintf(g_fp, "mNumMeshes: %d\n", scene->mNumMeshes); + fprintf(g_fp, "\n"); + + if (scene->mNumMaterials > 0) + { + fprintf(g_fp, "\n*** MATERIALS ***\n\n"); + + for (unsigned int i = 0; i < scene->mNumMaterials; ++i) + { + fprintf(g_fp, "[%d]:\n", i); + ShowMaterialInfo(scene->mMaterials[i]); + } + } + + fprintf(g_fp, "\n*** MESHES ***\n\n"); + + for (unsigned int i = 0; i < scene->mNumMeshes; ++i) + { + fprintf(g_fp, "[%d]\n", i); + ShowMeshInfo(scene->mMeshes[i], scene); + } + + fprintf(g_fp, "\n*** NODES ***\n"); + WalkNode(scene->mRootNode); + + if (scene->mNumAnimations > 0) + { + fprintf(g_fp, "\n*** ANIMATIONS ***\n\n"); + + for (unsigned int i = 0; i < scene->mNumAnimations; ++i) + { + fprintf(g_fp, "[%d]:\n", i); + ShowAnimationInfo(scene->mAnimations[i]); + } + } + + fclose(g_fp); + g_fp = NULL; +} + +void WalkNode(const aiNode *node) +{ + ++g_level; + fprintf(g_fp, "\n"); + + std::string indent = GetIndentString(); + + aiQuaternion rotation; + aiVector3D scaling; + aiVector3D position; + node->mTransformation.Decompose(scaling, rotation, position); + + fprintf(g_fp, "%sName: %s\n", indent.c_str(), node->mName.data); + fprintf(g_fp, "%smNumChildren: %d\n", indent.c_str(), node->mNumChildren); + fprintf(g_fp, "%smNumMeshes: %d", indent.c_str(), node->mNumMeshes); + if (node->mNumMeshes > 0) + { + fprintf(g_fp, " ["); + for (unsigned int i = 0; i < node->mNumMeshes; ++i) + { + if (i > 0) + fprintf(g_fp, ", "); + fprintf(g_fp, "%d", node->mMeshes[i]); + } + fprintf(g_fp, "]"); + } + fprintf(g_fp, "\n"); + fprintf(g_fp, "%smTransformation:\n", indent.c_str()); + fprintf(g_fp, "%s - Rotation: %f, %f, %f, %f\n", indent.c_str(), rotation.x, rotation.y, rotation.z, rotation.w); + fprintf(g_fp, "%s - Scaling: %f, %f, %f\n", indent.c_str(), scaling.x, scaling.y, scaling.z); + fprintf(g_fp, "%s - Position: %f, %f, %f\n", indent.c_str(), position.x, position.y, position.z); + + for (unsigned int i = 0; i < node->mNumChildren; ++i) + WalkNode(node->mChildren[i]); + + --g_level; +} + +void ShowMeshInfo(const aiMesh *mesh, const aiScene *scene) +{ + fprintf(g_fp, " Name: %s\n", mesh->mName.data); + fprintf(g_fp, " HasBones: %s\n", mesh->HasBones() ? "yes" : "no"); + fprintf(g_fp, " HasFaces: %s\n", mesh->HasFaces() ? "yes" : "no"); + fprintf(g_fp, " HasNormals: %s\n", mesh->HasNormals() ? "yes" : "no"); + fprintf(g_fp, " HasPositions: %s\n", mesh->HasPositions() ? "yes" : "no"); + fprintf(g_fp, " HasTangentsAndBitangents: %s\n", mesh->HasTangentsAndBitangents() ? "yes" : "no"); + fprintf(g_fp, " HasTextureCoords: %s, %s, %s, %s\n", + (mesh->HasTextureCoords(0) ? "yes" : "no"), + (mesh->HasTextureCoords(1) ? "yes" : "no"), + (mesh->HasTextureCoords(2) ? "yes" : "no"), + (mesh->HasTextureCoords(3) ? "yes" : "no") + ); + fprintf(g_fp, " HasVertexColors: %s, %s, %s, %s\n", + (mesh->HasVertexColors(0) ? "yes" : "no"), + (mesh->HasVertexColors(1) ? "yes" : "no"), + (mesh->HasVertexColors(2) ? "yes" : "no"), + (mesh->HasVertexColors(3) ? "yes" : "no") + ); + fprintf(g_fp, " mMaterialIndex: %d\n", mesh->mMaterialIndex); + fprintf(g_fp, " mNumFaces: %d\n", mesh->mNumFaces); + fprintf(g_fp, " mPrimitiveTypes: %d - (All Triangles? %s)\n", mesh->mPrimitiveTypes, mesh->mPrimitiveTypes == aiPrimitiveType_TRIANGLE ? "yes" : "no"); + fprintf(g_fp, " mNumVertices: %d\n", mesh->mNumVertices); + fprintf(g_fp, " mNumUVComponents: %d, %d, %d, %d\n", mesh->mNumUVComponents[0], mesh->mNumUVComponents[1], mesh->mNumUVComponents[2], mesh->mNumUVComponents[3]); + fprintf(g_fp, " mNumBones: %d\n", mesh->mNumBones); + fprintf(g_fp, " mNumAnimMeshes: %d\n", mesh->mNumAnimMeshes); + fprintf(g_fp, " mBones:\n"); + for (unsigned int i = 0; i < mesh->mNumBones; ++i) + { + aiBone *bone = mesh->mBones[i]; + + aiQuaternion rotation; + aiVector3D scaling; + aiVector3D position; + bone->mOffsetMatrix.Decompose(scaling, rotation, position); + + aiString parentName = "[null]"; + aiNode *boneNode = scene->mRootNode->FindNode(bone->mName); + if (boneNode != NULL) + { + aiNode *parent = boneNode->mParent; + if (parent != NULL) + parentName = parent->mName; + } + + fprintf(g_fp, " [%d]\n", i); + fprintf(g_fp, " Name: %s\n", bone->mName.data); + fprintf(g_fp, " Parent Name: %s\n", parentName.data); + fprintf(g_fp, " mNumWeights: %d\n", bone->mNumWeights); + fprintf(g_fp, " mOffsetMatrix:\n"); + fprintf(g_fp, " - Rotation: %f, %f, %f, %f\n", rotation.x, rotation.y, rotation.z, rotation.w); + fprintf(g_fp, " - Scaling: %f, %f, %f\n", scaling.x, scaling.y, scaling.z); + fprintf(g_fp, " - Position: %f, %f, %f\n", position.x, position.y, position.z); + } +} + +void ShowMaterialInfo(const aiMaterial *material) +{ + aiString name; + aiString textureFile; + aiColor3D ambient; + aiColor3D diffuse; + aiColor3D specular; + aiColor3D emissive; + float shininess; + float opacity; + + material->Get(AI_MATKEY_NAME, name); + material->Get(AI_MATKEY_COLOR_AMBIENT, ambient); + material->Get(AI_MATKEY_COLOR_DIFFUSE, diffuse); + material->Get(AI_MATKEY_COLOR_SPECULAR, specular); + material->Get(AI_MATKEY_COLOR_EMISSIVE, emissive); + material->Get(AI_MATKEY_SHININESS, shininess); + material->Get(AI_MATKEY_OPACITY, opacity); + + fprintf(g_fp, " Name: %s\n", name.data); + fprintf(g_fp, " Ambient: %f, %f, %f\n", ambient.r, ambient.g, ambient.b); + fprintf(g_fp, " Diffuse: %f, %f, %f\n", diffuse.r, diffuse.g, diffuse.b); + fprintf(g_fp, " Specular: %f, %f, %f\n", specular.r, specular.g, specular.b); + fprintf(g_fp, " Emissive: %f, %f, %f\n", emissive.r, emissive.g, emissive.b); + fprintf(g_fp, " Shininess: %f\n", shininess); + fprintf(g_fp, " Opacity: %f\n", opacity); + + ShowMaterialTextureInfo(material, aiTextureType_NONE, "aiTextureType_NONE"); + ShowMaterialTextureInfo(material, aiTextureType_DIFFUSE, "aiTextureType_DIFFUSE"); + ShowMaterialTextureInfo(material, aiTextureType_SPECULAR, "aiTextureType_SPECULAR"); + ShowMaterialTextureInfo(material, aiTextureType_AMBIENT, "aiTextureType_AMBIENT"); + ShowMaterialTextureInfo(material, aiTextureType_EMISSIVE, "aiTextureType_EMISSIVE"); + ShowMaterialTextureInfo(material, aiTextureType_HEIGHT, "aiTextureType_HEIGHT"); + ShowMaterialTextureInfo(material, aiTextureType_NORMALS, "aiTextureType_NORMALS"); + ShowMaterialTextureInfo(material, aiTextureType_SHININESS, "aiTextureType_SHININESS"); + ShowMaterialTextureInfo(material, aiTextureType_OPACITY, "aiTextureType_OPACITY"); + ShowMaterialTextureInfo(material, aiTextureType_DISPLACEMENT, "aiTextureType_DISPLACEMENT"); + ShowMaterialTextureInfo(material, aiTextureType_LIGHTMAP, "aiTextureType_LIGHTMAP"); + ShowMaterialTextureInfo(material, aiTextureType_REFLECTION, "aiTextureType_REFLECTION"); + ShowMaterialTextureInfo(material, aiTextureType_UNKNOWN, "aiTextureType_UNKNOWN"); +} + +void ShowMaterialTextureInfo(const aiMaterial *material, aiTextureType type, const std::string &typeText) +{ + aiString textureFile; + + unsigned int count = material->GetTextureCount(type); + if (count > 0) + { + fprintf(g_fp, " %s: %d\n", typeText.c_str(), count); + for (unsigned int i = 0; i < count; ++i) + { + material->Get(AI_MATKEY_TEXTURE(type, i), textureFile); + fprintf(g_fp, " %s\n", textureFile.data); + } + } +} + +void ShowAnimationInfo(const aiAnimation *animation) +{ + fprintf(g_fp, " Name: %s\n", animation->mName.data); + fprintf(g_fp, " mDuration: %f\n", animation->mDuration); + fprintf(g_fp, " mTicksPerSecond: %f\n", animation->mTicksPerSecond); + fprintf(g_fp, " mNumChannels: %d\n", animation->mNumChannels); + fprintf(g_fp, " mChannels:\n"); + for (unsigned int i = 0; i < animation->mNumChannels; ++i) + { + aiNodeAnim *channel = animation->mChannels[i]; + + fprintf(g_fp, " [%d]:\n", i); + fprintf(g_fp, " Name: %s\n", channel->mNodeName.data); + fprintf(g_fp, " mNumPositionKeys: %d\n", channel->mNumPositionKeys); + fprintf(g_fp, " mNumRotationKeys: %d\n", channel->mNumRotationKeys); + fprintf(g_fp, " mNumScalingKeys: %d\n", channel->mNumScalingKeys); + fprintf(g_fp, " mPositionKeys:\n"); + for (unsigned int i = 0; i < channel->mNumPositionKeys; ++i) + fprintf(g_fp, " [%d] %f, %f, %f\n", i, channel->mPositionKeys[i].mValue.x, channel->mPositionKeys[i].mValue.y, channel->mPositionKeys[i].mValue.z); + fprintf(g_fp, " mRotationKeys:\n"); + for (unsigned int i = 0; i < channel->mNumPositionKeys; ++i) + fprintf(g_fp, " [%d] %f, %f, %f\n", i, channel->mRotationKeys[i].mValue.x, channel->mRotationKeys[i].mValue.y, channel->mRotationKeys[i].mValue.z, channel->mRotationKeys[i].mValue.w); + fprintf(g_fp, " mScalingKeys:\n"); + for (unsigned int i = 0; i < channel->mNumScalingKeys; ++i) + fprintf(g_fp, " [%d] %f, %f, %f\n", i, channel->mScalingKeys[i].mValue.x, channel->mScalingKeys[i].mValue.y, channel->mScalingKeys[i].mValue.z); + } + fprintf(g_fp, " mNumMeshChannels: %d\n", animation->mNumMeshChannels); + fprintf(g_fp, " mMeshChannels:\n"); + for (unsigned int i = 0; i < animation->mNumMeshChannels; ++i) + { + aiMeshAnim *channel = animation->mMeshChannels[i]; + + fprintf(g_fp, " [%d]:\n", i); + fprintf(g_fp, " Name: %s\n", channel->mName.data); + fprintf(g_fp, " mNumKeys: %d\n", channel->mNumKeys); + } +} diff --git a/AssimpToMesh/src/nodetree/nodetree.h b/AssimpToMesh/src/nodetree/nodetree.h index ead3301..aa08a6c 100644 --- a/AssimpToMesh/src/nodetree/nodetree.h +++ b/AssimpToMesh/src/nodetree/nodetree.h @@ -1,9 +1,9 @@ -#ifndef __NODETREE_NODETREE_H_INCLUDED__ -#define __NODETREE_NODETREE_H_INCLUDED__ - -#include -#include - -void Walk(const aiScene *scene, const std::string &filename); - -#endif +#ifndef __NODETREE_NODETREE_H_INCLUDED__ +#define __NODETREE_NODETREE_H_INCLUDED__ + +#include +#include + +void Walk(const aiScene *scene, const std::string &filename); + +#endif diff --git a/AssimpToMesh/src/utils/fileutils.cpp b/AssimpToMesh/src/utils/fileutils.cpp index f397ab4..dcc6457 100644 --- a/AssimpToMesh/src/utils/fileutils.cpp +++ b/AssimpToMesh/src/utils/fileutils.cpp @@ -1,18 +1,18 @@ -#include "utils.h" - -#include - -std::string GetMeshFilenameFromInput(const std::string &filename) -{ - std::string meshFilename = ""; - - // strip off the existing extension, and replace it with ".mesh" - size_t extStart = filename.find_last_of('.'); - if (extStart != std::string::npos) - { - meshFilename = filename.substr(0, extStart); - meshFilename += ".mesh"; - } - - return meshFilename; -} +#include "utils.h" + +#include + +std::string GetMeshFilenameFromInput(const std::string &filename) +{ + std::string meshFilename = ""; + + // strip off the existing extension, and replace it with ".mesh" + size_t extStart = filename.find_last_of('.'); + if (extStart != std::string::npos) + { + meshFilename = filename.substr(0, extStart); + meshFilename += ".mesh"; + } + + return meshFilename; +} diff --git a/AssimpToMesh/src/utils/utils.h b/AssimpToMesh/src/utils/utils.h index 3b3bc06..84413ab 100644 --- a/AssimpToMesh/src/utils/utils.h +++ b/AssimpToMesh/src/utils/utils.h @@ -1,8 +1,8 @@ -#ifndef __UTILS_UTILS_H_INCLUDED__ -#define __UTILS_UTILS_H_INCLUDED__ - -#include - -std::string GetMeshFilenameFromInput(const std::string &filename); - -#endif +#ifndef __UTILS_UTILS_H_INCLUDED__ +#define __UTILS_UTILS_H_INCLUDED__ + +#include + +std::string GetMeshFilenameFromInput(const std::string &filename); + +#endif