java.lang.Object
com.marginallyclever.ro3.mesh.Mesh
Direct Known Subclasses:
Box, CircleXY, Cylinder, Decal, Grid, Sphere

public class Mesh extends Object

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 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

      public final transient List<Float> vertexArray
    • normalArray

      public final transient List<Float> normalArray
    • colorArray

      public final transient List<Float> colorArray
    • textureArray

      public final transient List<Float> textureArray
    • indexArray

      public final transient List<Integer> 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 to render(GL3) the mesh will be rebuilt to nothing. See also unload(GL3)
    • setSourceName

      public void setSourceName(String filename)
    • getSourceName

      public String 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 also clear()
      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 context
      startIndex - index of the first vertex to viewport
      count - 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-1
      g - green, 0-1
      b - blue, 0-1
      a - alpha, 0-1
    • addTexCoord

      public void addTexCoord(float u, float v)
      Add a texture coordinate to the mesh.
      Parameters:
      u - 0-1
      v - 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

      public AABB 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

      public RayHit intersect(Ray ray)
      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)