Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1
Chapter 12 ■ 3D MoDel Design anD priMitives: Using JavaFX 9 shape3D Classes

This TriangleMesh class (object) has one ObjectProperty vertexFormat property, which
will be used to specify the vertex format of this TriangleMesh, using the VertexFormat utility class, and therefore
this will be either VertexFormat.POINT_TEXCOORD or VertexFormat.POINT_NORMAL_TEXCOORD.
A TriangleMesh class has two overloaded constructor methods. The first (empty) one creates an
instance of TriangleMesh class using the default VertexFormat.POINT_TEXCOORD format type and looks
like the following:


triangleMesh = new TriangleMesh(); // Creates Points & Texture Map Only Polygonal Mesh Object


The second constructor method creates a new instance of TriangleMesh using the VertexFormat that is
specified in the parameter area of the method call. This looks like the following Java instantiation statement:


normalTriangleMesh = new TriangleMesh(VertexFormat.POINT_NORMAL_TEXCOORD) // Includes Normals


There are a dozen methods used for working with TriangleMesh object construction; let’s look at
them next.
The .getFaceElementSize() method will return the number of elements that represent a given face. Use
this method to determine what data (point, normal, texturemap) is being used for any given face.
The ObservableFaceArray getFaces() method will get the entire array of faces in a TriangleMesh object,
including indices into the points, normals (only if VertexFormat.POINT_NORMAL_TEXCOORD is specified
for a mesh), and texCoords arrays. Use this to extract the polygon data from your TriangleMesh object.
The ObservableIntegerArray getFaceSmoothingGroups() method will get a faceSmoothingGroups
data array from a TriangleMesh object. Smoothing groups define where seams appear in your surface
shading (smoothing) for the rendered 3D object. We covered this topic earlier in the book in Chapter 3.
The .getNormalElementSize() method will return the number of elements that represent a normal in
your TriangleMesh object. This tells you how many normals are being used to represent surface direction.
The ObservableFloatArray getNormals() method will get your normals array for a TriangleMesh
object.
The .getPointElementSize() method will return the number of elements representing XYZ points
in your TriangleMesh object. This will tell you how many vertices (vertex count) in the 3D model in your
TriangleMesh.
The ObservableFloatArray getPoints() method is used to get the points data array for a TriangleMesh.
The .getTexCoordElementSize() method will return a number of data elements that represent texture
coordinates within a TextureMesh object. Use this to determine the number of UV mapping coordinates in
the model.
The ObservableFloatArray getTexCoords() method will get your texCoords array for your
TriangleMesh object. Use this to extract the texture coordinate data (only) from your TextureMesh 3D
polygonal object.
The VertexFormat getVertexFormat() method will get the value of your vertexFormat property from
inside your TriangleMesh object. Use this to ascertain if Normals are supported (or not) with this 3D model
data.
The void .setVertexFormat(VertexFormat value) method is used to set the value of the vertexFormat
property for the TriangleMesh object. Be sure the data arrays inside the object match up correctly with this
setting.
The ObjectProperty vertexFormatProperty() method can be used to specify the
vertex format for the TriangleMesh; it can be either VertexFormat.POINT_TEXCOORD or VertexFormat.
POINT_NORMAL_TEXCOORD.
After we learn more about shaders, textures, and mapping in the next chapter, we’ll get into 3D software
and learn the import workflow that allows us to bridge powerful 3D software over to the JavaFX 9 game
engine.

Free download pdf