diff --git a/src/osgPlugins/fbx/fbxRMesh.cpp b/src/osgPlugins/fbx/fbxRMesh.cpp index 60205a032..209dc5366 100644 --- a/src/osgPlugins/fbx/fbxRMesh.cpp +++ b/src/osgPlugins/fbx/fbxRMesh.cpp @@ -1,6 +1,7 @@ #include #include +#include #include #include #include @@ -163,11 +164,26 @@ osg::Geometry* getGeometry(osg::Geode* pGeode, GeometryMap& geometryMap, if (mti < stateSetList.size()) { + bool transparent = false; const StateSetContent& ss = stateSetList[mti]; - if(ss.first) - pGeometry->getOrCreateStateSet()->setAttributeAndModes(ss.first); - if(ss.second) - pGeometry->getOrCreateStateSet()->setTextureAttributeAndModes(0, ss.second); + if (osg::Material* pMaterial = ss.first) + { + pGeometry->getOrCreateStateSet()->setAttributeAndModes(pMaterial); + transparent = pMaterial->getDiffuse(osg::Material::FRONT).w() < 1.0f; + } + if (osg::Texture2D* pTexture = ss.second) + { + pGeometry->getOrCreateStateSet()->setTextureAttributeAndModes(0, pTexture); + if (!transparent && pTexture->getImage()) + { + transparent = pTexture->getImage()->isImageTranslucent(); + } + } + + if (transparent) + { + pGeometry->getOrCreateStateSet()->setAttributeAndModes(new osg::BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); + } } geometryMap.insert(std::pair >(mti, pGeometry));