-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
50 lines (40 loc) · 1.1 KB
/
app.js
File metadata and controls
50 lines (40 loc) · 1.1 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
// Get the canvas element
const canvas = document.getElementById("renderCanvas");
// Create the Babylon.js engine
const engine = new BABYLON.Engine(canvas, true);
// Create the scene
const createScene = function() {
// Create a basic scene
const scene = new BABYLON.Scene(engine);
// Create a camera
const camera = new BABYLON.ArcRotateCamera("camera",
-Math.PI / 2,
Math.PI / 2.5,
10,
BABYLON.Vector3.Zero(),
scene
);
camera.attachControl(canvas, true);
// Create a light
const light = new BABYLON.HemisphericLight("light",
new BABYLON.Vector3(0, 1, 0),
scene
);
// Create a box
const box = BABYLON.MeshBuilder.CreateBox("box", {}, scene);
// Add some animation
scene.registerBeforeRender(function() {
box.rotation.y += 0.01;
});
return scene;
};
// Create the scene
const scene = createScene();
// Run the render loop
engine.runRenderLoop(function() {
scene.render();
});
// Handle browser/canvas resize events
window.addEventListener("resize", function() {
engine.resize();
});