@woosh/meep-engine 2.62.0 → 2.63.0
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/build/meep.cjs +1043 -1047
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +1043 -1047
- package/package.json +1 -1
- package/src/core/binary/EncodingBinaryBuffer.js +7 -43
- package/src/core/binary/EncodingBinaryBuffer.spec.js +16 -0
- package/src/core/bvh2/bvh3/EBBVHLeafProxy.js +4 -2
- package/src/core/cache/LoadingCache.js +4 -1
- package/src/core/collection/map/BiMap.js +49 -0
- package/src/engine/ecs/components/Tag.d.ts +2 -0
- package/src/engine/ecs/components/Tag.js +19 -28
- package/src/engine/ecs/components/Tag.spec.js +47 -0
- package/src/engine/ecs/fow/FogOfWar.js +4 -0
- package/src/engine/ecs/fow/FogOfWarEditor.js +3 -0
- package/src/engine/ecs/terrain/TerrainPreview.js +45 -44
- package/src/engine/ecs/terrain/ecs/cling/ClingToTerrain.js +22 -4
- package/src/engine/ecs/terrain/tiles/TerrainTile.js +17 -12
- package/src/engine/graphics/ecs/mesh/Mesh.d.ts +0 -4
- package/src/engine/graphics/ecs/mesh/Mesh.js +0 -11
- package/src/engine/graphics/ecs/mesh/MeshSystem.js +57 -67
- package/src/engine/grid/ORTHOGONAL_NEIGHBOURHOOD_MASK.js +11 -0
- package/src/core/binary/stringToByteArray.js +0 -24
- package/src/engine/save/storage/LocalStorage.js +0 -148
- package/src/engine/save/storage/MsgPackCodec.js +0 -22
|
@@ -4,9 +4,19 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
import { BoxBufferGeometry, MeshLambertMaterial } from "three";
|
|
7
|
+
import { assert } from "../../../../core/assert.js";
|
|
8
|
+
import {
|
|
9
|
+
ExplicitBinaryBoundingVolumeHierarchy
|
|
10
|
+
} from "../../../../core/bvh2/bvh3/ExplicitBinaryBoundingVolumeHierarchy.js";
|
|
11
|
+
import {
|
|
12
|
+
bvh_query_user_data_overlaps_frustum
|
|
13
|
+
} from "../../../../core/bvh2/bvh3/query/bvh_query_user_data_overlaps_frustum.js";
|
|
7
14
|
import { SignalBinding } from "../../../../core/events/signal/SignalBinding.js";
|
|
8
15
|
|
|
9
16
|
import Vector3 from "../../../../core/geom/Vector3.js";
|
|
17
|
+
import { ResourceAccessKind } from "../../../../core/model/ResourceAccessKind.js";
|
|
18
|
+
import { ResourceAccessSpecification } from "../../../../core/model/ResourceAccessSpecification.js";
|
|
19
|
+
import { GLTFAssetLoader } from "../../../asset/loaders/GLTFAssetLoader.js";
|
|
10
20
|
import { System } from "../../../ecs/System.js";
|
|
11
21
|
import { Transform } from "../../../ecs/transform/Transform.js";
|
|
12
22
|
|
|
@@ -15,26 +25,16 @@ import checkerTexture from "../../texture/CheckersTexture.js";
|
|
|
15
25
|
import ThreeFactory from "../../three/ThreeFactory.js";
|
|
16
26
|
import { assetTypeByPath } from "./assetTypeByPath.js";
|
|
17
27
|
import Mesh, { MeshFlags } from "./Mesh.js";
|
|
18
|
-
import { applyComponentPropertiesToThreeObject, setMesh } from "./setMesh.js";
|
|
19
|
-
import { GLTFAssetLoader } from "../../../asset/loaders/GLTFAssetLoader.js";
|
|
20
28
|
import { MeshEvents } from "./MeshEvents.js";
|
|
21
|
-
import {
|
|
22
|
-
import { ResourceAccessSpecification } from "../../../../core/model/ResourceAccessSpecification.js";
|
|
23
|
-
import { ResourceAccessKind } from "../../../../core/model/ResourceAccessKind.js";
|
|
24
|
-
import {
|
|
25
|
-
ExplicitBinaryBoundingVolumeHierarchy
|
|
26
|
-
} from "../../../../core/bvh2/bvh3/ExplicitBinaryBoundingVolumeHierarchy.js";
|
|
27
|
-
import {
|
|
28
|
-
bvh_query_user_data_overlaps_frustum
|
|
29
|
-
} from "../../../../core/bvh2/bvh3/query/bvh_query_user_data_overlaps_frustum.js";
|
|
29
|
+
import { setMesh } from "./setMesh.js";
|
|
30
30
|
|
|
31
|
-
const
|
|
31
|
+
const PLACEHOLDER_GEOMETRY = new BoxBufferGeometry(1, 1, 1);
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
PLACEHOLDER_GEOMETRY.computeBoundingSphere();
|
|
34
34
|
|
|
35
|
-
const
|
|
35
|
+
const PLACEHOLDER_TEXTURE = checkerTexture.create();
|
|
36
36
|
|
|
37
|
-
const
|
|
37
|
+
const PLACEHOLDER_MATERIAL = new MeshLambertMaterial({ map: PLACEHOLDER_TEXTURE });
|
|
38
38
|
|
|
39
39
|
const scratch_array = [];
|
|
40
40
|
|
|
@@ -134,13 +134,6 @@ export class MeshSystem extends System {
|
|
|
134
134
|
|
|
135
135
|
component.setFlag(MeshFlags.Loaded);
|
|
136
136
|
|
|
137
|
-
// override
|
|
138
|
-
if (asset.override_mesh !== undefined) {
|
|
139
|
-
component.override_mesh = asset.override_mesh.clone();
|
|
140
|
-
|
|
141
|
-
applyComponentPropertiesToThreeObject(component, component.override_mesh, entity);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
137
|
setMesh(dataset, entity, component, mesh);
|
|
145
138
|
|
|
146
139
|
|
|
@@ -318,8 +311,6 @@ export class MeshSystem extends System {
|
|
|
318
311
|
bScale
|
|
319
312
|
];
|
|
320
313
|
|
|
321
|
-
apply_transform();
|
|
322
|
-
|
|
323
314
|
model.__bvh_leaf.link(this.__bvh_binary, entity);
|
|
324
315
|
}
|
|
325
316
|
|
|
@@ -375,38 +366,6 @@ export class MeshSystem extends System {
|
|
|
375
366
|
|
|
376
367
|
const dataset = em.dataset;
|
|
377
368
|
|
|
378
|
-
/**
|
|
379
|
-
*
|
|
380
|
-
* @param {Asset<Object3D>} asset
|
|
381
|
-
*/
|
|
382
|
-
const assetLoaded = (asset) => {
|
|
383
|
-
if (!dataset.entityExists(entity)) {
|
|
384
|
-
//entity no longer exists, probably dataset has been switched, abort
|
|
385
|
-
return;
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
//check that component is still actual
|
|
389
|
-
const actualComponent = dataset.getComponent(entity, Mesh);
|
|
390
|
-
|
|
391
|
-
if (actualComponent === component) {
|
|
392
|
-
// scene.remove(component.mesh);
|
|
393
|
-
this.__set_mesh_from_asset(entity, dataset, asset, component);
|
|
394
|
-
|
|
395
|
-
} else {
|
|
396
|
-
//component is no longer in the manager. do nothing.
|
|
397
|
-
//console.warn("component is no longer in the manager");
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
function assetFailure(error) {
|
|
403
|
-
console.error("failed to load model " + component.url, error);
|
|
404
|
-
|
|
405
|
-
dataset.sendEvent(entity, MeshEvents.AssetLoadFailed, {
|
|
406
|
-
reason: error
|
|
407
|
-
});
|
|
408
|
-
}
|
|
409
|
-
|
|
410
369
|
if (component.hasMesh()) {
|
|
411
370
|
//do not re-run if mesh is set
|
|
412
371
|
setMesh(dataset, entity, component, component.mesh);
|
|
@@ -425,28 +384,59 @@ export class MeshSystem extends System {
|
|
|
425
384
|
if (asset !== null) {
|
|
426
385
|
// asset is already loaded, use it
|
|
427
386
|
this.__set_mesh_from_asset(entity, dataset, asset, component);
|
|
428
|
-
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// mesh was not found, use temp mesh and submit a request
|
|
391
|
+
|
|
392
|
+
if (this.__use_placeholder_mesh) {
|
|
393
|
+
// set placeholder mesh
|
|
394
|
+
const mesh = ThreeFactory.createMesh(PLACEHOLDER_GEOMETRY, PLACEHOLDER_MATERIAL);
|
|
395
|
+
|
|
396
|
+
setMesh(dataset, entity, component, mesh);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
function assetFailure(error) {
|
|
400
|
+
console.error("failed to load model " + component.url, error);
|
|
401
|
+
|
|
402
|
+
dataset.sendEvent(entity, MeshEvents.AssetLoadFailed, {
|
|
403
|
+
reason: error
|
|
404
|
+
});
|
|
405
|
+
}
|
|
429
406
|
|
|
430
|
-
|
|
407
|
+
if (assetType === null) {
|
|
408
|
+
// couldn't figure out what the asset type is
|
|
409
|
+
assetFailure("no asset type deduced");
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
431
412
|
|
|
432
|
-
if (this.__use_placeholder_mesh) {
|
|
433
|
-
// set placeholder mesh
|
|
434
|
-
const mesh = ThreeFactory.createMesh(placeholderGeometry, placeholderMaterial);
|
|
435
413
|
|
|
436
|
-
|
|
414
|
+
/**
|
|
415
|
+
*
|
|
416
|
+
* @param {Asset<Object3D>} asset
|
|
417
|
+
*/
|
|
418
|
+
const assetLoaded = (asset) => {
|
|
419
|
+
if (!dataset.entityExists(entity)) {
|
|
420
|
+
//entity no longer exists, probably dataset has been switched, abort
|
|
421
|
+
return;
|
|
437
422
|
}
|
|
438
423
|
|
|
439
|
-
|
|
424
|
+
//check that component is still actual
|
|
425
|
+
const actualComponent = dataset.getComponent(entity, Mesh);
|
|
440
426
|
|
|
441
|
-
|
|
427
|
+
if (actualComponent === component) {
|
|
428
|
+
// scene.remove(component.mesh);
|
|
429
|
+
this.__set_mesh_from_asset(entity, dataset, asset, component);
|
|
442
430
|
|
|
443
431
|
} else {
|
|
444
|
-
//
|
|
445
|
-
|
|
432
|
+
//component is no longer in the manager. do nothing.
|
|
433
|
+
//console.warn("component is no longer in the manager");
|
|
446
434
|
}
|
|
447
435
|
}
|
|
448
436
|
|
|
449
|
-
|
|
437
|
+
// load the asset
|
|
438
|
+
am.get({ path: component.url, type: assetType, callback: assetLoaded, failure: assetFailure });
|
|
439
|
+
|
|
450
440
|
}
|
|
451
441
|
|
|
452
442
|
update(timeDelta) {
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Turns a string into an array of bytes; a "byte" being a JS number in the
|
|
3
|
-
* range 0-255.
|
|
4
|
-
* @param {string} str String value to arrify.
|
|
5
|
-
* @return {Uint8Array} Array of numbers corresponding to the
|
|
6
|
-
* UCS character codes of each character in str.
|
|
7
|
-
*/
|
|
8
|
-
export function stringToByteArray(str) {
|
|
9
|
-
const length = str.length;
|
|
10
|
-
|
|
11
|
-
const output = [];
|
|
12
|
-
let p = 0;
|
|
13
|
-
|
|
14
|
-
for (let i = 0; i < length; i++) {
|
|
15
|
-
let c = str.charCodeAt(i);
|
|
16
|
-
while (c > 0xff) {
|
|
17
|
-
output[p++] = c & 0xff;
|
|
18
|
-
c >>= 8;
|
|
19
|
-
}
|
|
20
|
-
output[p++] = c;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return new Uint8Array(output);
|
|
24
|
-
}
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Alex on 22/02/2017.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import MsgPackCodec from './MsgPackCodec.js';
|
|
7
|
-
|
|
8
|
-
import Storage from '../Storage.js';
|
|
9
|
-
import { InMemoryLocalStorage } from "./InMemoryLocalStorage.js";
|
|
10
|
-
import {stringToByteArray} from "../../../core/binary/stringToByteArray.js";
|
|
11
|
-
import {byteArrayToString} from "../../../core/binary/byteArrayToString.js";
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
class LocalStorage extends Storage {
|
|
15
|
-
constructor(namespace, services) {
|
|
16
|
-
super();
|
|
17
|
-
this.namespace = namespace;
|
|
18
|
-
this.services = services;
|
|
19
|
-
|
|
20
|
-
this.compressionLevel = 2;
|
|
21
|
-
this.compressionEnabled = false;
|
|
22
|
-
|
|
23
|
-
this.codec = new MsgPackCodec();
|
|
24
|
-
|
|
25
|
-
try {
|
|
26
|
-
console.log('Accessing Window.localStorage...');
|
|
27
|
-
this.localStorage = window.localStorage;
|
|
28
|
-
console.log('LocalStorage acquired');
|
|
29
|
-
} catch (e) {
|
|
30
|
-
console.error(`Failed to get localStorage:`, e);
|
|
31
|
-
|
|
32
|
-
// This fallback allows the system to continue functioning at least
|
|
33
|
-
this.localStorage = new InMemoryLocalStorage();
|
|
34
|
-
|
|
35
|
-
console.warn(`Falling back to in-memory storage`);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const item = this.localStorage.getItem(this.namespace + "-list");
|
|
39
|
-
let stored;
|
|
40
|
-
|
|
41
|
-
try {
|
|
42
|
-
stored = JSON.parse(item);
|
|
43
|
-
} catch (e) {
|
|
44
|
-
console.error('Failed to parse loaded item:', e, item);
|
|
45
|
-
console.warn('Ignoring previously stored data');
|
|
46
|
-
stored = null;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (stored !== null && typeof stored === "object" && typeof stored.length === "number") {
|
|
50
|
-
this.__list = stored;
|
|
51
|
-
} else {
|
|
52
|
-
this.__list = [];
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
makeObjectId(key) {
|
|
57
|
-
return this.namespace + '-item-' + key;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
storeBinary(key, value, resolve, reject, progress) {
|
|
61
|
-
const self = this;
|
|
62
|
-
|
|
63
|
-
function store(data) {
|
|
64
|
-
const compressedUint8Array = new Uint8Array(data.length);
|
|
65
|
-
compressedUint8Array.set(data, 0);
|
|
66
|
-
|
|
67
|
-
if (compressedUint8Array.length !== value.length) {
|
|
68
|
-
console.log("Compressed size:", compressedUint8Array.length, "bytes, original ", value.length, ".", (compressedUint8Array.length / value.length * 100).toFixed(2) + "% of the original");
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const compressedString = byteArrayToString(compressedUint8Array);
|
|
72
|
-
|
|
73
|
-
self.localStorage.setItem(self.makeObjectId(key), compressedString);
|
|
74
|
-
|
|
75
|
-
if (self.__list.indexOf(key) === -1) {
|
|
76
|
-
//update the list
|
|
77
|
-
self.__list.push(key);
|
|
78
|
-
self.localStorage.setItem(self.namespace + "-list", JSON.stringify(self.__list));
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (typeof resolve === "function") {
|
|
82
|
-
resolve();
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (this.compressionEnabled) {
|
|
87
|
-
const compressionService = this.services.compression;
|
|
88
|
-
|
|
89
|
-
compressionService
|
|
90
|
-
.encode(value, this.compressionLevel)
|
|
91
|
-
.then(store, reject);
|
|
92
|
-
} else {
|
|
93
|
-
store(value);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
store(key, value, resolve, reject, progress) {
|
|
98
|
-
const rawData = this.codec.encode(value);
|
|
99
|
-
|
|
100
|
-
this.storeBinary(key, rawData, resolve, reject, progress);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
loadBinary(key, resolve, reject, progress) {
|
|
104
|
-
|
|
105
|
-
let compressedString = this.localStorage.getItem(this.makeObjectId(key));
|
|
106
|
-
|
|
107
|
-
if (compressedString === null) {
|
|
108
|
-
//no data
|
|
109
|
-
resolve(new ArrayBuffer(0));
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const uint8array = stringToByteArray(compressedString);
|
|
114
|
-
|
|
115
|
-
const data = uint8array.buffer;
|
|
116
|
-
// console.log("compressedBytes", compressedBytes);
|
|
117
|
-
|
|
118
|
-
if (this.compressionEnabled) {
|
|
119
|
-
const compressionService = this.services.compression;
|
|
120
|
-
|
|
121
|
-
compressionService.decode(data).then(resolve, reject);
|
|
122
|
-
} else {
|
|
123
|
-
resolve(data);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
load(key, resolve, reject, progress) {
|
|
128
|
-
const codec = this.codec;
|
|
129
|
-
|
|
130
|
-
this.loadBinary(key, function (binary) {
|
|
131
|
-
let result;
|
|
132
|
-
|
|
133
|
-
try {
|
|
134
|
-
result = codec.decode(new Uint8Array(binary));
|
|
135
|
-
} catch (e) {
|
|
136
|
-
reject(e);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
resolve(result);
|
|
140
|
-
}, reject, progress);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
list(resolve, reject) {
|
|
144
|
-
resolve(this.__list);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export default LocalStorage;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Alex on 12/06/2017.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import msgpack from 'msgpack-lite';
|
|
6
|
-
|
|
7
|
-
function MsgPackCodec() {
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
MsgPackCodec.prototype.encode = function (json) {
|
|
12
|
-
console.time("encoding of value");
|
|
13
|
-
const result = msgpack.encode(json);
|
|
14
|
-
console.timeEnd("encoding of value");
|
|
15
|
-
return result;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
MsgPackCodec.prototype.decode = function (bytes) {
|
|
19
|
-
return msgpack.decode(bytes);
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export default MsgPackCodec;
|