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