@woosh/meep-engine 2.47.3 → 2.47.10

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 (130) hide show
  1. package/build/bundle-worker-image-decoder.js +1 -0
  2. package/build/bundle-worker-terrain.js +1 -0
  3. package/build/meep.cjs +1044 -933
  4. package/build/meep.min.js +1 -1
  5. package/build/meep.module.js +1044 -933
  6. package/package.json +2 -2
  7. package/src/core/binary/BitSet.spec.js +3 -3
  8. package/src/core/bvh2/BinaryNode.js +12 -10
  9. package/src/core/bvh2/aabb3/AABB3.js +30 -31
  10. package/src/core/bvh2/binary/2/BinaryUint32BVH.js +1 -1
  11. package/src/core/bvh2/binary/BinaryBVH.js +1 -1
  12. package/src/core/bvh2/binary/RayLeafIntersectionVisitor.js +1 -1
  13. package/src/core/bvh2/bvh3/ExplicitBinaryBoundingVolumeHierarchy.js +1 -1
  14. package/src/core/bvh2/bvh3/ebvh_build_for_geometry_morton.js +2 -2
  15. package/src/core/bvh2/bvh3/query/BVHQueryIntersectsFrustum.js +1 -1
  16. package/src/core/bvh2/bvh3/query/BVHQueryIntersectsRay.js +1 -1
  17. package/src/core/bvh2/bvh3/query/bvh_collect_user_data.js +10 -8
  18. package/src/core/bvh2/bvh3/query/bvh_query_leaves_generic.js +14 -22
  19. package/src/core/bvh2/bvh3/query/bvh_query_leaves_ray.js +13 -15
  20. package/src/core/bvh2/bvh3/query/bvh_query_user_data_generic.js +14 -21
  21. package/src/core/bvh2/bvh3/query/bvh_query_user_data_nearest_to_point.js +16 -24
  22. package/src/core/bvh2/bvh3/query/bvh_query_user_data_overlaps_frustum.js +23 -26
  23. package/src/core/bvh2/bvh3/query/compute_tight_near_far_clipping_planes.js +10 -11
  24. package/src/core/bvh2/transform/BottomUpOptimizingRebuilder.js +2 -2
  25. package/src/core/bvh2/transform/tryRotateSingleNode.js +2 -2
  26. package/src/core/bvh2/traversal/aabb3_detailed_volume_intersection_callback_based.js +1 -1
  27. package/src/core/bvh2/traversal/queryBinaryNode_FrustumIntersections.js +1 -1
  28. package/src/core/collection/SCRATCH_UINT32_TRAVERSAL_STACK.js +13 -0
  29. package/src/core/color/Color.d.ts +2 -1
  30. package/src/core/color/Color.js +30 -5
  31. package/src/core/color/ColorUtils.js +7 -5
  32. package/src/core/color/parseHex.js +11 -3
  33. package/src/core/color/rgb2hex.js +1 -1
  34. package/src/core/geom/3d/SurfacePoint3.d.ts +7 -0
  35. package/src/core/geom/3d/SurfacePoint3.js +56 -1
  36. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_array_combine.js +2 -2
  37. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_array_contains_point.js +1 -1
  38. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_array_intersects_frustum_degree.js +2 -2
  39. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_combined_surface_area.js +2 -2
  40. package/src/core/geom/3d/aabb/aabb3_compute_distance_above_plane_max.js +1 -1
  41. package/src/core/geom/3d/aabb/aabb3_compute_distance_above_plane_max.spec.js +8 -0
  42. package/src/core/geom/3d/aabb/{computeAABB3PlaneSide.js → aabb3_compute_plane_side.js} +1 -1
  43. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_detailed_volume_intersection.js +7 -7
  44. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_from_v3_array.js +4 -4
  45. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_from_v3_array_transformed.js +2 -2
  46. package/src/core/{bvh2/aabb3/aabb3_intersect_aabb3.js → geom/3d/aabb/aabb3_intersects_aabb3.js} +2 -2
  47. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_intersects_frustum_array.js +2 -2
  48. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_intersects_frustum_degree.js +4 -4
  49. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_intersects_line_segment.js +1 -1
  50. package/src/core/geom/3d/aabb/aabb3_intersects_ray.js +87 -0
  51. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_intersects_ray.spec.js +1 -1
  52. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_intersects_ray_branchless.js +2 -2
  53. package/src/core/{bvh2/aabb3/aabb3_intersect_ray_slab.js → geom/3d/aabb/aabb3_intersects_ray_slab.js} +35 -17
  54. package/src/core/geom/3d/aabb/aabb3_matrix4_project_by_corners.js +5 -1
  55. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_nearest_point_on_surface.js +2 -2
  56. package/src/core/geom/3d/aabb/aabb3_raycast.js +103 -0
  57. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_signed_distance_sqr_to_point.js +1 -1
  58. package/src/core/geom/3d/aabb/computeBoundingBoxFromVertexData.js +4 -12
  59. package/src/core/geom/3d/aabb/compute_aabb_from_points.js +8 -1
  60. package/src/core/geom/3d/shape/UnitCubeShape3D.js +1 -1
  61. package/src/core/geom/3d/triangle/computeTriangleRayIntersection.js +4 -7
  62. package/src/core/model/node-graph/DataType.d.ts +4 -0
  63. package/src/core/model/node-graph/node/NodeDescription.d.ts +11 -1
  64. package/src/core/model/node-graph/node/NodeRegistry.spec.js +47 -1
  65. package/src/core/model/node-graph/node/Port.d.ts +3 -0
  66. package/src/core/model/node-graph/node/Port.js +7 -3
  67. package/src/core/model/node-graph/node/Port.spec.js +44 -0
  68. package/src/core/model/node-graph/node/PortDirection.d.ts +5 -0
  69. package/src/engine/asset/Asset.js +1 -1
  70. package/src/engine/asset/AssetLoadState.js +10 -0
  71. package/src/engine/asset/AssetManager.js +164 -228
  72. package/src/engine/asset/PendingAsset.js +61 -0
  73. package/src/engine/asset/loaders/GLTFAssetLoader.js +1 -1
  74. package/src/engine/ecs/foliage/InstancedFoliage.js +1 -1
  75. package/src/engine/ecs/storage/BinaryBufferSerializer.js +13 -1
  76. package/src/engine/ecs/storage/binary/collection/BinaryCollectionSerializer.js +11 -4
  77. package/src/engine/ecs/storage/binary/object/BinaryObjectSerializationAdapter2.js +54 -0
  78. package/src/engine/ecs/systems/RenderSystem.js +1 -33
  79. package/src/engine/ecs/terrain/ecs/makeTerrainWorkerProxy.js +2 -4
  80. package/src/engine/ecs/terrain/tiles/TileBuildWorker.js +6 -1
  81. package/src/engine/graphics/GraphicsEngine.js +5 -1
  82. package/src/engine/graphics/ecs/decal/v2/Decal.js +44 -2
  83. package/src/engine/graphics/ecs/decal/v2/DecalSerializationAdapter.js +31 -0
  84. package/src/engine/graphics/ecs/decal/v2/FPDecalSystem.js +16 -5
  85. package/src/engine/graphics/ecs/decal/v2/prototypeDecalSystem.js +88 -56
  86. package/src/engine/graphics/geometry/buffered/compute_buffer_geometry_byte_size.js +5 -1
  87. package/src/engine/graphics/geometry/buffered/query/ClippingPlaneContainmentComputingVisitor.js +2 -2
  88. package/src/engine/graphics/geometry/buffered/query/RaycastNearestHitComputingVisitor.js +1 -1
  89. package/src/engine/graphics/geometry/instancing/InstancedMeshGroup.js +3 -2
  90. package/src/engine/graphics/geometry/skining/computeSkinnedMeshBoundingVolumes.js +3 -2
  91. package/src/engine/graphics/micron/format/MicronGeometry.js +1 -1
  92. package/src/engine/graphics/micron/format/validate_patch_bounds.js +1 -1
  93. package/src/engine/graphics/micron/render/refinement/ActivePatchList.js +1 -1
  94. package/src/engine/graphics/micron/render/refinement/get_geometry_patch_cut.js +16 -16
  95. package/src/engine/graphics/render/forward_plus/LightManager.js +3 -0
  96. package/src/engine/graphics/render/forward_plus/LightManager.spec.js +5 -5
  97. package/src/engine/graphics/render/forward_plus/materials/FP_SHADER_CHUNK_APPLY_DECALS.js +4 -0
  98. package/src/engine/graphics/render/forward_plus/model/Decal.js +10 -2
  99. package/src/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_objects.js +2 -2
  100. package/src/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_texture.js +18 -16
  101. package/src/engine/graphics/render/gizmo/GizmoShapeRenderingInterface.js +2 -0
  102. package/src/engine/graphics/render/visibility/IncrementalDeltaSet.js +26 -13
  103. package/src/engine/graphics/sh3/path_tracer/GeometryBVHBatched.js +8 -2
  104. package/src/engine/graphics/sh3/path_tracer/PathTracer.js +3 -3
  105. package/src/engine/graphics/sh3/path_tracer/prototypePathTracer.js +18 -15
  106. package/src/engine/graphics/texture/sampler/sampler2d_channel_compute_max.js +1 -1
  107. package/src/engine/graphics/texture/sampler/sampler2d_channel_compute_min.js +1 -1
  108. package/src/engine/graphics/three/three_computeObjectBoundingBox.js +56 -0
  109. package/src/engine/input/devices/{InputDeviceButton.d.ts → InputDeviceSwitch.d.ts} +1 -1
  110. package/src/engine/input/devices/{InputDeviceButton.js → InputDeviceSwitch.js} +1 -1
  111. package/src/engine/input/devices/KeyboardDevice.d.ts +2 -2
  112. package/src/engine/input/devices/KeyboardDevice.js +58 -40
  113. package/src/engine/input/devices/PointerDevice.js +224 -179
  114. package/src/core/bvh2/aabb3/aabb3_intersects_ray.js +0 -97
  115. package/src/core/geom/3d/aabb/aabb3_computeDistanceAbovePlane_max.spec.js +0 -8
  116. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_array_intersects_frustum_array.js +0 -0
  117. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_array_intersects_ray.js +0 -0
  118. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_array_intersects_ray_array.js +0 -0
  119. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_box_surface_area_2.js +0 -0
  120. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_compute_half_surface_area.js +0 -0
  121. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_compute_surface_area.js +0 -0
  122. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_corner_edge_mapping.js +0 -0
  123. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_corner_edge_mapping.spec.js +0 -0
  124. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_edge_corner_mapping.js +0 -0
  125. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_edge_corner_mapping.spec.js +0 -0
  126. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_edge_plane_mapping.js +0 -0
  127. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_expand_array.js +0 -0
  128. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_intersects_ray_fast.js +0 -0
  129. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_score_boxes_SAH.js +0 -0
  130. /package/src/core/{bvh2/aabb3/aabb_score_boxes_SAH_delta.js → geom/3d/aabb/aabb3_score_boxes_SAH_delta.js} +0 -0
@@ -27,6 +27,10 @@ import { OctahedralUvEncoder } from "../../../impostors/octahedral/grid/Octahedr
27
27
  import { makeSolidArrowGeometry } from "../../../../../../editor/process/symbolic/makeSolidArrowGeometry.js";
28
28
  import { vec3 } from "gl-matrix";
29
29
  import Quaternion from "../../../../../core/geom/Quaternion.js";
30
+ import { GizmoRenderingPlugin } from "../../../render/gizmo/GizmoRenderingPlugin.js";
31
+ import { Gizmo } from "../../../render/gizmo/Gizmo.js";
32
+ import { ForwardPlusRenderingPlugin } from "../../../render/forward_plus/plugin/ForwardPlusRenderingPlugin.js";
33
+ import { TaskLoadingScreen } from "../../../../../view/task/TaskLoadingScreen.js";
30
34
 
31
35
  const decal_urls = `data/textures/icons/FantasyIconsMegaPack/MagicItems/MagicItems_png/transparent/x64/staff_13_t.png
32
36
  data/textures/icons/FantasyIconsMegaPack/MagicItems/MagicItems_png/transparent/x64/artifact_01_t.png
@@ -371,18 +375,87 @@ function makeNormalTestDecal() {
371
375
  return entity;
372
376
  }
373
377
 
378
+ function sample_grid(ecd) {
379
+ const q_down = new Quaternion();
380
+ q_down.lookRotation(Vector3.down)
381
+
382
+ makeNormalTestGridDecal(ecd, Transform.fromJSON({
383
+ position: new Vector3(5, 0, 5),
384
+ rotation: q_down
385
+ }));
386
+
387
+
388
+ const q_forward = new Quaternion();
389
+ q_forward.lookRotation(Vector3.forward)
390
+
391
+ const t_forward_grid = Transform.fromJSON({
392
+ position: new Vector3(5, 4, 5),
393
+ rotation: q_forward
394
+ });
395
+ makeNormalTestGridDecal(ecd, t_forward_grid);
396
+
397
+ new EntityBuilder()
398
+ .add(SGMesh.fromURL('data/models/snaps/cube_white.gltf'))
399
+ .add(Transform.fromJSON({
400
+ position: new Vector3(14, 1, 4.8),
401
+ rotation: t_forward_grid.rotation,
402
+ scale: new Vector3(25, 25, 0.1)
403
+ }))
404
+ .build(ecd);
405
+ }
406
+
407
+ function raycast_tool(engine) {
408
+ let hits = [];
409
+
410
+ engine.graphics.on.preRender.add(() => {
411
+
412
+ hits.forEach(hit => {
413
+
414
+ Gizmo.draw_solid_sphere(hit.contact.position.asArray(), 0.1);
415
+
416
+ });
417
+
418
+ });
419
+
420
+ engine.devices.pointer.position.onChanged.add(() => {
421
+ const ray_origin = new Vector3();
422
+ const ray_direction = new Vector3();
423
+
424
+
425
+ const pointer = engine.devices.pointer.position;
426
+
427
+ const ndc = new Vector2();
428
+
429
+ engine.graphics.normalizeViewportPoint(pointer, ndc);
430
+ engine.graphics.viewportProjectionRay(ndc.x, ndc.y, ray_origin, ray_direction);
431
+
432
+ hits = engine.entityManager.getSystem(FPDecalSystem)?.raycast(
433
+ ray_origin.x, ray_origin.y, ray_origin.z,
434
+ ray_direction.x, ray_direction.y, ray_direction.z
435
+ );
436
+
437
+ console.warn(hits);
438
+
439
+ });
440
+ }
441
+
374
442
  /**
375
443
  *
376
444
  * @param {Engine} engine
377
445
  */
378
446
  async function main(engine) {
379
447
 
448
+ const fpp = engine.plugins.getPlugin(ForwardPlusRenderingPlugin);
449
+ fpp.setClusterResolution(12, 8, 1);
450
+
451
+ const TERRAIN_SIZE = 1000;
452
+
380
453
  await EngineHarness.buildBasics({
381
454
  engine,
382
455
  enableWater: false,
383
456
  cameraFarDistance: 300,
384
457
  terrainResolution: 1,
385
- terrainSize: new Vector2(1000, 1000)
458
+ terrainSize: new Vector2(TERRAIN_SIZE, TERRAIN_SIZE)
386
459
  });
387
460
 
388
461
  new EntityBuilder()
@@ -396,10 +469,12 @@ async function main(engine) {
396
469
 
397
470
  const random = seededRandom();
398
471
 
399
- const ENTITY_COUNT = 1;
472
+ const ENTITY_COUNT = 100000;
400
473
 
401
474
  const ecd = engine.entityManager.dataset;
402
475
 
476
+ console.log('Decal image pool size:', decal_urls.length);
477
+
403
478
  function makeOne() {
404
479
  const decal = new Decal();
405
480
 
@@ -411,17 +486,17 @@ async function main(engine) {
411
486
 
412
487
  const transform = new Transform();
413
488
  transform.position.set(
414
- randomFloatBetween(random, -400, 400),
489
+ randomFloatBetween(random, 0, TERRAIN_SIZE),
415
490
  randomFloatBetween(random, 0, 0),
416
- randomFloatBetween(random, -400, 400)
491
+ randomFloatBetween(random, 0, TERRAIN_SIZE)
417
492
  );
418
- transform.rotation.random(random);
419
- transform.scale.setScalar(0.5);
493
+ transform.rotation._lookRotation(0, -1, 0, 0, 1, 0);
494
+ transform.scale.set(1,1,0.5);
420
495
 
421
496
  entity
422
497
  .add(transform)
423
498
  .add(decal)
424
- .add(BehaviorComponent.fromOne(RotationBehavior.fromJSON({ speed: 1 })))
499
+ // .add(BehaviorComponent.fromOne(RotationBehavior.fromJSON({ speed: 1 })))
425
500
 
426
501
  entity.build(ecd);
427
502
  }
@@ -433,34 +508,9 @@ async function main(engine) {
433
508
 
434
509
  const task = countTask(0, ENTITY_COUNT, makeOne);
435
510
 
436
- const q_down = new Quaternion();
437
- q_down.lookRotation(Vector3.down)
438
-
439
- makeNormalTestGridDecal(ecd, Transform.fromJSON({
440
- position: new Vector3(5, 0, 5),
441
- rotation: q_down
442
- }));
443
-
444
-
445
- const q_forward = new Quaternion();
446
- q_forward.lookRotation(Vector3.forward)
447
-
448
- const t_forward_grid = Transform.fromJSON({
449
- position: new Vector3(5, 4, 5),
450
- rotation: q_forward
451
- });
452
- makeNormalTestGridDecal(ecd, t_forward_grid);
453
-
454
- new EntityBuilder()
455
- .add(SGMesh.fromURL('data/models/snaps/cube_white.gltf'))
456
- .add(Transform.fromJSON({
457
- position: new Vector3(14, 1, 4.8),
458
- rotation: t_forward_grid.rotation,
459
- scale: new Vector3(25, 25, 0.1)
460
- }))
461
- .build(ecd);
511
+ //sample_grid(ecd);
462
512
 
463
- // TaskLoadingScreen.instance.load(engine, task);
513
+ TaskLoadingScreen.instance.load(engine, task);
464
514
 
465
515
  // console.profile('spawn');
466
516
 
@@ -468,34 +518,14 @@ async function main(engine) {
468
518
  // console.profileEnd('spawn');
469
519
  });
470
520
 
471
- // engine.executor.run(task);
521
+ engine.executor.run(task);
472
522
 
473
523
 
474
524
  //grid(engine.entityManager.dataset, 20,10,80, 25, .4, .6, .1, decal_urls.slice(105, 105+3));
475
525
 
476
526
  //grid(engine.entityManager.dataset, 20,30,80, 25, .4, .6, .1, decal_urls.slice(105, 105+3));
477
527
  // await promise_time_out(10);
478
-
479
- engine.devices.pointer.position.onChanged.add(() => {
480
- const ray_origin = new Vector3();
481
- const ray_direction = new Vector3();
482
-
483
-
484
- const pointer = engine.devices.pointer.position;
485
-
486
- const ndc = new Vector2();
487
-
488
- engine.graphics.normalizeViewportPoint(pointer,ndc);
489
- engine.graphics.viewportProjectionRay(ndc.x, ndc.y, ray_origin, ray_direction);
490
-
491
- const hits = engine.entityManager.getSystem(FPDecalSystem)?.raycast(
492
- ray_origin.x, ray_origin.y, ray_origin.z,
493
- ray_direction.x, ray_direction.y, ray_direction.z
494
- );
495
-
496
- console.warn(hits);
497
-
498
- });
528
+ // raycast_tool(engine);
499
529
 
500
530
  }
501
531
 
@@ -504,6 +534,8 @@ new EngineHarness()
504
534
  configuration(config, engine) {
505
535
  const gltfAssetLoader = new GLTFAssetLoader();
506
536
 
537
+ config.addPlugin(GizmoRenderingPlugin);
538
+
507
539
  config.addLoader(GameAssetType.ModelGLTF_JSON, gltfAssetLoader);
508
540
  config.addLoader(GameAssetType.ModelGLTF, gltfAssetLoader);
509
541
 
@@ -6,7 +6,11 @@
6
6
  export function compute_buffer_geometry_byte_size(g) {
7
7
  let result = 0;
8
8
 
9
- result += g.getIndex().array.buffer.byteLength;
9
+ const index = g.getIndex();
10
+
11
+ if (index !== null) {
12
+ result += index.array.buffer.byteLength;
13
+ }
10
14
 
11
15
  for (const attribute_name in g.attributes) {
12
16
  result += g.attributes[attribute_name].array.buffer.byteLength;
@@ -1,4 +1,4 @@
1
- import { computeAABB3PlaneSide } from "../../../../../core/geom/3d/aabb/computeAABB3PlaneSide.js";
1
+ import { aabb3_compute_plane_side } from "../../../../../core/geom/3d/aabb/aabb3_compute_plane_side.js";
2
2
  import { NodeType } from "../../../../../core/bvh2/binary/NodeType.js";
3
3
  import { computeTrianglePlaneSide } from "../../../../../core/geom/3d/triangle/computeTrianglePlaneSide.js";
4
4
  import { GeometrySpatialAcceleratorVisitor } from "./GeometryVisitor.js";
@@ -162,7 +162,7 @@ export class ClippingPlaneContainmentComputingVisitor extends GeometrySpatialAcc
162
162
  const plane_normal_z = plane.normal.z;
163
163
  const plane_constant = plane.constant;
164
164
 
165
- const side = computeAABB3PlaneSide(
165
+ const side = aabb3_compute_plane_side(
166
166
  plane_normal_x,
167
167
  plane_normal_y,
168
168
  plane_normal_z,
@@ -3,7 +3,7 @@ import { NodeType } from "../../../../../core/bvh2/binary/NodeType.js";
3
3
  import Vector3 from "../../../../../core/geom/Vector3.js";
4
4
  import { computeTriangleRayIntersection } from "../../../../../core/geom/3d/triangle/computeTriangleRayIntersection.js";
5
5
  import { GeometrySpatialAcceleratorVisitor } from "./GeometryVisitor.js";
6
- import { aabb3_intersects_ray } from "../../../../../core/bvh2/aabb3/aabb3_intersects_ray.js";
6
+ import { aabb3_intersects_ray } from "../../../../../core/geom/3d/aabb/aabb3_intersects_ray.js";
7
7
  import { assert } from "../../../../../core/assert.js";
8
8
 
9
9
  export class RaycastNearestHitComputingVisitor extends GeometrySpatialAcceleratorVisitor {
@@ -17,6 +17,7 @@ import { rewriteMaterial } from "./rewriteMaterial.js";
17
17
  import { max3 } from "../../../../core/math/max3.js";
18
18
  import { min2 } from "../../../../core/math/min2.js";
19
19
  import { DrawMode } from "../../ecs/mesh-v2/DrawMode.js";
20
+ import { array_copy } from "../../../../core/collection/array/copyArray.js";
20
21
 
21
22
  export class InstancedMeshGroup {
22
23
  /**
@@ -316,7 +317,7 @@ export class InstancedMeshGroup {
316
317
  * @param {number[]|ArrayLike<number>|Float32Array} transform 4x4 transform matrix of the instance
317
318
  */
318
319
  setTransformAt(index, transform) {
319
- this.__attributeTransformArray.set(transform, index * 16);
320
+ array_copy(transform,0,this.__attributeTransformArray,index*16,16);
320
321
  }
321
322
 
322
323
  /**
@@ -325,7 +326,7 @@ export class InstancedMeshGroup {
325
326
  * @param {number[]|ArrayLike<number>|Float32Array} color RGBA color in uint8 format (0...255), LDR
326
327
  */
327
328
  setColorAt(index, color) {
328
- this.__attributeColorArray.set(color, index * 4);
329
+ array_copy(color,0,this.__attributeColorArray,index*4,4);
329
330
  }
330
331
 
331
332
  /**
@@ -3,7 +3,7 @@ import { AABB3 } from "../../../../core/bvh2/aabb3/AABB3.js";
3
3
  import Vector4 from "../../../../core/geom/Vector4.js";
4
4
  import { computeBoundingSphereFromVertexData } from "../computeBoundingSphereFromVertexData.js";
5
5
  import { Box3, Sphere as ThreeSphere, Vector3 as ThreeVector3 } from "three";
6
- import { computeBoundingBoxFromVertexData } from "../../../../core/geom/3d/aabb/computeBoundingBoxFromVertexData.js";
6
+ import { aabb3_from_v3_array } from "../../../../core/geom/3d/aabb/aabb3_from_v3_array.js";
7
7
 
8
8
  /**
9
9
  *
@@ -21,7 +21,8 @@ export function computeSkinnedMeshBoundingVolumes(mesh) {
21
21
  const aabb3 = new AABB3(0, 0, 0, 0, 0, 0);
22
22
  const sphere = new Vector4();
23
23
 
24
- computeBoundingBoxFromVertexData(vertices, aabb3);
24
+
25
+ aabb3_from_v3_array(aabb3, vertices, vertices.length);
25
26
  computeBoundingSphereFromVertexData(vertices, sphere);
26
27
 
27
28
  const min = new ThreeVector3(aabb3.x0, aabb3.y0, aabb3.z0);
@@ -2,7 +2,7 @@ import { VertexDataSpec } from "../../geometry/VertexDataSpec.js";
2
2
  import { assert } from "../../../../core/assert.js";
3
3
  import { computeTriangleRayIntersection } from "../../../../core/geom/3d/triangle/computeTriangleRayIntersection.js";
4
4
  import { SurfacePoint3 } from "../../../../core/geom/3d/SurfacePoint3.js";
5
- import { aabb3_array_intersects_ray } from "../../../../core/bvh2/aabb3/aabb3_array_intersects_ray.js";
5
+ import { aabb3_array_intersects_ray } from "../../../../core/geom/3d/aabb/aabb3_array_intersects_ray.js";
6
6
  import { sphere_array_intersects_ray } from "../../../../core/geom/3d/sphere/sphere_array_intersects_ray.js";
7
7
  import { BitSet } from "../../../../core/binary/BitSet.js";
8
8
  import { micron_build_proxy_geometry } from "./micron_build_proxy_geometry.js";
@@ -1,5 +1,5 @@
1
1
  import { noop } from "../../../../core/function/Functions.js";
2
- import { aabb3_array_contains_point } from "../../../../core/bvh2/aabb3/aabb3_array_contains_point.js";
2
+ import { aabb3_array_contains_point } from "../../../../core/geom/3d/aabb/aabb3_array_contains_point.js";
3
3
  import { sphere_array_intersects_point } from "../../../../core/geom/3d/sphere/sphere_array_intersects_point.js";
4
4
 
5
5
  /**
@@ -4,7 +4,7 @@ import { aabb3_project_to_2d } from "../../../../../core/geom/3d/aabb/aabb3_comp
4
4
  import { BitSet } from "../../../../../core/binary/BitSet.js";
5
5
  import {
6
6
  aabb3_array_intersects_frustum_array
7
- } from "../../../../../core/bvh2/aabb3/aabb3_array_intersects_frustum_array.js";
7
+ } from "../../../../../core/geom/3d/aabb/aabb3_array_intersects_frustum_array.js";
8
8
 
9
9
  export class ActivePatchList {
10
10
  constructor() {
@@ -1,8 +1,9 @@
1
1
  import { BitSet } from "../../../../../core/binary/BitSet.js";
2
2
  import {
3
3
  aabb3_array_intersects_frustum_array
4
- } from "../../../../../core/bvh2/aabb3/aabb3_array_intersects_frustum_array.js";
4
+ } from "../../../../../core/geom/3d/aabb/aabb3_array_intersects_frustum_array.js";
5
5
  import { aabb3_estimate_projected_area2 } from "../../../../../core/geom/3d/aabb/aabb3_estimate_projected_area2.js";
6
+ import { SCRATCH_UINT32_TRAVERSAL_STACK } from "../../../../../core/collection/SCRATCH_UINT32_TRAVERSAL_STACK.js";
6
7
 
7
8
 
8
9
  /**
@@ -12,12 +13,7 @@ import { aabb3_estimate_projected_area2 } from "../../../../../core/geom/3d/aabb
12
13
  const scratch_traversal_bitset = new BitSet();
13
14
  scratch_traversal_bitset.preventShrink();
14
15
 
15
- /**
16
- * Using a pre-allocated continuous chunk of memory gets us better cache coherence
17
- * @readonly
18
- * @type {number[]}
19
- */
20
- const scratch_traversal_stack = new Uint32Array(781250);
16
+ const stack = SCRATCH_UINT32_TRAVERSAL_STACK;
21
17
 
22
18
  /**
23
19
  *
@@ -41,16 +37,20 @@ export function get_geometry_patch_cut(
41
37
 
42
38
  const geometry_id = geometry.id;
43
39
 
44
- const destination_patch_address = destination.patch_count;
45
- let output_patch_cursor = destination_patch_address;
40
+ let output_patch_cursor = destination.patch_count;
46
41
 
47
42
  let i;
48
- let stack_cursor = 1;
49
43
 
50
44
  // initialize stack
51
- const stack = scratch_traversal_stack;
52
45
  const root = geometry.root;
53
- stack[0] = root.id;
46
+
47
+ /**
48
+ *
49
+ * @type {number}
50
+ */
51
+ const stack_top = stack.pointer++;
52
+
53
+ stack[stack_top] = root.id;
54
54
 
55
55
  const included_set = scratch_traversal_bitset;
56
56
  included_set.reset();
@@ -60,10 +60,10 @@ export function get_geometry_patch_cut(
60
60
  const patches = geometry.patches;
61
61
  const destination_patches = destination.patches;
62
62
 
63
- while (stack_cursor > 0) {
64
- stack_cursor--;
63
+ while (stack.pointer > stack_top) {
64
+ stack.pointer--;
65
65
 
66
- const patch_id = stack[stack_cursor];
66
+ const patch_id = stack[stack.pointer];
67
67
  const patch = patches[patch_id];
68
68
 
69
69
  /*
@@ -101,7 +101,7 @@ export function get_geometry_patch_cut(
101
101
  continue;
102
102
  }
103
103
 
104
- stack[stack_cursor++] = child_id;
104
+ stack[stack.pointer++] = child_id;
105
105
  }
106
106
 
107
107
  continue;
@@ -1133,14 +1133,17 @@ export class LightManager {
1133
1133
  assert.isNumber(x, 'x');
1134
1134
  assert.isNonNegativeInteger(x, 'x');
1135
1135
  assert.isFiniteNumber(x, 'x');
1136
+ assert.greaterThan(x,0,'x must be > 0');
1136
1137
 
1137
1138
  assert.isNumber(y, 'y');
1138
1139
  assert.isNonNegativeInteger(y, 'y');
1139
1140
  assert.isFiniteNumber(y, 'y');
1141
+ assert.greaterThan(y,0,'y must be > 0');
1140
1142
 
1141
1143
  assert.isNumber(z, 'z');
1142
1144
  assert.isNonNegativeInteger(z, 'z');
1143
1145
  assert.isFiniteNumber(z, 'z');
1146
+ assert.greaterThan(z,0,'z must be > 0');
1144
1147
 
1145
1148
  const r = this.__tiles_resolution;
1146
1149
 
@@ -20,7 +20,7 @@ test('correct cluster content (empty)', () => {
20
20
 
21
21
  const tex = lm.getTextureClusters();
22
22
 
23
- expect(Array.from(tex.image.data)).toEqual([0, 0, 0]);
23
+ expect(Array.from(tex.image.data)).toEqual([0, 0, 0, 0]);
24
24
  });
25
25
 
26
26
  test('correct cluster content (single small light)', () => {
@@ -35,7 +35,7 @@ test('correct cluster content (single small light)', () => {
35
35
 
36
36
  const camera = new PerspectiveCamera(45, 1, 1, 10);
37
37
  camera.lookAt(0, 0, 5);
38
-
38
+
39
39
  camera.updateProjectionMatrix();
40
40
  camera.updateMatrix();
41
41
  camera.updateMatrixWorld(true);
@@ -46,7 +46,7 @@ test('correct cluster content (single small light)', () => {
46
46
 
47
47
  const tex = lm.getTextureClusters();
48
48
 
49
- expect(Array.from(tex.image.data)).toEqual([0, 1, 0]);
49
+ expect(Array.from(tex.image.data)).toEqual([0, 1, 0, 0]);
50
50
  });
51
51
 
52
52
  test('correct cluster content (single huge light)', () => {
@@ -68,7 +68,7 @@ test('correct cluster content (single huge light)', () => {
68
68
 
69
69
  const tex = lm.getTextureClusters();
70
70
 
71
- expect(Array.from(tex.image.data)).toEqual([0, 1, 0]);
71
+ expect(Array.from(tex.image.data)).toEqual([0, 1, 0, 0]);
72
72
  });
73
73
 
74
74
  test('correct cluster content (single huge light overlapping)', () => {
@@ -90,5 +90,5 @@ test('correct cluster content (single huge light overlapping)', () => {
90
90
 
91
91
  const tex = lm.getTextureClusters();
92
92
 
93
- expect(Array.from(tex.image.data)).toEqual([0, 1, 0]);
93
+ expect(Array.from(tex.image.data)).toEqual([0, 1, 0, 0]);
94
94
  });
@@ -54,6 +54,10 @@ export const FP_SHADER_CHUNK_APPLY_DECALS = `
54
54
 
55
55
  vec4 decal_color = texture2D(fp_t_decal_atlas,decal_uv, -0.2);
56
56
 
57
+ vec4 decal_color_tint = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address+5u), 0);
58
+
59
+ decal_color*= decal_color_tint;
60
+
57
61
  // compute decal alpha
58
62
  float decal_alpha = decal_color.a * decal_surface_angle_fade;
59
63
 
@@ -19,6 +19,11 @@ export class Decal extends AbstractLight {
19
19
  this.transform_inverse = new Float32Array(16);
20
20
  this.uv = new Float32Array(4);
21
21
 
22
+ this.color = new Float32Array(4);
23
+ // initialize color to full white
24
+ this.color.fill(1);
25
+
26
+
22
27
  /**
23
28
  *
24
29
  * @type {Sampler2D}
@@ -98,8 +103,11 @@ export class Decal extends AbstractLight {
98
103
  array_copy(this.uv, 0, destination, address + 16, 4);
99
104
 
100
105
  // required for sorting
101
- destination[address + 20] = this.draw_priority;
102
- destination[address + 21] = this.id;
106
+ // destination[address + 20] = this.draw_priority;
107
+ // destination[address + 21] = this.id;
108
+
109
+ // color
110
+ array_copy(this.color, 0, destination, address + 20, 4);
103
111
 
104
112
  return 24;
105
113
  }
@@ -1,5 +1,5 @@
1
1
  import {
2
- aabb3_computeDistanceAbovePlane_max
2
+ aabb3_compute_distance_above_plane_max
3
3
  } from "../../../../../core/geom/3d/aabb/aabb3_compute_distance_above_plane_max.js";
4
4
  import { point_light_inside_volume } from "./point_light_inside_volume.js";
5
5
  import { spot_light_inside_volume } from "./spot_light_inside_volume.js";
@@ -52,7 +52,7 @@ export function query_bvh_frustum_from_objects(
52
52
  const plane_normal_z = planes[plane_address + 2];
53
53
  const plane_constant = planes[plane_address + 3];
54
54
 
55
- const distanceAbovePlane = aabb3_computeDistanceAbovePlane_max(
55
+ const distanceAbovePlane = aabb3_compute_distance_above_plane_max(
56
56
  plane_normal_x, plane_normal_y, plane_normal_z, plane_constant,
57
57
  n.x0, n.y0, n.z0,
58
58
  n.x1, n.y1, n.z1
@@ -1,14 +1,11 @@
1
1
  import {
2
- aabb3_computeDistanceAbovePlane_max
2
+ aabb3_compute_distance_above_plane_max
3
3
  } from "../../../../../core/geom/3d/aabb/aabb3_compute_distance_above_plane_max.js";
4
4
  import { point_light_inside_volume } from "./point_light_inside_volume.js";
5
5
  import { BVH_BINARY_NODE_SIZE, BVH_LEAF_NODE_SIZE } from "../../../../../core/bvh2/binary/2/BinaryUint32BVH.js";
6
+ import { SCRATCH_UINT32_TRAVERSAL_STACK } from "../../../../../core/collection/SCRATCH_UINT32_TRAVERSAL_STACK.js";
6
7
 
7
- /**
8
- *
9
- * @type {number[]}
10
- */
11
- const stack = [];
8
+ const stack = SCRATCH_UINT32_TRAVERSAL_STACK;
12
9
 
13
10
  /**
14
11
  *
@@ -33,7 +30,7 @@ function frustum_check(data_view, address, planes) {
33
30
  const plane_normal_z = planes[plane_address + 2];
34
31
  const plane_constant = planes[plane_address + 3];
35
32
 
36
- const distanceAbovePlane = aabb3_computeDistanceAbovePlane_max(
33
+ const distanceAbovePlane = aabb3_compute_distance_above_plane_max(
37
34
  plane_normal_x, plane_normal_y, plane_normal_z, plane_constant,
38
35
  n_x0, n_y0, n_z0,
39
36
  n_x1, n_y1, n_z1
@@ -70,8 +67,6 @@ export function query_bvh_frustum_from_texture(
70
67
  source_data,
71
68
  planes, points
72
69
  ) {
73
-
74
- let stackPointer = 1;
75
70
  let result = 0;
76
71
 
77
72
  const binary_node_count = root.getBinaryNodeCount();
@@ -81,19 +76,26 @@ export function query_bvh_frustum_from_texture(
81
76
  return 0;
82
77
  }
83
78
 
79
+ /**
80
+ *
81
+ * @type {number}
82
+ */
83
+ const stack_top = stack.pointer++;
84
+
84
85
  /**
85
86
  * After performing empirical tests, stack-based depth-first traversal turns out faster than using a queue
86
87
  * @type {number}
87
88
  */
88
- stack[0] = 0;
89
+ stack[stack_top] = 0;
89
90
 
90
91
  const last_valid_index = binary_node_count + root.getLeafNodeCount();
91
92
  const data_view = root.getDataView();
92
93
 
93
- while (stackPointer-- > 0) {
94
+ do {
95
+ stack.pointer--;
94
96
 
95
97
  // query_bvh_frustum_from_objects.iteration_count++;
96
- const node_index = stack[stackPointer];
98
+ const node_index = stack[stack.pointer];
97
99
 
98
100
  if (node_index < binary_node_count) {
99
101
  // is intermediate node
@@ -108,11 +110,11 @@ export function query_bvh_frustum_from_texture(
108
110
 
109
111
  // left node ends up on top of the stack, which aligns with the desired access sequence
110
112
  if (right_index < last_valid_index) {
111
- stack[stackPointer++] = right_index;
113
+ stack[stack.pointer++] = right_index;
112
114
  // micro-optimization, since we know that right node is valid and left appears before that, left is valid too
113
- stack[stackPointer++] = left_index;
115
+ stack[stack.pointer++] = left_index;
114
116
  } else if (left_index < last_valid_index) {
115
- stack[stackPointer++] = left_index;
117
+ stack[stack.pointer++] = left_index;
116
118
  }
117
119
 
118
120
 
@@ -160,7 +162,7 @@ export function query_bvh_frustum_from_texture(
160
162
  result++;
161
163
  }
162
164
 
163
- }
165
+ }while (stack.pointer > stack_top)
164
166
 
165
167
  return result;
166
168
  }
@@ -35,6 +35,8 @@ function add_instance(group, matrix, color) {
35
35
  Math.round(color[2] * 255),
36
36
  Math.round(color[3] * 255)
37
37
  );
38
+
39
+ group.requestAttributeUpdate();
38
40
  }
39
41
 
40
42
  /**