Class ModelBuilder
- java.lang.Object
-
- com.badlogic.gdx.graphics.g3d.utils.ModelBuilder
-
public class ModelBuilder extends java.lang.ObjectHelper class to createModels from code. To start building use thebegin()method, when finished building use theend()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 thenode()method to start a new node. Use one of the #part(...) methods to add a part within a node. Thepart(String, int, VertexAttributes, Material)method will return aMeshPartBuilderwhich can be used to build the node part.
-
-
Constructor Summary
Constructors Constructor Description ModelBuilder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbegin()Begin building a new modelModelcreateArrow(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.ModelcreateArrow(Vector3 from, Vector3 to, Material material, long attributes)Convenience method to create a model with an arrow.ModelcreateBox(float width, float height, float depth, int primitiveType, Material material, long attributes)Convenience method to create a model with a single node containing a box shape.ModelcreateBox(float width, float height, float depth, Material material, long attributes)Convenience method to create a model with a single node containing a box shape.ModelcreateCapsule(float radius, float height, int divisions, int primitiveType, Material material, long attributes)Convenience method to create a model with a single node containing a capsule shape.ModelcreateCapsule(float radius, float height, int divisions, Material material, long attributes)Convenience method to create a model with a single node containing a capsule shape.ModelcreateCone(float width, float height, float depth, int divisions, int primitiveType, Material material, long attributes)Convenience method to create a model with a single node containing a cone shape.ModelcreateCone(float width, float height, float depth, int divisions, int primitiveType, Material material, long attributes, float angleFrom, float angleTo)Convenience method to create a model with a single node containing a cone shape.ModelcreateCone(float width, float height, float depth, int divisions, Material material, long attributes)Convenience method to create a model with a single node containing a cone shape.ModelcreateCone(float width, float height, float depth, int divisions, Material material, long attributes, float angleFrom, float angleTo)Convenience method to create a model with a single node containing a cone shape.ModelcreateCylinder(float width, float height, float depth, int divisions, int primitiveType, Material material, long attributes)Convenience method to create a model with a single node containing a cylinder shape.ModelcreateCylinder(float width, float height, float depth, int divisions, int primitiveType, Material material, long attributes, float angleFrom, float angleTo)Convenience method to create a model with a single node containing a cylinder shape.ModelcreateCylinder(float width, float height, float depth, int divisions, Material material, long attributes)Convenience method to create a model with a single node containing a cylinder shape.ModelcreateCylinder(float width, float height, float depth, int divisions, Material material, long attributes, float angleFrom, float angleTo)Convenience method to create a model with a single node containing a cylinder shape.ModelcreateLineGrid(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.ModelcreateRect(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, Material material, long attributes)Convenience method to create a model with a single node containing a rectangle shape.ModelcreateRect(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, Material material, long attributes)Convenience method to create a model with a single node containing a rectangle shape.ModelcreateSphere(float width, float height, float depth, int divisionsU, int divisionsV, int primitiveType, Material material, long attributes)Convenience method to create a model with a single node containing a sphere shape.ModelcreateSphere(float width, float height, float depth, int divisionsU, int divisionsV, int primitiveType, Material material, long attributes, float angleUFrom, float angleUTo, float angleVFrom, float angleVTo)Convenience method to create a model with a single node containing a sphere shape.ModelcreateSphere(float width, float height, float depth, int divisionsU, int divisionsV, Material material, long attributes)Convenience method to create a model with a single node containing a sphere shape.ModelcreateSphere(float width, float height, float depth, int divisionsU, int divisionsV, Material material, long attributes, float angleUFrom, float angleUTo, float angleVFrom, float angleVTo)Convenience method to create a model with a single node containing a sphere shape.ModelcreateXYZCoordinates(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.ModelcreateXYZCoordinates(float axisLength, Material material, long attributes)Modelend()End building the model.voidmanage(Disposable disposable)Add theDisposableobject to the model, causing it to be disposed when the model is disposed.Nodenode()Add a node to the model.protected Nodenode(Node node)Adds theNodeto the model and sets it active for building.Nodenode(java.lang.String id, Model model)Adds the nodes of the specified model to a new node of the model being build.voidpart(MeshPart meshpart, Material material)Adds the specified MeshPart to the current Node.MeshPartBuilderpart(java.lang.String id, int primitiveType, long attributes, Material material)Creates a new MeshPart within the current Node and returns aMeshPartBuilderwhich can be used to build the shape of the part.MeshPartBuilderpart(java.lang.String id, int primitiveType, VertexAttributes attributes, Material material)Creates a new MeshPart within the current Node and returns aMeshPartBuilderwhich can be used to build the shape of the part.MeshPartpart(java.lang.String id, Mesh mesh, int primitiveType, int offset, int size, Material material)Adds the specified mesh part to the current node.MeshPartpart(java.lang.String id, Mesh mesh, int primitiveType, Material material)Adds the specified mesh part to the current node.static voidrebuildReferences(Model model)
-
-
-
Method Detail
-
begin
public void begin()
Begin building a new model
-
end
public Model end()
End building the model.- Returns:
- The newly created model. Call the
Model.dispose()method when no longer used.
-
node
protected Node node(Node node)
Adds theNodeto the model and sets it active for building. Use any of the part(...) method to add a NodePart.
-
node
public Node node()
Add a node to the model. Use any of the part(...) method to add a NodePart.- Returns:
- The node being created.
-
node
public Node node(java.lang.String id, 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 theModel.dispose()method on that model.- Returns:
- The newly created node containing the nodes of the given model.
-
manage
public void manage(Disposable disposable)
Add theDisposableobject to the model, causing it to be disposed when the model is disposed.
-
part
public void part(MeshPart meshpart, 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, usemanage(Disposable)to add those to the model.
-
part
public MeshPart part(java.lang.String id, Mesh mesh, int primitiveType, int offset, int size, 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, usemanage(Disposable)to add those to the model.- Returns:
- The added MeshPart.
-
part
public MeshPart part(java.lang.String id, Mesh mesh, int primitiveType, 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, usemanage(Disposable)to add those to the model.- Returns:
- The added MeshPart.
-
part
public MeshPartBuilder part(java.lang.String id, int primitiveType, VertexAttributes attributes, Material material)
Creates a new MeshPart within the current Node and returns aMeshPartBuilderwhich can be used to build the shape of the part. If possible a previously usedMeshPartBuilderwill 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, usemanage(Disposable)to add those to the model.- Returns:
- The
MeshPartBuilderyou can use to build the MeshPart.
-
part
public MeshPartBuilder part(java.lang.String id, int primitiveType, long attributes, Material material)
Creates a new MeshPart within the current Node and returns aMeshPartBuilderwhich can be used to build the shape of the part. If possible a previously usedMeshPartBuilderwill 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, usemanage(Disposable)to add those to the model.- Parameters:
attributes- bitwise mask of theVertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.- Returns:
- The
MeshPartBuilderyou can use to build the MeshPart.
-
createBox
public Model createBox(float width, float height, float depth, Material material, 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, useModel.manageDisposable(Disposable)to add those to the model.- Parameters:
attributes- bitwise mask of theVertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.
-
createBox
public Model createBox(float width, float height, float depth, int primitiveType, Material material, 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, useModel.manageDisposable(Disposable)to add those to the model.- Parameters:
attributes- bitwise mask of theVertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.
-
createRect
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, Material material, 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, useModel.manageDisposable(Disposable)to add those to the model.- Parameters:
attributes- bitwise mask of theVertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.
-
createRect
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, Material material, 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, useModel.manageDisposable(Disposable)to add those to the model.- Parameters:
attributes- bitwise mask of theVertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.
-
createCylinder
public Model createCylinder(float width, float height, float depth, int divisions, Material material, 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, useModel.manageDisposable(Disposable)to add those to the model.- Parameters:
attributes- bitwise mask of theVertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.
-
createCylinder
public Model createCylinder(float width, float height, float depth, int divisions, int primitiveType, Material material, 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, useModel.manageDisposable(Disposable)to add those to the model.- Parameters:
attributes- bitwise mask of theVertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.
-
createCylinder
public Model createCylinder(float width, float height, float depth, int divisions, Material material, 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, useModel.manageDisposable(Disposable)to add those to the model.- Parameters:
attributes- bitwise mask of theVertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.
-
createCylinder
public Model createCylinder(float width, float height, float depth, int divisions, int primitiveType, Material material, 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, useModel.manageDisposable(Disposable)to add those to the model.- Parameters:
attributes- bitwise mask of theVertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.
-
createCone
public Model createCone(float width, float height, float depth, int divisions, Material material, 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, useModel.manageDisposable(Disposable)to add those to the model.- Parameters:
attributes- bitwise mask of theVertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.
-
createCone
public Model createCone(float width, float height, float depth, int divisions, int primitiveType, Material material, 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, useModel.manageDisposable(Disposable)to add those to the model.- Parameters:
attributes- bitwise mask of theVertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.
-
createCone
public Model createCone(float width, float height, float depth, int divisions, Material material, 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, useModel.manageDisposable(Disposable)to add those to the model.- Parameters:
attributes- bitwise mask of theVertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.
-
createCone
public Model createCone(float width, float height, float depth, int divisions, int primitiveType, Material material, 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, useModel.manageDisposable(Disposable)to add those to the model.- Parameters:
attributes- bitwise mask of theVertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.
-
createSphere
public Model createSphere(float width, float height, float depth, int divisionsU, int divisionsV, Material material, 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, useModel.manageDisposable(Disposable)to add those to the model.- Parameters:
attributes- bitwise mask of theVertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.
-
createSphere
public Model createSphere(float width, float height, float depth, int divisionsU, int divisionsV, int primitiveType, Material material, 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, useModel.manageDisposable(Disposable)to add those to the model.- Parameters:
attributes- bitwise mask of theVertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.
-
createSphere
public Model createSphere(float width, float height, float depth, int divisionsU, int divisionsV, Material material, 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, useModel.manageDisposable(Disposable)to add those to the model.- Parameters:
attributes- bitwise mask of theVertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.
-
createSphere
public Model createSphere(float width, float height, float depth, int divisionsU, int divisionsV, int primitiveType, Material material, 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, useModel.manageDisposable(Disposable)to add those to the model.- Parameters:
attributes- bitwise mask of theVertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.
-
createCapsule
public Model createCapsule(float radius, float height, int divisions, Material material, 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, useModel.manageDisposable(Disposable)to add those to the model.- Parameters:
attributes- bitwise mask of theVertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.
-
createCapsule
public Model createCapsule(float radius, float height, int divisions, int primitiveType, Material material, 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, useModel.manageDisposable(Disposable)to add those to the model.- Parameters:
attributes- bitwise mask of theVertexAttributes.Usage, only Position, Color, Normal and TextureCoordinates is supported.
-
rebuildReferences
public static void rebuildReferences(Model model)
-
createXYZCoordinates
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, useModel.manageDisposable(Disposable)to add those to the model.- Parameters:
axisLength- Length of each axis.capLength- is the height of the cap in percentage, must be in (0,1)stemThickness- is the percentage of stem diameter compared to cap diameter, must be in (0,1]divisions- the amount of vertices used to generate the cap and stem ellipsoidal bases
-
createXYZCoordinates
public Model createXYZCoordinates(float axisLength, Material material, long attributes)
-
createArrow
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, useModel.manageDisposable(Disposable)to add those to the model.- Parameters:
material-capLength- is the height of the cap in percentage, must be in (0,1)stemThickness- is the percentage of stem diameter compared to cap diameter, must be in (0,1]divisions- the amount of vertices used to generate the cap and stem ellipsoidal bases
-
createArrow
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, useModel.manageDisposable(Disposable)to add those to the model.
-
createLineGrid
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, useModel.manageDisposable(Disposable)to add those to the model.- Parameters:
xDivisions- row count along x axis.zDivisions- row count along z axis.xSize- Length of a single row on x.zSize- Length of a single row on z.
-
-