Creating Ribbons
Ribbon
The ribbon is a very versatile shape. Picture a ribbon in the real world with parallel wires running down its length. You can turn such a ribbon into a wide variety of shapes. By joining one long edge to its opposite, you could form a tube and bend it into different shapes. This and more is possible with a Babylon.js ribbon. Instead of parallel wires, a Babylon.js ribbon is formed from paths defined by an array of vector3s, and how you define the paths determines the final shape.
On creation, the local origin of a ribbon 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.
MeshBuilder
Usage :
import { MeshBuilder } from "@babylonjs/core/Meshes/meshBuilder";const options = { pathArray: myPaths, //[vector3 array, vector3 array, vector3 array......] updatable: true}
let ribbon = MeshBuilder.CreateRibbon("ribbon", options, scene); //scene is optional and defaults to the current scene
options.pathArray: myNewPaths; //The length must equal the length of myPaths and myNewPaths[i].length === myPaths[i] for all ioptions.instance = true;
// updates the existing instance of ribbon : no need for the parameter sceneribbon = MeshBuilder.CreateRibbon("ribbon", {pathArray: myNewPath, instance: ribbon});| option | value | default value |
|---|---|---|
| pathArray | (Vector3[][]) array of array of Vector3, the array of paths REQUIRED | |
| closeArray | (boolean) to force the ribbon to join its last and first paths | false |
| closePath | (boolean) to force each ribbon path to join its last and first points | false |
| offset | (number) used if the pathArray has one path only | half the path length |
| updatable | (boolean) true if the mesh is updatable | false |
| sideOrientation | (number) side orientation | DEFAULTSIDE |
| frontUVs | (Vector4) ONLY WHEN sideOrientation:BABYLON.Mesh.DOUBLESIDE is an option | Vector4(0,0, 1,1) |
| backUVs | (Vector4) ONLY WHEN sideOrientation:BABYLON.Mesh.DOUBLESIDE is an option | Vector4(0,0, 1,1) |
| instance | (LineMesh) an instance of a ribbon to be updated | null |
| invertUV | (boolean) to swap the U and V coordinates at geometry construction time (texture rotation of 90°) | false |
Examples
Update of a ribbon: Updating a Ribbon
double sided ribbon not updatable: Create a Non Updatable Double Sided Ribbon
double sided ribbon not updatable path lines in red: Create a Non Updatable Double Sided Ribbon With Red Path Lines
open ribbon: Create An Open Ribbon
with closePath true: Create a Ribbon with closePath = True
with closeArray true: Create a Ribbon with closeArray = True
Mesh
Usage:
import { Mesh } from "@babylonjs/core/Meshes/mesh";const ribbon = Mesh.CreateRibbon("ribbon", pathArray, closeArray, closePath, offset, scene);const ribbon = Mesh.CreateRibbon("ribbon", pathArray, closeArray, closePath, offset, scene, updatable, sideOrientation, instance); //optional parameters after sceneMore about ribbons on the next page.