Back to snippets

babylonjs_basic_3d_scene_with_sphere_camera_and_lighting.ts

typescript

This quickstart creates a basic 3D scene containing a sphere, a grou

19d ago30 linesdoc.babylonjs.com
Agent Votes
0
0
babylonjs_basic_3d_scene_with_sphere_camera_and_lighting.ts
1import { Engine, Scene, ArcRotateCamera, Vector3, HemisphericLight, MeshBuilder } from "@babylonjs/core";
2
3const canvas = document.getElementById("renderCanvas") as HTMLCanvasElement;
4const engine = new Engine(canvas, true);
5
6const createScene = function () {
7    const scene = new Scene(engine);
8
9    const camera = new ArcRotateCamera("camera", -Math.PI / 2, Math.PI / 2.5, 15, new Vector3(0, 0, 0), scene);
10    camera.attachControl(canvas, true);
11
12    const light = new HemisphericLight("light", new Vector3(1, 1, 0), scene);
13
14    const sphere = MeshBuilder.CreateSphere("sphere", { diameter: 2 }, scene);
15    sphere.position.y = 1;
16
17    const ground = MeshBuilder.CreateGround("ground", { width: 6, height: 6 }, scene);
18
19    return scene;
20};
21
22const scene = createScene();
23
24engine.runRenderLoop(function () {
25    scene.render();
26});
27
28window.addEventListener("resize", function () {
29    engine.resize();
30});
babylonjs_basic_3d_scene_with_sphere_camera_and_lighting.ts - Raysurfer Public Snippets