@xviewer.js/core 1.0.1 → 1.0.2

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.
Files changed (55) hide show
  1. package/dist/{main.js → main.cjs} +2301 -2472
  2. package/dist/main.cjs.map +1 -0
  3. package/dist/module.js +2130 -2320
  4. package/dist/module.js.map +1 -1
  5. package/package.json +3 -3
  6. package/types/Component.d.ts +4 -0
  7. package/types/Mount.d.ts +2 -1
  8. package/types/SystemInfo.d.ts +1 -4
  9. package/types/Utils.d.ts +4 -4
  10. package/types/Viewer.d.ts +7 -5
  11. package/types/asset/{aLoader.d.ts → Loader.d.ts} +1 -1
  12. package/types/asset/ResourceManager.d.ts +4 -4
  13. package/types/cinestation/CinestationBlendDefinition.d.ts +4 -4
  14. package/types/components/AccumulativeShadows.d.ts +68 -0
  15. package/types/components/Center.d.ts +44 -0
  16. package/types/components/index.d.ts +2 -0
  17. package/types/constants.d.ts +1 -0
  18. package/types/index.d.ts +1 -2
  19. package/types/loaders/BINLoader.d.ts +8 -0
  20. package/types/loaders/{aEXRLoader.d.ts → EXRLoader.d.ts} +2 -2
  21. package/types/loaders/{aFBXLoader.d.ts → FBXLoader.d.ts} +2 -2
  22. package/types/loaders/{aGLTFLoader.d.ts → GLTFLoader.d.ts} +2 -2
  23. package/types/loaders/{aHDRLoader.d.ts → HDRLoader.d.ts} +2 -2
  24. package/types/loaders/{aJSONLoader.d.ts → JSONLoader.d.ts} +2 -2
  25. package/types/loaders/{aTextureLoader.d.ts → TextureLoader.d.ts} +2 -2
  26. package/types/loaders/index.d.ts +7 -6
  27. package/types/materials/DiscardMaterial.d.ts +5 -0
  28. package/types/math/index.d.ts +1 -0
  29. package/types/plugins/DropFile.d.ts +3 -1
  30. package/types/plugins/UI.d.ts +30 -0
  31. package/types/plugins/index.d.ts +1 -0
  32. package/types/shaderMaterial.d.ts +8 -0
  33. package/types/types.d.ts +20 -17
  34. package/dist/main.js.map +0 -1
  35. package/types/Plugin.d.ts +0 -4
  36. package/types/PluginManager.d.ts +0 -17
  37. package/types/components/PerformanceMonitor.d.ts +0 -48
  38. package/types/plugins/BoxProjectionPlugin.d.ts +0 -20
  39. package/types/plugins/DebugPlugin.d.ts +0 -10
  40. package/types/plugins/DebugScene.d.ts +0 -8
  41. package/types/plugins/DropFilePlugin.d.ts +0 -18
  42. package/types/plugins/EnvironmentPlugin.d.ts +0 -41
  43. package/types/plugins/PerformanceMonitorPlugin.d.ts +0 -48
  44. package/types/tween/Group.d.ts +0 -16
  45. package/types/tween/Interpolation.d.ts +0 -19
  46. package/types/tween/Now.d.ts +0 -2
  47. package/types/tween/Sequence.d.ts +0 -7
  48. package/types/tween/Tween.d.ts +0 -98
  49. package/types/tween/TweenChain.d.ts +0 -26
  50. package/types/tween/TweenGroup.d.ts +0 -17
  51. package/types/tween/TweenManager.d.ts +0 -8
  52. package/types/tween/Version.d.ts +0 -1
  53. package/types/tween/index.d.ts +0 -6
  54. package/types/tween/mainGroup.d.ts +0 -2
  55. /package/types/{tween → math}/Easing.d.ts +0 -0
package/dist/module.js CHANGED
@@ -1,9 +1,10 @@
1
- import { EXRLoader } from 'three/examples/jsm/loaders/EXRLoader.js';
2
- import { FBXLoader } from 'three/examples/jsm/loaders/FBXLoader.js';
3
- import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
1
+ import { EXRLoader as EXRLoader$1 } from 'three/examples/jsm/loaders/EXRLoader.js';
2
+ import { FBXLoader as FBXLoader$1 } from 'three/examples/jsm/loaders/FBXLoader.js';
3
+ import { GLTFLoader as GLTFLoader$1 } from 'three/examples/jsm/loaders/GLTFLoader.js';
4
4
  import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader.js';
5
5
  import { MeshoptDecoder } from 'three/examples/jsm/libs/meshopt_decoder.module.js';
6
- import { EquirectangularReflectionMapping, FileLoader, TextureLoader, SRGBColorSpace, MathUtils, Vector3, Quaternion, Raycaster, Vector2, LinearInterpolant, Spherical, Mesh, BoxGeometry, SphereGeometry, PlaneGeometry, Plane as Plane$1, Matrix4, Vector4, PerspectiveCamera, WebGLRenderTarget, HalfFloatType, LinearMipMapLinearFilter, LinearFilter, AnimationMixer, Color, OrthographicCamera, MeshDepthMaterial, ShaderMaterial, Euler, Group, UniformsUtils, NoBlending, AdditiveBlending, FloatType, UnsignedByteType, BufferGeometry, Float32BufferAttribute, Object3D, ClampToEdgeWrapping, NearestFilter, LinearSRGBColorSpace, WebGLCubeRenderTarget, DataTexture, RGBAFormat, UVMapping, Scene, WebGLRenderer, PCFSoftShadowMap, LoadingManager, LinearToneMapping, PMREMGenerator, CubeCamera, ShaderLib, ShaderChunk } from 'three';
6
+ import * as THREE from 'three';
7
+ import { EquirectangularReflectionMapping, FileLoader, TextureLoader as TextureLoader$1, SRGBColorSpace, MathUtils, Vector3, Vector2, LinearInterpolant, Quaternion, Raycaster, Spherical, Mesh, BoxGeometry, SphereGeometry, PlaneGeometry, Plane as Plane$1, Matrix4, Vector4, PerspectiveCamera, WebGLRenderTarget, HalfFloatType, LinearMipMapLinearFilter, LinearFilter, AnimationMixer, Color, OrthographicCamera, MeshDepthMaterial, ShaderMaterial, Euler, Group, REVISION, Box3, Sphere as Sphere$1, UniformsUtils, NoBlending, AdditiveBlending, FloatType, UnsignedByteType, Object3D, BufferGeometry, Float32BufferAttribute, ClampToEdgeWrapping, NearestFilter, LinearSRGBColorSpace, WebGLCubeRenderTarget, DataTexture, RGBAFormat, UVMapping, Scene, WebGLRenderer, PCFSoftShadowMap, LoadingManager, LinearToneMapping, PMREMGenerator, CubeCamera, ShaderLib, ShaderChunk } from 'three';
7
8
  import { RGBELoader } from 'three/examples/jsm/loaders/RGBELoader.js';
8
9
  import { HorizontalBlurShader, VerticalBlurShader } from 'three/examples/jsm/Addons.js';
9
10
 
@@ -140,2291 +141,632 @@ function getClassInstance(constructor, args = []) {
140
141
  return typeof constructor === "function" ? new constructor(...args) : constructor;
141
142
  }
142
143
 
143
- /**
144
- * Controlling groups of tweens
145
- *
146
- * Using the TWEEN singleton to manage your tweens can cause issues in large apps with many components.
147
- * In these cases, you may want to create your own smaller groups of tween
148
- */ class TweenGroup {
149
- getAll() {
150
- return Object.values(this._tweens);
151
- }
152
- removeAll() {
153
- this._tweens = {};
154
- }
155
- removeOf(target) {
156
- this.getAll().forEach((tween)=>tween.getObject() === target && this.remove(tween));
157
- }
158
- add(tween) {
159
- this._tweens[tween.getId()] = tween;
160
- this._tweensAddedDuringUpdate[tween.getId()] = tween;
161
- }
162
- remove(tween) {
163
- delete this._tweens[tween.getId()];
164
- delete this._tweensAddedDuringUpdate[tween.getId()];
165
- }
166
- update(time, preserve = false) {
167
- let tweenIds = Object.keys(this._tweens);
168
- if (tweenIds.length === 0) {
169
- return false;
170
- }
171
- // Tweens are updated in "batches". If you add a new tween during an
172
- // update, then the new tween will be updated in the next batch.
173
- // If you remove a tween during an update, it may or may not be updated.
174
- // However, if the removed tween was added during the current batch,
175
- // then it will not be updated.
176
- while(tweenIds.length > 0){
177
- this._tweensAddedDuringUpdate = {};
178
- for(let i = 0; i < tweenIds.length; i++){
179
- const tween = this._tweens[tweenIds[i]];
180
- const autoStart = !preserve;
181
- if (tween && tween.update(time, autoStart) === false && !preserve) {
182
- delete this._tweens[tweenIds[i]];
183
- }
144
+ class Loader {
145
+ static _setUserData(node) {
146
+ const keys = Loader._texKeys;
147
+ const meshes = [];
148
+ const textures = {};
149
+ const materials = {};
150
+ const queue = [
151
+ node
152
+ ];
153
+ while(queue.length !== 0){
154
+ let object = queue.shift();
155
+ if (object.isMesh) {
156
+ meshes.push(object);
157
+ const mat = object.material;
158
+ if (Array.isArray(mat)) mat.forEach((v)=>materials[v.uuid] = v);
159
+ else materials[mat.uuid] = mat;
184
160
  }
185
- tweenIds = Object.keys(this._tweensAddedDuringUpdate);
161
+ queue.push(...object.children);
186
162
  }
187
- return true;
163
+ Object.values(materials).forEach((mat)=>{
164
+ keys.forEach((k)=>{
165
+ let tex = mat[k];
166
+ if (tex) {
167
+ textures[tex.uuid] = tex;
168
+ }
169
+ });
170
+ });
171
+ Object.assign(node.userData, {
172
+ meshes,
173
+ materials,
174
+ textures
175
+ });
176
+ return node;
188
177
  }
189
- constructor(){
190
- this._tweens = {};
191
- this._tweensAddedDuringUpdate = {};
178
+ constructor(manager){
179
+ this.manager = manager;
192
180
  }
193
181
  }
182
+ Loader._texKeys = [
183
+ "map",
184
+ "alphaMap",
185
+ "aoMap",
186
+ "bumpMap",
187
+ "displacementMap",
188
+ "emissiveMap",
189
+ "envMap",
190
+ "lightMap",
191
+ "metalnessMap",
192
+ "normalMap",
193
+ "roughnessMap",
194
+ "specularMap",
195
+ "alphaMap"
196
+ ];
194
197
 
195
- const now = ()=>performance.now() * 0.001;
196
-
197
- /**
198
- * The Ease class provides a collection of easing functions for use with tween.js.
199
- */ const Easing = Object.freeze({
200
- Linear: Object.freeze({
201
- None (amount) {
202
- return amount;
203
- },
204
- In (amount) {
205
- return amount;
206
- },
207
- Out (amount) {
208
- return amount;
209
- },
210
- InOut (amount) {
211
- return amount;
198
+ class EXRLoader extends Loader {
199
+ load({ url, path, resourcePath, manager, texSettings, onLoad, onProgress, onError }) {
200
+ let loader = this._loader;
201
+ if (loader === undefined) {
202
+ loader = this._loader = new EXRLoader$1();
212
203
  }
213
- }),
214
- Quadratic: Object.freeze({
215
- In (amount) {
216
- return amount * amount;
217
- },
218
- Out (amount) {
219
- return amount * (2 - amount);
220
- },
221
- InOut (amount) {
222
- if ((amount *= 2) < 1) {
223
- return 0.5 * amount * amount;
224
- }
225
- return -0.5 * (--amount * (amount - 2) - 1);
204
+ loader.manager = manager;
205
+ loader.setPath(path);
206
+ loader.setResourcePath(resourcePath);
207
+ loader.load(url, (tex)=>onLoad(Object.assign(tex, texSettings)), onProgress, onError);
208
+ }
209
+ constructor(...args){
210
+ super(...args);
211
+ this.extension = [
212
+ "exr"
213
+ ];
214
+ }
215
+ }
216
+
217
+ class FBXLoader extends Loader {
218
+ load({ url, buffer, path, resourcePath, manager, onLoad, onProgress, onError }) {
219
+ let loader = this._loader;
220
+ if (loader === undefined) {
221
+ loader = this._loader = new FBXLoader$1();
226
222
  }
227
- }),
228
- Cubic: Object.freeze({
229
- In (amount) {
230
- return amount * amount * amount;
231
- },
232
- Out (amount) {
233
- return --amount * amount * amount + 1;
234
- },
235
- InOut (amount) {
236
- if ((amount *= 2) < 1) {
237
- return 0.5 * amount * amount * amount;
238
- }
239
- return 0.5 * ((amount -= 2) * amount * amount + 2);
223
+ loader.manager = manager;
224
+ loader.setPath(path);
225
+ loader.setResourcePath(resourcePath);
226
+ const loadCallback = (node)=>{
227
+ onLoad(Loader._setUserData(node));
228
+ };
229
+ if (buffer) {
230
+ loadCallback(loader.parse(buffer, resourcePath));
231
+ } else {
232
+ loader.load(url, loadCallback, onProgress, onError);
240
233
  }
241
- }),
242
- Quartic: Object.freeze({
243
- In (amount) {
244
- return amount * amount * amount * amount;
245
- },
246
- Out (amount) {
247
- return 1 - --amount * amount * amount * amount;
248
- },
249
- InOut (amount) {
250
- if ((amount *= 2) < 1) {
251
- return 0.5 * amount * amount * amount * amount;
252
- }
253
- return -0.5 * ((amount -= 2) * amount * amount * amount - 2);
234
+ }
235
+ constructor(...args){
236
+ super(...args);
237
+ this.extension = [
238
+ "fbx"
239
+ ];
240
+ }
241
+ }
242
+
243
+ class GLTFLoader extends Loader {
244
+ load({ url, buffer, path, resourcePath, dracoPath, manager, onLoad, onProgress, onError }) {
245
+ let dracoLoader = this._dracoLoader;
246
+ if (dracoLoader === undefined) {
247
+ dracoLoader = this._dracoLoader = new DRACOLoader();
254
248
  }
255
- }),
256
- Quintic: Object.freeze({
257
- In (amount) {
258
- return amount * amount * amount * amount * amount;
259
- },
260
- Out (amount) {
261
- return --amount * amount * amount * amount * amount + 1;
262
- },
263
- InOut (amount) {
264
- if ((amount *= 2) < 1) {
265
- return 0.5 * amount * amount * amount * amount * amount;
266
- }
267
- return 0.5 * ((amount -= 2) * amount * amount * amount * amount + 2);
249
+ dracoLoader.manager = manager;
250
+ dracoLoader.setDecoderPath(dracoPath);
251
+ let loader = this._loader;
252
+ if (loader === undefined) {
253
+ loader = this._loader = new GLTFLoader$1();
254
+ loader.setDRACOLoader(dracoLoader);
255
+ loader.setMeshoptDecoder(MeshoptDecoder);
268
256
  }
269
- }),
270
- Sinusoidal: Object.freeze({
271
- In (amount) {
272
- return 1 - Math.sin((1.0 - amount) * Math.PI / 2);
273
- },
274
- Out (amount) {
275
- return Math.sin(amount * Math.PI / 2);
276
- },
277
- InOut (amount) {
278
- return 0.5 * (1 - Math.sin(Math.PI * (0.5 - amount)));
257
+ loader.manager = manager;
258
+ loader.setPath(path);
259
+ loader.setResourcePath(resourcePath);
260
+ const loadCallback = (gltf)=>{
261
+ const node = gltf.scene;
262
+ node.animations.push(...gltf.animations);
263
+ onLoad(Loader._setUserData(node));
264
+ };
265
+ if (buffer) {
266
+ loader.parse(buffer, resourcePath, loadCallback, onError);
267
+ } else {
268
+ loader.load(url, loadCallback, onProgress, onError);
279
269
  }
280
- }),
281
- Exponential: Object.freeze({
282
- In (amount) {
283
- return amount === 0 ? 0 : Math.pow(1024, amount - 1);
284
- },
285
- Out (amount) {
286
- return amount === 1 ? 1 : 1 - Math.pow(2, -10 * amount);
287
- },
288
- InOut (amount) {
289
- if (amount === 0) {
290
- return 0;
291
- }
292
- if (amount === 1) {
293
- return 1;
294
- }
295
- if ((amount *= 2) < 1) {
296
- return 0.5 * Math.pow(1024, amount - 1);
297
- }
298
- return 0.5 * (-Math.pow(2, -10 * (amount - 1)) + 2);
270
+ }
271
+ constructor(...args){
272
+ super(...args);
273
+ this.extension = [
274
+ "gltf",
275
+ "glb"
276
+ ];
277
+ }
278
+ }
279
+
280
+ class HDRLoader extends Loader {
281
+ load({ url, path, resourcePath, manager, texSettings, onLoad, onProgress, onError }) {
282
+ let loader = this._loader;
283
+ if (loader === undefined) {
284
+ loader = this._loader = new RGBELoader();
299
285
  }
300
- }),
301
- Circular: Object.freeze({
302
- In (amount) {
303
- return 1 - Math.sqrt(1 - amount * amount);
304
- },
305
- Out (amount) {
306
- return Math.sqrt(1 - --amount * amount);
307
- },
308
- InOut (amount) {
309
- if ((amount *= 2) < 1) {
310
- return -0.5 * (Math.sqrt(1 - amount * amount) - 1);
311
- }
312
- return 0.5 * (Math.sqrt(1 - (amount -= 2) * amount) + 1);
313
- }
314
- }),
315
- Elastic: Object.freeze({
316
- In (amount) {
317
- if (amount === 0) {
318
- return 0;
319
- }
320
- if (amount === 1) {
321
- return 1;
322
- }
323
- return -Math.pow(2, 10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI);
324
- },
325
- Out (amount) {
326
- if (amount === 0) {
327
- return 0;
328
- }
329
- if (amount === 1) {
330
- return 1;
331
- }
332
- return Math.pow(2, -10 * amount) * Math.sin((amount - 0.1) * 5 * Math.PI) + 1;
333
- },
334
- InOut (amount) {
335
- if (amount === 0) {
336
- return 0;
337
- }
338
- if (amount === 1) {
339
- return 1;
340
- }
341
- amount *= 2;
342
- if (amount < 1) {
343
- return -0.5 * Math.pow(2, 10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI);
344
- }
345
- return 0.5 * Math.pow(2, -10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI) + 1;
346
- }
347
- }),
348
- Back: Object.freeze({
349
- In (amount) {
350
- const s = 1.70158;
351
- return amount === 1 ? 1 : amount * amount * ((s + 1) * amount - s);
352
- },
353
- Out (amount) {
354
- const s = 1.70158;
355
- return amount === 0 ? 0 : --amount * amount * ((s + 1) * amount + s) + 1;
356
- },
357
- InOut (amount) {
358
- const s = 1.70158 * 1.525;
359
- if ((amount *= 2) < 1) {
360
- return 0.5 * (amount * amount * ((s + 1) * amount - s));
361
- }
362
- return 0.5 * ((amount -= 2) * amount * ((s + 1) * amount + s) + 2);
363
- }
364
- }),
365
- Bounce: Object.freeze({
366
- In (amount) {
367
- return 1 - Easing.Bounce.Out(1 - amount);
368
- },
369
- Out (amount) {
370
- if (amount < 1 / 2.75) {
371
- return 7.5625 * amount * amount;
372
- } else if (amount < 2 / 2.75) {
373
- return 7.5625 * (amount -= 1.5 / 2.75) * amount + 0.75;
374
- } else if (amount < 2.5 / 2.75) {
375
- return 7.5625 * (amount -= 2.25 / 2.75) * amount + 0.9375;
376
- } else {
377
- return 7.5625 * (amount -= 2.625 / 2.75) * amount + 0.984375;
378
- }
379
- },
380
- InOut (amount) {
381
- if (amount < 0.5) {
382
- return Easing.Bounce.In(amount * 2) * 0.5;
383
- }
384
- return Easing.Bounce.Out(amount * 2 - 1) * 0.5 + 0.5;
385
- }
386
- }),
387
- generatePow (power = 4) {
388
- power = power < Number.EPSILON ? Number.EPSILON : power;
389
- power = power > 10000 ? 10000 : power;
390
- return {
391
- In (amount) {
392
- return amount ** power;
393
- },
394
- Out (amount) {
395
- return 1 - (1 - amount) ** power;
396
- },
397
- InOut (amount) {
398
- if (amount < 0.5) {
399
- return (amount * 2) ** power / 2;
400
- }
401
- return (1 - (2 - amount * 2) ** power) / 2 + 0.5;
402
- }
403
- };
404
- }
405
- });
406
-
407
- /**
408
- *
409
- */ /**
410
- *
411
- */ const Interpolation = {
412
- Linear: function(v, k) {
413
- const m = v.length - 1;
414
- const f = m * k;
415
- const i = Math.floor(f);
416
- const fn = Interpolation.Utils.Linear;
417
- if (k < 0) {
418
- return fn(v[0], v[1], f);
419
- }
420
- if (k > 1) {
421
- return fn(v[m], v[m - 1], m - f);
422
- }
423
- return fn(v[i], v[i + 1 > m ? m : i + 1], f - i);
424
- },
425
- Bezier: function(v, k) {
426
- let b = 0;
427
- const n = v.length - 1;
428
- const pw = Math.pow;
429
- const bn = Interpolation.Utils.Bernstein;
430
- for(let i = 0; i <= n; i++){
431
- b += pw(1 - k, n - i) * pw(k, i) * v[i] * bn(n, i);
432
- }
433
- return b;
434
- },
435
- CatmullRom: function(v, k) {
436
- const m = v.length - 1;
437
- let f = m * k;
438
- let i = Math.floor(f);
439
- const fn = Interpolation.Utils.CatmullRom;
440
- if (v[0] === v[m]) {
441
- if (k < 0) {
442
- i = Math.floor(f = m * (1 + k));
443
- }
444
- return fn(v[(i - 1 + m) % m], v[i], v[(i + 1) % m], v[(i + 2) % m], f - i);
445
- } else {
446
- if (k < 0) {
447
- return v[0] - (fn(v[0], v[0], v[1], v[1], -f) - v[0]);
448
- }
449
- if (k > 1) {
450
- return v[m] - (fn(v[m], v[m], v[m - 1], v[m - 1], f - m) - v[m]);
451
- }
452
- return fn(v[i ? i - 1 : 0], v[i], v[m < i + 1 ? m : i + 1], v[m < i + 2 ? m : i + 2], f - i);
453
- }
454
- },
455
- Utils: {
456
- Linear: function(p0, p1, t) {
457
- return (p1 - p0) * t + p0;
458
- },
459
- Bernstein: function(n, i) {
460
- const fc = Interpolation.Utils.Factorial;
461
- return fc(n) / fc(i) / fc(n - i);
462
- },
463
- Factorial: function() {
464
- const a = [
465
- 1
466
- ];
467
- return function(n) {
468
- let s = 1;
469
- if (a[n]) {
470
- return a[n];
471
- }
472
- for(let i = n; i > 1; i--){
473
- s *= i;
474
- }
475
- a[n] = s;
476
- return s;
477
- };
478
- }(),
479
- CatmullRom: function(p0, p1, p2, p3, t) {
480
- const v0 = (p2 - p0) * 0.5;
481
- const v1 = (p3 - p1) * 0.5;
482
- const t2 = t * t;
483
- const t3 = t * t2;
484
- return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
286
+ loader.manager = manager;
287
+ loader.setPath(path);
288
+ loader.setResourcePath(resourcePath);
289
+ const settings = Object.assign({
290
+ mapping: EquirectangularReflectionMapping
291
+ }, texSettings);
292
+ loader.load(url, (tex)=>onLoad(Object.assign(tex, settings)), onProgress, onError);
293
+ }
294
+ constructor(...args){
295
+ super(...args);
296
+ this.extension = [
297
+ "hdr"
298
+ ];
299
+ }
300
+ }
301
+
302
+ class JSONLoader extends Loader {
303
+ load({ url, path, resourcePath, manager, onLoad, onProgress, onError }) {
304
+ let loader = this._loader;
305
+ if (loader === undefined) {
306
+ loader = this._loader = new FileLoader();
485
307
  }
308
+ loader.manager = manager;
309
+ loader.setPath(path);
310
+ loader.setResourcePath(resourcePath);
311
+ loader.load(url, (file)=>onLoad(JSON.parse(file)), onProgress, onError);
486
312
  }
487
- };
488
-
489
- const mainGroup = new TweenGroup();
490
-
491
- /**
492
- * Utils
493
- */ class Sequence {
494
- static nextId() {
495
- return Sequence._nextId++;
313
+ constructor(...args){
314
+ super(...args);
315
+ this.extension = [
316
+ "json"
317
+ ];
496
318
  }
497
319
  }
498
- Sequence._nextId = 0;
499
320
 
500
- class Tween {
501
- getId() {
502
- return this._id;
503
- }
504
- getObject() {
505
- return this._object;
506
- }
507
- getGroup() {
508
- return this._group;
509
- }
510
- isPlaying() {
511
- return this._isPlaying;
512
- }
513
- isPaused() {
514
- return this._isPaused;
515
- }
516
- getDuration() {
517
- return this._duration;
518
- }
519
- from(properties) {
520
- this._valuesStart = Object.create(properties);
521
- return this;
522
- }
523
- to(target, duration = 1) {
524
- if (this._isPlaying) throw new Error('Can not call Tween.to() while Tween is already started or paused. Stop the Tween first.');
525
- this._valuesEnd = target;
526
- this._propertiesAreSetUp = false;
527
- this._duration = duration < 0 ? 0 : duration;
528
- return this;
529
- }
530
- duration(duration = 1) {
531
- this._duration = duration < 0 ? 0 : duration;
532
- return this;
533
- }
534
- dynamic(dynamic = false) {
535
- this._isDynamic = dynamic;
536
- return this;
537
- }
538
- start(time, overrideStartingValues = false) {
539
- if (this._isPlaying) {
540
- return this;
541
- }
542
- // eslint-disable-next-line
543
- this._group && this._group.add(this);
544
- this._repeat = this._initialRepeat;
545
- if (this._reversed) {
546
- // If we were reversed (f.e. using the yoyo feature) then we need to
547
- // flip the tween direction back to forward.
548
- this._reversed = false;
549
- for(const property in this._valuesStartRepeat){
550
- this._swapEndStartRepeatValues(property);
551
- this._valuesStart[property] = this._valuesStartRepeat[property];
552
- }
553
- }
554
- this._isPlaying = true;
555
- this._isPaused = false;
556
- this._onStartCallbackFired = false;
557
- this._onEveryStartCallbackFired = false;
558
- this._isChainStopped = false;
559
- this._startTime = time;
560
- this._startTime += this._delayTime;
561
- if (!this._propertiesAreSetUp || overrideStartingValues) {
562
- this._propertiesAreSetUp = true;
563
- // If dynamic is not enabled, clone the end values instead of using the passed-in end values.
564
- if (!this._isDynamic) {
565
- const tmp = {};
566
- for(const prop in this._valuesEnd)tmp[prop] = this._valuesEnd[prop];
567
- this._valuesEnd = tmp;
568
- }
569
- this._setupProperties(this._object, this._valuesStart, this._valuesEnd, this._valuesStartRepeat, overrideStartingValues);
570
- }
571
- return this;
572
- }
573
- startFromCurrentValues(time) {
574
- return this.start(time, true);
575
- }
576
- _setupProperties(_object, _valuesStart, _valuesEnd, _valuesStartRepeat, overrideStartingValues) {
577
- for(const property in _valuesEnd){
578
- const startValue = _object[property];
579
- const startValueIsArray = Array.isArray(startValue);
580
- const propType = startValueIsArray ? 'array' : typeof startValue;
581
- let isInterpolationList = !startValueIsArray && Array.isArray(_valuesEnd[property]);
582
- // If `to()` specifies a property that doesn't exist in the source object,
583
- // we should not set that property in the object
584
- if (propType === 'undefined' || propType === 'function') {
585
- continue;
586
- }
587
- // Check if an Array was provided as property value
588
- if (isInterpolationList) {
589
- const endValues = _valuesEnd[property];
590
- if (endValues.length === 0) {
591
- continue;
592
- }
593
- // Handle an array of relative values.
594
- // Creates a local copy of the Array with the start value at the front
595
- const temp = [
596
- startValue
597
- ];
598
- for(let i = 0, l = endValues.length; i < l; i += 1){
599
- const value = this._handleRelativeValue(startValue, endValues[i]);
600
- if (isNaN(value)) {
601
- isInterpolationList = false;
602
- console.warn('Found invalid interpolation list. Skipping.');
603
- break;
604
- }
605
- temp.push(value);
606
- }
607
- if (isInterpolationList) {
608
- // if (_valuesStart[property] === undefined) { // handle end values only the first time. NOT NEEDED? setupProperties is now guarded by _propertiesAreSetUp.
609
- _valuesEnd[property] = temp;
610
- // }
611
- }
612
- }
613
- // handle the deepness of the values
614
- if ((propType === 'object' || startValueIsArray) && startValue && !isInterpolationList) {
615
- _valuesStart[property] = startValueIsArray ? [] : {};
616
- const nestedObject = startValue;
617
- for(const prop in nestedObject){
618
- _valuesStart[property][prop] = nestedObject[prop];
619
- }
620
- // TODO? repeat nested values? And yoyo? And array values?
621
- _valuesStartRepeat[property] = startValueIsArray ? [] : {};
622
- let endValues = _valuesEnd[property];
623
- // If dynamic is not enabled, clone the end values instead of using the passed-in end values.
624
- if (!this._isDynamic) {
625
- const tmp = {};
626
- for(const prop in endValues)tmp[prop] = endValues[prop];
627
- _valuesEnd[property] = endValues = tmp;
628
- }
629
- this._setupProperties(nestedObject, _valuesStart[property], endValues, _valuesStartRepeat[property], overrideStartingValues);
630
- } else {
631
- // Save the starting value, but only once unless override is requested.
632
- if (typeof _valuesStart[property] === 'undefined' || overrideStartingValues) {
633
- _valuesStart[property] = startValue;
634
- }
635
- if (!startValueIsArray) {
636
- // eslint-disable-next-line
637
- // @ts-ignore FIXME?
638
- _valuesStart[property] *= 1.0 // Ensures we're using numbers, not strings
639
- ;
640
- }
641
- if (isInterpolationList) {
642
- // eslint-disable-next-line
643
- // @ts-ignore FIXME?
644
- _valuesStartRepeat[property] = _valuesEnd[property].slice().reverse();
645
- } else {
646
- _valuesStartRepeat[property] = _valuesStart[property] || 0;
647
- }
648
- }
649
- }
650
- }
651
- stop() {
652
- if (!this._isChainStopped) {
653
- this._isChainStopped = true;
654
- this.stopChainedTweens();
655
- }
656
- if (!this._isPlaying) {
657
- return this;
658
- }
659
- // eslint-disable-next-line
660
- this._group && this._group.remove(this);
661
- this._isPlaying = false;
662
- this._isPaused = false;
663
- if (this._onStopCallback) {
664
- this._onStopCallback(this._object);
321
+ class TextureLoader extends Loader {
322
+ load({ url, path, resourcePath, manager, texSettings, onLoad, onProgress, onError }) {
323
+ let loader = this._loader;
324
+ if (loader === undefined) {
325
+ loader = this._loader = new TextureLoader$1();
665
326
  }
666
- return this;
327
+ loader.manager = manager;
328
+ loader.setPath(path);
329
+ loader.setResourcePath(resourcePath);
330
+ const loadCallback = (tex)=>{
331
+ tex.colorSpace = SRGBColorSpace;
332
+ onLoad(Object.assign(tex, texSettings));
333
+ };
334
+ loader.load(url, loadCallback, onProgress, onError);
667
335
  }
668
- end() {
669
- this._goToEnd = true;
670
- this.update(Infinity);
671
- return this;
336
+ constructor(...args){
337
+ super(...args);
338
+ this.extension = [
339
+ "png",
340
+ "jpg",
341
+ "webp",
342
+ "avif"
343
+ ];
672
344
  }
673
- pause(time) {
674
- if (this._isPaused || !this._isPlaying) {
675
- return this;
345
+ }
346
+
347
+ class BINLoader extends Loader {
348
+ load({ url, buffer, path, resourcePath, dracoPath, manager, onLoad, onProgress, onError }) {
349
+ let dracoLoader = this._dracoLoader;
350
+ if (dracoLoader === undefined) {
351
+ dracoLoader = this._dracoLoader = new DRACOLoader();
676
352
  }
677
- this._isPaused = true;
678
- this._pauseStart = time;
679
- // eslint-disable-next-line
680
- this._group && this._group.remove(this);
681
- return this;
682
- }
683
- resume(time) {
684
- if (!this._isPaused || !this._isPlaying) {
685
- return this;
353
+ dracoLoader.manager = manager;
354
+ dracoLoader.setDecoderPath(dracoPath);
355
+ let loader = this._loader;
356
+ if (loader === undefined) {
357
+ loader = this._loader = new CustomLoader();
358
+ loader.setDRACOLoader(dracoLoader);
359
+ loader.setMeshoptDecoder(MeshoptDecoder);
686
360
  }
687
- this._isPaused = false;
688
- this._startTime += time - this._pauseStart;
689
- this._pauseStart = 0;
690
- // eslint-disable-next-line
691
- this._group && this._group.add(this);
692
- return this;
693
- }
694
- stopChainedTweens() {
695
- for(let i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++){
696
- this._chainedTweens[i].stop();
361
+ loader.salt = this.salt;
362
+ loader.manager = manager;
363
+ loader.setPath(path);
364
+ loader.setResourcePath(resourcePath);
365
+ const loadCallback = (gltf)=>{
366
+ const node = gltf.scene;
367
+ node.animations.push(...gltf.animations);
368
+ onLoad(Loader._setUserData(node));
369
+ };
370
+ if (buffer) {
371
+ loader.parse(buffer, resourcePath, loadCallback, onError);
372
+ } else {
373
+ loader.load(url, loadCallback, onProgress, onError);
697
374
  }
698
- return this;
699
- }
700
- group(group = mainGroup) {
701
- this._group = group;
702
- return this;
703
- }
704
- call(callback) {
705
- this._onFinishCallback = callback;
706
- return this;
707
- }
708
- delay(amount = 0) {
709
- this._delayTime = amount;
710
- return this;
711
- }
712
- union(headTween, tailTween) {
713
- this._headTween = headTween;
714
- this._tailTween = tailTween.chain(this);
715
- return this;
716
- }
717
- repeat(times = 0) {
718
- this._initialRepeat = times;
719
- this._repeat = times;
720
- return this;
721
- }
722
- repeatDelay(amount) {
723
- this._repeatDelayTime = amount;
724
- return this;
725
- }
726
- yoyo(yoyo = false) {
727
- this._yoyo = yoyo;
728
- return this;
729
- }
730
- easing(easingFunction = Easing.Linear.None) {
731
- this._easingFunction = easingFunction;
732
- return this;
733
- }
734
- interpolation(interpolationFunction = Interpolation.Linear) {
735
- this._interpolationFunction = interpolationFunction;
736
- return this;
737
- }
738
- // eslint-disable-next-line
739
- chain(...tweens) {
740
- this._chainedTweens = tweens;
741
- return this;
742
- }
743
- unchain(...tweens) {
744
- tweens.forEach((tween)=>{
745
- let index = this._chainedTweens.findIndex((v)=>v === tween);
746
- if (index > -1) this._chainedTweens.splice(index, 1);
747
- });
748
- return this;
749
- }
750
- onStart(callback) {
751
- this._onStartCallback = callback;
752
- return this;
753
375
  }
754
- onEveryStart(callback) {
755
- this._onEveryStartCallback = callback;
756
- return this;
757
- }
758
- onUpdate(callback) {
759
- this._onUpdateCallback = callback;
760
- return this;
376
+ constructor(...args){
377
+ super(...args);
378
+ this.extension = [
379
+ "bin"
380
+ ];
381
+ this.salt = 255;
761
382
  }
762
- onRepeat(callback) {
763
- this._onRepeatCallback = callback;
764
- return this;
383
+ }
384
+ class CustomLoader extends GLTFLoader$1 {
385
+ parse(data, path, onLoad, onError) {
386
+ super.parse(glbDecode(data, this.salt), path, onLoad, onError);
765
387
  }
766
- onComplete(callback) {
767
- this._onCompleteCallback = callback;
768
- return this;
388
+ constructor(...args){
389
+ super(...args);
390
+ this.salt = 255;
769
391
  }
770
- onStop(callback) {
771
- this._onStopCallback = callback;
772
- return this;
392
+ }
393
+ const BINARY_EXTENSION_HEADER_MAGIC = 'glTF';
394
+ const BINARY_EXTENSION_HEADER_LENGTH = 12;
395
+ function encryptArray(array, salt) {
396
+ for(let i = 0, n = array.length; i < n; i++){
397
+ array[i] ^= salt;
773
398
  }
774
- /**
775
- * @returns true if the tween is still playing after the update, false
776
- * otherwise (calling update on a paused tween still returns true because
777
- * it is still playing, just paused).
778
- */ update(time, autoStart = true) {
779
- if (this._isPaused) return true;
780
- const endTime = this._startTime + this._duration;
781
- if (!this._goToEnd && !this._isPlaying) {
782
- if (time > endTime) return false;
783
- if (autoStart) this.start(time, true);
784
- }
785
- this._goToEnd = false;
786
- if (time < this._startTime) {
787
- return true;
788
- }
789
- if (this._onStartCallbackFired === false) {
790
- if (this._onStartCallback) {
791
- this._onStartCallback(this._object);
792
- }
793
- this._onStartCallbackFired = true;
794
- }
795
- if (this._onEveryStartCallbackFired === false) {
796
- if (this._onEveryStartCallback) {
797
- this._onEveryStartCallback(this._object);
798
- }
799
- this._onEveryStartCallbackFired = true;
800
- }
801
- const elapsedTime = time - this._startTime;
802
- var _this__repeatDelayTime;
803
- const durationAndDelay = this._duration + ((_this__repeatDelayTime = this._repeatDelayTime) != null ? _this__repeatDelayTime : this._delayTime);
804
- const totalTime = this._duration + this._repeat * durationAndDelay;
805
- const elapsed = this._calculateElapsedPortion(elapsedTime, durationAndDelay, totalTime);
806
- const value = this._easingFunction(elapsed);
807
- if (elapsed === 1) {
808
- if (this._onFinishCallback) {
809
- this._onFinishCallback(this._object);
810
- }
811
- if (this._headTween) {
812
- if (this._headTweenStartFired === false) {
813
- this._headTweenStartFired = true;
814
- this._headTween.start(this._startTime + this._duration);
815
- this._isPlaying = false;
816
- return false;
817
- }
818
- }
819
- }
820
- const status = this._calculateCompletionStatus(elapsedTime, durationAndDelay);
821
- if (status === 'repeat') {
822
- // the current update is happening after the instant the tween repeated
823
- this._processRepetition(elapsedTime, durationAndDelay);
824
- }
825
- this._updateProperties(this._object, this._valuesStart, this._valuesEnd, value);
826
- if (status === 'about-to-repeat') {
827
- // the current update is happening at the exact instant the tween is going to repeat
828
- // the values should match the end of the tween, not the beginning,
829
- // that's why _processRepetition happens after _updateProperties
830
- this._processRepetition(elapsedTime, durationAndDelay);
831
- }
832
- if (this._onUpdateCallback) {
833
- this._onUpdateCallback(this._object, elapsed);
834
- }
835
- if (status === 'repeat' || status === 'about-to-repeat') {
836
- if (this._onRepeatCallback) {
837
- this._onRepeatCallback(this._object);
838
- }
839
- if (this._headTween) {
840
- this._headTweenStartFired = false;
841
- this._initialRepeat = this._repeat;
842
- }
843
- this._onEveryStartCallbackFired = false;
844
- } else if (status === 'completed') {
845
- this._isPlaying = false;
846
- if (this._tailTween) {
847
- this._tailTween.unchain(this);
848
- }
849
- if (this._onCompleteCallback) {
850
- this._onCompleteCallback(this._object);
851
- }
852
- for(let i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++){
853
- // Make the chained tweens start exactly at the time they should,
854
- // even if the `update()` method was called way past the duration of the tween
855
- this._chainedTweens[i].start(this._startTime + this._duration, false);
856
- }
857
- }
858
- return status !== 'completed';
859
- }
860
- _calculateElapsedPortion(elapsedTime, durationAndDelay, totalTime) {
861
- if (this._duration === 0 || elapsedTime > totalTime) {
862
- return 1;
863
- }
864
- const timeIntoCurrentRepeat = elapsedTime % durationAndDelay;
865
- const portion = Math.min(timeIntoCurrentRepeat / this._duration, 1);
866
- if (portion === 0 && elapsedTime !== 0 && elapsedTime % this._duration === 0) {
867
- return 1;
868
- }
869
- return portion;
870
- }
871
- _calculateCompletionStatus(elapsedTime, durationAndDelay) {
872
- if (this._duration !== 0 && elapsedTime < this._duration) {
873
- return 'playing';
874
- }
875
- if (this._repeat <= 0) {
876
- return 'completed';
877
- }
878
- if (elapsedTime === this._duration) {
879
- return 'about-to-repeat';
880
- }
881
- return 'repeat';
399
+ return array;
400
+ }
401
+ function glbDecode(buffer, salt = 255) {
402
+ encryptArray(new Uint8Array(buffer, 0, 4), salt);
403
+ const headerView = new DataView(buffer, 0, BINARY_EXTENSION_HEADER_LENGTH);
404
+ const textDecoder = new TextDecoder();
405
+ const header = {
406
+ magic: textDecoder.decode(new Uint8Array(buffer.slice(0, 4))),
407
+ version: headerView.getUint32(4, true),
408
+ length: headerView.getUint32(8, true)
409
+ };
410
+ if (header.magic !== BINARY_EXTENSION_HEADER_MAGIC) {
411
+ throw new Error('Unsupported glTF-Binary header.');
412
+ } else if (header.version < 2.0) {
413
+ throw new Error('Legacy binary file detected.');
414
+ }
415
+ const chunkContentsLength = header.length - BINARY_EXTENSION_HEADER_LENGTH;
416
+ const chunkView = new DataView(buffer, BINARY_EXTENSION_HEADER_LENGTH);
417
+ let chunkIndex = 0;
418
+ while(chunkIndex < chunkContentsLength){
419
+ const chunkLength = chunkView.getUint32(chunkIndex, true);
420
+ chunkIndex += 4;
421
+ encryptArray(new Uint8Array(buffer, BINARY_EXTENSION_HEADER_LENGTH + chunkIndex, chunkLength + 4), salt);
422
+ chunkIndex += 4;
423
+ chunkIndex += chunkLength;
424
+ }
425
+ return buffer;
426
+ }
427
+
428
+ /******************************************************************************
429
+ Copyright (c) Microsoft Corporation.
430
+
431
+ Permission to use, copy, modify, and/or distribute this software for any
432
+ purpose with or without fee is hereby granted.
433
+
434
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
435
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
436
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
437
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
438
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
439
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
440
+ PERFORMANCE OF THIS SOFTWARE.
441
+ ***************************************************************************** */
442
+ /* global Reflect, Promise, SuppressedError, Symbol */
443
+
444
+
445
+ function __decorate(decorators, target, key, desc) {
446
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
447
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
448
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
449
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
450
+ }
451
+
452
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
453
+ var e = new Error(message);
454
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
455
+ };
456
+
457
+ const { clamp: clamp$4 } = MathUtils;
458
+ const { min, max: max$1, exp } = Math;
459
+ const kNegligibleResidual = 0.01;
460
+ const kLogNegligibleResidual = Math.log(kNegligibleResidual) // -4.605170186;
461
+ ;
462
+ function exponentialDamp(current, target, dampTime, deltaTime) {
463
+ let k = -kLogNegligibleResidual / dampTime;
464
+ return current + (target - current) * (1 - exp(-k * deltaTime));
465
+ }
466
+ // cuve like exponentialDecay but cost less
467
+ function quarticDamp(current, target, dampTime, deltaTime) {
468
+ let t = 1 - min(deltaTime, dampTime) / dampTime;
469
+ let tt = t * t;
470
+ return current + (target - current) * (1 - tt * tt);
471
+ }
472
+ function smoothDamp(state, current, target, smoothTime, maxSpeed, deltaTime) {
473
+ if (state._velocity === undefined) {
474
+ state._velocity = 0;
882
475
  }
883
- _processRepetition(elapsedTime, durationAndDelay) {
884
- const completeCount = Math.min(durationAndDelay > 0 ? Math.trunc((elapsedTime - this._duration) / durationAndDelay) + 1 : 1, this._repeat);
885
- if (isFinite(this._repeat)) {
886
- this._repeat -= completeCount;
887
- }
888
- // Reassign starting values, restart by making startTime = now
889
- for(const property in this._valuesStartRepeat){
890
- const valueEnd = this._valuesEnd[property];
891
- if (!this._yoyo && typeof valueEnd === 'string') {
892
- this._valuesStartRepeat[property] = this._valuesStartRepeat[property] + parseFloat(valueEnd);
893
- }
894
- if (this._yoyo) {
895
- this._swapEndStartRepeatValues(property);
896
- }
897
- this._valuesStart[property] = this._valuesStartRepeat[property];
898
- }
899
- if (this._yoyo) {
900
- this._reversed = !this._reversed;
901
- }
902
- this._startTime += durationAndDelay * completeCount;
476
+ smoothTime = max$1(0.0001, smoothTime);
477
+ let num = 2 / smoothTime;
478
+ let num2 = num * deltaTime;
479
+ let num3 = 1 / (1 + num2 + 0.48 * num2 * num2 + 0.235 * num2 * num2 * num2);
480
+ let num4 = current - target;
481
+ let num5 = target;
482
+ let num6 = maxSpeed * smoothTime;
483
+ num4 = clamp$4(num4, -num6, num6);
484
+ target = current - num4;
485
+ let num7 = (state._velocity + num * num4) * deltaTime;
486
+ state._velocity = (state._velocity - num * num7) * num3;
487
+ let num8 = target + (num4 + num7) * num3;
488
+ if (num5 - current > 0 == num8 > num5) {
489
+ num8 = num5;
490
+ state._velocity = (num8 - num5) / deltaTime;
903
491
  }
904
- _updateProperties(_object, _valuesStart, _valuesEnd, value) {
905
- for(const property in _valuesEnd){
906
- // Don't update properties that do not exist in the source object
907
- if (_valuesStart[property] === undefined) {
908
- continue;
909
- }
910
- const start = _valuesStart[property] || 0;
911
- let end = _valuesEnd[property];
912
- const startIsArray = Array.isArray(_object[property]);
913
- const endIsArray = Array.isArray(end);
914
- const isInterpolationList = !startIsArray && endIsArray;
915
- if (isInterpolationList) {
916
- _object[property] = this._interpolationFunction(end, value);
917
- } else if (typeof end === 'object' && end) {
918
- // eslint-disable-next-line
919
- // @ts-ignore FIXME?
920
- let des = getPropertyDescriptor(_object, property);
921
- if ((des == null ? void 0 : des.set) || (des == null ? void 0 : des.writable)) {
922
- _object[property] = this._updateProperties(_object[property], start, end, value);
923
- } else {
924
- this._updateProperties(_object[property], start, end, value);
925
- }
926
- } else {
927
- // Parses relative end values with start as base (e.g.: +10, -3)
928
- end = this._handleRelativeValue(start, end);
929
- // Protect against non numeric properties.
930
- if (typeof end === 'number') {
931
- // eslint-disable-next-line
932
- // @ts-ignore FIXME?
933
- _object[property] = start + (end - start) * value;
934
- }
935
- }
936
- }
937
- return _object;
492
+ return num8;
493
+ }
494
+ function Quat_exponentialDamp(current, target, dampTime, deltaTime, out = current) {
495
+ return out.copy(current).slerp(target, exponentialDamp(0, 1, dampTime, deltaTime));
496
+ }
497
+ function Quat_quarticDamp(current, target, dampTime, deltaTime, out = current) {
498
+ return out.copy(current).slerp(target, quarticDamp(0, 1, dampTime, deltaTime));
499
+ }
500
+ function Quat_smoothDamp(current, target, dampTime, deltaTime, out = current) {
501
+ return out.copy(current).slerp(target, smoothDamp(out, 0, 1, dampTime, Infinity, deltaTime));
502
+ }
503
+ function Vec3_smoothDamp(current, target, dampTime, deltaTime, out = current) {
504
+ return out.copy(current).lerp(target, smoothDamp(out, 0, 1, dampTime, Infinity, deltaTime));
505
+ }
506
+
507
+ const Vector3_UNIT_X = Object.freeze(new Vector3(1, 0, 0));
508
+ const Vector3_UNIT_Y = Object.freeze(new Vector3(0, 1, 0));
509
+ const Vector3_UNIT_Z = Object.freeze(new Vector3(0, 0, 1));
510
+ const Vector3_RIGHT = Object.freeze(new Vector3(1, 0, 0));
511
+ const Vector3_UP = Object.freeze(new Vector3(0, 1, 0));
512
+ const Vector3_ZERO = Object.freeze(new Vector3(0, 0, 0));
513
+ const Vector3_ONE = Object.freeze(new Vector3(1, 1, 1));
514
+ const Vector3_NEG_ONE = Object.freeze(new Vector3(-1, -1, -1));
515
+
516
+ const { clamp: clamp$3 } = MathUtils;
517
+ const { max, abs: abs$1, acos } = Math;
518
+ const EPSILON = 1.e-6;
519
+ const __deltaMap = new Map();
520
+ __deltaMap.set(Vector3, new Vector3());
521
+ __deltaMap.set(Vector2, new Vector2());
522
+ function VInterpTo(current, target, deltaTime, speed, out = current, epsilon = EPSILON) {
523
+ if (speed <= 0) {
524
+ return out.copy(target);
938
525
  }
939
- _handleRelativeValue(start, end) {
940
- if (typeof end !== 'string') {
941
- return end;
942
- }
943
- if (end.charAt(0) === '+' || end.charAt(0) === '-') {
944
- return start + parseFloat(end);
945
- }
946
- return parseFloat(end);
526
+ let dist = __deltaMap.get(current.constructor).copy(target).sub(current);
527
+ if (dist.lengthSq() < epsilon) {
528
+ return out.copy(target);
947
529
  }
948
- _swapEndStartRepeatValues(property) {
949
- const tmp = this._valuesStartRepeat[property];
950
- const endValue = this._valuesEnd[property];
951
- if (typeof endValue === 'string') {
952
- this._valuesStartRepeat[property] = this._valuesStartRepeat[property] + parseFloat(endValue);
530
+ return out.copy(current).add(dist.multiplyScalar(clamp$3(deltaTime * speed, 0, 1)));
531
+ }
532
+ function VInterpConstantTo(current, target, deltaTime, speed, out = current) {
533
+ let delta = __deltaMap.get(current.constructor).copy(target).sub(current);
534
+ let deltaM = delta.length();
535
+ let maxStep = speed * deltaTime;
536
+ if (deltaM > maxStep) {
537
+ if (maxStep > 0) {
538
+ let deltaN = delta.multiplyScalar(1 / deltaM);
539
+ return out.copy(current).add(deltaN);
953
540
  } else {
954
- this._valuesStartRepeat[property] = this._valuesEnd[property];
955
- }
956
- this._valuesEnd[property] = tmp;
957
- }
958
- constructor(_object, _group = mainGroup){
959
- this._object = _object;
960
- this._group = _group;
961
- this._isPaused = false;
962
- this._pauseStart = 0;
963
- this._valuesStart = {};
964
- this._valuesEnd = {};
965
- this._valuesStartRepeat = {};
966
- this._duration = 0;
967
- this._isDynamic = false;
968
- this._initialRepeat = 0;
969
- this._repeat = 0;
970
- this._yoyo = false;
971
- this._isPlaying = false;
972
- this._reversed = false;
973
- this._delayTime = 0;
974
- this._startTime = 0;
975
- this._easingFunction = Easing.Linear.None;
976
- this._interpolationFunction = Interpolation.Linear;
977
- this._chainedTweens = [];
978
- this._onStartCallbackFired = false;
979
- this._onEveryStartCallbackFired = false;
980
- this._id = Sequence.nextId();
981
- this._isChainStopped = false;
982
- this._propertiesAreSetUp = false;
983
- this._headTween = null;
984
- this._tailTween = null;
985
- this._headTweenStartFired = false;
986
- this._goToEnd = false;
541
+ return out.copy(current);
542
+ }
987
543
  }
544
+ return out.copy(target);
988
545
  }
989
- function getPropertyDescriptor(obj, prop) {
990
- while(obj){
991
- let desc = Object.getOwnPropertyDescriptor(obj, prop);
992
- if (desc) return desc;
993
- obj = Object.getPrototypeOf(obj);
994
- }
995
- return undefined;
546
+ function Quat_Equals(a, b, epsilon = EPSILON) {
547
+ return abs$1(a.x - b.x) <= epsilon * max(1., abs$1(a.x), abs$1(b.x)) && abs$1(a.y - b.y) <= epsilon * max(1., abs$1(a.y), abs$1(b.y)) && abs$1(a.z - b.z) <= epsilon * max(1., abs$1(a.z), abs$1(b.z)) && abs$1(a.w - b.w) <= epsilon * max(1., abs$1(a.w), abs$1(b.w));
996
548
  }
997
-
998
- class TweenChain {
999
- start() {
1000
- if (this._group) {
1001
- this._group.removeOf(this._obj);
1002
- }
1003
- this._tween.start(now());
1004
- return this;
549
+ function Quat_AngularDistance(a, b) {
550
+ let innerProd = a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
551
+ return acos(2 * innerProd * innerProd - 1);
552
+ }
553
+ function QInterpTo(current, target, deltaTime, speed, epsilon = EPSILON) {
554
+ if (speed <= 0) {
555
+ return target;
1005
556
  }
1006
- pause() {
1007
- this._tween.pause(now());
1008
- return this;
557
+ if (Quat_Equals(current, target, epsilon)) {
558
+ return target;
1009
559
  }
1010
- stop() {
1011
- this._tween.stop();
1012
- return this;
560
+ return current.slerp(target, clamp$3(speed * deltaTime, 0, 1));
561
+ }
562
+ function QInterpConstantTo(current, target, deltaTime, speed, out = current) {
563
+ if (speed <= 0) {
564
+ return out.copy(target);
1013
565
  }
1014
- repeat(times) {
1015
- this._chainedTween.repeat(times);
1016
- return this;
566
+ if (Quat_Equals(current, target)) {
567
+ return out.copy(target);
1017
568
  }
1018
- union() {
1019
- this._chainedTween = this._tween = new Tween(this._obj, this._group).union(this._tween, this._chainedTween);
1020
- return this;
569
+ let deltaSpeed = clamp$3(speed * deltaTime, 0, 1);
570
+ let angularDist = max(Quat_AngularDistance(current, target), EPSILON);
571
+ return out.copy(current).slerp(target, clamp$3(deltaSpeed / angularDist, 0, 1));
572
+ }
573
+ //非线性
574
+ function FInterpTo(current, target, deltaTime, speed, epsilon = EPSILON) {
575
+ if (speed <= 0) {
576
+ return target;
1021
577
  }
1022
- call(callback) {
1023
- this._chainTween().call(callback);
1024
- return this;
578
+ let dist = target - current;
579
+ if (abs$1(dist) < epsilon) {
580
+ return target;
1025
581
  }
1026
- delay(amount) {
1027
- this._chainTween().delay(amount);
1028
- return this;
582
+ return current + dist * clamp$3(speed * deltaTime, 0, 1);
583
+ }
584
+ //线性插值
585
+ function FInterpConstantTo(current, target, deltaTime, speed, epsilon = EPSILON) {
586
+ let dist = target - current;
587
+ if (abs$1(dist) < epsilon) {
588
+ return target;
1029
589
  }
1030
- to(properties, duration, props) {
1031
- let tween = this._chainTween().to(properties, duration);
1032
- if (props) {
1033
- if (props.from) tween.from(props.from);
1034
- if (props.easing) tween.easing(props.easing);
1035
- if (props.onStart) tween.onStart(props.onStart);
1036
- if (props.onStop) tween.onStop(props.onStop);
1037
- if (props.onComplete) tween.onComplete(props.onComplete);
1038
- if (props.onUpdate) tween.onUpdate(props.onUpdate);
1039
- if (props.onRepeat) tween.onRepeat(props.onRepeat);
1040
- }
590
+ let step = speed * deltaTime;
591
+ return current + clamp$3(dist, -step, step);
592
+ }
593
+
594
+ const { lerp: lerp$1, clamp: clamp$2 } = MathUtils;
595
+ function catmullRom(t, p0, p1, p2, p3) {
596
+ const v0 = (p2 - p0) * 0.5;
597
+ const v1 = (p3 - p1) * 0.5;
598
+ const t2 = t * t;
599
+ const t3 = t * t2;
600
+ return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
601
+ }
602
+ class CurvePoint {
603
+ set(x, y) {
604
+ this.x = x;
605
+ this.y = y;
1041
606
  return this;
1042
607
  }
1043
- _chainTween() {
1044
- let tween = this._tween;
1045
- if (this._chainedTween) {
1046
- tween = new Tween(this._obj, this._group);
1047
- this._chainedTween.chain(tween);
1048
- }
1049
- this._chainedTween = tween;
1050
- return tween;
608
+ lerp(p, t, out = this) {
609
+ out.x = lerp$1(this.x, p.x, t);
610
+ out.y = lerp$1(this.y, p.y, t);
611
+ return out;
1051
612
  }
1052
- constructor(object, group){
1053
- this._obj = object;
1054
- this._group = group;
1055
- this._tween = new Tween(object, group);
613
+ constructor(x = 0, y = 0, mode = 0){
614
+ this.x = x;
615
+ this.y = y;
616
+ this.mode = mode;
1056
617
  }
1057
618
  }
1058
-
1059
- class TweenManager {
1060
- update(dt) {
1061
- this._group.update(now());
619
+ class AnimationCurve {
620
+ _getInterpolant(samples) {
621
+ if (this._samples !== samples) {
622
+ this._samples = samples;
623
+ this._interpolant = new LinearInterpolant(new Float32Array(samples), new Float32Array(samples), 1, new Float32Array(samples));
624
+ }
625
+ return this._interpolant;
1062
626
  }
1063
- timeline(target) {
1064
- return new TweenChain(target, this._group);
627
+ createCurvePoint(x, y, mode) {
628
+ return new CurvePoint(x, y, mode);
1065
629
  }
1066
- killAll() {
1067
- this._group.removeAll();
630
+ resample(samples = 100) {
631
+ const step = 1 / (samples - 1);
632
+ const interpolant = this._getInterpolant(samples);
633
+ const times = interpolant.parameterPositions;
634
+ const values = interpolant.sampleValues;
635
+ const point = this.createCurvePoint();
636
+ for(let i = 0; i < samples; i++){
637
+ this.getPoint(i * step, point);
638
+ times[i] = point.x;
639
+ values[i] = point.y;
640
+ }
1068
641
  }
1069
- killOf(target) {
1070
- this._group.removeOf(target);
642
+ evaluate(t) {
643
+ if (this.needsUpdate) {
644
+ this.needsUpdate = false;
645
+ this.resample();
646
+ }
647
+ return this._interpolant.evaluate(t)[0];
1071
648
  }
1072
- constructor(){
1073
- this._group = new TweenGroup();
649
+ getPoint(t, out) {
650
+ const points = this.points;
651
+ if (t <= 0) {
652
+ return out.set(t, points[0].y);
653
+ }
654
+ if (t >= 1) {
655
+ return out.set(t, points[points.length - 1].y);
656
+ }
657
+ const p = (points.length - 1) * t;
658
+ const intPoint = Math.floor(p);
659
+ const weight = p - intPoint;
660
+ const p0 = points[intPoint === 0 ? intPoint : intPoint - 1];
661
+ const p1 = points[intPoint];
662
+ const p2 = points[intPoint > points.length - 2 ? points.length - 1 : intPoint + 1];
663
+ const p3 = points[intPoint > points.length - 3 ? points.length - 1 : intPoint + 2];
664
+ if (p1.mode === 1 || p0 === p1 && p2.mode === 1) {
665
+ return p1.lerp(p2, weight, out);
666
+ }
667
+ return out.set(clamp$2(catmullRom(weight, p0.x, p1.x, p2.x, p3.x), 0, 1), clamp$2(catmullRom(weight, p0.y, p1.y, p2.y, p3.y), 0, 1));
1074
668
  }
1075
- }
1076
-
1077
- class aLoader {
1078
- static _setUserData(node) {
1079
- const keys = aLoader._texKeys;
1080
- const meshes = [];
1081
- const textures = {};
1082
- const materials = {};
1083
- const queue = [
1084
- node
1085
- ];
1086
- while(queue.length !== 0){
1087
- let object = queue.shift();
1088
- if (object.isMesh) {
1089
- meshes.push(object);
1090
- const mat = object.material;
1091
- if (Array.isArray(mat)) mat.forEach((v)=>materials[v.uuid] = v);
1092
- else materials[mat.uuid] = mat;
1093
- }
1094
- queue.push(...object.children);
1095
- }
1096
- Object.values(materials).forEach((mat)=>{
1097
- keys.forEach((k)=>{
1098
- let tex = mat[k];
1099
- if (tex) {
1100
- textures[tex.uuid] = tex;
1101
- }
1102
- });
1103
- });
1104
- Object.assign(node.userData, {
1105
- meshes,
1106
- materials,
1107
- textures
1108
- });
1109
- return node;
1110
- }
1111
- constructor(manager){
1112
- this.manager = manager;
1113
- }
1114
- }
1115
- aLoader._texKeys = [
1116
- "map",
1117
- "alphaMap",
1118
- "aoMap",
1119
- "bumpMap",
1120
- "displacementMap",
1121
- "emissiveMap",
1122
- "envMap",
1123
- "lightMap",
1124
- "metalnessMap",
1125
- "normalMap",
1126
- "roughnessMap",
1127
- "specularMap",
1128
- "alphaMap"
1129
- ];
1130
-
1131
- class aEXRLoader extends aLoader {
1132
- load({ url, path, resourcePath, manager, texSettings, onLoad, onProgress, onError }) {
1133
- let loader = this._loader;
1134
- if (loader === undefined) {
1135
- loader = this._loader = new EXRLoader();
1136
- }
1137
- loader.manager = manager;
1138
- loader.setPath(path);
1139
- loader.setResourcePath(resourcePath);
1140
- loader.load(url, (tex)=>onLoad(Object.assign(tex, texSettings)), onProgress, onError);
1141
- }
1142
- constructor(...args){
1143
- super(...args);
1144
- this.extension = [
1145
- "exr"
1146
- ];
669
+ constructor(name = "", points = [
670
+ new CurvePoint(0, 0),
671
+ new CurvePoint(1, 1)
672
+ ]){
673
+ this.name = name;
674
+ this.points = points;
675
+ this.needsUpdate = true;
676
+ this.isAnimationCurve = true;
677
+ this._samples = 100;
678
+ this._interpolant = new LinearInterpolant(new Float32Array(100), new Float32Array(100), 1, new Float32Array(100));
1147
679
  }
1148
680
  }
1149
681
 
1150
- class aFBXLoader extends aLoader {
1151
- load({ url, buffer, path, resourcePath, manager, onLoad, onProgress, onError }) {
1152
- let loader = this._loader;
1153
- if (loader === undefined) {
1154
- loader = this._loader = new FBXLoader();
1155
- }
1156
- loader.manager = manager;
1157
- loader.setPath(path);
1158
- loader.setResourcePath(resourcePath);
1159
- const loadCallback = (node)=>{
1160
- onLoad(aLoader._setUserData(node));
1161
- };
1162
- if (buffer) {
1163
- loadCallback(loader.parse(buffer, resourcePath));
682
+ const { floor } = Math;
683
+ // Copyright (C) 2016 Keijiro Takahashi
684
+ // https://mrl.cs.nyu.edu/~perlin/noise/
685
+ class Perlin {
686
+ static Noise(x, y, z) {
687
+ let fade = Perlin._Fade;
688
+ let grad = Perlin._Grad;
689
+ let lerp = Perlin._Lerp;
690
+ let p = Perlin._Permutation;
691
+ if (y !== undefined && z !== undefined) {
692
+ let xi = floor(x);
693
+ let yi = floor(y);
694
+ let zi = floor(z);
695
+ let X = xi & 0xff; // FIND UNIT CUBE THAT
696
+ let Y = yi & 0xff; // CONTAINS POINT.
697
+ let Z = zi & 0xff;
698
+ x -= xi; // FIND RELATIVE X,Y,Z
699
+ y -= yi; // OF POINT IN CUBE.
700
+ z -= zi;
701
+ let u = fade(x); // COMPUTE FADE CURVES
702
+ let v = fade(y); // FOR EACH OF X,Y,Z.
703
+ let w = fade(z);
704
+ let A = p[X] + Y, AA = p[A] + Z, AB = p[A + 1] + Z; // HASH COORDINATES OF
705
+ let B = p[X + 1] + Y, BA = p[B] + Z, BB = p[B + 1] + Z; // THE 8 CUBE CORNERS,
706
+ return lerp(w, lerp(v, lerp(u, grad(p[AA], x, y, z), grad(p[BA], x - 1, y, z)), lerp(u, grad(p[AB], x, y - 1, z), grad(p[BB], x - 1, y - 1, z))), lerp(v, lerp(u, grad(p[AA + 1], x, y, z - 1), grad(p[BA + 1], x - 1, y, z - 1)), lerp(u, grad(p[AB + 1], x, y - 1, z - 1), grad(p[BB + 1], x - 1, y - 1, z - 1))));
707
+ } else if (y !== undefined) {
708
+ let xi = floor(x);
709
+ let yi = floor(y);
710
+ let X = xi & 0xff;
711
+ let Y = yi & 0xff;
712
+ x -= xi;
713
+ y -= yi;
714
+ let u = fade(x);
715
+ let v = fade(y);
716
+ let A = p[X] + Y & 0xff;
717
+ let B = p[X + 1] + Y & 0xff;
718
+ return lerp(v, lerp(u, grad(p[A], x, y), grad(p[B], x - 1, y)), lerp(u, grad(p[A + 1], x, y - 1), grad(p[B + 1], x - 1, y - 1)));
1164
719
  } else {
1165
- loader.load(url, loadCallback, onProgress, onError);
720
+ let xi = floor(x);
721
+ let X = xi & 0xff;
722
+ x -= xi;
723
+ let u = fade(x);
724
+ return lerp(u, grad(p[X], x), grad(p[X + 1], x - 1));
1166
725
  }
1167
726
  }
1168
- constructor(...args){
1169
- super(...args);
1170
- this.extension = [
1171
- "fbx"
1172
- ];
1173
- }
1174
- }
1175
-
1176
- class aGLTFLoader extends aLoader {
1177
- load({ url, buffer, path, resourcePath, dracoPath, manager, onLoad, onProgress, onError }) {
1178
- let dracoLoader = this._dracoLoader;
1179
- if (dracoLoader === undefined) {
1180
- dracoLoader = this._dracoLoader = new DRACOLoader();
1181
- }
1182
- dracoLoader.manager = manager;
1183
- dracoLoader.setDecoderPath(dracoPath);
1184
- let loader = this._loader;
1185
- if (loader === undefined) {
1186
- loader = this._loader = new GLTFLoader();
1187
- loader.setDRACOLoader(dracoLoader);
1188
- loader.setMeshoptDecoder(MeshoptDecoder);
1189
- }
1190
- loader.manager = manager;
1191
- loader.setPath(path);
1192
- loader.setResourcePath(resourcePath);
1193
- const loadCallback = (gltf)=>{
1194
- const node = gltf.scene;
1195
- node.animations.push(...gltf.animations);
1196
- onLoad(aLoader._setUserData(node));
1197
- };
1198
- if (buffer) {
1199
- loader.parse(buffer, resourcePath, loadCallback, onError);
727
+ static Fbm(octave, x, y, z) {
728
+ let f = 0;
729
+ let w = 0.5;
730
+ let noise = Perlin.Noise;
731
+ if (y !== undefined && z !== undefined) {
732
+ for(let i = 0; i < octave; i++){
733
+ f += w * noise(x, y, z);
734
+ x *= 2.0;
735
+ y *= 2.0;
736
+ z *= 2.0;
737
+ w *= 0.5;
738
+ }
739
+ } else if (y !== undefined) {
740
+ for(let i = 0; i < octave; i++){
741
+ f += w * noise(x, y);
742
+ x *= 2.0;
743
+ y *= 2.0;
744
+ w *= 0.5;
745
+ }
1200
746
  } else {
1201
- loader.load(url, loadCallback, onProgress, onError);
747
+ for(let i = 0; i < octave; i++){
748
+ f += w * noise(x);
749
+ x *= 2.0;
750
+ w *= 0.5;
751
+ }
1202
752
  }
753
+ return f;
1203
754
  }
1204
- constructor(...args){
1205
- super(...args);
1206
- this.extension = [
1207
- "gltf",
1208
- "glb"
1209
- ];
1210
- }
1211
- }
1212
-
1213
- class aHDRLoader extends aLoader {
1214
- load({ url, path, resourcePath, manager, texSettings, onLoad, onProgress, onError }) {
1215
- let loader = this._loader;
1216
- if (loader === undefined) {
1217
- loader = this._loader = new RGBELoader();
1218
- }
1219
- loader.manager = manager;
1220
- loader.setPath(path);
1221
- loader.setResourcePath(resourcePath);
1222
- const settings = Object.assign({
1223
- mapping: EquirectangularReflectionMapping
1224
- }, texSettings);
1225
- loader.load(url, (tex)=>onLoad(Object.assign(tex, settings)), onProgress, onError);
755
+ static _Fade(t) {
756
+ return t * t * t * (t * (t * 6 - 15) + 10);
1226
757
  }
1227
- constructor(...args){
1228
- super(...args);
1229
- this.extension = [
1230
- "hdr"
1231
- ];
758
+ static _Lerp(t, a, b) {
759
+ return a + t * (b - a);
1232
760
  }
1233
- }
1234
-
1235
- class aJSONLoader extends aLoader {
1236
- load({ url, path, resourcePath, manager, onLoad, onProgress, onError }) {
1237
- let loader = this._loader;
1238
- if (loader === undefined) {
1239
- loader = this._loader = new FileLoader();
1240
- }
1241
- loader.manager = manager;
1242
- loader.setPath(path);
1243
- loader.setResourcePath(resourcePath);
1244
- loader.load(url, (file)=>onLoad(JSON.parse(file)), onProgress, onError);
1245
- }
1246
- constructor(...args){
1247
- super(...args);
1248
- this.extension = [
1249
- "json"
1250
- ];
1251
- }
1252
- }
1253
-
1254
- class aTextureLoader extends aLoader {
1255
- load({ url, path, resourcePath, manager, texSettings, onLoad, onProgress, onError }) {
1256
- let loader = this._loader;
1257
- if (loader === undefined) {
1258
- loader = this._loader = new TextureLoader();
1259
- }
1260
- loader.manager = manager;
1261
- loader.setPath(path);
1262
- loader.setResourcePath(resourcePath);
1263
- const loadCallback = (tex)=>{
1264
- tex.colorSpace = SRGBColorSpace;
1265
- onLoad(Object.assign(tex, texSettings));
1266
- };
1267
- loader.load(url, loadCallback, onProgress, onError);
1268
- }
1269
- constructor(...args){
1270
- super(...args);
1271
- this.extension = [
1272
- "png",
1273
- "jpg",
1274
- "webp",
1275
- "avif"
1276
- ];
1277
- }
1278
- }
1279
-
1280
- /******************************************************************************
1281
- Copyright (c) Microsoft Corporation.
1282
-
1283
- Permission to use, copy, modify, and/or distribute this software for any
1284
- purpose with or without fee is hereby granted.
1285
-
1286
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
1287
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
1288
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
1289
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
1290
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
1291
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1292
- PERFORMANCE OF THIS SOFTWARE.
1293
- ***************************************************************************** */
1294
- /* global Reflect, Promise, SuppressedError, Symbol */
1295
-
1296
-
1297
- function __decorate(decorators, target, key, desc) {
1298
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1299
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1300
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1301
- return c > 3 && r && Object.defineProperty(target, key, r), r;
1302
- }
1303
-
1304
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
1305
- var e = new Error(message);
1306
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
1307
- };
1308
-
1309
- class ClassProperties {
1310
- property(propertyKey, options = {}) {
1311
- this._properties[propertyKey] = options;
1312
- return this;
1313
- }
1314
- applyProperties(target) {
1315
- Object.assign(target, this._properties);
1316
- return target;
1317
- }
1318
- constructor(clsName){
1319
- this.clsName = clsName;
1320
- this._properties = Object.create(null);
1321
- }
1322
- }
1323
- class PropertyManager {
1324
- static _hasProperties(constructor) {
1325
- return PropertyManager._propertyMap.has(constructor);
1326
- }
1327
- static _getProperties(constructor, autoAdd = true) {
1328
- let props = PropertyManager._propertyMap.get(constructor);
1329
- if (props === undefined && autoAdd) {
1330
- props = Object.create(null);
1331
- PropertyManager._propertyMap.set(constructor, props);
1332
- }
1333
- return props;
1334
- }
1335
- static _getMergedProperties(constructor) {
1336
- let merged = null;
1337
- while(constructor !== Object.constructor.prototype){
1338
- let props = PropertyManager._getProperties(constructor, false);
1339
- if (props) {
1340
- if (merged === null) {
1341
- merged = Object.create(null);
1342
- }
1343
- Object.assign(merged, props);
1344
- }
1345
- constructor = Object.getPrototypeOf(constructor);
1346
- }
1347
- return merged;
1348
- }
1349
- static _getClassProperties(clsName, autoAdd = true) {
1350
- let props = PropertyManager._classMap.get(clsName);
1351
- if (props === undefined && autoAdd) {
1352
- props = new ClassProperties(clsName);
1353
- PropertyManager._classMap.set(clsName, props);
1354
- }
1355
- return props;
1356
- }
1357
- static _applyClassProperties(clsName, constructor) {
1358
- let cls = PropertyManager._getClassProperties(clsName, false);
1359
- if (cls) {
1360
- return cls.applyProperties(PropertyManager._getProperties(constructor));
1361
- } else {
1362
- return PropertyManager._getProperties(constructor, false);
1363
- }
1364
- }
1365
- }
1366
- PropertyManager._classMap = new Map();
1367
- PropertyManager._propertyMap = new Map();
1368
- function property(target, propertyKey) {
1369
- let options = null;
1370
- function normalized(target, propertyKey) {
1371
- PropertyManager._getProperties(target.constructor)[propertyKey] = options;
1372
- }
1373
- if (target === undefined) {
1374
- return property({});
1375
- } else if (typeof propertyKey === "undefined") {
1376
- options = target;
1377
- return normalized;
1378
- } else {
1379
- options = {};
1380
- normalized(target, propertyKey);
1381
- }
1382
- }
1383
-
1384
- const CinestationBlendStyle = {
1385
- Linear: Easing.Linear.None,
1386
- QuadraticIn: Easing.Quadratic.In,
1387
- QuadraticOut: Easing.Quadratic.Out,
1388
- QuadraticInOut: Easing.Quadratic.InOut
1389
- };
1390
- class CinestationBlendDefinition {
1391
- constructor(){
1392
- this.style = CinestationBlendStyle.QuadraticInOut;
1393
- this.time = 4;
1394
- }
1395
- }
1396
- __decorate([
1397
- property({
1398
- value: CinestationBlendStyle
1399
- })
1400
- ], CinestationBlendDefinition.prototype, "style", void 0);
1401
- __decorate([
1402
- property
1403
- ], CinestationBlendDefinition.prototype, "time", void 0);
1404
-
1405
- class ObjectInstance {
1406
- constructor(){
1407
- this.instanceId = ObjectInstance._instanceCount++;
1408
- this.uuid = MathUtils.generateUUID();
1409
- this.name = "";
1410
- this.type = "ObjectInstance";
1411
- }
1412
- }
1413
- ObjectInstance._instanceCount = 0;
1414
-
1415
- class Component extends ObjectInstance {
1416
- get enabled() {
1417
- return this._enabled;
1418
- }
1419
- set enabled(v) {
1420
- if (this._enabled !== v) {
1421
- this._enabled = v;
1422
- this.manager.componentScheduler.enableComponent(this, v);
1423
- }
1424
- }
1425
- _onPreDestroy() {
1426
- this.unscheduleAll();
1427
- this.manager.removeComponent(this.node, this);
1428
- if (this._enabled) {
1429
- this.manager.componentScheduler.enableComponent(this, false);
1430
- }
1431
- if (this.onDestroy && this.flags.OnLoadCalled) {
1432
- this.onDestroy();
1433
- }
1434
- }
1435
- schedule(callback, interval, repeat = -1) {
1436
- this.manager.scheduler.schedule(this, callback, interval, repeat);
1437
- }
1438
- unshedule(callback) {
1439
- this.manager.scheduler.unshedule(this, callback);
1440
- }
1441
- unscheduleAll() {
1442
- this.manager.scheduler.unscheduleAll(this);
1443
- }
1444
- destroy() {
1445
- if (this.flags.Destroyed) {
1446
- return false;
1447
- }
1448
- this.destroyImmediate();
1449
- return true;
1450
- }
1451
- destroyImmediate() {
1452
- if (this._onPreDestroy) {
1453
- this._onPreDestroy();
1454
- }
1455
- this.flags.Destroyed = true;
1456
- }
1457
- constructor(...args){
1458
- super(...args);
1459
- this._enabled = true;
1460
- this.isComponent = true;
1461
- this.type = "Component";
1462
- this.flags = {};
1463
- }
1464
- }
1465
-
1466
- const { clamp: clamp$4, lerp: lerp$1 } = MathUtils;
1467
- class CinestationBrain extends Component {
1468
- get vcam() {
1469
- return this._vcam;
1470
- }
1471
- get vcams() {
1472
- return this._vcams;
1473
- }
1474
- lastUpdate(dt) {
1475
- let vcam = this.getActiveCamera();
1476
- if (vcam == null) return;
1477
- this._vcams.forEach((v)=>{
1478
- if (!v.locked) {
1479
- v.enabled = v === vcam;
1480
- }
1481
- });
1482
- if (this._lerpTime < this.brainBlend.time) {
1483
- this._lerpTime += dt;
1484
- let t = clamp$4(this._lerpTime / this.brainBlend.time, 0, 1);
1485
- this._lerpToMainCamera(vcam, this.brainBlend.style(t));
1486
- } else {
1487
- this._lerpToMainCamera(vcam, 1);
1488
- }
1489
- }
1490
- activeCamera(vcam, time = 4) {
1491
- if (this._vcamSolo !== vcam) {
1492
- this._vcamSolo = vcam;
1493
- this._lerpTime = 0;
1494
- this.brainBlend.time = time;
1495
- }
1496
- }
1497
- addCamera(vcam) {
1498
- let index = this._vcams.indexOf(vcam);
1499
- if (index === -1) {
1500
- this._vcams.push(vcam);
1501
- }
1502
- }
1503
- removeCamera(vcam) {
1504
- let index = this._vcams.indexOf(vcam);
1505
- if (index !== -1) {
1506
- this._vcams.splice(index, 1);
1507
- }
1508
- }
1509
- getActiveCamera() {
1510
- return this._vcamSolo || this._vcams.filter((v)=>v.enabled || v.locked).sort((a, b)=>b.priority - a.priority)[0];
1511
- }
1512
- _lerpToMainCamera(vcam, t) {
1513
- const from = this.node, to = vcam;
1514
- const { lens, finalPosition, finalRotation } = to;
1515
- const isLensChanged = from.fov != lens.fov || from.near != lens.near || from.far != lens.far;
1516
- from.position.lerp(finalPosition, t);
1517
- from.quaternion.slerp(finalRotation, t);
1518
- from.fov = lerp$1(from.fov, lens.fov, t);
1519
- from.near = lens.near;
1520
- from.far = lens.far;
1521
- if (isLensChanged) {
1522
- from.updateProjectionMatrix();
1523
- }
1524
- }
1525
- constructor(...args){
1526
- super(...args);
1527
- this._vcam = null;
1528
- this._vcamSolo = null;
1529
- this._vcams = [];
1530
- this._lerpTime = 4;
1531
- this.brainBlend = new CinestationBlendDefinition();
1532
- }
1533
- }
1534
- __decorate([
1535
- property
1536
- ], CinestationBrain.prototype, "brainBlend", void 0);
1537
-
1538
- class Lens {
1539
- constructor(){
1540
- this.fov = 45;
1541
- this.near = 0.1;
1542
- this.far = 1000;
1543
- }
1544
- }
1545
- __decorate([
1546
- property
1547
- ], Lens.prototype, "fov", void 0);
1548
- __decorate([
1549
- property
1550
- ], Lens.prototype, "near", void 0);
1551
- __decorate([
1552
- property
1553
- ], Lens.prototype, "far", void 0);
1554
- class VirtualCamera extends Component {
1555
- get finalPosition() {
1556
- return this._finalPosition.copy(this.node.position).add(this.correctPosition);
1557
- }
1558
- get finalRotation() {
1559
- return this._finalRotation.copy(this.node.quaternion).multiply(this.correctRotation);
1560
- }
1561
- onLoad() {
1562
- const camera = this.viewer.camera;
1563
- this.node.isCamera = true;
1564
- this.lens.fov = camera.fov;
1565
- this.lens.near = camera.near;
1566
- this.lens.far = camera.far;
1567
- this.brain = this.manager.getComponent(camera, CinestationBrain, true);
1568
- this.brain.addCamera(this);
1569
- }
1570
- onDestroy() {
1571
- this.brain.removeCamera(this);
1572
- }
1573
- constructor(...args){
1574
- super(...args);
1575
- this._finalPosition = new Vector3();
1576
- this._finalRotation = new Quaternion();
1577
- this.locked = false;
1578
- this.priority = 10;
1579
- this.lens = new Lens();
1580
- this.correctPosition = new Vector3();
1581
- this.correctRotation = new Quaternion();
1582
- }
1583
- }
1584
- __decorate([
1585
- property
1586
- ], VirtualCamera.prototype, "lens", void 0);
1587
-
1588
- const PressState = {
1589
- NONE: 1 << 0,
1590
- SELECTED: 1 << 1,
1591
- IN: 1 << 2
1592
- };
1593
- class Pressability {
1594
- connect(target) {
1595
- let connector = this._connectors.find((v)=>v.target === target);
1596
- if (connector === undefined) {
1597
- connector = {
1598
- target,
1599
- state: PressState.NONE
1600
- };
1601
- this._connectors.push(connector);
1602
- }
1603
- }
1604
- disconnect(target) {
1605
- let index = this._connectors.findIndex((v)=>v.target === target);
1606
- if (index !== -1) {
1607
- this._connectors.splice(index, 1);
1608
- }
1609
- }
1610
- pointerDown(pointer, camera) {
1611
- if (this._connectors.length === 0) return;
1612
- this._raycaster.setFromCamera(pointer, camera);
1613
- for (let conn of this._connectors){
1614
- if (conn.target.has("click") || conn.target.has("pointerdown")) {
1615
- let intersects = this._raycaster.intersectObject(conn.target.node, true);
1616
- if (intersects.length) {
1617
- conn.state |= PressState.SELECTED;
1618
- conn.target.emit("pointerdown", {
1619
- intersects
1620
- });
1621
- }
1622
- }
1623
- }
1624
- }
1625
- pointerUp(pointer, camera) {
1626
- if (this._connectors.length === 0) return;
1627
- this._raycaster.setFromCamera(pointer, camera);
1628
- for (let conn of this._connectors){
1629
- if (conn.target.has("click") || conn.target.has("pointerup")) {
1630
- let intersects = this._raycaster.intersectObject(conn.target.node, true);
1631
- if (intersects.length) {
1632
- if (conn.state & PressState.SELECTED) {
1633
- conn.state &= ~PressState.SELECTED;
1634
- conn.target.emit("click", {
1635
- intersects
1636
- });
1637
- }
1638
- conn.target.emit("pointerup", {
1639
- intersects
1640
- });
1641
- }
1642
- }
1643
- }
1644
- }
1645
- pointerMove(pointer, camera) {
1646
- if (this._connectors.length === 0) return;
1647
- this._raycaster.setFromCamera(pointer, camera);
1648
- for (let conn of this._connectors){
1649
- if (conn.target.has("pointerover") || conn.target.has("pointerout")) {
1650
- let intersects = this._raycaster.intersectObject(conn.target.node, true);
1651
- if (intersects.length) {
1652
- if (!(conn.state & PressState.IN)) {
1653
- conn.state |= PressState.IN;
1654
- conn.target.emit("pointerover", {
1655
- intersects
1656
- });
1657
- }
1658
- } else {
1659
- if (conn.state & PressState.IN) {
1660
- conn.state &= ~PressState.IN;
1661
- conn.target.emit("pointerout", {
1662
- intersects
1663
- });
1664
- }
1665
- }
1666
- }
1667
- }
1668
- }
1669
- constructor(){
1670
- this._raycaster = new Raycaster();
1671
- this._connectors = [];
1672
- }
1673
- }
1674
-
1675
- class DeviceInput {
1676
- get pointerButton() {
1677
- return this._pointerButton;
1678
- }
1679
- get pointer() {
1680
- return this._pointer;
1681
- }
1682
- get pointerPosition() {
1683
- return this._pointerPosition;
1684
- }
1685
- get mouseWheel() {
1686
- return this._mouseWheel;
1687
- }
1688
- get touchCount() {
1689
- return this._touchCount;
1690
- }
1691
- get touches() {
1692
- return this._touches;
1693
- }
1694
- get keys() {
1695
- return this._keys;
1696
- }
1697
- addEventListeners() {
1698
- const { canvas } = this.viewer;
1699
- canvas.style.touchAction = 'none';
1700
- this._addEventListener(canvas, 'contextmenu', (e)=>e.preventDefault());
1701
- this._addEventListener(canvas, "pointerdown", (e)=>this._onPointerDown(e), {
1702
- passive: false
1703
- });
1704
- this._addEventListener(canvas, "pointerup", (e)=>this._onPointerUp(e), {
1705
- passive: false
1706
- });
1707
- this._addEventListener(canvas, "pointercancel", (e)=>this._onPointerUp(e), {
1708
- passive: false
1709
- });
1710
- this._addEventListener(canvas, "pointerout", (e)=>this._onPointerUp(e), {
1711
- passive: false
1712
- });
1713
- this._addEventListener(canvas, "pointermove", (e)=>this._onPointerMove(e), {
1714
- passive: true
1715
- });
1716
- this._addEventListener(canvas, "wheel", (e)=>this._onMouseWheel(e), {
1717
- passive: false
1718
- });
1719
- this._addEventListener(canvas, "touchstart", (e)=>this._onTouchStart(e), {
1720
- passive: true
1721
- });
1722
- this._addEventListener(canvas, "touchend", (e)=>this._onTouchEnd(e), {
1723
- passive: true
1724
- });
1725
- this._addEventListener(canvas, "touchmove", (e)=>this._onTouchMove(e), {
1726
- passive: true
1727
- });
1728
- //监听了pointer事件之后,key事件失效,改成window解决
1729
- this._addEventListener(window, "keydown", (e)=>this._onKeyDown(e), {
1730
- passive: false
1731
- });
1732
- this._addEventListener(window, "keypress", (e)=>this._onKeyPress(e), {
1733
- passive: false
1734
- });
1735
- this._addEventListener(window, "keyup", (e)=>this._onKeyUp(e), {
1736
- passive: false
1737
- });
1738
- this._addEventListener(window, "resize", (e)=>this._onResize(e), {
1739
- passive: false
1740
- });
1741
- }
1742
- removeAllListeners() {
1743
- for (let { target, type, callback } of this._listeners){
1744
- if (target.removeEventListener) target.removeEventListener(type, callback);
1745
- else if (target.off) target.off(type, callback, target);
1746
- }
1747
- this._listeners = [];
1748
- }
1749
- connect(target, event) {
1750
- switch(event){
1751
- case DeviceInput.CLICK:
1752
- case DeviceInput.POINTER_DOWN:
1753
- case DeviceInput.POINTER_UP:
1754
- case DeviceInput.POINTER_OVER:
1755
- case DeviceInput.POINTER_OUT:
1756
- this._pressability.connect(target);
1757
- break;
1758
- }
1759
- }
1760
- disconnect(target) {
1761
- this._pressability.disconnect(target);
1762
- }
1763
- _addEventListener(target, type, callback, options) {
1764
- if (target.addEventListener) target.addEventListener(type, callback, options);
1765
- else if (target.on) target.on(type, callback, target);
1766
- this._listeners.push({
1767
- target,
1768
- type,
1769
- callback
1770
- });
1771
- }
1772
- _onResize(e) {
1773
- this.viewer.rotate();
1774
- this.viewer.resize();
1775
- }
1776
- _remapPointer(e) {
1777
- const width = this.viewer.width;
1778
- return this.viewer.rootRotated ? {
1779
- button: e.button,
1780
- buttons: e.buttons,
1781
- clientX: e.clientY,
1782
- clientY: width - e.clientX,
1783
- offsetX: e.offsetY,
1784
- offsetY: width - e.offsetX,
1785
- pageX: e.pageY,
1786
- pageY: width - e.pageX,
1787
- screenX: e.screenY,
1788
- screenY: width - e.screenX,
1789
- movementX: e.movementY,
1790
- movementY: e.movementX
1791
- } : e;
1792
- }
1793
- _remapTouch(e) {
1794
- const width = this.viewer.width;
1795
- return this.viewer.rootRotated ? {
1796
- touches: Array.from(e.touches).map((v)=>{
1797
- return {
1798
- identifier: v.identifier,
1799
- clientX: v.clientY,
1800
- clientY: width - v.clientX,
1801
- pageX: v.pageY,
1802
- pageY: width - v.pageX,
1803
- screenX: v.screenY,
1804
- screenY: width - v.screenX
1805
- };
1806
- })
1807
- } : e;
1808
- }
1809
- _computePointer(e) {
1810
- this._pointer.x = e.offsetX / this.viewer.width * 2 - 1;
1811
- this._pointer.y = 1 - e.offsetY / this.viewer.height * 2;
1812
- this._pointerPosition.set(e.offsetX, e.offsetY);
1813
- }
1814
- _onPointerDown(e) {
1815
- e.preventDefault();
1816
- e = this._remapPointer(e);
1817
- this._pointerButton = e.button;
1818
- this._computePointer(e);
1819
- this._pressability.pointerDown(this._pointer, this.viewer.camera);
1820
- this.viewer.emit(DeviceInput.POINTER_DOWN, e);
1821
- }
1822
- _onPointerUp(e) {
1823
- e.preventDefault();
1824
- e = this._remapPointer(e);
1825
- this._pointerButton = -1;
1826
- this._computePointer(e);
1827
- this._pressability.pointerUp(this._pointer, this.viewer.camera);
1828
- this.viewer.emit(DeviceInput.POINTER_UP, e);
1829
- }
1830
- _onPointerMove(e) {
1831
- e = this._remapPointer(e);
1832
- this._computePointer(e);
1833
- this._pressability.pointerMove(this._pointer, this.viewer.camera);
1834
- this.viewer.emit(DeviceInput.POINTER_MOVE, e);
1835
- }
1836
- _onMouseWheel(e) {
1837
- e.preventDefault();
1838
- this._mouseWheel = e.deltaY || e.wheelDelta;
1839
- this.viewer.emit(DeviceInput.MOUSE_WHEEL, e);
1840
- }
1841
- _onTouchStart(e) {
1842
- e = this._remapTouch(e);
1843
- this.viewer.emit(DeviceInput.TOUCH_START, e);
1844
- }
1845
- _onTouchEnd(e) {
1846
- e = this._remapTouch(e);
1847
- this.viewer.emit(DeviceInput.TOUCH_END, e);
1848
- }
1849
- _onTouchMove(e) {
1850
- e = this._remapTouch(e);
1851
- let touches = e.touches;
1852
- let touchesTo = this._touches;
1853
- for(let i = touches.length; i--;){
1854
- if (touchesTo[i] == undefined) {
1855
- touchesTo[i] = {
1856
- id: -1,
1857
- position: new Vector2()
1858
- };
1859
- }
1860
- const touch = touches[i];
1861
- touchesTo[i].id = touch.identifier;
1862
- touchesTo[i].position.set(touch.pageX, touch.pageY);
1863
- }
1864
- this._touchCount = touches.length;
1865
- this.viewer.emit(DeviceInput.TOUCH_MOVE, e);
1866
- }
1867
- _onKeyDown(e) {
1868
- this._keys[e.key] = true;
1869
- this.viewer.emit(DeviceInput.KEYDOWN, e);
1870
- }
1871
- _onKeyPress(e) {
1872
- this._keys[e.key] = true;
1873
- this.viewer.emit(DeviceInput.KEYPRESS, e);
1874
- }
1875
- _onKeyUp(e) {
1876
- this._keys[e.key] = false;
1877
- this.viewer.emit(DeviceInput.KEYUP, e);
1878
- }
1879
- constructor(viewer){
1880
- this.viewer = viewer;
1881
- this._listeners = [];
1882
- this._mouseWheel = 0;
1883
- this._touches = [];
1884
- this._touchCount = 0;
1885
- this._pointerButton = -1;
1886
- this._pointerPosition = new Vector2();
1887
- this._pointer = new Vector2();
1888
- this._keys = {};
1889
- this._pressability = new Pressability();
1890
- }
1891
- }
1892
- DeviceInput.CLICK = "click";
1893
- DeviceInput.MOUSE_WHEEL = "mousewheel";
1894
- DeviceInput.TOUCH_START = "touchstart";
1895
- DeviceInput.TOUCH_END = "touchend";
1896
- DeviceInput.TOUCH_MOVE = "touchmove";
1897
- DeviceInput.POINTER_DOWN = "pointerdown";
1898
- DeviceInput.POINTER_UP = "pointerup";
1899
- DeviceInput.POINTER_MOVE = "pointermove";
1900
- DeviceInput.POINTER_OVER = "pointerover";
1901
- DeviceInput.POINTER_OUT = "pointerout";
1902
- DeviceInput.KEYDOWN = "keydown";
1903
- DeviceInput.KEYPRESS = "keypress";
1904
- DeviceInput.KEYUP = "keyup";
1905
-
1906
- const isSSR = typeof window === 'undefined';
1907
- class DetectUA {
1908
- /**
1909
- * Match entry based on position found in the user-agent string
1910
- *
1911
- * @param pattern regular expression pattern
1912
- */ match(position, pattern) {
1913
- const match = this.userAgent.match(pattern);
1914
- return match && match.length > 1 && match[position] || '';
1915
- }
1916
- /**
1917
- * Returns if the device is a mobile device
1918
- */ get isMobile() {
1919
- return(// Default mobile
1920
- !this.isTablet && (/[^-]mobi/i.test(this.userAgent) || // iPhone / iPod
1921
- this.iOSDevice === 'iphone' || this.iOSDevice === 'ipod' || // Android
1922
- this.isAndroidDevice || // Nexus mobile
1923
- /nexus\s*[0-6]\s*/i.test(this.userAgent)));
1924
- }
1925
- /**
1926
- * Returns if the device is a tablet device
1927
- */ get isTablet() {
1928
- return(// Default tablet
1929
- /tablet/i.test(this.userAgent) && !/tablet pc/i.test(this.userAgent) || // iPad
1930
- this.iOSDevice === 'ipad' || // Android
1931
- this.isAndroidDevice && !/[^-]mobi/i.test(this.userAgent) || // Nexus tablet
1932
- !/nexus\s*[0-6]\s*/i.test(this.userAgent) && /nexus\s*[0-9]+/i.test(this.userAgent));
1933
- }
1934
- /**
1935
- * Returns if the device is a desktop device
1936
- */ get isDesktop() {
1937
- return !this.isMobile && !this.isTablet;
1938
- }
1939
- /**
1940
- * Returns if the device is running MacOS (and if so which version)
1941
- *
1942
- * '5' => Leopard'
1943
- * '6' => Snow Leopard'
1944
- * '7' => Lion'
1945
- * '8' => Mountain Lion'
1946
- * '9' => Mavericks'
1947
- * '10' => Yosemite'
1948
- * '11' => El Capitan'
1949
- * '12' => Sierra'
1950
- * '13' => High Sierra'
1951
- * '14' => Mojave'
1952
- * '15' => Catalina'
1953
- */ get isMacOS() {
1954
- return /macintosh/i.test(this.userAgent) && {
1955
- version: this.match(1, /mac os x (\d+(\.?_?\d+)+)/i).replace(/[_\s]/g, '.').split('.').map((versionNumber)=>versionNumber)[1]
1956
- };
1957
- }
1958
- /**
1959
- * Returns if the device is running Windows (and if so which version)
1960
- *
1961
- * 'NT' => 'NT'
1962
- * 'XP' => 'XP'
1963
- * 'NT 5.0' => '2000'
1964
- * 'NT 5.1' => 'XP'
1965
- * 'NT 5.2' => '2003'
1966
- * 'NT 6.0' => 'Vista'
1967
- * 'NT 6.1' => '7'
1968
- * 'NT 6.2' => '8'
1969
- * 'NT 6.3' => '8.1'
1970
- * 'NT 10.0' => '10'
1971
- */ get isWindows() {
1972
- return /windows /i.test(this.userAgent) && {
1973
- version: this.match(1, /Windows ((NT|XP)( \d\d?.\d)?)/i)
1974
- };
1975
- }
1976
- /**
1977
- * Returns if the device is an iOS device (and if so which version)
1978
- */ get isiOS() {
1979
- return !!this.iOSDevice && {
1980
- version: this.match(1, /os (\d+([_\s]\d+)*) like mac os x/i).replace(/[_\s]/g, '.') || this.match(1, /version\/(\d+(\.\d+)?)/i)
1981
- };
1982
- }
1983
- /**
1984
- * Returns if the device is an Android device (and if so which version)
1985
- */ get isAndroid() {
1986
- return this.isAndroidDevice && {
1987
- version: this.match(1, /android[ \/-](\d+(\.\d+)*)/i)
1988
- };
1989
- }
1990
- /**
1991
- * Returns the browser name and version
1992
- */ get browser() {
1993
- const versionIdentifier = this.match(1, /version\/(\d+(\.\d+)?)/i);
1994
- if (/opera/i.test(this.userAgent)) {
1995
- // Opera
1996
- return {
1997
- name: 'Opera',
1998
- version: versionIdentifier || this.match(1, /(?:opera|opr|opios)[\s\/](\d+(\.\d+)?)/i)
1999
- };
2000
- } else if (/opr\/|opios/i.test(this.userAgent)) {
2001
- // Opera
2002
- return {
2003
- name: 'Opera',
2004
- version: this.match(1, /(?:opr|opios)[\s\/](\d+(\.\d+)?)/i) || versionIdentifier
2005
- };
2006
- } else if (/SamsungBrowser/i.test(this.userAgent)) {
2007
- // Samsung Browser
2008
- return {
2009
- name: 'Samsung Internet for Android',
2010
- version: versionIdentifier || this.match(1, /(?:SamsungBrowser)[\s\/](\d+(\.\d+)?)/i)
2011
- };
2012
- } else if (/yabrowser/i.test(this.userAgent)) {
2013
- // Yandex Browser
2014
- return {
2015
- name: 'Yandex Browser',
2016
- version: versionIdentifier || this.match(1, /(?:yabrowser)[\s\/](\d+(\.\d+)?)/i)
2017
- };
2018
- } else if (/ucbrowser/i.test(this.userAgent)) {
2019
- // UC Browser
2020
- return {
2021
- name: 'UC Browser',
2022
- version: this.match(1, /(?:ucbrowser)[\s\/](\d+(\.\d+)?)/i)
2023
- };
2024
- } else if (/msie|trident/i.test(this.userAgent)) {
2025
- // Internet Explorer
2026
- return {
2027
- name: 'Internet Explorer',
2028
- version: this.match(1, /(?:msie |rv:)(\d+(\.\d+)?)/i)
2029
- };
2030
- } else if (/(edge|edgios|edga|edg)/i.test(this.userAgent)) {
2031
- // Edge
2032
- return {
2033
- name: 'Microsoft Edge',
2034
- version: this.match(2, /(edge|edgios|edga|edg)\/(\d+(\.\d+)?)/i)
2035
- };
2036
- } else if (/firefox|iceweasel|fxios/i.test(this.userAgent)) {
2037
- // Firefox
2038
- return {
2039
- name: 'Firefox',
2040
- version: this.match(1, /(?:firefox|iceweasel|fxios)[ \/](\d+(\.\d+)?)/i)
2041
- };
2042
- } else if (/chromium/i.test(this.userAgent)) {
2043
- // Chromium
2044
- return {
2045
- name: 'Chromium',
2046
- version: this.match(1, /(?:chromium)[\s\/](\d+(?:\.\d+)?)/i) || versionIdentifier
2047
- };
2048
- } else if (/chrome|crios|crmo/i.test(this.userAgent)) {
2049
- // Chrome
2050
- return {
2051
- name: 'Chrome',
2052
- version: this.match(1, /(?:chrome|crios|crmo)\/(\d+(\.\d+)?)/i)
2053
- };
2054
- } else if (/safari|applewebkit/i.test(this.userAgent)) {
2055
- // Safari
2056
- return {
2057
- name: 'Safari',
2058
- version: versionIdentifier
2059
- };
2060
- } else {
2061
- // Everything else
2062
- return {
2063
- name: this.match(1, /^(.*)\/(.*) /),
2064
- version: this.match(2, /^(.*)\/(.*) /)
2065
- };
2066
- }
2067
- }
2068
- /**
2069
- * Detect a users browser, browser version and whether it is a mobile-, tablet- or desktop device
2070
- *
2071
- * @param forceUserAgent Force a user agent string (useful for testing)
2072
- */ constructor(forceUserAgent){
2073
- this.userAgent = forceUserAgent ? forceUserAgent : !isSSR && window.navigator ? window.navigator.userAgent : '';
2074
- this.isAndroidDevice = !/like android/i.test(this.userAgent) && /android/i.test(this.userAgent);
2075
- this.iOSDevice = this.match(1, /(iphone|ipod|ipad)/i).toLowerCase();
2076
- // Workaround for ipadOS, force detection as tablet
2077
- // SEE: https://github.com/lancedikson/bowser/issues/329
2078
- // SEE: https://stackoverflow.com/questions/58019463/how-to-detect-device-name-in-safari-on-ios-13-while-it-doesnt-show-the-correct
2079
- if (!isSSR && navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 2 && !window.MSStream) {
2080
- this.iOSDevice = 'ipad';
2081
- }
2082
- }
2083
- }
2084
-
2085
- const detectUA = new DetectUA();
2086
- const userAgent = (navigator.userAgent || navigator.vendor).toLowerCase();
2087
- const browserName = typeof detectUA.browser === "boolean" ? "" : detectUA.browser.name;
2088
- const audioElem = document.createElement("audio");
2089
- class SystemInfo {
2090
- }
2091
- SystemInfo.isTablet = detectUA.isTablet;
2092
- SystemInfo.isMobile = detectUA.isMobile || detectUA.isTablet;
2093
- SystemInfo.isDesktop = detectUA.isDesktop;
2094
- SystemInfo.device = SystemInfo.isMobile ? "mobile" : "desktop";
2095
- SystemInfo.isAndroid = !!detectUA.isAndroid;
2096
- SystemInfo.isIOS = !!detectUA.isiOS;
2097
- SystemInfo.isMacOS = !!detectUA.isMacOS;
2098
- SystemInfo.isWindows = typeof detectUA.isWindows === "boolean" ? detectUA.isWindows : detectUA.isWindows.version !== null;
2099
- SystemInfo.isLinux = userAgent.indexOf("linux") != -1;
2100
- SystemInfo.ua = userAgent;
2101
- SystemInfo.isEdge = browserName === "Microsoft Edge";
2102
- SystemInfo.isIE = browserName === "Internet Explorer";
2103
- SystemInfo.isFirefox = browserName === "Firefox";
2104
- SystemInfo.isChrome = browserName === "Chrome";
2105
- SystemInfo.isOpera = browserName === "Opera";
2106
- SystemInfo.isSafari = browserName === "Safari";
2107
- SystemInfo.isSupportMSAA = !userAgent.match("version/15.4 ");
2108
- SystemInfo.isSupportOgg = !!audioElem.canPlayType("audio/ogg");
2109
- SystemInfo.isRetina = window.devicePixelRatio && window.devicePixelRatio >= 1.5;
2110
- SystemInfo.devicePixelRatio = window.devicePixelRatio || 1;
2111
- SystemInfo.cpuCoreCount = navigator.hardwareConcurrency || 1;
2112
- SystemInfo.baseUrl = document.location.origin;
2113
- SystemInfo.isIFrame = window.self !== window.top;
2114
-
2115
- const { clamp: clamp$3 } = MathUtils;
2116
- const { min, max: max$1, exp } = Math;
2117
- const kNegligibleResidual = 0.01;
2118
- const kLogNegligibleResidual = Math.log(kNegligibleResidual) // -4.605170186;
2119
- ;
2120
- function exponentialDamp(current, target, dampTime, deltaTime) {
2121
- let k = -kLogNegligibleResidual / dampTime;
2122
- return current + (target - current) * (1 - exp(-k * deltaTime));
2123
- }
2124
- // cuve like exponentialDecay but cost less
2125
- function quarticDamp(current, target, dampTime, deltaTime) {
2126
- let t = 1 - min(deltaTime, dampTime) / dampTime;
2127
- let tt = t * t;
2128
- return current + (target - current) * (1 - tt * tt);
2129
- }
2130
- function smoothDamp(state, current, target, smoothTime, maxSpeed, deltaTime) {
2131
- if (state._velocity === undefined) {
2132
- state._velocity = 0;
2133
- }
2134
- smoothTime = max$1(0.0001, smoothTime);
2135
- let num = 2 / smoothTime;
2136
- let num2 = num * deltaTime;
2137
- let num3 = 1 / (1 + num2 + 0.48 * num2 * num2 + 0.235 * num2 * num2 * num2);
2138
- let num4 = current - target;
2139
- let num5 = target;
2140
- let num6 = maxSpeed * smoothTime;
2141
- num4 = clamp$3(num4, -num6, num6);
2142
- target = current - num4;
2143
- let num7 = (state._velocity + num * num4) * deltaTime;
2144
- state._velocity = (state._velocity - num * num7) * num3;
2145
- let num8 = target + (num4 + num7) * num3;
2146
- if (num5 - current > 0 == num8 > num5) {
2147
- num8 = num5;
2148
- state._velocity = (num8 - num5) / deltaTime;
2149
- }
2150
- return num8;
2151
- }
2152
- function Quat_exponentialDamp(current, target, dampTime, deltaTime, out = current) {
2153
- return out.copy(current).slerp(target, exponentialDamp(0, 1, dampTime, deltaTime));
2154
- }
2155
- function Quat_quarticDamp(current, target, dampTime, deltaTime, out = current) {
2156
- return out.copy(current).slerp(target, quarticDamp(0, 1, dampTime, deltaTime));
2157
- }
2158
- function Quat_smoothDamp(current, target, dampTime, deltaTime, out = current) {
2159
- return out.copy(current).slerp(target, smoothDamp(out, 0, 1, dampTime, Infinity, deltaTime));
2160
- }
2161
- function Vec3_smoothDamp(current, target, dampTime, deltaTime, out = current) {
2162
- return out.copy(current).lerp(target, smoothDamp(out, 0, 1, dampTime, Infinity, deltaTime));
2163
- }
2164
-
2165
- const Vector3_UNIT_X = Object.freeze(new Vector3(1, 0, 0));
2166
- const Vector3_UNIT_Y = Object.freeze(new Vector3(0, 1, 0));
2167
- const Vector3_UNIT_Z = Object.freeze(new Vector3(0, 0, 1));
2168
- const Vector3_RIGHT = Object.freeze(new Vector3(1, 0, 0));
2169
- const Vector3_UP = Object.freeze(new Vector3(0, 1, 0));
2170
- const Vector3_ZERO = Object.freeze(new Vector3(0, 0, 0));
2171
- const Vector3_ONE = Object.freeze(new Vector3(1, 1, 1));
2172
- const Vector3_NEG_ONE = Object.freeze(new Vector3(-1, -1, -1));
2173
-
2174
- const { clamp: clamp$2 } = MathUtils;
2175
- const { max, abs: abs$1, acos } = Math;
2176
- const EPSILON = 1.e-6;
2177
- const __deltaMap = new Map();
2178
- __deltaMap.set(Vector3, new Vector3());
2179
- __deltaMap.set(Vector2, new Vector2());
2180
- function VInterpTo(current, target, deltaTime, speed, out = current, epsilon = EPSILON) {
2181
- if (speed <= 0) {
2182
- return out.copy(target);
2183
- }
2184
- let dist = __deltaMap.get(current.constructor).copy(target).sub(current);
2185
- if (dist.lengthSq() < epsilon) {
2186
- return out.copy(target);
2187
- }
2188
- return out.copy(current).add(dist.multiplyScalar(clamp$2(deltaTime * speed, 0, 1)));
2189
- }
2190
- function VInterpConstantTo(current, target, deltaTime, speed, out = current) {
2191
- let delta = __deltaMap.get(current.constructor).copy(target).sub(current);
2192
- let deltaM = delta.length();
2193
- let maxStep = speed * deltaTime;
2194
- if (deltaM > maxStep) {
2195
- if (maxStep > 0) {
2196
- let deltaN = delta.multiplyScalar(1 / deltaM);
2197
- return out.copy(current).add(deltaN);
2198
- } else {
2199
- return out.copy(current);
2200
- }
2201
- }
2202
- return out.copy(target);
2203
- }
2204
- function Quat_Equals(a, b, epsilon = EPSILON) {
2205
- return abs$1(a.x - b.x) <= epsilon * max(1., abs$1(a.x), abs$1(b.x)) && abs$1(a.y - b.y) <= epsilon * max(1., abs$1(a.y), abs$1(b.y)) && abs$1(a.z - b.z) <= epsilon * max(1., abs$1(a.z), abs$1(b.z)) && abs$1(a.w - b.w) <= epsilon * max(1., abs$1(a.w), abs$1(b.w));
2206
- }
2207
- function Quat_AngularDistance(a, b) {
2208
- let innerProd = a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
2209
- return acos(2 * innerProd * innerProd - 1);
2210
- }
2211
- function QInterpTo(current, target, deltaTime, speed, epsilon = EPSILON) {
2212
- if (speed <= 0) {
2213
- return target;
2214
- }
2215
- if (Quat_Equals(current, target, epsilon)) {
2216
- return target;
2217
- }
2218
- return current.slerp(target, clamp$2(speed * deltaTime, 0, 1));
2219
- }
2220
- function QInterpConstantTo(current, target, deltaTime, speed, out = current) {
2221
- if (speed <= 0) {
2222
- return out.copy(target);
2223
- }
2224
- if (Quat_Equals(current, target)) {
2225
- return out.copy(target);
2226
- }
2227
- let deltaSpeed = clamp$2(speed * deltaTime, 0, 1);
2228
- let angularDist = max(Quat_AngularDistance(current, target), EPSILON);
2229
- return out.copy(current).slerp(target, clamp$2(deltaSpeed / angularDist, 0, 1));
2230
- }
2231
- //非线性
2232
- function FInterpTo(current, target, deltaTime, speed, epsilon = EPSILON) {
2233
- if (speed <= 0) {
2234
- return target;
2235
- }
2236
- let dist = target - current;
2237
- if (abs$1(dist) < epsilon) {
2238
- return target;
2239
- }
2240
- return current + dist * clamp$2(speed * deltaTime, 0, 1);
2241
- }
2242
- //线性插值
2243
- function FInterpConstantTo(current, target, deltaTime, speed, epsilon = EPSILON) {
2244
- let dist = target - current;
2245
- if (abs$1(dist) < epsilon) {
2246
- return target;
2247
- }
2248
- let step = speed * deltaTime;
2249
- return current + clamp$2(dist, -step, step);
2250
- }
2251
-
2252
- const { lerp, clamp: clamp$1 } = MathUtils;
2253
- function catmullRom(t, p0, p1, p2, p3) {
2254
- const v0 = (p2 - p0) * 0.5;
2255
- const v1 = (p3 - p1) * 0.5;
2256
- const t2 = t * t;
2257
- const t3 = t * t2;
2258
- return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
2259
- }
2260
- class CurvePoint {
2261
- set(x, y) {
2262
- this.x = x;
2263
- this.y = y;
2264
- return this;
2265
- }
2266
- lerp(p, t, out = this) {
2267
- out.x = lerp(this.x, p.x, t);
2268
- out.y = lerp(this.y, p.y, t);
2269
- return out;
2270
- }
2271
- constructor(x = 0, y = 0, mode = 0){
2272
- this.x = x;
2273
- this.y = y;
2274
- this.mode = mode;
2275
- }
2276
- }
2277
- class AnimationCurve {
2278
- _getInterpolant(samples) {
2279
- if (this._samples !== samples) {
2280
- this._samples = samples;
2281
- this._interpolant = new LinearInterpolant(new Float32Array(samples), new Float32Array(samples), 1, new Float32Array(samples));
2282
- }
2283
- return this._interpolant;
2284
- }
2285
- createCurvePoint(x, y, mode) {
2286
- return new CurvePoint(x, y, mode);
2287
- }
2288
- resample(samples = 100) {
2289
- const step = 1 / (samples - 1);
2290
- const interpolant = this._getInterpolant(samples);
2291
- const times = interpolant.parameterPositions;
2292
- const values = interpolant.sampleValues;
2293
- const point = this.createCurvePoint();
2294
- for(let i = 0; i < samples; i++){
2295
- this.getPoint(i * step, point);
2296
- times[i] = point.x;
2297
- values[i] = point.y;
2298
- }
2299
- }
2300
- evaluate(t) {
2301
- if (this.needsUpdate) {
2302
- this.needsUpdate = false;
2303
- this.resample();
2304
- }
2305
- return this._interpolant.evaluate(t)[0];
2306
- }
2307
- getPoint(t, out) {
2308
- const points = this.points;
2309
- if (t <= 0) {
2310
- return out.set(t, points[0].y);
2311
- }
2312
- if (t >= 1) {
2313
- return out.set(t, points[points.length - 1].y);
2314
- }
2315
- const p = (points.length - 1) * t;
2316
- const intPoint = Math.floor(p);
2317
- const weight = p - intPoint;
2318
- const p0 = points[intPoint === 0 ? intPoint : intPoint - 1];
2319
- const p1 = points[intPoint];
2320
- const p2 = points[intPoint > points.length - 2 ? points.length - 1 : intPoint + 1];
2321
- const p3 = points[intPoint > points.length - 3 ? points.length - 1 : intPoint + 2];
2322
- if (p1.mode === 1 || p0 === p1 && p2.mode === 1) {
2323
- return p1.lerp(p2, weight, out);
2324
- }
2325
- return out.set(clamp$1(catmullRom(weight, p0.x, p1.x, p2.x, p3.x), 0, 1), clamp$1(catmullRom(weight, p0.y, p1.y, p2.y, p3.y), 0, 1));
2326
- }
2327
- constructor(name = "", points = [
2328
- new CurvePoint(0, 0),
2329
- new CurvePoint(1, 1)
2330
- ]){
2331
- this.name = name;
2332
- this.points = points;
2333
- this.needsUpdate = true;
2334
- this.isAnimationCurve = true;
2335
- this._samples = 100;
2336
- this._interpolant = new LinearInterpolant(new Float32Array(100), new Float32Array(100), 1, new Float32Array(100));
2337
- }
2338
- }
2339
-
2340
- const { floor } = Math;
2341
- // Copyright (C) 2016 Keijiro Takahashi
2342
- // https://mrl.cs.nyu.edu/~perlin/noise/
2343
- class Perlin {
2344
- static Noise(x, y, z) {
2345
- let fade = Perlin._Fade;
2346
- let grad = Perlin._Grad;
2347
- let lerp = Perlin._Lerp;
2348
- let p = Perlin._Permutation;
2349
- if (y !== undefined && z !== undefined) {
2350
- let xi = floor(x);
2351
- let yi = floor(y);
2352
- let zi = floor(z);
2353
- let X = xi & 0xff; // FIND UNIT CUBE THAT
2354
- let Y = yi & 0xff; // CONTAINS POINT.
2355
- let Z = zi & 0xff;
2356
- x -= xi; // FIND RELATIVE X,Y,Z
2357
- y -= yi; // OF POINT IN CUBE.
2358
- z -= zi;
2359
- let u = fade(x); // COMPUTE FADE CURVES
2360
- let v = fade(y); // FOR EACH OF X,Y,Z.
2361
- let w = fade(z);
2362
- let A = p[X] + Y, AA = p[A] + Z, AB = p[A + 1] + Z; // HASH COORDINATES OF
2363
- let B = p[X + 1] + Y, BA = p[B] + Z, BB = p[B + 1] + Z; // THE 8 CUBE CORNERS,
2364
- return lerp(w, lerp(v, lerp(u, grad(p[AA], x, y, z), grad(p[BA], x - 1, y, z)), lerp(u, grad(p[AB], x, y - 1, z), grad(p[BB], x - 1, y - 1, z))), lerp(v, lerp(u, grad(p[AA + 1], x, y, z - 1), grad(p[BA + 1], x - 1, y, z - 1)), lerp(u, grad(p[AB + 1], x, y - 1, z - 1), grad(p[BB + 1], x - 1, y - 1, z - 1))));
2365
- } else if (y !== undefined) {
2366
- let xi = floor(x);
2367
- let yi = floor(y);
2368
- let X = xi & 0xff;
2369
- let Y = yi & 0xff;
2370
- x -= xi;
2371
- y -= yi;
2372
- let u = fade(x);
2373
- let v = fade(y);
2374
- let A = p[X] + Y & 0xff;
2375
- let B = p[X + 1] + Y & 0xff;
2376
- return lerp(v, lerp(u, grad(p[A], x, y), grad(p[B], x - 1, y)), lerp(u, grad(p[A + 1], x, y - 1), grad(p[B + 1], x - 1, y - 1)));
2377
- } else {
2378
- let xi = floor(x);
2379
- let X = xi & 0xff;
2380
- x -= xi;
2381
- let u = fade(x);
2382
- return lerp(u, grad(p[X], x), grad(p[X + 1], x - 1));
2383
- }
2384
- }
2385
- static Fbm(octave, x, y, z) {
2386
- let f = 0;
2387
- let w = 0.5;
2388
- let noise = Perlin.Noise;
2389
- if (y !== undefined && z !== undefined) {
2390
- for(let i = 0; i < octave; i++){
2391
- f += w * noise(x, y, z);
2392
- x *= 2.0;
2393
- y *= 2.0;
2394
- z *= 2.0;
2395
- w *= 0.5;
2396
- }
2397
- } else if (y !== undefined) {
2398
- for(let i = 0; i < octave; i++){
2399
- f += w * noise(x, y);
2400
- x *= 2.0;
2401
- y *= 2.0;
2402
- w *= 0.5;
2403
- }
2404
- } else {
2405
- for(let i = 0; i < octave; i++){
2406
- f += w * noise(x);
2407
- x *= 2.0;
2408
- w *= 0.5;
2409
- }
2410
- }
2411
- return f;
2412
- }
2413
- static _Fade(t) {
2414
- return t * t * t * (t * (t * 6 - 15) + 10);
2415
- }
2416
- static _Lerp(t, a, b) {
2417
- return a + t * (b - a);
2418
- }
2419
- static _Grad(hash, x, y, z) {
2420
- if (y !== undefined && z !== undefined) {
2421
- let h = hash & 15; // CONVERT LO 4 BITS OF HASH CODE
2422
- let u = h < 8 ? x : y, v = h < 4 ? y : h == 12 || h == 14 ? x : z;
2423
- return ((h & 1) == 0 ? u : -u) + ((h & 2) == 0 ? v : -v);
2424
- } else if (y !== undefined) {
2425
- return ((hash & 1) == 0 ? x : -x) + ((hash & 2) == 0 ? y : -y);
2426
- } else {
2427
- return (hash & 1) == 0 ? x : -x;
761
+ static _Grad(hash, x, y, z) {
762
+ if (y !== undefined && z !== undefined) {
763
+ let h = hash & 15; // CONVERT LO 4 BITS OF HASH CODE
764
+ let u = h < 8 ? x : y, v = h < 4 ? y : h == 12 || h == 14 ? x : z;
765
+ return ((h & 1) == 0 ? u : -u) + ((h & 2) == 0 ? v : -v);
766
+ } else if (y !== undefined) {
767
+ return ((hash & 1) == 0 ? x : -x) + ((hash & 2) == 0 ? y : -y);
768
+ } else {
769
+ return (hash & 1) == 0 ? x : -x;
2428
770
  }
2429
771
  }
2430
772
  }
@@ -2688,6 +1030,1091 @@ Perlin._Permutation = [
2688
1030
  151
2689
1031
  ];
2690
1032
 
1033
+ /**
1034
+ * The Ease class provides a collection of easing functions for use with tween.js.
1035
+ */ const Easing = Object.freeze({
1036
+ Linear: Object.freeze({
1037
+ None (amount) {
1038
+ return amount;
1039
+ },
1040
+ In (amount) {
1041
+ return amount;
1042
+ },
1043
+ Out (amount) {
1044
+ return amount;
1045
+ },
1046
+ InOut (amount) {
1047
+ return amount;
1048
+ }
1049
+ }),
1050
+ Quadratic: Object.freeze({
1051
+ In (amount) {
1052
+ return amount * amount;
1053
+ },
1054
+ Out (amount) {
1055
+ return amount * (2 - amount);
1056
+ },
1057
+ InOut (amount) {
1058
+ if ((amount *= 2) < 1) {
1059
+ return 0.5 * amount * amount;
1060
+ }
1061
+ return -0.5 * (--amount * (amount - 2) - 1);
1062
+ }
1063
+ }),
1064
+ Cubic: Object.freeze({
1065
+ In (amount) {
1066
+ return amount * amount * amount;
1067
+ },
1068
+ Out (amount) {
1069
+ return --amount * amount * amount + 1;
1070
+ },
1071
+ InOut (amount) {
1072
+ if ((amount *= 2) < 1) {
1073
+ return 0.5 * amount * amount * amount;
1074
+ }
1075
+ return 0.5 * ((amount -= 2) * amount * amount + 2);
1076
+ }
1077
+ }),
1078
+ Quartic: Object.freeze({
1079
+ In (amount) {
1080
+ return amount * amount * amount * amount;
1081
+ },
1082
+ Out (amount) {
1083
+ return 1 - --amount * amount * amount * amount;
1084
+ },
1085
+ InOut (amount) {
1086
+ if ((amount *= 2) < 1) {
1087
+ return 0.5 * amount * amount * amount * amount;
1088
+ }
1089
+ return -0.5 * ((amount -= 2) * amount * amount * amount - 2);
1090
+ }
1091
+ }),
1092
+ Quintic: Object.freeze({
1093
+ In (amount) {
1094
+ return amount * amount * amount * amount * amount;
1095
+ },
1096
+ Out (amount) {
1097
+ return --amount * amount * amount * amount * amount + 1;
1098
+ },
1099
+ InOut (amount) {
1100
+ if ((amount *= 2) < 1) {
1101
+ return 0.5 * amount * amount * amount * amount * amount;
1102
+ }
1103
+ return 0.5 * ((amount -= 2) * amount * amount * amount * amount + 2);
1104
+ }
1105
+ }),
1106
+ Sinusoidal: Object.freeze({
1107
+ In (amount) {
1108
+ return 1 - Math.sin((1.0 - amount) * Math.PI / 2);
1109
+ },
1110
+ Out (amount) {
1111
+ return Math.sin(amount * Math.PI / 2);
1112
+ },
1113
+ InOut (amount) {
1114
+ return 0.5 * (1 - Math.sin(Math.PI * (0.5 - amount)));
1115
+ }
1116
+ }),
1117
+ Exponential: Object.freeze({
1118
+ In (amount) {
1119
+ return amount === 0 ? 0 : Math.pow(1024, amount - 1);
1120
+ },
1121
+ Out (amount) {
1122
+ return amount === 1 ? 1 : 1 - Math.pow(2, -10 * amount);
1123
+ },
1124
+ InOut (amount) {
1125
+ if (amount === 0) {
1126
+ return 0;
1127
+ }
1128
+ if (amount === 1) {
1129
+ return 1;
1130
+ }
1131
+ if ((amount *= 2) < 1) {
1132
+ return 0.5 * Math.pow(1024, amount - 1);
1133
+ }
1134
+ return 0.5 * (-Math.pow(2, -10 * (amount - 1)) + 2);
1135
+ }
1136
+ }),
1137
+ Circular: Object.freeze({
1138
+ In (amount) {
1139
+ return 1 - Math.sqrt(1 - amount * amount);
1140
+ },
1141
+ Out (amount) {
1142
+ return Math.sqrt(1 - --amount * amount);
1143
+ },
1144
+ InOut (amount) {
1145
+ if ((amount *= 2) < 1) {
1146
+ return -0.5 * (Math.sqrt(1 - amount * amount) - 1);
1147
+ }
1148
+ return 0.5 * (Math.sqrt(1 - (amount -= 2) * amount) + 1);
1149
+ }
1150
+ }),
1151
+ Elastic: Object.freeze({
1152
+ In (amount) {
1153
+ if (amount === 0) {
1154
+ return 0;
1155
+ }
1156
+ if (amount === 1) {
1157
+ return 1;
1158
+ }
1159
+ return -Math.pow(2, 10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI);
1160
+ },
1161
+ Out (amount) {
1162
+ if (amount === 0) {
1163
+ return 0;
1164
+ }
1165
+ if (amount === 1) {
1166
+ return 1;
1167
+ }
1168
+ return Math.pow(2, -10 * amount) * Math.sin((amount - 0.1) * 5 * Math.PI) + 1;
1169
+ },
1170
+ InOut (amount) {
1171
+ if (amount === 0) {
1172
+ return 0;
1173
+ }
1174
+ if (amount === 1) {
1175
+ return 1;
1176
+ }
1177
+ amount *= 2;
1178
+ if (amount < 1) {
1179
+ return -0.5 * Math.pow(2, 10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI);
1180
+ }
1181
+ return 0.5 * Math.pow(2, -10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI) + 1;
1182
+ }
1183
+ }),
1184
+ Back: Object.freeze({
1185
+ In (amount) {
1186
+ const s = 1.70158;
1187
+ return amount === 1 ? 1 : amount * amount * ((s + 1) * amount - s);
1188
+ },
1189
+ Out (amount) {
1190
+ const s = 1.70158;
1191
+ return amount === 0 ? 0 : --amount * amount * ((s + 1) * amount + s) + 1;
1192
+ },
1193
+ InOut (amount) {
1194
+ const s = 1.70158 * 1.525;
1195
+ if ((amount *= 2) < 1) {
1196
+ return 0.5 * (amount * amount * ((s + 1) * amount - s));
1197
+ }
1198
+ return 0.5 * ((amount -= 2) * amount * ((s + 1) * amount + s) + 2);
1199
+ }
1200
+ }),
1201
+ Bounce: Object.freeze({
1202
+ In (amount) {
1203
+ return 1 - Easing.Bounce.Out(1 - amount);
1204
+ },
1205
+ Out (amount) {
1206
+ if (amount < 1 / 2.75) {
1207
+ return 7.5625 * amount * amount;
1208
+ } else if (amount < 2 / 2.75) {
1209
+ return 7.5625 * (amount -= 1.5 / 2.75) * amount + 0.75;
1210
+ } else if (amount < 2.5 / 2.75) {
1211
+ return 7.5625 * (amount -= 2.25 / 2.75) * amount + 0.9375;
1212
+ } else {
1213
+ return 7.5625 * (amount -= 2.625 / 2.75) * amount + 0.984375;
1214
+ }
1215
+ },
1216
+ InOut (amount) {
1217
+ if (amount < 0.5) {
1218
+ return Easing.Bounce.In(amount * 2) * 0.5;
1219
+ }
1220
+ return Easing.Bounce.Out(amount * 2 - 1) * 0.5 + 0.5;
1221
+ }
1222
+ }),
1223
+ generatePow (power = 4) {
1224
+ power = power < Number.EPSILON ? Number.EPSILON : power;
1225
+ power = power > 10000 ? 10000 : power;
1226
+ return {
1227
+ In (amount) {
1228
+ return amount ** power;
1229
+ },
1230
+ Out (amount) {
1231
+ return 1 - (1 - amount) ** power;
1232
+ },
1233
+ InOut (amount) {
1234
+ if (amount < 0.5) {
1235
+ return (amount * 2) ** power / 2;
1236
+ }
1237
+ return (1 - (2 - amount * 2) ** power) / 2 + 0.5;
1238
+ }
1239
+ };
1240
+ }
1241
+ });
1242
+
1243
+ class ClassProperties {
1244
+ property(propertyKey, options = {}) {
1245
+ this._properties[propertyKey] = options;
1246
+ return this;
1247
+ }
1248
+ applyProperties(target) {
1249
+ Object.assign(target, this._properties);
1250
+ return target;
1251
+ }
1252
+ constructor(clsName){
1253
+ this.clsName = clsName;
1254
+ this._properties = Object.create(null);
1255
+ }
1256
+ }
1257
+ class PropertyManager {
1258
+ static _hasProperties(constructor) {
1259
+ return PropertyManager._propertyMap.has(constructor);
1260
+ }
1261
+ static _getProperties(constructor, autoAdd = true) {
1262
+ let props = PropertyManager._propertyMap.get(constructor);
1263
+ if (props === undefined && autoAdd) {
1264
+ props = Object.create(null);
1265
+ PropertyManager._propertyMap.set(constructor, props);
1266
+ }
1267
+ return props;
1268
+ }
1269
+ static _getMergedProperties(constructor) {
1270
+ let merged = null;
1271
+ while(constructor !== Object.constructor.prototype){
1272
+ let props = PropertyManager._getProperties(constructor, false);
1273
+ if (props) {
1274
+ if (merged === null) {
1275
+ merged = Object.create(null);
1276
+ }
1277
+ Object.assign(merged, props);
1278
+ }
1279
+ constructor = Object.getPrototypeOf(constructor);
1280
+ }
1281
+ return merged;
1282
+ }
1283
+ static _getClassProperties(clsName, autoAdd = true) {
1284
+ let props = PropertyManager._classMap.get(clsName);
1285
+ if (props === undefined && autoAdd) {
1286
+ props = new ClassProperties(clsName);
1287
+ PropertyManager._classMap.set(clsName, props);
1288
+ }
1289
+ return props;
1290
+ }
1291
+ static _applyClassProperties(clsName, constructor) {
1292
+ let cls = PropertyManager._getClassProperties(clsName, false);
1293
+ if (cls) {
1294
+ return cls.applyProperties(PropertyManager._getProperties(constructor));
1295
+ } else {
1296
+ return PropertyManager._getProperties(constructor, false);
1297
+ }
1298
+ }
1299
+ }
1300
+ PropertyManager._classMap = new Map();
1301
+ PropertyManager._propertyMap = new Map();
1302
+ function property(target, propertyKey) {
1303
+ let options = null;
1304
+ function normalized(target, propertyKey) {
1305
+ PropertyManager._getProperties(target.constructor)[propertyKey] = options;
1306
+ }
1307
+ if (target === undefined) {
1308
+ return property({});
1309
+ } else if (typeof propertyKey === "undefined") {
1310
+ options = target;
1311
+ return normalized;
1312
+ } else {
1313
+ options = {};
1314
+ normalized(target, propertyKey);
1315
+ }
1316
+ }
1317
+
1318
+ const CinestationBlendStyle = {
1319
+ Linear: Easing.Linear.None,
1320
+ QuadraticIn: Easing.Quadratic.In,
1321
+ QuadraticOut: Easing.Quadratic.Out,
1322
+ QuadraticInOut: Easing.Quadratic.InOut
1323
+ };
1324
+ class CinestationBlendDefinition {
1325
+ constructor(){
1326
+ this.style = CinestationBlendStyle.QuadraticInOut;
1327
+ this.time = 4;
1328
+ }
1329
+ }
1330
+ __decorate([
1331
+ property({
1332
+ value: CinestationBlendStyle
1333
+ })
1334
+ ], CinestationBlendDefinition.prototype, "style", void 0);
1335
+ __decorate([
1336
+ property
1337
+ ], CinestationBlendDefinition.prototype, "time", void 0);
1338
+
1339
+ class ObjectInstance {
1340
+ constructor(){
1341
+ this.instanceId = ObjectInstance._instanceCount++;
1342
+ this.uuid = MathUtils.generateUUID();
1343
+ this.name = "";
1344
+ this.type = "ObjectInstance";
1345
+ }
1346
+ }
1347
+ ObjectInstance._instanceCount = 0;
1348
+
1349
+ function applyProps(target, props) {
1350
+ for(let k in props){
1351
+ let prop = props[k];
1352
+ if (prop === undefined) {
1353
+ continue;
1354
+ }
1355
+ if (target[k] !== undefined) {
1356
+ let des = Object.getOwnPropertyDescriptor(target, k);
1357
+ if (!des || des.writable || des.set) {
1358
+ target[k] = prop;
1359
+ } else {
1360
+ let value = target[k];
1361
+ if (value && value.copy) {
1362
+ value.copy(prop);
1363
+ }
1364
+ }
1365
+ }
1366
+ }
1367
+ return target;
1368
+ }
1369
+ function find(node, path) {
1370
+ let child = null;
1371
+ let parts = path.split("/");
1372
+ let children = node.children;
1373
+ for (let part of parts){
1374
+ child = children.find((v)=>v.name === part);
1375
+ if (child) {
1376
+ children = child.children;
1377
+ } else {
1378
+ return null;
1379
+ }
1380
+ }
1381
+ return child;
1382
+ }
1383
+ function getChildren(node, filter, group = false) {
1384
+ const queue = [
1385
+ node
1386
+ ];
1387
+ const objects = [];
1388
+ while(queue.length !== 0){
1389
+ let object = queue.shift();
1390
+ let target = filter(object);
1391
+ if (target) {
1392
+ objects.push(object);
1393
+ if (!group) {
1394
+ break;
1395
+ }
1396
+ }
1397
+ object.children.forEach((v)=>queue.push(v));
1398
+ }
1399
+ if (group) {
1400
+ return objects;
1401
+ }
1402
+ return objects[0];
1403
+ }
1404
+ function getChildByName(node, name) {
1405
+ return getChildren(node, (v)=>v && v.name === name);
1406
+ }
1407
+ const __emtpyObject = {};
1408
+ function queryValues(object, name, group = false) {
1409
+ if (name) {
1410
+ if (group) {
1411
+ return Object.values(object || __emtpyObject).filter((v)=>v.name === name);
1412
+ }
1413
+ return Object.values(object || __emtpyObject).find((v)=>v.name === name);
1414
+ }
1415
+ return Object.values(object);
1416
+ }
1417
+
1418
+ class Component extends ObjectInstance {
1419
+ get enabled() {
1420
+ return this._enabled;
1421
+ }
1422
+ set enabled(v) {
1423
+ if (this._enabled !== v) {
1424
+ this._enabled = v;
1425
+ this.manager.componentScheduler.enableComponent(this, v);
1426
+ }
1427
+ }
1428
+ _onPreDestroy() {
1429
+ this.unscheduleAll();
1430
+ this.manager.removeComponent(this.node, this);
1431
+ if (this._enabled) {
1432
+ this.manager.componentScheduler.enableComponent(this, false);
1433
+ }
1434
+ if (this.onDestroy && this.flags.OnLoadCalled) {
1435
+ this.onDestroy();
1436
+ }
1437
+ }
1438
+ schedule(callback, interval, repeat = -1) {
1439
+ this.manager.scheduler.schedule(this, callback, interval, repeat);
1440
+ }
1441
+ unshedule(callback) {
1442
+ this.manager.scheduler.unshedule(this, callback);
1443
+ }
1444
+ unscheduleAll() {
1445
+ this.manager.scheduler.unscheduleAll(this);
1446
+ }
1447
+ destroy() {
1448
+ if (this.flags.Destroyed) {
1449
+ return false;
1450
+ }
1451
+ this.destroyImmediate();
1452
+ return true;
1453
+ }
1454
+ destroyImmediate() {
1455
+ if (this._onPreDestroy) {
1456
+ this._onPreDestroy();
1457
+ }
1458
+ this.flags.Destroyed = true;
1459
+ }
1460
+ apply(props) {
1461
+ return applyProps(this, props);
1462
+ }
1463
+ constructor(...args){
1464
+ super(...args);
1465
+ this._enabled = true;
1466
+ this.isComponent = true;
1467
+ this.type = "Component";
1468
+ this.flags = {};
1469
+ }
1470
+ }
1471
+
1472
+ const { clamp: clamp$1, lerp } = MathUtils;
1473
+ class CinestationBrain extends Component {
1474
+ get vcam() {
1475
+ return this._vcam;
1476
+ }
1477
+ get vcams() {
1478
+ return this._vcams;
1479
+ }
1480
+ lastUpdate(dt) {
1481
+ let vcam = this.getActiveCamera();
1482
+ if (vcam == null) return;
1483
+ this._vcams.forEach((v)=>{
1484
+ if (!v.locked) {
1485
+ v.enabled = v === vcam;
1486
+ }
1487
+ });
1488
+ if (this._lerpTime < this.brainBlend.time) {
1489
+ this._lerpTime += dt;
1490
+ let t = clamp$1(this._lerpTime / this.brainBlend.time, 0, 1);
1491
+ this._lerpToMainCamera(vcam, this.brainBlend.style(t));
1492
+ } else {
1493
+ this._lerpToMainCamera(vcam, 1);
1494
+ }
1495
+ }
1496
+ activeCamera(vcam, time = 4) {
1497
+ if (this._vcamSolo !== vcam) {
1498
+ this._vcamSolo = vcam;
1499
+ this._lerpTime = 0;
1500
+ this.brainBlend.time = time;
1501
+ }
1502
+ }
1503
+ addCamera(vcam) {
1504
+ let index = this._vcams.indexOf(vcam);
1505
+ if (index === -1) {
1506
+ this._vcams.push(vcam);
1507
+ }
1508
+ }
1509
+ removeCamera(vcam) {
1510
+ let index = this._vcams.indexOf(vcam);
1511
+ if (index !== -1) {
1512
+ this._vcams.splice(index, 1);
1513
+ }
1514
+ }
1515
+ getActiveCamera() {
1516
+ return this._vcamSolo || this._vcams.filter((v)=>v.enabled || v.locked).sort((a, b)=>b.priority - a.priority)[0];
1517
+ }
1518
+ _lerpToMainCamera(vcam, t) {
1519
+ const from = this.node, to = vcam;
1520
+ const { lens, finalPosition, finalRotation } = to;
1521
+ const isLensChanged = from.fov != lens.fov || from.near != lens.near || from.far != lens.far;
1522
+ from.position.lerp(finalPosition, t);
1523
+ from.quaternion.slerp(finalRotation, t);
1524
+ from.fov = lerp(from.fov, lens.fov, t);
1525
+ from.near = lens.near;
1526
+ from.far = lens.far;
1527
+ if (isLensChanged) {
1528
+ from.updateProjectionMatrix();
1529
+ }
1530
+ }
1531
+ constructor(...args){
1532
+ super(...args);
1533
+ this._vcam = null;
1534
+ this._vcamSolo = null;
1535
+ this._vcams = [];
1536
+ this._lerpTime = 4;
1537
+ this.brainBlend = new CinestationBlendDefinition();
1538
+ }
1539
+ }
1540
+ __decorate([
1541
+ property
1542
+ ], CinestationBrain.prototype, "brainBlend", void 0);
1543
+
1544
+ class Lens {
1545
+ constructor(){
1546
+ this.fov = 45;
1547
+ this.near = 0.1;
1548
+ this.far = 1000;
1549
+ }
1550
+ }
1551
+ __decorate([
1552
+ property
1553
+ ], Lens.prototype, "fov", void 0);
1554
+ __decorate([
1555
+ property
1556
+ ], Lens.prototype, "near", void 0);
1557
+ __decorate([
1558
+ property
1559
+ ], Lens.prototype, "far", void 0);
1560
+ class VirtualCamera extends Component {
1561
+ get finalPosition() {
1562
+ return this._finalPosition.copy(this.node.position).add(this.correctPosition);
1563
+ }
1564
+ get finalRotation() {
1565
+ return this._finalRotation.copy(this.node.quaternion).multiply(this.correctRotation);
1566
+ }
1567
+ onLoad() {
1568
+ const camera = this.viewer.camera;
1569
+ this.node.isCamera = true;
1570
+ this.lens.fov = camera.fov;
1571
+ this.lens.near = camera.near;
1572
+ this.lens.far = camera.far;
1573
+ this.brain = this.manager.getComponent(camera, CinestationBrain, true);
1574
+ this.brain.addCamera(this);
1575
+ }
1576
+ onDestroy() {
1577
+ this.brain.removeCamera(this);
1578
+ }
1579
+ constructor(...args){
1580
+ super(...args);
1581
+ this._finalPosition = new Vector3();
1582
+ this._finalRotation = new Quaternion();
1583
+ this.locked = false;
1584
+ this.priority = 10;
1585
+ this.lens = new Lens();
1586
+ this.correctPosition = new Vector3();
1587
+ this.correctRotation = new Quaternion();
1588
+ }
1589
+ }
1590
+ __decorate([
1591
+ property
1592
+ ], VirtualCamera.prototype, "lens", void 0);
1593
+
1594
+ const PressState = {
1595
+ NONE: 1 << 0,
1596
+ SELECTED: 1 << 1,
1597
+ IN: 1 << 2
1598
+ };
1599
+ class Pressability {
1600
+ connect(target) {
1601
+ let connector = this._connectors.find((v)=>v.target === target);
1602
+ if (connector === undefined) {
1603
+ connector = {
1604
+ target,
1605
+ state: PressState.NONE
1606
+ };
1607
+ this._connectors.push(connector);
1608
+ }
1609
+ }
1610
+ disconnect(target) {
1611
+ let index = this._connectors.findIndex((v)=>v.target === target);
1612
+ if (index !== -1) {
1613
+ this._connectors.splice(index, 1);
1614
+ }
1615
+ }
1616
+ pointerDown(pointer, camera) {
1617
+ if (this._connectors.length === 0) return;
1618
+ this._raycaster.setFromCamera(pointer, camera);
1619
+ for (let conn of this._connectors){
1620
+ if (conn.target.has("click") || conn.target.has("pointerdown")) {
1621
+ let intersects = this._raycaster.intersectObject(conn.target.node, true);
1622
+ if (intersects.length) {
1623
+ conn.state |= PressState.SELECTED;
1624
+ conn.target.emit("pointerdown", {
1625
+ intersects
1626
+ });
1627
+ }
1628
+ }
1629
+ }
1630
+ }
1631
+ pointerUp(pointer, camera) {
1632
+ if (this._connectors.length === 0) return;
1633
+ this._raycaster.setFromCamera(pointer, camera);
1634
+ for (let conn of this._connectors){
1635
+ if (conn.target.has("click") || conn.target.has("pointerup")) {
1636
+ let intersects = this._raycaster.intersectObject(conn.target.node, true);
1637
+ if (intersects.length) {
1638
+ if (conn.state & PressState.SELECTED) {
1639
+ conn.state &= ~PressState.SELECTED;
1640
+ conn.target.emit("click", {
1641
+ intersects
1642
+ });
1643
+ }
1644
+ conn.target.emit("pointerup", {
1645
+ intersects
1646
+ });
1647
+ }
1648
+ }
1649
+ }
1650
+ }
1651
+ pointerMove(pointer, camera) {
1652
+ if (this._connectors.length === 0) return;
1653
+ this._raycaster.setFromCamera(pointer, camera);
1654
+ for (let conn of this._connectors){
1655
+ if (conn.target.has("pointerover") || conn.target.has("pointerout")) {
1656
+ let intersects = this._raycaster.intersectObject(conn.target.node, true);
1657
+ if (intersects.length) {
1658
+ if (!(conn.state & PressState.IN)) {
1659
+ conn.state |= PressState.IN;
1660
+ conn.target.emit("pointerover", {
1661
+ intersects
1662
+ });
1663
+ }
1664
+ } else {
1665
+ if (conn.state & PressState.IN) {
1666
+ conn.state &= ~PressState.IN;
1667
+ conn.target.emit("pointerout", {
1668
+ intersects
1669
+ });
1670
+ }
1671
+ }
1672
+ }
1673
+ }
1674
+ }
1675
+ constructor(){
1676
+ this._raycaster = new Raycaster();
1677
+ this._connectors = [];
1678
+ }
1679
+ }
1680
+
1681
+ class DeviceInput {
1682
+ get pointerButton() {
1683
+ return this._pointerButton;
1684
+ }
1685
+ get pointer() {
1686
+ return this._pointer;
1687
+ }
1688
+ get pointerPosition() {
1689
+ return this._pointerPosition;
1690
+ }
1691
+ get mouseWheel() {
1692
+ return this._mouseWheel;
1693
+ }
1694
+ get touchCount() {
1695
+ return this._touchCount;
1696
+ }
1697
+ get touches() {
1698
+ return this._touches;
1699
+ }
1700
+ get keys() {
1701
+ return this._keys;
1702
+ }
1703
+ addEventListeners() {
1704
+ const { canvas } = this.viewer;
1705
+ canvas.style.touchAction = 'none';
1706
+ this._addEventListener(canvas, 'contextmenu', (e)=>e.preventDefault());
1707
+ this._addEventListener(canvas, "pointerdown", (e)=>this._onPointerDown(e), {
1708
+ passive: false
1709
+ });
1710
+ this._addEventListener(canvas, "pointerup", (e)=>this._onPointerUp(e), {
1711
+ passive: false
1712
+ });
1713
+ this._addEventListener(canvas, "pointercancel", (e)=>this._onPointerUp(e), {
1714
+ passive: false
1715
+ });
1716
+ this._addEventListener(canvas, "pointerout", (e)=>this._onPointerUp(e), {
1717
+ passive: false
1718
+ });
1719
+ this._addEventListener(canvas, "pointermove", (e)=>this._onPointerMove(e), {
1720
+ passive: true
1721
+ });
1722
+ this._addEventListener(canvas, "wheel", (e)=>this._onMouseWheel(e), {
1723
+ passive: false
1724
+ });
1725
+ this._addEventListener(canvas, "touchstart", (e)=>this._onTouchStart(e), {
1726
+ passive: true
1727
+ });
1728
+ this._addEventListener(canvas, "touchend", (e)=>this._onTouchEnd(e), {
1729
+ passive: true
1730
+ });
1731
+ this._addEventListener(canvas, "touchmove", (e)=>this._onTouchMove(e), {
1732
+ passive: true
1733
+ });
1734
+ //监听了pointer事件之后,key事件失效,改成window解决
1735
+ this._addEventListener(window, "keydown", (e)=>this._onKeyDown(e), {
1736
+ passive: false
1737
+ });
1738
+ this._addEventListener(window, "keypress", (e)=>this._onKeyPress(e), {
1739
+ passive: false
1740
+ });
1741
+ this._addEventListener(window, "keyup", (e)=>this._onKeyUp(e), {
1742
+ passive: false
1743
+ });
1744
+ this._addEventListener(window, "resize", (e)=>this._onResize(e), {
1745
+ passive: false
1746
+ });
1747
+ }
1748
+ removeAllListeners() {
1749
+ for (let { target, type, callback } of this._listeners){
1750
+ if (target.removeEventListener) target.removeEventListener(type, callback);
1751
+ else if (target.off) target.off(type, callback, target);
1752
+ }
1753
+ this._listeners = [];
1754
+ }
1755
+ connect(target, event) {
1756
+ switch(event){
1757
+ case DeviceInput.CLICK:
1758
+ case DeviceInput.POINTER_DOWN:
1759
+ case DeviceInput.POINTER_UP:
1760
+ case DeviceInput.POINTER_OVER:
1761
+ case DeviceInput.POINTER_OUT:
1762
+ this._pressability.connect(target);
1763
+ break;
1764
+ }
1765
+ }
1766
+ disconnect(target) {
1767
+ this._pressability.disconnect(target);
1768
+ }
1769
+ _addEventListener(target, type, callback, options) {
1770
+ if (target.addEventListener) target.addEventListener(type, callback, options);
1771
+ else if (target.on) target.on(type, callback, target);
1772
+ this._listeners.push({
1773
+ target,
1774
+ type,
1775
+ callback
1776
+ });
1777
+ }
1778
+ _onResize(e) {
1779
+ this.viewer.rotate();
1780
+ this.viewer.resize();
1781
+ }
1782
+ _remapPointer(e) {
1783
+ const width = this.viewer.width;
1784
+ return this.viewer.rootRotated ? {
1785
+ button: e.button,
1786
+ buttons: e.buttons,
1787
+ clientX: e.clientY,
1788
+ clientY: width - e.clientX,
1789
+ offsetX: e.offsetY,
1790
+ offsetY: width - e.offsetX,
1791
+ pageX: e.pageY,
1792
+ pageY: width - e.pageX,
1793
+ screenX: e.screenY,
1794
+ screenY: width - e.screenX,
1795
+ movementX: e.movementY,
1796
+ movementY: e.movementX
1797
+ } : e;
1798
+ }
1799
+ _remapTouch(e) {
1800
+ const width = this.viewer.width;
1801
+ return this.viewer.rootRotated ? {
1802
+ touches: Array.from(e.touches).map((v)=>{
1803
+ return {
1804
+ identifier: v.identifier,
1805
+ clientX: v.clientY,
1806
+ clientY: width - v.clientX,
1807
+ pageX: v.pageY,
1808
+ pageY: width - v.pageX,
1809
+ screenX: v.screenY,
1810
+ screenY: width - v.screenX
1811
+ };
1812
+ })
1813
+ } : e;
1814
+ }
1815
+ _computePointer(e) {
1816
+ this._pointer.x = e.offsetX / this.viewer.width * 2 - 1;
1817
+ this._pointer.y = 1 - e.offsetY / this.viewer.height * 2;
1818
+ this._pointerPosition.set(e.offsetX, e.offsetY);
1819
+ }
1820
+ _onPointerDown(e) {
1821
+ e.preventDefault();
1822
+ e = this._remapPointer(e);
1823
+ this._pointerButton = e.button;
1824
+ this._computePointer(e);
1825
+ this._pressability.pointerDown(this._pointer, this.viewer.camera);
1826
+ this.viewer.emit(DeviceInput.POINTER_DOWN, e);
1827
+ }
1828
+ _onPointerUp(e) {
1829
+ e.preventDefault();
1830
+ e = this._remapPointer(e);
1831
+ this._pointerButton = -1;
1832
+ this._computePointer(e);
1833
+ this._pressability.pointerUp(this._pointer, this.viewer.camera);
1834
+ this.viewer.emit(DeviceInput.POINTER_UP, e);
1835
+ }
1836
+ _onPointerMove(e) {
1837
+ e = this._remapPointer(e);
1838
+ this._computePointer(e);
1839
+ this._pressability.pointerMove(this._pointer, this.viewer.camera);
1840
+ this.viewer.emit(DeviceInput.POINTER_MOVE, e);
1841
+ }
1842
+ _onMouseWheel(e) {
1843
+ e.preventDefault();
1844
+ this._mouseWheel = e.deltaY || e.wheelDelta;
1845
+ this.viewer.emit(DeviceInput.MOUSE_WHEEL, e);
1846
+ }
1847
+ _onTouchStart(e) {
1848
+ e = this._remapTouch(e);
1849
+ this.viewer.emit(DeviceInput.TOUCH_START, e);
1850
+ }
1851
+ _onTouchEnd(e) {
1852
+ e = this._remapTouch(e);
1853
+ this.viewer.emit(DeviceInput.TOUCH_END, e);
1854
+ }
1855
+ _onTouchMove(e) {
1856
+ e = this._remapTouch(e);
1857
+ let touches = e.touches;
1858
+ let touchesTo = this._touches;
1859
+ for(let i = touches.length; i--;){
1860
+ if (touchesTo[i] == undefined) {
1861
+ touchesTo[i] = {
1862
+ id: -1,
1863
+ position: new Vector2()
1864
+ };
1865
+ }
1866
+ const touch = touches[i];
1867
+ touchesTo[i].id = touch.identifier;
1868
+ touchesTo[i].position.set(touch.pageX, touch.pageY);
1869
+ }
1870
+ this._touchCount = touches.length;
1871
+ this.viewer.emit(DeviceInput.TOUCH_MOVE, e);
1872
+ }
1873
+ _onKeyDown(e) {
1874
+ this._keys[e.key] = true;
1875
+ this.viewer.emit(DeviceInput.KEYDOWN, e);
1876
+ }
1877
+ _onKeyPress(e) {
1878
+ this._keys[e.key] = true;
1879
+ this.viewer.emit(DeviceInput.KEYPRESS, e);
1880
+ }
1881
+ _onKeyUp(e) {
1882
+ this._keys[e.key] = false;
1883
+ this.viewer.emit(DeviceInput.KEYUP, e);
1884
+ }
1885
+ constructor(viewer){
1886
+ this.viewer = viewer;
1887
+ this._listeners = [];
1888
+ this._mouseWheel = 0;
1889
+ this._touches = [];
1890
+ this._touchCount = 0;
1891
+ this._pointerButton = -1;
1892
+ this._pointerPosition = new Vector2();
1893
+ this._pointer = new Vector2();
1894
+ this._keys = {};
1895
+ this._pressability = new Pressability();
1896
+ }
1897
+ }
1898
+ DeviceInput.CLICK = "click";
1899
+ DeviceInput.MOUSE_WHEEL = "mousewheel";
1900
+ DeviceInput.TOUCH_START = "touchstart";
1901
+ DeviceInput.TOUCH_END = "touchend";
1902
+ DeviceInput.TOUCH_MOVE = "touchmove";
1903
+ DeviceInput.POINTER_DOWN = "pointerdown";
1904
+ DeviceInput.POINTER_UP = "pointerup";
1905
+ DeviceInput.POINTER_MOVE = "pointermove";
1906
+ DeviceInput.POINTER_OVER = "pointerover";
1907
+ DeviceInput.POINTER_OUT = "pointerout";
1908
+ DeviceInput.KEYDOWN = "keydown";
1909
+ DeviceInput.KEYPRESS = "keypress";
1910
+ DeviceInput.KEYUP = "keyup";
1911
+
1912
+ const isSSR$1 = typeof window === 'undefined';
1913
+ class DetectUA {
1914
+ /**
1915
+ * Match entry based on position found in the user-agent string
1916
+ *
1917
+ * @param pattern regular expression pattern
1918
+ */ match(position, pattern) {
1919
+ const match = this.userAgent.match(pattern);
1920
+ return match && match.length > 1 && match[position] || '';
1921
+ }
1922
+ /**
1923
+ * Returns if the device is a mobile device
1924
+ */ get isMobile() {
1925
+ return(// Default mobile
1926
+ !this.isTablet && (/[^-]mobi/i.test(this.userAgent) || // iPhone / iPod
1927
+ this.iOSDevice === 'iphone' || this.iOSDevice === 'ipod' || // Android
1928
+ this.isAndroidDevice || // Nexus mobile
1929
+ /nexus\s*[0-6]\s*/i.test(this.userAgent)));
1930
+ }
1931
+ /**
1932
+ * Returns if the device is a tablet device
1933
+ */ get isTablet() {
1934
+ return(// Default tablet
1935
+ /tablet/i.test(this.userAgent) && !/tablet pc/i.test(this.userAgent) || // iPad
1936
+ this.iOSDevice === 'ipad' || // Android
1937
+ this.isAndroidDevice && !/[^-]mobi/i.test(this.userAgent) || // Nexus tablet
1938
+ !/nexus\s*[0-6]\s*/i.test(this.userAgent) && /nexus\s*[0-9]+/i.test(this.userAgent));
1939
+ }
1940
+ /**
1941
+ * Returns if the device is a desktop device
1942
+ */ get isDesktop() {
1943
+ return !this.isMobile && !this.isTablet;
1944
+ }
1945
+ /**
1946
+ * Returns if the device is running MacOS (and if so which version)
1947
+ *
1948
+ * '5' => Leopard'
1949
+ * '6' => Snow Leopard'
1950
+ * '7' => Lion'
1951
+ * '8' => Mountain Lion'
1952
+ * '9' => Mavericks'
1953
+ * '10' => Yosemite'
1954
+ * '11' => El Capitan'
1955
+ * '12' => Sierra'
1956
+ * '13' => High Sierra'
1957
+ * '14' => Mojave'
1958
+ * '15' => Catalina'
1959
+ */ get isMacOS() {
1960
+ return /macintosh/i.test(this.userAgent) && {
1961
+ version: this.match(1, /mac os x (\d+(\.?_?\d+)+)/i).replace(/[_\s]/g, '.').split('.').map((versionNumber)=>versionNumber)[1]
1962
+ };
1963
+ }
1964
+ /**
1965
+ * Returns if the device is running Windows (and if so which version)
1966
+ *
1967
+ * 'NT' => 'NT'
1968
+ * 'XP' => 'XP'
1969
+ * 'NT 5.0' => '2000'
1970
+ * 'NT 5.1' => 'XP'
1971
+ * 'NT 5.2' => '2003'
1972
+ * 'NT 6.0' => 'Vista'
1973
+ * 'NT 6.1' => '7'
1974
+ * 'NT 6.2' => '8'
1975
+ * 'NT 6.3' => '8.1'
1976
+ * 'NT 10.0' => '10'
1977
+ */ get isWindows() {
1978
+ return /windows /i.test(this.userAgent) && {
1979
+ version: this.match(1, /Windows ((NT|XP)( \d\d?.\d)?)/i)
1980
+ };
1981
+ }
1982
+ /**
1983
+ * Returns if the device is an iOS device (and if so which version)
1984
+ */ get isiOS() {
1985
+ return !!this.iOSDevice && {
1986
+ version: this.match(1, /os (\d+([_\s]\d+)*) like mac os x/i).replace(/[_\s]/g, '.') || this.match(1, /version\/(\d+(\.\d+)?)/i)
1987
+ };
1988
+ }
1989
+ /**
1990
+ * Returns if the device is an Android device (and if so which version)
1991
+ */ get isAndroid() {
1992
+ return this.isAndroidDevice && {
1993
+ version: this.match(1, /android[ \/-](\d+(\.\d+)*)/i)
1994
+ };
1995
+ }
1996
+ /**
1997
+ * Returns the browser name and version
1998
+ */ get browser() {
1999
+ const versionIdentifier = this.match(1, /version\/(\d+(\.\d+)?)/i);
2000
+ if (/opera/i.test(this.userAgent)) {
2001
+ // Opera
2002
+ return {
2003
+ name: 'Opera',
2004
+ version: versionIdentifier || this.match(1, /(?:opera|opr|opios)[\s\/](\d+(\.\d+)?)/i)
2005
+ };
2006
+ } else if (/opr\/|opios/i.test(this.userAgent)) {
2007
+ // Opera
2008
+ return {
2009
+ name: 'Opera',
2010
+ version: this.match(1, /(?:opr|opios)[\s\/](\d+(\.\d+)?)/i) || versionIdentifier
2011
+ };
2012
+ } else if (/SamsungBrowser/i.test(this.userAgent)) {
2013
+ // Samsung Browser
2014
+ return {
2015
+ name: 'Samsung Internet for Android',
2016
+ version: versionIdentifier || this.match(1, /(?:SamsungBrowser)[\s\/](\d+(\.\d+)?)/i)
2017
+ };
2018
+ } else if (/yabrowser/i.test(this.userAgent)) {
2019
+ // Yandex Browser
2020
+ return {
2021
+ name: 'Yandex Browser',
2022
+ version: versionIdentifier || this.match(1, /(?:yabrowser)[\s\/](\d+(\.\d+)?)/i)
2023
+ };
2024
+ } else if (/ucbrowser/i.test(this.userAgent)) {
2025
+ // UC Browser
2026
+ return {
2027
+ name: 'UC Browser',
2028
+ version: this.match(1, /(?:ucbrowser)[\s\/](\d+(\.\d+)?)/i)
2029
+ };
2030
+ } else if (/msie|trident/i.test(this.userAgent)) {
2031
+ // Internet Explorer
2032
+ return {
2033
+ name: 'Internet Explorer',
2034
+ version: this.match(1, /(?:msie |rv:)(\d+(\.\d+)?)/i)
2035
+ };
2036
+ } else if (/(edge|edgios|edga|edg)/i.test(this.userAgent)) {
2037
+ // Edge
2038
+ return {
2039
+ name: 'Microsoft Edge',
2040
+ version: this.match(2, /(edge|edgios|edga|edg)\/(\d+(\.\d+)?)/i)
2041
+ };
2042
+ } else if (/firefox|iceweasel|fxios/i.test(this.userAgent)) {
2043
+ // Firefox
2044
+ return {
2045
+ name: 'Firefox',
2046
+ version: this.match(1, /(?:firefox|iceweasel|fxios)[ \/](\d+(\.\d+)?)/i)
2047
+ };
2048
+ } else if (/chromium/i.test(this.userAgent)) {
2049
+ // Chromium
2050
+ return {
2051
+ name: 'Chromium',
2052
+ version: this.match(1, /(?:chromium)[\s\/](\d+(?:\.\d+)?)/i) || versionIdentifier
2053
+ };
2054
+ } else if (/chrome|crios|crmo/i.test(this.userAgent)) {
2055
+ // Chrome
2056
+ return {
2057
+ name: 'Chrome',
2058
+ version: this.match(1, /(?:chrome|crios|crmo)\/(\d+(\.\d+)?)/i)
2059
+ };
2060
+ } else if (/safari|applewebkit/i.test(this.userAgent)) {
2061
+ // Safari
2062
+ return {
2063
+ name: 'Safari',
2064
+ version: versionIdentifier
2065
+ };
2066
+ } else {
2067
+ // Everything else
2068
+ return {
2069
+ name: this.match(1, /^(.*)\/(.*) /),
2070
+ version: this.match(2, /^(.*)\/(.*) /)
2071
+ };
2072
+ }
2073
+ }
2074
+ /**
2075
+ * Detect a users browser, browser version and whether it is a mobile-, tablet- or desktop device
2076
+ *
2077
+ * @param forceUserAgent Force a user agent string (useful for testing)
2078
+ */ constructor(forceUserAgent){
2079
+ this.userAgent = forceUserAgent ? forceUserAgent : !isSSR$1 && window.navigator ? window.navigator.userAgent : '';
2080
+ this.isAndroidDevice = !/like android/i.test(this.userAgent) && /android/i.test(this.userAgent);
2081
+ this.iOSDevice = this.match(1, /(iphone|ipod|ipad)/i).toLowerCase();
2082
+ // Workaround for ipadOS, force detection as tablet
2083
+ // SEE: https://github.com/lancedikson/bowser/issues/329
2084
+ // SEE: https://stackoverflow.com/questions/58019463/how-to-detect-device-name-in-safari-on-ios-13-while-it-doesnt-show-the-correct
2085
+ if (!isSSR$1 && navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 2 && !window.MSStream) {
2086
+ this.iOSDevice = 'ipad';
2087
+ }
2088
+ }
2089
+ }
2090
+
2091
+ const isSSR = typeof window === 'undefined';
2092
+ const detectUA = new DetectUA();
2093
+ const userAgent = (navigator.userAgent || navigator.vendor).toLowerCase();
2094
+ const browserName = typeof detectUA.browser === "boolean" ? "" : detectUA.browser.name;
2095
+ class SystemInfo {
2096
+ }
2097
+ SystemInfo.isTablet = detectUA.isTablet;
2098
+ SystemInfo.isMobile = detectUA.isMobile || detectUA.isTablet;
2099
+ SystemInfo.isDesktop = detectUA.isDesktop;
2100
+ SystemInfo.device = SystemInfo.isMobile ? "mobile" : "desktop";
2101
+ SystemInfo.isAndroid = !!detectUA.isAndroid;
2102
+ SystemInfo.isIOS = !!detectUA.isiOS;
2103
+ SystemInfo.isMacOS = !!detectUA.isMacOS;
2104
+ SystemInfo.isWindows = typeof detectUA.isWindows === "boolean" ? detectUA.isWindows : detectUA.isWindows.version !== null;
2105
+ SystemInfo.isLinux = userAgent.indexOf("linux") != -1;
2106
+ SystemInfo.ua = userAgent;
2107
+ SystemInfo.isEdge = browserName === "Microsoft Edge";
2108
+ SystemInfo.isIE = browserName === "Internet Explorer";
2109
+ SystemInfo.isFirefox = browserName === "Firefox";
2110
+ SystemInfo.isChrome = browserName === "Chrome";
2111
+ SystemInfo.isOpera = browserName === "Opera";
2112
+ SystemInfo.isSafari = browserName === "Safari";
2113
+ SystemInfo.isSupportMSAA = !userAgent.match("version/15.4 ");
2114
+ SystemInfo.cpuCoreCount = navigator.hardwareConcurrency || 1;
2115
+ SystemInfo.isRetina = !isSSR && window.devicePixelRatio && window.devicePixelRatio >= 1.5;
2116
+ SystemInfo.isIFrame = !isSSR && window.self !== window.top;
2117
+
2691
2118
  const { clamp, degToRad } = MathUtils;
2692
2119
  const { abs, tan, PI } = Math;
2693
2120
  const PI2 = PI * 2;
@@ -3255,75 +2682,6 @@ class Animation extends Component {
3255
2682
  }
3256
2683
  }
3257
2684
 
3258
- function applyProps(target, props) {
3259
- for(let k in props){
3260
- let prop = props[k];
3261
- if (prop === undefined) {
3262
- continue;
3263
- }
3264
- if (target[k] !== undefined) {
3265
- let des = Object.getOwnPropertyDescriptor(target, k);
3266
- if (!des || des.writable || des.set) {
3267
- target[k] = prop;
3268
- } else {
3269
- let value = target[k];
3270
- if (value && value.copy) {
3271
- value.copy(prop);
3272
- }
3273
- }
3274
- }
3275
- }
3276
- return target;
3277
- }
3278
- function find(node, path) {
3279
- let child = null;
3280
- let parts = path.split("/");
3281
- let children = node.children;
3282
- for (let part of parts){
3283
- child = children.find((v)=>v.name === part);
3284
- if (child) {
3285
- children = child.children;
3286
- } else {
3287
- return null;
3288
- }
3289
- }
3290
- return child;
3291
- }
3292
- function getChildren(node, filter, group = false) {
3293
- const queue = [
3294
- node
3295
- ];
3296
- const objects = [];
3297
- while(queue.length !== 0){
3298
- let object = queue.shift();
3299
- let target = filter(object);
3300
- if (target) {
3301
- objects.push(object);
3302
- if (!group) {
3303
- break;
3304
- }
3305
- }
3306
- object.children.forEach((v)=>queue.push(v));
3307
- }
3308
- if (group) {
3309
- return objects;
3310
- }
3311
- return objects[0];
3312
- }
3313
- function getChildByName(node, name) {
3314
- return getChildren(node, (v)=>v && v.name === name);
3315
- }
3316
- const __emtpyObject = {};
3317
- function queryValues(object, name, group = false) {
3318
- if (name) {
3319
- if (group) {
3320
- return Object.values(object || __emtpyObject).filter((v)=>v.name === name);
3321
- }
3322
- return Object.values(object || __emtpyObject).find((v)=>v.name === name);
3323
- }
3324
- return Object.values(object);
3325
- }
3326
-
3327
2685
  class ContactShadows extends Component {
3328
2686
  get visible() {
3329
2687
  return this.node.visible;
@@ -3435,6 +2793,321 @@ __decorate([
3435
2793
  })
3436
2794
  ], ContactShadows.prototype, "blur", void 0);
3437
2795
 
2796
+ const getVersion = ()=>parseInt(REVISION.replace(/\D+/g, ''));
2797
+ const version = /* @__PURE__ */ getVersion();
2798
+
2799
+ class DiscardMaterial extends ShaderMaterial {
2800
+ constructor(...args){
2801
+ super(...args);
2802
+ this.vertexShader = 'void main() { }';
2803
+ this.fragmentShader = 'void main() { gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); discard; }';
2804
+ }
2805
+ }
2806
+
2807
+ function shaderMaterial(uniforms, vertexShader, fragmentShader) {
2808
+ var _class;
2809
+ return _class = class extends THREE.ShaderMaterial {
2810
+ constructor(parameters){
2811
+ super({
2812
+ vertexShader,
2813
+ fragmentShader
2814
+ });
2815
+ for(const key in uniforms){
2816
+ this.uniforms[key] = new THREE.Uniform(uniforms[key]);
2817
+ Object.defineProperty(this, key, {
2818
+ get () {
2819
+ return this.uniforms[key].value;
2820
+ },
2821
+ set (value) {
2822
+ this.uniforms[key].value = value;
2823
+ }
2824
+ });
2825
+ }
2826
+ this.uniforms = THREE.UniformsUtils.clone(this.uniforms);
2827
+ this.setValues(parameters);
2828
+ }
2829
+ }, _class.key = THREE.MathUtils.generateUUID(), _class;
2830
+ }
2831
+
2832
+ class AccumulativeShadows extends Component {
2833
+ constructor({ temporal, frames = 40, limit = Infinity, blend = 20, scale = 10, opacity = 1, alphaTest = 0.75, color = 'black', colorBlend = 2, resolution = 1024, toneMapped = true, randomLights = [], ...props } = {}){
2834
+ super();
2835
+ this.temporal = false;
2836
+ this.frames = 1;
2837
+ this.count = 0;
2838
+ this.limit = Infinity;
2839
+ this.blend = 2;
2840
+ this.temporal = !!temporal;
2841
+ this.frames = Math.max(2, frames);
2842
+ this.blend = Math.max(2, frames === Infinity ? blend : frames);
2843
+ this.count = 0;
2844
+ this.node = applyProps(new THREE.Group(), props);
2845
+ this.onLoad = ()=>{
2846
+ const { viewer } = this;
2847
+ const { renderer, scene, camera } = viewer;
2848
+ const plm = new ProgressiveLightMap(renderer, scene, resolution);
2849
+ const gPlane = viewer.add(Plane, {
2850
+ parent: this.node,
2851
+ receiveShadow: true,
2852
+ scale: new THREE.Vector3(scale, scale, scale),
2853
+ rotation: new THREE.Euler(-Math.PI / 2, 0, 0),
2854
+ material: new SoftShadowMaterial({
2855
+ color,
2856
+ toneMapped,
2857
+ transparent: true,
2858
+ depthWrite: false,
2859
+ blend: colorBlend,
2860
+ map: plm.progressiveLightMap2.texture
2861
+ })
2862
+ });
2863
+ plm.configure(gPlane);
2864
+ const gLights = viewer.add(THREE.Group, {
2865
+ parent: this.node
2866
+ });
2867
+ gLights.traverse = ()=>null;
2868
+ randomLights.forEach((light)=>gLights.add(light));
2869
+ const update = (frames = 1)=>{
2870
+ // Adapt the opacity-blend ratio to the number of frames
2871
+ const material = gPlane.material;
2872
+ if (!this.temporal) {
2873
+ material.opacity = opacity;
2874
+ material.alphaTest = alphaTest;
2875
+ } else {
2876
+ material.opacity = Math.min(opacity, material.opacity + opacity / this.blend);
2877
+ material.alphaTest = Math.min(alphaTest, material.alphaTest + alphaTest / this.blend);
2878
+ }
2879
+ // Switch accumulative lights on
2880
+ gLights.visible = true;
2881
+ // Collect scene lights and meshes
2882
+ plm.prepare();
2883
+ // Update the lightmap and the accumulative lights
2884
+ for(let i = 0; i < frames; i++){
2885
+ randomLights.forEach((light)=>light.update());
2886
+ plm.update(camera, this.blend);
2887
+ }
2888
+ // Switch lights off
2889
+ gLights.visible = false;
2890
+ // Restore lights and meshes
2891
+ plm.finish();
2892
+ };
2893
+ const reset = ()=>{
2894
+ // Clear buffers, reset opacities, set frame count to 0
2895
+ plm.clear();
2896
+ const material = gPlane.material;
2897
+ material.opacity = 0;
2898
+ material.alphaTest = 0;
2899
+ this.count = 0;
2900
+ };
2901
+ this.start = ()=>{
2902
+ // Reset internals, buffers, ...
2903
+ reset();
2904
+ // Update lightmap
2905
+ if (!this.temporal && this.frames !== Infinity) update(this.blend);
2906
+ };
2907
+ this.update = ()=>{
2908
+ if ((this.temporal || this.frames === Infinity) && this.count < this.frames && this.count < this.limit) {
2909
+ update();
2910
+ this.count++;
2911
+ }
2912
+ };
2913
+ };
2914
+ }
2915
+ }
2916
+ class RandomizedLight extends THREE.Group {
2917
+ constructor({ castShadow = true, bias = 0.001, mapSize = 512, size = 5, near = 0.5, far = 500, frames = 1, position = new THREE.Vector3(), radius = 1, amount = 8, intensity = version >= 155 ? Math.PI : 1, ambient = 0.5, ...props } = {}){
2918
+ super();
2919
+ applyProps(this, props);
2920
+ const length = position.length();
2921
+ for(let i = 0; i < amount; i++){
2922
+ const light = new THREE.DirectionalLight();
2923
+ light.shadow.bias = bias;
2924
+ light.shadow.mapSize.set(mapSize, mapSize);
2925
+ light.shadow.camera = new THREE.OrthographicCamera(-size, size, size, -size, near, far);
2926
+ light.castShadow = castShadow;
2927
+ light.intensity = intensity / amount;
2928
+ this.add(light);
2929
+ }
2930
+ this.update = ()=>{
2931
+ for (let light of this.children){
2932
+ if (Math.random() > ambient) {
2933
+ light.position.set(position.x + THREE.MathUtils.randFloatSpread(radius), position.y + THREE.MathUtils.randFloatSpread(radius), position.z + THREE.MathUtils.randFloatSpread(radius));
2934
+ } else {
2935
+ const lambda = Math.acos(2 * Math.random() - 1) - Math.PI / 2.0;
2936
+ const phi = 2 * Math.PI * Math.random();
2937
+ light.position.set(Math.cos(lambda) * Math.cos(phi) * length, Math.abs(Math.cos(lambda) * Math.sin(phi) * length), Math.sin(lambda) * length);
2938
+ }
2939
+ }
2940
+ };
2941
+ }
2942
+ }
2943
+ const SoftShadowMaterial = shaderMaterial({
2944
+ color: new THREE.Color(),
2945
+ blend: 2.0,
2946
+ alphaTest: 0.75,
2947
+ opacity: 0,
2948
+ map: null
2949
+ }, `varying vec2 vUv;
2950
+ void main() {
2951
+ gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(position, 1.);
2952
+ vUv = uv;
2953
+ }`, `varying vec2 vUv;
2954
+ uniform sampler2D map;
2955
+ uniform vec3 color;
2956
+ uniform float opacity;
2957
+ uniform float alphaTest;
2958
+ uniform float blend;
2959
+ void main() {
2960
+ vec4 sampledDiffuseColor = texture2D(map, vUv);
2961
+ gl_FragColor = vec4(color * sampledDiffuseColor.r * blend, max(0.0, (1.0 - (sampledDiffuseColor.r + sampledDiffuseColor.g + sampledDiffuseColor.b) / alphaTest)) * opacity);
2962
+ #include <${version >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
2963
+ }`);
2964
+ function isLight(object) {
2965
+ return object.isLight;
2966
+ }
2967
+ function isGeometry(object) {
2968
+ return !!object.geometry;
2969
+ }
2970
+ class ProgressiveLightMap {
2971
+ clear() {
2972
+ this.renderer.getClearColor(this.clearColor);
2973
+ this.clearAlpha = this.renderer.getClearAlpha();
2974
+ this.renderer.setClearColor('black', 1);
2975
+ this.renderer.setRenderTarget(this.progressiveLightMap1);
2976
+ this.renderer.clear();
2977
+ this.renderer.setRenderTarget(this.progressiveLightMap2);
2978
+ this.renderer.clear();
2979
+ this.renderer.setRenderTarget(null);
2980
+ this.renderer.setClearColor(this.clearColor, this.clearAlpha);
2981
+ this.lights = [];
2982
+ this.meshes = [];
2983
+ this.scene.traverse((object)=>{
2984
+ if (isGeometry(object)) {
2985
+ this.meshes.push({
2986
+ object,
2987
+ material: object.material
2988
+ });
2989
+ } else if (isLight(object)) {
2990
+ this.lights.push({
2991
+ object,
2992
+ intensity: object.intensity
2993
+ });
2994
+ }
2995
+ });
2996
+ }
2997
+ prepare() {
2998
+ this.lights.forEach((light)=>light.object.intensity = 0);
2999
+ this.meshes.forEach((mesh)=>mesh.object.material = this.discardMat);
3000
+ }
3001
+ finish() {
3002
+ this.lights.forEach((light)=>light.object.intensity = light.intensity);
3003
+ this.meshes.forEach((mesh)=>mesh.object.material = mesh.material);
3004
+ }
3005
+ configure(object) {
3006
+ this.object = object;
3007
+ }
3008
+ update(camera, blendWindow = 100) {
3009
+ if (!this.object) return;
3010
+ // Set each object's material to the UV Unwrapped Surface Mapping Version
3011
+ this.averagingWindow.value = blendWindow;
3012
+ this.object.material = this.targetMat;
3013
+ // Ping-pong two surface buffers for reading/writing
3014
+ const activeMap = this.buffer1Active ? this.progressiveLightMap1 : this.progressiveLightMap2;
3015
+ const inactiveMap = this.buffer1Active ? this.progressiveLightMap2 : this.progressiveLightMap1;
3016
+ // Render the object's surface maps
3017
+ const oldBg = this.scene.background;
3018
+ this.scene.background = null;
3019
+ this.renderer.setRenderTarget(activeMap);
3020
+ this.previousShadowMap.value = inactiveMap.texture;
3021
+ this.buffer1Active = !this.buffer1Active;
3022
+ this.renderer.render(this.scene, camera);
3023
+ this.renderer.setRenderTarget(null);
3024
+ this.scene.background = oldBg;
3025
+ }
3026
+ constructor(renderer, scene, res = 1024){
3027
+ this.renderer = renderer;
3028
+ this.res = res;
3029
+ this.scene = scene;
3030
+ this.buffer1Active = false;
3031
+ this.lights = [];
3032
+ this.meshes = [];
3033
+ this.object = null;
3034
+ this.clearColor = new THREE.Color();
3035
+ this.clearAlpha = 0;
3036
+ // Create the Progressive LightMap Texture
3037
+ const textureParams = {
3038
+ type: THREE.HalfFloatType,
3039
+ magFilter: THREE.NearestFilter,
3040
+ minFilter: THREE.NearestFilter
3041
+ };
3042
+ this.progressiveLightMap1 = new THREE.WebGLRenderTarget(this.res, this.res, textureParams);
3043
+ this.progressiveLightMap2 = new THREE.WebGLRenderTarget(this.res, this.res, textureParams);
3044
+ // Inject some spicy new logic into a standard phong material
3045
+ this.discardMat = new DiscardMaterial();
3046
+ this.targetMat = new THREE.MeshLambertMaterial({
3047
+ fog: false
3048
+ });
3049
+ this.previousShadowMap = {
3050
+ value: this.progressiveLightMap1.texture
3051
+ };
3052
+ this.averagingWindow = {
3053
+ value: 100
3054
+ };
3055
+ this.targetMat.onBeforeCompile = (shader)=>{
3056
+ // Vertex Shader: Set Vertex Positions to the Unwrapped UV Positions
3057
+ shader.vertexShader = 'varying vec2 vUv;\n' + shader.vertexShader.slice(0, -1) + 'vUv = uv; gl_Position = vec4((uv - 0.5) * 2.0, 1.0, 1.0); }';
3058
+ // Fragment Shader: Set Pixels to average in the Previous frame's Shadows
3059
+ const bodyStart = shader.fragmentShader.indexOf('void main() {');
3060
+ shader.fragmentShader = 'varying vec2 vUv;\n' + shader.fragmentShader.slice(0, bodyStart) + 'uniform sampler2D previousShadowMap;\n uniform float averagingWindow;\n' + shader.fragmentShader.slice(bodyStart - 1, -1) + `\nvec3 texelOld = texture2D(previousShadowMap, vUv).rgb;
3061
+ gl_FragColor.rgb = mix(texelOld, gl_FragColor.rgb, 1.0/ averagingWindow);
3062
+ }`;
3063
+ // Set the Previous Frame's Texture Buffer and Averaging Window
3064
+ shader.uniforms.previousShadowMap = this.previousShadowMap;
3065
+ shader.uniforms.averagingWindow = this.averagingWindow;
3066
+ };
3067
+ }
3068
+ }
3069
+
3070
+ class Center extends Component {
3071
+ constructor({ disable, disableX, disableY, disableZ, left, right, top, bottom, front, back, onCentered, precise = true, cacheKey = 0, children = [], ...props } = {}){
3072
+ super();
3073
+ this.node = applyProps(new Group(), props);
3074
+ this.start = ()=>{
3075
+ const inner = new Group().add(...children);
3076
+ const outer = new Group().add(inner);
3077
+ this.node.add(outer);
3078
+ outer.matrixWorld.identity();
3079
+ const box3 = new Box3().setFromObject(inner, precise);
3080
+ const center = new Vector3();
3081
+ const sphere = new Sphere$1();
3082
+ const width = box3.max.x - box3.min.x;
3083
+ const height = box3.max.y - box3.min.y;
3084
+ const depth = box3.max.z - box3.min.z;
3085
+ box3.getCenter(center);
3086
+ box3.getBoundingSphere(sphere);
3087
+ const vAlign = top ? height / 2 : bottom ? -height / 2 : 0;
3088
+ const hAlign = left ? -width / 2 : right ? width / 2 : 0;
3089
+ const dAlign = front ? depth / 2 : back ? -depth / 2 : 0;
3090
+ outer.position.set(disable || disableX ? 0 : -center.x + hAlign, disable || disableY ? 0 : -center.y + vAlign, disable || disableZ ? 0 : -center.z + dAlign);
3091
+ // Only fire onCentered if the bounding box has changed
3092
+ if (typeof onCentered !== 'undefined') {
3093
+ onCentered({
3094
+ parent: this.node.parent,
3095
+ container: this.node,
3096
+ width,
3097
+ height,
3098
+ depth,
3099
+ boundingBox: box3,
3100
+ boundingSphere: sphere,
3101
+ center: center,
3102
+ verticalAlignment: vAlign,
3103
+ horizontalAlignment: hAlign,
3104
+ depthAlignment: dAlign
3105
+ });
3106
+ }
3107
+ };
3108
+ }
3109
+ }
3110
+
3438
3111
  const vert_fullscreen = /*glsl*/ `
3439
3112
  varying vec2 vUv;
3440
3113
  void main() {
@@ -3984,6 +3657,143 @@ class ShadowMaterial extends ShaderMaterial {
3984
3657
  }
3985
3658
  }
3986
3659
 
3660
+ class Mount extends Component {
3661
+ constructor(...args){
3662
+ super(...args);
3663
+ this.isMount = true;
3664
+ }
3665
+ }
3666
+
3667
+ class UI extends Mount {
3668
+ get layerMask() {
3669
+ return this._camera.layers.mask;
3670
+ }
3671
+ set layerMask(v) {
3672
+ this._camera.layers.mask = v;
3673
+ }
3674
+ onLoad() {
3675
+ const { width, height } = this.viewer;
3676
+ const aspect = width / height;
3677
+ this._camera = new OrthographicCamera(-aspect, aspect, 1, -1, -1000, 10000);
3678
+ this._camera.layers.mask = 1 << 1;
3679
+ this.viewer.on(DeviceInput.POINTER_DOWN, this._onPointerDown, this);
3680
+ this.viewer.on(DeviceInput.POINTER_UP, this._onPointerUp, this);
3681
+ this.viewer.on(DeviceInput.POINTER_MOVE, this._onPointerMove, this);
3682
+ this.viewer.on(DeviceInput.MOUSE_WHEEL, this._onMouseWheel, this);
3683
+ this.viewer.on(DeviceInput.TOUCH_START, this._onTouchStart, this);
3684
+ this.viewer.on(DeviceInput.TOUCH_MOVE, this._onTouchMove, this);
3685
+ }
3686
+ onDestroy() {
3687
+ this.viewer.targetOff(this);
3688
+ }
3689
+ _onPointerDown(e) {
3690
+ if (SystemInfo.isMobile) return;
3691
+ this._button = e.button;
3692
+ this._preLoc0.set(e.pageX, e.pageY);
3693
+ }
3694
+ _onPointerUp(e) {
3695
+ if (SystemInfo.isMobile) return;
3696
+ this._button = -1;
3697
+ }
3698
+ _onPointerMove(e) {
3699
+ if (SystemInfo.isMobile) return;
3700
+ const { __loc0, __panOffset } = UI;
3701
+ __loc0.set(e.pageX, e.pageY);
3702
+ switch(this._button){
3703
+ case 0:
3704
+ this._setTargetPosition(this._calculatePanDelta(__panOffset, __loc0, this._preLoc0));
3705
+ break;
3706
+ }
3707
+ this._preLoc0.copy(__loc0);
3708
+ }
3709
+ _onMouseWheel(e) {
3710
+ if (e.deltaY > 0) {
3711
+ this._targetZoom *= 0.85;
3712
+ } else if (e.deltaY < 0) {
3713
+ this._targetZoom /= 0.85;
3714
+ }
3715
+ }
3716
+ _onTouchStart(e) {
3717
+ if (!SystemInfo.isMobile) return;
3718
+ let touches = e.touches;
3719
+ if (touches.length > 1) {
3720
+ this._preLoc0.set(touches[0].pageX, touches[0].pageY);
3721
+ this._preLoc1.set(touches[1].pageX, touches[1].pageY);
3722
+ } else if (touches.length > 0) {
3723
+ this._touchID = touches[0].identifier;
3724
+ this._preLoc0.set(touches[0].pageX, touches[0].pageY);
3725
+ }
3726
+ }
3727
+ _onTouchMove(e) {
3728
+ if (!SystemInfo.isMobile) return;
3729
+ const { __loc0, __loc1, __panOffset } = UI;
3730
+ let touches = e.touches;
3731
+ if (touches.length > 1) {
3732
+ __loc0.set(touches[0].pageX, touches[0].pageY);
3733
+ __loc1.set(touches[1].pageX, touches[1].pageY);
3734
+ this._targetZoom /= this._preLoc0.distanceTo(this._preLoc1) / __loc0.distanceTo(__loc1);
3735
+ this._preLoc0.copy(__loc0);
3736
+ this._preLoc1.copy(__loc1);
3737
+ } else if (touches.length > 0) {
3738
+ if (this._touchID === touches[0].identifier) {
3739
+ __loc0.set(touches[0].pageX, touches[0].pageY);
3740
+ this._setTargetPosition(this._calculatePanDelta(__panOffset, __loc0, this._preLoc0));
3741
+ this._preLoc0.copy(__loc0);
3742
+ }
3743
+ }
3744
+ }
3745
+ _setTargetPosition(panOffset) {
3746
+ this._targetPosition.x -= panOffset.x;
3747
+ this._targetPosition.y += panOffset.y;
3748
+ }
3749
+ _calculatePanDelta(out, loc0, loc1) {
3750
+ out.copy(loc0).sub(loc1);
3751
+ out.x *= (this._camera.right - this._camera.left) / this._camera.zoom / this.viewer.width;
3752
+ out.y *= (this._camera.top - this._camera.bottom) / this._camera.zoom / this.viewer.height;
3753
+ return out;
3754
+ }
3755
+ update(dt) {
3756
+ this._camera.position.x = FInterpTo(this._camera.position.x, this._targetPosition.x, dt, 5, 0.001);
3757
+ this._camera.position.y = FInterpTo(this._camera.position.y, this._targetPosition.y, dt, 5, 0.001);
3758
+ this._zoom = FInterpTo(this._zoom, this._targetZoom, dt, 5, 0.001);
3759
+ if (this._zoom !== this._targetZoom) {
3760
+ this._camera.zoom = this._zoom;
3761
+ this._camera.updateProjectionMatrix();
3762
+ }
3763
+ }
3764
+ resize(width, height) {
3765
+ const aspect = width / height;
3766
+ this._camera.left = -aspect;
3767
+ this._camera.right = aspect;
3768
+ this._camera.top = 1;
3769
+ this._camera.bottom = -1;
3770
+ this._camera.updateProjectionMatrix();
3771
+ }
3772
+ render(dt) {
3773
+ const { renderer, scene } = this.viewer;
3774
+ const autoClearDepth = renderer.autoClearDepth;
3775
+ const autoClearColor = renderer.autoClearColor;
3776
+ renderer.autoClearDepth = true;
3777
+ renderer.autoClearColor = false;
3778
+ renderer.render(scene, this._camera);
3779
+ renderer.autoClearDepth = autoClearDepth;
3780
+ renderer.autoClearColor = autoClearColor;
3781
+ }
3782
+ constructor(...args){
3783
+ super(...args);
3784
+ this._zoom = 1;
3785
+ this._targetZoom = 0.3;
3786
+ this._targetPosition = new Vector2();
3787
+ this._button = -1;
3788
+ this._touchID = -1;
3789
+ this._preLoc0 = new Vector2();
3790
+ this._preLoc1 = new Vector2();
3791
+ }
3792
+ }
3793
+ UI.__loc0 = new Vector2();
3794
+ UI.__loc1 = new Vector2();
3795
+ UI.__panOffset = new Vector2();
3796
+
3987
3797
  const LOD_MIN = 4;
3988
3798
  const _flatCamera = /*@__PURE__*/ new OrthographicCamera();
3989
3799
  // Golden Ratio
@@ -4541,7 +4351,7 @@ class ComponentManager {
4541
4351
  this._componentsMap.forEach((v)=>v.forEach(callback));
4542
4352
  }
4543
4353
  _addDendencies(node, constructor) {
4544
- while(constructor !== Component){
4354
+ while(constructor && constructor !== Component){
4545
4355
  let info = ComponentManager._infoMap.get(constructor);
4546
4356
  if (info) {
4547
4357
  const { components, mode } = info;
@@ -4721,6 +4531,7 @@ class ResourceManager {
4721
4531
  for (let ext of loader.extension){
4722
4532
  this._loaders.set(ext, loader);
4723
4533
  }
4534
+ return loader;
4724
4535
  }
4725
4536
  loadAsset({ url, buffer, ext, path, resourcePath, dracoPath, manager, onProgress, ...props }) {
4726
4537
  return new Promise((resolve, reject)=>{
@@ -4766,6 +4577,9 @@ ResourceManager._texSettingKeys = [
4766
4577
  "channel"
4767
4578
  ];
4768
4579
 
4580
+ Object3D.prototype.apply = function(props) {
4581
+ return applyProps(this, props);
4582
+ };
4769
4583
  class Viewer extends EventEmitter {
4770
4584
  static _setDirectLightShadow(shadow, props) {
4771
4585
  const shadowCamera = shadow.camera;
@@ -4898,15 +4712,14 @@ class Viewer extends EventEmitter {
4898
4712
  this._taskManager.destroy();
4899
4713
  this._resourceManager.destroy();
4900
4714
  this._componentManager.destroy();
4901
- this._tweens.forEach((tween)=>tween.killAll());
4902
- this._tweens = [];
4903
4715
  this._input.removeAllListeners();
4904
4716
  }
4905
4717
  _addDefaultLoaders() {
4906
- this.addLoader(aGLTFLoader);
4907
- this.addLoader(aHDRLoader);
4908
- this.addLoader(aTextureLoader);
4909
- this.addLoader(aJSONLoader);
4718
+ this.addLoader(GLTFLoader);
4719
+ this.addLoader(HDRLoader);
4720
+ this.addLoader(TextureLoader);
4721
+ this.addLoader(JSONLoader);
4722
+ this.addLoader(BINLoader);
4910
4723
  }
4911
4724
  _frame(time) {
4912
4725
  this._time = time;
@@ -4929,7 +4742,6 @@ class Viewer extends EventEmitter {
4929
4742
  this.render(dt);
4930
4743
  }
4931
4744
  update(dt) {
4932
- this._tweens.forEach((tween)=>tween.update(dt));
4933
4745
  this._taskManager.update();
4934
4746
  this._componentManager.update(dt);
4935
4747
  }
@@ -5035,7 +4847,7 @@ class Viewer extends EventEmitter {
5035
4847
  return this._resourceManager.getLoader(ext);
5036
4848
  }
5037
4849
  addLoader(Loader) {
5038
- this._resourceManager.addLoader(Loader);
4850
+ return this._resourceManager.addLoader(Loader);
5039
4851
  }
5040
4852
  traverseMaterials(callback) {
5041
4853
  this._scene.traverse((item)=>{
@@ -5051,15 +4863,10 @@ class Viewer extends EventEmitter {
5051
4863
  mount(constructor, autoAdd = false) {
5052
4864
  return this._componentManager.getComponent(this._mount, constructor, autoAdd);
5053
4865
  }
5054
- tween() {
5055
- const tween = new TweenManager();
5056
- this._tweens.push(tween);
5057
- return tween;
5058
- }
5059
4866
  task(task) {
5060
4867
  this._taskManager.add(task);
5061
4868
  }
5062
- add(object, { node, args, debug, scale, position, rotation, layer, shadowArgs, makeDefault, component, parent = this._scene, ...props } = {}) {
4869
+ add(object, { node, args, debug, scale, position, rotation, shadowArgs, makeDefault, component, layer, parent = this._scene, ...props } = {}) {
5063
4870
  let ins = getClassInstance(object, args);
5064
4871
  if (ins.isObject3D) {
5065
4872
  node = ins;
@@ -5218,7 +5025,6 @@ class Viewer extends EventEmitter {
5218
5025
  this._targetFrameRate = -1;
5219
5026
  this._fixedFrameTime = false;
5220
5027
  this._autoResize = true;
5221
- this._tweens = [];
5222
5028
  const el = canvas || document.getElementById("canvas");
5223
5029
  const webgl = parepareWebGL(el, webglOpts);
5224
5030
  if (!webgl) {
@@ -5498,13 +5304,6 @@ class MergeMipBlurPass {
5498
5304
  }
5499
5305
  }
5500
5306
 
5501
- class Mount extends Component {
5502
- constructor(...args){
5503
- super(...args);
5504
- this.isMount = true;
5505
- }
5506
- }
5507
-
5508
5307
  class Environment extends Mount {
5509
5308
  get envMap() {
5510
5309
  return this._reflectPass.envMap;
@@ -5827,6 +5626,7 @@ class DropFile extends Mount {
5827
5626
  }
5828
5627
  }
5829
5628
  _loadFile(file, dir = "") {
5629
+ const viewer = this.viewer;
5830
5630
  const filename = file.name;
5831
5631
  const ext = ResourceManager.extension(filename);
5832
5632
  if (this._extensions.some((v)=>v === ext)) {
@@ -5849,7 +5649,11 @@ class DropFile extends Mount {
5849
5649
  "glb"
5850
5650
  ].some((v)=>v === ext)) {
5851
5651
  reader.addEventListener("load", (event)=>{
5852
- this.viewer.loadAsset({
5652
+ if (this._raw) loadCallback({
5653
+ userData: {},
5654
+ raw: event.target.result
5655
+ });
5656
+ else viewer.loadAsset({
5853
5657
  ext,
5854
5658
  buffer: event.target.result,
5855
5659
  resourcePath: dir
@@ -5858,7 +5662,11 @@ class DropFile extends Mount {
5858
5662
  reader.readAsArrayBuffer(file);
5859
5663
  } else {
5860
5664
  reader.addEventListener("load", (event)=>{
5861
- this.viewer.loadAsset({
5665
+ if (this._raw) loadCallback({
5666
+ userData: {},
5667
+ raw: event.target.result
5668
+ });
5669
+ else viewer.loadAsset({
5862
5670
  ext,
5863
5671
  url: event.target.result
5864
5672
  }).then(loadCallback).catch(errCallback);
@@ -5872,8 +5680,9 @@ class DropFile extends Mount {
5872
5680
  "gltf",
5873
5681
  "fbx",
5874
5682
  "hdr"
5875
- ] } = {}){
5683
+ ], raw = false } = {}){
5876
5684
  super();
5685
+ this._raw = false;
5877
5686
  this._onDrogOver = (e)=>{
5878
5687
  e.preventDefault();
5879
5688
  e.dataTransfer.dropEffect = "copy";
@@ -5892,6 +5701,7 @@ class DropFile extends Mount {
5892
5701
  this._extensions = Array.isArray(extension) ? extension : [
5893
5702
  extension
5894
5703
  ];
5704
+ this._raw = raw;
5895
5705
  }
5896
5706
  }
5897
5707
  function createFilesMap(files) {
@@ -5941,5 +5751,5 @@ function getFilesFromItemList(items, onDone) {
5941
5751
  }
5942
5752
  }
5943
5753
 
5944
- export { Animation, AnimationCurve, Box, BoxProjection, CinestationBlendDefinition, CinestationBrain, Component, ContactShadows, DependentMode, DeviceInput, DropFile, Easing, Environment, EventEmitter, FInterpConstantTo, FInterpTo, FreelookVirtualCamera, Logger, Mount, ObjectInstance, Orientation, PerformanceMonitor, Perlin, Plane, PropertyManager, QInterpConstantTo, QInterpTo, Quat_AngularDistance, Quat_Equals, Quat_exponentialDamp, Quat_quarticDamp, Quat_smoothDamp, Reflector, ReflectorMaterial, ResourceManager, ShadowMaterial, Sphere, SystemInfo, Tween, TweenChain, TweenGroup, TweenManager, 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, VirtualCamera, aEXRLoader, aFBXLoader, aGLTFLoader, aHDRLoader, aJSONLoader, aLoader, aTextureLoader, applyProps, dependencies, exponentialDamp, find, frag_BoxfilterBlur, frag_cubeMapToPanorama, frag_panoramaToCubeMap, getChildByName, getChildren, getClassInstance, getShaderMaterial, mixin, property, quarticDamp, queryValues, smoothDamp, vert_fullscreen };
5754
+ export { AccumulativeShadows, Animation, AnimationCurve, BINLoader, Box, BoxProjection, Center, CinestationBlendDefinition, CinestationBrain, Component, ContactShadows, DependentMode, DeviceInput, DropFile, EXRLoader, Easing, Environment, EventEmitter, FBXLoader, FInterpConstantTo, FInterpTo, FreelookVirtualCamera, GLTFLoader, HDRLoader, JSONLoader, Loader, Logger, Mount, ObjectInstance, Orientation, PerformanceMonitor, Perlin, Plane, PropertyManager, QInterpConstantTo, QInterpTo, Quat_AngularDistance, Quat_Equals, Quat_exponentialDamp, Quat_quarticDamp, Quat_smoothDamp, RandomizedLight, Reflector, ReflectorMaterial, ResourceManager, ShadowMaterial, Sphere, SystemInfo, TextureLoader, UI, 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, VirtualCamera, applyProps, dependencies, exponentialDamp, find, frag_BoxfilterBlur, frag_cubeMapToPanorama, frag_panoramaToCubeMap, getChildByName, getChildren, getClassInstance, getShaderMaterial, mixin, property, quarticDamp, queryValues, smoothDamp, vert_fullscreen };
5945
5755
  //# sourceMappingURL=module.js.map