public class TriangleMesh extends Mesh
VertexFormat
and a set of separate arrays of vertex components such as points, normals,
texture coordinates, and an array of faces that define the individual triangles
of the mesh.
Note that the term point, as used in the method names and method descriptions, actually refers to a 3D point (x, y, z) in space representing the position of a single vertex. The term points (plural) is used to indicate sets of 3D points for multiple vertices. Similarly, the term normal is used to indicate a 3D vector (nx, ny, nz) in space representing the direction of a single vertex. The term normals (plural) is used to indicate sets of 3D vectors for multiple vertices. The term texCoord is used to indicate a single pair of 2D texture coordinates (u, v) for a single vertex, while the term texCoords (plural) is used to indicate sets of texture coordinates for multiple vertices. Lastly, the term face is used to indicate 3 sets of interleaving points, normals (optional, depending on the associated VertexFormat) and texture coordinates that together represent the geometric topology of a single triangle, while the term faces (plural) is used to indicate sets of triangles (each represent by a face).
For example, the faces with VertexFormat.POINT_TEXCOORD
that represent
a single textured rectangle, using 2 triangles, have the following data order: [
p0, t0, p1, t1, p3, t3, // First triangle of a textured rectangle
p1, t1, p2, t2, p3, t3 // Second triangle of a textured rectangle
]
whereas the faces with VertexFormat.POINT_NORMAL_TEXCOORD
that represent
a single textured rectangle, using 2 triangles, have the following data order: [
p0, n0, t0, p1, n1, t1, p3, n3, t3, // First triangle of a textured rectangle
p1, n1, t1, p2, n2, t2, p3, n3, t3 // Second triangle of a textured rectangle
]
where p0, p1, p2 and p3 are indices into the points array, n0, n1, n2 and n3 are indices into the normals array, and t0, t1, t2 and t3 are indices into the texCoords array.
A triangle has a front and back face. The winding order of a triangle's vertices
determines which side is the front face. JavaFX chooses the counter-clockwise
(or right-hand rule) winding order as the front face. By default, only the
front face of a triangle is rendered. See CullFace
for more
information.
The length of points
, normals
, and texCoords
must be
divisible by 3, 3, and 2 respectively. The length of faces
must be
divisible by 6 if it is of VertexFormat.POINT_TEXCOORD
else it must
be divisible by 9 if it is of VertexFormat.POINT_NORMAL_TEXCOORD
.
The values in the faces array must be within the range of the number of vertices
in the points array (0 to points.length / 3 - 1) for the point indices, within
the range of the number of vertices in the normals array
(0 to normals.length / 3 - 1) for the normal indices, and within the range of
the number of the vertices in the texCoords array (0 to texCoords.length / 2 - 1)
for the texture coordinate indices.
A warning will be recorded to the logger and the mesh will not be rendered (and will have an empty bounds) if any of the array lengths are invalid or if any of the values in the faces array are out of range.
Type | Property and Description |
---|---|
<any> |
vertexFormat
Specifies the vertex format of this
TriangleMesh , one of
VertexFormat.POINT_TEXCOORD or VertexFormat.POINT_NORMAL_TEXCOORD . |
dirtyProperty
Modifier and Type | Class and Description |
---|---|
private class |
TriangleMesh.Listener<T extends <any>> |
Modifier and Type | Field and Description |
---|---|
private BaseBounds |
cachedBounds |
private ObservableFaceArray |
faces |
private ObservableIntegerArray |
faceSmoothingGroups |
private TriangleMesh.Listener |
faceSmoothingGroupsSyncer |
private TriangleMesh.Listener |
facesSyncer |
private boolean |
isFaceSmoothingGroupValid |
private boolean |
isFacesValid |
private boolean |
isNormalsValid |
private boolean |
isPointsValid |
private boolean |
isPredefinedShape |
private boolean |
isTexCoordsValid |
private boolean |
isValidDirty |
private ObservableFloatArray |
normals |
private TriangleMesh.Listener |
normalsSyncer |
private NGTriangleMesh |
peer |
private ObservableFloatArray |
points |
private TriangleMesh.Listener |
pointsSyncer |
private int |
refCount |
private ObservableFloatArray |
texCoords |
private TriangleMesh.Listener |
texCoordsSyncer |
private <any> |
vertexFormat
Specifies the vertex format of this
TriangleMesh , one of
VertexFormat.POINT_TEXCOORD or VertexFormat.POINT_NORMAL_TEXCOORD . |
Constructor and Description |
---|
TriangleMesh()
Creates a new instance of
TriangleMesh class with the default
VertexFormat.POINT_TEXCOORD format type. |
TriangleMesh(boolean isPredefinedShape) |
TriangleMesh(VertexFormat vertexFormat)
Creates a new instance of
TriangleMesh class with the specified
VertexFormat . |
Modifier and Type | Method and Description |
---|---|
(package private) BaseBounds |
computeBounds(BaseBounds bounds) |
private Point3D |
computeCentroid(double v0x,
double v0y,
double v0z,
double v1x,
double v1y,
double v1z,
double v2x,
double v2y,
double v2z)
Computes the centroid of the given triangle
|
private Point2D |
computeCentroid(Point2D v0,
Point2D v1,
Point2D v2)
Computes the centroid of the given triangle
|
private boolean |
computeIntersectsFace(PickRay pickRay,
Vec3d origin,
Vec3d dir,
int faceIndex,
CullFace cullFace,
Node candidate,
boolean reportFace,
PickResultChooser result)
Computes intersection of a pick ray and a single triangle face.
|
(package private) void |
decRef() |
private boolean |
doComputeIntersects(PickRay pickRay,
PickResultChooser pickResult,
Node candidate,
CullFace cullFace,
boolean reportFace) |
int |
getFaceElementSize()
Returns the number of elements that represents a face.
|
ObservableFaceArray |
getFaces()
Gets the
faces array, indices into the points ,
normals (optional, if it is a VertexFormat.POINT_NORMAL_TEXCOORD
mesh) and texCoords arrays, of this TriangleMesh . |
ObservableIntegerArray |
getFaceSmoothingGroups()
Gets the
faceSmoothingGroups array of this TriangleMesh . |
int |
getNormalElementSize()
Returns the number of elements that represents a normal.
|
ObservableFloatArray |
getNormals()
Gets the
normals array of this TriangleMesh . |
(package private) NGTriangleMesh |
getPGMesh() |
(package private) NGTriangleMesh |
getPGTriangleMesh() |
int |
getPointElementSize()
Returns the number of elements that represents a point.
|
ObservableFloatArray |
getPoints()
Gets the
points array of this TriangleMesh . |
(package private) int |
getRefCount() |
int |
getTexCoordElementSize()
Returns the number of elements that represents a texture coordinates.
|
ObservableFloatArray |
getTexCoords()
Gets the
texCoords array of this TriangleMesh . |
VertexFormat |
getVertexFormat()
Gets the value of the property vertexFormat.
|
(package private) void |
incRef() |
(package private) void |
setDirty(boolean value) |
void |
setVertexFormat(VertexFormat value)
Sets the value of the property vertexFormat.
|
(package private) void |
updatePG() |
private boolean |
validate() |
private boolean |
validateFaces() |
private boolean |
validateFaceSmoothingGroups() |
private boolean |
validateNormals() |
private boolean |
validatePoints() |
private boolean |
validateTexCoords() |
<any> |
vertexFormatProperty()
Specifies the vertex format of this
TriangleMesh , one of
VertexFormat.POINT_TEXCOORD or VertexFormat.POINT_NORMAL_TEXCOORD . |
dirtyProperty, isDirty
public final <any> vertexFormatProperty
TriangleMesh
, one of
VertexFormat.POINT_TEXCOORD
or VertexFormat.POINT_NORMAL_TEXCOORD
.getVertexFormat()
,
setVertexFormat(VertexFormat)
private final ObservableFloatArray points
private final ObservableFloatArray normals
private final ObservableFloatArray texCoords
private final ObservableFaceArray faces
private final ObservableIntegerArray faceSmoothingGroups
private final TriangleMesh.Listener pointsSyncer
private final TriangleMesh.Listener normalsSyncer
private final TriangleMesh.Listener texCoordsSyncer
private final TriangleMesh.Listener facesSyncer
private final TriangleMesh.Listener faceSmoothingGroupsSyncer
private final boolean isPredefinedShape
private boolean isValidDirty
private boolean isPointsValid
private boolean isNormalsValid
private boolean isTexCoordsValid
private boolean isFacesValid
private boolean isFaceSmoothingGroupValid
private int refCount
private BaseBounds cachedBounds
private <any> vertexFormat
TriangleMesh
, one of
VertexFormat.POINT_TEXCOORD
or VertexFormat.POINT_NORMAL_TEXCOORD
.private NGTriangleMesh peer
public TriangleMesh()
TriangleMesh
class with the default
VertexFormat.POINT_TEXCOORD
format type.public TriangleMesh(VertexFormat vertexFormat)
TriangleMesh
class with the specified
VertexFormat
.vertexFormat
- specifies the vertex format type.TriangleMesh(boolean isPredefinedShape)
public final void setVertexFormat(VertexFormat value)
public final VertexFormat getVertexFormat()
public final <any> vertexFormatProperty()
TriangleMesh
, one of
VertexFormat.POINT_TEXCOORD
or VertexFormat.POINT_NORMAL_TEXCOORD
.getVertexFormat()
,
setVertexFormat(VertexFormat)
public final int getPointElementSize()
public final int getNormalElementSize()
public final int getTexCoordElementSize()
public final int getFaceElementSize()
public final ObservableFloatArray getPoints()
points
array of this TriangleMesh
.points
array where each point is
represented by 3 float values x, y and z, in that order.public final ObservableFloatArray getNormals()
normals
array of this TriangleMesh
.normals
array where each normal is
represented by 3 float values nx, ny and nz, in that order.public final ObservableFloatArray getTexCoords()
texCoords
array of this TriangleMesh
.
The coordinates are proportional, so texture's top-left corner
is at [0, 0] and bottom-right corner is at [1, 1].texCoord
array where each texture coordinate is represented
by 2 float values: u and v, in that order.public final ObservableFaceArray getFaces()
faces
array, indices into the points
,
normals
(optional, if it is a VertexFormat.POINT_NORMAL_TEXCOORD
mesh) and texCoords
arrays, of this TriangleMesh
. All
indices are in terms of elements in to the points, normals or texCoords
arrays not individual floats.faces
array where each face is of
3 * VertexFormat.getVertexIndexSize()
integers.public final ObservableIntegerArray getFaceSmoothingGroups()
faceSmoothingGroups
array of this TriangleMesh
.
Smoothing affects how a mesh is rendered but it does not effect its
geometry. The face smoothing group value is used to control the smoothing
between adjacent faces.
The face smoothing group value is represented by an array of bits and up to 32 unique groups is possible; (1 << 0) to (1 << 31). The face smoothing group value can range from 0 (no smoothing group) to all 32 groups. A face can belong to zero or more smoothing groups. A face is a member of group N if bit N is set, for example, groups |= (1 << N). A value of 0 implies no smoothing group or hard edges. Smoothing is applied when adjacent pair of faces shared a smoothing group. Otherwise the faces are rendered with a hard edge between them.
An empty faceSmoothingGroups implies all faces in this mesh have a smoothing group value of 1.
If faceSmoothingGroups is not empty, its size must be equal to number of faces.
This faceSmoothingGroups has no effect on its TriangleMesh
if
it is of VertexFormat.POINT_NORMAL_TEXCOORD
format.
faceSmoothingGroups
array of this TriangleMesh
int getRefCount()
void incRef()
void decRef()
NGTriangleMesh getPGTriangleMesh()
private boolean validatePoints()
private boolean validateNormals()
private boolean validateTexCoords()
private boolean validateFaces()
private boolean validateFaceSmoothingGroups()
private boolean validate()
BaseBounds computeBounds(BaseBounds bounds)
computeBounds
in class Mesh
private Point3D computeCentroid(double v0x, double v0y, double v0z, double v1x, double v1y, double v1z, double v2x, double v2y, double v2z)
v0x
- x coord of first vertex of the trianglev0y
- y coord of first vertex of the trianglev0z
- z coord of first vertex of the trianglev1x
- x coord of second vertex of the trianglev1y
- y coord of second vertex of the trianglev1z
- z coord of second vertex of the trianglev2x
- x coord of third vertex of the trianglev2y
- y coord of third vertex of the trianglev2z
- z coord of third vertex of the triangleprivate Point2D computeCentroid(Point2D v0, Point2D v1, Point2D v2)
v0
- vertex of the trianglev1
- vertex of the trianglev2
- vertex of the triangleprivate boolean computeIntersectsFace(PickRay pickRay, Vec3d origin, Vec3d dir, int faceIndex, CullFace cullFace, Node candidate, boolean reportFace, PickResultChooser result)
pickRay
- pick rayorigin
- pick ray's origindir
- pick ray's directionfaceIndex
- index of the face to testcullFace
- cull face of the Node (and thus the tested face)candidate
- the owner node (for the possible placement to the result)reportFace
- whether or not to report he hit faceresult
- the pick result to be updated if a closer intersection is foundprivate boolean doComputeIntersects(PickRay pickRay, PickResultChooser pickResult, Node candidate, CullFace cullFace, boolean reportFace)