Class ShapeCache
java.lang.Object
com.badlogic.gdx.graphics.g3d.utils.ShapeCache
- All Implemented Interfaces:
RenderableProvider
,Disposable
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();
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a ShapeCache with default valuesShapeCache
(int maxVertices, int maxIndices, VertexAttributes attributes, int primitiveType) Create a ShapeCache with parameters -
Method Summary
Modifier and TypeMethodDescriptionbegin()
Initialize ShapeCache for mesh generation with GL_LINES primitive typebegin
(int primitiveType) Initialize ShapeCache for mesh generationvoid
dispose()
Releases all resources of this object.void
end()
Generate mesh and renderableAllows to customize the material.void
getRenderables
(Array<Renderable> renderables, Pool<Renderable> pool) ReturnsRenderable
instances.Allows to customize the world transform matrix.
-
Constructor Details
-
ShapeCache
public ShapeCache()Create a ShapeCache with default values -
ShapeCache
Create a ShapeCache with parameters- Parameters:
maxVertices
- max vertices in meshmaxIndices
- max indices in meshattributes
- vertex attributesprimitiveType
-
-
-
Method Details
-
begin
Initialize ShapeCache for mesh generation with GL_LINES primitive type -
begin
Initialize ShapeCache for mesh generation- Parameters:
primitiveType
- OpenGL primitive type
-
end
public void end()Generate mesh and renderable -
getRenderables
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
Allows to customize the material.- Returns:
- material
-
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
-