Class ShapeCache
- java.lang.Object
-
- com.badlogic.gdx.graphics.g3d.utils.ShapeCache
-
- All Implemented Interfaces:
RenderableProvider
,Disposable
public class ShapeCache extends java.lang.Object implements Disposable, RenderableProvider
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 sameMaterial
and transformationMatrix4
within the world. UseModelBatch
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();
-
-
Constructor Summary
Constructors Constructor Description ShapeCache()
Create a ShapeCache with default valuesShapeCache(int maxVertices, int maxIndices, VertexAttributes attributes, int primitiveType)
Create a ShapeCache with parameters
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MeshPartBuilder
begin()
Initialize ShapeCache for mesh generation with GL_LINES primitive typeMeshPartBuilder
begin(int primitiveType)
Initialize ShapeCache for mesh generationvoid
dispose()
Releases all resources of this object.void
end()
Generate mesh and renderableMaterial
getMaterial()
Allows to customize the material.void
getRenderables(Array<Renderable> renderables, Pool<Renderable> pool)
ReturnsRenderable
instances.Matrix4
getWorldTransform()
Allows to customize the world transform matrix.
-
-
-
Constructor Detail
-
ShapeCache
public ShapeCache()
Create a ShapeCache with default values
-
ShapeCache
public ShapeCache(int maxVertices, int maxIndices, VertexAttributes attributes, int primitiveType)
Create a ShapeCache with parameters- Parameters:
maxVertices
- max vertices in meshmaxIndices
- max indices in meshattributes
- vertex attributesprimitiveType
-
-
-
Method Detail
-
begin
public MeshPartBuilder begin()
Initialize ShapeCache for mesh generation with GL_LINES primitive type
-
begin
public MeshPartBuilder begin(int primitiveType)
Initialize ShapeCache for mesh generation- Parameters:
primitiveType
- OpenGL primitive type
-
end
public void end()
Generate mesh and renderable
-
getRenderables
public void getRenderables(Array<Renderable> renderables, Pool<Renderable> pool)
Description copied from interface:RenderableProvider
ReturnsRenderable
instances. Renderables are obtained from the providedPool
and added to the provided array. The Renderables obtained usingPool.obtain()
will later be put back into the pool, do not store them internally. The resulting array can be rendered via aModelBatch
.- Specified by:
getRenderables
in interfaceRenderableProvider
- Parameters:
renderables
- the output arraypool
- the pool to obtain Renderables from
-
getMaterial
public Material getMaterial()
Allows to customize the material.- Returns:
- material
-
getWorldTransform
public Matrix4 getWorldTransform()
Allows to customize the world transform matrix.- Returns:
- world transform
-
dispose
public void dispose()
Description copied from interface:Disposable
Releases all resources of this object.- Specified by:
dispose
in interfaceDisposable
-
-