-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.js
200 lines (179 loc) · 4.81 KB
/
test.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
function onReady() {
var materialMatch = require('threejs-helper-material-assigner');
var View = require('threejs-managed-view').View;
var JITGeomSceneLoader = require('./');
var formatHelper = require('./formatHelpers/customBinary');
var MemoryStats = require('memory-stats');
var memoryStats = new MemoryStats();
memoryStats.domElement.style.position = 'fixed';
memoryStats.domElement.style.right = '0px';
memoryStats.domElement.style['z-index'] = '1';
memoryStats.domElement.style.bottom = '0px';
document.body.appendChild( memoryStats.domElement );
//all you really need
var view = new View({
// stats: true
});
view.renderManager.onEnterFrame.add(function() {
memoryStats.update();
})
view.renderer.setClearColor(0x999999);
var assetBasePath = '../../assets/models/parseTest/';
var scenePath = assetBasePath + 'parse.autodesk';
var geometryPath = assetBasePath + 'geometry';
var materials = {
carPaint: new THREE.MeshPhongMaterial({
diffuse: 0x7f7f7f,
emissive: 0xffddaa,
lights: false,
vertexColors: THREE.VertexColors
//side: THREE.BackSide
}),
ball: new THREE.MeshPhongMaterial({
diffuse: 0xff7f7f,
emissive: 0xff6644,
lights: false,
vertexColors: THREE.VertexColors
//side: THREE.BackSide
}),
pedestal: new THREE.MeshPhongMaterial({
diffuse: 0x7f7f7f,
emissive: 0xaaddcc,
lights: false,
vertexColors: THREE.VertexColors
//side: THREE.BackSide
}),
vertexShadow: new THREE.MeshPhongMaterial({
diffuse: 0x7f7f7f,
emissive: 0xffffff,
lights: false,
vertexColors: THREE.VertexColors,
//side: THREE.BackSide
}),
groundPlane: new THREE.MeshPhongMaterial({
diffuse: 0x7f7f7f,
emissive: 0xaa99aa,
lights: false,
vertexColors: THREE.VertexColors
//side: THREE.BackSide
})
}
materials.box = materials.carPaint;
function onProgress(val) {
console.log("Scene loading progress:", val);
}
function onComplete() {
console.log("Scene loading complete.");
//hierarchy loaded, so let's load and show some objects by name
//first group
function loadByName(name) {
jitGeomSceneLoader.loadByName(
name,
true,
function(value) {
progressReporter(name, value);
},
onGeometriesComplete.bind(this, name)
);
};
function progressReporter(name, value) {
console.log(name, "Geometries loading progress:", value);
};
function onGeometriesComplete(name) {
console.log(name, "Geometries loading complete.");
jitGeomSceneLoader.showByName(name, true);
};
// var name = 'all/groundPlane/niceTeapot';
// var alreadyLoaded = jitGeomSceneLoader.checkIfLoadedByName(name, true);
// console.log(name, 'alreadyLoaded?', alreadyLoaded);
// loadByName(name);
//another group which includes some objects from the first group
var tests = [];
function registerTest(name, test) {
tests.push([name, test]);
}
registerTest(
'load all',
function() {
loadByName('all');
}
);
//another group
registerTest(
'load a subPart',
function() {
loadByName('Gengon001');
}
);
/*
//redundant group should already be loaded.
registerTest(
'load even though it might exist',
function() {
name = 'all';
var alreadyLoaded = jitGeomSceneLoader.checkIfLoadedByName(name, true);
console.log(name, 'alreadyLoaded?', alreadyLoaded);
if(!alreadyLoaded) {
loadByName(name);
};
}
);
//redundant group should already be loaded.
registerTest(
'hide all but Ball1',
function() {
jitGeomSceneLoader.hideByName('all/groundPlane', true, true);
jitGeomSceneLoader.showByName('all/groundPlane/ball1', true);
}
);
registerTest(
'hide all but Ball2',
function() {
jitGeomSceneLoader.hideByName('all/groundPlane', true, true);
jitGeomSceneLoader.showByName('all/groundPlane/ball2', true);
}
);
registerTest(
'hide all but Ball3',
function() {
jitGeomSceneLoader.hideByName('all/groundPlane', true, true);
jitGeomSceneLoader.showByName('all/groundPlane/ball3', true);
}
);
*/
for (var i = 0; i < tests.length; i++) {
function closure() {
var i2 = i;
setTimeout(function() {
console.log("TEST: " + tests[i2][0]);
tests[i2][1]();
}, 1000*(i2+1));
};
closure();
};
}
function onMeshComplete(mesh) {
materialMatch(mesh, materials);
}
JITGeomSceneLoader.setFormatHelper(formatHelper);
var jitGeomSceneLoader = new JITGeomSceneLoader({
path: scenePath,
geometryPath: geometryPath,
targetParent: view.scene,
materials: materials,
onProgress: onProgress,
onMeshComplete: onMeshComplete,
onComplete: onComplete,
debugLevel: 0
});
}
var loadAndRunScripts = require('loadandrunscripts');
loadAndRunScripts(
[
'bower_components/three.js/three.js',
'lib/stats.min.js',
'lib/threex.rendererstats.js',
'lib/gzip.js'
],
onReady
);