@woosh/meep-engine 2.33.21 → 2.33.25

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 (285) hide show
  1. package/core/assert.js +3 -1
  2. package/core/bvh2/BinaryNode.js +1 -1
  3. package/core/bvh2/aabb3/AABB3.js +18 -0
  4. package/core/bvh2/aabb3/AABB3Math.js +1 -1
  5. package/core/bvh2/binary/2/BinaryUint32BVH.js +498 -0
  6. package/core/bvh2/binary/2/BinaryUint32BVH.spec.js +54 -0
  7. package/core/bvh2/binary/IndexedBinaryBVH.js +22 -26
  8. package/core/bvh2/traversal/ThreeClippingPlaneComputingBVHVisitor.js +5 -1
  9. package/core/bvh2/traversal/__detailed_box_volume_intersection.js +31 -11
  10. package/core/collection/ArrayUtils.js +1 -1
  11. package/core/collection/array/arrayQuickSort.js +9 -6
  12. package/core/collection/array/array_swap.js +22 -0
  13. package/core/collection/array/binarySearchHighIndex.js +1 -1
  14. package/core/collection/array/computeHashArray.js +22 -0
  15. package/core/collection/array/computeHashIntegerArray.js +15 -0
  16. package/core/collection/array/copyArray.js +2 -2
  17. package/core/collection/table/DataType2TypedArrayConstructorMapping.js +15 -0
  18. package/core/color/Color.js +2 -1
  19. package/core/function/FunctionCompiler.js +2 -1
  20. package/core/geom/3d/aabb/aabb3_computeDistanceAbovePlane.js +9 -33
  21. package/core/geom/3d/frustum/frustum3_computeNearestPointToPoint.js +10 -2
  22. package/core/geom/3d/line/line3_computeSegmentPointDistance_sqr.js +41 -0
  23. package/core/geom/3d/morton/mortonEncode_magicbits.js +2 -1
  24. package/core/geom/3d/morton/reinterpret_float32_as_int32.js +13 -0
  25. package/core/geom/3d/morton/v3_morton_encode_transformed.js +33 -0
  26. package/core/geom/3d/normal/hemioct/unit_hemioct.spec.js +1 -1
  27. package/core/geom/3d/plane/plane_computeConvex3PlaneIntersection.js +13 -14
  28. package/core/geom/3d/ray/ray_computeNearestPointToPoint.js +37 -0
  29. package/core/geom/3d/shape/AbstractShape3D.js +38 -0
  30. package/core/geom/3d/shape/CompositeShape.js +240 -0
  31. package/core/geom/3d/shape/TransformedShape3D.js +126 -0
  32. package/core/geom/3d/shape/UnitCubeShape3D.js +24 -0
  33. package/core/geom/3d/shape/UnitSphereShape3D.js +24 -0
  34. package/core/geom/3d/shape/util/shape_to_visual_entity.js +159 -0
  35. package/core/geom/3d/voxel/DenseBitVolume3D.js +87 -0
  36. package/core/geom/3d/voxel/buildVolumeFromProjectedGeometry.js +23 -0
  37. package/core/geom/AABB2.js +1 -1
  38. package/core/geom/ConicRay.js +3 -1
  39. package/core/geom/LineSegment.js +0 -78
  40. package/core/geom/Matrix4.js +7 -8
  41. package/core/geom/Plane.js +14 -9
  42. package/core/geom/Rectangle.js +2 -1
  43. package/core/geom/Vector1.js +1 -1
  44. package/core/geom/Vector3.js +2 -1
  45. package/core/geom/Vector4.js +2 -1
  46. package/core/geom/random/randomPointInBox.js +7 -3
  47. package/core/geom/random/randomPointInPoint.js +6 -3
  48. package/core/geom/random/randomPointInSphere.js +9 -5
  49. package/core/geom/random/randomPointOnBox.js +7 -3
  50. package/core/geom/random/randomPointOnSphere.js +6 -3
  51. package/core/geom/v3_length.js +8 -3
  52. package/core/graph/graph_k_means_cluster.js +1 -1
  53. package/core/json/resolvePathByArray.js +2 -2
  54. package/core/math/MathUtils.js +0 -354
  55. package/core/math/MathUtils.spec.js +7 -1
  56. package/core/math/gaussian.js +9 -0
  57. package/core/math/hash/computeHashFloat.js +17 -0
  58. package/core/math/hash/computeHashFloatArray.js +34 -0
  59. package/core/math/hash/computeObjectHash.js +54 -0
  60. package/core/math/intersects1D.js +19 -0
  61. package/core/math/interval/NumericInterval.js +2 -2
  62. package/core/math/isValueBetween.js +10 -0
  63. package/core/math/isValueBetweenInclusive.js +10 -0
  64. package/core/math/noise/curl_noise_3dt.js +1 -1
  65. package/core/math/noise/sdnoise.js +10 -10
  66. package/core/math/overlap1D.js +19 -0
  67. package/core/math/pingpong.js +17 -0
  68. package/core/math/random/makeRangedRandom.js +19 -0
  69. package/core/math/random/randomFloatBetween.js +14 -0
  70. package/core/math/random/randomFromArray.js +19 -0
  71. package/core/math/random/randomGaussian.js +15 -0
  72. package/core/math/random/randomIntegerBetween.js +14 -0
  73. package/core/math/random/roundFair.js +15 -0
  74. package/core/math/separation1D.js +21 -0
  75. package/core/math/solveQuadratic.js +25 -0
  76. package/core/model/BoundedValue.js +1 -1
  77. package/core/model/node-graph/node/NodeInstancePortReference.js +1 -1
  78. package/core/model/node-graph/node/Port.js +1 -1
  79. package/core/model/reactive/evaluation/MultiPredicateEvaluator.spec.js +3 -1
  80. package/core/model/reactive/model/ReactiveBinaryExpression.js +1 -1
  81. package/core/model/reactive/model/terminal/ReactiveLiteralNumber.js +1 -1
  82. package/core/model/reactive/model/terminal/ReactiveReference.js +1 -1
  83. package/core/model/reactive/model/util/createRandomReactiveExpression.js +1 -1
  84. package/core/model/stat/LinearModifier.js +1 -1
  85. package/core/primitives/array/computeIntegerArrayHash.js +1 -1
  86. package/{engine/graphics/render/forward_plus/materials → core/primitives/strings}/insert_after.js +3 -0
  87. package/core/primitives/strings/insert_after_or_replace.js +27 -0
  88. package/editor/process/symbolic/makeHelperBoxGeometry.js +44 -0
  89. package/editor/view/ecs/EntityEditor.js +2 -2
  90. package/editor/view/ecs/components/particles/ParticleEmitterController.js +2 -2
  91. package/engine/EngineHarness.js +1 -0
  92. package/engine/animation/AnimationUtils.js +5 -5
  93. package/engine/animation/curve/AnimationCurve.js +72 -0
  94. package/engine/animation/curve/Keyframe.js +27 -0
  95. package/engine/animation/keyed2/AnimationTrack.js +27 -3
  96. package/engine/asset/Asset.js +1 -1
  97. package/engine/asset/loaders/GLTFAssetLoader.d.ts +1 -1
  98. package/engine/asset/loaders/GLTFAssetLoader.js +10 -0
  99. package/engine/asset/loaders/image/ImageRGBADataAsset.js +8 -1
  100. package/engine/asset/loaders/material/computeImageBitmapEquality.js +11 -0
  101. package/engine/asset/loaders/material/computeImageBitmapHash.js +22 -28
  102. package/engine/asset/loaders/material/computeMaterialHash.js +3 -1
  103. package/engine/asset/loaders/material/computeTextureHash.js +2 -1
  104. package/engine/ecs/EntityBuilder.js +25 -5
  105. package/engine/ecs/animation/Animation.js +2 -1
  106. package/engine/ecs/animation/InverseKinematics.js +2 -1
  107. package/engine/ecs/attachment/AttachmentBinding.js +8 -0
  108. package/engine/ecs/attachment/AttachmentSystem.js +4 -0
  109. package/engine/ecs/attachment/TransformAttachmentBinding.js +14 -44
  110. package/engine/ecs/components/Tag.js +27 -6
  111. package/engine/ecs/dynamic_actions/DynamicActorSystem.js +2 -1
  112. package/engine/ecs/dynamic_actions/DynamicRuleDescriptionTable.spec.js +3 -5
  113. package/engine/ecs/dynamic_actions/actions/definition/WeightedRandomActionDescription.js +1 -1
  114. package/engine/ecs/evaluation/complex/PointFitnessGaussianBlur.js +1 -1
  115. package/engine/ecs/foliage/ecs/Foliage2.js +1 -1
  116. package/engine/ecs/fow/FogOfWar.js +4 -0
  117. package/engine/ecs/fow/FogOfWarSystem.js +2 -0
  118. package/engine/ecs/fow/shader/FogOfWarRenderer.js +1 -1
  119. package/engine/ecs/gui/GUIElement.js +1 -1
  120. package/engine/ecs/gui/hud/HeadsUpDisplay.js +1 -1
  121. package/engine/ecs/gui/hud/HeadsUpDisplaySystem.js +2 -0
  122. package/engine/ecs/gui/position/ViewportPosition.js +2 -1
  123. package/engine/ecs/system/AbstractContextSystem.js +1 -1
  124. package/engine/ecs/systems/RangedAttackSystem.js +1 -1
  125. package/engine/ecs/systems/SteeringSystem.js +1 -1
  126. package/engine/ecs/systems/TagSystem.js +17 -0
  127. package/engine/ecs/terrain/tiles/TerrainTileManager.js +1 -1
  128. package/engine/ecs/tooltip/TooltipComponent.js +15 -0
  129. package/engine/ecs/transform/Transform.js +19 -6
  130. package/engine/ecs/util/hideEntityGracefully.js +18 -0
  131. package/engine/graphics/GraphicsEngine.js +11 -23
  132. package/engine/graphics/camera/testClippingPlaneComputation.js +2 -2
  133. package/engine/graphics/composit/CompositLayer.js +17 -4
  134. package/engine/graphics/composit/CompositingStages.js +8 -0
  135. package/engine/graphics/composit/LayerCompositer.js +35 -6
  136. package/engine/graphics/ecs/animation/animator/AnimationClip.js +2 -1
  137. package/engine/graphics/ecs/animation/animator/AnimationClipDefinition.js +2 -1
  138. package/engine/graphics/ecs/animation/animator/AnimationNotification.js +2 -1
  139. package/engine/graphics/ecs/animation/animator/AnimationNotificationDefinition.js +2 -1
  140. package/engine/graphics/ecs/animation/animator/graph/AnimationGraph.js +2 -1
  141. package/engine/graphics/ecs/animation/animator/graph/definition/AnimationGraphDefinition.js +2 -1
  142. package/engine/graphics/ecs/animation/animator/graph/definition/AnimationStateDefinition.js +1 -1
  143. package/engine/graphics/ecs/animation/animator/graph/definition/AnimationTransitionDefinition.js +2 -1
  144. package/engine/graphics/ecs/camera/CameraClippingPlaneComputer.js +1 -1
  145. package/engine/graphics/ecs/highlight/HighlightDefinition.js +2 -1
  146. package/engine/graphics/ecs/highlight/plugin/OutlineRenderPlugin.js +11 -7
  147. package/engine/graphics/ecs/light/Light.d.ts +1 -1
  148. package/engine/graphics/ecs/light/Light.js +5 -0
  149. package/engine/graphics/ecs/light/binding/three/ThreeLightBinding.js +5 -1
  150. package/engine/graphics/ecs/mesh/Mesh.js +2 -1
  151. package/engine/graphics/ecs/mesh-v2/DrawMode.js +5 -0
  152. package/engine/graphics/ecs/mesh-v2/ShadedGeometry.d.ts +13 -0
  153. package/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +32 -18
  154. package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.d.ts +6 -0
  155. package/engine/graphics/ecs/path/testPathDisplaySystem.js +98 -98
  156. package/engine/graphics/ecs/trail2d/Trail2D.js +17 -4
  157. package/engine/graphics/ecs/trail2d/Trail2DSystem.d.ts +2 -3
  158. package/engine/graphics/ecs/trail2d/Trail2DSystem.js +34 -118
  159. package/engine/graphics/geometry/AttributeSpec.js +105 -0
  160. package/engine/graphics/{micron/format/MicronVertexDataSpec.js → geometry/VertexDataSpec.js} +56 -25
  161. package/engine/graphics/micron/build/buildMicronGeometryFromBufferGeometry.js +7 -7
  162. package/engine/graphics/micron/build/fill_patch_geometry_data.js +1 -1
  163. package/engine/graphics/micron/buildPatchwork.js +1 -1
  164. package/engine/graphics/micron/format/MicronGeometry.js +3 -3
  165. package/engine/graphics/micron/format/serialization/MicronGeometryBinarySerializationAdapter.js +2 -2
  166. package/engine/graphics/micron/format/serialization/deserialize_attribute_spec.js +1 -1
  167. package/engine/graphics/micron/format/serialization/serialize_attribute_spec.js +1 -1
  168. package/engine/graphics/micron/render/PatchCacheKey.js +1 -1
  169. package/engine/graphics/micron/render/instanced/AttributeDataTexture.js +5 -5
  170. package/engine/graphics/micron/render/v1/ThreeVirtualGeometryAdapter.js +1 -1
  171. package/engine/graphics/particles/ParticleEmitterLibrary.js +3 -0
  172. package/engine/graphics/particles/ecs/{ParticleEmitterSystem2.js → ParticleEmitterSystem.js} +17 -9
  173. package/engine/graphics/particles/particular/engine/ParticularEngine.js +12 -4
  174. package/engine/graphics/particles/particular/engine/emitter/PARTICULAR_PARTICLE_SPECIFICATION.js +84 -0
  175. package/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.js +106 -169
  176. package/engine/graphics/particles/particular/engine/emitter/ParticleEmitterFlag.js +5 -0
  177. package/engine/graphics/particles/particular/engine/emitter/ParticleLayer.js +14 -3
  178. package/engine/graphics/particles/particular/engine/emitter/ParticlePool.js +141 -14
  179. package/engine/graphics/particles/particular/engine/emitter/ParticlePool.spec.js +8 -7
  180. package/engine/graphics/particles/particular/engine/emitter/computeEmissionFunction.js +37 -0
  181. package/engine/graphics/particles/particular/engine/emitter/distance_to_camera.js +25 -0
  182. package/engine/graphics/particles/particular/engine/emitter/serde/ParameterLookupTableSerializationAdapter.js +8 -2
  183. package/engine/graphics/particles/particular/engine/parameter/ParameterLookupTable.js +2 -1
  184. package/engine/graphics/particles/particular/engine/parameter/ParameterTrack.js +1 -1
  185. package/engine/graphics/particles/particular/engine/parameter/ParticleParameter.js +1 -1
  186. package/engine/graphics/particles/particular/engine/renderers/billboard/BILLBOARD_PARTICLE_SPECIFICATION.js +24 -0
  187. package/engine/graphics/particles/particular/engine/renderers/billboard/ParticleBillboardMaterial.js +262 -71
  188. package/engine/graphics/particles/particular/engine/renderers/billboard/prototypeBillboardRenderer.js +9 -9
  189. package/engine/graphics/particles/particular/engine/shader/ShaderManager.js +80 -46
  190. package/engine/graphics/particles/particular/engine/shader/debugAtlas.js +14 -0
  191. package/engine/graphics/particles/particular/engine/simulator/SimulationStepApplyForce.js +2 -5
  192. package/engine/graphics/particles/particular/engine/simulator/SimulationStepCurlNoiseAcceleration.js +2 -6
  193. package/engine/graphics/particles/particular/engine/simulator/SimulationStepCurlNoiseVelocity.js +2 -7
  194. package/engine/graphics/particles/particular/engine/simulator/SimulationStepFixedPhysics.js +2 -5
  195. package/engine/graphics/particles/particular/engine/simulator/update_parameters.js +1 -1
  196. package/engine/graphics/particles/particular/engine/utils/distributeParticlesOnObject3D.js +1 -1
  197. package/engine/graphics/particles/particular/engine/utils/distrubuteParticlesOnMesh.js +1 -1
  198. package/engine/graphics/particles/particular/engine/utils/volume/AttributeValue.js +141 -0
  199. package/engine/graphics/particles/particular/engine/utils/volume/ParticleVolume.js +478 -0
  200. package/engine/graphics/particles/particular/engine/utils/volume/lut_to_sampler.js +27 -0
  201. package/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +935 -0
  202. package/engine/graphics/particles/particular/group/Operation.js +18 -0
  203. package/engine/graphics/particles/particular/group/OperationType.js +9 -0
  204. package/engine/graphics/particles/particular/group/ParticleAttribute.js +2 -1
  205. package/engine/graphics/particles/particular/group/ParticleAttributeType.js +11 -0
  206. package/engine/graphics/particles/particular/group/ParticleDataType.js +10 -0
  207. package/engine/graphics/particles/particular/group/ParticleGroup.js +7 -245
  208. package/engine/graphics/particles/particular/group/ParticleGroup.spec.js +3 -1
  209. package/engine/graphics/particles/particular/group/ParticleSpecification.js +21 -14
  210. package/engine/graphics/particles/particular/group/itemSizeFromAttributeType.js +20 -0
  211. package/engine/graphics/particles/particular/group/optimizeCommandQueue.js +162 -0
  212. package/engine/graphics/particles/particular/group/typedArrayConstructorFromDataType.js +19 -0
  213. package/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +2 -2
  214. package/engine/graphics/render/buffer/simple-fx/ao/AmbientOcclusionPostProcessEffect.js +13 -7
  215. package/engine/graphics/render/buffer/slot/parameter/ProgramValueSlotParameter.js +2 -1
  216. package/engine/graphics/render/buffer/slot/parameter/ProgramValueSlotParameterSet.js +1 -1
  217. package/engine/graphics/render/forward_plus/LightManager.js +126 -95
  218. package/engine/graphics/render/forward_plus/PointLight.js +9 -0
  219. package/engine/graphics/render/forward_plus/PointLightData.js +1 -1
  220. package/engine/graphics/render/forward_plus/SpotLight.js +9 -0
  221. package/engine/graphics/render/forward_plus/cluster/compute_light_data_hash_0.js +2 -2
  222. package/engine/graphics/render/forward_plus/computeFrustumCorners.js +14 -32
  223. package/engine/graphics/render/forward_plus/materials/FP_INJECTION_POINT_ACCUMULATION.js +1 -0
  224. package/engine/graphics/render/forward_plus/materials/FP_SHADER_CHUNK_ACCUMULATION.js +32 -0
  225. package/engine/graphics/render/forward_plus/materials/FP_SHADER_CHUNK_DECODE_PARS.js +51 -0
  226. package/engine/graphics/render/forward_plus/materials/FP_SHADER_CHUNK_PREAMBLE.js +25 -0
  227. package/engine/graphics/render/forward_plus/materials/fp_build_fragment_shader.js +31 -120
  228. package/engine/graphics/render/forward_plus/materials/fp_build_vertex_lighting_shared.js +35 -0
  229. package/engine/graphics/render/forward_plus/materials/fp_build_vertex_shader.js +4 -5
  230. package/engine/graphics/render/forward_plus/plugin/ForwardPlusRenderingPlugin.js +1 -1
  231. package/engine/graphics/render/forward_plus/plugin/MaterialTransformer.js +10 -3
  232. package/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +595 -60
  233. package/engine/graphics/render/forward_plus/prototypeLightManager.js +256 -136
  234. package/engine/graphics/render/forward_plus/query/analytical_triplanar_corner_mapping.js +8 -0
  235. package/engine/graphics/render/forward_plus/query/cube_mapping.js +38 -0
  236. package/engine/graphics/render/forward_plus/query/detailed_sphere_frustum_intersection_test.js +86 -0
  237. package/engine/graphics/render/forward_plus/query/point_light_inside_volume.js +73 -0
  238. package/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_objects.js +131 -0
  239. package/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_texture.js +129 -0
  240. package/engine/graphics/render/forward_plus/query/spot_light_inside_volume.js +33 -0
  241. package/engine/graphics/render/forward_plus/read_frustum_corner.js +14 -0
  242. package/engine/graphics/render/forward_plus/testClusterEquality.js +22 -0
  243. package/engine/graphics/render/layers/RenderLayerUtils.js +7 -4
  244. package/engine/graphics/render/visibility/IncrementalDeltaSet.js +11 -0
  245. package/engine/graphics/render/visibility/hiz/prototypeHiZ.js +2 -2
  246. package/engine/graphics/shaders/TerrainShader.js +4 -5
  247. package/engine/graphics/texture/atlas/AtlasPatch.js +7 -2
  248. package/engine/graphics/texture/atlas/TextureAtlas.js +2 -2
  249. package/engine/graphics/texture/sampler/HarmonicDiffusionGrid.spec.js +1 -1
  250. package/engine/graphics/texture/sampler/SampleTraverser.js +1 -1
  251. package/engine/graphics/texture/sampler/Sampler2D.js +8 -7
  252. package/engine/graphics/texture/sampler/distanceField.spec.js +1 -1
  253. package/engine/graphics/texture/sampler/scaleSampler2D.js +7 -10
  254. package/engine/graphics/trail/x/RibbonMaterialX.js +3 -3
  255. package/engine/graphics/trail/x/RibbonX.js +17 -2
  256. package/engine/graphics/trail/x/RibbonXPlugin.js +51 -1
  257. package/engine/graphics/util/composeMatrix4.js +33 -23
  258. package/engine/graphics/util/decompose_matrix_4_array.js +61 -0
  259. package/engine/grid/components/GridObstacle.js +3 -10
  260. package/engine/intelligence/behavior/ecs/BehaviorComponent.js +30 -14
  261. package/engine/intelligence/behavior/selector/WeightedElement.js +2 -1
  262. package/engine/intelligence/optimization/RandomOptimizer.js +1 -1
  263. package/engine/knowledge/database/StaticKnowledgeDataTable.js +6 -1
  264. package/engine/navigation/ecs/components/Path.js +1 -6
  265. package/engine/navigation/grid/FastBinaryHeap.spec.js +1 -1
  266. package/engine/reference/v2/Reference.js +6 -0
  267. package/engine/sound/ecs/emitter/SoundEmitter.js +2 -1
  268. package/engine/sound/ecs/emitter/SoundTrack.js +2 -1
  269. package/engine/sound/material/concrete/RandomSoundMaterial.js +1 -1
  270. package/engine/ui/notification/notificationGenerator.js +1 -1
  271. package/generation/filtering/numeric/complex/CellFilterGaussianBlur.js +1 -1
  272. package/generation/grid/generation/GridTaskExecuteRuleTimes.js +2 -1
  273. package/generation/markers/actions/MarkerNodeActionSelectRandom.js +1 -1
  274. package/generation/markers/transform/MarkerNodeTransformerRecordUniqueRandomEnum.js +1 -1
  275. package/generation/placement/action/random/CellActionSelectRandom.js +1 -1
  276. package/generation/theme/ThemeEngine.js +2 -2
  277. package/misc/makeMaterialIconCached.js +2 -2
  278. package/package.json +3 -3
  279. package/view/View.js +4 -2
  280. package/view/elements/image/HTMLElementCacheKey.js +2 -1
  281. package/view/elements/radial/RadialText.js +2 -1
  282. package/view/minimap/gl/MinimapMarkersGL.js +6 -100
  283. package/view/minimap/gl/buildMaterial.js +94 -0
  284. package/engine/graphics/micron/format/MicronGeometryBufferAttributeSpec.js +0 -71
  285. package/engine/graphics/render/forward_plus/queryBVH_Frustum.js +0 -345
@@ -6,8 +6,13 @@ import { min2 } from "../../math/min2.js";
6
6
  import { IndexedBinaryBVHVisitor } from "./IndexedBinaryBVHVisitor.js";
7
7
  import { NodeType } from "./NodeType.js";
8
8
  import { RayLeafIntersectionVisitor } from "./RayLeafIntersectionVisitor.js";
9
+ import { array_copy } from "../../collection/array/copyArray.js";
9
10
 
10
11
 
12
+ /**
13
+ *
14
+ * @type {Float32Array|number[]}
15
+ */
11
16
  const scratch_aabb_0 = new Float32Array(6);
12
17
 
13
18
 
@@ -30,16 +35,16 @@ export default class IndexedBinaryBVH {
30
35
  this.binaryNodeCount = 0;
31
36
 
32
37
  /**
33
- *
38
+ * Total number of boxes contained in the tree, some might be unused
34
39
  * @type {number}
35
40
  */
36
41
  this.boxCount = 0;
37
42
 
38
43
  /**
39
44
  *
40
- * @type {null|Float32Array}
45
+ * @type {Float32Array|number[]}
41
46
  */
42
- this.data = null;
47
+ this.data = new Float32Array(16);
43
48
  }
44
49
 
45
50
  /**
@@ -59,7 +64,14 @@ export default class IndexedBinaryBVH {
59
64
 
60
65
  this.boxCount = this.leafNodeCount + this.binaryNodeCount;
61
66
 
62
- this.data = new Float32Array(this.boxCount * 6);
67
+ // possibly resize the storage
68
+ const storage_size = this.boxCount * 6;
69
+
70
+ if (this.data.length < storage_size) {
71
+ this.data = new Float32Array(storage_size);
72
+ } else {
73
+ this.data.fill(0);
74
+ }
63
75
  }
64
76
 
65
77
  unsortedBuiltIntermediate() {
@@ -117,7 +129,7 @@ export default class IndexedBinaryBVH {
117
129
  }
118
130
 
119
131
  //set bounds of the bvh
120
- copy_box_array(0, data, scratch_aabb_0, 0);
132
+ array_copy(data, 0, scratch_aabb_0, 0, 6);
121
133
 
122
134
  this.x0 = scratch_aabb_0[0];
123
135
  this.y0 = scratch_aabb_0[1];
@@ -238,7 +250,7 @@ export default class IndexedBinaryBVH {
238
250
  }
239
251
 
240
252
  /**
241
- *
253
+ * @deprecated use a visitor object instead
242
254
  * @param {number} startX
243
255
  * @param {number} startY
244
256
  * @param {number} startZ
@@ -265,22 +277,6 @@ export default class IndexedBinaryBVH {
265
277
  }
266
278
  }
267
279
 
268
- /**
269
- *
270
- * @param {number} source_offset
271
- * @param {number[]|Float32Array} source
272
- * @param {number[]|Float32Array} destination
273
- * @param {number} destination_offset
274
- */
275
- function copy_box_array(source_offset, source, destination, destination_offset) {
276
- destination[destination_offset] = source[source_offset];
277
- destination[destination_offset + 1] = source[source_offset + 1];
278
- destination[destination_offset + 2] = source[source_offset + 2];
279
- destination[destination_offset + 3] = source[source_offset + 3];
280
- destination[destination_offset + 4] = source[source_offset + 4];
281
- destination[destination_offset + 5] = source[source_offset + 5];
282
- }
283
-
284
280
  /**
285
281
  *
286
282
  * @param {number[]|Float32Array} source
@@ -348,23 +344,23 @@ function writeBox(array, address, x0, y0, z0, x1, y1, z1) {
348
344
  * @param {Float32Array} array
349
345
  */
350
346
  function copyBox(from, to, array) {
351
- copy_box_array(from, array, array, to);
347
+ array_copy(array, from, array, to, 6);
352
348
  }
353
349
 
354
350
  /**
355
351
  *
356
352
  * @param {number} from
357
353
  * @param {number} to
358
- * @param {Float32Array} array
354
+ * @param {Float32Array|number[]} array
359
355
  */
360
356
  function copyBoxZeroSize(from, to, array) {
361
- copy_box_array(from, array, scratch_aabb_0, 0);
357
+ array_copy(array, from, scratch_aabb_0, 0, 3);
362
358
 
363
359
  scratch_aabb_0[3] = scratch_aabb_0[0];
364
360
  scratch_aabb_0[4] = scratch_aabb_0[1];
365
361
  scratch_aabb_0[5] = scratch_aabb_0[2];
366
362
 
367
- copy_box_array(0, scratch_aabb_0, array, to);
363
+ array_copy(scratch_aabb_0, 0, array, to, 6);
368
364
  }
369
365
 
370
366
  /**
@@ -40,7 +40,11 @@ export class ThreeClippingPlaneComputingBVHVisitor extends BVHVisitor {
40
40
  */
41
41
  this.__nearPlaneConstant = 0;
42
42
 
43
-
43
+ /**
44
+ *
45
+ * @type {Float32Array}
46
+ * @private
47
+ */
44
48
  this.__planes_f32 = new Float32Array(24);
45
49
 
46
50
  this.near = 0;
@@ -6,35 +6,55 @@ import { aabb3_edge_corner_mapping } from "../aabb3/aabb3_edge_corner_mapping.js
6
6
  import { __process_point_if_within_planes } from "./__process_point_if_within_planes.js";
7
7
  import { plane_computeConvex3PlaneIntersection } from "../../geom/3d/plane/plane_computeConvex3PlaneIntersection.js";
8
8
  import { EPSILON } from "../../math/MathUtils.js";
9
- import Vector3 from "../../geom/Vector3.js";
9
+
10
+ /**
11
+ * Common piece of continuous memory for better cache coherence
12
+ * @type {ArrayBuffer}
13
+ * @private
14
+ */
15
+ const __scratch_buffer = new ArrayBuffer(
16
+ 24 * 4
17
+ + 24 * 4
18
+ + 8 * 4
19
+ + 3 * 4
20
+ );
10
21
 
11
22
  /**
12
23
  *
13
24
  * @type {number[]}
14
25
  */
15
- const scratch_aabb_corners = new Float32Array(24);
26
+ const scratch_aabb_corners = new Float32Array(__scratch_buffer, 0, 24);
16
27
 
17
28
  /**
18
29
  *
19
30
  * @type {number[]}
20
31
  */
21
- const scratch_aabb_planes = new Float32Array(24);
32
+ const scratch_aabb_planes = new Float32Array(__scratch_buffer, 96, 24);
22
33
 
23
34
  /**
24
35
  *
25
36
  * @type {number[]}
26
37
  */
27
- const scratch_corner_out_bitfields = new Uint32Array(8);
38
+ const scratch_corner_out_bitfields = new Uint32Array(__scratch_buffer, 192, 8);
28
39
 
29
- const scratch_v3 = new Vector3();
40
+ /**
41
+ *
42
+ * @type {number[]}
43
+ */
44
+ const scratch_v3_array = new Float32Array(__scratch_buffer, 224, 3);
30
45
 
31
46
  /**
47
+ * Figures out intersection volume between an AABB and a frustum for much tighter bounds
48
+ *
49
+ * Especially beneficial when trying to intersect a large AABB against a small frustum,
50
+ * where where traditionally only AABB corners would be considered,
51
+ * we're instead able to compute minimum bounds of the overlap of the two
32
52
  *
33
53
  * @param {AABB3} box
34
54
  * @param {number[]} planes
35
55
  * @param {number} plane_count
36
56
  * @param {number} plane_mask
37
- * @param {function} callback
57
+ * @param {function(x:number,y:number,z:number)} callback
38
58
  * @param {*} [thisArg]
39
59
  * @private
40
60
  */
@@ -183,7 +203,7 @@ export function __detailed_box_volume_intersection(
183
203
  const c = planes[plane_address + 3];
184
204
 
185
205
  const edge_intersects = plane3_computeLineSegmentIntersection(
186
- scratch_v3,
206
+ scratch_v3_array, 0,
187
207
  corner_0_x, corner_0_y, corner_0_z,
188
208
  corner_1_x, corner_1_y, corner_1_z,
189
209
  nx, ny, nz, c
@@ -192,7 +212,7 @@ export function __detailed_box_volume_intersection(
192
212
  if (edge_intersects) {
193
213
  // a possible candidate, let's see if this point is within rest of the planes
194
214
  __process_point_if_within_planes(
195
- scratch_v3.x, scratch_v3.y, scratch_v3.z,
215
+ scratch_v3_array[0], scratch_v3_array[1], scratch_v3_array[2],
196
216
  (plane_mask ^ plane_bit_mask),
197
217
  planes,
198
218
  plane_count,
@@ -230,7 +250,7 @@ export function __detailed_box_volume_intersection(
230
250
  const cp_1 = next_orthogonal_plane_index * 4;
231
251
 
232
252
  const intersection_exists = plane_computeConvex3PlaneIntersection(
233
- scratch_v3,
253
+ scratch_v3_array, 0,
234
254
  aabb_plane_nx, aabb_plane_ny, aabb_plane_nz, aabb_plane_constant,
235
255
  planes[cp_0], planes[cp_0 + 1], planes[cp_0 + 2], planes[cp_0 + 3],
236
256
  planes[cp_1], planes[cp_1 + 1], planes[cp_1 + 2], planes[cp_1 + 3]
@@ -238,14 +258,14 @@ export function __detailed_box_volume_intersection(
238
258
 
239
259
  if (intersection_exists) {
240
260
 
241
- const point_within_box = box.containsPointWithTolerance(scratch_v3.x, scratch_v3.y, scratch_v3.z, EPSILON);
261
+ const point_within_box = box.containsPointWithTolerance(scratch_v3_array[0], scratch_v3_array[1], scratch_v3_array[2], EPSILON);
242
262
 
243
263
  if (point_within_box) {
244
264
  // point is within the AABB bounds
245
265
 
246
266
  // ThreeClippingPlaneComputingBVHVisitor.DEBUG_POINTS_2.send3(scratch_v3.x, scratch_v3.y, scratch_v3.z);
247
267
 
248
- callback.call(thisArg, scratch_v3.x, scratch_v3.y, scratch_v3.z);
268
+ callback.call(thisArg, scratch_v3_array[0], scratch_v3_array[1], scratch_v3_array[2]);
249
269
  }
250
270
  }
251
271
  }
@@ -6,9 +6,9 @@
6
6
  */
7
7
  import { assert } from "../assert.js";
8
8
  import { returnZero } from "../function/Functions.js";
9
- import { randomIntegerBetween } from "../math/MathUtils.js";
10
9
  import { min2 } from "../math/min2.js";
11
10
  import { HashMap } from "./HashMap.js";
11
+ import { randomIntegerBetween } from "../math/random/randomIntegerBetween.js";
12
12
 
13
13
 
14
14
  /**
@@ -5,11 +5,14 @@ const stack = [];
5
5
  /**
6
6
  * @template T
7
7
  * @param {T[]} data
8
- * @param {function(T):number} keyExtractor
8
+ * @param {function(T):number} score_function
9
+ * @param {*} score_function_context
9
10
  * @param {number} start
10
11
  * @param {number} end
12
+ * @param {function(T[],number, number):*} [swap_operator]
13
+ * @param {*} [swap_context]
11
14
  */
12
- export function arrayQuickSort(data, keyExtractor, start, end) {
15
+ export function arrayQuickSort(data, score_function, score_function_context, start, end, swap_operator = arraySwapElements, swap_context = undefined) {
13
16
  if (start >= end) {
14
17
  // section of 0 size, nothing to sort
15
18
  return;
@@ -32,15 +35,15 @@ export function arrayQuickSort(data, keyExtractor, start, end) {
32
35
 
33
36
  const pivotIndex = (left + right) >> 1;
34
37
 
35
- const pivot = keyExtractor(data[pivotIndex]);
38
+ const pivot = score_function.call(score_function_context,data[pivotIndex]);
36
39
 
37
40
  /* partition */
38
41
  while (i <= j) {
39
- while (keyExtractor(data[i]) < pivot) {
42
+ while (score_function.call(score_function_context,data[i]) < pivot) {
40
43
  i++;
41
44
  }
42
45
 
43
- while (keyExtractor(data[j]) > pivot) {
46
+ while (score_function.call(score_function_context,data[j]) > pivot) {
44
47
  j--;
45
48
  }
46
49
 
@@ -48,7 +51,7 @@ export function arrayQuickSort(data, keyExtractor, start, end) {
48
51
 
49
52
  if (i !== j) {
50
53
  //do swap
51
- arraySwapElements(data, i, j);
54
+ swap_operator.call(swap_context, data, i, j);
52
55
  }
53
56
 
54
57
  i++;
@@ -0,0 +1,22 @@
1
+ /**
2
+ *
3
+ * @param {T[]|ArrayLike<T>|TypedArray|Uint8ClampedArray|Uint8Array} a
4
+ * @param {number} a_offset
5
+ * @param {T[]|ArrayLike<T>|TypedArray|Uint8ClampedArray|Uint8Array} b
6
+ * @param {number} b_offset
7
+ * @param {number} length How many elements should be moved
8
+ */
9
+ export function array_swap(a, a_offset, b, b_offset, length) {
10
+
11
+ let i, j, k;
12
+
13
+ for (k = 0; k < length; k++) {
14
+ i = a_offset + k;
15
+ j = b_offset + k;
16
+
17
+ const t = b[j];
18
+
19
+ b[j] = a[i];
20
+ a[i] = t;
21
+ }
22
+ }
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @template T,V
3
- * @param {T[]} array
3
+ * @param {T[]|ArrayLike<T>|Float32Array} array
4
4
  * @param {V} el
5
5
  * @param {function(V,T):number} compareFunction
6
6
  * @param {number} [minIndex]
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @template T
3
+ * @param {T[]} array
4
+ * @param {function(T):number} elementHashFunction
5
+ */
6
+ export function computeHashArray(array, elementHashFunction) {
7
+
8
+ const numArguments = array.length;
9
+ let hash = numArguments;
10
+
11
+ for (let i = 0; i < numArguments; i++) {
12
+
13
+ const singleValue = array[i];
14
+
15
+ const elementHash = elementHashFunction(singleValue);
16
+
17
+ hash = ((hash << 5) - hash) + elementHash;
18
+ hash |= 0; // Convert to 32bit integer
19
+ }
20
+
21
+ return hash;
22
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Computes hash on integer values
3
+ * @param {...number} value
4
+ * @returns {number}
5
+ */
6
+ export function computeHashIntegerArray(value) {
7
+ let hash = 0;
8
+ const numArguments = arguments.length;
9
+ for (let i = 0; i < numArguments; i++) {
10
+ const singleValue = arguments[i];
11
+ hash = ((hash << 5) - hash) + singleValue;
12
+ hash |= 0; // Convert to 32bit integer
13
+ }
14
+ return hash;
15
+ }
@@ -25,9 +25,9 @@ export function copyArray(source, target) {
25
25
  * Follows Java System.arraycopy interface
26
26
  * Copy data from one array to another
27
27
  * @template T
28
- * @param {T[]|ArrayLike<T>|TypedArray|Uint8ClampedArray|Uint8Array} source The source array
28
+ * @param {T[]|ArrayLike<T>|TypedArray|Uint8ClampedArray|Uint8Array|Float32Array|Float64Array} source The source array
29
29
  * @param {number} source_position Starting position where to copy from inside the source array
30
- * @param {T[]|ArrayLike<T>|TypedArray|Uint8ClampedArray|Uint8Array} destination The destination array
30
+ * @param {T[]|ArrayLike<T>|TypedArray|Uint8ClampedArray|Uint8Array|Float32Array|Float64Array} destination The destination array
31
31
  * @param {number} destination_position Starting position where to copy to inside the destination array
32
32
  * @param {number} length How many elements should be copied
33
33
  */
@@ -16,4 +16,19 @@ export const DataType2TypedArrayConstructorMapping = {
16
16
  [DataType.Float16]: Uint16Array,
17
17
  [DataType.Float32]: Float32Array,
18
18
  [DataType.Float64]: Float64Array,
19
+ };
20
+
21
+ /**
22
+ *
23
+ * @param {DataType} dt
24
+ * @returns {constructor|function}
25
+ */
26
+ export function compute_typed_array_constructor_from_data_type(dt) {
27
+ const r = DataType2TypedArrayConstructorMapping[dt];
28
+
29
+ if (r === undefined) {
30
+ throw new Error(`Unsupported data type '${dt}'`);
31
+ }
32
+
33
+ return r;
19
34
  }
@@ -1,11 +1,12 @@
1
1
  import { assert } from "../assert.js";
2
2
  import Signal from "../events/signal/Signal.js";
3
- import { computeHashFloat, computeHashIntegerArray } from "../math/MathUtils.js";
4
3
  import { parseColor, rgb2hsv } from "./ColorUtils.js";
5
4
  import { clamp } from "../math/clamp.js";
6
5
  import { min2 } from "../math/min2.js";
7
6
  import { max2 } from "../math/max2.js";
8
7
  import { min3 } from "../math/min3.js";
8
+ import { computeHashIntegerArray } from "../collection/array/computeHashIntegerArray.js";
9
+ import { computeHashFloat } from "../math/hash/computeHashFloat.js";
9
10
 
10
11
  class Color {
11
12
  /**
@@ -1,11 +1,12 @@
1
1
  import { assert } from "../assert.js";
2
2
  import { Cache } from "../cache/Cache.js";
3
3
  import { isArrayEqualStrict } from "../collection/array/isArrayEqualStrict.js";
4
- import { computeHashArray, computeHashIntegerArray } from "../math/MathUtils.js";
5
4
  import { invokeObjectEquals } from "../model/object/invokeObjectEquals.js";
6
5
  import { invokeObjectHash } from "../model/object/invokeObjectHash.js";
7
6
  import { computeStringHash } from "../primitives/strings/computeStringHash.js";
8
7
  import { computeUTF8StringByteSize } from "../primitives/strings/StringUtils.js";
8
+ import { computeHashArray } from "../collection/array/computeHashArray.js";
9
+ import { computeHashIntegerArray } from "../collection/array/computeHashIntegerArray.js";
9
10
 
10
11
  /**
11
12
  * Hash is an integer value, so this is an invalid value for a computed hash
@@ -1,5 +1,3 @@
1
- import { computePointDistanceToPlane } from "../../Plane.js";
2
-
3
1
  /**
4
2
  * @param {number} plane_normal_x
5
3
  * @param {number} plane_normal_y
@@ -14,38 +12,16 @@ import { computePointDistanceToPlane } from "../../Plane.js";
14
12
  * @returns {number}
15
13
  */
16
14
  export function aabb3_computeDistanceAbovePlane(
17
- plane_normal_x,
18
- plane_normal_y,
19
- plane_normal_z,
20
- plane_constant,
21
- _x0,
22
- _y0,
23
- _z0,
24
- _x1,
25
- _y1,
26
- _z1
15
+ plane_normal_x, plane_normal_y, plane_normal_z, plane_constant,
16
+ _x0, _y0, _z0,
17
+ _x1, _y1, _z1
27
18
  ) {
28
19
 
29
- let px, py, pz;
30
-
31
- // pick a corner point furthest along the normal
32
- if (plane_normal_x > 0) {
33
- px = _x1;
34
- } else {
35
- px = _x0;
36
- }
37
-
38
- if (plane_normal_y > 0) {
39
- py = _y1;
40
- } else {
41
- py = _y0;
42
- }
43
-
44
- if (plane_normal_z > 0) {
45
- pz = _z1;
46
- } else {
47
- pz = _z0;
48
- }
20
+ // pick a corner point furthest along the plane normal
21
+ const px = plane_normal_x > 0 ? _x1 : _x0;
22
+ const py = plane_normal_y > 0 ? _y1 : _y0;
23
+ const pz = plane_normal_z > 0 ? _z1 : _z0;
49
24
 
50
- return computePointDistanceToPlane(px, py, pz, plane_normal_x, plane_normal_y, plane_normal_z, plane_constant);
25
+ // dot(v4,v4) inlined for speed
26
+ return (plane_normal_x * px + plane_normal_y * py + plane_normal_z * pz) + plane_constant;
51
27
  }
@@ -1,8 +1,8 @@
1
- import { ray_computeNearestPointToPoint } from "../../LineSegment.js";
2
1
  import { computePlanePlaneIntersection, computePointDistanceToPlane } from "../../Plane.js";
3
2
  import Vector3 from "../../Vector3.js";
4
3
  import { plane3_projectPoint } from "../plane/plane3_projectPoint.js";
5
4
  import { plane_three_computeConvex3PlaneIntersection } from "../plane/plane_computeConvex3PlaneIntersection.js";
5
+ import { ray_computeNearestPointToPoint } from "../ray/ray_computeNearestPointToPoint.js";
6
6
 
7
7
  /**
8
8
  *
@@ -14,6 +14,12 @@ const scratch_v3_0 = new Vector3();
14
14
 
15
15
  const scratch_v3_1 = new Vector3();
16
16
 
17
+ /**
18
+ *
19
+ * @type {number[]}
20
+ */
21
+ const scratch_v3_array = [];
22
+
17
23
  /**
18
24
  *
19
25
  * @param {Vector3} result
@@ -94,7 +100,9 @@ export function frustum3_computeNearestPointToPoint(result, planes, target_x, ta
94
100
  const plane_1 = planes[plane_1_index];
95
101
  const plane_2 = planes[plane_2_index];
96
102
 
97
- plane_three_computeConvex3PlaneIntersection(result, plane_0, plane_1, plane_2);
103
+ plane_three_computeConvex3PlaneIntersection(scratch_v3_array, 0, plane_0, plane_1, plane_2);
104
+
105
+ result.readFromArray(scratch_v3_array, 0)
98
106
  }
99
107
 
100
108
  return false;
@@ -0,0 +1,41 @@
1
+ import { clamp } from "../../../math/clamp.js";
2
+ import { v3_distance_sqr } from "../../v3_distance_sqr.js";
3
+
4
+ /**
5
+ * Computes shortest distance between a line segment(defined by 2 points) and a point
6
+ * @param {number} x0
7
+ * @param {number} y0
8
+ * @param {number} z0
9
+ * @param {number} x1
10
+ * @param {number} y1
11
+ * @param {number} z1
12
+ * @param {number} px
13
+ * @param {number} py
14
+ * @param {number} pz
15
+ */
16
+ export function line3_computeSegmentPointDistance_sqr(x0, y0, z0, x1, y1, z1, px, py, pz) {
17
+ // get line delta
18
+ const line_delta_x = x1 - x0;
19
+ const line_delta_y = y1 - y0;
20
+ const line_delta_z = z1 - z0;
21
+
22
+ // find closest point
23
+ const sp0_x = px - x0;
24
+ const sp0_y = py - y0;
25
+ const sp0_z = pz - z0;
26
+
27
+ //
28
+ const d2 = line_delta_x * line_delta_x + line_delta_y * line_delta_y + line_delta_z * line_delta_z;
29
+
30
+ const d3 = line_delta_x * sp0_x + line_delta_y * sp0_y + line_delta_z * sp0_z;
31
+
32
+ const t = clamp(d3 / d2, 0, 1);
33
+
34
+ // compute point on the line
35
+ const lp_x = line_delta_x * t + x0;
36
+ const lp_y = line_delta_y * t + y0;
37
+ const lp_z = line_delta_z * t + z0;
38
+
39
+ // compute distance from the point in question to the point on the line
40
+ return v3_distance_sqr(px, py, pz, lp_x, lp_y, lp_z);
41
+ }
@@ -1,10 +1,11 @@
1
1
  /**
2
2
  * method to separate bits from a given integer 3 positions apart
3
+ * we only look at the first 10 bits
3
4
  * @param {number} a
4
5
  * @returns {number}
5
6
  */
6
7
  function splitBy3(a) {
7
- let x = a & 0x000003ff; // we only look at the first 10 bits
8
+ let x = a;
8
9
  x = (x | x << 16) & 0x30000ff;
9
10
  x = (x | x << 8) & 0x0300f00f;
10
11
  x = (x | x << 4) & 0x30c30c3;
@@ -0,0 +1,13 @@
1
+ const b = new ArrayBuffer(4);
2
+ const b_f32 = new Float32Array(b);
3
+ const b_i32 = new Int32Array(b);
4
+
5
+ /**
6
+ *
7
+ * @param {number} value
8
+ * @returns {number}
9
+ */
10
+ export function reinterpret_float32_as_int32(value) {
11
+ b_f32[0] = value;
12
+ return b_i32[0];
13
+ }
@@ -0,0 +1,33 @@
1
+ import { mortonEncode_magicbits } from "./mortonEncode_magicbits.js";
2
+
3
+ /**
4
+ * Assumes that coordinates will be mapped to -1..1 range after transform
5
+ * @param {number} x
6
+ * @param {number} y
7
+ * @param {number} z
8
+ * @param {number[]} matrix matrix to transform supplied coordinates to Normalized Device Coordinates
9
+ * @returns {number}
10
+ */
11
+ export function v3_morton_encode_transformed(x, y, z, matrix) {
12
+
13
+ // apply matrix transform
14
+ const _x = matrix[0] * x + matrix[4] * y + matrix[8] * z + matrix[12];
15
+ const _y = matrix[1] * x + matrix[5] * y + matrix[9] * z + matrix[13];
16
+ const _z = matrix[2] * x + matrix[6] * y + matrix[10] * z + matrix[14];
17
+ const _w = matrix[3] * x + matrix[7] * y + matrix[11] * z + matrix[15];
18
+
19
+ const d = 1 / _w;
20
+
21
+ // apply perspective divide, values are now in Normalized Coordinate system (-1,1)
22
+ const px = _x * d;
23
+ const py = _y * d;
24
+ const pz = _z * d;
25
+
26
+ // scale each value up to 10 bits (for 10 bits, the multiplier = 1024. As we have -1,1 range, we do (v+1)/2. 1024/2 = 512)
27
+
28
+ const cx = ((px + 1) * 512) | 0;
29
+ const cy = ((py + 1) * 512) | 0;
30
+ const cz = ((pz + 1) * 512) | 0;
31
+
32
+ return mortonEncode_magicbits(cx, cy, cz);
33
+ }
@@ -1,5 +1,5 @@
1
1
  import { decode_hemioct_to_unit, encode_unit_to_hemioct } from "./encode_unit3_hemioct.js";
2
- import { v3_length } from "../../../Vector3.d.ts";
2
+ import { v3_length } from "../../../v3_length.js";
3
3
 
4
4
  test('encode-decode', () => {
5
5
  const v0 = [];