-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
315 lines (252 loc) · 12.6 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
<!DOCTYPE html>
<html>
<head>
<title>Georgs Christmas Greetings</title>
<meta charset="UTF-8" />
<!-- this link to the preview online version of BJS -->
<script src="https://preview.babylonjs.com/babylon.js"></script>
<!-- this is needed for BJS to load scene files -->
<script src="https://preview.babylonjs.com/loaders/babylonjs.loaders.js"></script>
<script src="https://code.jquery.com/pep/0.4.3/pep.js"></script>
<style>
html,
body {
overflow: hidden;
width: 100%;
height: 100%;
margin: 0;
padding: 0;
color: white;
}
#canvas {
width: 100%;
height: 100%;
touch-action: none;
}
</style>
</head>
<body>
<canvas id="canvas"></canvas>
<script type="text/javascript">
var canvas = document.getElementById("canvas");
var engine = new BABYLON.Engine(canvas, true);
// here the doc for Load function: //doc.babylonjs.com/typedoc/classes/babylon.sceneloader#load
BABYLON.SceneLoader.Load("", "../Lake.babylon", engine, function(scene) {
//LICENSE: Any code herein including the comments is in the public domain
// The linked to libraries are governed by their own respective licenses
// All linked to images and sounds are in the public domain as well
scene.clearColor = new BABYLON.Color3(1, 1, 1);
scene.ambientColor = new BABYLON.Color3.White();
// implement the sounds
// this one is the background music, therefore autoplay and loop are true
const sound = new BABYLON.Sound("Background music", "Track1.mp3", scene, null, {
loop: true,
autoplay: true
});
// the other sounds should only be played once triggered, therefore autoplay is false
// they are not supposed to loop, therefore loop is false
const sound1 = new BABYLON.Sound("1", "Track2.mp3", scene, null, {
loop: false,
autoplay: false
});
const sound4 = new BABYLON.Sound("4", "Track5.mp3", scene, null, {
loop: false,
autoplay: false
});
const sound2 = new BABYLON.Sound("2", "Track3.mp3", scene, null, {
loop: false,
autoplay: false
});
const sound3 = new BABYLON.Sound("3", "Track4.mp3", scene, null, {
loop: false,
autoplay: false
});
// The universal camera - Parameters : name, position, scene
var camera = new BABYLON.UniversalCamera("UniversalCamera", new BABYLON.Vector3(9, -20, -21), scene);
// Targets the camera to a particular target position, in this case the first house
camera.setTarget(new BABYLON.Vector3(10, -20, -18.1));
// Attach the camera to the canvas
camera.attachControl(canvas, true);
// set the camera to be active in the scene
scene.activeCamera = camera
// these calculations are for movement speed and gravity
const assumedFramesPerSecond = 60;
const earthGravity = -9.81;
scene.gravity = new BABYLON.Vector3(0, earthGravity / assumedFramesPerSecond, 0);
camera.applyGravity = true;
camera.speed = 0.75;
camera.inertia = 0.75;
// the shape of the ellipsoid around the camera used for collision with other objects
camera.ellipsoid = new BABYLON.Vector3(1.5, 1.6, 1.5);
// Enable Collisions
scene.collisionsEnabled = true;
camera.checkCollisions = true;
scene.getNodeByName("Ground").checkCollisions = true;
// set collision for all houses, trees and christmas objects
for (let i = 0; i < scene.meshes.length; i++) {
let mesh = scene.meshes[i];
if (mesh.name.indexOf("House") > -1) {
mesh.checkCollisions = true;
}
if (mesh.name.indexOf("Tree") > -1) {
mesh.checkCollisions = true;
}
if (mesh.name.indexOf("Christmas") > -1) {
mesh.checkCollisions = true;
}
}
// set the collision for the movement bounds mesh
// and set its visibility to zero
// and set pickable to false, so that actionable objects inside the bounds
// can be activated by clicking (if true [default], the clicks would be consumed
// by the bounds and not be delivered to clickable objects like houses inside the bounds)
scene.getNodeByName("Bounds").visibility = 0.0;
scene.getNodeByName("Bounds").checkCollisions = true;
scene.getNodeByName("Bounds").isPickable = false;
//Hemilight to illuminate the snowy day
var light = new BABYLON.HemisphericLight("hemiLight", new BABYLON.Vector3(0, 1, 0), scene);
light.diffuse = new BABYLON.Color3(0.4, 0.76, 0.97);
light.groundColor = new BABYLON.Color3(.5, .5, .5);
// Particle system for snow
var myParticleSystem;
// try to start a GPU particle system, alternatively use the CPU
if (BABYLON.GPUParticleSystem.IsSupported) {
myParticleSystem = new BABYLON.GPUParticleSystem("particles", {
capacity: 1000000
}, scene);
myParticleSystem.activeParticleCount = 200000;
myParticleSystem.emitRate = 10000;
console.log("Using GPU particles")
} else {
myParticleSystem = new BABYLON.ParticleSystem("particles", 50000, scene);
console.log("Using CPU particles")
myParticleSystem.emitRate = 4000;
}
myParticleSystem.particleTexture = new BABYLON.Texture("snowflake.png");
// set the emitter box
myParticleSystem.emitter = new BABYLON.Vector3(0, 26, 0);
myParticleSystem.minEmitBox = new BABYLON.Vector3(-75, 0, -75); // minimum box dimensions
myParticleSystem.maxEmitBox = new BABYLON.Vector3(75, 0, 75); // maximum box dimensions
myParticleSystem.minSize = .2;
myParticleSystem.maxSize = .25;
myParticleSystem.minLifeTime = 20;
myParticleSystem.maxLifeTime = 20;
myParticleSystem.minEmitPower = -2;
myParticleSystem.maxEmitPower = -3;
myParticleSystem.applyGravity = true;
// add movement noise to the snow particles
var noiseTexture = new BABYLON.NoiseProceduralTexture("perlin", 256, scene);
noiseTexture.animationSpeedFactor = 5;
noiseTexture.persistence = 2;
noiseTexture.brightness = 0.5;
noiseTexture.octaves = 5;
myParticleSystem.noiseTexture = noiseTexture;
myParticleSystem.noiseStrength = new BABYLON.Vector3(1, 0.03, 1);
// Add actions to all houses and the sledge
// lower the visibility of the christmas objects until the house was clicked
var meshChristmasTree = scene.getMeshByName("Christmas Tree");
meshChristmasTree.visibility = 0.1;
scene.getMeshByName("House 1").actionManager = new BABYLON.ActionManager(scene);
// The executeCodeAction allows to execute multiple functions easily upon OnPickTrigger
scene.getMeshByName("House 1").actionManager.registerAction(
new BABYLON.ExecuteCodeAction({
trigger: BABYLON.ActionManager.OnPickTrigger,
parameter: scene.getMeshByName("House 1")
},
function() {
sound1.play();
meshChristmasTree.visibility = 1;
}
)
);
var meshChristmasLamps = scene.getMeshByName("Christmas Lamps");
meshChristmasLamps.visibility = 0.0;
scene.getMeshByName("House 2").actionManager = new BABYLON.ActionManager(scene);
scene.getMeshByName("House 2").actionManager.registerAction(
new BABYLON.ExecuteCodeAction({
trigger: BABYLON.ActionManager.OnPickTrigger,
parameter: scene.getMeshByName("House 2")
},
function() {
sound2.play();
meshChristmasLamps.visibility = 1.0;
}
)
);
var meshChristmasWreath = scene.getMeshByName("Christmas Wreath");
meshChristmasWreath.visibility = 0.0;
scene.getMeshByName("House 1.1").actionManager = new BABYLON.ActionManager(scene);
scene.getMeshByName("House 1.1").actionManager.registerAction(
new BABYLON.ExecuteCodeAction({
trigger: BABYLON.ActionManager.OnPickTrigger,
parameter: scene.getMeshByName("House 1.1")
},
function() {
sound3.play();
meshChristmasWreath.visibility = 1.0;
}
)
);
var meshChristmasStar = scene.getMeshByName("Christmas Star");
var meshChristmasStar1 = scene.getMeshByName("Christmas Star 1");
var meshChristmasStar2 = scene.getMeshByName("Christmas Star 2");
meshChristmasStar.visibility = 0.0;
meshChristmasStar1.visibility = 0.0;
meshChristmasStar2.visibility = 0.0;
scene.getMeshByName("House 1.2").actionManager = new BABYLON.ActionManager(scene);
scene.getMeshByName("House 1.2").actionManager.registerAction(
new BABYLON.ExecuteCodeAction({
trigger: BABYLON.ActionManager.OnPickTrigger,
parameter: scene.getMeshByName("House 1.2")
},
function() {
sound4.play();
meshChristmasStar.visibility = 1.0;
meshChristmasStar1.visibility = 1.0;
meshChristmasStar2.visibility = 1.0;
scene.beginAnimation(scene.getMeshByName("Train"), 0, 2400, true);
}
)
);
var meshChristmasSledgeText = scene.getMeshByName("Text Sledge");
meshChristmasSledgeText.visibility = 0.0
scene.getMeshByName("Christmas Sledge").actionManager = new BABYLON.ActionManager(scene);
scene.getMeshByName("Christmas Sledge").actionManager.registerAction(
new BABYLON.ExecuteCodeAction({
trigger: BABYLON.ActionManager.OnPickTrigger,
parameter: scene.getMeshByName("Christmas Sledge")
},
function() {
meshChristmasSledgeText.visibility = 1.0;
}
)
);
// Add glow to objects with emission materials
var gl = new BABYLON.GlowLayer("glow", scene);
gl.intensity = 0.7;
// // Create SSAO and configure all properties (for the example)
// var ssaoRatio = {
// ssaoRatio: 0.5, // Ratio of the SSAO post-process, in a lower resolution
// combineRatio: 1.0 // Ratio of the combine post-process (combines the SSAO and the scene)
// };
// var ssao = new BABYLON.SSAORenderingPipeline("ssao", scene, ssaoRatio);
// ssao.fallOff = 0.00001;
// ssao.area = 0.3;
// ssao.radius = 0.00001;
// ssao.totalStrength = .7;
// ssao.base = 0.5;
// Add fog
scene.fogMode = BABYLON.Scene.FOGMODE_LINEAR;
scene.fogColor = scene.clearColor;
scene.fogStart = 50.0;
scene.fogEnd = 120.0;
engine.runRenderLoop(function() {
scene.render();
});
window.addEventListener("resize", function() {
engine.resize();
});
});
</script>
</body>
</html>