Class SpriteMesh

java.lang.Object
edu.cornell.gdiac.graphics.SpriteMesh
Direct Known Subclasses:
TexturedMesh

public class SpriteMesh extends Object
This class represents a flexible mesh data type for rendering sprites.

A mesh is a collection of vertices and indices to pass to an OpenGL/ES 3.0 shader. It also includes a drawing command to interpret those indices. For example if the drawing command is GL_TRIANGLES, the indices are in groups of three, defining triangles. If GL_LINES, they are segment pairs.

This representation is entirely separate from OpenGL. One of the problems with most game engines (LibGDX included) is that they make geometric data tightly coupled with the OpenGL pipeline. The result is heavyweight and difficult to combine with computational geometry algorithms (LibGDX's greatest failing is its horrible computational geometry tools).

This mesh is designed to support a vertex type with four attributes: position, color, texture coordinate, and gradiant coordinate (though gradient coordinate is only supported if GL30 is used). Color is represented as a single float, encoding the RGB bits.The others are each two floats representing an x and a y. This class provides methods to make it easier to access these values.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    int
    The drawing command
    com.badlogic.gdx.utils.ShortArray
    The indices for this mesh
    com.badlogic.gdx.utils.FloatArray
    The vertices for this mesh
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an empty sprite mesh.
    SpriteMesh(float[] vertices)
    Sets the sprite mesh to have the given vertices
    SpriteMesh(float[] vertices, int voffset, int vlength)
    Sets the sprite mesh to have the given vertices
    SpriteMesh(float[] vertices, short[] indices)
    Sets the sprite mesh to have the given vertices and indices.
    SpriteMesh(float x, float y, float width, float height)
    Creates a rectangular sprite mesh.
    SpriteMesh(com.badlogic.gdx.math.Rectangle rect)
    Creates a rectangular sprite mesh.
    Creates a copy of the given sprite mesh.
    Creates a sprite mesh from the given path.
    SpriteMesh(Path2 path, float width, float height)
    Creates a sprite mesh from the given path and bounds
    SpriteMesh(Path2 path, float x, float y, float width, float height)
    Creates a sprite mesh from the given path and bounds
    SpriteMesh(Path2 path, com.badlogic.gdx.math.Rectangle rect)
    Creates a sprite mesh from the given path and bounds
    Creates a sprite mesh from the given polygon.
    SpriteMesh(Poly2 poly, float width, float height)
    Creates a sprite mesh from the given polygon and bounds
    SpriteMesh(Poly2 poly, float x, float y, float width, float height)
    Creates a sprite mesh from the given polygon and bounds
    SpriteMesh(Poly2 poly, com.badlogic.gdx.math.Rectangle rect)
    Creates a sprite mesh from the given polygon and bounds
  • Method Summary

    Modifier and Type
    Method
    Description
    add(float offset)
    Uniformly translates all of the vertices of this mesh.
    add(float x, float y)
    Non-uniformly translates all of the vertices of this mesh.
    add(com.badlogic.gdx.math.Vector2 offset)
    Non-uniformly translates all of the vertices of this mesh.
    void
    Clears the contents of this sprite mesh (both vertices and indices)
    com.badlogic.gdx.math.Rectangle
    Returns the minimal rectangle bounding this mesh.
    com.badlogic.gdx.math.Rectangle
    computeBounds(com.badlogic.gdx.math.Rectangle rect)
    Returns the minimal rectangle bounding this mesh.
    div(float scale)
    Uniformly scales all of the vertices of this mesh.
    div(com.badlogic.gdx.math.Vector2 scale)
    Nonuniformly scales all of the vertices of this mesh.
    com.badlogic.gdx.graphics.Color
    getColor(int idx)
    Returns the vertex color for index idx
    com.badlogic.gdx.graphics.Color
    getColor(int idx, com.badlogic.gdx.graphics.Color c)
    Returns the vertex color for index idx
    com.badlogic.gdx.math.Vector2
    Returns the vertex gradient coordinate for index idx
    com.badlogic.gdx.math.Vector2
    getGradientCoord(int idx, com.badlogic.gdx.math.Vector2 v)
    Returns the vertex gradient coordinate for index idx
    float
    getGradientX(int idx)
    Returns the x-coordinate of the gradient for index idx
    float
    getGradientY(int idx)
    Returns the y-coordinate of the gradient for index idx
    float
    getPackedColor(int idx)
    Returns the packed color representation for index idx
    com.badlogic.gdx.math.Vector2
    getPosition(int idx)
    Returns the vertex position for index idx
    com.badlogic.gdx.math.Vector2
    getPosition(int idx, com.badlogic.gdx.math.Vector2 v)
    Returns the vertex position for index idx
    float
    getPositionX(int idx)
    Returns the x-coordinate of the position for index idx
    float
    getPositionY(int idx)
    Returns the y-coordinate of the position for index idx
    int
    Returns the float stride for vertices in this mesh
    com.badlogic.gdx.math.Vector2
    getTextureCoord(int idx)
    Returns the vertex texture coordinate for index idx
    com.badlogic.gdx.math.Vector2
    getTextureCoord(int idx, com.badlogic.gdx.math.Vector2 v)
    Returns the vertex texture coordinate for index idx
    float
    getTextureX(int idx)
    Returns the x-coordinate of the texture for index idx
    float
    getTextureY(int idx)
    Returns the y-coordinate of the texture for index idx
    int
    Returns the number of indices in this mesh
    boolean
    Returns true if this mesh can be composed in a SpriteBatch.
    mul(com.badlogic.gdx.math.Matrix4 transform)
    Transforms all of the vertices of this mesh.
    void
    push(float x, float y)
    Adds a vertex to the end of this mesh
    void
    push(float x, float y, float tx, float ty)
    Adds a vertex to the end of this mesh
    void
    push(float x, float y, com.badlogic.gdx.graphics.Color color)
    Adds a vertex to the end of this mesh
    void
    push(float x, float y, com.badlogic.gdx.graphics.Color color, float tx, float ty)
    Adds a vertex to the end of this mesh
    void
    push(float x, float y, com.badlogic.gdx.graphics.Color color, float tx, float ty, float gx, float gy)
    Adds a vertex to the end of this mesh This method does not update the indices.
    void
    push(com.badlogic.gdx.math.Vector2 position)
    Adds a vertex to the end of this mesh
    void
    push(com.badlogic.gdx.math.Vector2 position, com.badlogic.gdx.graphics.Color color)
    Adds a vertex to the end of this mesh
    void
    push(com.badlogic.gdx.math.Vector2 position, com.badlogic.gdx.graphics.Color color, com.badlogic.gdx.math.Vector2 texcoord)
    Adds a vertex to the end of this mesh
    void
    push(com.badlogic.gdx.math.Vector2 position, com.badlogic.gdx.graphics.Color color, com.badlogic.gdx.math.Vector2 texcoord, com.badlogic.gdx.math.Vector2 gradcoord)
    Adds a vertex to the end of this mesh
    void
    push(com.badlogic.gdx.math.Vector2 position, com.badlogic.gdx.math.Vector2 texcoord)
    Adds a vertex to the end of this mesh
    scl(float scale)
    Uniformly scales all of the vertices of this mesh.
    scl(com.badlogic.gdx.math.Vector2 scale)
    Nonuniformly scales all of the vertices of this mesh.
    set(float[] vertices)
    Sets the sprite mesh to have the given vertices
    set(float[] vertices, int voffset, int vlength)
    Sets the sprite mesh to have the given vertices.
    set(float x, float y, float width, float height)
    Sets the sprite mesh to represent the given rectangle.
    set(com.badlogic.gdx.math.Rectangle rect)
    Sets the mesh to represent the given rectangle.
    Sets this sprite mesh to be a copy of the given one.
    set(Path2 path)
    Sets this sprite mesh using the given path.
    set(Path2 path, float width, float height)
    Sets this sprite mesh using the given path and bounds
    set(Path2 path, float x, float y, float width, float height)
    Sets this sprite mesh using the given path and bounds
    set(Path2 path, com.badlogic.gdx.math.Rectangle rect)
    Sets this sprite mesh using the given path and bounds
    set(Poly2 poly)
    Sets this sprite mesh using the given polygon.
    set(Poly2 poly, float width, float height)
    Sets this sprite mesh using the given polygon and bounds
    set(Poly2 poly, float x, float y, float width, float height)
    Sets this sprite mesh using the given polygon and bounds
    set(Poly2 poly, com.badlogic.gdx.math.Rectangle rect)
    Sets this sprite mesh using the given polygon and bounds
    void
    setColor(int idx, com.badlogic.gdx.graphics.Color c)
    Sets the vertex color for index idx
    void
    setGradientCoord(int idx, float x, float y)
    Sets the vertex gradient coordinate for index idx
    void
    setGradientCoord(int idx, com.badlogic.gdx.math.Vector2 v)
    Sets the vertex gradient coordinate for index idx.
    setIndices(short[] indices)
    Sets the indices for this sprite mesh to the ones given.
    setIndices(short[] indices, int ioffset, int ilength)
    Sets the indices for this sprite mesh to the ones given.
    void
    setPackedColor(int idx, float c)
    Sets the packed color representation for index idx
    void
    setPosition(int idx, float x, float y)
    Sets the vertex position for index idx
    void
    setPosition(int idx, com.badlogic.gdx.math.Vector2 v)
    Sets the vertex position for index idx
    void
    setTextureCoord(int idx, float x, float y)
    Sets the vertex texture coordinate for index idx
    void
    setTextureCoord(int idx, com.badlogic.gdx.math.Vector2 v)
    Sets the vertex texture coordinate for index idx
    sub(float offset)
    Uniformly translates all of the vertices of this mesh.
    sub(float x, float y)
    Non-uniformly translates all of the vertices of this mesh.
    sub(com.badlogic.gdx.math.Vector2 offset)
    Non-uniformly translates all of the vertices of this mesh.
    transform(com.badlogic.gdx.math.Affine2 matrix)
    Transforms all of the positional data in this mesh.
    transform(com.badlogic.gdx.math.Affine2 matrix, int offset, int count)
    Transforms all of the positional data in this mesh.
    int
    Returns the number of vertices in this mesh

    Methods inherited from class java.lang.Object

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

    • command

      public int command
      The drawing command
    • vertices

      public com.badlogic.gdx.utils.FloatArray vertices
      The vertices for this mesh
    • indices

      public com.badlogic.gdx.utils.ShortArray indices
      The indices for this mesh
  • Constructor Details

    • SpriteMesh

      public SpriteMesh()
      Creates an empty sprite mesh.

      The created mesh has no vertices and no triangulation. The drawing command is also invalid.

    • SpriteMesh

      public SpriteMesh(float[] vertices)
      Sets the sprite mesh to have the given vertices

      The resulting mesh has no indices triangulating the vertices. The drawing command is also invalid.

      Parameters:
      vertices - The vector of vertices (as float in pairs) in this mesh.
    • SpriteMesh

      public SpriteMesh(float[] vertices, int voffset, int vlength)
      Sets the sprite mesh to have the given vertices

      The resulting mesh has no indices triangulating the vertices. The drawing command is also invalid.

      Parameters:
      vertices - The vector of vertices (as float in pairs) in this polygon
      voffset - The offset of the first array vertex
      vlength - The array size to use
    • SpriteMesh

      public SpriteMesh(float[] vertices, short[] indices)
      Sets the sprite mesh to have the given vertices and indices.

      The drawing command is inferred from the size of the indices. If the length of the indices is a multiple of 3, it uses GL_TRIANGLES. If it is a multiple of 2, it uses GL_LINES. Otherwise it is invalid.

      Parameters:
      vertices - The float array of vertices (as float in pairs) in this mesh
      indices - The array of indices in this polygon
    • SpriteMesh

      public SpriteMesh(Poly2 poly)
      Creates a sprite mesh from the given polygon.

      The color will be white. All texture and gradient coordinates are 0.

      Parameters:
      poly - The defining polygon
    • SpriteMesh

      public SpriteMesh(Poly2 poly, float width, float height)
      Creates a sprite mesh from the given polygon and bounds

      The color will be white. The texture and gradient coordinates are each inferred from the provided bounds, using a "cookie-cutter" interpretation. That is, the texture is assumed to be sized to fit in the rectangle (0,0,width,height), and the polygon vertices are superimposed onto this texture layout. So if the polygon fits inside of this rectangle, it will cut out the parts of the image in its interior, like a cookie cutter.

      Note that if the rectangle is smaller than the polygon, then this has the effect of tiling the image across the polygon. In such cases, the texture associated with this sprite mesh should be set to REPEAT.

      Parameters:
      poly - The defining polygon
      width - The texture width
      height - The texture height
    • SpriteMesh

      public SpriteMesh(Poly2 poly, float x, float y, float width, float height)
      Creates a sprite mesh from the given polygon and bounds

      The color will be white. The texture and gradient coordinates are each inferred from the provided bounds, using a "cookie-cutter" interpretation. That is, the texture is assumed to be sized to fit in the given rectangle, and the polygon vertices are superimposed onto this texture layout. So if the polygon fits inside of this rectangle, it will cut out the parts of the image in its interior, like a cookie cutter.

      Note that if the rectangle is smaller than the polygon, then this has the effect of tiling the image across the polygon. In such cases, the texture associated with this sprite mesh should be set to REPEAT.

      Parameters:
      poly - The defining polygon
      x - The left edge of the texture bounds
      y - The bottom edge of the texture bounds
      width - The texture width
      height - The texture height
    • SpriteMesh

      public SpriteMesh(Poly2 poly, com.badlogic.gdx.math.Rectangle rect)
      Creates a sprite mesh from the given polygon and bounds

      The color will be white. The texture and gradient coordinates are each inferred from the provided bounds, using a "cookie-cutter" interpretation. That is, the texture is assumed to be sized to fit in the given rectangle, and the polygon vertices are superimposed onto this texture layout. So if the polygon fits inside of this rectangle, it will cut out the parts of the image in its interior, like a cookie cutter.

      Note that if the rectangle is smaller than the polygon, then this has the effect of tiling the image across the polygon. In such cases, the texture associated with this sprite mesh should be set to REPEAT.

      Parameters:
      poly - The defining polygon
      rect - The texture bounds
    • SpriteMesh

      public SpriteMesh(Path2 path)
      Creates a sprite mesh from the given path.

      The color will be white. All texture and gradient coordinates are 0.

      Parameters:
      path - The defining path
    • SpriteMesh

      public SpriteMesh(Path2 path, float width, float height)
      Creates a sprite mesh from the given path and bounds

      The color will be white. The texture and gradient coordinates are each inferred from the provided bounds, using a "cookie-cutter" interpretation. That is, the texture is assumed to be sized to fit in the rectangle (0,0,width,height), and the path vertices are superimposed onto this texture layout. So any for any part of the path that fits inside the bounds, the path will pick up the appropriate part of the image, like a cookie cutter.

      Note that if the rectangle is smaller than the path, then this has the effect of tiling the image across the polygon. In such cases, the texture associated with this sprite mesh should be set to REPEAT.

      Parameters:
      path - The defining path
      width - The texture width
      height - The texture height
    • SpriteMesh

      public SpriteMesh(Path2 path, float x, float y, float width, float height)
      Creates a sprite mesh from the given path and bounds

      The color will be white. The texture and gradient coordinates are each inferred from the provided bounds, using a "cookie-cutter" interpretation. That is, the texture is assumed to be sized to fit in the given rectangle, and the path vertices are superimposed onto this texture layout. So any for any part of the path that fits inside the bounds, the path will pick up the appropriate part of the image, like a cookie cutter.

      Note that if the rectangle is smaller than the path, then this has the effect of tiling the image across the polygon. In such cases, the texture associated with this sprite mesh should be set to REPEAT.

      Parameters:
      path - The defining path
      x - The left edge of the texture bounds
      y - The bottom edge of the texture bounds
      width - The texture width
      height - The texture height
    • SpriteMesh

      public SpriteMesh(Path2 path, com.badlogic.gdx.math.Rectangle rect)
      Creates a sprite mesh from the given path and bounds

      The color will be white. The texture and gradient coordinates are each inferred from the provided bounds, using a "cookie-cutter" interpretation. That is, the texture is assumed to be sized to fit in the given rectangle, and the path vertices are superimposed onto this texture layout. So any for any part of the path that fits inside the bounds, the path will pick up the appropriate part of the image, like a cookie cutter.

      Note that if the rectangle is smaller than the path, then this has the effect of tiling the image across the polygon. In such cases, the texture associated with this sprite mesh should be set to REPEAT.

      Parameters:
      path - The defining path
      rect - The texture bounds
    • SpriteMesh

      public SpriteMesh(SpriteMesh mesh)
      Creates a copy of the given sprite mesh.

      All of the contents are copied, so that this mesh does not hold any references to elements of the other mesh.

      Parameters:
      mesh - The mesh to copy
    • SpriteMesh

      public SpriteMesh(com.badlogic.gdx.math.Rectangle rect)
      Creates a rectangular sprite mesh.

      The polygon will have four vertices, one for each corner of the rectangle. The indices will define two triangles on these vertices. This method is faster than using one of the more heavy-weight triangulators.

      The color will be white. The texture and gradient coordinates will align with the rectangle so that any texture is sized to fit

      Parameters:
      rect - The rectangle to copy
    • SpriteMesh

      public SpriteMesh(float x, float y, float width, float height)
      Creates a rectangular sprite mesh.

      The polygon will have four vertices, one for each corner of the rectangle. The indices will define two triangles on these vertices. This method is faster than using one of the more heavy-weight triangulators.

      The color will be white. The texture and gradient coordinates will align with the rectangle so that any texture is sized to fit

      Parameters:
      x - The rectangle left edge
      y - The rectangle bottom edge
      width - The rectangle width
      height - The rectangle height
  • Method Details

    • mul

      public SpriteMesh mul(com.badlogic.gdx.math.Matrix4 transform)
      Transforms all of the vertices of this mesh.

      Since meshes can have arbitrary dimensions, the only guaranteed safe transforms are 4x4 matrices like Matrix4.

      Parameters:
      transform - The transformation matrix
      Returns:
      This mesh with transformed vertices
    • getStride

      public int getStride()
      Returns the float stride for vertices in this mesh
      Returns:
      the float stride for vertices in this mesh
    • set

      public SpriteMesh set(float[] vertices)
      Sets the sprite mesh to have the given vertices

      The method will invalid the indices. The resulting mesh has no indices triangulating the vertices. The drawing command is also invalid.

      This method returns a reference to this mesh for chaining.

      Parameters:
      vertices - The vertices in this mesh
      Returns:
      This mesh, returned for chaining
    • set

      public SpriteMesh set(float[] vertices, int voffset, int vlength)
      Sets the sprite mesh to have the given vertices.

      The method will invalid the indices. The resulting mesh has no indices triangulating the vertices. The drawing command is also invalid.

      This method returns a reference to this mesh for chaining.

      Parameters:
      vertices - The array of vertices in this mesh
      voffset - The offset of the first array vertex
      vlength - The array size to use
      Returns:
      This mesh, returned for chaining
    • set

      public SpriteMesh set(Poly2 poly)
      Sets this sprite mesh using the given polygon.

      The color will be white. All texture and gradient coordinates are 0.

      This method returns a reference to this mesh for chaining.

      Parameters:
      poly - The defining polygon
      Returns:
      This mesh, returned for chaining
    • set

      public SpriteMesh set(Poly2 poly, float width, float height)
      Sets this sprite mesh using the given polygon and bounds

      The color will be white. The texture and gradient coordinates are each inferred from the provided bounds, using a "cookie-cutter" interpretation. That is, the texture is assumed to be sized to fit in the rectangle (0,0,width,height), and the polygon vertices are superimposed onto this texture layout. So if the polygon fits inside of this rectangle, it will cut out the parts of the image in its interior, like a cookie cutter.

      Note that if the rectangle is smaller than the polygon, then this has the effect of tiling the image across the polygon. In such cases, the texture associated with this sprite mesh should be set to REPEAT.

      This method returns a reference to this mesh for chaining.

      Parameters:
      poly - The defining polygon
      width - The texture width
      height - The texture height
      Returns:
      This mesh, returned for chaining
    • set

      public SpriteMesh set(Poly2 poly, float x, float y, float width, float height)
      Sets this sprite mesh using the given polygon and bounds

      The color will be white. The texture and gradient coordinates are each inferred from the provided bounds, using a "cookie-cutter" interpretation. That is, the texture is assumed to be sized to fit in the given rectangle, and the polygon vertices are superimposed onto this texture layout. So if the polygon fits inside of this rectangle, it will cut out the parts of the image in its interior, like a cookie cutter.

      Note that if the rectangle is smaller than the polygon, then this has the effect of tiling the image across the polygon. In such cases, the texture associated with this sprite mesh should be set to REPEAT.

      This method returns a reference to this mesh for chaining.

      Parameters:
      poly - The defining polygon
      x - The left edge of the texture bounds
      y - The bottom edge of the texture bounds
      width - The texture width
      height - The texture height
      Returns:
      This mesh, returned for chaining
    • set

      public SpriteMesh set(Poly2 poly, com.badlogic.gdx.math.Rectangle rect)
      Sets this sprite mesh using the given polygon and bounds

      The color will be white. The texture and gradient coordinates are each inferred from the provided bounds, using a "cookie-cutter" interpretation. That is, the texture is assumed to be sized to fit in the given rectangle, and the polygon vertices are superimposed onto this texture layout. So if the polygon fits inside of this rectangle, it will cut out the parts of the image in its interior, like a cookie cutter.

      Note that if the rectangle is smaller than the polygon, then this has the effect of tiling the image across the polygon. In such cases, the texture associated with this sprite mesh should be set to REPEAT.

      This method returns a reference to this mesh for chaining.

      Parameters:
      poly - The defining polygon
      rect - The texture bounds
      Returns:
      This mesh, returned for chaining
    • set

      public SpriteMesh set(Path2 path)
      Sets this sprite mesh using the given path.

      The color will be white. All texture and gradient coordinates are 0.

      This method returns a reference to this mesh for chaining.

      Parameters:
      path - The defining path
      Returns:
      This mesh, returned for chaining
    • set

      public SpriteMesh set(Path2 path, float width, float height)
      Sets this sprite mesh using the given path and bounds

      The color will be white. The texture and gradient coordinates are each inferred from the provided bounds, using a "cookie-cutter" interpretation. That is, the texture is assumed to be sized to fit in the rectangle (0,0,width,height), and the path vertices are superimposed onto this texture layout. So any for any part of the path that fits inside the bounds, the path will pick up the appropriate part of the image, like a cookie cutter.

      Note that if the rectangle is smaller than the path, then this has the effect of tiling the image across the polygon. In such cases, the texture associated with this sprite mesh should be set to REPEAT.

      This method returns a reference to this mesh for chaining.

      Parameters:
      path - The defining path
      width - The texture width
      height - The texture height
      Returns:
      This mesh, returned for chaining
    • set

      public SpriteMesh set(Path2 path, float x, float y, float width, float height)
      Sets this sprite mesh using the given path and bounds

      The color will be white. The texture and gradient coordinates are each inferred from the provided bounds, using a "cookie-cutter" interpretation. That is, the texture is assumed to be sized to fit in the given rectangle, and the path vertices are superimposed onto this texture layout. So any for any part of the path that fits inside the bounds, the path will pick up the appropriate part of the image, like a cookie cutter.

      Note that if the rectangle is smaller than the path, then this has the effect of tiling the image across the polygon. In such cases, the texture associated with this sprite mesh should be set to REPEAT.

      This method returns a reference to this mesh for chaining.

      Parameters:
      path - The defining path
      x - The left edge of the texture bounds
      y - The bottom edge of the texture bounds
      width - The texture width
      height - The texture height
      Returns:
      This mesh, returned for chaining
    • set

      public SpriteMesh set(Path2 path, com.badlogic.gdx.math.Rectangle rect)
      Sets this sprite mesh using the given path and bounds

      The color will be white. The texture and gradient coordinates are each inferred from the provided bounds, using a "cookie-cutter" interpretation. That is, the texture is assumed to be sized to fit in the given rectangle, and the path vertices are superimposed onto this texture layout. So any for any part of the path that fits inside the bounds, the path will pick up the appropriate part of the image, like a cookie cutter.

      Note that if the rectangle is smaller than the path, then this has the effect of tiling the image across the polygon. In such cases, the texture associated with this sprite mesh should be set to REPEAT.

      This method returns a reference to this mesh for chaining.

      Parameters:
      path - The defining path
      rect - The texture bounds
      Returns:
      This mesh, returned for chaining
    • set

      public SpriteMesh set(SpriteMesh mesh)
      Sets this sprite mesh to be a copy of the given one.

      All of the contents are copied, so that this mesh does not hold any references to elements of the other mesh.

      This method returns a reference to this mesh for chaining.

      Parameters:
      mesh - The mesh to copy
      Returns:
      This mesh, returned for chaining
    • set

      public SpriteMesh set(com.badlogic.gdx.math.Rectangle rect)
      Sets the mesh to represent the given rectangle.

      The polygon will have four vertices, one for each corner of the rectangle. The indices will define two triangles on these vertices. This method is faster than using one of the more heavy-weight triangulators.

      The color will be white. The texture and gradient coordinates will align with the rectangle.

      This method returns a reference to this mesh for chaining.

      Parameters:
      rect - The rectangle to copy
      Returns:
      This mesh, returned for chaining
    • set

      public SpriteMesh set(float x, float y, float width, float height)
      Sets the sprite mesh to represent the given rectangle.

      The polygon will have four vertices, one for each corner of the rectangle. The indices will define two triangles on these vertices. This method is faster than using one of the more heavy-weight triangulators.

      The color will be white. The texture and gradient coordinates will align with the rectangle so that any texture is sized to fit

      This method returns a reference to this mesh for chaining.

      Parameters:
      x - The rectangle left edge
      y - The rectangle bottom edge
      width - The rectangle width
      height - The rectangle height
      Returns:
      This mesh, returned for chaining
    • setIndices

      public SpriteMesh setIndices(short[] indices)
      Sets the indices for this sprite mesh to the ones given.

      A valid list of indices must only refer to vertices in the vertex array. That is, the indices should all be non-negative, and each value should be less than the number of vertices. In addition, the number of indices should be a consistent the the current command (GL_TRIANGLES) or (GL_LINES). However, this method does not currently enforce either of these preconditions.

      The provided indices are copied. The mesh does not retain a reference.

      Parameters:
      indices - The vector of indices for the shape
      Returns:
      This mesh, returned for chaining
    • setIndices

      public SpriteMesh setIndices(short[] indices, int ioffset, int ilength)
      Sets the indices for this sprite mesh to the ones given.

      A valid list of indices must only refer to vertices in the vertex array. That is, the indices should all be non-negative, and each value should be less than the number of vertices. In addition, the number of indices should be a consistent the the current command (GL_TRIANGLES) or (GL_LINES). However, this method does not currently enforce either of these preconditions.

      The provided indices are copied. The mesh does not retain a reference.

      Parameters:
      indices - The array of indices for the rendering
      ioffset - The offset of the first array vertex
      ilength - The array size to use
      Returns:
      This mesh, returned for chaining
    • clear

      public void clear()
      Clears the contents of this sprite mesh (both vertices and indices)
    • isComposable

      public boolean isComposable()
      Returns true if this mesh can be composed in a SpriteBatch.

      Composable meshes can be drawn together in a single pass. Only the commands `GL_TRIANGLES`, `GL_LINES`, and `GL_POINTS` are composable.

      Returns:
      true if this mesh can be composed in a SpriteBatch.
    • vertexCount

      public int vertexCount()
      Returns the number of vertices in this mesh
      Returns:
      the number of vertices in this mesh
    • indexCount

      public int indexCount()
      Returns the number of indices in this mesh
      Returns:
      the number of indices in this mesh
    • getPositionX

      public float getPositionX(int idx)
      Returns the x-coordinate of the position for index idx
      Parameters:
      idx - The vertex index
      Returns:
      the x-coordinate of the position for index idx
    • getPositionY

      public float getPositionY(int idx)
      Returns the y-coordinate of the position for index idx
      Parameters:
      idx - The vertex index
      Returns:
      the y-coordinate of the position for index idx
    • getPosition

      public com.badlogic.gdx.math.Vector2 getPosition(int idx)
      Returns the vertex position for index idx

      Note that this method creates a new Vector2 object. You can prevent this memory allocation by using the alternate getter.

      Parameters:
      idx - The vertex index
      Returns:
      the vertex position for index idx
    • getPosition

      public com.badlogic.gdx.math.Vector2 getPosition(int idx, com.badlogic.gdx.math.Vector2 v)
      Returns the vertex position for index idx

      Note that this method places the data into the provided Vector2 object, preventing an object allocation. It will return this vector for chaining.

      Parameters:
      idx - The vertex index
      v - The vector to store the results;
      Returns:
      the vertex position for index idx
    • setPosition

      public void setPosition(int idx, com.badlogic.gdx.math.Vector2 v)
      Sets the vertex position for index idx
      Parameters:
      idx - The vertex index
      v - The vertex position
    • setPosition

      public void setPosition(int idx, float x, float y)
      Sets the vertex position for index idx
      Parameters:
      idx - The vertex index
      x - The vertex x-coordinate
      y - The vertex y-coordinate
    • getPackedColor

      public float getPackedColor(int idx)
      Returns the packed color representation for index idx
      Parameters:
      idx - The vertex index
      Returns:
      the packed color representation for index idx
    • setPackedColor

      public void setPackedColor(int idx, float c)
      Sets the packed color representation for index idx
      Parameters:
      idx - The vertex index
      c - The packed color representation
    • getColor

      public com.badlogic.gdx.graphics.Color getColor(int idx)
      Returns the vertex color for index idx

      Note that this method creates a new Color object. You can prevent this memory allocation by using the alternate getter.

      Parameters:
      idx - The vertex index
      Returns:
      the vertex color for index idx
    • getColor

      public com.badlogic.gdx.graphics.Color getColor(int idx, com.badlogic.gdx.graphics.Color c)
      Returns the vertex color for index idx

      Note that this method places the data into the provided Color object, preventing an object allocation. It will return this vector for chaining.

      Parameters:
      idx - The vertex index
      c - The color to store the results;
      Returns:
      the vertex color for index idx
    • setColor

      public void setColor(int idx, com.badlogic.gdx.graphics.Color c)
      Sets the vertex color for index idx
      Parameters:
      idx - The vertex index
      c - The vertex color
    • getTextureX

      public float getTextureX(int idx)
      Returns the x-coordinate of the texture for index idx
      Parameters:
      idx - The vertex index
      Returns:
      the x-coordinate of the texture for index idx
    • getTextureY

      public float getTextureY(int idx)
      Returns the y-coordinate of the texture for index idx
      Parameters:
      idx - The vertex index
      Returns:
      the y-coordinate of the texture for index idx
    • getTextureCoord

      public com.badlogic.gdx.math.Vector2 getTextureCoord(int idx)
      Returns the vertex texture coordinate for index idx

      Note that this method creates a new Vector2 object. You can prevent this memory allocation by using the alternate getter.

      Parameters:
      idx - The vertex index
      Returns:
      the vertex texture coordinate for index idx
    • getTextureCoord

      public com.badlogic.gdx.math.Vector2 getTextureCoord(int idx, com.badlogic.gdx.math.Vector2 v)
      Returns the vertex texture coordinate for index idx

      Note that this method places the data into the provided Vector2 object, preventing an object allocation. It will return this vector for chaining.

      Parameters:
      idx - The vertex index
      v - The vector to store the results;
      Returns:
      the vertex texture coordinate for index idx
    • setTextureCoord

      public void setTextureCoord(int idx, com.badlogic.gdx.math.Vector2 v)
      Sets the vertex texture coordinate for index idx
      Parameters:
      idx - The vertex index
      v - The vertex texture coordinate
    • setTextureCoord

      public void setTextureCoord(int idx, float x, float y)
      Sets the vertex texture coordinate for index idx
      Parameters:
      idx - The vertex index
      x - The texture x-coordinate
      y - The texture y-coordinate
    • getGradientX

      public float getGradientX(int idx)
      Returns the x-coordinate of the gradient for index idx

      This method returns 0 if gradient coordinates are not supported.

      Parameters:
      idx - The vertex index
      Returns:
      the x-coordinate of the gradient for index idx
    • getGradientY

      public float getGradientY(int idx)
      Returns the y-coordinate of the gradient for index idx

      This method returns 0 if gradient coordinates are not supported.

      Parameters:
      idx - The vertex index
      Returns:
      the y-coordinate of the gradient for index idx
    • getGradientCoord

      public com.badlogic.gdx.math.Vector2 getGradientCoord(int idx)
      Returns the vertex gradient coordinate for index idx

      Note that this method creates a new Vector2 object. You can prevent this memory allocation by using the alternate getter.

      This method returns the zero vector if gradient coordinates are not supported.

      Parameters:
      idx - The vertex index
      Returns:
      the vertex gradient coordinate for index idx
    • getGradientCoord

      public com.badlogic.gdx.math.Vector2 getGradientCoord(int idx, com.badlogic.gdx.math.Vector2 v)
      Returns the vertex gradient coordinate for index idx

      Note that this method places the data into the provided Vector2 object, preventing an object allocation. It will return this vector for chaining.

      This method returns the zero vector if gradient coordinates are not supported.

      Parameters:
      idx - The vertex index
      v - The vector to store the results;
      Returns:
      the vertex gradient coordinate for index idx
    • setGradientCoord

      public void setGradientCoord(int idx, com.badlogic.gdx.math.Vector2 v)
      Sets the vertex gradient coordinate for index idx.

      This method does nothing if gradient coordinates are not supported.

      Parameters:
      idx - The vertex index
      v - The vertex gradient coordinate
    • setGradientCoord

      public void setGradientCoord(int idx, float x, float y)
      Sets the vertex gradient coordinate for index idx

      This method does nothing if gradient coordinates are not supported.

      Parameters:
      idx - The vertex index
      x - The gradient x-coordinate
      y - The gradient y-coordinate
    • scl

      public SpriteMesh scl(float scale)
      Uniformly scales all of the vertices of this mesh.

      The vertices are scaled from the origin of the coordinate space. This means that if the origin is not in the interior of this mesh, the mesh will be effectively translated by the scaling.

      Parameters:
      scale - The uniform scaling factor
      Returns:
      This mesh, scaled uniformly.
    • scl

      public SpriteMesh scl(com.badlogic.gdx.math.Vector2 scale)
      Nonuniformly scales all of the vertices of this mesh.

      The vertices are scaled from the origin of the coordinate space. This means that if the origin is not in the interior of this mesh, the mesh will be effectively translated by the scaling.

      Parameters:
      scale - The non-uniform scaling factor
      Returns:
      This mesh, scaled non-uniformly.
    • div

      public SpriteMesh div(float scale)
      Uniformly scales all of the vertices of this mesh.

      The vertices are scaled from the origin of the coordinate space. This means that if the origin is not in the interior of this mesh, the mesh will be effectively translated by the scaling.

      Parameters:
      scale - The inverse of the uniform scaling factor
      Returns:
      This mesh, scaled uniformly.
    • div

      public SpriteMesh div(com.badlogic.gdx.math.Vector2 scale)
      Nonuniformly scales all of the vertices of this mesh.

      The vertices are scaled from the origin of the coordinate space. This means that if the origin is not in the interior of this mesh, the mesh will be effectively translated by the scaling.

      Parameters:
      scale - The inverse of the non-uniform scaling factor
      Returns:
      This mesh, scaled non-uniformly.
    • add

      public SpriteMesh add(float offset)
      Uniformly translates all of the vertices of this mesh.
      Parameters:
      offset - The uniform translation amount
      Returns:
      This mesh, translated uniformly.
    • add

      public SpriteMesh add(com.badlogic.gdx.math.Vector2 offset)
      Non-uniformly translates all of the vertices of this mesh.
      Parameters:
      offset - The non-uniform translation amount
      Returns:
      This mesh, translated non-uniformly.
    • add

      public SpriteMesh add(float x, float y)
      Non-uniformly translates all of the vertices of this mesh.
      Parameters:
      x - The x-coordinate translation amount
      y - The y-coordinate translation amount
      Returns:
      This mesh, translated non-uniformly.
    • sub

      public SpriteMesh sub(float offset)
      Uniformly translates all of the vertices of this mesh.
      Parameters:
      offset - The inverse of the uniform translation amount
      Returns:
      This mesh, translated uniformly.
    • sub

      public SpriteMesh sub(com.badlogic.gdx.math.Vector2 offset)
      Non-uniformly translates all of the vertices of this mesh.
      Parameters:
      offset - The inverse of the non-uniform translation amount
      Returns:
      This mesh, translated non-uniformly.
    • sub

      public SpriteMesh sub(float x, float y)
      Non-uniformly translates all of the vertices of this mesh.
      Parameters:
      x - The inverse of the x-coordinate translation amount
      y - The inverse of the y-coordinate translation amount
      Returns:
      This mesh, translated non-uniformly.
    • transform

      public SpriteMesh transform(com.badlogic.gdx.math.Affine2 matrix)
      Transforms all of the positional data in this mesh.
      Parameters:
      matrix - The transform matrix
      Returns:
      This mesh with the vertices transformed
    • transform

      public SpriteMesh transform(com.badlogic.gdx.math.Affine2 matrix, int offset, int count)
      Transforms all of the positional data in this mesh.

      The value offset is a vertex position, not a float array position.

      Parameters:
      matrix - The transform matrix
      offset - The first vertex to transform
      count - The number of vertices to transform
      Returns:
      This mesh with the vertices transformed
    • push

      public void push(com.badlogic.gdx.math.Vector2 position)
      Adds a vertex to the end of this mesh

      This method does not update the indices. It is simply a convenience method for adding vertices. The colors and texture/gradient coordinates will be set to the defaults.

      Parameters:
      position - The vertex position
    • push

      public void push(float x, float y)
      Adds a vertex to the end of this mesh

      This method does not update the indices. It is simply a convenience method for adding vertices. The colors and texture/gradient coordinates will be set to the defaults.

      Parameters:
      x - The vertex x-coordinate
      y - The vertex y-coordinate
    • push

      public void push(com.badlogic.gdx.math.Vector2 position, com.badlogic.gdx.graphics.Color color)
      Adds a vertex to the end of this mesh

      This method does not update the indices. It is simply a convenience method for adding vertices. The colors and texture/gradient coordinates will be set to the defaults.

      Parameters:
      position - The vertex position
      color - The vertex color
    • push

      public void push(float x, float y, com.badlogic.gdx.graphics.Color color)
      Adds a vertex to the end of this mesh

      This method does not update the indices. It is simply a convenience method for adding vertices. The colors and texture/gradient coordinates will be set to the defaults.

      Parameters:
      x - The vertex x-coordinate
      y - The vertex y-coordinate
      color - The vertex color
    • push

      public void push(com.badlogic.gdx.math.Vector2 position, com.badlogic.gdx.math.Vector2 texcoord)
      Adds a vertex to the end of this mesh

      This method does not update the indices. It is simply a convenience method for adding vertices. The color will be the default white. The gradient coordinates will agree with the texture coordinates.

      Parameters:
      position - The vertex position
      texcoord - The vertex texture coordinates
    • push

      public void push(float x, float y, float tx, float ty)
      Adds a vertex to the end of this mesh

      This method does not update the indices. It is simply a convenience method for adding vertices. The color will be the default white. The gradient coordinates will agree with the texture coordinates.

      Parameters:
      x - The vertex x-coordinate
      y - The vertex y-coordinate
      tx - The texture x-coordinate
      ty - The texture y-coordinate
    • push

      public void push(com.badlogic.gdx.math.Vector2 position, com.badlogic.gdx.graphics.Color color, com.badlogic.gdx.math.Vector2 texcoord)
      Adds a vertex to the end of this mesh

      This method does not update the indices. It is simply a convenience method for adding vertices. Gradient coordinates will be ignored if they are not supported.

      Parameters:
      position - The vertex position
      color - The vertex color
      texcoord - The vertex texture coordinates
    • push

      public void push(float x, float y, com.badlogic.gdx.graphics.Color color, float tx, float ty)
      Adds a vertex to the end of this mesh

      This method does not update the indices. It is simply a convenience method for adding vertices. The color will be the default white. The gradient coordinates will agree with the texture coordinates.

      Parameters:
      x - The vertex x-coordinate
      y - The vertex y-coordinate
      color - The vertex color
      tx - The texture x-coordinate
      ty - The texture y-coordinate
    • push

      public void push(com.badlogic.gdx.math.Vector2 position, com.badlogic.gdx.graphics.Color color, com.badlogic.gdx.math.Vector2 texcoord, com.badlogic.gdx.math.Vector2 gradcoord)
      Adds a vertex to the end of this mesh

      This method does not update the indices. It is simply a convenience method for adding vertices. Gradient coordinates will be ignored if they are not supported.

      Parameters:
      position - The vertex position
      color - The vertex color
      texcoord - The vertex texture coordinates
      gradcoord - The vertex gradient coordinates
    • push

      public void push(float x, float y, com.badlogic.gdx.graphics.Color color, float tx, float ty, float gx, float gy)
      Adds a vertex to the end of this mesh This method does not update the indices. It is simply a convenience method for adding vertices. Gradient coordinates will be ignored if they are not supported.
      Parameters:
      x - The vertex x-coordinate
      y - The vertex y-coordinate
      color - The vertex color
      tx - The texture x-coordinate
      ty - The texture y-coordinate
      gx - The gradient x-coordinate
      gy - The gradient y-coordinate
    • computeBounds

      public com.badlogic.gdx.math.Rectangle computeBounds()
      Returns the minimal rectangle bounding this mesh.
      Returns:
      the minimal rectangle bounding this mesh.
    • computeBounds

      public com.badlogic.gdx.math.Rectangle computeBounds(com.badlogic.gdx.math.Rectangle rect)
      Returns the minimal rectangle bounding this mesh.

      Note that this method places the data into the provided Rectangle object, preventing an object allocation. It will return this vector for chaining.

      Parameters:
      rect - The rectangle to store the results;
      Returns:
      the minimal rectangle bounding this mesh.