@woosh/meep-engine 2.57.0 → 2.58.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.
Files changed (102) hide show
  1. package/editor/Editor.js +4 -4
  2. package/editor/process/symbolic/buildThreeJSHelperEntity.js +3 -3
  3. package/editor/process/symbolic/makeGridPositionSymbolDisplay.js +3 -3
  4. package/editor/process/symbolic/makePositionedIconDisplaySymbol.js +3 -3
  5. package/editor/tools/v2/prototypeTransformControls.js +3 -3
  6. package/editor/view/ecs/ComponentControlView.js +2 -1
  7. package/package.json +1 -1
  8. package/samples/generation/main.js +2 -2
  9. package/samples/terrain/from_image.js +2 -2
  10. package/samples/terrain/from_image_2.js +4 -4
  11. package/src/core/binary/byteArrayToString.js +28 -0
  12. package/src/core/binary/downloadAsFile.js +28 -0
  13. package/src/core/binary/downloadUrlAsFile.js +14 -0
  14. package/src/core/binary/jsonToStringToByteArray.js +27 -0
  15. package/src/core/binary/stringToByteArray.js +24 -0
  16. package/src/core/bvh2/BinaryNode.spec.js +2 -1
  17. package/src/core/color/Color.spec.js +27 -1
  18. package/src/core/color/parse_color.js +1 -1
  19. package/src/core/fsm/simple/SimpleStateMachine.spec.js +34 -2
  20. package/src/core/geom/3d/matrix/m4_multiply.js +2 -2
  21. package/src/core/geom/3d/matrix/m4_multiply.spec.js +11 -0
  22. package/src/core/geom/3d/matrix/m4_multiply_alphatensor.spec.js +11 -0
  23. package/src/core/geom/3d/morton/split_by_2.js +1 -1
  24. package/src/core/geom/3d/shape/util/shape_to_visual_entity.js +10 -10
  25. package/src/core/geom/3d/tetrahedra/prototypeTetrahedraBuilder.js +2 -2
  26. package/src/core/geom/3d/topology/samples/sampleFloodFill.js +3 -3
  27. package/src/core/process/action/AsynchronousDelayAction.js +2 -2
  28. package/src/core/process/executor/profile/ConcurrentExecutorProfiler.js +1 -1
  29. package/src/engine/EngineHarness.js +7 -7
  30. package/src/engine/EntityCreator.js +5 -5
  31. package/src/engine/__module.js +1 -1
  32. package/src/engine/achievements/AchievementManager.js +2 -2
  33. package/src/engine/animation/AnimationUtils.js +4 -4
  34. package/src/engine/animation/behavior/animateProperty.js +2 -2
  35. package/src/engine/animation/curve/draw/build_plot_entity_from_array.js +3 -3
  36. package/src/engine/animation/playAnimationTrack.js +3 -3
  37. package/src/engine/animation/playTrackRealTime.js +3 -3
  38. package/src/engine/animation/removeEntityWithMeshParticlesEffect.js +2 -2
  39. package/src/engine/control/ControlContext.js +7 -7
  40. package/src/engine/ecs/{EntityBuilder.d.ts → Entity.d.ts} +5 -5
  41. package/src/engine/ecs/{EntityBuilder.js → Entity.js} +29 -29
  42. package/src/engine/ecs/{EntityBuilder.spec.js → Entity.spec.js} +17 -17
  43. package/src/engine/ecs/EntityBlueprint.d.ts +2 -2
  44. package/src/engine/ecs/EntityBlueprint.js +3 -3
  45. package/src/engine/ecs/EntityBlueprint.spec.js +2 -2
  46. package/src/engine/ecs/{EntityBuilderFlags.js → EntityFlags.js} +1 -1
  47. package/src/engine/ecs/EntityObserver.spec.js +8 -8
  48. package/src/engine/ecs/dynamic_actions/DynamicActorSystem.js +5 -5
  49. package/src/engine/ecs/foliage/ecs/InstancedMeshUtils.js +3 -3
  50. package/src/engine/ecs/gui/menu/radial/RadialContextMenu.d.ts +2 -2
  51. package/src/engine/ecs/gui/menu/radial/RadialContextMenu.js +5 -5
  52. package/src/engine/ecs/parent/EntityNode.d.ts +3 -3
  53. package/src/engine/ecs/parent/EntityNode.js +5 -5
  54. package/src/engine/ecs/parent/testHuDPerf.js +2 -2
  55. package/src/engine/ecs/speaker/VoiceSystem.js +5 -5
  56. package/src/engine/ecs/tooltip/testTooltipComponentSystem.js +3 -3
  57. package/src/engine/graphics/camera/makeOrbitalCameraController.js +3 -3
  58. package/src/engine/graphics/camera/testClippingPlaneComputation.js +3 -3
  59. package/src/engine/graphics/debug/createDebugLabel.js +3 -3
  60. package/src/engine/graphics/ecs/camera/filter/setup_filtered_camera_controller.js +3 -3
  61. package/src/engine/graphics/ecs/decal/v2/prototypeDecalEditor.js +3 -3
  62. package/src/engine/graphics/ecs/decal/v2/prototypeDecalSystem.js +14 -14
  63. package/src/engine/graphics/ecs/mesh-v2/aggregate/prototypeSGMesh.js +3 -3
  64. package/src/engine/graphics/ecs/mesh-v2/sample/prototypeShadedGeometry.js +5 -5
  65. package/src/engine/graphics/ecs/mesh-v2/sample/prototype_sg_raycast.js +6 -6
  66. package/src/engine/graphics/ecs/path/ribbon/RibbonPathBuilder.js +3 -3
  67. package/src/engine/graphics/ecs/path/testPathDisplaySystem.js +3 -3
  68. package/src/engine/graphics/ecs/path/tube/build/TubePathBuilder.js +3 -3
  69. package/src/engine/graphics/ecs/path/tube/prototypeAnimatedPathMask.js +3 -3
  70. package/src/engine/graphics/ecs/sprite/SpriteSystemPE.js +2 -2
  71. package/src/engine/graphics/ecs/sprite/prototypeSpriteSystem.js +2 -2
  72. package/src/engine/graphics/geometry/optimization/merge/prototypeGeometryMerge.js +4 -4
  73. package/src/engine/graphics/impostors/octahedral/prototypeBaker.js +7 -7
  74. package/src/engine/graphics/particles/node-based/editor/ParticleSpecificationEditorView.js +1 -1
  75. package/src/engine/graphics/particles/particular/engine/renderers/billboard/prototypeBillboardRenderer.js +2 -2
  76. package/src/engine/graphics/particles/particular/engine/utils/volume/ParticleVolume.d.ts +2 -2
  77. package/src/engine/graphics/particles/particular/engine/utils/volume/ParticleVolume.js +3 -3
  78. package/src/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +10 -10
  79. package/src/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +2 -2
  80. package/src/engine/graphics/render/buffer/simple-fx/taa/prototypeTAA.js +2 -2
  81. package/src/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +11 -11
  82. package/src/engine/graphics/render/visibility/hiz/prototypeHiZ.js +5 -5
  83. package/src/engine/graphics/sh3/LightProbeVolume.js +2 -2
  84. package/src/engine/graphics/sh3/prototypeSH3Probe.js +3 -3
  85. package/src/engine/graphics/sh3/visualise_probe.js +3 -3
  86. package/src/engine/graphics/shadows/testShadowMapRendering.js +3 -3
  87. package/src/engine/graphics/texture/sampler/downloadSamplerAsPNG.js +1 -1
  88. package/src/engine/graphics/texture/sprite/prototypeSpriteCutoutGeometry.js +2 -2
  89. package/src/engine/input/ecs/controllers/KeyboardCameraController.js +2 -2
  90. package/src/engine/input/ecs/util/TopDownCameraControllerHelper.js +2 -2
  91. package/src/engine/intelligence/behavior/composite/ParallelBehavior.spec.js +13 -12
  92. package/src/engine/physics/fluid/prototype.js +3 -3
  93. package/src/engine/save/storage/JsonStringCodec.js +1 -1
  94. package/src/engine/save/storage/LocalStorage.js +2 -1
  95. package/src/engine/ui/GUIEngine.js +4 -4
  96. package/src/engine/ui/notification/NotificationManager.js +3 -3
  97. package/src/generation/markers/debug/visualizeMarkers.js +2 -2
  98. package/src/generation/markers/prototypeGridCellActionPlaceMarker.js +2 -2
  99. package/src/core/binary/ByteArrayTools.js +0 -137
  100. package/src/core/binary/NaiveBitSet.js +0 -69
  101. package/src/core/binary/objects/StandardTypeBuilder.js +0 -126
  102. package/src/core/binary/serde/JsonSerializer.js +0 -113
package/editor/Editor.js CHANGED
@@ -17,7 +17,7 @@ import { SelectionVisualizer } from "./SelectionVisualizer.js";
17
17
  import { ProcessEngine } from "./process/ProcessEngine.js";
18
18
  import { MeshLibrary } from "./library/MeshLibrary.js";
19
19
  import { TransformerMode } from "./tools/TransformTool.js";
20
- import EntityBuilder from "../src/engine/ecs/EntityBuilder.js";
20
+ import Entity from "../src/engine/ecs/Entity.js";
21
21
  import { Camera } from "../src/engine/graphics/ecs/camera/Camera.js";
22
22
  import EditorEntitySystem from "./ecs/EditorEntitySystem.js";
23
23
  import EditorEntity from "./ecs/EditorEntity.js";
@@ -26,7 +26,6 @@ import { Transform } from "../src/engine/ecs/transform/Transform.js";
26
26
  import TopDownCameraControllerSystem, {
27
27
  setCameraControllerFromTransform
28
28
  } from "../src/engine/graphics/ecs/camera/topdown/TopDownCameraControllerSystem.js";
29
- import { downloadAsFile } from "../src/core/binary/ByteArrayTools.js";
30
29
  import BinaryBufferSerializer from "../src/engine/ecs/storage/BinaryBufferSerializer.js";
31
30
  import { EncodingBinaryBuffer } from "../src/core/binary/EncodingBinaryBuffer.js";
32
31
  import { EntityComponentDataset } from "../src/engine/ecs/EntityComponentDataset.js";
@@ -73,6 +72,7 @@ import '../../../../css/editor/EntityEditorView.scss';
73
72
  import '../../../../css/editor/EditorView.scss';
74
73
  import { ParameterTrackSet } from "../src/engine/graphics/particles/particular/engine/parameter/ParameterTrackSet.js";
75
74
  import { ParameterTrackSetEditor } from "./ecs/component/editors/ecs/ParameterTrackSetEditor.js";
75
+ import {downloadAsFile} from "../src/core/binary/downloadAsFile.js";
76
76
 
77
77
  /**
78
78
  * @template T
@@ -250,7 +250,7 @@ function pasteEntities(editor) {
250
250
  }
251
251
 
252
252
  function buildEditorCamera() {
253
- const cameraEntity = new EntityBuilder();
253
+ const cameraEntity = new Entity();
254
254
  const camera = new Camera();
255
255
 
256
256
  camera.projectionType.set(Camera.ProjectionType.Perspective);
@@ -274,7 +274,7 @@ function buildEditorCamera() {
274
274
 
275
275
  /**
276
276
  *
277
- * @param {EntityBuilder} cameraEntity
277
+ * @param {Entity} cameraEntity
278
278
  * @param {EntityComponentDataset} dataset
279
279
  * @param {Editor} editor
280
280
  */
@@ -1,4 +1,4 @@
1
- import EntityBuilder from "../../../src/engine/ecs/EntityBuilder.js";
1
+ import Entity from "../../../src/engine/ecs/Entity.js";
2
2
  import Renderable from "../../../src/engine/ecs/renderable/Renderable.js";
3
3
  import { Transform } from "../../../src/engine/ecs/transform/Transform.js";
4
4
  import EditorEntity from "../../ecs/EditorEntity.js";
@@ -9,12 +9,12 @@ import Script from "../../../src/engine/ecs/components/Script.js";
9
9
  *
10
10
  * @param {Object3D} helper
11
11
  * @param {number} sourceEntity
12
- * @return {EntityBuilder}
12
+ * @return {Entity}
13
13
  */
14
14
  export function buildThreeJSHelperEntity(helper, sourceEntity = -1) {
15
15
  helper.frustumCulled = false;
16
16
 
17
- const entityBuilder = new EntityBuilder();
17
+ const entityBuilder = new Entity();
18
18
 
19
19
  const renderable = new Renderable(helper);
20
20
  // renderable.matrixAutoUpdate = false;
@@ -2,7 +2,7 @@ import { max2 } from "../../../src/core/math/max2.js";
2
2
  import { min2 } from "../../../src/core/math/min2.js";
3
3
  import Task from "../../../src/core/process/task/Task.js";
4
4
  import { TaskSignal } from "../../../src/core/process/task/TaskSignal.js";
5
- import EntityBuilder from "../../../src/engine/ecs/EntityBuilder.js";
5
+ import Entity from "../../../src/engine/ecs/Entity.js";
6
6
  import { BufferGeometry, Float32BufferAttribute, Line, LineBasicMaterial } from "three";
7
7
  import Renderable from "../../../src/engine/ecs/renderable/Renderable.js";
8
8
  import { SurfacePoint3 } from "../../../src/core/geom/3d/SurfacePoint3.js";
@@ -48,10 +48,10 @@ export function makeGridPositionSymbolDisplay(engine) {
48
48
  *
49
49
  * @param {GridPosition} gridPosition
50
50
  * @param {Transform} transform
51
- * @returns {EntityBuilder}
51
+ * @returns {Entity}
52
52
  */
53
53
  function makeHelper(gridPosition, transform) {
54
- const builder = new EntityBuilder();
54
+ const builder = new Entity();
55
55
 
56
56
  // TODO replace with {@link VisualSymbolLine}
57
57
 
@@ -1,7 +1,7 @@
1
1
  import { assert } from "../../../src/core/assert.js";
2
2
  import { Sprite, SpriteMaterial } from "three";
3
3
  import { make3DSymbolicDisplay } from "./make3DSymbolicDisplay.js";
4
- import EntityBuilder from "../../../src/engine/ecs/EntityBuilder.js";
4
+ import Entity from "../../../src/engine/ecs/Entity.js";
5
5
  import Renderable from "../../../src/engine/ecs/renderable/Renderable.js";
6
6
  import { Transform } from "../../../src/engine/ecs/transform/Transform.js";
7
7
  import { synchronizeTransform } from "./synchronizeTransform.js";
@@ -42,11 +42,11 @@ export function makePositionedIconDisplaySymbol(engine, iconURL, ComponentClass)
42
42
  * @param transform
43
43
  * @param entity
44
44
  * @param {SymbolicDisplayInternalAPI} api
45
- * @return {EntityBuilder}
45
+ * @return {Entity}
46
46
  */
47
47
  factory([component, transform, entity], api) {
48
48
 
49
- const b = new EntityBuilder();
49
+ const b = new Entity();
50
50
 
51
51
  const sprite = new Sprite(spriteMaterial);
52
52
  sprite.frustumCulled = false;
@@ -1,5 +1,5 @@
1
1
  import { EngineHarness } from "../../../src/engine/EngineHarness.js";
2
- import EntityBuilder from "../../../src/engine/ecs/EntityBuilder.js";
2
+ import Entity from "../../../src/engine/ecs/Entity.js";
3
3
  import { ShadedGeometry } from "../../../src/engine/graphics/ecs/mesh-v2/ShadedGeometry.js";
4
4
  import { BoxBufferGeometry, MeshStandardMaterial } from "three";
5
5
  import { Transform } from "../../../src/engine/ecs/transform/Transform.js";
@@ -32,7 +32,7 @@ async function main(engine) {
32
32
  const ecd = engine.entityManager.dataset;
33
33
 
34
34
  // create something to drag
35
- const cube_entity = new EntityBuilder()
35
+ const cube_entity = new Entity()
36
36
  .add(ShadedGeometry.from(
37
37
  new BoxBufferGeometry(1, 1, 1),
38
38
  new MeshStandardMaterial({
@@ -60,7 +60,7 @@ async function main(engine) {
60
60
  // controls.attach(cube_entity); // make controls target the cube
61
61
  controls.attach(entityNode.entity.entity); // make controls target the cube
62
62
 
63
- new EntityBuilder()
63
+ new Entity()
64
64
  .add(new InputController([{
65
65
  path: 'keyboard/keys/w/down',
66
66
  listener() {
@@ -5,7 +5,8 @@ import ObservedBoolean from "../../../src/core/model/ObservedBoolean.js";
5
5
  import LabelView from "../../../src/view/common/LabelView.js";
6
6
  import ButtonView from "../../../src/view/elements/button/ButtonView.js";
7
7
  import EmptyView from "../../../src/view/elements/EmptyView.js";
8
- import { downloadAsFile } from "../../../src/core/binary/ByteArrayTools.js";
8
+
9
+ import {downloadAsFile} from "../../../src/core/binary/downloadAsFile.js";
9
10
 
10
11
  export async function obtainClipBoard() {
11
12
  const navigator = globalThis.navigator;
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "description": "Fully featured ECS game engine written in JavaScript",
6
6
  "type": "module",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.57.0",
8
+ "version": "2.58.0",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -8,7 +8,7 @@ import Terrain from "../../src/engine/ecs/terrain/ecs/Terrain.js";
8
8
  import { TerrainFlags } from "../../src/engine/ecs/terrain/ecs/TerrainFlags.js";
9
9
  import Water from "../../src/engine/graphics/ecs/water/Water.js";
10
10
  import GridObstacle from "../../src/engine/grid/obstacle/GridObstacle.js";
11
- import EntityBuilder from "../../src/engine/ecs/EntityBuilder.js";
11
+ import Entity from "../../src/engine/ecs/Entity.js";
12
12
  import GridPosition from "../../src/engine/grid/position/GridPosition.js";
13
13
  import { Transform } from "../../src/engine/ecs/transform/Transform.js";
14
14
  import { GridData } from "../../src/generation/grid/GridData.js";
@@ -115,7 +115,7 @@ function prepare_gen_task({
115
115
  const obstacle = new GridObstacle();
116
116
  obstacle.resize(terrain.size.x, terrain.size.y);
117
117
 
118
- const terrainBuilder = new EntityBuilder();
118
+ const terrainBuilder = new Entity();
119
119
 
120
120
  terrainBuilder
121
121
  .add(terrain)
@@ -3,7 +3,7 @@ import { EngineHarness } from "../../src/engine/EngineHarness.js";
3
3
  import { GameAssetType } from "../../src/engine/asset/GameAssetType.js";
4
4
  import { TextureAssetLoader } from "../../src/engine/asset/loaders/texture/TextureAssetLoader.js";
5
5
  import Vector3 from "../../src/core/geom/Vector3.js";
6
- import EntityBuilder from "../../src/engine/ecs/EntityBuilder.js";
6
+ import Entity from "../../src/engine/ecs/Entity.js";
7
7
  import Terrain from "../../src/engine/ecs/terrain/ecs/Terrain.js";
8
8
  import { ImageRGBADataLoader } from "../../src/engine/asset/loaders/image/ImageRGBADataLoader.js";
9
9
  import TerrainSystem from "../../src/engine/ecs/terrain/ecs/TerrainSystem.js";
@@ -261,7 +261,7 @@ async function main(engine) {
261
261
  water.shoreDepthTransition.set(0.1, 0.3);
262
262
  water.scattering.set(3);
263
263
 
264
- new EntityBuilder()
264
+ new Entity()
265
265
  .add(terrain)
266
266
  // .add(water)
267
267
  .build(ecd);
@@ -3,7 +3,7 @@ import { EngineHarness } from "../../src/engine/EngineHarness.js";
3
3
  import { GameAssetType } from "../../src/engine/asset/GameAssetType.js";
4
4
  import { TextureAssetLoader } from "../../src/engine/asset/loaders/texture/TextureAssetLoader.js";
5
5
  import Vector3 from "../../src/core/geom/Vector3.js";
6
- import EntityBuilder from "../../src/engine/ecs/EntityBuilder.js";
6
+ import Entity from "../../src/engine/ecs/Entity.js";
7
7
  import Terrain from "../../src/engine/ecs/terrain/ecs/Terrain.js";
8
8
  import { ImageRGBADataLoader } from "../../src/engine/asset/loaders/image/ImageRGBADataLoader.js";
9
9
  import TerrainSystem from "../../src/engine/ecs/terrain/ecs/TerrainSystem.js";
@@ -15,9 +15,9 @@ import { TerrainLayer } from "../../src/engine/ecs/terrain/ecs/layers/TerrainLay
15
15
  import Mesh from "../../src/engine/graphics/ecs/mesh/Mesh.js";
16
16
  import { Transform } from "../../src/engine/ecs/transform/Transform.js";
17
17
  import { MeshSystem } from "../../src/engine/graphics/ecs/mesh/MeshSystem.js";
18
- import { downloadAsFile } from "../../src/core/binary/ByteArrayTools.js";
19
18
  import { url_to_data_url } from "../../src/core/binary/url_to_data_url.js";
20
19
  import ButtonView from "../../src/view/elements/button/ButtonView.js";
20
+ import {downloadAsFile} from "../../src/core/binary/downloadAsFile.js";
21
21
 
22
22
  const HEIGHT_RANGE = 64;
23
23
 
@@ -136,7 +136,7 @@ async function main(engine) {
136
136
  water.shoreDepthTransition.set(0.1, 0.3);
137
137
  water.scattering.set(3);
138
138
 
139
- new EntityBuilder()
139
+ new Entity()
140
140
  .add(terrain)
141
141
  // .add(water)
142
142
  .build(ecd);
@@ -250,7 +250,7 @@ async function load_gltf(path, engine, transform) {
250
250
 
251
251
  const ecd = em.dataset;
252
252
 
253
- new EntityBuilder()
253
+ new Entity()
254
254
  .add(Mesh.fromJSON({
255
255
  url: path
256
256
  }))
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Turns an array of numbers into the string given by the concatenation of the
3
+ * characters to which the numbers correspond.
4
+ * @param {!Uint8Array|!Array<number>} bytes Array of numbers representing
5
+ * characters.
6
+ * @return {string} Stringification of the array.
7
+ */
8
+ export function byteArrayToString(bytes) {
9
+ const numBytes = bytes.length;
10
+
11
+ const CHUNK_SIZE = 8192;
12
+
13
+ // Special-case the simple case for speed's sake.
14
+ if (numBytes <= CHUNK_SIZE) {
15
+ return String.fromCharCode.apply(null, bytes);
16
+ }
17
+
18
+ // The remaining logic splits conversion by chunks since
19
+ // Function#apply() has a maximum parameter count.
20
+ // See discussion: http://goo.gl/LrWmZ9
21
+
22
+ let str = '';
23
+ for (let i = 0; i < numBytes; i += CHUNK_SIZE) {
24
+ const chunk = Array.prototype.slice.call(bytes, i, i + CHUNK_SIZE);
25
+ str += String.fromCharCode.apply(null, chunk);
26
+ }
27
+ return str;
28
+ }
@@ -0,0 +1,28 @@
1
+ import {downloadUrlAsFile} from "./downloadUrlAsFile.js";
2
+
3
+ export function downloadAsFile(data, filename, type = 'text/json') {
4
+
5
+ let blobContent;
6
+
7
+ if (data instanceof ArrayBuffer || data instanceof Uint8Array) {
8
+ //raw binary data
9
+ blobContent = [data];
10
+ } else if (data instanceof Array) {
11
+ //already an array
12
+ blobContent = data;
13
+ } else if (data instanceof Blob) {
14
+ //already a blob
15
+ blobContent = [data];
16
+ } else if (typeof data === "string") {
17
+ blobContent = [data];
18
+ } else {
19
+ blobContent = [data]
20
+ }
21
+
22
+ const blob = new Blob(blobContent, {type});
23
+ if (window.navigator.msSaveOrOpenBlob) {
24
+ window.navigator.msSaveBlob(blob, filename);
25
+ } else {
26
+ downloadUrlAsFile(window.URL.createObjectURL(blob), filename);
27
+ }
28
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ *
3
+ * @param {string} url
4
+ * @param {string} filename
5
+ */
6
+ export function downloadUrlAsFile(url, filename) {
7
+ const elem = window.document.createElement('a');
8
+ elem.href = url;
9
+ elem.download = filename;
10
+ document.body.appendChild(elem);
11
+ elem.click();
12
+ document.body.removeChild(elem);
13
+ }
14
+
@@ -0,0 +1,27 @@
1
+ import {stringifyStream} from "../json/JsonUtils.js";
2
+
3
+ /**
4
+ *
5
+ * @param {Object} json
6
+ * @returns {number[]}
7
+ */
8
+ function jsonToStringToByteArray(json) {
9
+ const output = [];
10
+ let p = 0;
11
+
12
+ function addToOutput(str) {
13
+ for (let i = 0; i < str.length; i++) {
14
+ let c = str.charCodeAt(i);
15
+ while (c > 0xff) {
16
+ output[p++] = c & 0xff;
17
+ c >>= 8;
18
+ }
19
+ output[p++] = c;
20
+ }
21
+ }
22
+
23
+ stringifyStream(json, addToOutput);
24
+ return output;
25
+ }
26
+
27
+ export {jsonToStringToByteArray};
@@ -0,0 +1,24 @@
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,5 +1,4 @@
1
1
  import { BinaryBuffer } from "../binary/BinaryBuffer.js";
2
- import { byteArrayToString, jsonToStringToByteArray } from "../binary/ByteArrayTools.js";
3
2
  import { BinaryNode } from "./BinaryNode.js";
4
3
  import { isLeaf, LeafNode } from "./LeafNode.js";
5
4
  import { validateNode, validateTree } from "./NodeValidator.js";
@@ -7,6 +6,8 @@ import { deserializeBinaryNode } from "./serialization/deserializeBinaryNode.js"
7
6
  import { deserializeBinaryNodeFromBinaryBuffer } from "./serialization/deserializeBinaryNodeFromBinaryBuffer.js";
8
7
  import { serializeBinaryNode } from "./serialization/serializeBinaryNode.js";
9
8
  import { serializeBinaryNodeToBinaryBuffer } from "./serialization/serializeBinaryNodeToBinaryBuffer.js";
9
+ import {byteArrayToString} from "../binary/byteArrayToString.js";
10
+ import {jsonToStringToByteArray} from "../binary/jsonToStringToByteArray.js";
10
11
 
11
12
  /**
12
13
  *
@@ -1,4 +1,4 @@
1
- import { Color } from "./Color.js";
1
+ import {Color} from "./Color.js";
2
2
 
3
3
  test('toUint', () => {
4
4
  const c = new Color();
@@ -146,3 +146,29 @@ test("iterator", () => {
146
146
  expect(last.done).toBe(true)
147
147
  expect(last.value).toBeUndefined()
148
148
  });
149
+
150
+ test("array-style getters", () => {
151
+
152
+ const color = new Color(0.1, 0.3, 0.7, 0.11);
153
+
154
+ expect(color[0]).toBe(0.1);
155
+ expect(color[1]).toBe(0.3);
156
+ expect(color[2]).toBe(0.7);
157
+ expect(color[3]).toBe(0.11);
158
+
159
+ });
160
+ test("array-style setters", () => {
161
+
162
+ const color = new Color(0.001, 0.001, 0.001, 0.001);
163
+
164
+ color[0] = 0.1;
165
+ color[1] = 0.3;
166
+ color[2] = 0.7;
167
+ color[3] = 0.11;
168
+
169
+ expect(color.r).toBe(0.1);
170
+ expect(color.g).toBe(0.3);
171
+ expect(color.b).toBe(0.7);
172
+ expect(color.a).toBe(0.11);
173
+
174
+ });
@@ -13,7 +13,7 @@ const hsvRegEx = /hsv\(([0-9]+(?:\.[0-9]*)?),\s*([0-9]+(?:\.[0-9]*)?),\s*([0-9]+
13
13
  /**
14
14
  * Parses most CSS-format colors
15
15
  * @param {string|number} c
16
- * @returns {number[]} Numeric array, values are in Uint8 range (0...255)
16
+ * @returns {number[]} Numeric array, values are in Uint8 range (0...255) for RGB and 0..1 for Alpha
17
17
  */
18
18
  export function parse_color(c) {
19
19
 
@@ -1,5 +1,5 @@
1
- import { SimpleStateMachine } from "./SimpleStateMachine.js";
2
- import { SimpleStateMachineDescription } from "./SimpleStateMachineDescription.js";
1
+ import {SimpleStateMachine} from "./SimpleStateMachine.js";
2
+ import {SimpleStateMachineDescription} from "./SimpleStateMachineDescription.js";
3
3
 
4
4
  test("constructor does not throw", () => {
5
5
  const description = new SimpleStateMachineDescription();
@@ -31,6 +31,22 @@ test("state entry event handler is fired as expected", () => {
31
31
  expect(entry_callback).toHaveBeenCalledWith(b, a);
32
32
  });
33
33
 
34
+ test("remove entry event handler", () => {
35
+ const description = new SimpleStateMachineDescription();
36
+
37
+ const a = description.createState();
38
+ const fsm = new SimpleStateMachine(description);
39
+
40
+ const handler = () => {
41
+ };
42
+
43
+ fsm.addEventHandlerStateEntry(a, handler);
44
+
45
+ expect(fsm.removeEventHandlerStateEntry(a, handler)).toBe(true);
46
+ expect(fsm.removeEventHandlerStateEntry(a, handler)).toBe(false);
47
+
48
+ });
49
+
34
50
  test("state exit event handler is fired as expected", () => {
35
51
 
36
52
  const description = new SimpleStateMachineDescription();
@@ -54,6 +70,22 @@ test("state exit event handler is fired as expected", () => {
54
70
  expect(entry_callback).toHaveBeenCalledWith(a, b);
55
71
  });
56
72
 
73
+ test("remove exit event handler", () => {
74
+ const description = new SimpleStateMachineDescription();
75
+
76
+ const a = description.createState();
77
+ const fsm = new SimpleStateMachine(description);
78
+
79
+ const handler = () => {
80
+ };
81
+
82
+ fsm.addEventHandlerStateExit(a, handler);
83
+
84
+ expect(fsm.removeEventHandlerStateExit(a, handler)).toBe(true);
85
+ expect(fsm.removeEventHandlerStateExit(a, handler)).toBe(false);
86
+
87
+ });
88
+
57
89
  test("'advance' moves us to the next state in the chain", () => {
58
90
 
59
91
 
@@ -1,6 +1,6 @@
1
1
  /**
2
- * Multiplies two mat4s
3
- * Adapter from gl-matrix
2
+ * Multiplies two 4x4 matrices
3
+ * Adapted from gl-matrix
4
4
  *
5
5
  * @param {ArrayLike<number>|Float32Array} out the receiving matrix
6
6
  * @param {ArrayLike<number>|Float32Array} a the first operand
@@ -0,0 +1,11 @@
1
+ import {MATRIX_4_IDENTITY} from "./MATRIX_4_IDENTITY.js";
2
+ import {m4_multiply} from "./m4_multiply.js";
3
+
4
+ test("identity multiplication", () => {
5
+
6
+ const result = [];
7
+
8
+ m4_multiply(result, MATRIX_4_IDENTITY, MATRIX_4_IDENTITY);
9
+
10
+ expect(result).toEqual(MATRIX_4_IDENTITY);
11
+ });
@@ -0,0 +1,11 @@
1
+ import {m4_multiply_alphatensor} from "./m4_multiply_alphatensor.js";
2
+ import {MATRIX_4_IDENTITY} from "./MATRIX_4_IDENTITY.js";
3
+
4
+ test("identity multiplication", () => {
5
+
6
+ const result = [];
7
+
8
+ m4_multiply_alphatensor(result, MATRIX_4_IDENTITY, MATRIX_4_IDENTITY);
9
+
10
+ expect(result).toEqual(MATRIX_4_IDENTITY);
11
+ });
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * method to separate bits from a given integer 2 positions apart
3
3
  *
4
- * @example when input is ABC, output bits are A00B00C
4
+ * @example when input is ABC, output bits are A0B0C
5
5
  * @see https://github.com/Forceflow/libmorton/blob/234a443ca8e2c64f6385f1a9d6ee10a70d08a3fa/include/libmorton/morton2D.h#L99
6
6
  * @param {number} a
7
7
  * @returns {number}
@@ -2,7 +2,7 @@ import { UnionShape3D } from "../UnionShape3D.js";
2
2
  import { UnitCubeShape3D } from "../UnitCubeShape3D.js";
3
3
  import { UnitSphereShape3D } from "../UnitSphereShape3D.js";
4
4
  import { TransformedShape3D } from "../TransformedShape3D.js";
5
- import EntityBuilder from "../../../../../engine/ecs/EntityBuilder.js";
5
+ import Entity from "../../../../../engine/ecs/Entity.js";
6
6
  import { Transform } from "../../../../../engine/ecs/transform/Transform.js";
7
7
  import { AttachmentSockets } from "../../../../../engine/ecs/sockets/AttachmentSockets.js";
8
8
  import { Attachment } from "../../../../../engine/ecs/attachment/Attachment.js";
@@ -32,11 +32,11 @@ export const SHAPE_VISUAL_ENTITY_TAG = 'util/vis/Shape3D';
32
32
  *
33
33
  * @param {UnionShape3D} shape
34
34
  * @param {EntityComponentDataset} ecd
35
- * @returns {EntityBuilder}
35
+ * @returns {Entity}
36
36
  */
37
37
  function composite_shape_to_entity(shape, ecd) {
38
38
 
39
- const parent = new EntityBuilder();
39
+ const parent = new Entity();
40
40
  parent
41
41
  .add(new Transform())
42
42
  .add(AttachmentSockets.fromJSON({
@@ -69,10 +69,10 @@ function composite_shape_to_entity(shape, ecd) {
69
69
  *
70
70
  * @param {UnitCubeShape3D} shape
71
71
  * @param {EntityComponentDataset} ecd
72
- * @returns {EntityBuilder}
72
+ * @returns {Entity}
73
73
  */
74
74
  function cube_shape_to_entity(shape, ecd) {
75
- const eb = new EntityBuilder();
75
+ const eb = new Entity();
76
76
 
77
77
  eb.add(new Transform());
78
78
  eb.add(Tag.fromOne(SHAPE_VISUAL_ENTITY_TAG));
@@ -88,10 +88,10 @@ function cube_shape_to_entity(shape, ecd) {
88
88
  *
89
89
  * @param {UnitSphereShape3D} shape
90
90
  * @param {EntityComponentDataset} ecd
91
- * @returns {EntityBuilder}
91
+ * @returns {Entity}
92
92
  */
93
93
  function sphere_shape_to_entity(shape, ecd) {
94
- const eb = new EntityBuilder();
94
+ const eb = new Entity();
95
95
 
96
96
  eb.add(new Transform());
97
97
  eb.add(Tag.fromOne(SHAPE_VISUAL_ENTITY_TAG));
@@ -107,12 +107,12 @@ function sphere_shape_to_entity(shape, ecd) {
107
107
  *
108
108
  * @param {TransformedShape3D} shape
109
109
  * @param {EntityComponentDataset} ecd
110
- * @returns {EntityBuilder}
110
+ * @returns {Entity}
111
111
  */
112
112
  function transformed_shape_to_entity(shape, ecd) {
113
113
  const subject = shape_to_visual_entity(shape.subject, ecd);
114
114
 
115
- const parent = new EntityBuilder();
115
+ const parent = new Entity();
116
116
  parent
117
117
  .add(new Transform())
118
118
  .add(AttachmentSockets.fromJSON({
@@ -142,7 +142,7 @@ function transformed_shape_to_entity(shape, ecd) {
142
142
  *
143
143
  * @param {AbstractShape3D} shape
144
144
  * @param {EntityComponentDataset} ecd
145
- * @returns {EntityBuilder}
145
+ * @returns {Entity}
146
146
  */
147
147
  export function shape_to_visual_entity(shape, ecd) {
148
148
  if (shape instanceof UnionShape3D) {
@@ -3,7 +3,7 @@ import { compute_delaunay_tetrahedral_mesh } from "./delaunay/compute_delaunay_t
3
3
  import { LineBasicMaterial } from "three";
4
4
  import { ShadedGeometry } from "../../../../engine/graphics/ecs/mesh-v2/ShadedGeometry.js";
5
5
  import { DrawMode } from "../../../../engine/graphics/ecs/mesh-v2/DrawMode.js";
6
- import EntityBuilder from "../../../../engine/ecs/EntityBuilder.js";
6
+ import Entity from "../../../../engine/ecs/Entity.js";
7
7
  import { Transform } from "../../../../engine/ecs/transform/Transform.js";
8
8
  import { ShadedGeometrySystem } from "../../../../engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js";
9
9
  import { GizmoRenderingPlugin } from "../../../../engine/graphics/render/gizmo/GizmoRenderingPlugin.js";
@@ -76,7 +76,7 @@ async function main(engine) {
76
76
 
77
77
 
78
78
 
79
- new EntityBuilder()
79
+ new Entity()
80
80
  .add(ShadedGeometry.from(geometry, new LineBasicMaterial({ color: 0xFF0000 }), DrawMode.LineSegments))
81
81
  .add(Transform.fromJSON({
82
82
  position: { x: offset[0], y: offset[1], z: offset[2] },
@@ -1,6 +1,6 @@
1
1
  import { EngineHarness } from "../../../../../engine/EngineHarness.js";
2
2
  import { MeshBasicMaterial, MeshStandardMaterial, OctahedronBufferGeometry } from "three";
3
- import EntityBuilder from "../../../../../engine/ecs/EntityBuilder.js";
3
+ import Entity from "../../../../../engine/ecs/Entity.js";
4
4
  import { ShadedGeometry } from "../../../../../engine/graphics/ecs/mesh-v2/ShadedGeometry.js";
5
5
  import { Transform } from "../../../../../engine/ecs/transform/Transform.js";
6
6
  import { ShadedGeometrySystem } from "../../../../../engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js";
@@ -104,7 +104,7 @@ async function main(engine) {
104
104
 
105
105
  const ecd = engine.entityManager.dataset;
106
106
 
107
- const entityBuilder = new EntityBuilder();
107
+ const entityBuilder = new Entity();
108
108
  entityBuilder
109
109
  .add(SGMesh.fromURL(path))
110
110
  .add(Transform.fromJSON({}))
@@ -151,7 +151,7 @@ async function main(engine) {
151
151
  makeGeometryIndexed(source_geo);
152
152
  source_geo = mergeVertices(source_geo, 0.002);
153
153
 
154
- const entity_source = new EntityBuilder();
154
+ const entity_source = new Entity();
155
155
  entity_source
156
156
  .add(ShadedGeometry.from(source_geo, new MeshStandardMaterial({
157
157
  color: '#b60000'