forked from michaljaz/webmc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssetLoader.coffee
More file actions
57 lines (55 loc) · 1.31 KB
/
AssetLoader.coffee
File metadata and controls
57 lines (55 loc) · 1.31 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
import * as THREE from "three"
import {FBXLoader} from "three/examples/jsm/loaders/FBXLoader.js"
class AssetLoader
constructor: (init)->
@assets={}
_this=@
$.get "assets/assetLoader.json", (assets)->
_this.load assets,()->
console.log "AssetLoader: done loading!"
if init isnt null
init _this
return
return
return
load: (assets,callback) ->
_this=@
textureLoader = new THREE.TextureLoader
fbxl = new FBXLoader()
assetsNumber=0
assetsLoaded=0
Object.keys(assets).forEach (p)->
assetsNumber++
Object.keys(assets).forEach (p)->
type=assets[p].type
path=assets[p].path
if type is "texture"
textureLoader.load path,(texture)->
_this.assets[p]=texture
assetsLoaded++;
if assetsLoaded is assetsNumber
callback()
if type is "text"
$.get path,(data)->
_this.assets[p]=data
assetsLoaded++;
if assetsLoaded is assetsNumber
callback()
if type is "image"
img = new Image
img.onload= ->
_this.assets[p]=img
assetsLoaded++;
if assetsLoaded is assetsNumber
callback()
img.src=path
if type is "fbx"
fbxl.load path,(fbx)->
_this.assets[p]=fbx
assetsLoaded++;
if assetsLoaded is assetsNumber
callback()
return this;
get: (assetName)->
return @assets[assetName]
export {AssetLoader}