Class MeshPart
- java.lang.Object
-
- com.badlogic.gdx.graphics.g3d.model.MeshPart
-
public class MeshPart extends java.lang.ObjectA MeshPart is composed of a subset of vertices of aMesh, along with the primitive type. The vertices subset is described by an offset and size. When the mesh is indexed (which is whenMesh.getNumIndices()> 0), then theoffsetrepresents the offset in the indices array andsizerepresents the number of indices. When the mesh isn't indexed, then theoffsetmember represents the offset in the vertices array and thesizemember represents the number of vertices. In other words: Regardless whether the mesh is indexed or not, whenprimitiveTypeis not a strip, thensizeequals the number of primitives multiplied by the number of vertices per primitive. So if the MeshPart represents 4 triangles (primitiveTypeis GL_TRIANGLES), then thesizemember is 12 (4 triangles * 3 vertices = 12 vertices total). Likewise, if the part represents 12 lines (primitiveTypeis 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. TheMeshreferenced by themeshmember must outlive the MeshPart. When the mesh is disposed, the MeshPart is unusable.
-
-
Field Summary
Fields Modifier and Type Field Description Vector3centerThe offset to the center of the bounding box of the shape, only valid after the call toupdate().Vector3halfExtentsThe location, relative tocenter, of the corner of the axis aligned bounding box of the shape.java.lang.StringidUnique id within model, may be null.MeshmeshThe Mesh the part references, also stored inModelintoffsetThe offset in themeshto this part.intprimitiveTypeThe primitive type, OpenGL constant e.g:GL20.GL_TRIANGLES,GL20.GL_POINTS,GL20.GL_LINES,GL20.GL_LINE_STRIP,GL20.GL_TRIANGLE_STRIPfloatradiusThe radius relative tocenterof the bounding sphere of the shape, or negative if not calculated yet.intsizeThe size (in total number of vertices) of this part in themesh.
-
Constructor Summary
Constructors Constructor Description MeshPart()Construct a new MeshPart, with null values.MeshPart(MeshPart copyFrom)Construct a new MeshPart which is an exact copy of the provided MeshPart.MeshPart(java.lang.String id, Mesh mesh, int offset, int size, int type)Construct a new MeshPart and set all its values.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(MeshPart other)Compares this MeshPart to the specified MeshPart and returns true if they both reference the sameMeshand theoffset,sizeandprimitiveTypemembers are equal.booleanequals(java.lang.Object arg0)voidrender(ShaderProgram shader)Renders the mesh part using the specified shader, must be called afterShaderProgram.bind().voidrender(ShaderProgram shader, boolean autoBind)Renders the mesh part using the specified shader, must be called afterShaderProgram.bind().MeshPartset(MeshPart other)Set this MeshPart to be a copy of the other MeshPartMeshPartset(java.lang.String id, Mesh mesh, int offset, int size, int type)Set this MeshPart to given values, does notupdate()the bounding box values.voidupdate()
-
-
-
Field Detail
-
id
public java.lang.String id
Unique id within model, may be null. Will be ignored byequals(MeshPart)
-
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 themeshto 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 themesh. When the mesh is indexed (Mesh.getNumIndices()> 0), this is the number of indices, otherwise it is the number of vertices.
-
center
public final Vector3 center
The offset to the center of the bounding box of the shape, only valid after the call toupdate().
-
halfExtents
public final Vector3 halfExtents
The location, relative tocenter, 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, whereVector3.xis half the width,Vector3.yis half the height andVector3.zis half the depth. Only valid after the call toupdate().
-
radius
public float radius
The radius relative tocenterof the bounding sphere of the shape, or negative if not calculated yet. This is the same as the length of thehalfExtentsmember. Seeupdate().
-
-
Constructor Detail
-
MeshPart
public MeshPart()
Construct a new MeshPart, with null values. The MeshPart is unusable until you set all members.
-
MeshPart
public MeshPart(java.lang.String id, Mesh 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.).
-
MeshPart
public MeshPart(MeshPart copyFrom)
Construct a new MeshPart which is an exact copy of the provided MeshPart.- Parameters:
copyFrom- The MeshPart to copy.
-
-
Method Detail
-
set
public MeshPart set(MeshPart 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 MeshPart set(java.lang.String id, Mesh mesh, int offset, int size, int type)
Set this MeshPart to given values, does notupdate()the bounding box values.- Returns:
- this MeshPart, for chaining.
-
update
public void update()
Calculates and updates thecenter,halfExtentsandradiusvalues. 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(MeshPart other)
Compares this MeshPart to the specified MeshPart and returns true if they both reference the sameMeshand theoffset,sizeandprimitiveTypemembers are equal. Theidmember is ignored.- Parameters:
other- The other MeshPart to compare this MeshPart to.- Returns:
- True when this MeshPart equals the other MeshPart (ignoring the
idmember), false otherwise.
-
equals
public boolean equals(java.lang.Object arg0)
- Overrides:
equalsin classjava.lang.Object
-
render
public void render(ShaderProgram shader, boolean autoBind)
Renders the mesh part using the specified shader, must be called afterShaderProgram.bind().- Parameters:
shader- the shader to be usedautoBind- overrides the autoBind member of the Mesh
-
render
public void render(ShaderProgram shader)
Renders the mesh part using the specified shader, must be called afterShaderProgram.bind().- Parameters:
shader- the shader to be used
-
-