From 632b2db97c57d2147bf6e8393ba8e35d2b2f4bad Mon Sep 17 00:00:00 2001 From: RichardTea <31507749+RichardTea@users.noreply.github.com> Date: Wed, 14 Jul 2021 13:39:41 +0100 Subject: [PATCH] Ensure glTFv2 scene name is unique Use the provided scene name if extant Fixes issue #3978 --- code/AssetLib/glTF2/glTF2Exporter.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/code/AssetLib/glTF2/glTF2Exporter.cpp b/code/AssetLib/glTF2/glTF2Exporter.cpp index 02c3233f3..47780606f 100644 --- a/code/AssetLib/glTF2/glTF2Exporter.cpp +++ b/code/AssetLib/glTF2/glTF2Exporter.cpp @@ -88,15 +88,13 @@ namespace Assimp { } // end of namespace Assimp glTF2Exporter::glTF2Exporter(const char* filename, IOSystem* pIOSystem, const aiScene* pScene, - const ExportProperties* pProperties, bool isBinary) + const ExportProperties* pProperties, bool isBinary) : mFilename(filename) , mIOSystem(pIOSystem) + , mScene(pScene) , mProperties(pProperties) + , mAsset(new Asset(pIOSystem)) { - mScene = pScene; - - mAsset.reset( new Asset( pIOSystem ) ); - // Always on as our triangulation process is aware of this type of encoding mAsset->extensionsUsed.FB_ngon_encoding = true; @@ -1338,8 +1336,11 @@ unsigned int glTF2Exporter::ExportNode(const aiNode* n, Ref& parent) void glTF2Exporter::ExportScene() { - const char* sceneName = "defaultScene"; - Ref scene = mAsset->scenes.Create(sceneName); + // Use the name of the scene if specified + const std::string sceneName = (mScene->mName.length > 0) ? mScene->mName.C_Str() : "defaultScene"; + + // Ensure unique + Ref scene = mAsset->scenes.Create(mAsset->FindUniqueID(sceneName, "")); // root node will be the first one exported (idx 0) if (mAsset->nodes.Size() > 0) {