From 1f33e65c2a08a0c7f30cd6e04a58cc871740c473 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 7 Jun 2011 14:28:58 +0000 Subject: [PATCH] From Sukender, "Lastest change (update to FBX 2012.1) introduced a regression. It didn't take materials' order into consideration. The line lMaterialLayer->GetDirectArray().SetAt(it->second.getIndex(), lMaterial); has been replaced by _curFbxNode->AddMaterial(lMaterial); because KFbxLayerElementMaterial::GetDirectArray() is now private and we can't access to it. However, pushing back the material at the end of the vector is wrong. We can use the (now) public attribute KFbxLayerElementMaterial::mDirectArray, as in this submission. " --- src/osgPlugins/fbx/WriterNodeVisitor.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/osgPlugins/fbx/WriterNodeVisitor.cpp b/src/osgPlugins/fbx/WriterNodeVisitor.cpp index 9f60d7f87..f9b2c809a 100644 --- a/src/osgPlugins/fbx/WriterNodeVisitor.cpp +++ b/src/osgPlugins/fbx/WriterNodeVisitor.cpp @@ -372,7 +372,7 @@ WriterNodeVisitor::Material::Material(WriterNodeVisitor& writerNodeVisitor, // Note there should be no reason KFbxSurfacePhong::Create() would return NULL, but as previous code made this secirity test, here we keep the same way. if (_fbxMaterial) { - _fbxMaterial->GetDiffuseColor().ConnectSrcObject(_fbxTexture); + _fbxMaterial->Diffuse.ConnectSrcObject(_fbxTexture); } } } @@ -435,6 +435,8 @@ WriterNodeVisitor::setLayerTextureAndMaterial(KFbxMesh* mesh) lMaterialLayer->SetReferenceMode(KFbxLayerElement::eINDEX_TO_DIRECT); lTextureDiffuseLayer->GetDirectArray().SetCount(_lastMaterialIndex); + lMaterialLayer->mDirectArray->SetCount(_lastMaterialIndex); + for (MaterialMap::iterator it = _materialMap.begin(); it != _materialMap.end(); ++it) { if (it->second.getIndex() != -1) @@ -442,7 +444,7 @@ WriterNodeVisitor::setLayerTextureAndMaterial(KFbxMesh* mesh) KFbxSurfaceMaterial* lMaterial = it->second.getFbxMaterial(); KFbxFileTexture* lTexture = it->second.getFbxTexture(); lTextureDiffuseLayer->GetDirectArray().SetAt(it->second.getIndex(), lTexture); - _curFbxNode->AddMaterial(lMaterial); + lMaterialLayer->mDirectArray->SetAt(it->second.getIndex(), lMaterial); } } mesh->GetLayer(0)->SetMaterials(lMaterialLayer);