forked from michaljaz/webmc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssetLoader.js
More file actions
79 lines (72 loc) · 1.79 KB
/
AssetLoader.js
File metadata and controls
79 lines (72 loc) · 1.79 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
68
69
70
71
72
73
74
75
76
77
78
79
// Generated by CoffeeScript 2.5.1
var AssetLoader;
import * as THREE from './build/three.module.js';
import {
FBXLoader
} from './jsm/loaders/FBXLoader.js';
AssetLoader = class AssetLoader {
constructor(options) {
this.assets = {};
}
load(assets, callback) {
var _this, assetsLoaded, assetsNumber, fbxl, textureLoader;
_this = this;
textureLoader = new THREE.TextureLoader();
fbxl = new FBXLoader();
assetsNumber = 0;
assetsLoaded = 0;
Object.keys(assets).forEach(function(p) {
return assetsNumber++;
});
Object.keys(assets).forEach(function(p) {
var img, path, type;
type = assets[p].type;
path = assets[p].path;
if (type === "texture") {
textureLoader.load(path, function(texture) {
_this.assets[p] = texture;
assetsLoaded++;
if (assetsLoaded === assetsNumber) {
return callback();
}
});
}
if (type === "text") {
$.get(path, function(data) {
_this.assets[p] = data;
assetsLoaded++;
if (assetsLoaded === assetsNumber) {
return callback();
}
});
}
if (type === "image") {
img = new Image();
img.onload = function() {
_this.assets[p] = img;
assetsLoaded++;
if (assetsLoaded === assetsNumber) {
return callback();
}
};
img.src = path;
}
if (type === "fbx") {
return fbxl.load(path, function(fbx) {
_this.assets[p] = fbx;
assetsLoaded++;
if (assetsLoaded === assetsNumber) {
return callback();
}
});
}
});
return this;
}
get(assetName) {
return this.assets[assetName];
}
};
export {
AssetLoader
};