| | 114 | |
| | 115 | void FbxMaterialToOsgStateSet::checkInvertTransparency() |
| | 116 | { |
| | 117 | int zeroAlpha = 0, oneAlpha = 0; |
| | 118 | for (KFbxMaterialMap::const_iterator it = _kFbxMaterialMap.begin(); it != _kFbxMaterialMap.end(); ++it) |
| | 119 | { |
| | 120 | const osg::Material* pMaterial = it->second.first; |
| | 121 | float alpha = pMaterial->getDiffuse(osg::Material::FRONT).a(); |
| | 122 | if (alpha > 0.999f) |
| | 123 | { |
| | 124 | ++oneAlpha; |
| | 125 | } |
| | 126 | else if (alpha < 0.001f) |
| | 127 | { |
| | 128 | ++zeroAlpha; |
| | 129 | } |
| | 130 | } |
| | 131 | |
| | 132 | if (zeroAlpha > oneAlpha) |
| | 133 | { |
| | 134 | //Transparency values seem to be back to front so invert them. |
| | 135 | |
| | 136 | for (KFbxMaterialMap::const_iterator it = _kFbxMaterialMap.begin(); it != _kFbxMaterialMap.end(); ++it) |
| | 137 | { |
| | 138 | osg::Material* pMaterial = it->second.first; |
| | 139 | osg::Vec4 diffuse = pMaterial->getDiffuse(osg::Material::FRONT); |
| | 140 | diffuse.a() = 1.0f - diffuse.a(); |
| | 141 | pMaterial->setDiffuse(osg::Material::FRONT_AND_BACK, diffuse); |
| | 142 | } |
| | 143 | } |
| | 144 | } |