BabylonJS - Ribbon



In this section, we will learn how to create a Ribbon.

Syntax

Following is the syntax to create a Ribbon.

var ribbon = BABYLON.Mesh.CreateRibbon("ribbon", [path1, path2, ..., pathn], false, false, 0, scene, false, BABYLON.Mesh.DEFAULTSIDE);

Parameters

Consider the following parameters to create a ribbon −

  • Name − The name given to the ribbon.

  • Path − The array of array of Vector3, the array of paths REQUIRED.

  • CloseArray − This helps force the ribbon to join its last and first paths.

  • ClosePath − This helps force each ribbon path to join its last and first points.

  • Offset − This is used if the pathArray has one path only.

  • Scene − The scene to which the ribbon will be attached.

  • Boolean − By default, it is false.In case the ribbon mesh needs to be updated for morhphing, it is set to true.

  • Mesh.DEFAULTSIDE − This is the side orientation.

Demo - Ribbon

<!doctype html>
<html>
   <head>
      <meta charset = "utf-8">
      <title>MDN Games: Babylon.js demo - shapes</title>
      <script src = "babylon.js"></script>
      <style>
         html,body,canvas { margin: 0; padding: 0; width: 100%; height: 100%; font-size: 0; }
      </style>
   </head>
   
   <body>
      <canvas id = "renderCanvas"></canvas>
      <script type = "text/javascript">
         var canvas = document.getElementById("renderCanvas");
         var engine = new BABYLON.Engine(canvas, true);
         var createScene  = function() {
            var scene = new BABYLON.Scene(engine);
            scene.clearColor = new BABYLON.Color3(0, 1, 0);
            var camera = new BABYLON.ArcRotateCamera("Camera", 1, 0.8, 10, new BABYLON.Vector3(0, 0, 0), scene);
            var light = new BABYLON.HemisphericLight("hemi", new BABYLON.Vector3(0, 1, 0), scene);

            var exponentialPath = function (p) {
               var path = [];
               for (var i = -5; i < 5; i++) {
                  path.push(new BABYLON.Vector3(p, i, Math.sin(p / 3) * 5 * Math.exp(-(i - p) * (i - p) / 90) + i / 3));
               }
               return path;
            };

            var arrayOfPaths = [];
            for (var p = 0; p < 30; p++) {
               arrayOfPaths[p] = exponentialPath(p);
            }
         
            var ribbon = BABYLON.Mesh.CreateRibbon("ribbon", arrayOfPaths, false, false, 0, scene);
            scene.activeCamera.attachControl(canvas);
            return scene;
         };
         var scene = createScene();
         engine.runRenderLoop(function() {
            scene.render();
         });
      </script>
   </body>
</html>

Output

Basic Elements Ribbon
babylonjs_basic_elements.htm
Advertisements