2015-09-05 68 views
0

我正在開發一個OpenGLES2項目(iOS),在該項目中我必須將場景/模型導出爲FBX格式,以便可以使用FBX Review應用程序將其打開。我已經完成了模型加載的點,法線和材質都很好,但紋理沒有被加載。我已經使用iTunes將導出的修復文件和紋理文件粘貼到FBX Review應用程序的文檔目錄中。以下是我的代碼:使用FBX SDK導出的FBX中無法加載的紋理

材質製作:

FbxString lMaterialName = "material"; 
FbxString lShadingName = "Phong"; 
FbxDouble3 lBlack(0.0, 0.0, 0.0); 
FbxDouble3 lRed(0.0, 1.0, 0.0); 
FbxDouble3 lDiffuseColor(1.0, 1.0, 1.0); 
gMaterial = FbxSurfacePhong::Create(pScene, lMaterialName.Buffer()); 
gMaterial->Emissive.Set(lBlack); 
gMaterial->Ambient.Set(lRed); 
gMaterial->Diffuse.Set(lDiffuseColor); 
gMaterial->TransparencyFactor.Set(40.5); 
gMaterial->ShadingModel.Set(lShadingName); 
gMaterial->Shininess.Set(0.5); 

紋理製作:

gTexture = FbxFileTexture::Create(pScene, "Diffuse Texture"); 
gTexture->SetFileName("sample.png"); 
gTexture->SetTextureUse(FbxTexture::eStandard); 
gTexture->SetMappingType(FbxTexture::eUV); 
gTexture->SetMaterialUse(FbxFileTexture::eModelMaterial); 
gTexture->SetSwapUV(false); 
gTexture->SetTranslation(0.0, 0.0); 
gTexture->SetScale(1.0, 1.0); 
gTexture->SetRotation(0.0, 0.0); 

創建FBXLayeredTexture:

finalNode->AddMaterial(gMaterial); 
FbxLayeredTexture* layeredTexture = FbxLayeredTexture::Create(fbxManager, "layered texture"); 
layeredTexture->ConnectSrcObject(gTexture); 
layeredTexture->SetMappingType(FbxTexture::eUV); 
FbxSurfacePhong* surfMaterial = (FbxSurfacePhong*)sampleNode->GetMaterial(0); 
surfMaterial->Diffuse.ConnectSrcObject(layeredTexture); 

// Creating FBXLayerElementUV in another method 
.... 
fbxMesh->InitControlPoints(objMesh->getVerticesCount()); 

FbxLayer* meshLayer = fbxMesh->GetLayer(0); 
FbxLayerElementUV* lUVElement1 = FbxLayerElementUV::Create(fbxMesh, "UVSet1"); 
lUVElement1->SetMappingMode(FbxGeometryElement::eByControlPoint); 
lUVElement1->SetReferenceMode(FbxGeometryElement::eDirect); 
lUVElement1->GetDirectArray().SetCount(objMesh->getVerticesCount()); 

for (int index = 0; index < objMesh->getVerticesCount(); index++) { 
    vertexData* vData = objMesh->getVertexByIndex(index); 
    Vector3 vPos = vData->vertPosition; 
    Vector3 vNor = vData->vertNormal; 
    Vector2 vUV = vData->texCoord1; 

    fbxMesh->SetControlPointAt(fbxsdk_2015_1::FbxVector4(vPos.x, vPos.y, vPos.z), fbxsdk_2015_1::FbxVector4(vNor.x, vNor.y, vNor.z), index); 
    //fbxMesh->AddTextureUV(FbxVector2(vUV.x, vUV.y)); // For Trial 
    lUVElement1->GetDirectArray().Add(FbxVector2(vUV.x, vUV.y)); 
} 
meshLayer->SetUVs(lUVElement1); 
// And Finally 
    ... 
    finalNode->SetNodeAttribute(fbxMesh); 
    finalNode->SetShadingMode(FbxNode::eTextureShading); 

在此先感謝。

回答

1

在這一行,你應該改變 「fbxManager」 到 「pScene」:

FbxLayeredTexture* layeredTexture = FbxLayeredTexture::Create(fbxManager, "layered texture");