BabylonJS - Ground
在本节中,我们将学习如何创建 Ground。
语法
以下是创建 Ground 的语法 −
var ground = BABYLON.Mesh.CreateGround("ground", 6, 6, 2, scene);
参数
请考虑以下参数来创建 Ground −
Name − 地面的名称。
Width − 地面的宽度。
Height −地面的高度。
Subdivisions − 正方形细分的数量。
Scene − 要附加地面的场景。
演示 - 地面
<!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 ground = BABYLON.Mesh.CreateGround("ground1", 6, 6, 2, scene); scene.activeCamera.attachControl(canvas); return scene; }; var scene = createScene(); engine.runRenderLoop(function() { scene.render(); }); </script> </body> </html>
输出
上面这行代码将生成以下输出: