-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbabylon.ts
More file actions
61 lines (49 loc) · 1.4 KB
/
babylon.ts
File metadata and controls
61 lines (49 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { init, World } from "../ext/babylon.ts";
class Game extends World {
constructor() {
super({
title: "Babylon.js",
width: 800,
height: 600,
}, {
preserveDrawingBuffer: true,
stencil: true,
// deno-lint-ignore no-explicit-any
} as any, true);
}
createScene() {
const scene = new BABYLON.Scene(this.engine);
// This creates and positions a free camera (non-mesh)
const camera = new BABYLON.FreeCamera(
"camera1",
new BABYLON.Vector3(0, 5, -10),
scene,
);
// This targets the camera to scene origin
camera.setTarget(BABYLON.Vector3.Zero());
// This attaches the camera to the canvas
camera.attachControl(globalThis, true);
// This creates a light, aiming 0,1,0 - to the sky (non-mesh)
const light = new BABYLON.HemisphericLight(
"light",
new BABYLON.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.
const sphere = BABYLON.MeshBuilder.CreateSphere("sphere", {
diameter: 2,
segments: 32,
}, scene);
// Move the sphere upward 1/2 its height
sphere.position.y = 1;
// Our built-in 'ground' shape.
const _ground = BABYLON.MeshBuilder.CreateGround("ground", {
width: 6,
height: 6,
}, scene);
return scene;
}
}
init(new Game());