@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/module.js
CHANGED
|
@@ -3,7 +3,7 @@ import { FBXLoader } from 'three/examples/jsm/loaders/FBXLoader.js';
|
|
|
3
3
|
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
|
|
4
4
|
import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader.js';
|
|
5
5
|
import { MeshoptDecoder } from 'three/examples/jsm/libs/meshopt_decoder.module.js';
|
|
6
|
-
import { EquirectangularReflectionMapping, FileLoader, TextureLoader, SRGBColorSpace, MathUtils, Vector3, Quaternion, Raycaster, Vector2, LinearInterpolant, Spherical,
|
|
6
|
+
import { EquirectangularReflectionMapping, FileLoader, TextureLoader, SRGBColorSpace, MathUtils, Vector3, Quaternion, Raycaster, Vector2, LinearInterpolant, Spherical, Mesh, BoxGeometry, SphereGeometry, PlaneGeometry, Plane as Plane$1, Matrix4, Vector4, PerspectiveCamera, WebGLRenderTarget, HalfFloatType, LinearMipMapLinearFilter, LinearFilter, ShaderMaterial, UniformsUtils, Color, Scene, OrthographicCamera, NoBlending, AdditiveBlending, FloatType, UnsignedByteType, BufferGeometry, Float32BufferAttribute, Object3D, ClampToEdgeWrapping, NearestFilter, LinearSRGBColorSpace, WebGLCubeRenderTarget, DataTexture, RGBAFormat, UVMapping, WebGLRenderer, PCFSoftShadowMap, LoadingManager, LinearToneMapping, PMREMGenerator, MeshBasicMaterial, CubeCamera, Box3Helper, Box3, ShaderLib, ShaderChunk } from 'three';
|
|
7
7
|
import { RGBELoader } from 'three/examples/jsm/loaders/RGBELoader.js';
|
|
8
8
|
|
|
9
9
|
class EventEmitter {
|
|
@@ -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
|
-
*/
|
|
145
|
-
Linear: {
|
|
146
|
-
None
|
|
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
|
|
158
|
+
}),
|
|
159
|
+
Quadratic: Object.freeze({
|
|
160
|
+
In (amount) {
|
|
152
161
|
return amount * amount;
|
|
153
162
|
},
|
|
154
|
-
Out
|
|
163
|
+
Out (amount) {
|
|
155
164
|
return amount * (2 - amount);
|
|
156
165
|
},
|
|
157
|
-
InOut
|
|
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
|
|
172
|
+
}),
|
|
173
|
+
Cubic: Object.freeze({
|
|
174
|
+
In (amount) {
|
|
166
175
|
return amount * amount * amount;
|
|
167
176
|
},
|
|
168
|
-
Out
|
|
177
|
+
Out (amount) {
|
|
169
178
|
return --amount * amount * amount + 1;
|
|
170
179
|
},
|
|
171
|
-
InOut
|
|
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
|
|
186
|
+
}),
|
|
187
|
+
Quartic: Object.freeze({
|
|
188
|
+
In (amount) {
|
|
180
189
|
return amount * amount * amount * amount;
|
|
181
190
|
},
|
|
182
|
-
Out
|
|
191
|
+
Out (amount) {
|
|
183
192
|
return 1 - --amount * amount * amount * amount;
|
|
184
193
|
},
|
|
185
|
-
InOut
|
|
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
|
|
200
|
+
}),
|
|
201
|
+
Quintic: Object.freeze({
|
|
202
|
+
In (amount) {
|
|
194
203
|
return amount * amount * amount * amount * amount;
|
|
195
204
|
},
|
|
196
|
-
Out
|
|
205
|
+
Out (amount) {
|
|
197
206
|
return --amount * amount * amount * amount * amount + 1;
|
|
198
207
|
},
|
|
199
|
-
InOut
|
|
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
|
|
208
|
-
return 1 - Math.
|
|
214
|
+
}),
|
|
215
|
+
Sinusoidal: Object.freeze({
|
|
216
|
+
In (amount) {
|
|
217
|
+
return 1 - Math.sin((1.0 - amount) * Math.PI / 2);
|
|
209
218
|
},
|
|
210
|
-
Out
|
|
219
|
+
Out (amount) {
|
|
211
220
|
return Math.sin(amount * Math.PI / 2);
|
|
212
221
|
},
|
|
213
|
-
InOut
|
|
214
|
-
return 0.5 * (1 - Math.
|
|
222
|
+
InOut (amount) {
|
|
223
|
+
return 0.5 * (1 - Math.sin(Math.PI * (0.5 - amount)));
|
|
215
224
|
}
|
|
216
|
-
},
|
|
217
|
-
Exponential: {
|
|
218
|
-
In
|
|
225
|
+
}),
|
|
226
|
+
Exponential: Object.freeze({
|
|
227
|
+
In (amount) {
|
|
219
228
|
return amount === 0 ? 0 : Math.pow(1024, amount - 1);
|
|
220
229
|
},
|
|
221
|
-
Out
|
|
230
|
+
Out (amount) {
|
|
222
231
|
return amount === 1 ? 1 : 1 - Math.pow(2, -10 * amount);
|
|
223
232
|
},
|
|
224
|
-
InOut
|
|
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
|
|
245
|
+
}),
|
|
246
|
+
Circular: Object.freeze({
|
|
247
|
+
In (amount) {
|
|
239
248
|
return 1 - Math.sqrt(1 - amount * amount);
|
|
240
249
|
},
|
|
241
|
-
Out
|
|
250
|
+
Out (amount) {
|
|
242
251
|
return Math.sqrt(1 - --amount * amount);
|
|
243
252
|
},
|
|
244
|
-
InOut
|
|
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
|
|
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
|
|
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
|
|
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
|
|
286
|
-
|
|
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
|
|
290
|
-
|
|
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
|
|
294
|
-
|
|
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
|
|
309
|
+
}),
|
|
310
|
+
Bounce: Object.freeze({
|
|
311
|
+
In (amount) {
|
|
303
312
|
return 1 - Easing.Bounce.Out(1 - amount);
|
|
304
313
|
},
|
|
305
|
-
Out
|
|
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
|
|
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
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
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
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
return Group;
|
|
408
|
-
}();
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
|
|
409
352
|
/**
|
|
410
353
|
*
|
|
411
|
-
*/
|
|
354
|
+
*/ /**
|
|
355
|
+
*
|
|
356
|
+
*/ const Interpolation = {
|
|
412
357
|
Linear: function(v, k) {
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
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
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
for(
|
|
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
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
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
|
-
|
|
405
|
+
const fc = Interpolation.Utils.Factorial;
|
|
461
406
|
return fc(n) / fc(i) / fc(n - i);
|
|
462
407
|
},
|
|
463
408
|
Factorial: function() {
|
|
464
|
-
|
|
409
|
+
const a = [
|
|
465
410
|
1
|
|
466
411
|
];
|
|
467
412
|
return function(n) {
|
|
468
|
-
|
|
413
|
+
let s = 1;
|
|
469
414
|
if (a[n]) {
|
|
470
415
|
return a[n];
|
|
471
416
|
}
|
|
472
|
-
for(
|
|
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
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
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
|
-
*
|
|
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
|
-
*
|
|
505
|
-
*
|
|
506
|
-
*/
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
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
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
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
|
-
|
|
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
|
-
|
|
501
|
+
}
|
|
502
|
+
isPlaying() {
|
|
541
503
|
return this._isPlaying;
|
|
542
|
-
}
|
|
543
|
-
|
|
504
|
+
}
|
|
505
|
+
isPaused() {
|
|
544
506
|
return this._isPaused;
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
this._duration
|
|
507
|
+
}
|
|
508
|
+
getDuration() {
|
|
509
|
+
return this._duration;
|
|
510
|
+
}
|
|
511
|
+
from(properties) {
|
|
512
|
+
this._valuesStart = Object.create(properties);
|
|
548
513
|
return this;
|
|
549
|
-
}
|
|
550
|
-
|
|
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(
|
|
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
|
|
551
|
+
this._startTime = time;
|
|
571
552
|
this._startTime += this._delayTime;
|
|
572
|
-
|
|
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
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
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
|
-
|
|
581
|
+
const endValues = _valuesEnd[property];
|
|
589
582
|
if (endValues.length === 0) {
|
|
590
583
|
continue;
|
|
591
584
|
}
|
|
592
|
-
//
|
|
593
|
-
|
|
594
|
-
|
|
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
|
-
]
|
|
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
|
-
|
|
603
|
-
for(
|
|
604
|
-
|
|
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
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
659
|
+
}
|
|
660
|
+
end() {
|
|
650
661
|
this._goToEnd = true;
|
|
651
662
|
this.update(Infinity);
|
|
652
663
|
return this;
|
|
653
|
-
}
|
|
654
|
-
|
|
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
|
-
|
|
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,97 @@ var mainGroup = new Group();
|
|
|
677
682
|
// eslint-disable-next-line
|
|
678
683
|
this._group && this._group.add(this);
|
|
679
684
|
return this;
|
|
680
|
-
}
|
|
681
|
-
|
|
682
|
-
for(
|
|
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
|
-
|
|
691
|
+
}
|
|
692
|
+
group(group = mainGroup) {
|
|
689
693
|
this._group = group;
|
|
690
694
|
return this;
|
|
691
|
-
}
|
|
692
|
-
|
|
695
|
+
}
|
|
696
|
+
call(callback) {
|
|
693
697
|
this._onFinishCallback = callback;
|
|
694
698
|
return this;
|
|
695
|
-
}
|
|
696
|
-
|
|
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
|
-
|
|
703
|
+
}
|
|
704
|
+
union(headTween, tailTween) {
|
|
717
705
|
this._headTween = headTween;
|
|
718
706
|
this._tailTween = tailTween.chain(this);
|
|
719
|
-
this._headStart = true;
|
|
720
707
|
return this;
|
|
721
|
-
}
|
|
722
|
-
|
|
708
|
+
}
|
|
709
|
+
repeat(times = 0) {
|
|
723
710
|
this._initialRepeat = times;
|
|
724
711
|
this._repeat = times;
|
|
725
712
|
return this;
|
|
726
|
-
}
|
|
727
|
-
|
|
713
|
+
}
|
|
714
|
+
repeatDelay(amount) {
|
|
728
715
|
this._repeatDelayTime = amount;
|
|
729
716
|
return this;
|
|
730
|
-
}
|
|
731
|
-
|
|
717
|
+
}
|
|
718
|
+
yoyo(yoyo = false) {
|
|
732
719
|
this._yoyo = yoyo;
|
|
733
720
|
return this;
|
|
734
|
-
}
|
|
735
|
-
|
|
721
|
+
}
|
|
722
|
+
easing(easingFunction = Easing.Linear.None) {
|
|
736
723
|
this._easingFunction = easingFunction;
|
|
737
724
|
return this;
|
|
738
|
-
}
|
|
739
|
-
|
|
725
|
+
}
|
|
726
|
+
interpolation(interpolationFunction = Interpolation.Linear) {
|
|
740
727
|
this._interpolationFunction = interpolationFunction;
|
|
741
728
|
return this;
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
for(var _i = 0; _i < arguments.length; _i++){
|
|
746
|
-
tweens[_i] = arguments[_i];
|
|
747
|
-
}
|
|
729
|
+
}
|
|
730
|
+
// eslint-disable-next-line
|
|
731
|
+
chain(...tweens) {
|
|
748
732
|
this._chainedTweens = tweens;
|
|
749
733
|
return this;
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
let index = this._chainedTweens.findIndex((v)=>v
|
|
754
|
-
if (index > -1)
|
|
755
|
-
|
|
756
|
-
}
|
|
757
|
-
}
|
|
734
|
+
}
|
|
735
|
+
unchain(...tweens) {
|
|
736
|
+
tweens.forEach((tween)=>{
|
|
737
|
+
let index = this._chainedTweens.findIndex((v)=>v === tween);
|
|
738
|
+
if (index > -1) this._chainedTweens.splice(index, 1);
|
|
739
|
+
});
|
|
758
740
|
return this;
|
|
759
|
-
}
|
|
760
|
-
|
|
741
|
+
}
|
|
742
|
+
onStart(callback) {
|
|
761
743
|
this._onStartCallback = callback;
|
|
762
744
|
return this;
|
|
763
|
-
}
|
|
764
|
-
|
|
745
|
+
}
|
|
746
|
+
onEveryStart(callback) {
|
|
747
|
+
this._onEveryStartCallback = callback;
|
|
748
|
+
return this;
|
|
749
|
+
}
|
|
750
|
+
onUpdate(callback) {
|
|
765
751
|
this._onUpdateCallback = callback;
|
|
766
752
|
return this;
|
|
767
|
-
}
|
|
768
|
-
|
|
753
|
+
}
|
|
754
|
+
onRepeat(callback) {
|
|
769
755
|
this._onRepeatCallback = callback;
|
|
770
756
|
return this;
|
|
771
|
-
}
|
|
772
|
-
|
|
757
|
+
}
|
|
758
|
+
onComplete(callback) {
|
|
773
759
|
this._onCompleteCallback = callback;
|
|
774
760
|
return this;
|
|
775
|
-
}
|
|
776
|
-
|
|
761
|
+
}
|
|
762
|
+
onStop(callback) {
|
|
777
763
|
this._onStopCallback = callback;
|
|
778
764
|
return this;
|
|
779
|
-
}
|
|
765
|
+
}
|
|
780
766
|
/**
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
if (time === void 0) {
|
|
786
|
-
time = now$1();
|
|
787
|
-
}
|
|
788
|
-
if (autoStart === void 0) {
|
|
789
|
-
autoStart = true;
|
|
790
|
-
}
|
|
767
|
+
* @returns true if the tween is still playing after the update, false
|
|
768
|
+
* otherwise (calling update on a paused tween still returns true because
|
|
769
|
+
* it is still playing, just paused).
|
|
770
|
+
*/ update(time = now(), autoStart = true) {
|
|
791
771
|
if (this._isPaused) return true;
|
|
792
|
-
|
|
793
|
-
var elapsed;
|
|
794
|
-
var endTime = this._startTime + this._duration;
|
|
772
|
+
const endTime = this._startTime + this._duration;
|
|
795
773
|
if (!this._goToEnd && !this._isPlaying) {
|
|
796
774
|
if (time > endTime) return false;
|
|
797
|
-
if (autoStart) this.start(time);
|
|
775
|
+
if (autoStart) this.start(time, true);
|
|
798
776
|
}
|
|
799
777
|
this._goToEnd = false;
|
|
800
778
|
if (time < this._startTime) {
|
|
@@ -806,85 +784,126 @@ var mainGroup = new Group();
|
|
|
806
784
|
}
|
|
807
785
|
this._onStartCallbackFired = true;
|
|
808
786
|
}
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
787
|
+
if (this._onEveryStartCallbackFired === false) {
|
|
788
|
+
if (this._onEveryStartCallback) {
|
|
789
|
+
this._onEveryStartCallback(this._object);
|
|
790
|
+
}
|
|
791
|
+
this._onEveryStartCallbackFired = true;
|
|
792
|
+
}
|
|
793
|
+
const elapsedTime = time - this._startTime;
|
|
794
|
+
var _this__repeatDelayTime;
|
|
795
|
+
const durationAndDelay = this._duration + ((_this__repeatDelayTime = this._repeatDelayTime) != null ? _this__repeatDelayTime : this._delayTime);
|
|
796
|
+
const totalTime = this._duration + this._repeat * durationAndDelay;
|
|
797
|
+
const elapsed = this._calculateElapsedPortion(elapsedTime, durationAndDelay, totalTime);
|
|
798
|
+
const value = this._easingFunction(elapsed);
|
|
799
|
+
if (elapsed === 1) {
|
|
800
|
+
if (this._onFinishCallback) {
|
|
801
|
+
this._onFinishCallback(this._object);
|
|
802
|
+
}
|
|
803
|
+
if (this._headTween) {
|
|
804
|
+
if (this._headTweenStartFired === false) {
|
|
805
|
+
this._headTweenStartFired = true;
|
|
806
|
+
this._headTween.start(this._startTime + this._duration);
|
|
807
|
+
this._isPlaying = false;
|
|
808
|
+
return false;
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
const status = this._calculateCompletionStatus(elapsedTime, durationAndDelay);
|
|
813
|
+
if (status === 'repeat') {
|
|
814
|
+
// the current update is happening after the instant the tween repeated
|
|
815
|
+
this._processRepetition(elapsedTime, durationAndDelay);
|
|
816
|
+
}
|
|
813
817
|
this._updateProperties(this._object, this._valuesStart, this._valuesEnd, value);
|
|
818
|
+
if (status === 'about-to-repeat') {
|
|
819
|
+
// the current update is happening at the exact instant the tween is going to repeat
|
|
820
|
+
// the values should match the end of the tween, not the beginning,
|
|
821
|
+
// that's why _processRepetition happens after _updateProperties
|
|
822
|
+
this._processRepetition(elapsedTime, durationAndDelay);
|
|
823
|
+
}
|
|
814
824
|
if (this._onUpdateCallback) {
|
|
815
825
|
this._onUpdateCallback(this._object, elapsed);
|
|
816
826
|
}
|
|
817
|
-
if (
|
|
818
|
-
if (this.
|
|
819
|
-
this.
|
|
827
|
+
if (status === 'repeat' || status === 'about-to-repeat') {
|
|
828
|
+
if (this._onRepeatCallback) {
|
|
829
|
+
this._onRepeatCallback(this._object);
|
|
820
830
|
}
|
|
821
|
-
if (this._headTween
|
|
822
|
-
this.
|
|
823
|
-
this.
|
|
824
|
-
this._isPlaying = false;
|
|
825
|
-
return false;
|
|
831
|
+
if (this._headTween) {
|
|
832
|
+
this._headTweenStartFired = false;
|
|
833
|
+
this._initialRepeat = this._repeat;
|
|
826
834
|
}
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
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;
|
|
835
|
+
this._onEveryStartCallbackFired = false;
|
|
836
|
+
} else if (status === 'completed') {
|
|
837
|
+
this._isPlaying = false;
|
|
838
|
+
if (this._tailTween) {
|
|
839
|
+
this._tailTween.unchain(this);
|
|
840
|
+
}
|
|
841
|
+
if (this._onCompleteCallback) {
|
|
842
|
+
this._onCompleteCallback(this._object);
|
|
843
|
+
}
|
|
844
|
+
for(let i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++){
|
|
845
|
+
// Make the chained tweens start exactly at the time they should,
|
|
846
|
+
// even if the `update()` method was called way past the duration of the tween
|
|
847
|
+
this._chainedTweens[i].start(this._startTime + this._duration, false);
|
|
873
848
|
}
|
|
874
849
|
}
|
|
875
|
-
return
|
|
876
|
-
}
|
|
877
|
-
|
|
878
|
-
|
|
850
|
+
return status !== 'completed';
|
|
851
|
+
}
|
|
852
|
+
_calculateElapsedPortion(elapsedTime, durationAndDelay, totalTime) {
|
|
853
|
+
if (this._duration === 0 || elapsedTime > totalTime) {
|
|
854
|
+
return 1;
|
|
855
|
+
}
|
|
856
|
+
const timeIntoCurrentRepeat = elapsedTime % durationAndDelay;
|
|
857
|
+
const portion = Math.min(timeIntoCurrentRepeat / this._duration, 1);
|
|
858
|
+
if (portion === 0 && elapsedTime !== 0 && elapsedTime % this._duration === 0) {
|
|
859
|
+
return 1;
|
|
860
|
+
}
|
|
861
|
+
return portion;
|
|
862
|
+
}
|
|
863
|
+
_calculateCompletionStatus(elapsedTime, durationAndDelay) {
|
|
864
|
+
if (this._duration !== 0 && elapsedTime < this._duration) {
|
|
865
|
+
return 'playing';
|
|
866
|
+
}
|
|
867
|
+
if (this._repeat <= 0) {
|
|
868
|
+
return 'completed';
|
|
869
|
+
}
|
|
870
|
+
if (elapsedTime === this._duration) {
|
|
871
|
+
return 'about-to-repeat';
|
|
872
|
+
}
|
|
873
|
+
return 'repeat';
|
|
874
|
+
}
|
|
875
|
+
_processRepetition(elapsedTime, durationAndDelay) {
|
|
876
|
+
const completeCount = Math.min(durationAndDelay > 0 ? Math.trunc((elapsedTime - this._duration) / durationAndDelay) + 1 : 1, this._repeat);
|
|
877
|
+
if (isFinite(this._repeat)) {
|
|
878
|
+
this._repeat -= completeCount;
|
|
879
|
+
}
|
|
880
|
+
// Reassign starting values, restart by making startTime = now
|
|
881
|
+
for(const property in this._valuesStartRepeat){
|
|
882
|
+
const valueEnd = this._valuesEnd[property];
|
|
883
|
+
if (!this._yoyo && typeof valueEnd === 'string') {
|
|
884
|
+
this._valuesStartRepeat[property] = this._valuesStartRepeat[property] + parseFloat(valueEnd);
|
|
885
|
+
}
|
|
886
|
+
if (this._yoyo) {
|
|
887
|
+
this._swapEndStartRepeatValues(property);
|
|
888
|
+
}
|
|
889
|
+
this._valuesStart[property] = this._valuesStartRepeat[property];
|
|
890
|
+
}
|
|
891
|
+
if (this._yoyo) {
|
|
892
|
+
this._reversed = !this._reversed;
|
|
893
|
+
}
|
|
894
|
+
this._startTime += durationAndDelay * completeCount;
|
|
895
|
+
}
|
|
896
|
+
_updateProperties(_object, _valuesStart, _valuesEnd, value) {
|
|
897
|
+
for(const property in _valuesEnd){
|
|
879
898
|
// Don't update properties that do not exist in the source object
|
|
880
899
|
if (_valuesStart[property] === undefined) {
|
|
881
900
|
continue;
|
|
882
901
|
}
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
902
|
+
const start = _valuesStart[property] || 0;
|
|
903
|
+
let end = _valuesEnd[property];
|
|
904
|
+
const startIsArray = Array.isArray(_object[property]);
|
|
905
|
+
const endIsArray = Array.isArray(end);
|
|
906
|
+
const isInterpolationList = !startIsArray && endIsArray;
|
|
888
907
|
if (isInterpolationList) {
|
|
889
908
|
_object[property] = this._interpolationFunction(end, value);
|
|
890
909
|
} else if (typeof end === 'object' && end) {
|
|
@@ -906,29 +925,57 @@ var mainGroup = new Group();
|
|
|
906
925
|
}
|
|
907
926
|
}
|
|
908
927
|
}
|
|
909
|
-
}
|
|
910
|
-
|
|
928
|
+
}
|
|
929
|
+
_handleRelativeValue(start, end) {
|
|
911
930
|
if (typeof end !== 'string') {
|
|
912
931
|
return end;
|
|
913
932
|
}
|
|
914
933
|
if (end.charAt(0) === '+' || end.charAt(0) === '-') {
|
|
915
934
|
return start + parseFloat(end);
|
|
916
|
-
} else {
|
|
917
|
-
return parseFloat(end);
|
|
918
935
|
}
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
936
|
+
return parseFloat(end);
|
|
937
|
+
}
|
|
938
|
+
_swapEndStartRepeatValues(property) {
|
|
939
|
+
const tmp = this._valuesStartRepeat[property];
|
|
940
|
+
const endValue = this._valuesEnd[property];
|
|
923
941
|
if (typeof endValue === 'string') {
|
|
924
942
|
this._valuesStartRepeat[property] = this._valuesStartRepeat[property] + parseFloat(endValue);
|
|
925
943
|
} else {
|
|
926
944
|
this._valuesStartRepeat[property] = this._valuesEnd[property];
|
|
927
945
|
}
|
|
928
946
|
this._valuesEnd[property] = tmp;
|
|
929
|
-
}
|
|
930
|
-
|
|
931
|
-
|
|
947
|
+
}
|
|
948
|
+
constructor(_object, _group = mainGroup){
|
|
949
|
+
this._object = _object;
|
|
950
|
+
this._group = _group;
|
|
951
|
+
this._isPaused = false;
|
|
952
|
+
this._pauseStart = 0;
|
|
953
|
+
this._valuesStart = {};
|
|
954
|
+
this._valuesEnd = {};
|
|
955
|
+
this._valuesStartRepeat = {};
|
|
956
|
+
this._duration = 0;
|
|
957
|
+
this._isDynamic = false;
|
|
958
|
+
this._initialRepeat = 0;
|
|
959
|
+
this._repeat = 0;
|
|
960
|
+
this._yoyo = false;
|
|
961
|
+
this._isPlaying = false;
|
|
962
|
+
this._reversed = false;
|
|
963
|
+
this._delayTime = 0;
|
|
964
|
+
this._startTime = 0;
|
|
965
|
+
this._easingFunction = Easing.Linear.None;
|
|
966
|
+
this._interpolationFunction = Interpolation.Linear;
|
|
967
|
+
this._chainedTweens = [];
|
|
968
|
+
this._onStartCallbackFired = false;
|
|
969
|
+
this._onEveryStartCallbackFired = false;
|
|
970
|
+
this._id = Sequence.nextId();
|
|
971
|
+
this._isChainStopped = false;
|
|
972
|
+
this._propertiesAreSetUp = false;
|
|
973
|
+
this._headTween = null;
|
|
974
|
+
this._tailTween = null;
|
|
975
|
+
this._headTweenStartFired = false;
|
|
976
|
+
this._goToEnd = false;
|
|
977
|
+
}
|
|
978
|
+
}
|
|
932
979
|
|
|
933
980
|
class TweenChain {
|
|
934
981
|
start() {
|
|
@@ -944,7 +991,7 @@ class TweenChain {
|
|
|
944
991
|
return this;
|
|
945
992
|
}
|
|
946
993
|
union() {
|
|
947
|
-
this._chainedTween = this._tween = new Tween(this._object).union(this._tween, this._chainedTween);
|
|
994
|
+
this._chainedTween = this._tween = new Tween(this._object, this._group).union(this._tween, this._chainedTween);
|
|
948
995
|
return this;
|
|
949
996
|
}
|
|
950
997
|
call(callback) {
|
|
@@ -991,9 +1038,6 @@ class TweenManager {
|
|
|
991
1038
|
update(time) {
|
|
992
1039
|
this._group.update(time);
|
|
993
1040
|
}
|
|
994
|
-
tween(target) {
|
|
995
|
-
return new Tween(target, this._group);
|
|
996
|
-
}
|
|
997
1041
|
timeline(target) {
|
|
998
1042
|
return new TweenChain(target, this._group);
|
|
999
1043
|
}
|
|
@@ -1397,22 +1441,16 @@ class CinestationBrain extends Component {
|
|
|
1397
1441
|
}
|
|
1398
1442
|
_lerpToMainCamera(vcam, t) {
|
|
1399
1443
|
const from = this.node, to = vcam;
|
|
1400
|
-
const {
|
|
1401
|
-
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;
|
|
1444
|
+
const { lens, finalPosition, finalRotation } = to;
|
|
1445
|
+
const isLensChanged = from.fov != lens.fov || from.near != lens.near || from.far != lens.far;
|
|
1404
1446
|
from.position.lerp(finalPosition, t);
|
|
1405
1447
|
from.quaternion.slerp(finalRotation, t);
|
|
1406
|
-
from.fov = lerp$1(from.fov, fov, t);
|
|
1407
|
-
from.near =
|
|
1408
|
-
from.far =
|
|
1448
|
+
from.fov = lerp$1(from.fov, lens.fov, t);
|
|
1449
|
+
from.near = lens.near;
|
|
1450
|
+
from.far = lens.far;
|
|
1409
1451
|
if (isLensChanged) {
|
|
1410
1452
|
from.updateProjectionMatrix();
|
|
1411
1453
|
}
|
|
1412
|
-
if (this._isChanged !== isChanged) {
|
|
1413
|
-
this._isChanged = isChanged;
|
|
1414
|
-
this.onChanged && this.onChanged(isChanged);
|
|
1415
|
-
}
|
|
1416
1454
|
}
|
|
1417
1455
|
constructor(...args){
|
|
1418
1456
|
super(...args);
|
|
@@ -1420,15 +1458,35 @@ class CinestationBrain extends Component {
|
|
|
1420
1458
|
this._vcamSolo = null;
|
|
1421
1459
|
this._vcams = [];
|
|
1422
1460
|
this._lerpTime = 0;
|
|
1423
|
-
this._isChanged = false;
|
|
1424
1461
|
this.brainBlend = new CinestationBlendDefinition();
|
|
1425
|
-
this.onChanged = null;
|
|
1426
1462
|
}
|
|
1427
1463
|
}
|
|
1428
1464
|
__decorate([
|
|
1429
1465
|
property
|
|
1430
1466
|
], CinestationBrain.prototype, "brainBlend", void 0);
|
|
1431
1467
|
|
|
1468
|
+
class Lens {
|
|
1469
|
+
constructor(){
|
|
1470
|
+
this.fov = 45;
|
|
1471
|
+
this.near = 0.1;
|
|
1472
|
+
this.far = 1000;
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
__decorate([
|
|
1476
|
+
property({
|
|
1477
|
+
dir: "lens"
|
|
1478
|
+
})
|
|
1479
|
+
], Lens.prototype, "fov", void 0);
|
|
1480
|
+
__decorate([
|
|
1481
|
+
property({
|
|
1482
|
+
dir: "lens"
|
|
1483
|
+
})
|
|
1484
|
+
], Lens.prototype, "near", void 0);
|
|
1485
|
+
__decorate([
|
|
1486
|
+
property({
|
|
1487
|
+
dir: "lens"
|
|
1488
|
+
})
|
|
1489
|
+
], Lens.prototype, "far", void 0);
|
|
1432
1490
|
class VirtualCamera extends Component {
|
|
1433
1491
|
get finalPosition() {
|
|
1434
1492
|
return this._finalPosition.copy(this.node.position).add(this.correctPosition);
|
|
@@ -1439,9 +1497,9 @@ class VirtualCamera extends Component {
|
|
|
1439
1497
|
onLoad() {
|
|
1440
1498
|
this.node.isCamera = true;
|
|
1441
1499
|
const camera = this.viewer.camera;
|
|
1442
|
-
this.fov = camera.fov;
|
|
1443
|
-
this.near = camera.near;
|
|
1444
|
-
this.far = camera.far;
|
|
1500
|
+
this.lens.fov = camera.fov;
|
|
1501
|
+
this.lens.near = camera.near;
|
|
1502
|
+
this.lens.far = camera.far;
|
|
1445
1503
|
this.node.position.set(0, 0, 4);
|
|
1446
1504
|
this.brain = this.viewer.getComponent(camera, CinestationBrain, true);
|
|
1447
1505
|
this.brain.addCamera(this);
|
|
@@ -1449,42 +1507,19 @@ class VirtualCamera extends Component {
|
|
|
1449
1507
|
onDestroy() {
|
|
1450
1508
|
this.brain.removeCamera(this);
|
|
1451
1509
|
}
|
|
1452
|
-
update(dt) {
|
|
1453
|
-
if (this.lookAt) {
|
|
1454
|
-
this.node.lookAt(this.lookAt.position);
|
|
1455
|
-
}
|
|
1456
|
-
}
|
|
1457
1510
|
constructor(...args){
|
|
1458
1511
|
super(...args);
|
|
1459
1512
|
this._finalPosition = new Vector3();
|
|
1460
1513
|
this._finalRotation = new Quaternion();
|
|
1461
1514
|
this.priority = 10;
|
|
1462
|
-
this.
|
|
1463
|
-
this.follow = null;
|
|
1464
|
-
this.fov = 45;
|
|
1465
|
-
this.near = 0.1;
|
|
1466
|
-
this.far = 1000;
|
|
1515
|
+
this.lens = new Lens();
|
|
1467
1516
|
this.correctPosition = new Vector3();
|
|
1468
1517
|
this.correctRotation = new Quaternion();
|
|
1469
|
-
this.lookaheadPosition = new Vector3();
|
|
1470
|
-
this.lookAtOffset = new Vector3();
|
|
1471
1518
|
}
|
|
1472
1519
|
}
|
|
1473
1520
|
__decorate([
|
|
1474
|
-
property
|
|
1475
|
-
|
|
1476
|
-
})
|
|
1477
|
-
], VirtualCamera.prototype, "fov", void 0);
|
|
1478
|
-
__decorate([
|
|
1479
|
-
property({
|
|
1480
|
-
dir: "lens"
|
|
1481
|
-
})
|
|
1482
|
-
], VirtualCamera.prototype, "near", void 0);
|
|
1483
|
-
__decorate([
|
|
1484
|
-
property({
|
|
1485
|
-
dir: "lens"
|
|
1486
|
-
})
|
|
1487
|
-
], VirtualCamera.prototype, "far", void 0);
|
|
1521
|
+
property
|
|
1522
|
+
], VirtualCamera.prototype, "lens", void 0);
|
|
1488
1523
|
|
|
1489
1524
|
const PressState = {
|
|
1490
1525
|
NONE: 1 << 0,
|
|
@@ -2581,10 +2616,39 @@ Perlin._Permutation = [
|
|
|
2581
2616
|
];
|
|
2582
2617
|
|
|
2583
2618
|
const { clamp, degToRad } = MathUtils;
|
|
2584
|
-
const { abs, tan } = Math;
|
|
2619
|
+
const { abs, tan, PI } = Math;
|
|
2620
|
+
const PI2 = PI * 2;
|
|
2621
|
+
const ESP = 0.001;
|
|
2585
2622
|
class FreelookVirtualCamera extends VirtualCamera {
|
|
2586
|
-
|
|
2587
|
-
|
|
2623
|
+
get lookAt() {
|
|
2624
|
+
return this._lookAt;
|
|
2625
|
+
}
|
|
2626
|
+
set lookAt(v) {
|
|
2627
|
+
this._lookAt = this._targetLookAt = v;
|
|
2628
|
+
}
|
|
2629
|
+
get springLength() {
|
|
2630
|
+
return this._spherical.radius;
|
|
2631
|
+
}
|
|
2632
|
+
set springLength(v) {
|
|
2633
|
+
this._spherical.radius = this._targetSpringLength = v;
|
|
2634
|
+
}
|
|
2635
|
+
get theta() {
|
|
2636
|
+
return this._spherical.theta;
|
|
2637
|
+
}
|
|
2638
|
+
set theta(v) {
|
|
2639
|
+
this._spherical.theta = this._targetTheta = v;
|
|
2640
|
+
}
|
|
2641
|
+
get phi() {
|
|
2642
|
+
return this._spherical.phi;
|
|
2643
|
+
}
|
|
2644
|
+
set phi(v) {
|
|
2645
|
+
this._spherical.phi = this._targetPhi = v;
|
|
2646
|
+
}
|
|
2647
|
+
get fov() {
|
|
2648
|
+
return this.lens.fov;
|
|
2649
|
+
}
|
|
2650
|
+
set fov(v) {
|
|
2651
|
+
this.lens.fov = this._targetFov = v;
|
|
2588
2652
|
}
|
|
2589
2653
|
onEnable() {
|
|
2590
2654
|
this.viewer.on(DeviceInput.POINTER_DOWN, this._onPointerDown, this);
|
|
@@ -2606,9 +2670,13 @@ class FreelookVirtualCamera extends VirtualCamera {
|
|
|
2606
2670
|
reset() {
|
|
2607
2671
|
this._button = -1;
|
|
2608
2672
|
this._touchID = -1;
|
|
2609
|
-
this.
|
|
2610
|
-
|
|
2611
|
-
|
|
2673
|
+
this._setSpherical(this.node.position, this.lookAt);
|
|
2674
|
+
}
|
|
2675
|
+
_setSpherical(position, lookAt) {
|
|
2676
|
+
const { __posDelta } = FreelookVirtualCamera;
|
|
2677
|
+
__posDelta.copy(position).sub(lookAt);
|
|
2678
|
+
this._spherical.setFromVector3(__posDelta);
|
|
2679
|
+
this._targetSpherical.copy(this._spherical);
|
|
2612
2680
|
}
|
|
2613
2681
|
_onPointerDown(e) {
|
|
2614
2682
|
if (SystemInfo.isMobile) return;
|
|
@@ -2621,77 +2689,75 @@ class FreelookVirtualCamera extends VirtualCamera {
|
|
|
2621
2689
|
}
|
|
2622
2690
|
_onPointerMove(e) {
|
|
2623
2691
|
if (SystemInfo.isMobile) return;
|
|
2624
|
-
const { __loc0,
|
|
2692
|
+
const { __loc0, __panDelta, __rotateDelta } = FreelookVirtualCamera;
|
|
2625
2693
|
__loc0.set(e.pageX, e.pageY);
|
|
2626
2694
|
switch(this._button){
|
|
2627
2695
|
case 0:
|
|
2628
|
-
this.
|
|
2696
|
+
this._calculateRotatelDelta(__rotateDelta, this._preLoc0, __loc0);
|
|
2697
|
+
this._calculateTargetSpringArm(__rotateDelta);
|
|
2629
2698
|
break;
|
|
2630
2699
|
case 1:
|
|
2631
2700
|
case 2:
|
|
2632
|
-
this.
|
|
2701
|
+
this._calculatePanDelta(__panDelta, this._preLoc0, __loc0);
|
|
2702
|
+
this._calculateTargetLookAt(__panDelta);
|
|
2633
2703
|
break;
|
|
2634
2704
|
}
|
|
2635
2705
|
this._preLoc0.copy(__loc0);
|
|
2636
2706
|
}
|
|
2637
2707
|
_onMouseWheel(e) {
|
|
2638
|
-
const { __worldPos } = FreelookVirtualCamera;
|
|
2639
2708
|
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
2709
|
if (e.deltaY > 0) {
|
|
2643
|
-
|
|
2710
|
+
this._targetSpringLength *= this._calculateDistanceScale(1 / 0.85);
|
|
2644
2711
|
} else if (e.deltaY < 0) {
|
|
2645
|
-
|
|
2712
|
+
this._targetSpringLength *= this._calculateDistanceScale(0.85);
|
|
2646
2713
|
}
|
|
2647
|
-
this._distanceDelta = distNew - dist;
|
|
2648
2714
|
}
|
|
2649
2715
|
}
|
|
2650
2716
|
_onTouchStart(e) {
|
|
2651
2717
|
if (!SystemInfo.isMobile) return;
|
|
2652
2718
|
let touches = e.touches;
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
this.
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
this.
|
|
2659
|
-
this._preLoc0.set(touches[rotateTouchID].pageX, touches[rotateTouchID].pageY);
|
|
2719
|
+
if (touches.length > 1) {
|
|
2720
|
+
this._preLoc0.set(touches[0].pageX, touches[0].pageY);
|
|
2721
|
+
this._preLoc1.set(touches[1].pageX, touches[1].pageY);
|
|
2722
|
+
} else if (touches.length > 0) {
|
|
2723
|
+
this._touchID = touches[0].identifier;
|
|
2724
|
+
this._preLoc0.set(touches[0].pageX, touches[0].pageY);
|
|
2660
2725
|
}
|
|
2661
2726
|
}
|
|
2662
2727
|
_onTouchMove(e) {
|
|
2663
2728
|
if (!SystemInfo.isMobile) return;
|
|
2664
|
-
const { __loc0, __loc1,
|
|
2729
|
+
const { __loc0, __loc1, __panDelta, __rotateDelta, __preCenter, __center } = FreelookVirtualCamera;
|
|
2665
2730
|
let touches = e.touches;
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
__loc1.set(touches[rotateTouchID + 1].pageX, touches[rotateTouchID + 1].pageY);
|
|
2731
|
+
if (touches.length > 1) {
|
|
2732
|
+
__loc0.set(touches[0].pageX, touches[0].pageY);
|
|
2733
|
+
__loc1.set(touches[1].pageX, touches[1].pageY);
|
|
2670
2734
|
if (this.lookAt) {
|
|
2671
|
-
|
|
2672
|
-
let distNew = (dist + this._distanceDelta) * this._calculateDistanceScale(this._preLoc0.distanceTo(this._preLoc1) / __loc0.distanceTo(__loc1));
|
|
2673
|
-
this._distanceDelta = distNew - dist;
|
|
2735
|
+
this._targetSpringLength *= this._calculateDistanceScale(this._preLoc0.distanceTo(this._preLoc1) / __loc0.distanceTo(__loc1));
|
|
2674
2736
|
}
|
|
2675
2737
|
__preCenter.copy(this._preLoc0).add(this._preLoc1).multiplyScalar(0.5);
|
|
2676
2738
|
__center.copy(__loc0).add(__loc1).multiplyScalar(0.5);
|
|
2677
|
-
this.
|
|
2739
|
+
this._calculatePanDelta(__panDelta, __preCenter, __center);
|
|
2740
|
+
this._calculateTargetLookAt(__panDelta);
|
|
2678
2741
|
this._preLoc0.copy(__loc0);
|
|
2679
2742
|
this._preLoc1.copy(__loc1);
|
|
2680
|
-
} else if (touches.length >
|
|
2681
|
-
if (this._touchID === touches[
|
|
2682
|
-
__loc0.set(touches[
|
|
2683
|
-
this.
|
|
2743
|
+
} else if (touches.length > 0) {
|
|
2744
|
+
if (this._touchID === touches[0].identifier) {
|
|
2745
|
+
__loc0.set(touches[0].pageX, touches[0].pageY);
|
|
2746
|
+
this._calculateRotatelDelta(__rotateDelta, this._preLoc0, __loc0);
|
|
2747
|
+
this._calculateTargetSpringArm(__rotateDelta);
|
|
2684
2748
|
this._preLoc0.copy(__loc0);
|
|
2685
2749
|
}
|
|
2686
2750
|
}
|
|
2687
2751
|
}
|
|
2688
2752
|
_calculateDistanceScale(scale) {
|
|
2753
|
+
this._tempSmoothing = this.smoothing;
|
|
2689
2754
|
if (this.forbidZ) {
|
|
2690
2755
|
scale = 1;
|
|
2691
2756
|
}
|
|
2692
2757
|
return scale;
|
|
2693
2758
|
}
|
|
2694
|
-
|
|
2759
|
+
_calculateRotatelDelta(out, loc0, loc1) {
|
|
2760
|
+
this._tempSmoothing = this.smoothing;
|
|
2695
2761
|
const domElement = this.viewer.canvas;
|
|
2696
2762
|
out.copy(loc1).sub(loc0).multiplyScalar(this.rotateSpeed * 2 * Math.PI / domElement.height);
|
|
2697
2763
|
out.y = -out.y;
|
|
@@ -2701,10 +2767,10 @@ class FreelookVirtualCamera extends VirtualCamera {
|
|
|
2701
2767
|
if (this.forbidY) {
|
|
2702
2768
|
out.y = 0;
|
|
2703
2769
|
}
|
|
2704
|
-
this._tempSmoothing = this.smoothing;
|
|
2705
2770
|
return out;
|
|
2706
2771
|
}
|
|
2707
2772
|
_calculatePanDelta(out, loc0, loc1) {
|
|
2773
|
+
this._tempSmoothing = this.smoothing;
|
|
2708
2774
|
const domElement = this.viewer.canvas;
|
|
2709
2775
|
out.copy(loc1).sub(loc0).multiplyScalar(this.panSpeed / domElement.height);
|
|
2710
2776
|
if (this.forbidPanX) {
|
|
@@ -2713,116 +2779,97 @@ class FreelookVirtualCamera extends VirtualCamera {
|
|
|
2713
2779
|
if (this.forbidPanY) {
|
|
2714
2780
|
out.y = 0;
|
|
2715
2781
|
}
|
|
2716
|
-
this._tempSmoothing = this.smoothing;
|
|
2717
2782
|
return out;
|
|
2718
2783
|
}
|
|
2719
|
-
|
|
2720
|
-
const {
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
__posDelta.copy(this.node.position).sub(
|
|
2728
|
-
__posDelta.
|
|
2729
|
-
|
|
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;
|
|
2736
|
-
this._tempSmoothing = smoothing;
|
|
2737
|
-
this._lookAtOffsetDelta.copy(lookAt).sub(this.lookAt.position).sub(this.lookAtOffset);
|
|
2784
|
+
_calculateTargetLookAt(panDelta) {
|
|
2785
|
+
const { __xAxis, __yAxis, __posDelta } = FreelookVirtualCamera;
|
|
2786
|
+
__xAxis.setFromMatrixColumn(this.node.matrix, 0);
|
|
2787
|
+
__yAxis.setFromMatrixColumn(this.node.matrix, 1);
|
|
2788
|
+
if (this.forbitPanOffsetY) {
|
|
2789
|
+
__yAxis.y = 0;
|
|
2790
|
+
__yAxis.normalize();
|
|
2791
|
+
}
|
|
2792
|
+
__posDelta.copy(this.node.position).sub(this.lookAt);
|
|
2793
|
+
const length = __posDelta.length() * 2 * tan(degToRad(this.fov * 0.5));
|
|
2794
|
+
this._targetLookAt.sub(__xAxis.multiplyScalar(panDelta.x * length)).add(__yAxis.multiplyScalar(panDelta.y * length));
|
|
2738
2795
|
}
|
|
2739
|
-
|
|
2740
|
-
if (
|
|
2741
|
-
|
|
2742
|
-
|
|
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));
|
|
2796
|
+
_calculateTargetSpringArm(rotateDelta, radius) {
|
|
2797
|
+
if (rotateDelta) {
|
|
2798
|
+
this._targetTheta -= rotateDelta.x;
|
|
2799
|
+
this._targetPhi += rotateDelta.y;
|
|
2776
2800
|
}
|
|
2777
|
-
if (
|
|
2778
|
-
this.
|
|
2779
|
-
this._lookAtOffsetDelta.multiplyScalar(dampFactor);
|
|
2801
|
+
if (radius) {
|
|
2802
|
+
this._targetSpringLength = radius;
|
|
2780
2803
|
}
|
|
2781
|
-
this.
|
|
2804
|
+
this._targetTheta = clamp(this._targetTheta, this.thetaMin, this.thetaMax);
|
|
2805
|
+
this._targetPhi = clamp(this._targetPhi, this.phiMin, this.phiMax);
|
|
2806
|
+
this._targetSpringLength = clamp(this._targetSpringLength, this.distanceMin, this.distanceMax);
|
|
2807
|
+
}
|
|
2808
|
+
gotoPOI({ springLength = this._targetSpringLength, theta = this._targetTheta, phi = this._targetPhi, lookAt = this.lookAt, fov = this.lens.fov, smoothing = this.smoothing }) {
|
|
2809
|
+
this._targetFov = fov;
|
|
2810
|
+
this._tempSmoothing = smoothing;
|
|
2811
|
+
this._targetSpringLength = springLength;
|
|
2812
|
+
this._targetPhi = phi;
|
|
2813
|
+
this._targetTheta = theta;
|
|
2814
|
+
this._calculateTargetSpringArm();
|
|
2815
|
+
const theta0 = MathUtils.euclideanModulo(this._spherical.theta, PI2);
|
|
2816
|
+
const theta1 = theta0 - PI2;
|
|
2817
|
+
this._spherical.theta = abs(theta0 - this._targetTheta) < abs(theta1 - this._targetTheta) ? theta0 : theta1;
|
|
2818
|
+
this._targetLookAt.copy(lookAt);
|
|
2819
|
+
}
|
|
2820
|
+
update(dt) {
|
|
2821
|
+
const smoothing = this._tempSmoothing;
|
|
2822
|
+
this._spherical.theta = FInterpTo(this._spherical.theta, this._targetTheta, dt, smoothing);
|
|
2823
|
+
this._spherical.phi = FInterpTo(this._spherical.phi, this._targetPhi, dt, smoothing);
|
|
2824
|
+
this._spherical.radius = FInterpTo(this._spherical.radius, this._targetSpringLength, dt, smoothing);
|
|
2825
|
+
this.lens.fov = FInterpTo(this.lens.fov, this._targetFov, dt, smoothing);
|
|
2826
|
+
VInterpTo(this._lookAt, this._targetLookAt, dt, smoothing);
|
|
2827
|
+
this.node.position.setFromSpherical(this._spherical).add(this.lookAt);
|
|
2828
|
+
this.node.lookAt(this._lookAt);
|
|
2782
2829
|
}
|
|
2783
2830
|
constructor(...args){
|
|
2784
2831
|
super(...args);
|
|
2785
2832
|
this._button = -1;
|
|
2786
2833
|
this._touchID = -1;
|
|
2787
|
-
this._distanceDelta = 0;
|
|
2788
2834
|
this._preLoc0 = new Vector2();
|
|
2789
2835
|
this._preLoc1 = new Vector2();
|
|
2790
|
-
this.
|
|
2791
|
-
this.
|
|
2836
|
+
this._spherical = new Spherical();
|
|
2837
|
+
this._lookAt = new Vector3();
|
|
2792
2838
|
this._tempSmoothing = 0;
|
|
2793
|
-
this.
|
|
2839
|
+
this._targetTheta = 0;
|
|
2840
|
+
this._targetPhi = 0;
|
|
2841
|
+
this._targetSpringLength = 1;
|
|
2842
|
+
this._targetFov = this.fov;
|
|
2843
|
+
this._targetLookAt = new Vector3();
|
|
2844
|
+
this._targetSpherical = new Spherical();
|
|
2794
2845
|
this.forbidX = false;
|
|
2795
2846
|
this.forbidY = false;
|
|
2796
2847
|
this.forbidZ = false;
|
|
2797
2848
|
this.forbidPanX = false;
|
|
2798
2849
|
this.forbidPanY = false;
|
|
2799
2850
|
this.forbitPanOffsetY = false;
|
|
2800
|
-
this.
|
|
2801
|
-
this.rotateSpeed =
|
|
2802
|
-
this.
|
|
2803
|
-
this.
|
|
2804
|
-
this.
|
|
2805
|
-
this.phiMax = Math.PI - 0.001;
|
|
2851
|
+
this.panSpeed = 1;
|
|
2852
|
+
this.rotateSpeed = 1;
|
|
2853
|
+
this.smoothing = 5;
|
|
2854
|
+
this.phiMin = ESP;
|
|
2855
|
+
this.phiMax = Math.PI - ESP;
|
|
2806
2856
|
this.thetaMin = -Infinity;
|
|
2807
2857
|
this.thetaMax = Infinity;
|
|
2808
|
-
this.distanceMin =
|
|
2858
|
+
this.distanceMin = ESP;
|
|
2809
2859
|
this.distanceMax = Infinity;
|
|
2810
|
-
this.rotateTouchID = 0;
|
|
2811
|
-
this.lookAt = new Object3D();
|
|
2812
2860
|
}
|
|
2813
2861
|
}
|
|
2814
2862
|
FreelookVirtualCamera.__loc0 = new Vector2();
|
|
2815
2863
|
FreelookVirtualCamera.__loc1 = new Vector2();
|
|
2816
2864
|
FreelookVirtualCamera.__center = new Vector2();
|
|
2817
2865
|
FreelookVirtualCamera.__preCenter = new Vector2();
|
|
2818
|
-
FreelookVirtualCamera.
|
|
2819
|
-
FreelookVirtualCamera.
|
|
2866
|
+
FreelookVirtualCamera.__panDelta = new Vector2();
|
|
2867
|
+
FreelookVirtualCamera.__panTarget = new Vector2();
|
|
2868
|
+
FreelookVirtualCamera.__rotateDelta = new Vector2();
|
|
2820
2869
|
FreelookVirtualCamera.__posDelta = new Vector3();
|
|
2821
2870
|
FreelookVirtualCamera.__xAxis = new Vector3();
|
|
2822
2871
|
FreelookVirtualCamera.__yAxis = new Vector3();
|
|
2823
2872
|
FreelookVirtualCamera.__quat = new Quaternion();
|
|
2824
|
-
FreelookVirtualCamera.__spherical = new Spherical();
|
|
2825
|
-
FreelookVirtualCamera.__offsetDelta = new Vector3();
|
|
2826
2873
|
__decorate([
|
|
2827
2874
|
property({
|
|
2828
2875
|
dir: "set"
|
|
@@ -2853,9 +2900,83 @@ __decorate([
|
|
|
2853
2900
|
dir: "set"
|
|
2854
2901
|
})
|
|
2855
2902
|
], FreelookVirtualCamera.prototype, "forbitPanOffsetY", void 0);
|
|
2903
|
+
__decorate([
|
|
2904
|
+
property({
|
|
2905
|
+
dir: "set",
|
|
2906
|
+
step: 0.01
|
|
2907
|
+
})
|
|
2908
|
+
], FreelookVirtualCamera.prototype, "panSpeed", void 0);
|
|
2909
|
+
__decorate([
|
|
2910
|
+
property({
|
|
2911
|
+
dir: "set",
|
|
2912
|
+
step: 0.01
|
|
2913
|
+
})
|
|
2914
|
+
], FreelookVirtualCamera.prototype, "rotateSpeed", void 0);
|
|
2915
|
+
__decorate([
|
|
2916
|
+
property({
|
|
2917
|
+
dir: "set",
|
|
2918
|
+
step: 0.01
|
|
2919
|
+
})
|
|
2920
|
+
], FreelookVirtualCamera.prototype, "smoothing", void 0);
|
|
2921
|
+
__decorate([
|
|
2922
|
+
property({
|
|
2923
|
+
dir: "set",
|
|
2924
|
+
step: 0.01
|
|
2925
|
+
})
|
|
2926
|
+
], FreelookVirtualCamera.prototype, "phiMin", void 0);
|
|
2927
|
+
__decorate([
|
|
2928
|
+
property({
|
|
2929
|
+
dir: "set",
|
|
2930
|
+
step: 0.01
|
|
2931
|
+
})
|
|
2932
|
+
], FreelookVirtualCamera.prototype, "phiMax", void 0);
|
|
2933
|
+
__decorate([
|
|
2934
|
+
property({
|
|
2935
|
+
dir: "set",
|
|
2936
|
+
step: 0.01
|
|
2937
|
+
})
|
|
2938
|
+
], FreelookVirtualCamera.prototype, "thetaMin", void 0);
|
|
2939
|
+
__decorate([
|
|
2940
|
+
property({
|
|
2941
|
+
dir: "set",
|
|
2942
|
+
step: 0.01
|
|
2943
|
+
})
|
|
2944
|
+
], FreelookVirtualCamera.prototype, "thetaMax", void 0);
|
|
2945
|
+
__decorate([
|
|
2946
|
+
property({
|
|
2947
|
+
dir: "set",
|
|
2948
|
+
step: 0.01
|
|
2949
|
+
})
|
|
2950
|
+
], FreelookVirtualCamera.prototype, "distanceMin", void 0);
|
|
2951
|
+
__decorate([
|
|
2952
|
+
property({
|
|
2953
|
+
dir: "set",
|
|
2954
|
+
step: 0.01
|
|
2955
|
+
})
|
|
2956
|
+
], FreelookVirtualCamera.prototype, "distanceMax", void 0);
|
|
2957
|
+
__decorate([
|
|
2958
|
+
property({
|
|
2959
|
+
step: 0.01
|
|
2960
|
+
})
|
|
2961
|
+
], FreelookVirtualCamera.prototype, "lookAt", null);
|
|
2962
|
+
__decorate([
|
|
2963
|
+
property({
|
|
2964
|
+
step: 0.01
|
|
2965
|
+
})
|
|
2966
|
+
], FreelookVirtualCamera.prototype, "springLength", null);
|
|
2967
|
+
__decorate([
|
|
2968
|
+
property({
|
|
2969
|
+
step: 0.01
|
|
2970
|
+
})
|
|
2971
|
+
], FreelookVirtualCamera.prototype, "theta", null);
|
|
2972
|
+
__decorate([
|
|
2973
|
+
property({
|
|
2974
|
+
step: 0.01
|
|
2975
|
+
})
|
|
2976
|
+
], FreelookVirtualCamera.prototype, "phi", null);
|
|
2856
2977
|
__decorate([
|
|
2857
2978
|
property
|
|
2858
|
-
], FreelookVirtualCamera.prototype, "
|
|
2979
|
+
], FreelookVirtualCamera.prototype, "fov", null);
|
|
2859
2980
|
|
|
2860
2981
|
class Box extends Mesh {
|
|
2861
2982
|
constructor(...args){
|
|
@@ -4569,9 +4690,6 @@ class Viewer extends EventEmitter {
|
|
|
4569
4690
|
this.addNode(node, props);
|
|
4570
4691
|
return node;
|
|
4571
4692
|
}
|
|
4572
|
-
tween(target) {
|
|
4573
|
-
return this._tweenManager.tween(target);
|
|
4574
|
-
}
|
|
4575
4693
|
timeline(target) {
|
|
4576
4694
|
return this._tweenManager.timeline(target);
|
|
4577
4695
|
}
|