BabylonJS - Knot



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

Syntax

Following is the syntax to create a knot.

var knot = BABYLON.Mesh.CreateTorusKnot("knot", 2, 0.5, 128, 64, 2, 3, scene, false, BABYLON.Mesh.DEFAULTSIDE);

Parameters

Consider the following parameters to create a Knot −

  • Name − This is the name of the knot.

  • Radius − The radius of the knot.

  • Tube − The thickness of its tube.

  • Radial segments − The number of radial segments.

  • Tubular segments − The number of tubular segments.

  • P − The number of windings.

  • Q − The number of windings.

  • Scene − The scene to which the knot is attached.

  • Boolean − Incase the shape of the knot needs tobe changed, you can set this to true. This is mainly used while morphing.

  • SideOrientation − side orientation.Defaultside - it the default option.

Demo - Knot

<!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 knot = BABYLON.Mesh.CreateTorusKnot("knot", 2, 0.5, 128, 64, 2, 3, scene);

            scene.activeCamera.attachControl(canvas);
            return scene;
         };
         var scene = createScene();
         engine.runRenderLoop(function() {
            scene.render();
         });
      </script>
   </body>
</html>

Output

Basic Eements Knot
babylonjs_basic_elements.htm
Advertisements