java.lang.Object
com.marginallyclever.ro3.mesh.Mesh
Mesh
contains the vertex data for a 3D model. It may also contain normal, color, and texture data.
It uses Vertex Array Objects and Vertex Buffer Objects to optimize rendering large collections of triangles.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
static final int
static final int
int
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addColor
(float r, float g, float b, float a) Add a color to the mesh.void
addIndex
(int n) void
addNormal
(float x, float y, float z) void
addTexCoord
(float u, float v) Add a texture coordinate to the mesh.void
addVertex
(float x, float y, float z) void
clear()
Remove all vertexes, normals, colors, texture coordinates, etc.boolean
boolean
boolean
boolean
javax.vecmath.Vector3d
getNormal
(int t) int
int
int
javax.vecmath.Vector3d
getVertex
(int t) Intersect a ray with this mesh.boolean
isDirty()
boolean
isLoaded()
boolean
void
render
(com.jogamp.opengl.GL3 gl) Render the entire mesh.void
render
(com.jogamp.opengl.GL3 gl, int startIndex, int count) Render a portion of the mesh.void
setDirty
(boolean isDirty) void
setLoaded
(boolean loaded) void
setRenderStyle
(int style) void
setSourceName
(String filename) void
setVertex
(int i, double x, double y, double z) void
unload
(com.jogamp.opengl.GL3 gl) Destroy the optimized rendering buffers for the fixed function pipeline.void
Force recalculation of the minimum bounding box to contain this STL file.void
updateVertexBuffers
(com.jogamp.opengl.GL3 gl3)
-
Field Details
-
NUM_BUFFERS
public static final int NUM_BUFFERS- See Also:
-
BYTES_PER_INT
public static final int BYTES_PER_INT- See Also:
-
BYTES_PER_FLOAT
public static final int BYTES_PER_FLOAT- See Also:
-
vertexArray
-
normalArray
-
colorArray
-
textureArray
-
indexArray
-
renderStyle
public int renderStyle
-
-
Constructor Details
-
Mesh
public Mesh() -
Mesh
public Mesh(int renderStyle)
-
-
Method Details
-
clear
public void clear()Remove all vertexes, normals, colors, texture coordinates, etc. on the next call torender(GL3)
the mesh will be rebuilt to nothing. See alsounload(GL3)
-
setSourceName
-
getSourceName
-
isLoaded
public boolean isLoaded() -
setLoaded
public void setLoaded(boolean loaded) -
isTransparent
public boolean isTransparent() -
unload
public void unload(com.jogamp.opengl.GL3 gl) Destroy the optimized rendering buffers for the fixed function pipeline. This does not free the memory used by the mesh. See alsoclear()
- Parameters:
gl
- the OpenGL context
-
render
public void render(com.jogamp.opengl.GL3 gl) Render the entire mesh.- Parameters:
gl
- the OpenGL context
-
render
public void render(com.jogamp.opengl.GL3 gl, int startIndex, int count) Render a portion of the mesh.- Parameters:
gl
- the OpenGL contextstartIndex
- index of the first vertex to viewportcount
- number of vertices to viewport
-
addNormal
public void addNormal(float x, float y, float z) -
addVertex
public void addVertex(float x, float y, float z) -
addColor
public void addColor(float r, float g, float b, float a) Add a color to the mesh.- Parameters:
r
- red, 0-1g
- green, 0-1b
- blue, 0-1a
- alpha, 0-1
-
addTexCoord
public void addTexCoord(float u, float v) Add a texture coordinate to the mesh.- Parameters:
u
- 0-1v
- 0-1
-
addIndex
public void addIndex(int n) -
updateCuboid
public void updateCuboid()Force recalculation of the minimum bounding box to contain this STL file. Done automatically every time updateBuffers() is called. Meaningless if there is no vertexArray of points. -
getBoundingBox
- Returns:
- axially-aligned bounding box in the mesh's local space.
-
getNumTriangles
public int getNumTriangles() -
getNumVertices
public int getNumVertices() -
getVertex
public javax.vecmath.Vector3d getVertex(int t) -
getNormal
public javax.vecmath.Vector3d getNormal(int t) -
isDirty
public boolean isDirty() -
setDirty
public void setDirty(boolean isDirty) -
getHasNormals
public boolean getHasNormals() -
getHasColors
public boolean getHasColors() -
getHasTextures
public boolean getHasTextures() -
getHasIndexes
public boolean getHasIndexes() -
setRenderStyle
public void setRenderStyle(int style) -
getRenderStyle
public int getRenderStyle() -
intersect
Intersect a ray with this mesh.- Parameters:
ray
- The ray to intersect with.- Returns:
- The RayHit object containing the intersection point and normal, or null if no intersection.
-
setVertex
public void setVertex(int i, double x, double y, double z) -
updateVertexBuffers
public void updateVertexBuffers(com.jogamp.opengl.GL3 gl3)
-