-
Notifications
You must be signed in to change notification settings - Fork 0
/
AssetsLoader.js
33 lines (29 loc) · 1.01 KB
/
AssetsLoader.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
const Scene = require('Scene');
const Materials = require('Materials');
const Textures = require('Textures');
export const handleLoadedAssetGroup = (names, loadedAssets) => {
const items = {};
names.forEach((name, i) => {
items[name] = loadedAssets[i];
});
return items;
}
export const AssetsLoader = ({
objects = [],
materials = [],
textures = []
}) => {
return new Promise(resolve => {
Promise.all([
Promise.all(objects.map(obj => obj.indexOf('*') > -1 ? Scene.root.findByPath(obj) : Scene.root.findFirst(obj))),
Promise.all(materials.map(mat => mat.indexOf('*') > -1 ? Materials.findUsingPattern(mat) : Materials.findFirst(mat))),
Promise.all(textures.map(tex => tex.indexOf('*') > -1 ? Textures.findUsingPattern(tex) : Textures.findFirst(tex))),
]).then( assets => {
resolve({
objects: handleLoadedAssetGroup(objects, assets[0]),
materials: handleLoadedAssetGroup(materials, assets[1]),
textures: handleLoadedAssetGroup(textures, assets[2])
});
})
});
}