Class IntMeshPart

java.lang.Object
gaiasky.util.gdx.model.IntMeshPart

public class IntMeshPart
extends java.lang.Object
A libgdx MeshPart which uses IntMesh (for integer indices) instead of a regular Mesh A MeshPart is composed of a subset of vertices of a IntMesh, along with the primitive type. The vertices subset is described by an offset and size. When the mesh is indexed (which is when IntMesh.getNumIndices() > 0), then the offset represents the offset in the indices array and size represents the number of indices. When the mesh isn't indexed, then the offset member represents the offset in the vertices array and the size member represents the number of vertices. In other words: Regardless whether the mesh is indexed or not, when primitiveType is not a strip, then size equals the number of primitives multiplied by the number of vertices per primitive. So if the MeshPart represents 4 triangles ( primitiveType is GL_TRIANGLES), then the size member is 12 (4 triangles * 3 vertices = 12 vertices total). Likewise, if the part represents 12 lines (primitiveType is GL_LINES), then the size is 24 (12 lines * 2 vertices = 24 vertices total). Note that some classes might require the mesh (part) to be indexed. The IntMesh referenced by the mesh member must outlive the MeshPart. When the mesh is disposed, the MeshPart is unusable.
  • Field Summary

    Fields
    Modifier and Type Field Description
    com.badlogic.gdx.math.Vector3 center
    The offset to the center of the bounding box of the shape, only valid after the call to update().
    com.badlogic.gdx.math.Vector3 halfExtents
    The location, relative to center, of the corner of the axis aligned bounding box of the shape.
    java.lang.String id
    Unique id within model, may be null.
    IntMesh mesh
    The Mesh the part references, also stored in IntModel
    int offset
    The offset in the mesh to this part.
    int primitiveType
    The primitive type, OpenGL constant e.g: GL20.GL_TRIANGLES, GL20.GL_POINTS, GL20.GL_LINES, GL20.GL_LINE_STRIP, GL20.GL_TRIANGLE_STRIP
    float radius
    The radius relative to center of the bounding sphere of the shape, or negative if not calculated yet.
    int size
    The size (in total number of vertices) of this part in the mesh.
  • Constructor Summary

    Constructors
    Constructor Description
    IntMeshPart()
    Construct a new MeshPart, with null values.
    IntMeshPart​(IntMeshPart copyFrom)
    Construct a new MeshPart which is an exact copy of the provided MeshPart.
    IntMeshPart​(java.lang.String id, IntMesh mesh, int offset, int size, int type)
    Construct a new MeshPart and set all its values.
  • Method Summary

    Modifier and Type Method Description
    boolean equals​(IntMeshPart other)
    Compares this MeshPart to the specified MeshPart and returns true if they both reference the same IntMesh and the offset, size and primitiveType members are equal.
    boolean equals​(java.lang.Object arg0)  
    void render​(ExtShaderProgram shader)
    Renders the mesh part using the specified shader, must be called in between ExtShaderProgram.begin() and ExtShaderProgram.end().
    void render​(ExtShaderProgram shader, boolean autoBind)
    Renders the mesh part using the specified shader, must be called in between ExtShaderProgram.begin() and ExtShaderProgram.end().
    IntMeshPart set​(IntMeshPart other)
    Set this MeshPart to be a copy of the other MeshPart
    IntMeshPart set​(java.lang.String id, IntMesh mesh, int offset, int size, int type)
    Set this MeshPart to given values, does not update() the bounding box values.
    void update()
    Calculates and updates the center, halfExtents and radius values.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • id

      public java.lang.String id
      Unique id within model, may be null. Will be ignored by equals(IntMeshPart)
    • primitiveType

      public int primitiveType
      The primitive type, OpenGL constant e.g: GL20.GL_TRIANGLES, GL20.GL_POINTS, GL20.GL_LINES, GL20.GL_LINE_STRIP, GL20.GL_TRIANGLE_STRIP
    • offset

      public int offset
      The offset in the mesh to this part. If the mesh is indexed (Mesh.getNumIndices() > 0), this is the offset in the indices array, otherwise it is the offset in the vertices array.
    • size

      public int size
      The size (in total number of vertices) of this part in the mesh. When the mesh is indexed ( Mesh.getNumIndices() > 0), this is the number of indices, otherwise it is the number of vertices.
    • mesh

      public IntMesh mesh
      The Mesh the part references, also stored in IntModel
    • center

      public final com.badlogic.gdx.math.Vector3 center
      The offset to the center of the bounding box of the shape, only valid after the call to update().
    • halfExtents

      public final com.badlogic.gdx.math.Vector3 halfExtents
      The location, relative to center, of the corner of the axis aligned bounding box of the shape. Or, in other words: half the dimensions of the bounding box of the shape, where Vector3.x is half the width, Vector3.y is half the height and Vector3.z is half the depth. Only valid after the call to update().
    • radius

      public float radius
      The radius relative to center of the bounding sphere of the shape, or negative if not calculated yet. This is the same as the length of the halfExtents member. See update().
  • Constructor Details

    • IntMeshPart

      public IntMeshPart()
      Construct a new MeshPart, with null values. The MeshPart is unusable until you set all members.
    • IntMeshPart

      public IntMeshPart​(java.lang.String id, IntMesh mesh, int offset, int size, int type)
      Construct a new MeshPart and set all its values.
      Parameters:
      id - The id of the new part, may be null.
      mesh - The mesh which holds all vertices and (optional) indices of this part.
      offset - The offset within the mesh to this part.
      size - The size (in total number of vertices) of the part.
      type - The primitive type of the part (e.g. GL_TRIANGLES, GL_LINE_STRIP, etc.).
    • IntMeshPart

      public IntMeshPart​(IntMeshPart copyFrom)
      Construct a new MeshPart which is an exact copy of the provided MeshPart.
      Parameters:
      copyFrom - The MeshPart to copy.
  • Method Details

    • set

      public IntMeshPart set​(IntMeshPart other)
      Set this MeshPart to be a copy of the other MeshPart
      Parameters:
      other - The MeshPart from which to copy the values
      Returns:
      this MeshPart, for chaining
    • set

      public IntMeshPart set​(java.lang.String id, IntMesh mesh, int offset, int size, int type)
      Set this MeshPart to given values, does not update() the bounding box values.
      Returns:
      this MeshPart, for chaining.
    • update

      public void update()
      Calculates and updates the center, halfExtents and radius values. This is considered a costly operation and should not be called frequently. All vertices (points) of the shape are traversed to calculate the maximum and minimum x, y and z coordinate of the shape. Note that MeshPart is not aware of any transformation that might be applied when rendering. It calculates the untransformed (not moved, not scaled, not rotated) values.
    • equals

      public boolean equals​(IntMeshPart other)
      Compares this MeshPart to the specified MeshPart and returns true if they both reference the same IntMesh and the offset, size and primitiveType members are equal. The id member is ignored.
      Parameters:
      other - The other IntMeshPart to compare this IntMeshPart to.
      Returns:
      True when this IntMeshPart equals the other IntMeshPart (ignoring the id member), false otherwise.
    • equals

      public boolean equals​(java.lang.Object arg0)
      Overrides:
      equals in class java.lang.Object
    • render

      public void render​(ExtShaderProgram shader, boolean autoBind)
      Renders the mesh part using the specified shader, must be called in between ExtShaderProgram.begin() and ExtShaderProgram.end().
      Parameters:
      shader - the shader to be used
      autoBind - overrides the autoBind member of the Mesh
    • render

      public void render​(ExtShaderProgram shader)
      Renders the mesh part using the specified shader, must be called in between ExtShaderProgram.begin() and ExtShaderProgram.end().
      Parameters:
      shader - the shader to be used