diff --git a/code/ColladaHelper.h b/code/ColladaHelper.h index f249a28d5..200e9f8fc 100644 --- a/code/ColladaHelper.h +++ b/code/ColladaHelper.h @@ -502,6 +502,8 @@ struct Effect // Scalar factory float mShininess, mRefractIndex, mReflectivity; float mTransparency; + bool mHasTransparency; + bool mRGBTransparency; // local params referring to each other by their SID typedef std::map ParamLibrary; @@ -522,7 +524,9 @@ struct Effect , mShininess (10.0f) , mRefractIndex (1.f) , mReflectivity (1.f) - , mTransparency (0.f) + , mTransparency (1.f) + , mHasTransparency (false) + , mRGBTransparency(false) , mDoubleSided (false) , mWireframe (false) , mFaceted (false) diff --git a/code/ColladaLoader.cpp b/code/ColladaLoader.cpp index aa4826fc9..d42293490 100644 --- a/code/ColladaLoader.cpp +++ b/code/ColladaLoader.cpp @@ -109,6 +109,7 @@ void ColladaLoader::SetupProperties(const Importer* pImp) { noSkeletonMesh = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_NO_SKELETON_MESHES,0) != 0; ignoreUpDirection = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_COLLADA_IGNORE_UP_DIRECTION,0) != 0; + invertTransparency = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_COLLADA_INVERT_TRANSPARENCY,0) != 0; } @@ -1289,11 +1290,25 @@ void ColladaLoader::FillMaterials( const ColladaParser& pParser, aiScene* /*pSce mat.AddProperty( &effect.mRefractIndex, 1, AI_MATKEY_REFRACTI); // transparency, a very hard one. seemingly not all files are following the - // specification here .. but we can trick. - if (effect.mTransparency >= 0.f && effect.mTransparency < 1.f) { - effect.mTransparency = 1.f- effect.mTransparency; - mat.AddProperty( &effect.mTransparency, 1, AI_MATKEY_OPACITY ); - mat.AddProperty( &effect.mTransparent, 1, AI_MATKEY_COLOR_TRANSPARENT ); + // specification here (1.0 transparency => completly opaque)... + // therefore, we let the opportunity for the user to manually invert + // the transparency if necessary and we add preliminary support for RGB_ZERO mode + if(effect.mTransparency >= 0.f && effect.mTransparency <= 1.f) { + // Trying some support for RGB_ZERO mode + if(effect.mRGBTransparency) { + effect.mTransparency = 1.f - effect.mTransparent.a; + } + + // Global option + if(invertTransparency) { + effect.mTransparency = 1.f - effect.mTransparency; + } + + // Is the material finally transparent ? + if (effect.mHasTransparency || effect.mTransparency < 1.f) { + mat.AddProperty( &effect.mTransparency, 1, AI_MATKEY_OPACITY ); + mat.AddProperty( &effect.mTransparent, 1, AI_MATKEY_COLOR_TRANSPARENT ); + } } // add textures, if given diff --git a/code/ColladaLoader.h b/code/ColladaLoader.h index 392c8f359..46e6c8710 100644 --- a/code/ColladaLoader.h +++ b/code/ColladaLoader.h @@ -235,6 +235,7 @@ protected: bool noSkeletonMesh; bool ignoreUpDirection; + bool invertTransparency; /** Used by FindNameForNode() to generate unique node names */ unsigned int mNodeNameCounter; diff --git a/code/ColladaParser.cpp b/code/ColladaParser.cpp index fb7cd298a..bb2bc1777 100644 --- a/code/ColladaParser.cpp +++ b/code/ColladaParser.cpp @@ -1199,6 +1199,14 @@ void ColladaParser::ReadEffectProfileCommon( Collada::Effect& pEffect) ReadEffectColor( pEffect.mReflective, pEffect.mTexReflective); } else if( IsElement( "transparent")) { + pEffect.mHasTransparency = true; + + // In RGB_ZERO mode, the transparency is interpreted in reverse, go figure... + if(::strcmp(mReader->getAttributeValueSafe("opaque"), "RGB_ZERO") == 0) { + // TODO: handle RGB_ZERO mode completely + pEffect.mRGBTransparency = true; + } + ReadEffectColor( pEffect.mTransparent,pEffect.mTexTransparent); } else if( IsElement( "shininess")) diff --git a/include/assimp/config.h b/include/assimp/config.h index 56ef8f3b5..8b70fd653 100644 --- a/include/assimp/config.h +++ b/include/assimp/config.h @@ -878,4 +878,6 @@ enum aiComponent #define AI_CONFIG_IMPORT_COLLADA_IGNORE_UP_DIRECTION "IMPORT_COLLADA_IGNORE_UP_DIRECTION" +#define AI_CONFIG_IMPORT_COLLADA_INVERT_TRANSPARENCY "IMPORT_COLLADA_INVERT_TRANSPARENCY" + #endif // !! AI_CONFIG_H_INC