-
Notifications
You must be signed in to change notification settings - Fork 0
/
obj-manager.js
executable file
·101 lines (91 loc) · 3.45 KB
/
obj-manager.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
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// import OBJLoader from 'three-obj-loader'
import OBJLoader2 from 'vendor/loaders/OBJLoader2.js'
// import SubdivisionModifier from 'three-subdivision-modifier'
import * as THREE from 'three'
OBJLoader2(THREE);
module.exports = function() {
class ObjManager {
constructor(materialManager){
this.manager = new THREE.LoadingManager();
this.queue = [];
this.initLoaded = false;
this.getObjLoaded = false,
this.materialManager = materialManager;
this.meshes = {
drawerHandle: new THREE.Object3D(),
drawerHandleCap: new THREE.Object3D(),
lockingCasterBlack: new THREE.Object3D(),
lockingCasterSilver: new THREE.Object3D(),
casterBlack: new THREE.Object3D(),
casterSilver: new THREE.Object3D(),
handles : {
steelR : new THREE.Object3D(),
steelL : new THREE.Object3D(),
blackPlastic : new THREE.Object3D(),
techSeriesR : new THREE.Object3D(),
techSeriesL : new THREE.Object3D()
},
lockKeypadH: new THREE.Object3D(),
lockHasp : new THREE.Object3D()
}
this.init();
}
init(){
this.loadObj(this.meshes.drawerHandle, '/obj/handle-smooth-1mm.obj');
this.loadObj(this.meshes.drawerHandleCap, '/obj/handle-cap-1mm.obj');
this.loadObj(this.meshes.lockingCasterBlack, '/obj/pivoting_casters_brakeAndRubberPart.obj');
this.loadObj(this.meshes.lockingCasterSilver, '/obj/pivoting_casters_steelPart.obj');
this.loadObj(this.meshes.casterBlack, '/obj/stationary_casters_rubberPart.obj');
this.loadObj(this.meshes.casterSilver, '/obj/stationary_casters_steelPart.obj');
this.loadObj(this.meshes.handles.steelR, '/obj/side_handles_steelPart_right.obj');
this.loadObj(this.meshes.handles.steelL, '/obj/side_handles_steelPart_left.obj');
this.loadObj(this.meshes.handles.blackPlastic, '/obj/handle_black-plastic.obj');
this.loadObj(this.meshes.handles.techSeriesL, '/obj/handle_tech-series-left.obj');
this.loadObj(this.meshes.handles.techSeriesR, '/obj/handle_tech-series-right.obj');
this.loadObj(this.meshes.lockKeypadH, '/obj/lock_keypad-h.obj');
this.loadObj(this.meshes.lockHasp, '/obj/lock_hasp.obj');
this.manager.onLoad = () => {
this.initLoaded = true;
this.dumpQueue();
}
}
whenLoaded(callback){
if(!this.manager.isLoading && this.initLoaded){
callback();
} else {
this.queue.push(callback)
}
}
dumpQueue(){
this.queue.forEach(function(callback){
callback();
},this)
}
loadObj(parent, ref){
let loader = new THREE.OBJLoader2( this.manager );
loader.load( ref, object => {
object.traverse( child => {
if ( child instanceof THREE.Mesh ){
child.geometry.computeFaceNormals();
child.geometry.computeVertexNormals();
let material = this.materialManager.materials.tops.stainless;
child.material = material;
}
});
parent.name = ref;
parent.add(object);
}, this.onProgress, this.onError );
}
onProgress( xhr ) {
if ( xhr.lengthComputable ) {
var percentComplete = xhr.loaded / xhr.total * 100;
// console.log("OBJ Downloading: " + Math.round(percentComplete, 2) + '% downloaded' );
}
};
onError( xhr ) {
//console.log("<OBJ LOAD ERROR>")
//console.log(xhr)
};
}
return ObjManager;
}