Class MeshData

java.lang.Object
com.ardor3d.scenegraph.MeshData
All Implemented Interfaces:
Savable

public class MeshData extends Object implements Savable
MeshData contains all the commonly used buffers for rendering a mesh.
  • Field Details

    • _vertexCount

      protected int _vertexCount
      Number of vertices represented by this data.
    • _primitiveCounts

      protected transient int[] _primitiveCounts
      Number of primitives represented by this data.
    • _vertexCoords

      protected FloatBufferData _vertexCoords
      Buffer data holding buffers and number of coordinates per vertex
    • _normalCoords

      protected FloatBufferData _normalCoords
    • _colorCoords

      protected FloatBufferData _colorCoords
    • _fogCoords

      protected FloatBufferData _fogCoords
    • _tangentCoords

      protected FloatBufferData _tangentCoords
    • _textureCoords

      protected List<FloatBufferData> _textureCoords
    • _indexBuffer

      protected IndexBufferData<?> _indexBuffer
      Index data.
    • _indexLengths

      protected int[] _indexLengths
    • _indexModes

      protected IndexMode[] _indexModes
  • Constructor Details

    • MeshData

      public MeshData()
  • Method Details

    • getVertexCount

      public int getVertexCount()
      Gets the vertex count.
      Returns:
      the vertex count
    • getVertexBuffer

      public FloatBuffer getVertexBuffer()
      Gets the vertex buffer.
      Returns:
      the vertex buffer
    • setVertexBuffer

      public void setVertexBuffer(FloatBuffer vertexBuffer)
      Sets the vertex buffer.
      Parameters:
      vertexBuffer - the new vertex buffer
    • getVertexCoords

      public FloatBufferData getVertexCoords()
      Gets the vertex coords.
      Returns:
      the vertex coords
    • setVertexCoords

      public void setVertexCoords(FloatBufferData bufferData)
      Sets the vertex coords.
      Parameters:
      bufferData - the new vertex coords
    • getNormalBuffer

      public FloatBuffer getNormalBuffer()
      Gets the normal buffer.
      Returns:
      the normal buffer
    • setNormalBuffer

      public void setNormalBuffer(FloatBuffer normalBuffer)
      Sets the normal buffer.
      Parameters:
      normalBuffer - the new normal buffer
    • getNormalCoords

      public FloatBufferData getNormalCoords()
      Gets the normal coords.
      Returns:
      the normal coords
    • setNormalCoords

      public void setNormalCoords(FloatBufferData bufferData)
      Sets the normal coords.
      Parameters:
      bufferData - the new normal coords
    • getColorBuffer

      public FloatBuffer getColorBuffer()
      Gets the color buffer.
      Returns:
      the color buffer
    • setColorBuffer

      public void setColorBuffer(FloatBuffer colorBuffer)
      Sets the color buffer.
      Parameters:
      colorBuffer - the new color buffer
    • getColorCoords

      public FloatBufferData getColorCoords()
      Gets the color coords.
      Returns:
      the color coords
    • setColorCoords

      public void setColorCoords(FloatBufferData bufferData)
      Sets the color coords.
      Parameters:
      bufferData - the new color coords
    • getFogBuffer

      public FloatBuffer getFogBuffer()
      Gets the fog buffer.
      Returns:
      the fog buffer
    • setFogBuffer

      public void setFogBuffer(FloatBuffer fogBuffer)
      Sets the fog buffer.
      Parameters:
      fogBuffer - the new fog buffer
    • getFogCoords

      public FloatBufferData getFogCoords()
      Gets the fog coords.
      Returns:
      the fog coords
    • setFogCoords

      public void setFogCoords(FloatBufferData bufferData)
      Sets the fog coords.
      Parameters:
      bufferData - the new fog coords
    • getTangentBuffer

      public FloatBuffer getTangentBuffer()
      Gets the tangent buffer.
      Returns:
      the tangent buffer
    • setTangentBuffer

      public void setTangentBuffer(FloatBuffer tangentBuffer)
      Sets the tangent buffer.
      Parameters:
      tangentBuffer - the new tangent buffer
    • getTangentCoords

      public FloatBufferData getTangentCoords()
      Gets the tangent coords.
      Returns:
      the tangent coords
    • setTangentCoords

      public void setTangentCoords(FloatBufferData bufferData)
      Sets the tangent coords.
      Parameters:
      bufferData - the new tangent coords
    • getTextureBuffer

      public FloatBuffer getTextureBuffer(int index)
      Gets the FloatBuffer of the FloatBufferData set on a given texture unit.
      Parameters:
      index - the unit index
      Returns:
      the texture buffer for the given index, or null if none was set.
    • setTextureBuffer

      public void setTextureBuffer(FloatBuffer textureBuffer, int index)
      Sets the texture buffer for a given texture unit index. Interprets it as a 2 component float buffer data. If you need other sizes, use setTextureCoords instead.
      Parameters:
      textureBuffer - the texture buffer
      index - the unit index
      See Also:
    • getTextureCoords

      public List<FloatBufferData> getTextureCoords()
      Gets the texture coords.
      Returns:
      the texture coords
    • getTextureCoords

      public FloatBufferData getTextureCoords(int index)
      Gets the texture coords assigned to a specific texture unit index of this MeshData.
      Parameters:
      index - the texture unit index
      Returns:
      the texture coords
    • setTextureCoords

      public void setTextureCoords(List<FloatBufferData> textureCoords)
      Sets all texture coords on this MeshData.
      Parameters:
      textureCoords - the new texture coords
    • setTextureCoords

      public void setTextureCoords(FloatBufferData textureCoords, int index)
      Sets the texture coords of a specific texture unit index to the given FloatBufferData.
      Parameters:
      textureCoords - the texture coords
      index - the unit index
    • updateVertexCount

      public void updateVertexCount()
      Update the vertex count based on the current limit of the vertex buffer.
    • copyTextureCoordinates

      public void copyTextureCoordinates(int fromIndex, int toIndex, float factor)
      copyTextureCoords copies the texture coordinates of a given texture unit to another location. If the texture unit is not valid, then the coordinates are ignored. Coords are multiplied by the given factor.
      Parameters:
      fromIndex - the coordinates to copy.
      toIndex - the texture unit to set them to. Must not be the same as the fromIndex.
      factor - a multiple to apply when copying
    • copyTextureCoordinates

      public void copyTextureCoordinates(int fromIndex, int toIndex, float factorS, float factorT)
      copyTextureCoords copies the texture coordinates of a given texture unit to another location. If the texture unit is not valid, then the coordinates are ignored. Coords are multiplied by the given S and T factors.
      Parameters:
      fromIndex - the coordinates to copy.
      toIndex - the texture unit to set them to. Must not be the same as the fromIndex.
      factorS - a multiple to apply to the S channel when copying
      factorT - a multiple to apply to the T channel when copying
    • getNumberOfUnits

      public int getNumberOfUnits()
      getNumberOfUnits returns the number of texture units this geometry is currently using.
      Returns:
      the number of texture units in use.
    • getIndexBuffer

      public Buffer getIndexBuffer()
      Gets the index buffer.
      Returns:
      the index buffer
    • setIndexBuffer

      public void setIndexBuffer(IntBuffer indices)
      Sets the index buffer.
      Parameters:
      indices - the new index buffer
    • setIndexBuffer

      public void setIndexBuffer(ShortBuffer indices)
      Sets the index buffer.
      Parameters:
      indices - the new index buffer
    • setIndexBuffer

      public void setIndexBuffer(ByteBuffer indices)
      Sets the index buffer.
      Parameters:
      indices - the new index buffer
    • getIndices

      public IndexBufferData<?> getIndices()
      Gets the indices.
      Returns:
      the indices
    • setIndices

      public void setIndices(IndexBufferData<?> bufferData)
      Sets the indices
      Parameters:
      bufferData - the new indices
    • getIndexMode

      @Deprecated public IndexMode getIndexMode()
      Deprecated.
      Please switch to getIndexMode(int)
      Gets the index mode.
      Returns:
      the IndexMode of the first section of this MeshData.
    • setIndexMode

      public void setIndexMode(IndexMode indexMode)
      Sets the index mode.
      Parameters:
      indexMode - the new IndexMode to use for the first section of this MeshData.
    • getIndexLengths

      public int[] getIndexLengths()
      Gets the index lengths.
      Returns:
      the index lengths
    • setIndexLengths

      public void setIndexLengths(int[] indexLengths)
      Sets the index lengths.
      Parameters:
      indexLengths - the new index lengths
    • getIndexModes

      public IndexMode[] getIndexModes()
      Gets the index modes.
      Returns:
      the index modes
    • getIndexMode

      public IndexMode getIndexMode(int sectionIndex)
      Gets the index mode.
      Parameters:
      sectionIndex - the section index
      Returns:
      the index mode
    • setIndexModes

      public void setIndexModes(IndexMode[] indexModes)
      Note: Also updates primitive counts.
      Parameters:
      indexModes - the index modes to use for this MeshData.
    • getSectionCount

      public int getSectionCount()
      Gets the section count.
      Returns:
      the number of sections (lengths, indexModes, etc.) this MeshData contains.
    • getTotalPrimitiveCount

      public int getTotalPrimitiveCount()
      Gets the total primitive count.
      Returns:
      the sum of the primitive counts on all sections of this mesh data.
    • getPrimitiveCount

      public int getPrimitiveCount(int section)
      Gets the primitive count.
      Parameters:
      section - the section
      Returns:
      the number of primitives (triangles, quads, lines, points, etc.) on a given section of this mesh data.
    • getPrimitiveIndices

      public int[] getPrimitiveIndices(int primitiveIndex, int section, int[] store)
      Returns the vertex indices of a specified primitive.
      Parameters:
      primitiveIndex - which triangle, quad, etc
      section - which section to pull from (corresponds to array position in indexmodes and lengths)
      store - an int array to store the results in. if null, or the length < the size of the primitive, a new array is created and returned.
      Returns:
      the primitive's vertex indices as an array
      Throws:
      IndexOutOfBoundsException - if primitiveIndex is outside of range [0, count-1] where count is the number of primitives in the given section.
      ArrayIndexOutOfBoundsException - if section is out of range [0, N-1] where N is the number of sections in this MeshData object.
    • getPrimitiveVertices

      public Vector3[] getPrimitiveVertices(int primitiveIndex, int section, Vector3[] store)
      Gets the vertices that make up the given primitive.
      Parameters:
      primitiveIndex - the primitive index
      section - the section
      store - the store. If null or the wrong size, we'll make a new array and return that instead.
      Returns:
      the primitive
    • getPrimitiveTextureCoords

      public Vector2[] getPrimitiveTextureCoords(int primitiveIndex, int section, int textureIndex, Vector2[] store)
      Gets the texture coordinates of the primitive.
      Parameters:
      primitiveIndex - the primitive index
      section - the section
      textureIndex - the texture index
      store - the store
      Returns:
      the texture coordinates of the primitive
    • getPrimitiveNormals

      public Vector3[] getPrimitiveNormals(int primitiveIndex, int section, Vector3[] store)
      Gets the normals of the primitive.
      Parameters:
      primitiveIndex - the primitive index
      section - the section
      store - the store
      Returns:
      the normals of the primitive
    • getVertexIndex

      public int getVertexIndex(int primitiveIndex, int point, int section)
      Gets the vertex index.
      Parameters:
      primitiveIndex - which triangle, quad, etc.
      point - which point on the triangle, quad, etc. (triangle has three points, so this would be 0-2, etc.)
      section - which section to pull from (corresponds to array position in indexmodes and lengths)
      Returns:
      the position you would expect to find the given point in the index buffer
    • randomVertex

      public Vector3 randomVertex(Vector3 store)
      Random vertex.
      Parameters:
      store - the vector object to store the result in. if null, a new one is created.
      Returns:
      a random vertex from the vertices stored in this MeshData. null is returned if there are no vertices.
    • randomPointOnPrimitives

      public Vector3 randomPointOnPrimitives(Vector3 store)
      Random point on primitives.
      Parameters:
      store - the vector object to store the result in. if null, a new one is created.
      Returns:
      a random point from the surface of a primitive stored in this MeshData. null is returned if there are no vertices or indices.
    • translatePoints

      public void translatePoints(double x, double y, double z)
      Translate points.
      Parameters:
      x - the x
      y - the y
      z - the z
    • translatePoints

      public void translatePoints(Vector3 amount)
      Translate points.
      Parameters:
      amount - the amount
    • transformVertices

      public void transformVertices(Transform transform)
    • transformNormals

      public void transformNormals(Transform transform, boolean normalize)
    • rotatePoints

      public void rotatePoints(Quaternion rotate)
      Rotate points.
      Parameters:
      rotate - the rotate
    • rotateNormals

      public void rotateNormals(Quaternion rotate)
      Rotate normals.
      Parameters:
      rotate - the rotate
    • makeCopy

      public MeshData makeCopy()
    • getClassTag

      public Class<? extends MeshData> getClassTag()
      Specified by:
      getClassTag in interface Savable
    • write

      public void write(OutputCapsule capsule) throws IOException
      Specified by:
      write in interface Savable
      Throws:
      IOException
    • read

      public void read(InputCapsule capsule) throws IOException
      Specified by:
      read in interface Savable
      Throws:
      IOException
    • getInstancingManager

      public InstancingManager getInstancingManager()
    • setInstancingManager

      public void setInstancingManager(InstancingManager info)