Hi there.
I'm trying to make a hole with FbxLayerElementHole class.
But I have no idea to make it.
Followings are the code that I modified from CreateCube sample.
There are 2 rectangules. Bigger one is outter contour, and smaller one is inner contour(hole).
Thanks
Lee
FbxNode* CreateHole(FbxScene* pScene, char* pName)
{
int i, j;
FbxMesh* lMesh = FbxMesh::Create(pScene,pName);
FbxVector4 lControlPoint0(-50, 0, 50);
FbxVector4 lControlPoint1(50, 0, 50);
FbxVector4 lControlPoint2(50, 0, -50);
FbxVector4 lControlPoint3(-50, 0, -50);
FbxVector4 lControlPoint8(-25, 0, 25);
FbxVector4 lControlPoint9(25, 0, 25);
FbxVector4 lControlPoint10(25, 0, -25);
FbxVector4 lControlPoint11(-25, 0, -25);
FbxVector4 lNormalYPos(0, 1, 0);
// Create control points.
lMesh->InitControlPoints(8);
FbxVector4* lControlPoints = lMesh->GetControlPoints();
lControlPoints[0] = lControlPoint0;
lControlPoints[1] = lControlPoint1;
lControlPoints[2] = lControlPoint2;
lControlPoints[3] = lControlPoint3;
lControlPoints[4] = lControlPoint8;
lControlPoints[5] = lControlPoint9;
lControlPoints[6] = lControlPoint10;
lControlPoints[7] = lControlPoint11;
// Set the normals on Layer 0.
FbxLayer* lLayer = lMesh->GetLayer(0);
if (lLayer == NULL)
{
lMesh->CreateLayer();
lLayer = lMesh->GetLayer(0);
}
// We want to have one normal for each vertex (or control point),
// so we set the mapping mode to eByControlPoint.
FbxLayerElementNormal* lLayerElementNormal= FbxLayerElementNormal::Create(lMesh, "Normal");
lLayerElementNormal->SetMappingMode(FbxLayerElement::eByControlPoint);
// Set the normal values for every control point.
lLayerElementNormal->SetReferenceMode(FbxLayerElement::eDirect);
lLayerElementNormal->GetDirectArray().Add(lNormalYPos);
lLayerElementNormal->GetDirectArray().Add(lNormalYPos);
lLayerElementNormal->GetDirectArray().Add(lNormalYPos);
lLayerElementNormal->GetDirectArray().Add(lNormalYPos);
lLayerElementNormal->GetDirectArray().Add(lNormalYPos);
lLayerElementNormal->GetDirectArray().Add(lNormalYPos);
lLayerElementNormal->GetDirectArray().Add(lNormalYPos);
lLayerElementNormal->GetDirectArray().Add(lNormalYPos);
lLayer->SetNormals(lLayerElementNormal);
// Array of polygon vertices.
int lPolygonVertices[] = { 0, 1, 2, 3, 4, 5, 6, 7};
// Create UV for Diffuse channel.
FbxLayerElementUV* lUVDiffuseLayer = FbxLayerElementUV::Create(lMesh, "DiffuseUV");
lUVDiffuseLayer->SetMappingMode(FbxLayerElement::eByPolygonVertex);
lUVDiffuseLayer->SetReferenceMode(FbxLayerElement::eIndexToDirect);
lLayer->SetUVs(lUVDiffuseLayer, FbxLayerElement::eTextureDiffuse);
FbxVector2 lVectors0(0, 0);
FbxVector2 lVectors1(1, 0);
FbxVector2 lVectors2(1, 1);
FbxVector2 lVectors3(0, 1);
lUVDiffuseLayer->GetDirectArray().Add(lVectors0);
lUVDiffuseLayer->GetDirectArray().Add(lVectors1);
lUVDiffuseLayer->GetDirectArray().Add(lVectors2);
lUVDiffuseLayer->GetDirectArray().Add(lVectors3);
//Now we have set the UVs as eIndexToDirect reference and in eByPolygonVertex mapping mode
//we must update the size of the index array.
lUVDiffuseLayer->GetIndexArray().SetCount(8);
// Create polygons. Assign texture and texture UV indices.
for(i = 0; i < 2; i++)
{
// all faces of the cube have the same texture
lMesh->BeginPolygon(-1,-1,-1,false);
for(j = 0; j < 4; j++)
{
// Control point index
lMesh->AddPolygon(lPolygonVertices[i*4 + j]);
// update the index array of the UVs that map the texture to the face
lUVDiffuseLayer->GetIndexArray().SetAt(i*4+j, j);
}
lMesh->EndPolygon ();
}
// Set material indices
FbxLayerElementMaterial* lMaterialLayer = FbxLayerElementMaterial::Create(lMesh, "MaterialIndices");
lMaterialLayer->SetMappingMode(FbxLayerElement::eByPolygon);
lMaterialLayer->SetReferenceMode(FbxLayerElement::eIndexToDirect);
lLayer->SetMaterials(lMaterialLayer);
for (int i = 0; i < 2; i++)
{
// the i-th material on FbxNode is applied to the i-th polygon
lMaterialLayer->GetIndexArray().Add(i);
}
FbxLayerElementHole* lHole = FbxLayerElementHole::Create(lMesh, "Hole");
lHole->SetMappingMode(FbxLayerElement::eByPolygon);
lHole->SetReferenceMode(FbxLayerElement::eIndexToDirect);
lLayer->SetHole(lHole);
lMesh->SetPolyHoleInfo(0,true);
for (int i = 4 ; i < 8 ; i++)
{
lHole->GetIndexArray().Add(i);
}
// create a FbxNode
FbxNode* lNode = FbxNode::Create(pScene,pName);
// set the node attribute
lNode->SetNodeAttribute(lMesh);
// set the shading mode to view texture
lNode->SetShadingMode(FbxNode::eTextureShading);
// rescale the cube
lNode->LclScaling.Set(FbxVector4(0.3, 0.3, 0.3));
// Add node to the scene
pScene->GetRootNode()->AddChild(lNode);
// return the FbxNode
return lNode;
}
Can't find what you're looking for? Ask the community or share your knowledge.