@woosh/meep-engine 2.34.49 → 2.35.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 (51) hide show
  1. package/core/bvh2/BinaryNode.js +19 -35
  2. package/core/bvh2/aabb3/aabb3_intersects_frustum_array.js +5 -5
  3. package/core/bvh2/aabb3_combined_surface_area.js +21 -0
  4. package/core/bvh2/traversal/queryBinaryNode_FrustumIntersections.js +24 -12
  5. package/core/cache/Cache.d.ts +2 -0
  6. package/core/cache/Cache.js +27 -23
  7. package/core/geom/3d/frustum/frustum_from_projection_matrix_array.js +2 -0
  8. package/core/math/max2.js +2 -6
  9. package/core/math/min2.js +2 -6
  10. package/engine/asset/loaders/geometry/geometry/computeGeometryEquality.js +1 -1
  11. package/engine/asset/loaders/geometry/geometry/computeGeometryHash.js +9 -1
  12. package/engine/ecs/EntityComponentDataset.js +7 -2
  13. package/engine/ecs/foliage/ViewState.js +13 -3
  14. package/engine/ecs/parent/EntityNode.js +23 -11
  15. package/engine/ecs/transform/Transform.js +15 -13
  16. package/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +63 -26
  17. package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +63 -3
  18. package/engine/graphics/ecs/mesh-v2/render/AbstractRenderAdapter.js +67 -0
  19. package/engine/graphics/ecs/mesh-v2/render/GenericRendererAdapter.js +48 -0
  20. package/engine/graphics/ecs/mesh-v2/render/InstancedRendererAdapter.js +110 -0
  21. package/engine/graphics/ecs/mesh-v2/render/ShadedGeometryRendererContext.js +98 -0
  22. package/engine/graphics/ecs/mesh-v2/sample/load_gltf.js +5 -0
  23. package/engine/graphics/ecs/mesh-v2/sample/prototypeShadedGeometry.js +23 -5
  24. package/engine/graphics/ecs/mesh-v2/three_object_to_entity_composition.js +8 -3
  25. package/engine/graphics/geometry/instancing/InstancedMeshGroup.js +23 -85
  26. package/engine/graphics/geometry/instancing/rewriteMaterial.js +9 -45
  27. package/engine/graphics/material/optimization/BUFFER_GEOMETRY_UVS.js +10 -0
  28. package/engine/graphics/material/optimization/MaterialDescriptor.js +46 -0
  29. package/engine/graphics/material/optimization/MaterialOptimizationContext.js +470 -201
  30. package/engine/graphics/material/optimization/UvContext.js +18 -0
  31. package/engine/graphics/material/optimization/is_compliant_mesh.js +71 -0
  32. package/engine/graphics/material/optimization/prepare_atlas_texture.js +23 -0
  33. package/engine/graphics/material/optimization/prototypeMaterialOptimizer.js +127 -0
  34. package/engine/graphics/micron/format/MicronGeometryPatch.js +1 -1
  35. package/engine/graphics/micron/format/VirtualGeometry.js +47 -11
  36. package/engine/graphics/micron/format/serialization/MicronGeometryBinarySerializationAdapter.js +16 -0
  37. package/engine/graphics/micron/prototypeVirtualGeometry.js +3 -2
  38. package/engine/graphics/micron/render/VirtualGeometryBuilder.js +5 -7
  39. package/engine/graphics/micron/render/instanced/AttributeDataTexture.js +1 -45
  40. package/engine/graphics/micron/render/instanced/ThreeInstancedAdapter.js +18 -7
  41. package/engine/graphics/micron/render/refinement/RefinementSpec.js +0 -1
  42. package/engine/graphics/micron/render/refinement/get_geometry_patch_cut.js +17 -24
  43. package/engine/graphics/micron/render/v1/MaterialContext.js +3 -2
  44. package/engine/graphics/micron/render/v1/VGThreeRenderer.js +19 -4
  45. package/engine/graphics/render/utils/ThreeBypassRenderer.js +3 -2
  46. package/engine/graphics/texture/normalized_internal_format.js +48 -0
  47. package/engine/graphics/texture/sampler/Sampler2D.js +6 -0
  48. package/engine/graphics/texture/sampler/sampler2d_copy_channel_data.js +25 -0
  49. package/engine/graphics/texture/sampler/scaleSampler2D.js +3 -0
  50. package/engine/graphics/texture/sampler/util/drawSamplerHTML.js +14 -1
  51. package/package.json +1 -1
@@ -16,6 +16,7 @@ const scratch_mvc = new MaterialVertexSpec();
16
16
  export class VGThreeRenderer {
17
17
  constructor() {
18
18
  this.geometry = new VirtualGeometry();
19
+
19
20
  this.builder = new VirtualGeometryBuilder();
20
21
 
21
22
  /**
@@ -158,6 +159,10 @@ export class VGThreeRenderer {
158
159
  const contexts = this.__contexts_array;
159
160
  const context_count = contexts.length;
160
161
 
162
+ /**
163
+ *
164
+ * @type {Map<number, MaterialContext>}
165
+ */
161
166
  const instance_to_ctx = new Map();
162
167
 
163
168
  for (let i = 0; i < context_count; i++) {
@@ -175,18 +180,28 @@ export class VGThreeRenderer {
175
180
  const patches = geometry.patches;
176
181
 
177
182
  for (let i = 0; i < patch_count; i++) {
178
- const patch = patches[i];
183
+ const i3 = i * 3;
184
+
185
+ const instance_id = patches[i3];
186
+ const geometry_id = patches[i3 + 1];
187
+ const patch_id = patches[i3 + 2];
188
+
189
+ const ctx = instance_to_ctx.get(instance_id);
190
+
191
+ const target_address = ctx.__patch_count * 3;
179
192
 
180
- const ctx = instance_to_ctx.get(patch.instance_id);
193
+ ctx.__patches[target_address] = instance_id;
194
+ ctx.__patches[target_address + 1] = geometry_id;
195
+ ctx.__patches[target_address + 2] = patch_id;
181
196
 
182
- ctx.__patches[ctx.__patch_count++] = patch;
197
+ ctx.__patch_count++;
183
198
  }
184
199
 
185
200
  // build each context
186
201
  for (let i = 0; i < context_count; i++) {
187
202
  const ctx = contexts[i];
188
203
 
189
- ctx.build();
204
+ ctx.build(this.geometry);
190
205
  }
191
206
  }
192
207
 
@@ -72,8 +72,9 @@ export class ThreeBypassRenderer {
72
72
 
73
73
  let stack_top = 0;
74
74
  let j = 0;
75
+ let i = 0;
75
76
 
76
- for (let i = 0; i < input_size; i++) {
77
+ for (; i < input_size; i++) {
77
78
  const object3D = input[i];
78
79
 
79
80
  if (input_filter(object3D)) {
@@ -119,7 +120,7 @@ export class ThreeBypassRenderer {
119
120
  const children = object3D.children;
120
121
  const child_count = children.length;
121
122
 
122
- for (let i = 0; i < child_count; i++) {
123
+ for (i = 0; i < child_count; i++) {
123
124
  const child = children[i];
124
125
 
125
126
  stack[stack_top++] = child;
@@ -0,0 +1,48 @@
1
+ import { DataType } from "../../../core/collection/table/DataType.js";
2
+ import { assert } from "../../../core/assert.js";
3
+
4
+ /**
5
+ *
6
+ * @returns {string}
7
+ * @param {DataType} dt
8
+ * @param {number} channel_count
9
+ */
10
+ export function normalized_internal_format(dt, channel_count) {
11
+ assert.isNonNegativeInteger(channel_count, 'channel_count');
12
+
13
+ let suffix = '';
14
+ switch (dt) {
15
+ case DataType.Uint8:
16
+ suffix = '8';
17
+ break;
18
+ case DataType.Int8:
19
+ suffix = '8_SNORM';
20
+ break;
21
+ case DataType.Uint16:
22
+ suffix = '16UI';
23
+ break;
24
+ default:
25
+ throw new Error(`Unsupported data type '${dt}'`);
26
+ }
27
+
28
+ let prefix = '';
29
+
30
+ switch (channel_count) {
31
+ case 1:
32
+ prefix = 'R';
33
+ break;
34
+ case 2:
35
+ prefix = 'RG';
36
+ break;
37
+ case 3:
38
+ prefix = 'RGB';
39
+ break;
40
+ case 4:
41
+ prefix = 'RGBA';
42
+ break;
43
+ default:
44
+ throw new Error(`Unsupported channel count '${channel_count}'`);
45
+ }
46
+
47
+ return prefix + suffix;
48
+ }
@@ -1555,3 +1555,9 @@ Sampler2D.prototype.traverseOrthogonalNeighbours = function (x, y, visitor, this
1555
1555
  }
1556
1556
  };
1557
1557
 
1558
+ /**
1559
+ * @readonly
1560
+ * @type {boolean}
1561
+ */
1562
+ Sampler2D.prototype.isSampler2D = true;
1563
+
@@ -0,0 +1,25 @@
1
+ //
2
+
3
+ /**
4
+ * Copy single channel from one sampler to another
5
+ * @param {Sampler2D} source
6
+ * @param {number} source_channel
7
+ * @param {Sampler2D} destination
8
+ * @param {number} destination_channel
9
+ */
10
+ export function sampler2d_copy_channel_data(source, source_channel, destination, destination_channel) {
11
+ const pixel_count = source.height * source.width;
12
+
13
+ const source_item_size = source.itemSize;
14
+ const destination_item_size = destination.itemSize;
15
+
16
+ const source_data = source.data;
17
+ const destination_data = destination.data;
18
+
19
+ for (let i = 0; i < pixel_count; i++) {
20
+ const address_source = i * source_item_size + source_channel;
21
+ const address_destination = i * destination_item_size + destination_channel;
22
+
23
+ destination_data[address_destination] = source_data[address_source];
24
+ }
25
+ }
@@ -10,6 +10,9 @@ import { genericResampleSampler2D } from "./genericResampleSampler2D.js";
10
10
  * @param {Sampler2D} output
11
11
  */
12
12
  export function scaleSampler2D(input, output) {
13
+ assert.equal(input.isSampler2D, true, 'input.isSampler2D !== true');
14
+ assert.equal(output.isSampler2D, true, 'output.isSampler2D !== true');
15
+
13
16
  const targetItemSize = output.itemSize;
14
17
 
15
18
  assert.equal(input.itemSize, targetItemSize, 'both source and target must have the same number of channels');
@@ -16,7 +16,20 @@ import { typedArrayConstructorByInstance } from "../typedArrayConstructorByInsta
16
16
  export function drawSamplerHTML(parentNode, sampler, x, y, scale, offset, size) {
17
17
 
18
18
 
19
- const target = new Sampler2D(typedArrayConstructorByInstance(sampler.data), sampler.itemSize, size, size);
19
+ const TA = typedArrayConstructorByInstance(sampler.data);
20
+
21
+
22
+ let target_width = size;
23
+ let target_height = size;
24
+
25
+ // apply aspect ratio
26
+ if (sampler.width > sampler.height) {
27
+ target_height = Math.ceil(size * (sampler.height / sampler.width));
28
+ } else if (sampler.width < sampler.height) {
29
+ target_width = Math.ceil(size * (sampler.width / sampler.height));
30
+ }
31
+
32
+ const target = new Sampler2D(new TA(target_width * target_height * sampler.itemSize), sampler.itemSize, target_width, target_height);
20
33
 
21
34
  scaleSampler2D(sampler, target);
22
35
 
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "productName": "Meep",
6
6
  "description": "production-ready JavaScript game engine based on Entity Component System Architecture",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.34.49",
8
+ "version": "2.35.0",
9
9
  "dependencies": {
10
10
  "gl-matrix": "3.4.3",
11
11
  "fast-levenshtein": "2.0.6",