|
||||||||||
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
An extensible class to dynamically build, manipulate & export triangle meshes. Meshes are built face by face. This implementation automatically re-uses existing vertices and can generate smooth vertex normals. Vertice and face lists are directly accessible for speed & convenience.
Field Summary | |
---|---|
static int |
DEFAULT_NUM_FACES
Default size for face list |
static int |
DEFAULT_NUM_VERTICES
Default size for vertex list |
static int |
DEFAULT_STRIDE
Default stride setting used for serializing mesh properties into arrays. |
java.util.ArrayList<Face> |
faces
Face list |
java.lang.String |
name
Mesh name |
java.util.LinkedHashMap<Vec3D,Vertex> |
vertices
Vertex buffer & lookup index when adding new faces |
Constructor Summary | |
---|---|
TriangleMesh()
|
|
TriangleMesh(java.lang.String name)
Creates a new mesh instance with initial default buffer sizes. |
|
TriangleMesh(java.lang.String name,
int numV,
int numF)
Creates a new mesh instance with the given initial buffer sizes. |
Method Summary | |
---|---|
TriangleMesh |
addFace(Vec3D a,
Vec3D b,
Vec3D c)
Adds the given 3 points as triangle face to the mesh. |
TriangleMesh |
addFace(Vec3D a,
Vec3D b,
Vec3D c,
Vec2D uvA,
Vec2D uvB,
Vec2D uvC)
Adds the given 3 points as triangle face to the mesh and assigns the given texture coordinates to each vertex. |
TriangleMesh |
addFace(Vec3D a,
Vec3D b,
Vec3D c,
Vec3D n)
|
TriangleMesh |
addFace(Vec3D a,
Vec3D b,
Vec3D c,
Vec3D n,
Vec2D uvA,
Vec2D uvB,
Vec2D uvC)
|
TriangleMesh |
addMesh(Mesh3D m)
Adds all faces from the given mesh to this one. |
AABB |
center(ReadonlyVec3D origin)
Centers the mesh around the given pivot point (the centroid of its AABB). |
TriangleMesh |
clear()
Clears all counters, and vertex & face buffers. |
Vec3D |
computeCentroid()
Computes the mesh centroid, the average position of all vertices. |
TriangleMesh |
computeFaceNormals()
Re-calculates all face normals. |
TriangleMesh |
computeVertexNormals()
Computes the smooth vertex normals for the entire mesh. |
TriangleMesh |
copy()
Creates a deep clone of the mesh. |
TriangleMesh |
faceOutwards()
Changes the vertex order of faces such that their normal is facing away from the mesh centroid. |
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. |
Vertex |
getClosestVertexToPoint(ReadonlyVec3D p)
|
float[] |
getFaceNormalsAsArray()
Creates an array of unravelled normal coordinates. |
float[] |
getFaceNormalsAsArray(float[] normals,
int offset,
int stride)
Creates an array of unravelled normal coordinates. |
java.util.List<Face> |
getFaces()
|
int[] |
getFacesAsArray()
Builds an array of vertex indices of all faces. |
IsectData3D |
getIntersectionData()
|
float[] |
getMeshAsVertexArray()
Creates an array of unravelled vertex coordinates for all faces using a stride setting of 4, resulting in a serialized version of all mesh vertex coordinates suitable for VBOs. |
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). |
TriangleMesh |
getRotatedAroundAxis(Vec3D axis,
float theta)
|
TriangleMesh |
getRotatedX(float theta)
|
TriangleMesh |
getRotatedY(float theta)
|
TriangleMesh |
getRotatedZ(float theta)
|
TriangleMesh |
getScaled(float scale)
|
TriangleMesh |
getScaled(Vec3D scale)
|
TriangleMesh |
getTranslated(Vec3D trans)
|
float[] |
getUniqueVerticesAsArray()
|
Vertex |
getVertexAtPoint(Vec3D v)
|
Vertex |
getVertexForID(int id)
|
float[] |
getVertexNormalsAsArray()
Creates an array of unravelled vertex normal coordinates for all faces. |
float[] |
getVertexNormalsAsArray(float[] normals,
int offset,
int stride)
Creates an array of unravelled vertex normal coordinates for all faces. |
java.util.Collection<Vertex> |
getVertices()
|
TriangleMesh |
init(java.lang.String name,
int numV,
int numF)
|
boolean |
intersectsRay(Ray3D ray)
Checks if entity intersects with the given ray. |
Triangle3D |
perforateFace(Face f,
float size)
|
TriangleMesh |
pointTowards(ReadonlyVec3D dir)
Rotates the mesh in such a way so that its "forward" axis is aligned with the given direction. |
TriangleMesh |
pointTowards(ReadonlyVec3D dir,
ReadonlyVec3D forward)
Rotates the mesh in such a way so that its "forward" axis is aligned with the given direction. |
void |
removeFace(Face f)
|
TriangleMesh |
rotateAroundAxis(Vec3D axis,
float theta)
|
TriangleMesh |
rotateX(float theta)
|
TriangleMesh |
rotateY(float theta)
|
TriangleMesh |
rotateZ(float theta)
|
void |
saveAsOBJ(OBJWriter obj)
Saves the mesh as OBJ format by appending it to the given mesh OBJWriter instance. |
void |
saveAsOBJ(java.io.OutputStream stream)
Saves the mesh as OBJ format to the given OutputStream . |
void |
saveAsOBJ(java.lang.String path)
Saves the mesh as OBJ format to the given file path. |
void |
saveAsSTL(java.io.OutputStream stream)
Saves the mesh as binary STL format to the given OutputStream . |
void |
saveAsSTL(java.io.OutputStream stream,
boolean useFlippedY)
Saves the mesh as binary STL format to the given OutputStream . |
void |
saveAsSTL(java.io.OutputStream stream,
STLWriter stl,
boolean useFlippedY)
Saves the mesh as binary STL format to the given OutputStream and
using the supplied STLWriter instance. |
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)
|
TriangleMesh |
scale(float scale)
|
TriangleMesh |
scale(Vec3D scale)
|
TriangleMesh |
setName(java.lang.String name)
|
java.lang.String |
toString()
|
WETriangleMesh |
toWEMesh()
|
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. |
TriangleMesh |
translate(Vec3D trans)
|
TriangleMesh |
updateVertex(Vec3D orig,
Vec3D newPos)
|
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int DEFAULT_NUM_VERTICES
public static final int DEFAULT_NUM_FACES
public static final int DEFAULT_STRIDE
public java.lang.String name
public java.util.LinkedHashMap<Vec3D,Vertex> vertices
public java.util.ArrayList<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 TriangleMesh addFace(Vec3D a, Vec3D b, Vec3D c)
Mesh3D
addFace
in interface Mesh3D
public TriangleMesh addFace(Vec3D a, Vec3D b, Vec3D c, Vec2D uvA, Vec2D uvB, Vec2D uvC)
Mesh3D
addFace
in interface Mesh3D
public TriangleMesh addFace(Vec3D a, Vec3D b, Vec3D c, Vec3D n)
addFace
in interface Mesh3D
public TriangleMesh addFace(Vec3D a, Vec3D b, Vec3D c, Vec3D n, Vec2D uvA, Vec2D uvB, Vec2D uvC)
addFace
in interface Mesh3D
public TriangleMesh addMesh(Mesh3D m)
addMesh
in interface Mesh3D
m
- source mesh instancepublic AABB center(ReadonlyVec3D origin)
Mesh3D
center
in interface Mesh3D
origin
- new centroid or null (defaults to {0,0,0})public TriangleMesh clear()
clear
in interface Mesh3D
public Vec3D computeCentroid()
Mesh3D
computeCentroid
in interface Mesh3D
public TriangleMesh computeFaceNormals()
computeFaceNormals
in interface Mesh3D
public TriangleMesh computeVertexNormals()
computeVertexNormals
in interface Mesh3D
public TriangleMesh copy()
public TriangleMesh faceOutwards()
Mesh3D
faceOutwards
in interface Mesh3D
public TriangleMesh flipVertexOrder()
Mesh3D
flipVertexOrder
in interface Mesh3D
public TriangleMesh flipYAxis()
Mesh3D
flipYAxis
in interface Mesh3D
public AABB getBoundingBox()
Mesh3D
getBoundingBox
in interface Mesh3D
public Sphere getBoundingSphere()
Mesh3D
getBoundingSphere
in interface Mesh3D
public Vertex getClosestVertexToPoint(ReadonlyVec3D p)
getClosestVertexToPoint
in interface Mesh3D
public float[] getFaceNormalsAsArray()
getFaceNormalsAsArray(float[], int, int)
with a
default stride = 4.
public float[] getFaceNormalsAsArray(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 java.util.List<Face> getFaces()
getFaces
in interface Mesh3D
public int[] getFacesAsArray()
vertices
HashMap. The
resulting array will be 3 times the face count.
public IsectData3D getIntersectionData()
getIntersectionData
in interface Intersector3D
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()
Mesh3D
getNumFaces
in interface Mesh3D
public int getNumVertices()
Mesh3D
getNumVertices
in interface Mesh3D
public TriangleMesh getRotatedAroundAxis(Vec3D axis, float theta)
public TriangleMesh getRotatedX(float theta)
public TriangleMesh getRotatedY(float theta)
public TriangleMesh getRotatedZ(float theta)
public TriangleMesh getScaled(float scale)
public TriangleMesh getScaled(Vec3D scale)
public TriangleMesh getTranslated(Vec3D trans)
public float[] getUniqueVerticesAsArray()
public Vertex getVertexAtPoint(Vec3D v)
public Vertex getVertexForID(int id)
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 java.util.Collection<Vertex> getVertices()
getVertices
in interface Mesh3D
public TriangleMesh init(java.lang.String name, int numV, int numF)
init
in interface Mesh3D
public boolean intersectsRay(Ray3D ray)
Intersector3D
IsectData3D
instance returned
by Intersector3D.getIntersectionData()
.
intersectsRay
in interface Intersector3D
ray
- ray to check
public Triangle3D perforateFace(Face f, float size)
public TriangleMesh pointTowards(ReadonlyVec3D dir)
dir
- new target direction to point in
public TriangleMesh pointTowards(ReadonlyVec3D dir, ReadonlyVec3D forward)
dir
- new target direction to point inforward
- current forward axis
public void removeFace(Face f)
public TriangleMesh rotateAroundAxis(Vec3D axis, float theta)
public TriangleMesh rotateX(float theta)
public TriangleMesh rotateY(float theta)
public TriangleMesh rotateZ(float theta)
public void saveAsOBJ(OBJWriter obj)
OBJWriter
instance.
obj
- public void saveAsOBJ(java.io.OutputStream stream)
OutputStream
. Currently
no texture coordinates are supported or written.
stream
- public void saveAsOBJ(java.lang.String path)
path
- public final void saveAsSTL(java.io.OutputStream stream)
OutputStream
.
stream
- saveAsSTL(OutputStream, boolean)
public final void saveAsSTL(java.io.OutputStream stream, boolean useFlippedY)
OutputStream
.
The exported mesh can optionally have it's Y axis flipped by setting the
useFlippedY flag to true.
stream
- useFlippedY
- public final void saveAsSTL(java.io.OutputStream stream, STLWriter stl, boolean useFlippedY)
OutputStream
and
using the supplied STLWriter
instance. Use this method to export
data in a custom STLColorModel
. The exported mesh can optionally
have it's Y axis flipped by setting the useFlippedY flag to true.
stream
- stl
- useFlippedY
- 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 TriangleMesh scale(float scale)
public TriangleMesh scale(Vec3D scale)
public TriangleMesh setName(java.lang.String name)
setName
in interface Mesh3D
public java.lang.String toString()
toString
in class java.lang.Object
public WETriangleMesh toWEMesh()
public TriangleMesh transform(Matrix4x4 mat)
mat
-
public TriangleMesh transform(Matrix4x4 mat, boolean updateNormals)
mat
- updateNormals
-
public TriangleMesh translate(Vec3D trans)
public TriangleMesh updateVertex(Vec3D orig, Vec3D newPos)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |