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 <kimkulling@users.noreply.github.com>
This commit is contained in:
Elijah Nicol
2024-12-05 21:10:46 +11:00
committed by GitHub
parent 164a5ae8cf
commit bddc374b5a

View File

@@ -800,10 +800,20 @@ void PbrtExporter::WriteLights() {
void PbrtExporter::WriteMesh(aiMesh* mesh) {
mOutput << "# - Mesh: ";
const char* mName;
if (mesh->mName == aiString(""))
mOutput << "<No Name>\n";
mName = "<No Name>";
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";
aiMaterial* material = mScene->mMaterials[mesh->mMaterialIndex];
@@ -816,14 +826,6 @@ void PbrtExporter::WriteMesh(aiMesh* mesh) {
mOutput << " AreaLightSource \"diffuse\" \"rgb L\" [ " << emission.r <<
" " << 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
std::string alpha;
aiString opacityTexture;