@woosh/meep-engine 2.64.0 → 2.66.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 (92) hide show
  1. package/build/bundle-worker-terrain.js +1 -1
  2. package/build/meep.cjs +33388 -34714
  3. package/build/meep.min.js +1 -1
  4. package/build/meep.module.js +33388 -34714
  5. package/editor/ecs/component/editors/ecs/terrain/TerrainEditor.js +4 -10
  6. package/editor/process/symbolic/makeGridPositionSymbolDisplay.js +7 -7
  7. package/editor/tools/SelectionTool.js +6 -95
  8. package/package.json +1 -1
  9. package/src/core/bvh2/BinaryNode.js +14 -14
  10. package/src/core/bvh2/LeafNode.js +4 -4
  11. package/src/core/bvh2/binary/2/BinaryUint32BVH.js +118 -113
  12. package/src/core/bvh2/binary/2/BinaryUint32BVH.spec.js +54 -0
  13. package/src/core/bvh2/binary/2/bvh32_query_user_data_ray.js +98 -0
  14. package/src/core/bvh2/bvh3/{ExplicitBinaryBoundingVolumeHierarchy.d.ts → BVH.d.ts} +1 -1
  15. package/src/core/bvh2/bvh3/{ExplicitBinaryBoundingVolumeHierarchy.js → BVH.js} +2 -2
  16. package/src/core/bvh2/bvh3/{ExplicitBinaryBoundingVolumeHierarchy.spec.js → BVH.spec.js} +20 -20
  17. package/src/core/bvh2/bvh3/BvhClient.d.ts +11 -0
  18. package/src/core/bvh2/bvh3/{EBBVHLeafProxy.js → BvhClient.js} +22 -3
  19. package/src/core/bvh2/bvh3/BvhClient.spec.js +51 -0
  20. package/src/core/bvh2/bvh3/ebvh_build_for_geometry_incremental.js +2 -2
  21. package/src/core/bvh2/bvh3/ebvh_build_for_geometry_morton.js +4 -4
  22. package/src/core/bvh2/bvh3/ebvh_build_for_geometry_morton.spec.js +3 -3
  23. package/src/core/bvh2/bvh3/ebvh_sort_for_traversal_depth_first.js +2 -8
  24. package/src/core/bvh2/bvh3/query/BVHQuery.js +1 -1
  25. package/src/core/bvh2/bvh3/query/bvh_collect_user_data.js +2 -2
  26. package/src/core/bvh2/bvh3/query/bvh_query_leaves_generic.js +2 -2
  27. package/src/core/bvh2/bvh3/query/bvh_query_leaves_generic.spec.js +2 -2
  28. package/src/core/bvh2/bvh3/query/bvh_query_leaves_ray.js +3 -8
  29. package/src/core/bvh2/bvh3/query/bvh_query_leaves_ray.spec.js +2 -2
  30. package/src/core/bvh2/bvh3/query/bvh_query_user_data_generic.js +2 -2
  31. package/src/core/bvh2/bvh3/query/bvh_query_user_data_generic.spec.js +2 -2
  32. package/src/core/bvh2/bvh3/query/bvh_query_user_data_nearest_to_point.js +3 -3
  33. package/src/core/bvh2/bvh3/query/bvh_query_user_data_nearest_to_point.spec.js +3 -3
  34. package/src/core/bvh2/bvh3/query/bvh_query_user_data_overlaps_frustum.js +3 -3
  35. package/src/core/bvh2/bvh3/query/compute_tight_near_far_clipping_planes.js +4 -4
  36. package/src/core/bvh2/bvh3/query/compute_tight_near_far_clipping_planes.spec.js +3 -3
  37. package/src/core/collection/array/array_copy.js +6 -0
  38. package/src/core/geom/3d/aabb/aabb3_array_combine.js +17 -8
  39. package/src/core/geom/3d/aabb/aabb3_array_intersects_ray.js +5 -2
  40. package/src/core/geom/3d/aabb/aabb3_array_set.js +25 -0
  41. package/src/core/geom/3d/aabb/aabb3_compute_half_surface_area.js +3 -0
  42. package/src/core/geom/3d/triangle/computeTriangleRayIntersectionBarycentric.js +8 -1
  43. package/src/engine/EngineHarness.js +23 -25
  44. package/src/engine/ecs/renderable/RenderSystem.js +44 -32
  45. package/src/engine/ecs/renderable/Renderable.d.ts +2 -2
  46. package/src/engine/ecs/renderable/Renderable.js +12 -11
  47. package/src/engine/ecs/terrain/ecs/Terrain.js +83 -87
  48. package/src/engine/ecs/terrain/ecs/TerrainSystem.js +106 -57
  49. package/src/engine/ecs/terrain/ecs/makeTerrainWorkerProxy.js +5 -2
  50. package/src/engine/ecs/terrain/tiles/TerrainTile.js +122 -67
  51. package/src/engine/ecs/terrain/tiles/TerrainTileManager.js +162 -146
  52. package/src/engine/ecs/terrain/tiles/TileBuildWorker.js +16 -5
  53. package/src/engine/graphics/camera/testClippingPlaneComputation.js +3 -6
  54. package/src/engine/graphics/debug/VisualSymbolLine.js +1 -0
  55. package/src/engine/graphics/ecs/camera/CameraSystem.js +9 -9
  56. package/src/engine/graphics/ecs/camera/auto_set_camera_clipping_planes.js +3 -23
  57. package/src/engine/graphics/ecs/decal/v2/FPDecalSystem.js +22 -24
  58. package/src/engine/graphics/ecs/light/LightSystem.js +12 -48
  59. package/src/engine/graphics/ecs/mesh/Mesh.js +8 -8
  60. package/src/engine/graphics/ecs/mesh/MeshSystem.js +12 -36
  61. package/src/engine/graphics/ecs/mesh/updateNodeByTransformAndBBB.js +3 -43
  62. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +6 -6
  63. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.d.ts +3 -3
  64. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +16 -18
  65. package/src/engine/graphics/ecs/mesh-v2/render/ShadedGeometryRendererContext.js +5 -5
  66. package/src/engine/graphics/ecs/trail2d/Trail2D.js +105 -106
  67. package/src/engine/graphics/ecs/trail2d/Trail2DSystem.js +60 -61
  68. package/src/engine/graphics/ecs/trail2d/makeGradientTrail.js +3 -3
  69. package/src/engine/graphics/ecs/water/WATER_SIZE.js +1 -0
  70. package/src/engine/graphics/ecs/water/Water.js +84 -42
  71. package/src/engine/graphics/ecs/water/WaterSystem.js +53 -105
  72. package/src/engine/graphics/geometry/bvh/buffered/BVHGeometryRaycaster.js +13 -7
  73. package/src/engine/graphics/geometry/bvh/buffered/bvh32_from_indexed_geometry.js +58 -0
  74. package/src/engine/graphics/particles/ecs/ParticleEmitterSystem.js +32 -62
  75. package/src/engine/graphics/particles/particular/engine/ParticularEngine.js +9 -11
  76. package/src/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.js +4 -4
  77. package/src/engine/graphics/particles/particular/engine/renderers/billboard/prototypeBillboardRenderer.js +8 -11
  78. package/src/engine/graphics/render/forward_plus/LightManager.js +30 -32
  79. package/src/engine/graphics/render/forward_plus/LightRenderMetadata.js +3 -3
  80. package/src/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_texture.js +21 -19
  81. package/src/engine/graphics/render/layers/RenderLayer.d.ts +8 -2
  82. package/src/engine/graphics/render/layers/RenderLayer.js +7 -65
  83. package/src/engine/graphics/render/make_bvh_visibility_builder.js +64 -0
  84. package/src/engine/graphics/sh3/LightProbeVolume.js +19 -19
  85. package/src/engine/graphics/sh3/path_tracer/GeometryBVHBatched.js +4 -6
  86. package/src/engine/graphics/sh3/path_tracer/PathTracer.js +17 -19
  87. package/src/engine/graphics/three/expand_aabb_by_transformed_three_object.js +4 -4
  88. package/src/engine/graphics/trail/x/RibbonX.js +26 -5
  89. package/src/engine/sound/ecs/emitter/SoundEmitter.js +18 -16
  90. package/src/engine/sound/ecs/emitter/SoundEmitterSystem.js +3 -5
  91. package/src/core/bvh2/binary/tiny/TinyBVH.js +0 -221
  92. package/src/engine/graphics/ecs/camera/CameraClippingPlaneComputer.js +0 -138
@@ -1,221 +0,0 @@
1
- import { AABB3 } from "../../aabb3/AABB3.js";
2
-
3
- /**
4
- *
5
- * @param {AABB3} bounds
6
- * @param {number} type
7
- * @param {number} x0
8
- * @param {number} y0
9
- * @param {number} z0
10
- * @param {number} x1
11
- * @param {number} y1
12
- * @param {number} z1
13
- */
14
- function build_common_part(bounds, type, x0, y0, z0, x1, y1, z1) {
15
- const bounds_x0 = bounds.x0;
16
- const bounds_x1 = bounds.x1;
17
-
18
- const bounds_y0 = bounds.y0;
19
- const bounds_y1 = bounds.y1;
20
-
21
- const bounds_z0 = bounds.z0;
22
- const bounds_z1 = bounds.z1;
23
-
24
- const range_x = bounds_x1 - bounds_x0;
25
- const range_y = bounds_y1 - bounds_y0;
26
- const range_z = bounds_z1 - bounds_z0;
27
-
28
- const n_x0 = range_x * (x0 - bounds_x0);
29
- const n_x1 = range_x * (x1 - bounds_x0);
30
-
31
- const n_y0 = range_y * (y0 - bounds_y0);
32
- const n_y1 = range_y * (y1 - bounds_y0);
33
-
34
- const n_z0 = range_z * (z0 - bounds_z0);
35
- const n_z1 = range_z * (z1 - bounds_z0);
36
-
37
- const _x0 = n_x0 * 32;
38
- const _x1 = Math.ceil(n_x1 * 32);
39
-
40
- const _y0 = n_y0 * 32;
41
- const _y1 = Math.ceil(n_y1 * 32);
42
-
43
- const _z0 = n_z0 * 32;
44
- const _z1 = Math.ceil(n_z1 * 32);
45
-
46
- return (type << 30)
47
- | ((_x0 << 25) & 0b00111110000000000000000000000000)
48
- | ((_y0 << 20) & 0b00000001111100000000000000000000)
49
- | ((_z0 << 15) & 0b00000000000011111000000000000000)
50
- | ((_x1 << 10) & 0b00000000000000000111110000000000)
51
- | ((_y1 << 5) & 0b00000000000000000000001111100000)
52
- | ((_z1) & 0b00000000000000000000000000011111)
53
- ;
54
- }
55
-
56
- const scratch_aabb3_0 = new AABB3(0, 0, 0, 0, 0, 0);
57
-
58
- /**
59
- * This is WiP
60
- * TODO implement
61
- * The idea is to have fixed precision of bounds at each level, so the deeper the hierarchy - the more precise the bounds, at the same time take up very little space
62
- * Binary layout:
63
- * * common: 2[type],5[x0],5[y0],5[z0],5[x1],5[y1],5[z1]
64
- * * leaf: common, 16[id]
65
- * * intermediate: common
66
- */
67
- export class TinyBVH {
68
- constructor() {
69
- /**
70
- *
71
- * @type {DataView|null}
72
- */
73
- this.view = null;
74
-
75
- this.leaf_count = 0;
76
- this.leaf_nodes_offset = 0;
77
-
78
- /**
79
- *
80
- * @type {AABB3}
81
- */
82
- this.bounds = new AABB3(0, 0, 0, 0, 0, 0);
83
- }
84
-
85
- initialize(length) {
86
-
87
- this.leaf_count = length;
88
-
89
- const two_log = Math.log2(length);
90
-
91
- const two_leaf_limit = Math.pow(2, Math.ceil(two_log));
92
-
93
- const binary_node_count = two_leaf_limit - 1;
94
-
95
- this.leaf_nodes_offset = binary_node_count * 4;
96
- }
97
-
98
-
99
- /**
100
- *
101
- * @param {number} length
102
- * @param {function} factory
103
- */
104
- initialize(length, factory) {
105
- this.leaf_count = length;
106
-
107
- const two_log = Math.log2(length);
108
-
109
- const two_leaf_limit = Math.pow(2, Math.ceil(two_log));
110
-
111
- const binary_node_count = two_leaf_limit - 1;
112
-
113
- this.leaf_nodes_offset = binary_node_count * 4;
114
-
115
- const view = this.view;
116
-
117
- // initialize bounds
118
- this.bounds.setNegativelyInfiniteBounds();
119
-
120
- // actual full bounds of each node
121
- const proper_leaf_bounds = new Float32Array((length + binary_node_count) * 6);
122
-
123
- const morton_codes = new Uint32Array(length);
124
-
125
- const leaf_index_mapping = new Uint32Array(length);
126
-
127
- // collect leaf data
128
- for (let i = 0; i < length; i++) {
129
- const id = factory(i, scratch_aabb3_0);
130
-
131
- const address = this.leaf_nodes_offset + i * 8;
132
-
133
- // write leaf ID
134
- view.setUint32(address + 4, id);
135
-
136
- const bounds_address_offset = (binary_node_count + i) * 6;
137
-
138
- proper_leaf_bounds[bounds_address_offset] = scratch_aabb3_0.x0;
139
- proper_leaf_bounds[bounds_address_offset + 1] = scratch_aabb3_0.y0;
140
- proper_leaf_bounds[bounds_address_offset + 2] = scratch_aabb3_0.z0;
141
-
142
- proper_leaf_bounds[bounds_address_offset + 3] = scratch_aabb3_0.x1;
143
- proper_leaf_bounds[bounds_address_offset + 4] = scratch_aabb3_0.y1;
144
- proper_leaf_bounds[bounds_address_offset + 5] = scratch_aabb3_0.z1;
145
-
146
- morton_codes[i] = scratch_aabb3_0.computeMortonCode();
147
-
148
- leaf_index_mapping[i] = i;
149
- }
150
-
151
- leaf_index_mapping.sort((a, b) => {
152
- return morton_codes[a] - morton_codes[b];
153
- });
154
-
155
-
156
- let level = Math.floor(Math.log2(binary_node_count));
157
-
158
- let level_node_count = Math.pow(2, level);
159
- let offset = (level_node_count - 1)
160
-
161
- let i;
162
- for (i = 0; i < level_node_count; i++) {
163
- const child_offset = i * 2;
164
-
165
- const child_index_0 = child_offset;
166
- const child_index_1 = child_offset + 1;
167
-
168
- if (child_index_0 < length) {
169
- const leaf_index_0 = leaf_index_mapping[child_index_0];
170
- const address_0 = leaf_index_0 * 8 + this.leaf_nodes_offset;
171
-
172
- view.setUint16(address_0,)
173
- }
174
- }
175
-
176
- for (; level >= 0; level--) {
177
- level_node_count = Math.pow(2, level);
178
- let parent_index = level_node_count - 1;
179
-
180
- for (i = 0; i < level_node_count; i++) {
181
- const child_index_0 = (parent_index << 1) + 1;
182
- const child_index_1 = child_index_0 + 1;
183
-
184
-
185
- }
186
-
187
- parent_index++;
188
- }
189
-
190
- }
191
-
192
- /**
193
- *
194
- * @param {number} index
195
- * @param {number} id
196
- * @param {number} x0
197
- * @param {number} y0
198
- * @param {number} z0
199
- * @param {number} x1
200
- * @param {number} y1
201
- * @param {number} z1
202
- */
203
- setLeaf(index, id, x0, y0, z0, x1, y1, z1) {
204
- const address = this.leaf_nodes_offset + index * 8;
205
-
206
- const view = this.view;
207
-
208
- const part_0 = build_common_part(this.bounds, 0, x0, y0, z0, x1, y1, z1);
209
-
210
- view.setUint32(address, part_0);
211
- view.setUint32(address + 4, id);
212
- }
213
-
214
- /**
215
- *
216
- * @param {DataView} view
217
- */
218
- attach(view) {
219
- this.view = view;
220
- }
221
- }
@@ -1,138 +0,0 @@
1
- import { Frustum as ThreeFrustum } from "three";
2
- import { v3_dot } from "../../../../core/geom/vec3/v3_dot.js";
3
- import { isValueBetweenInclusive } from "../../../../core/math/interval/isValueBetweenInclusive.js";
4
- import { frustum_from_camera } from "./frustum_from_camera.js";
5
- import { is_valid_distance_value } from "./is_valid_distance_value.js";
6
-
7
- const CLIPPING_EPSILON = 0.001;
8
-
9
- const CLIPPING_NEAR_MIN = 0.5;
10
-
11
- const CLIPPING_FAR_DEFAULT = 100;
12
-
13
- export class CameraClippingPlaneComputer {
14
- constructor() {
15
- /**
16
- *
17
- * @type {Camera}
18
- */
19
- this.camera = null;
20
-
21
- /**
22
- *
23
- * @type {RenderLayerManager}
24
- */
25
- this.layers = null;
26
-
27
- /**
28
- * Prevents minor shrinkage of the frustum. This variable controls the threshold at which the shrinkage should occur.
29
- * @example value 0 would result is unconditional shrinkage
30
- * @example value 1 would result in shrinkage occurring never
31
- * @type {number}
32
- */
33
- this.hysteresis = 0.5;
34
-
35
- /**
36
- *
37
- * @type {Frustum}
38
- * @private
39
- */
40
- this.__frustum = new ThreeFrustum();
41
-
42
-
43
- this.near = 0;
44
- this.far = 0;
45
- }
46
-
47
- /**
48
- *
49
- * @param {RenderLayer} layer
50
- * @private
51
- */
52
- __processLayer(layer) {
53
- if (!layer.state.visible) {
54
- return;
55
- }
56
-
57
- layer.computeNearFarClippingPlanes(this.__frustum, this.near, this.far, this.__updateClippingPlanes, this);
58
- }
59
-
60
- /**
61
- *
62
- * @param {number} z0
63
- * @param {number} z1
64
- * @private
65
- */
66
- __updateClippingPlanes(z0, z1) {
67
- if (z0 < this.near && z0 !== Number.NEGATIVE_INFINITY) {
68
- this.near = z0;
69
- }
70
- if (z1 > this.far && z1 !== Number.POSITIVE_INFINITY) {
71
- this.far = z1;
72
- }
73
- }
74
-
75
- compute() {
76
- const camera = this.camera;
77
-
78
- /**
79
- *
80
- * @type {number}
81
- */
82
- const hysteresis = this.hysteresis;
83
-
84
- //quantify hysteresis
85
- const oldNear = camera.near;
86
- const oldFar = camera.far;
87
- const oldClippingPlaneDistance = Math.abs(oldFar - oldNear);
88
-
89
- const shrinkThreshold = hysteresis * oldClippingPlaneDistance;
90
-
91
- frustum_from_camera(camera, this.__frustum);
92
-
93
- // compute plane constant (D) to move "near" plane to intersect camera position
94
- const nearPlane = this.__frustum.planes[5];
95
- const near_plane_normal = nearPlane.normal;
96
- const camera_position = camera.position;
97
-
98
- nearPlane.constant = -v3_dot(
99
- camera_position.x,
100
- camera_position.y,
101
- camera_position.z,
102
- near_plane_normal.x,
103
- near_plane_normal.y,
104
- near_plane_normal.z
105
- );
106
-
107
- this.far = Number.NEGATIVE_INFINITY;
108
- this.near = Number.POSITIVE_INFINITY;
109
-
110
- this.layers.traverse(this.__processLayer, this);
111
-
112
- //offset clipping planes by a small margin to prevent clipping of parallel planar surfaces
113
- this.near -= CLIPPING_EPSILON;
114
- this.far += CLIPPING_EPSILON;
115
-
116
- //clip near
117
- if (!is_valid_distance_value(this.near) || this.near < CLIPPING_NEAR_MIN) {
118
- //use a default
119
- //NOTE: values smaller than 0.001 seem to lead to glitchy rendering where polygons clip through one another
120
- this.near = CLIPPING_NEAR_MIN;
121
- }
122
-
123
- if (!is_valid_distance_value(this.far) || this.far < 0) {
124
- //use a default
125
- this.far = CLIPPING_FAR_DEFAULT;
126
- }
127
-
128
- //hysteresis check
129
- if (isValueBetweenInclusive(this.near - oldNear, 0, shrinkThreshold)) {
130
- this.near = oldNear;
131
- }
132
-
133
- if (isValueBetweenInclusive(oldFar - this.far, 0, shrinkThreshold)) {
134
- this.far = oldFar;
135
- }
136
-
137
- }
138
- }