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