basics

Standard Shapes


Standard Shapes

Methods of Creation

A Playground Example of the Standard Shapes -


From BJS 2.3 onwards a mesh is created using MeshBuilder. Shapes are created using the using the following format

var mesh = BABYLON.MeshBuilder.CreateMesh(name, {param1 : val1, param2: val2}, scene);

This method has the advantages of making some (or all) of the parameters optional depending on the mesh and provides more features to the created mesh over the legacy method.

The legacy method which has the form

var mesh = BABYLON.Mesh.CreateMesh(name, param1, param2, ..., scene);

is still available and will often be seen in Playground examples.

Box

Example :

var box = BABYLON.MeshBuilder.CreateBox("box", {height: 5}, scene);

Properties, all optional :

property value default value
size (number) size of each box side 1
height (number) height size, overwrites size property size
width (number) width size, overwrites size property size
depth (number) depth size, overwrites size property size
faceColors (Color4[]) array of 6 Color4, one per box face Color4(1, 1, 1, 1) for each side
faceUV (Vector4[]) array of 6 Vector4, one per box face UVs(0, 0, 1, 1) for each side
updatable (boolean) true if the mesh is updatable false
sideOrientation (number) side orientation DEFAULTSIDE

Sphere

Example :

var sphere = BABYLON.MeshBuilder.CreateSphere("sphere", {diameter: 2, diameterX: 3}, scene);

Properties, all optional :

property value default value
segments (number) number of horizontal segments 32
diameter (number) diameter of the sphere 1
diameterX (number) diameter on X axis, overwrites diameter property diameter
diameterY (number) diameter on Y axis, overwrites diameter property diameter
diameterZ (number) diameter on Z axis, overwrites diameter property diameter
arc (number) ratio of the circumference (latitude) between 0 and 1 1
slice (number) ratio of the height (longitude) between 0 and 1 1
updatable (boolean) true if the mesh is updatable false
sideOrientation (number) side orientation DEFAULTSIDE

Cylinder or Cone

If you set diameterTop to zero, you get a cone instead of a cylinder. Example :

var cone = BABYLON.MeshBuilder.CreateCylinder("cone", {diameterTop: 0, tessellation: 4}, scene);

Properties, all optional :

property value default value
height (number) height of the cylinder 2
diameterTop (number) diameter of the top cap, can be zero to create a cone, overwrites the diameter property 1
diameterBottom (number) diameter of the bottom cap, can't be zero, overwrites the diameter property 1
diameter (number) diameter of both caps 1
tessellation (number) number of radial sides 24
subdivisions (number) number of rings 1
faceColors (Color4[]) array of 3 Color4, 0 : bottom cap, 1 : cylinder tube, 2 : top cap Color4(1, 1, 1, 1) for each face
faceUV (Vector4[]) array of 3 Vector4, 0 : bottom cap, 1 : cylinder tube, 2 : top cap UVs(0, 0, 1, 1) for each face
arc (number) ratio of the circumference between 0 and 1 1
updatable (boolean) true if the mesh is updatable false
sideOrientation (number) side orientation DEFAULTSIDE

Plane

Example :

var plane = BABYLON.MeshBuilder.CreatePlane("plane", {width: 5}, scene);

Properties, all optional :

property value default value
size (number) side size of the plane 1
width (number) size of the width size
height (number) size of the height size
updatable (boolean) true if the mesh is updatable false
sideOrientation (number) side orientation DEFAULTSIDE
sourcePlane (Plane) source plane (math) the mesh will be transformed to null

Ground

Example :

var ground = BABYLON.MeshBuilder.CreateGround("gd", {width: 6, subdivsions: 4}, scene);

Properties, all optional :

property value default value
width (number) size of the width 1
height (number) size of the height 1
updatable (boolean) true if the mesh is updatable false
subdivisions (number) number of square subdivisions 1

Updatable

Where a standard shape has an updatable parameter in its options it means that it is possible to alter the data associated with each vertex of the mesh and so alter the shape of the mesh. For more information see Updating Vertices

Further Reading

Intermediate

Additional Shapes
Parametric Shapes
Polyhedra Shapes

Advanced

Ribbons In Detail
Maths Makes Ribbons
Decals