BabylonJS - 圓盤



在本節中,我們將學習如何建立一個圓盤。

語法

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

引數

  • 名稱 − 這是圓盤的名稱。

  • 半徑 − 這是圓盤的半徑。

  • 鑲嵌 − 這是指使用一個或多個幾何形狀來平鋪平面。

  • 使用鑲嵌值,你可以得到一個正多邊形 −

    • 3 得到一個三角形
    • 4 得到一個正方形
    • 5 得到一個五邊形
    • 6 得到一個六邊形
    • 7 得到一個七邊形
    • 8 得到一個八邊形,依此類推
  • 場景 − 這是要附加網格的場景。

  • 布林值 − 這是可更新的;預設為 false。

  • 預設邊 − 這是可選的邊定向。

最後 2 個引數可以省略。

演示 - 圓盤

<!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>

輸出

Basic Elements Disc
babylonjs_basic_elements.htm
廣告