From edc7a950c4a19f04b2c1e3de4eb74aa6f274d484 Mon Sep 17 00:00:00 2001 From: Madrich Date: Wed, 11 Jun 2014 00:41:18 +0200 Subject: [PATCH] ReFix the stuff before Fix XFileExporter Normal Fix Collada (Triangle->Poly) --- code/ColladaExporter.cpp | 39 ++++--------------------- code/ConvertToLHProcess.cpp | 10 ------- code/Exporter.cpp | 17 ++++++----- code/ObjExporter.cpp | 2 +- code/PlyExporter.cpp | 2 +- code/STLExporter.cpp | 4 +-- code/XFileExporter.cpp | 58 +++++++++++++++++-------------------- code/XFileExporter.h | 6 ++-- include/assimp/Exporter.hpp | 2 +- 9 files changed, 49 insertions(+), 91 deletions(-) diff --git a/code/ColladaExporter.cpp b/code/ColladaExporter.cpp index 3a1c096bf..e4099b365 100644 --- a/code/ColladaExporter.cpp +++ b/code/ColladaExporter.cpp @@ -58,7 +58,7 @@ namespace Assimp // ------------------------------------------------------------------------------------------------ // Worker function for exporting a scene to Collada. Prototyped and registered in Exporter.cpp -void ExportSceneCollada(const char* pFile,IOSystem* pIOSystem, aiScene* pScene) +void ExportSceneCollada(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene) { std::string path = ""; std::string file = pFile; @@ -634,13 +634,11 @@ void ColladaExporter::WriteGeometry( size_t pIndex) // count the number of lines, triangles and polygon meshes int countLines = 0; - int countTriangles = 0; int countPoly = 0; for( size_t a = 0; a < mesh->mNumFaces; ++a ) { if (mesh->mFaces[a].mNumIndices == 2) countLines++; - else if (mesh->mFaces[a].mNumIndices == 3) countTriangles++; - else if (mesh->mFaces[a].mNumIndices > 3) countPoly++; + else if (mesh->mFaces[a].mNumIndices >= 3) countPoly++; } // lines @@ -662,34 +660,7 @@ void ColladaExporter::WriteGeometry( size_t pIndex) mOutput << startstr << "" << endstr; } - // triangles, note for collada, triangles are defined in a right hand system - if (countTriangles) - { - mOutput << startstr << "" << endstr; - PushTag(); - mOutput << startstr << "" << endstr; - mOutput << startstr << "" << endstr; - mOutput << startstr << "

"; - for( size_t a = 0; a < mesh->mNumFaces; ++a ) - { - const aiFace& face = mesh->mFaces[a]; - if (face.mNumIndices != 3) continue; - // write vertix indices - for( size_t b = 0; b < face.mNumIndices; ++b ) - { - mOutput << face.mIndices[b] << " "; - } - // write normal indices - for( size_t b = 0; b < face.mNumIndices; ++b ) - { - mOutput << face.mIndices[b] << " "; - } - - } - mOutput << "

" << endstr; - PopTag(); - mOutput << startstr << "
" << endstr; - } + // triangle - dont use it, because compatibility problems // polygons if (countPoly) @@ -701,7 +672,7 @@ void ColladaExporter::WriteGeometry( size_t pIndex) mOutput << startstr << ""; for( size_t a = 0; a < mesh->mNumFaces; ++a ) { - if (mesh->mFaces[a].mNumIndices <= 3) continue; + if (mesh->mFaces[a].mNumIndices < 3) continue; mOutput << mesh->mFaces[a].mNumIndices << " "; } mOutput << "" << endstr; @@ -710,7 +681,7 @@ void ColladaExporter::WriteGeometry( size_t pIndex) for( size_t a = 0; a < mesh->mNumFaces; ++a ) { const aiFace& face = mesh->mFaces[a]; - if (face.mNumIndices <= 3) continue; + if (face.mNumIndices < 3) continue; for( size_t b = 0; b < face.mNumIndices; ++b ) mOutput << face.mIndices[b] << " "; } diff --git a/code/ConvertToLHProcess.cpp b/code/ConvertToLHProcess.cpp index 17e157c45..3a51daf57 100644 --- a/code/ConvertToLHProcess.cpp +++ b/code/ConvertToLHProcess.cpp @@ -140,16 +140,6 @@ void MakeLeftHandedProcess::ProcessMesh( aiMesh* pMesh) pMesh->mTangents[a].z *= -1.0f; pMesh->mBitangents[a].z *= -1.0f; } - - // texture coords for all channels - for (unsigned int c = 0; c < pMesh->GetNumUVChannels(); c++) - { - if (pMesh->HasTextureCoords(c)) - { - pMesh->mTextureCoords[c][a].y = 1.0f - pMesh->mTextureCoords[c][a].y; - } - } - } // mirror offset matrices of all bones diff --git a/code/Exporter.cpp b/code/Exporter.cpp index 37c36fb8c..a53639fac 100644 --- a/code/Exporter.cpp +++ b/code/Exporter.cpp @@ -72,13 +72,13 @@ void GetPostProcessingStepInstanceList(std::vector< BaseProcess* >& out); // ------------------------------------------------------------------------------------------------ // Exporter worker function prototypes. Should not be necessary to #ifndef them, it's just a prototype // do not use const, because some exporter need to convert the scene temporary -void ExportSceneCollada(const char*,IOSystem*, aiScene*); -void ExportSceneXFile(const char*,IOSystem*, aiScene*); -void ExportSceneObj(const char*,IOSystem*, aiScene*); -void ExportSceneSTL(const char*,IOSystem*, aiScene*); -void ExportSceneSTLBinary(const char*,IOSystem*, aiScene*); -void ExportScenePly(const char*,IOSystem*, aiScene*); -void ExportScene3DS(const char*, IOSystem*, aiScene*) {} +void ExportSceneCollada(const char*,IOSystem*, const aiScene*); +void ExportSceneXFile(const char*,IOSystem*, const aiScene*); +void ExportSceneObj(const char*,IOSystem*, const aiScene*); +void ExportSceneSTL(const char*,IOSystem*, const aiScene*); +void ExportSceneSTLBinary(const char*,IOSystem*, const aiScene*); +void ExportScenePly(const char*,IOSystem*, const aiScene*); +void ExportScene3DS(const char*, IOSystem*, const aiScene*) {} // ------------------------------------------------------------------------------------------------ // global array of all export formats which Assimp supports in its current build @@ -89,7 +89,8 @@ Exporter::ExportFormatEntry gExporters[] = #endif #ifndef ASSIMP_BUILD_NO_OBJ_EXPORTER - Exporter::ExportFormatEntry( "x", "X Files", "x", &ExportSceneXFile), + Exporter::ExportFormatEntry( "x", "X Files", "x", &ExportSceneXFile, + aiProcess_MakeLeftHanded | aiProcess_FlipWindingOrder | aiProcess_FlipUVs), #endif #ifndef ASSIMP_BUILD_NO_OBJ_EXPORTER diff --git a/code/ObjExporter.cpp b/code/ObjExporter.cpp index 25bcfc9c5..ff9fa4b25 100644 --- a/code/ObjExporter.cpp +++ b/code/ObjExporter.cpp @@ -51,7 +51,7 @@ namespace Assimp { // ------------------------------------------------------------------------------------------------ // Worker function for exporting a scene to Wavefront OBJ. Prototyped and registered in Exporter.cpp -void ExportSceneObj(const char* pFile,IOSystem* pIOSystem, aiScene* pScene) +void ExportSceneObj(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene) { // invoke the exporter ObjExporter exporter(pFile, pScene); diff --git a/code/PlyExporter.cpp b/code/PlyExporter.cpp index bd04dfcb3..e78cfd964 100644 --- a/code/PlyExporter.cpp +++ b/code/PlyExporter.cpp @@ -50,7 +50,7 @@ namespace Assimp { // ------------------------------------------------------------------------------------------------ // Worker function for exporting a scene to PLY. Prototyped and registered in Exporter.cpp -void ExportScenePly(const char* pFile,IOSystem* pIOSystem, aiScene* pScene) +void ExportScenePly(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene) { // invoke the exporter PlyExporter exporter(pFile, pScene); diff --git a/code/STLExporter.cpp b/code/STLExporter.cpp index d1765f446..e3df2fbff 100644 --- a/code/STLExporter.cpp +++ b/code/STLExporter.cpp @@ -50,7 +50,7 @@ namespace Assimp { // ------------------------------------------------------------------------------------------------ // Worker function for exporting a scene to Stereolithograpy. Prototyped and registered in Exporter.cpp -void ExportSceneSTL(const char* pFile,IOSystem* pIOSystem, aiScene* pScene) +void ExportSceneSTL(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene) { // invoke the exporter STLExporter exporter(pFile, pScene); @@ -63,7 +63,7 @@ void ExportSceneSTL(const char* pFile,IOSystem* pIOSystem, aiScene* pScene) outfile->Write( exporter.mOutput.str().c_str(), static_cast(exporter.mOutput.tellp()),1); } -void ExportSceneSTLBinary(const char* pFile,IOSystem* pIOSystem, aiScene* pScene) +void ExportSceneSTLBinary(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene) { // invoke the exporter STLExporter exporter(pFile, pScene, true); diff --git a/code/XFileExporter.cpp b/code/XFileExporter.cpp index e56dc3ce4..e06382bcb 100644 --- a/code/XFileExporter.cpp +++ b/code/XFileExporter.cpp @@ -59,7 +59,7 @@ namespace Assimp // ------------------------------------------------------------------------------------------------ // Worker function for exporting a scene to Collada. Prototyped and registered in Exporter.cpp -void ExportSceneXFile(const char* pFile,IOSystem* pIOSystem, aiScene* pScene) +void ExportSceneXFile(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene) { std::string path = ""; std::string file = pFile; @@ -96,7 +96,7 @@ void ExportSceneXFile(const char* pFile,IOSystem* pIOSystem, aiScene* pScene) // ------------------------------------------------------------------------------------------------ // Constructor for a specific scene to export -XFileExporter::XFileExporter(aiScene* pScene, IOSystem* pIOSystem, const std::string& path, const std::string& file) : mIOSystem(pIOSystem), mPath(path), mFile(file) +XFileExporter::XFileExporter(const aiScene* pScene, IOSystem* pIOSystem, const std::string& path, const std::string& file) : mIOSystem(pIOSystem), mPath(path), mFile(file) { // make sure that all formatting happens using the standard, C locale and not the user's current locale mOutput.imbue( std::locale("C") ); @@ -128,13 +128,6 @@ void XFileExporter::WriteFile() mOutput.setf(_IOSfixed); mOutput.precision(6); // precission for float - // the scene is already in OpenGL, applying MakeLeftHandedProcess, makes it xFile left handed - MakeLeftHandedProcess convertProcess; - FlipWindingOrderProcess flipper; - - convertProcess.Execute(mScene); - flipper.Execute(mScene); - // entry of writing the file WriteHeader(); @@ -149,9 +142,6 @@ void XFileExporter::WriteFile() mOutput << startstr << "}" << endstr; - // and back to OpenGL right handed - convertProcess.Execute(mScene); - flipper.Execute(mScene); } // ------------------------------------------------------------------------------------------------ @@ -289,10 +279,10 @@ void XFileExporter::WriteFrameTransform(aiMatrix4x4& m) { mOutput << startstr << "FrameTransformMatrix {" << endstr << " "; PushTag(); - mOutput << startstr << m.a1 << "," << m.b1 << "," << m.c1 << "," << m.d1 << "," << endstr; - mOutput << startstr << m.a2 << "," << m.b2 << "," << m.c2 << "," << m.d2 << "," << endstr; - mOutput << startstr << m.a3 << "," << m.b3 << "," << m.c3 << "," << m.d3 << "," << endstr; - mOutput << startstr << m.a4 << "," << m.b4 << "," << m.c4 << "," << m.d4 << ";;" << endstr; + mOutput << startstr << m.a1 << ", " << m.b1 << ", " << m.c1 << ", " << m.d1 << "," << endstr; + mOutput << startstr << m.a2 << ", " << m.b2 << ", " << m.c2 << ", " << m.d2 << "," << endstr; + mOutput << startstr << m.a3 << ", " << m.b3 << ", " << m.c3 << ", " << m.d3 << "," << endstr; + mOutput << startstr << m.a4 << ", " << m.b4 << ", " << m.c4 << ", " << m.d4 << ";;" << endstr; PopTag(); mOutput << startstr << "}" << endstr << endstr; } @@ -300,10 +290,15 @@ void XFileExporter::WriteFrameTransform(aiMatrix4x4& m) // ------------------------------------------------------------------------------------------------ // Recursively writes the given node -void XFileExporter::WriteNode( const aiNode* pNode) +void XFileExporter::WriteNode( aiNode* pNode) { - - mOutput << startstr << "Frame " << pNode->mName.C_Str() << " {" << " // " << pNode->mName.C_Str() << endstr; + if (pNode->mName.length==0) + { + std::stringstream ss; + ss << "Node_" << pNode; + pNode->mName.Set(ss.str()); + } + mOutput << startstr << "Frame " << pNode->mName.C_Str() << " {" << endstr; PushTag(); @@ -330,7 +325,7 @@ void XFileExporter::WriteMesh(const aiMesh* mesh) PushTag(); // write all the vertices - mOutput << startstr << mesh->mNumVertices << ";" << endstr; + mOutput << startstr << mesh->mNumVertices << ";" << endstr; for (size_t a = 0; a < mesh->mNumVertices; a++) { aiVector3D &v = mesh->mVertices[a]; @@ -377,11 +372,12 @@ void XFileExporter::WriteMesh(const aiMesh* mesh) PushTag(); mOutput << startstr << "1;" << endstr; // number of materials mOutput << startstr << mesh->mNumFaces << ";" << endstr; // number of faces + mOutput << startstr; for( size_t a = 0; a < mesh->mNumFaces; ++a ) { - mOutput << startstr << a; + mOutput << "0"; // the material index if (a < mesh->mNumFaces - 1) - mOutput << "," << endstr; + mOutput << ", "; else mOutput << ";" << endstr; } @@ -403,15 +399,15 @@ void XFileExporter::WriteMesh(const aiMesh* mesh) } // write normals (every vertex has one) - mOutput << endstr; if (mesh->HasNormals()) { - mOutput << startstr << "MeshNormals {" << endstr; + mOutput << endstr << startstr << "MeshNormals {" << endstr; mOutput << startstr << mesh->mNumVertices << ";" << endstr; for (size_t a = 0; a < mesh->mNumVertices; a++) { aiVector3D &v = mesh->mNormals[a]; - mOutput << startstr << v[0] << ";"<< v[1] << ";" << v[2] << ";"; + // because we have a LHS and also changed wth winding, we need to invert the normals again + mOutput << startstr << -v[0] << ";"<< -v[1] << ";" << -v[2] << ";"; if (a < mesh->mNumVertices - 1) mOutput << "," << endstr; else @@ -446,7 +442,7 @@ void XFileExporter::WriteMesh(const aiMesh* mesh) // write texture UVs if available if (mesh->HasTextureCoords(0)) { - mOutput << startstr << "MeshTextureCoords {" << endstr; + mOutput << endstr << startstr << "MeshTextureCoords {" << endstr; mOutput << startstr << mesh->mNumVertices << ";" << endstr; for (size_t a = 0; a < mesh->mNumVertices; a++) //for (int a = (int)mesh->mNumVertices-1; a >=0 ; a--) @@ -465,7 +461,7 @@ void XFileExporter::WriteMesh(const aiMesh* mesh) // write color channel if available if (mesh->HasVertexColors(0)) { - mOutput << startstr << "MeshVertexColors {" << endstr; + mOutput << endstr << startstr << "MeshVertexColors {" << endstr; mOutput << startstr << mesh->mNumVertices << ";" << endstr; for (size_t a = 0; a < mesh->mNumVertices; a++) { @@ -478,15 +474,15 @@ void XFileExporter::WriteMesh(const aiMesh* mesh) } mOutput << startstr << "}" << endstr; } - // test ... + /* else { - mOutput << startstr << "MeshVertexColors {" << endstr; + mOutput << endstr << startstr << "MeshVertexColors {" << endstr; mOutput << startstr << mesh->mNumVertices << ";" << endstr; for (size_t a = 0; a < mesh->mNumVertices; a++) { aiColor4D* mColors = mesh->mColors[a]; - mOutput << startstr << a << ";0.500000;0.000000;0.000000;0.000000;;"; + mOutput << startstr << a << ";0.500000;0.000000;0.000000;0.500000;;"; if (a < mesh->mNumVertices-1) mOutput << "," << endstr; else @@ -494,7 +490,7 @@ void XFileExporter::WriteMesh(const aiMesh* mesh) } mOutput << startstr << "}" << endstr; } - + */ PopTag(); mOutput << startstr << "}" << endstr << endstr; diff --git a/code/XFileExporter.h b/code/XFileExporter.h index 5e4877c48..fa4e6d38e 100644 --- a/code/XFileExporter.h +++ b/code/XFileExporter.h @@ -61,7 +61,7 @@ class XFileExporter { public: /// Constructor for a specific scene to export - XFileExporter(aiScene* pScene, IOSystem* pIOSystem, const std::string& path, const std::string& file); + XFileExporter(const aiScene* pScene, IOSystem* pIOSystem, const std::string& path, const std::string& file); /// Destructor virtual ~XFileExporter(); @@ -77,7 +77,7 @@ protected: void WriteFrameTransform(aiMatrix4x4& m); /// Recursively writes the given node - void WriteNode( const aiNode* pNode); + void WriteNode( aiNode* pNode ); /// write a mesh entry of the scene void WriteMesh(const aiMesh* mesh); @@ -107,7 +107,7 @@ protected: const std::string mFile; /// The scene to be written - aiScene* mScene; + const aiScene* mScene; bool mSceneOwned; /// current line start string, contains the current indentation for simple stream insertion diff --git a/include/assimp/Exporter.hpp b/include/assimp/Exporter.hpp index 2c9a2e2af..a879a33c8 100644 --- a/include/assimp/Exporter.hpp +++ b/include/assimp/Exporter.hpp @@ -81,7 +81,7 @@ class ASSIMP_API Exporter public: /** Function pointer type of a Export worker function */ - typedef void (*fpExportFunc)(const char*,IOSystem*, aiScene*); + typedef void (*fpExportFunc)(const char*,IOSystem*, const aiScene*); /** Internal description of an Assimp export format option */ struct ExportFormatEntry