@woosh/meep-engine 2.35.15 → 2.36.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 (81) hide show
  1. package/core/binary/BinaryBuffer.js +42 -17
  2. package/core/bvh2/BinaryNode.js +1 -1
  3. package/core/bvh2/aabb3/AABB3.js +2 -2
  4. package/core/bvh2/aabb3/aabb3_array_combine.js +20 -0
  5. package/core/bvh2/aabb3/aabb3_array_intersects_frustum_array.js +20 -0
  6. package/core/bvh2/aabb3/aabb3_array_intersects_ray.js +1 -0
  7. package/core/bvh2/aabb3/aabb3_array_intersects_ray_array.js +14 -0
  8. package/core/bvh2/{aabb3_combined_surface_area.js → aabb3/aabb3_combined_surface_area.js} +3 -3
  9. package/core/bvh2/aabb3/aabb3_intersects_frustum_array.js +1 -19
  10. package/core/bvh2/bvh3/BVHNodeProxy.js +53 -0
  11. package/core/bvh2/bvh3/ExplicitBinaryBoundingVolumeHierarchy.js +848 -0
  12. package/core/bvh2/bvh3/ExplicitBinaryBoundingVolumeHierarchy.spec.js +142 -0
  13. package/core/bvh2/bvh3/bvh_query_leaves_generic.js +79 -0
  14. package/core/bvh2/bvh3/bvh_query_leaves_ray.js +95 -0
  15. package/core/bvh2/bvh3/query/BVHQuery.js +11 -0
  16. package/core/bvh2/bvh3/query/BVHQueryIntersectsFrustum.js +36 -0
  17. package/core/bvh2/bvh3/query/BVHQueryIntersectsRay.js +36 -0
  18. package/core/collection/array/copyArray.js +2 -2
  19. package/core/collection/array/typed/uint_array_for_count.js +17 -0
  20. package/core/collection/table/RowFirstTable.js +25 -7
  21. package/core/collection/table/RowFirstTableSpec.js +4 -4
  22. package/core/geom/3d/aabb/aabb3_matrix4_project.spec.js +1 -1
  23. package/{engine/graphics/util → core/geom/3d/aabb}/computeBoundingBoxFromVertexData.js +1 -1
  24. package/core/geom/3d/compose_matrix4_array.js +53 -0
  25. package/{engine/graphics/util → core/geom/3d}/decompose_matrix_4_array.js +0 -0
  26. package/core/geom/Vector1.js +2 -3
  27. package/engine/asset/loaders/GLTFAssetLoader.js +3 -0
  28. package/engine/asset/loaders/gltf/GLTFAssetTransformMikkTSpaceTangents.js +27 -0
  29. package/engine/ecs/EntityComponentDataset.js +7 -4
  30. package/engine/ecs/foliage/InstancedFoliage.js +1 -1
  31. package/engine/ecs/foliage/ViewState.js +1 -1
  32. package/engine/ecs/transform/Transform.js +2 -2
  33. package/engine/graphics/ecs/mesh-v2/ShadedGeometry.d.ts +5 -0
  34. package/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +46 -12
  35. package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +81 -95
  36. package/engine/graphics/ecs/mesh-v2/render/ShadedGeometryRendererContext.js +16 -5
  37. package/engine/graphics/ecs/mesh-v2/sample/load_gltf.js +1 -0
  38. package/engine/graphics/ecs/mesh-v2/sample/prototypeShadedGeometry.js +3 -4
  39. package/engine/graphics/ecs/path/PathDisplaySystem.js +2 -1
  40. package/engine/graphics/ecs/path/testPathDisplaySystem.js +8 -8
  41. package/engine/graphics/ecs/path/tube/CapType.d.ts +5 -0
  42. package/engine/graphics/ecs/path/tube/CapType.js +9 -0
  43. package/engine/graphics/ecs/path/tube/TubePathStyle.d.ts +2 -0
  44. package/engine/graphics/ecs/path/tube/TubePathStyle.js +10 -1
  45. package/engine/graphics/ecs/path/tube/build/GeometryOutput.js +90 -0
  46. package/engine/graphics/ecs/path/tube/build/build_geometry_catmullrom.js +3 -2
  47. package/engine/graphics/ecs/path/tube/build/build_geometry_linear.js +1 -1
  48. package/engine/graphics/ecs/path/tube/build/computeFrenetFrames.js +1 -2
  49. package/engine/graphics/ecs/path/tube/build/makeTubeGeometry.js +353 -91
  50. package/engine/graphics/ecs/path/tube/prototypeAnimatedPathMask.js +390 -0
  51. package/engine/graphics/geometry/MikkT/MikkTSpace.js +2210 -0
  52. package/engine/graphics/geometry/MikkT/MikkTSpace.spec.js +22 -0
  53. package/engine/graphics/geometry/MikkT/buffer_geometry_ensure_tangents.js +34 -0
  54. package/engine/graphics/geometry/MikkT/buffer_geometry_generate_tangents.js +28 -0
  55. package/engine/graphics/{compute_geometry_polycount.js → geometry/compute_geometry_polycount.js} +0 -0
  56. package/engine/graphics/geometry/skining/computeSkinnedMeshBoundingVolumes.js +1 -1
  57. package/engine/graphics/micron/build/fill_patch_geometry_data.js +1 -18
  58. package/engine/graphics/micron/format/MicronGeometry.js +7 -4
  59. package/engine/graphics/micron/format/micron_build_proxy_geometry.js +203 -0
  60. package/engine/graphics/micron/format/serialization/collection/geometry_collection_serialization.js +83 -0
  61. package/engine/graphics/micron/plugin/GLTFAssetTransformer.js +63 -19
  62. package/engine/graphics/micron/plugin/GLTF_MICRON_ID_FIELD.js +5 -0
  63. package/engine/graphics/micron/plugin/MicronRenderPlugin.js +0 -4
  64. package/engine/graphics/micron/prototypeMicronProxyBuild.js +227 -0
  65. package/engine/graphics/micron/render/refinement/ActivePatchList.js +2 -2
  66. package/engine/graphics/micron/render/refinement/get_geometry_patch_cut.js +2 -2
  67. package/engine/graphics/render/forward_plus/LightManager.js +5 -5
  68. package/engine/graphics/render/forward_plus/data/channelCountToThreIntegerTextureType.js +3 -3
  69. package/engine/graphics/texture/channelCountToThreeTextureFormat.js +2 -2
  70. package/engine/graphics/util/composeMatrix4.js +1 -53
  71. package/engine/graphics/util/composeMatrix4RotationScale.js +1 -1
  72. package/engine/intelligence/behavior/ecs/BehaviorComponent.js +1 -1
  73. package/engine/intelligence/blackboard/AbstractBlackboard.js +9 -0
  74. package/engine/navigation/grid/FastBinaryHeap.js +13 -2
  75. package/engine/notify/Notification.js +1 -1
  76. package/engine/ui/notification/ViewEmitter.js +7 -1
  77. package/engine/ui/notification/notificationGenerator.js +1 -1
  78. package/engine/ui/scene/SceneGUIContext.js +11 -130
  79. package/engine/ui/scene/initializeNotifications.js +141 -0
  80. package/package.json +1 -1
  81. package/view/elements/notify/NotificationView.js +1 -2
@@ -11,9 +11,9 @@ import { deserializeBinaryNodeFromBinaryBuffer } from "../../../core/bvh2/serial
11
11
  import { computeGeometryBoundingSphereMiniball } from "../../graphics/geometry/buffered/computeGeometryBoundingSphereMiniball.js";
12
12
  import { serializeRowFirstTable } from "../../../core/collection/table/serializeRowFirstTable.js";
13
13
  import { deserializeRowFirstTable } from "../../../core/collection/table/deserializeRowFirstTable.js";
14
- import { compose_matrix4_array } from "../../graphics/util/composeMatrix4.js";
15
14
  import { aabb3_from_v3_array_transformed } from "../../../core/bvh2/aabb3/aabb3_from_v3_array_transformed.js";
16
15
  import { ViewState } from "./ViewState.js";
16
+ import { compose_matrix4_array } from "../../../core/geom/3d/compose_matrix4_array.js";
17
17
 
18
18
  /**
19
19
  * @readonly
@@ -2,8 +2,8 @@ import { BitSet } from "../../../core/binary/BitSet.js";
2
2
  import { InstancedMeshGroup } from "../../graphics/geometry/instancing/InstancedMeshGroup.js";
3
3
  import { queryBinaryNode_FrustumIntersections_Data } from "../../../core/bvh2/traversal/queryBinaryNode_FrustumIntersections.js";
4
4
  import Quaternion from "../../../core/geom/Quaternion.js";
5
- import { compose_matrix4_array } from "../../graphics/util/composeMatrix4.js";
6
5
  import Vector3 from "../../../core/geom/Vector3.js";
6
+ import { compose_matrix4_array } from "../../../core/geom/3d/compose_matrix4_array.js";
7
7
 
8
8
  /**
9
9
  *
@@ -4,9 +4,9 @@
4
4
 
5
5
  import Vector3 from "../../../core/geom/Vector3.js";
6
6
  import Quaternion from "../../../core/geom/Quaternion.js";
7
- import { compose_matrix4_array } from "../../graphics/util/composeMatrix4.js";
8
- import { decompose_matrix_4_array } from "../../graphics/util/decompose_matrix_4_array.js";
7
+ import { decompose_matrix_4_array } from "../../../core/geom/3d/decompose_matrix_4_array.js";
9
8
  import { mat4 } from "gl-matrix";
9
+ import { compose_matrix4_array } from "../../../core/geom/3d/compose_matrix4_array.js";
10
10
 
11
11
  const delta = new Vector3();
12
12
 
@@ -5,8 +5,13 @@ export class ShadedGeometry {
5
5
  readonly geometry: BufferGeometry
6
6
  readonly material: Material
7
7
 
8
+ /**
9
+ * @deprecated
10
+ */
8
11
  readonly bvh: Readonly<AABB3>
9
12
 
13
+ getBoundingBox(destination: AABB3): void
14
+
10
15
  from(geometry: BufferGeometry, material: Material): void
11
16
 
12
17
  static from(geometry: BufferGeometry, material: Material): ShadedGeometry
@@ -1,11 +1,13 @@
1
- import { updateNodeByMatrix4AndBBB } from "../mesh/updateNodeByTransformAndBBB.js";
2
1
  import { LeafNode } from "../../../../core/bvh2/LeafNode.js";
3
2
  import { AABB3 } from "../../../../core/bvh2/aabb3/AABB3.js";
4
3
  import { DrawMode } from "./DrawMode.js";
5
4
  import { ShadedGeometryFlags } from "./ShadedGeometryFlags.js";
5
+ import { aabb3_matrix4_project } from "../../../../core/geom/3d/aabb/aabb3_matrix4_project.js";
6
6
 
7
7
  const _aabb3 = new AABB3();
8
8
 
9
+ const scratch_aabb3_array = new Float32Array(6);
10
+
9
11
  const DEFAULT_FLAGS = ShadedGeometryFlags.CastShadow
10
12
  | ShadedGeometryFlags.ReceiveShadow
11
13
  ;
@@ -36,6 +38,15 @@ export class ShadedGeometry {
36
38
  */
37
39
  this.__bvh_leaf = new LeafNode(this, 0, 0, 0, 0, 0, 0);
38
40
 
41
+ this.__bvh_leaf_id = -1;
42
+ /**
43
+ *
44
+ * @type {ExplicitBinaryBoundingVolumeHierarchy|null}
45
+ * @private
46
+ */
47
+ this.__bvh_tree = null;
48
+ this.__bvh_aabb = new Float32Array(6);
49
+
39
50
  /**
40
51
  * Transient, assigned in the system
41
52
  * @type {number}
@@ -75,7 +86,7 @@ export class ShadedGeometry {
75
86
  * @deprecated
76
87
  * @private
77
88
  */
78
- get __cached_object(){
89
+ get __cached_object() {
79
90
  throw new Error('Deprecated');
80
91
  }
81
92
 
@@ -155,10 +166,22 @@ export class ShadedGeometry {
155
166
  return this.__transform;
156
167
  }
157
168
 
169
+ /**
170
+ * @deprecated
171
+ * @returns {LeafNode<ShadedGeometry>}
172
+ */
158
173
  get bvh() {
159
174
  return this.__bvh_leaf;
160
175
  }
161
176
 
177
+ /**
178
+ *
179
+ * @param {AABB3} destination
180
+ */
181
+ getBoundingBox(destination) {
182
+ destination.copy(this.__bvh_leaf);
183
+ }
184
+
162
185
  /**
163
186
  *
164
187
  * @param {THREE.BufferGeometry} geometry
@@ -195,22 +218,33 @@ export class ShadedGeometry {
195
218
  //
196
219
  this.__c_transform.toMatrix4(this.__transform);
197
220
 
221
+ this.update_bounds();
222
+
223
+ this.__bvh_tree.node_move_aabb(this.__bvh_leaf_id, this.__bvh_aabb);
224
+ }
225
+
226
+ update_bounds() {
198
227
  // update bounds
199
228
  const gbb = this.geometry.boundingBox;
200
229
 
201
230
  const min = gbb.min;
202
231
  const max = gbb.max;
203
232
 
204
- _aabb3.setBounds(
205
- min.x,
206
- min.y,
207
- min.z,
208
- max.x,
209
- max.y,
210
- max.z
211
- );
212
-
213
- updateNodeByMatrix4AndBBB(this.__bvh_leaf, _aabb3, this.__transform);
233
+ const x0 = min.x;
234
+ const y0 = min.y;
235
+ const z0 = min.z;
236
+ const x1 = max.x;
237
+ const y1 = max.y;
238
+ const z1 = max.z;
239
+
240
+ scratch_aabb3_array[0] = x0;
241
+ scratch_aabb3_array[1] = y0;
242
+ scratch_aabb3_array[2] = z0;
243
+ scratch_aabb3_array[3] = x1;
244
+ scratch_aabb3_array[4] = y1;
245
+ scratch_aabb3_array[5] = z1;
246
+
247
+ aabb3_matrix4_project(this.__bvh_aabb, scratch_aabb3_array, this.__transform);
214
248
  }
215
249
  }
216
250
 
@@ -6,24 +6,14 @@ import { SurfacePoint3 } from "../../../../core/geom/3d/SurfacePoint3.js";
6
6
  import { v3_distance_sqr } from "../../../../core/geom/v3_distance_sqr.js";
7
7
  import { mat4 } from "gl-matrix";
8
8
  import { returnTrue } from "../../../../core/function/Functions.js";
9
- import { aabb3_intersects_ray } from "../../../../core/bvh2/aabb3/aabb3_intersects_ray.js";
10
9
  import { ShadedGeometryRendererContext } from "./render/ShadedGeometryRendererContext.js";
11
- import { BinaryNode } from "../../../../core/bvh2/BinaryNode.js";
12
10
  import { assert } from "../../../../core/assert.js";
13
11
  import { ray3_array_compose } from "../../../../core/geom/3d/ray/ray3_array_compose.js";
14
12
  import { ray3_array_apply_matrix4 } from "../../../../core/geom/3d/ray/ray3_array_apply_matrix4.js";
13
+ import { ExplicitBinaryBoundingVolumeHierarchy } from "../../../../core/bvh2/bvh3/ExplicitBinaryBoundingVolumeHierarchy.js";
14
+ import { bvh_query_leaves_generic } from "../../../../core/bvh2/bvh3/bvh_query_leaves_generic.js";
15
+ import { BVHQueryIntersectsRay } from "../../../../core/bvh2/bvh3/query/BVHQueryIntersectsRay.js";
15
16
 
16
- /**
17
- *
18
- * @type {BinaryNode|LeafNode[]}
19
- */
20
- const traversal_stack = [];
21
-
22
- /**
23
- *
24
- * @type {number}
25
- */
26
- let traversal_cursor = 0;
27
17
 
28
18
  /**
29
19
  *
@@ -38,7 +28,6 @@ const scratch_point = new SurfacePoint3();
38
28
  const scratch_m4 = new Float32Array(16);
39
29
 
40
30
  const scratch_ray_0 = new Float32Array(6);
41
- const scratch_ray_1 = new Float32Array(6);
42
31
 
43
32
  export class ShadedGeometrySystem extends System {
44
33
  /**
@@ -70,9 +59,6 @@ export class ShadedGeometrySystem extends System {
70
59
  */
71
60
  this.__view_contexts = new Map();
72
61
 
73
- this.__bvh = new BinaryNode();
74
- this.__bvh.setNegativelyInfiniteBounds();
75
-
76
62
  /**
77
63
  *
78
64
  * @type {Map<number, function():AbstractRenderAdapter>}
@@ -86,6 +72,13 @@ export class ShadedGeometrySystem extends System {
86
72
  * @private
87
73
  */
88
74
  this.__geometry_usage_counters = new Map();
75
+
76
+ /**
77
+ *
78
+ * @type {ExplicitBinaryBoundingVolumeHierarchy}
79
+ * @private
80
+ */
81
+ this.__bvh_binary = new ExplicitBinaryBoundingVolumeHierarchy();
89
82
  }
90
83
 
91
84
  /**
@@ -178,7 +171,13 @@ export class ShadedGeometrySystem extends System {
178
171
  this.__render_layer.buildVisibleSet = ((destination, destination_offset, view) => {
179
172
  const ctx = this.__view_contexts.get(view);
180
173
 
181
- return ctx.collect(destination, destination_offset, graphics.renderer, view, this.__bvh);
174
+ const ecd = entityManager.dataset;
175
+
176
+ if (ecd === null) {
177
+ return 0;
178
+ }
179
+
180
+ return ctx.collect(destination, destination_offset, graphics.renderer, view, this.__bvh_binary, ecd);
182
181
  });
183
182
 
184
183
  readyCallback();
@@ -211,7 +210,8 @@ export class ShadedGeometrySystem extends System {
211
210
  t.rotation.onChanged.add(sg.updateTransform, sg);
212
211
  t.scale.onChanged.add(sg.updateTransform, sg);
213
212
 
214
- sg.updateTransform();
213
+ t.toMatrix4(sg.__transform);
214
+ sg.update_bounds();
215
215
 
216
216
  const leaf_node = sg.bvh;
217
217
 
@@ -221,7 +221,15 @@ export class ShadedGeometrySystem extends System {
221
221
  // remember entity for lookups
222
222
  sg.__entity = entity;
223
223
 
224
- this.__bvh.insertNode(leaf_node);
224
+ // insert BVH entry
225
+ const bvh_node_id = this.__bvh_binary.allocate_node();
226
+ this.__bvh_binary.node_set_aabb(bvh_node_id, sg.__bvh_aabb);
227
+ this.__bvh_binary.insert_leaf(bvh_node_id);
228
+ this.__bvh_binary.node_set_user_data(bvh_node_id, entity);
229
+
230
+ sg.__bvh_tree = this.__bvh_binary;
231
+ sg.__bvh_leaf_id = bvh_node_id;
232
+
225
233
 
226
234
  // update usage count
227
235
  const geometry_id = sg.geometry.id;
@@ -242,7 +250,10 @@ export class ShadedGeometrySystem extends System {
242
250
  t.rotation.onChanged.remove(sg.updateTransform, sg);
243
251
  t.scale.onChanged.remove(sg.updateTransform, sg);
244
252
 
245
- sg.bvh.disconnect();
253
+ // disconnect BVH
254
+ const node_id = sg.__bvh_leaf_id;
255
+ this.__bvh_binary.remove_leaf(node_id);
256
+ this.__bvh_binary.release_node(node_id);
246
257
 
247
258
  const geometry_id = sg.geometry.id;
248
259
  const count_existing = this.__geometry_usage_counters.get(geometry_id);
@@ -279,107 +290,82 @@ export class ShadedGeometrySystem extends System {
279
290
  direction_x, direction_y, direction_z,
280
291
  filter_function = returnTrue, filter_function_context
281
292
  ) {
282
- const root_bvh = this.__bvh;
283
- const stack_frame_address = traversal_cursor;
284
-
285
- traversal_stack[traversal_cursor++] = root_bvh;
286
293
 
287
294
  let best_distance = Infinity;
288
295
  let found_hit = false;
289
296
  let best_result = null;
290
297
 
291
- while (traversal_cursor > stack_frame_address) {
292
- traversal_cursor--;
298
+ const hits = [];
293
299
 
294
- /**
295
- *
296
- * @type {BinaryNode|LeafNode<ShadedGeometry>}
297
- */
298
- const node = traversal_stack[traversal_cursor];
300
+ const hit_count = bvh_query_leaves_generic(hits, 0, this.__bvh_binary, BVHQueryIntersectsRay.from([origin_x, origin_y, origin_z, direction_x, direction_y, direction_z]));
299
301
 
300
- // test node against the ray
301
- const intersects = aabb3_intersects_ray(
302
- node.x0, node.y0, node.z0,
303
- node.x1, node.y1, node.z1,
304
- origin_x, origin_y, origin_z,
305
- direction_x, direction_y, direction_z
306
- );
302
+ const ecd = this.entityManager.dataset;
307
303
 
308
- if (!intersects) {
309
- continue;
310
- }
304
+ if (ecd === null) {
305
+ return;
306
+ }
311
307
 
312
- if (node.isBinaryNode) {
313
- if (node.right !== null) {
314
- traversal_stack[traversal_cursor++] = node.right;
315
- }
316
- if (node.left !== null) {
317
- traversal_stack[traversal_cursor++] = node.left;
318
- }
319
- } else {
320
- // leaf node
308
+ const sg_component_index = ecd.computeComponentTypeIndex(ShadedGeometry);
321
309
 
322
- /**
323
- *
324
- * @type {ShadedGeometry}
325
- */
326
- const sg = node.object;
310
+ for (let i = 0; i < hit_count; i++) {
311
+ const node_id = hits[i];
327
312
 
328
- const entity = sg.__entity;
313
+ const entity = this.__bvh_binary.node_get_user_data(node_id);
329
314
 
330
- if (!filter_function.call(filter_function_context, entity, sg)) {
331
- // filtered out
332
- continue;
333
- }
315
+ /**
316
+ *
317
+ * @type {ShadedGeometry}
318
+ */
319
+ const sg = ecd.getComponentByIndex(entity, sg_component_index);
334
320
 
335
- const m4 = sg.transform;
321
+ if (!filter_function.call(filter_function_context, entity, sg)) {
322
+ // filtered out
323
+ continue;
324
+ }
336
325
 
337
- // get transform in local space
338
- mat4.invert(scratch_m4, m4);
326
+ const m4 = sg.transform;
339
327
 
340
- ray3_array_compose(
341
- scratch_ray_0,
342
- origin_x, origin_y, origin_z,
343
- direction_x, direction_y, direction_z
344
- );
328
+ // get transform in local space
329
+ mat4.invert(scratch_m4, m4);
345
330
 
346
- // transform ray to local space
347
- ray3_array_apply_matrix4(scratch_ray_0, scratch_ray_0, scratch_m4);
331
+ ray3_array_compose(
332
+ scratch_ray_0,
333
+ origin_x, origin_y, origin_z,
334
+ direction_x, direction_y, direction_z
335
+ );
348
336
 
349
- const geometry_hit_found = GeometrySpatialQueryAccelerator.INSTANCE.queryRaycastNearest_array(
350
- scratch_point,
351
- sg.geometry,
352
- scratch_ray_0
353
- );
337
+ // transform ray to local space
338
+ ray3_array_apply_matrix4(scratch_ray_0, scratch_ray_0, scratch_m4);
354
339
 
355
- if (!geometry_hit_found) {
356
- continue;
357
- }
340
+ const geometry_hit_found = GeometrySpatialQueryAccelerator.INSTANCE.queryRaycastNearest_array(
341
+ scratch_point,
342
+ sg.geometry,
343
+ scratch_ray_0
344
+ );
358
345
 
359
- // transform hit contact into global space
360
- scratch_point.applyMatrix4(m4);
346
+ if (!geometry_hit_found) {
347
+ continue;
348
+ }
361
349
 
362
- found_hit = true;
350
+ // transform hit contact into global space
351
+ scratch_point.applyMatrix4(m4);
363
352
 
364
- const hit_position = scratch_point.position;
353
+ found_hit = true;
365
354
 
366
- const distance_sqr = v3_distance_sqr(
367
- hit_position.x, hit_position.y, hit_position.z,
368
- origin_x, origin_y, origin_z
369
- );
355
+ const hit_position = scratch_point.position;
370
356
 
371
- if (distance_sqr < best_distance) {
372
- contact.copy(scratch_point);
373
- best_result = sg;
374
- best_distance = distance_sqr;
375
- }
357
+ const distance_sqr = v3_distance_sqr(
358
+ hit_position.x, hit_position.y, hit_position.z,
359
+ origin_x, origin_y, origin_z
360
+ );
376
361
 
362
+ if (distance_sqr < best_distance) {
363
+ contact.copy(scratch_point);
364
+ best_result = sg;
365
+ best_distance = distance_sqr;
377
366
  }
378
367
  }
379
368
 
380
- // drop stack frame
381
- traversal_cursor = stack_frame_address;
382
-
383
369
  if (found_hit) {
384
370
  return {
385
371
  entity: best_result.__entity,
@@ -1,8 +1,10 @@
1
- import { queryBinaryNode_FrustumIntersections_Data } from "../../../../../core/bvh2/traversal/queryBinaryNode_FrustumIntersections.js";
2
1
  import { AbstractRenderAdapter } from "./adapters/AbstractRenderAdapter.js";
3
2
  import { InstancedRendererAdapter } from "./adapters/InstancedRendererAdapter.js";
4
3
  import { GenericRendererAdapter } from "./adapters/GenericRendererAdapter.js";
5
4
  import { assert } from "../../../../../core/assert.js";
5
+ import { bvh_query_leaves_generic } from "../../../../../core/bvh2/bvh3/bvh_query_leaves_generic.js";
6
+ import { BVHQueryIntersectsFrustum } from "../../../../../core/bvh2/bvh3/query/BVHQueryIntersectsFrustum.js";
7
+ import { ShadedGeometry } from "../ShadedGeometry.js";
6
8
 
7
9
  /**
8
10
  * 1 - collect visible meshes
@@ -66,9 +68,10 @@ export class ShadedGeometryRendererContext {
66
68
  * @param {number} destination_offset
67
69
  * @param {THREE.WebGLRenderer} renderer
68
70
  * @param {CameraView} view
69
- * @param {BinaryNode<ShadedGeometry>} bvh
71
+ * @param {ExplicitBinaryBoundingVolumeHierarchy} bvh
72
+ * @param {EntityComponentDataset} ecd
70
73
  */
71
- collect(destination, destination_offset, renderer, view, bvh) {
74
+ collect(destination, destination_offset, renderer, view, bvh, ecd) {
72
75
  const adapters = this.adapters;
73
76
  const adapter_count = adapters.length;
74
77
 
@@ -84,14 +87,22 @@ export class ShadedGeometryRendererContext {
84
87
 
85
88
  const data = [];
86
89
 
87
- const intersection_count = queryBinaryNode_FrustumIntersections_Data(data, 0, bvh, view.frustum);
90
+ const query = BVHQueryIntersectsFrustum.from(view.frustum);
91
+
92
+ const intersection_count = bvh_query_leaves_generic(data, 0, bvh, query);
93
+
94
+ const sg_component_index = ecd.computeComponentTypeIndex(ShadedGeometry);
88
95
 
89
96
  for (i = 0; i < intersection_count; i++) {
97
+ const node_index = data[i];
98
+
99
+ const entity = bvh.node_get_user_data(node_index);
100
+
90
101
  /**
91
102
  *
92
103
  * @type {ShadedGeometry}
93
104
  */
94
- const sg = data[i];
105
+ const sg = ecd.getComponentByIndex(entity, sg_component_index);
95
106
 
96
107
  const adapter = adapters[sg.draw_method];
97
108
 
@@ -53,6 +53,7 @@ async function load_gltf(path, engine) {
53
53
  composition.build(ecd);
54
54
  // console.profileEnd('composition build');
55
55
  console.timeEnd('composition build');
56
+
56
57
  }
57
58
 
58
59
  async function timeout(t = 1) {
@@ -22,7 +22,6 @@ import { OrbitingBehavior } from "../../../../../../model/game/util/behavior/Orb
22
22
  import { BehaviorSystem } from "../../../../intelligence/behavior/ecs/BehaviorSystem.js";
23
23
  import { MicronShadedGeometryRenderAdapter } from "../../../micron/plugin/shaded_geometry/MicronShadedGeometryRenderAdapter.js";
24
24
  import { MicronRenderContext } from "../../../micron/render/v1/MicronRenderContext.js";
25
- import { randomIntegerBetween } from "../../../../../core/math/random/randomIntegerBetween.js";
26
25
 
27
26
  const eh = new EngineHarness();
28
27
 
@@ -100,10 +99,10 @@ async function main(engine) {
100
99
  const sg = ShadedGeometry.from(geometry, material);
101
100
 
102
101
  // sg.draw_method = DRAW_METHOD_PLAIN;
103
- // sg.draw_method = DRAW_METHOD_INSTANCED;
102
+ sg.draw_method = DRAW_METHOD_INSTANCED;
104
103
  // sg.draw_method = 2;
105
- sg.draw_method = randomIntegerBetween(random, 0, 2);
106
- // sg.draw_method = random() > 0.01 ? DRAW_METHOD_INSTANCED : DRAW_METHOD_PLAIN;
104
+ // sg.draw_method = DRAW_METHOD_INSTANCED;
105
+ // sg.draw_method = random() > 0.5 ? DRAW_METHOD_INSTANCED : 2;
107
106
  sg.clearFlag(ShadedGeometryFlags.CastShadow | ShadedGeometryFlags.ReceiveShadow);
108
107
 
109
108
  new EntityBuilder()
@@ -125,7 +125,8 @@ class PathDisplayContext extends SystemEntityContext {
125
125
  try {
126
126
  builder(spec.style, path, this.system, ownedEntities);
127
127
  } catch (e) {
128
- console.error(`Failed to build path of type '${spec.type}': ${e}`);
128
+ console.error(`Failed to build path of type '${spec.type}'`);
129
+ console.error(e);
129
130
  }
130
131
  }
131
132
 
@@ -359,14 +359,14 @@ function main(engine) {
359
359
 
360
360
  const pathDisplay = new PathDisplay();
361
361
  pathDisplay.specs.push(
362
- PathDisplaySpec.from(
363
- PathDisplayType.Ribbon,
364
- trailPathStyle
365
- ),
366
- PathDisplaySpec.from(
367
- PathDisplayType.Entity,
368
- sample_style_entity()
369
- ),
362
+ // PathDisplaySpec.from(
363
+ // PathDisplayType.Ribbon,
364
+ // trailPathStyle
365
+ // ),
366
+ // PathDisplaySpec.from(
367
+ // PathDisplayType.Entity,
368
+ // sample_style_entity()
369
+ // ),
370
370
  PathDisplaySpec.from(
371
371
  PathDisplayType.Tube,
372
372
  sample_style_tube()
@@ -0,0 +1,5 @@
1
+ export enum CapType {
2
+ None,
3
+ Flat,
4
+ Round
5
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @readonly
3
+ * @enum {number}
4
+ */
5
+ export const CapType = {
6
+ None: 0,
7
+ Flat: 1,
8
+ Round: 2
9
+ };
@@ -2,6 +2,7 @@ import {Color} from "../../../../../core/color/Color";
2
2
  import {TubeMaterialType} from "./TubeMaterialType";
3
3
  import {StandardMaterialDefinition} from "./StandardMaterialDefinition";
4
4
  import {MatcapMaterialDefinition} from "./MatcapMaterialDefinition";
5
+ import {CapType} from "./CapType";
5
6
 
6
7
  export class TubePathStyle {
7
8
  public color: Color
@@ -14,4 +15,5 @@ export class TubePathStyle {
14
15
  public cast_shadow: boolean
15
16
  public receive_shadow: boolean
16
17
  public path_mask: number[]
18
+ public cap_type: CapType
17
19
  }
@@ -2,6 +2,7 @@ import { Color } from "../../../../../core/color/Color.js";
2
2
  import { TubeMaterialType } from "./TubeMaterialType.js";
3
3
  import { assert } from "../../../../../core/assert.js";
4
4
  import { MatcapMaterialDefinition } from "./MatcapMaterialDefinition.js";
5
+ import { CapType } from "./CapType.js";
5
6
 
6
7
  const DEFAULT_COLOR = Object.freeze({ r: 1, g: 1, b: 1 });
7
8
 
@@ -71,6 +72,11 @@ export class TubePathStyle {
71
72
  * @type {number[]}
72
73
  */
73
74
  this.path_mask = [0, 1];
75
+
76
+ /**
77
+ * @type {CapType}
78
+ */
79
+ this.cap_type = CapType.Flat;
74
80
  }
75
81
 
76
82
  static fromJSON(j) {
@@ -91,7 +97,8 @@ export class TubePathStyle {
91
97
  radial_resolution = 16,
92
98
  cast_shadow = false,
93
99
  receive_shadow = false,
94
- path_mask = [0, 1]
100
+ path_mask = [0, 1],
101
+ cap_type = CapType.None
95
102
  }) {
96
103
  assert.enum(material_type, TubeMaterialType, 'material_type');
97
104
  assert.isNumber(opacity, 'opacity');
@@ -106,6 +113,7 @@ export class TubePathStyle {
106
113
 
107
114
  assert.greaterThanOrEqual(path_mask.length, 2, 'path_mask length bust be at least 2');
108
115
  assert.ok(path_mask.length % 2 === 0, 'path_mask length bust be multiple of 2');
116
+ assert.enum(cap_type, CapType, 'cap_type');
109
117
 
110
118
  if (typeof color === 'string') {
111
119
  this.color.parse(color);
@@ -123,6 +131,7 @@ export class TubePathStyle {
123
131
  this.receive_shadow = receive_shadow;
124
132
 
125
133
  this.path_mask = path_mask;
134
+ this.cap_type = cap_type;
126
135
 
127
136
  switch (material_type) {
128
137
  case TubeMaterialType.Matcap: