diff --git a/src/osgPlugins/fbx/fbxMaterialToOsgStateSet.cpp b/src/osgPlugins/fbx/fbxMaterialToOsgStateSet.cpp index 88a277f5e..2f57c98a4 100644 --- a/src/osgPlugins/fbx/fbxMaterialToOsgStateSet.cpp +++ b/src/osgPlugins/fbx/fbxMaterialToOsgStateSet.cpp @@ -148,6 +148,69 @@ FbxMaterialToOsgStateSet::convert(const FbxSurfaceMaterial* pFbxMat) } } + // normal map... + const FbxProperty lNormalProperty = pFbxMat->FindProperty(FbxSurfaceMaterial::sNormalMap); + if (lNormalProperty.IsValid()) + { + int lNbTex = lNormalProperty.GetSrcObjectCount(); + for (int lTextureIndex = 0; lTextureIndex < lNbTex; lTextureIndex++) + { + FbxFileTexture* lTexture = FbxCast(lNormalProperty.GetSrcObject(lTextureIndex)); + if (lTexture) + { + result.normalTexture = fbxTextureToOsgTexture(lTexture); + result.normalChannel = lTexture->UVSet.Get(); + result.normalScaleU = lTexture->GetScaleU(); + result.normalScaleV = lTexture->GetScaleV(); + } + + //For now only allow 1 texture + break; + } + } + + // specular map... + const FbxProperty lSpecularProperty = pFbxMat->FindProperty(FbxSurfaceMaterial::sSpecular); + if (lSpecularProperty.IsValid()) + { + int lNbTex = lSpecularProperty.GetSrcObjectCount(); + for (int lTextureIndex = 0; lTextureIndex < lNbTex; lTextureIndex++) + { + FbxFileTexture* lTexture = FbxCast(lSpecularProperty.GetSrcObject(lTextureIndex)); + if (lTexture) + { + result.specularTexture = fbxTextureToOsgTexture(lTexture); + result.specularChannel = lTexture->UVSet.Get(); + result.specularScaleU = lTexture->GetScaleU(); + result.specularScaleV = lTexture->GetScaleV(); + } + + //For now only allow 1 texture + break; + } + } + + // shininess map... + const FbxProperty lShininessProperty = pFbxMat->FindProperty(FbxSurfaceMaterial::sShininess); + if (lShininessProperty.IsValid()) + { + int lNbTex = lShininessProperty.GetSrcObjectCount(); + for (int lTextureIndex = 0; lTextureIndex < lNbTex; lTextureIndex++) + { + FbxFileTexture* lTexture = FbxCast(lShininessProperty.GetSrcObject(lTextureIndex)); + if (lTexture) + { + result.shininessTexture = fbxTextureToOsgTexture(lTexture); + result.shininessChannel = lTexture->UVSet.Get(); + result.shininessScaleU = lTexture->GetScaleU(); + result.shininessScaleV = lTexture->GetScaleV(); + } + + //For now only allow 1 texture + break; + } + } + if (pFbxLambert) { FbxDouble3 color = pFbxLambert->Diffuse.Get(); @@ -177,6 +240,9 @@ FbxMaterialToOsgStateSet::convert(const FbxSurfaceMaterial* pFbxMat) // get maps factors... result.diffuseFactor = pFbxLambert->DiffuseFactor.Get(); + result.emissiveFactor = pFbxLambert->EmissiveFactor.Get(); + result.ambientFactor = pFbxLambert->AmbientFactor.Get(); + result.normalFactor = pFbxLambert->BumpFactor.Get(); if (const FbxSurfacePhong* pFbxPhong = FbxCast(pFbxLambert)) { @@ -196,6 +262,7 @@ FbxMaterialToOsgStateSet::convert(const FbxSurfaceMaterial* pFbxMat) // get maps factors... result.reflectionFactor = pFbxPhong->ReflectionFactor.Get(); + result.specularFactor = pFbxPhong->SpecularFactor.Get(); // get more factors here... } } diff --git a/src/osgPlugins/fbx/fbxMaterialToOsgStateSet.h b/src/osgPlugins/fbx/fbxMaterialToOsgStateSet.h index 181778b28..1d4a3dcf1 100644 --- a/src/osgPlugins/fbx/fbxMaterialToOsgStateSet.h +++ b/src/osgPlugins/fbx/fbxMaterialToOsgStateSet.h @@ -23,7 +23,9 @@ struct StateSetContent : diffuseFactor(1.0), reflectionFactor(1.0), emissiveFactor(1.0), - ambientFactor(1.0) + ambientFactor(1.0), + normalFactor(1.0), + specularFactor(1.0) { } @@ -35,6 +37,9 @@ struct StateSetContent osg::ref_ptr reflectionTexture; osg::ref_ptr emissiveTexture; osg::ref_ptr ambientTexture; + osg::ref_ptr normalTexture; + osg::ref_ptr specularTexture; + osg::ref_ptr shininessTexture; // more textures types here... // textures maps channels names... @@ -43,6 +48,9 @@ struct StateSetContent std::string reflectionChannel; std::string emissiveChannel; std::string ambientChannel; + std::string normalChannel; + std::string specularChannel; + std::string shininessChannel; // more channels names here... // combining factors... @@ -50,6 +58,8 @@ struct StateSetContent double reflectionFactor; double emissiveFactor; double ambientFactor; + double normalFactor; + double specularFactor; // more combining factors here... double diffuseScaleU; @@ -60,6 +70,12 @@ struct StateSetContent double emissiveScaleV; double ambientScaleU; double ambientScaleV; + double normalScaleU; + double normalScaleV; + double specularScaleU; + double specularScaleV; + double shininessScaleU; + double shininessScaleV; // texture units (eventually used for each texture map)... enum TextureUnit @@ -68,7 +84,10 @@ struct StateSetContent OPACITY_TEXTURE_UNIT, REFLECTION_TEXTURE_UNIT, EMISSIVE_TEXTURE_UNIT, - AMBIENT_TEXTURE_UNIT + AMBIENT_TEXTURE_UNIT, + NORMAL_TEXTURE_UNIT, + SPECULAR_TEXTURE_UNIT, + SHININESS_TEXTURE_UNIT // more texture units here... }; }; diff --git a/src/osgPlugins/fbx/fbxRMesh.cpp b/src/osgPlugins/fbx/fbxRMesh.cpp index 3d1736257..c5b07506e 100644 --- a/src/osgPlugins/fbx/fbxRMesh.cpp +++ b/src/osgPlugins/fbx/fbxRMesh.cpp @@ -155,6 +155,9 @@ osg::Geometry* getGeometry(osg::Geode* pGeode, GeometryMap& geometryMap, bool useOpacityMap, bool useEmissiveMap, bool useAmbientMap, + bool useNormalMap, + bool useSpecularMap, + bool useShininessMap, // more here... bool bColor, const osgDB::Options& options, @@ -191,6 +194,12 @@ osg::Geometry* getGeometry(osg::Geode* pGeode, GeometryMap& geometryMap, pGeometry->setTexCoordArray(StateSetContent::EMISSIVE_TEXTURE_UNIT, createVec2Array((precision & osgDB::Options::DOUBLE_PRECISION_TEX_COORD) != 0), osg::Array::BIND_PER_VERTEX); if (useAmbientMap) pGeometry->setTexCoordArray(StateSetContent::AMBIENT_TEXTURE_UNIT, createVec2Array((precision & osgDB::Options::DOUBLE_PRECISION_TEX_COORD) != 0), osg::Array::BIND_PER_VERTEX); + if (useNormalMap) + pGeometry->setTexCoordArray(StateSetContent::NORMAL_TEXTURE_UNIT, createVec2Array((precision & osgDB::Options::DOUBLE_PRECISION_TEX_COORD) != 0), osg::Array::BIND_PER_VERTEX); + if (useSpecularMap) + pGeometry->setTexCoordArray(StateSetContent::SPECULAR_TEXTURE_UNIT, createVec2Array((precision & osgDB::Options::DOUBLE_PRECISION_TEX_COORD) != 0), osg::Array::BIND_PER_VERTEX); + if (useShininessMap) + pGeometry->setTexCoordArray(StateSetContent::SHININESS_TEXTURE_UNIT, createVec2Array((precision & osgDB::Options::DOUBLE_PRECISION_TEX_COORD) != 0), osg::Array::BIND_PER_VERTEX); // create more textures coordinates here... if (bColor) pGeometry->setColorArray(createVec4Array((precision & osgDB::Options::DOUBLE_PRECISION_COLOR) != 0), osg::Array::BIND_PER_VERTEX); @@ -320,6 +329,54 @@ osg::Geometry* getGeometry(osg::Geode* pGeode, GeometryMap& geometryMap, stateSet->setTextureAttributeAndModes(StateSetContent::AMBIENT_TEXTURE_UNIT, ssc.ambientTexture.get()); } + // normal texture map + if (ssc.normalTexture) + { + if (ssc.normalScaleU != 1.0 || ssc.normalScaleV != 1.0) + { + // set UV scaling... + osg::ref_ptr texmat = new osg::TexMat(); + osg::Matrix uvScaling; + uvScaling.makeScale(osg::Vec3(ssc.normalScaleU, ssc.normalScaleV, 1.0)); + texmat->setMatrix(uvScaling); + stateSet->setTextureAttributeAndModes(StateSetContent::NORMAL_TEXTURE_UNIT, texmat.get(), osg::StateAttribute::ON); + } + + stateSet->setTextureAttributeAndModes(StateSetContent::NORMAL_TEXTURE_UNIT, ssc.normalTexture.get()); + } + + // specular texture map + if (ssc.specularTexture) + { + if (ssc.specularScaleU != 1.0 || ssc.specularScaleV != 1.0) + { + // set UV scaling... + osg::ref_ptr texmat = new osg::TexMat(); + osg::Matrix uvScaling; + uvScaling.makeScale(osg::Vec3(ssc.specularScaleU, ssc.specularScaleV, 1.0)); + texmat->setMatrix(uvScaling); + stateSet->setTextureAttributeAndModes(StateSetContent::SPECULAR_TEXTURE_UNIT, texmat.get(), osg::StateAttribute::ON); + } + + stateSet->setTextureAttributeAndModes(StateSetContent::SPECULAR_TEXTURE_UNIT, ssc.specularTexture.get()); + } + + // shininess texture map + if (ssc.shininessTexture) + { + if (ssc.shininessScaleU != 1.0 || ssc.shininessScaleV != 1.0) + { + // set UV scaling... + osg::ref_ptr texmat = new osg::TexMat(); + osg::Matrix uvScaling; + uvScaling.makeScale(osg::Vec3(ssc.shininessScaleU, ssc.shininessScaleV, 1.0)); + texmat->setMatrix(uvScaling); + stateSet->setTextureAttributeAndModes(StateSetContent::SHININESS_TEXTURE_UNIT, texmat.get(), osg::StateAttribute::ON); + } + + stateSet->setTextureAttributeAndModes(StateSetContent::SHININESS_TEXTURE_UNIT, ssc.shininessTexture.get()); + } + // add more texture maps here... if (transparent) @@ -504,6 +561,12 @@ std::string getUVChannelForTextureMap(std::vector& stateSetList return stateSetList[i].emissiveChannel; if (0 == strcmp(pName, FbxSurfaceMaterial::sAmbient)) return stateSetList[i].ambientChannel; + if (0 == strcmp(pName, FbxSurfaceMaterial::sNormalMap)) + return stateSetList[i].normalChannel; + if (0 == strcmp(pName, FbxSurfaceMaterial::sSpecular)) + return stateSetList[i].specularChannel; + if (0 == strcmp(pName, FbxSurfaceMaterial::sShininess)) + return stateSetList[i].shininessChannel; // more here... } @@ -558,6 +621,9 @@ void readMeshTriangle(const FbxMesh * fbxMesh, int i /*polygonIndex*/, const FbxLayerElementUV* pFbxUVs_opacity, const FbxLayerElementUV* pFbxUVs_emissive, const FbxLayerElementUV* pFbxUVs_ambient, + const FbxLayerElementUV* pFbxUVs_normal, + const FbxLayerElementUV* pFbxUVs_specular, + const FbxLayerElementUV* pFbxUVs_shininess, const FbxLayerElementVertexColor* pFbxColors, osg::Geometry* pGeometry, osg::Array* pVertices, @@ -566,6 +632,9 @@ void readMeshTriangle(const FbxMesh * fbxMesh, int i /*polygonIndex*/, osg::Array* pTexCoords_opacity, osg::Array* pTexCoords_emissive, osg::Array* pTexCoords_ambient, + osg::Array* pTexCoords_normal, + osg::Array* pTexCoords_specular, + osg::Array* pTexCoords_shininess, osg::Array* pColors) { int v0 = fbxMesh->GetPolygonVertex(i, posInPoly0), @@ -623,6 +692,24 @@ void readMeshTriangle(const FbxMesh * fbxMesh, int i /*polygonIndex*/, addVec2ArrayElement(*pTexCoords_ambient, getElement(pFbxUVs_ambient, fbxMesh, i, posInPoly1, meshVertex1)); addVec2ArrayElement(*pTexCoords_ambient, getElement(pFbxUVs_ambient, fbxMesh, i, posInPoly2, meshVertex2)); } + if (pTexCoords_normal && (pTexCoords_normal != pTexCoords_opacity) && (pTexCoords_normal != pTexCoords_diffuse) && (pTexCoords_normal != pTexCoords_emissive) && (pTexCoords_normal != pTexCoords_ambient)) + { + addVec2ArrayElement(*pTexCoords_normal, getElement(pFbxUVs_normal, fbxMesh, i, posInPoly0, meshVertex0)); + addVec2ArrayElement(*pTexCoords_normal, getElement(pFbxUVs_normal, fbxMesh, i, posInPoly1, meshVertex1)); + addVec2ArrayElement(*pTexCoords_normal, getElement(pFbxUVs_normal, fbxMesh, i, posInPoly2, meshVertex2)); + } + if (pTexCoords_specular && (pTexCoords_specular != pTexCoords_opacity) && (pTexCoords_specular != pTexCoords_diffuse) && (pTexCoords_specular != pTexCoords_emissive) && (pTexCoords_specular != pTexCoords_ambient) && (pTexCoords_specular != pTexCoords_normal)) + { + addVec2ArrayElement(*pTexCoords_specular, getElement(pFbxUVs_specular, fbxMesh, i, posInPoly0, meshVertex0)); + addVec2ArrayElement(*pTexCoords_specular, getElement(pFbxUVs_specular, fbxMesh, i, posInPoly1, meshVertex1)); + addVec2ArrayElement(*pTexCoords_specular, getElement(pFbxUVs_specular, fbxMesh, i, posInPoly2, meshVertex2)); + } + if (pTexCoords_shininess && (pTexCoords_shininess != pTexCoords_opacity) && (pTexCoords_shininess != pTexCoords_diffuse) && (pTexCoords_shininess != pTexCoords_emissive) && (pTexCoords_shininess != pTexCoords_ambient) && (pTexCoords_shininess != pTexCoords_normal) && (pTexCoords_shininess != pTexCoords_specular)) + { + addVec2ArrayElement(*pTexCoords_shininess, getElement(pFbxUVs_shininess, fbxMesh, i, posInPoly0, meshVertex0)); + addVec2ArrayElement(*pTexCoords_shininess, getElement(pFbxUVs_shininess, fbxMesh, i, posInPoly1, meshVertex1)); + addVec2ArrayElement(*pTexCoords_shininess, getElement(pFbxUVs_shininess, fbxMesh, i, posInPoly2, meshVertex2)); + } // add more texture maps here... if (pColors) @@ -725,6 +812,9 @@ osgDB::ReaderWriter::ReadResult OsgFbxReader::readMesh( std::string opacityChannel = getUVChannelForTextureMap(stateSetList, FbxSurfaceMaterial::sTransparentColor); std::string emissiveChannel = getUVChannelForTextureMap(stateSetList, FbxSurfaceMaterial::sEmissive); std::string ambientChannel = getUVChannelForTextureMap(stateSetList, FbxSurfaceMaterial::sAmbient); + std::string normalChannel = getUVChannelForTextureMap(stateSetList, FbxSurfaceMaterial::sNormalMap); + std::string specularChannel = getUVChannelForTextureMap(stateSetList, FbxSurfaceMaterial::sSpecular); + std::string shininessChannel = getUVChannelForTextureMap(stateSetList, FbxSurfaceMaterial::sShininess); // look for more UV elements here... // UV elements... @@ -732,6 +822,9 @@ osgDB::ReaderWriter::ReadResult OsgFbxReader::readMesh( const FbxLayerElementUV* pFbxUVs_opacity = getUVElementForChannel(opacityChannel, FbxLayerElement::eTextureTransparency, fbxMesh); const FbxLayerElementUV* pFbxUVs_emissive = getUVElementForChannel(emissiveChannel, FbxLayerElement::eTextureEmissive, fbxMesh); const FbxLayerElementUV* pFbxUVs_ambient = getUVElementForChannel(ambientChannel, FbxLayerElement::eTextureAmbient, fbxMesh); + const FbxLayerElementUV* pFbxUVs_normal = getUVElementForChannel(normalChannel, FbxLayerElement::eTextureNormalMap, fbxMesh); + const FbxLayerElementUV* pFbxUVs_specular = getUVElementForChannel(specularChannel, FbxLayerElement::eTextureSpecular, fbxMesh); + const FbxLayerElementUV* pFbxUVs_shininess = getUVElementForChannel(shininessChannel, FbxLayerElement::eTextureShininess, fbxMesh); // more UV elements here... // check elements validity... @@ -742,6 +835,9 @@ osgDB::ReaderWriter::ReadResult OsgFbxReader::readMesh( if (!layerElementValid(pFbxUVs_opacity)) pFbxUVs_opacity = 0; if (!layerElementValid(pFbxUVs_emissive)) pFbxUVs_emissive = 0; if (!layerElementValid(pFbxUVs_ambient)) pFbxUVs_ambient = 0; + if (!layerElementValid(pFbxUVs_normal)) pFbxUVs_normal = 0; + if (!layerElementValid(pFbxUVs_specular)) pFbxUVs_specular = 0; + if (!layerElementValid(pFbxUVs_shininess)) pFbxUVs_shininess = 0; // more here... int nPolys = fbxMesh->GetPolygonCount(); @@ -783,6 +879,9 @@ osgDB::ReaderWriter::ReadResult OsgFbxReader::readMesh( pFbxUVs_opacity != 0, pFbxUVs_emissive != 0, pFbxUVs_ambient != 0, + pFbxUVs_normal != 0, + pFbxUVs_specular != 0, + pFbxUVs_shininess != 0, // more UV elements here... pFbxColors != 0, options, @@ -796,6 +895,9 @@ osgDB::ReaderWriter::ReadResult OsgFbxReader::readMesh( osg::Array* pTexCoords_opacity = pGeometry->getTexCoordArray(StateSetContent::OPACITY_TEXTURE_UNIT); osg::Array* pTexCoords_emissive = pGeometry->getTexCoordArray(StateSetContent::EMISSIVE_TEXTURE_UNIT); osg::Array* pTexCoords_ambient = pGeometry->getTexCoordArray(StateSetContent::AMBIENT_TEXTURE_UNIT); + osg::Array* pTexCoords_normal = pGeometry->getTexCoordArray(StateSetContent::NORMAL_TEXTURE_UNIT); + osg::Array* pTexCoords_specular = pGeometry->getTexCoordArray(StateSetContent::SPECULAR_TEXTURE_UNIT); + osg::Array* pTexCoords_shininess = pGeometry->getTexCoordArray(StateSetContent::SHININESS_TEXTURE_UNIT); // more texture coordinates here... osg::Array* pColors = pGeometry->getColorArray(); @@ -807,9 +909,9 @@ osgDB::ReaderWriter::ReadResult OsgFbxReader::readMesh( 0, 1, 2, nVertex, nVertex+1, nVertex+2, fbxToOsgVertMap, osgToFbxNormMap, - pFbxVertices, pFbxNormals, pFbxUVs_diffuse, pFbxUVs_opacity, pFbxUVs_emissive, pFbxUVs_ambient, pFbxColors, + pFbxVertices, pFbxNormals, pFbxUVs_diffuse, pFbxUVs_opacity, pFbxUVs_emissive, pFbxUVs_ambient, pFbxUVs_normal, pFbxUVs_specular, pFbxUVs_shininess, pFbxColors, pGeometry, - pVertices, pNormals, pTexCoords_diffuse, pTexCoords_opacity, pTexCoords_emissive, pTexCoords_ambient, pColors); + pVertices, pNormals, pTexCoords_diffuse, pTexCoords_opacity, pTexCoords_emissive, pTexCoords_ambient, pTexCoords_normal, pTexCoords_specular, pTexCoords_shininess, pColors); nVertex += 3; } else if (lPolygonSize == 4) @@ -824,16 +926,16 @@ osgDB::ReaderWriter::ReadResult OsgFbxReader::readMesh( 0, 1, p02, nVertex, nVertex+1, nVertex+p02, fbxToOsgVertMap, osgToFbxNormMap, - pFbxVertices, pFbxNormals, pFbxUVs_diffuse, pFbxUVs_opacity, pFbxUVs_emissive, pFbxUVs_ambient, pFbxColors, + pFbxVertices, pFbxNormals, pFbxUVs_diffuse, pFbxUVs_opacity, pFbxUVs_emissive, pFbxUVs_ambient, pFbxUVs_normal, pFbxUVs_specular, pFbxUVs_shininess, pFbxColors, pGeometry, - pVertices, pNormals, pTexCoords_diffuse, pTexCoords_opacity, pTexCoords_emissive, pTexCoords_ambient, pColors); + pVertices, pNormals, pTexCoords_diffuse, pTexCoords_opacity, pTexCoords_emissive, pTexCoords_ambient, pTexCoords_normal, pTexCoords_specular, pTexCoords_shininess, pColors); readMeshTriangle(fbxMesh, i, p10, 2, 3, nVertex+p10, nVertex+2, nVertex+3, fbxToOsgVertMap, osgToFbxNormMap, - pFbxVertices, pFbxNormals, pFbxUVs_diffuse, pFbxUVs_opacity, pFbxUVs_emissive, pFbxUVs_ambient, pFbxColors, + pFbxVertices, pFbxNormals, pFbxUVs_diffuse, pFbxUVs_opacity, pFbxUVs_emissive, pFbxUVs_ambient, pFbxUVs_normal, pFbxUVs_specular, pFbxUVs_shininess, pFbxColors, pGeometry, - pVertices, pNormals, pTexCoords_diffuse, pTexCoords_opacity, pTexCoords_emissive, pTexCoords_ambient, pColors); + pVertices, pNormals, pTexCoords_diffuse, pTexCoords_opacity, pTexCoords_emissive, pTexCoords_ambient, pTexCoords_normal, pTexCoords_specular, pTexCoords_shininess, pColors); nVertex += 4; } else if (tessellatePolygons) @@ -853,9 +955,9 @@ osgDB::ReaderWriter::ReadResult OsgFbxReader::readMesh( 0, j - 1, j, nVertex0, nVertex - 1, nVertex, fbxToOsgVertMap, osgToFbxNormMap, - pFbxVertices, pFbxNormals, pFbxUVs_diffuse, pFbxUVs_opacity, pFbxUVs_emissive, pFbxUVs_ambient, pFbxColors, + pFbxVertices, pFbxNormals, pFbxUVs_diffuse, pFbxUVs_opacity, pFbxUVs_emissive, pFbxUVs_ambient, pFbxUVs_normal, pFbxUVs_specular, pFbxUVs_shininess, pFbxColors, pGeometry, - pVertices, pNormals, pTexCoords_diffuse, pTexCoords_opacity, pTexCoords_emissive, pTexCoords_ambient, pColors); + pVertices, pNormals, pTexCoords_diffuse, pTexCoords_opacity, pTexCoords_emissive, pTexCoords_ambient, pTexCoords_normal, pTexCoords_specular, pTexCoords_shininess, pColors); } } } @@ -886,6 +988,9 @@ osgDB::ReaderWriter::ReadResult OsgFbxReader::readMesh( osg::Array* pTexCoords_opacity = pGeometry->getTexCoordArray(StateSetContent::OPACITY_TEXTURE_UNIT); osg::Array* pTexCoords_emissive = pGeometry->getTexCoordArray(StateSetContent::EMISSIVE_TEXTURE_UNIT); osg::Array* pTexCoords_ambient = pGeometry->getTexCoordArray(StateSetContent::AMBIENT_TEXTURE_UNIT); + osg::Array* pTexCoords_normal = pGeometry->getTexCoordArray(StateSetContent::NORMAL_TEXTURE_UNIT); + osg::Array* pTexCoords_specular = pGeometry->getTexCoordArray(StateSetContent::SPECULAR_TEXTURE_UNIT); + osg::Array* pTexCoords_shininess = pGeometry->getTexCoordArray(StateSetContent::SHININESS_TEXTURE_UNIT); osg::Array* pColors = pGeometry->getColorArray(); // Index of the 1st vertex of the polygon in the geometry int osgVertex0 = pVertices->getNumElements(); @@ -918,10 +1023,22 @@ osgDB::ReaderWriter::ReadResult OsgFbxReader::readMesh( { addVec2ArrayElement(*pTexCoords_emissive, getElement(pFbxUVs_emissive, fbxMesh, i, j, nVertex)); } - if (pTexCoords_ambient && (pTexCoords_ambient != pTexCoords_opacity) && (pTexCoords_ambient != pTexCoords_diffuse)) + if (pTexCoords_ambient && (pTexCoords_ambient != pTexCoords_opacity) && (pTexCoords_ambient != pTexCoords_diffuse) && (pTexCoords_ambient != pTexCoords_emissive)) { addVec2ArrayElement(*pTexCoords_ambient, getElement(pFbxUVs_ambient, fbxMesh, i, j, nVertex)); } + if (pTexCoords_normal && (pTexCoords_normal != pTexCoords_opacity) && (pTexCoords_normal != pTexCoords_diffuse) && (pTexCoords_normal != pTexCoords_emissive) && (pTexCoords_normal != pTexCoords_ambient)) + { + addVec2ArrayElement(*pTexCoords_normal, getElement(pFbxUVs_normal, fbxMesh, i, j, nVertex)); + } + if (pTexCoords_specular && (pTexCoords_specular != pTexCoords_opacity) && (pTexCoords_specular != pTexCoords_diffuse) && (pTexCoords_specular != pTexCoords_emissive) && (pTexCoords_specular != pTexCoords_ambient) && (pTexCoords_specular != pTexCoords_normal)) + { + addVec2ArrayElement(*pTexCoords_specular, getElement(pFbxUVs_specular, fbxMesh, i, j, nVertex)); + } + if (pTexCoords_shininess && (pTexCoords_shininess != pTexCoords_opacity) && (pTexCoords_shininess != pTexCoords_diffuse) && (pTexCoords_shininess != pTexCoords_emissive) && (pTexCoords_shininess != pTexCoords_ambient) && (pTexCoords_shininess != pTexCoords_normal) && (pTexCoords_shininess != pTexCoords_specular)) + { + addVec2ArrayElement(*pTexCoords_shininess, getElement(pFbxUVs_shininess, fbxMesh, i, j, nVertex)); + } // add more texture maps here... if (pColors)