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

public Class ModelBuilder

extends Object
Class Inheritance
Imports
com.badlogic.gdx.graphics.Color, .GL20, .Mesh, .VertexAttributes, com.badlogic.gdx.graphics.g3d.Material, .Model, com.badlogic.gdx.graphics.g3d.model.MeshPart, .Node, .NodePart, com.badlogic.gdx.math.Matrix4, .Vector3, com.badlogic.gdx.utils.Array, .Disposable, .GdxRuntimeException

Helper class to create Models from code. To start building use the begin() method, when finished building use the end() method. The end method returns the model just build. Building cannot be nested, only one model (per ModelBuilder) can be build at the time. The same ModelBuilder can be used to build multiple models sequential. Use the node() method to start a new node. Use one of the #part(...) methods to add a part within a node. The part(String, int, VertexAttributes, Material) method will return a MeshPartBuilder which can be used to build the node part.
Author
Xoppa

Field Summary

Modifier and TypeField and Description
protected Array<MeshBuilder>
builders

The mesh builders created between begin and end

protected Model
model

The model currently being build

protected Node
node

The node currently being build

private Matrix4

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
begin()

Begin building a new model

public Model
createArrow(float x1, float y1, float z1, float x2, float y2, float z2, float
is the height of the cap in percentage, must be in (0,1)
capLength
,
float
is the percentage of stem diameter compared to cap diameter, must be in (0,1]
stemThickness
,
int
the amount of vertices used to generate the cap and stem ellipsoidal bases
divisions
,
int primitiveType, Material material, long attributes)

Convenience method to create a model with an arrow.

public Model
createArrow(Vector3 from, Vector3 to, Material material, long attributes)

Convenience method to create a model with an arrow.

public Model
createBox(float width, float height, float depth, final Material material, final long
bitwise mask of the com.badlogic.gdx.graphics.VertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.
attributes
)

Convenience method to create a model with a single node containing a box shape.

public Model
createBox(float width, float height, float depth, int primitiveType, final Material material, final long
bitwise mask of the com.badlogic.gdx.graphics.VertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.
attributes
)

Convenience method to create a model with a single node containing a box shape.

public Model
createCapsule(float radius, float height, int divisions, final Material material, final long
bitwise mask of the com.badlogic.gdx.graphics.VertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.
attributes
)

Convenience method to create a model with a single node containing a capsule shape.

public Model
createCapsule(float radius, float height, int divisions, int primitiveType, final Material material, final long
bitwise mask of the com.badlogic.gdx.graphics.VertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.
attributes
)

Convenience method to create a model with a single node containing a capsule shape.

public Model
createCone(float width, float height, float depth, int divisions, final Material material, final long
bitwise mask of the com.badlogic.gdx.graphics.VertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.
attributes
)

Convenience method to create a model with a single node containing a cone shape.

public Model
createCone(float width, float height, float depth, int divisions, int primitiveType, final Material material, final long
bitwise mask of the com.badlogic.gdx.graphics.VertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.
attributes
)

Convenience method to create a model with a single node containing a cone shape.

public Model
createCone(float width, float height, float depth, int divisions, final Material material, final long
bitwise mask of the com.badlogic.gdx.graphics.VertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.
attributes
,
float angleFrom, float angleTo)

Convenience method to create a model with a single node containing a cone shape.

public Model
createCone(float width, float height, float depth, int divisions, int primitiveType, final Material material, final long
bitwise mask of the com.badlogic.gdx.graphics.VertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.
attributes
,
float angleFrom, float angleTo)

Convenience method to create a model with a single node containing a cone shape.

public Model
createCylinder(float width, float height, float depth, int divisions, final Material material, final long
bitwise mask of the com.badlogic.gdx.graphics.VertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.
attributes
)

Convenience method to create a model with a single node containing a cylinder shape.

public Model
createCylinder(float width, float height, float depth, int divisions, int primitiveType, final Material material, final long
bitwise mask of the com.badlogic.gdx.graphics.VertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.
attributes
)

Convenience method to create a model with a single node containing a cylinder shape.

public Model
createCylinder(float width, float height, float depth, int divisions, final Material material, final long
bitwise mask of the com.badlogic.gdx.graphics.VertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.
attributes
,
float angleFrom, float angleTo)

Convenience method to create a model with a single node containing a cylinder shape.

public Model
createCylinder(float width, float height, float depth, int divisions, int primitiveType, final Material material, final long
bitwise mask of the com.badlogic.gdx.graphics.VertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.
attributes
,
float angleFrom, float angleTo)

Convenience method to create a model with a single node containing a cylinder shape.

public Model
createLineGrid(int
row count along x axis.
xDivisions
,
int
row count along z axis.
zDivisions
,
float
Length of a single row on x.
xSize
,
float
Length of a single row on z.
zSize
,
Material material, long attributes)

Convenience method to create a model which represents a grid of lines on the XZ plane.

public Model
createRect(float x00, float y00, float z00, float x10, float y10, float z10, float x11, float y11, float z11, float x01, float y01, float z01, float normalX, float normalY, float normalZ, final Material material, final long
bitwise mask of the com.badlogic.gdx.graphics.VertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.
attributes
)

Convenience method to create a model with a single node containing a rectangle shape.

public Model
createRect(float x00, float y00, float z00, float x10, float y10, float z10, float x11, float y11, float z11, float x01, float y01, float z01, float normalX, float normalY, float normalZ, int primitiveType, final Material material, final long
bitwise mask of the com.badlogic.gdx.graphics.VertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.
attributes
)

Convenience method to create a model with a single node containing a rectangle shape.

public Model
createSphere(float width, float height, float depth, int divisionsU, int divisionsV, final Material material, final long
bitwise mask of the com.badlogic.gdx.graphics.VertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.
attributes
)

Convenience method to create a model with a single node containing a sphere shape.

public Model
createSphere(float width, float height, float depth, int divisionsU, int divisionsV, int primitiveType, final Material material, final long
bitwise mask of the com.badlogic.gdx.graphics.VertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.
attributes
)

Convenience method to create a model with a single node containing a sphere shape.

public Model
createSphere(float width, float height, float depth, int divisionsU, int divisionsV, final Material material, final long
bitwise mask of the com.badlogic.gdx.graphics.VertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.
attributes
,
float angleUFrom, float angleUTo, float angleVFrom, float angleVTo)

Convenience method to create a model with a single node containing a sphere shape.

public Model
createSphere(float width, float height, float depth, int divisionsU, int divisionsV, int primitiveType, final Material material, final long
bitwise mask of the com.badlogic.gdx.graphics.VertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.
attributes
,
float angleUFrom, float angleUTo, float angleVFrom, float angleVTo)

Convenience method to create a model with a single node containing a sphere shape.

public Model
createXYZCoordinates(float
Length of each axis.
axisLength
,
float
is the height of the cap in percentage, must be in (0,1)
capLength
,
float
is the percentage of stem diameter compared to cap diameter, must be in (0,1]
stemThickness
,
int
the amount of vertices used to generate the cap and stem ellipsoidal bases
divisions
,
int primitiveType, Material material, long attributes)

Convenience method to create a model with three orthonormal vectors shapes.

public Model
createXYZCoordinates(float axisLength, Material material, long attributes)

public Model

Returns:

The newly created model. Call the Model#dispose() method when no longer used.
end
()

End building the model.

private void
private MeshBuilder
getBuilder(final VertexAttributes attributes)

public void
manage(final Disposable disposable)

Add the Disposable object to the model, causing it to be disposed when the model is disposed.

protected Node
node(final Node node)

Adds the Node to the model and sets it active for building.

public Node

Returns:

The node being created.
node
()

Add a node to the model.

public Node

Returns:

The newly created node containing the nodes of the given model.
node
(final String id, final Model model)

Adds the nodes of the specified model to a new node of the model being build.

public void
part(final MeshPart meshpart, final Material material)

Adds the specified MeshPart to the current Node.

public MeshPart

Returns:

The added MeshPart.
part
(final String id, final Mesh mesh, int primitiveType, int offset, int size, final Material material)

Adds the specified mesh part to the current node.

public MeshPart

Returns:

The added MeshPart.
part
(final String id, final Mesh mesh, int primitiveType, final Material material)

Adds the specified mesh part to the current node.

public MeshPartBuilder

Returns:

The MeshPartBuilder you can use to build the MeshPart.
part
(final String id, int primitiveType, final VertexAttributes attributes, final Material material)

Creates a new MeshPart within the current Node and returns a MeshPartBuilder which can be used to build the shape of the part.

public MeshPartBuilder

Returns:

The MeshPartBuilder you can use to build the MeshPart.
part
(final String id, int primitiveType, final long
bitwise mask of the com.badlogic.gdx.graphics.VertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.
attributes
,
final Material material)

Creates a new MeshPart within the current Node and returns a MeshPartBuilder which can be used to build the shape of the part.

public static void
rebuildReferences(final Model model)

Resets the references to Materials, Meshes and MeshParts within the model to the ones used within it's nodes.

private static void
rebuildReferences(final Model model, final Node node)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

buildersback to summary
protected Array<MeshBuilder> builders

The mesh builders created between begin and end

modelback to summary
protected Model model

The model currently being build

nodeback to summary
protected Node node

The node currently being build

tmpTransformback to summary
private Matrix4 tmpTransform

Constructor Detail

ModelBuilderback to summary
public ModelBuilder()

Method Detail

beginback to summary
public void begin()

Begin building a new model

createArrowback to summary
public Model createArrow(float x1, float y1, float z1, float x2, float y2, float z2, float capLength, float stemThickness, int divisions, int primitiveType, Material material, long attributes)

Convenience method to create a model with an arrow. The resources the Material might contain are not managed, use Model#manageDisposable(Disposable) to add those to the model.

Parameters
capLength:float

is the height of the cap in percentage, must be in (0,1)

stemThickness:float

is the percentage of stem diameter compared to cap diameter, must be in (0,1]

divisions:int

the amount of vertices used to generate the cap and stem ellipsoidal bases

createArrowback to summary
public Model createArrow(Vector3 from, Vector3 to, Material material, long attributes)

Convenience method to create a model with an arrow. The resources the Material might contain are not managed, use Model#manageDisposable(Disposable) to add those to the model.

createBoxback to summary
public Model createBox(float width, float height, float depth, final Material material, final long attributes)

Convenience method to create a model with a single node containing a box shape. The resources the Material might contain are not managed, use Model#manageDisposable(Disposable) to add those to the model.

Parameters
attributes:long

bitwise mask of the com.badlogic.gdx.graphics.VertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.

createBoxback to summary
public Model createBox(float width, float height, float depth, int primitiveType, final Material material, final long attributes)

Convenience method to create a model with a single node containing a box shape. The resources the Material might contain are not managed, use Model#manageDisposable(Disposable) to add those to the model.

Parameters
attributes:long

bitwise mask of the com.badlogic.gdx.graphics.VertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.

createCapsuleback to summary
public Model createCapsule(float radius, float height, int divisions, final Material material, final long attributes)

Convenience method to create a model with a single node containing a capsule shape. The resources the Material might contain are not managed, use Model#manageDisposable(Disposable) to add those to the model.

Parameters
attributes:long

bitwise mask of the com.badlogic.gdx.graphics.VertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.

createCapsuleback to summary
public Model createCapsule(float radius, float height, int divisions, int primitiveType, final Material material, final long attributes)

Convenience method to create a model with a single node containing a capsule shape. The resources the Material might contain are not managed, use Model#manageDisposable(Disposable) to add those to the model.

Parameters
attributes:long

bitwise mask of the com.badlogic.gdx.graphics.VertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.

createConeback to summary
public Model createCone(float width, float height, float depth, int divisions, final Material material, final long attributes)

Convenience method to create a model with a single node containing a cone shape. The resources the Material might contain are not managed, use Model#manageDisposable(Disposable) to add those to the model.

Parameters
attributes:long

bitwise mask of the com.badlogic.gdx.graphics.VertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.

createConeback to summary
public Model createCone(float width, float height, float depth, int divisions, int primitiveType, final Material material, final long attributes)

Convenience method to create a model with a single node containing a cone shape. The resources the Material might contain are not managed, use Model#manageDisposable(Disposable) to add those to the model.

Parameters
attributes:long

bitwise mask of the com.badlogic.gdx.graphics.VertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.

createConeback to summary
public Model createCone(float width, float height, float depth, int divisions, final Material material, final long attributes, float angleFrom, float angleTo)

Convenience method to create a model with a single node containing a cone shape. The resources the Material might contain are not managed, use Model#manageDisposable(Disposable) to add those to the model.

Parameters
attributes:long

bitwise mask of the com.badlogic.gdx.graphics.VertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.

createConeback to summary
public Model createCone(float width, float height, float depth, int divisions, int primitiveType, final Material material, final long attributes, float angleFrom, float angleTo)

Convenience method to create a model with a single node containing a cone shape. The resources the Material might contain are not managed, use Model#manageDisposable(Disposable) to add those to the model.

Parameters
attributes:long

bitwise mask of the com.badlogic.gdx.graphics.VertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.

createCylinderback to summary
public Model createCylinder(float width, float height, float depth, int divisions, final Material material, final long attributes)

Convenience method to create a model with a single node containing a cylinder shape. The resources the Material might contain are not managed, use Model#manageDisposable(Disposable) to add those to the model.

Parameters
attributes:long

bitwise mask of the com.badlogic.gdx.graphics.VertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.

createCylinderback to summary
public Model createCylinder(float width, float height, float depth, int divisions, int primitiveType, final Material material, final long attributes)

Convenience method to create a model with a single node containing a cylinder shape. The resources the Material might contain are not managed, use Model#manageDisposable(Disposable) to add those to the model.

Parameters
attributes:long

bitwise mask of the com.badlogic.gdx.graphics.VertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.

createCylinderback to summary
public Model createCylinder(float width, float height, float depth, int divisions, final Material material, final long attributes, float angleFrom, float angleTo)

Convenience method to create a model with a single node containing a cylinder shape. The resources the Material might contain are not managed, use Model#manageDisposable(Disposable) to add those to the model.

Parameters
attributes:long

bitwise mask of the com.badlogic.gdx.graphics.VertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.

createCylinderback to summary
public Model createCylinder(float width, float height, float depth, int divisions, int primitiveType, final Material material, final long attributes, float angleFrom, float angleTo)

Convenience method to create a model with a single node containing a cylinder shape. The resources the Material might contain are not managed, use Model#manageDisposable(Disposable) to add those to the model.

Parameters
attributes:long

bitwise mask of the com.badlogic.gdx.graphics.VertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.

createLineGridback to summary
public Model createLineGrid(int xDivisions, int zDivisions, float xSize, float zSize, Material material, long attributes)

Convenience method to create a model which represents a grid of lines on the XZ plane. The resources the Material might contain are not managed, use Model#manageDisposable(Disposable) to add those to the model.

Parameters
xDivisions:int

row count along x axis.

zDivisions:int

row count along z axis.

xSize:float

Length of a single row on x.

zSize:float

Length of a single row on z.

createRectback to summary
public Model createRect(float x00, float y00, float z00, float x10, float y10, float z10, float x11, float y11, float z11, float x01, float y01, float z01, float normalX, float normalY, float normalZ, final Material material, final long attributes)

Convenience method to create a model with a single node containing a rectangle shape. The resources the Material might contain are not managed, use Model#manageDisposable(Disposable) to add those to the model.

Parameters
attributes:long

bitwise mask of the com.badlogic.gdx.graphics.VertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.

createRectback to summary
public Model createRect(float x00, float y00, float z00, float x10, float y10, float z10, float x11, float y11, float z11, float x01, float y01, float z01, float normalX, float normalY, float normalZ, int primitiveType, final Material material, final long attributes)

Convenience method to create a model with a single node containing a rectangle shape. The resources the Material might contain are not managed, use Model#manageDisposable(Disposable) to add those to the model.

Parameters
attributes:long

bitwise mask of the com.badlogic.gdx.graphics.VertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.

createSphereback to summary
public Model createSphere(float width, float height, float depth, int divisionsU, int divisionsV, final Material material, final long attributes)

Convenience method to create a model with a single node containing a sphere shape. The resources the Material might contain are not managed, use Model#manageDisposable(Disposable) to add those to the model.

Parameters
attributes:long

bitwise mask of the com.badlogic.gdx.graphics.VertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.

createSphereback to summary
public Model createSphere(float width, float height, float depth, int divisionsU, int divisionsV, int primitiveType, final Material material, final long attributes)

Convenience method to create a model with a single node containing a sphere shape. The resources the Material might contain are not managed, use Model#manageDisposable(Disposable) to add those to the model.

Parameters
attributes:long

bitwise mask of the com.badlogic.gdx.graphics.VertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.

createSphereback to summary
public Model createSphere(float width, float height, float depth, int divisionsU, int divisionsV, final Material material, final long attributes, float angleUFrom, float angleUTo, float angleVFrom, float angleVTo)

Convenience method to create a model with a single node containing a sphere shape. The resources the Material might contain are not managed, use Model#manageDisposable(Disposable) to add those to the model.

Parameters
attributes:long

bitwise mask of the com.badlogic.gdx.graphics.VertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.

createSphereback to summary
public Model createSphere(float width, float height, float depth, int divisionsU, int divisionsV, int primitiveType, final Material material, final long attributes, float angleUFrom, float angleUTo, float angleVFrom, float angleVTo)

Convenience method to create a model with a single node containing a sphere shape. The resources the Material might contain are not managed, use Model#manageDisposable(Disposable) to add those to the model.

Parameters
attributes:long

bitwise mask of the com.badlogic.gdx.graphics.VertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.

createXYZCoordinatesback to summary
public Model createXYZCoordinates(float axisLength, float capLength, float stemThickness, int divisions, int primitiveType, Material material, long attributes)

Convenience method to create a model with three orthonormal vectors shapes. The resources the Material might contain are not managed, use Model#manageDisposable(Disposable) to add those to the model.

Parameters
axisLength:float

Length of each axis.

capLength:float

is the height of the cap in percentage, must be in (0,1)

stemThickness:float

is the percentage of stem diameter compared to cap diameter, must be in (0,1]

divisions:int

the amount of vertices used to generate the cap and stem ellipsoidal bases

createXYZCoordinatesback to summary
public Model createXYZCoordinates(float axisLength, Material material, long attributes)
endback to summary
public Model end()

End building the model.

Returns:Model

The newly created model. Call the Model#dispose() method when no longer used.

endnodeback to summary
private void endnode()
getBuilderback to summary
private MeshBuilder getBuilder(final VertexAttributes attributes)
manageback to summary
public void manage(final Disposable disposable)

Add the Disposable object to the model, causing it to be disposed when the model is disposed.

nodeback to summary
protected Node node(final Node node)

Adds the Node to the model and sets it active for building. Use any of the part(...) method to add a NodePart.

nodeback to summary
public Node node()

Add a node to the model. Use any of the part(...) method to add a NodePart.

Returns:Node

The node being created.

nodeback to summary
public Node node(final String id, final Model model)

Adds the nodes of the specified model to a new node of the model being build. After this method the given model can no longer be used. Do not call the Model#dispose() method on that model.

Returns:Node

The newly created node containing the nodes of the given model.

partback to summary
public void part(final MeshPart meshpart, final Material material)

Adds the specified MeshPart to the current Node. The Mesh will be managed by the model and disposed when the model is disposed. The resources the Material might contain are not managed, use manage(Disposable) to add those to the model.

partback to summary
public MeshPart part(final String id, final Mesh mesh, int primitiveType, int offset, int size, final Material material)

Adds the specified mesh part to the current node. The Mesh will be managed by the model and disposed when the model is disposed. The resources the Material might contain are not managed, use manage(Disposable) to add those to the model.

Returns:MeshPart

The added MeshPart.

partback to summary
public MeshPart part(final String id, final Mesh mesh, int primitiveType, final Material material)

Adds the specified mesh part to the current node. The Mesh will be managed by the model and disposed when the model is disposed. The resources the Material might contain are not managed, use manage(Disposable) to add those to the model.

Returns:MeshPart

The added MeshPart.

partback to summary
public MeshPartBuilder part(final String id, int primitiveType, final VertexAttributes attributes, final Material material)

Creates a new MeshPart within the current Node and returns a MeshPartBuilder which can be used to build the shape of the part. If possible a previously used MeshPartBuilder will be reused, to reduce the number of mesh binds. Therefore you can only build one part at a time. The resources the Material might contain are not managed, use manage(Disposable) to add those to the model.

Returns:MeshPartBuilder

The MeshPartBuilder you can use to build the MeshPart.

partback to summary
public MeshPartBuilder part(final String id, int primitiveType, final long attributes, final Material material)

Creates a new MeshPart within the current Node and returns a MeshPartBuilder which can be used to build the shape of the part. If possible a previously used MeshPartBuilder will be reused, to reduce the number of mesh binds. Therefore you can only build one part at a time. The resources the Material might contain are not managed, use manage(Disposable) to add those to the model.

Parameters
attributes:long

bitwise mask of the com.badlogic.gdx.graphics.VertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.

Returns:MeshPartBuilder

The MeshPartBuilder you can use to build the MeshPart.

rebuildReferencesback to summary
public static void rebuildReferences(final Model model)

Resets the references to Materials, Meshes and MeshParts within the model to the ones used within it's nodes. This will make the model responsible for disposing all referenced meshes.

rebuildReferencesback to summary
private static void rebuildReferences(final Model model, final Node node)