@xviewer.js/core 1.0.5-alhpa.9 → 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/module.js CHANGED
@@ -1,14 +1,15 @@
1
1
  import { EXRLoader as EXRLoader$1 } from 'three/examples/jsm/loaders/EXRLoader.js';
2
2
  import { FBXLoader as FBXLoader$1 } from 'three/examples/jsm/loaders/FBXLoader.js';
3
3
  import { GLTFLoader as GLTFLoader$1 } from 'three/examples/jsm/loaders/GLTFLoader.js';
4
- import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader.js';
5
4
  import { MeshoptDecoder } from 'three/examples/jsm/libs/meshopt_decoder.module.js';
6
- import * as THREE from 'three';
7
- import { EquirectangularReflectionMapping, FileLoader, TextureLoader as TextureLoader$1, SRGBColorSpace, CubeUVReflectionMapping, Mesh, BoxGeometry, SphereGeometry, PlaneGeometry, MathUtils, Vector3, Vector2, LinearInterpolant, Object3D, Matrix4, Plane as Plane$1, Vector4, PerspectiveCamera, WebGLRenderTarget, LinearMipMapLinearFilter, LinearFilter, HalfFloatType, AnimationMixer, Color, OrthographicCamera, MeshDepthMaterial, ShaderMaterial, Euler, Group, REVISION, Box3, Sphere as Sphere$1, Raycaster, Quaternion, Spherical, UniformsUtils, NoBlending, AdditiveBlending, FloatType, UnsignedByteType, LinearSRGBColorSpace, NearestFilter, ClampToEdgeWrapping, WebGLCubeRenderTarget, DataTexture, RGBAFormat, UVMapping, BufferGeometry, Float32BufferAttribute, Scene, WebGLRenderer, LinearToneMapping, PCFSoftShadowMap, LoadingManager, PMREMGenerator, CubeCamera, ShaderLib, ShaderChunk, BufferAttribute, NormalBlending } from 'three';
8
5
  import { HDRLoader as HDRLoader$1 } from 'three/examples/jsm/loaders/HDRLoader.js';
6
+ import * as THREE from 'three';
7
+ import { FileLoader, TextureLoader as TextureLoader$1, SRGBColorSpace, Mesh, BoxGeometry, SphereGeometry, PlaneGeometry, MathUtils, Vector3, Vector2, LinearInterpolant, Object3D, Matrix4, Plane as Plane$1, Vector4, PerspectiveCamera, WebGLRenderTarget, LinearMipMapLinearFilter, LinearFilter, HalfFloatType, AnimationMixer, Color, OrthographicCamera, MeshDepthMaterial, ShaderMaterial, Euler, Group, REVISION, Box3, Sphere as Sphere$1, Raycaster, Quaternion, Spherical, UniformsUtils, NoBlending, AdditiveBlending, LinearSRGBColorSpace, UnsignedByteType, NearestFilter, ClampToEdgeWrapping, WebGLCubeRenderTarget, DataTexture, RGBAFormat, FloatType, UVMapping, BufferGeometry, Float32BufferAttribute, Scene, WebGLRenderer, LinearToneMapping, PCFSoftShadowMap, LoadingManager, PMREMGenerator, CubeCamera, ShaderLib, ShaderChunk, BufferAttribute, NormalBlending } from 'three';
9
8
  import { SVGLoader as SVGLoader$1 } from 'three/examples/jsm/loaders/SVGLoader.js';
10
- import { KTX2Loader as KTX2Loader$1 } from 'three/examples/jsm/loaders/KTX2Loader.js';
11
9
  import { HorizontalBlurShader, VerticalBlurShader } from 'three/examples/jsm/Addons.js';
10
+ import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader.js';
11
+ import { KTX2Loader as KTX2Loader$1 } from 'three/examples/jsm/loaders/KTX2Loader.js';
12
+ import { STLLoader as STLLoader$1 } from 'three/examples/jsm/loaders/STLLoader.js';
12
13
 
13
14
  class EventEmitter {
14
15
  _removeEvent(list, index, name) {
@@ -144,65 +145,18 @@ function getClassInstance(constructor, args = []) {
144
145
  }
145
146
 
146
147
  class Loader {
147
- static _setUserData(node) {
148
- const meshes = [];
149
- const textures = {};
150
- const materials = {};
151
- const queue = [
152
- node
153
- ];
154
- while(queue.length !== 0){
155
- let object = queue.shift();
156
- if (object.isMesh) {
157
- meshes.push(object);
158
- const mat = object.material;
159
- if (Array.isArray(mat)) mat.forEach((v)=>materials[v.uuid] = v);
160
- else materials[mat.uuid] = mat;
161
- }
162
- queue.push(...object.children);
163
- }
164
- Object.values(materials).forEach((mat)=>{
165
- Loader._texKeys.forEach((k)=>{
166
- let tex = mat[k];
167
- if (tex) {
168
- textures[tex.uuid] = tex;
169
- }
170
- });
171
- });
172
- Object.assign(node.userData, {
173
- meshes,
174
- textures: Object.values(textures),
175
- materials: Object.values(materials)
176
- });
177
- return node;
178
- }
179
- constructor(viewer){
180
- this.viewer = viewer;
181
- }
182
- }
183
- Loader._texKeys = [
184
- "map",
185
- "alphaMap",
186
- "aoMap",
187
- "bumpMap",
188
- "displacementMap",
189
- "emissiveMap",
190
- "envMap",
191
- "lightMap",
192
- "metalnessMap",
193
- "normalMap",
194
- "roughnessMap",
195
- "specularMap",
196
- "alphaMap"
197
- ];
148
+ constructor(manager){
149
+ this.manager = manager;
150
+ }
151
+ }
198
152
 
199
153
  class EXRLoader extends Loader {
200
- load({ url, path, resourcePath, manager, texSettings, onLoad, onProgress, onError }) {
154
+ load({ url, path, resourcePath, texSettings, onLoad, onProgress, onError }) {
201
155
  let loader = this._loader;
202
156
  if (loader === undefined) {
203
157
  loader = this._loader = new EXRLoader$1();
158
+ loader.manager = this.manager.loadingManager;
204
159
  }
205
- loader.manager = manager;
206
160
  loader.setPath(path);
207
161
  loader.setResourcePath(resourcePath);
208
162
  loader.load(url, (tex)=>onLoad(Object.assign(tex, texSettings)), onProgress, onError);
@@ -215,12 +169,12 @@ class EXRLoader extends Loader {
215
169
  }
216
170
 
217
171
  class FBXLoader extends Loader {
218
- load({ url, buffer, path, resourcePath, manager, onLoad, onProgress, onError }) {
172
+ load({ url, buffer, path, resourcePath, onLoad, onProgress, onError }) {
219
173
  let loader = this._loader;
220
174
  if (loader === undefined) {
221
175
  loader = this._loader = new FBXLoader$1();
176
+ loader.manager = this.manager.loadingManager;
222
177
  }
223
- loader.manager = manager;
224
178
  loader.setPath(path);
225
179
  loader.setResourcePath(resourcePath);
226
180
  if (buffer) {
@@ -237,20 +191,15 @@ class FBXLoader extends Loader {
237
191
  }
238
192
 
239
193
  class GLTFLoader extends Loader {
240
- load({ url, buffer, path, resourcePath, dracoPath, manager, onLoad, onProgress, onError }) {
241
- let dracoLoader = this._dracoLoader;
242
- if (dracoLoader === undefined) {
243
- dracoLoader = this._dracoLoader = new DRACOLoader();
244
- }
245
- dracoLoader.manager = manager;
246
- dracoLoader.setDecoderPath(dracoPath);
194
+ load({ url, buffer, path, resourcePath, onLoad, onProgress, onError }) {
247
195
  let loader = this._loader;
248
196
  if (loader === undefined) {
249
197
  loader = this._loader = new GLTFLoader$1();
250
- loader.setDRACOLoader(dracoLoader);
198
+ loader.manager = this.manager.loadingManager;
251
199
  loader.setMeshoptDecoder(MeshoptDecoder);
200
+ loader.setDRACOLoader(this.manager.dracoLoader);
201
+ loader.setKTX2Loader(this.manager.ktx2Loader);
252
202
  }
253
- loader.manager = manager;
254
203
  loader.setPath(path);
255
204
  loader.setResourcePath(resourcePath);
256
205
  const cb = (gltf)=>{
@@ -286,19 +235,15 @@ class GLTFLoader extends Loader {
286
235
  }
287
236
 
288
237
  class HDRLoader extends Loader {
289
- load({ url, path, resourcePath, manager, texSettings, onLoad, onProgress, onError }) {
238
+ load({ url, path, resourcePath, texSettings, onLoad, onProgress, onError }) {
290
239
  let loader = this._loader;
291
240
  if (loader === undefined) {
292
241
  loader = this._loader = new HDRLoader$1();
242
+ loader.manager = this.manager.loadingManager;
293
243
  }
294
- loader.manager = manager;
295
244
  loader.setPath(path);
296
245
  loader.setResourcePath(resourcePath);
297
- const loadCallback = (tex)=>{
298
- tex.mapping = EquirectangularReflectionMapping;
299
- onLoad(Object.assign(tex, texSettings));
300
- };
301
- loader.load(url, loadCallback, onProgress, onError);
246
+ loader.load(url, (tex)=>onLoad(Object.assign(tex, texSettings)), onProgress, onError);
302
247
  }
303
248
  constructor(...args){
304
249
  super(...args), this.extension = [
@@ -308,12 +253,12 @@ class HDRLoader extends Loader {
308
253
  }
309
254
 
310
255
  class JSONLoader extends Loader {
311
- load({ url, path, resourcePath, manager, onLoad, onProgress, onError }) {
256
+ load({ url, path, resourcePath, onLoad, onProgress, onError }) {
312
257
  let loader = this._loader;
313
258
  if (loader === undefined) {
314
259
  loader = this._loader = new FileLoader();
260
+ loader.manager = this.manager.loadingManager;
315
261
  }
316
- loader.manager = manager;
317
262
  loader.setPath(path);
318
263
  loader.setResourcePath(resourcePath);
319
264
  loader.load(url, (file)=>onLoad(JSON.parse(file)), onProgress, onError);
@@ -326,12 +271,12 @@ class JSONLoader extends Loader {
326
271
  }
327
272
 
328
273
  class TextureLoader extends Loader {
329
- load({ url, path, resourcePath, manager, texSettings, onLoad, onProgress, onError }) {
274
+ load({ url, path, resourcePath, texSettings, onLoad, onProgress, onError }) {
330
275
  let loader = this._loader;
331
276
  if (loader === undefined) {
332
277
  loader = this._loader = new TextureLoader$1();
278
+ loader.manager = this.manager.loadingManager;
333
279
  }
334
- loader.manager = manager;
335
280
  loader.setPath(path);
336
281
  loader.setResourcePath(resourcePath);
337
282
  const loadCallback = (tex)=>{
@@ -350,86 +295,13 @@ class TextureLoader extends Loader {
350
295
  }
351
296
  }
352
297
 
353
- class BINLoader extends Loader {
354
- load({ url, buffer, path, resourcePath, dracoPath, manager, onLoad, onProgress, onError }) {
355
- let dracoLoader = this._dracoLoader;
356
- if (dracoLoader === undefined) {
357
- dracoLoader = this._dracoLoader = new DRACOLoader();
358
- }
359
- dracoLoader.manager = manager;
360
- dracoLoader.setDecoderPath(dracoPath);
361
- let loader = this._loader;
362
- if (loader === undefined) {
363
- loader = this._loader = new CustomLoader();
364
- loader.setDRACOLoader(dracoLoader);
365
- loader.setMeshoptDecoder(MeshoptDecoder);
366
- }
367
- loader.salt = this.salt;
368
- loader.manager = manager;
369
- loader.setPath(path);
370
- loader.setResourcePath(resourcePath);
371
- if (buffer) {
372
- loader.parse(buffer, resourcePath, onLoad, onError);
373
- } else {
374
- loader.load(url, onLoad, onProgress, onError);
375
- }
376
- }
377
- constructor(...args){
378
- super(...args), this.extension = [
379
- "bin"
380
- ], this.salt = 255;
381
- }
382
- }
383
- class CustomLoader extends GLTFLoader$1 {
384
- parse(data, path, onLoad, onError) {
385
- super.parse(glbDecode(data, this.salt), path, onLoad, onError);
386
- }
387
- constructor(...args){
388
- super(...args), this.salt = 255;
389
- }
390
- }
391
- const BINARY_EXTENSION_HEADER_MAGIC = 'glTF';
392
- const BINARY_EXTENSION_HEADER_LENGTH = 12;
393
- function encryptArray(array, salt) {
394
- for(let i = 0, n = array.length; i < n; i++){
395
- array[i] ^= salt;
396
- }
397
- return array;
398
- }
399
- function glbDecode(buffer, salt = 255) {
400
- encryptArray(new Uint8Array(buffer, 0, 4), salt);
401
- const headerView = new DataView(buffer, 0, BINARY_EXTENSION_HEADER_LENGTH);
402
- const textDecoder = new TextDecoder();
403
- const header = {
404
- magic: textDecoder.decode(new Uint8Array(buffer.slice(0, 4))),
405
- version: headerView.getUint32(4, true),
406
- length: headerView.getUint32(8, true)
407
- };
408
- if (header.magic !== BINARY_EXTENSION_HEADER_MAGIC) {
409
- throw new Error('Unsupported glTF-Binary header.');
410
- } else if (header.version < 2.0) {
411
- throw new Error('Legacy binary file detected.');
412
- }
413
- const chunkContentsLength = header.length - BINARY_EXTENSION_HEADER_LENGTH;
414
- const chunkView = new DataView(buffer, BINARY_EXTENSION_HEADER_LENGTH);
415
- let chunkIndex = 0;
416
- while(chunkIndex < chunkContentsLength){
417
- const chunkLength = chunkView.getUint32(chunkIndex, true);
418
- chunkIndex += 4;
419
- encryptArray(new Uint8Array(buffer, BINARY_EXTENSION_HEADER_LENGTH + chunkIndex, chunkLength + 4), salt);
420
- chunkIndex += 4;
421
- chunkIndex += chunkLength;
422
- }
423
- return buffer;
424
- }
425
-
426
298
  class SVGLoader extends Loader {
427
- load({ url, path, resourcePath, manager, onLoad, onProgress, onError }) {
299
+ load({ url, path, resourcePath, onLoad, onProgress, onError }) {
428
300
  let loader = this._loader;
429
301
  if (loader === undefined) {
430
302
  loader = this._loader = new SVGLoader$1();
303
+ loader.manager = this.manager.loadingManager;
431
304
  }
432
- loader.manager = manager;
433
305
  loader.setPath(path);
434
306
  loader.setResourcePath(resourcePath);
435
307
  loader.load(url, onLoad, onProgress, onError);
@@ -443,21 +315,12 @@ class SVGLoader extends Loader {
443
315
  SVGLoader.Primitive = SVGLoader$1;
444
316
 
445
317
  class KTX2Loader extends Loader {
446
- load({ url, path, resourcePath, transcoderPath, manager, texSettings, onLoad, onProgress, onError }) {
447
- let loader = this._loader;
448
- if (loader === undefined) {
449
- loader = this._loader = new KTX2Loader$1();
450
- loader.setTranscoderPath(transcoderPath);
451
- loader.detectSupport(this.viewer.renderer);
452
- }
453
- loader.manager = manager;
318
+ load({ url, path, resourcePath, texSettings, onLoad, onProgress, onError }) {
319
+ const loader = this.manager.ktx2Loader;
454
320
  loader.setPath(path);
455
321
  loader.setResourcePath(resourcePath);
456
- const loadCallback = (tex)=>{
457
- tex.mapping = CubeUVReflectionMapping;
458
- onLoad(Object.assign(tex, texSettings));
459
- };
460
- loader.load(url, loadCallback, onProgress, onError);
322
+ loader.manager = this.manager.loadingManager;
323
+ loader.load(url, (tex)=>onLoad(Object.assign(tex, texSettings)), onProgress, onError);
461
324
  }
462
325
  constructor(...args){
463
326
  super(...args), this.extension = [
@@ -545,7 +408,7 @@ const Vector3_NEG_ONE = Object.freeze(new Vector3(-1, -1, -1));
545
408
 
546
409
  const { clamp: clamp$2 } = MathUtils;
547
410
  const { max, abs, acos } = Math;
548
- const EPSILON = 1.e-6;
411
+ const EPSILON = 1.e-8;
549
412
  const __deltaMap = new Map();
550
413
  __deltaMap.set(Vector3, new Vector3());
551
414
  __deltaMap.set(Vector2, new Vector2());
@@ -1292,7 +1155,7 @@ class Component extends ObjectInstance {
1292
1155
  }
1293
1156
  _onPreDestroy() {
1294
1157
  this.unscheduleAll();
1295
- this.manager.removeComponent(this.node, this);
1158
+ this.manager.remove(this.node, this);
1296
1159
  if (this._enabled) {
1297
1160
  this.manager.componentScheduler.enableComponent(this, false);
1298
1161
  }
@@ -1640,19 +1503,6 @@ function getChildren(node, filter, group = false) {
1640
1503
  }
1641
1504
  return objects[0];
1642
1505
  }
1643
- function getChildByName(node, name) {
1644
- return getChildren(node, (v)=>v && v.name === name);
1645
- }
1646
- const __emtpyObject = {};
1647
- function queryValues(object, name, group = false) {
1648
- if (name) {
1649
- if (group) {
1650
- return Object.values(object || __emtpyObject).filter((v)=>v.name === name);
1651
- }
1652
- return Object.values(object || __emtpyObject).find((v)=>v.name === name);
1653
- }
1654
- return Object.values(object);
1655
- }
1656
1506
 
1657
1507
  class ContactShadows extends Component {
1658
1508
  get visible() {
@@ -2330,6 +2180,12 @@ function single() {
2330
2180
  };
2331
2181
  }
2332
2182
  class ComponentManager {
2183
+ get started() {
2184
+ return this._started;
2185
+ }
2186
+ get manual() {
2187
+ return this._manual;
2188
+ }
2333
2189
  get viewer() {
2334
2190
  return this._viewer;
2335
2191
  }
@@ -2339,45 +2195,62 @@ class ComponentManager {
2339
2195
  get componentScheduler() {
2340
2196
  return this._componentScheduler;
2341
2197
  }
2342
- destroy() {
2343
- this._componentsMap.forEach((components)=>components.forEach((comp)=>comp.destroy()));
2344
- this._componentsMap.clear();
2198
+ destroy(node) {
2199
+ if (node) {
2200
+ let components = this._componentsMap.get(node);
2201
+ if (components) {
2202
+ components.forEach((comp)=>comp.destroy());
2203
+ this._componentsMap.delete(node);
2204
+ }
2205
+ for (let child of node.children){
2206
+ this.destroy(child);
2207
+ }
2208
+ } else {
2209
+ this._componentsMap.forEach((components)=>components.forEach((comp)=>comp.destroy()));
2210
+ this._componentsMap.clear();
2211
+ }
2345
2212
  }
2346
2213
  tick(dt) {
2347
2214
  this._componentScheduler.tick(dt);
2348
2215
  }
2349
2216
  update(dt) {
2217
+ if (!this._started) return;
2350
2218
  this._scheduler.update(dt);
2351
2219
  this._componentScheduler.start();
2352
2220
  this._componentScheduler.update(dt);
2353
2221
  this._componentScheduler.lastUpdate(dt);
2354
2222
  }
2355
2223
  render(dt) {
2224
+ if (!this._started) return;
2356
2225
  this._componentScheduler.render(dt);
2357
2226
  }
2358
2227
  resize(width, height) {
2359
2228
  this.componentScheduler.resize(width, height);
2360
2229
  }
2361
- destroyComponents(node) {
2362
- let components = this._componentsMap.get(node);
2363
- if (components) {
2364
- components.forEach((comp)=>comp.destroy());
2365
- this._componentsMap.delete(node);
2366
- }
2367
- for (let child of node.children){
2368
- this.destroyComponents(child);
2369
- }
2230
+ start() {
2231
+ this._started = true;
2232
+ return this;
2233
+ }
2234
+ pause() {
2235
+ this._started = false;
2236
+ return this;
2237
+ }
2238
+ resume() {
2239
+ return this.start();
2370
2240
  }
2371
- activeComponents(node) {
2241
+ stop() {
2242
+ return this.pause();
2243
+ }
2244
+ active(node) {
2372
2245
  let components = this._componentsMap.get(node);
2373
2246
  if (components) {
2374
2247
  components.forEach((comp)=>this._activeComponent(comp, node.visible));
2375
2248
  }
2376
2249
  for (let child of node.children){
2377
- this.activeComponents(child);
2250
+ this.active(child);
2378
2251
  }
2379
2252
  }
2380
- addComponent(node, constructor) {
2253
+ add(node, constructor) {
2381
2254
  let root = node instanceof Component ? node.node : node;
2382
2255
  let func = typeof constructor === "function";
2383
2256
  const proto = func ? constructor : constructor.constructor;
@@ -2407,26 +2280,26 @@ class ComponentManager {
2407
2280
  throw Error("Add multiple components");
2408
2281
  }
2409
2282
  }
2410
- removeComponent(node, component) {
2283
+ remove(node, component) {
2411
2284
  let components = this._componentsMap.get(node);
2412
2285
  if (components) {
2413
2286
  components.splice(components.indexOf(component), 1);
2414
2287
  }
2415
2288
  return this;
2416
2289
  }
2417
- getComponent(node, constructor) {
2290
+ get(node, constructor) {
2418
2291
  return this._findComponent(node, constructor);
2419
2292
  }
2420
- getComponentInChildren(node, constructor) {
2293
+ getInChildren(node, constructor) {
2421
2294
  let comp = this._findComponent(node, constructor);
2422
2295
  if (comp) return comp;
2423
2296
  for (let child of node.children){
2424
- if (comp = this.getComponentInChildren(child, constructor)) {
2297
+ if (comp = this.getInChildren(child, constructor)) {
2425
2298
  return comp;
2426
2299
  }
2427
2300
  }
2428
2301
  }
2429
- getComponentsInChidren(node, constructor, out = []) {
2302
+ getAllInChildren(node, constructor, out = []) {
2430
2303
  let components = this._componentsMap.get(node);
2431
2304
  if (components) {
2432
2305
  for(let i = components.length; i--;){
@@ -2434,11 +2307,11 @@ class ComponentManager {
2434
2307
  }
2435
2308
  }
2436
2309
  for (let child of node.children){
2437
- this.getComponentsInChidren(child, constructor, out);
2310
+ this.getAllInChildren(child, constructor, out);
2438
2311
  }
2439
2312
  return out;
2440
2313
  }
2441
- traverseComponents(callback) {
2314
+ traverse(callback) {
2442
2315
  this._componentsMap.forEach((v)=>v.forEach(callback));
2443
2316
  }
2444
2317
  _addDendencies(node, constructor) {
@@ -2447,9 +2320,9 @@ class ComponentManager {
2447
2320
  if (info) {
2448
2321
  const { components = [], mode } = info;
2449
2322
  for (const dep of components){
2450
- if (!this.getComponent(node, dep)) {
2323
+ if (!this.get(node, dep)) {
2451
2324
  if (mode === 1) {
2452
- this.addComponent(node, dep);
2325
+ this.add(node, dep);
2453
2326
  } else {
2454
2327
  throw `Should add ${dep.name} before adding ${constructor.name}`;
2455
2328
  }
@@ -2473,11 +2346,15 @@ class ComponentManager {
2473
2346
  _activeComponent(comp, active) {
2474
2347
  this._componentScheduler.enableComponent(comp, active);
2475
2348
  }
2476
- constructor(viewer){
2349
+ constructor(viewer, { manual = false } = {}){
2477
2350
  this._scheduler = new Scheduler();
2478
2351
  this._componentScheduler = new ComponentScheduler();
2479
2352
  this._componentsMap = new Map();
2353
+ this._started = false;
2354
+ this._manual = false;
2480
2355
  this._viewer = viewer;
2356
+ this._manual = manual;
2357
+ this._started = !manual;
2481
2358
  }
2482
2359
  }
2483
2360
  ComponentManager._infoMap = new Map();
@@ -2922,15 +2799,15 @@ class DeviceInput extends Component {
2922
2799
  this.viewer.emit(DeviceInput.TOUCH_MOVE, ex);
2923
2800
  }
2924
2801
  _onKeyDown(e) {
2925
- this._keys[e.key] = true;
2802
+ this._keys[e.code] = true;
2926
2803
  this.viewer.emit(DeviceInput.KEYDOWN, e);
2927
2804
  }
2928
2805
  _onKeyPress(e) {
2929
- this._keys[e.key] = true;
2806
+ this._keys[e.code] = true;
2930
2807
  this.viewer.emit(DeviceInput.KEYPRESS, e);
2931
2808
  }
2932
2809
  _onKeyUp(e) {
2933
- this._keys[e.key] = false;
2810
+ this._keys[e.code] = false;
2934
2811
  this.viewer.emit(DeviceInput.KEYUP, e);
2935
2812
  }
2936
2813
  constructor(option){
@@ -3346,15 +3223,15 @@ class FreelookVirtualCamera extends Component {
3346
3223
  return out;
3347
3224
  }
3348
3225
  _calculateLookAtOffset(panDelta, out = new Vector3()) {
3349
- const { xAxis, yAxis, posDelta } = FreelookVirtualCamera;
3226
+ const { xAxis, yAxis } = FreelookVirtualCamera;
3227
+ this.node.updateMatrix();
3350
3228
  xAxis.setFromMatrixColumn(this.node.matrix, 0);
3351
3229
  yAxis.setFromMatrixColumn(this.node.matrix, 1);
3352
3230
  if (this.forbitAll || this.forbitPanOffsetY) {
3353
3231
  yAxis.y = 0;
3354
3232
  yAxis.normalize();
3355
3233
  }
3356
- posDelta.copy(this.node.position).sub(this.lookAt);
3357
- const length = posDelta.length() * 2 * tan(degToRad(this.fov * 0.5));
3234
+ const length = this._spherical.radius * 2 * tan(degToRad(this.fov * 0.5));
3358
3235
  return out.set(0, 0, 0).sub(xAxis.multiplyScalar(panDelta.x * length)).add(yAxis.multiplyScalar(panDelta.y * length));
3359
3236
  }
3360
3237
  _setTargetLookAt(panDelta) {
@@ -3495,7 +3372,6 @@ FreelookVirtualCamera.center = new Vector2();
3495
3372
  FreelookVirtualCamera.preCenter = new Vector2();
3496
3373
  FreelookVirtualCamera.panDelta = new Vector2();
3497
3374
  FreelookVirtualCamera.rotateDelta = new Vector2();
3498
- FreelookVirtualCamera.posDelta = new Vector3();
3499
3375
  FreelookVirtualCamera.lookAtOffset = new Vector3();
3500
3376
  FreelookVirtualCamera.xAxis = new Vector3();
3501
3377
  FreelookVirtualCamera.yAxis = new Vector3();
@@ -4449,18 +4325,50 @@ function _getMipBlurMaterial(lodMax, width, height) {
4449
4325
  });
4450
4326
  }
4451
4327
 
4328
+ class Task {
4329
+ constructor(excute, name){
4330
+ this.instanceId = Task._instanceCount++;
4331
+ this.name = "task" + this.instanceId;
4332
+ this.excute = excute;
4333
+ this.name = name || this.name;
4334
+ }
4335
+ }
4336
+ Task._instanceCount = 0;
4337
+
4452
4338
  class TaskManager {
4453
4339
  get isComplete() {
4454
4340
  return this._taskIndex >= this._tasks.length;
4455
4341
  }
4342
+ get started() {
4343
+ return this._started;
4344
+ }
4345
+ get manual() {
4346
+ return this._manual;
4347
+ }
4456
4348
  destroy() {
4457
4349
  this._tasks = [];
4458
4350
  this._taskIndex = 0;
4459
4351
  }
4460
- add(task) {
4352
+ start() {
4353
+ this._started = true;
4354
+ return this;
4355
+ }
4356
+ pause() {
4357
+ this._started = false;
4358
+ return this;
4359
+ }
4360
+ resume() {
4361
+ return this.start();
4362
+ }
4363
+ add(task, name) {
4364
+ if (typeof task === "function") {
4365
+ task = new Task(task, name);
4366
+ }
4461
4367
  this._tasks.push(task);
4368
+ return task;
4462
4369
  }
4463
4370
  update() {
4371
+ if (!this._started) return;
4464
4372
  let task = this._tasks[this._taskIndex];
4465
4373
  if (task) {
4466
4374
  try {
@@ -4481,69 +4389,20 @@ class TaskManager {
4481
4389
  }
4482
4390
  }
4483
4391
  }
4484
- constructor(onComplete, onProgress, onError){
4485
- this.onComplete = onComplete;
4486
- this.onProgress = onProgress;
4487
- this.onError = onError;
4392
+ constructor({ manual = false, onComplete, onProgress, onError } = {}){
4488
4393
  this._tasks = [];
4489
4394
  this._taskIndex = 0;
4490
4395
  this._onStartCalled = false;
4396
+ this._started = false;
4397
+ this._manual = false;
4398
+ this._manual = manual;
4399
+ this._started = !manual;
4400
+ this.onComplete = onComplete;
4401
+ this.onProgress = onProgress;
4402
+ this.onError = onError;
4491
4403
  }
4492
4404
  }
4493
4405
 
4494
- function checkWebGL(canvas, props) {
4495
- let isSupportedBrowser = (SystemInfo.isChrome || SystemInfo.isSafari || SystemInfo.isEdge || SystemInfo.isFirefox || SystemInfo.isOpera) && !SystemInfo.isIE;
4496
- if (!isSupportedBrowser) {
4497
- Logger.error("Unsupport platform");
4498
- return null;
4499
- }
4500
- if (!(canvas instanceof HTMLCanvasElement)) {
4501
- Logger.error("Canvas is null");
4502
- return null;
4503
- }
4504
- let webglOpts = Object.assign({
4505
- alpha: false,
4506
- depth: true,
4507
- stencil: true,
4508
- antialias: false,
4509
- premultipliedAlpha: true,
4510
- preserveDrawingBuffer: false,
4511
- powerPreference: "high-performance",
4512
- failIfMajorPerformanceCaveat: false
4513
- }, props);
4514
- if (window.WebGL2RenderingContext) {
4515
- try {
4516
- const gl = canvas.getContext("webgl2", webglOpts);
4517
- return {
4518
- gl,
4519
- RENDER_TARGET_FLOAT_TYPE: HalfFloatType,
4520
- DATA_FLOAT_TYPE: FloatType
4521
- };
4522
- } catch (err) {
4523
- Logger.error(err);
4524
- return null;
4525
- }
4526
- } else if (window.WebGLRenderingContext) {
4527
- const gl = canvas.getContext("webgl", webglOpts) || canvas.getContext("webgl2", webglOpts) || canvas.getContext("experimental-webgl", webglOpts);
4528
- if ((gl.getExtension("OES_texture_float") || gl.getExtension("OES_texture_half_float")) && gl.getParameter(gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS)) {
4529
- return {
4530
- gl,
4531
- RENDER_TARGET_FLOAT_TYPE: SystemInfo.isIOS || gl.getExtension("OES_texture_half_float") ? HalfFloatType : FloatType,
4532
- DATA_FLOAT_TYPE: FloatType
4533
- };
4534
- } else if (this._floatPacking) {
4535
- return {
4536
- gl,
4537
- RENDER_TARGET_FLOAT_TYPE: UnsignedByteType,
4538
- DATA_FLOAT_TYPE: UnsignedByteType
4539
- };
4540
- }
4541
- Logger.debug("Unspport float type in current platform");
4542
- return null;
4543
- }
4544
- return null;
4545
- }
4546
-
4547
4406
  var Orientation = /*#__PURE__*/ function(Orientation) {
4548
4407
  Orientation[Orientation["AUTO"] = 0] = "AUTO";
4549
4408
  Orientation[Orientation["LANDSCAPE"] = 1] = "LANDSCAPE";
@@ -4588,20 +4447,88 @@ class ResourceManager {
4588
4447
  get isComplete() {
4589
4448
  return this._loaded >= this._totalCount;
4590
4449
  }
4450
+ get started() {
4451
+ return this._started;
4452
+ }
4453
+ get manual() {
4454
+ return this._manual;
4455
+ }
4456
+ get loadingManager() {
4457
+ return this._loadingManager;
4458
+ }
4459
+ get ktx2Loader() {
4460
+ return this._ktx2Loader;
4461
+ }
4462
+ get dracoLoader() {
4463
+ return this._dracoLoader;
4464
+ }
4591
4465
  destroy() {
4592
4466
  this._loaders.clear();
4467
+ this._pendingAssets.length = 0;
4468
+ this._readyWaiters.length = 0;
4469
+ }
4470
+ start() {
4471
+ if (this._started) return this;
4472
+ this._started = true;
4473
+ this._flushPendingAssets();
4474
+ return this;
4475
+ }
4476
+ pause() {
4477
+ this._started = false;
4478
+ return this;
4479
+ }
4480
+ ready() {
4481
+ const total = this._totalCount;
4482
+ if (this._loaded >= total) {
4483
+ return Promise.resolve();
4484
+ }
4485
+ return new Promise((resolve)=>{
4486
+ this._readyWaiters.push({
4487
+ total,
4488
+ resolve
4489
+ });
4490
+ });
4593
4491
  }
4594
4492
  getLoader(ext) {
4595
4493
  return this._loaders.get(ext);
4596
4494
  }
4597
4495
  addLoader(Loader) {
4598
- let loader = new Loader(this._viewer);
4496
+ let loader = new Loader(this);
4599
4497
  for (let ext of loader.extension){
4600
4498
  this._loaders.set(ext, loader);
4601
4499
  }
4602
4500
  return loader;
4603
4501
  }
4604
- loadAsset({ url, ext, onProgress, ...props }) {
4502
+ load({ url, ext, onProgress, ...props }) {
4503
+ return new Promise((resolve, reject)=>{
4504
+ const fullUrl = url ? this._URL(url) : url;
4505
+ const assetProps = Object.assign({
4506
+ url: fullUrl,
4507
+ ext,
4508
+ onProgress
4509
+ }, this._resourceOptions, props);
4510
+ this._totalCount++;
4511
+ if (this._started) {
4512
+ this._load(assetProps).then(resolve).catch(reject);
4513
+ } else {
4514
+ this._pendingAssets.push({
4515
+ props: assetProps,
4516
+ resolve: resolve,
4517
+ reject
4518
+ });
4519
+ }
4520
+ });
4521
+ }
4522
+ get(url) {
4523
+ return this._resources.get(this._URL(url));
4524
+ }
4525
+ _flushPendingAssets() {
4526
+ const assets = this._pendingAssets.splice(0);
4527
+ for (const asset of assets){
4528
+ this._load(asset.props).then(asset.resolve).catch(asset.reject);
4529
+ }
4530
+ }
4531
+ _load({ url, ext, onProgress, ...props }) {
4605
4532
  return new Promise((resolve, reject)=>{
4606
4533
  const sel = ext || url && ResourceManager.extension(url) || "";
4607
4534
  const texSettings = ResourceManager._splitTextureSettings(props);
@@ -4614,28 +4541,56 @@ class ResourceManager {
4614
4541
  onLoad: (asset)=>{
4615
4542
  this._loaded++;
4616
4543
  this._resources.set(url, asset);
4544
+ this._checkReadyWaiters();
4617
4545
  resolve(asset);
4618
4546
  },
4619
4547
  onError: (err)=>{
4548
+ this._loaded++;
4549
+ this._checkReadyWaiters();
4620
4550
  console.error(`${url} not exist`, err);
4621
4551
  reject(err);
4622
4552
  }
4623
4553
  });
4624
- this._totalCount++;
4625
4554
  } else {
4626
- reject("ResourceManager.loadAsset: missing loader for " + sel);
4555
+ this._loaded++;
4556
+ this._checkReadyWaiters();
4557
+ reject("ResourceManager.load: missing loader for " + sel);
4627
4558
  }
4628
4559
  });
4629
4560
  }
4630
- getAsset(url) {
4631
- return this._resources.get(url);
4561
+ _checkReadyWaiters() {
4562
+ for(let i = this._readyWaiters.length; i--;){
4563
+ const waiter = this._readyWaiters[i];
4564
+ if (this._loaded >= waiter.total) {
4565
+ this._readyWaiters.splice(i, 1);
4566
+ waiter.resolve();
4567
+ }
4568
+ }
4632
4569
  }
4633
- constructor(viewer){
4570
+ constructor({ dracoPath, basisPath, loadingManager, renderer, path = "", resourcePath = "", URL = (url)=>url, manual = false }){
4634
4571
  this._loaders = new Map();
4635
4572
  this._resources = new Map();
4573
+ this._pendingAssets = [];
4574
+ this._readyWaiters = [];
4636
4575
  this._loaded = 0;
4637
4576
  this._totalCount = 0;
4638
- this._viewer = viewer;
4577
+ this._started = false;
4578
+ this._manual = false;
4579
+ this._manual = manual;
4580
+ this._started = !manual;
4581
+ this._resourceOptions = {
4582
+ path,
4583
+ resourcePath
4584
+ };
4585
+ this._URL = URL;
4586
+ this._loadingManager = loadingManager;
4587
+ this._dracoLoader = new DRACOLoader();
4588
+ this._dracoLoader.setDecoderPath(dracoPath);
4589
+ this._dracoLoader.manager = loadingManager;
4590
+ this._ktx2Loader = new KTX2Loader$1();
4591
+ this._ktx2Loader.setTranscoderPath(basisPath);
4592
+ this._ktx2Loader.detectSupport(renderer);
4593
+ this._ktx2Loader.manager = loadingManager;
4639
4594
  }
4640
4595
  }
4641
4596
  ResourceManager._texSettingKeys = [
@@ -4653,15 +4608,27 @@ ResourceManager._texSettingKeys = [
4653
4608
  "channel"
4654
4609
  ];
4655
4610
 
4656
- class Task {
4657
- constructor(excute, name){
4658
- this.instanceId = Task._instanceCount++;
4659
- this.name = "task" + this.instanceId;
4660
- this.excute = excute;
4661
- this.name = name || this.name;
4611
+ class STLLoader extends Loader {
4612
+ load({ url, buffer, path, resourcePath, onLoad, onProgress, onError }) {
4613
+ let loader = this._loader;
4614
+ if (loader === undefined) {
4615
+ loader = this._loader = new STLLoader$1();
4616
+ loader.manager = this.manager.loadingManager;
4617
+ }
4618
+ loader.setPath(path);
4619
+ loader.setResourcePath(resourcePath);
4620
+ if (buffer) {
4621
+ onLoad(loader.parse(buffer));
4622
+ } else {
4623
+ loader.load(url, onLoad, onProgress, onError);
4624
+ }
4625
+ }
4626
+ constructor(...args){
4627
+ super(...args), this.extension = [
4628
+ "stl"
4629
+ ];
4662
4630
  }
4663
4631
  }
4664
- Task._instanceCount = 0;
4665
4632
 
4666
4633
  const vert_Fullscreen = `
4667
4634
  varying vec2 v_uv;
@@ -4755,6 +4722,16 @@ void main() {
4755
4722
  gl_FragColor = color;
4756
4723
  }`;
4757
4724
  const EMPTY = {};
4725
+ const FRAME_TIME_EPSILON = 0.0005;
4726
+ const DefaultLoaders = [
4727
+ STLLoader,
4728
+ GLTFLoader,
4729
+ HDRLoader,
4730
+ TextureLoader,
4731
+ JSONLoader,
4732
+ SVGLoader,
4733
+ KTX2Loader
4734
+ ];
4758
4735
  class Viewer extends EventEmitter {
4759
4736
  get root() {
4760
4737
  return this._root;
@@ -4768,12 +4745,6 @@ class Viewer extends EventEmitter {
4768
4745
  get gl() {
4769
4746
  return this._gl;
4770
4747
  }
4771
- get RENDER_TARGET_FLOAT_TYPE() {
4772
- return this._RENDER_TARGET_FLOAT_TYPE;
4773
- }
4774
- get DATA_FLOAT_TYPE() {
4775
- return this._DATA_FLOAT_TYPE;
4776
- }
4777
4748
  get dpr() {
4778
4749
  return this._dpr;
4779
4750
  }
@@ -4792,17 +4763,31 @@ class Viewer extends EventEmitter {
4792
4763
  get input() {
4793
4764
  return this._input;
4794
4765
  }
4766
+ get mount() {
4767
+ return this._mount;
4768
+ }
4795
4769
  get targetFrameRate() {
4796
4770
  return this._targetFrameRate;
4797
4771
  }
4798
4772
  set targetFrameRate(v) {
4799
- this._targetFrameRate = Math.max(0.001, v);
4773
+ this._targetFrameRate = v < 0 ? -1 : Math.max(0.001, v);
4774
+ this._lastTime = this._time;
4775
+ this._lastFrameTime = this._time;
4800
4776
  }
4801
4777
  get instanceId() {
4802
4778
  return this._instanceId;
4803
4779
  }
4804
- get componentManager() {
4805
- return this._componentManager;
4780
+ get loading() {
4781
+ return this._loading;
4782
+ }
4783
+ get resources() {
4784
+ return this._resources;
4785
+ }
4786
+ get tasks() {
4787
+ return this._tasks;
4788
+ }
4789
+ get components() {
4790
+ return this._components;
4806
4791
  }
4807
4792
  get scene() {
4808
4793
  return this._scene;
@@ -4822,23 +4807,21 @@ class Viewer extends EventEmitter {
4822
4807
  destroy() {
4823
4808
  this.stop();
4824
4809
  this._renderer.dispose();
4825
- this._taskManager.destroy();
4826
- this._resourceManager.destroy();
4827
- this._componentManager.destroy();
4810
+ this._tasks.destroy();
4811
+ this._resources.destroy();
4812
+ this._components.destroy();
4828
4813
  }
4829
4814
  animate() {
4830
4815
  const loop = (dt)=>{
4831
4816
  if (!this._active) return;
4832
- this._componentManager.tick(dt);
4833
- if (this._resourceManager.isComplete) {
4834
- this._taskManager.update();
4835
- }
4836
- if (this._taskManager.isComplete) {
4817
+ this._components.tick(dt);
4818
+ this._tasks.update();
4819
+ if (this._components.started) {
4837
4820
  dt = Math.min(dt, 0.067);
4838
- this._componentManager.update(dt);
4821
+ this._components.update(dt);
4839
4822
  this._renderer.info.reset();
4840
4823
  if (!this._freeze) {
4841
- this._componentManager.render(dt);
4824
+ this._components.render(dt);
4842
4825
  }
4843
4826
  }
4844
4827
  };
@@ -4847,10 +4830,10 @@ class Viewer extends EventEmitter {
4847
4830
  if (this._targetFrameRate > -1) {
4848
4831
  const interval = 1 / this._targetFrameRate;
4849
4832
  const delta = this._time - this._lastFrameTime;
4850
- if (delta >= interval) {
4833
+ if (delta + FRAME_TIME_EPSILON >= interval) {
4851
4834
  loop(this._fixedFrameTime ? interval : this._time - this._lastTime);
4852
4835
  this._lastTime = this._time;
4853
- this._lastFrameTime = this._time - delta % interval;
4836
+ this._lastFrameTime = delta >= interval ? this._time - delta % interval : this._lastFrameTime + interval;
4854
4837
  }
4855
4838
  } else {
4856
4839
  loop(this._time - this._lastTime);
@@ -4945,38 +4928,7 @@ class Viewer extends EventEmitter {
4945
4928
  factor: width / w
4946
4929
  };
4947
4930
  }
4948
- this._componentManager.resize(width, height);
4949
- }
4950
- setURLModifier(callback) {
4951
- return this._loadingManager.setURLModifier(callback);
4952
- }
4953
- loadAsset({ url, ...props }) {
4954
- return this._resourceManager.loadAsset(Object.assign({
4955
- url: this._decodeURL(url)
4956
- }, this._resourceOptions, props));
4957
- }
4958
- getAsset(url) {
4959
- return this._resourceManager.getAsset(this._decodeURL(url));
4960
- }
4961
- getLoader(ext) {
4962
- return this._resourceManager.getLoader(ext);
4963
- }
4964
- addLoader(Loader) {
4965
- return this._resourceManager.addLoader(Loader);
4966
- }
4967
- getComponent(constructor, node) {
4968
- if (node) {
4969
- return this._componentManager.getComponent(node, constructor);
4970
- }
4971
- for (let child of this._mount.children){
4972
- let comp = this._componentManager.getComponent(child, constructor);
4973
- if (comp) return comp;
4974
- }
4975
- }
4976
- task(target) {
4977
- const excute = typeof target === "function" ? target : ()=>this.compile(target);
4978
- this._taskManager.add(new Task(excute));
4979
- return target;
4931
+ this._components.resize(width, height);
4980
4932
  }
4981
4933
  use(object, props) {
4982
4934
  let ins = getClassInstance(object);
@@ -5011,7 +4963,7 @@ class Viewer extends EventEmitter {
5011
4963
  node = new Object3D();
5012
4964
  mount = true;
5013
4965
  }
5014
- this._componentManager.addComponent(node, ins);
4966
+ this._components.add(node, ins);
5015
4967
  } else {
5016
4968
  throw Error("Unsuport object");
5017
4969
  }
@@ -5026,7 +4978,7 @@ class Viewer extends EventEmitter {
5026
4978
  component
5027
4979
  ];
5028
4980
  for (const comp of components){
5029
- this._componentManager.addComponent(node, comp);
4981
+ this._components.add(node, comp);
5030
4982
  }
5031
4983
  }
5032
4984
  if (children) {
@@ -5052,10 +5004,10 @@ class Viewer extends EventEmitter {
5052
5004
  }
5053
5005
  remove(ins) {
5054
5006
  if (ins instanceof Object3D) {
5055
- this._componentManager.destroyComponents(ins);
5007
+ this._components.destroy(ins);
5056
5008
  ins.removeFromParent();
5057
5009
  } else if (ins instanceof Component) {
5058
- this._componentManager.removeComponent(ins.node, ins);
5010
+ this._components.remove(ins.node, ins);
5059
5011
  } else {
5060
5012
  throw Error("remove invalid");
5061
5013
  }
@@ -5067,7 +5019,7 @@ class Viewer extends EventEmitter {
5067
5019
  wrapT: ClampToEdgeWrapping,
5068
5020
  magFilter: nearest ? NearestFilter : LinearFilter,
5069
5021
  minFilter: nearest ? NearestFilter : mipmap ? LinearMipMapLinearFilter : LinearFilter,
5070
- type: typeof floatType === "boolean" ? floatType ? this.DATA_FLOAT_TYPE : UnsignedByteType : floatType,
5022
+ type: typeof floatType === "boolean" ? floatType ? HalfFloatType : UnsignedByteType : floatType,
5071
5023
  anisotropy: 0,
5072
5024
  colorSpace: LinearSRGBColorSpace,
5073
5025
  depthBuffer: depth,
@@ -5082,7 +5034,7 @@ class Viewer extends EventEmitter {
5082
5034
  wrapT: ClampToEdgeWrapping,
5083
5035
  magFilter: nearest ? NearestFilter : LinearFilter,
5084
5036
  minFilter: nearest ? NearestFilter : mipmap ? LinearMipMapLinearFilter : LinearFilter,
5085
- type: typeof floatType === "boolean" ? floatType ? this.DATA_FLOAT_TYPE : UnsignedByteType : floatType,
5037
+ type: typeof floatType === "boolean" ? floatType ? HalfFloatType : UnsignedByteType : floatType,
5086
5038
  anisotropy: 0,
5087
5039
  colorSpace: LinearSRGBColorSpace,
5088
5040
  depthBuffer: depth,
@@ -5238,7 +5190,7 @@ class Viewer extends EventEmitter {
5238
5190
  near: 0.1,
5239
5191
  far: 1000,
5240
5192
  position: new Vector3(0, 0, 4)
5241
- }, targetFrameRate = -1, fixedFrameTime = false, colorSpace = SRGBColorSpace, toneMapping = 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){
5193
+ }, targetFrameRate = -1, fixedFrameTime = false, colorSpace = SRGBColorSpace, toneMapping = 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){
5242
5194
  super(), this._instanceId = Viewer.instanceCount++, this._dpr = 1, this._width = 1, this._height = 1, this._viewport = {
5243
5195
  width: 1,
5244
5196
  height: 1,
@@ -5248,22 +5200,15 @@ class Viewer extends EventEmitter {
5248
5200
  window.innerHeight
5249
5201
  ], this._orientation = Orientation.AUTO, this._freeze = false;
5250
5202
  const el = canvas || document.getElementById("canvas");
5251
- const webgl = checkWebGL(el, webglOpts);
5252
- if (!webgl) {
5253
- throw Error("Unsupport WebGL in current platform");
5254
- }
5255
5203
  this._canvas = el;
5256
5204
  this._root = root || el;
5257
- this._gl = webgl.gl;
5258
- this._RENDER_TARGET_FLOAT_TYPE = webgl.RENDER_TARGET_FLOAT_TYPE;
5259
- this._DATA_FLOAT_TYPE = webgl.DATA_FLOAT_TYPE;
5260
5205
  this._dpr = Math.min(maxDPR, window.devicePixelRatio);
5261
5206
  this._orientation = orientation;
5262
5207
  this._scene = new Scene();
5263
5208
  this._camera = applyProps(orthographic ? new OrthographicCamera() : new PerspectiveCamera(), camera);
5264
5209
  this._renderer = new WebGLRenderer({
5265
5210
  canvas: el,
5266
- context: webgl.gl
5211
+ ...webglOpts
5267
5212
  });
5268
5213
  this._renderer.setPixelRatio(this._dpr);
5269
5214
  this._renderer.info.autoReset = false;
@@ -5273,37 +5218,50 @@ class Viewer extends EventEmitter {
5273
5218
  this._renderer.shadowMap.enabled = !!shadows;
5274
5219
  this._renderer.shadowMap.type = typeof shadows === "boolean" ? PCFSoftShadowMap : shadows;
5275
5220
  this._renderer.sortObjects = sortObjects;
5221
+ this._gl = this._renderer.getContext();
5276
5222
  this._context = {
5277
5223
  scene: this._scene,
5278
5224
  camera: this._camera
5279
5225
  };
5280
- this._targetFrameRate = targetFrameRate;
5226
+ this.targetFrameRate = targetFrameRate;
5281
5227
  this._windowSize = typeof resize === "function" ? resize : resize === ResizeMode.AUTO ? this._windowSize : null;
5282
- this._taskManager = new TaskManager(tasker.onComplete, tasker.onProgress, tasker.onError);
5283
- this._loadingManager = new LoadingManager(loader.onComplete, loader.onProgress, loader.onError);
5284
- this._resourceManager = new ResourceManager(this);
5285
- this._componentManager = new ComponentManager(this);
5286
- this._resourceOptions = {
5228
+ var _resources_manual;
5229
+ const resourcesManual = (_resources_manual = resources.manual) != null ? _resources_manual : manual;
5230
+ var _tasks_manual;
5231
+ const tasksManual = (_tasks_manual = tasks.manual) != null ? _tasks_manual : manual;
5232
+ var _components_manual;
5233
+ const componentsManual = (_components_manual = components.manual) != null ? _components_manual : manual;
5234
+ this._tasks = new TaskManager({
5235
+ manual: tasksManual,
5236
+ onComplete: tasks.onComplete,
5237
+ onProgress: tasks.onProgress,
5238
+ onError: tasks.onError
5239
+ });
5240
+ this._loading = new LoadingManager(resources.onComplete, resources.onProgress, resources.onError);
5241
+ this._resources = new ResourceManager({
5242
+ manual: resourcesManual,
5243
+ dracoPath,
5244
+ basisPath,
5245
+ renderer: this._renderer,
5246
+ loadingManager: this._loading,
5287
5247
  path,
5288
5248
  resourcePath,
5289
- dracoPath,
5290
- transcoderPath,
5291
- manager: this._loadingManager
5292
- };
5249
+ URL
5250
+ });
5251
+ var _resources_loaders;
5252
+ for (const Loader of (_resources_loaders = resources.loaders) != null ? _resources_loaders : DefaultLoaders){
5253
+ this._resources.addLoader(Loader);
5254
+ }
5255
+ this._components = new ComponentManager(this, {
5256
+ manual: componentsManual
5257
+ });
5293
5258
  this._mount = applyProps(new Object3D(), {
5294
5259
  name: "Mount"
5295
5260
  });
5296
5261
  this._input = this.add(new DeviceInput(input || {
5297
5262
  source: this._canvas
5298
5263
  }));
5299
- this._decodeURL = decodeURL;
5300
5264
  this.add(Renderer);
5301
- this.addLoader(GLTFLoader);
5302
- this.addLoader(HDRLoader);
5303
- this.addLoader(TextureLoader);
5304
- this.addLoader(JSONLoader);
5305
- this.addLoader(SVGLoader);
5306
- this.addLoader(KTX2Loader);
5307
5265
  this.rotate();
5308
5266
  this.resize();
5309
5267
  this.animate();
@@ -5866,6 +5824,7 @@ const defaultExtension = {
5866
5824
  "gltf": 0,
5867
5825
  "glb": 0,
5868
5826
  "buf": 0,
5827
+ "exr": 2,
5869
5828
  "hdr": 2,
5870
5829
  "png": 2,
5871
5830
  "jpg": 2,
@@ -5889,7 +5848,7 @@ class DropFile extends Component {
5889
5848
  if (files.length > 0) {
5890
5849
  filesMap = filesMap || createFilesMap(files);
5891
5850
  dirs = dirs || [];
5892
- this.viewer.setURLModifier((url)=>{
5851
+ this.viewer.loading.setURLModifier((url)=>{
5893
5852
  url = url.replace(/^(\.?\/)/, ''); // remove './'
5894
5853
  const file = filesMap[url];
5895
5854
  if (file) {
@@ -5920,12 +5879,12 @@ class DropFile extends Component {
5920
5879
  this._onError && this._onError(err);
5921
5880
  };
5922
5881
  const viewer = this.viewer;
5923
- const loadAsset = (props)=>{
5924
- return viewer.loadAsset(props).then(loadCallback).catch(errCallback);
5882
+ const load = (props)=>{
5883
+ return viewer.resources.load(props).then(loadCallback).catch(errCallback);
5925
5884
  };
5926
5885
  switch(this._extension[ext]){
5927
5886
  case 2:
5928
- reader.addEventListener("load", (event)=>loadAsset({
5887
+ reader.addEventListener("load", (event)=>load({
5929
5888
  ext,
5930
5889
  url: event.target.result
5931
5890
  }), false);
@@ -5939,7 +5898,7 @@ class DropFile extends Component {
5939
5898
  reader.readAsDataURL(file);
5940
5899
  break;
5941
5900
  case 0:
5942
- reader.addEventListener("load", (event)=>loadAsset({
5901
+ reader.addEventListener("load", (event)=>load({
5943
5902
  ext,
5944
5903
  buffer: event.target.result,
5945
5904
  resourcePath: dir
@@ -5975,6 +5934,7 @@ class DropFile extends Component {
5975
5934
  }
5976
5935
  }
5977
5936
  DropFile.Mode = Mode;
5937
+ DropFile.defaultExtension = defaultExtension;
5978
5938
  DropFile = __decorate([
5979
5939
  single()
5980
5940
  ], DropFile);
@@ -6567,6 +6527,7 @@ uniform float u_opacity;
6567
6527
  uniform vec3 u_strokeColor;
6568
6528
  uniform float u_strokeWidth;
6569
6529
  uniform vec3 u_shadowColor;
6530
+ uniform float u_shadowOpacity;
6570
6531
  uniform float u_shadowBlur;
6571
6532
  uniform vec2 u_shadowOffset;
6572
6533
  uniform float u_weight;
@@ -6581,23 +6542,32 @@ float signedDistance(in vec2 uv) {
6581
6542
  }
6582
6543
 
6583
6544
  void main() {
6584
- vec4 color = vec4(u_color, 1.);
6585
6545
  float d = signedDistance(v_uv) + u_weight;
6586
6546
  float w = fwidth(d);
6587
6547
 
6588
- vec4 stroke = vec4(u_strokeColor, smoothstep(-w, w, d));
6589
- color.a *= smoothstep(-w, w, d - u_strokeWidth);
6590
- color = mix(stroke, color, color.a);
6548
+ float outer = smoothstep(-w, w, d);
6549
+ float inner = smoothstep(-w, w, d - u_strokeWidth);
6550
+
6551
+ float stroke = step(0.0001, u_strokeWidth);
6552
+
6553
+ vec4 color = vec4(u_color, inner);
6554
+ color = mix(color, vec4(u_strokeColor, outer), stroke * (1.0 - inner));
6591
6555
 
6592
6556
  float sd = signedDistance(v_uv + u_shadowOffset) + u_weight;
6593
- vec4 shadow = vec4(u_shadowColor, smoothstep(-w - u_shadowBlur, w + u_shadowBlur, sd));
6557
+ float sw = fwidth(sd) + u_shadowBlur;
6558
+
6559
+ vec4 shadow = vec4(
6560
+ u_shadowColor,
6561
+ smoothstep(-sw, sw, sd) * u_shadowOpacity
6562
+ );
6563
+
6594
6564
  color = mix(shadow, color, color.a);
6595
6565
 
6596
6566
  color.a *= u_opacity;
6597
6567
  gl_FragColor = color;
6598
6568
 
6599
6569
  #include <tonemapping_fragment>
6600
- #include <colorspace_fragment>
6570
+ #include <colorspace_fragment>
6601
6571
  }
6602
6572
  `;
6603
6573
  class BMFontAtlas {
@@ -6685,13 +6655,16 @@ class BMFontAtlas {
6685
6655
  value: 0
6686
6656
  },
6687
6657
  u_shadowColor: {
6688
- value: new Color(0xffffff)
6658
+ value: new Color(0x606060)
6659
+ },
6660
+ u_shadowOpacity: {
6661
+ value: 0
6689
6662
  },
6690
6663
  u_shadowBlur: {
6691
6664
  value: 0
6692
6665
  },
6693
6666
  u_shadowOffset: {
6694
- value: new Vector2()
6667
+ value: new Vector2(0.01, 0)
6695
6668
  },
6696
6669
  u_fontTexture: {
6697
6670
  value: null
@@ -6713,5 +6686,5 @@ class BMFontAtlas {
6713
6686
  }
6714
6687
  }
6715
6688
 
6716
- export { AccumulativeShadows, Animation, AnimationCurve, BINLoader, BMFontAtlas, BMFontTextGeometry, BMFontTextLayout, Box, BoxProjection, Center, Component, ContactShadows, DependentMode, DeviceInput, DropFile, EXRLoader, Easing, Environment, EventEmitter, FBXLoader, FInterpConstantTo, FInterpTo, FreelookVirtualCamera, GLTFLoader, HDRLoader, JSONLoader, KTX2Loader, Label, Loader, Logger, ObjectInstance, Orientation, PerformanceMonitor, Perlin, Plane, PropertyManager, QInterpConstantTo, QInterpTo, Quat_AngularDistance, Quat_Equals, Quat_exponentialDamp, Quat_quarticDamp, Quat_smoothDamp, RandomizedLight, Reflector, ReflectorMaterial, RenderTexture, Renderer, ResizeMode, ResourceManager, SVGLoader, ShadowMaterial, Sphere, SystemInfo, Task, TextureLoader, VInterpConstantTo, VInterpTo, Vec3_smoothDamp, Vector3_NEG_ONE, Vector3_ONE, Vector3_RIGHT, Vector3_UNIT_X, Vector3_UNIT_Y, Vector3_UNIT_Z, Vector3_UP, Vector3_ZERO, Viewer, applyProps, dependencies, exponentialDamp, find, frag_BoxfilterBlur, frag_cubeMapToPanorama, frag_panoramaToCubeMap, getChildByName, getChildren, getClassInstance, getShaderMaterial, mixin, property, quarticDamp, queryValues, single, smoothDamp, vert_fullscreen };
6689
+ export { AccumulativeShadows, Animation, AnimationCurve, BMFontAtlas, BMFontTextGeometry, BMFontTextLayout, Box, BoxProjection, Center, Component, ComponentManager, ContactShadows, DefaultLoaders, DependentMode, DeviceInput, DropFile, EXRLoader, Easing, Environment, EventEmitter, FBXLoader, FInterpConstantTo, FInterpTo, FreelookVirtualCamera, GLTFLoader, HDRLoader, JSONLoader, KTX2Loader, Label, Loader, Logger, ObjectInstance, Orientation, PerformanceMonitor, Perlin, Plane, PropertyManager, QInterpConstantTo, QInterpTo, Quat_AngularDistance, Quat_Equals, Quat_exponentialDamp, Quat_quarticDamp, Quat_smoothDamp, RandomizedLight, Reflector, ReflectorMaterial, RenderTexture, Renderer, ResizeMode, ResourceManager, SVGLoader, ShadowMaterial, Sphere, SystemInfo, Task, TaskManager, TextureLoader, VInterpConstantTo, VInterpTo, Vec3_smoothDamp, Vector3_NEG_ONE, Vector3_ONE, Vector3_RIGHT, Vector3_UNIT_X, Vector3_UNIT_Y, Vector3_UNIT_Z, Vector3_UP, Vector3_ZERO, Viewer, applyProps, dependencies, exponentialDamp, find, frag_BoxfilterBlur, frag_cubeMapToPanorama, frag_panoramaToCubeMap, getChildren, getClassInstance, getShaderMaterial, mixin, property, quarticDamp, single, smoothDamp, vert_fullscreen };
6717
6690
  //# sourceMappingURL=module.js.map