-
Notifications
You must be signed in to change notification settings - Fork 3
/
Box.js
52 lines (34 loc) · 1.15 KB
/
Box.js
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
var BoxConstructor = function() {
this.list = {};
var size = 2;
this.create = function(scene) {
// create the box into the scene
var newBox = BABYLON.MeshBuilder.CreateBox('box', {
height: size,
width: size,
depth: size
}, scene);
// give the box an id
newBox.id = Math.random();
// Apply material to box
newBox.material = Materials.woodenCrate;
newBox.physicsImpostor = new BABYLON.PhysicsImpostor(newBox, BABYLON.PhysicsImpostor.BoxImpostor, { mass: 0.1, restitution: 0.9 }, scene);
// Put newBox into the list of boxes
this.list[newBox.id] = newBox;
return newBox;
}
this.update = function() {
for(var id in BulletConstructor.list) {
var bullet = BulletConstructor.list[id];
for(var id in BoxConstructor.list) {
var box = BoxConstructor.list[id];
if(bullet.intersectsMesh(box)) {
var decal = BABYLON.MeshBuilder.CreateDecal("decal", box, {position: bullet.position, size: decalSize});
decal.material = decalMaterial;
bullet.dispose();
}
}
}
}
}
var BoxConstructor = new BoxConstructor();