Extruding Shapes

Extruded Shape

An extruded shape is created by defining a shape profile using vector3 coordinates in the xy plane and providing a path along which the profile will be extruded. You must set at least the shape and path options. On update, you must set the shape, path and instance options and you can set the scale and rotation options.

On creation the local origin of an extrusion is coincident with the world origin. It is not possible to give a position relative to the constructed shape as this depends on the data sets used.

The profile shape's local origin is (0, 0, 0) relative to its defining coordinates and it is the local origin that runs along the path during the extrusion.

When you need the appearance of a solid shape then there is an option to cap the ends. The caps are drawn by creating triangles from the Barycenter of the shape profile to the profile vertices, so that there are profile shapes that cause caps to not correctly fit the profile shape. In this case you can used CreatePolygon for the caps, however you do need to position and rotate these caps in addition to creating them.

When you need sharp mitred corners there is a utility function available Extruded Shape with Mitred Corners

MeshBuilder

Usage :

const options = {
shape: myPoints, //vec3 array with z = 0,
path: myPath, //vec3 array
updatable: true
}
let extruded = BABYLON.MeshBuilder.ExtrudeShape("ext", options, scene); //scene is optional and defaults to the current scene
// Update
options.shape = newShape;
options.path = newPath;
options.instance = extruded;
extruded = BABYLON.MeshBuilder.ExtrudeShape("ext", options); //No scene parameter when using instance
optionvaluedefault value
option
shape
value
(Vector3[]) array of Vector3, the shape you want to extrude REQUIRED
default value
 
option
path
value
(Vector3[]) array of Vector3, the extrusion axis REQUIRED
default value
 
option
scale
value
(number) the value to scale the shape
default value
1
option
rotation
value
(number) the value to rotate the shape each step along the path
default value
0
option
cap
value
(number) extrusion cap : NO_CAP, CAP_START, CAP_END, CAP_ALL
default value
NO_CAP
option
updatable
value
(boolean) true if the mesh is updatable
default value
false
option
sideOrientation
value
(number) side orientation
default value
DEFAULTSIDE
option
frontUVs
value
(Vector4) ONLY WHEN sideOrientation:BABYLON.Mesh.DOUBLESIDE is an option
default value
Vector4(0,0, 1,1)
option
backUVs
value
(Vector4) ONLY WHEN sideOrientation:BABYLON.Mesh.DOUBLESIDE is an option
default value
Vector4(0,0, 1,1)
option
instance
value
(LineMesh) an instance of an extruded shape to be updated
default value
null
option
invertUV
value
(boolean) to swap the U and V coordinates at geometry construction time (texture rotation of 90°)
default value
false

Examples

non updatable extrusion: Non Updatable Extrusion update of extrusion including, shape, path, scale and rotation: Updatable Extrusion extrusion with open shape: Extrusion With Open Shape

spiral extrusion with straight path and rotation set: Spiral Extrusion

capped extrusion: Capped Extrusion profile that does not cap correctly: Incorrectly Capped Extrusion

Mesh

Usage:

let extrusion = BABYLON.Mesh.ExtrudeShape(name, shape, path, scale, rotation, cap, scene);
let extrusion = BABYLON.Mesh.ExtrudeShape(name, shape, path, scale, rotation, cap, scene, updatable, sideOrientation, instance); //optional parameters after scene