In this section, we create objects that will be used to define the cube’s vertices, faces, and normals.
The following code creates eight points in 3D space that define the eight corners of a cube. These corners are the control points (vertices) of the mesh:
KFbxVector4 lControlPoint0(-50, 0, 50);
KFbxVector4 lControlPoint1(50, 0, 50);
KFbxVector4 lControlPoint2(50, 100, 50);
KFbxVector4 lControlPoint3(-50, 100, 50);
KFbxVector4 lControlPoint4(-50, 0, -50);
KFbxVector4 lControlPoint5(50, 0, -50);
KFbxVector4 lControlPoint6(50, 100, -50);
KFbxVector4 lControlPoint7(-50, 100, -50);
Here we define six normals, one for each face of the cube:
KFbxVector4 lNormalXPos(1, 0, 0);
KFbxVector4 lNormalXNeg(-1, 0, 0);
KFbxVector4 lNormalYPos(0, 1, 0);
KFbxVector4 lNormalYNeg(0, -1, 0);
KFbxVector4 lNormalZPos(0, 0, 1);
KFbxVector4 lNormalZNeg(0, 0, -1);
Here we tell the mesh object that it needs 24 control points, four control points for each of the cube’s six faces:
// Create control points.
lMesh->InitControlPoints(24);
Here we get a pointer to the mesh’s array of 24 control points:
KFbxVector4* lControlPoints = lMesh->GetControlPoints();
Here we set the values of the mesh’s control point array, one face at a time:
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;