@xviewer.js/core 1.0.5-alhpa.8 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.cjs CHANGED
@@ -3,13 +3,14 @@
3
3
  var EXRLoader_js = require('three/examples/jsm/loaders/EXRLoader.js');
4
4
  var FBXLoader_js = require('three/examples/jsm/loaders/FBXLoader.js');
5
5
  var GLTFLoader_js = require('three/examples/jsm/loaders/GLTFLoader.js');
6
- var DRACOLoader_js = require('three/examples/jsm/loaders/DRACOLoader.js');
7
6
  var meshopt_decoder_module_js = require('three/examples/jsm/libs/meshopt_decoder.module.js');
8
- var THREE = require('three');
9
7
  var HDRLoader_js = require('three/examples/jsm/loaders/HDRLoader.js');
8
+ var THREE = require('three');
10
9
  var SVGLoader_js = require('three/examples/jsm/loaders/SVGLoader.js');
11
- var KTX2Loader_js = require('three/examples/jsm/loaders/KTX2Loader.js');
12
10
  var Addons_js = require('three/examples/jsm/Addons.js');
11
+ var DRACOLoader_js = require('three/examples/jsm/loaders/DRACOLoader.js');
12
+ var KTX2Loader_js = require('three/examples/jsm/loaders/KTX2Loader.js');
13
+ var STLLoader_js = require('three/examples/jsm/loaders/STLLoader.js');
13
14
 
14
15
  function _interopNamespaceDefault(e) {
15
16
  var n = Object.create(null);
@@ -164,65 +165,18 @@ function getClassInstance(constructor, args = []) {
164
165
  }
165
166
 
166
167
  class Loader {
167
- static _setUserData(node) {
168
- const meshes = [];
169
- const textures = {};
170
- const materials = {};
171
- const queue = [
172
- node
173
- ];
174
- while(queue.length !== 0){
175
- let object = queue.shift();
176
- if (object.isMesh) {
177
- meshes.push(object);
178
- const mat = object.material;
179
- if (Array.isArray(mat)) mat.forEach((v)=>materials[v.uuid] = v);
180
- else materials[mat.uuid] = mat;
181
- }
182
- queue.push(...object.children);
183
- }
184
- Object.values(materials).forEach((mat)=>{
185
- Loader._texKeys.forEach((k)=>{
186
- let tex = mat[k];
187
- if (tex) {
188
- textures[tex.uuid] = tex;
189
- }
190
- });
191
- });
192
- Object.assign(node.userData, {
193
- meshes,
194
- textures: Object.values(textures),
195
- materials: Object.values(materials)
196
- });
197
- return node;
198
- }
199
- constructor(viewer){
200
- this.viewer = viewer;
201
- }
202
- }
203
- Loader._texKeys = [
204
- "map",
205
- "alphaMap",
206
- "aoMap",
207
- "bumpMap",
208
- "displacementMap",
209
- "emissiveMap",
210
- "envMap",
211
- "lightMap",
212
- "metalnessMap",
213
- "normalMap",
214
- "roughnessMap",
215
- "specularMap",
216
- "alphaMap"
217
- ];
168
+ constructor(manager){
169
+ this.manager = manager;
170
+ }
171
+ }
218
172
 
219
173
  class EXRLoader extends Loader {
220
- load({ url, path, resourcePath, manager, texSettings, onLoad, onProgress, onError }) {
174
+ load({ url, path, resourcePath, texSettings, onLoad, onProgress, onError }) {
221
175
  let loader = this._loader;
222
176
  if (loader === undefined) {
223
177
  loader = this._loader = new EXRLoader_js.EXRLoader();
178
+ loader.manager = this.manager.loadingManager;
224
179
  }
225
- loader.manager = manager;
226
180
  loader.setPath(path);
227
181
  loader.setResourcePath(resourcePath);
228
182
  loader.load(url, (tex)=>onLoad(Object.assign(tex, texSettings)), onProgress, onError);
@@ -235,12 +189,12 @@ class EXRLoader extends Loader {
235
189
  }
236
190
 
237
191
  class FBXLoader extends Loader {
238
- load({ url, buffer, path, resourcePath, manager, onLoad, onProgress, onError }) {
192
+ load({ url, buffer, path, resourcePath, onLoad, onProgress, onError }) {
239
193
  let loader = this._loader;
240
194
  if (loader === undefined) {
241
195
  loader = this._loader = new FBXLoader_js.FBXLoader();
196
+ loader.manager = this.manager.loadingManager;
242
197
  }
243
- loader.manager = manager;
244
198
  loader.setPath(path);
245
199
  loader.setResourcePath(resourcePath);
246
200
  if (buffer) {
@@ -257,20 +211,15 @@ class FBXLoader extends Loader {
257
211
  }
258
212
 
259
213
  class GLTFLoader extends Loader {
260
- load({ url, buffer, path, resourcePath, dracoPath, manager, onLoad, onProgress, onError }) {
261
- let dracoLoader = this._dracoLoader;
262
- if (dracoLoader === undefined) {
263
- dracoLoader = this._dracoLoader = new DRACOLoader_js.DRACOLoader();
264
- }
265
- dracoLoader.manager = manager;
266
- dracoLoader.setDecoderPath(dracoPath);
214
+ load({ url, buffer, path, resourcePath, onLoad, onProgress, onError }) {
267
215
  let loader = this._loader;
268
216
  if (loader === undefined) {
269
217
  loader = this._loader = new GLTFLoader_js.GLTFLoader();
270
- loader.setDRACOLoader(dracoLoader);
218
+ loader.manager = this.manager.loadingManager;
271
219
  loader.setMeshoptDecoder(meshopt_decoder_module_js.MeshoptDecoder);
220
+ loader.setDRACOLoader(this.manager.dracoLoader);
221
+ loader.setKTX2Loader(this.manager.ktx2Loader);
272
222
  }
273
- loader.manager = manager;
274
223
  loader.setPath(path);
275
224
  loader.setResourcePath(resourcePath);
276
225
  const cb = (gltf)=>{
@@ -306,19 +255,15 @@ class GLTFLoader extends Loader {
306
255
  }
307
256
 
308
257
  class HDRLoader extends Loader {
309
- load({ url, path, resourcePath, manager, texSettings, onLoad, onProgress, onError }) {
258
+ load({ url, path, resourcePath, texSettings, onLoad, onProgress, onError }) {
310
259
  let loader = this._loader;
311
260
  if (loader === undefined) {
312
261
  loader = this._loader = new HDRLoader_js.HDRLoader();
262
+ loader.manager = this.manager.loadingManager;
313
263
  }
314
- loader.manager = manager;
315
264
  loader.setPath(path);
316
265
  loader.setResourcePath(resourcePath);
317
- const loadCallback = (tex)=>{
318
- tex.mapping = THREE.EquirectangularReflectionMapping;
319
- onLoad(Object.assign(tex, texSettings));
320
- };
321
- loader.load(url, loadCallback, onProgress, onError);
266
+ loader.load(url, (tex)=>onLoad(Object.assign(tex, texSettings)), onProgress, onError);
322
267
  }
323
268
  constructor(...args){
324
269
  super(...args), this.extension = [
@@ -328,12 +273,12 @@ class HDRLoader extends Loader {
328
273
  }
329
274
 
330
275
  class JSONLoader extends Loader {
331
- load({ url, path, resourcePath, manager, onLoad, onProgress, onError }) {
276
+ load({ url, path, resourcePath, onLoad, onProgress, onError }) {
332
277
  let loader = this._loader;
333
278
  if (loader === undefined) {
334
279
  loader = this._loader = new THREE.FileLoader();
280
+ loader.manager = this.manager.loadingManager;
335
281
  }
336
- loader.manager = manager;
337
282
  loader.setPath(path);
338
283
  loader.setResourcePath(resourcePath);
339
284
  loader.load(url, (file)=>onLoad(JSON.parse(file)), onProgress, onError);
@@ -346,12 +291,12 @@ class JSONLoader extends Loader {
346
291
  }
347
292
 
348
293
  class TextureLoader extends Loader {
349
- load({ url, path, resourcePath, manager, texSettings, onLoad, onProgress, onError }) {
294
+ load({ url, path, resourcePath, texSettings, onLoad, onProgress, onError }) {
350
295
  let loader = this._loader;
351
296
  if (loader === undefined) {
352
297
  loader = this._loader = new THREE.TextureLoader();
298
+ loader.manager = this.manager.loadingManager;
353
299
  }
354
- loader.manager = manager;
355
300
  loader.setPath(path);
356
301
  loader.setResourcePath(resourcePath);
357
302
  const loadCallback = (tex)=>{
@@ -370,86 +315,13 @@ class TextureLoader extends Loader {
370
315
  }
371
316
  }
372
317
 
373
- class BINLoader extends Loader {
374
- load({ url, buffer, path, resourcePath, dracoPath, manager, onLoad, onProgress, onError }) {
375
- let dracoLoader = this._dracoLoader;
376
- if (dracoLoader === undefined) {
377
- dracoLoader = this._dracoLoader = new DRACOLoader_js.DRACOLoader();
378
- }
379
- dracoLoader.manager = manager;
380
- dracoLoader.setDecoderPath(dracoPath);
381
- let loader = this._loader;
382
- if (loader === undefined) {
383
- loader = this._loader = new CustomLoader();
384
- loader.setDRACOLoader(dracoLoader);
385
- loader.setMeshoptDecoder(meshopt_decoder_module_js.MeshoptDecoder);
386
- }
387
- loader.salt = this.salt;
388
- loader.manager = manager;
389
- loader.setPath(path);
390
- loader.setResourcePath(resourcePath);
391
- if (buffer) {
392
- loader.parse(buffer, resourcePath, onLoad, onError);
393
- } else {
394
- loader.load(url, onLoad, onProgress, onError);
395
- }
396
- }
397
- constructor(...args){
398
- super(...args), this.extension = [
399
- "bin"
400
- ], this.salt = 255;
401
- }
402
- }
403
- class CustomLoader extends GLTFLoader_js.GLTFLoader {
404
- parse(data, path, onLoad, onError) {
405
- super.parse(glbDecode(data, this.salt), path, onLoad, onError);
406
- }
407
- constructor(...args){
408
- super(...args), this.salt = 255;
409
- }
410
- }
411
- const BINARY_EXTENSION_HEADER_MAGIC = 'glTF';
412
- const BINARY_EXTENSION_HEADER_LENGTH = 12;
413
- function encryptArray(array, salt) {
414
- for(let i = 0, n = array.length; i < n; i++){
415
- array[i] ^= salt;
416
- }
417
- return array;
418
- }
419
- function glbDecode(buffer, salt = 255) {
420
- encryptArray(new Uint8Array(buffer, 0, 4), salt);
421
- const headerView = new DataView(buffer, 0, BINARY_EXTENSION_HEADER_LENGTH);
422
- const textDecoder = new TextDecoder();
423
- const header = {
424
- magic: textDecoder.decode(new Uint8Array(buffer.slice(0, 4))),
425
- version: headerView.getUint32(4, true),
426
- length: headerView.getUint32(8, true)
427
- };
428
- if (header.magic !== BINARY_EXTENSION_HEADER_MAGIC) {
429
- throw new Error('Unsupported glTF-Binary header.');
430
- } else if (header.version < 2.0) {
431
- throw new Error('Legacy binary file detected.');
432
- }
433
- const chunkContentsLength = header.length - BINARY_EXTENSION_HEADER_LENGTH;
434
- const chunkView = new DataView(buffer, BINARY_EXTENSION_HEADER_LENGTH);
435
- let chunkIndex = 0;
436
- while(chunkIndex < chunkContentsLength){
437
- const chunkLength = chunkView.getUint32(chunkIndex, true);
438
- chunkIndex += 4;
439
- encryptArray(new Uint8Array(buffer, BINARY_EXTENSION_HEADER_LENGTH + chunkIndex, chunkLength + 4), salt);
440
- chunkIndex += 4;
441
- chunkIndex += chunkLength;
442
- }
443
- return buffer;
444
- }
445
-
446
318
  class SVGLoader extends Loader {
447
- load({ url, path, resourcePath, manager, onLoad, onProgress, onError }) {
319
+ load({ url, path, resourcePath, onLoad, onProgress, onError }) {
448
320
  let loader = this._loader;
449
321
  if (loader === undefined) {
450
322
  loader = this._loader = new SVGLoader_js.SVGLoader();
323
+ loader.manager = this.manager.loadingManager;
451
324
  }
452
- loader.manager = manager;
453
325
  loader.setPath(path);
454
326
  loader.setResourcePath(resourcePath);
455
327
  loader.load(url, onLoad, onProgress, onError);
@@ -463,21 +335,12 @@ class SVGLoader extends Loader {
463
335
  SVGLoader.Primitive = SVGLoader_js.SVGLoader;
464
336
 
465
337
  class KTX2Loader extends Loader {
466
- load({ url, path, resourcePath, transcoderPath, manager, texSettings, onLoad, onProgress, onError }) {
467
- let loader = this._loader;
468
- if (loader === undefined) {
469
- loader = this._loader = new KTX2Loader_js.KTX2Loader();
470
- loader.setTranscoderPath(transcoderPath);
471
- loader.detectSupport(this.viewer.renderer);
472
- }
473
- loader.manager = manager;
338
+ load({ url, path, resourcePath, texSettings, onLoad, onProgress, onError }) {
339
+ const loader = this.manager.ktx2Loader;
474
340
  loader.setPath(path);
475
341
  loader.setResourcePath(resourcePath);
476
- const loadCallback = (tex)=>{
477
- tex.mapping = THREE.CubeUVReflectionMapping;
478
- onLoad(Object.assign(tex, texSettings));
479
- };
480
- loader.load(url, loadCallback, onProgress, onError);
342
+ loader.manager = this.manager.loadingManager;
343
+ loader.load(url, (tex)=>onLoad(Object.assign(tex, texSettings)), onProgress, onError);
481
344
  }
482
345
  constructor(...args){
483
346
  super(...args), this.extension = [
@@ -565,7 +428,7 @@ const Vector3_NEG_ONE = Object.freeze(new THREE.Vector3(-1, -1, -1));
565
428
 
566
429
  const { clamp: clamp$2 } = THREE.MathUtils;
567
430
  const { max, abs, acos } = Math;
568
- const EPSILON = 1.e-6;
431
+ const EPSILON = 1.e-8;
569
432
  const __deltaMap = new Map();
570
433
  __deltaMap.set(THREE.Vector3, new THREE.Vector3());
571
434
  __deltaMap.set(THREE.Vector2, new THREE.Vector2());
@@ -1312,7 +1175,7 @@ class Component extends ObjectInstance {
1312
1175
  }
1313
1176
  _onPreDestroy() {
1314
1177
  this.unscheduleAll();
1315
- this.manager.removeComponent(this.node, this);
1178
+ this.manager.remove(this.node, this);
1316
1179
  if (this._enabled) {
1317
1180
  this.manager.componentScheduler.enableComponent(this, false);
1318
1181
  }
@@ -1660,19 +1523,6 @@ function getChildren(node, filter, group = false) {
1660
1523
  }
1661
1524
  return objects[0];
1662
1525
  }
1663
- function getChildByName(node, name) {
1664
- return getChildren(node, (v)=>v && v.name === name);
1665
- }
1666
- const __emtpyObject = {};
1667
- function queryValues(object, name, group = false) {
1668
- if (name) {
1669
- if (group) {
1670
- return Object.values(object || __emtpyObject).filter((v)=>v.name === name);
1671
- }
1672
- return Object.values(object || __emtpyObject).find((v)=>v.name === name);
1673
- }
1674
- return Object.values(object);
1675
- }
1676
1526
 
1677
1527
  class ContactShadows extends Component {
1678
1528
  get visible() {
@@ -2350,6 +2200,12 @@ function single() {
2350
2200
  };
2351
2201
  }
2352
2202
  class ComponentManager {
2203
+ get started() {
2204
+ return this._started;
2205
+ }
2206
+ get manual() {
2207
+ return this._manual;
2208
+ }
2353
2209
  get viewer() {
2354
2210
  return this._viewer;
2355
2211
  }
@@ -2359,45 +2215,62 @@ class ComponentManager {
2359
2215
  get componentScheduler() {
2360
2216
  return this._componentScheduler;
2361
2217
  }
2362
- destroy() {
2363
- this._componentsMap.forEach((components)=>components.forEach((comp)=>comp.destroy()));
2364
- this._componentsMap.clear();
2218
+ destroy(node) {
2219
+ if (node) {
2220
+ let components = this._componentsMap.get(node);
2221
+ if (components) {
2222
+ components.forEach((comp)=>comp.destroy());
2223
+ this._componentsMap.delete(node);
2224
+ }
2225
+ for (let child of node.children){
2226
+ this.destroy(child);
2227
+ }
2228
+ } else {
2229
+ this._componentsMap.forEach((components)=>components.forEach((comp)=>comp.destroy()));
2230
+ this._componentsMap.clear();
2231
+ }
2365
2232
  }
2366
2233
  tick(dt) {
2367
2234
  this._componentScheduler.tick(dt);
2368
2235
  }
2369
2236
  update(dt) {
2237
+ if (!this._started) return;
2370
2238
  this._scheduler.update(dt);
2371
2239
  this._componentScheduler.start();
2372
2240
  this._componentScheduler.update(dt);
2373
2241
  this._componentScheduler.lastUpdate(dt);
2374
2242
  }
2375
2243
  render(dt) {
2244
+ if (!this._started) return;
2376
2245
  this._componentScheduler.render(dt);
2377
2246
  }
2378
2247
  resize(width, height) {
2379
2248
  this.componentScheduler.resize(width, height);
2380
2249
  }
2381
- destroyComponents(node) {
2382
- let components = this._componentsMap.get(node);
2383
- if (components) {
2384
- components.forEach((comp)=>comp.destroy());
2385
- this._componentsMap.delete(node);
2386
- }
2387
- for (let child of node.children){
2388
- this.destroyComponents(child);
2389
- }
2250
+ start() {
2251
+ this._started = true;
2252
+ return this;
2390
2253
  }
2391
- activeComponents(node) {
2254
+ pause() {
2255
+ this._started = false;
2256
+ return this;
2257
+ }
2258
+ resume() {
2259
+ return this.start();
2260
+ }
2261
+ stop() {
2262
+ return this.pause();
2263
+ }
2264
+ active(node) {
2392
2265
  let components = this._componentsMap.get(node);
2393
2266
  if (components) {
2394
2267
  components.forEach((comp)=>this._activeComponent(comp, node.visible));
2395
2268
  }
2396
2269
  for (let child of node.children){
2397
- this.activeComponents(child);
2270
+ this.active(child);
2398
2271
  }
2399
2272
  }
2400
- addComponent(node, constructor) {
2273
+ add(node, constructor) {
2401
2274
  let root = node instanceof Component ? node.node : node;
2402
2275
  let func = typeof constructor === "function";
2403
2276
  const proto = func ? constructor : constructor.constructor;
@@ -2427,26 +2300,26 @@ class ComponentManager {
2427
2300
  throw Error("Add multiple components");
2428
2301
  }
2429
2302
  }
2430
- removeComponent(node, component) {
2303
+ remove(node, component) {
2431
2304
  let components = this._componentsMap.get(node);
2432
2305
  if (components) {
2433
2306
  components.splice(components.indexOf(component), 1);
2434
2307
  }
2435
2308
  return this;
2436
2309
  }
2437
- getComponent(node, constructor) {
2310
+ get(node, constructor) {
2438
2311
  return this._findComponent(node, constructor);
2439
2312
  }
2440
- getComponentInChildren(node, constructor) {
2313
+ getInChildren(node, constructor) {
2441
2314
  let comp = this._findComponent(node, constructor);
2442
2315
  if (comp) return comp;
2443
2316
  for (let child of node.children){
2444
- if (comp = this.getComponentInChildren(child, constructor)) {
2317
+ if (comp = this.getInChildren(child, constructor)) {
2445
2318
  return comp;
2446
2319
  }
2447
2320
  }
2448
2321
  }
2449
- getComponentsInChidren(node, constructor, out = []) {
2322
+ getAllInChildren(node, constructor, out = []) {
2450
2323
  let components = this._componentsMap.get(node);
2451
2324
  if (components) {
2452
2325
  for(let i = components.length; i--;){
@@ -2454,11 +2327,11 @@ class ComponentManager {
2454
2327
  }
2455
2328
  }
2456
2329
  for (let child of node.children){
2457
- this.getComponentsInChidren(child, constructor, out);
2330
+ this.getAllInChildren(child, constructor, out);
2458
2331
  }
2459
2332
  return out;
2460
2333
  }
2461
- traverseComponents(callback) {
2334
+ traverse(callback) {
2462
2335
  this._componentsMap.forEach((v)=>v.forEach(callback));
2463
2336
  }
2464
2337
  _addDendencies(node, constructor) {
@@ -2467,9 +2340,9 @@ class ComponentManager {
2467
2340
  if (info) {
2468
2341
  const { components = [], mode } = info;
2469
2342
  for (const dep of components){
2470
- if (!this.getComponent(node, dep)) {
2343
+ if (!this.get(node, dep)) {
2471
2344
  if (mode === 1) {
2472
- this.addComponent(node, dep);
2345
+ this.add(node, dep);
2473
2346
  } else {
2474
2347
  throw `Should add ${dep.name} before adding ${constructor.name}`;
2475
2348
  }
@@ -2493,11 +2366,15 @@ class ComponentManager {
2493
2366
  _activeComponent(comp, active) {
2494
2367
  this._componentScheduler.enableComponent(comp, active);
2495
2368
  }
2496
- constructor(viewer){
2369
+ constructor(viewer, { manual = false } = {}){
2497
2370
  this._scheduler = new Scheduler();
2498
2371
  this._componentScheduler = new ComponentScheduler();
2499
2372
  this._componentsMap = new Map();
2373
+ this._started = false;
2374
+ this._manual = false;
2500
2375
  this._viewer = viewer;
2376
+ this._manual = manual;
2377
+ this._started = !manual;
2501
2378
  }
2502
2379
  }
2503
2380
  ComponentManager._infoMap = new Map();
@@ -2942,15 +2819,15 @@ class DeviceInput extends Component {
2942
2819
  this.viewer.emit(DeviceInput.TOUCH_MOVE, ex);
2943
2820
  }
2944
2821
  _onKeyDown(e) {
2945
- this._keys[e.key] = true;
2822
+ this._keys[e.code] = true;
2946
2823
  this.viewer.emit(DeviceInput.KEYDOWN, e);
2947
2824
  }
2948
2825
  _onKeyPress(e) {
2949
- this._keys[e.key] = true;
2826
+ this._keys[e.code] = true;
2950
2827
  this.viewer.emit(DeviceInput.KEYPRESS, e);
2951
2828
  }
2952
2829
  _onKeyUp(e) {
2953
- this._keys[e.key] = false;
2830
+ this._keys[e.code] = false;
2954
2831
  this.viewer.emit(DeviceInput.KEYUP, e);
2955
2832
  }
2956
2833
  constructor(option){
@@ -3366,15 +3243,15 @@ class FreelookVirtualCamera extends Component {
3366
3243
  return out;
3367
3244
  }
3368
3245
  _calculateLookAtOffset(panDelta, out = new THREE.Vector3()) {
3369
- const { xAxis, yAxis, posDelta } = FreelookVirtualCamera;
3246
+ const { xAxis, yAxis } = FreelookVirtualCamera;
3247
+ this.node.updateMatrix();
3370
3248
  xAxis.setFromMatrixColumn(this.node.matrix, 0);
3371
3249
  yAxis.setFromMatrixColumn(this.node.matrix, 1);
3372
3250
  if (this.forbitAll || this.forbitPanOffsetY) {
3373
3251
  yAxis.y = 0;
3374
3252
  yAxis.normalize();
3375
3253
  }
3376
- posDelta.copy(this.node.position).sub(this.lookAt);
3377
- const length = posDelta.length() * 2 * tan(degToRad(this.fov * 0.5));
3254
+ const length = this._spherical.radius * 2 * tan(degToRad(this.fov * 0.5));
3378
3255
  return out.set(0, 0, 0).sub(xAxis.multiplyScalar(panDelta.x * length)).add(yAxis.multiplyScalar(panDelta.y * length));
3379
3256
  }
3380
3257
  _setTargetLookAt(panDelta) {
@@ -3515,7 +3392,6 @@ FreelookVirtualCamera.center = new THREE.Vector2();
3515
3392
  FreelookVirtualCamera.preCenter = new THREE.Vector2();
3516
3393
  FreelookVirtualCamera.panDelta = new THREE.Vector2();
3517
3394
  FreelookVirtualCamera.rotateDelta = new THREE.Vector2();
3518
- FreelookVirtualCamera.posDelta = new THREE.Vector3();
3519
3395
  FreelookVirtualCamera.lookAtOffset = new THREE.Vector3();
3520
3396
  FreelookVirtualCamera.xAxis = new THREE.Vector3();
3521
3397
  FreelookVirtualCamera.yAxis = new THREE.Vector3();
@@ -4469,18 +4345,50 @@ function _getMipBlurMaterial(lodMax, width, height) {
4469
4345
  });
4470
4346
  }
4471
4347
 
4348
+ class Task {
4349
+ constructor(excute, name){
4350
+ this.instanceId = Task._instanceCount++;
4351
+ this.name = "task" + this.instanceId;
4352
+ this.excute = excute;
4353
+ this.name = name || this.name;
4354
+ }
4355
+ }
4356
+ Task._instanceCount = 0;
4357
+
4472
4358
  class TaskManager {
4473
4359
  get isComplete() {
4474
4360
  return this._taskIndex >= this._tasks.length;
4475
4361
  }
4362
+ get started() {
4363
+ return this._started;
4364
+ }
4365
+ get manual() {
4366
+ return this._manual;
4367
+ }
4476
4368
  destroy() {
4477
4369
  this._tasks = [];
4478
4370
  this._taskIndex = 0;
4479
4371
  }
4480
- add(task) {
4372
+ start() {
4373
+ this._started = true;
4374
+ return this;
4375
+ }
4376
+ pause() {
4377
+ this._started = false;
4378
+ return this;
4379
+ }
4380
+ resume() {
4381
+ return this.start();
4382
+ }
4383
+ add(task, name) {
4384
+ if (typeof task === "function") {
4385
+ task = new Task(task, name);
4386
+ }
4481
4387
  this._tasks.push(task);
4388
+ return task;
4482
4389
  }
4483
4390
  update() {
4391
+ if (!this._started) return;
4484
4392
  let task = this._tasks[this._taskIndex];
4485
4393
  if (task) {
4486
4394
  try {
@@ -4501,69 +4409,20 @@ class TaskManager {
4501
4409
  }
4502
4410
  }
4503
4411
  }
4504
- constructor(onComplete, onProgress, onError){
4505
- this.onComplete = onComplete;
4506
- this.onProgress = onProgress;
4507
- this.onError = onError;
4412
+ constructor({ manual = false, onComplete, onProgress, onError } = {}){
4508
4413
  this._tasks = [];
4509
4414
  this._taskIndex = 0;
4510
4415
  this._onStartCalled = false;
4416
+ this._started = false;
4417
+ this._manual = false;
4418
+ this._manual = manual;
4419
+ this._started = !manual;
4420
+ this.onComplete = onComplete;
4421
+ this.onProgress = onProgress;
4422
+ this.onError = onError;
4511
4423
  }
4512
4424
  }
4513
4425
 
4514
- function checkWebGL(canvas, props) {
4515
- let isSupportedBrowser = (SystemInfo.isChrome || SystemInfo.isSafari || SystemInfo.isEdge || SystemInfo.isFirefox || SystemInfo.isOpera) && !SystemInfo.isIE;
4516
- if (!isSupportedBrowser) {
4517
- Logger.error("Unsupport platform");
4518
- return null;
4519
- }
4520
- if (!(canvas instanceof HTMLCanvasElement)) {
4521
- Logger.error("Canvas is null");
4522
- return null;
4523
- }
4524
- let webglOpts = Object.assign({
4525
- alpha: false,
4526
- depth: true,
4527
- stencil: true,
4528
- antialias: false,
4529
- premultipliedAlpha: true,
4530
- preserveDrawingBuffer: false,
4531
- powerPreference: "high-performance",
4532
- failIfMajorPerformanceCaveat: false
4533
- }, props);
4534
- if (window.WebGL2RenderingContext) {
4535
- try {
4536
- const gl = canvas.getContext("webgl2", webglOpts);
4537
- return {
4538
- gl,
4539
- RENDER_TARGET_FLOAT_TYPE: THREE.HalfFloatType,
4540
- DATA_FLOAT_TYPE: THREE.FloatType
4541
- };
4542
- } catch (err) {
4543
- Logger.error(err);
4544
- return null;
4545
- }
4546
- } else if (window.WebGLRenderingContext) {
4547
- const gl = canvas.getContext("webgl", webglOpts) || canvas.getContext("webgl2", webglOpts) || canvas.getContext("experimental-webgl", webglOpts);
4548
- if ((gl.getExtension("OES_texture_float") || gl.getExtension("OES_texture_half_float")) && gl.getParameter(gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS)) {
4549
- return {
4550
- gl,
4551
- RENDER_TARGET_FLOAT_TYPE: SystemInfo.isIOS || gl.getExtension("OES_texture_half_float") ? THREE.HalfFloatType : THREE.FloatType,
4552
- DATA_FLOAT_TYPE: THREE.FloatType
4553
- };
4554
- } else if (this._floatPacking) {
4555
- return {
4556
- gl,
4557
- RENDER_TARGET_FLOAT_TYPE: THREE.UnsignedByteType,
4558
- DATA_FLOAT_TYPE: THREE.UnsignedByteType
4559
- };
4560
- }
4561
- Logger.debug("Unspport float type in current platform");
4562
- return null;
4563
- }
4564
- return null;
4565
- }
4566
-
4567
4426
  var Orientation = /*#__PURE__*/ function(Orientation) {
4568
4427
  Orientation[Orientation["AUTO"] = 0] = "AUTO";
4569
4428
  Orientation[Orientation["LANDSCAPE"] = 1] = "LANDSCAPE";
@@ -4608,20 +4467,88 @@ class ResourceManager {
4608
4467
  get isComplete() {
4609
4468
  return this._loaded >= this._totalCount;
4610
4469
  }
4470
+ get started() {
4471
+ return this._started;
4472
+ }
4473
+ get manual() {
4474
+ return this._manual;
4475
+ }
4476
+ get loadingManager() {
4477
+ return this._loadingManager;
4478
+ }
4479
+ get ktx2Loader() {
4480
+ return this._ktx2Loader;
4481
+ }
4482
+ get dracoLoader() {
4483
+ return this._dracoLoader;
4484
+ }
4611
4485
  destroy() {
4612
4486
  this._loaders.clear();
4487
+ this._pendingAssets.length = 0;
4488
+ this._readyWaiters.length = 0;
4489
+ }
4490
+ start() {
4491
+ if (this._started) return this;
4492
+ this._started = true;
4493
+ this._flushPendingAssets();
4494
+ return this;
4495
+ }
4496
+ pause() {
4497
+ this._started = false;
4498
+ return this;
4499
+ }
4500
+ ready() {
4501
+ const total = this._totalCount;
4502
+ if (this._loaded >= total) {
4503
+ return Promise.resolve();
4504
+ }
4505
+ return new Promise((resolve)=>{
4506
+ this._readyWaiters.push({
4507
+ total,
4508
+ resolve
4509
+ });
4510
+ });
4613
4511
  }
4614
4512
  getLoader(ext) {
4615
4513
  return this._loaders.get(ext);
4616
4514
  }
4617
4515
  addLoader(Loader) {
4618
- let loader = new Loader(this._viewer);
4516
+ let loader = new Loader(this);
4619
4517
  for (let ext of loader.extension){
4620
4518
  this._loaders.set(ext, loader);
4621
4519
  }
4622
4520
  return loader;
4623
4521
  }
4624
- loadAsset({ url, ext, onProgress, ...props }) {
4522
+ load({ url, ext, onProgress, ...props }) {
4523
+ return new Promise((resolve, reject)=>{
4524
+ const fullUrl = url ? this._URL(url) : url;
4525
+ const assetProps = Object.assign({
4526
+ url: fullUrl,
4527
+ ext,
4528
+ onProgress
4529
+ }, this._resourceOptions, props);
4530
+ this._totalCount++;
4531
+ if (this._started) {
4532
+ this._load(assetProps).then(resolve).catch(reject);
4533
+ } else {
4534
+ this._pendingAssets.push({
4535
+ props: assetProps,
4536
+ resolve: resolve,
4537
+ reject
4538
+ });
4539
+ }
4540
+ });
4541
+ }
4542
+ get(url) {
4543
+ return this._resources.get(this._URL(url));
4544
+ }
4545
+ _flushPendingAssets() {
4546
+ const assets = this._pendingAssets.splice(0);
4547
+ for (const asset of assets){
4548
+ this._load(asset.props).then(asset.resolve).catch(asset.reject);
4549
+ }
4550
+ }
4551
+ _load({ url, ext, onProgress, ...props }) {
4625
4552
  return new Promise((resolve, reject)=>{
4626
4553
  const sel = ext || url && ResourceManager.extension(url) || "";
4627
4554
  const texSettings = ResourceManager._splitTextureSettings(props);
@@ -4634,28 +4561,56 @@ class ResourceManager {
4634
4561
  onLoad: (asset)=>{
4635
4562
  this._loaded++;
4636
4563
  this._resources.set(url, asset);
4564
+ this._checkReadyWaiters();
4637
4565
  resolve(asset);
4638
4566
  },
4639
4567
  onError: (err)=>{
4568
+ this._loaded++;
4569
+ this._checkReadyWaiters();
4640
4570
  console.error(`${url} not exist`, err);
4641
4571
  reject(err);
4642
4572
  }
4643
4573
  });
4644
- this._totalCount++;
4645
4574
  } else {
4646
- reject("ResourceManager.loadAsset: missing loader for " + sel);
4575
+ this._loaded++;
4576
+ this._checkReadyWaiters();
4577
+ reject("ResourceManager.load: missing loader for " + sel);
4647
4578
  }
4648
4579
  });
4649
4580
  }
4650
- getAsset(url) {
4651
- return this._resources.get(url);
4581
+ _checkReadyWaiters() {
4582
+ for(let i = this._readyWaiters.length; i--;){
4583
+ const waiter = this._readyWaiters[i];
4584
+ if (this._loaded >= waiter.total) {
4585
+ this._readyWaiters.splice(i, 1);
4586
+ waiter.resolve();
4587
+ }
4588
+ }
4652
4589
  }
4653
- constructor(viewer){
4590
+ constructor({ dracoPath, basisPath, loadingManager, renderer, path = "", resourcePath = "", URL = (url)=>url, manual = false }){
4654
4591
  this._loaders = new Map();
4655
4592
  this._resources = new Map();
4593
+ this._pendingAssets = [];
4594
+ this._readyWaiters = [];
4656
4595
  this._loaded = 0;
4657
4596
  this._totalCount = 0;
4658
- this._viewer = viewer;
4597
+ this._started = false;
4598
+ this._manual = false;
4599
+ this._manual = manual;
4600
+ this._started = !manual;
4601
+ this._resourceOptions = {
4602
+ path,
4603
+ resourcePath
4604
+ };
4605
+ this._URL = URL;
4606
+ this._loadingManager = loadingManager;
4607
+ this._dracoLoader = new DRACOLoader_js.DRACOLoader();
4608
+ this._dracoLoader.setDecoderPath(dracoPath);
4609
+ this._dracoLoader.manager = loadingManager;
4610
+ this._ktx2Loader = new KTX2Loader_js.KTX2Loader();
4611
+ this._ktx2Loader.setTranscoderPath(basisPath);
4612
+ this._ktx2Loader.detectSupport(renderer);
4613
+ this._ktx2Loader.manager = loadingManager;
4659
4614
  }
4660
4615
  }
4661
4616
  ResourceManager._texSettingKeys = [
@@ -4673,15 +4628,27 @@ ResourceManager._texSettingKeys = [
4673
4628
  "channel"
4674
4629
  ];
4675
4630
 
4676
- class Task {
4677
- constructor(excute, name){
4678
- this.instanceId = Task._instanceCount++;
4679
- this.name = "task" + this.instanceId;
4680
- this.excute = excute;
4681
- this.name = name || this.name;
4631
+ class STLLoader extends Loader {
4632
+ load({ url, buffer, path, resourcePath, onLoad, onProgress, onError }) {
4633
+ let loader = this._loader;
4634
+ if (loader === undefined) {
4635
+ loader = this._loader = new STLLoader_js.STLLoader();
4636
+ loader.manager = this.manager.loadingManager;
4637
+ }
4638
+ loader.setPath(path);
4639
+ loader.setResourcePath(resourcePath);
4640
+ if (buffer) {
4641
+ onLoad(loader.parse(buffer));
4642
+ } else {
4643
+ loader.load(url, onLoad, onProgress, onError);
4644
+ }
4645
+ }
4646
+ constructor(...args){
4647
+ super(...args), this.extension = [
4648
+ "stl"
4649
+ ];
4682
4650
  }
4683
4651
  }
4684
- Task._instanceCount = 0;
4685
4652
 
4686
4653
  const vert_Fullscreen = `
4687
4654
  varying vec2 v_uv;
@@ -4775,6 +4742,16 @@ void main() {
4775
4742
  gl_FragColor = color;
4776
4743
  }`;
4777
4744
  const EMPTY = {};
4745
+ const FRAME_TIME_EPSILON = 0.0005;
4746
+ const DefaultLoaders = [
4747
+ STLLoader,
4748
+ GLTFLoader,
4749
+ HDRLoader,
4750
+ TextureLoader,
4751
+ JSONLoader,
4752
+ SVGLoader,
4753
+ KTX2Loader
4754
+ ];
4778
4755
  class Viewer extends EventEmitter {
4779
4756
  get root() {
4780
4757
  return this._root;
@@ -4788,12 +4765,6 @@ class Viewer extends EventEmitter {
4788
4765
  get gl() {
4789
4766
  return this._gl;
4790
4767
  }
4791
- get RENDER_TARGET_FLOAT_TYPE() {
4792
- return this._RENDER_TARGET_FLOAT_TYPE;
4793
- }
4794
- get DATA_FLOAT_TYPE() {
4795
- return this._DATA_FLOAT_TYPE;
4796
- }
4797
4768
  get dpr() {
4798
4769
  return this._dpr;
4799
4770
  }
@@ -4812,17 +4783,31 @@ class Viewer extends EventEmitter {
4812
4783
  get input() {
4813
4784
  return this._input;
4814
4785
  }
4786
+ get mount() {
4787
+ return this._mount;
4788
+ }
4815
4789
  get targetFrameRate() {
4816
4790
  return this._targetFrameRate;
4817
4791
  }
4818
4792
  set targetFrameRate(v) {
4819
- this._targetFrameRate = Math.max(0.001, v);
4793
+ this._targetFrameRate = v < 0 ? -1 : Math.max(0.001, v);
4794
+ this._lastTime = this._time;
4795
+ this._lastFrameTime = this._time;
4820
4796
  }
4821
4797
  get instanceId() {
4822
4798
  return this._instanceId;
4823
4799
  }
4824
- get componentManager() {
4825
- return this._componentManager;
4800
+ get loading() {
4801
+ return this._loading;
4802
+ }
4803
+ get resources() {
4804
+ return this._resources;
4805
+ }
4806
+ get tasks() {
4807
+ return this._tasks;
4808
+ }
4809
+ get components() {
4810
+ return this._components;
4826
4811
  }
4827
4812
  get scene() {
4828
4813
  return this._scene;
@@ -4842,23 +4827,21 @@ class Viewer extends EventEmitter {
4842
4827
  destroy() {
4843
4828
  this.stop();
4844
4829
  this._renderer.dispose();
4845
- this._taskManager.destroy();
4846
- this._resourceManager.destroy();
4847
- this._componentManager.destroy();
4830
+ this._tasks.destroy();
4831
+ this._resources.destroy();
4832
+ this._components.destroy();
4848
4833
  }
4849
4834
  animate() {
4850
4835
  const loop = (dt)=>{
4851
4836
  if (!this._active) return;
4852
- this._componentManager.tick(dt);
4853
- if (this._resourceManager.isComplete) {
4854
- this._taskManager.update();
4855
- }
4856
- if (this._taskManager.isComplete) {
4837
+ this._components.tick(dt);
4838
+ this._tasks.update();
4839
+ if (this._components.started) {
4857
4840
  dt = Math.min(dt, 0.067);
4858
- this._componentManager.update(dt);
4841
+ this._components.update(dt);
4859
4842
  this._renderer.info.reset();
4860
4843
  if (!this._freeze) {
4861
- this._componentManager.render(dt);
4844
+ this._components.render(dt);
4862
4845
  }
4863
4846
  }
4864
4847
  };
@@ -4867,10 +4850,10 @@ class Viewer extends EventEmitter {
4867
4850
  if (this._targetFrameRate > -1) {
4868
4851
  const interval = 1 / this._targetFrameRate;
4869
4852
  const delta = this._time - this._lastFrameTime;
4870
- if (delta >= interval) {
4853
+ if (delta + FRAME_TIME_EPSILON >= interval) {
4871
4854
  loop(this._fixedFrameTime ? interval : this._time - this._lastTime);
4872
4855
  this._lastTime = this._time;
4873
- this._lastFrameTime = this._time - delta % interval;
4856
+ this._lastFrameTime = delta >= interval ? this._time - delta % interval : this._lastFrameTime + interval;
4874
4857
  }
4875
4858
  } else {
4876
4859
  loop(this._time - this._lastTime);
@@ -4965,38 +4948,7 @@ class Viewer extends EventEmitter {
4965
4948
  factor: width / w
4966
4949
  };
4967
4950
  }
4968
- this._componentManager.resize(width, height);
4969
- }
4970
- setURLModifier(callback) {
4971
- return this._loadingManager.setURLModifier(callback);
4972
- }
4973
- loadAsset({ url, ...props }) {
4974
- return this._resourceManager.loadAsset(Object.assign({
4975
- url: this._decodeURL(url)
4976
- }, this._resourceOptions, props));
4977
- }
4978
- getAsset(url) {
4979
- return this._resourceManager.getAsset(this._decodeURL(url));
4980
- }
4981
- getLoader(ext) {
4982
- return this._resourceManager.getLoader(ext);
4983
- }
4984
- addLoader(Loader) {
4985
- return this._resourceManager.addLoader(Loader);
4986
- }
4987
- getComponent(constructor, node) {
4988
- if (node) {
4989
- return this._componentManager.getComponent(node, constructor);
4990
- }
4991
- for (let child of this._mount.children){
4992
- let comp = this._componentManager.getComponent(child, constructor);
4993
- if (comp) return comp;
4994
- }
4995
- }
4996
- task(target) {
4997
- const excute = typeof target === "function" ? target : ()=>this.compile(target);
4998
- this._taskManager.add(new Task(excute));
4999
- return target;
4951
+ this._components.resize(width, height);
5000
4952
  }
5001
4953
  use(object, props) {
5002
4954
  let ins = getClassInstance(object);
@@ -5031,7 +4983,7 @@ class Viewer extends EventEmitter {
5031
4983
  node = new THREE.Object3D();
5032
4984
  mount = true;
5033
4985
  }
5034
- this._componentManager.addComponent(node, ins);
4986
+ this._components.add(node, ins);
5035
4987
  } else {
5036
4988
  throw Error("Unsuport object");
5037
4989
  }
@@ -5046,7 +4998,7 @@ class Viewer extends EventEmitter {
5046
4998
  component
5047
4999
  ];
5048
5000
  for (const comp of components){
5049
- this._componentManager.addComponent(node, comp);
5001
+ this._components.add(node, comp);
5050
5002
  }
5051
5003
  }
5052
5004
  if (children) {
@@ -5072,10 +5024,10 @@ class Viewer extends EventEmitter {
5072
5024
  }
5073
5025
  remove(ins) {
5074
5026
  if (ins instanceof THREE.Object3D) {
5075
- this._componentManager.destroyComponents(ins);
5027
+ this._components.destroy(ins);
5076
5028
  ins.removeFromParent();
5077
5029
  } else if (ins instanceof Component) {
5078
- this._componentManager.removeComponent(ins.node, ins);
5030
+ this._components.remove(ins.node, ins);
5079
5031
  } else {
5080
5032
  throw Error("remove invalid");
5081
5033
  }
@@ -5087,7 +5039,7 @@ class Viewer extends EventEmitter {
5087
5039
  wrapT: THREE.ClampToEdgeWrapping,
5088
5040
  magFilter: nearest ? THREE.NearestFilter : THREE.LinearFilter,
5089
5041
  minFilter: nearest ? THREE.NearestFilter : mipmap ? THREE.LinearMipMapLinearFilter : THREE.LinearFilter,
5090
- type: typeof floatType === "boolean" ? floatType ? this.DATA_FLOAT_TYPE : THREE.UnsignedByteType : floatType,
5042
+ type: typeof floatType === "boolean" ? floatType ? THREE.HalfFloatType : THREE.UnsignedByteType : floatType,
5091
5043
  anisotropy: 0,
5092
5044
  colorSpace: THREE.LinearSRGBColorSpace,
5093
5045
  depthBuffer: depth,
@@ -5102,7 +5054,7 @@ class Viewer extends EventEmitter {
5102
5054
  wrapT: THREE.ClampToEdgeWrapping,
5103
5055
  magFilter: nearest ? THREE.NearestFilter : THREE.LinearFilter,
5104
5056
  minFilter: nearest ? THREE.NearestFilter : mipmap ? THREE.LinearMipMapLinearFilter : THREE.LinearFilter,
5105
- type: typeof floatType === "boolean" ? floatType ? this.DATA_FLOAT_TYPE : THREE.UnsignedByteType : floatType,
5057
+ type: typeof floatType === "boolean" ? floatType ? THREE.HalfFloatType : THREE.UnsignedByteType : floatType,
5106
5058
  anisotropy: 0,
5107
5059
  colorSpace: THREE.LinearSRGBColorSpace,
5108
5060
  depthBuffer: depth,
@@ -5136,20 +5088,19 @@ class Viewer extends EventEmitter {
5136
5088
  }
5137
5089
  compile(target) {
5138
5090
  const { renderer, scene, camera } = this;
5139
- if (Array.isArray(target)) {
5140
- if (target.every((v)=>v.isMaterial)) {
5141
- Viewer.CompileMaterial(renderer, scene, camera, target);
5142
- } else {
5143
- throw Error("Viewer.compile: unsuport material");
5091
+ const compile = (v)=>{
5092
+ if (v.isMaterial) {
5093
+ Viewer.CompileMaterial(renderer, scene, camera, v);
5094
+ } else if (v.isObject3D) {
5095
+ Viewer.CompileObject3D(renderer, scene, camera, v);
5096
+ } else if (v.isTexture) {
5097
+ Viewer.CompileTexture(renderer, v);
5144
5098
  }
5099
+ };
5100
+ if (Array.isArray(target)) {
5101
+ target.forEach((v)=>compile(v));
5145
5102
  } else if (typeof target === "object") {
5146
- if (target.isMaterial) {
5147
- Viewer.CompileMaterial(renderer, scene, camera, target);
5148
- } else if (target.isObject3D) {
5149
- Viewer.CompileObject3D(renderer, scene, camera, target);
5150
- } else if (target.isTexture) {
5151
- Viewer.CompileTexture(renderer, target);
5152
- }
5103
+ compile(target);
5153
5104
  } else {
5154
5105
  Viewer.CompileObject3D(renderer, scene, camera, scene);
5155
5106
  }
@@ -5259,7 +5210,7 @@ class Viewer extends EventEmitter {
5259
5210
  near: 0.1,
5260
5211
  far: 1000,
5261
5212
  position: new THREE.Vector3(0, 0, 4)
5262
- }, targetFrameRate = -1, fixedFrameTime = false, colorSpace = THREE.SRGBColorSpace, toneMapping = THREE.LinearToneMapping, toneMappingExposure = 1, maxDPR = 1.5, path = "", resourcePath = "", dracoPath = "https://www.gstatic.com/draco/v1/decoders/", transcoderPath = "three/examples/js/libs/basis/", orientation = Orientation.AUTO, decodeURL = (url)=>url, loader = {}, tasker = {}, ...webglOpts } = EMPTY){
5213
+ }, targetFrameRate = -1, fixedFrameTime = false, colorSpace = THREE.SRGBColorSpace, toneMapping = THREE.LinearToneMapping, toneMappingExposure = 1, maxDPR = 1.5, path = "", resourcePath = "", dracoPath = "https://www.gstatic.com/draco/v1/decoders/", basisPath = "three/examples/js/libs/basis/", orientation = Orientation.AUTO, URL = (url)=>url, manual = false, resources = {}, tasks = {}, components = {}, ...webglOpts } = EMPTY){
5263
5214
  super(), this._instanceId = Viewer.instanceCount++, this._dpr = 1, this._width = 1, this._height = 1, this._viewport = {
5264
5215
  width: 1,
5265
5216
  height: 1,
@@ -5269,22 +5220,15 @@ class Viewer extends EventEmitter {
5269
5220
  window.innerHeight
5270
5221
  ], this._orientation = Orientation.AUTO, this._freeze = false;
5271
5222
  const el = canvas || document.getElementById("canvas");
5272
- const webgl = checkWebGL(el, webglOpts);
5273
- if (!webgl) {
5274
- throw Error("Unsupport WebGL in current platform");
5275
- }
5276
5223
  this._canvas = el;
5277
5224
  this._root = root || el;
5278
- this._gl = webgl.gl;
5279
- this._RENDER_TARGET_FLOAT_TYPE = webgl.RENDER_TARGET_FLOAT_TYPE;
5280
- this._DATA_FLOAT_TYPE = webgl.DATA_FLOAT_TYPE;
5281
5225
  this._dpr = Math.min(maxDPR, window.devicePixelRatio);
5282
5226
  this._orientation = orientation;
5283
5227
  this._scene = new THREE.Scene();
5284
5228
  this._camera = applyProps(orthographic ? new THREE.OrthographicCamera() : new THREE.PerspectiveCamera(), camera);
5285
5229
  this._renderer = new THREE.WebGLRenderer({
5286
5230
  canvas: el,
5287
- context: webgl.gl
5231
+ ...webglOpts
5288
5232
  });
5289
5233
  this._renderer.setPixelRatio(this._dpr);
5290
5234
  this._renderer.info.autoReset = false;
@@ -5294,37 +5238,50 @@ class Viewer extends EventEmitter {
5294
5238
  this._renderer.shadowMap.enabled = !!shadows;
5295
5239
  this._renderer.shadowMap.type = typeof shadows === "boolean" ? THREE.PCFSoftShadowMap : shadows;
5296
5240
  this._renderer.sortObjects = sortObjects;
5241
+ this._gl = this._renderer.getContext();
5297
5242
  this._context = {
5298
5243
  scene: this._scene,
5299
5244
  camera: this._camera
5300
5245
  };
5301
- this._targetFrameRate = targetFrameRate;
5246
+ this.targetFrameRate = targetFrameRate;
5302
5247
  this._windowSize = typeof resize === "function" ? resize : resize === ResizeMode.AUTO ? this._windowSize : null;
5303
- this._taskManager = new TaskManager(tasker.onComplete, tasker.onProgress, tasker.onError);
5304
- this._loadingManager = new THREE.LoadingManager(loader.onComplete, loader.onProgress, loader.onError);
5305
- this._resourceManager = new ResourceManager(this);
5306
- this._componentManager = new ComponentManager(this);
5307
- this._resourceOptions = {
5248
+ var _resources_manual;
5249
+ const resourcesManual = (_resources_manual = resources.manual) != null ? _resources_manual : manual;
5250
+ var _tasks_manual;
5251
+ const tasksManual = (_tasks_manual = tasks.manual) != null ? _tasks_manual : manual;
5252
+ var _components_manual;
5253
+ const componentsManual = (_components_manual = components.manual) != null ? _components_manual : manual;
5254
+ this._tasks = new TaskManager({
5255
+ manual: tasksManual,
5256
+ onComplete: tasks.onComplete,
5257
+ onProgress: tasks.onProgress,
5258
+ onError: tasks.onError
5259
+ });
5260
+ this._loading = new THREE.LoadingManager(resources.onComplete, resources.onProgress, resources.onError);
5261
+ this._resources = new ResourceManager({
5262
+ manual: resourcesManual,
5263
+ dracoPath,
5264
+ basisPath,
5265
+ renderer: this._renderer,
5266
+ loadingManager: this._loading,
5308
5267
  path,
5309
5268
  resourcePath,
5310
- dracoPath,
5311
- transcoderPath,
5312
- manager: this._loadingManager
5313
- };
5269
+ URL
5270
+ });
5271
+ var _resources_loaders;
5272
+ for (const Loader of (_resources_loaders = resources.loaders) != null ? _resources_loaders : DefaultLoaders){
5273
+ this._resources.addLoader(Loader);
5274
+ }
5275
+ this._components = new ComponentManager(this, {
5276
+ manual: componentsManual
5277
+ });
5314
5278
  this._mount = applyProps(new THREE.Object3D(), {
5315
5279
  name: "Mount"
5316
5280
  });
5317
5281
  this._input = this.add(new DeviceInput(input || {
5318
5282
  source: this._canvas
5319
5283
  }));
5320
- this._decodeURL = decodeURL;
5321
5284
  this.add(Renderer);
5322
- this.addLoader(GLTFLoader);
5323
- this.addLoader(HDRLoader);
5324
- this.addLoader(TextureLoader);
5325
- this.addLoader(JSONLoader);
5326
- this.addLoader(SVGLoader);
5327
- this.addLoader(KTX2Loader);
5328
5285
  this.rotate();
5329
5286
  this.resize();
5330
5287
  this.animate();
@@ -5887,6 +5844,7 @@ const defaultExtension = {
5887
5844
  "gltf": 0,
5888
5845
  "glb": 0,
5889
5846
  "buf": 0,
5847
+ "exr": 2,
5890
5848
  "hdr": 2,
5891
5849
  "png": 2,
5892
5850
  "jpg": 2,
@@ -5910,7 +5868,7 @@ class DropFile extends Component {
5910
5868
  if (files.length > 0) {
5911
5869
  filesMap = filesMap || createFilesMap(files);
5912
5870
  dirs = dirs || [];
5913
- this.viewer.setURLModifier((url)=>{
5871
+ this.viewer.loading.setURLModifier((url)=>{
5914
5872
  url = url.replace(/^(\.?\/)/, ''); // remove './'
5915
5873
  const file = filesMap[url];
5916
5874
  if (file) {
@@ -5941,12 +5899,12 @@ class DropFile extends Component {
5941
5899
  this._onError && this._onError(err);
5942
5900
  };
5943
5901
  const viewer = this.viewer;
5944
- const loadAsset = (props)=>{
5945
- return viewer.loadAsset(props).then(loadCallback).catch(errCallback);
5902
+ const load = (props)=>{
5903
+ return viewer.resources.load(props).then(loadCallback).catch(errCallback);
5946
5904
  };
5947
5905
  switch(this._extension[ext]){
5948
5906
  case 2:
5949
- reader.addEventListener("load", (event)=>loadAsset({
5907
+ reader.addEventListener("load", (event)=>load({
5950
5908
  ext,
5951
5909
  url: event.target.result
5952
5910
  }), false);
@@ -5960,7 +5918,7 @@ class DropFile extends Component {
5960
5918
  reader.readAsDataURL(file);
5961
5919
  break;
5962
5920
  case 0:
5963
- reader.addEventListener("load", (event)=>loadAsset({
5921
+ reader.addEventListener("load", (event)=>load({
5964
5922
  ext,
5965
5923
  buffer: event.target.result,
5966
5924
  resourcePath: dir
@@ -5996,6 +5954,7 @@ class DropFile extends Component {
5996
5954
  }
5997
5955
  }
5998
5956
  DropFile.Mode = Mode;
5957
+ DropFile.defaultExtension = defaultExtension;
5999
5958
  DropFile = __decorate([
6000
5959
  single()
6001
5960
  ], DropFile);
@@ -6588,6 +6547,7 @@ uniform float u_opacity;
6588
6547
  uniform vec3 u_strokeColor;
6589
6548
  uniform float u_strokeWidth;
6590
6549
  uniform vec3 u_shadowColor;
6550
+ uniform float u_shadowOpacity;
6591
6551
  uniform float u_shadowBlur;
6592
6552
  uniform vec2 u_shadowOffset;
6593
6553
  uniform float u_weight;
@@ -6602,23 +6562,32 @@ float signedDistance(in vec2 uv) {
6602
6562
  }
6603
6563
 
6604
6564
  void main() {
6605
- vec4 color = vec4(u_color, 1.);
6606
6565
  float d = signedDistance(v_uv) + u_weight;
6607
6566
  float w = fwidth(d);
6608
6567
 
6609
- vec4 stroke = vec4(u_strokeColor, smoothstep(-w, w, d));
6610
- color.a *= smoothstep(-w, w, d - u_strokeWidth);
6611
- color = mix(stroke, color, color.a);
6568
+ float outer = smoothstep(-w, w, d);
6569
+ float inner = smoothstep(-w, w, d - u_strokeWidth);
6570
+
6571
+ float stroke = step(0.0001, u_strokeWidth);
6572
+
6573
+ vec4 color = vec4(u_color, inner);
6574
+ color = mix(color, vec4(u_strokeColor, outer), stroke * (1.0 - inner));
6612
6575
 
6613
6576
  float sd = signedDistance(v_uv + u_shadowOffset) + u_weight;
6614
- vec4 shadow = vec4(u_shadowColor, smoothstep(-w - u_shadowBlur, w + u_shadowBlur, sd));
6577
+ float sw = fwidth(sd) + u_shadowBlur;
6578
+
6579
+ vec4 shadow = vec4(
6580
+ u_shadowColor,
6581
+ smoothstep(-sw, sw, sd) * u_shadowOpacity
6582
+ );
6583
+
6615
6584
  color = mix(shadow, color, color.a);
6616
6585
 
6617
6586
  color.a *= u_opacity;
6618
6587
  gl_FragColor = color;
6619
6588
 
6620
6589
  #include <tonemapping_fragment>
6621
- #include <colorspace_fragment>
6590
+ #include <colorspace_fragment>
6622
6591
  }
6623
6592
  `;
6624
6593
  class BMFontAtlas {
@@ -6706,13 +6675,16 @@ class BMFontAtlas {
6706
6675
  value: 0
6707
6676
  },
6708
6677
  u_shadowColor: {
6709
- value: new THREE.Color(0xffffff)
6678
+ value: new THREE.Color(0x606060)
6679
+ },
6680
+ u_shadowOpacity: {
6681
+ value: 0
6710
6682
  },
6711
6683
  u_shadowBlur: {
6712
6684
  value: 0
6713
6685
  },
6714
6686
  u_shadowOffset: {
6715
- value: new THREE.Vector2()
6687
+ value: new THREE.Vector2(0.01, 0)
6716
6688
  },
6717
6689
  u_fontTexture: {
6718
6690
  value: null
@@ -6737,7 +6709,6 @@ class BMFontAtlas {
6737
6709
  exports.AccumulativeShadows = AccumulativeShadows;
6738
6710
  exports.Animation = Animation;
6739
6711
  exports.AnimationCurve = AnimationCurve;
6740
- exports.BINLoader = BINLoader;
6741
6712
  exports.BMFontAtlas = BMFontAtlas;
6742
6713
  exports.BMFontTextGeometry = BMFontTextGeometry;
6743
6714
  exports.BMFontTextLayout = BMFontTextLayout;
@@ -6745,7 +6716,9 @@ exports.Box = Box;
6745
6716
  exports.BoxProjection = BoxProjection;
6746
6717
  exports.Center = Center;
6747
6718
  exports.Component = Component;
6719
+ exports.ComponentManager = ComponentManager;
6748
6720
  exports.ContactShadows = ContactShadows;
6721
+ exports.DefaultLoaders = DefaultLoaders;
6749
6722
  exports.DependentMode = DependentMode;
6750
6723
  exports.DeviceInput = DeviceInput;
6751
6724
  exports.DropFile = DropFile;
@@ -6789,6 +6762,7 @@ exports.ShadowMaterial = ShadowMaterial;
6789
6762
  exports.Sphere = Sphere;
6790
6763
  exports.SystemInfo = SystemInfo;
6791
6764
  exports.Task = Task;
6765
+ exports.TaskManager = TaskManager;
6792
6766
  exports.TextureLoader = TextureLoader;
6793
6767
  exports.VInterpConstantTo = VInterpConstantTo;
6794
6768
  exports.VInterpTo = VInterpTo;
@@ -6809,14 +6783,12 @@ exports.find = find;
6809
6783
  exports.frag_BoxfilterBlur = frag_BoxfilterBlur;
6810
6784
  exports.frag_cubeMapToPanorama = frag_cubeMapToPanorama;
6811
6785
  exports.frag_panoramaToCubeMap = frag_panoramaToCubeMap;
6812
- exports.getChildByName = getChildByName;
6813
6786
  exports.getChildren = getChildren;
6814
6787
  exports.getClassInstance = getClassInstance;
6815
6788
  exports.getShaderMaterial = getShaderMaterial;
6816
6789
  exports.mixin = mixin;
6817
6790
  exports.property = property;
6818
6791
  exports.quarticDamp = quarticDamp;
6819
- exports.queryValues = queryValues;
6820
6792
  exports.single = single;
6821
6793
  exports.smoothDamp = smoothDamp;
6822
6794
  exports.vert_fullscreen = vert_fullscreen;