@woosh/meep-engine 2.34.40 → 2.34.44

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 (55) hide show
  1. package/core/bvh2/BinaryNode.js +10 -8
  2. package/core/bvh2/BinaryNode.spec.js +1 -0
  3. package/core/bvh2/LeafNode.js +2 -1
  4. package/core/bvh2/aabb3/AABB3.js +879 -1059
  5. package/core/bvh2/aabb3/AABB3.spec.js +5 -7
  6. package/core/bvh2/aabb3/aabb3_array_intersects_ray.js +2 -2
  7. package/core/bvh2/aabb3/aabb3_box_surface_area_2.js +10 -0
  8. package/core/bvh2/aabb3/aabb3_compute_half_surface_area.js +16 -0
  9. package/core/bvh2/aabb3/aabb3_compute_surface_area.js +18 -0
  10. package/core/bvh2/aabb3/aabb3_expand_array.js +15 -0
  11. package/core/bvh2/aabb3/aabb3_intersect_aabb3.js +28 -0
  12. package/core/bvh2/aabb3/aabb3_intersect_ray_slab.js +73 -0
  13. package/core/bvh2/aabb3/{aabb3_intersects_frustum.js → aabb3_intersects_frustum_array.js} +16 -1
  14. package/core/bvh2/aabb3/aabb3_intersects_line_segment.js +79 -0
  15. package/core/bvh2/aabb3/aabb3_intersects_ray.js +92 -0
  16. package/core/bvh2/aabb3/{AABB3Math.spec.js → aabb3_intersects_ray.spec.js} +3 -3
  17. package/core/bvh2/aabb3/aabb3_intersects_ray_fast.js +176 -0
  18. package/core/bvh2/aabb3/aabb3_score_boxes_SAH.js +43 -0
  19. package/core/bvh2/aabb3/aabb_score_boxes_SAH_delta.js +37 -0
  20. package/core/bvh2/aabb3/deserializeAABB3.js +17 -0
  21. package/core/bvh2/aabb3/deserializeAABB3Encoded_v0.js +73 -0
  22. package/core/bvh2/aabb3/deserializeAABB3Quantized16Uint.js +36 -0
  23. package/core/bvh2/aabb3/serializeAABB3.js +13 -0
  24. package/core/bvh2/aabb3/serializeAABB3Quantized16Uint.js +33 -0
  25. package/core/bvh2/binary/2/BinaryUint32BVH.js +3 -3
  26. package/core/bvh2/binary/BinaryBVH.js +2 -2
  27. package/core/bvh2/binary/RayLeafIntersectionVisitor.js +2 -2
  28. package/core/bvh2/serialization/deserializeBinaryNode.js +1 -1
  29. package/core/bvh2/serialization/deserializeBinaryNodeFromBinaryBuffer.js +2 -1
  30. package/core/bvh2/serialization/serializeBinaryNode.js +1 -1
  31. package/core/bvh2/serialization/serializeBinaryNodeToBinaryBuffer.js +2 -1
  32. package/core/bvh2/transform/BottomUpOptimizingRebuilder.js +6 -5
  33. package/core/bvh2/transform/tryRotateSingleNode.js +2 -1
  34. package/core/geom/3d/frustum/{array_setFromProjectionMatrix.js → frustum_from_projection_matrix_array.js} +1 -1
  35. package/core/math/fabsf.js +8 -0
  36. package/engine/development/performance/MetricCollection.js +6 -0
  37. package/engine/graphics/composit/CompositLayer.js +15 -1
  38. package/engine/graphics/ecs/highlight/plugin/OutlineRenderPlugin.js +7 -0
  39. package/engine/graphics/ecs/light/binding/three/ThreeLightBinding.js +1 -1
  40. package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +2 -2
  41. package/engine/graphics/ecs/mesh-v2/sample/prototypeShadedGeometry.js +23 -8
  42. package/engine/graphics/geometry/buffered/query/RaycastNearestHitComputingVisitor.js +2 -2
  43. package/engine/graphics/micron/format/MicronGeometryPatchOccurance.js +3 -2
  44. package/engine/graphics/micron/prototypeVirtualGeometry.js +4 -2
  45. package/engine/graphics/micron/render/PatchCacheKey.js +1 -1
  46. package/engine/graphics/micron/render/VirtualGeometryBuilder.js +15 -41
  47. package/engine/graphics/micron/render/instanced/ThreeInstancedAdapter.js +5 -1
  48. package/engine/graphics/micron/render/refinement/ActivePatchList.js +2 -2
  49. package/engine/graphics/micron/render/refinement/RefinementSpec.js +16 -20
  50. package/engine/graphics/render/buffer/simple-fx/DepthLimitedBlur.js +27 -4
  51. package/engine/graphics/render/buffer/simple-fx/ao/AmbientOcclusionPostProcessEffect.js +7 -2
  52. package/engine/graphics/render/buffer/simple-fx/ao/SAOShader.js +186 -187
  53. package/engine/graphics/render/visibility/hiz/buildCanvasViewFromTexture.js +3 -3
  54. package/package.json +1 -1
  55. package/core/bvh2/aabb3/AABB3Math.js +0 -579
@@ -1,10 +1,10 @@
1
- import { Frustum, Matrix4 } from "three";
2
1
  import { array_copy } from "../../../../core/collection/array/copyArray.js";
3
2
  import Vector2 from "../../../../core/geom/Vector2.js";
4
3
  import { MicronGeometryPatchOccurrence } from "../format/MicronGeometryPatchOccurance.js";
5
4
  import { RefinementSpec } from "./refinement/RefinementSpec.js";
6
5
  import { ActivePatchList } from "./refinement/ActivePatchList.js";
7
6
  import { ActivePatchFlags } from "./refinement/ActivePatchFlags.js";
7
+ import { mat4 } from "gl-matrix";
8
8
 
9
9
  /**
10
10
  * @readonly
@@ -14,27 +14,27 @@ const refinement_spec = new RefinementSpec();
14
14
 
15
15
  export class VirtualGeometryBuilder {
16
16
  constructor() {
17
- this.view_projection_matrix = new Matrix4();
17
+
18
+
19
+ const common_buffer = new ArrayBuffer(192);
20
+
18
21
 
19
22
  /**
20
- *
23
+ * Camera's world inverse matrix
21
24
  * @type {Float32Array|number[]|mat4}
22
25
  */
23
- this.matrix_projection = new Float32Array(16);
24
-
25
- this.matrix_projection_inverse = new Matrix4();
26
-
26
+ this.matrix_world_inverse = new Float32Array(common_buffer, 0, 16);
27
27
  /**
28
- *
28
+ * Camera's projection matrix
29
29
  * @type {Float32Array|number[]|mat4}
30
30
  */
31
- this.matrix_world_inverse = new Float32Array(16);
31
+ this.matrix_projection = new Float32Array(common_buffer, 64, 16);
32
32
 
33
33
  /**
34
34
  *
35
- * @type {Frustum}
35
+ * @type {Float32Array|number[]|mat4}
36
36
  */
37
- this.view_frustum = new Frustum();
37
+ this.view_projection_matrix = new Float32Array(common_buffer, 128, 16);
38
38
 
39
39
  /**
40
40
  * @private
@@ -74,20 +74,6 @@ export class VirtualGeometryBuilder {
74
74
  * @type {number}
75
75
  */
76
76
  this.error_bias = 2;
77
-
78
- /**
79
- *
80
- * @type {number}
81
- * @private
82
- */
83
- this.__info_enforced_node_splits = 0;
84
-
85
- /**
86
- *
87
- * @type {boolean}
88
- * @private
89
- */
90
- this.__flags__enforce_dependency_splits = true;
91
77
  }
92
78
 
93
79
  dropCache() {
@@ -111,27 +97,15 @@ export class VirtualGeometryBuilder {
111
97
  camera.updateMatrix();
112
98
  camera.updateMatrixWorld(true);
113
99
 
114
- this.view_projection_matrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
115
-
116
100
  this.matrix_world_inverse.set(camera.matrixWorldInverse.elements);
117
101
  this.matrix_projection.set(camera.projectionMatrix.elements);
118
102
 
119
- this.matrix_projection_inverse.copy(camera.projectionMatrixInverse);
120
-
121
- this.view_frustum.setFromProjectionMatrix(this.view_projection_matrix);
103
+ mat4.multiply(this.view_projection_matrix, this.matrix_projection, this.matrix_world_inverse);
122
104
 
123
105
  //
124
106
  refinement_spec.focal_length = camera.fov / 180;
125
107
  }
126
108
 
127
- /**
128
- *
129
- * @param {THREE.Matrix4} matrix
130
- */
131
- setProjectionMatrix(matrix) {
132
- this.view_projection_matrix.copy(matrix);
133
- }
134
-
135
109
  /**
136
110
  *
137
111
  * @param {THREE.Object3D|ThreeMicronMesh} object
@@ -156,7 +130,7 @@ export class VirtualGeometryBuilder {
156
130
  this.buildForMesh(
157
131
  object.instance_id,
158
132
  micron_geometry,
159
- object.matrixWorld,
133
+ object.matrixWorld.elements,
160
134
  acl
161
135
  );
162
136
  }
@@ -176,7 +150,7 @@ export class VirtualGeometryBuilder {
176
150
  *
177
151
  * @param {number} instance_id
178
152
  * @param {MicronGeometry} geometry
179
- * @param {THREE.Matrix4} transform
153
+ * @param {number[]} transform world transform matrix of the instance
180
154
  * @param {ActivePatchList} apl
181
155
  */
182
156
  buildForMesh(
@@ -186,7 +160,7 @@ export class VirtualGeometryBuilder {
186
160
  apl
187
161
  ) {
188
162
 
189
- refinement_spec.build(transform.elements, this.matrix_world_inverse, this.matrix_projection);
163
+ refinement_spec.build(transform, this.view_projection_matrix);
190
164
 
191
165
  const output = this.output;
192
166
 
@@ -141,6 +141,10 @@ export class ThreeInstancedAdapter {
141
141
  const geo = this.__buffer_geometry;
142
142
 
143
143
  const patch_transform_attribute = geo.getAttribute(ATTRIBUTE_NAME_TRANSFORM);
144
+ /**
145
+ *
146
+ * @type {Float32Array}
147
+ */
144
148
  const patch_transform_array = patch_transform_attribute.array;
145
149
 
146
150
  patch_transform_attribute.needsUpdate = true;
@@ -157,7 +161,7 @@ export class ThreeInstancedAdapter {
157
161
 
158
162
  const i16 = i * 16;
159
163
 
160
- occurrence.transform.toArray(patch_transform_array, i16);
164
+ patch_transform_array.set(occurrence.transform, i16);
161
165
 
162
166
  const patch_slot_id = patch_data.ensure(occurrence.patch);
163
167
 
@@ -2,7 +2,7 @@ import { ActivePatchRecord } from "./ActivePatchRecord.js";
2
2
  import { ActivePatchFlags } from "./ActivePatchFlags.js";
3
3
  import { aabb3_project_to_2d } from "../../../../../core/geom/3d/aabb/aabb3_compute_projected_area.js";
4
4
  import { BitSet } from "../../../../../core/binary/BitSet.js";
5
- import { aabb3_intersects_frustum } from "../../../../../core/bvh2/aabb3/aabb3_intersects_frustum.js";
5
+ import { aabb3_intersects_frustum_array } from "../../../../../core/bvh2/aabb3/aabb3_intersects_frustum_array.js";
6
6
 
7
7
  export class ActivePatchList {
8
8
  constructor() {
@@ -201,7 +201,7 @@ export class ActivePatchList {
201
201
  check if node is in view frustum
202
202
  NOTE: following suggestion in "FastMesh: Efficient View-dependent Meshing" by Renato Pajarola et al, we can do a more coarse frustum test approximating frustum as a cone initially
203
203
  */
204
- const in_view_frustum = aabb3_intersects_frustum(node.bounding_box, frustum_planes);
204
+ const in_view_frustum = aabb3_intersects_frustum_array(node.bounding_box, frustum_planes);
205
205
 
206
206
  if (!in_view_frustum) {
207
207
  // outside of view frustum, cull
@@ -1,6 +1,6 @@
1
1
  import Vector2 from "../../../../../core/geom/Vector2.js";
2
2
  import { mat4 } from "gl-matrix";
3
- import { array_setFromProjectionMatrix } from "../../../../../core/geom/3d/frustum/array_setFromProjectionMatrix.js";
3
+ import { frustum_from_projection_matrix_array } from "../../../../../core/geom/3d/frustum/frustum_from_projection_matrix_array.js";
4
4
 
5
5
  export class RefinementSpec {
6
6
  constructor() {
@@ -37,25 +37,20 @@ export class RefinementSpec {
37
37
  */
38
38
  const array_buffer = new ArrayBuffer(160);
39
39
 
40
- /**
41
- * Object-space camera frustum
42
- * Frustum planes in compact form
43
- * @type {Float32Array}
44
- */
45
- this.frustum_f32 = new Float32Array(array_buffer, 0, 24);
46
-
47
40
 
48
41
  /**
49
42
  * Contains transformation from camera space to object space
50
43
  * @type {Float32Array|number[]|mat4}
51
44
  */
52
- this.projection_matrix = new Float32Array(array_buffer, 24 * 4, 16);
45
+ this.projection_matrix = new Float32Array(array_buffer, 0, 16);
53
46
 
54
47
  /**
55
- * Model world transform
56
- * @type {Float32Array|number[]|mat4}
48
+ * Object-space camera frustum
49
+ * Frustum planes in compact form
50
+ * @type {Float32Array}
57
51
  */
58
- // this.transform = new Float32Array(16);
52
+ this.frustum_f32 = new Float32Array(array_buffer, 64, 24);
53
+
59
54
 
60
55
  /**
61
56
  * Object-space camera position
@@ -68,6 +63,11 @@ export class RefinementSpec {
68
63
  throw new Error('deprecated, use .frustum_f32 instead');
69
64
  }
70
65
 
66
+ /**
67
+ *
68
+ * @param {number} x
69
+ * @param {number} y
70
+ */
71
71
  setResolution(x, y) {
72
72
  this.resolution.set(x, y);
73
73
 
@@ -79,20 +79,16 @@ export class RefinementSpec {
79
79
  /**
80
80
  *
81
81
  * @param {number[]|mat4|Float32Array|ArrayLike<number>} transform world-space object transform
82
- * @param {number[]|mat4|Float32Array|ArrayLike<number>} matrix_world_inverse camera's world inverse matrix
83
- * @param {number[]|mat4|Float32Array|ArrayLike<number>} matrix_projection camera's projection matrix
82
+ * @param {number[]|mat4|Float32Array|ArrayLike<number>} view_projection_matrix camera's view projection matrix (projection* world_inverse)
84
83
  */
85
- build(transform, matrix_world_inverse, matrix_projection) {
86
- // const _transform = this.transform;
87
- // _transform.set(transform);
84
+ build(transform, view_projection_matrix) {
88
85
 
89
86
  // build projection matrix
90
87
  const projection_matrix = this.projection_matrix;
91
88
 
92
- mat4.multiply(projection_matrix, matrix_world_inverse, transform);
93
- mat4.multiply(projection_matrix, matrix_projection, projection_matrix);
89
+ mat4.multiply(projection_matrix, view_projection_matrix, transform);
94
90
 
95
91
  // compute view frustum in model-space
96
- array_setFromProjectionMatrix(this.frustum_f32, projection_matrix);
92
+ frustum_from_projection_matrix_array(this.frustum_f32, projection_matrix);
97
93
  }
98
94
  }
@@ -1,9 +1,19 @@
1
- import { NoBlending, RGBAFormat, ShaderMaterial, UniformsUtils, Vector2, WebGLMultisampleRenderTarget } from "three";
1
+ import {
2
+ Color,
3
+ NoBlending,
4
+ RGBAFormat,
5
+ ShaderMaterial,
6
+ UniformsUtils,
7
+ Vector2,
8
+ WebGLMultisampleRenderTarget
9
+ } from "three";
2
10
  import { BlurShaderUtils, DepthLimitedBlurShader } from "three/examples/jsm/shaders/DepthLimitedBlurShader.js";
3
11
  import { renderScreenSpace } from "../../utils/renderScreenSpace.js";
4
12
 
13
+ const scratch_color = new Color();
14
+
5
15
  export class DepthLimitedBlur {
6
- constructor({ format = RGBAFormat, radius = 8 }) {
16
+ constructor({ format = RGBAFormat, radius = 8, clear_color = 0, clear_alpha = 1 }) {
7
17
 
8
18
  /**
9
19
  *
@@ -43,6 +53,9 @@ export class DepthLimitedBlur {
43
53
 
44
54
  this.__blur_radius = radius;
45
55
  this.__blur_std_dev = 4;
56
+
57
+ this.__clear_color = new Color(clear_color);
58
+ this.__clear_alpha = clear_alpha;
46
59
  }
47
60
 
48
61
  configureMaterials() {
@@ -113,21 +126,31 @@ export class DepthLimitedBlur {
113
126
  mx.uniforms.size.value.set(this.__rt_output.width, this.__rt_output.height);
114
127
  my.uniforms.size.value.set(this.__rt_output.width, this.__rt_output.height);
115
128
 
116
-
129
+ // remember renderer state
117
130
  const __old_state_rt = renderer.getRenderTarget();
118
-
131
+ const __old_clear_color = scratch_color;
132
+ renderer.getClearColor(__old_clear_color);
133
+ const __old_clear_alpha = renderer.getClearAlpha();
134
+ const __old_auto_clear = renderer.autoClear;
135
+
136
+ //
137
+ renderer.autoClear = false;
138
+ renderer.setClearColor(this.__clear_color);
119
139
  renderer.setRenderTarget(this.__intermediate);
120
140
  renderer.clearColor();
121
141
 
122
142
  renderScreenSpace(renderer, mx);
123
143
 
124
144
  renderer.setRenderTarget(this.__rt_output);
145
+
125
146
  renderer.clearColor();
126
147
 
127
148
  renderScreenSpace(renderer, my);
128
149
 
129
150
  // restore state
130
151
  renderer.setRenderTarget(__old_state_rt);
152
+ renderer.setClearColor(__old_clear_color, __old_clear_alpha);
153
+ renderer.autoClear = __old_auto_clear;
131
154
  }
132
155
 
133
156
  /**
@@ -6,6 +6,7 @@ import {
6
6
  RedFormat,
7
7
  ShaderMaterial,
8
8
  UniformsUtils,
9
+ UnsignedByteType,
9
10
  WebGLMultisampleRenderTarget
10
11
  } from "three";
11
12
  import { SAOShader } from "./SAOShader.js";
@@ -91,6 +92,8 @@ export class AmbientOcclusionPostProcessEffect extends EnginePlugin {
91
92
  magFilter: LinearFilter,
92
93
 
93
94
  format: RedFormat,
95
+ type: UnsignedByteType,
96
+ internalFormat: 'R8',
94
97
  depthBuffer: false,
95
98
  stencilBuffer: false,
96
99
  generateMipmaps: false,
@@ -108,7 +111,7 @@ export class AmbientOcclusionPostProcessEffect extends EnginePlugin {
108
111
  * @type {DepthLimitedBlur}
109
112
  * @private
110
113
  */
111
- this.__blur = new DepthLimitedBlur({ format: RedFormat });
114
+ this.__blur = new DepthLimitedBlur({ format: RedFormat, clear_color: 0xFFFFFF });
112
115
  }
113
116
 
114
117
  /**
@@ -304,7 +307,9 @@ export class AmbientOcclusionPostProcessEffect extends EnginePlugin {
304
307
  // bind compositing layer
305
308
  this.__composit_layer = graphics.layerComposer.createLayer(
306
309
  {
307
- format: RedFormat
310
+ format: RedFormat,
311
+ type: UnsignedByteType,
312
+ internalFormat: 'R8'
308
313
  },
309
314
  BlendingType.Multiply
310
315
  );