APIdia Launch Partner
Top Description Fields Constructors Methods
com.badlogic.gdx.graphics.g3d.model

public Class MeshPart

extends Object
Class Inheritance
Imports
com.badlogic.gdx.graphics.GL20, .Mesh, com.badlogic.gdx.graphics.g3d.Model, com.badlogic.gdx.graphics.glutils.ShaderProgram, com.badlogic.gdx.math.Vector3, com.badlogic.gdx.math.collision.BoundingBox

A MeshPart is composed of a subset of vertices of a Mesh, along with the primitive type. The vertices subset is described by an offset and size. When the mesh is indexed (which is when Mesh#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 Mesh referenced by the mesh member must outlive the MeshPart. When the mesh is disposed, the MeshPart is unusable.
Author
badlogic, Xoppa

Field Summary

Modifier and TypeField and Description
private static final BoundingBox
bounds

Temporary static BoundingBox instance, used in the update() method.

public final Vector3
center

The offset to the center of the bounding box of the shape, only valid after the call to update().

public final Vector3
halfExtents

The location, relative to center, of the corner of the axis aligned bounding box of the shape.

public String
id

Unique id within model, may be null.

public Mesh
mesh

The Mesh the part references, also stored in Model

public int
offset

The offset in the mesh to this part.

public int
public float
radius

The radius relative to center of the bounding sphere of the shape, or negative if not calculated yet.

public int
size

The size (in total number of vertices) of this part in the mesh.

Constructor Summary

AccessConstructor and Description
public
MeshPart()

Construct a new MeshPart, with null values.

public
MeshPart(final String
The id of the new part, may be null.
id
,
final Mesh
The mesh which holds all vertices and (optional) indices of this part.
mesh
,
final int
The offset within the mesh to this part.
offset
,
final int
The size (in total number of vertices) of the part.
size
,
final int
The primitive type of the part (e.g. GL_TRIANGLES, GL_LINE_STRIP, etc.).
type
)

Construct a new MeshPart and set all its values.

public
MeshPart(final MeshPart
The MeshPart to copy.
copyFrom
)

Construct a new MeshPart which is an exact copy of the provided MeshPart.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

True when this MeshPart equals the other MeshPart (ignoring the id member), false otherwise.
equals
(final MeshPart
The other MeshPart to compare this MeshPart to.
other
)

Compares this MeshPart to the specified MeshPart and returns true if they both reference the same Mesh and the offset, size and primitiveType members are equal.

public boolean
equals(final Object arg0)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public void
render(ShaderProgram
the shader to be used
shader
,
boolean
overrides the autoBind member of the Mesh
autoBind
)

Renders the mesh part using the specified shader, must be called after ShaderProgram#bind().

public void
render(ShaderProgram
the shader to be used
shader
)

Renders the mesh part using the specified shader, must be called after ShaderProgram#bind().

public MeshPart

Returns:

this MeshPart, for chaining
set
(final MeshPart
The MeshPart from which to copy the values
other
)

Set this MeshPart to be a copy of the other MeshPart

public MeshPart

Returns:

this MeshPart, for chaining.
set
(final String id, final Mesh mesh, final int offset, final int size, final int type)

Set this MeshPart to given values, does not update() the bounding box values.

public void
update()

Calculates and updates the center, halfExtents and radius values.

Inherited from java.lang.Object:
clonefinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

boundsback to summary
private static final BoundingBox bounds

Temporary static BoundingBox instance, used in the update() method.

centerback to summary
public final Vector3 center

The offset to the center of the bounding box of the shape, only valid after the call to update().

halfExtentsback to summary
public final 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().

idback to summary
public String id

Unique id within model, may be null. Will be ignored by equals(MeshPart)

meshback to summary
public Mesh mesh

The Mesh the part references, also stored in Model

offsetback to summary
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.

primitiveTypeback to summary
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

radiusback to summary
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().

sizeback to summary
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.

Constructor Detail

MeshPartback to summary
public MeshPart()

Construct a new MeshPart, with null values. The MeshPart is unusable until you set all members.

MeshPartback to summary
public MeshPart(final String id, final Mesh mesh, final int offset, final int size, final int type)

Construct a new MeshPart and set all its values.

Parameters
id:String

The id of the new part, may be null.

mesh:Mesh

The mesh which holds all vertices and (optional) indices of this part.

offset:int

The offset within the mesh to this part.

size:int

The size (in total number of vertices) of the part.

type:int

The primitive type of the part (e.g. GL_TRIANGLES, GL_LINE_STRIP, etc.).

MeshPartback to summary
public MeshPart(final MeshPart copyFrom)

Construct a new MeshPart which is an exact copy of the provided MeshPart.

Parameters
copyFrom:MeshPart

The MeshPart to copy.

Method Detail

equalsback to summary
public boolean equals(final MeshPart other)

Compares this MeshPart to the specified MeshPart and returns true if they both reference the same Mesh and the offset, size and primitiveType members are equal. The id member is ignored.

Parameters
other:MeshPart

The other MeshPart to compare this MeshPart to.

Returns:boolean

True when this MeshPart equals the other MeshPart (ignoring the id member), false otherwise.

equalsback to summary
public boolean equals(final Object arg0)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Annotations
@Override
renderback to summary
public void render(ShaderProgram shader, boolean autoBind)

Renders the mesh part using the specified shader, must be called after ShaderProgram#bind().

Parameters
shader:ShaderProgram

the shader to be used

autoBind:boolean

overrides the autoBind member of the Mesh

renderback to summary
public void render(ShaderProgram shader)

Renders the mesh part using the specified shader, must be called after ShaderProgram#bind().

Parameters
shader:ShaderProgram

the shader to be used

setback to summary
public MeshPart set(final MeshPart other)

Set this MeshPart to be a copy of the other MeshPart

Parameters
other:MeshPart

The MeshPart from which to copy the values

Returns:MeshPart

this MeshPart, for chaining

setback to summary
public MeshPart set(final String id, final Mesh mesh, final int offset, final int size, final int type)

Set this MeshPart to given values, does not update() the bounding box values.

Returns:MeshPart

this MeshPart, for chaining.

updateback to summary
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.