@woosh/meep-engine 2.33.59 → 2.33.60
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/core/bvh2/aabb3/AABB3.js +4 -1
- package/core/bvh2/traversal/traverseBinaryNodeUsingVisitor.js +6 -6
- package/core/cache/Cache.js +7 -0
- package/core/collection/array/fastArrayEquals.js +17 -0
- package/core/collection/array/typed/is_typed_array_equals.js +58 -0
- package/core/collection/map/AbstractAsyncMap.js +30 -0
- package/core/collection/map/AsyncMapWrapper.js +16 -0
- package/core/collection/map/AsyncRemoteHashMap.js +358 -0
- package/core/collection/map/CachedAsyncMap.js +34 -0
- package/core/geom/Vector4.js +5 -5
- package/engine/animation/removeEntityGenericEffect.js +22 -31
- package/engine/asset/Asset.js +0 -45
- package/engine/asset/AssetDescription.js +51 -0
- package/engine/asset/AssetManager.d.ts +7 -0
- package/engine/asset/AssetManager.js +98 -2
- package/engine/asset/AssetTransformer.d.ts +5 -0
- package/engine/asset/AssetTransformer.js +15 -0
- package/engine/asset/loaders/GLTFAssetLoader.js +27 -25
- package/engine/asset/loaders/material/computeImageBitmapEquality.js +2 -2
- package/engine/asset/loaders/material/computeTextureEquality.js +2 -2
- package/engine/ecs/gui/hud/HeadsUpDisplaySystem.js +60 -45
- package/engine/ecs/storage/binary/BinaryClassUpgrader.js +1 -0
- package/engine/ecs/util/removeComponentsExcept.js +3 -3
- package/engine/graphics/GraphicsEngine.js +3 -3
- package/engine/graphics/ecs/mesh/Mesh.js +5 -5
- package/engine/graphics/ecs/mesh/MeshSystem.js +12 -20
- package/engine/graphics/ecs/trail2d/Trail2D.js +35 -1
- package/engine/graphics/ecs/trail2d/Trail2DSystem.js +26 -19
- package/engine/graphics/ecs/trail2d/makeGradientTrail.js +68 -0
- package/engine/graphics/micron/convert_three_object_to_micron.js +24 -7
- package/engine/graphics/micron/plugin/MicronRenderPlugin.js +107 -4
- package/engine/graphics/micron/plugin/serialization/BufferGeometrySerializationAdapter.js +176 -0
- package/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +1 -2
- package/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_texture.js +3 -1
- package/engine/graphics/shadows/ShadowMapRenderer.js +10 -4
- package/engine/graphics/texture/sampler/Sampler2D.js +24 -45
- package/engine/intelligence/behavior/ecs/WaitForEventBehavior.js +3 -0
- package/engine/save/storage/IndexedDBStorage.js +8 -1
- package/package.json +1 -1
package/engine/asset/Asset.js
CHANGED
|
@@ -4,51 +4,6 @@
|
|
|
4
4
|
* @param {string} type
|
|
5
5
|
* @constructor
|
|
6
6
|
*/
|
|
7
|
-
import { assert } from "../../core/assert.js";
|
|
8
|
-
import { computeStringHash } from "../../core/primitives/strings/computeStringHash.js";
|
|
9
|
-
import { computeHashIntegerArray } from "../../core/collection/array/computeHashIntegerArray.js";
|
|
10
|
-
|
|
11
|
-
export class AssetDescription {
|
|
12
|
-
/**
|
|
13
|
-
*
|
|
14
|
-
* @param {string} path
|
|
15
|
-
* @param {string} type
|
|
16
|
-
* @constructor
|
|
17
|
-
*/
|
|
18
|
-
constructor(path, type) {
|
|
19
|
-
assert.typeOf(path, 'string', 'path');
|
|
20
|
-
assert.typeOf(type, 'string', 'type');
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* @type {string}
|
|
24
|
-
*/
|
|
25
|
-
this.path = path;
|
|
26
|
-
/**
|
|
27
|
-
* @type {string}
|
|
28
|
-
*/
|
|
29
|
-
this.type = type;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
*
|
|
34
|
-
* @param {AssetDescription} other
|
|
35
|
-
* @returns {boolean}
|
|
36
|
-
*/
|
|
37
|
-
equals(other) {
|
|
38
|
-
return this.path === other.path && this.type === other.type;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
*
|
|
43
|
-
* @returns {number}
|
|
44
|
-
*/
|
|
45
|
-
hash() {
|
|
46
|
-
return computeHashIntegerArray(
|
|
47
|
-
computeStringHash(this.path),
|
|
48
|
-
computeStringHash(this.type)
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
7
|
|
|
53
8
|
|
|
54
9
|
export class Asset {
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { assert } from "../../core/assert.js";
|
|
2
|
+
import { computeHashIntegerArray } from "../../core/collection/array/computeHashIntegerArray.js";
|
|
3
|
+
import { computeStringHash } from "../../core/primitives/strings/computeStringHash.js";
|
|
4
|
+
|
|
5
|
+
export class AssetDescription {
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @param {string} path
|
|
9
|
+
* @param {string} type
|
|
10
|
+
* @constructor
|
|
11
|
+
*/
|
|
12
|
+
constructor(path, type) {
|
|
13
|
+
assert.isString(path, 'path');
|
|
14
|
+
assert.isString(type, 'type');
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @type {string}
|
|
18
|
+
*/
|
|
19
|
+
this.path = path;
|
|
20
|
+
/**
|
|
21
|
+
* @type {string}
|
|
22
|
+
*/
|
|
23
|
+
this.type = type;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
*
|
|
28
|
+
* @param {AssetDescription} other
|
|
29
|
+
* @returns {boolean}
|
|
30
|
+
*/
|
|
31
|
+
equals(other) {
|
|
32
|
+
return this.path === other.path
|
|
33
|
+
&& this.type === other.type
|
|
34
|
+
;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
*
|
|
39
|
+
* @returns {number}
|
|
40
|
+
*/
|
|
41
|
+
hash() {
|
|
42
|
+
return computeHashIntegerArray(
|
|
43
|
+
computeStringHash(this.path),
|
|
44
|
+
computeStringHash(this.type)
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
toString() {
|
|
49
|
+
return `{ type: '${this.type}', path: '${this.path}' }`;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {AssetLoader} from "./loaders/AssetLoader";
|
|
2
2
|
import {Asset} from "./Asset";
|
|
3
3
|
import {CrossOriginConfig} from "./CORS/CrossOriginConfig";
|
|
4
|
+
import {AssetTransformer} from "./AssetTransformer";
|
|
4
5
|
|
|
5
6
|
export class AssetManager {
|
|
6
7
|
public readonly crossOriginConfig: CrossOriginConfig
|
|
@@ -12,4 +13,10 @@ export class AssetManager {
|
|
|
12
13
|
public clear(): void
|
|
13
14
|
|
|
14
15
|
public registerLoader<T>(type: string, loader: AssetLoader<T>): Promise<void>
|
|
16
|
+
|
|
17
|
+
public unregisterLoader(type: string): Promise<void>
|
|
18
|
+
|
|
19
|
+
public registerTransformer<T extends Asset<X>, X = any>(type: string, transformer: AssetTransformer<T>): void
|
|
20
|
+
|
|
21
|
+
public unregisterTransformer<T extends Asset<X>, X = any>(type: string, transformer: AssetTransformer<T>): boolean
|
|
15
22
|
}
|
|
@@ -5,12 +5,13 @@
|
|
|
5
5
|
|
|
6
6
|
import BoundedValue from "../../core/model/BoundedValue.js";
|
|
7
7
|
import { ObservedMap } from "../../core/collection/ObservedMap.js";
|
|
8
|
-
import { AssetDescription } from "./Asset.js";
|
|
9
8
|
import { HashMap } from "../../core/collection/HashMap.js";
|
|
10
9
|
import { extractAssetListFromManager } from "./preloader/extractAssetListFromManager.js";
|
|
11
10
|
import { assert } from "../../core/assert.js";
|
|
12
11
|
import { HashSet } from "../../core/collection/HashSet.js";
|
|
13
12
|
import { CrossOriginConfig } from "./CORS/CrossOriginConfig.js";
|
|
13
|
+
import { array_remove_element } from "../../core/collection/array/array_remove_element.js";
|
|
14
|
+
import { AssetDescription } from "./AssetDescription.js";
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
*
|
|
@@ -62,6 +63,13 @@ function AssetManager(engine) {
|
|
|
62
63
|
*/
|
|
63
64
|
this.loaders = {};
|
|
64
65
|
|
|
66
|
+
/**
|
|
67
|
+
* After asset is loaded, a chain of transforms can be applied to it, these are registered here
|
|
68
|
+
* Transformers are executed in the order in which they are added
|
|
69
|
+
* @type {Object<AssetTransformer[]>}
|
|
70
|
+
*/
|
|
71
|
+
this.transformers = {};
|
|
72
|
+
|
|
65
73
|
/**
|
|
66
74
|
* Named links to specific assets. Useful to later re-mapping assets and having meaningful names for them
|
|
67
75
|
* @type {Map<string, AssetDescription>}
|
|
@@ -209,7 +217,30 @@ AssetManager.prototype.submitRequest = function (path, type, request) {
|
|
|
209
217
|
const assets = this.assets;
|
|
210
218
|
const failures = this.failures;
|
|
211
219
|
|
|
212
|
-
|
|
220
|
+
/**
|
|
221
|
+
*
|
|
222
|
+
* @param {Asset} loaded_asset
|
|
223
|
+
*/
|
|
224
|
+
const success = async (loaded_asset) => {
|
|
225
|
+
let asset = loaded_asset;
|
|
226
|
+
|
|
227
|
+
// apply transform chain
|
|
228
|
+
const transformers = this.transformers[type];
|
|
229
|
+
if (transformers !== undefined) {
|
|
230
|
+
const transformer_count = transformers.length;
|
|
231
|
+
for (let i = 0; i < transformer_count; i++) {
|
|
232
|
+
const transformer = transformers[i];
|
|
233
|
+
|
|
234
|
+
const transformed_asset = await transformer.transform(asset);
|
|
235
|
+
|
|
236
|
+
if (typeof transformed_asset !== "object") {
|
|
237
|
+
console.error('Transformer produced invalid result. Ignoring result.', transformer, assetDescription);
|
|
238
|
+
} else {
|
|
239
|
+
asset = transformed_asset;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
213
244
|
//link asset description
|
|
214
245
|
asset.description = assetDescription;
|
|
215
246
|
|
|
@@ -298,6 +329,71 @@ AssetManager.prototype.getLoaderByType = function (type) {
|
|
|
298
329
|
return this.loaders[type];
|
|
299
330
|
};
|
|
300
331
|
|
|
332
|
+
/**
|
|
333
|
+
*
|
|
334
|
+
* @param {string} type
|
|
335
|
+
* @return {AssetDescription[]}
|
|
336
|
+
* @private
|
|
337
|
+
*/
|
|
338
|
+
AssetManager.prototype.__getLoadedAssetDescriptorsByType = function (type) {
|
|
339
|
+
const loaded_assets = Array.from(this.assets.keys());
|
|
340
|
+
return loaded_assets.filter(t => t.type === type);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* @template T
|
|
345
|
+
* @param {string} type
|
|
346
|
+
* @param {AssetTransformer<T>} transformer
|
|
347
|
+
*/
|
|
348
|
+
AssetManager.prototype.registerTransformer = function (type, transformer) {
|
|
349
|
+
let transformers = this.transformers[type];
|
|
350
|
+
|
|
351
|
+
if (transformers === undefined) {
|
|
352
|
+
transformers = [];
|
|
353
|
+
|
|
354
|
+
this.transformers[type] = transformers;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
transformers.push(transformer);
|
|
358
|
+
|
|
359
|
+
// check for loaded assets
|
|
360
|
+
const matching_assets = this.__getLoadedAssetDescriptorsByType(type);
|
|
361
|
+
|
|
362
|
+
if (matching_assets.length > 0) {
|
|
363
|
+
console.warn(`Following assets of matching type '${type}' are already loaded and transform is not applied to them:\n\t${matching_assets.join('\n\t')}`);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* @template T
|
|
370
|
+
* @param {string} type
|
|
371
|
+
* @param {AssetTransformer<T>} transformer
|
|
372
|
+
*/
|
|
373
|
+
AssetManager.prototype.unregisterTransformer = function (type, transformer) {
|
|
374
|
+
|
|
375
|
+
const transformers = this.transformers[type];
|
|
376
|
+
|
|
377
|
+
if (transformers === undefined) {
|
|
378
|
+
// not found
|
|
379
|
+
return false;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
if (!array_remove_element(transformers, 0, transformers.length, transformer)) {
|
|
383
|
+
// not found
|
|
384
|
+
return false;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
// check for loaded assets
|
|
388
|
+
const matching_assets = this.__getLoadedAssetDescriptorsByType(type);
|
|
389
|
+
|
|
390
|
+
if (matching_assets.length > 0) {
|
|
391
|
+
console.warn(`Following assets of matching type '${type}' are already loaded and transform was probably already applied to them:\n\t${matching_assets.join('\n\t')}`);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
return true;
|
|
395
|
+
}
|
|
396
|
+
|
|
301
397
|
/**
|
|
302
398
|
* @template T
|
|
303
399
|
* @param {string} type
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Applies a transformation to an asset. Such as performing mesh simplification for example.
|
|
3
|
+
* Transformation is executed by the {@link AssetManager}
|
|
4
|
+
* @template {Asset<T>} A
|
|
5
|
+
* @template T
|
|
6
|
+
*/
|
|
7
|
+
export class AssetTransformer {
|
|
8
|
+
/**
|
|
9
|
+
* @param {A} source
|
|
10
|
+
* @returns {A}
|
|
11
|
+
*/
|
|
12
|
+
async transform(source) {
|
|
13
|
+
throw new Error('Not Implemented');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -19,7 +19,6 @@ import { CrossOriginKind } from "../CORS/CrossOriginKind.js";
|
|
|
19
19
|
import { computeObjectBoundingSphere } from "./gltf/computeObjectBoundingSphere.js";
|
|
20
20
|
import { isMesh } from "./gltf/isMesh.js";
|
|
21
21
|
import { DRACOLoader } from "three/examples/jsm/loaders/DRACOLoader.js";
|
|
22
|
-
import { convert_three_object_to_micron } from "../../graphics/micron/convert_three_object_to_micron.js";
|
|
23
22
|
import { HashSet } from "../../../core/collection/HashSet.js";
|
|
24
23
|
import { computeGeometryHash } from "./geometry/geometry/computeGeometryHash.js";
|
|
25
24
|
import { computeGeometryEquality } from "./geometry/geometry/computeGeometryEquality.js";
|
|
@@ -173,11 +172,20 @@ export class GLTFAssetLoader extends AssetLoader {
|
|
|
173
172
|
this.loader = loader;
|
|
174
173
|
|
|
175
174
|
/**
|
|
176
|
-
*
|
|
175
|
+
* Asset optimization flag
|
|
176
|
+
* Whether or not geometry de-duping should be done
|
|
177
177
|
* @type {boolean}
|
|
178
178
|
* @private
|
|
179
179
|
*/
|
|
180
|
-
this.
|
|
180
|
+
this.__enable_geometry_cache = false;
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Asset optimization flag
|
|
184
|
+
* Whether or not texture de-duping should be done
|
|
185
|
+
* @type {boolean}
|
|
186
|
+
* @private
|
|
187
|
+
*/
|
|
188
|
+
this.__enable_texture_cache = false;
|
|
181
189
|
|
|
182
190
|
/**
|
|
183
191
|
*
|
|
@@ -216,7 +224,7 @@ export class GLTFAssetLoader extends AssetLoader {
|
|
|
216
224
|
* @param {boolean} v
|
|
217
225
|
*/
|
|
218
226
|
set is_micron_enabled(v) {
|
|
219
|
-
|
|
227
|
+
console.warn('Deprecated. Handled by the MicronRenderPlugin. Remove usage, no further action required');
|
|
220
228
|
}
|
|
221
229
|
|
|
222
230
|
/**
|
|
@@ -224,7 +232,7 @@ export class GLTFAssetLoader extends AssetLoader {
|
|
|
224
232
|
* @returns {boolean}
|
|
225
233
|
*/
|
|
226
234
|
get is_micron_enabled() {
|
|
227
|
-
|
|
235
|
+
throw new Error('Deprecated. Handled by the MicronRenderPlugin. Remove usage, no further action required. To check for presence of micron, check plugins instead.');
|
|
228
236
|
}
|
|
229
237
|
|
|
230
238
|
async link(assetManager, engine) {
|
|
@@ -275,14 +283,15 @@ export class GLTFAssetLoader extends AssetLoader {
|
|
|
275
283
|
alphaTest: object.material.alphaTest
|
|
276
284
|
});
|
|
277
285
|
|
|
278
|
-
|
|
286
|
+
if (this.__enable_texture_cache) {
|
|
287
|
+
object.customDepthMaterial = materialCache.acquire(depthMaterial);
|
|
288
|
+
}
|
|
279
289
|
}
|
|
280
290
|
}
|
|
281
291
|
|
|
282
292
|
|
|
283
293
|
load(path, success, failure, progress) {
|
|
284
294
|
const loader = this.loader;
|
|
285
|
-
const geometry_cache = this.__geometry_cache;
|
|
286
295
|
const texture_cache = this.__texture_cache;
|
|
287
296
|
|
|
288
297
|
|
|
@@ -290,19 +299,24 @@ export class GLTFAssetLoader extends AssetLoader {
|
|
|
290
299
|
*
|
|
291
300
|
* @param {THREE.Mesh|THREE.SkinnedMesh} mesh
|
|
292
301
|
*/
|
|
293
|
-
async
|
|
302
|
+
const processMesh = async (mesh) => {
|
|
294
303
|
let geometry = mesh.geometry;
|
|
295
304
|
|
|
296
305
|
if (geometry === undefined) {
|
|
297
306
|
throw new Error(`No geometry found`);
|
|
298
307
|
}
|
|
299
308
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
309
|
+
if (this.__enable_geometry_cache) {
|
|
310
|
+
// replace geometry
|
|
311
|
+
geometry = this.__geometry_cache.ensure(geometry);
|
|
312
|
+
mesh.geometry = geometry;
|
|
313
|
+
}
|
|
314
|
+
|
|
303
315
|
|
|
304
|
-
|
|
305
|
-
|
|
316
|
+
if (this.__enable_texture_cache) {
|
|
317
|
+
// replace textures from cache
|
|
318
|
+
replace_material_textures_from_cache(mesh.material, texture_cache);
|
|
319
|
+
}
|
|
306
320
|
|
|
307
321
|
const isSkinned = mesh.isSkinnedMesh === true;
|
|
308
322
|
|
|
@@ -431,18 +445,6 @@ export class GLTFAssetLoader extends AssetLoader {
|
|
|
431
445
|
asset.animations = animations;
|
|
432
446
|
}
|
|
433
447
|
|
|
434
|
-
// build micron mesh
|
|
435
|
-
if (
|
|
436
|
-
this.__enable_micron
|
|
437
|
-
&& (asset.animations === undefined || asset.animations.length === 0)
|
|
438
|
-
) {
|
|
439
|
-
// TODO deal with animations
|
|
440
|
-
const micron_root = await convert_three_object_to_micron(root.clone());
|
|
441
|
-
micron_root.boundingSphere = root.boundingSphere;
|
|
442
|
-
|
|
443
|
-
asset.micron = micron_root;
|
|
444
|
-
}
|
|
445
|
-
|
|
446
448
|
success(asset);
|
|
447
449
|
}, function (xhr) {
|
|
448
450
|
//dispatch progress callback
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Sampler2D } from "../../../graphics/texture/sampler/Sampler2D.js";
|
|
2
2
|
import { assert } from "../../../../core/assert.js";
|
|
3
|
-
import { isArrayEqualStrict } from "../../../../core/collection/array/isArrayEqualStrict.js";
|
|
4
3
|
import { bitmap2sampler_gl } from "./bitmap2sampler_gl.js";
|
|
4
|
+
import { fastArrayEquals } from "../../../../core/collection/array/fastArrayEquals.js";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
*
|
|
@@ -114,5 +114,5 @@ export function computeImageBitmapEquality(a, b) {
|
|
|
114
114
|
|
|
115
115
|
const b_s = obtainSampler(b, ctx);
|
|
116
116
|
|
|
117
|
-
return
|
|
117
|
+
return fastArrayEquals(a_s.data, b_s.data);
|
|
118
118
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { computeImageBitmapEquality } from "./computeImageBitmapEquality.js";
|
|
2
|
-
import {
|
|
2
|
+
import { fastArrayEquals } from "../../../../core/collection/array/fastArrayEquals.js";
|
|
3
3
|
|
|
4
4
|
//
|
|
5
5
|
|
|
@@ -184,5 +184,5 @@ function textureMipmapEqual(a, b) {
|
|
|
184
184
|
return true;
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
-
return
|
|
187
|
+
return fastArrayEquals(aData, bData);
|
|
188
188
|
}
|
|
@@ -6,23 +6,15 @@
|
|
|
6
6
|
import { System } from '../../System.js';
|
|
7
7
|
import HeadsUpDisplay from './HeadsUpDisplay.js';
|
|
8
8
|
import { Transform } from '../../transform/Transform.js';
|
|
9
|
-
|
|
10
|
-
import { Matrix4 } from 'three';
|
|
11
9
|
import { GraphicsEngine } from "../../../graphics/GraphicsEngine.js";
|
|
12
10
|
import { FogOfWarVisibilityPredicate } from "../../fow/FogOfWarVisibilityPredicate.js";
|
|
13
|
-
import Vector4 from "../../../../core/geom/Vector4.js";
|
|
14
11
|
import ViewportPosition from "../position/ViewportPosition.js";
|
|
15
12
|
import GUIElement from "../GUIElement.js";
|
|
16
13
|
import { HeadsUpDisplayFlag } from "./HeadsUpDisplayFlag.js";
|
|
14
|
+
import { mat4 } from "gl-matrix";
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
*
|
|
20
|
-
* @type {Vector4}
|
|
21
|
-
*/
|
|
22
|
-
const v4 = new Vector4();
|
|
23
|
-
const projectionMatrix = new Matrix4();
|
|
16
|
+
const projection = new Float32Array(16);
|
|
24
17
|
|
|
25
|
-
const up = new Vector4();
|
|
26
18
|
|
|
27
19
|
/**
|
|
28
20
|
*
|
|
@@ -77,7 +69,7 @@ class HeadsUpDisplaySystem extends System {
|
|
|
77
69
|
}
|
|
78
70
|
|
|
79
71
|
/**
|
|
80
|
-
*
|
|
72
|
+
* NOTE: for the sake of speed all of the matrix and vector multiplications have been inlined, readability of this method is pretty bad
|
|
81
73
|
* @param {HeadsUpDisplay} hud
|
|
82
74
|
* @param {Transform} transform
|
|
83
75
|
* @param {ViewportPosition} vp
|
|
@@ -87,48 +79,69 @@ class HeadsUpDisplaySystem extends System {
|
|
|
87
79
|
__apply_entity_transformation(hud, transform, vp, element) {
|
|
88
80
|
const worldOffset = hud.worldOffset;
|
|
89
81
|
|
|
90
|
-
let
|
|
91
|
-
let
|
|
92
|
-
let
|
|
93
|
-
|
|
94
|
-
v4.set(
|
|
95
|
-
worldOffsetX,
|
|
96
|
-
worldOffsetY,
|
|
97
|
-
worldOffsetZ,
|
|
98
|
-
1
|
|
99
|
-
);
|
|
82
|
+
let x = worldOffset.x;
|
|
83
|
+
let y = worldOffset.y;
|
|
84
|
+
let z = worldOffset.z;
|
|
100
85
|
|
|
101
86
|
if (hud.getFlag(HeadsUpDisplayFlag.TransformWorldOffset)) {
|
|
102
87
|
//apply scale and rotation
|
|
88
|
+
const transform_scale = transform.scale;
|
|
89
|
+
|
|
90
|
+
x *= transform_scale.x;
|
|
91
|
+
y *= transform_scale.y;
|
|
92
|
+
z *= transform_scale.y;
|
|
103
93
|
|
|
104
|
-
|
|
94
|
+
const q = transform.rotation;
|
|
95
|
+
|
|
96
|
+
const qx = q.x;
|
|
97
|
+
const qy = q.y;
|
|
98
|
+
const qz = q.z;
|
|
99
|
+
const qw = q.w;
|
|
100
|
+
|
|
101
|
+
// calculate quat * vec
|
|
102
|
+
const ix = qw * x + qy * z - qz * y;
|
|
103
|
+
const iy = qw * y + qz * x - qx * z;
|
|
104
|
+
const iz = qw * z + qx * y - qy * x;
|
|
105
|
+
const iw = -qx * x - qy * y - qz * z;
|
|
106
|
+
|
|
107
|
+
// calculate result * inverse quat
|
|
108
|
+
x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
|
|
109
|
+
y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
|
|
110
|
+
z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
|
|
105
111
|
|
|
106
|
-
v4.applyQuaternion(transform.rotation);
|
|
107
112
|
}
|
|
108
113
|
|
|
114
|
+
// add transform position to get final world position
|
|
109
115
|
const position = transform.position;
|
|
110
116
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const worldPositionY = v4.y;
|
|
115
|
-
const worldPositionZ = v4.z;
|
|
117
|
+
x += position.x;
|
|
118
|
+
y += position.y;
|
|
119
|
+
z += position.z;
|
|
116
120
|
|
|
121
|
+
const worldPositionX = x;
|
|
122
|
+
const worldPositionY = y;
|
|
123
|
+
const worldPositionZ = z;
|
|
117
124
|
|
|
118
125
|
// Convert the [-1, 1] screen coordinate into a world coordinate on the near plane
|
|
119
|
-
v4.threeApplyMatrix4(projectionMatrix);
|
|
120
126
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
127
|
+
// apply projection matrix
|
|
128
|
+
const _x = projection[0] * x + projection[4] * y + projection[8] * z + projection[12];
|
|
129
|
+
const _y = projection[1] * x + projection[5] * y + projection[9] * z + projection[13];
|
|
130
|
+
const _z = projection[2] * x + projection[6] * y + projection[10] * z + projection[14];
|
|
131
|
+
const _w = projection[3] * x + projection[7] * y + projection[11] * z + projection[15];
|
|
132
|
+
|
|
133
|
+
// apply perspective transform
|
|
134
|
+
const d = 1 / Math.abs(_w);
|
|
135
|
+
x = _x * d;
|
|
136
|
+
y = _y * d;
|
|
137
|
+
z = _z * d;
|
|
125
138
|
|
|
126
|
-
const ndcX = (
|
|
127
|
-
const ndcY = (1 -
|
|
139
|
+
const ndcX = (x + 1) / 2;
|
|
140
|
+
const ndcY = (1 - y) / 2;
|
|
128
141
|
|
|
129
142
|
vp.position.set(ndcX, ndcY);
|
|
130
143
|
|
|
131
|
-
const trackedPositionOutOfBounds =
|
|
144
|
+
const trackedPositionOutOfBounds = z > 1 || z < -1;
|
|
132
145
|
|
|
133
146
|
const visible = (!trackedPositionOutOfBounds || vp.stickToScreenEdge) && this.__visibility_predicate.test(worldPositionX, worldPositionY, worldPositionZ);
|
|
134
147
|
|
|
@@ -141,18 +154,20 @@ class HeadsUpDisplaySystem extends System {
|
|
|
141
154
|
if (hud.getFlag(HeadsUpDisplayFlag.PerspectiveRotation)) {
|
|
142
155
|
//compute rotation in screen-space
|
|
143
156
|
|
|
144
|
-
|
|
145
|
-
|
|
157
|
+
const w_y_1 = worldPositionY + 1;
|
|
158
|
+
|
|
159
|
+
const _up_x = projection[0] * worldPositionX + projection[4] * w_y_1 + projection[8] * worldPositionZ + projection[12];
|
|
160
|
+
const _up_y = projection[1] * worldPositionX + projection[5] * w_y_1 + projection[9] * worldPositionZ + projection[13];
|
|
161
|
+
const _up_w = projection[3] * worldPositionX + projection[7] * w_y_1 + projection[11] * worldPositionZ + projection[15];
|
|
146
162
|
|
|
147
163
|
// compute perspective divide
|
|
148
|
-
const d = 1 / Math.abs(
|
|
164
|
+
const d = 1 / Math.abs(_up_w);
|
|
149
165
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
up.z *= d;
|
|
166
|
+
const up_x = _up_x * d;
|
|
167
|
+
const up_y = _up_y * d;
|
|
153
168
|
|
|
154
|
-
const up_ndcX = (
|
|
155
|
-
const up_ndcY = (1 -
|
|
169
|
+
const up_ndcX = (up_x + 1) / 2;
|
|
170
|
+
const up_ndcY = (1 - up_y) / 2;
|
|
156
171
|
|
|
157
172
|
const angle = Math.atan2(up_ndcY - ndcY, up_ndcX - ndcX);
|
|
158
173
|
|
|
@@ -176,7 +191,7 @@ class HeadsUpDisplaySystem extends System {
|
|
|
176
191
|
*/
|
|
177
192
|
const camera = this.graphics.camera;
|
|
178
193
|
|
|
179
|
-
|
|
194
|
+
mat4.multiply(projection, camera.projectionMatrix.elements, camera.matrixWorldInverse.elements);
|
|
180
195
|
|
|
181
196
|
const visibilityPredicate = this.__visibility_predicate;
|
|
182
197
|
|
|
@@ -10,7 +10,7 @@ export function removeComponentsExcept(ecd, entity, whitelist) {
|
|
|
10
10
|
const components = ecd.getAllComponents(entity);
|
|
11
11
|
const component_count = components.length;
|
|
12
12
|
|
|
13
|
-
for (let i = 0; i < component_count; i++) {
|
|
13
|
+
l0:for (let i = 0; i < component_count; i++) {
|
|
14
14
|
const component = components[i];
|
|
15
15
|
|
|
16
16
|
if (component === undefined) {
|
|
@@ -21,7 +21,7 @@ export function removeComponentsExcept(ecd, entity, whitelist) {
|
|
|
21
21
|
for (let i = 0; i < exception_count; i++) {
|
|
22
22
|
if (component instanceof whitelist[i]) {
|
|
23
23
|
//keep
|
|
24
|
-
continue;
|
|
24
|
+
continue l0;
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
|
|
@@ -29,4 +29,4 @@ export function removeComponentsExcept(ecd, entity, whitelist) {
|
|
|
29
29
|
ecd.removeComponentFromEntityByIndex(entity, i);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
}
|
|
32
|
+
}
|
|
@@ -35,7 +35,6 @@ import { MetricsCategory } from "../metrics/MetricsCategory.js";
|
|
|
35
35
|
import Vector1 from "../../core/geom/Vector1.js";
|
|
36
36
|
import { NormalFrameBuffer } from "./render/buffer/buffers/NormalFrameBuffer.js";
|
|
37
37
|
import { MaterialManager } from "./material/manager/MaterialManager.js";
|
|
38
|
-
import { CoalesceTextures } from "./material/manager/compilers/CoalesceTextures.js";
|
|
39
38
|
import { ShadowMapRenderer } from "./shadows/ShadowMapRenderer.js";
|
|
40
39
|
import { CameraViewManager } from "./render/view/CameraViewManager.js";
|
|
41
40
|
import { StandardFrameBuffers } from "./StandardFrameBuffers.js";
|
|
@@ -91,14 +90,15 @@ function GraphicsEngine(camera, entityManger) {
|
|
|
91
90
|
*/
|
|
92
91
|
this.__material_manager = new MaterialManager();
|
|
93
92
|
|
|
94
|
-
|
|
93
|
+
// The line below would de-dupe textures, it is a rather slow process however
|
|
94
|
+
// this.__material_manager.addCompileStep(new CoalesceTextures());
|
|
95
95
|
|
|
96
96
|
this.on = {
|
|
97
97
|
preRender: new Signal(),
|
|
98
98
|
postRender: new Signal(),
|
|
99
99
|
|
|
100
100
|
preOpaquePass: new Signal(),
|
|
101
|
-
postOpaquePass
|
|
101
|
+
postOpaquePass: new Signal(),
|
|
102
102
|
|
|
103
103
|
/**
|
|
104
104
|
* @deprecated
|
|
@@ -52,10 +52,10 @@ class Mesh {
|
|
|
52
52
|
this.mesh = null;
|
|
53
53
|
|
|
54
54
|
/**
|
|
55
|
-
* Mesh
|
|
55
|
+
* Override Mesh data, if available. Typically set via plugins
|
|
56
56
|
* @type {Object3D|null}
|
|
57
57
|
*/
|
|
58
|
-
this.
|
|
58
|
+
this.override_mesh = null;
|
|
59
59
|
|
|
60
60
|
/**
|
|
61
61
|
* @transient
|
|
@@ -128,9 +128,9 @@ class Mesh {
|
|
|
128
128
|
//set bvh
|
|
129
129
|
updateNodeByTransformAndBBB(this.bvh, this.boundingBox, _t);
|
|
130
130
|
|
|
131
|
-
//
|
|
132
|
-
if (this.
|
|
133
|
-
applyTransformToThreeObject(this.
|
|
131
|
+
// override
|
|
132
|
+
if (this.override_mesh !== null) {
|
|
133
|
+
applyTransformToThreeObject(this.override_mesh, _t);
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
|