@woosh/meep-engine 2.33.36 → 2.33.40

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 (90) hide show
  1. package/core/bvh2/binary/2/BinaryUint32BVH.js +3 -3
  2. package/core/collection/HashMap.js +19 -12
  3. package/core/collection/array/typed/typed_array_copy.js +2 -2
  4. package/core/collection/table/RowFirstTable.js +13 -8
  5. package/core/collection/table/RowFirstTableSpec.js +6 -0
  6. package/core/color/Color.js +5 -9
  7. package/core/color/ColorUtils.js +4 -150
  8. package/core/color/YCbCr_to_rgb_uint24.js +20 -0
  9. package/core/color/hsv2rgb.js +54 -0
  10. package/core/color/int2rgb.js +12 -0
  11. package/core/color/parseHex.js +18 -0
  12. package/core/color/rgb2hex.js +16 -0
  13. package/core/color/rgb2hsv.js +47 -0
  14. package/core/color/rgb2uint24.js +17 -0
  15. package/core/color/rgb_to_YCbCr_uint24.js +18 -0
  16. package/core/geom/3d/aabb/aabb3_matrix4_project_by_corners.js +1 -1
  17. package/core/geom/3d/aabb/compute_aabb_from_points.js +28 -0
  18. package/core/geom/3d/morton/mortonEncode_magicbits.js +7 -6
  19. package/core/geom/3d/morton/v3_morton_encode_transformed.js +15 -11
  20. package/core/geom/3d/plane/orient3d_fast.js +51 -0
  21. package/core/geom/3d/plane/plane_computeConvex3PlaneIntersection.js +5 -0
  22. package/core/geom/3d/tetrahedra/GetDepthForTetrahedronProbe.glsl +43 -0
  23. package/core/geom/3d/tetrahedra/compute_bounding_simplex_3d.js +177 -0
  24. package/core/geom/3d/tetrahedra/compute_bounding_simplex_3d.spec.js +66 -0
  25. package/core/geom/3d/tetrahedra/compute_circumsphere.js +271 -0
  26. package/core/geom/3d/tetrahedra/compute_delaunay_tetrahedral_mesh.js +50 -0
  27. package/core/geom/3d/tetrahedra/compute_delaunay_tetrahedral_mesh.spec.js +14 -0
  28. package/core/geom/3d/tetrahedra/point_in_tetrahedron_circumsphere.js +77 -0
  29. package/core/geom/3d/tetrahedra/tetrahedra_collection.js +454 -0
  30. package/core/geom/3d/tetrahedra/tetrahedron_contains_point.js +26 -0
  31. package/core/geom/Quaternion.js +4 -0
  32. package/core/math/hash/murmur3_32.js +39 -0
  33. package/core/process/undo/ActionProcessor.d.ts +2 -0
  34. package/core/process/undo/ActionProcessor.js +15 -4
  35. package/editor/tools/FoliagePaintTool.js +1 -1
  36. package/editor/tools/GridPaintTool.js +1 -1
  37. package/engine/asset/loaders/GLTFAssetLoader.js +4 -8
  38. package/engine/ecs/System.d.ts +24 -1
  39. package/engine/ecs/foliage/InstancedFoliage.js +45 -0
  40. package/engine/ecs/foliage/ecs/InstancedMeshLayer.js +4 -0
  41. package/engine/ecs/storage/BinaryBufferSerializer.js +48 -38
  42. package/engine/ecs/storage/binary/collection/BinaryCollectionSerializer.js +1 -1
  43. package/engine/ecs/terrain/ecs/splat/SplatMapOptimizerDebugger.js +1 -1
  44. package/engine/ecs/terrain/tiles/TerrainTile.js +1 -1
  45. package/engine/graphics/GraphicsEngine.js +7 -0
  46. package/engine/graphics/ecs/light/binding/fp/FPLightBinding.js +1 -1
  47. package/engine/graphics/ecs/mesh/Mesh.js +2 -2
  48. package/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +13 -0
  49. package/engine/graphics/geometry/instancing/InstancedMeshGroup.js +339 -314
  50. package/engine/graphics/micron/prototypeVirtualGeometry.js +4 -1
  51. package/engine/graphics/micron/render/v1/VGThreeRenderer.js +6 -2
  52. package/engine/graphics/particles/node-based/rendering/billboard/ParticleBillboardShader.js +1 -1
  53. package/engine/graphics/particles/particular/engine/parameter/ParameterLookupTable.js +20 -24
  54. package/engine/graphics/particles/particular/engine/renderers/billboard/ParticleBillboardMaterial.js +100 -55
  55. package/engine/graphics/particles/particular/engine/shader/ShaderManager.js +7 -2
  56. package/engine/graphics/particles/particular/engine/utils/volume/ParticleVolume.js +1 -0
  57. package/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +2 -2
  58. package/engine/graphics/render/buffer/simple-fx/DepthLimitedBlur.js +9 -4
  59. package/engine/graphics/render/buffer/simple-fx/ao/AmbientOcclusionPostProcessEffect.js +7 -1
  60. package/engine/graphics/render/forward_plus/LightManager.js +295 -51
  61. package/engine/graphics/render/forward_plus/LightManager.spec.js +1 -1
  62. package/engine/graphics/render/forward_plus/PointLightData.js +9 -13
  63. package/engine/graphics/render/forward_plus/cluster/compute_light_data_hash_0.js +1 -1
  64. package/engine/graphics/render/forward_plus/data/TextureBackedMemoryRegion.js +10 -1
  65. package/engine/graphics/render/forward_plus/debug/LightClusterVolumeMaterial.js +1 -1
  66. package/engine/graphics/render/forward_plus/debug/buildLightClusterWidget.js +3 -1
  67. package/engine/graphics/render/forward_plus/materials/FP_SHADER_CHUNK_ACCUMULATION.js +31 -18
  68. package/engine/graphics/render/forward_plus/materials/fp_build_fragment_shader.js +18 -4
  69. package/engine/graphics/render/forward_plus/model/AbstractLight.js +50 -0
  70. package/engine/graphics/render/forward_plus/model/Decal.js +68 -0
  71. package/engine/graphics/render/forward_plus/{PointLight.js → model/PointLight.js} +19 -11
  72. package/engine/graphics/render/forward_plus/{SpotLight.js → model/SpotLight.js} +20 -12
  73. package/engine/graphics/render/forward_plus/plugin/ForwardPlusRenderingPlugin.js +1 -1
  74. package/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +6 -5
  75. package/engine/graphics/render/forward_plus/{prototypeLightManager.js → prototype/prototypeLightManager.js} +100 -25
  76. package/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_texture.js +29 -20
  77. package/engine/graphics/render/visibility/IncrementalDeltaSet.d.ts +2 -0
  78. package/engine/graphics/render/visibility/IncrementalDeltaSet.js +1 -0
  79. package/engine/graphics/render/visibility/VisibilityComputer.js +8 -7
  80. package/engine/graphics/shaders/TerrainShader.js +5 -5
  81. package/engine/graphics/shadows/testShadowMapRendering.js +192 -0
  82. package/engine/graphics/texture/atlas/AbstractTextureAtlas.js +19 -0
  83. package/engine/graphics/texture/atlas/CachingTextureAtlas.js +99 -0
  84. package/engine/graphics/texture/atlas/ManagedTextureAtlas.js +19 -39
  85. package/engine/graphics/texture/atlas/ReferencedTextureAtlas.js +75 -0
  86. package/engine/graphics/texture/atlas/TextureAtlas.js +22 -2
  87. package/engine/reference/v2/Reference.d.ts +4 -0
  88. package/engine/reference/v2/Reference.js +3 -1
  89. package/package.json +2 -1
  90. package/view/elements/ColorPickerView.js +2 -1
@@ -96,16 +96,24 @@ export class ActionProcessor {
96
96
  }
97
97
 
98
98
  /**
99
- * Drop records beyond a given limit. records are dropped in batches between marks.
99
+ * Remove all of the history
100
+ */
101
+ clear() {
102
+ // drop all of the history
103
+ this.dropHistory(Infinity);
104
+ }
105
+
106
+ /**
107
+ * Drop number of records from the history
100
108
  *
101
109
  * NOTE valid use-cases for this method from the outside are: 1) memory management and 1) removing access to a set of previous actions
102
110
  * NOTE this method is used internally by {@link #mark} method
103
111
  *
104
112
  * @example if there are 2 marks A at record 9 and B at record 11, and requested limit is 10 - 9 records will be kept as records 10 and 11 belong to the same batch and will be removed together.
105
- * @param {number} limit maximum number of records to keep
113
+ * @param {number} drop_count maximum number of records to drop
106
114
  */
107
- dropHistory(limit) {
108
- const recordsToDrop = Math.min(limit, this.history.length);
115
+ dropHistory(drop_count) {
116
+ const recordsToDrop = Math.min(drop_count, this.history.length);
109
117
  if (recordsToDrop <= 0) {
110
118
  return;
111
119
  }
@@ -136,6 +144,9 @@ export class ActionProcessor {
136
144
 
137
145
  // dispatch signal
138
146
  dropped_marks.forEach(this.onMarkRemoved.send1, this.onMarkRemoved);
147
+
148
+ // update history
149
+
139
150
  }
140
151
 
141
152
  /**
@@ -2,11 +2,11 @@ import Tool from "./engine/Tool.js";
2
2
  import Vector1 from "../../core/geom/Vector1.js";
3
3
  import { obtainTerrain } from "../../../model/game/scenes/SceneUtils.js";
4
4
  import ObservedValue from "../../core/model/ObservedValue.js";
5
- import { parseHex } from "../../core/color/ColorUtils.js";
6
5
  import Vector4 from "../../core/geom/Vector4.js";
7
6
  import loadSampler2D from "../../engine/graphics/texture/sampler/loadSampler2D.js";
8
7
  import convertSampler2D2Canvas from "../../engine/graphics/texture/sampler/Sampler2D2Canvas.js";
9
8
  import { InstancedMeshComponent } from "../../engine/ecs/foliage/ecs/InstancedMeshComponent.js";
9
+ import { parseHex } from "../../core/color/parseHex.js";
10
10
 
11
11
  class FoliagePaintTool extends Tool {
12
12
  constructor() {
@@ -3,7 +3,6 @@ import GridPosition from "../../engine/grid/components/GridPosition.js";
3
3
  import GridObstacle from "../../engine/grid/components/GridObstacle.js";
4
4
  import { pick } from "../../../model/game/util/ScreenGridPicker.js";
5
5
  import Vector4 from "../../core/geom/Vector4.js";
6
- import { parseHex } from "../../core/color/ColorUtils.js";
7
6
  import ObservedValue from "../../core/model/ObservedValue.js";
8
7
  import Vector1 from "../../core/geom/Vector1.js";
9
8
  import WriteGridValueAction from "../actions/concrete/WriteGridValueAction.js";
@@ -12,6 +11,7 @@ import PaintTerrainOverlayAction from "../actions/concrete/PaintTerrainOverlayAc
12
11
  import { decodeMouseEventButtons, PointerDevice } from "../../engine/input/devices/PointerDevice.js";
13
12
  import Vector2 from "../../core/geom/Vector2.js";
14
13
  import TopDownCameraControllerSystem from "../../engine/graphics/ecs/camera/topdown/TopDownCameraControllerSystem.js";
14
+ import { parseHex } from "../../core/color/parseHex.js";
15
15
 
16
16
  class GridPaintTool extends Tool {
17
17
  constructor() {
@@ -337,16 +337,12 @@ export class GLTFAssetLoader extends AssetLoader {
337
337
  return;
338
338
  }
339
339
 
340
- //find a child that is a mesh
341
- const meshes = scene.children.filter(isMesh);
342
340
 
343
- let root;
341
+ let root = scene;
344
342
 
345
- if (meshes.length !== 1) {
346
- //use the whole scene
347
- root = scene;
348
- } else {
349
- root = meshes[0];
343
+ if (children.length === 1 && isMesh(children[0])) {
344
+ // scene only contains a single mesh, use that directly
345
+ root = children[0];
350
346
  }
351
347
 
352
348
  traverseThreeObject(root, this.__prepareObjectMaterial, this);
@@ -1,3 +1,26 @@
1
- export class System {
1
+ import {EntityManager} from "./EntityManager";
2
2
 
3
+ interface Type<T> extends Function {
4
+ new(...args: any[]): T;
5
+ }
6
+
7
+ export class System<A, B = void, C = void, D = void, E = void> {
8
+ dependencies: Type<any>[]
9
+
10
+ startup(em: EntityManager, ready_callback: () => void, error_callback: () => void): void
11
+
12
+ shutdown(em: EntityManager, ready_callback: () => void, error_callback: () => void): void
13
+
14
+ link(a: A, entity: number): void
15
+ link(a: A, b: B, entity: number): void
16
+ link(a: A, b: B, c: C, entity: number): void
17
+ link(a: A, b: B, c: C, d: D, entity: number): void
18
+ link(a: A, b: B, c: C, d: D, e: E, entity: number): void
19
+
20
+ unlink(a: A, entity: number): void
21
+ unlink(a: A, b: B, entity: number): void
22
+ unlink(a: A, b: B, c: C, d: D, entity: number): void
23
+ unlink(a: A, b: B, c: C, d: D, e: E, entity: number): void
24
+
25
+ update(time_delta: number): void
3
26
  }
@@ -61,12 +61,29 @@ export class InstancedFoliage {
61
61
  */
62
62
  this.instances = new InstancedMeshGroup();
63
63
 
64
+ /**
65
+ *
66
+ * @type {THREE.BufferGeometry|null}
67
+ */
64
68
  this.geometry = null;
69
+
70
+ /**
71
+ *
72
+ * @type {Vector4|Vector4}
73
+ */
65
74
  this.instanceBoundingSphere = new Vector4(0, 0, 0, 0);
66
75
 
67
76
 
77
+ /**
78
+ *
79
+ * @type {ThreeFrustumsIntersectionBVHVisitor}
80
+ */
68
81
  this.bvhVisibilityVisitor = new ThreeFrustumsIntersectionBVHVisitor();
69
82
 
83
+ /**
84
+ *
85
+ * @type {FoliageVisibilitySetBuilder}
86
+ */
70
87
  this.visibilitySetBuilder = new FoliageVisibilitySetBuilder();
71
88
  this.bvhVisibilityVisitor.collector = this.visibilitySetBuilder;
72
89
 
@@ -84,6 +101,10 @@ export class InstancedFoliage {
84
101
  this.__garbagePointer = 0;
85
102
  }
86
103
 
104
+ /**
105
+ *
106
+ * @returns {number}
107
+ */
87
108
  hash() {
88
109
  return this.data.hash();
89
110
  }
@@ -95,6 +116,25 @@ export class InstancedFoliage {
95
116
 
96
117
  }
97
118
 
119
+ /**
120
+ *
121
+ * @param {SurfacePoint3} contact
122
+ * @param {number} origin_x
123
+ * @param {number} origin_y
124
+ * @param {number} origin_z
125
+ * @param {number} direction_x
126
+ * @param {number} direction_y
127
+ * @param {number} direction_z
128
+ * @returns {number} index of the contact instance, or -1 if no hit found
129
+ */
130
+ raypick(
131
+ contact,
132
+ origin_x, origin_y, origin_z,
133
+ direction_x, direction_y, direction_z
134
+ ) {
135
+ throw new Error('Not implemented');
136
+ }
137
+
98
138
  dispose() {
99
139
  this.instances.dispose();
100
140
  }
@@ -212,6 +252,11 @@ export class InstancedFoliage {
212
252
  this.instanceBoundingSphere = computeGeometryBoundingSphereMiniball(this.geometry);
213
253
  }
214
254
 
255
+ /**
256
+ *
257
+ * @param {BufferGeometry} geometry
258
+ * @param {Material} material
259
+ */
215
260
  setInstance(geometry, material) {
216
261
  if (material === undefined) {
217
262
  throw new Error(`Material is undefined`);
@@ -40,6 +40,10 @@ export class InstancedMeshLayer {
40
40
  this.data.dispose();
41
41
  }
42
42
 
43
+ /**
44
+ *
45
+ * @returns {number}
46
+ */
43
47
  hash() {
44
48
 
45
49
  return computeHashIntegerArray(
@@ -5,6 +5,48 @@ import { COMPONENT_SERIALIZATION_TRANSIENT_FIELD } from "./COMPONENT_SERIALIZATI
5
5
  import { currentTimeInSeconds } from "../../Clock.js";
6
6
  import { BinaryObjectSerializationAdapter } from "./binary/object/BinaryObjectSerializationAdapter.js";
7
7
 
8
+ /**
9
+ * @template T
10
+ * @param {Class<T>|constructor|function|{serializable?:boolean}} componentClass
11
+ * @returns {boolean}
12
+ */
13
+ function isComponentClassSerializable(componentClass) {
14
+ return componentClass.serializable !== false;
15
+ }
16
+
17
+ /**
18
+ * Whether or not an entity should be serialized at all
19
+ * @param {number} entity
20
+ * @param {EntityComponentDataset} dataset
21
+ * @param {number} smComponentIndex
22
+ * @param {Object} componentInstance
23
+ * @returns {boolean}
24
+ */
25
+ function isEntityTransient(entity, dataset, smComponentIndex, componentInstance) {
26
+ if (smComponentIndex === -1) {
27
+ return false;
28
+ }
29
+
30
+ //check component instance flag
31
+ if (componentInstance[COMPONENT_SERIALIZATION_TRANSIENT_FIELD] === true) {
32
+ return true;
33
+ }
34
+
35
+
36
+ /**
37
+ *
38
+ * @type {SerializationMetadata}
39
+ */
40
+ const serializationMetadata = dataset.getComponentByIndex(entity, smComponentIndex);
41
+
42
+ if (serializationMetadata === undefined) {
43
+ return false;
44
+ }
45
+
46
+ const isTransient = serializationMetadata.getFlag(SerializationFlags.Transient);
47
+
48
+ return isTransient;
49
+ }
8
50
 
9
51
  class BinaryBufferSerialization {
10
52
  constructor() {
@@ -27,9 +69,8 @@ class BinaryBufferSerialization {
27
69
 
28
70
  const smComponentIndex = dataset.computeComponentTypeIndex(SerializationMetadata);
29
71
 
30
- const serializableComponentTypes = dataset.getComponentTypeMap().filter(function (componentClass) {
31
- return componentClass.serializable !== false;
32
- });
72
+ // get a list of serializable component classes
73
+ const serializableComponentTypes = dataset.getComponentTypeMap().filter(isComponentClassSerializable);
33
74
 
34
75
  const numSerializableTypes = serializableComponentTypes.length;
35
76
 
@@ -59,6 +100,9 @@ class BinaryBufferSerialization {
59
100
 
60
101
  const className = componentType.typeName;
61
102
 
103
+ if (className === undefined) {
104
+ throw new Error(`Component type has no .typeName property`);
105
+ }
62
106
 
63
107
  collectionSerializer.setClass(className);
64
108
  collectionSerializer.initialize({
@@ -83,7 +127,7 @@ class BinaryBufferSerialization {
83
127
  return;
84
128
  }
85
129
 
86
- assert.ok(entity >= lastEntity, `entity(=${entity}) < lastEntity(=${lastEntity})`)
130
+ assert.ok(entity >= lastEntity, `entity[=${entity}] < lastEntity[=${lastEntity}]`);
87
131
 
88
132
  //write only the entity step
89
133
  const step = entity - lastEntity;
@@ -127,38 +171,4 @@ class BinaryBufferSerialization {
127
171
  }
128
172
  }
129
173
 
130
- /**
131
- * Whether or not an entity should be serialized at all
132
- * @param {number} entity
133
- * @param {EntityComponentDataset} dataset
134
- * @param {number} smComponentIndex
135
- * @param {Object} componentInstance
136
- * @returns {boolean}
137
- */
138
- function isEntityTransient(entity, dataset, smComponentIndex, componentInstance) {
139
- if (smComponentIndex === -1) {
140
- return false;
141
- }
142
-
143
- //check component instance flag
144
- if (componentInstance[COMPONENT_SERIALIZATION_TRANSIENT_FIELD] === true) {
145
- return true;
146
- }
147
-
148
-
149
- /**
150
- *
151
- * @type {SerializationMetadata}
152
- */
153
- const serializationMetadata = dataset.getComponentByIndex(entity, smComponentIndex);
154
-
155
- if (serializationMetadata === undefined) {
156
- return false;
157
- }
158
-
159
- const isTransient = serializationMetadata.getFlag(SerializationFlags.Transient);
160
-
161
- return isTransient;
162
- }
163
-
164
174
  export default BinaryBufferSerialization;
@@ -88,7 +88,7 @@ export class BinaryCollectionSerializer {
88
88
  * @param {string} className
89
89
  */
90
90
  setClass(className) {
91
- assert.typeOf(className, 'string', 'className');
91
+ assert.isString(className, 'className');
92
92
 
93
93
  this.className = className;
94
94
  }
@@ -10,8 +10,8 @@ import SVG from "../../../../../view/SVG.js";
10
10
  import Vector2 from "../../../../../core/geom/Vector2.js";
11
11
  import Vector4 from "../../../../../core/geom/Vector4.js";
12
12
  import { MersenneTwister } from "../../../../../core/math/random/MersenneTwister.js";
13
- import { hsv2rgb } from "../../../../../core/color/ColorUtils.js";
14
13
  import { arrayPickBestElement } from "../../../../../core/collection/array/arrayPickBestElement.js";
14
+ import { hsv2rgb } from "../../../../../core/color/hsv2rgb.js";
15
15
 
16
16
  function removeAllChildren(node) {
17
17
  const children = node.children;
@@ -581,7 +581,7 @@ class TerrainTile {
581
581
  mesh.geometry = g;
582
582
 
583
583
  mesh.receiveShadow = true;
584
- mesh.castShadow = false;
584
+ mesh.castShadow = true;
585
585
 
586
586
  // console.timeEnd('total');
587
587
  // console.groupEnd();
@@ -97,6 +97,9 @@ function GraphicsEngine(camera, entityManger) {
97
97
  preRender: new Signal(),
98
98
  postRender: new Signal(),
99
99
 
100
+ preOpaquePass: new Signal(),
101
+ postOpaquePass : new Signal(),
102
+
100
103
  /**
101
104
  * @deprecated
102
105
  */
@@ -558,6 +561,8 @@ GraphicsEngine.prototype.prepareRenderPass = function (passType) {
558
561
  * Renders opaque assets
559
562
  */
560
563
  GraphicsEngine.prototype.renderOpaque = function () {
564
+ this.on.preOpaquePass.send0();
565
+
561
566
  this.prepareRenderPass(RenderPassType.Opaque);
562
567
 
563
568
  const renderer = this.renderer;
@@ -570,6 +575,8 @@ GraphicsEngine.prototype.renderOpaque = function () {
570
575
  const frameBuffer = buffers.getById(StandardFrameBuffers.ColorAndDepth);
571
576
 
572
577
  renderTextureToScreenQuad(frameBuffer.renderTarget.texture, renderer);
578
+
579
+ this.on.postOpaquePass.send0();
573
580
  };
574
581
 
575
582
  /**
@@ -1,5 +1,5 @@
1
1
  import { LightBinding } from "../LightBinding.js";
2
- import { PointLight } from "../../../../render/forward_plus/PointLight.js";
2
+ import { PointLight } from "../../../../render/forward_plus/model/PointLight.js";
3
3
 
4
4
  export class FPLightBinding extends LightBinding {
5
5
  constructor() {
@@ -252,8 +252,8 @@ class Mesh {
252
252
 
253
253
  fromJSON({
254
254
  url = null,
255
- castShadow = false,
256
- receiveShadow = false,
255
+ castShadow = true,
256
+ receiveShadow = true,
257
257
  opacity = 1
258
258
  }) {
259
259
  this.url = url;
@@ -167,3 +167,16 @@ export class ShadedGeometry {
167
167
  this.updateTransform();
168
168
  }
169
169
  }
170
+
171
+ /**
172
+ * @readonly
173
+ * @type {string}
174
+ */
175
+ ShadedGeometry.typeName = 'ShadedGeometry';
176
+
177
+ /**
178
+ * TODO add serialization support
179
+ * @readonly
180
+ * @type {boolean}
181
+ */
182
+ ShadedGeometry.serializable = false;