|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objecttoxi.geom.mesh.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. |
void |
addMesh(TriangleMesh m)
Adds all faces from the given mesh to this one. |
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. |
TriangleMesh |
computeFaceNormals()
Re-calculates all face normals. |
void |
computeVertexNormals()
Computes the smooth vertex normals for the entire mesh. |
TriangleMesh |
copy()
Creates a deep clone of the mesh. |
TriangleMesh |
flipVertexOrder()
Flips the vertex ordering between clockwise and anti-clockwise. |
TriangleMesh |
flipYAxis()
Flips all vertices along the Y axis and reverses the vertex ordering of all faces to compensate and keep the direction of normals intact. |
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. |
TriangleMesh |
pointTowards(Vec3D dir)
Rotates the mesh in such a way so that its "forward" axis is aligned with the given direction. |
TriangleMesh |
pointTowards(Vec3D dir,
Vec3D forward)
Rotates the mesh in such a way so that its "forward" axis is aligned with the given direction. |
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. |
void |
saveAsSTL(java.lang.String fileName,
boolean useFlippedY)
Saves the mesh as binary STL format to the given file path. |
void |
saveAsSTL(java.lang.String fileName,
STLWriter stl,
boolean useFlippedY)
|
java.lang.String |
toString()
|
TriangleMesh |
transform(Matrix4x4 mat)
Applies the given matrix transform to all mesh vertices and updates all face normals. |
TriangleMesh |
transform(Matrix4x4 mat,
boolean updateNormals)
Applies the given matrix transform to all mesh vertices. |
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 void addFace(Vec3D a, Vec3D b, Vec3D c)
a
- b
- c
- public void addMesh(TriangleMesh m)
m
- source mesh instancepublic AABB center(Vec3D origin)
origin
- new centroid or null (defaults to {0,0,0})public void clear()
public TriangleMesh computeFaceNormals()
public void computeVertexNormals()
public TriangleMesh copy()
public TriangleMesh flipVertexOrder()
public TriangleMesh flipYAxis()
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 (min value
= 3)
getMeshAsVertexArray(float[], int, int)
public TriangleMesh pointTowards(Vec3D dir)
dir
- new target direction to point in
public TriangleMesh pointTowards(Vec3D dir, Vec3D forward)
dir
- new target direction to point inforward
- current forward axis
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 final void saveAsSTL(java.lang.String fileName, boolean useFlippedY)
fileName
- useFlippedY
- public final void saveAsSTL(java.lang.String fileName, STLWriter stl, boolean useFlippedY)
public java.lang.String toString()
toString
in class java.lang.Object
public TriangleMesh transform(Matrix4x4 mat)
mat
-
public TriangleMesh transform(Matrix4x4 mat, boolean updateNormals)
mat
- updateNormals
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |