Selaa lähdekoodia

Validate mesh in WriteMesh before AttributeBegin call (#5884)

If mesh is validated after AttributeBegin call, then
the AttributeBegin is never closed with an
AttributeEnd, causing problems in pbrt.

Co-authored-by: Kim Kulling <[email protected]>
Elijah Nicol 9 kuukautta sitten
vanhempi
commit
bddc374b5a
1 muutettua tiedostoa jossa 12 lisäystä ja 10 poistoa
  1. 12 10
      code/Pbrt/PbrtExporter.cpp

+ 12 - 10
code/Pbrt/PbrtExporter.cpp

@@ -800,10 +800,20 @@ void PbrtExporter::WriteLights() {
 
 
 void PbrtExporter::WriteMesh(aiMesh* mesh) {
 void PbrtExporter::WriteMesh(aiMesh* mesh) {
     mOutput << "# - Mesh: ";
     mOutput << "# - Mesh: ";
+    const char* mName;
     if (mesh->mName == aiString(""))
     if (mesh->mName == aiString(""))
-        mOutput << "<No Name>\n";
+        mName = "<No Name>";
     else
     else
-        mOutput << mesh->mName.C_Str() << "\n";
+        mName = mesh->mName.C_Str();
+    mOutput << mName << "\n";
+
+    // Check if any types other than tri
+    if (   (mesh->mPrimitiveTypes & aiPrimitiveType_POINT)
+           || (mesh->mPrimitiveTypes & aiPrimitiveType_LINE)
+           || (mesh->mPrimitiveTypes & aiPrimitiveType_POLYGON)) {
+        std::cerr << "Error: ignoring point / line / polygon mesh " << mName << ".\n";
+        return;
+    }
 
 
     mOutput << "AttributeBegin\n";
     mOutput << "AttributeBegin\n";
     aiMaterial* material = mScene->mMaterials[mesh->mMaterialIndex];
     aiMaterial* material = mScene->mMaterials[mesh->mMaterialIndex];
@@ -816,14 +826,6 @@ void PbrtExporter::WriteMesh(aiMesh* mesh) {
         mOutput << "    AreaLightSource \"diffuse\" \"rgb L\" [ " << emission.r <<
         mOutput << "    AreaLightSource \"diffuse\" \"rgb L\" [ " << emission.r <<
             " " << emission.g << " " << emission.b << " ]\n";
             " " << emission.g << " " << emission.b << " ]\n";
 
 
-    // Check if any types other than tri
-    if (   (mesh->mPrimitiveTypes & aiPrimitiveType_POINT)
-        || (mesh->mPrimitiveTypes & aiPrimitiveType_LINE)
-        || (mesh->mPrimitiveTypes & aiPrimitiveType_POLYGON)) {
-        std::cerr << "Error: ignoring point / line / polygon mesh " << mesh->mName.C_Str() << ".\n";
-        return;
-    }
-
     // Alpha mask
     // Alpha mask
     std::string alpha;
     std::string alpha;
     aiString opacityTexture;
     aiString opacityTexture;