Holes in Polygons possible using FbxMesh?

Holes in Polygons possible using FbxMesh?

Anonymous
Not applicable
955 Views
5 Replies
Message 1 of 6

Holes in Polygons possible using FbxMesh?

Anonymous
Not applicable

Hello! 

I'm trying to read proprietary 3D data and convert it to FBX.

The proprietary format carries it's 3D data as faces with holes. So I have 1 defining polygon boundary which can contain multiple polygons as "holes".

 

I have found that the FbxMesh seems to support Polygons with holes (at least I found the function "SetPolyHoleFunction", I assumed from the description that I can use it to mark a polygon as a hole.)

Please consider the following code:

 

FbxMesh * lMsh = FbxMesh::Create(m_pScene, "myname");
lMsh->BeginPolygon(-1, -1, 1, true);
lMsh->SetControlPointAt(myPoint1, 1);
lMsh->AddPolygon(1);
lMsh->SetControlPointAt(myPoint2, 2);
lMsh->AddPolygon(2);
lMsh->SetControlPointAt(myPoint3, 3);
lMsh->AddPolygon(3);
lMsh->SetControlPointAt(myPoint4, 4);
lMsh->AddPolygon(4);
lMsh->EndPolygon();

lMsh->BeginPolygon(-1, -1, 1, true);
lMsh->SetControlPointAt(myPoint5, 5);
lMsh->AddPolygon(5);
lMsh->SetControlPointAt(myPoint6, 6);
lMsh->AddPolygon(6);
lMsh->SetControlPointAt(myPoint7, 7);
lMsh->AddPolygon(7);
lMsh->SetControlPointAt(myPoint8, 8);
lMsh->AddPolygon(8);
lMsh->EndPolygon();

bool ret = lMsh->SetPolyHoleInfo(1, true);

Unfortunately "SetPolyHoleInfo" ALWAYS returns "false" -> So it was unsuccessfull setting the HoleInfo 😞

 

Is my assumption, of what "SetPolyHoleInfo" is supposed to be used for wrong? Can anybody point me to a direction how I can create Polygons with holes in them?


Thank you so much!

0 Likes
956 Views
5 Replies
Replies (5)
Message 2 of 6

regalir
Autodesk
Autodesk

Hi,

 

The function expects to find an FbxLayerElementHole. If it doesn't it will fail and return false.

 

Your code should look similar to this:

 

 

FbxLayer* lLayer = pFbxMesh->GetLayer(0);
FbxLayerElementHole* lPolyHole = lLayer->GetHole();
if( !lPolyHole )
lPolyHole = FbxLayerElementHole::Create(pFbxMesh, "");
lLayer->SetHole( lPolyHole );

lPolyHole->SetMappingMode( FbxLayerElement::eByPolygon );
lPolyHole->SetReferenceMode( FbxLayerElement::eDirect );
lPolyHole->GetDirectArray().Resize( pFbxMesh->GetPolygonCount() );

FbxArray<bool> lHoleArray;
lHoleArray.Resize(pFbxMesh->GetPolygonCount());
for(unsigned int i = 0; i < lPolyHoleIDArray.length(); i++)
lHoleArray[lPolyHoleIDArray[i]] = true;

pFbxMesh->SetPolyHoleInfoArray(&lHoleArray);

 

lPolyHoleIDArray is the list of polygon ids that are holes.

 

Message 3 of 6

Anonymous
Not applicable

Hello regalir! Thank you so much for taking the time to look into this!

 

Unfortunately even with your help I seem to not be able to create actual holes. The function "SetPolygonHoleInfo" now does return TRUE - so I am able to successfully set the "Hole Info" - But I still see no holes in FBX Review. Consider the following example:

 

    FbxNode* lMeshNode = FbxNode::Create(m_pScene, "mynode");
    FbxMesh * lMsh = FbxMesh::Create(m_pScene, "mymesh");
    lMeshNode->AddNodeAttribute(lMsh);
    lMsh->BeginPolygon();
    lMsh->SetControlPointAt(FbxVector4( 50.0, -50.0, 0.0), 1);
    lMsh->AddPolygon(1);
    lMsh->SetControlPointAt(FbxVector4( 50.0,  50.0, 0.0), 2);
    lMsh->AddPolygon(2);
    lMsh->SetControlPointAt(FbxVector4(-50.0,  50.0, 0.0), 3);
    lMsh->AddPolygon(3);
    lMsh->SetControlPointAt(FbxVector4(-50.0, -50.0, 0.0), 4);
    lMsh->AddPolygon(4);
    lMsh->EndPolygon();

    lMsh->BeginPolygon();
    lMsh->SetControlPointAt(FbxVector4(-25.0,  25.0, 0.0), 5);
    lMsh->AddPolygon(5);
    lMsh->SetControlPointAt(FbxVector4( 25.0,  25.0, 0.0), 6);
    lMsh->AddPolygon(6);
    lMsh->SetControlPointAt(FbxVector4( 25.0, -25.0, 0.0), 7);
    lMsh->AddPolygon(7);
    lMsh->SetControlPointAt(FbxVector4(-25.0, -25.0, 0.0), 8);
    lMsh->AddPolygon(8);
    lMsh->EndPolygon();

    FbxLayer* lLayer = lMsh->GetLayer(0);
    FbxLayerElementHole* lPolyHole = lLayer->GetHole();
    if( !lPolyHole )
        lPolyHole = FbxLayerElementHole::Create(lMsh, "");
    lLayer->SetHole( lPolyHole );
    lPolyHole->SetMappingMode( FbxLayerElement::eByPolygon );
    lPolyHole->SetReferenceMode( FbxLayerElement::eDirect );
    lPolyHole->GetDirectArray().Resize( lMsh->GetPolygonCount() );
    bool result = lMsh->SetPolyHoleInfo(1, true);

    FbxNode *lRootNode = m_pScene->GetRootNode();
    lRootNode->AddChild(lMeshNode);

What I would expect to see is a rectangle with a rectangular hole in the middle:

image.png

 

However, the second polygon is still not cut from the first polygon when I view it in FBXReview. I have also tried running the Points of the "Hole" Clock- and Counterclockwise. The only difference it produces is from which side the "hole" polygon is visible.

 

What am I still missing here?

 

Again thanks for taking the time! It is greatly appreciated 🙂

0 Likes
Message 4 of 6

regalir
Autodesk
Autodesk

FBXReview does not implement the code to display holes so you cannot use it to view your meshes with holes (it does, however, work if the meshes have been properly tesselated).

0 Likes
Message 5 of 6

Anonymous
Not applicable

So I guess this must mean that my way of tesselating using the FBX SDK is off aswell 😞

 

I simply did this:

    FbxNode* lMeshNode = FbxNode::Create(m_pScene, "mynode");
    FbxMesh * lMsh = FbxMesh::Create(m_pScene, "mymesh");
    lMeshNode->AddNodeAttribute(lMsh);
    lMsh->BeginPolygon();
    lMsh->SetControlPointAt(FbxVector4( 50.0, -50.0, 0.0), 1);
    lMsh->AddPolygon(1);
    lMsh->SetControlPointAt(FbxVector4( 50.0,  50.0, 0.0), 2);
    lMsh->AddPolygon(2);
    lMsh->SetControlPointAt(FbxVector4(-50.0,  50.0, 0.0), 3);
    lMsh->AddPolygon(3);
    lMsh->SetControlPointAt(FbxVector4(-50.0, -50.0, 0.0), 4);
    lMsh->AddPolygon(4);
    lMsh->EndPolygon();

    lMsh->BeginPolygon();
    lMsh->SetControlPointAt(FbxVector4(-25.0,  25.0, 0.0), 5);
    lMsh->AddPolygon(5);
    lMsh->SetControlPointAt(FbxVector4( 25.0,  25.0, 0.0), 6);
    lMsh->AddPolygon(6);
    lMsh->SetControlPointAt(FbxVector4( 25.0, -25.0, 0.0), 7);
    lMsh->AddPolygon(7);
    lMsh->SetControlPointAt(FbxVector4(-25.0, -25.0, 0.0), 8);
    lMsh->AddPolygon(8);
    lMsh->EndPolygon();

    FbxLayer* lLayer = lMsh->GetLayer(0);
    FbxLayerElementHole* lPolyHole = lLayer->GetHole();
    if( !lPolyHole )
        lPolyHole = FbxLayerElementHole::Create(lMsh, "");
    lLayer->SetHole( lPolyHole );
    lPolyHole->SetMappingMode( FbxLayerElement::eByPolygon );
    lPolyHole->SetReferenceMode( FbxLayerElement::eDirect );
    lPolyHole->GetDirectArray().Resize( lMsh->GetPolygonCount() );
    bool result = lMsh->SetPolyHoleInfo(1, true);

    FbxNode *lRootNode = m_pScene->GetRootNode();
    lRootNode->AddChild(lMeshNode);
    FbxGeometryConverter Triangulator(m_pSdkManager);
    bool success =  Triangulator.Triangulate(m_pScene, true);

This is the same example as before, only with the last two lines for tesselation / triangulation added.

 

Did I get this wrong aswell? It does return "true" when called, however the holes don't seem to be regarded as holes.

 

I have noticed that in older versions of the SDK there were separate routines available, some specifically mentioning the support of holes. This seems to have been merged into one "Triangulate" routine - however, no holes in the output 😞

 

Do I need to do the Triangulation "by hand" instead of using the SDK functionalities?

 

Regards,

elstev

0 Likes
Message 6 of 6

regalir
Autodesk
Autodesk

Hi,

 

the Triangulation function inside the FBX SDK does not consider the holes information of the FbxMesh data structure so you are better doing the triangulation by hand.

0 Likes