@xviewer.js/core 1.0.0-alpha.33 → 1.0.0-alpha.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.js CHANGED
@@ -141,87 +141,96 @@ function getClassInstance(constructor, args = []) {
141
141
 
142
142
  /**
143
143
  * The Ease class provides a collection of easing functions for use with tween.js.
144
- */ var Easing = {
145
- Linear: {
146
- None: function(amount) {
144
+ */ const Easing = Object.freeze({
145
+ Linear: Object.freeze({
146
+ None (amount) {
147
+ return amount;
148
+ },
149
+ In (amount) {
150
+ return amount;
151
+ },
152
+ Out (amount) {
153
+ return amount;
154
+ },
155
+ InOut (amount) {
147
156
  return amount;
148
157
  }
149
- },
150
- Quadratic: {
151
- In: function(amount) {
158
+ }),
159
+ Quadratic: Object.freeze({
160
+ In (amount) {
152
161
  return amount * amount;
153
162
  },
154
- Out: function(amount) {
163
+ Out (amount) {
155
164
  return amount * (2 - amount);
156
165
  },
157
- InOut: function(amount) {
166
+ InOut (amount) {
158
167
  if ((amount *= 2) < 1) {
159
168
  return 0.5 * amount * amount;
160
169
  }
161
170
  return -0.5 * (--amount * (amount - 2) - 1);
162
171
  }
163
- },
164
- Cubic: {
165
- In: function(amount) {
172
+ }),
173
+ Cubic: Object.freeze({
174
+ In (amount) {
166
175
  return amount * amount * amount;
167
176
  },
168
- Out: function(amount) {
177
+ Out (amount) {
169
178
  return --amount * amount * amount + 1;
170
179
  },
171
- InOut: function(amount) {
180
+ InOut (amount) {
172
181
  if ((amount *= 2) < 1) {
173
182
  return 0.5 * amount * amount * amount;
174
183
  }
175
184
  return 0.5 * ((amount -= 2) * amount * amount + 2);
176
185
  }
177
- },
178
- Quartic: {
179
- In: function(amount) {
186
+ }),
187
+ Quartic: Object.freeze({
188
+ In (amount) {
180
189
  return amount * amount * amount * amount;
181
190
  },
182
- Out: function(amount) {
191
+ Out (amount) {
183
192
  return 1 - --amount * amount * amount * amount;
184
193
  },
185
- InOut: function(amount) {
194
+ InOut (amount) {
186
195
  if ((amount *= 2) < 1) {
187
196
  return 0.5 * amount * amount * amount * amount;
188
197
  }
189
198
  return -0.5 * ((amount -= 2) * amount * amount * amount - 2);
190
199
  }
191
- },
192
- Quintic: {
193
- In: function(amount) {
200
+ }),
201
+ Quintic: Object.freeze({
202
+ In (amount) {
194
203
  return amount * amount * amount * amount * amount;
195
204
  },
196
- Out: function(amount) {
205
+ Out (amount) {
197
206
  return --amount * amount * amount * amount * amount + 1;
198
207
  },
199
- InOut: function(amount) {
208
+ InOut (amount) {
200
209
  if ((amount *= 2) < 1) {
201
210
  return 0.5 * amount * amount * amount * amount * amount;
202
211
  }
203
212
  return 0.5 * ((amount -= 2) * amount * amount * amount * amount + 2);
204
213
  }
205
- },
206
- Sinusoidal: {
207
- In: function(amount) {
208
- return 1 - Math.cos(amount * Math.PI / 2);
214
+ }),
215
+ Sinusoidal: Object.freeze({
216
+ In (amount) {
217
+ return 1 - Math.sin((1.0 - amount) * Math.PI / 2);
209
218
  },
210
- Out: function(amount) {
219
+ Out (amount) {
211
220
  return Math.sin(amount * Math.PI / 2);
212
221
  },
213
- InOut: function(amount) {
214
- return 0.5 * (1 - Math.cos(Math.PI * amount));
222
+ InOut (amount) {
223
+ return 0.5 * (1 - Math.sin(Math.PI * (0.5 - amount)));
215
224
  }
216
- },
217
- Exponential: {
218
- In: function(amount) {
225
+ }),
226
+ Exponential: Object.freeze({
227
+ In (amount) {
219
228
  return amount === 0 ? 0 : Math.pow(1024, amount - 1);
220
229
  },
221
- Out: function(amount) {
230
+ Out (amount) {
222
231
  return amount === 1 ? 1 : 1 - Math.pow(2, -10 * amount);
223
232
  },
224
- InOut: function(amount) {
233
+ InOut (amount) {
225
234
  if (amount === 0) {
226
235
  return 0;
227
236
  }
@@ -233,23 +242,23 @@ function getClassInstance(constructor, args = []) {
233
242
  }
234
243
  return 0.5 * (-Math.pow(2, -10 * (amount - 1)) + 2);
235
244
  }
236
- },
237
- Circular: {
238
- In: function(amount) {
245
+ }),
246
+ Circular: Object.freeze({
247
+ In (amount) {
239
248
  return 1 - Math.sqrt(1 - amount * amount);
240
249
  },
241
- Out: function(amount) {
250
+ Out (amount) {
242
251
  return Math.sqrt(1 - --amount * amount);
243
252
  },
244
- InOut: function(amount) {
253
+ InOut (amount) {
245
254
  if ((amount *= 2) < 1) {
246
255
  return -0.5 * (Math.sqrt(1 - amount * amount) - 1);
247
256
  }
248
257
  return 0.5 * (Math.sqrt(1 - (amount -= 2) * amount) + 1);
249
258
  }
250
- },
251
- Elastic: {
252
- In: function(amount) {
259
+ }),
260
+ Elastic: Object.freeze({
261
+ In (amount) {
253
262
  if (amount === 0) {
254
263
  return 0;
255
264
  }
@@ -258,7 +267,7 @@ function getClassInstance(constructor, args = []) {
258
267
  }
259
268
  return -Math.pow(2, 10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI);
260
269
  },
261
- Out: function(amount) {
270
+ Out (amount) {
262
271
  if (amount === 0) {
263
272
  return 0;
264
273
  }
@@ -267,7 +276,7 @@ function getClassInstance(constructor, args = []) {
267
276
  }
268
277
  return Math.pow(2, -10 * amount) * Math.sin((amount - 0.1) * 5 * Math.PI) + 1;
269
278
  },
270
- InOut: function(amount) {
279
+ InOut (amount) {
271
280
  if (amount === 0) {
272
281
  return 0;
273
282
  }
@@ -280,29 +289,29 @@ function getClassInstance(constructor, args = []) {
280
289
  }
281
290
  return 0.5 * Math.pow(2, -10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI) + 1;
282
291
  }
283
- },
284
- Back: {
285
- In: function(amount) {
286
- var s = 1.70158;
287
- return amount * amount * ((s + 1) * amount - s);
292
+ }),
293
+ Back: Object.freeze({
294
+ In (amount) {
295
+ const s = 1.70158;
296
+ return amount === 1 ? 1 : amount * amount * ((s + 1) * amount - s);
288
297
  },
289
- Out: function(amount) {
290
- var s = 1.70158;
291
- return --amount * amount * ((s + 1) * amount + s) + 1;
298
+ Out (amount) {
299
+ const s = 1.70158;
300
+ return amount === 0 ? 0 : --amount * amount * ((s + 1) * amount + s) + 1;
292
301
  },
293
- InOut: function(amount) {
294
- var s = 1.70158 * 1.525;
302
+ InOut (amount) {
303
+ const s = 1.70158 * 1.525;
295
304
  if ((amount *= 2) < 1) {
296
305
  return 0.5 * (amount * amount * ((s + 1) * amount - s));
297
306
  }
298
307
  return 0.5 * ((amount -= 2) * amount * ((s + 1) * amount + s) + 2);
299
308
  }
300
- },
301
- Bounce: {
302
- In: function(amount) {
309
+ }),
310
+ Bounce: Object.freeze({
311
+ In (amount) {
303
312
  return 1 - Easing.Bounce.Out(1 - amount);
304
313
  },
305
- Out: function(amount) {
314
+ Out (amount) {
306
315
  if (amount < 1 / 2.75) {
307
316
  return 7.5625 * amount * amount;
308
317
  } else if (amount < 2 / 2.75) {
@@ -313,107 +322,43 @@ function getClassInstance(constructor, args = []) {
313
322
  return 7.5625 * (amount -= 2.625 / 2.75) * amount + 0.984375;
314
323
  }
315
324
  },
316
- InOut: function(amount) {
325
+ InOut (amount) {
317
326
  if (amount < 0.5) {
318
327
  return Easing.Bounce.In(amount * 2) * 0.5;
319
328
  }
320
329
  return Easing.Bounce.Out(amount * 2 - 1) * 0.5 + 0.5;
321
330
  }
322
- }
323
- };
324
- var now;
325
- // Include a performance.now polyfill.
326
- // In node.js, use process.hrtime.
327
- // eslint-disable-next-line
328
- // @ts-ignore
329
- if (typeof self === 'undefined' && typeof process !== 'undefined' && process.hrtime) {
330
- now = function() {
331
- // eslint-disable-next-line
332
- // @ts-ignore
333
- var time = process.hrtime();
334
- // Convert [seconds, nanoseconds] to milliseconds.
335
- return time[0] * 1000 + time[1] / 1000000;
336
- };
337
- } else if (typeof self !== 'undefined' && self.performance !== undefined && self.performance.now !== undefined) {
338
- // This must be bound, because directly assigning this function
339
- // leads to an invocation exception in Chrome.
340
- now = self.performance.now.bind(self.performance);
341
- } else if (Date.now !== undefined) {
342
- now = Date.now;
343
- } else {
344
- now = function() {
345
- return new Date().getTime();
346
- };
347
- }
348
- function now$1() {
349
- return now() * 0.001;
350
- }
351
- /**
352
- * Controlling groups of tweens
353
- *
354
- * Using the TWEEN singleton to manage your tweens can cause issues in large apps with many components.
355
- * In these cases, you may want to create your own smaller groups of tween
356
- */ var Group = /** @class */ function() {
357
- function Group() {
358
- this._tweens = {};
359
- this._tweensAddedDuringUpdate = {};
360
- }
361
- Group.prototype.getAll = function() {
362
- var _this = this;
363
- return Object.keys(this._tweens).map(function(tweenId) {
364
- return _this._tweens[tweenId];
365
- });
366
- };
367
- Group.prototype.removeAll = function() {
368
- this._tweens = {};
369
- };
370
- Group.prototype.add = function(tween) {
371
- this._tweens[tween.getId()] = tween;
372
- this._tweensAddedDuringUpdate[tween.getId()] = tween;
373
- };
374
- Group.prototype.remove = function(tween) {
375
- delete this._tweens[tween.getId()];
376
- delete this._tweensAddedDuringUpdate[tween.getId()];
377
- };
378
- Group.prototype.update = function(time, preserve) {
379
- if (time === void 0) {
380
- time = now$1();
381
- }
382
- if (preserve === void 0) {
383
- preserve = false;
384
- }
385
- var tweenIds = Object.keys(this._tweens);
386
- if (tweenIds.length === 0) {
387
- return false;
388
- }
389
- // Tweens are updated in "batches". If you add a new tween during an
390
- // update, then the new tween will be updated in the next batch.
391
- // If you remove a tween during an update, it may or may not be updated.
392
- // However, if the removed tween was added during the current batch,
393
- // then it will not be updated.
394
- while(tweenIds.length > 0){
395
- this._tweensAddedDuringUpdate = {};
396
- for(var i = 0; i < tweenIds.length; i++){
397
- var tween = this._tweens[tweenIds[i]];
398
- var autoStart = !preserve;
399
- if (tween && tween.update(time, autoStart) === false && !preserve) {
400
- delete this._tweens[tweenIds[i]];
331
+ }),
332
+ generatePow (power = 4) {
333
+ power = power < Number.EPSILON ? Number.EPSILON : power;
334
+ power = power > 10000 ? 10000 : power;
335
+ return {
336
+ In (amount) {
337
+ return amount ** power;
338
+ },
339
+ Out (amount) {
340
+ return 1 - (1 - amount) ** power;
341
+ },
342
+ InOut (amount) {
343
+ if (amount < 0.5) {
344
+ return (amount * 2) ** power / 2;
401
345
  }
346
+ return (1 - (2 - amount * 2) ** power) / 2 + 0.5;
402
347
  }
403
- tweenIds = Object.keys(this._tweensAddedDuringUpdate);
404
- }
405
- return true;
406
- };
407
- return Group;
408
- }();
348
+ };
349
+ }
350
+ });
351
+
409
352
  /**
410
353
  *
411
- */ var Interpolation = {
354
+ */ /**
355
+ *
356
+ */ const Interpolation = {
412
357
  Linear: function(v, k) {
413
- var m = v.length - 1;
414
- var f = m * k;
415
- var i = Math.floor(f);
416
- var fn = Interpolation.Utils.Linear;
358
+ const m = v.length - 1;
359
+ const f = m * k;
360
+ const i = Math.floor(f);
361
+ const fn = Interpolation.Utils.Linear;
417
362
  if (k < 0) {
418
363
  return fn(v[0], v[1], f);
419
364
  }
@@ -423,20 +368,20 @@ function now$1() {
423
368
  return fn(v[i], v[i + 1 > m ? m : i + 1], f - i);
424
369
  },
425
370
  Bezier: function(v, k) {
426
- var b = 0;
427
- var n = v.length - 1;
428
- var pw = Math.pow;
429
- var bn = Interpolation.Utils.Bernstein;
430
- for(var i = 0; i <= n; i++){
371
+ let b = 0;
372
+ const n = v.length - 1;
373
+ const pw = Math.pow;
374
+ const bn = Interpolation.Utils.Bernstein;
375
+ for(let i = 0; i <= n; i++){
431
376
  b += pw(1 - k, n - i) * pw(k, i) * v[i] * bn(n, i);
432
377
  }
433
378
  return b;
434
379
  },
435
380
  CatmullRom: function(v, k) {
436
- var m = v.length - 1;
437
- var f = m * k;
438
- var i = Math.floor(f);
439
- var fn = Interpolation.Utils.CatmullRom;
381
+ const m = v.length - 1;
382
+ let f = m * k;
383
+ let i = Math.floor(f);
384
+ const fn = Interpolation.Utils.CatmullRom;
440
385
  if (v[0] === v[m]) {
441
386
  if (k < 0) {
442
387
  i = Math.floor(f = m * (1 + k));
@@ -457,19 +402,19 @@ function now$1() {
457
402
  return (p1 - p0) * t + p0;
458
403
  },
459
404
  Bernstein: function(n, i) {
460
- var fc = Interpolation.Utils.Factorial;
405
+ const fc = Interpolation.Utils.Factorial;
461
406
  return fc(n) / fc(i) / fc(n - i);
462
407
  },
463
408
  Factorial: function() {
464
- var a = [
409
+ const a = [
465
410
  1
466
411
  ];
467
412
  return function(n) {
468
- var s = 1;
413
+ let s = 1;
469
414
  if (a[n]) {
470
415
  return a[n];
471
416
  }
472
- for(var i = n; i > 1; i--){
417
+ for(let i = n; i > 1; i--){
473
418
  s *= i;
474
419
  }
475
420
  a[n] = s;
@@ -477,77 +422,112 @@ function now$1() {
477
422
  };
478
423
  }(),
479
424
  CatmullRom: function(p0, p1, p2, p3, t) {
480
- var v0 = (p2 - p0) * 0.5;
481
- var v1 = (p3 - p1) * 0.5;
482
- var t2 = t * t;
483
- var t3 = t * t2;
425
+ const v0 = (p2 - p0) * 0.5;
426
+ const v1 = (p3 - p1) * 0.5;
427
+ const t2 = t * t;
428
+ const t3 = t * t2;
484
429
  return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
485
430
  }
486
431
  }
487
432
  };
433
+
434
+ const now = ()=>performance.now() * 0.001;
435
+
488
436
  /**
489
- * Utils
490
- */ var Sequence = /** @class */ function() {
491
- function Sequence() {}
492
- Sequence.nextId = function() {
493
- return Sequence._nextId++;
494
- };
495
- Sequence._nextId = 0;
496
- return Sequence;
497
- }();
498
- var mainGroup = new Group();
499
- /**
500
- * Tween.js - Licensed under the MIT license
501
- * https://github.com/tweenjs/tween.js
502
- * ----------------------------------------------
437
+ * Controlling groups of tweens
503
438
  *
504
- * See https://github.com/tweenjs/tween.js/graphs/contributors for the full list of contributors.
505
- * Thank you all, you're awesome!
506
- */ var Tween = /** @class */ function() {
507
- function Tween(_object, _group) {
508
- if (_group === void 0) {
509
- _group = mainGroup;
439
+ * Using the TWEEN singleton to manage your tweens can cause issues in large apps with many components.
440
+ * In these cases, you may want to create your own smaller groups of tween
441
+ */ class Group {
442
+ getAll() {
443
+ return Object.keys(this._tweens).map((tweenId)=>{
444
+ return this._tweens[tweenId];
445
+ });
446
+ }
447
+ removeAll() {
448
+ this._tweens = {};
449
+ }
450
+ add(tween) {
451
+ this._tweens[tween.getId()] = tween;
452
+ this._tweensAddedDuringUpdate[tween.getId()] = tween;
453
+ }
454
+ remove(tween) {
455
+ delete this._tweens[tween.getId()];
456
+ delete this._tweensAddedDuringUpdate[tween.getId()];
457
+ }
458
+ update(time = now(), preserve = false) {
459
+ let tweenIds = Object.keys(this._tweens);
460
+ if (tweenIds.length === 0) {
461
+ return false;
510
462
  }
511
- this._object = _object;
512
- this._group = _group;
513
- this._isPaused = false;
514
- this._pauseStart = 0;
515
- this._valuesStart = {};
516
- this._valuesEnd = {};
517
- this._valuesStartRepeat = {};
518
- this._duration = 0;
519
- this._initialRepeat = 0;
520
- this._repeat = 0;
521
- this._yoyo = false;
522
- this._isPlaying = false;
523
- this._reversed = false;
524
- this._delayTime = 0;
525
- this._startTime = 0;
526
- this._easingFunction = Easing.Linear.None;
527
- this._interpolationFunction = Interpolation.Linear;
528
- this._chainedTweens = [];
529
- this._onStartCallbackFired = false;
530
- this._id = Sequence.nextId();
531
- this._isChainStopped = false;
532
- this._goToEnd = false;
533
- this._headTween = null;
534
- this._tailTween = null;
535
- this._headStart = false;
463
+ // Tweens are updated in "batches". If you add a new tween during an
464
+ // update, then the new tween will be updated in the next batch.
465
+ // If you remove a tween during an update, it may or may not be updated.
466
+ // However, if the removed tween was added during the current batch,
467
+ // then it will not be updated.
468
+ while(tweenIds.length > 0){
469
+ this._tweensAddedDuringUpdate = {};
470
+ for(let i = 0; i < tweenIds.length; i++){
471
+ const tween = this._tweens[tweenIds[i]];
472
+ const autoStart = !preserve;
473
+ if (tween && tween.update(time, autoStart) === false && !preserve) {
474
+ delete this._tweens[tweenIds[i]];
475
+ }
476
+ }
477
+ tweenIds = Object.keys(this._tweensAddedDuringUpdate);
478
+ }
479
+ return true;
536
480
  }
537
- Tween.prototype.getId = function() {
481
+ constructor(){
482
+ this._tweens = {};
483
+ this._tweensAddedDuringUpdate = {};
484
+ }
485
+ }
486
+
487
+ const mainGroup = new Group();
488
+
489
+ /**
490
+ * Utils
491
+ */ class Sequence {
492
+ static nextId() {
493
+ return Sequence._nextId++;
494
+ }
495
+ }
496
+ Sequence._nextId = 0;
497
+
498
+ class Tween {
499
+ getId() {
538
500
  return this._id;
539
- };
540
- Tween.prototype.isPlaying = function() {
501
+ }
502
+ isPlaying() {
541
503
  return this._isPlaying;
542
- };
543
- Tween.prototype.isPaused = function() {
504
+ }
505
+ isPaused() {
544
506
  return this._isPaused;
545
- };
546
- Tween.prototype.duration = function(d) {
547
- this._duration = d;
507
+ }
508
+ getDuration() {
509
+ return this._duration;
510
+ }
511
+ from(properties) {
512
+ this._valuesStart = Object.create(properties);
548
513
  return this;
549
- };
550
- Tween.prototype.start = function(time) {
514
+ }
515
+ to(target, duration = 1) {
516
+ if (this._isPlaying) throw new Error('Can not call Tween.to() while Tween is already started or paused. Stop the Tween first.');
517
+ this._valuesEnd = target;
518
+ this._propertiesAreSetUp = false;
519
+ this._duration = duration < 0 ? 0 : duration;
520
+ return this;
521
+ }
522
+ duration(duration = 1) {
523
+ this._duration = duration < 0 ? 0 : duration;
524
+ return this;
525
+ }
526
+ dynamic(dynamic = false) {
527
+ this._isDynamic = dynamic;
528
+ return this;
529
+ }
530
+ start(time = now(), overrideStartingValues = false) {
551
531
  if (this._isPlaying) {
552
532
  return this;
553
533
  }
@@ -558,7 +538,7 @@ var mainGroup = new Group();
558
538
  // If we were reversed (f.e. using the yoyo feature) then we need to
559
539
  // flip the tween direction back to forward.
560
540
  this._reversed = false;
561
- for(var property in this._valuesStartRepeat){
541
+ for(const property in this._valuesStartRepeat){
562
542
  this._swapEndStartRepeatValues(property);
563
543
  this._valuesStart[property] = this._valuesStartRepeat[property];
564
544
  }
@@ -566,18 +546,31 @@ var mainGroup = new Group();
566
546
  this._isPlaying = true;
567
547
  this._isPaused = false;
568
548
  this._onStartCallbackFired = false;
549
+ this._onEveryStartCallbackFired = false;
569
550
  this._isChainStopped = false;
570
- this._startTime = time !== undefined ? typeof time === 'string' ? now$1() + parseFloat(time) : time : now$1();
551
+ this._startTime = time;
571
552
  this._startTime += this._delayTime;
572
- this._setupProperties(this._object, this._valuesStart, this._valuesEnd, this._valuesStartRepeat);
553
+ if (!this._propertiesAreSetUp || overrideStartingValues) {
554
+ this._propertiesAreSetUp = true;
555
+ // If dynamic is not enabled, clone the end values instead of using the passed-in end values.
556
+ if (!this._isDynamic) {
557
+ const tmp = {};
558
+ for(const prop in this._valuesEnd)tmp[prop] = this._valuesEnd[prop];
559
+ this._valuesEnd = tmp;
560
+ }
561
+ this._setupProperties(this._object, this._valuesStart, this._valuesEnd, this._valuesStartRepeat, overrideStartingValues);
562
+ }
573
563
  return this;
574
- };
575
- Tween.prototype._setupProperties = function(_object, _valuesStart, _valuesEnd, _valuesStartRepeat) {
576
- for(var property in _valuesEnd){
577
- var startValue = _object[property];
578
- var startValueIsArray = Array.isArray(startValue);
579
- var propType = startValueIsArray ? 'array' : typeof startValue;
580
- var isInterpolationList = !startValueIsArray && Array.isArray(_valuesEnd[property]);
564
+ }
565
+ startFromCurrentValues(time) {
566
+ return this.start(time, true);
567
+ }
568
+ _setupProperties(_object, _valuesStart, _valuesEnd, _valuesStartRepeat, overrideStartingValues) {
569
+ for(const property in _valuesEnd){
570
+ const startValue = _object[property];
571
+ const startValueIsArray = Array.isArray(startValue);
572
+ const propType = startValueIsArray ? 'array' : typeof startValue;
573
+ let isInterpolationList = !startValueIsArray && Array.isArray(_valuesEnd[property]);
581
574
  // If `to()` specifies a property that doesn't exist in the source object,
582
575
  // we should not set that property in the object
583
576
  if (propType === 'undefined' || propType === 'function') {
@@ -585,39 +578,57 @@ var mainGroup = new Group();
585
578
  }
586
579
  // Check if an Array was provided as property value
587
580
  if (isInterpolationList) {
588
- var endValues = _valuesEnd[property];
581
+ const endValues = _valuesEnd[property];
589
582
  if (endValues.length === 0) {
590
583
  continue;
591
584
  }
592
- // handle an array of relative values
593
- endValues = endValues.map(this._handleRelativeValue.bind(this, startValue));
594
- // Create a local copy of the Array with the start value at the front
595
- _valuesEnd[property] = [
585
+ // Handle an array of relative values.
586
+ // Creates a local copy of the Array with the start value at the front
587
+ const temp = [
596
588
  startValue
597
- ].concat(endValues);
589
+ ];
590
+ for(let i = 0, l = endValues.length; i < l; i += 1){
591
+ const value = this._handleRelativeValue(startValue, endValues[i]);
592
+ if (isNaN(value)) {
593
+ isInterpolationList = false;
594
+ console.warn('Found invalid interpolation list. Skipping.');
595
+ break;
596
+ }
597
+ temp.push(value);
598
+ }
599
+ if (isInterpolationList) {
600
+ // if (_valuesStart[property] === undefined) { // handle end values only the first time. NOT NEEDED? setupProperties is now guarded by _propertiesAreSetUp.
601
+ _valuesEnd[property] = temp;
602
+ // }
603
+ }
598
604
  }
599
605
  // handle the deepness of the values
600
606
  if ((propType === 'object' || startValueIsArray) && startValue && !isInterpolationList) {
601
607
  _valuesStart[property] = startValueIsArray ? [] : {};
602
- // eslint-disable-next-line
603
- for(var prop in startValue){
604
- // eslint-disable-next-line
605
- // @ts-ignore FIXME?
606
- _valuesStart[property][prop] = startValue[prop];
608
+ const nestedObject = startValue;
609
+ for(const prop in nestedObject){
610
+ _valuesStart[property][prop] = nestedObject[prop];
607
611
  }
608
- _valuesStartRepeat[property] = startValueIsArray ? [] : {}; // TODO? repeat nested values? And yoyo? And array values?
609
- // eslint-disable-next-line
610
- // @ts-ignore FIXME?
611
- this._setupProperties(startValue, _valuesStart[property], _valuesEnd[property], _valuesStartRepeat[property]);
612
+ // TODO? repeat nested values? And yoyo? And array values?
613
+ _valuesStartRepeat[property] = startValueIsArray ? [] : {};
614
+ let endValues = _valuesEnd[property];
615
+ // If dynamic is not enabled, clone the end values instead of using the passed-in end values.
616
+ if (!this._isDynamic) {
617
+ const tmp = {};
618
+ for(const prop in endValues)tmp[prop] = endValues[prop];
619
+ _valuesEnd[property] = endValues = tmp;
620
+ }
621
+ this._setupProperties(nestedObject, _valuesStart[property], endValues, _valuesStartRepeat[property], overrideStartingValues);
612
622
  } else {
613
- // Save the starting value, but only once.
614
- if (typeof _valuesStart[property] === 'undefined') {
623
+ // Save the starting value, but only once unless override is requested.
624
+ if (typeof _valuesStart[property] === 'undefined' || overrideStartingValues) {
615
625
  _valuesStart[property] = startValue;
616
626
  }
617
627
  if (!startValueIsArray) {
618
628
  // eslint-disable-next-line
619
629
  // @ts-ignore FIXME?
620
- _valuesStart[property] *= 1.0; // Ensures we're using numbers, not strings
630
+ _valuesStart[property] *= 1.0 // Ensures we're using numbers, not strings
631
+ ;
621
632
  }
622
633
  if (isInterpolationList) {
623
634
  // eslint-disable-next-line
@@ -628,8 +639,8 @@ var mainGroup = new Group();
628
639
  }
629
640
  }
630
641
  }
631
- };
632
- Tween.prototype.stop = function() {
642
+ }
643
+ stop() {
633
644
  if (!this._isChainStopped) {
634
645
  this._isChainStopped = true;
635
646
  this.stopChainedTweens();
@@ -645,16 +656,13 @@ var mainGroup = new Group();
645
656
  this._onStopCallback(this._object);
646
657
  }
647
658
  return this;
648
- };
649
- Tween.prototype.end = function() {
659
+ }
660
+ end() {
650
661
  this._goToEnd = true;
651
662
  this.update(Infinity);
652
663
  return this;
653
- };
654
- Tween.prototype.pause = function(time) {
655
- if (time === void 0) {
656
- time = now$1();
657
- }
664
+ }
665
+ pause(time = now()) {
658
666
  if (this._isPaused || !this._isPlaying) {
659
667
  return this;
660
668
  }
@@ -663,11 +671,8 @@ var mainGroup = new Group();
663
671
  // eslint-disable-next-line
664
672
  this._group && this._group.remove(this);
665
673
  return this;
666
- };
667
- Tween.prototype.resume = function(time) {
668
- if (time === void 0) {
669
- time = now$1();
670
- }
674
+ }
675
+ resume(time = now()) {
671
676
  if (!this._isPaused || !this._isPlaying) {
672
677
  return this;
673
678
  }
@@ -677,124 +682,98 @@ var mainGroup = new Group();
677
682
  // eslint-disable-next-line
678
683
  this._group && this._group.add(this);
679
684
  return this;
680
- };
681
- Tween.prototype.stopChainedTweens = function() {
682
- for(var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++){
685
+ }
686
+ stopChainedTweens() {
687
+ for(let i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++){
683
688
  this._chainedTweens[i].stop();
684
689
  }
685
- this._chainedTweens = [];
686
690
  return this;
687
- };
688
- Tween.prototype.group = function(group) {
691
+ }
692
+ group(group = mainGroup) {
689
693
  this._group = group;
690
694
  return this;
691
- };
692
- Tween.prototype.call = function(callback) {
695
+ }
696
+ call(callback) {
693
697
  this._onFinishCallback = callback;
694
698
  return this;
695
- };
696
- Tween.prototype.from = function(properties) {
697
- this._valuesStart = Object.create(properties);
698
- return this;
699
- };
700
- Tween.prototype.to = function(properties, duration) {
701
- // TODO? restore this, then update the 07_dynamic_to example to set fox
702
- // tween's to on each update. That way the behavior is opt-in (there's
703
- // currently no opt-out).
704
- // for (const prop in properties) this._valuesEnd[prop] = properties[prop]
705
- this._valuesEnd = Object.create(properties);
706
- if (duration !== undefined) {
707
- this._duration = duration;
708
- }
709
- this._chainedTween = this;
710
- return this;
711
- };
712
- Tween.prototype.delay = function(amount) {
699
+ }
700
+ delay(amount = 0) {
713
701
  this._delayTime = amount;
714
702
  return this;
715
- };
716
- Tween.prototype.union = function(headTween, tailTween) {
703
+ }
704
+ union(headTween, tailTween) {
717
705
  this._headTween = headTween;
718
706
  this._tailTween = tailTween.chain(this);
719
707
  this._headStart = true;
720
708
  return this;
721
- };
722
- Tween.prototype.repeat = function(times) {
709
+ }
710
+ repeat(times = 0) {
723
711
  this._initialRepeat = times;
724
712
  this._repeat = times;
725
713
  return this;
726
- };
727
- Tween.prototype.repeatDelay = function(amount) {
714
+ }
715
+ repeatDelay(amount) {
728
716
  this._repeatDelayTime = amount;
729
717
  return this;
730
- };
731
- Tween.prototype.yoyo = function(yoyo) {
718
+ }
719
+ yoyo(yoyo = false) {
732
720
  this._yoyo = yoyo;
733
721
  return this;
734
- };
735
- Tween.prototype.easing = function(easingFunction) {
722
+ }
723
+ easing(easingFunction = Easing.Linear.None) {
736
724
  this._easingFunction = easingFunction;
737
725
  return this;
738
- };
739
- Tween.prototype.interpolation = function(interpolationFunction) {
726
+ }
727
+ interpolation(interpolationFunction = Interpolation.Linear) {
740
728
  this._interpolationFunction = interpolationFunction;
741
729
  return this;
742
- };
743
- Tween.prototype.chain = function() {
744
- var tweens = [];
745
- for(var _i = 0; _i < arguments.length; _i++){
746
- tweens[_i] = arguments[_i];
747
- }
730
+ }
731
+ // eslint-disable-next-line
732
+ chain(...tweens) {
748
733
  this._chainedTweens = tweens;
749
734
  return this;
750
- };
751
- Tween.prototype.unchain = function() {
752
- for(var _i = 0; _i < arguments.length; _i++){
753
- let index = this._chainedTweens.findIndex((v)=>v == arguments[_i]);
754
- if (index > -1) {
755
- this._chainedTweens.splice(index, 1);
756
- }
757
- }
735
+ }
736
+ unchain(...tweens) {
737
+ tweens.forEach((tween)=>{
738
+ let index = this._chainedTweens.findIndex((v)=>v === tween);
739
+ if (index > -1) this._chainedTweens.splice(index, 1);
740
+ });
758
741
  return this;
759
- };
760
- Tween.prototype.onStart = function(callback) {
742
+ }
743
+ onStart(callback) {
761
744
  this._onStartCallback = callback;
762
745
  return this;
763
- };
764
- Tween.prototype.onUpdate = function(callback) {
746
+ }
747
+ onEveryStart(callback) {
748
+ this._onEveryStartCallback = callback;
749
+ return this;
750
+ }
751
+ onUpdate(callback) {
765
752
  this._onUpdateCallback = callback;
766
753
  return this;
767
- };
768
- Tween.prototype.onRepeat = function(callback) {
754
+ }
755
+ onRepeat(callback) {
769
756
  this._onRepeatCallback = callback;
770
757
  return this;
771
- };
772
- Tween.prototype.onComplete = function(callback) {
758
+ }
759
+ onComplete(callback) {
773
760
  this._onCompleteCallback = callback;
774
761
  return this;
775
- };
776
- Tween.prototype.onStop = function(callback) {
762
+ }
763
+ onStop(callback) {
777
764
  this._onStopCallback = callback;
778
765
  return this;
779
- };
766
+ }
780
767
  /**
781
- * @returns true if the tween is still playing after the update, false
782
- * otherwise (calling update on a paused tween still returns true because
783
- * it is still playing, just paused).
784
- */ Tween.prototype.update = function(time, autoStart) {
785
- if (time === void 0) {
786
- time = now$1();
787
- }
788
- if (autoStart === void 0) {
789
- autoStart = true;
790
- }
768
+ * @returns true if the tween is still playing after the update, false
769
+ * otherwise (calling update on a paused tween still returns true because
770
+ * it is still playing, just paused).
771
+ */ update(time = now(), autoStart = true) {
791
772
  if (this._isPaused) return true;
792
- var property;
793
- var elapsed;
794
- var endTime = this._startTime + this._duration;
773
+ const endTime = this._startTime + this._duration;
795
774
  if (!this._goToEnd && !this._isPlaying) {
796
775
  if (time > endTime) return false;
797
- if (autoStart) this.start(time);
776
+ if (autoStart) this.start(time, true);
798
777
  }
799
778
  this._goToEnd = false;
800
779
  if (time < this._startTime) {
@@ -806,14 +785,18 @@ var mainGroup = new Group();
806
785
  }
807
786
  this._onStartCallbackFired = true;
808
787
  }
809
- elapsed = (time - this._startTime) / this._duration;
810
- elapsed = this._duration === 0 || elapsed > 1 ? 1 : elapsed;
811
- var value = this._easingFunction(elapsed);
812
- // properties transformations
813
- this._updateProperties(this._object, this._valuesStart, this._valuesEnd, value);
814
- if (this._onUpdateCallback) {
815
- this._onUpdateCallback(this._object, elapsed);
816
- }
788
+ if (this._onEveryStartCallbackFired === false) {
789
+ if (this._onEveryStartCallback) {
790
+ this._onEveryStartCallback(this._object);
791
+ }
792
+ this._onEveryStartCallbackFired = true;
793
+ }
794
+ const elapsedTime = time - this._startTime;
795
+ var _this__repeatDelayTime;
796
+ const durationAndDelay = this._duration + ((_this__repeatDelayTime = this._repeatDelayTime) != null ? _this__repeatDelayTime : this._delayTime);
797
+ const totalTime = this._duration + this._repeat * durationAndDelay;
798
+ const elapsed = this._calculateElapsedPortion(elapsedTime, durationAndDelay, totalTime);
799
+ const value = this._easingFunction(elapsed);
817
800
  if (elapsed === 1) {
818
801
  if (this._onFinishCallback) {
819
802
  this._onFinishCallback(this._object);
@@ -824,67 +807,102 @@ var mainGroup = new Group();
824
807
  this._isPlaying = false;
825
808
  return false;
826
809
  }
827
- if (this._repeat > 0) {
828
- if (isFinite(this._repeat)) {
829
- this._repeat--;
830
- }
831
- // Reassign starting values, restart by making startTime = now
832
- for(property in this._valuesStartRepeat){
833
- if (!this._yoyo && typeof this._valuesEnd[property] === 'string') {
834
- this._valuesStartRepeat[property] = // eslint-disable-next-line
835
- // @ts-ignore FIXME?
836
- this._valuesStartRepeat[property] + parseFloat(this._valuesEnd[property]);
837
- }
838
- if (this._yoyo) {
839
- this._swapEndStartRepeatValues(property);
840
- }
841
- this._valuesStart[property] = this._valuesStartRepeat[property];
842
- }
843
- if (this._yoyo) {
844
- this._reversed = !this._reversed;
845
- }
846
- if (this._repeatDelayTime !== undefined) {
847
- this._startTime = time + this._repeatDelayTime;
848
- } else {
849
- this._startTime = time + this._delayTime;
850
- }
851
- if (this._onRepeatCallback) {
852
- this._onRepeatCallback(this._object);
853
- }
854
- if (this._headTween) {
855
- this._headStart = true;
856
- this._initialRepeat = this._repeat;
857
- }
858
- return true;
859
- } else {
860
- if (this._tailTween) {
861
- this._tailTween.unchain(this);
862
- }
863
- if (this._onCompleteCallback) {
864
- this._onCompleteCallback(this._object);
865
- }
866
- for(var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++){
867
- // Make the chained tweens start exactly at the time they should,
868
- // even if the `update()` method was called way past the duration of the tween
869
- this._chainedTweens[i].start(this._startTime + this._duration);
870
- }
871
- this._isPlaying = false;
872
- return false;
810
+ }
811
+ const status = this._calculateCompletionStatus(elapsedTime, durationAndDelay);
812
+ if (status === 'repeat') {
813
+ // the current update is happening after the instant the tween repeated
814
+ this._processRepetition(elapsedTime, durationAndDelay);
815
+ }
816
+ this._updateProperties(this._object, this._valuesStart, this._valuesEnd, value);
817
+ if (status === 'about-to-repeat') {
818
+ // the current update is happening at the exact instant the tween is going to repeat
819
+ // the values should match the end of the tween, not the beginning,
820
+ // that's why _processRepetition happens after _updateProperties
821
+ this._processRepetition(elapsedTime, durationAndDelay);
822
+ }
823
+ if (this._onUpdateCallback) {
824
+ this._onUpdateCallback(this._object, elapsed);
825
+ }
826
+ if (status === 'repeat' || status === 'about-to-repeat') {
827
+ if (this._onRepeatCallback) {
828
+ this._onRepeatCallback(this._object);
829
+ }
830
+ if (this._headTween) {
831
+ this._headStart = true;
832
+ this._initialRepeat = this._repeat;
833
+ }
834
+ this._onEveryStartCallbackFired = false;
835
+ } else if (status === 'completed') {
836
+ this._isPlaying = false;
837
+ if (this._tailTween) {
838
+ this._tailTween.unchain(this);
839
+ }
840
+ if (this._onCompleteCallback) {
841
+ this._onCompleteCallback(this._object);
842
+ }
843
+ for(let i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++){
844
+ // Make the chained tweens start exactly at the time they should,
845
+ // even if the `update()` method was called way past the duration of the tween
846
+ this._chainedTweens[i].start(this._startTime + this._duration, false);
873
847
  }
874
848
  }
875
- return true;
876
- };
877
- Tween.prototype._updateProperties = function(_object, _valuesStart, _valuesEnd, value) {
878
- for(var property in _valuesEnd){
849
+ return status !== 'completed';
850
+ }
851
+ _calculateElapsedPortion(elapsedTime, durationAndDelay, totalTime) {
852
+ if (this._duration === 0 || elapsedTime > totalTime) {
853
+ return 1;
854
+ }
855
+ const timeIntoCurrentRepeat = elapsedTime % durationAndDelay;
856
+ const portion = Math.min(timeIntoCurrentRepeat / this._duration, 1);
857
+ if (portion === 0 && elapsedTime !== 0 && elapsedTime % this._duration === 0) {
858
+ return 1;
859
+ }
860
+ return portion;
861
+ }
862
+ _calculateCompletionStatus(elapsedTime, durationAndDelay) {
863
+ if (this._duration !== 0 && elapsedTime < this._duration) {
864
+ return 'playing';
865
+ }
866
+ if (this._repeat <= 0) {
867
+ return 'completed';
868
+ }
869
+ if (elapsedTime === this._duration) {
870
+ return 'about-to-repeat';
871
+ }
872
+ return 'repeat';
873
+ }
874
+ _processRepetition(elapsedTime, durationAndDelay) {
875
+ const completeCount = Math.min(durationAndDelay > 0 ? Math.trunc((elapsedTime - this._duration) / durationAndDelay) + 1 : 1, this._repeat);
876
+ if (isFinite(this._repeat)) {
877
+ this._repeat -= completeCount;
878
+ }
879
+ // Reassign starting values, restart by making startTime = now
880
+ for(const property in this._valuesStartRepeat){
881
+ const valueEnd = this._valuesEnd[property];
882
+ if (!this._yoyo && typeof valueEnd === 'string') {
883
+ this._valuesStartRepeat[property] = this._valuesStartRepeat[property] + parseFloat(valueEnd);
884
+ }
885
+ if (this._yoyo) {
886
+ this._swapEndStartRepeatValues(property);
887
+ }
888
+ this._valuesStart[property] = this._valuesStartRepeat[property];
889
+ }
890
+ if (this._yoyo) {
891
+ this._reversed = !this._reversed;
892
+ }
893
+ this._startTime += durationAndDelay * completeCount;
894
+ }
895
+ _updateProperties(_object, _valuesStart, _valuesEnd, value) {
896
+ for(const property in _valuesEnd){
879
897
  // Don't update properties that do not exist in the source object
880
898
  if (_valuesStart[property] === undefined) {
881
899
  continue;
882
900
  }
883
- var start = _valuesStart[property] || 0;
884
- var end = _valuesEnd[property];
885
- var startIsArray = Array.isArray(_object[property]);
886
- var endIsArray = Array.isArray(end);
887
- var isInterpolationList = !startIsArray && endIsArray;
901
+ const start = _valuesStart[property] || 0;
902
+ let end = _valuesEnd[property];
903
+ const startIsArray = Array.isArray(_object[property]);
904
+ const endIsArray = Array.isArray(end);
905
+ const isInterpolationList = !startIsArray && endIsArray;
888
906
  if (isInterpolationList) {
889
907
  _object[property] = this._interpolationFunction(end, value);
890
908
  } else if (typeof end === 'object' && end) {
@@ -906,29 +924,57 @@ var mainGroup = new Group();
906
924
  }
907
925
  }
908
926
  }
909
- };
910
- Tween.prototype._handleRelativeValue = function(start, end) {
927
+ }
928
+ _handleRelativeValue(start, end) {
911
929
  if (typeof end !== 'string') {
912
930
  return end;
913
931
  }
914
932
  if (end.charAt(0) === '+' || end.charAt(0) === '-') {
915
933
  return start + parseFloat(end);
916
- } else {
917
- return parseFloat(end);
918
934
  }
919
- };
920
- Tween.prototype._swapEndStartRepeatValues = function(property) {
921
- var tmp = this._valuesStartRepeat[property];
922
- var endValue = this._valuesEnd[property];
935
+ return parseFloat(end);
936
+ }
937
+ _swapEndStartRepeatValues(property) {
938
+ const tmp = this._valuesStartRepeat[property];
939
+ const endValue = this._valuesEnd[property];
923
940
  if (typeof endValue === 'string') {
924
941
  this._valuesStartRepeat[property] = this._valuesStartRepeat[property] + parseFloat(endValue);
925
942
  } else {
926
943
  this._valuesStartRepeat[property] = this._valuesEnd[property];
927
944
  }
928
945
  this._valuesEnd[property] = tmp;
929
- };
930
- return Tween;
931
- }();
946
+ }
947
+ constructor(_object, _group = mainGroup){
948
+ this._object = _object;
949
+ this._group = _group;
950
+ this._isPaused = false;
951
+ this._pauseStart = 0;
952
+ this._valuesStart = {};
953
+ this._valuesEnd = {};
954
+ this._valuesStartRepeat = {};
955
+ this._duration = 0;
956
+ this._isDynamic = false;
957
+ this._initialRepeat = 0;
958
+ this._repeat = 0;
959
+ this._yoyo = false;
960
+ this._isPlaying = false;
961
+ this._reversed = false;
962
+ this._delayTime = 0;
963
+ this._startTime = 0;
964
+ this._easingFunction = Easing.Linear.None;
965
+ this._interpolationFunction = Interpolation.Linear;
966
+ this._chainedTweens = [];
967
+ this._onStartCallbackFired = false;
968
+ this._onEveryStartCallbackFired = false;
969
+ this._id = Sequence.nextId();
970
+ this._isChainStopped = false;
971
+ this._propertiesAreSetUp = false;
972
+ this._headTween = null;
973
+ this._tailTween = null;
974
+ this._headStart = false;
975
+ this._goToEnd = false;
976
+ }
977
+ }
932
978
 
933
979
  class TweenChain {
934
980
  start() {
@@ -944,7 +990,7 @@ class TweenChain {
944
990
  return this;
945
991
  }
946
992
  union() {
947
- this._chainedTween = this._tween = new Tween(this._object).union(this._tween, this._chainedTween);
993
+ this._chainedTween = this._tween = new Tween(this._object, this._group).union(this._tween, this._chainedTween);
948
994
  return this;
949
995
  }
950
996
  call(callback) {
@@ -991,9 +1037,6 @@ class TweenManager {
991
1037
  update(time) {
992
1038
  this._group.update(time);
993
1039
  }
994
- tween(target) {
995
- return new Tween(target, this._group);
996
- }
997
1040
  timeline(target) {
998
1041
  return new TweenChain(target, this._group);
999
1042
  }
@@ -1399,20 +1442,14 @@ class CinestationBrain extends Component {
1399
1442
  const from = this.node, to = vcam;
1400
1443
  const { fov, near, far, finalPosition, finalRotation } = to;
1401
1444
  const isLensChanged = from.fov != fov || from.near != near || from.far != far;
1402
- const isTransformChanged = !from.position.equals(finalPosition) || !from.quaternion.equals(finalRotation);
1403
- const isChanged = isLensChanged || isTransformChanged;
1404
1445
  from.position.lerp(finalPosition, t);
1405
1446
  from.quaternion.slerp(finalRotation, t);
1406
1447
  from.fov = lerp$1(from.fov, fov, t);
1407
- from.near = lerp$1(from.near, near, t);
1408
- from.far = lerp$1(from.far, far, t);
1448
+ from.near = near;
1449
+ from.far = far;
1409
1450
  if (isLensChanged) {
1410
1451
  from.updateProjectionMatrix();
1411
1452
  }
1412
- if (this._isChanged !== isChanged) {
1413
- this._isChanged = isChanged;
1414
- this.onChanged && this.onChanged(isChanged);
1415
- }
1416
1453
  }
1417
1454
  constructor(...args){
1418
1455
  super(...args);
@@ -1420,9 +1457,7 @@ class CinestationBrain extends Component {
1420
1457
  this._vcamSolo = null;
1421
1458
  this._vcams = [];
1422
1459
  this._lerpTime = 0;
1423
- this._isChanged = false;
1424
1460
  this.brainBlend = new CinestationBlendDefinition();
1425
- this.onChanged = null;
1426
1461
  }
1427
1462
  }
1428
1463
  __decorate([
@@ -1449,11 +1484,6 @@ class VirtualCamera extends Component {
1449
1484
  onDestroy() {
1450
1485
  this.brain.removeCamera(this);
1451
1486
  }
1452
- update(dt) {
1453
- if (this.lookAt) {
1454
- this.node.lookAt(this.lookAt.position);
1455
- }
1456
- }
1457
1487
  constructor(...args){
1458
1488
  super(...args);
1459
1489
  this._finalPosition = new Vector3();
@@ -1466,8 +1496,6 @@ class VirtualCamera extends Component {
1466
1496
  this.far = 1000;
1467
1497
  this.correctPosition = new Vector3();
1468
1498
  this.correctRotation = new Quaternion();
1469
- this.lookaheadPosition = new Vector3();
1470
- this.lookAtOffset = new Vector3();
1471
1499
  }
1472
1500
  }
1473
1501
  __decorate([
@@ -2584,7 +2612,13 @@ const { clamp, degToRad } = MathUtils;
2584
2612
  const { abs, tan } = Math;
2585
2613
  class FreelookVirtualCamera extends VirtualCamera {
2586
2614
  printInfo() {
2587
- console.log(this.node.position, this.lookAt.position);
2615
+ const spherical = this._spherical;
2616
+ const lookAt = new Vector3().copy(this.lookAt.position).add(this._lookAtOffset);
2617
+ console.log([
2618
+ `springLength: ${spherical.radius.toFixed(2)}`,
2619
+ `rotation: ${spherical.theta.toFixed(2)}, ${spherical.phi.toFixed(2)}`,
2620
+ `lookAt: ${lookAt.x.toFixed(2)},${lookAt.y.toFixed(2)},${lookAt.z.toFixed(2)}`
2621
+ ].join("\n"));
2588
2622
  }
2589
2623
  onEnable() {
2590
2624
  this.viewer.on(DeviceInput.POINTER_DOWN, this._onPointerDown, this);
@@ -2606,9 +2640,16 @@ class FreelookVirtualCamera extends VirtualCamera {
2606
2640
  reset() {
2607
2641
  this._button = -1;
2608
2642
  this._touchID = -1;
2609
- this._rotateDelta.set(0, 0);
2610
- this._panDelta.set(0, 0);
2611
- this._distanceDelta = 0;
2643
+ this._setSpherical(this.node.position, this.lookAtPosition);
2644
+ }
2645
+ get lookAtPosition() {
2646
+ return this._lookAtPosition.copy(this.lookAt.position).add(this._lookAtOffset);
2647
+ }
2648
+ _setSpherical(position, lookAt) {
2649
+ const { __posDelta } = FreelookVirtualCamera;
2650
+ __posDelta.copy(position).sub(lookAt);
2651
+ this._spherical.setFromVector3(__posDelta);
2652
+ this._targetSpherical.copy(this._spherical);
2612
2653
  }
2613
2654
  _onPointerDown(e) {
2614
2655
  if (SystemInfo.isMobile) return;
@@ -2621,30 +2662,28 @@ class FreelookVirtualCamera extends VirtualCamera {
2621
2662
  }
2622
2663
  _onPointerMove(e) {
2623
2664
  if (SystemInfo.isMobile) return;
2624
- const { __loc0, __moveDelta } = FreelookVirtualCamera;
2665
+ const { __loc0, __panDelta, __rotateDelta } = FreelookVirtualCamera;
2625
2666
  __loc0.set(e.pageX, e.pageY);
2626
2667
  switch(this._button){
2627
2668
  case 0:
2628
- this._rotateDelta.add(this._calculateRotateDelta(__moveDelta, this._preLoc0, __loc0));
2669
+ this._calculateRotatelDelta(__rotateDelta, this._preLoc0, __loc0);
2670
+ this._calculateSpherical(__rotateDelta);
2629
2671
  break;
2630
2672
  case 1:
2631
2673
  case 2:
2632
- this._panDelta.add(this._calculatePanDelta(__moveDelta, this._preLoc0, __loc0));
2674
+ this._calculatePanDelta(__panDelta, this._preLoc0, __loc0);
2675
+ this._calculateLookAtOffset(__panDelta);
2633
2676
  break;
2634
2677
  }
2635
2678
  this._preLoc0.copy(__loc0);
2636
2679
  }
2637
2680
  _onMouseWheel(e) {
2638
- const { __worldPos } = FreelookVirtualCamera;
2639
2681
  if (this.lookAt) {
2640
- let dist = __worldPos.copy(this.lookAt.position).add(this.lookAtOffset).distanceTo(this.node.position);
2641
- let distNew = dist + this._distanceDelta;
2642
2682
  if (e.deltaY > 0) {
2643
- distNew *= this._calculateDistanceScale(1 / 0.85);
2683
+ this._targetSpherical.radius *= this._calculateDistanceScale(1 / 0.85);
2644
2684
  } else if (e.deltaY < 0) {
2645
- distNew *= this._calculateDistanceScale(0.85);
2685
+ this._targetSpherical.radius *= this._calculateDistanceScale(0.85);
2646
2686
  }
2647
- this._distanceDelta = distNew - dist;
2648
2687
  }
2649
2688
  }
2650
2689
  _onTouchStart(e) {
@@ -2661,37 +2700,39 @@ class FreelookVirtualCamera extends VirtualCamera {
2661
2700
  }
2662
2701
  _onTouchMove(e) {
2663
2702
  if (!SystemInfo.isMobile) return;
2664
- const { __loc0, __loc1, __worldPos, __moveDelta, __preCenter, __center } = FreelookVirtualCamera;
2703
+ const { __loc0, __loc1, __panDelta, __rotateDelta, __preCenter, __center } = FreelookVirtualCamera;
2665
2704
  let touches = e.touches;
2666
2705
  let rotateTouchID = this.rotateTouchID;
2667
2706
  if (touches.length > rotateTouchID + 1) {
2668
2707
  __loc0.set(touches[rotateTouchID].pageX, touches[rotateTouchID].pageY);
2669
2708
  __loc1.set(touches[rotateTouchID + 1].pageX, touches[rotateTouchID + 1].pageY);
2670
2709
  if (this.lookAt) {
2671
- let dist = __worldPos.copy(this.lookAt.position).add(this.lookAtOffset).distanceTo(this.node.position);
2672
- let distNew = (dist + this._distanceDelta) * this._calculateDistanceScale(this._preLoc0.distanceTo(this._preLoc1) / __loc0.distanceTo(__loc1));
2673
- this._distanceDelta = distNew - dist;
2710
+ this._targetSpherical.radius *= this._calculateDistanceScale(this._preLoc0.distanceTo(this._preLoc1) / __loc0.distanceTo(__loc1));
2674
2711
  }
2675
2712
  __preCenter.copy(this._preLoc0).add(this._preLoc1).multiplyScalar(0.5);
2676
2713
  __center.copy(__loc0).add(__loc1).multiplyScalar(0.5);
2677
- this._panDelta.add(this._calculatePanDelta(__moveDelta, __preCenter, __center));
2714
+ this._calculatePanDelta(__panDelta, __preCenter, __center);
2715
+ this._calculateLookAtOffset(__panDelta);
2678
2716
  this._preLoc0.copy(__loc0);
2679
2717
  this._preLoc1.copy(__loc1);
2680
2718
  } else if (touches.length > rotateTouchID) {
2681
2719
  if (this._touchID === touches[rotateTouchID].identifier) {
2682
2720
  __loc0.set(touches[rotateTouchID].pageX, touches[rotateTouchID].pageY);
2683
- this._rotateDelta.add(this._calculateRotateDelta(__moveDelta, this._preLoc0, __loc0));
2721
+ this._calculateRotatelDelta(__rotateDelta, this._preLoc0, __loc0);
2722
+ this._calculateSpherical(__rotateDelta);
2684
2723
  this._preLoc0.copy(__loc0);
2685
2724
  }
2686
2725
  }
2687
2726
  }
2688
2727
  _calculateDistanceScale(scale) {
2728
+ this._tempSmoothing = this.smoothing;
2689
2729
  if (this.forbidZ) {
2690
2730
  scale = 1;
2691
2731
  }
2692
2732
  return scale;
2693
2733
  }
2694
- _calculateRotateDelta(out, loc0, loc1) {
2734
+ _calculateRotatelDelta(out, loc0, loc1) {
2735
+ this._tempSmoothing = this.smoothing;
2695
2736
  const domElement = this.viewer.canvas;
2696
2737
  out.copy(loc1).sub(loc0).multiplyScalar(this.rotateSpeed * 2 * Math.PI / domElement.height);
2697
2738
  out.y = -out.y;
@@ -2701,10 +2742,10 @@ class FreelookVirtualCamera extends VirtualCamera {
2701
2742
  if (this.forbidY) {
2702
2743
  out.y = 0;
2703
2744
  }
2704
- this._tempSmoothing = this.smoothing;
2705
2745
  return out;
2706
2746
  }
2707
2747
  _calculatePanDelta(out, loc0, loc1) {
2748
+ this._tempSmoothing = this.smoothing;
2708
2749
  const domElement = this.viewer.canvas;
2709
2750
  out.copy(loc1).sub(loc0).multiplyScalar(this.panSpeed / domElement.height);
2710
2751
  if (this.forbidPanX) {
@@ -2713,91 +2754,77 @@ class FreelookVirtualCamera extends VirtualCamera {
2713
2754
  if (this.forbidPanY) {
2714
2755
  out.y = 0;
2715
2756
  }
2716
- this._tempSmoothing = this.smoothing;
2717
2757
  return out;
2718
2758
  }
2719
- gotoPOI(position, lookAt, smoothing = 1) {
2720
- const { __posDelta, __worldPos, __quat, __spherical } = FreelookVirtualCamera;
2721
- __quat.setFromUnitVectors(this.node.up, Object3D.DEFAULT_UP);
2722
- __posDelta.copy(position).sub(lookAt);
2723
- __posDelta.applyQuaternion(__quat);
2724
- __spherical.setFromVector3(__posDelta);
2725
- const { theta, phi, radius } = __spherical;
2726
- __worldPos.copy(this.lookAt.position).add(this.lookAtOffset);
2727
- __posDelta.copy(this.node.position).sub(__worldPos);
2728
- __posDelta.applyQuaternion(__quat);
2729
- __spherical.setFromVector3(__posDelta);
2730
- const dx = theta - __spherical.theta;
2731
- const dy = phi - __spherical.phi;
2732
- const dz = radius - __spherical.radius;
2733
- this._rotateDelta.x = -dx;
2734
- this._rotateDelta.y = dy;
2735
- this._distanceDelta = dz;
2759
+ _calculateLookAtOffset(panDelta) {
2760
+ const { __xAxis, __yAxis, __posDelta } = FreelookVirtualCamera;
2761
+ __xAxis.setFromMatrixColumn(this.node.matrix, 0);
2762
+ __yAxis.setFromMatrixColumn(this.node.matrix, 1);
2763
+ if (this.forbitPanOffsetY) {
2764
+ __yAxis.y = 0;
2765
+ __yAxis.normalize();
2766
+ }
2767
+ __posDelta.copy(this.node.position).sub(this.lookAtPosition);
2768
+ const length = __posDelta.length() * 2 * tan(degToRad(this.fov * 0.5));
2769
+ return this._targetLookAtOffset.sub(__xAxis.multiplyScalar(panDelta.x * length)).add(__yAxis.multiplyScalar(panDelta.y * length));
2770
+ }
2771
+ _calculateSpherical(rotateDelta, radius) {
2772
+ const spherical = this._targetSpherical;
2773
+ if (rotateDelta) {
2774
+ spherical.theta -= rotateDelta.x;
2775
+ spherical.phi += rotateDelta.y;
2776
+ }
2777
+ if (radius) {
2778
+ spherical.radius = radius;
2779
+ }
2780
+ spherical.theta = clamp(spherical.theta, this.thetaMin, this.thetaMax);
2781
+ spherical.phi = clamp(spherical.phi, this.phiMin, this.phiMax);
2782
+ spherical.radius = clamp(spherical.radius, this.distanceMin, this.distanceMax);
2783
+ return spherical;
2784
+ }
2785
+ gotoPOI(springLength, rotation, lookAt, fov = this.fov, smoothing = this.smoothing) {
2786
+ this._targetFov = fov;
2736
2787
  this._tempSmoothing = smoothing;
2737
- this._lookAtOffsetDelta.copy(lookAt).sub(this.lookAt.position).sub(this.lookAtOffset);
2738
- }
2739
- update(dt) {
2740
- if (!this.lookAt) return;
2741
- const dampFactor = exponentialDamp(1, 0, this._tempSmoothing, dt);
2742
- const { __posDelta, __offsetDelta, __worldPos, __quat, __spherical, __xAxis, __yAxis } = FreelookVirtualCamera;
2743
- __worldPos.copy(this.lookAt.position).add(this.lookAtOffset);
2744
- if (this._rotateDelta.manhattanLength() + abs(this._distanceDelta) > 0.001) {
2745
- __quat.setFromUnitVectors(this.node.up, Object3D.DEFAULT_UP);
2746
- __posDelta.copy(this.node.position).sub(__worldPos);
2747
- __posDelta.applyQuaternion(__quat);
2748
- __spherical.setFromVector3(__posDelta);
2749
- this._rotateDelta.x = __spherical.theta - clamp(__spherical.theta - this._rotateDelta.x, this.thetaMin, this.thetaMax);
2750
- __spherical.theta = __spherical.theta - this._rotateDelta.x * (1 - dampFactor);
2751
- this._rotateDelta.y = clamp(__spherical.phi + this._rotateDelta.y, this.phiMin, this.phiMax) - __spherical.phi;
2752
- __spherical.phi = clamp(__spherical.phi + this._rotateDelta.y * (1 - dampFactor), 0.001, Math.PI - 0.001);
2753
- this._distanceDelta = clamp(__spherical.radius + this._distanceDelta, this.distanceMin, this.distanceMax) - __spherical.radius;
2754
- __spherical.radius = __spherical.radius + this._distanceDelta * (1 - dampFactor);
2755
- this._rotateDelta.multiplyScalar(dampFactor);
2756
- this._distanceDelta *= dampFactor;
2757
- __posDelta.setFromSpherical(__spherical);
2758
- __posDelta.applyQuaternion(__quat.invert());
2759
- this.node.position.copy(__posDelta.add(__worldPos));
2760
- }
2761
- if (this._panDelta.manhattanLength() > 0.001) {
2762
- __posDelta.copy(this.node.position).sub(__worldPos);
2763
- __xAxis.setFromMatrixColumn(this.node.matrix, 0);
2764
- __yAxis.setFromMatrixColumn(this.node.matrix, 1);
2765
- if (this.forbitPanOffsetY) {
2766
- __yAxis.y = 0;
2767
- __yAxis.normalize();
2768
- }
2769
- let length = __posDelta.length() * 2 * tan(degToRad(this.fov * 0.5));
2770
- let lookAtOffset = this.lookAtOffset;
2771
- lookAtOffset.sub(__xAxis.multiplyScalar(this._panDelta.x * length * (1 - dampFactor)));
2772
- lookAtOffset.add(__yAxis.multiplyScalar(this._panDelta.y * length * (1 - dampFactor)));
2773
- this._panDelta.multiplyScalar(dampFactor);
2774
- __worldPos.copy(this.lookAt.position).add(lookAtOffset);
2775
- this.node.position.copy(__posDelta.add(__worldPos));
2788
+ this._targetSpherical.radius = springLength;
2789
+ if (rotation) {
2790
+ this._targetSpherical.theta = rotation.x;
2791
+ this._targetSpherical.phi = rotation.y;
2776
2792
  }
2777
- if (this._lookAtOffsetDelta.manhattanLength() > 0.001) {
2778
- this.lookAtOffset.add(__offsetDelta.copy(this._lookAtOffsetDelta).multiplyScalar(1 - dampFactor));
2779
- this._lookAtOffsetDelta.multiplyScalar(dampFactor);
2793
+ this._calculateSpherical();
2794
+ if (lookAt) {
2795
+ this._targetLookAtOffset.copy(lookAt).sub(this.lookAt.position);
2780
2796
  }
2781
- this.node.lookAt(__worldPos);
2797
+ }
2798
+ update(dt) {
2799
+ const smoothing = this._tempSmoothing;
2800
+ this._spherical.theta = FInterpTo(this._spherical.theta, this._targetSpherical.theta, dt, smoothing);
2801
+ this._spherical.phi = FInterpTo(this._spherical.phi, this._targetSpherical.phi, dt, smoothing);
2802
+ this._spherical.radius = FInterpTo(this._spherical.radius, this._targetSpherical.radius, dt, smoothing);
2803
+ this.node.position.setFromSpherical(this._spherical).add(this.lookAtPosition);
2804
+ this.fov = FInterpTo(this.fov, this._targetFov, dt, smoothing);
2805
+ VInterpTo(this._lookAtOffset, this._targetLookAtOffset, dt, smoothing);
2806
+ this.node.lookAt(this.lookAtPosition);
2782
2807
  }
2783
2808
  constructor(...args){
2784
2809
  super(...args);
2785
2810
  this._button = -1;
2786
2811
  this._touchID = -1;
2787
- this._distanceDelta = 0;
2788
2812
  this._preLoc0 = new Vector2();
2789
2813
  this._preLoc1 = new Vector2();
2790
- this._rotateDelta = new Vector2();
2791
- this._panDelta = new Vector2();
2814
+ this._spherical = new Spherical();
2815
+ this._lookAtPosition = new Vector3();
2816
+ this._lookAtOffset = new Vector3();
2792
2817
  this._tempSmoothing = 0;
2793
- this._lookAtOffsetDelta = new Vector3();
2818
+ this._targetFov = this.fov;
2819
+ this._targetLookAtOffset = new Vector3();
2820
+ this._targetSpherical = new Spherical();
2794
2821
  this.forbidX = false;
2795
2822
  this.forbidY = false;
2796
2823
  this.forbidZ = false;
2797
2824
  this.forbidPanX = false;
2798
2825
  this.forbidPanY = false;
2799
2826
  this.forbitPanOffsetY = false;
2800
- this.smoothing = 0.5;
2827
+ this.smoothing = 5;
2801
2828
  this.rotateSpeed = 2;
2802
2829
  this.panSpeed = 2;
2803
2830
  this.panScale = new Vector3(1, 1, 1);
@@ -2815,14 +2842,13 @@ FreelookVirtualCamera.__loc0 = new Vector2();
2815
2842
  FreelookVirtualCamera.__loc1 = new Vector2();
2816
2843
  FreelookVirtualCamera.__center = new Vector2();
2817
2844
  FreelookVirtualCamera.__preCenter = new Vector2();
2818
- FreelookVirtualCamera.__moveDelta = new Vector2();
2819
- FreelookVirtualCamera.__worldPos = new Vector3();
2845
+ FreelookVirtualCamera.__panDelta = new Vector2();
2846
+ FreelookVirtualCamera.__panTarget = new Vector2();
2847
+ FreelookVirtualCamera.__rotateDelta = new Vector2();
2820
2848
  FreelookVirtualCamera.__posDelta = new Vector3();
2821
2849
  FreelookVirtualCamera.__xAxis = new Vector3();
2822
2850
  FreelookVirtualCamera.__yAxis = new Vector3();
2823
2851
  FreelookVirtualCamera.__quat = new Quaternion();
2824
- FreelookVirtualCamera.__spherical = new Spherical();
2825
- FreelookVirtualCamera.__offsetDelta = new Vector3();
2826
2852
  __decorate([
2827
2853
  property({
2828
2854
  dir: "set"
@@ -4569,9 +4595,6 @@ class Viewer extends EventEmitter {
4569
4595
  this.addNode(node, props);
4570
4596
  return node;
4571
4597
  }
4572
- tween(target) {
4573
- return this._tweenManager.tween(target);
4574
- }
4575
4598
  timeline(target) {
4576
4599
  return this._tweenManager.timeline(target);
4577
4600
  }