Selaa lähdekoodia

add material reference to faces.

Kim Kulling 7 vuotta sitten
vanhempi
commit
336a09ee0e
3 muutettua tiedostoa jossa 24 lisäystä ja 13 poistoa
  1. 17 9
      code/ConvertToLHProcess.cpp
  2. 6 3
      code/D3MFExporter.cpp
  3. 1 1
      code/D3MFExporter.h

+ 17 - 9
code/ConvertToLHProcess.cpp

@@ -91,12 +91,14 @@ void MakeLeftHandedProcess::Execute( aiScene* pScene)
     ProcessNode( pScene->mRootNode, aiMatrix4x4());
     ProcessNode( pScene->mRootNode, aiMatrix4x4());
 
 
     // process the meshes accordingly
     // process the meshes accordingly
-    for( unsigned int a = 0; a < pScene->mNumMeshes; ++a)
-        ProcessMesh( pScene->mMeshes[a]);
+    for ( unsigned int a = 0; a < pScene->mNumMeshes; ++a ) {
+        ProcessMesh( pScene->mMeshes[ a ] );
+    }
 
 
     // process the materials accordingly
     // process the materials accordingly
-    for( unsigned int a = 0; a < pScene->mNumMaterials; ++a)
-        ProcessMaterial( pScene->mMaterials[a]);
+    for ( unsigned int a = 0; a < pScene->mNumMaterials; ++a ) {
+        ProcessMaterial( pScene->mMaterials[ a ] );
+    }
 
 
     // transform all animation channels as well
     // transform all animation channels as well
     for( unsigned int a = 0; a < pScene->mNumAnimations; a++)
     for( unsigned int a = 0; a < pScene->mNumAnimations; a++)
@@ -136,8 +138,11 @@ void MakeLeftHandedProcess::ProcessNode( aiNode* pNode, const aiMatrix4x4& pPare
 
 
 // ------------------------------------------------------------------------------------------------
 // ------------------------------------------------------------------------------------------------
 // Converts a single mesh to left handed coordinates.
 // Converts a single mesh to left handed coordinates.
-void MakeLeftHandedProcess::ProcessMesh( aiMesh* pMesh)
-{
+void MakeLeftHandedProcess::ProcessMesh( aiMesh* pMesh) {
+    if ( nullptr == pMesh ) {
+        DefaultLogger::get()->error( "Nullptr to mesh found." );
+        return;
+    }
     // mirror positions, normals and stuff along the Z axis
     // mirror positions, normals and stuff along the Z axis
     for( size_t a = 0; a < pMesh->mNumVertices; ++a)
     for( size_t a = 0; a < pMesh->mNumVertices; ++a)
     {
     {
@@ -173,8 +178,12 @@ void MakeLeftHandedProcess::ProcessMesh( aiMesh* pMesh)
 
 
 // ------------------------------------------------------------------------------------------------
 // ------------------------------------------------------------------------------------------------
 // Converts a single material to left handed coordinates.
 // Converts a single material to left handed coordinates.
-void MakeLeftHandedProcess::ProcessMaterial( aiMaterial* _mat)
-{
+void MakeLeftHandedProcess::ProcessMaterial( aiMaterial* _mat) {
+    if ( nullptr == _mat ) {
+        DefaultLogger::get()->error( "Nullptr to aiMaterial found." );
+        return;
+    }
+
     aiMaterial* mat = (aiMaterial*)_mat;
     aiMaterial* mat = (aiMaterial*)_mat;
     for (unsigned int a = 0; a < mat->mNumProperties;++a)   {
     for (unsigned int a = 0; a < mat->mNumProperties;++a)   {
         aiMaterialProperty* prop = mat->mProperties[a];
         aiMaterialProperty* prop = mat->mProperties[a];
@@ -183,7 +192,6 @@ void MakeLeftHandedProcess::ProcessMaterial( aiMaterial* _mat)
         if (!::strcmp( prop->mKey.data, "$tex.mapaxis"))    {
         if (!::strcmp( prop->mKey.data, "$tex.mapaxis"))    {
             ai_assert( prop->mDataLength >= sizeof(aiVector3D)); /* something is wrong with the validation if we end up here */
             ai_assert( prop->mDataLength >= sizeof(aiVector3D)); /* something is wrong with the validation if we end up here */
             aiVector3D* pff = (aiVector3D*)prop->mData;
             aiVector3D* pff = (aiVector3D*)prop->mData;
-
             pff->z *= -1.f;
             pff->z *= -1.f;
         }
         }
     }
     }

+ 6 - 3
code/D3MFExporter.cpp

@@ -285,7 +285,9 @@ void D3MFExporter::writeMesh( aiMesh *mesh ) {
     }
     }
     mModelOutput << "</" << XmlTag::vertices << ">" << std::endl;
     mModelOutput << "</" << XmlTag::vertices << ">" << std::endl;
 
 
-    writeFaces( mesh );
+    const unsigned int matIdx( mesh->mMaterialIndex );
+
+    writeFaces( mesh, matIdx );
 
 
     mModelOutput << "</" << XmlTag::mesh << ">" << std::endl;
     mModelOutput << "</" << XmlTag::mesh << ">" << std::endl;
 }
 }
@@ -295,7 +297,7 @@ void D3MFExporter::writeVertex( const aiVector3D &pos ) {
     mModelOutput << std::endl;
     mModelOutput << std::endl;
 }
 }
 
 
-void D3MFExporter::writeFaces( aiMesh *mesh ) {
+void D3MFExporter::writeFaces( aiMesh *mesh, unsigned int matIdx ) {
     if ( nullptr == mesh ) {
     if ( nullptr == mesh ) {
         return;
         return;
     }
     }
@@ -307,7 +309,8 @@ void D3MFExporter::writeFaces( aiMesh *mesh ) {
     for ( unsigned int i = 0; i < mesh->mNumFaces; ++i ) {
     for ( unsigned int i = 0; i < mesh->mNumFaces; ++i ) {
         aiFace &currentFace = mesh->mFaces[ i ];
         aiFace &currentFace = mesh->mFaces[ i ];
         mModelOutput << "<" << XmlTag::triangle << " v1=\"" << currentFace.mIndices[ 0 ] << "\" v2=\""
         mModelOutput << "<" << XmlTag::triangle << " v1=\"" << currentFace.mIndices[ 0 ] << "\" v2=\""
-                << currentFace.mIndices[ 1 ] << "\" v3=\"" << currentFace.mIndices[ 2 ] << "\"/>";
+                << currentFace.mIndices[ 1 ] << "\" v3=\"" << currentFace.mIndices[ 2 ]
+                << "\" pid=\"1\" p1=\""+to_string(matIdx)+"\" />";
         mModelOutput << std::endl;
         mModelOutput << std::endl;
     }
     }
     mModelOutput << "</" << XmlTag::triangles << ">";
     mModelOutput << "</" << XmlTag::triangles << ">";

+ 1 - 1
code/D3MFExporter.h

@@ -80,7 +80,7 @@ protected:
     void writeObjects();
     void writeObjects();
     void writeMesh( aiMesh *mesh );
     void writeMesh( aiMesh *mesh );
     void writeVertex( const aiVector3D &pos );
     void writeVertex( const aiVector3D &pos );
-    void writeFaces( aiMesh *mesh );
+    void writeFaces( aiMesh *mesh, unsigned int matIdx );
     void writeBuild();
     void writeBuild();
     void exportContentTyp( const std::string &filename );
     void exportContentTyp( const std::string &filename );
     void writeModelToArchive( const std::string &folder, const std::string &modelName );
     void writeModelToArchive( const std::string &folder, const std::string &modelName );