-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDecalManager.js
More file actions
47 lines (40 loc) · 1.33 KB
/
DecalManager.js
File metadata and controls
47 lines (40 loc) · 1.33 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
import * as BABYLON from 'babylonjs';
import { scene } from './globals';
var DecalManager = new function() {
// private variables
var bulletHoles = [];
var bulletHoleIndex = 0;
// public methods
this.init = function(assets)
{
this.materials = assets.materials;
this.run();
}
this.run = function()
{
var hiddenPosition = new BABYLON.Vector3(0, -30, 0);
var decalSize = new BABYLON.Vector3(0.1, 0.1, 0.1);
var decalMesh = BABYLON.MeshBuilder.CreatePlane("decalMesh", {size:0.1}, scene);
decalMesh.isPickable = false;
decalMesh.position = hiddenPosition;
decalMesh.material = this.materials.test;
//decalMesh.material.bumpTexture = new BABYLON.Texture('textures/NormalMap.png')
//decalMesh.material.diffuseTexture.hasAlpha = true;
//decalMesh.material.alpha = 1;
for (var i = 0; i < 50; i++) {
var bulletHoleInstance = decalMesh.createInstance();
bulletHoleInstance.isPickable = false;
bulletHoles.push(bulletHoleInstance);
}
}
this.createBulletHoleAt = function(pos, normal)
{
bulletHoles[bulletHoleIndex].position = pos;
bulletHoles[bulletHoleIndex].lookAt(bulletHoles[bulletHoleIndex].position.add(normal));
bulletHoleIndex++;
if(bulletHoleIndex > bulletHoles.length - 1) {
bulletHoleIndex = 0;
}
}
}
export default DecalManager;