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

public Class ShapeCache

extends Object
implements Disposable, RenderableProvider
Class Inheritance
All Implemented Interfaces
com.badlogic.gdx.graphics.g3d.RenderableProvider, com.badlogic.gdx.utils.Disposable
Imports
com.badlogic.gdx.graphics.GL20, .Mesh, .VertexAttribute, .VertexAttributes, .VertexAttributes.Usage, com.badlogic.gdx.graphics.g3d.Material, .ModelBatch, .Renderable, .RenderableProvider, com.badlogic.gdx.math.Matrix4, com.badlogic.gdx.utils.Array, .Disposable, .GdxRuntimeException, .Pool

A relatively lightweight class which can be used to render basic shapes which don't need a node structure and alike. Can be used for batching both static and dynamic shapes which share the same Material and transformation Matrix4 within the world. Use ModelBatch to render the `ShapeCache`. Must be disposed when no longer needed to release native resources.

How to use it :

// Create cache
ShapeCache cache = new ShapeCache();
// Build the cache, for dynamic shapes, this would be in the render method.
MeshPartBuilder builder = cache.begin();
FrustumShapeBuilder.build(builder, camera);
BoxShapeBuilder.build(builder, box);
cache.end()
// Render
modelBatch.render(cache);
// After using it
cache.dispose();
Author
realitix

Field Summary

Modifier and TypeField and Description
private final MeshBuilder
builder

Builder used to update the mesh

private boolean
private final String
private final Mesh
mesh

Mesh being rendered

private final Renderable

Constructor Summary

AccessConstructor and Description
public
ShapeCache()

Create a ShapeCache with default values

public
ShapeCache(int
max vertices in mesh
maxVertices
,
int
max indices in mesh
maxIndices
,
VertexAttributes
vertex attributes
attributes
,
int primitiveType)

Create a ShapeCache with parameters

Method Summary

Modifier and TypeMethod and Description
public MeshPartBuilder
begin()

Initialize ShapeCache for mesh generation with GL_LINES primitive type

public MeshPartBuilder
begin(int
OpenGL primitive type
primitiveType
)

Initialize ShapeCache for mesh generation

public void
dispose()

Implements com.badlogic.gdx.utils.Disposable.dispose.

Releases all resources of this object.

public void
end()

Generate mesh and renderable

public Material

Returns:

material
getMaterial
()

Allows to customize the material.

public void
public Matrix4

Returns:

world transform
getWorldTransform
()

Allows to customize the world transform matrix.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

builderback to summary
private final MeshBuilder builder

Builder used to update the mesh

buildingback to summary
private boolean building
idback to summary
private final String id
meshback to summary
private final Mesh mesh

Mesh being rendered

renderableback to summary
private final Renderable renderable

Constructor Detail

ShapeCacheback to summary
public ShapeCache()

Create a ShapeCache with default values

ShapeCacheback to summary
public ShapeCache(int maxVertices, int maxIndices, VertexAttributes attributes, int primitiveType)

Create a ShapeCache with parameters

Parameters
maxVertices:int

max vertices in mesh

maxIndices:int

max indices in mesh

attributes:VertexAttributes

vertex attributes

Method Detail

beginback to summary
public MeshPartBuilder begin()

Initialize ShapeCache for mesh generation with GL_LINES primitive type

beginback to summary
public MeshPartBuilder begin(int primitiveType)

Initialize ShapeCache for mesh generation

Parameters
primitiveType:int

OpenGL primitive type

disposeback to summary
public void dispose()

Implements com.badlogic.gdx.utils.Disposable.dispose.

Doc from com.badlogic.gdx.utils.Disposable.dispose.

Releases all resources of this object.

Annotations
@Override
endback to summary
public void end()

Generate mesh and renderable

getMaterialback to summary
public Material getMaterial()

Allows to customize the material.

Returns:Material

material

getRenderablesback to summary
public void getRenderables(Array<Renderable> renderables, Pool<Renderable> pool)

Implements com.badlogic.gdx.graphics.g3d.RenderableProvider.getRenderables.

Doc from com.badlogic.gdx.graphics.g3d.RenderableProvider.getRenderables.

Returns Renderable instances. Renderables are obtained from the provided Pool and added to the provided array. The Renderables obtained using Pool#obtain() will later be put back into the pool, do not store them internally. The resulting array can be rendered via a ModelBatch.

Annotations
@Override
getWorldTransformback to summary
public Matrix4 getWorldTransform()

Allows to customize the world transform matrix.

Returns:Matrix4

world transform