Java Reference
In-Depth Information
ObservableFaceArray getFaces()
•
ObservableIntegerArray getFaceSmoothingGroups()
•
int getPointElementSize()
•
int getTexCoordElementSize()
•
int getFaceElementSize()
The
getPoints()
method returns an
ObservableFloatArray
, which you can use to add three-dimensional vertex
coordinates. This observable float array's size must be a multiple of 3, and the elements of the array are interpreted as
x0
,
y0
,
z0
,
x1
,
y1
,
z1
, … , where (
x0
,
y0
,
z0
) are the coordinates of the first vertex
p0
, (
x1
,
y1
,
z1
) are the coordinates of
the second vertex
p1
, and so on.
The
getTexCoords()
method returns an
ObservableFloatArray
, which you can use to add two-dimensional
texture coordinates. This observable float array's size must be a multiple of 2, and the elements of the array are
interpreted as
u0
,
v0
,
u1
,
v1
, … , where (
u0
,
v0
) is the first texture point, (
u1
,
v1
) is the second texture point, and so on.
We cover texture coordinates in more detail in the materials section. For now it is sufficient to understand the texture
coordinates as points in a two-dimensional image with a top left point that has coordinates (0, 0) and a bottom right
point that has coordinates (1, 1).
The
getFaces()
method returns an
ObservableFaceArray
, which you can use to add faces to the 3D shape. The
ObservableFaceArray
is a subinterface of the
ObservableIntegerArray
interface. This array's size must be a multiple
of 6, and the elements of the array are interpreted as
p0
,
t0
,
p1
,
t1
,
p2
,
t2
,
p3
,
t3
,
p4
,
t4
,
p5
,
t5
, . . . , where
p0
,
t0
,
p1
,
t1
,
p2
,
t2
defines the first face,
p3
,
t3
,
p4
,
t4
,
p5
,
t5
defines the second face, and so on. Of the six ints that define a face, the
p
values are indices into the conceptual points array, which is one-third the length of the actual points array because
we consider three float elements from the actual points array as constituting one conceptual point; and the
t
values
are indices into the conceptual texture coordinates array, which is one-half the length of the actual texture coordinates
array because we consider two float elements from the actual texture coordinates array as constituting one conceptual
texture coordinates pair.
The
getFaceSmoothingGroups()
method returns an
ObservableIntegerArray
, which you can use to define
smoothing groups for the faces of the 3D shape. You can leave this array empty, in which case the JavaFX runtime
will consider all faces of the 3D shape as belonging to one and the same smoothing group, resulting in a 3D shape
with a surface that is smooth everywhere. Such is the case for the underlying
TriangleMesh
of the
Sphere
predefined
3D shape. If you fill this array, then you must fill it with the same number of elements as there are conceptual faces,
which is one-sixth of the length of the actual faces array because we consider six int elements from the actual faces
array as constituting one conceptual face. Each element in the face smoothing group array represents one face of the
3D shape, and two faces belong to the same smoothing group if and only if their representations share a common
on bit when each int value is viewed as 32 individual bits. There could be at most 32 face smoothing groups in a
TriangleMesh
.
The
getPointElementSize()
method always returns 3. The
getTexCoordElementSize()
method always returns
2. The
getFaceElementSize()
method always returns 6.
Each face in a 3D shape has two sides. In 3D graphics programming, it is important to distinguish these two
sides as either the front side or the back side. JavaFX 3D uses the counterclockwise winding order to define the
front side. Imagine yourself standing on one side of the triangle, and trace the edges of the triangle according to
the order in which each vertex appears in the definition of the face. If it appears that you are tracing the edges in a
counterclockwise fashion, then you are standing on the front side of the face. This concept of front side and back
side of faces is what
CullFace.FRONT
and
CullFace.BACK
enum declarators refer to. By default,
Shape3D
uses the
CullFace.BACK
setting, which means the back sides of faces are not rendered.
The program in Listing 10-4 illustrates the use of a user-defined 3D shape in JavaFX.
•
Search WWH ::
Custom Search