-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.js
More file actions
67 lines (55 loc) · 2.55 KB
/
main.js
File metadata and controls
67 lines (55 loc) · 2.55 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import * as BABYLON from 'babylonjs';
import { scene, assetsManager } from './globals';
import opts from './options';
import game from './game';
const { verbose } = opts;
const assets = {
materials: {}
};
const textures = {
'wireFrame': { type: 'diffuse', fileName: 'woodenCrate.jpg' }, // change in the future
'bulletHoleMaterial': { type: 'diffuse', fileName: 'impact.png' },
'woodenCrate': { type: 'diffuse', fileName: 'woodenCrate.jpg' },
'e1m1wall': { type: 'diffuse', fileName: 'e1m1wall.png' },
//'e1m1wallBump': { type: 'bump', for: 'e1m1wall', fileName: 'NormalMap.png' },
'e1m1floor': { type: 'diffuse', fileName: 'e1m1floor.png' },
'e1m1floorBump': { type: 'bump', for: 'e1m1floor', fileName: 'bump_e1m1floor.png' },
'e1m1ceil': { type: 'diffuse', fileName: 'e1m1ceil.png' },
//'e1m1ceilBump': { type: 'bump', for: 'e1m1ceil', fileName: 'bump_e1m1ceil.png' },
'test': { type: 'diffuse', fileName: 'test.png' },
'testBump': { type: 'bump', for: 'test', fileName: 'bump_test.png' }
};
const numberOfTextures = Object.keys(textures).length;
let loadedTextures = 0;
for(let textureName in textures) {
if(verbose) { console.log(`loading ${textureName}`) }
var imageTask = assetsManager.addImageTask(textureName, 'textures/' + textures[textureName].fileName);
imageTask.onSuccess = function(task) {
if(verbose) { console.log(`loaded ${textureName}`); }
loadedTextures++;
if(textures[textureName].for) {
assets.materials[textures[textureName].for].bumpTexture = new BABYLON.Texture('textures/' + textures[textureName].fileName);
} else {
assets.materials[textureName] = new BABYLON.StandardMaterial(textureName, scene);
assets.materials[textureName][textures[textureName].type + 'Texture'] = new BABYLON.Texture('textures/' + textures[textureName].fileName);
}
if(loadedTextures == numberOfTextures) {
assets.materials.bulletHoleMaterial.diffuseTexture.hasAlpha = true;
assets.materials.bulletHoleMaterial.zOffset = -2;
assets.materials.wireFrame.wireframe = false;
// Shotgun Material
assets.materials.shotgunMaterial = new BABYLON.StandardMaterial(name, scene);
var shotgunTexture = new BABYLON.Texture("sprites/shotgun.png", scene);
shotgunTexture.uScale = 1/7;
shotgunTexture.hasAlpha = true;
assets.materials.shotgunMaterial.diffuseTexture = shotgunTexture;
//
assets.materials.test.diffuseTexture.hasAlpha = true;
assets.materials.test.zOffset = -2;
}
}
};
assetsManager.onFinish = function() {
game.init(assets);
}
assetsManager.load();