@woosh/meep-engine 2.33.26 → 2.33.27

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 (52) hide show
  1. package/core/binary/BitSet.js +151 -167
  2. package/core/binary/BitSet.spec.js +99 -1
  3. package/core/binary/ValidatingBitSetWrapper.js +81 -0
  4. package/core/bvh2/aabb3/AABB3.js +3 -10
  5. package/core/cache/Cache.d.ts +4 -2
  6. package/core/cache/Cache.js +5 -2
  7. package/core/collection/HashMap.d.ts +9 -2
  8. package/core/collection/HashSet.d.ts +7 -2
  9. package/core/collection/HashSet.js +7 -2
  10. package/core/collection/array/typed/typed_array_copy.js +1 -1
  11. package/core/geom/3d/frustum/array_setFromProjectionMatrix.js +3 -3
  12. package/core/parser/simple/Token.d.ts +13 -0
  13. package/core/parser/simple/Token.js +61 -27
  14. package/editor/tools/FoliagePaintTool.js +4 -4
  15. package/engine/asset/loaders/GLTFAssetLoader.js +52 -1
  16. package/engine/asset/loaders/image/ImageDecoderWorker.js +4 -3
  17. package/engine/asset/loaders/image/ImageRGBADataAsset.js +3 -2
  18. package/engine/asset/loaders/image/ImageRGBADataLoader.js +3 -3
  19. package/engine/asset/loaders/image/codec/NativeImageDecoder.js +2 -1
  20. package/engine/asset/loaders/image/png/PNG.js +113 -6
  21. package/engine/asset/loaders/image/png/PNGReader.js +5 -0
  22. package/engine/asset/loaders/material/bitmap2sampler_gl.js +1 -1
  23. package/engine/asset/loaders/material/computeImageBitmapEquality.js +6 -1
  24. package/engine/asset/loaders/material/computeTextureEquality.js +40 -49
  25. package/engine/ecs/EntityComponentDataset.js +1 -1
  26. package/engine/ecs/foliage/InstancedFoliage.js +277 -266
  27. package/engine/ecs/foliage/ecs/Foliage2System.js +7 -7
  28. package/engine/ecs/foliage/ecs/InstancedMeshComponent.js +37 -0
  29. package/engine/ecs/foliage/ecs/{Foliage2.js → InstancedMeshLayer.js} +3 -45
  30. package/engine/ecs/foliage/ecs/InstancedMeshSerializationAdapter.js +6 -5
  31. package/engine/ecs/foliage/ecs/InstancedMeshUtils.js +7 -6
  32. package/engine/ecs/storage/binary/BinarySerializationRegistry.js +1 -1
  33. package/engine/ecs/terrain/ecs/layers/TerrainLayer.js +12 -16
  34. package/engine/graphics/geometry/instancing/InstancedMeshGroup.js +14 -72
  35. package/engine/graphics/geometry/instancing/rewriteMaterial.js +70 -0
  36. package/engine/graphics/material/manager/MaterialManager.js +2 -1
  37. package/engine/graphics/micron/render/instanced/AttributeDataTexture.js +6 -4
  38. package/engine/graphics/micron/render/instanced/ThreeInstancedAdapter.js +0 -2
  39. package/engine/graphics/particles/particular/engine/shader/ShaderManager.js +1 -2
  40. package/engine/graphics/particles/particular/engine/shader/debugAtlas.js +1 -1
  41. package/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +5 -2
  42. package/engine/graphics/render/buffer/simple-fx/ao/AmbientOcclusionPostProcessEffect.js +3 -4
  43. package/engine/graphics/render/forward_plus/materials/FPlusDebugMaterial.js +3 -3
  44. package/engine/graphics/render/forward_plus/materials/ForwardPlusThreeMaterial.js +1 -1
  45. package/engine/graphics/render/forward_plus/prototypeLightManager.js +4 -4
  46. package/engine/graphics/render/forward_plus/query/point_light_inside_volume.js +10 -9
  47. package/engine/graphics/texture/atlas/ManagedTextureAtlas.js +12 -1
  48. package/engine/graphics/texture/sampler/Sampler2D.js +3 -1
  49. package/engine/graphics/texture/sampler/convertTexture2Sampler2D.js +1 -1
  50. package/engine/graphics/texture/sampler/copy_Sampler2D_channel_data.js +66 -0
  51. package/package.json +1 -1
  52. package/view/minimap/gl/MinimapWorldGL.js +12 -5
@@ -5,12 +5,23 @@ export function PNG() {
5
5
  // initialize all members to keep the same hidden class
6
6
  this.width = 0;
7
7
  this.height = 0;
8
+
9
+ /**
10
+ * Number of bits per channel?
11
+ * @type {number}
12
+ */
8
13
  this.bitDepth = 0;
14
+
9
15
  this.colorType = 0;
10
16
  this.compressionMethod = 0;
11
17
  this.filterMethod = 0;
12
18
  this.interlaceMethod = 0;
13
19
 
20
+ /**
21
+ * Number of channels in the image
22
+ * @example RGB = 3, RGBA = 4, etc.
23
+ * @type {number}
24
+ */
14
25
  this.colors = 0;
15
26
  this.alpha = false;
16
27
  this.pixelBits = 0;
@@ -23,6 +34,10 @@ export function PNG() {
23
34
  */
24
35
  this.pixels = null;
25
36
 
37
+ /**
38
+ * Transparency palette
39
+ * @type {Uint8Array|null}
40
+ */
26
41
  this.trns = null;
27
42
 
28
43
  }
@@ -138,6 +153,10 @@ PNG.prototype.setInterlaceMethod = function (interlaceMethod) {
138
153
  this.interlaceMethod = interlaceMethod;
139
154
  };
140
155
 
156
+ /**
157
+ *
158
+ * @param {Uint8Array} trns
159
+ */
141
160
  PNG.prototype.setTRNS = function (trns) {
142
161
  this.trns = trns;
143
162
  };
@@ -161,7 +180,9 @@ PNG.prototype.getPalette = function () {
161
180
  * result is an array: [red, green, blue, alpha]
162
181
  */
163
182
  PNG.prototype.getPixel = function (result, result_offset, x, y) {
164
- if (!this.pixels) {
183
+ var pixels = this.pixels;
184
+
185
+ if (!pixels) {
165
186
  throw new Error("pixel data is empty");
166
187
  }
167
188
 
@@ -170,7 +191,6 @@ PNG.prototype.getPixel = function (result, result_offset, x, y) {
170
191
  }
171
192
 
172
193
  var i = this.colors * this.bitDepth / 8 * (y * this.width + x);
173
- var pixels = this.pixels;
174
194
 
175
195
  let r, g, b, a;
176
196
 
@@ -189,14 +209,17 @@ PNG.prototype.getPixel = function (result, result_offset, x, y) {
189
209
  break;
190
210
  case 3:
191
211
  a = 255;
192
- if (this.trns != null && this.trns[pixels[i]] != null) {
212
+
213
+ if (this.trns != null) {
193
214
  a = this.trns[pixels[i]];
194
215
  }
216
+
195
217
  const offset = pixels[i] * 3;
196
218
 
197
- r = this.palette[offset];
198
- g = this.palette[offset + 1];
199
- b = this.palette[offset + 2];
219
+ const palette = this.palette;
220
+ r = palette[offset];
221
+ g = palette[offset + 1];
222
+ b = palette[offset + 2];
200
223
 
201
224
  break;
202
225
  case 4:
@@ -293,3 +316,87 @@ PNG.prototype.getRGBA8Array = function () {
293
316
 
294
317
  return data;
295
318
  };
319
+
320
+ PNG.prototype.getUint8Data_case3 = function () {
321
+ const w = this.width;
322
+ const h = this.height;
323
+
324
+ const pixel_count = w * h;
325
+
326
+ let itemSize;
327
+
328
+ const transparency_lookup = this.trns;
329
+ if (transparency_lookup !== null) {
330
+ // has transparency
331
+ itemSize = 4;
332
+ } else {
333
+ itemSize = 3;
334
+ }
335
+
336
+ const result_data = new Uint8Array(pixel_count * itemSize);
337
+
338
+ const pixels = this.pixels;
339
+ const palette = this.palette;
340
+
341
+ const d = this.colors * this.bitDepth / 8;
342
+
343
+ for (let i = 0; i < pixel_count; i++) {
344
+ const destination_address = i * itemSize;
345
+
346
+ const lookup_value = pixels[i * d];
347
+
348
+ result_data[destination_address] = palette[lookup_value];
349
+ result_data[destination_address + 1] = palette[lookup_value + 1];
350
+ result_data[destination_address + 2] = palette[lookup_value + 2];
351
+ }
352
+
353
+ //transparency
354
+ if (transparency_lookup !== null) {
355
+ for (let i = 0; i < pixel_count; i++) {
356
+ result_data[i * 4 + 3] = transparency_lookup[pixels[i * d]];
357
+ }
358
+ }
359
+
360
+ return {
361
+ data: result_data,
362
+ itemSize: itemSize
363
+ }
364
+ }
365
+
366
+ /**
367
+ * @returns {{itemSize:number, data:Uint8Array}}
368
+ */
369
+ PNG.prototype.getUint8Data = function () {
370
+ let data;
371
+ let itemSize = 0; // note, can take this from this.colors
372
+
373
+ switch (this.colorType) {
374
+ case 0:
375
+ data = this.pixels;
376
+ itemSize = 1;
377
+ break;
378
+ case 2:
379
+ data = this.pixels;
380
+ itemSize = 3;
381
+ break;
382
+ case 3:
383
+ // palette
384
+ return this.getUint8Data_case3();
385
+ case 4:
386
+ // grayscale with alpha
387
+ data = this.pixels;
388
+ itemSize = 2;
389
+ break;
390
+ case 6:
391
+ data = this.pixels;
392
+ itemSize = 4;
393
+ break;
394
+ default:
395
+ throw new Error('Unsupported color type');
396
+ }
397
+
398
+ return {
399
+ data,
400
+ itemSize
401
+ };
402
+ };
@@ -91,6 +91,10 @@ PNGReader.prototype.decodeChunk = function () {
91
91
 
92
92
  const type = buffer.readASCIICharacters(4);
93
93
 
94
+ /**
95
+ *
96
+ * @type {Uint8Array}
97
+ */
94
98
  var chunk = this.readBytes(length);
95
99
 
96
100
  // checksum
@@ -161,6 +165,7 @@ PNGReader.prototype.decodeIDAT = function (chunk) {
161
165
 
162
166
  /**
163
167
  * https://www.w3.org/TR/PNG/#11tRNS
168
+ * @param {Uint8Array} chunk
164
169
  */
165
170
  PNGReader.prototype.decodeTRNS = function (chunk) {
166
171
  this.png.setTRNS(chunk);
@@ -1,5 +1,5 @@
1
1
  /**
2
- *
2
+ * Transfer bitmap contents to Sampler2D, effectively moving data to CPU, making it readable
3
3
  * @param {WebGL2RenderingContext} gl
4
4
  * @param {Sampler2D} sampler
5
5
  * @param {ImageBitmap} bitmap
@@ -40,7 +40,7 @@ function obtainSampler(bitmap, ctx) {
40
40
  }
41
41
 
42
42
  /**
43
- *
43
+ * Ref holding webgl context, being weak-ref, allows context to be removed when not in use
44
44
  * @type {WeakRef<WebGL2RenderingContext>|null}
45
45
  */
46
46
  let ctx_ref = null;
@@ -97,8 +97,13 @@ export function sampler_from_bitmap(bitmap) {
97
97
  * @returns {boolean}
98
98
  */
99
99
  export function computeImageBitmapEquality(a, b) {
100
+ if (a === b) {
101
+ // strict equality check, special case
102
+ return true;
103
+ }
100
104
 
101
105
  if (a.width !== b.width || a.height !== b.height) {
106
+ // check dimensions
102
107
  return false;
103
108
  }
104
109
 
@@ -1,4 +1,5 @@
1
1
  import { computeImageBitmapEquality } from "./computeImageBitmapEquality.js";
2
+ import { isArrayEqualStrict } from "../../../../core/collection/array/isArrayEqualStrict.js";
2
3
 
3
4
  //
4
5
 
@@ -50,20 +51,10 @@ export function computeTextureEquality(a, b) {
50
51
  const aMipmaps = a.mipmaps;
51
52
  const bMipmaps = b.mipmaps;
52
53
 
53
- const n = aMipmaps.length;
54
-
55
- if (n !== bMipmaps.length) {
54
+ if (!textureMipChainEqual(aMipmaps, bMipmaps)) {
56
55
  return false;
57
56
  }
58
57
 
59
- for (let i = 0; i < n; i++) {
60
- const aMipmap = aMipmaps[i];
61
- const bMipmap = bMipmaps[i];
62
-
63
- if (!textureMipmapEqual(aMipmap, bMipmap)) {
64
- return false;
65
- }
66
- }
67
58
  }
68
59
 
69
60
  //TODO implement support for other texture types
@@ -119,47 +110,52 @@ export function textureImagesEqual(a, b) {
119
110
  const bMipmaps = bi.mipmaps;
120
111
 
121
112
  //TODO should we ignore mipmaps if they are absent?
122
- if (aMipmaps === undefined) {
123
- if (bMipmaps === undefined) {
124
- continue;
125
- } else {
126
- return false;
127
- }
128
- } else if (bMipmaps === undefined) {
113
+ if (!textureMipChainEqual(aMipmaps, bMipmaps)) {
129
114
  return false;
130
115
  }
116
+ }
117
+
118
+ }
131
119
 
132
- for (let j = 0; j < aMipmaps.length; j++) {
133
- const aMipmap = aMipmaps[j];
134
- const bMipmap = bMipmaps[j];
120
+ // assume equivalent
121
+ return true;
122
+ }
123
+
124
+ /**
125
+ *
126
+ * @param {[]} a
127
+ * @param {[]} b
128
+ * @returns {boolean}
129
+ */
130
+ function textureMipChainEqual(a, b) {
131
+ if (a === undefined) {
132
+ if (b === undefined) {
133
+ return true;
134
+ } else {
135
+ return false;
136
+ }
137
+ } else if (b === undefined) {
138
+ return false;
139
+ }
135
140
 
136
- /**
137
- * @type {Uint8Array}
138
- */
139
- const aData = aMipmap.data;
141
+ const a_length = a.length;
140
142
 
141
- /**
142
- * @type {Uint8Array}
143
- */
144
- const bData = bMipmap.data;
143
+ if (a_length !== b.length) {
144
+ // different mip chain length
145
+ return false;
146
+ }
145
147
 
146
- const dataLength = aData.length;
147
- if (dataLength !== bData.length) {
148
- return false;
149
- }
148
+ for (let j = a_length - 1; j >= 0; j--) { //traverse chain top to bottom, starting from smallest mip for faster rejection
150
149
 
150
+ const aMipmap = a[j];
151
+ const bMipmap = b[j];
151
152
 
152
- for (let k = 0; k < dataLength; k++) {
153
- if (aData[k] !== bData[k]) {
154
- return false;
155
- }
156
- }
157
- }
153
+ if (!textureMipmapEqual(aMipmap, bMipmap)) {
154
+ return false;
158
155
  }
159
156
 
160
157
  }
161
158
 
162
- // assume equivalent
163
159
  return true;
164
160
  }
165
161
 
@@ -182,16 +178,11 @@ function textureMipmapEqual(a, b) {
182
178
  const aData = a.data;
183
179
  const bData = b.data;
184
180
 
185
- const n = aData.length;
186
- if (bData.length !== n) {
187
- return false;
188
- }
189
181
 
190
- for (let i = 0; i < n; i++) {
191
- if (aData[i] !== bData[i]) {
192
- return false;
193
- }
182
+ if (aData === bData) {
183
+ // special case
184
+ return true;
194
185
  }
195
186
 
196
- return true;
187
+ return isArrayEqualStrict(aData, bData);
197
188
  }
@@ -1212,7 +1212,7 @@ export class EntityComponentDataset {
1212
1212
 
1213
1213
  if (!ENV_PRODUCTION) {
1214
1214
  assert.isNumber(componentTypeIndex, "componentTypeIndex");
1215
- assert.typeOf(visitor, "function", "visitor");
1215
+ assert.isFunction(visitor, "visitor");
1216
1216
  }
1217
1217
 
1218
1218