我正在开发OpenGLES2项目(iOS),我必须将场景/模型导出为FBX格式,以便可以使用FBX评论应用程序打开它。我已经达到模型加载的程度,法线和材质工作正常,但纹理没有加载。我已使用iTunes将导出的修复文件和纹理文件粘贴到FBX Review应用程序的文档目录中。以下是我的代码:
材料创作:
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);
提前致谢。
答案 0 :(得分:1)
在此行中,您应将“fbxManager”更改为“pScene”:
FbxLayeredTexture* layeredTexture = FbxLayeredTexture::Create(fbxManager, "layered texture");