minGridMaterial.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { Engine } from "@babylonjs/core/Engines/engine";
  2. import { Scene } from "@babylonjs/core/scene";
  3. import { Vector3 } from "@babylonjs/core/Maths/math.vector";
  4. import { FreeCamera } from "@babylonjs/core/Cameras/freeCamera";
  5. import { HemisphericLight } from "@babylonjs/core/Lights/hemisphericLight";
  6. import { Mesh } from "@babylonjs/core/Meshes/mesh";
  7. import { GridMaterial } from "@babylonjs/materials/grid/gridMaterial";
  8. import "@babylonjs/core/Meshes/Builders/boxBuilder";
  9. import "@babylonjs/core/Meshes/Builders/sphereBuilder";
  10. const canvas = document.getElementById("renderCanvas") as HTMLCanvasElement;
  11. const engine = new Engine(canvas);
  12. var scene = new Scene(engine);
  13. // This creates and positions a free camera (non-mesh)
  14. var camera = new FreeCamera("camera1", new Vector3(0, 5, -10), scene);
  15. // This targets the camera to scene origin
  16. camera.setTarget(Vector3.Zero());
  17. // This attaches the camera to the canvas
  18. camera.attachControl(canvas, true);
  19. // This creates a light, aiming 0,1,0 - to the sky (non-mesh)
  20. var light = new HemisphericLight("light1", new Vector3(0, 1, 0), scene);
  21. // Default intensity is 1. Let's dim the light a small amount
  22. light.intensity = 0.7;
  23. // Our built-in 'sphere' shape. Params: name, subdivs, size, scene
  24. var sphere = Mesh.CreateSphere("sphere1", 16, 2, scene);
  25. // Move the sphere upward 1/2 its height
  26. sphere.position.y = 2;
  27. // Our built-in 'ground' shape. Params: name, width, depth, subdivs, scene
  28. var ground = Mesh.CreateGround("ground1", 6, 6, 2, scene);
  29. ground.material = new GridMaterial("", scene);
  30. sphere.material = new GridMaterial("", scene);
  31. engine.runRenderLoop(() => {
  32. scene.render();
  33. });