From 5d3f3281f451f50d4ec7f8ad7c910e66020f354c Mon Sep 17 00:00:00 2001 From: Tomas Maly Date: Tue, 27 Jun 2023 12:40:27 +0200 Subject: [PATCH 1/2] fix incorrect default for material::get with aiColor3D --- include/assimp/material.inl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/assimp/material.inl b/include/assimp/material.inl index 744743bc7..b7222f9c7 100644 --- a/include/assimp/material.inl +++ b/include/assimp/material.inl @@ -211,7 +211,8 @@ AI_FORCE_INLINE aiReturn aiMaterial::Get(const char* pKey,unsigned int type, unsigned int idx,aiColor3D& pOut) const { aiColor4D c; const aiReturn ret = aiGetMaterialColor(this,pKey,type,idx,&c); - pOut = aiColor3D(c.r,c.g,c.b); + if (ret == aiReturn_SUCCESS) + pOut = aiColor3D(c.r,c.g,c.b); return ret; } // --------------------------------------------------------------------------- From bb1873dd221da14729fab9bb7301c329fc6610bf Mon Sep 17 00:00:00 2001 From: Martin Weber Date: Fri, 4 Aug 2023 09:54:55 +0200 Subject: [PATCH 2/2] Collada: added import property to disable unit size scaling --- code/AssetLib/Collada/ColladaLoader.cpp | 17 +++++++++++------ code/AssetLib/Collada/ColladaLoader.h | 1 + include/assimp/config.h.in | 9 +++++++++ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/code/AssetLib/Collada/ColladaLoader.cpp b/code/AssetLib/Collada/ColladaLoader.cpp index f3750ceab..e1f19a5ed 100644 --- a/code/AssetLib/Collada/ColladaLoader.cpp +++ b/code/AssetLib/Collada/ColladaLoader.cpp @@ -95,6 +95,7 @@ ColladaLoader::ColladaLoader() : noSkeletonMesh(false), removeEmptyBones(false), ignoreUpDirection(false), + ignoreUnitSize(false), useColladaName(false), mNodeNameCounter(0) { // empty @@ -122,6 +123,7 @@ void ColladaLoader::SetupProperties(const Importer *pImp) { noSkeletonMesh = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_NO_SKELETON_MESHES, 0) != 0; removeEmptyBones = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_REMOVE_EMPTY_BONES, true) != 0; ignoreUpDirection = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_COLLADA_IGNORE_UP_DIRECTION, 0) != 0; + ignoreUnitSize = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_COLLADA_IGNORE_UNIT_SIZE, 0) != 0; useColladaName = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_COLLADA_USE_COLLADA_NAMES, 0) != 0; } @@ -170,12 +172,15 @@ void ColladaLoader::InternReadFile(const std::string &pFile, aiScene *pScene, IO // ... then fill the materials with the now adjusted settings FillMaterials(parser, pScene); - // Apply unit-size scale calculation - - pScene->mRootNode->mTransformation *= aiMatrix4x4(parser.mUnitSize, 0, 0, 0, - 0, parser.mUnitSize, 0, 0, - 0, 0, parser.mUnitSize, 0, - 0, 0, 0, 1); + if (!ignoreUnitSize) { + // Apply unit-size scale calculation + pScene->mRootNode->mTransformation *= aiMatrix4x4( + parser.mUnitSize, 0, 0, 0, + 0, parser.mUnitSize, 0, 0, + 0, 0, parser.mUnitSize, 0, + 0, 0, 0, 1); + } + if (!ignoreUpDirection) { // Convert to Y_UP, if different orientation if (parser.mUpDirection == ColladaParser::UP_X) { diff --git a/code/AssetLib/Collada/ColladaLoader.h b/code/AssetLib/Collada/ColladaLoader.h index 870c12a5a..74b5c06b7 100644 --- a/code/AssetLib/Collada/ColladaLoader.h +++ b/code/AssetLib/Collada/ColladaLoader.h @@ -239,6 +239,7 @@ protected: bool noSkeletonMesh; bool removeEmptyBones; bool ignoreUpDirection; + bool ignoreUnitSize; bool useColladaName; /** Used by FindNameForNode() to generate unique node names */ diff --git a/include/assimp/config.h.in b/include/assimp/config.h.in index 9e843a20d..97551e602 100644 --- a/include/assimp/config.h.in +++ b/include/assimp/config.h.in @@ -1035,6 +1035,15 @@ enum aiComponent */ #define AI_CONFIG_IMPORT_COLLADA_IGNORE_UP_DIRECTION "IMPORT_COLLADA_IGNORE_UP_DIRECTION" +// --------------------------------------------------------------------------- +/** @brief Specifies whether the Collada loader will ignore the provided unit size. + * + * If this property is set to true, the unit size provided in the file header will + * be ignored and the file will be loaded without scaling the assets. + * Property type: Bool. Default value: false. + */ +#define AI_CONFIG_IMPORT_COLLADA_IGNORE_UNIT_SIZE "IMPORT_COLLADA_IGNORE_UNIT_SIZE" + // --------------------------------------------------------------------------- /** @brief Specifies whether the Collada loader should use Collada names. *