public class TriangleGroup extends Group implements Selectable
Triangles may be specified by providing an array of packed vertex (x,y,z) coordinates and an array of packed (i,j,k) vertex indices. Each triplet (i,j,k) of vertex indices corresponds to one triangle.
Alternatively, triangles may be specified by providing only the array of packed vertex (x,y,z) coordinates. In this case, a vertex index is assigned automatically to each vertex.
Normal vectors are computed for each vertex as an area-weighted average of the vectors normal to all triangles that reference that vertex with the same index. These area-weighted normal vectors are used in lighting.
Constructor and Description |
---|
TriangleGroup(boolean vn,
float[] xyz)
Constructs a triangle group with specified vertex coordinates.
|
TriangleGroup(boolean vn,
float[] xyz,
float[] rgb)
Constructs a triangle group with specified vertex coordinates.
|
TriangleGroup(boolean vn,
Sampling sx,
Sampling sy,
float[][] z)
Constructs a triangle group for a sampled function z = f(x,y).
|
TriangleGroup(boolean vn,
Sampling sx,
Sampling sy,
float[][] z,
float[][] r,
float[][] g,
float[][] b)
Constructs a triangle group for a sampled function z = f(x,y).
|
TriangleGroup(float[] xyz,
float[] uvw)
Constructs a triangle group with specified vertex coordinates.
|
TriangleGroup(float[] xyz,
float[] uvw,
float[] rgb)
Constructs a triangle group with specified vertex coordinates
and optional corresponding normal vectors and colors.
|
TriangleGroup(int[] ijk,
float[] xyz)
Constructs a triangle group with specified vertex coordinates.
|
TriangleGroup(int[] ijk,
float[] xyz,
float[] uvw)
Constructs a triangle group with specified vertex coordinates.
|
TriangleGroup(int[] ijk,
float[] xyz,
float[] uvw,
float[] rgb)
Constructs a triangle group with specified vertex coordinates
and optional corresponding normal vectors and colors.
|
Modifier and Type | Method and Description |
---|---|
static int[] |
indexVertices(boolean sequential,
float[] xyz)
Computes indices ijk for triangle vertex coordinates xyz.
|
protected void |
selectedChanged()
This method is called when the selected state of this node has changed.
|
void |
setColor(java.awt.Color color)
Sets the color of the triangles in this triangle group.
|
addChild, computeBoundingSphere, countChildren, cull, draw, getAttributeBits, getChildren, pick, removeChild
countParents, cullApply, cullBegin, cullEnd, dirtyBoundingSphere, dirtyDraw, drawApply, drawBegin, drawEnd, getBoundingSphere, getParents, getStates, getWorld, isSelected, pickApply, pickBegin, pickEnd, setSelected, setStates
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
isSelected, setSelected
public TriangleGroup(boolean vn, float[] xyz)
The (x,y,z) coordinates of vertices are packed into the specified array xyz. The number of vertices is nv = xyz.length/3. The number of triangles is nt = nv/3 = xyz.length/9.
Normal vectors may be computed for either vertices or triangles. When computed for a vertex, a normal vector is the area-weighted average of the normal vectors for all triangles with that vertex.
If no vertices have the same (x,y,z) coordinates, then vertex and triangle normal vectors are the same vectors, but triangle normal vectors are less costly to compute.
vn
- true, for vertex normals; false, for triangle normals.xyz
- array[3*nv] of packed vertex coordinates.public TriangleGroup(boolean vn, float[] xyz, float[] rgb)
The (x,y,z) coordinates of vertices are packed into the specified array xyz. The number of vertices is nv = xyz.length/3. The number of triangles is nt = nv/3 = xyz.length/9.
The (r,g,b) components of colors are packed into the specified array rgb. The number of colors equals the number of vertices.
Normal vectors may be computed for either vertices or triangles. When computed for a vertex, a normal vector is the area-weighted average of the normal vectors for all triangles with that vertex.
If no vertices have the same (x,y,z) coordinates, then vertex and triangle normal vectors are the same vectors, but triangle normal vectors are less costly to compute.
vn
- true, for vertex normals; false, for triangle normals.xyz
- array[3*nv] of packed vertex coordinates.rgb
- array[3*nv] of packed color components.public TriangleGroup(boolean vn, Sampling sx, Sampling sy, float[][] z)
vn
- true, for vertex normals; false, for triangle normals.sx
- sampling of x coordinates; may be non-uniform.sy
- sampling of y coordinates; may be non-uniform.z
- array[nx][ny] of z coordinates z = f(x,y).public TriangleGroup(boolean vn, Sampling sx, Sampling sy, float[][] z, float[][] r, float[][] g, float[][] b)
vn
- true, for vertex normals; false, for triangle normals.sx
- sampling of x coordinates; may be non-uniform.sy
- sampling of y coordinates; may be non-uniform.z
- array[nx][ny] of z coordinates z = f(x,y).r
- array[nx][ny] of red color components.g
- array[nx][ny] of green color components.b
- array[nx][ny] of blue color components.public TriangleGroup(int[] ijk, float[] xyz)
Triangles are specified by triplets of vertex indices (i,j,k), one triplet per triangle, packed into the specified array of integers ijk. The number of triangles is nt = ijk.length/3.
The (x,y,z) coordinates of vertices are packed into the specified array xyz. The number of vertices is nv = xyz.length/3.
For any vertex with index iv, this method computes a normal vector as an area-weighted average of the normal vectors for all triangles specified with index iv.
ijk
- array[3*nt] of packed vertex indices.xyz
- array[3*nv] of packed vertex coordinates.public TriangleGroup(float[] xyz, float[] uvw)
The (x,y,z) coordinates of vertices are packed into the specified array xyz. The number of vertices is nv = xyz.length/3.
The (u,v,w) components of normal vectors are packed into the specified array uvw. The number of normal vectors equals the number of vertices.
xyz
- array[3*nv] of packed vertex coordinates.uvw
- array[3*nv] of packed normal vector components.public TriangleGroup(int[] ijk, float[] xyz, float[] uvw)
Triangles are specified by triplets of vertex indices (i,j,k), one triplet per triangle, packed into the specified array of integers ijk. The number of triangles is nt = ijk.length/3.
The (x,y,z) coordinates of vertices are packed into the specified array xyz. The number of vertices is nv = xyz.length/3.
The (u,v,w) components of normal vectors are packed into the specified array uvw. The number of normal vectors equals the number of vertices.
ijk
- array[3*nt] of packed vertex indices.xyz
- array[3*nv] of packed vertex coordinates.uvw
- array[3*nv] of packed normal vector components.public TriangleGroup(float[] xyz, float[] uvw, float[] rgb)
The (x,y,z) coordinates of vertices are packed into the specified array xyz. The number of vertices is nv = xyz.length/3.
The (u,v,w) components of normal vectors are packed into the specified array uvw. The number of normal vectors equals the number of vertices.
The (r,g,b) components of colors are packed into the specified array rgb. The number of colors equals the number of vertices.
xyz
- array[3*nv] of packed vertex coordinates.uvw
- array[3*nv] of packed normal vector components.rgb
- array[3*nv] of packed color components.public TriangleGroup(int[] ijk, float[] xyz, float[] uvw, float[] rgb)
Triangles are specified by triplets of vertex indices (i,j,k), one triplet per triangle, packed into the specified array of integers ijk. The number of triangles is nt = ijk.length/3.
The (x,y,z) coordinates of vertices are packed into the specified array xyz. The number of vertices is nv = xyz.length/3.
The (u,v,w) components of normal vectors are packed into the specified array uvw. If not null, the number of normal vectors equals the number of vertices.
The (r,g,b) components of colors are packed into the specified array rgb. If not null, the number of colors equals the number of vertices.
ijk
- array[3*nt] of packed vertex indices.xyz
- array[3*nv] of packed vertex coordinates.uvw
- array[3*nv] of packed normal vector components.rgb
- array[3*nv] of packed color components.public static int[] indexVertices(boolean sequential, float[] xyz)
The (x,y,z) coordinates of vertices are packed into the specified array xyz. The number of vertices is nv = xyz.length/3. The number of triangles is nt = nv/3 = xyz.length/9.
For each triangle, this method computes a triplet (i,j,k) of integer vertex indices. A vertex index is an integer in the range [0,nv-1]. The (x,y,z) coordinates of a vertex with index iv are xyz[3*iv+0], xyz[3*iv+1] and xyz[3*iv+2], respectively.
The simplest indexing is the sequence {0, 1, 2, ..., nv-1}. In this case, indices are assigned sequentially, so that every vertex of every triangle has a different index.
In non-sequential indexing, vertices with the same (x,y,z) coordinates are assigned the same index. Again, index vertices will be in the range [0,nv-1], but some integers in this range may not be used. Whereas sequential indexing would assign integers ia and ib to two vertices that have the same (x,y,z) coordinates, non-sequential indexing will assign the smaller index min(ia,ib) to both vertices; the larger index max(ia,ib) will be unused.
Triplets of indices (i,j,k), one triplet per triangle, are packed into the returned array of integers ijk, which has length 3*nt.
sequential
- true, for sequential indexing; false, otherwise.xyz
- array[3*nv] of packed vertex coordinates.public void setColor(java.awt.Color color)
color
- the color.protected void selectedChanged()
Node
This implementation does nothing.
selectedChanged
in class Node