For details on what it is and how it is constructed you might want to read the Ribbon Tutorial
var ribbon = BABYLON.Mesh.CreateRibbon("ribbon", [path1, path2, ..., pathn], false, false, 0, scene, false, BABYLON.Mesh.DEFAULTSIDE);
Parameters are: name, pathArray, closeArray, closePath, offset, scene, updatable? (if the mesh must be modified later) and the optional side orientation (see below).
The last two parameters can be omitted if you just need the default behavior :
var ribbon = BABYLON.Mesh.CreateRibbon("ribbon", [path1, path2, ..., pathn], false, false, 0, scene);
var tube = BABYLON.Mesh.CreateTube("tube", [V1, V2, ..., Vn], radius, tesselation, radiusFunction, cap, scene, false, BABYLON.Mesh.DEFAULTSIDE);
Parameters are : name, path, radius, tesselation, optional radiusFunction, cap, scene, updatable, sideOrientation.
The last two parameters can be omitted if you just need the default behavior :
var tube = BABYLON.Mesh.CreateTube("tube", [V1, V2, ..., Vn], radius, tesselation, radiusFunction, cap, scene);
While a tube can just be a cyclinder it can be far more than that
Your function must just return a radius value.
Example :
var myFunction = function(i, distance) {
var radius = 3 * Math.cos(distance / 5);
return radius;
};
var tube = BABYLON.Mesh.CreateTube("lumps", path, null, 20, myFunction, scene);
Here is an example with both an _i_ sinusoidal radius function and _x_ sinusoidal incrementing path : https://www.babylonjs-playground.com/#LG3GS#9 -
Please note that CreatePolygon uses Earcut, so, in non playground projects, you will have to add a reference to their cdn or download their npm package
var polygon = BABYLON.Mesh.CreatePolygon("polygon", [V1, V2, ..., Vn], scene, [[V1, V2, ..., Vn], [V1, V2, ..., Vn], ....[V1, V2, ..., Vn]], false, BABYLON.Mesh.DEFAULTSIDE);
Parameters are: name, polygon shape as an array of comma-separated vectors, scene, optional holes as an array of an array of comma-separated vectors, optional updatable and the optional side orientation. The last three parameters can be omitted if you just need the default behavior :
NOTE all vectors are Vector3 and should be in the XoZ plane, ie of the form BABYLON.Vector3(x, 0, z);
var polygon = BABYLON.Mesh.CreatePolygon("cylinder", [V1, V2, ..., Vn], scene);
Uses PolygonMeshBuilder
Please note that ExtrudePolygon uses Earcut, so, in non playground projects, you will have to add a reference to their cdn or download their npm package
var polygon = BABYLON.Mesh.ExtrudePolygon("polygon", [V1, V2, ..., Vn], 2, scene, [[V1, V2, ..., Vn], [V1, V2, ..., Vn], ....[V1, V2, ..., Vn]], false, BABYLON.Mesh.DEFAULTSIDE);
Parameters are: name, polygon shape as an array of comma-separated vectors, depth, scene, optional holes as an array of an array of comma-separated vectors, optional updatable and the optional side orientation. The last three parameters can be omitted if you just need the default behavior :
NOTE all vectors are Vector3 and should be in the XoZ plane, ie of the form BABYLON.Vector3(x, 0, z) and in counter clockwise order;
var polygon = BABYLON.Mesh.CreatePolygon("polygon", [V1, V2, ..., Vn], 2, scene);
Uses PolygonMeshBuilder
var lines = BABYLON.Mesh.CreateLines("lines", [
new BABYLON.Vector3(-10, 0, 0),
new BABYLON.Vector3(10, 0, 0),
new BABYLON.Vector3(0, 0, -10),
new BABYLON.Vector3(0, 0, 10)
], scene);
Parameters are: name, [array of comma-separated vectors], scene.
I could explain how the Lines Mesh constructor works, but I think you can see how it works just by looking at the demo code above. Notice the [ and ]. Those are the enclosing tokens for an array, yet another kind of Javascript value. The first vector3 of the array is the starting location for drawing lines. After that, a comma, and then the next vector3 location... indicating where the line is drawing-to next. Then, another comma, and another vector3 to a new location. You can add as many vectors as you wish, but notice that the LAST vector3 does not have a comma following it. Please make your array of vectors be formatted similarly.
var dashedlines = BABYLON.Mesh.CreateDashedLines("dashedLines", [v1, v2, ... vn], dashSize, gapSize, dashNb, scene);
Parameters are : name, [array of Vectors3], dashSize, gapSize, dashNumber, scene.
As for Lines, a line along the vectors3 will be displayed in space. It will try to set dashNumber strokes on this line depending on the length of each segment between two successive vectors3.
dashSize and gapSize are relative to each other dash and gap sizes within these strokes.
What is extrusion ?
Extrusion is the way to transform a 2D shape into a volumic shape.
Let's imagine that you define a star shape by filling an array with successive Vector3. In order to have a 2D shape, you only set these points in the xOy plane, so every z coordinate is zero.
ex : https://www.babylonjs-playground.com/#RF9W9 -
Let's now imagine you can extrude your star along a 3D path in space, a sinus curve for example, and not only along the z-axis.
https://www.babylonjs-playground.com/#RF9W9#31 -
Extrusion can be accomplished with two different methods. A basic one and an advanced or custom one.
BASIC METHOD
BABYLON.Mesh.ExtrudeShape(name, shape, path, scale, rotation, cap, scene, updatable?, sideOrientation)
If we change the scale value from 1 to 3 for example (line 84), the initial star is scaled to 3 along the curve : https://www.babylonjs-playground.com/#RF9W9#526 -
If we now change the rotation step value from 0 to PI / 24 for example, the curve is twisted this angle at each curve point : https://www.babylonjs-playground.com/#RF9W9#218 -Of course, even if you define your 2D shape in the xOy plane as described, the extrusion still works along any path direction : https://www.babylonjs-playground.com/#RF9W9#32 -
Moreover, the shape doesn't need to be closed. You can have a simple (or complex) open shape : https://www.babylonjs-playground.com/#RF9W9#7 -
Remember that your shape doesn't need to be centered on the coordinate system either. Here is an offset simple shape : https://www.babylonjs-playground.com/#RF9W9#10 -
ADVANCED METHOD
BABYLON.Mesh.ExtrudeShapeCustom(name, shape, path, scaleFunction, rotateFunction, ribbonCloseArray, ribbonClosePath, cap, scene)
In this advanced method, the scale and rotation parameters are replaced by custom functions.
scaleFunction
This javascript function will be called on each path point iteration when extruding. It will be passed two parameters : _i_ and distance.
This custom function must return a scale numeric value which will be applied to the shape on the i-th point.
Example :
var myScale = function(i, distance) {
var scale = 2 * Math.sin(i / 5);
return scale;
};
Here is an example with an unclosed un-centered simple shape whose scale evolves linearly along the path : https://www.babylonjs-playground.com/#RF9W9#38 -
rotateFunction
This javascript function will be called on each path point iteration when extruding. It will be passed two parameters : _i_ and distance.
This custom function must return a rotation numeric value which will be applied to the shape on the i-th point.
Example :
var myRotation = function(i, distance) {
var rotation = distance / 20;
return rotation;
};
Here is an example of constant scale and rotation evolving with the distance : https://www.babylonjs-playground.com/#RF9W9#41 -
Fixed values
This advanced method needs two custom functions. But you may want to use a custom scale function with a fixed (or no) rotation function, for example. In this case, just pass a custom rotation function returning a fixed value :
Example :
var noRotation = function(i, distance) {
return 0;
};
If you carefully read the code of this previous example, you can see in line 41 that the scaleFunction returns the constant 1 value : https://www.babylonjs-playground.com/#RF9W9#41 -
ribbonCloseXXX parameters
The extruded mesh is based on an underlying ribbon. When you extrude a shape, you actually make a particular ribbon.
This means you can also set this ribbon closeArray and closePath parameter if you need to automatically close the extruded shape.
NOTE : the closeXXX names are the ribbon ones. Not the extruded shape ones.
So it may be confusing because :
Let's now do this unclosed, un-centered extruded shape : https://www.babylonjs-playground.com/#RF9W9#20 -
Summary
At last, the extrude custom function call would be, for example:
BABYLON.Mesh.ExtrudeShapeCustom("extruded", shape, path, myScale, myRotation, false, true, scene)
A shape is an array of successive Vector3. This means 2D or 3D shapes can be extruded as well.
The shape is to be designed in the local coordinate system knowing that the z-axis will be the extrusion path axis.
Finally, shapes don't have to be centered in the local coordinate system.
A centered shape will be extruded symmetrically centered along the path axis. An un-centered shape will be extruded offset from the path axis.
Easy way to generate strange shapes : https://www.babylonjs-playground.com/#RF9W9#47 -
Mesh Overview
Set Shapes 101
Parametric Shapes 101
Set Shapes
Parametric Shapes
Polyhedra Shapes
Tiled Planes and Boxes