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