added simple "scene walking" which outputs various info about the scene. added a command line option to enable this before the scene conversion happens
This commit is contained in:
parent
11939f9033
commit
22d7c53fb7
|
@ -84,11 +84,13 @@
|
||||||
<ClCompile Include="src\convert\skeletalanimated.cpp" />
|
<ClCompile Include="src\convert\skeletalanimated.cpp" />
|
||||||
<ClCompile Include="src\convert\static.cpp" />
|
<ClCompile Include="src\convert\static.cpp" />
|
||||||
<ClCompile Include="src\main.cpp" />
|
<ClCompile Include="src\main.cpp" />
|
||||||
|
<ClCompile Include="src\nodetree\nodetree.cpp" />
|
||||||
<ClCompile Include="src\utils\fileutils.cpp" />
|
<ClCompile Include="src\utils\fileutils.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="src\assimputils\utils.h" />
|
<ClInclude Include="src\assimputils\utils.h" />
|
||||||
<ClInclude Include="src\convert\convert.h" />
|
<ClInclude Include="src\convert\convert.h" />
|
||||||
|
<ClInclude Include="src\nodetree\nodetree.h" />
|
||||||
<ClInclude Include="src\utils\utils.h" />
|
<ClInclude Include="src\utils\utils.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
|
|
@ -30,6 +30,9 @@
|
||||||
<ClCompile Include="src\convert\skeletalanimated.cpp">
|
<ClCompile Include="src\convert\skeletalanimated.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="src\nodetree\nodetree.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="src\utils\utils.h">
|
<ClInclude Include="src\utils\utils.h">
|
||||||
|
@ -41,5 +44,8 @@
|
||||||
<ClInclude Include="src\convert\convert.h">
|
<ClInclude Include="src\convert\convert.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="src\nodetree\nodetree.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
|
@ -9,6 +9,7 @@
|
||||||
#include "utils/utils.h"
|
#include "utils/utils.h"
|
||||||
#include "assimputils/utils.h"
|
#include "assimputils/utils.h"
|
||||||
#include "convert/convert.h"
|
#include "convert/convert.h"
|
||||||
|
#include "nodetree/nodetree.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
@ -16,22 +17,23 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
if (argc == 1)
|
if (argc == 1)
|
||||||
{
|
{
|
||||||
printf("Usage: assimptomesh.exe [inputfile]\n\n");
|
printf("Usage: assimptomesh.exe [--showinfo] inputfile\n\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string file = argv[1];
|
// input file is always the last argument
|
||||||
std::string outputFile = GetMeshFilenameFromInput(file);
|
std::string file = argv[argc - 1];
|
||||||
|
bool showInfo = false;
|
||||||
|
|
||||||
if (outputFile.length() == 0)
|
// find any options
|
||||||
|
for (int i = 1; i < argc - 1; ++i)
|
||||||
{
|
{
|
||||||
printf("Unable to determine output mesh filename from the input file name.\n\n");
|
if (strcmp(argv[i], "--showinfo") == 0)
|
||||||
return 1;
|
showInfo = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// attempt to load the input file
|
||||||
printf("Input file: %s\n", file.c_str());
|
printf("Input file: %s\n", file.c_str());
|
||||||
printf("Output file: %s\n", outputFile.c_str());
|
|
||||||
|
|
||||||
Assimp::Importer importer;
|
Assimp::Importer importer;
|
||||||
const aiScene *scene = importer.ReadFile(file,
|
const aiScene *scene = importer.ReadFile(file,
|
||||||
aiProcess_JoinIdenticalVertices |
|
aiProcess_JoinIdenticalVertices |
|
||||||
|
@ -47,9 +49,22 @@ int main(int argc, char *argv[])
|
||||||
printf("Failed to load input file: %s\n\n", importer.GetErrorString());
|
printf("Failed to load input file: %s\n\n", importer.GetErrorString());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Scene loaded.\n");
|
printf("Scene loaded.\n");
|
||||||
|
|
||||||
|
// input file loaded, now get the output filename
|
||||||
|
std::string 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 (showInfo)
|
||||||
|
Walk(scene);
|
||||||
|
|
||||||
|
// attempt conversion using an appropriate converter based on what kind of scene it is
|
||||||
if (IsSceneStatic(scene))
|
if (IsSceneStatic(scene))
|
||||||
{
|
{
|
||||||
printf("Using static converter.\n");
|
printf("Using static converter.\n");
|
||||||
|
|
213
AssimpToMesh/src/nodetree/nodetree.cpp
Normal file
213
AssimpToMesh/src/nodetree/nodetree.cpp
Normal file
|
@ -0,0 +1,213 @@
|
||||||
|
#include "nodetree.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
void WalkNode(const aiNode *node);
|
||||||
|
void ShowMeshInfo(const aiMesh *mesh, const aiScene *scene);
|
||||||
|
void ShowMaterialInfo(const aiMaterial *material);
|
||||||
|
void ShowAnimationInfo(const aiAnimation *animation);
|
||||||
|
|
||||||
|
unsigned int g_level;
|
||||||
|
|
||||||
|
std::string GetIndentString()
|
||||||
|
{
|
||||||
|
std::string indent;
|
||||||
|
for (unsigned int i = 0; i < g_level; ++i)
|
||||||
|
indent += " ";
|
||||||
|
return indent;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Walk(const aiScene *scene)
|
||||||
|
{
|
||||||
|
g_level = 0;
|
||||||
|
|
||||||
|
printf("\n*** GENERAL SCENE INFO ***\n\n");
|
||||||
|
printf("HasAnimations: %s\n", scene->HasAnimations() ? "yes" : "no");
|
||||||
|
printf("HasMaterials: %s\n", scene->HasMaterials() ? "yes" : "no");
|
||||||
|
printf("HasMeshes: %s\n", scene->HasMeshes() ? "yes" : "no");
|
||||||
|
printf("mNumAnimations: %d\n", scene->mNumAnimations);
|
||||||
|
printf("mNumMaterials: %d\n", scene->mNumMaterials);
|
||||||
|
printf("mNumMeshes: %d\n", scene->mNumMeshes);
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
if (scene->mNumMaterials > 0)
|
||||||
|
{
|
||||||
|
printf("\n*** MATERIALS ***\n\n");
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < scene->mNumMaterials; ++i)
|
||||||
|
{
|
||||||
|
printf("[%d]:\n", i);
|
||||||
|
ShowMaterialInfo(scene->mMaterials[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\n*** MESHES ***\n\n");
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < scene->mNumMeshes; ++i)
|
||||||
|
{
|
||||||
|
printf("[%d]\n", i);
|
||||||
|
ShowMeshInfo(scene->mMeshes[i], scene);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\n*** NODES ***\n");
|
||||||
|
WalkNode(scene->mRootNode);
|
||||||
|
|
||||||
|
if (scene->mNumAnimations > 0)
|
||||||
|
{
|
||||||
|
printf("\n*** ANIMATIONS ***\n\n");
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < scene->mNumAnimations; ++i)
|
||||||
|
{
|
||||||
|
printf("[%d]:\n", i);
|
||||||
|
ShowAnimationInfo(scene->mAnimations[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void WalkNode(const aiNode *node)
|
||||||
|
{
|
||||||
|
++g_level;
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
std::string indent = GetIndentString();
|
||||||
|
|
||||||
|
aiQuaternion rotation;
|
||||||
|
aiVector3D scaling;
|
||||||
|
aiVector3D position;
|
||||||
|
node->mTransformation.Decompose(scaling, rotation, position);
|
||||||
|
|
||||||
|
printf("%sName: %s\n", indent.c_str(), node->mName.data);
|
||||||
|
printf("%smNumChildren: %d\n", indent.c_str(), node->mNumChildren);
|
||||||
|
printf("%smNumMeshes: %d", indent.c_str(), node->mNumMeshes);
|
||||||
|
if (node->mNumMeshes > 0)
|
||||||
|
{
|
||||||
|
printf(" [");
|
||||||
|
for (unsigned int i = 0; i < node->mNumMeshes; ++i)
|
||||||
|
{
|
||||||
|
if (i > 0)
|
||||||
|
printf(", ");
|
||||||
|
printf("%d", node->mMeshes[i]);
|
||||||
|
}
|
||||||
|
printf("]");
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
printf("%sRotation: %f, %f, %f, %f\n", indent.c_str(), rotation.x, rotation.y, rotation.z, rotation.w);
|
||||||
|
printf("%sScaling: %f, %f, %f\n", indent.c_str(), scaling.x, scaling.y, scaling.z);
|
||||||
|
printf("%sPosition: %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)
|
||||||
|
{
|
||||||
|
printf(" Name: %s\n", mesh->mName.data);
|
||||||
|
printf(" HasBones: %s\n", mesh->HasBones() ? "yes" : "no");
|
||||||
|
printf(" HasFaces: %s\n", mesh->HasFaces() ? "yes" : "no");
|
||||||
|
printf(" HasNormals: %s\n", mesh->HasNormals() ? "yes" : "no");
|
||||||
|
printf(" HasPositions: %s\n", mesh->HasPositions() ? "yes" : "no");
|
||||||
|
printf(" HasTangentsAndBitangents: %s\n", mesh->HasTangentsAndBitangents() ? "yes" : "no");
|
||||||
|
printf(" 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")
|
||||||
|
);
|
||||||
|
printf(" 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")
|
||||||
|
);
|
||||||
|
printf(" mMaterialIndex: %d\n", mesh->mMaterialIndex);
|
||||||
|
printf(" mNumFaces: %d\n", mesh->mNumFaces);
|
||||||
|
printf(" mPrimitiveTypes: %d - (All Triangles? %s)\n", mesh->mPrimitiveTypes, mesh->mPrimitiveTypes == aiPrimitiveType_TRIANGLE ? "yes" : "no");
|
||||||
|
printf(" mNumVertices: %d\n", mesh->mNumVertices);
|
||||||
|
printf(" mNumUVComponents: %d, %d, %d, %d\n", mesh->mNumUVComponents[0], mesh->mNumUVComponents[1], mesh->mNumUVComponents[2], mesh->mNumUVComponents[3]);
|
||||||
|
printf(" mNumBones: %d\n", mesh->mNumBones);
|
||||||
|
printf(" mNumAnimMeshes: %d\n", mesh->mNumAnimMeshes);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf(" [%d]\n", i);
|
||||||
|
printf(" Name: %s\n", bone->mName.data);
|
||||||
|
printf(" Parent Name: %s\n", parentName.data);
|
||||||
|
printf(" mNumWeights: %d\n", bone->mNumWeights);
|
||||||
|
printf(" Rotation: %f, %f, %f, %f\n", rotation.x, rotation.y, rotation.z, rotation.w);
|
||||||
|
printf(" Scaling: %f, %f, %f\n", scaling.x, scaling.y, scaling.z);
|
||||||
|
printf(" Position: %f, %f, %f\n", position.x, position.y, position.z);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShowMaterialInfo(const aiMaterial *material)
|
||||||
|
{
|
||||||
|
aiString name;
|
||||||
|
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);
|
||||||
|
|
||||||
|
printf(" Name: %s\n", name.data);
|
||||||
|
printf(" Ambient: %f, %f, %f\n", ambient.r, ambient.g, ambient.b);
|
||||||
|
printf(" Diffuse: %f, %f, %f\n", diffuse.r, diffuse.g, diffuse.b);
|
||||||
|
printf(" Specular: %f, %f, %f\n", specular.r, specular.g, specular.b);
|
||||||
|
printf(" Emissive: %f, %f, %f\n", emissive.r, emissive.g, emissive.b);
|
||||||
|
printf(" Shininess: %f\n", shininess);
|
||||||
|
printf(" Opacity: %f\n", opacity);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShowAnimationInfo(const aiAnimation *animation)
|
||||||
|
{
|
||||||
|
printf(" Name: %s\n", animation->mName.data);
|
||||||
|
printf(" mDuration: %f\n", animation->mDuration);
|
||||||
|
printf(" mTicksPerSecond: %f\n", animation->mTicksPerSecond);
|
||||||
|
printf(" mNumChannels: %d\n", animation->mNumChannels);
|
||||||
|
for (unsigned int i = 0; i < animation->mNumChannels; ++i)
|
||||||
|
{
|
||||||
|
aiNodeAnim *channel = animation->mChannels[i];
|
||||||
|
|
||||||
|
printf(" [%d]:\n", i);
|
||||||
|
printf(" Name: %s\n", channel->mNodeName.data);
|
||||||
|
printf(" mNumPositionKeys: %d\n", channel->mNumPositionKeys);
|
||||||
|
printf(" mNumRotationKeys: %d\n", channel->mNumRotationKeys);
|
||||||
|
printf(" mNumScalingKeys: %d\n", channel->mNumScalingKeys);
|
||||||
|
}
|
||||||
|
printf(" mNumMeshChannels: %d\n", animation->mNumMeshChannels);
|
||||||
|
for (unsigned int i = 0; i < animation->mNumMeshChannels; ++i)
|
||||||
|
{
|
||||||
|
aiMeshAnim *channel = animation->mMeshChannels[i];
|
||||||
|
|
||||||
|
printf(" [%d]:\n", i);
|
||||||
|
printf(" Name: %s\n", channel->mName.data);
|
||||||
|
printf(" mNumKeys: %d\n", channel->mNumKeys);
|
||||||
|
}
|
||||||
|
}
|
8
AssimpToMesh/src/nodetree/nodetree.h
Normal file
8
AssimpToMesh/src/nodetree/nodetree.h
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#ifndef __NODETREE_NODETREE_H_INCLUDED__
|
||||||
|
#define __NODETREE_NODETREE_H_INCLUDED__
|
||||||
|
|
||||||
|
#include <aiScene.h>
|
||||||
|
|
||||||
|
void Walk(const aiScene *scene);
|
||||||
|
|
||||||
|
#endif
|
Reference in a new issue