-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
112 lines (97 loc) · 4.39 KB
/
index.html
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<!Doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>BabyJS Demo</title>
<style>
html, body {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
overflow: hidden;
}
#canvas {
width:100%;
height:100%;
touch-action: none;
-ms-touch-action: none;
}
</style>
<script src="https://cdn.babylonjs.com/babylon.js"></script>
<script src="https://lo-th.github.io/Oimo.js/build/oimo.min.js"></script>
</head>
<body>
<canvas id="canvas"></canvas>
<script>
document.addEventListener('DOMContentLoaded', startGame, false);
function startGame() {
if (BABYLON.Engine.isSupported()) {
canvas = document.getElementById("canvas");
engine = new BABYLON.Engine(canvas, true);
BABYLON.SceneLoader.Load("Espilit/", "home.babylon", engine, function (loadedScene) {
scene = loadedScene;
// create collistion detection
scene.collisionsEnabled = true;
scene.activeCamera.checkCollisions = true;
// create extra light
/*var light0 = new BABYLON.DirectionalLight("Dir0", new BABYLON.Vector3(1, -1, 0), scene);
light0.diffuse = new BABYLON.Color3(1, 0, 0);
light0.specular = new BABYLON.Color3(1, 1, 1);*/
// set up ambient light
var light0 = new BABYLON.HemisphericLight("Hemi0", new BABYLON.Vector3(0, 1, 0), scene);
light0.diffuse = new BABYLON.Color3(0.117647, 0.564706, 1);
light0.specular = new BABYLON.Color3(1, 1, 1);
light0.groundColor = new BABYLON.Color3(0, 0, 0);
// create gravity
scene.enablePhysics(new BABYLON.Vector3(0, -10, 0), new BABYLON.OimoJSPlugin());
// create shadow effect
//var cube = scene.getMeshByID("Cube");
var ground = scene.getMeshByID("Plane");
var wall = scene.getMeshByID("Cube");
var monkey = scene.getMeshByID("Suzanne");
wall.checkCollisions = true;
monkey.checkCollisions = true;
ground.checkCollisions = true;
//monkey.position.y = 20;
var light = scene.getLightByID("Lamp");
//light.diffuse = new BABYLON.Color3( 0.117647, 0.564706, 1);
var shadowGenerator = new BABYLON.ShadowGenerator(1024, light);
shadowGenerator.getShadowMap().renderList.push(monkey);
shadowGenerator.getShadowMap().renderList.push(wall);
ground.receiveShadows = true;
wall.rotation.z += 0.3;
//for (var i = 1; i < scene.meshes.length; i++) {
/*if (scene.meshes[i].checkCollisions && scene.meshes[i].isVisible === false) {
scene.meshes[i].setPhysicsState(BABYLON.PhysicsEngine.BoxImpostor, { mass: 0,
friction: 0.5, restitution: 0.7 });
if(i % 5 == 0)*/
//scene.meshes[i].checkCollisions = true;
//meshesColliderList.push(scene.meshes[i]);
// }
//}
// var meshObj = scene.getMeshByID("c94429ce-24d6-44a6-be62-c1df57b3f98e");
//meshObj.checkCollisions = false;
// meshObj.position.x -= 0;
// Wait for textures and shaders to be ready
scene.executeWhenReady(function () {
// Attach camera to canvas inputs
scene.activeCamera.attachControl(canvas);
// Once the scene is loaded, just register a render loop to render it
engine.runRenderLoop(function () {
monkey.rotation.y += 0.01;
//wall.rotation.z += 0.01;
wall.scaling.y = 0.1;
//wall.rotation.x += 0.01;
//cube.rotation.y += 0.01;
scene.render();
});
});
}, function (progress) {
// To do: give progress feedback to user
});
}
}
</script>
</body>
</html>