diff --git a/code/AssimpCExport.cpp b/code/AssimpCExport.cpp index 9483eb2d3..053e1b9f4 100644 --- a/code/AssimpCExport.cpp +++ b/code/AssimpCExport.cpp @@ -73,6 +73,7 @@ ASSIMP_API void aiCopyScene(const aiScene* pIn, aiScene** pOut) } SceneCombiner::CopyScene(pOut,pIn,true); + ScenePriv(*pOut)->mIsCopy = true; } diff --git a/code/Exporter.cpp b/code/Exporter.cpp index 3a2a5ec95..306ed824a 100644 --- a/code/Exporter.cpp +++ b/code/Exporter.cpp @@ -289,15 +289,16 @@ aiReturn Exporter :: Export( const aiScene* pScene, const char* pFormatId, const const unsigned int nonIdempotentSteps = aiProcess_FlipWindingOrder | aiProcess_FlipUVs | aiProcess_MakeLeftHanded; // Erase all pp steps that were already applied to this scene - unsigned int pp = (exp.mEnforcePP | pPreprocessing) & ~(priv + const unsigned int pp = (exp.mEnforcePP | pPreprocessing) & ~(priv && !priv->mIsCopy ? (priv->mPPStepsApplied & ~nonIdempotentSteps) : 0u); // If no extra postprocessing was specified, and we obtained this scene from an // Assimp importer, apply the reverse steps automatically. - if (!pPreprocessing && priv) { - pp |= (nonIdempotentSteps & priv->mPPStepsApplied); - } + // TODO: either drop this, or document it. Otherwise it is just a bad surprise. + //if (!pPreprocessing && priv) { + // pp |= (nonIdempotentSteps & priv->mPPStepsApplied); + //} // If the input scene is not in verbose format, but there is at least postprocessing step that relies on it, // we need to run the MakeVerboseFormat step first. diff --git a/code/ScenePrivate.h b/code/ScenePrivate.h index dc11bb4fa..8e9fde7ac 100644 --- a/code/ScenePrivate.h +++ b/code/ScenePrivate.h @@ -53,6 +53,7 @@ struct ScenePrivateData { ScenePrivateData() : mOrigImporter() , mPPStepsApplied() + , mIsCopy() {} // Importer that originally loaded the scene though the C-API @@ -61,6 +62,13 @@ struct ScenePrivateData { // List of postprocessing steps already applied to the scene. unsigned int mPPStepsApplied; + + // true if the scene is a copy made with aiCopyScene() + // or the corresponding C++ API. This means that user code + // may have made modifications to it, so mPPStepsApplied + // and mOrigImporter are no longer safe to rely on and only + // serve informative purposes. + bool mIsCopy; }; // Access private data stored in the scene diff --git a/include/assimp/Exporter.hpp b/include/assimp/Exporter.hpp index 1a993db48..b9318ae29 100644 --- a/include/assimp/Exporter.hpp +++ b/include/assimp/Exporter.hpp @@ -198,7 +198,13 @@ public: * redundant as exporters would apply them anyhow. A good example * is triangulation - whilst you can enforce it by specifying * the #aiProcess_Triangulate flag, most export formats support only - * triangulate data so they would run the step even if it wasn't requested. + * triangulate data so they would run the step even if it wasn't requested. + * + * If assimp detects that the input scene was directly taken from the importer side of + * the library (i.e. not copied using aiCopyScene and potetially modified afterwards), + * any postprocessing steps already applied to the scene will not be applied again, unless + * they show non-idempotent behaviour (#aiProcess_MakeLeftHanded, #aiProcess_FlipUVs and + * #aiProcess_FlipWindingOrder). * @return AI_SUCCESS if everything was fine. * @note Use aiCopyScene() to get a modifiable copy of a previously * imported scene.*/ diff --git a/include/assimp/cexport.h b/include/assimp/cexport.h index 797d5db1a..5916c2da9 100644 --- a/include/assimp/cexport.h +++ b/include/assimp/cexport.h @@ -143,6 +143,12 @@ ASSIMP_API void aiFreeScene(const C_STRUCT aiScene* pIn); * is triangulation - whilst you can enforce it by specifying * the #aiProcess_Triangulate flag, most export formats support only * triangulate data so they would run the step anyway. +* +* If assimp detects that the input scene was directly taken from the importer side of +* the library (i.e. not copied using aiCopyScene and potetially modified afterwards), +* any postprocessing steps already applied to the scene will not be applied again, unless +* they show non-idempotent behaviour (#aiProcess_MakeLeftHanded, #aiProcess_FlipUVs and +* #aiProcess_FlipWindingOrder). * @return a status code indicating the result of the export * @note Use aiCopyScene() to get a modifiable copy of a previously * imported scene.