@woosh/meep-engine 2.37.19 → 2.37.20

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 (110) hide show
  1. package/core/binary/float2uint8.js +8 -0
  2. package/core/binary/uint82float.js +8 -0
  3. package/core/bvh2/bvh3/ExplicitBinaryBoundingVolumeHierarchy.js +6 -4
  4. package/core/collection/list/List.d.ts +1 -1
  5. package/core/color/Color.js +69 -1
  6. package/core/color/YCbCr_to_rgb_uint24.js +3 -4
  7. package/core/color/hsv2rgb.js +4 -3
  8. package/core/color/linear_to_sRGB.js +4 -5
  9. package/core/color/rgb2uint24.js +6 -4
  10. package/core/color/rgb_to_YCbCr_uint24.js +11 -13
  11. package/core/events/signal/Signal.d.ts +11 -9
  12. package/core/geom/2d/quad-tree/qt_collect_by_circle.js +67 -0
  13. package/core/geom/Quaternion.d.ts +16 -1
  14. package/core/geom/Quaternion.js +129 -65
  15. package/core/geom/Quaternion.spec.js +24 -0
  16. package/core/geom/Vector2.js +3 -3
  17. package/core/geom/Vector3.d.ts +2 -0
  18. package/core/geom/Vector3.js +31 -7
  19. package/core/geom/Vector4.js +16 -0
  20. package/core/math/bell_membership_function.js +19 -0
  21. package/core/math/exp2.js +8 -0
  22. package/core/math/interval/NumericInterval.js +17 -0
  23. package/core/math/physics/brdf/brdf_burley.js +25 -0
  24. package/core/math/physics/bsdf/bsdf_schlick.js +22 -0
  25. package/core/math/physics/irradiance/interpolate_irradiance_linear.js +18 -0
  26. package/{engine/sound/ecs/emitter/attenuate/attenuateSoundLogarithmic.js → core/math/physics/irradiance/interpolate_irradiance_lograrithmic.js} +2 -2
  27. package/{engine/sound/ecs/emitter/attenuate/attenuateSoundSmith.js → core/math/physics/irradiance/interpolate_irradiance_smith.js} +1 -1
  28. package/editor/actions/concrete/ModifyPatchSampler2DAction.js +118 -0
  29. package/editor/actions/concrete/ModifyPatchSampler2DAction.spec.js +30 -0
  30. package/editor/actions/concrete/PatchTerrainHeightAction.js +12 -104
  31. package/editor/ecs/component/createObjectEditor.js +53 -29
  32. package/editor/ecs/component/editors/Sampler2DEditor.js +71 -24
  33. package/editor/ecs/component/editors/ecs/terrain/TerrainEditor.js +47 -0
  34. package/editor/ecs/component/editors/primitive/FunctionEditor.js +6 -2
  35. package/editor/tools/SelectionTool.js +1 -1
  36. package/editor/tools/paint/TerrainHeightPaintTool.js +88 -68
  37. package/editor/tools/paint/TerrainPaintTool.js +2 -1
  38. package/editor/tools/paint/TerrainTexturePaintTool.js +8 -73
  39. package/engine/asset/AssetManager.d.ts +1 -1
  40. package/engine/asset/AssetManager.js +390 -388
  41. package/engine/asset/loaders/gltf/extensions/MSFT_texture_dds.js +14 -2
  42. package/engine/ecs/fow/FogOfWarEditor.js +13 -0
  43. package/engine/ecs/terrain/ecs/OffsetScaleTransform2D.d.ts +6 -0
  44. package/engine/ecs/terrain/ecs/Terrain.js +21 -1
  45. package/engine/ecs/terrain/ecs/splat/SplatMapping.js +26 -28
  46. package/engine/ecs/terrain/overlay/TerrainOverlay.js +71 -66
  47. package/engine/ecs/terrain/tiles/TerrainTileManager.js +23 -0
  48. package/engine/ecs/terrain/util/paintTerrainOverlayViaLookupTable.js +13 -7
  49. package/engine/ecs/transform/Transform.d.ts +2 -0
  50. package/engine/ecs/transform/Transform.js +3 -0
  51. package/engine/graphics/ecs/light/Light.js +0 -47
  52. package/engine/graphics/ecs/light/LightSerializationAdapter.js +50 -0
  53. package/engine/graphics/ecs/mesh-v2/DrawMode.js +2 -1
  54. package/engine/graphics/ecs/mesh-v2/build_three_object.js +3 -1
  55. package/engine/graphics/ecs/sprite/Sprite.js +11 -0
  56. package/engine/graphics/ecs/sprite/SpriteSystemPE.js +133 -0
  57. package/engine/graphics/ecs/sprite/prototypeSpriteSystem.js +1566 -0
  58. package/engine/graphics/micron/prototypeVirtualGeometry.js +2 -2
  59. package/engine/graphics/particles/particular/engine/emitter/ParticleLayer.js +17 -9
  60. package/engine/graphics/particles/particular/engine/renderers/ParticleRenderer.js +12 -10
  61. package/engine/graphics/particles/particular/engine/renderers/billboard/ParticleBillboardMaterial.js +7 -2
  62. package/engine/graphics/particles/particular/engine/renderers/billboard/SoftBillboardParticlePool.js +27 -0
  63. package/engine/graphics/particles/particular/engine/renderers/billboard/SoftBillboardParticleRenderer.js +80 -0
  64. package/engine/graphics/particles/particular/engine/shader/ShaderManager.js +16 -4
  65. package/engine/graphics/shaders/TerrainShader.js +8 -8
  66. package/engine/graphics/texture/atlas/TextureAtlasDebugger.js +2 -1
  67. package/engine/graphics/texture/sampler/Sampler2D.js +190 -201
  68. package/engine/graphics/texture/sampler/Sampler2D.spec.js +34 -35
  69. package/engine/graphics/texture/sampler/bicubic.js +59 -0
  70. package/engine/graphics/texture/sampler/downsampleSample2D.spec.js +2 -2
  71. package/engine/graphics/texture/sampler/genericResampleSampler2D.js +0 -2
  72. package/engine/graphics/texture/sampler/prototypeSamplerFiltering.js +146 -0
  73. package/engine/graphics/texture/sampler/{downsampleSampler2D.js → sampler2D_scale_down_linear.js} +8 -4
  74. package/engine/graphics/texture/sampler/sampler2_d_scale_down_lanczos.js +140 -0
  75. package/engine/graphics/texture/sampler/scaleSampler2D.js +3 -3
  76. package/engine/graphics/texture/sampler/writeSampler2DDataToDataTexture.js +1 -1
  77. package/engine/input/ecs/util/TerrainCameraTargetSampler.js +2 -2
  78. package/engine/navigation/ecs/components/computeNonuniformCatmullRomSplineSample.js +117 -0
  79. package/engine/platform/GetURLHash.js +27 -0
  80. package/engine/platform/WebEnginePlatform.js +1 -22
  81. package/engine/sound/ecs/emitter/SoundEmitter.js +10 -6
  82. package/generation/GridGenerator.js +7 -6
  83. package/generation/example/SampleGenerator0.js +6 -6
  84. package/generation/example/filters/SampleGroundMoistureFilter.js +58 -17
  85. package/generation/example/themes/SampleTheme0.js +11 -7
  86. package/generation/filtering/numeric/CellFilterLiteralFloat.js +5 -0
  87. package/generation/filtering/numeric/complex/CellFilterDilate.js +36 -0
  88. package/generation/filtering/numeric/complex/CellFilterGaussianBlur.js +15 -5
  89. package/generation/filtering/numeric/complex/CellFilterSimplexNoise.js +53 -1
  90. package/generation/filtering/numeric/math/CellFilterMax2.js +3 -0
  91. package/generation/filtering/numeric/math/CellFilterMembershipGeneralizedBell.js +55 -0
  92. package/generation/filtering/numeric/sampling/AbstractCellFilterSampleGridLayer.js +42 -0
  93. package/generation/filtering/numeric/sampling/CellFilterSampleLayerCubic.js +36 -0
  94. package/generation/filtering/numeric/sampling/CellFilterSampleLayerLinear.js +41 -0
  95. package/generation/grid/GridData.d.ts +5 -1
  96. package/generation/grid/GridData.js +35 -36
  97. package/generation/grid/MarkerMatchCounter.js +5 -3
  98. package/generation/markers/GridActionRuleSet.js +15 -32
  99. package/generation/markers/GridCellActionPlaceMarker.js +8 -10
  100. package/generation/markers/debug/visualizeMarkers.js +56 -36
  101. package/generation/markers/emitter/MarkerNodeEmitterFromAction.js +8 -8
  102. package/generation/markers/prototypeGridCellActionPlaceMarker.js +209 -0
  103. package/generation/markers/transform/MarkerNodeTransformerOffsetPosition.js +1 -5
  104. package/generation/markers/transform/MarkerNodeTransformerYRotateByFilterGradient.spec.js +2 -2
  105. package/generation/placement/GridCellPlacementRule.js +10 -3
  106. package/package.json +1 -1
  107. package/samples/terrain/from_image.js +7 -3
  108. package/engine/graphics/particles/particular/engine/renderers/SoftBillboardParticleRenderer.js +0 -7
  109. package/engine/sound/ecs/emitter/attenuate/attenuateSoundLinear.js +0 -11
  110. package/generation/filtering/numeric/CellFilterReadGridLayer.js +0 -73
@@ -7,9 +7,84 @@ import { QuadTreeNode } from "../../../core/geom/2d/quad-tree/QuadTreeNode.js";
7
7
  import { Transform } from "../../../engine/ecs/transform/Transform.js";
8
8
  import TransformModifyAction from "../../actions/concrete/TransformModifyAction.js";
9
9
  import EditorEntity from "../../ecs/EditorEntity.js";
10
+ import { uint82float } from "../../../core/binary/uint82float.js";
10
11
 
11
12
  const LIMIT_VALUE = 1000;
12
13
 
14
+ /**
15
+ *
16
+ * @param {Terrain} terrain
17
+ * @param {number} uv_x0
18
+ * @param {number} uv_y0
19
+ * @param {number} uv_x1
20
+ * @param {number} uv_y1
21
+ * @param {Sampler2D} marker
22
+ * @param {number} value_delta
23
+ * @param {number} limitMin
24
+ * @param {number} limitMax
25
+ * @returns {PatchTerrainHeightAction}
26
+ */
27
+ function make_mod_action(terrain, uv_x0, uv_y0, uv_x1, uv_y1, marker, value_delta, limitMin, limitMax) {
28
+
29
+ const heightMap = terrain.samplerHeight;
30
+
31
+ const h_x0 = uv_x0 * heightMap.width;
32
+ const h_x1 = uv_x1 * heightMap.width;
33
+
34
+ const h_y0 = uv_y0 * heightMap.height;
35
+ const h_y1 = uv_y1 * heightMap.height;
36
+
37
+ const x0 = Math.ceil(h_x0);
38
+ const x1 = Math.floor(h_x1);
39
+
40
+ const y0 = Math.ceil(h_y0);
41
+ const y1 = Math.floor(h_y1);
42
+
43
+ const action = new PatchTerrainHeightAction(terrain, x0, y0, (x1 - x0), (y1 - y0));
44
+
45
+ const patch_destination_data = action.patch.data;
46
+
47
+ for (let y = y0; y < y1; y++) {
48
+
49
+ const v = inverseLerp(h_y0, h_y1 - 1, y);
50
+
51
+
52
+ for (let x = x0; x < x1; x++) {
53
+
54
+ const u = inverseLerp(h_x0, h_x1 - 1, x);
55
+
56
+ //Get alpha
57
+ const markerValue = marker.sampleChannelBilinearUV(u, v, 3);
58
+
59
+ const marker_value_normalized = uint82float(markerValue);
60
+
61
+ const source_address = y * heightMap.width + x;
62
+
63
+ const base = heightMap.data[source_address];
64
+
65
+ const patchAddress = (y - y0) * action.patch.width + (x - x0);
66
+
67
+ const targetValue = clamp(base + value_delta, limitMin, limitMax);
68
+
69
+
70
+ const value = lerp(base, targetValue, marker_value_normalized);
71
+
72
+ if (Number.isNaN(value)) {
73
+ // console.warn('.');
74
+
75
+ patch_destination_data[patchAddress] = base;
76
+
77
+ } else {
78
+
79
+ patch_destination_data[patchAddress] = value;
80
+
81
+ }
82
+ }
83
+
84
+ }
85
+ return action;
86
+ }
87
+
13
88
  export class TerrainHeightPaintTool extends TerrainPaintTool {
14
89
 
15
90
  constructor() {
@@ -57,7 +132,7 @@ export class TerrainHeightPaintTool extends TerrainPaintTool {
57
132
  const vS = 1 / (this.terrain.size.y * gridScale);
58
133
 
59
134
  dataset.traverseComponents(Transform, (transform, entity) => {
60
- if(dataset.getComponent(entity, EditorEntity) !== undefined){
135
+ if (dataset.getComponent(entity, EditorEntity) !== undefined) {
61
136
  //it's an editor entity
62
137
  return;
63
138
  }
@@ -91,7 +166,7 @@ export class TerrainHeightPaintTool extends TerrainPaintTool {
91
166
  *
92
167
  * @param {number} timeDelta
93
168
  */
94
- paint(timeDelta) {
169
+ async paint(timeDelta) {
95
170
  const power = this.settings.brushStrength * timeDelta;
96
171
 
97
172
  /**
@@ -100,12 +175,6 @@ export class TerrainHeightPaintTool extends TerrainPaintTool {
100
175
  */
101
176
  const terrain = this.terrain;
102
177
 
103
- /**
104
- *
105
- * @type {Sampler2D}
106
- */
107
- const heightMap = terrain.samplerHeight;
108
-
109
178
  const brushPosition = this.__brushPosition;
110
179
  const brushSize = this.settings.brushSize;
111
180
 
@@ -123,74 +192,17 @@ export class TerrainHeightPaintTool extends TerrainPaintTool {
123
192
  const uv_y0 = uv_y - uv_h / 2;
124
193
  const uv_y1 = uv_y + uv_h / 2;
125
194
 
126
- const h_x0 = uv_x0 * heightMap.width;
127
- const h_x1 = uv_x1 * heightMap.width;
128
-
129
- const h_y0 = uv_y0 * heightMap.height;
130
- const h_y1 = uv_y1 * heightMap.height;
131
-
132
- const x0 = Math.ceil(h_x0);
133
- const x1 = Math.floor(h_x1);
134
-
135
- const y0 = Math.ceil(h_y0);
136
- const y1 = Math.floor(h_y1);
137
195
 
138
196
  const marker = this.settings.marker;
139
197
 
140
198
  const direction = this.modifiers.shift ? -1 : 1;
141
199
 
142
- const speed = power * direction;
143
-
144
- const action = new PatchTerrainHeightAction(terrain, x0, y0, (x1 - x0), (y1 - y0));
200
+ const value_delta = power * direction;
145
201
 
146
202
  const limitMin = this.settings.limitMin;
147
203
  const limitMax = this.settings.limitMax;
148
204
 
149
- for (let y = y0; y < y1; y++) {
150
-
151
- const v = inverseLerp(h_y0, h_y1, y);
152
-
153
-
154
- for (let x = x0; x < x1; x++) {
155
-
156
- const u = inverseLerp(h_x0, h_x1, x);
157
-
158
- //Get alpha
159
- const markerValue = marker.sampleChannelBilinear(u, v, 3);
160
-
161
- const p = markerValue / 256;
162
-
163
- const address = y * heightMap.width + x;
164
-
165
- const base = heightMap.data[address];
166
-
167
- const patchAddress = (y - y0) * action.patch.width + (x - x0);
168
-
169
- const targetValue = clamp(base + speed, limitMin, limitMax);
170
-
171
- if (markerValue === 0) {
172
-
173
- action.patch.data[patchAddress] = base;
174
-
175
- } else {
176
-
177
- const value = lerp(base, targetValue, p);
178
-
179
- if (Number.isNaN(value)) {
180
- console.warn('.');
181
-
182
- action.patch.data[patchAddress] = base;
183
-
184
- } else {
185
-
186
- action.patch.data[patchAddress] = value;
187
-
188
- }
189
- }
190
- }
191
-
192
- }
193
-
205
+ const action = make_mod_action(terrain, uv_x0, uv_y0, uv_x1, uv_y1, marker, value_delta, limitMin, limitMax);
194
206
 
195
207
  this.editor.actions.do(action);
196
208
 
@@ -252,12 +264,20 @@ export class TerrainHeightPaintTool extends TerrainPaintTool {
252
264
  const tX = leaf.x0 * heightSampler.width;
253
265
  const tY = leaf.y0 * heightSampler.height;
254
266
 
255
- const delta = action.computeDelta(tX, tY);
267
+ const action_value = action.patch.sampleChannelBicubic(tX - action.x, tY - action.y, 0);
268
+ const existing_value = heightSampler.sampleChannelBicubic(tY, tY, 0);
269
+
270
+ const delta = action_value - existing_value;
256
271
 
257
272
  if (delta === 0) {
258
273
  continue;
259
274
  }
260
275
 
276
+ if (Number.isNaN(delta)) {
277
+ console.error('Delta is NaN, skipping.', action, tX, tY);
278
+ continue;
279
+ }
280
+
261
281
  const tM = new Transform();
262
282
  tM.copy(transform);
263
283
  tM.position._add(0, delta, 0);
@@ -21,7 +21,7 @@ export class TerrainPaintTool extends Tool {
21
21
  marker.data.fill(255);
22
22
 
23
23
  this.settings.markerColor = new Color(0, 1, 0.8);
24
- this.settings.markerOpacity = new Vector1(0.5);
24
+ this.settings.markerOpacity = new Vector1(1);
25
25
 
26
26
  this.settings.marker = marker;
27
27
  this.settings.brushSize = 5;
@@ -128,6 +128,7 @@ export class TerrainPaintTool extends Tool {
128
128
  const brushSizeX = brushRadius * dx;
129
129
  const brushSizeY = brushRadius * dy;
130
130
 
131
+
131
132
  overlay.paintImage(this.__brushImage, overlayPositionX - brushSizeX, overlayPositionY - brushSizeY, brushSize * dx, brushSize * dy);
132
133
  }
133
134
 
@@ -1,10 +1,9 @@
1
1
  import { clamp } from "../../../core/math/clamp.js";
2
2
  import { inverseLerp } from "../../../core/math/inverseLerp.js";
3
3
  import { TerrainPaintTool } from "./TerrainPaintTool.js";
4
- import { Sampler2D } from "../../../engine/graphics/texture/sampler/Sampler2D.js";
5
- import { PatchTerrainTextureAction } from "../../actions/concrete/PatchTerrainTextureAction.js";
6
4
  import { convertSampler2D2DataURL } from "../../../engine/graphics/texture/sampler/convertSampler2D2DataURL.js";
7
5
  import { obtainTerrain } from "../../../engine/ecs/terrain/util/obtainTerrain.js";
6
+ import { ModifyPatchSampler2DAction } from "../../actions/concrete/ModifyPatchSampler2DAction.js";
8
7
 
9
8
  export class TerrainTexturePaintTool extends TerrainPaintTool {
10
9
  constructor() {
@@ -96,7 +95,6 @@ export class TerrainTexturePaintTool extends TerrainPaintTool {
96
95
  const brushPosition = this.__brushPosition;
97
96
  const brushSize = this.settings.brushSize;
98
97
 
99
-
100
98
  const terrainSize = terrain.size;
101
99
 
102
100
  const terrainHeight = terrainSize.y;
@@ -126,14 +124,12 @@ export class TerrainTexturePaintTool extends TerrainPaintTool {
126
124
  */
127
125
  const weightData = this.__splatMapScratch;
128
126
 
129
-
130
127
  /**
131
128
  *
132
129
  * @type {SplatMapping}
133
130
  */
134
131
  const splat = terrain.splat;
135
132
 
136
- const splatDepth = splat.depth;
137
133
  const splatWidth = splat.size.x;
138
134
  const splatHeight = splat.size.y;
139
135
 
@@ -153,25 +149,17 @@ export class TerrainTexturePaintTool extends TerrainPaintTool {
153
149
 
154
150
  const splatIndex = this.settings.splatIndex;
155
151
 
156
- /**
157
- *
158
- * @type {Sampler2D}
159
- */
160
- const materialSampler = splat.materialSampler;
161
-
162
152
  //create action
163
153
  const patchWidth = x1 - x0;
164
- const patchHeight = y1 - y0;
165
154
 
166
155
  const targetSplatLayerAddress = splatIndex * splatLayerSize;
167
156
 
168
- const action = new PatchTerrainTextureAction(terrain, x0, y0, patchWidth, patchHeight);
169
- action.patchMaterial.copy_sameItemSize(materialSampler, x0, y0, 0, 0, patchWidth, patchHeight);
157
+ const splat_layer_sampler = splat.getLayerWeightSampler(splatIndex);
170
158
 
171
- const patchMaterialData = action.patchMaterial.data;
159
+ const m_action = new ModifyPatchSampler2DAction(splat_layer_sampler, [x0, y0, x1, y1]);
160
+
161
+ const patchMaterialData = m_action.patch.data;
172
162
 
173
- const a4_weight = new Array(4);
174
- const a4_material = new Array(4);
175
163
 
176
164
  for (let y = y0; y < y1; y++) {
177
165
 
@@ -208,68 +196,15 @@ export class TerrainTexturePaintTool extends TerrainPaintTool {
208
196
  weightData[targetSplatLayerAddress + splatTexelIndex] = clampedValue;
209
197
 
210
198
 
211
- for (let i = 0; i < splatDepth; i++) {
212
-
213
- if (i === splatIndex) {
214
- continue;
215
- }
216
-
217
- const address = i * splatLayerSize + splatTexelIndex;
218
-
219
- const v = weightData[address];
220
-
221
- const cV = clamp(v - delta, 0, 255);
222
-
223
- weightData[address] = cV;
224
-
225
- }
226
-
227
- a4_weight.fill(-1);
228
- a4_material.fill(255);
199
+ const patchIndex = ((y - y0) * patchWidth + (x - x0));
229
200
 
230
- //compute materials
231
- for (let i = 0; i < splatDepth; i++) {
232
-
233
- const address = i * splatLayerSize + splatTexelIndex;
234
-
235
- const weight = weightData[address];
236
-
237
- if (weight > a4_weight[3]) {
238
- a4_weight[3] = weight;
239
- a4_material[3] = i;
240
-
241
- for (let j = 3; j >= 0 && weight > a4_weight[j - 1]; j--) {
242
- const tW = a4_weight[j];
243
- const tM = a4_material[j];
244
-
245
- const j1 = j - 1;
246
-
247
- a4_weight[j] = a4_weight[j1];
248
- a4_material[j] = a4_material[j1];
249
-
250
- a4_weight[j1] = tW;
251
- a4_material[j1] = tM;
252
- }
253
-
254
- }
255
-
256
-
257
- }
258
-
259
- const patchIndex4 = ((y - y0) * patchWidth + (x - x0)) * 4;
260
-
261
- patchMaterialData[patchIndex4] = a4_material[0];
262
- patchMaterialData[patchIndex4 + 1] = a4_material[1];
263
- patchMaterialData[patchIndex4 + 2] = a4_material[2];
264
- patchMaterialData[patchIndex4 + 3] = a4_material[3];
201
+ patchMaterialData[patchIndex] = clampedValue;
265
202
  }
266
203
 
267
204
  }
268
205
 
269
206
 
270
- action.readWeights(this.__splatMapScratch, splatWidth, splatHeight);
271
-
272
- this.editor.actions.do(action);
207
+ this.editor.actions.do(m_action);
273
208
  }
274
209
 
275
210
  start() {
@@ -12,7 +12,7 @@ export class AssetManager {
12
12
 
13
13
  clear(): void
14
14
 
15
- registerLoader<T>(type: string, loader: AssetLoader<T>): Promise<void>
15
+ registerLoader<T>(type: string, loader: AssetLoader<T>): Promise<AssetLoader<T>>
16
16
 
17
17
  unregisterLoader(type: string): Promise<void>
18
18