BabylonJS - Disc



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

Syntax

var disc = BABYLON.Mesh.CreateDisc("disc", 5, 30, scene, false, BABYLON.Mesh.DEFAULTSIDE);

Parameters

  • Name − This is the name of the disc.

  • Radius − This is the radius of the disc.

  • Tessellation − This refers to the tiling of a plane using one or more geometric shapes.

  • With the tessellation value, you can get a regular polygon −

    • 3 gives a triangle
    • 4 gives a square
    • 5 gives a pentagon
    • 6 gives a hexagon
    • 7 gives a heptagon
    • 8 gives an octagon, and so on
  • Scene − This is the scene to attach the mesh.

  • Boolean − This is updatable; by default, it is false.

  • Defaultside − This is the optional side orientation.

The last 2 parameters can be omitted.

Demo - Disc

<!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);
            
            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 disc = BABYLON.Mesh.CreateDisc("disc",2,8, scene);
            disc.position = new BABYLON.Vector3(0, 0, 0);

            var disc1 = BABYLON.Mesh.CreateDisc("triangle",2,3, scene);
            disc1.position = new BABYLON.Vector3(-10, 0, 0);

            var disc2 = BABYLON.Mesh.CreateDisc("pentagon",2, 5, scene);
            disc2.position = new BABYLON.Vector3(0,0, 5);

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

Output

Basic Elements Disc
babylonjs_basic_elements.htm
Advertisements