|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objecttoxi.geom.util.TriangleMesh
public class TriangleMesh
A class to dynamically build, manipulate & export triangle meshes. Meshes are build face by face. The class automatically re-uses existing vertices and can create smooth vertex normals. Vertices and faces are directly accessible for speed & convenience.
Nested Class Summary | |
---|---|
static class |
TriangleMesh.Face
|
static class |
TriangleMesh.Vertex
|
Field Summary | |
---|---|
java.util.ArrayList<TriangleMesh.Face> |
faces
Face list |
java.lang.String |
name
Mesh name |
java.util.LinkedHashMap<Vec3D,TriangleMesh.Vertex> |
vertices
Vertex buffer & lookup index when adding new faces |
Constructor Summary | |
---|---|
TriangleMesh()
|
|
TriangleMesh(java.lang.String name)
Creates a new mesh instance with an initial buffer size of 1000 vertices & 3000 faces. |
|
TriangleMesh(java.lang.String name,
int numV,
int numF)
Creates a new mesh instance with the given initial buffer sizes. |
Method Summary | |
---|---|
void |
addFace(Vec3D a,
Vec3D b,
Vec3D c)
Adds the given 3 points as triangle face to the mesh. |
AABB |
center(Vec3D origin)
Centers the mesh around the given pivot point (the centroid of its AABB). |
void |
clear()
Clears all counters, and vertex & face buffers. |
void |
computeVertexNormals()
Computes the smooth vertex normals for the entire mesh. |
TriangleMesh |
copy()
Creates a deep clone of the mesh. |
AABB |
getBoundingBox()
Computes & returns the axis-aligned bounding box of the mesh. |
Sphere |
getBoundingSphere()
Computes & returns the bounding sphere of the mesh. |
Vec3D |
getCentroid()
Computes the mesh centroid, the average position of all vertices. |
int[] |
getFacesAsArray()
Builds an array of vertex indices of all faces. |
float[] |
getMeshAsVertexArray()
Creates an array of unravelled vertex coordinates for all faces using a stride setting of 3, resulting in a gap-less serialized version of all mesh vertex coordinates. |
float[] |
getMeshAsVertexArray(float[] verts,
int offset,
int stride)
Creates an array of unravelled vertex coordinates for all faces. |
int |
getNumFaces()
Returns the number of triangles used. |
int |
getNumVertices()
Returns the number of actual vertices used (unique vertices). |
float[] |
getUniqueVerticesAsArray()
|
float[] |
getVertexNormalsAsArray()
|
float[] |
getVertexNormalsAsArray(float[] normals,
int offset,
int stride)
Creates an array of unravelled vertex normal coordinates for all faces. |
void |
saveAsOBJ(OBJWriter obj)
Saves the mesh as OBJ format by appending it to the given mesh OBJWriter instance. |
void |
saveAsOBJ(java.lang.String path)
Saves the mesh as OBJ format to the given file path. |
void |
saveAsRaw(java.lang.String fileName)
Saves the mesh in a simple, proprietary compact binary format written using the standard DataOutputStream methods. |
void |
saveAsSTL(java.lang.String fileName)
Saves the mesh as binary STL format to the given file path. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public java.lang.String name
public final java.util.LinkedHashMap<Vec3D,TriangleMesh.Vertex> vertices
public final java.util.ArrayList<TriangleMesh.Face> faces
Constructor Detail |
---|
public TriangleMesh()
public TriangleMesh(java.lang.String name)
name
- mesh namepublic TriangleMesh(java.lang.String name, int numV, int numF)
name
- mesh namenumV
- initial vertex buffer sizenumF
- initial face list sizeMethod Detail |
---|
public final void addFace(Vec3D a, Vec3D b, Vec3D c)
a
- b
- c
- public AABB center(Vec3D origin)
origin
- new centroid or null (defaults to {0,0,0})public void clear()
public void computeVertexNormals()
public TriangleMesh copy()
public AABB getBoundingBox()
public Sphere getBoundingSphere()
public Vec3D getCentroid()
public int[] getFacesAsArray()
vertices
HashMap. The
resulting array will be 3 times the face count.
public float[] getMeshAsVertexArray()
getMeshAsVertexArray(float[], int, int)
public float[] getMeshAsVertexArray(float[] verts, int offset, int stride)
verts
- an existing target array or null to automatically create oneoffset
- start index in arrtay to place verticesstride
- stride/alignment setting for individual coordinates
public int getNumFaces()
public int getNumVertices()
public float[] getUniqueVerticesAsArray()
public float[] getVertexNormalsAsArray()
getVertexNormalsAsArray(float[], int, int)
public float[] getVertexNormalsAsArray(float[] normals, int offset, int stride)
getMeshAsVertexArray(float[], int, int)
normals
- existing float array or null to automatically create oneoffset
- start index in array to place normalsstride
- stride/alignment setting for individual coordinates
getMeshAsVertexArray(float[], int, int)
public void saveAsOBJ(OBJWriter obj)
OBJWriter
instance.
obj
- public void saveAsOBJ(java.lang.String path)
path
- public final void saveAsRaw(java.lang.String fileName)
DataOutputStream
methods. The format is as
follows:
fileName
- public final void saveAsSTL(java.lang.String fileName)
fileName
- public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |