Understanding Mesh Control Points

Understanding Mesh Control Points

Anonymous
Not applicable
1,797 Views
3 Replies
Message 1 of 4

Understanding Mesh Control Points

Anonymous
Not applicable

Hi,

 

I'm trying to write some code to export a scene.  I'm looking at ExportScene03 in the samples.  I'm trying to understand why control points are repeated in the control point array.  From the example:

 

lControlPoints[0] = lControlPoint0;
lControlPoints[1] = lControlPoint1;
lControlPoints[2] = lControlPoint2;
lControlPoints[3] = lControlPoint3;
lControlPoints[4] = lControlPoint1;
lControlPoints[5] = lControlPoint5;
lControlPoints[6] = lControlPoint6;
lControlPoints[7] = lControlPoint2;
lControlPoints[8] = lControlPoint5;
lControlPoints[9] = lControlPoint4;
lControlPoints[10] = lControlPoint7;
lControlPoints[11] = lControlPoint6;
lControlPoints[12] = lControlPoint4;
lControlPoints[13] = lControlPoint0;
lControlPoints[14] = lControlPoint3;
lControlPoints[15] = lControlPoint7;
lControlPoints[16] = lControlPoint3;
lControlPoints[17] = lControlPoint2;
lControlPoints[18] = lControlPoint6;
lControlPoints[19] = lControlPoint7;
lControlPoints[20] = lControlPoint1;
lControlPoints[21] = lControlPoint0;
lControlPoints[22] = lControlPoint4;
lControlPoints[23] = lControlPoint5;

 

 

Later in the example, every four points are added as a polygon:

 

// Array of polygon vertices.
int lPolygonVertices[] = { 0, 1, 2, 3,
4, 5, 6, 7,
8, 9, 10, 11,
12, 13, 14, 15,
16, 17, 18, 19,
20, 21, 22, 23 };

...

// Create polygons. Assign texture and texture UV indices.
for(i = 0; i < 6; i++)
{
   //we won't use the default way of assigning textures, as we have
   //textures on more than just the default (diffuse) channel.
   lMesh->BeginPolygon(-1, -1, false);

   for(j = 0; j < 4; j++)
   {
      //this function points
      lMesh->AddPolygon(lPolygonVertices[i*4 + j]); // Control point index.
      ...
   }
   lMesh->EndPolygon ();
}

Since we're making a cube, in reality there are only 8 vertices. Could this example have been modified to only load the 8 vertices as control points and selectively address them when forming the polygons? Do polygon vertices need to reference consecutive control points?

 

Thanks,

 

0 Likes
1,798 Views
3 Replies
Replies (3)
Message 2 of 4

regalir
Autodesk
Autodesk

Hi Andrew,

 

to answer your questions:

 

Could this example have been modified to only load the 8 vertices as control points and selectively address them when forming the polygons?

 

Yes, of course. For example, this code snipped below is a different way to define a cube (and totally valid - of course, you need to make sure the Normals and uvs data reflects what you want to achieve)

 

FbxMesh* test = FbxMesh::Create(lScene, "testCube");
test->InitControlPoints(8);
FbxVector4* ctrlPts = test->GetControlPoints();
ctrlPts[0] = FbxVector4(0, 0, 0);
ctrlPts[1] = FbxVector4(1, 0, 0);
ctrlPts[2] = FbxVector4(1, 0, 1);
ctrlPts[3] = FbxVector4(0, 0, 1);
ctrlPts[4] = FbxVector4(0, 1, 0);
ctrlPts[5] = FbxVector4(1, 1, 0);
ctrlPts[6] = FbxVector4(1, 1, 1);
ctrlPts[7] = FbxVector4(0, 1, 1);

test->BeginPolygon(); test->AddPolygon(0); test->AddPolygon(1); test->AddPolygon(2); test->AddPolygon(3);
test->EndPolygon(); test->BeginPolygon(); test->AddPolygon(0); test->AddPolygon(4); test->AddPolygon(5); test->AddPolygon(1); test->EndPolygon();
test->BeginPolygon(); test->AddPolygon(1); test->AddPolygon(2); test->AddPolygon(6); test->AddPolygon(5); test->EndPolygon(); test->BeginPolygon(); test->AddPolygon(2); test->AddPolygon(3); test->AddPolygon(7); test->AddPolygon(6); test->EndPolygon(); test->BeginPolygon(); test->AddPolygon(3); test->AddPolygon(0); test->AddPolygon(4); test->AddPolygon(7); test->EndPolygon(); test->BeginPolygon(); test->AddPolygon(4); test->AddPolygon(5); test->AddPolygon(6); test->AddPolygon(7); test->EndPolygon();

Do polygon vertices need to reference consecutive control points?

 

Not at all! You can see in the example above that all the "side" polygons of the cube definition are referencing the the control points that are not consecutive.

 

0 Likes
Message 3 of 4

Anonymous
Not applicable

Thanks,

 

This is very helpful.  Is there a reason the example was written as it was?  Does it provide any advantage to code you've provided?

 

0 Likes
Message 4 of 4

regalir
Autodesk
Autodesk

Hi,

 

this particular sample code implemented what we can call a: "beginner's straightforward approach". As you saw, there are multiple ways to use the FBX SDK and we tried to show them as simply as possible. ExportScene03 shows one way of creating a polygon mesh while my code snipped (and the Layers example) show the more "optimized" one 🙂

 

As you may have figured out, the approach in ExportScene03 is not optimal and uses more memory than necessary. However, it would be the good one if, at some point, you want do "explode" all the faces (since each polygon has its own set of control points).

 

 

0 Likes