@nova-lab/core 1.0.0-dev.19 → 1.1.0-dev.229
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.
- package/README.md +1035 -10
- package/THIRD_PARTY_NOTICES.md +26 -0
- package/dist/2d/accessibility.d.ts +2 -0
- package/dist/2d/accessibility.js +171 -0
- package/dist/2d/commands.d.ts +2 -0
- package/dist/2d/commands.js +80 -0
- package/dist/2d/effects.d.ts +10 -0
- package/dist/2d/effects.js +566 -0
- package/dist/2d/ktx2.d.ts +5 -0
- package/dist/2d/ktx2.js +542 -0
- package/dist/2d/lighting.d.ts +3 -0
- package/dist/2d/lighting.js +495 -0
- package/dist/2d/lottie.d.ts +3 -0
- package/dist/2d/lottie.js +254 -0
- package/dist/2d/meshes.d.ts +4 -0
- package/dist/2d/meshes.js +451 -0
- package/dist/2d/primitives.d.ts +3 -0
- package/dist/2d/primitives.js +85 -0
- package/dist/2d/render-textures.d.ts +3 -0
- package/dist/2d/render-textures.js +539 -0
- package/dist/2d/svg/documents.d.ts +5 -0
- package/dist/2d/svg/documents.js +7 -0
- package/dist/2d/svg/renderer.d.ts +3 -0
- package/dist/2d/svg/renderer.js +222 -0
- package/dist/2d/svg.d.ts +3 -0
- package/dist/2d/svg.js +4 -0
- package/dist/2d/tools.d.ts +2 -0
- package/dist/2d/tools.js +100 -0
- package/dist/2d/video.d.ts +5 -0
- package/dist/2d/video.js +90 -0
- package/dist/2d.d.ts +2 -0
- package/dist/2d.js +220 -0
- package/dist/3d/animation.d.ts +8 -0
- package/dist/3d/animation.js +1396 -0
- package/dist/3d/area-lights.d.ts +2 -0
- package/dist/3d/area-lights.js +19 -0
- package/dist/3d/audio.d.ts +4 -0
- package/dist/3d/audio.js +500 -0
- package/dist/3d/character.d.ts +2 -0
- package/dist/3d/character.js +136 -0
- package/dist/3d/collision.d.ts +3 -0
- package/dist/3d/collision.js +387 -0
- package/dist/3d/commands.d.ts +2 -0
- package/dist/3d/commands.js +108 -0
- package/dist/3d/controls.d.ts +8 -0
- package/dist/3d/controls.js +1041 -0
- package/dist/3d/documents.d.ts +5 -0
- package/dist/3d/documents.js +227 -0
- package/dist/3d/effects.d.ts +5 -0
- package/dist/3d/effects.js +1986 -0
- package/dist/3d/export.d.ts +4 -0
- package/dist/3d/export.js +347 -0
- package/dist/3d/fbx.d.ts +2 -0
- package/dist/3d/fbx.js +784 -0
- package/dist/3d/gltf.d.ts +2 -0
- package/dist/3d/gltf.js +5 -0
- package/dist/3d/helpers.d.ts +5 -0
- package/dist/3d/helpers.js +191 -0
- package/dist/3d/ik.d.ts +9 -0
- package/dist/3d/ik.js +777 -0
- package/dist/3d/loaders.d.ts +17 -0
- package/dist/3d/loaders.js +1406 -0
- package/dist/3d/nodes.d.ts +8 -0
- package/dist/3d/nodes.js +49 -0
- package/dist/3d/particles.d.ts +5 -0
- package/dist/3d/particles.js +1574 -0
- package/dist/3d/physics/backend.d.ts +7 -0
- package/dist/3d/physics/backend.js +1 -0
- package/dist/3d/physics/rapier.d.ts +3 -0
- package/dist/3d/physics/rapier.js +765 -0
- package/dist/3d/physics.d.ts +5 -0
- package/dist/3d/physics.js +3346 -0
- package/dist/3d/splats.d.ts +7 -0
- package/dist/3d/splats.js +862 -0
- package/dist/3d/text.d.ts +5 -0
- package/dist/3d/text.js +1043 -0
- package/dist/3d/tiles.d.ts +24 -0
- package/dist/3d/tiles.js +1705 -0
- package/dist/3d/tools.d.ts +12 -0
- package/dist/3d/tools.js +338 -0
- package/dist/3d/usdz.d.ts +2 -0
- package/dist/3d/usdz.js +634 -0
- package/dist/3d/xr.d.ts +2 -0
- package/dist/3d/xr.js +202 -0
- package/dist/3d-B4jWF8Qb.js +5591 -0
- package/dist/3d.d.ts +40 -0
- package/dist/3d.js +44 -0
- package/dist/Capsule-BFVpZfvc.js +44 -0
- package/dist/Clip-CAN7t03k.js +204 -0
- package/dist/Color-vuv9UnoY.js +34 -0
- package/dist/DeformedMesh-CPi0P_vc.js +280 -0
- package/dist/Document-DCVEZSvM.js +415 -0
- package/dist/Errors-B2ekO9bZ.js +30 -0
- package/dist/Features-BsjmePtc.js +557 -0
- package/dist/GLTFResourceIO-CYJyCUTt.js +124 -0
- package/dist/GPUParticleState-CQlNpoDa.js +545 -0
- package/dist/Geometry-DytO490z.js +227 -0
- package/dist/Inflate-DWw0V-Up.js +42 -0
- package/dist/InstancedMesh-DPrgrw5z.js +527 -0
- package/dist/Limits-Bw5XQdFr.js +20 -0
- package/dist/LineHelper-Ad0z9uDi.js +131 -0
- package/dist/LoaderIO-BwrM84OM.js +114 -0
- package/dist/Material-BpfLPmK9.js +777 -0
- package/dist/Mesh-BaRxAAJq.js +209 -0
- package/dist/Node-QfgAE2_v.js +877 -0
- package/dist/NovaAssetRegistry-p2QlCwvT.js +1168 -0
- package/dist/NovaNode-CBZ-Ol-W.js +2016 -0
- package/dist/NovaRenderCommandWriter-CWQRa42y.js +1949 -0
- package/dist/NovaTextSelectionService-CipuujCT.js +18526 -0
- package/dist/NovaWebGLProgram-BO250QNF.js +97 -0
- package/dist/Options-CajE7LLJ.js +15 -0
- package/dist/PolygonMesh-D4PnnfIo.js +657 -0
- package/dist/Ready-BzyhRtjD.js +21 -0
- package/dist/Scene-CDfNgf9I.js +911 -0
- package/dist/Shader-b6_HDndT.js +48 -0
- package/dist/SplatShader-wJ6GJ3vo.js +130 -0
- package/dist/Texture-dTKMlTpK.js +267 -0
- package/dist/TextureLoader-CfDzdy2m.js +411 -0
- package/dist/Textures-CGL4Kf-8.js +651 -0
- package/dist/ToneMapping-D9IWvN0u.js +46 -0
- package/dist/WebGPURenderer-DjD0IxVC.js +4921 -0
- package/dist/ZipReader-C-MSEsSr.js +84 -0
- package/dist/core.js +218 -24024
- package/dist/domain/types/base.types.d.ts +18 -9
- package/dist/domain/types/component.types.d.ts +5 -5
- package/dist/domain/types/cursor.types.d.ts +1 -1
- package/dist/domain/types/diagnostics.types.d.ts +2 -0
- package/dist/domain/types/export.types.d.ts +2 -2
- package/dist/domain/types/hit-test.types.d.ts +1 -1
- package/dist/domain/types/motion.types.d.ts +2 -2
- package/dist/domain/types/renderer.types.d.ts +88 -4
- package/dist/domain/types/rendering/index.d.ts +29 -4
- package/dist/domain/types/sound.types.d.ts +1 -1
- package/dist/domain/types/theme.types.d.ts +1 -1
- package/dist/domain/utils/bounds.d.ts +1 -1
- package/dist/domain/utils/nova-text.d.ts +9 -0
- package/dist/domain/utils/schemaBounds.d.ts +2 -2
- package/dist/export-svg-document-ChaNXMaG.js +668 -0
- package/dist/features/3d/Errors.d.ts +57 -0
- package/dist/features/3d/Nova3DApp.d.ts +429 -0
- package/dist/features/3d/animation/Animator.d.ts +260 -0
- package/dist/features/3d/animation/Clip.d.ts +74 -0
- package/dist/features/3d/animation/Graph.d.ts +158 -0
- package/dist/features/3d/animation/Mask.d.ts +40 -0
- package/dist/features/3d/audio/Audio.d.ts +114 -0
- package/dist/features/3d/audio/Sound.d.ts +133 -0
- package/dist/features/3d/character/CharacterController.d.ts +61 -0
- package/dist/features/3d/collision/Capsule.d.ts +25 -0
- package/dist/features/3d/collision/Octree.d.ts +94 -0
- package/dist/features/3d/controls/CameraMotionControls.d.ts +154 -0
- package/dist/features/3d/controls/CameraOrientation.d.ts +47 -0
- package/dist/features/3d/controls/OrbitControls.d.ts +73 -0
- package/dist/features/3d/controls/PointerGesture.d.ts +25 -0
- package/dist/features/3d/controls/PointerLock.d.ts +36 -0
- package/dist/features/3d/controls/Snapping.d.ts +32 -0
- package/dist/features/3d/controls/TransformGizmo.d.ts +79 -0
- package/dist/features/3d/deformation/DeformationGPU.d.ts +52 -0
- package/dist/features/3d/deformation/DeformationShader.d.ts +2 -0
- package/dist/features/3d/deformation/DeformedMesh.d.ts +36 -0
- package/dist/features/3d/deformation/GeometryDeformation.d.ts +25 -0
- package/dist/features/3d/documents/Document.d.ts +59 -0
- package/dist/features/3d/documents/DocumentCommands.d.ts +45 -0
- package/dist/features/3d/documents/DocumentSchema.d.ts +18 -0
- package/dist/features/3d/documents/DocumentTransform.d.ts +4 -0
- package/dist/features/3d/documents/DocumentTypes.d.ts +182 -0
- package/dist/features/3d/documents/DocumentValidation.d.ts +18 -0
- package/dist/features/3d/documents/Projection.d.ts +65 -0
- package/dist/features/3d/effects/CubeLUT.d.ts +24 -0
- package/dist/features/3d/effects/Effects.d.ts +32 -0
- package/dist/features/3d/effects/EffectsGPU.d.ts +80 -0
- package/dist/features/3d/effects/EffectsPlan.d.ts +268 -0
- package/dist/features/3d/effects/EffectsShaders.d.ts +35 -0
- package/dist/features/3d/export/GLTFExporter.d.ts +49 -0
- package/dist/features/3d/export/ThreeMFExporter.d.ts +19 -0
- package/dist/features/3d/export/ZipWriter.d.ts +9 -0
- package/dist/features/3d/fbx/FBXLoader.d.ts +26 -0
- package/dist/features/3d/fbx/FBXParser.d.ts +35 -0
- package/dist/features/3d/fbx/FBXScene.d.ts +20 -0
- package/dist/features/3d/gltf/GLTFLoader.d.ts +16 -0
- package/dist/features/3d/gltf/GLTFTypes.d.ts +64 -0
- package/dist/features/3d/gltf/services/GLTFBinary.d.ts +21 -0
- package/dist/features/3d/gltf/services/GLTFGeometry.d.ts +14 -0
- package/dist/features/3d/gltf/services/GLTFResourceIO.d.ts +64 -0
- package/dist/features/3d/helpers/LineHelper.d.ts +51 -0
- package/dist/features/3d/helpers/StaticHelpers.d.ts +47 -0
- package/dist/features/3d/helpers/TrackedHelpers.d.ts +84 -0
- package/dist/features/3d/ik/ChainIK.d.ts +44 -0
- package/dist/features/3d/ik/IKChain.d.ts +92 -0
- package/dist/features/3d/ik/IKMath.d.ts +49 -0
- package/dist/features/3d/ik/IKSolver.d.ts +97 -0
- package/dist/features/3d/ik/LookAtIK.d.ts +58 -0
- package/dist/features/3d/ik/TwoBoneIK.d.ts +57 -0
- package/dist/features/3d/import/ImportAnimation.d.ts +20 -0
- package/dist/features/3d/import/ImportMath.d.ts +42 -0
- package/dist/features/3d/import/ImportedModel.d.ts +135 -0
- package/dist/features/3d/import/Inflate.d.ts +5 -0
- package/dist/features/3d/import/ModelAsset.d.ts +149 -0
- package/dist/features/3d/import/PolygonMesh.d.ts +54 -0
- package/dist/features/3d/lights/AreaLightTables.d.ts +8 -0
- package/dist/features/3d/lights/AreaLights.d.ts +11 -0
- package/dist/features/3d/loaders/EXRCompression.d.ts +13 -0
- package/dist/features/3d/loaders/EXRLoader.d.ts +39 -0
- package/dist/features/3d/loaders/HDRLoader.d.ts +26 -0
- package/dist/features/3d/loaders/Limits.d.ts +70 -0
- package/dist/features/3d/loaders/LoaderBuffers.d.ts +42 -0
- package/dist/features/3d/loaders/LoaderIO.d.ts +81 -0
- package/dist/features/3d/loaders/LoaderModel.d.ts +80 -0
- package/dist/features/3d/loaders/LoaderText.d.ts +27 -0
- package/dist/features/3d/loaders/MTLLoader.d.ts +105 -0
- package/dist/features/3d/loaders/OBJLoader.d.ts +70 -0
- package/dist/features/3d/loaders/PLYLoader.d.ts +47 -0
- package/dist/features/3d/loaders/STLLoader.d.ts +27 -0
- package/dist/features/3d/model/Camera.d.ts +33 -0
- package/dist/features/3d/model/Environment.d.ts +31 -0
- package/dist/features/3d/model/Geometry.d.ts +59 -0
- package/dist/features/3d/model/InstancedMesh.d.ts +134 -0
- package/dist/features/3d/model/LOD.d.ts +31 -0
- package/dist/features/3d/model/Light.d.ts +200 -0
- package/dist/features/3d/model/Material.d.ts +308 -0
- package/dist/features/3d/model/MaterialExtensions.d.ts +200 -0
- package/dist/features/3d/model/Mesh.d.ts +92 -0
- package/dist/features/3d/model/Node.d.ts +87 -0
- package/dist/features/3d/model/ReflectionProbe.d.ts +45 -0
- package/dist/features/3d/model/RenderTarget.d.ts +41 -0
- package/dist/features/3d/model/Scene.d.ts +173 -0
- package/dist/features/3d/model/Texture.d.ts +143 -0
- package/dist/features/3d/nodes/Nodes.d.ts +8 -0
- package/dist/features/3d/nodes/ShaderNode.d.ts +240 -0
- package/dist/features/3d/particles/GPUParticleSchedule.d.ts +67 -0
- package/dist/features/3d/particles/GPUParticleShaders.d.ts +19 -0
- package/dist/features/3d/particles/GPUParticleState.d.ts +106 -0
- package/dist/features/3d/particles/GPUParticleSystem.d.ts +192 -0
- package/dist/features/3d/particles/ParticleCurves.d.ts +34 -0
- package/dist/features/3d/particles/ParticleOptions.d.ts +78 -0
- package/dist/features/3d/particles/ParticleSystem.d.ts +368 -0
- package/dist/features/3d/physics/PhysicsBackend.d.ts +352 -0
- package/dist/features/3d/physics/PhysicsDebug.d.ts +24 -0
- package/dist/features/3d/physics/PhysicsWorld.d.ts +352 -0
- package/dist/features/3d/physics/basic/BasicCollision.d.ts +75 -0
- package/dist/features/3d/physics/basic/BasicPhysics.d.ts +24 -0
- package/dist/features/3d/physics/basic/BasicShapes.d.ts +103 -0
- package/dist/features/3d/physics/rapier/ContactBuffer.d.ts +32 -0
- package/dist/features/3d/physics/rapier/RapierBackend.d.ts +17 -0
- package/dist/features/3d/physics/rapier/RapierShapes.d.ts +4 -0
- package/dist/features/3d/physics/rapier/RapierWorld.d.ts +198 -0
- package/dist/features/3d/physics/rapier/Validation.d.ts +8 -0
- package/dist/features/3d/services/Background.d.ts +22 -0
- package/dist/features/3d/services/BasicShader.d.ts +55 -0
- package/dist/features/3d/services/ClusteredLights.d.ts +69 -0
- package/dist/features/3d/services/DrawOrder.d.ts +37 -0
- package/dist/features/3d/services/EffectsProcessor.d.ts +38 -0
- package/dist/features/3d/services/EnvironmentBRDF.d.ts +35 -0
- package/dist/features/3d/services/EnvironmentMaps.d.ts +55 -0
- package/dist/features/3d/services/FogShader.d.ts +6 -0
- package/dist/features/3d/services/Frustum.d.ts +7 -0
- package/dist/features/3d/services/GLState.d.ts +86 -0
- package/dist/features/3d/services/GPUPicker.d.ts +31 -0
- package/dist/features/3d/services/InstanceShader.d.ts +3 -0
- package/dist/features/3d/services/LineProgram.d.ts +32 -0
- package/dist/features/3d/services/PBRProgram.d.ts +115 -0
- package/dist/features/3d/services/Renderer.d.ts +50 -0
- package/dist/features/3d/services/Shader.d.ts +22 -0
- package/dist/features/3d/services/ShaderProgram.d.ts +38 -0
- package/dist/features/3d/services/ShadowMaps.d.ts +97 -0
- package/dist/features/3d/services/SpatialIndex.d.ts +16 -0
- package/dist/features/3d/services/TextureLoader.d.ts +40 -0
- package/dist/features/3d/services/TextureMipmaps.d.ts +42 -0
- package/dist/features/3d/services/ToneMapping.d.ts +12 -0
- package/dist/features/3d/services/WebGLRenderer.d.ts +261 -0
- package/dist/features/3d/splats/SplatData.d.ts +136 -0
- package/dist/features/3d/splats/SplatLoaders.d.ts +64 -0
- package/dist/features/3d/splats/SplatShader.d.ts +14 -0
- package/dist/features/3d/splats/SplatSort.d.ts +69 -0
- package/dist/features/3d/splats/Splats.d.ts +116 -0
- package/dist/features/3d/text/FontAtlas.d.ts +246 -0
- package/dist/features/3d/text/SDF.d.ts +28 -0
- package/dist/features/3d/text/Text.d.ts +179 -0
- package/dist/features/3d/text/TextLayout.d.ts +73 -0
- package/dist/features/3d/text/TextShader.d.ts +12 -0
- package/dist/features/3d/tiles/BoundingVolume.d.ts +43 -0
- package/dist/features/3d/tiles/Geodesy.d.ts +106 -0
- package/dist/features/3d/tiles/GlobeControls.d.ts +147 -0
- package/dist/features/3d/tiles/TileContent.d.ts +35 -0
- package/dist/features/3d/tiles/TileFormats.d.ts +77 -0
- package/dist/features/3d/tiles/Tiles3D.d.ts +236 -0
- package/dist/features/3d/tiles/Tileset.d.ts +81 -0
- package/dist/features/3d/tools/BatchedMesh.d.ts +74 -0
- package/dist/features/3d/tools/CanvasSurface.d.ts +81 -0
- package/dist/features/3d/tools/Color.d.ts +11 -0
- package/dist/features/3d/tools/MergeGeometries.d.ts +22 -0
- package/dist/features/3d/tools/Options.d.ts +15 -0
- package/dist/features/3d/tools/Polyhedra.d.ts +30 -0
- package/dist/features/3d/tools/PrimitiveBuffers.d.ts +42 -0
- package/dist/features/3d/tools/Primitives.d.ts +164 -0
- package/dist/features/3d/tools/Ready.d.ts +12 -0
- package/dist/features/3d/tools/SpatialMath.d.ts +57 -0
- package/dist/features/3d/tools/SphericalHarmonics.d.ts +9 -0
- package/dist/features/3d/tools/math/mat3.d.ts +7 -0
- package/dist/features/3d/tools/math/mat4.d.ts +19 -0
- package/dist/features/3d/tools/math/quat.d.ts +6 -0
- package/dist/features/3d/tools/math/vec3.d.ts +16 -0
- package/dist/features/3d/tools/math/vec4.d.ts +5 -0
- package/dist/features/3d/types.d.ts +359 -0
- package/dist/features/3d/usdz/USDAParser.d.ts +50 -0
- package/dist/features/3d/usdz/USDScene.d.ts +20 -0
- package/dist/features/3d/usdz/USDZLoader.d.ts +27 -0
- package/dist/features/3d/usdz/ZipReader.d.ts +16 -0
- package/dist/features/3d/webgpu/Backend.d.ts +40 -0
- package/dist/features/3d/webgpu/BasicShader.d.ts +10 -0
- package/dist/features/3d/webgpu/Constants.d.ts +32 -0
- package/dist/features/3d/webgpu/Deformation.d.ts +71 -0
- package/dist/features/3d/webgpu/Environment.d.ts +66 -0
- package/dist/features/3d/webgpu/Features.d.ts +68 -0
- package/dist/features/3d/webgpu/Layouts.d.ts +27 -0
- package/dist/features/3d/webgpu/Lines.d.ts +40 -0
- package/dist/features/3d/webgpu/LitExtras.d.ts +46 -0
- package/dist/features/3d/webgpu/LitFeatures.d.ts +41 -0
- package/dist/features/3d/webgpu/LitScene.d.ts +60 -0
- package/dist/features/3d/webgpu/LitShader.d.ts +68 -0
- package/dist/features/3d/webgpu/Particles.d.ts +114 -0
- package/dist/features/3d/webgpu/Picking.d.ts +59 -0
- package/dist/features/3d/webgpu/PipelineKey.d.ts +33 -0
- package/dist/features/3d/webgpu/Points.d.ts +41 -0
- package/dist/features/3d/webgpu/Probes.d.ts +45 -0
- package/dist/features/3d/webgpu/ShaderChunks.d.ts +18 -0
- package/dist/features/3d/webgpu/ShaderMaterial.d.ts +57 -0
- package/dist/features/3d/webgpu/ShaderMaterialSource.d.ts +5 -0
- package/dist/features/3d/webgpu/Shadows.d.ts +49 -0
- package/dist/features/3d/webgpu/Splats.d.ts +47 -0
- package/dist/features/3d/webgpu/Textures.d.ts +52 -0
- package/dist/features/3d/webgpu/Transmission.d.ts +30 -0
- package/dist/features/3d/webgpu/UniformLayout.d.ts +30 -0
- package/dist/features/3d/webgpu/UtilityShaders.d.ts +38 -0
- package/dist/features/3d/webgpu/WebGPURenderer.d.ts +327 -0
- package/dist/features/3d/webgpu/effects/EffectsShaders.d.ts +74 -0
- package/dist/features/3d/webgpu/effects/WebGPUEffects.d.ts +140 -0
- package/dist/features/3d/xr/XR.d.ts +100 -0
- package/dist/gltf-By-n0qEg.js +960 -0
- package/dist/index.d.ts +86 -81
- package/dist/model/document-actions/document-commands.d.ts +18 -0
- package/dist/model/documents/svg/create-svg-document-renderer.d.ts +32 -0
- package/dist/model/documents/svg/export-svg-document.d.ts +5 -0
- package/dist/model/documents/svg/import-svg-document.d.ts +6 -0
- package/dist/model/documents/svg/svg-document.types.d.ts +111 -0
- package/dist/model/documents/svg/svg-values.d.ts +16 -0
- package/dist/model/documents/svg/svg-xml.d.ts +18 -0
- package/dist/model/input/NovaInputProxy_Adapter.d.ts +2 -1
- package/dist/model/input/NovaInputValidationController.d.ts +1 -1
- package/dist/model/input/NovaTextInputController.d.ts +1 -1
- package/dist/model/input/NovaTextLayoutEngine.d.ts +2 -6
- package/dist/model/input/index.d.ts +7 -7
- package/dist/model/input/nova-input.types.d.ts +1 -1
- package/dist/model/lighting/LightingRenderer2D.d.ts +58 -0
- package/dist/model/lighting/NovaLighting2D.d.ts +56 -0
- package/dist/model/lighting/lighting-shaders.d.ts +3 -0
- package/dist/model/lighting/lighting-state.d.ts +27 -0
- package/dist/model/lighting/lighting.types.d.ts +107 -0
- package/dist/model/lottie/LottieNode.d.ts +4 -0
- package/dist/model/lottie/lottie.types.d.ts +83 -0
- package/dist/model/lottie/prepare-lottie.d.ts +3 -0
- package/dist/model/lottie/sample-position.d.ts +9 -0
- package/dist/model/motion/NovaMotionEngine.d.ts +3 -3
- package/dist/model/motion/nova-motion-easing.d.ts +1 -1
- package/dist/model/motion/nova-motion-interpolation.d.ts +1 -1
- package/dist/model/motion/nova-motion-presets.d.ts +2 -2
- package/dist/model/motion/nova-motion-timeline.d.ts +1 -1
- package/dist/model/platform/NovaCanvas.d.ts +7 -6
- package/dist/model/primitives/NovaPrimitiveUnsupportedError.d.ts +13 -0
- package/dist/model/primitives/definePrimitive.d.ts +5 -0
- package/dist/model/primitives/primitive.types.d.ts +28 -0
- package/dist/model/render/backends/canvas2d/NovaCanvas2DTargetManager.d.ts +3 -3
- package/dist/model/render/backends/canvas2d/NovaRenderer2D.d.ts +61 -15
- package/dist/model/render/backends/canvas2d/nova-canvas-blend.d.ts +5 -0
- package/dist/model/render/backends/nova-render-backend-factory.d.ts +6 -6
- package/dist/model/render/backends/nova-render-backend.d.ts +8 -2
- package/dist/model/render/backends/webgl/NovaRendererWebGL.d.ts +32 -11
- package/dist/model/render/backends/webgl/NovaStreamCacheIdleLedger.d.ts +12 -1
- package/dist/model/render/backends/webgl/NovaWebGLBatcher.d.ts +1 -1
- package/dist/model/render/backends/webgl/NovaWebGLCircleImagePass.d.ts +23 -0
- package/dist/model/render/backends/webgl/NovaWebGLCompositionPass.d.ts +9 -0
- package/dist/model/render/backends/webgl/NovaWebGLDevice.d.ts +3 -1
- package/dist/model/render/backends/webgl/NovaWebGLDiagnostics.d.ts +1 -1
- package/dist/model/render/backends/webgl/NovaWebGLFrameRenderer.d.ts +162 -53
- package/dist/model/render/backends/webgl/NovaWebGLPathClipPass.d.ts +13 -0
- package/dist/model/render/backends/webgl/NovaWebGLPathUnion.d.ts +23 -0
- package/dist/model/render/compiler/NovaRenderBuilder.d.ts +24 -10
- package/dist/model/render/compiler/NovaRenderCommandWriter.d.ts +10 -5
- package/dist/model/render/compiler/NovaRenderCompiler.d.ts +7 -6
- package/dist/model/render/compiler/NovaRenderFrameBuilder.d.ts +4 -3
- package/dist/model/render/effects/blur.d.ts +8 -0
- package/dist/model/render/effects/color-matrix.d.ts +8 -0
- package/dist/model/render/effects/drop-shadow.d.ts +18 -0
- package/dist/model/render/effects/nova-effect-registry.d.ts +66 -0
- package/dist/model/render/effects/nova-gaussian-kernel.d.ts +7 -0
- package/dist/model/render/effects/nova-gaussian-textures.d.ts +11 -0
- package/dist/model/render/effects/shader-effect.d.ts +64 -0
- package/dist/model/render/geometry/nova-alpha-mask.d.ts +5 -0
- package/dist/model/render/geometry/nova-composition.d.ts +9 -0
- package/dist/model/render/geometry/nova-node-clip.d.ts +17 -0
- package/dist/model/render/geometry/nova-path-geometry.d.ts +24 -0
- package/dist/model/render/geometry/nova-path-tessellation.d.ts +7 -0
- package/dist/model/render/geometry/nova-polygon-triangulation.d.ts +1 -1
- package/dist/model/render/graph/NovaRectBatchBuffer.d.ts +58 -0
- package/dist/model/render/graph/NovaRenderGraph.d.ts +40 -6
- package/dist/model/render/graph/NovaRenderHitIndex.d.ts +1 -1
- package/dist/model/render/graph/nova-auto-rect.d.ts +1 -1
- package/dist/model/render/graph/nova-linear-rect-repack.d.ts +4 -4
- package/dist/model/render/graph/nova-linear-rect-transition.d.ts +2 -2
- package/dist/model/render/graph/nova-render-culling.d.ts +2 -2
- package/dist/model/render/graph/nova-render-dirty-items.d.ts +1 -1
- package/dist/model/render/graph/nova-render-group.d.ts +1 -1
- package/dist/model/render/graph/nova-render-item.d.ts +2 -2
- package/dist/model/render/graph/nova-render-layer.d.ts +1 -1
- package/dist/model/render/graph/nova-render-payload-snapshot.d.ts +3 -1
- package/dist/model/render/graph/nova-render-program.d.ts +5 -3
- package/dist/model/render/graph/nova-render-sequence.d.ts +1 -1
- package/dist/model/render/graph/nova-render-stream.d.ts +2 -2
- package/dist/model/render/ktx2/BasisSession.d.ts +45 -0
- package/dist/model/render/ktx2/KTX2Container.d.ts +26 -0
- package/dist/model/render/ktx2/KTX2Loader.d.ts +55 -0
- package/dist/model/render/meshes/MeshNode.d.ts +13 -0
- package/dist/model/render/meshes/NovaMeshWebGLDevice.d.ts +27 -0
- package/dist/model/render/meshes/geometry.d.ts +7 -0
- package/dist/model/render/meshes/mesh.d.ts +3 -0
- package/dist/model/render/meshes/mesh.types.d.ts +116 -0
- package/dist/model/render/meshes/nova-mesh-registry.d.ts +55 -0
- package/dist/model/render/orchestration/NovaRenderOrchestrator.d.ts +25 -3
- package/dist/model/render/policy/nova-render-policy.d.ts +1 -1
- package/dist/model/render/resources/NovaGlyphAtlasManager.d.ts +2 -2
- package/dist/model/render/resources/NovaTextAtlasManager.d.ts +3 -3
- package/dist/model/render/resources/NovaTextLayoutEngine.d.ts +1 -1
- package/dist/model/render/resources/nova-bitmap-upload.d.ts +10 -0
- package/dist/model/render/schema/NovaRenderContext.d.ts +6 -4
- package/dist/model/render/schema/nova-style-compiler.d.ts +5 -2
- package/dist/model/render/targets/NovaNodeRenderTextureSource.d.ts +29 -0
- package/dist/model/render/targets/NovaRenderTargetManager.d.ts +1 -1
- package/dist/model/render/targets/NovaRenderTexture.d.ts +57 -0
- package/dist/model/render/targets/nova-render-target-refs.d.ts +5 -0
- package/dist/model/render/targets/nova-render-target-resource.d.ts +1 -1
- package/dist/model/render/targets/nova-render-texture-runtime.d.ts +71 -0
- package/dist/model/render/textures/nova-compressed-image.d.ts +20 -0
- package/dist/model/render/utils/nova-icon-rendering.d.ts +3 -1
- package/dist/model/render/utils/nova-image-geometry.d.ts +11 -0
- package/dist/model/render/utils/nova-markdown-layout.d.ts +19 -0
- package/dist/model/render/utils/nova-text-paint.d.ts +26 -0
- package/dist/model/render/utils/nova-wrapped-text-layout.d.ts +19 -0
- package/dist/model/runtime/app/Nova.d.ts +35 -35
- package/dist/model/runtime/app/NovaApp.d.ts +58 -30
- package/dist/model/runtime/app/NovaRaphRuntime.d.ts +2 -2
- package/dist/model/runtime/app/createNovaRaphRuntime.d.ts +3 -3
- package/dist/model/runtime/assets/NovaAssetRegistry.d.ts +89 -2
- package/dist/model/runtime/assets/NovaVideoTexture.d.ts +38 -0
- package/dist/model/runtime/assets/nova-render-texture-image-identity.d.ts +4 -0
- package/dist/model/runtime/commands/NovaCommandBus.d.ts +1 -1
- package/dist/model/runtime/components/NovaComponentNode.d.ts +6 -6
- package/dist/model/runtime/components/NovaComponentRegistry.d.ts +1 -1
- package/dist/model/runtime/components/NovaSchemaRegistry.d.ts +7 -6
- package/dist/model/runtime/components/nova-component-metadata.d.ts +1 -1
- package/dist/model/runtime/components/nova-component.decorator.d.ts +2 -2
- package/dist/model/runtime/components/nova-defined-component.d.ts +3 -3
- package/dist/model/runtime/context/nova-context.d.ts +1 -1
- package/dist/model/runtime/cursor/NovaCursorManager.d.ts +3 -3
- package/dist/model/runtime/diagnostics/NovaDiagnostics_Module.d.ts +3 -3
- package/dist/model/runtime/interaction/NovaEvents.d.ts +16 -6
- package/dist/model/runtime/interaction/NovaHitIndex.d.ts +1 -1
- package/dist/model/runtime/interaction/NovaSpatialIndex.d.ts +2 -2
- package/dist/model/runtime/scene/NovaScene.d.ts +3 -3
- package/dist/model/runtime/scene/nova-scene-components.d.ts +6 -6
- package/dist/model/runtime/state/nova-store-decorators.d.ts +1 -1
- package/dist/model/runtime/state/nova-store-runtime.d.ts +1 -1
- package/dist/model/runtime/state/nova-store-tracking.d.ts +7 -3
- package/dist/model/runtime/sync/NovaSyncScope.d.ts +11 -2
- package/dist/model/runtime/sync/nova-sync-context.d.ts +2 -2
- package/dist/model/runtime/sync/nova-sync-ports.d.ts +2 -2
- package/dist/model/runtime/sync/nova-sync.types.d.ts +15 -3
- package/dist/model/runtime/template/NovaTemplateRuntime.d.ts +6 -6
- package/dist/model/runtime/tree/NovaContainer.d.ts +4 -4
- package/dist/model/runtime/tree/NovaNode.d.ts +58 -18
- package/dist/model/runtime/tree/NovaRaphNode.d.ts +8 -2
- package/dist/model/runtime/tree/NovaSurface.d.ts +32 -10
- package/dist/model/runtime/tree/nova-node-capture-invalidation.d.ts +11 -0
- package/dist/model/semantic/NovaSemanticService.d.ts +1 -1
- package/dist/model/semantic/browser/createAccessibilityBridge.d.ts +29 -0
- package/dist/model/sound/NovaSoundEngine.d.ts +3 -2
- package/dist/model/text-selection/NovaTextSelectionService.d.ts +2 -2
- package/dist/model/text-selection/index.d.ts +2 -2
- package/dist/model/text-selection/nova-text-selection.types.d.ts +1 -1
- package/dist/model/theme/NovaGlobalThemeRegistry.d.ts +2 -2
- package/dist/model/theme/NovaThemeService.d.ts +5 -3
- package/dist/model/theme/createTokenTheme.d.ts +15 -0
- package/dist/model/tools/transform-tools.d.ts +43 -0
- package/dist/nodes--Ds4IS2h.js +621 -0
- package/dist/nova-color-parser-BCN_rFRN.js +250 -0
- package/dist/nova-compressed-image-CE2Ya9Xa.js +46 -0
- package/dist/nova-mesh-registry-B7Xz5mhU.js +24 -0
- package/dist/nova-render-texture-image-identity-DQ09XFKs.js +15 -0
- package/dist/nova-text-paint-CcntsRjI.js +48 -0
- package/dist/tokens.d.ts +2 -0
- package/dist/tokens.js +50 -0
- package/dist/vec4-BTNv1fUp.js +20 -0
- package/package.json +223 -4
|
@@ -0,0 +1,3346 @@
|
|
|
1
|
+
import { N as F } from "../Errors-B2ekO9bZ.js";
|
|
2
|
+
import { c as dt, o as ct } from "../Options-CajE7LLJ.js";
|
|
3
|
+
import { N as cs } from "../InstancedMesh-DPrgrw5z.js";
|
|
4
|
+
import { c as es, d as Et, G as ls, N as Vt, b as Rt, H as vt, w as hs } from "../Node-QfgAE2_v.js";
|
|
5
|
+
import { s as _s } from "../Scene-CDfNgf9I.js";
|
|
6
|
+
import { N as ds, b as us, h as ps } from "../LineHelper-Ad0z9uDi.js";
|
|
7
|
+
const ut = 0, pt = 1, Q = 2, U = 3, tt = 4, Ht = 4096, jt = 256, fs = 16, ys = 1 << 21;
|
|
8
|
+
function it(d, t) {
|
|
9
|
+
if (typeof d != "number" || !Number.isFinite(d) || d <= 0)
|
|
10
|
+
throw new F("invalid-option", `[Nova3D] Physics ${t} must be a positive finite number.`);
|
|
11
|
+
return d;
|
|
12
|
+
}
|
|
13
|
+
function ms(d, t) {
|
|
14
|
+
if (typeof d != "number" || !Number.isFinite(d) || d < 0)
|
|
15
|
+
throw new F("invalid-option", `[Nova3D] Physics ${t} must be a nonnegative finite number.`);
|
|
16
|
+
return d;
|
|
17
|
+
}
|
|
18
|
+
function Dt(d, t, s) {
|
|
19
|
+
if (!d || typeof d != "object" || d.length !== t)
|
|
20
|
+
throw new F("invalid-option", `[Nova3D] Physics ${s} must have ${t} numbers.`);
|
|
21
|
+
const e = [];
|
|
22
|
+
for (let n = 0; n < t; n++) {
|
|
23
|
+
const i = d[n];
|
|
24
|
+
if (typeof i != "number" || !Number.isFinite(i))
|
|
25
|
+
throw new F("invalid-option", `[Nova3D] Physics ${s} must be finite.`);
|
|
26
|
+
e.push(i);
|
|
27
|
+
}
|
|
28
|
+
return e;
|
|
29
|
+
}
|
|
30
|
+
function Lt(d, t) {
|
|
31
|
+
const s = d.length / 3, e = new Float64Array(d), n = new Float64Array([1 / 0, 1 / 0, 1 / 0]), i = new Float64Array([-1 / 0, -1 / 0, -1 / 0]);
|
|
32
|
+
let o = 0, r = 0, c = 0;
|
|
33
|
+
for (let w = 0; w < s; w++) {
|
|
34
|
+
for (let v = 0; v < 3; v++)
|
|
35
|
+
n[v] = Math.min(n[v], e[w * 3 + v]), i[v] = Math.max(i[v], e[w * 3 + v]);
|
|
36
|
+
o += e[w * 3], r += e[w * 3 + 1], c += e[w * 3 + 2];
|
|
37
|
+
}
|
|
38
|
+
o /= s, r /= s, c /= s;
|
|
39
|
+
const a = t.length, l = new Float64Array(a * 3), h = new Float64Array(a), _ = new Int32Array(a + 1), p = [];
|
|
40
|
+
for (let w = 0; w < a; w++) {
|
|
41
|
+
const v = [...t[w]];
|
|
42
|
+
let I = 0, M = 0, b = 0, A = 0, g = 0, x = 0;
|
|
43
|
+
for (let S = 0; S < v.length; S++) {
|
|
44
|
+
const D = v[S] * 3, C = v[(S + 1) % v.length] * 3;
|
|
45
|
+
I += (e[D + 1] - e[C + 1]) * (e[D + 2] + e[C + 2]), M += (e[D + 2] - e[C + 2]) * (e[D] + e[C]), b += (e[D] - e[C]) * (e[D + 1] + e[C + 1]), A += e[D], g += e[D + 1], x += e[D + 2];
|
|
46
|
+
}
|
|
47
|
+
A /= v.length, g /= v.length, x /= v.length;
|
|
48
|
+
const k = Math.hypot(I, M, b);
|
|
49
|
+
if (!(k > 0))
|
|
50
|
+
throw new F("invalid-option", "[Nova3D] Physics hull has a degenerate face.");
|
|
51
|
+
I /= k, M /= k, b /= k, I * (A - o) + M * (g - r) + b * (x - c) < 0 && (I = -I, M = -M, b = -b, v.reverse()), l[w * 3] = I, l[w * 3 + 1] = M, l[w * 3 + 2] = b, h[w] = I * A + M * g + b * x, _[w] = p.length, p.push(...v);
|
|
52
|
+
}
|
|
53
|
+
_[a] = p.length;
|
|
54
|
+
const m = /* @__PURE__ */ new Set(), u = [], f = [], y = [];
|
|
55
|
+
for (let w = 0; w < a; w++) {
|
|
56
|
+
const v = _[w], I = _[w + 1] - v;
|
|
57
|
+
for (let M = 0; M < I; M++) {
|
|
58
|
+
const b = p[v + M], A = p[v + (M + 1) % I], g = Math.min(b, A) * 65536 + Math.max(b, A);
|
|
59
|
+
if (b === A || m.has(g))
|
|
60
|
+
continue;
|
|
61
|
+
m.add(g);
|
|
62
|
+
let x = e[A * 3] - e[b * 3], k = e[A * 3 + 1] - e[b * 3 + 1], S = e[A * 3 + 2] - e[b * 3 + 2];
|
|
63
|
+
const D = Math.hypot(x, k, S);
|
|
64
|
+
if (D < 1e-12)
|
|
65
|
+
continue;
|
|
66
|
+
x /= D, k /= D, S /= D;
|
|
67
|
+
let C = -1;
|
|
68
|
+
for (let N = 0; N < f.length / 3; N++)
|
|
69
|
+
if (Math.abs(f[N * 3] * x + f[N * 3 + 1] * k + f[N * 3 + 2] * S) > 1 - 1e-9) {
|
|
70
|
+
C = N;
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
C < 0 && (C = f.length / 3, f.push(x, k, S)), u.push(b, A), y.push(C);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
vertexCount: s,
|
|
78
|
+
vertices: e,
|
|
79
|
+
faceCount: a,
|
|
80
|
+
normals: l,
|
|
81
|
+
offsets: h,
|
|
82
|
+
faceStart: _,
|
|
83
|
+
faceIndices: new Int32Array(p),
|
|
84
|
+
edgeCount: u.length / 2,
|
|
85
|
+
edges: new Int32Array(u),
|
|
86
|
+
edgeDirCount: f.length / 3,
|
|
87
|
+
edgeDirs: new Float64Array(f),
|
|
88
|
+
edgeDirOf: new Int32Array(y),
|
|
89
|
+
min: n,
|
|
90
|
+
max: i
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function gs(d, t, s) {
|
|
94
|
+
const e = [];
|
|
95
|
+
for (let n = 0; n < 8; n++)
|
|
96
|
+
e.push(n & 1 ? d : -d, n & 2 ? t : -t, n & 4 ? s : -s);
|
|
97
|
+
return Lt(e, [[0, 2, 6, 4], [1, 5, 7, 3], [0, 4, 5, 1], [2, 3, 7, 6], [0, 1, 3, 2], [4, 6, 7, 5]]);
|
|
98
|
+
}
|
|
99
|
+
function ws(d, t, s = fs) {
|
|
100
|
+
const e = [];
|
|
101
|
+
for (let i = 0; i < 2; i++)
|
|
102
|
+
for (let o = 0; o < s; o++) {
|
|
103
|
+
const r = o * Math.PI * 2 / s;
|
|
104
|
+
e.push(Math.cos(r) * d, i ? t : -t, Math.sin(r) * d);
|
|
105
|
+
}
|
|
106
|
+
const n = [Array.from({ length: s }, (i, o) => o), Array.from({ length: s }, (i, o) => s + o)];
|
|
107
|
+
for (let i = 0; i < s; i++) {
|
|
108
|
+
const o = (i + 1) % s;
|
|
109
|
+
n.push([i, o, s + o, s + i]);
|
|
110
|
+
}
|
|
111
|
+
return Lt(e, n);
|
|
112
|
+
}
|
|
113
|
+
function ns(d) {
|
|
114
|
+
if (!d || typeof d.length != "number" || d.length % 3 !== 0 || d.length < 12 || d.length > Ht * 3)
|
|
115
|
+
throw new F("invalid-option", `[Nova3D] Convex hull needs 4 to ${Ht} xyz points.`);
|
|
116
|
+
const t = d.length / 3, s = new Float64Array(d.length);
|
|
117
|
+
let e = 0;
|
|
118
|
+
for (let g = 0; g < d.length; g++) {
|
|
119
|
+
const x = d[g];
|
|
120
|
+
if (typeof x != "number" || !Number.isFinite(x))
|
|
121
|
+
throw new F("invalid-option", "[Nova3D] Convex hull points must be finite.");
|
|
122
|
+
s[g] = x, e = Math.max(e, Math.abs(x));
|
|
123
|
+
}
|
|
124
|
+
const n = Math.max(e, 1e-6) * 1e-9, i = (g, x) => s[g * 3 + x], o = (g, x) => [i(g, 0) - i(x, 0), i(g, 1) - i(x, 1), i(g, 2) - i(x, 2)], r = (g, x) => [g[1] * x[2] - g[2] * x[1], g[2] * x[0] - g[0] * x[2], g[0] * x[1] - g[1] * x[0]], c = (g, x) => g[0] * x[0] + g[1] * x[1] + g[2] * x[2];
|
|
125
|
+
let a = 0;
|
|
126
|
+
for (let g = 1; g < t; g++)
|
|
127
|
+
i(g, 0) < i(a, 0) && (a = g);
|
|
128
|
+
let l = -1, h = n;
|
|
129
|
+
for (let g = 0; g < t; g++) {
|
|
130
|
+
const x = o(g, a), k = c(x, x);
|
|
131
|
+
k > h && (h = k, l = g);
|
|
132
|
+
}
|
|
133
|
+
let _ = -1;
|
|
134
|
+
if (h = n, l >= 0) {
|
|
135
|
+
const g = o(l, a);
|
|
136
|
+
for (let x = 0; x < t; x++) {
|
|
137
|
+
const k = r(g, o(x, a)), S = c(k, k);
|
|
138
|
+
S > h && (h = S, _ = x);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
let p = -1;
|
|
142
|
+
if (_ >= 0) {
|
|
143
|
+
const g = r(o(l, a), o(_, a)), x = Math.hypot(g[0], g[1], g[2]);
|
|
144
|
+
h = n * 10;
|
|
145
|
+
for (let k = 0; k < t; k++) {
|
|
146
|
+
const S = Math.abs(c(g, o(k, a))) / x;
|
|
147
|
+
S > h && (h = S, p = k);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (p < 0)
|
|
151
|
+
throw new F("invalid-option", "[Nova3D] Convex hull points must span a volume.");
|
|
152
|
+
const m = [], u = [0, 1, 2].map((g) => (i(a, g) + i(l, g) + i(_, g) + i(p, g)) / 4), f = (g, x, k) => {
|
|
153
|
+
let S = r(o(x, g), o(k, g));
|
|
154
|
+
const D = Math.hypot(S[0], S[1], S[2]);
|
|
155
|
+
if (!(D > 0))
|
|
156
|
+
return;
|
|
157
|
+
S = S.map((N) => N / D);
|
|
158
|
+
const C = S[0] * i(g, 0) + S[1] * i(g, 1) + S[2] * i(g, 2);
|
|
159
|
+
m.push({ a: g, b: x, c: k, n: S, d: C, alive: !0 });
|
|
160
|
+
}, y = (g, x, k) => {
|
|
161
|
+
const S = r(o(x, g), o(k, g));
|
|
162
|
+
S[0] * (u[0] - i(g, 0)) + S[1] * (u[1] - i(g, 1)) + S[2] * (u[2] - i(g, 2)) > 0 ? f(g, k, x) : f(g, x, k);
|
|
163
|
+
};
|
|
164
|
+
y(a, l, _), y(a, l, p), y(a, _, p), y(l, _, p);
|
|
165
|
+
const w = /* @__PURE__ */ new Map();
|
|
166
|
+
for (let g = 0; g < t; g++) {
|
|
167
|
+
if (g === a || g === l || g === _ || g === p)
|
|
168
|
+
continue;
|
|
169
|
+
const x = [];
|
|
170
|
+
for (const k of m)
|
|
171
|
+
k.alive && k.n[0] * i(g, 0) + k.n[1] * i(g, 1) + k.n[2] * i(g, 2) - k.d > n * 10 && x.push(k);
|
|
172
|
+
if (x.length !== 0) {
|
|
173
|
+
w.clear();
|
|
174
|
+
for (const k of x)
|
|
175
|
+
k.alive = !1, w.set(k.a * t + k.b, 1), w.set(k.b * t + k.c, 1), w.set(k.c * t + k.a, 1);
|
|
176
|
+
for (const k of x)
|
|
177
|
+
for (const [S, D] of [[k.a, k.b], [k.b, k.c], [k.c, k.a]])
|
|
178
|
+
w.has(D * t + S) || f(S, D, g);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
const v = m.filter((g) => g.alive), I = Array.from({ length: v.length }).fill(!1), M = [];
|
|
182
|
+
for (let g = 0; g < v.length; g++) {
|
|
183
|
+
if (I[g])
|
|
184
|
+
continue;
|
|
185
|
+
const x = [v[g]];
|
|
186
|
+
I[g] = !0;
|
|
187
|
+
for (let B = g + 1; B < v.length; B++)
|
|
188
|
+
!I[B] && c(v[g].n, v[B].n) > 1 - 1e-7 && Math.abs(v[g].d - v[B].d) < n * 1e3 && (I[B] = !0, x.push(v[B]));
|
|
189
|
+
const k = [...new Set(x.flatMap((B) => [B.a, B.b, B.c]))], S = v[g].n, D = [0, 1, 2].map((B) => k.reduce((T, V) => T + i(V, B), 0) / k.length), C = Math.abs(S[0]) < 0.9 ? r(S, [1, 0, 0]) : r(S, [0, 1, 0]), N = Math.hypot(C[0], C[1], C[2]), z = C.map((B) => B / N), P = r(S, z), E = (B) => {
|
|
190
|
+
const T = [i(B, 0) - D[0], i(B, 1) - D[1], i(B, 2) - D[2]];
|
|
191
|
+
return Math.atan2(c(T, P), c(T, z));
|
|
192
|
+
};
|
|
193
|
+
M.push(k.sort((B, T) => E(B) - E(T)));
|
|
194
|
+
}
|
|
195
|
+
const b = /* @__PURE__ */ new Map(), A = [];
|
|
196
|
+
for (const g of M)
|
|
197
|
+
for (let x = 0; x < g.length; x++) {
|
|
198
|
+
let k = b.get(g[x]);
|
|
199
|
+
k === void 0 && (k = b.size, b.set(g[x], k), A.push(i(g[x], 0), i(g[x], 1), i(g[x], 2))), g[x] = k;
|
|
200
|
+
}
|
|
201
|
+
if (b.size > jt)
|
|
202
|
+
throw new F("invalid-option", `[Nova3D] Convex hull has more than ${jt} vertices; simplify the points.`);
|
|
203
|
+
return Lt(A, M);
|
|
204
|
+
}
|
|
205
|
+
function vs(d, t) {
|
|
206
|
+
if (!d || typeof d.length != "number" || d.length % 3 !== 0 || d.length < 9)
|
|
207
|
+
throw new F("invalid-option", "[Nova3D] Triangle mesh positions must hold xyz triples.");
|
|
208
|
+
const s = d.length / 3, e = new Float64Array(d.length);
|
|
209
|
+
for (let u = 0; u < d.length; u++) {
|
|
210
|
+
const f = d[u];
|
|
211
|
+
if (typeof f != "number" || !Number.isFinite(f))
|
|
212
|
+
throw new F("invalid-option", "[Nova3D] Triangle mesh positions must be finite.");
|
|
213
|
+
e[u] = f;
|
|
214
|
+
}
|
|
215
|
+
const n = t ?? Array.from({ length: s - s % 3 }, (u, f) => f);
|
|
216
|
+
if (n.length % 3 !== 0 || n.length === 0 || n.length / 3 > ys)
|
|
217
|
+
throw new F("invalid-option", "[Nova3D] Triangle mesh indices must hold whole triangles.");
|
|
218
|
+
const i = new Int32Array(n.length);
|
|
219
|
+
for (let u = 0; u < n.length; u++) {
|
|
220
|
+
const f = n[u];
|
|
221
|
+
if (!Number.isInteger(f) || f < 0 || f >= s)
|
|
222
|
+
throw new F("invalid-option", "[Nova3D] Triangle mesh index out of range.");
|
|
223
|
+
i[u] = f;
|
|
224
|
+
}
|
|
225
|
+
const o = i.length / 3, r = new Float64Array(o * 3), c = new Float64Array(o * 6);
|
|
226
|
+
for (let u = 0; u < o; u++)
|
|
227
|
+
for (let f = 0; f < 3; f++) {
|
|
228
|
+
const y = e[i[u * 3] * 3 + f], w = e[i[u * 3 + 1] * 3 + f], v = e[i[u * 3 + 2] * 3 + f];
|
|
229
|
+
c[u * 6 + f] = Math.min(y, w, v), c[u * 6 + 3 + f] = Math.max(y, w, v), r[u * 3 + f] = (y + w + v) / 3;
|
|
230
|
+
}
|
|
231
|
+
const a = new Int32Array(o);
|
|
232
|
+
for (let u = 0; u < o; u++)
|
|
233
|
+
a[u] = u;
|
|
234
|
+
const l = [], h = [], _ = [], p = (u, f) => {
|
|
235
|
+
const y = h.length;
|
|
236
|
+
h.push(0), _.push(0);
|
|
237
|
+
const w = [1 / 0, 1 / 0, 1 / 0], v = [-1 / 0, -1 / 0, -1 / 0], I = [1 / 0, 1 / 0, 1 / 0], M = [-1 / 0, -1 / 0, -1 / 0];
|
|
238
|
+
for (let x = u; x < f; x++) {
|
|
239
|
+
const k = a[x];
|
|
240
|
+
for (let S = 0; S < 3; S++)
|
|
241
|
+
w[S] = Math.min(w[S], c[k * 6 + S]), v[S] = Math.max(v[S], c[k * 6 + 3 + S]), I[S] = Math.min(I[S], r[k * 3 + S]), M[S] = Math.max(M[S], r[k * 3 + S]);
|
|
242
|
+
}
|
|
243
|
+
if (l.push(...w, ...v), f - u <= 4)
|
|
244
|
+
return h[y] = u, _[y] = f - u, y;
|
|
245
|
+
let b = 0;
|
|
246
|
+
M[1] - I[1] > M[b] - I[b] && (b = 1), M[2] - I[2] > M[b] - I[b] && (b = 2);
|
|
247
|
+
const A = Array.from(a.subarray(u, f)).sort((x, k) => r[x * 3 + b] - r[k * 3 + b] || x - k);
|
|
248
|
+
a.set(A, u);
|
|
249
|
+
const g = u + f >> 1;
|
|
250
|
+
return p(u, g), h[y] = p(g, f), y;
|
|
251
|
+
};
|
|
252
|
+
p(0, o);
|
|
253
|
+
const m = new Float64Array(l);
|
|
254
|
+
return {
|
|
255
|
+
positions: e,
|
|
256
|
+
indices: i,
|
|
257
|
+
triangleCount: o,
|
|
258
|
+
nodeBounds: m,
|
|
259
|
+
nodeStart: new Int32Array(h),
|
|
260
|
+
nodeCount: new Int32Array(_),
|
|
261
|
+
order: a,
|
|
262
|
+
min: m.slice(0, 3),
|
|
263
|
+
max: m.slice(3, 6)
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
function ot(d, t) {
|
|
267
|
+
return {
|
|
268
|
+
kind: d,
|
|
269
|
+
radius: 0,
|
|
270
|
+
halfHeight: 0,
|
|
271
|
+
hull: null,
|
|
272
|
+
mesh: null,
|
|
273
|
+
planeNormal: new Float64Array([0, 1, 0]),
|
|
274
|
+
planeOffset: 0,
|
|
275
|
+
position: new Float64Array(3),
|
|
276
|
+
quaternion: new Float64Array([0, 0, 0, 1]),
|
|
277
|
+
identity: !0,
|
|
278
|
+
...t
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
function Ot(d) {
|
|
282
|
+
if (!d || typeof d != "object")
|
|
283
|
+
throw new F("invalid-option", "[Nova3D] Physics shape must be an object.");
|
|
284
|
+
switch (d.type) {
|
|
285
|
+
case "sphere": {
|
|
286
|
+
const t = it(d.radius, "sphere radius");
|
|
287
|
+
return ot(ut, { radius: t, min: new Float64Array([-t, -t, -t]), max: new Float64Array([t, t, t]), volume: 4 / 3 * Math.PI * t ** 3 });
|
|
288
|
+
}
|
|
289
|
+
case "capsule": {
|
|
290
|
+
const t = it(d.radius, "capsule radius"), s = ms(d.halfHeight, "capsule halfHeight");
|
|
291
|
+
return ot(s > 0 ? pt : ut, { radius: t, halfHeight: s, min: new Float64Array([-t, -t - s, -t]), max: new Float64Array([t, t + s, t]), volume: Math.PI * t * t * 2 * s + 4 / 3 * Math.PI * t ** 3 });
|
|
292
|
+
}
|
|
293
|
+
case "box": {
|
|
294
|
+
const [t, s, e] = Dt(d.halfExtents, 3, "box halfExtents");
|
|
295
|
+
it(t, "box halfExtents"), it(s, "box halfExtents"), it(e, "box halfExtents");
|
|
296
|
+
const n = gs(t, s, e);
|
|
297
|
+
return ot(Q, { hull: n, min: n.min, max: n.max, volume: 8 * t * s * e });
|
|
298
|
+
}
|
|
299
|
+
case "cylinder": {
|
|
300
|
+
const t = it(d.radius, "cylinder radius"), s = it(d.halfHeight, "cylinder halfHeight"), e = ws(t, s);
|
|
301
|
+
return ot(Q, { hull: e, min: e.min, max: e.max, volume: $t(e) });
|
|
302
|
+
}
|
|
303
|
+
case "convex-hull": {
|
|
304
|
+
const t = ns(d.points);
|
|
305
|
+
return ot(Q, { hull: t, min: t.min, max: t.max, volume: $t(t) });
|
|
306
|
+
}
|
|
307
|
+
case "plane": {
|
|
308
|
+
const t = Dt(d.normal ?? [0, 1, 0], 3, "plane normal"), s = Math.hypot(t[0], t[1], t[2]);
|
|
309
|
+
if (!(s > 1e-12))
|
|
310
|
+
throw new F("invalid-option", "[Nova3D] Physics plane normal must be nonzero.");
|
|
311
|
+
const e = d.offset ?? 0;
|
|
312
|
+
if (typeof e != "number" || !Number.isFinite(e))
|
|
313
|
+
throw new F("invalid-option", "[Nova3D] Physics plane offset must be finite.");
|
|
314
|
+
const n = 1e30;
|
|
315
|
+
return ot(U, { planeNormal: new Float64Array(t.map((i) => i / s)), planeOffset: e, min: new Float64Array([-n, -n, -n]), max: new Float64Array([n, n, n]), volume: 0 });
|
|
316
|
+
}
|
|
317
|
+
case "triangle-mesh": {
|
|
318
|
+
const t = vs(d.positions, d.indices);
|
|
319
|
+
return ot(tt, { mesh: t, min: t.min, max: t.max, volume: 0 });
|
|
320
|
+
}
|
|
321
|
+
default:
|
|
322
|
+
throw new F("invalid-option", `[Nova3D] Unsupported physics shape ${String(d.type)}.`);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
function $t(d) {
|
|
326
|
+
const t = new Float64Array(7);
|
|
327
|
+
return is(d, t), t[0];
|
|
328
|
+
}
|
|
329
|
+
function is(d, t) {
|
|
330
|
+
t.fill(0);
|
|
331
|
+
const s = d.vertices;
|
|
332
|
+
for (let e = 0; e < d.faceCount; e++) {
|
|
333
|
+
const n = d.faceStart[e], i = d.faceStart[e + 1] - n, o = d.faceIndices[n] * 3;
|
|
334
|
+
for (let r = 1; r + 1 < i; r++) {
|
|
335
|
+
const c = d.faceIndices[n + r] * 3, a = d.faceIndices[n + r + 1] * 3, l = s[o], h = s[o + 1], _ = s[o + 2], p = s[c], m = s[c + 1], u = s[c + 2], f = s[a], y = s[a + 1], w = s[a + 2], v = l * (m * w - u * y) - h * (p * w - u * f) + _ * (p * y - m * f), I = l + p + f, M = h + m + y, b = _ + u + w, A = v / 120;
|
|
336
|
+
t[0] += v / 6, t[1] += A * (l * l + p * p + f * f + I * I), t[2] += A * (h * h + m * m + y * y + M * M), t[3] += A * (_ * _ + u * u + w * w + b * b), t[4] += A * (l * h + p * m + f * y + I * M), t[5] += A * (l * _ + p * u + f * w + I * b), t[6] += A * (h * _ + m * u + y * w + M * b);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
function Kt(d, t, s) {
|
|
341
|
+
s.fill(0);
|
|
342
|
+
const e = d.radius, n = d.halfHeight;
|
|
343
|
+
if (d.kind === ut)
|
|
344
|
+
s[0] = s[1] = s[2] = 0.4 * e * e;
|
|
345
|
+
else if (d.kind === pt) {
|
|
346
|
+
const i = Math.PI * e * e * 2 * n, o = 4 / 3 * Math.PI * e ** 3, r = i / (i + o), c = o / (i + o);
|
|
347
|
+
s[1] = r * e * e / 2 + c * 0.4 * e * e, s[0] = s[2] = r * (e * e / 4 + n * n / 3) + c * (0.4 * e * e + n * n + 0.75 * n * e);
|
|
348
|
+
} else if (t.type === "box") {
|
|
349
|
+
const [i, o, r] = t.halfExtents;
|
|
350
|
+
s[0] = (o * o + r * r) / 3, s[1] = (i * i + r * r) / 3, s[2] = (i * i + o * o) / 3;
|
|
351
|
+
} else if (d.hull) {
|
|
352
|
+
const i = new Float64Array(7);
|
|
353
|
+
is(d.hull, i);
|
|
354
|
+
const o = i[0], r = i[1] + i[2] + i[3];
|
|
355
|
+
s[0] = (r - i[1]) / o, s[1] = (r - i[2]) / o, s[2] = (r - i[3]) / o, s[3] = -i[4] / o, s[4] = -i[5] / o, s[5] = -i[6] / o;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
function bs(d, t, s, e) {
|
|
359
|
+
const n = new Float64Array(9);
|
|
360
|
+
Tt(n, 0, s[0], s[1], s[2], s[3]);
|
|
361
|
+
const i = [t[0], t[3], t[4], t[3], t[1], t[5], t[4], t[5], t[2]], o = new Float64Array(9);
|
|
362
|
+
for (let c = 0; c < 3; c++)
|
|
363
|
+
for (let a = 0; a < 3; a++)
|
|
364
|
+
for (let l = 0; l < 3; l++)
|
|
365
|
+
o[c * 3 + a] += n[c * 3 + l] * i[l * 3 + a];
|
|
366
|
+
const r = new Float64Array(9);
|
|
367
|
+
for (let c = 0; c < 3; c++)
|
|
368
|
+
for (let a = 0; a < 3; a++)
|
|
369
|
+
for (let l = 0; l < 3; l++)
|
|
370
|
+
r[c * 3 + a] += o[c * 3 + l] * n[a * 3 + l];
|
|
371
|
+
d[0] += e * r[0], d[1] += e * r[4], d[2] += e * r[8], d[3] += e * r[1], d[4] += e * r[2], d[5] += e * r[5];
|
|
372
|
+
}
|
|
373
|
+
function Tt(d, t, s, e, n, i) {
|
|
374
|
+
const o = s * s, r = e * e, c = n * n, a = s * e, l = s * n, h = e * n, _ = i * s, p = i * e, m = i * n;
|
|
375
|
+
d[t] = 1 - 2 * (r + c), d[t + 1] = 2 * (a - m), d[t + 2] = 2 * (l + p), d[t + 3] = 2 * (a + m), d[t + 4] = 1 - 2 * (o + c), d[t + 5] = 2 * (h - _), d[t + 6] = 2 * (l - p), d[t + 7] = 2 * (h + _), d[t + 8] = 1 - 2 * (o + r);
|
|
376
|
+
}
|
|
377
|
+
function xs(d, t) {
|
|
378
|
+
const s = Dt(d, 4, t), e = Math.hypot(s[0], s[1], s[2], s[3]);
|
|
379
|
+
if (!(e > 1e-12))
|
|
380
|
+
throw new F("invalid-option", `[Nova3D] Physics ${t} must be nonzero.`);
|
|
381
|
+
return s.map((n) => n / e);
|
|
382
|
+
}
|
|
383
|
+
function As(d) {
|
|
384
|
+
if (!d || typeof d != "object")
|
|
385
|
+
throw new F("invalid-option", "[Nova3D] Physics shape must be an object.");
|
|
386
|
+
const t = [], s = new Float64Array(6), e = new Float64Array(6);
|
|
387
|
+
if (d.type === "compound") {
|
|
388
|
+
if (!Array.isArray(d.children) || d.children.length === 0 || d.children.length > 256)
|
|
389
|
+
throw new F("invalid-option", "[Nova3D] Compound shapes need 1 to 256 children.");
|
|
390
|
+
let r = 0;
|
|
391
|
+
const c = [];
|
|
392
|
+
for (const a of d.children) {
|
|
393
|
+
if (!a || typeof a != "object" || !a.shape || a.shape.type === "compound" || a.shape.type === "plane")
|
|
394
|
+
throw new F("invalid-option", "[Nova3D] Compound children must be non-compound, non-plane shapes.");
|
|
395
|
+
const l = Ot(a.shape), h = new Float64Array(Dt(a.position ?? [0, 0, 0], 3, "compound child position")), _ = new Float64Array(xs(a.quaternion ?? [0, 0, 0, 1], "compound child quaternion")), p = h[0] === 0 && h[1] === 0 && h[2] === 0 && _[3] === 1, m = { ...l, position: h, quaternion: _, identity: p };
|
|
396
|
+
t.push(m), c.push({ leaf: m, child: a.shape }), r += m.volume;
|
|
397
|
+
}
|
|
398
|
+
if (r > 0)
|
|
399
|
+
for (const { leaf: a, child: l } of c) {
|
|
400
|
+
const h = a.volume / r;
|
|
401
|
+
Kt(a, l, e), bs(s, e, a.quaternion, h);
|
|
402
|
+
const [_, p, m] = a.position;
|
|
403
|
+
s[0] += h * (p * p + m * m), s[1] += h * (_ * _ + m * m), s[2] += h * (_ * _ + p * p), s[3] -= h * _ * p, s[4] -= h * _ * m, s[5] -= h * p * m;
|
|
404
|
+
}
|
|
405
|
+
} else {
|
|
406
|
+
const r = Ot(d);
|
|
407
|
+
t.push(r), Kt(r, d, s);
|
|
408
|
+
}
|
|
409
|
+
let n = 3, i = 2, o = 3;
|
|
410
|
+
for (const r of t)
|
|
411
|
+
r.hull && (n = Math.max(n, r.hull.vertexCount), i = Math.max(i, r.hull.faceCount), o = Math.max(o, r.hull.edgeDirCount));
|
|
412
|
+
return {
|
|
413
|
+
type: d.type,
|
|
414
|
+
leaves: t,
|
|
415
|
+
unitInertia: s,
|
|
416
|
+
staticOnly: t.some((r) => r.kind === U || r.kind === tt),
|
|
417
|
+
maxHullVertices: n,
|
|
418
|
+
maxHullFaces: i,
|
|
419
|
+
maxHullEdgeDirs: o
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
function ks(d, t, s, e, n, i, o, r, c, a) {
|
|
423
|
+
const l = Math.max(-r, Math.min(r, t));
|
|
424
|
+
if (d * d + (t - l) ** 2 + s * s <= o * o)
|
|
425
|
+
return a.t = 0, a.nx = -e, a.ny = -n, a.nz = -i, !0;
|
|
426
|
+
let h = 1 / 0;
|
|
427
|
+
const _ = e * e + i * i;
|
|
428
|
+
if (_ > 1e-14) {
|
|
429
|
+
const p = d * e + s * i, m = d * d + s * s - o * o, u = p * p - _ * m;
|
|
430
|
+
if (u >= 0) {
|
|
431
|
+
const f = (-p - Math.sqrt(u)) / _, y = t + n * f;
|
|
432
|
+
f >= 0 && y >= -r && y <= r && (h = f, a.nx = (d + e * f) / o, a.ny = 0, a.nz = (s + i * f) / o);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
for (const p of r > 0 ? [-r, r] : [0]) {
|
|
436
|
+
const m = t - p, u = d * e + m * n + s * i, f = d * d + m * m + s * s - o * o, y = u * u - f;
|
|
437
|
+
if (y >= 0) {
|
|
438
|
+
const w = -u - Math.sqrt(y);
|
|
439
|
+
w >= 0 && w < h && (h = w, a.nx = (d + e * w) / o, a.ny = (m + n * w) / o, a.nz = (s + i * w) / o);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
return h > c ? !1 : (a.t = h, !0);
|
|
443
|
+
}
|
|
444
|
+
function Is(d, t, s, e, n, i, o, r, c) {
|
|
445
|
+
let a = 0, l = r, h = -1;
|
|
446
|
+
const _ = d.normals;
|
|
447
|
+
for (let p = 0; p < d.faceCount; p++) {
|
|
448
|
+
const m = _[p * 3], u = _[p * 3 + 1], f = _[p * 3 + 2], y = m * n + u * i + f * o, w = d.offsets[p] - (m * t + u * s + f * e);
|
|
449
|
+
if (Math.abs(y) < 1e-15) {
|
|
450
|
+
if (w < 0)
|
|
451
|
+
return !1;
|
|
452
|
+
continue;
|
|
453
|
+
}
|
|
454
|
+
const v = w / y;
|
|
455
|
+
if (y < 0 ? v > a && (a = v, h = p) : v < l && (l = v), a > l)
|
|
456
|
+
return !1;
|
|
457
|
+
}
|
|
458
|
+
return c.t = a, h < 0 ? (c.nx = -n, c.ny = -i, c.nz = -o) : (c.nx = _[h * 3], c.ny = _[h * 3 + 1], c.nz = _[h * 3 + 2]), !0;
|
|
459
|
+
}
|
|
460
|
+
function Ms(d, t, s, e, n, i, o, r, c, a) {
|
|
461
|
+
const l = d.positions, h = d.indices[t * 3] * 3, _ = d.indices[t * 3 + 1] * 3, p = d.indices[t * 3 + 2] * 3, m = l[_] - l[h], u = l[_ + 1] - l[h + 1], f = l[_ + 2] - l[h + 2], y = l[p] - l[h], w = l[p + 1] - l[h + 1], v = l[p + 2] - l[h + 2], I = o * v - r * w, M = r * y - i * v, b = i * w - o * y, A = m * I + u * M + f * b;
|
|
462
|
+
if (Math.abs(A) < 1e-18)
|
|
463
|
+
return !1;
|
|
464
|
+
const g = 1 / A, x = s - l[h], k = e - l[h + 1], S = n - l[h + 2], D = (x * I + k * M + S * b) * g;
|
|
465
|
+
if (D < 0 || D > 1)
|
|
466
|
+
return !1;
|
|
467
|
+
const C = k * f - S * u, N = S * m - x * f, z = x * u - k * m, P = (i * C + o * N + r * z) * g;
|
|
468
|
+
if (P < 0 || D + P > 1)
|
|
469
|
+
return !1;
|
|
470
|
+
const E = (y * C + w * N + v * z) * g;
|
|
471
|
+
if (E < 0 || E > c)
|
|
472
|
+
return !1;
|
|
473
|
+
let B = u * v - f * w, T = f * y - m * v, V = m * w - u * y;
|
|
474
|
+
const L = Math.hypot(B, T, V);
|
|
475
|
+
return B /= L, T /= L, V /= L, B * i + T * o + V * r > 0 && (B = -B, T = -T, V = -V), a.t = E, a.nx = B, a.ny = T, a.nz = V, !0;
|
|
476
|
+
}
|
|
477
|
+
const Ut = 2e-3, Ss = 5e-4, Ds = 0.995, Fs = 128, st = {
|
|
478
|
+
faceStart: new Int32Array([0, 3, 6]),
|
|
479
|
+
faceIndices: new Int32Array([0, 1, 2, 2, 1, 0]),
|
|
480
|
+
edges: new Int32Array([0, 1, 1, 2, 2, 0]),
|
|
481
|
+
edgeDirOf: new Int32Array([0, 1, 2])
|
|
482
|
+
};
|
|
483
|
+
class Jt {
|
|
484
|
+
vertexCount = 0;
|
|
485
|
+
faceCount = 0;
|
|
486
|
+
edgeCount = 0;
|
|
487
|
+
edgeDirCount = 0;
|
|
488
|
+
vertices = new Float64Array(24);
|
|
489
|
+
normals = new Float64Array(18);
|
|
490
|
+
offsets = new Float64Array(6);
|
|
491
|
+
edgeDirs = new Float64Array(9);
|
|
492
|
+
faceStart = st.faceStart;
|
|
493
|
+
faceIndices = st.faceIndices;
|
|
494
|
+
edges = st.edges;
|
|
495
|
+
edgeDirOf = st.edgeDirOf;
|
|
496
|
+
/** Projection range written by `projectHull`. */
|
|
497
|
+
low = 0;
|
|
498
|
+
high = 0;
|
|
499
|
+
fill(t, s) {
|
|
500
|
+
this._reserve(t.vertexCount, t.faceCount, t.edgeDirCount), this.vertexCount = t.vertexCount, this.faceCount = t.faceCount, this.edgeCount = t.edgeCount, this.edgeDirCount = t.edgeDirCount, this.faceStart = t.faceStart, this.faceIndices = t.faceIndices, this.edges = t.edges, this.edgeDirOf = t.edgeDirOf;
|
|
501
|
+
const e = s[0], n = s[1], i = s[2], o = t.vertices, r = this.vertices;
|
|
502
|
+
for (let l = 0; l < t.vertexCount * 3; l += 3) {
|
|
503
|
+
const h = o[l], _ = o[l + 1], p = o[l + 2];
|
|
504
|
+
r[l] = s[3] * h + s[4] * _ + s[5] * p + e, r[l + 1] = s[6] * h + s[7] * _ + s[8] * p + n, r[l + 2] = s[9] * h + s[10] * _ + s[11] * p + i;
|
|
505
|
+
}
|
|
506
|
+
const c = t.normals;
|
|
507
|
+
for (let l = 0; l < t.faceCount; l++) {
|
|
508
|
+
const h = l * 3, _ = c[h], p = c[h + 1], m = c[h + 2], u = s[3] * _ + s[4] * p + s[5] * m, f = s[6] * _ + s[7] * p + s[8] * m, y = s[9] * _ + s[10] * p + s[11] * m;
|
|
509
|
+
this.normals[h] = u, this.normals[h + 1] = f, this.normals[h + 2] = y, this.offsets[l] = t.offsets[l] + u * e + f * n + y * i;
|
|
510
|
+
}
|
|
511
|
+
const a = t.edgeDirs;
|
|
512
|
+
for (let l = 0; l < t.edgeDirCount * 3; l += 3) {
|
|
513
|
+
const h = a[l], _ = a[l + 1], p = a[l + 2];
|
|
514
|
+
this.edgeDirs[l] = s[3] * h + s[4] * _ + s[5] * p, this.edgeDirs[l + 1] = s[6] * h + s[7] * _ + s[8] * p, this.edgeDirs[l + 2] = s[9] * h + s[10] * _ + s[11] * p;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
/** Two-sided world triangle; returns false for a degenerate one. */
|
|
518
|
+
fillTriangle(t, s, e) {
|
|
519
|
+
this._reserve(3, 2, 3), this.vertexCount = 3, this.faceCount = 2, this.edgeCount = 3, this.edgeDirCount = 3, this.faceStart = st.faceStart, this.faceIndices = st.faceIndices, this.edges = st.edges, this.edgeDirOf = st.edgeDirOf;
|
|
520
|
+
const n = t.positions, i = this.vertices;
|
|
521
|
+
for (let y = 0; y < 3; y++) {
|
|
522
|
+
const w = t.indices[s * 3 + y] * 3, v = n[w], I = n[w + 1], M = n[w + 2];
|
|
523
|
+
i[y * 3] = e[3] * v + e[4] * I + e[5] * M + e[0], i[y * 3 + 1] = e[6] * v + e[7] * I + e[8] * M + e[1], i[y * 3 + 2] = e[9] * v + e[10] * I + e[11] * M + e[2];
|
|
524
|
+
}
|
|
525
|
+
const o = i[3] - i[0], r = i[4] - i[1], c = i[5] - i[2], a = i[6] - i[0], l = i[7] - i[1], h = i[8] - i[2];
|
|
526
|
+
let _ = r * h - c * l, p = c * a - o * h, m = o * l - r * a;
|
|
527
|
+
const u = Math.sqrt(_ * _ + p * p + m * m);
|
|
528
|
+
if (!(u > 1e-14))
|
|
529
|
+
return !1;
|
|
530
|
+
_ /= u, p /= u, m /= u;
|
|
531
|
+
const f = _ * i[0] + p * i[1] + m * i[2];
|
|
532
|
+
this.normals[0] = _, this.normals[1] = p, this.normals[2] = m, this.offsets[0] = f, this.normals[3] = -_, this.normals[4] = -p, this.normals[5] = -m, this.offsets[1] = -f;
|
|
533
|
+
for (let y = 0; y < 3; y++) {
|
|
534
|
+
const w = y * 3, v = (y + 1) % 3 * 3, I = i[v] - i[w], M = i[v + 1] - i[w + 1], b = i[v + 2] - i[w + 2], A = Math.sqrt(I * I + M * M + b * b);
|
|
535
|
+
this.edgeDirs[w] = I / A, this.edgeDirs[w + 1] = M / A, this.edgeDirs[w + 2] = b / A;
|
|
536
|
+
}
|
|
537
|
+
return !0;
|
|
538
|
+
}
|
|
539
|
+
_reserve(t, s, e) {
|
|
540
|
+
this.vertices.length < t * 3 && (this.vertices = new Float64Array(t * 3)), this.offsets.length < s && (this.normals = new Float64Array(s * 3), this.offsets = new Float64Array(s)), this.edgeDirs.length < e * 3 && (this.edgeDirs = new Float64Array(e * 3));
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
class Ns {
|
|
544
|
+
/** Points of the last `collide` calls: position xyz, normal xyz, separation. */
|
|
545
|
+
count = 0;
|
|
546
|
+
points = new Float64Array(112);
|
|
547
|
+
/** Gap within which contacts are generated, metres. */
|
|
548
|
+
margin = 0;
|
|
549
|
+
_hullA = new Jt();
|
|
550
|
+
_hullB = new Jt();
|
|
551
|
+
_clipA = new Float64Array(192);
|
|
552
|
+
_clipB = new Float64Array(192);
|
|
553
|
+
/** Reduction scratch: candidates (xyz, separation) collected before keeping four. */
|
|
554
|
+
_candidates = new Float64Array(256);
|
|
555
|
+
_stack = new Int32Array(Fs);
|
|
556
|
+
_meshMin = new Float64Array(3);
|
|
557
|
+
_meshMax = new Float64Array(3);
|
|
558
|
+
/** −1 when the routine's first collider is the pair's second body. */
|
|
559
|
+
_sign = 1;
|
|
560
|
+
/** Radius of the current segment collider. */
|
|
561
|
+
_radius = 0;
|
|
562
|
+
/** Point to push: xyz, normal xyz, separation. */
|
|
563
|
+
_q = new Float64Array(7);
|
|
564
|
+
/** Current segment collider: start xyz, end xyz. */
|
|
565
|
+
_s = new Float64Array(6);
|
|
566
|
+
/** Closest-segments input p1 q1 p2 q2 and output c1 c2. */
|
|
567
|
+
_seg = new Float64Array(12);
|
|
568
|
+
_c = new Float64Array(6);
|
|
569
|
+
_axis = new Float64Array(3);
|
|
570
|
+
_normal = new Float64Array(3);
|
|
571
|
+
_clipPlane = new Float64Array(4);
|
|
572
|
+
/** Collides two leaves with world poses `ta` and `tb`, appending to `points`. */
|
|
573
|
+
collide(t, s, e, n) {
|
|
574
|
+
const i = t.kind, o = e.kind;
|
|
575
|
+
if (i === tt || o === tt) {
|
|
576
|
+
i === tt && o !== tt && o !== U ? (this._sign = 1, this._mesh(t.mesh, s, e, n)) : o === tt && i !== U && i !== tt && (this._sign = -1, this._mesh(e.mesh, n, t, s));
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
if (i === U || o === U) {
|
|
580
|
+
i === U && o !== U ? (this._sign = 1, this._plane(t, s, e, n)) : o === U && i !== U && (this._sign = -1, this._plane(e, n, t, s));
|
|
581
|
+
return;
|
|
582
|
+
}
|
|
583
|
+
if (i === Q && o === Q) {
|
|
584
|
+
this._sign = 1, this._hullA.fill(t.hull, s), this._hullB.fill(e.hull, n), this._hullHull(this._hullA, this._hullB);
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
if (i === Q) {
|
|
588
|
+
this._sign = 1, this._hullA.fill(t.hull, s), this._loadSegment(e, n), this._radius = e.radius, this._hullSegment(this._hullA);
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
591
|
+
if (o === Q) {
|
|
592
|
+
this._sign = -1, this._hullA.fill(e.hull, n), this._loadSegment(t, s), this._radius = t.radius, this._hullSegment(this._hullA);
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
this._sign = 1, this._segmentSegment(t, s, e, n);
|
|
596
|
+
}
|
|
597
|
+
/** Grows clip buffers for hulls with `faceVertices` vertices on one face. */
|
|
598
|
+
reserve(t) {
|
|
599
|
+
const s = (t * 2 + 8) * 3;
|
|
600
|
+
this._clipA.length < s && (this._clipA = new Float64Array(s), this._clipB = new Float64Array(s));
|
|
601
|
+
}
|
|
602
|
+
/** Appends `_q`, flipping the normal for swapped colliders. */
|
|
603
|
+
_push() {
|
|
604
|
+
if ((this.count + 1) * 7 > this.points.length) {
|
|
605
|
+
const i = new Float64Array(this.points.length * 2);
|
|
606
|
+
i.set(this.points), this.points = i;
|
|
607
|
+
}
|
|
608
|
+
const t = this.count * 7, s = this.points, e = this._q, n = this._sign;
|
|
609
|
+
s[t] = e[0], s[t + 1] = e[1], s[t + 2] = e[2], s[t + 3] = e[3] * n, s[t + 4] = e[4] * n, s[t + 5] = e[5] * n, s[t + 6] = e[6], this.count++;
|
|
610
|
+
}
|
|
611
|
+
_loadSegment(t, s) {
|
|
612
|
+
const e = t.kind === pt ? t.halfHeight : 0, n = this._s;
|
|
613
|
+
n[0] = s[0] - s[4] * e, n[1] = s[1] - s[7] * e, n[2] = s[2] - s[10] * e, n[3] = s[0] + s[4] * e, n[4] = s[1] + s[7] * e, n[5] = s[2] + s[10] * e;
|
|
614
|
+
}
|
|
615
|
+
// ---------------------------------------------------------------- spheres and capsules
|
|
616
|
+
_segmentSegment(t, s, e, n) {
|
|
617
|
+
const i = this._seg, o = this._s;
|
|
618
|
+
this._loadSegment(t, s);
|
|
619
|
+
for (let P = 0; P < 6; P++)
|
|
620
|
+
i[P] = o[P];
|
|
621
|
+
this._loadSegment(e, n);
|
|
622
|
+
for (let P = 0; P < 6; P++)
|
|
623
|
+
i[6 + P] = o[P];
|
|
624
|
+
const r = t.radius, c = e.radius, a = this.margin, l = this._c, h = this._q;
|
|
625
|
+
this._closestSegments();
|
|
626
|
+
let _ = l[3] - l[0], p = l[4] - l[1], m = l[5] - l[2];
|
|
627
|
+
const u = Math.sqrt(_ * _ + p * p + m * m), f = u - r - c;
|
|
628
|
+
if (f > a)
|
|
629
|
+
return;
|
|
630
|
+
u > 1e-9 ? (_ /= u, p /= u, m /= u) : (_ = 0, p = 1, m = 0);
|
|
631
|
+
const y = (r - c) / 2, w = i[0], v = i[1], I = i[2], M = i[3] - w, b = i[4] - v, A = i[5] - I, g = i[6], x = i[7], k = i[8], S = i[9] - g, D = i[10] - x, C = i[11] - k, N = Math.sqrt(M * M + b * b + A * A), z = Math.sqrt(S * S + D * D + C * C);
|
|
632
|
+
if (N > 1e-9 && z > 1e-9 && Math.abs(M * S + b * D + A * C) > Ds * N * z) {
|
|
633
|
+
const P = M / N, E = b / N, B = A / N, T = (g - w) * P + (x - v) * E + (k - I) * B, V = (i[9] - w) * P + (i[10] - v) * E + (i[11] - I) * B, L = Math.max(0, Math.min(T, V)), H = Math.min(N, Math.max(T, V));
|
|
634
|
+
if (H - L > 1e-6) {
|
|
635
|
+
for (let $ = 0; $ < 2; $++) {
|
|
636
|
+
const J = $ ? H : L, K = w + P * J, G = v + E * J, lt = I + B * J, ht = Math.max(0, Math.min(1, ((K - g) * S + (G - x) * D + (lt - k) * C) / (z * z))), ft = g + S * ht, mt = x + D * ht, gt = k + C * ht, wt = (ft - K) * _ + (mt - G) * p + (gt - lt) * m - r - c;
|
|
637
|
+
wt <= a && (h[0] = (K + ft) / 2 + _ * y, h[1] = (G + mt) / 2 + p * y, h[2] = (lt + gt) / 2 + m * y, h[3] = _, h[4] = p, h[5] = m, h[6] = wt, this._push());
|
|
638
|
+
}
|
|
639
|
+
return;
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
h[0] = (l[0] + l[3]) / 2 + _ * y, h[1] = (l[1] + l[4]) / 2 + p * y, h[2] = (l[2] + l[5]) / 2 + m * y, h[3] = _, h[4] = p, h[5] = m, h[6] = f, this._push();
|
|
643
|
+
}
|
|
644
|
+
/** Closest points c1, c2 between segments p1q1 and p2q2 of `_seg` (Ericson 5.1.9). */
|
|
645
|
+
_closestSegments() {
|
|
646
|
+
const t = this._seg, s = t[0], e = t[1], n = t[2], i = t[6], o = t[7], r = t[8], c = t[3] - s, a = t[4] - e, l = t[5] - n, h = t[9] - i, _ = t[10] - o, p = t[11] - r, m = s - i, u = e - o, f = n - r, y = c * c + a * a + l * l, w = h * h + _ * _ + p * p, v = h * m + _ * u + p * f;
|
|
647
|
+
let I = 0, M = 0;
|
|
648
|
+
const b = 1e-18;
|
|
649
|
+
if (y <= b && w <= b)
|
|
650
|
+
I = 0, M = 0;
|
|
651
|
+
else if (y <= b)
|
|
652
|
+
M = Math.max(0, Math.min(1, v / w));
|
|
653
|
+
else {
|
|
654
|
+
const g = c * m + a * u + l * f;
|
|
655
|
+
if (w <= b)
|
|
656
|
+
I = Math.max(0, Math.min(1, -g / y));
|
|
657
|
+
else {
|
|
658
|
+
const x = c * h + a * _ + l * p, k = y * w - x * x;
|
|
659
|
+
I = k > b * y * w ? Math.max(0, Math.min(1, (x * v - g * w) / k)) : 0, M = (x * I + v) / w, M < 0 ? (M = 0, I = Math.max(0, Math.min(1, -g / y))) : M > 1 && (M = 1, I = Math.max(0, Math.min(1, (x - g) / y)));
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
const A = this._c;
|
|
663
|
+
A[0] = s + c * I, A[1] = e + a * I, A[2] = n + l * I, A[3] = i + h * M, A[4] = o + _ * M, A[5] = r + p * M;
|
|
664
|
+
}
|
|
665
|
+
/** Writes hull vertices `a`, `b` and the current segment into `_seg`. */
|
|
666
|
+
_loadEdgeAndSegment(t, s, e) {
|
|
667
|
+
const n = t.vertices, i = this._seg, o = this._s;
|
|
668
|
+
i[0] = n[s], i[1] = n[s + 1], i[2] = n[s + 2], i[3] = n[e], i[4] = n[e + 1], i[5] = n[e + 2];
|
|
669
|
+
for (let r = 0; r < 6; r++)
|
|
670
|
+
i[6 + r] = o[r];
|
|
671
|
+
}
|
|
672
|
+
// ---------------------------------------------------------------- hull against segment
|
|
673
|
+
/** Hull first, the loaded segment of `_radius` second. */
|
|
674
|
+
_hullSegment(t) {
|
|
675
|
+
const s = this.margin, e = this._radius, n = this._s, i = n[0], o = n[1], r = n[2], c = n[3], a = n[4], l = n[5], h = t.normals;
|
|
676
|
+
let _ = -1 / 0, p = -1;
|
|
677
|
+
for (let A = 0; A < t.faceCount; A++) {
|
|
678
|
+
const g = h[A * 3], x = h[A * 3 + 1], k = h[A * 3 + 2], S = Math.min(g * i + x * o + k * r, g * c + x * a + k * l) - t.offsets[A];
|
|
679
|
+
if (S - e > s)
|
|
680
|
+
return;
|
|
681
|
+
S > _ && (_ = S, p = A);
|
|
682
|
+
}
|
|
683
|
+
let m = c - i, u = a - o, f = l - r;
|
|
684
|
+
const y = Math.sqrt(m * m + u * u + f * f);
|
|
685
|
+
let w = -1 / 0, v = -1, I = 0, M = 0, b = 0;
|
|
686
|
+
if (y > 1e-9) {
|
|
687
|
+
m /= y, u /= y, f /= y;
|
|
688
|
+
const A = t.edgeDirs, g = t.vertices;
|
|
689
|
+
for (let x = 0; x < t.edgeDirCount; x++) {
|
|
690
|
+
let k = A[x * 3 + 1] * f - A[x * 3 + 2] * u, S = A[x * 3 + 2] * m - A[x * 3] * f, D = A[x * 3] * u - A[x * 3 + 1] * m;
|
|
691
|
+
const C = Math.sqrt(k * k + S * S + D * D);
|
|
692
|
+
if (C < 1e-6)
|
|
693
|
+
continue;
|
|
694
|
+
k /= C, S /= C, D /= C;
|
|
695
|
+
let N = 1 / 0, z = -1 / 0;
|
|
696
|
+
for (let L = 0; L < t.vertexCount * 3; L += 3) {
|
|
697
|
+
const H = k * g[L] + S * g[L + 1] + D * g[L + 2];
|
|
698
|
+
N = H < N ? H : N, z = H > z ? H : z;
|
|
699
|
+
}
|
|
700
|
+
const P = k * i + S * o + D * r, E = k * c + S * a + D * l, B = Math.min(P, E) - z, T = N - Math.max(P, E), V = B > T ? B : T;
|
|
701
|
+
if (V - e > s)
|
|
702
|
+
return;
|
|
703
|
+
if (V > w) {
|
|
704
|
+
w = V, v = x;
|
|
705
|
+
const L = B >= T ? 1 : -1;
|
|
706
|
+
I = k * L, M = S * L, b = D * L;
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
if (_ > 0 || w > 0) {
|
|
711
|
+
this._hullSegmentSeparated(t);
|
|
712
|
+
return;
|
|
713
|
+
}
|
|
714
|
+
if (w > _ + Ut) {
|
|
715
|
+
const A = t.vertices;
|
|
716
|
+
let g = -1 / 0, x = 0;
|
|
717
|
+
for (let D = 0; D < t.edgeCount; D++) {
|
|
718
|
+
if (t.edgeDirOf[D] !== v)
|
|
719
|
+
continue;
|
|
720
|
+
const C = t.edges[D * 2] * 3, N = t.edges[D * 2 + 1] * 3, z = I * (A[C] + A[N]) + M * (A[C + 1] + A[N + 1]) + b * (A[C + 2] + A[N + 2]);
|
|
721
|
+
z > g && (g = z, x = D);
|
|
722
|
+
}
|
|
723
|
+
this._loadEdgeAndSegment(t, t.edges[x * 2] * 3, t.edges[x * 2 + 1] * 3), this._closestSegments();
|
|
724
|
+
const k = this._c, S = this._q;
|
|
725
|
+
S[0] = (k[0] + k[3] - I * e) / 2, S[1] = (k[1] + k[4] - M * e) / 2, S[2] = (k[2] + k[5] - b * e) / 2, S[3] = I, S[4] = M, S[5] = b, S[6] = w - e, this._push();
|
|
726
|
+
return;
|
|
727
|
+
}
|
|
728
|
+
this._segmentOnFace(t, p, !0);
|
|
729
|
+
}
|
|
730
|
+
/**
|
|
731
|
+
* Clips the loaded segment to the prism of a face and pushes its ends.
|
|
732
|
+
* Without any clipped point, pushes the deeper segment end when `fallback`.
|
|
733
|
+
*/
|
|
734
|
+
_segmentOnFace(t, s, e) {
|
|
735
|
+
const n = this._radius, i = this.margin, o = t.normals[s * 3], r = t.normals[s * 3 + 1], c = t.normals[s * 3 + 2], a = t.offsets[s], l = this._s, h = this._q, _ = l[0], p = l[1], m = l[2], u = l[3] - _, f = l[4] - p, y = l[5] - m;
|
|
736
|
+
let w = 0, v = 1;
|
|
737
|
+
const I = t.faceStart[s], M = t.faceStart[s + 1] - I, b = t.vertices;
|
|
738
|
+
for (let g = 0; g < M && w <= v; g++) {
|
|
739
|
+
const x = t.faceIndices[I + g] * 3, k = t.faceIndices[I + (g + 1) % M] * 3, S = b[k] - b[x], D = b[k + 1] - b[x + 1], C = b[k + 2] - b[x + 2], N = D * c - C * r, z = C * o - S * c, P = S * r - D * o, E = N * (_ - b[x]) + z * (p - b[x + 1]) + P * (m - b[x + 2]), B = N * u + z * f + P * y;
|
|
740
|
+
if (Math.abs(B) < 1e-15) {
|
|
741
|
+
E > 0 && (w = 2);
|
|
742
|
+
continue;
|
|
743
|
+
}
|
|
744
|
+
const T = -E / B;
|
|
745
|
+
B > 0 ? v = T < v ? T : v : w = T > w ? T : w;
|
|
746
|
+
}
|
|
747
|
+
let A = !1;
|
|
748
|
+
if (w <= v) {
|
|
749
|
+
const g = Math.abs(u) + Math.abs(f) + Math.abs(y) < 1e-12 || v - w < 1e-9;
|
|
750
|
+
for (let x = 0; x < (g ? 1 : 2); x++) {
|
|
751
|
+
const k = x === 0 ? w : v, S = _ + u * k, D = p + f * k, C = m + y * k, N = o * S + r * D + c * C - a - n;
|
|
752
|
+
if (N <= i) {
|
|
753
|
+
const z = n + N / 2;
|
|
754
|
+
h[0] = S - o * z, h[1] = D - r * z, h[2] = C - c * z, h[3] = o, h[4] = r, h[5] = c, h[6] = N, this._push(), A = !0;
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
if (!A && e) {
|
|
759
|
+
const g = o * _ + r * p + c * m, x = o * l[3] + r * l[4] + c * l[5], k = g <= x, S = k ? _ : l[3], D = k ? p : l[4], C = k ? m : l[5], N = (k ? g : x) - a - n, z = n + N / 2;
|
|
760
|
+
h[0] = S - o * z, h[1] = D - r * z, h[2] = C - c * z, h[3] = o, h[4] = r, h[5] = c, h[6] = N, this._push(), A = !0;
|
|
761
|
+
}
|
|
762
|
+
return A;
|
|
763
|
+
}
|
|
764
|
+
/** Exact closest points when the segment core lies outside the hull. */
|
|
765
|
+
_hullSegmentSeparated(t) {
|
|
766
|
+
const s = this._radius, e = this._s, n = e[0], i = e[1], o = e[2], r = e[3], c = e[4], a = e[5], l = t.vertices, h = t.normals, _ = this._c;
|
|
767
|
+
let p = 1 / 0, m = 0, u = 0, f = 0, y = 0, w = 0, v = 0, I = -1;
|
|
768
|
+
for (let x = 0; x < t.faceCount; x++) {
|
|
769
|
+
const k = h[x * 3], S = h[x * 3 + 1], D = h[x * 3 + 2], C = t.offsets[x], N = k * n + S * i + D * o - C, z = k * r + S * c + D * a - C;
|
|
770
|
+
if (N <= 0 && z <= 0)
|
|
771
|
+
continue;
|
|
772
|
+
const P = t.faceStart[x], E = t.faceStart[x + 1] - P;
|
|
773
|
+
for (let B = 0; B < 2; B++) {
|
|
774
|
+
const T = B ? r : n, V = B ? c : i, L = B ? a : o, H = B ? z : N;
|
|
775
|
+
if (H < 0 || H >= p)
|
|
776
|
+
continue;
|
|
777
|
+
let $ = !0;
|
|
778
|
+
for (let J = 0; J < E && $; J++) {
|
|
779
|
+
const K = t.faceIndices[P + J] * 3, G = t.faceIndices[P + (J + 1) % E] * 3, lt = l[G] - l[K], ht = l[G + 1] - l[K + 1], ft = l[G + 2] - l[K + 2], mt = ht * D - ft * S, gt = ft * k - lt * D, wt = lt * S - ht * k;
|
|
780
|
+
$ = mt * (T - l[K]) + gt * (V - l[K + 1]) + wt * (L - l[K + 2]) <= 0;
|
|
781
|
+
}
|
|
782
|
+
$ && (p = H, y = T, w = V, v = L, m = T - k * H, u = V - S * H, f = L - D * H, I = x);
|
|
783
|
+
}
|
|
784
|
+
for (let B = 0; B < E; B++) {
|
|
785
|
+
this._loadEdgeAndSegment(t, t.faceIndices[P + B] * 3, t.faceIndices[P + (B + 1) % E] * 3), this._closestSegments();
|
|
786
|
+
const T = _[3] - _[0], V = _[4] - _[1], L = _[5] - _[2], H = Math.sqrt(T * T + V * V + L * L);
|
|
787
|
+
H < p && (p = H, m = _[0], u = _[1], f = _[2], y = _[3], w = _[4], v = _[5], I = -1);
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
if (!(p < 1 / 0) || p - s > this.margin || p < 1e-12)
|
|
791
|
+
return;
|
|
792
|
+
const M = (y - m) / p, b = (w - u) / p, A = (v - f) / p;
|
|
793
|
+
if (I < 0) {
|
|
794
|
+
for (let x = 0; x < t.faceCount; x++)
|
|
795
|
+
if (h[x * 3] * M + h[x * 3 + 1] * b + h[x * 3 + 2] * A > 0.9999) {
|
|
796
|
+
I = x;
|
|
797
|
+
break;
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
if (I >= 0) {
|
|
801
|
+
const x = r - n, k = c - i, S = a - o, D = Math.sqrt(x * x + k * k + S * S), C = x * h[I * 3] + k * h[I * 3 + 1] + S * h[I * 3 + 2];
|
|
802
|
+
if (D > 1e-9 && Math.abs(C) < 0.1 * D && this._segmentOnFace(t, I, !1))
|
|
803
|
+
return;
|
|
804
|
+
}
|
|
805
|
+
const g = this._q;
|
|
806
|
+
g[0] = (m + y - M * s) / 2, g[1] = (u + w - b * s) / 2, g[2] = (f + v - A * s) / 2, g[3] = M, g[4] = b, g[5] = A, g[6] = p - s, this._push();
|
|
807
|
+
}
|
|
808
|
+
// ---------------------------------------------------------------- hull against hull
|
|
809
|
+
_hullHull(t, s) {
|
|
810
|
+
const e = this.margin, n = this._axis;
|
|
811
|
+
let i = -1 / 0, o = -1;
|
|
812
|
+
for (let y = 0; y < t.faceCount; y++) {
|
|
813
|
+
n[0] = t.normals[y * 3], n[1] = t.normals[y * 3 + 1], n[2] = t.normals[y * 3 + 2], bt(s, n);
|
|
814
|
+
const w = s.low - t.offsets[y];
|
|
815
|
+
if (w > e)
|
|
816
|
+
return;
|
|
817
|
+
w > i && (i = w, o = y);
|
|
818
|
+
}
|
|
819
|
+
let r = -1 / 0, c = -1;
|
|
820
|
+
for (let y = 0; y < s.faceCount; y++) {
|
|
821
|
+
n[0] = s.normals[y * 3], n[1] = s.normals[y * 3 + 1], n[2] = s.normals[y * 3 + 2], bt(t, n);
|
|
822
|
+
const w = t.low - s.offsets[y];
|
|
823
|
+
if (w > e)
|
|
824
|
+
return;
|
|
825
|
+
w > r && (r = w, c = y);
|
|
826
|
+
}
|
|
827
|
+
let a = -1 / 0, l = -1, h = -1;
|
|
828
|
+
const _ = this._normal, p = t.edgeDirs, m = s.edgeDirs;
|
|
829
|
+
for (let y = 0; y < t.edgeDirCount; y++) {
|
|
830
|
+
const w = p[y * 3], v = p[y * 3 + 1], I = p[y * 3 + 2];
|
|
831
|
+
for (let M = 0; M < s.edgeDirCount; M++) {
|
|
832
|
+
const b = m[M * 3], A = m[M * 3 + 1], g = m[M * 3 + 2], x = v * g - I * A, k = I * b - w * g, S = w * A - v * b, D = Math.sqrt(x * x + k * k + S * S);
|
|
833
|
+
if (D < 1e-5)
|
|
834
|
+
continue;
|
|
835
|
+
n[0] = x / D, n[1] = k / D, n[2] = S / D, bt(t, n), bt(s, n);
|
|
836
|
+
const C = s.low - t.high, N = t.low - s.high, z = C > N ? C : N;
|
|
837
|
+
if (z > e)
|
|
838
|
+
return;
|
|
839
|
+
if (z > a) {
|
|
840
|
+
a = z, l = y, h = M;
|
|
841
|
+
const P = C >= N ? 1 : -1;
|
|
842
|
+
_[0] = n[0] * P, _[1] = n[1] * P, _[2] = n[2] * P;
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
const u = r > i + Ss;
|
|
847
|
+
if (a > (u ? r : i) + Ut) {
|
|
848
|
+
const y = Gt(t, l, _, !1), w = Gt(s, h, _, !0), v = t.vertices, I = s.vertices, M = this._seg;
|
|
849
|
+
for (let g = 0; g < 3; g++)
|
|
850
|
+
M[g] = v[t.edges[y * 2] * 3 + g], M[3 + g] = v[t.edges[y * 2 + 1] * 3 + g], M[6 + g] = I[s.edges[w * 2] * 3 + g], M[9 + g] = I[s.edges[w * 2 + 1] * 3 + g];
|
|
851
|
+
this._closestSegments();
|
|
852
|
+
const b = this._c, A = (b[3] - b[0]) * _[0] + (b[4] - b[1]) * _[1] + (b[5] - b[2]) * _[2];
|
|
853
|
+
if (A <= e) {
|
|
854
|
+
const g = this._q;
|
|
855
|
+
g[0] = (b[0] + b[3]) / 2, g[1] = (b[1] + b[4]) / 2, g[2] = (b[2] + b[5]) / 2, g[3] = _[0], g[4] = _[1], g[5] = _[2], g[6] = A, this._push();
|
|
856
|
+
}
|
|
857
|
+
return;
|
|
858
|
+
}
|
|
859
|
+
u ? (this._sign = -this._sign, this._faceContact(s, c, t), this._sign = -this._sign) : this._faceContact(t, o, s);
|
|
860
|
+
}
|
|
861
|
+
/** Clips the incident face of `incident` against reference face `face` of `reference`. */
|
|
862
|
+
_faceContact(t, s, e) {
|
|
863
|
+
const n = t.normals[s * 3], i = t.normals[s * 3 + 1], o = t.normals[s * 3 + 2], r = t.offsets[s];
|
|
864
|
+
let c = 0, a = 1 / 0;
|
|
865
|
+
for (let b = 0; b < e.faceCount; b++) {
|
|
866
|
+
const A = e.normals[b * 3] * n + e.normals[b * 3 + 1] * i + e.normals[b * 3 + 2] * o;
|
|
867
|
+
A < a && (a = A, c = b);
|
|
868
|
+
}
|
|
869
|
+
const l = e.vertices, h = e.faceStart[c];
|
|
870
|
+
let _ = e.faceStart[c + 1] - h, p = this._clipA, m = this._clipB;
|
|
871
|
+
for (let b = 0; b < _; b++) {
|
|
872
|
+
const A = e.faceIndices[h + b] * 3;
|
|
873
|
+
p[b * 3] = l[A], p[b * 3 + 1] = l[A + 1], p[b * 3 + 2] = l[A + 2];
|
|
874
|
+
}
|
|
875
|
+
const u = t.vertices, f = t.faceStart[s], y = t.faceStart[s + 1] - f, w = this._clipPlane;
|
|
876
|
+
for (let b = 0; b < y && _ > 0; b++) {
|
|
877
|
+
const A = t.faceIndices[f + b] * 3, g = t.faceIndices[f + (b + 1) % y] * 3, x = u[g] - u[A], k = u[g + 1] - u[A + 1], S = u[g + 2] - u[A + 2], D = k * o - S * i, C = S * n - x * o, N = x * i - k * n;
|
|
878
|
+
if (D * D + C * C + N * N < 1e-24)
|
|
879
|
+
continue;
|
|
880
|
+
w[0] = D, w[1] = C, w[2] = N, w[3] = D * u[A] + C * u[A + 1] + N * u[A + 2], _ = Cs(p, _, m, w);
|
|
881
|
+
const z = p;
|
|
882
|
+
p = m, m = z;
|
|
883
|
+
}
|
|
884
|
+
let v = 0;
|
|
885
|
+
const I = this._reserveCandidates(_);
|
|
886
|
+
for (let b = 0; b < _; b++) {
|
|
887
|
+
const A = p[b * 3], g = p[b * 3 + 1], x = p[b * 3 + 2], k = n * A + i * g + o * x - r;
|
|
888
|
+
k <= this.margin && (I[v * 4] = A - n * k / 2, I[v * 4 + 1] = g - i * k / 2, I[v * 4 + 2] = x - o * k / 2, I[v * 4 + 3] = k, v++);
|
|
889
|
+
}
|
|
890
|
+
const M = this._normal;
|
|
891
|
+
M[0] = n, M[1] = i, M[2] = o, this._pushReduced(v);
|
|
892
|
+
}
|
|
893
|
+
_reserveCandidates(t) {
|
|
894
|
+
return this._candidates.length < t * 4 && (this._candidates = new Float64Array(t * 8)), this._candidates;
|
|
895
|
+
}
|
|
896
|
+
/** Pushes candidates sharing `_normal`, reduced to the deepest four that span the most area. */
|
|
897
|
+
_pushReduced(t) {
|
|
898
|
+
const s = this._candidates, e = this._normal, n = e[0], i = e[1], o = e[2], r = this._q;
|
|
899
|
+
if (r[3] = n, r[4] = i, r[5] = o, t <= 4) {
|
|
900
|
+
for (let A = 0; A < t; A++)
|
|
901
|
+
r[0] = s[A * 4], r[1] = s[A * 4 + 1], r[2] = s[A * 4 + 2], r[6] = s[A * 4 + 3], this._push();
|
|
902
|
+
return;
|
|
903
|
+
}
|
|
904
|
+
let c = 0;
|
|
905
|
+
for (let A = 1; A < t; A++)
|
|
906
|
+
s[A * 4 + 3] < s[c * 4 + 3] && (c = A);
|
|
907
|
+
const a = s[c * 4], l = s[c * 4 + 1], h = s[c * 4 + 2];
|
|
908
|
+
let _ = c, p = -1;
|
|
909
|
+
for (let A = 0; A < t; A++) {
|
|
910
|
+
const g = s[A * 4] - a, x = s[A * 4 + 1] - l, k = s[A * 4 + 2] - h, S = g * g + x * x + k * k;
|
|
911
|
+
S > p && (p = S, _ = A);
|
|
912
|
+
}
|
|
913
|
+
const m = s[_ * 4] - a, u = s[_ * 4 + 1] - l, f = s[_ * 4 + 2] - h;
|
|
914
|
+
let y = c, w = 0;
|
|
915
|
+
p = -1;
|
|
916
|
+
for (let A = 0; A < t; A++) {
|
|
917
|
+
const g = s[A * 4] - a, x = s[A * 4 + 1] - l, k = s[A * 4 + 2] - h, S = n * (u * k - f * x) + i * (f * g - m * k) + o * (m * x - u * g);
|
|
918
|
+
Math.abs(S) > p && (p = Math.abs(S), y = A, w = S);
|
|
919
|
+
}
|
|
920
|
+
const v = w < 0 ? _ : c, I = w < 0 ? c : _, M = y;
|
|
921
|
+
let b = -1;
|
|
922
|
+
p = 0;
|
|
923
|
+
for (let A = 0; A < t; A++) {
|
|
924
|
+
if (A === c || A === _ || A === y)
|
|
925
|
+
continue;
|
|
926
|
+
const g = s[A * 4], x = s[A * 4 + 1], k = s[A * 4 + 2];
|
|
927
|
+
let S = 0;
|
|
928
|
+
for (let D = 0; D < 3; D++) {
|
|
929
|
+
const C = D === 0 ? v : D === 1 ? I : M, N = D === 0 ? I : D === 1 ? M : v, z = s[N * 4] - s[C * 4], P = s[N * 4 + 1] - s[C * 4 + 1], E = s[N * 4 + 2] - s[C * 4 + 2], B = g - s[C * 4], T = x - s[C * 4 + 1], V = k - s[C * 4 + 2], L = n * (P * V - E * T) + i * (E * B - z * V) + o * (z * T - P * B);
|
|
930
|
+
S = -L > S ? -L : S;
|
|
931
|
+
}
|
|
932
|
+
S > p && (p = S, b = A);
|
|
933
|
+
}
|
|
934
|
+
for (let A = 0; A < 4; A++) {
|
|
935
|
+
const g = A === 0 ? c : A === 1 ? _ : A === 2 ? y : b;
|
|
936
|
+
(A === 0 || A === 1 && g !== c || A === 2 && g !== c && g !== _ || A === 3 && g >= 0) && (r[0] = s[g * 4], r[1] = s[g * 4 + 1], r[2] = s[g * 4 + 2], r[6] = s[g * 4 + 3], this._push());
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
// ---------------------------------------------------------------- planes and meshes
|
|
940
|
+
_plane(t, s, e, n) {
|
|
941
|
+
const i = t.planeNormal[0], o = t.planeNormal[1], r = t.planeNormal[2], c = s[3] * i + s[4] * o + s[5] * r, a = s[6] * i + s[7] * o + s[8] * r, l = s[9] * i + s[10] * o + s[11] * r, h = t.planeOffset + c * s[0] + a * s[1] + l * s[2], _ = this.margin;
|
|
942
|
+
if (e.kind === ut || e.kind === pt) {
|
|
943
|
+
this._loadSegment(e, n);
|
|
944
|
+
const w = this._s, v = this._q, I = e.radius;
|
|
945
|
+
for (let M = 0; M < (e.kind === ut ? 1 : 2); M++) {
|
|
946
|
+
const b = w[M * 3], A = w[M * 3 + 1], g = w[M * 3 + 2], x = c * b + a * A + l * g - h - I;
|
|
947
|
+
if (x <= _) {
|
|
948
|
+
const k = I + x / 2;
|
|
949
|
+
v[0] = b - c * k, v[1] = A - a * k, v[2] = g - l * k, v[3] = c, v[4] = a, v[5] = l, v[6] = x, this._push();
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
return;
|
|
953
|
+
}
|
|
954
|
+
if (e.kind !== Q)
|
|
955
|
+
return;
|
|
956
|
+
const p = this._hullB;
|
|
957
|
+
p.fill(e.hull, n);
|
|
958
|
+
const m = this._reserveCandidates(p.vertexCount);
|
|
959
|
+
let u = 0;
|
|
960
|
+
const f = p.vertices;
|
|
961
|
+
for (let w = 0; w < p.vertexCount; w++) {
|
|
962
|
+
const v = f[w * 3], I = f[w * 3 + 1], M = f[w * 3 + 2], b = c * v + a * I + l * M - h;
|
|
963
|
+
b <= _ && (m[u * 4] = v - c * b / 2, m[u * 4 + 1] = I - a * b / 2, m[u * 4 + 2] = M - l * b / 2, m[u * 4 + 3] = b, u++);
|
|
964
|
+
}
|
|
965
|
+
const y = this._normal;
|
|
966
|
+
y[0] = c, y[1] = a, y[2] = l, this._pushReduced(u);
|
|
967
|
+
}
|
|
968
|
+
/** Triangles of a static mesh against a convex leaf; triangles act as the first collider. */
|
|
969
|
+
_mesh(t, s, e, n) {
|
|
970
|
+
const i = this._meshMin, o = this._meshMax, r = e.min, c = e.max;
|
|
971
|
+
for (let v = 0; v < 3; v++) {
|
|
972
|
+
let I = n[v], M = 0;
|
|
973
|
+
for (let b = 0; b < 3; b++) {
|
|
974
|
+
const A = n[3 + v * 3 + b];
|
|
975
|
+
I += A * (r[b] + c[b]) / 2, M += Math.abs(A) * (c[b] - r[b]) / 2;
|
|
976
|
+
}
|
|
977
|
+
i[v] = I, o[v] = M + this.margin;
|
|
978
|
+
}
|
|
979
|
+
const a = i[0] - s[0], l = i[1] - s[1], h = i[2] - s[2], _ = o[0], p = o[1], m = o[2];
|
|
980
|
+
for (let v = 0; v < 3; v++) {
|
|
981
|
+
const I = s[3 + v], M = s[6 + v], b = s[9 + v], A = I * a + M * l + b * h, g = Math.abs(I) * _ + Math.abs(M) * p + Math.abs(b) * m;
|
|
982
|
+
i[v] = A - g, o[v] = A + g;
|
|
983
|
+
}
|
|
984
|
+
const u = e.kind !== Q;
|
|
985
|
+
u ? (this._loadSegment(e, n), this._radius = e.radius) : this._hullB.fill(e.hull, n);
|
|
986
|
+
const f = t.nodeBounds, y = this._stack;
|
|
987
|
+
let w = 0;
|
|
988
|
+
for (y[w++] = 0; w > 0; ) {
|
|
989
|
+
const v = y[--w], I = v * 6;
|
|
990
|
+
if (f[I] > o[0] || f[I + 3] < i[0] || f[I + 1] > o[1] || f[I + 4] < i[1] || f[I + 2] > o[2] || f[I + 5] < i[2])
|
|
991
|
+
continue;
|
|
992
|
+
const M = t.nodeCount[v];
|
|
993
|
+
if (M === 0) {
|
|
994
|
+
if (w + 2 > y.length)
|
|
995
|
+
throw new F("invalid-option", "[Nova3D] Triangle mesh tree is too deep.");
|
|
996
|
+
y[w++] = v + 1, y[w++] = t.nodeStart[v];
|
|
997
|
+
continue;
|
|
998
|
+
}
|
|
999
|
+
const b = t.nodeStart[v];
|
|
1000
|
+
for (let A = 0; A < M; A++)
|
|
1001
|
+
this._hullA.fillTriangle(t, t.order[b + A], s) && (u ? this._hullSegment(this._hullA) : this._hullHull(this._hullA, this._hullB));
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
function bt(d, t) {
|
|
1006
|
+
const s = d.vertices, e = t[0], n = t[1], i = t[2];
|
|
1007
|
+
let o = 1 / 0, r = -1 / 0;
|
|
1008
|
+
for (let c = 0; c < d.vertexCount * 3; c += 3) {
|
|
1009
|
+
const a = e * s[c] + n * s[c + 1] + i * s[c + 2];
|
|
1010
|
+
o = a < o ? a : o, r = a > r ? a : r;
|
|
1011
|
+
}
|
|
1012
|
+
d.low = o, d.high = r;
|
|
1013
|
+
}
|
|
1014
|
+
function Gt(d, t, s, e) {
|
|
1015
|
+
const n = d.vertices, i = e ? -1 : 1, o = s[0] * i, r = s[1] * i, c = s[2] * i;
|
|
1016
|
+
let a = -1 / 0, l = 0;
|
|
1017
|
+
for (let h = 0; h < d.edgeCount; h++) {
|
|
1018
|
+
if (d.edgeDirOf[h] !== t)
|
|
1019
|
+
continue;
|
|
1020
|
+
const _ = d.edges[h * 2] * 3, p = d.edges[h * 2 + 1] * 3, m = o * (n[_] + n[p]) + r * (n[_ + 1] + n[p + 1]) + c * (n[_ + 2] + n[p + 2]);
|
|
1021
|
+
m > a && (a = m, l = h);
|
|
1022
|
+
}
|
|
1023
|
+
return l;
|
|
1024
|
+
}
|
|
1025
|
+
function Cs(d, t, s, e) {
|
|
1026
|
+
const n = e[0], i = e[1], o = e[2], r = e[3];
|
|
1027
|
+
let c = 0;
|
|
1028
|
+
for (let a = 0; a < t; a++) {
|
|
1029
|
+
const l = a * 3, h = (a + 1) % t * 3, _ = n * d[l] + i * d[l + 1] + o * d[l + 2] - r, p = n * d[h] + i * d[h + 1] + o * d[h + 2] - r;
|
|
1030
|
+
if (_ <= 0 && (s[c * 3] = d[l], s[c * 3 + 1] = d[l + 1], s[c * 3 + 2] = d[l + 2], c++), _ < 0 && p > 0 || _ > 0 && p < 0) {
|
|
1031
|
+
const m = _ / (_ - p);
|
|
1032
|
+
s[c * 3] = d[l] + (d[h] - d[l]) * m, s[c * 3 + 1] = d[l + 1] + (d[h + 1] - d[l + 1]) * m, s[c * 3 + 2] = d[l + 2] + (d[h + 2] - d[l + 2]) * m, c++;
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
return c;
|
|
1036
|
+
}
|
|
1037
|
+
const W = 2 ** 20, Wt = 1023, rt = 0, O = 1, R = 2, X = 3, Bs = ["static", "static", "dynamic", "kinematic"], zs = ["sphere", "box", "capsule", "cylinder", "plane", "convex-hull", "triangle-mesh", "compound"], Ps = ["sphere", "box", "capsule", "cylinder", "convex-hull", "compound"], Ts = ["fixed", "ball", "hinge", "distance"], _t = 1e30;
|
|
1038
|
+
function St(d, t) {
|
|
1039
|
+
if (typeof d != "number" || !Number.isFinite(d))
|
|
1040
|
+
throw new F("invalid-option", `[Nova3D] Physics ${t} must be a finite number.`);
|
|
1041
|
+
return d;
|
|
1042
|
+
}
|
|
1043
|
+
function Y(d, t) {
|
|
1044
|
+
const s = St(d, t);
|
|
1045
|
+
if (s < 0)
|
|
1046
|
+
throw new F("invalid-option", `[Nova3D] Physics ${t} must be nonnegative.`);
|
|
1047
|
+
return s;
|
|
1048
|
+
}
|
|
1049
|
+
function j(d, t) {
|
|
1050
|
+
if (!d || typeof d != "object" || d.length !== 3)
|
|
1051
|
+
throw new F("invalid-option", `[Nova3D] Physics ${t} must have 3 numbers.`);
|
|
1052
|
+
const s = d;
|
|
1053
|
+
if (!Number.isFinite(s[0]) || !Number.isFinite(s[1]) || !Number.isFinite(s[2]))
|
|
1054
|
+
throw new F("invalid-option", `[Nova3D] Physics ${t} must be finite.`);
|
|
1055
|
+
return s;
|
|
1056
|
+
}
|
|
1057
|
+
function Ft(d, t) {
|
|
1058
|
+
if (!d || typeof d != "object" || d.length !== 4)
|
|
1059
|
+
throw new F("invalid-option", `[Nova3D] Physics ${t} must have 4 numbers.`);
|
|
1060
|
+
const s = d;
|
|
1061
|
+
if (!Number.isFinite(s[0]) || !Number.isFinite(s[1]) || !Number.isFinite(s[2]) || !Number.isFinite(s[3]) || !(Math.hypot(s[0], s[1], s[2], s[3]) > 1e-12))
|
|
1062
|
+
throw new F("invalid-option", `[Nova3D] Physics ${t} must be finite and nonzero.`);
|
|
1063
|
+
return s;
|
|
1064
|
+
}
|
|
1065
|
+
function et(d, t, s, e, n) {
|
|
1066
|
+
const i = d ?? t;
|
|
1067
|
+
if (typeof i != "number" || !Number.isFinite(i) || i < s || i > e)
|
|
1068
|
+
throw new F("invalid-option", `[Nova3D] Basic physics ${n} must be within [${s}, ${e}].`);
|
|
1069
|
+
return i;
|
|
1070
|
+
}
|
|
1071
|
+
function q(d, t) {
|
|
1072
|
+
if (d.length >= t)
|
|
1073
|
+
return d;
|
|
1074
|
+
const s = new d.constructor(Math.max(t, d.length * 2));
|
|
1075
|
+
return s.set(d), s;
|
|
1076
|
+
}
|
|
1077
|
+
class Xt {
|
|
1078
|
+
count = 0;
|
|
1079
|
+
capacity = 0;
|
|
1080
|
+
bodyA = new Int32Array(0);
|
|
1081
|
+
bodyB = new Int32Array(0);
|
|
1082
|
+
/** Sensor pairs are reported, never solved. */
|
|
1083
|
+
solve = new Uint8Array(0);
|
|
1084
|
+
point = new Float64Array(0);
|
|
1085
|
+
normal = new Float64Array(0);
|
|
1086
|
+
tangent1 = new Float64Array(0);
|
|
1087
|
+
tangent2 = new Float64Array(0);
|
|
1088
|
+
ra = new Float64Array(0);
|
|
1089
|
+
rb = new Float64Array(0);
|
|
1090
|
+
localA = new Float64Array(0);
|
|
1091
|
+
localB = new Float64Array(0);
|
|
1092
|
+
separation = new Float64Array(0);
|
|
1093
|
+
normalImpulse = new Float64Array(0);
|
|
1094
|
+
tangentImpulse1 = new Float64Array(0);
|
|
1095
|
+
tangentImpulse2 = new Float64Array(0);
|
|
1096
|
+
biasImpulse = new Float64Array(0);
|
|
1097
|
+
maxNormalImpulse = new Float64Array(0);
|
|
1098
|
+
normalMass = new Float64Array(0);
|
|
1099
|
+
tangentMass1 = new Float64Array(0);
|
|
1100
|
+
tangentMass2 = new Float64Array(0);
|
|
1101
|
+
relativeVelocity = new Float64Array(0);
|
|
1102
|
+
friction = new Float64Array(0);
|
|
1103
|
+
restitution = new Float64Array(0);
|
|
1104
|
+
reserve(t) {
|
|
1105
|
+
if (t <= this.capacity)
|
|
1106
|
+
return;
|
|
1107
|
+
const s = Math.max(t, this.capacity * 2, 64);
|
|
1108
|
+
this.capacity = s, this.bodyA = q(this.bodyA, s), this.bodyB = q(this.bodyB, s), this.solve = q(this.solve, s);
|
|
1109
|
+
for (const e of ["point", "normal", "tangent1", "tangent2", "ra", "rb", "localA", "localB"])
|
|
1110
|
+
this[e] = q(this[e], s * 3);
|
|
1111
|
+
for (const e of ["separation", "normalImpulse", "tangentImpulse1", "tangentImpulse2", "biasImpulse", "maxNormalImpulse", "normalMass", "tangentMass1", "tangentMass2", "relativeVelocity", "friction", "restitution"])
|
|
1112
|
+
this[e] = q(this[e], s);
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
class qs {
|
|
1116
|
+
size = 0;
|
|
1117
|
+
_slots = Array.from({ length: 64 }).fill(null);
|
|
1118
|
+
_mask = 63;
|
|
1119
|
+
get(t, s) {
|
|
1120
|
+
let e = (Math.imul(t, -1640531535) ^ Math.imul(s, -2048144777)) & this._mask;
|
|
1121
|
+
for (; ; ) {
|
|
1122
|
+
const n = this._slots[e];
|
|
1123
|
+
if (n === null || n.a === t && n.b === s)
|
|
1124
|
+
return n;
|
|
1125
|
+
e = e + 1 & this._mask;
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
add(t) {
|
|
1129
|
+
if ((this.size + 1) * 2 > this._slots.length) {
|
|
1130
|
+
const e = this._slots;
|
|
1131
|
+
this._slots = Array.from({ length: e.length * 2 }).fill(null), this._mask = this._slots.length - 1, this.size = 0;
|
|
1132
|
+
for (const n of e)
|
|
1133
|
+
n && this.add(n);
|
|
1134
|
+
}
|
|
1135
|
+
let s = (Math.imul(t.a, -1640531535) ^ Math.imul(t.b, -2048144777)) & this._mask;
|
|
1136
|
+
for (; this._slots[s] !== null; )
|
|
1137
|
+
s = s + 1 & this._mask;
|
|
1138
|
+
this._slots[s] = t, this.size++;
|
|
1139
|
+
}
|
|
1140
|
+
/** Removes with backward-shift deletion, so probes never meet tombstones. */
|
|
1141
|
+
delete(t) {
|
|
1142
|
+
const s = this._mask;
|
|
1143
|
+
let e = (Math.imul(t.a, -1640531535) ^ Math.imul(t.b, -2048144777)) & s;
|
|
1144
|
+
for (; this._slots[e] !== t; ) {
|
|
1145
|
+
if (this._slots[e] === null)
|
|
1146
|
+
return;
|
|
1147
|
+
e = e + 1 & s;
|
|
1148
|
+
}
|
|
1149
|
+
this._slots[e] = null, this.size--;
|
|
1150
|
+
let n = e + 1 & s;
|
|
1151
|
+
for (; this._slots[n] !== null; ) {
|
|
1152
|
+
const i = this._slots[n], o = (Math.imul(i.a, -1640531535) ^ Math.imul(i.b, -2048144777)) & s;
|
|
1153
|
+
(e <= n ? o > e && o <= n : o > e || o <= n) || (this._slots[e] = i, this._slots[n] = null, e = n), n = n + 1 & s;
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
clear() {
|
|
1157
|
+
this._slots.fill(null), this.size = 0;
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
class Ls {
|
|
1161
|
+
a = 0;
|
|
1162
|
+
b = 0;
|
|
1163
|
+
/** Position in the world's pair list. */
|
|
1164
|
+
index = 0;
|
|
1165
|
+
/** Touching state computed this step, reported after the solve. */
|
|
1166
|
+
next = !1;
|
|
1167
|
+
start = 0;
|
|
1168
|
+
count = 0;
|
|
1169
|
+
previousStart = 0;
|
|
1170
|
+
previousCount = 0;
|
|
1171
|
+
stamp = 0;
|
|
1172
|
+
touching = !1;
|
|
1173
|
+
sensor = !1;
|
|
1174
|
+
impulse = 0;
|
|
1175
|
+
point = new Float64Array(3);
|
|
1176
|
+
normal = new Float64Array(3);
|
|
1177
|
+
}
|
|
1178
|
+
class Es {
|
|
1179
|
+
type = 0;
|
|
1180
|
+
a = 0;
|
|
1181
|
+
b = 0;
|
|
1182
|
+
generation = 1;
|
|
1183
|
+
alive = !1;
|
|
1184
|
+
collide = !1;
|
|
1185
|
+
localA = new Float64Array(3);
|
|
1186
|
+
localB = new Float64Array(3);
|
|
1187
|
+
axisA = new Float64Array(3);
|
|
1188
|
+
axisB = new Float64Array(3);
|
|
1189
|
+
referenceA = new Float64Array(3);
|
|
1190
|
+
referenceB = new Float64Array(3);
|
|
1191
|
+
/** Fixed joints: conj(qA)·qB at creation. */
|
|
1192
|
+
relative = new Float64Array(4);
|
|
1193
|
+
hasLimits = !1;
|
|
1194
|
+
lower = 0;
|
|
1195
|
+
upper = 0;
|
|
1196
|
+
hasMotor = !1;
|
|
1197
|
+
motorSpeed = 0;
|
|
1198
|
+
motorForce = 0;
|
|
1199
|
+
minDistance = 0;
|
|
1200
|
+
maxDistance = 0;
|
|
1201
|
+
// Solver scratch.
|
|
1202
|
+
ra = new Float64Array(3);
|
|
1203
|
+
rb = new Float64Array(3);
|
|
1204
|
+
pointMass = new Float64Array(9);
|
|
1205
|
+
pointBias = new Float64Array(3);
|
|
1206
|
+
pointImpulse = new Float64Array(3);
|
|
1207
|
+
angularMass = new Float64Array(9);
|
|
1208
|
+
angularBias = new Float64Array(3);
|
|
1209
|
+
angularImpulse = new Float64Array(3);
|
|
1210
|
+
/** Hinge rows: two perpendicular axes, then the hinge axis. */
|
|
1211
|
+
rows = new Float64Array(9);
|
|
1212
|
+
rowMass = new Float64Array(3);
|
|
1213
|
+
rowBias = new Float64Array(3);
|
|
1214
|
+
rowImpulse = new Float64Array(3);
|
|
1215
|
+
angle = 0;
|
|
1216
|
+
lowerImpulse = 0;
|
|
1217
|
+
upperImpulse = 0;
|
|
1218
|
+
motorImpulse = 0;
|
|
1219
|
+
lowerBias = 0;
|
|
1220
|
+
upperBias = 0;
|
|
1221
|
+
direction = new Float64Array(3);
|
|
1222
|
+
length = 0;
|
|
1223
|
+
}
|
|
1224
|
+
const Vs = { fixed: 1, ball: 2, hinge: 3, distance: 4 }, xt = 1, At = 3, yt = 4;
|
|
1225
|
+
class Rs {
|
|
1226
|
+
constructor(t, s, e) {
|
|
1227
|
+
if (this.backend = t, !s || typeof s != "object")
|
|
1228
|
+
throw new F("invalid-option", "[Nova3D] Physics world description is required.");
|
|
1229
|
+
this._gravity.set(j(s.gravity, "gravity")), this._contactStay = s.contactStay ?? !1, this._iterations = e.velocityIterations, this._beta = e.positionCorrection, this._slop = e.linearSlop, this._speculative = e.speculativeDistance, this._restitutionThreshold = e.restitutionThreshold, this._sleepLinear = e.sleepLinearVelocity, this._sleepAngular = e.sleepAngularVelocity, this._timeToSleep = e.timeToSleep, this._narrowphase.margin = this._speculative, this._reserveBodies(16), this._generation[0] = 1, this._type[0] = O, this._orientation[3] = 1, this._rotation[0] = this._rotation[4] = this._rotation[8] = 1, this._shapes[0] = null, this._joints[0] = null, this._bodyCount = 0;
|
|
1230
|
+
}
|
|
1231
|
+
_destroyed = !1;
|
|
1232
|
+
_gravity = new Float64Array(3);
|
|
1233
|
+
_contactStay;
|
|
1234
|
+
_iterations;
|
|
1235
|
+
_beta;
|
|
1236
|
+
_slop;
|
|
1237
|
+
_speculative;
|
|
1238
|
+
_restitutionThreshold;
|
|
1239
|
+
_sleepLinear;
|
|
1240
|
+
_sleepAngular;
|
|
1241
|
+
_timeToSleep;
|
|
1242
|
+
// Bodies.
|
|
1243
|
+
_capacity = 0;
|
|
1244
|
+
_generation = new Uint32Array(0);
|
|
1245
|
+
_type = new Uint8Array(0);
|
|
1246
|
+
_awake = new Uint8Array(0);
|
|
1247
|
+
_canSleep = new Uint8Array(0);
|
|
1248
|
+
_sensor = new Uint8Array(0);
|
|
1249
|
+
_hasTarget = new Uint8Array(0);
|
|
1250
|
+
_group = new Uint32Array(0);
|
|
1251
|
+
_mask = new Uint32Array(0);
|
|
1252
|
+
_position = new Float64Array(0);
|
|
1253
|
+
_orientation = new Float64Array(0);
|
|
1254
|
+
_rotation = new Float64Array(0);
|
|
1255
|
+
_linear = new Float64Array(0);
|
|
1256
|
+
_angular = new Float64Array(0);
|
|
1257
|
+
_biasLinear = new Float64Array(0);
|
|
1258
|
+
_biasAngular = new Float64Array(0);
|
|
1259
|
+
_force = new Float64Array(0);
|
|
1260
|
+
_torque = new Float64Array(0);
|
|
1261
|
+
_target = new Float64Array(0);
|
|
1262
|
+
_mass = new Float64Array(0);
|
|
1263
|
+
_inverseMass = new Float64Array(0);
|
|
1264
|
+
_localInverseInertia = new Float64Array(0);
|
|
1265
|
+
_inverseInertia = new Float64Array(0);
|
|
1266
|
+
_linearDamping = new Float64Array(0);
|
|
1267
|
+
_angularDamping = new Float64Array(0);
|
|
1268
|
+
_friction = new Float64Array(0);
|
|
1269
|
+
_restitution = new Float64Array(0);
|
|
1270
|
+
_gravityScale = new Float64Array(0);
|
|
1271
|
+
_sleepTime = new Float64Array(0);
|
|
1272
|
+
_bounds = new Float64Array(0);
|
|
1273
|
+
_island = new Int32Array(0);
|
|
1274
|
+
_islandRest = new Float64Array(0);
|
|
1275
|
+
_shapes = [];
|
|
1276
|
+
_joints = [];
|
|
1277
|
+
_free = [];
|
|
1278
|
+
_bodyCount = 0;
|
|
1279
|
+
_order = new Int32Array(0);
|
|
1280
|
+
_orderCount = 0;
|
|
1281
|
+
// Contacts and pairs.
|
|
1282
|
+
_contacts = new Xt();
|
|
1283
|
+
_previous = new Xt();
|
|
1284
|
+
_pairs = new qs();
|
|
1285
|
+
_pairList = [];
|
|
1286
|
+
_pairPool = [];
|
|
1287
|
+
_active = [];
|
|
1288
|
+
_activeCount = 0;
|
|
1289
|
+
_stamp = 0;
|
|
1290
|
+
// Joints.
|
|
1291
|
+
_jointRecords = [];
|
|
1292
|
+
_jointFree = [];
|
|
1293
|
+
_jointCount = 0;
|
|
1294
|
+
// Events.
|
|
1295
|
+
_eventCount = 0;
|
|
1296
|
+
_eventPhase = new Uint8Array(0);
|
|
1297
|
+
_eventBodies = new Float64Array(0);
|
|
1298
|
+
_eventData = new Float64Array(0);
|
|
1299
|
+
_eventSensor = new Uint8Array(0);
|
|
1300
|
+
_event = { phase: "begin", bodyA: 0, bodyB: 0, point: new Float64Array(3), normal: new Float64Array(3), impulse: 0, sensor: !1 };
|
|
1301
|
+
// Scratch.
|
|
1302
|
+
_narrowphase = new Ns();
|
|
1303
|
+
_leafA = new Float64Array(12);
|
|
1304
|
+
_leafB = new Float64Array(12);
|
|
1305
|
+
_leafBoundsA = new Float64Array(6);
|
|
1306
|
+
_leafBoundsB = new Float64Array(6);
|
|
1307
|
+
_rayLocal = { t: 0, nx: 0, ny: 0, nz: 0 };
|
|
1308
|
+
_rayStack = new Int32Array(128);
|
|
1309
|
+
_matrix = new Float64Array(9);
|
|
1310
|
+
_inverseStep = 60;
|
|
1311
|
+
_dt = 1 / 60;
|
|
1312
|
+
/** Relative velocity written by `_velocity`. */
|
|
1313
|
+
_dv = new Float64Array(3);
|
|
1314
|
+
/** Impulse read by `_applyPairImpulse`, `_applyAngularPair` and `_applyInertia`. */
|
|
1315
|
+
_impulse = new Float64Array(3);
|
|
1316
|
+
/** Pose read by `_writePose`: position xyz, quaternion xyzw. */
|
|
1317
|
+
_pose = new Float64Array(7);
|
|
1318
|
+
_referenceA = new Float64Array(3);
|
|
1319
|
+
_referenceB = new Float64Array(3);
|
|
1320
|
+
get destroyed() {
|
|
1321
|
+
return this._destroyed;
|
|
1322
|
+
}
|
|
1323
|
+
destroy() {
|
|
1324
|
+
this._destroyed || (this._destroyed = !0, this._pairs.clear(), this._pairList.length = 0, this._pairPool.length = 0, this._active.length = 0, this._shapes = [], this._joints = [], this._jointRecords.length = 0, this._eventCount = 0);
|
|
1325
|
+
}
|
|
1326
|
+
setGravity(t) {
|
|
1327
|
+
this._assertAlive(), this._gravity.set(j(t, "gravity"));
|
|
1328
|
+
for (let s = 1; s < this._capacity; s++)
|
|
1329
|
+
this._type[s] === R && this._wakeSlot(s);
|
|
1330
|
+
}
|
|
1331
|
+
getGravity(t) {
|
|
1332
|
+
return this._assertAlive(), t[0] = this._gravity[0], t[1] = this._gravity[1], t[2] = this._gravity[2], t;
|
|
1333
|
+
}
|
|
1334
|
+
diagnostics() {
|
|
1335
|
+
let t = 0;
|
|
1336
|
+
for (let s = 1; s < this._capacity; s++)
|
|
1337
|
+
this._type[s] === R && this._awake[s] && t++;
|
|
1338
|
+
return Object.freeze({
|
|
1339
|
+
bodies: this._bodyCount,
|
|
1340
|
+
awakeBodies: t,
|
|
1341
|
+
bodyCapacity: this._capacity,
|
|
1342
|
+
joints: this._jointCount,
|
|
1343
|
+
pairs: this._pairs.size,
|
|
1344
|
+
pairPool: this._pairPool.length,
|
|
1345
|
+
contacts: this._contacts.count,
|
|
1346
|
+
contactCapacity: this._contacts.capacity + this._previous.capacity,
|
|
1347
|
+
eventCapacity: this._eventPhase.length,
|
|
1348
|
+
activeCapacity: this._active.length
|
|
1349
|
+
});
|
|
1350
|
+
}
|
|
1351
|
+
// ---------------------------------------------------------------- bodies
|
|
1352
|
+
createBody(t) {
|
|
1353
|
+
if (this._assertAlive(), !t || typeof t != "object")
|
|
1354
|
+
throw new F("invalid-option", "[Nova3D] Physics body description is required.");
|
|
1355
|
+
const s = t.type === "static" ? O : t.type === "dynamic" ? R : t.type === "kinematic" ? X : rt;
|
|
1356
|
+
if (s === rt)
|
|
1357
|
+
throw new F("invalid-option", "[Nova3D] Physics body type must be static, dynamic or kinematic.");
|
|
1358
|
+
const e = As(t.shape);
|
|
1359
|
+
if (e.staticOnly && s !== O)
|
|
1360
|
+
throw new F("invalid-option", "[Nova3D] Planes and triangle meshes need static bodies.");
|
|
1361
|
+
const n = t.mass ?? 1;
|
|
1362
|
+
if (!(typeof n == "number" && Number.isFinite(n) && n > 0))
|
|
1363
|
+
throw new F("invalid-option", "[Nova3D] Physics body mass must be positive.");
|
|
1364
|
+
const i = j(t.position ?? [0, 0, 0], "body position"), o = Ft(t.quaternion ?? [0, 0, 0, 1], "body quaternion"), r = j(t.linearVelocity ?? [0, 0, 0], "body linear velocity"), c = j(t.angularVelocity ?? [0, 0, 0], "body angular velocity"), a = Y(t.linearDamping ?? 0, "linear damping"), l = Y(t.angularDamping ?? 0, "angular damping"), h = Y(t.friction ?? 0.5, "friction"), _ = Y(t.restitution ?? 0, "restitution");
|
|
1365
|
+
if (_ > 1)
|
|
1366
|
+
throw new F("invalid-option", "[Nova3D] Physics restitution must be within [0, 1].");
|
|
1367
|
+
const p = St(t.gravityScale ?? 1, "gravity scale"), m = t.collisionGroup ?? 1, u = t.collisionMask ?? 4294967295;
|
|
1368
|
+
if (!Number.isInteger(m) || !Number.isInteger(u) || m < 0 || u < 0 || m > 4294967295 || u > 4294967295)
|
|
1369
|
+
throw new F("invalid-option", "[Nova3D] Physics collision group and mask must be 32-bit unsigned integers.");
|
|
1370
|
+
let f = this._free.pop();
|
|
1371
|
+
if (f === void 0) {
|
|
1372
|
+
for (f = this._bodyCount + 1; f < this._capacity && this._type[f] !== rt; )
|
|
1373
|
+
f++;
|
|
1374
|
+
if (f >= W)
|
|
1375
|
+
throw new F("budget", "[Nova3D] Physics world body limit reached.");
|
|
1376
|
+
this._reserveBodies(f + 1);
|
|
1377
|
+
}
|
|
1378
|
+
this._generation[f] === 0 && (this._generation[f] = 1), this._type[f] = s, this._shapes[f] = e, this._joints[f] = null, this._sensor[f] = t.sensor ? 1 : 0, this._canSleep[f] = t.canSleep === !1 ? 0 : 1, this._group[f] = m >>> 0, this._mask[f] = u >>> 0, this._mass[f] = n, this._linearDamping[f] = a, this._angularDamping[f] = l, this._friction[f] = h, this._restitution[f] = _, this._gravityScale[f] = p, this._writePoseValues(f, i, o);
|
|
1379
|
+
for (let y = 0; y < 3; y++)
|
|
1380
|
+
this._linear[f * 3 + y] = s === O ? 0 : r[y], this._angular[f * 3 + y] = s === O ? 0 : c[y], this._force[f * 3 + y] = 0, this._torque[f * 3 + y] = 0, this._biasLinear[f * 3 + y] = 0, this._biasAngular[f * 3 + y] = 0;
|
|
1381
|
+
return this._hasTarget[f] = 0, this._sleepTime[f] = 0, this._awake[f] = s === O ? 0 : 1, this._updateMass(f), this._updateBounds(f), this._narrowphase.reserve(e.maxHullVertices), this._order = q(this._order, this._orderCount + 1), this._order[this._orderCount++] = f, this._bodyCount++, this._generation[f] * W + f;
|
|
1382
|
+
}
|
|
1383
|
+
destroyBody(t) {
|
|
1384
|
+
const s = this._slot(t);
|
|
1385
|
+
for (const n of [...this._joints[s] ?? []])
|
|
1386
|
+
this._removeJoint(n);
|
|
1387
|
+
for (let n = this._pairList.length - 1; n >= 0; n--) {
|
|
1388
|
+
const i = this._pairList[n];
|
|
1389
|
+
(i.a === s || i.b === s) && (this._wakeSlot(i.a === s ? i.b : i.a), this._removePair(i));
|
|
1390
|
+
}
|
|
1391
|
+
let e = 0;
|
|
1392
|
+
for (let n = 0; n < this._orderCount; n++)
|
|
1393
|
+
this._order[n] !== s && (this._order[e++] = this._order[n]);
|
|
1394
|
+
this._orderCount = e, this._type[s] = rt, this._shapes[s] = null, this._joints[s] = null, this._awake[s] = 0, this._inverseMass[s] = 0, this._generation[s] = this._generation[s] % Wt + 1, this._free.push(s), this._bodyCount--;
|
|
1395
|
+
}
|
|
1396
|
+
hasBody(t) {
|
|
1397
|
+
return !this._destroyed && this._resolve(t) > 0;
|
|
1398
|
+
}
|
|
1399
|
+
getBodyType(t) {
|
|
1400
|
+
return Bs[this._type[this._slot(t)]];
|
|
1401
|
+
}
|
|
1402
|
+
setBodyType(t, s) {
|
|
1403
|
+
const e = this._slot(t), n = s === "static" ? O : s === "dynamic" ? R : s === "kinematic" ? X : rt;
|
|
1404
|
+
if (n === rt)
|
|
1405
|
+
throw new F("invalid-option", "[Nova3D] Physics body type must be static, dynamic or kinematic.");
|
|
1406
|
+
if (this._shapes[e].staticOnly && n !== O)
|
|
1407
|
+
throw new F("invalid-option", "[Nova3D] Planes and triangle meshes need static bodies.");
|
|
1408
|
+
this._wakeTouching(e), this._type[e] = n, this._hasTarget[e] = 0, n === O ? (this._linear.fill(0, e * 3, e * 3 + 3), this._angular.fill(0, e * 3, e * 3 + 3), this._awake[e] = 0) : (this._awake[e] = 1, this._sleepTime[e] = 0), this._updateMass(e);
|
|
1409
|
+
}
|
|
1410
|
+
setMass(t, s) {
|
|
1411
|
+
const e = this._slot(t);
|
|
1412
|
+
if (!(typeof s == "number" && Number.isFinite(s) && s > 0))
|
|
1413
|
+
throw new F("invalid-option", "[Nova3D] Physics body mass must be positive.");
|
|
1414
|
+
this._mass[e] = s, this._updateMass(e), this._wakeSlot(e);
|
|
1415
|
+
}
|
|
1416
|
+
setDamping(t, s, e) {
|
|
1417
|
+
const n = this._slot(t);
|
|
1418
|
+
this._linearDamping[n] = Y(s, "linear damping"), this._angularDamping[n] = Y(e, "angular damping");
|
|
1419
|
+
}
|
|
1420
|
+
setMaterial(t, s, e) {
|
|
1421
|
+
const n = this._slot(t);
|
|
1422
|
+
if (Y(s, "friction"), !(Y(e, "restitution") <= 1))
|
|
1423
|
+
throw new F("invalid-option", "[Nova3D] Physics restitution must be within [0, 1].");
|
|
1424
|
+
this._friction[n] = s, this._restitution[n] = e;
|
|
1425
|
+
}
|
|
1426
|
+
setGravityScale(t, s) {
|
|
1427
|
+
const e = this._slot(t);
|
|
1428
|
+
this._gravityScale[e] = St(s, "gravity scale"), this._wakeSlot(e);
|
|
1429
|
+
}
|
|
1430
|
+
setCollisionFilter(t, s, e) {
|
|
1431
|
+
const n = this._slot(t);
|
|
1432
|
+
if (!Number.isInteger(s) || !Number.isInteger(e) || s < 0 || e < 0 || s > 4294967295 || e > 4294967295)
|
|
1433
|
+
throw new F("invalid-option", "[Nova3D] Physics collision group and mask must be 32-bit unsigned integers.");
|
|
1434
|
+
this._group[n] = s >>> 0, this._mask[n] = e >>> 0, this._wakeTouching(n);
|
|
1435
|
+
}
|
|
1436
|
+
getTransform(t, s, e = 0) {
|
|
1437
|
+
const n = this._slot(t);
|
|
1438
|
+
return s[e] = this._position[n * 3], s[e + 1] = this._position[n * 3 + 1], s[e + 2] = this._position[n * 3 + 2], s[e + 3] = this._orientation[n * 4], s[e + 4] = this._orientation[n * 4 + 1], s[e + 5] = this._orientation[n * 4 + 2], s[e + 6] = this._orientation[n * 4 + 3], s;
|
|
1439
|
+
}
|
|
1440
|
+
setTransform(t, s, e) {
|
|
1441
|
+
const n = this._slot(t);
|
|
1442
|
+
j(s, "body position"), Ft(e, "body quaternion"), this._wakeTouching(n), this._writePoseValues(n, s, e), this._updateInertia(n), this._updateBounds(n), this._hasTarget[n] = 0, this._type[n] !== O && this._wakeSlot(n);
|
|
1443
|
+
}
|
|
1444
|
+
setKinematicTarget(t, s, e) {
|
|
1445
|
+
const n = this._slot(t);
|
|
1446
|
+
if (this._type[n] !== X)
|
|
1447
|
+
throw new F("invalid-option", "[Nova3D] Kinematic targets need a kinematic body.");
|
|
1448
|
+
j(s, "kinematic position"), Ft(e, "kinematic quaternion");
|
|
1449
|
+
const i = n * 7, o = Math.hypot(e[0], e[1], e[2], e[3]);
|
|
1450
|
+
this._target[i] = s[0], this._target[i + 1] = s[1], this._target[i + 2] = s[2], this._target[i + 3] = e[0] / o, this._target[i + 4] = e[1] / o, this._target[i + 5] = e[2] / o, this._target[i + 6] = e[3] / o, this._hasTarget[n] = 1;
|
|
1451
|
+
}
|
|
1452
|
+
getLinearVelocity(t, s) {
|
|
1453
|
+
const e = this._slot(t);
|
|
1454
|
+
return s[0] = this._linear[e * 3], s[1] = this._linear[e * 3 + 1], s[2] = this._linear[e * 3 + 2], s;
|
|
1455
|
+
}
|
|
1456
|
+
setLinearVelocity(t, s) {
|
|
1457
|
+
const e = this._slot(t);
|
|
1458
|
+
j(s, "linear velocity"), this._type[e] !== O && (this._linear.set(s, e * 3), this._wakeSlot(e));
|
|
1459
|
+
}
|
|
1460
|
+
getAngularVelocity(t, s) {
|
|
1461
|
+
const e = this._slot(t);
|
|
1462
|
+
return s[0] = this._angular[e * 3], s[1] = this._angular[e * 3 + 1], s[2] = this._angular[e * 3 + 2], s;
|
|
1463
|
+
}
|
|
1464
|
+
setAngularVelocity(t, s) {
|
|
1465
|
+
const e = this._slot(t);
|
|
1466
|
+
j(s, "angular velocity"), this._type[e] !== O && (this._angular.set(s, e * 3), this._wakeSlot(e));
|
|
1467
|
+
}
|
|
1468
|
+
applyForce(t, s, e) {
|
|
1469
|
+
const n = this._slot(t);
|
|
1470
|
+
if (j(s, "force"), e !== void 0 && j(e, "force point"), this._type[n] === R) {
|
|
1471
|
+
this._wakeSlot(n);
|
|
1472
|
+
for (let i = 0; i < 3; i++)
|
|
1473
|
+
this._force[n * 3 + i] += s[i];
|
|
1474
|
+
if (e) {
|
|
1475
|
+
const i = e[0] - this._position[n * 3], o = e[1] - this._position[n * 3 + 1], r = e[2] - this._position[n * 3 + 2];
|
|
1476
|
+
this._torque[n * 3] += o * s[2] - r * s[1], this._torque[n * 3 + 1] += r * s[0] - i * s[2], this._torque[n * 3 + 2] += i * s[1] - o * s[0];
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
applyImpulse(t, s, e) {
|
|
1481
|
+
const n = this._slot(t);
|
|
1482
|
+
if (j(s, "impulse"), e !== void 0 && j(e, "impulse point"), this._type[n] !== R)
|
|
1483
|
+
return;
|
|
1484
|
+
this._wakeSlot(n);
|
|
1485
|
+
const i = this._inverseMass[n];
|
|
1486
|
+
for (let o = 0; o < 3; o++)
|
|
1487
|
+
this._linear[n * 3 + o] += s[o] * i;
|
|
1488
|
+
if (e) {
|
|
1489
|
+
const o = e[0] - this._position[n * 3], r = e[1] - this._position[n * 3 + 1], c = e[2] - this._position[n * 3 + 2];
|
|
1490
|
+
this._impulse[0] = r * s[2] - c * s[1], this._impulse[1] = c * s[0] - o * s[2], this._impulse[2] = o * s[1] - r * s[0], this._applyInertia(n, 1);
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
applyTorque(t, s) {
|
|
1494
|
+
const e = this._slot(t);
|
|
1495
|
+
if (j(s, "torque"), this._type[e] === R) {
|
|
1496
|
+
this._wakeSlot(e);
|
|
1497
|
+
for (let n = 0; n < 3; n++)
|
|
1498
|
+
this._torque[e * 3 + n] += s[n];
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
applyTorqueImpulse(t, s) {
|
|
1502
|
+
const e = this._slot(t);
|
|
1503
|
+
j(s, "torque impulse"), this._type[e] === R && (this._wakeSlot(e), this._impulse.set(s), this._applyInertia(e, 1));
|
|
1504
|
+
}
|
|
1505
|
+
getSleeping(t) {
|
|
1506
|
+
const s = this._slot(t);
|
|
1507
|
+
return this._type[s] === R && !this._awake[s];
|
|
1508
|
+
}
|
|
1509
|
+
wake(t) {
|
|
1510
|
+
this._wakeSlot(this._slot(t));
|
|
1511
|
+
}
|
|
1512
|
+
// ---------------------------------------------------------------- joints
|
|
1513
|
+
createJoint(t) {
|
|
1514
|
+
if (this._assertAlive(), !t || typeof t != "object")
|
|
1515
|
+
throw new F("invalid-option", "[Nova3D] Physics joint description is required.");
|
|
1516
|
+
const s = Vs[t.type];
|
|
1517
|
+
if (!s)
|
|
1518
|
+
throw new F("unsupported", `[Nova3D] The basic physics backend does not support ${String(t.type)} joints.`);
|
|
1519
|
+
const e = this._slot(t.bodyA), n = t.bodyB === null ? 0 : this._slot(t.bodyB);
|
|
1520
|
+
if (e === n)
|
|
1521
|
+
throw new F("invalid-option", "[Nova3D] A joint needs two different bodies.");
|
|
1522
|
+
let i = this._jointFree.pop();
|
|
1523
|
+
i === void 0 && (i = this._jointRecords.length, this._jointRecords.push(new Es()));
|
|
1524
|
+
const o = this._jointRecords[i];
|
|
1525
|
+
if (o.type = s, o.a = e, o.b = n, o.collide = t.collideConnected ?? !1, o.localA.set(j(t.anchorA ?? [0, 0, 0], "joint anchorA")), o.localB.set(j(t.anchorB ?? [0, 0, 0], "joint anchorB")), o.pointImpulse.fill(0), o.angularImpulse.fill(0), o.rowImpulse.fill(0), o.lowerImpulse = 0, o.upperImpulse = 0, o.motorImpulse = 0, o.hasLimits = !1, o.hasMotor = !1, Nt(o.relative, 0, this._orientation, e * 4, !0, this._orientation, n * 4, !1), t.type === "hinge") {
|
|
1526
|
+
const r = Yt(j(t.axisA, "hinge axisA"), "hinge axisA"), c = Yt(j(t.axisB, "hinge axisB"), "hinge axisB");
|
|
1527
|
+
o.axisA.set(r), o.axisB.set(c);
|
|
1528
|
+
const a = Math.abs(r[0]) < 0.9 ? 1 : 0, l = a ? 0 : 1;
|
|
1529
|
+
let h = r[1] * 0 - r[2] * l, _ = r[2] * a - r[0] * 0, p = r[0] * l - r[1] * a;
|
|
1530
|
+
const m = Math.hypot(h, _, p);
|
|
1531
|
+
h /= m, _ /= m, p /= m, o.referenceA.set([h, _, p]);
|
|
1532
|
+
const u = this._rotation, f = u[e * 9] * h + u[e * 9 + 1] * _ + u[e * 9 + 2] * p, y = u[e * 9 + 3] * h + u[e * 9 + 4] * _ + u[e * 9 + 5] * p, w = u[e * 9 + 6] * h + u[e * 9 + 7] * _ + u[e * 9 + 8] * p;
|
|
1533
|
+
if (o.referenceB[0] = u[n * 9] * f + u[n * 9 + 3] * y + u[n * 9 + 6] * w, o.referenceB[1] = u[n * 9 + 1] * f + u[n * 9 + 4] * y + u[n * 9 + 7] * w, o.referenceB[2] = u[n * 9 + 2] * f + u[n * 9 + 5] * y + u[n * 9 + 8] * w, t.limits !== void 0) {
|
|
1534
|
+
const [v, I] = t.limits;
|
|
1535
|
+
if (!(Number.isFinite(v) && Number.isFinite(I) && v <= I))
|
|
1536
|
+
throw new F("invalid-option", "[Nova3D] Hinge limits must be finite with lower ≤ upper.");
|
|
1537
|
+
o.hasLimits = !0, o.lower = v, o.upper = I;
|
|
1538
|
+
}
|
|
1539
|
+
this._writeMotor(o, t.motor ?? null);
|
|
1540
|
+
} else if (t.type === "distance") {
|
|
1541
|
+
const r = Y(t.minDistance, "joint minDistance"), c = Y(t.maxDistance, "joint maxDistance");
|
|
1542
|
+
if (r > c)
|
|
1543
|
+
throw new F("invalid-option", "[Nova3D] Distance joint minDistance must not exceed maxDistance.");
|
|
1544
|
+
o.minDistance = r, o.maxDistance = c;
|
|
1545
|
+
}
|
|
1546
|
+
o.alive = !0;
|
|
1547
|
+
for (const r of [e, n])
|
|
1548
|
+
if (r > 0) {
|
|
1549
|
+
const c = this._joints[r] ?? [];
|
|
1550
|
+
c.push(o), this._joints[r] = c;
|
|
1551
|
+
}
|
|
1552
|
+
if (this._jointCount++, this._wakeSlot(e), this._wakeSlot(n), !o.collide)
|
|
1553
|
+
for (let r = this._pairList.length - 1; r >= 0; r--) {
|
|
1554
|
+
const c = this._pairList[r];
|
|
1555
|
+
(c.a === e && c.b === n || c.a === n && c.b === e) && this._removePair(c);
|
|
1556
|
+
}
|
|
1557
|
+
return o.generation * W + i;
|
|
1558
|
+
}
|
|
1559
|
+
destroyJoint(t) {
|
|
1560
|
+
this._removeJoint(this._joint(t));
|
|
1561
|
+
}
|
|
1562
|
+
setJointMotor(t, s) {
|
|
1563
|
+
const e = this._joint(t);
|
|
1564
|
+
if (e.type !== At)
|
|
1565
|
+
throw new F("invalid-option", "[Nova3D] Motors need a hinge joint in the basic physics backend.");
|
|
1566
|
+
this._writeMotor(e, s), this._wakeSlot(e.a), this._wakeSlot(e.b);
|
|
1567
|
+
}
|
|
1568
|
+
// ---------------------------------------------------------------- queries
|
|
1569
|
+
raycast(t, s, e, n, i) {
|
|
1570
|
+
this._assertAlive(), j(t, "ray origin"), j(s, "ray direction");
|
|
1571
|
+
const o = Math.hypot(s[0], s[1], s[2]);
|
|
1572
|
+
if (!(o > 1e-12))
|
|
1573
|
+
throw new F("invalid-option", "[Nova3D] Ray direction must be nonzero.");
|
|
1574
|
+
if (!(e >= 0))
|
|
1575
|
+
throw new F("invalid-option", "[Nova3D] Ray maxDistance must be nonnegative.");
|
|
1576
|
+
const r = t[0], c = t[1], a = t[2], l = s[0] / o, h = s[1] / o, _ = s[2] / o;
|
|
1577
|
+
let p = e, m = !1;
|
|
1578
|
+
const u = this._rayLocal;
|
|
1579
|
+
for (let f = 0; f < this._orderCount; f++) {
|
|
1580
|
+
const y = this._order[f];
|
|
1581
|
+
if (!(this._sensor[y] || (this._group[y] & n) === 0) && Zt(this._bounds, y * 6, r, c, a, l, h, _, p))
|
|
1582
|
+
for (const w of this._shapes[y].leaves) {
|
|
1583
|
+
const v = this._leafA;
|
|
1584
|
+
this._leafTransform(y, w, v);
|
|
1585
|
+
const I = r - v[0], M = c - v[1], b = a - v[2], A = v[3] * I + v[6] * M + v[9] * b, g = v[4] * I + v[7] * M + v[10] * b, x = v[5] * I + v[8] * M + v[11] * b, k = v[3] * l + v[6] * h + v[9] * _, S = v[4] * l + v[7] * h + v[10] * _, D = v[5] * l + v[8] * h + v[11] * _;
|
|
1586
|
+
if (!this._rayLeaf(w, A, g, x, k, S, D, p, u) || u.t > p)
|
|
1587
|
+
continue;
|
|
1588
|
+
p = u.t, m = !0, i.body = this._generation[y] * W + y, i.distance = u.t, i.point[0] = r + l * u.t, i.point[1] = c + h * u.t, i.point[2] = a + _ * u.t;
|
|
1589
|
+
const C = v[3] * u.nx + v[4] * u.ny + v[5] * u.nz, N = v[6] * u.nx + v[7] * u.ny + v[8] * u.nz, z = v[9] * u.nx + v[10] * u.ny + v[11] * u.nz, P = Math.hypot(C, N, z) || 1;
|
|
1590
|
+
i.normal[0] = C / P, i.normal[1] = N / P, i.normal[2] = z / P;
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1593
|
+
return m;
|
|
1594
|
+
}
|
|
1595
|
+
drainContacts(t) {
|
|
1596
|
+
this._assertAlive();
|
|
1597
|
+
const s = this._event, e = this._eventCount;
|
|
1598
|
+
this._eventCount = 0;
|
|
1599
|
+
for (let n = 0; n < e; n++) {
|
|
1600
|
+
const i = this._eventPhase[n];
|
|
1601
|
+
s.phase = i === 0 ? "begin" : i === 1 ? "stay" : "end", s.bodyA = this._eventBodies[n * 2], s.bodyB = this._eventBodies[n * 2 + 1];
|
|
1602
|
+
for (let o = 0; o < 3; o++)
|
|
1603
|
+
s.point[o] = this._eventData[n * 7 + o], s.normal[o] = this._eventData[n * 7 + 3 + o];
|
|
1604
|
+
s.impulse = this._eventData[n * 7 + 6], s.sensor = this._eventSensor[n] === 1, t(s);
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
// ---------------------------------------------------------------- step
|
|
1608
|
+
//
|
|
1609
|
+
// Every helper below takes only integers, arrays and objects and exchanges numbers
|
|
1610
|
+
// through typed-array scratch (`_dv`, `_impulse`, `_pose`) or fields: optimized code
|
|
1611
|
+
// then never boxes a double, so a warmed-up step allocates nothing.
|
|
1612
|
+
step(t) {
|
|
1613
|
+
if (this._assertAlive(), !(typeof t == "number" && Number.isFinite(t) && t > 0))
|
|
1614
|
+
throw new F("invalid-option", "[Nova3D] Physics step must be a positive finite number of seconds.");
|
|
1615
|
+
this._dt = t, this._inverseStep = 1 / t, this._eventCount = 0, this._stamp++, this._prepareKinematic();
|
|
1616
|
+
for (let s = 0; s < this._orderCount; s++) {
|
|
1617
|
+
const e = this._order[s];
|
|
1618
|
+
this._type[e] !== O && (this._awake[e] || this._type[e] === X) && this._updateBounds(e);
|
|
1619
|
+
}
|
|
1620
|
+
this._collide(), this._prepareContacts(), this._prepareJoints(), this._integrateVelocities(), this._warmStart();
|
|
1621
|
+
for (let s = 0; s < this._iterations; s++)
|
|
1622
|
+
this._solveJoints(), this._solveContacts();
|
|
1623
|
+
this._applyRestitution(), this._integratePositions(), this._updateSleep(), this._reportContacts();
|
|
1624
|
+
}
|
|
1625
|
+
_prepareKinematic() {
|
|
1626
|
+
const t = this._inverseStep, s = this._target, e = this._orientation;
|
|
1627
|
+
for (let n = 0; n < this._orderCount; n++) {
|
|
1628
|
+
const i = this._order[n];
|
|
1629
|
+
if (this._type[i] !== X || !this._hasTarget[i])
|
|
1630
|
+
continue;
|
|
1631
|
+
const o = i * 7;
|
|
1632
|
+
for (let b = 0; b < 3; b++)
|
|
1633
|
+
this._linear[i * 3 + b] = (s[o + b] - this._position[i * 3 + b]) * t;
|
|
1634
|
+
const r = i * 4, c = s[o + 3], a = s[o + 4], l = s[o + 5], h = s[o + 6], _ = -e[r], p = -e[r + 1], m = -e[r + 2], u = e[r + 3];
|
|
1635
|
+
let f = h * _ + c * u + a * m - l * p, y = h * p - c * m + a * u + l * _, w = h * m + c * p - a * _ + l * u, v = h * u - c * _ - a * p - l * m;
|
|
1636
|
+
v < 0 && (f = -f, y = -y, w = -w, v = -v);
|
|
1637
|
+
const I = Math.sqrt(f * f + y * y + w * w), M = I > 1e-12 ? 2 * Math.atan2(I, v) / I * t : 2 * t;
|
|
1638
|
+
this._angular[i * 3] = f * M, this._angular[i * 3 + 1] = y * M, this._angular[i * 3 + 2] = w * M;
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
/** Sweep-and-prune on x, narrowphase, pair bookkeeping and contact matching. */
|
|
1642
|
+
_collide() {
|
|
1643
|
+
const t = this._previous;
|
|
1644
|
+
this._previous = this._contacts, this._contacts = t, this._contacts.count = 0;
|
|
1645
|
+
for (let n = 0; n < this._pairList.length; n++) {
|
|
1646
|
+
const i = this._pairList[n];
|
|
1647
|
+
i.previousStart = i.start, i.previousCount = i.count, i.count = 0;
|
|
1648
|
+
}
|
|
1649
|
+
const s = this._order, e = this._bounds;
|
|
1650
|
+
for (let n = 1; n < this._orderCount; n++) {
|
|
1651
|
+
const i = s[n], o = e[i * 6];
|
|
1652
|
+
let r = n - 1;
|
|
1653
|
+
for (; r >= 0 && e[s[r] * 6] > o; )
|
|
1654
|
+
s[r + 1] = s[r], r--;
|
|
1655
|
+
s[r + 1] = i;
|
|
1656
|
+
}
|
|
1657
|
+
this._activeCount = 0;
|
|
1658
|
+
for (let n = 0; n < this._orderCount; n++) {
|
|
1659
|
+
const i = s[n], o = e[i * 6 + 3];
|
|
1660
|
+
for (let r = n + 1; r < this._orderCount; r++) {
|
|
1661
|
+
const c = s[r];
|
|
1662
|
+
if (e[c * 6] > o)
|
|
1663
|
+
break;
|
|
1664
|
+
e[i * 6 + 1] > e[c * 6 + 4] || e[c * 6 + 1] > e[i * 6 + 4] || e[i * 6 + 2] > e[c * 6 + 5] || e[c * 6 + 2] > e[i * 6 + 5] || this._shouldCollide(i, c) && (i < c ? this._collidePair(i, c) : this._collidePair(c, i));
|
|
1665
|
+
}
|
|
1666
|
+
}
|
|
1667
|
+
for (let n = this._pairList.length - 1; n >= 0; n--) {
|
|
1668
|
+
const i = this._pairList[n];
|
|
1669
|
+
if (i.stamp === this._stamp)
|
|
1670
|
+
continue;
|
|
1671
|
+
const o = this._awake[i.a] || this._type[i.a] === X, r = this._awake[i.b] || this._type[i.b] === X;
|
|
1672
|
+
!o && !r || (i.touching && (i.impulse = 0, this._pushEvent(2, i)), this._removePair(i));
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
_removePair(t) {
|
|
1676
|
+
const s = this._pairList.pop();
|
|
1677
|
+
s !== t && (this._pairList[t.index] = s, s.index = t.index), this._pairs.delete(t), this._pairPool.push(t);
|
|
1678
|
+
}
|
|
1679
|
+
_shouldCollide(t, s) {
|
|
1680
|
+
const e = this._type[t], n = this._type[s];
|
|
1681
|
+
if (e !== R && n !== R)
|
|
1682
|
+
return !1;
|
|
1683
|
+
const i = e === R ? this._awake[t] === 1 : e === X && this._moving(t), o = n === R ? this._awake[s] === 1 : n === X && this._moving(s);
|
|
1684
|
+
if (!i && !o || (this._group[t] & this._mask[s]) === 0 || (this._group[s] & this._mask[t]) === 0)
|
|
1685
|
+
return !1;
|
|
1686
|
+
const r = this._joints[t];
|
|
1687
|
+
if (r)
|
|
1688
|
+
for (let c = 0; c < r.length; c++) {
|
|
1689
|
+
const a = r[c];
|
|
1690
|
+
if (!a.collide && (a.a === t && a.b === s || a.a === s && a.b === t))
|
|
1691
|
+
return !1;
|
|
1692
|
+
}
|
|
1693
|
+
return !0;
|
|
1694
|
+
}
|
|
1695
|
+
_moving(t) {
|
|
1696
|
+
const s = this._linear, e = this._angular;
|
|
1697
|
+
return s[t * 3] !== 0 || s[t * 3 + 1] !== 0 || s[t * 3 + 2] !== 0 || e[t * 3] !== 0 || e[t * 3 + 1] !== 0 || e[t * 3 + 2] !== 0 || this._hasTarget[t] === 1;
|
|
1698
|
+
}
|
|
1699
|
+
_collidePair(t, s) {
|
|
1700
|
+
const e = this._shapes[t].leaves, n = this._shapes[s].leaves, i = this._narrowphase;
|
|
1701
|
+
i.count = 0;
|
|
1702
|
+
const o = e.length > 1 || n.length > 1;
|
|
1703
|
+
for (let m = 0; m < e.length; m++) {
|
|
1704
|
+
const u = e[m];
|
|
1705
|
+
this._leafTransform(t, u, this._leafA), o && this._leafBounds(u, this._leafA, this._leafBoundsA);
|
|
1706
|
+
for (let f = 0; f < n.length; f++) {
|
|
1707
|
+
const y = n[f];
|
|
1708
|
+
if (this._leafTransform(s, y, this._leafB), o) {
|
|
1709
|
+
this._leafBounds(y, this._leafB, this._leafBoundsB);
|
|
1710
|
+
const w = this._leafBoundsA, v = this._leafBoundsB;
|
|
1711
|
+
if (w[0] > v[3] || v[0] > w[3] || w[1] > v[4] || v[1] > w[4] || w[2] > v[5] || v[2] > w[5])
|
|
1712
|
+
continue;
|
|
1713
|
+
}
|
|
1714
|
+
i.collide(u, this._leafA, y, this._leafB);
|
|
1715
|
+
}
|
|
1716
|
+
}
|
|
1717
|
+
let r = this._pairs.get(t, s);
|
|
1718
|
+
if (i.count === 0) {
|
|
1719
|
+
r && (r.stamp = this._stamp, this._markActive(r));
|
|
1720
|
+
return;
|
|
1721
|
+
}
|
|
1722
|
+
r || (r = this._pairPool.pop() ?? new Ls(), r.a = t, r.b = s, r.touching = !1, r.previousCount = 0, r.count = 0, r.index = this._pairList.length, this._pairList.push(r), this._pairs.add(r)), r.stamp = this._stamp, r.sensor = this._sensor[t] === 1 || this._sensor[s] === 1, this._markActive(r);
|
|
1723
|
+
const c = this._contacts, a = c.count;
|
|
1724
|
+
c.reserve(a + i.count), r.start = a, r.count = i.count;
|
|
1725
|
+
const l = i.points, h = this._previous, _ = 16 * this._slop * this._slop, p = r.sensor ? 0 : 1;
|
|
1726
|
+
for (let m = 0; m < i.count; m++) {
|
|
1727
|
+
const u = a + m, f = m * 7;
|
|
1728
|
+
c.bodyA[u] = t, c.bodyB[u] = s, c.solve[u] = p, c.point[u * 3] = l[f], c.point[u * 3 + 1] = l[f + 1], c.point[u * 3 + 2] = l[f + 2];
|
|
1729
|
+
const y = l[f + 3], w = l[f + 4], v = l[f + 5];
|
|
1730
|
+
c.normal[u * 3] = y, c.normal[u * 3 + 1] = w, c.normal[u * 3 + 2] = v, c.separation[u] = l[f + 6];
|
|
1731
|
+
let I = 0, M = 0, b = 0;
|
|
1732
|
+
if (Math.abs(y) > Math.abs(w)) {
|
|
1733
|
+
const N = Math.sqrt(y * y + v * v);
|
|
1734
|
+
I = v / N, b = -y / N;
|
|
1735
|
+
} else {
|
|
1736
|
+
const N = Math.sqrt(w * w + v * v);
|
|
1737
|
+
M = v / N, b = -w / N;
|
|
1738
|
+
}
|
|
1739
|
+
const A = w * b - v * M, g = v * I - y * b, x = y * M - w * I;
|
|
1740
|
+
c.tangent1[u * 3] = I, c.tangent1[u * 3 + 1] = M, c.tangent1[u * 3 + 2] = b, c.tangent2[u * 3] = A, c.tangent2[u * 3 + 1] = g, c.tangent2[u * 3 + 2] = x, this._toLocal(t, c.point, u * 3, c.localA), this._toLocal(s, c.point, u * 3, c.localB), c.normalImpulse[u] = 0, c.tangentImpulse1[u] = 0, c.tangentImpulse2[u] = 0;
|
|
1741
|
+
const k = c.localA, S = c.localB;
|
|
1742
|
+
let D = -1, C = _;
|
|
1743
|
+
for (let N = r.previousStart; N < r.previousStart + r.previousCount; N++) {
|
|
1744
|
+
if (h.normal[N * 3] * y + h.normal[N * 3 + 1] * w + h.normal[N * 3 + 2] * v < 0.95)
|
|
1745
|
+
continue;
|
|
1746
|
+
const z = h.localA[N * 3] - k[u * 3], P = h.localA[N * 3 + 1] - k[u * 3 + 1], E = h.localA[N * 3 + 2] - k[u * 3 + 2], B = h.localB[N * 3] - S[u * 3], T = h.localB[N * 3 + 1] - S[u * 3 + 1], V = h.localB[N * 3 + 2] - S[u * 3 + 2], L = z * z + P * P + E * E, H = B * B + T * T + V * V, $ = L < H ? L : H;
|
|
1747
|
+
$ < C && (C = $, D = N);
|
|
1748
|
+
}
|
|
1749
|
+
if (D >= 0) {
|
|
1750
|
+
c.normalImpulse[u] = h.normalImpulse[D];
|
|
1751
|
+
const N = h.tangentImpulse1[D], z = h.tangentImpulse2[D], P = h.tangent1[D * 3] * N + h.tangent2[D * 3] * z, E = h.tangent1[D * 3 + 1] * N + h.tangent2[D * 3 + 1] * z, B = h.tangent1[D * 3 + 2] * N + h.tangent2[D * 3 + 2] * z;
|
|
1752
|
+
c.tangentImpulse1[u] = P * I + E * M + B * b, c.tangentImpulse2[u] = P * A + E * g + B * x;
|
|
1753
|
+
}
|
|
1754
|
+
}
|
|
1755
|
+
c.count = a + i.count;
|
|
1756
|
+
}
|
|
1757
|
+
_markActive(t) {
|
|
1758
|
+
this._activeCount < this._active.length ? this._active[this._activeCount] = t : this._active.push(t), this._activeCount++;
|
|
1759
|
+
}
|
|
1760
|
+
/** Writes Rᵀ(point − position) of `slot` for the point at `point[offset…]` into `out[offset…]`. */
|
|
1761
|
+
_toLocal(t, s, e, n) {
|
|
1762
|
+
const i = this._rotation, o = t * 9, r = s[e] - this._position[t * 3], c = s[e + 1] - this._position[t * 3 + 1], a = s[e + 2] - this._position[t * 3 + 2];
|
|
1763
|
+
n[e] = i[o] * r + i[o + 3] * c + i[o + 6] * a, n[e + 1] = i[o + 1] * r + i[o + 4] * c + i[o + 7] * a, n[e + 2] = i[o + 2] * r + i[o + 5] * c + i[o + 8] * a;
|
|
1764
|
+
}
|
|
1765
|
+
_prepareContacts() {
|
|
1766
|
+
for (let e = 0; e < this._activeCount; e++) {
|
|
1767
|
+
const n = this._active[e];
|
|
1768
|
+
if (n.count === 0 || n.sensor)
|
|
1769
|
+
continue;
|
|
1770
|
+
const i = n.a, o = n.b;
|
|
1771
|
+
this._type[i] === R && !this._awake[i] && this._pushes(o) ? this._wakeSlot(i) : this._type[o] === R && !this._awake[o] && this._pushes(i) && this._wakeSlot(o);
|
|
1772
|
+
}
|
|
1773
|
+
const t = this._contacts, s = this._dv;
|
|
1774
|
+
for (let e = 0; e < t.count; e++) {
|
|
1775
|
+
const n = t.bodyA[e], i = t.bodyB[e], o = e * 3;
|
|
1776
|
+
for (let a = 0; a < 3; a++)
|
|
1777
|
+
t.ra[o + a] = t.point[o + a] - this._position[n * 3 + a], t.rb[o + a] = t.point[o + a] - this._position[i * 3 + a];
|
|
1778
|
+
this._effectiveMass(n, i, t.ra, t.rb, o, t.normal, t.normalMass, e), this._effectiveMass(n, i, t.ra, t.rb, o, t.tangent1, t.tangentMass1, e), this._effectiveMass(n, i, t.ra, t.rb, o, t.tangent2, t.tangentMass2, e), this._velocity(n, i, t.ra, t.rb, o, this._linear, this._angular), t.relativeVelocity[e] = s[0] * t.normal[o] + s[1] * t.normal[o + 1] + s[2] * t.normal[o + 2], t.friction[e] = Math.sqrt(this._friction[n] * this._friction[i]);
|
|
1779
|
+
const r = this._restitution[n], c = this._restitution[i];
|
|
1780
|
+
t.restitution[e] = r > c ? r : c, t.maxNormalImpulse[e] = 0, t.biasImpulse[e] = 0;
|
|
1781
|
+
}
|
|
1782
|
+
for (let e = 0; e < this._activeCount; e++) {
|
|
1783
|
+
const n = this._active[e];
|
|
1784
|
+
let i = -1;
|
|
1785
|
+
for (let o = n.start; o < n.start + n.count; o++)
|
|
1786
|
+
(i < 0 || t.separation[o] < t.separation[i]) && (i = o);
|
|
1787
|
+
if (i >= 0)
|
|
1788
|
+
for (let o = 0; o < 3; o++)
|
|
1789
|
+
n.point[o] = t.point[i * 3 + o], n.normal[o] = t.normal[i * 3 + o];
|
|
1790
|
+
n.next = i >= 0 && t.separation[i] < this._slop;
|
|
1791
|
+
}
|
|
1792
|
+
}
|
|
1793
|
+
/** Whether `slot` moves enough to wake a resting body it touches. */
|
|
1794
|
+
_pushes(t) {
|
|
1795
|
+
const s = this._type[t];
|
|
1796
|
+
if (s === X)
|
|
1797
|
+
return this._moving(t);
|
|
1798
|
+
if (s !== R || !this._awake[t])
|
|
1799
|
+
return !1;
|
|
1800
|
+
const e = this._linear, n = this._angular, i = t * 3, o = e[i] * e[i] + e[i + 1] * e[i + 1] + e[i + 2] * e[i + 2], r = n[i] * n[i] + n[i + 1] * n[i + 1] + n[i + 2] * n[i + 2];
|
|
1801
|
+
return o > this._sleepLinear * this._sleepLinear || r > this._sleepAngular * this._sleepAngular;
|
|
1802
|
+
}
|
|
1803
|
+
/** `_dv` = (vB + wB × rB) − (vA + wA × rA) for the arms at `ra[offset…]`, `rb[offset…]`. */
|
|
1804
|
+
_velocity(t, s, e, n, i, o, r) {
|
|
1805
|
+
const c = t * 3, a = s * 3, l = e[i], h = e[i + 1], _ = e[i + 2], p = n[i], m = n[i + 1], u = n[i + 2], f = this._dv;
|
|
1806
|
+
f[0] = o[a] + r[a + 1] * u - r[a + 2] * m - o[c] - (r[c + 1] * _ - r[c + 2] * h), f[1] = o[a + 1] + r[a + 2] * p - r[a] * u - o[c + 1] - (r[c + 2] * l - r[c] * _), f[2] = o[a + 2] + r[a] * m - r[a + 1] * p - o[c + 2] - (r[c] * h - r[c + 1] * l);
|
|
1807
|
+
}
|
|
1808
|
+
/** out[outIndex] = 1 / (ma + mb + (ra×n)·Ia(ra×n) + (rb×n)·Ib(rb×n)); 0 when both bodies are immovable. */
|
|
1809
|
+
_effectiveMass(t, s, e, n, i, o, r, c) {
|
|
1810
|
+
const a = o[i], l = o[i + 1], h = o[i + 2], _ = this._inverseInertia;
|
|
1811
|
+
let p = this._inverseMass[t] + this._inverseMass[s];
|
|
1812
|
+
for (let m = 0; m < 2; m++) {
|
|
1813
|
+
const u = m === 0 ? e : n, f = (m === 0 ? t : s) * 9, y = u[i], w = u[i + 1], v = u[i + 2], I = w * h - v * l, M = v * a - y * h, b = y * l - w * a;
|
|
1814
|
+
p += I * (_[f] * I + _[f + 1] * M + _[f + 2] * b) + M * (_[f + 3] * I + _[f + 4] * M + _[f + 5] * b) + b * (_[f + 6] * I + _[f + 7] * M + _[f + 8] * b);
|
|
1815
|
+
}
|
|
1816
|
+
r[c] = p > 1e-12 ? 1 / p : 0;
|
|
1817
|
+
}
|
|
1818
|
+
_integrateVelocities() {
|
|
1819
|
+
const t = this._dt, s = this._gravity, e = this._impulse;
|
|
1820
|
+
for (let n = 0; n < this._orderCount; n++) {
|
|
1821
|
+
const i = this._order[n];
|
|
1822
|
+
if (this._type[i] !== R || !this._awake[i])
|
|
1823
|
+
continue;
|
|
1824
|
+
const o = i * 3, r = this._inverseMass[i], c = this._gravityScale[i], a = 1 / (1 + t * this._linearDamping[i]), l = 1 / (1 + t * this._angularDamping[i]);
|
|
1825
|
+
for (let h = 0; h < 3; h++)
|
|
1826
|
+
this._linear[o + h] = (this._linear[o + h] + t * (s[h] * c + this._force[o + h] * r)) * a, e[h] = this._torque[o + h] * t;
|
|
1827
|
+
this._applyInertia(i, 1);
|
|
1828
|
+
for (let h = 0; h < 3; h++)
|
|
1829
|
+
this._angular[o + h] *= l, this._force[o + h] = 0, this._torque[o + h] = 0;
|
|
1830
|
+
}
|
|
1831
|
+
}
|
|
1832
|
+
_warmStart() {
|
|
1833
|
+
const t = this._contacts, s = this._impulse;
|
|
1834
|
+
for (let n = 0; n < t.count; n++) {
|
|
1835
|
+
if (!t.solve[n])
|
|
1836
|
+
continue;
|
|
1837
|
+
const i = n * 3, o = t.normalImpulse[n], r = t.tangentImpulse1[n], c = t.tangentImpulse2[n];
|
|
1838
|
+
for (let a = 0; a < 3; a++)
|
|
1839
|
+
s[a] = t.normal[i + a] * o + t.tangent1[i + a] * r + t.tangent2[i + a] * c;
|
|
1840
|
+
this._applyPairImpulse(t.bodyA[n], t.bodyB[n], t.ra, t.rb, i, this._linear, this._angular);
|
|
1841
|
+
}
|
|
1842
|
+
const e = this._jointRecords;
|
|
1843
|
+
for (let n = 0; n < e.length; n++)
|
|
1844
|
+
e[n].alive && this._warmStartJoint(e[n]);
|
|
1845
|
+
}
|
|
1846
|
+
_solveContacts() {
|
|
1847
|
+
const t = this._contacts, s = this._linear, e = this._angular, n = this._dv, i = this._impulse, o = this._inverseStep;
|
|
1848
|
+
for (let r = 0; r < t.count; r++) {
|
|
1849
|
+
if (!t.solve[r])
|
|
1850
|
+
continue;
|
|
1851
|
+
const c = t.bodyA[r], a = t.bodyB[r], l = r * 3, h = t.friction[r] * t.normalImpulse[r], _ = t.tangent1[l], p = t.tangent1[l + 1], m = t.tangent1[l + 2], u = t.tangent2[l], f = t.tangent2[l + 1], y = t.tangent2[l + 2];
|
|
1852
|
+
this._velocity(c, a, t.ra, t.rb, l, s, e);
|
|
1853
|
+
const w = n[0] * _ + n[1] * p + n[2] * m, v = n[0] * u + n[1] * f + n[2] * y, I = t.tangentImpulse1[r], M = t.tangentImpulse2[r];
|
|
1854
|
+
let b = I - t.tangentMass1[r] * w, A = M - t.tangentMass2[r] * v;
|
|
1855
|
+
const g = Math.sqrt(b * b + A * A);
|
|
1856
|
+
if (g > h) {
|
|
1857
|
+
const L = g > 0 ? h / g : 0;
|
|
1858
|
+
b *= L, A *= L;
|
|
1859
|
+
}
|
|
1860
|
+
t.tangentImpulse1[r] = b, t.tangentImpulse2[r] = A;
|
|
1861
|
+
const x = b - I, k = A - M;
|
|
1862
|
+
i[0] = _ * x + u * k, i[1] = p * x + f * k, i[2] = m * x + y * k, this._applyPairImpulse(c, a, t.ra, t.rb, l, s, e);
|
|
1863
|
+
const S = t.normal[l], D = t.normal[l + 1], C = t.normal[l + 2], N = t.separation[r];
|
|
1864
|
+
this._velocity(c, a, t.ra, t.rb, l, s, e);
|
|
1865
|
+
const z = n[0] * S + n[1] * D + n[2] * C, P = N > 0 ? N * o : 0, E = t.normalImpulse[r], B = E - t.normalMass[r] * (z + P), T = B > 0 ? B : 0;
|
|
1866
|
+
t.normalImpulse[r] = T, T > t.maxNormalImpulse[r] && (t.maxNormalImpulse[r] = T);
|
|
1867
|
+
const V = T - E;
|
|
1868
|
+
if (i[0] = S * V, i[1] = D * V, i[2] = C * V, this._applyPairImpulse(c, a, t.ra, t.rb, l, s, e), N < -this._slop) {
|
|
1869
|
+
this._velocity(c, a, t.ra, t.rb, l, this._biasLinear, this._biasAngular);
|
|
1870
|
+
const L = n[0] * S + n[1] * D + n[2] * C, H = this._beta * (-N - this._slop) * o, $ = t.biasImpulse[r], J = $ - t.normalMass[r] * (L - H), K = J > 0 ? J : 0;
|
|
1871
|
+
t.biasImpulse[r] = K;
|
|
1872
|
+
const G = K - $;
|
|
1873
|
+
i[0] = S * G, i[1] = D * G, i[2] = C * G, this._applyPairImpulse(c, a, t.ra, t.rb, l, this._biasLinear, this._biasAngular);
|
|
1874
|
+
}
|
|
1875
|
+
}
|
|
1876
|
+
}
|
|
1877
|
+
_applyRestitution() {
|
|
1878
|
+
const t = this._contacts, s = this._dv, e = this._impulse, n = -this._restitutionThreshold;
|
|
1879
|
+
for (let i = 0; i < t.count; i++) {
|
|
1880
|
+
const o = t.restitution[i];
|
|
1881
|
+
if (!t.solve[i] || o === 0 || t.relativeVelocity[i] > n || t.maxNormalImpulse[i] === 0)
|
|
1882
|
+
continue;
|
|
1883
|
+
const r = t.bodyA[i], c = t.bodyB[i], a = i * 3, l = t.normal[a], h = t.normal[a + 1], _ = t.normal[a + 2];
|
|
1884
|
+
this._velocity(r, c, t.ra, t.rb, a, this._linear, this._angular);
|
|
1885
|
+
const p = s[0] * l + s[1] * h + s[2] * _, m = t.normalImpulse[i], u = m - t.normalMass[i] * (p + o * t.relativeVelocity[i]), f = u > 0 ? u : 0;
|
|
1886
|
+
t.normalImpulse[i] = f;
|
|
1887
|
+
const y = f - m;
|
|
1888
|
+
e[0] = l * y, e[1] = h * y, e[2] = _ * y, this._applyPairImpulse(r, c, t.ra, t.rb, a, this._linear, this._angular);
|
|
1889
|
+
}
|
|
1890
|
+
}
|
|
1891
|
+
_integratePositions() {
|
|
1892
|
+
const t = this._dt, s = this._pose;
|
|
1893
|
+
for (let e = 0; e < this._orderCount; e++) {
|
|
1894
|
+
const n = this._order[e], i = this._type[n];
|
|
1895
|
+
if (i === O || i === R && !this._awake[n])
|
|
1896
|
+
continue;
|
|
1897
|
+
const o = n * 3;
|
|
1898
|
+
if (i === X && this._hasTarget[n]) {
|
|
1899
|
+
for (let y = 0; y < 7; y++)
|
|
1900
|
+
s[y] = this._target[n * 7 + y];
|
|
1901
|
+
this._writePose(n), this._hasTarget[n] = 0;
|
|
1902
|
+
for (let y = 0; y < 3; y++)
|
|
1903
|
+
this._linear[o + y] = 0, this._angular[o + y] = 0;
|
|
1904
|
+
continue;
|
|
1905
|
+
}
|
|
1906
|
+
let r = this._angular[o], c = this._angular[o + 1], a = this._angular[o + 2];
|
|
1907
|
+
const l = Math.sqrt(r * r + c * c + a * a) * t;
|
|
1908
|
+
if (l > Math.PI / 2) {
|
|
1909
|
+
const y = Math.PI / 2 / l;
|
|
1910
|
+
r *= y, c *= y, a *= y, this._angular[o] = r, this._angular[o + 1] = c, this._angular[o + 2] = a;
|
|
1911
|
+
}
|
|
1912
|
+
r += this._biasAngular[o], c += this._biasAngular[o + 1], a += this._biasAngular[o + 2];
|
|
1913
|
+
for (let y = 0; y < 3; y++)
|
|
1914
|
+
s[y] = this._position[o + y] + t * (this._linear[o + y] + this._biasLinear[o + y]), this._biasLinear[o + y] = 0, this._biasAngular[o + y] = 0;
|
|
1915
|
+
const h = n * 4, _ = this._orientation[h], p = this._orientation[h + 1], m = this._orientation[h + 2], u = this._orientation[h + 3], f = t / 2;
|
|
1916
|
+
s[3] = _ + f * (r * u + c * m - a * p), s[4] = p + f * (c * u + a * _ - r * m), s[5] = m + f * (a * u + r * p - c * _), s[6] = u + f * (-r * _ - c * p - a * m), this._writePose(n), i === R && this._updateInertia(n);
|
|
1917
|
+
}
|
|
1918
|
+
}
|
|
1919
|
+
/** Union-find islands over touching dynamic pairs and joints; resting islands sleep together. */
|
|
1920
|
+
_updateSleep() {
|
|
1921
|
+
const t = this._dt, s = this._island, e = this._sleepLinear * this._sleepLinear, n = this._sleepAngular * this._sleepAngular, i = this._linear, o = this._angular;
|
|
1922
|
+
for (let a = 0; a < this._orderCount; a++) {
|
|
1923
|
+
const l = this._order[a];
|
|
1924
|
+
if (s[l] = l, this._type[l] !== R || !this._awake[l])
|
|
1925
|
+
continue;
|
|
1926
|
+
const h = l * 3, _ = i[h] * i[h] + i[h + 1] * i[h + 1] + i[h + 2] * i[h + 2], p = o[h] * o[h] + o[h + 1] * o[h + 1] + o[h + 2] * o[h + 2];
|
|
1927
|
+
!this._canSleep[l] || _ > e || p > n ? this._sleepTime[l] = 0 : this._sleepTime[l] += t;
|
|
1928
|
+
}
|
|
1929
|
+
for (let a = 0; a < this._activeCount; a++) {
|
|
1930
|
+
const l = this._active[a];
|
|
1931
|
+
l.count > 0 && !l.sensor && this._union(l.a, l.b);
|
|
1932
|
+
}
|
|
1933
|
+
const r = this._jointRecords;
|
|
1934
|
+
for (let a = 0; a < r.length; a++)
|
|
1935
|
+
r[a].alive && this._union(r[a].a, r[a].b);
|
|
1936
|
+
const c = this._islandRest;
|
|
1937
|
+
for (let a = 0; a < this._orderCount; a++)
|
|
1938
|
+
c[this._order[a]] = 1 / 0;
|
|
1939
|
+
for (let a = 0; a < this._orderCount; a++) {
|
|
1940
|
+
const l = this._order[a];
|
|
1941
|
+
if (this._type[l] === R && this._awake[l]) {
|
|
1942
|
+
const h = this._find(l);
|
|
1943
|
+
this._sleepTime[l] < c[h] && (c[h] = this._sleepTime[l]);
|
|
1944
|
+
}
|
|
1945
|
+
}
|
|
1946
|
+
for (let a = 0; a < this._orderCount; a++) {
|
|
1947
|
+
const l = this._order[a];
|
|
1948
|
+
this._type[l] === R && this._awake[l] && c[this._find(l)] >= this._timeToSleep && this._sleepSlot(l);
|
|
1949
|
+
}
|
|
1950
|
+
}
|
|
1951
|
+
_union(t, s) {
|
|
1952
|
+
if (this._type[t] !== R || this._type[s] !== R || !this._awake[t] || !this._awake[s])
|
|
1953
|
+
return;
|
|
1954
|
+
const e = this._find(t), n = this._find(s);
|
|
1955
|
+
e !== n && (e < n ? this._island[n] = e : this._island[e] = n);
|
|
1956
|
+
}
|
|
1957
|
+
_find(t) {
|
|
1958
|
+
const s = this._island;
|
|
1959
|
+
let e = t;
|
|
1960
|
+
for (; s[e] !== e; )
|
|
1961
|
+
e = s[e];
|
|
1962
|
+
for (; s[t] !== e; ) {
|
|
1963
|
+
const n = s[t];
|
|
1964
|
+
s[t] = e, t = n;
|
|
1965
|
+
}
|
|
1966
|
+
return e;
|
|
1967
|
+
}
|
|
1968
|
+
_reportContacts() {
|
|
1969
|
+
for (let t = 0; t < this._activeCount; t++) {
|
|
1970
|
+
const s = this._active[t], e = s.next;
|
|
1971
|
+
let n = 0;
|
|
1972
|
+
if (!s.sensor)
|
|
1973
|
+
for (let i = s.start; i < s.start + s.count; i++)
|
|
1974
|
+
n += this._contacts.normalImpulse[i];
|
|
1975
|
+
s.impulse = n, e && !s.touching ? this._pushEvent(0, s) : !e && s.touching ? (s.impulse = 0, this._pushEvent(2, s)) : e && this._contactStay && this._pushEvent(1, s), s.touching = e;
|
|
1976
|
+
}
|
|
1977
|
+
}
|
|
1978
|
+
_pushEvent(t, s) {
|
|
1979
|
+
const e = this._eventCount++;
|
|
1980
|
+
if (e >= this._eventPhase.length) {
|
|
1981
|
+
const n = Math.max(32, this._eventPhase.length * 2);
|
|
1982
|
+
this._eventPhase = q(this._eventPhase, n), this._eventSensor = q(this._eventSensor, n), this._eventBodies = q(this._eventBodies, n * 2), this._eventData = q(this._eventData, n * 7);
|
|
1983
|
+
}
|
|
1984
|
+
this._eventPhase[e] = t, this._eventSensor[e] = s.sensor ? 1 : 0, this._eventBodies[e * 2] = this._generation[s.a] * W + s.a, this._eventBodies[e * 2 + 1] = this._generation[s.b] * W + s.b;
|
|
1985
|
+
for (let n = 0; n < 3; n++)
|
|
1986
|
+
this._eventData[e * 7 + n] = s.point[n], this._eventData[e * 7 + 3 + n] = s.normal[n];
|
|
1987
|
+
this._eventData[e * 7 + 6] = s.impulse;
|
|
1988
|
+
}
|
|
1989
|
+
// ---------------------------------------------------------------- joint solver
|
|
1990
|
+
_prepareJoints() {
|
|
1991
|
+
const t = this._inverseStep, s = this._beta * t, e = this._jointRecords;
|
|
1992
|
+
for (let n = 0; n < e.length; n++) {
|
|
1993
|
+
const i = e[n];
|
|
1994
|
+
if (!i.alive)
|
|
1995
|
+
continue;
|
|
1996
|
+
const o = i.a, r = i.b;
|
|
1997
|
+
if (this._rotate(o, i.localA, i.ra), this._rotate(r, i.localB, i.rb), i.type !== yt) {
|
|
1998
|
+
const c = this._matrix;
|
|
1999
|
+
c.fill(0);
|
|
2000
|
+
const a = this._inverseMass[o] + this._inverseMass[r];
|
|
2001
|
+
c[0] = a, c[4] = a, c[8] = a, Qt(c, this._inverseInertia, o * 9, i.ra), Qt(c, this._inverseInertia, r * 9, i.rb), Ct(i.pointMass, c);
|
|
2002
|
+
for (let l = 0; l < 3; l++)
|
|
2003
|
+
i.pointBias[l] = s * (this._position[r * 3 + l] + i.rb[l] - this._position[o * 3 + l] - i.ra[l]);
|
|
2004
|
+
}
|
|
2005
|
+
if (i.type === xt) {
|
|
2006
|
+
const c = this._matrix;
|
|
2007
|
+
for (let h = 0; h < 9; h++)
|
|
2008
|
+
c[h] = this._inverseInertia[o * 9 + h] + this._inverseInertia[r * 9 + h];
|
|
2009
|
+
Ct(i.angularMass, c);
|
|
2010
|
+
const a = this._matrix;
|
|
2011
|
+
Nt(a, 0, this._orientation, o * 4, !1, i.relative, 0, !1), Nt(a, 4, this._orientation, r * 4, !1, a, 0, !0);
|
|
2012
|
+
const l = a[7] < 0 ? -2 : 2;
|
|
2013
|
+
i.angularBias[0] = s * l * a[4], i.angularBias[1] = s * l * a[5], i.angularBias[2] = s * l * a[6];
|
|
2014
|
+
} else if (i.type === At) {
|
|
2015
|
+
const c = i.direction;
|
|
2016
|
+
this._rotate(o, i.axisA, c);
|
|
2017
|
+
const a = c[0], l = c[1], h = c[2], _ = this._matrix;
|
|
2018
|
+
this._rotate(r, i.axisB, _);
|
|
2019
|
+
const p = l * _[2] - h * _[1], m = h * _[0] - a * _[2], u = a * _[1] - l * _[0];
|
|
2020
|
+
Hs(c, i.rows), i.rows[6] = a, i.rows[7] = l, i.rows[8] = h;
|
|
2021
|
+
for (let f = 0; f < 3; f++)
|
|
2022
|
+
this._angularRowMass(o, r, i.rows, f * 3, i.rowMass, f);
|
|
2023
|
+
for (let f = 0; f < 2; f++)
|
|
2024
|
+
i.rowBias[f] = s * (p * i.rows[f * 3] + m * i.rows[f * 3 + 1] + u * i.rows[f * 3 + 2]);
|
|
2025
|
+
if (i.hasLimits) {
|
|
2026
|
+
const f = this._referenceA, y = this._referenceB;
|
|
2027
|
+
this._rotate(o, i.referenceA, f), this._rotate(r, i.referenceB, y);
|
|
2028
|
+
const w = f[1] * y[2] - f[2] * y[1], v = f[2] * y[0] - f[0] * y[2], I = f[0] * y[1] - f[1] * y[0];
|
|
2029
|
+
i.angle = Math.atan2(w * a + v * l + I * h, f[0] * y[0] + f[1] * y[1] + f[2] * y[2]);
|
|
2030
|
+
const M = i.angle - i.lower, b = i.upper - i.angle;
|
|
2031
|
+
i.lowerBias = M > 0 ? M * t : s * M, i.upperBias = b > 0 ? b * t : s * b;
|
|
2032
|
+
} else
|
|
2033
|
+
i.lowerImpulse = 0, i.upperImpulse = 0;
|
|
2034
|
+
i.hasMotor || (i.motorImpulse = 0);
|
|
2035
|
+
} else if (i.type === yt) {
|
|
2036
|
+
const c = i.direction;
|
|
2037
|
+
for (let _ = 0; _ < 3; _++)
|
|
2038
|
+
c[_] = this._position[r * 3 + _] + i.rb[_] - this._position[o * 3 + _] - i.ra[_];
|
|
2039
|
+
const a = Math.sqrt(c[0] * c[0] + c[1] * c[1] + c[2] * c[2]);
|
|
2040
|
+
i.length = a, a > 1e-9 ? (c[0] /= a, c[1] /= a, c[2] /= a) : (c[0] = 0, c[1] = 1, c[2] = 0), this._effectiveMass(o, r, i.ra, i.rb, 0, c, i.rowMass, 0);
|
|
2041
|
+
const l = a - i.minDistance, h = i.maxDistance - a;
|
|
2042
|
+
i.lowerBias = l > 0 && i.minDistance !== i.maxDistance ? l * t : s * l, i.upperBias = h > 0 ? h * t : s * h;
|
|
2043
|
+
}
|
|
2044
|
+
}
|
|
2045
|
+
}
|
|
2046
|
+
/** out[outIndex] = 1 / (axis·Ia·axis + axis·Ib·axis) for the unit axis at `rows[offset…]`. */
|
|
2047
|
+
_angularRowMass(t, s, e, n, i, o) {
|
|
2048
|
+
const r = e[n], c = e[n + 1], a = e[n + 2], l = this._inverseInertia;
|
|
2049
|
+
let h = 0;
|
|
2050
|
+
for (let _ = 0; _ < 2; _++) {
|
|
2051
|
+
const p = (_ === 0 ? t : s) * 9;
|
|
2052
|
+
h += r * (l[p] * r + l[p + 1] * c + l[p + 2] * a) + c * (l[p + 3] * r + l[p + 4] * c + l[p + 5] * a) + a * (l[p + 6] * r + l[p + 7] * c + l[p + 8] * a);
|
|
2053
|
+
}
|
|
2054
|
+
i[o] = 1 / (h > 1e-12 ? h : 1e-12);
|
|
2055
|
+
}
|
|
2056
|
+
_warmStartJoint(t) {
|
|
2057
|
+
const s = t.a, e = t.b, n = this._impulse;
|
|
2058
|
+
if (t.type !== yt && (n.set(t.pointImpulse), this._applyPairImpulse(s, e, t.ra, t.rb, 0, this._linear, this._angular)), t.type === xt)
|
|
2059
|
+
n.set(t.angularImpulse), this._applyAngularPair(s, e);
|
|
2060
|
+
else if (t.type === At) {
|
|
2061
|
+
const i = t.rows, o = t.lowerImpulse - t.upperImpulse + t.motorImpulse;
|
|
2062
|
+
for (let r = 0; r < 3; r++)
|
|
2063
|
+
n[r] = i[r] * t.rowImpulse[0] + i[3 + r] * t.rowImpulse[1] + i[6 + r] * o;
|
|
2064
|
+
this._applyAngularPair(s, e);
|
|
2065
|
+
} else if (t.type === yt) {
|
|
2066
|
+
const i = t.lowerImpulse - t.upperImpulse;
|
|
2067
|
+
for (let o = 0; o < 3; o++)
|
|
2068
|
+
n[o] = t.direction[o] * i;
|
|
2069
|
+
this._applyPairImpulse(s, e, t.ra, t.rb, 0, this._linear, this._angular);
|
|
2070
|
+
}
|
|
2071
|
+
}
|
|
2072
|
+
_solveJoints() {
|
|
2073
|
+
const t = this._linear, s = this._angular, e = this._dv, n = this._impulse, i = this._jointRecords;
|
|
2074
|
+
for (let o = 0; o < i.length; o++) {
|
|
2075
|
+
const r = i[o];
|
|
2076
|
+
if (!r.alive)
|
|
2077
|
+
continue;
|
|
2078
|
+
const c = r.a, a = r.b;
|
|
2079
|
+
if ((r.type === xt || r.type === At) && this._solveAngular(r), r.type === yt) {
|
|
2080
|
+
const m = r.direction, u = r.rowMass[0];
|
|
2081
|
+
this._velocity(c, a, r.ra, r.rb, 0, t, s);
|
|
2082
|
+
const f = e[0] * m[0] + e[1] * m[1] + e[2] * m[2];
|
|
2083
|
+
if (r.minDistance === r.maxDistance) {
|
|
2084
|
+
const g = -u * (f + r.lowerBias);
|
|
2085
|
+
r.lowerImpulse += g;
|
|
2086
|
+
for (let x = 0; x < 3; x++)
|
|
2087
|
+
n[x] = m[x] * g;
|
|
2088
|
+
this._applyPairImpulse(c, a, r.ra, r.rb, 0, t, s);
|
|
2089
|
+
continue;
|
|
2090
|
+
}
|
|
2091
|
+
const y = r.lowerImpulse, w = y - u * (f + r.lowerBias);
|
|
2092
|
+
r.lowerImpulse = w > 0 ? w : 0;
|
|
2093
|
+
const v = r.lowerImpulse - y;
|
|
2094
|
+
for (let g = 0; g < 3; g++)
|
|
2095
|
+
n[g] = m[g] * v;
|
|
2096
|
+
this._applyPairImpulse(c, a, r.ra, r.rb, 0, t, s), this._velocity(c, a, r.ra, r.rb, 0, t, s);
|
|
2097
|
+
const I = -(e[0] * m[0] + e[1] * m[1] + e[2] * m[2]), M = r.upperImpulse, b = M - u * (I + r.upperBias);
|
|
2098
|
+
r.upperImpulse = b > 0 ? b : 0;
|
|
2099
|
+
const A = r.upperImpulse - M;
|
|
2100
|
+
for (let g = 0; g < 3; g++)
|
|
2101
|
+
n[g] = -m[g] * A;
|
|
2102
|
+
this._applyPairImpulse(c, a, r.ra, r.rb, 0, t, s);
|
|
2103
|
+
continue;
|
|
2104
|
+
}
|
|
2105
|
+
this._velocity(c, a, r.ra, r.rb, 0, t, s);
|
|
2106
|
+
const l = e[0] + r.pointBias[0], h = e[1] + r.pointBias[1], _ = e[2] + r.pointBias[2], p = r.pointMass;
|
|
2107
|
+
n[0] = -(p[0] * l + p[1] * h + p[2] * _), n[1] = -(p[3] * l + p[4] * h + p[5] * _), n[2] = -(p[6] * l + p[7] * h + p[8] * _);
|
|
2108
|
+
for (let m = 0; m < 3; m++)
|
|
2109
|
+
r.pointImpulse[m] += n[m];
|
|
2110
|
+
this._applyPairImpulse(c, a, r.ra, r.rb, 0, t, s);
|
|
2111
|
+
}
|
|
2112
|
+
}
|
|
2113
|
+
_solveAngular(t) {
|
|
2114
|
+
const s = t.a, e = t.b, n = this._angular, i = this._impulse;
|
|
2115
|
+
if (t.type === xt) {
|
|
2116
|
+
const h = n[e * 3] - n[s * 3] + t.angularBias[0], _ = n[e * 3 + 1] - n[s * 3 + 1] + t.angularBias[1], p = n[e * 3 + 2] - n[s * 3 + 2] + t.angularBias[2], m = t.angularMass;
|
|
2117
|
+
i[0] = -(m[0] * h + m[1] * _ + m[2] * p), i[1] = -(m[3] * h + m[4] * _ + m[5] * p), i[2] = -(m[6] * h + m[7] * _ + m[8] * p);
|
|
2118
|
+
for (let u = 0; u < 3; u++)
|
|
2119
|
+
t.angularImpulse[u] += i[u];
|
|
2120
|
+
this._applyAngularPair(s, e);
|
|
2121
|
+
return;
|
|
2122
|
+
}
|
|
2123
|
+
const o = t.rows, r = o[6], c = o[7], a = o[8], l = t.rowMass[2];
|
|
2124
|
+
if (t.hasMotor) {
|
|
2125
|
+
const h = (n[e * 3] - n[s * 3]) * r + (n[e * 3 + 1] - n[s * 3 + 1]) * c + (n[e * 3 + 2] - n[s * 3 + 2]) * a, _ = t.motorImpulse, p = t.motorForce * this._dt, m = _ - l * (h - t.motorSpeed);
|
|
2126
|
+
t.motorImpulse = m > p ? p : m < -p ? -p : m;
|
|
2127
|
+
const u = t.motorImpulse - _;
|
|
2128
|
+
i[0] = r * u, i[1] = c * u, i[2] = a * u, this._applyAngularPair(s, e);
|
|
2129
|
+
}
|
|
2130
|
+
if (t.hasLimits)
|
|
2131
|
+
for (let h = 0; h < 2; h++) {
|
|
2132
|
+
const _ = h === 0 ? 1 : -1, p = _ * ((n[e * 3] - n[s * 3]) * r + (n[e * 3 + 1] - n[s * 3 + 1]) * c + (n[e * 3 + 2] - n[s * 3 + 2]) * a), m = h === 0 ? t.lowerImpulse : t.upperImpulse, u = m - l * (p + (h === 0 ? t.lowerBias : t.upperBias)), f = u > 0 ? u : 0;
|
|
2133
|
+
h === 0 ? t.lowerImpulse = f : t.upperImpulse = f;
|
|
2134
|
+
const y = (f - m) * _;
|
|
2135
|
+
i[0] = r * y, i[1] = c * y, i[2] = a * y, this._applyAngularPair(s, e);
|
|
2136
|
+
}
|
|
2137
|
+
for (let h = 0; h < 2; h++) {
|
|
2138
|
+
const _ = o[h * 3], p = o[h * 3 + 1], m = o[h * 3 + 2], u = (n[e * 3] - n[s * 3]) * _ + (n[e * 3 + 1] - n[s * 3 + 1]) * p + (n[e * 3 + 2] - n[s * 3 + 2]) * m, f = -t.rowMass[h] * (u + t.rowBias[h]);
|
|
2139
|
+
t.rowImpulse[h] += f, i[0] = _ * f, i[1] = p * f, i[2] = m * f, this._applyAngularPair(s, e);
|
|
2140
|
+
}
|
|
2141
|
+
}
|
|
2142
|
+
// ---------------------------------------------------------------- helpers
|
|
2143
|
+
/** Applies `_impulse` at B and its negative at A, on the velocity arrays `v` and `w`. */
|
|
2144
|
+
_applyPairImpulse(t, s, e, n, i, o, r) {
|
|
2145
|
+
const c = this._impulse, a = c[0], l = c[1], h = c[2], _ = this._inverseInertia, p = this._inverseMass[t];
|
|
2146
|
+
if (p > 0) {
|
|
2147
|
+
o[t * 3] -= a * p, o[t * 3 + 1] -= l * p, o[t * 3 + 2] -= h * p;
|
|
2148
|
+
const u = e[i + 2] * l - e[i + 1] * h, f = e[i] * h - e[i + 2] * a, y = e[i + 1] * a - e[i] * l, w = t * 9;
|
|
2149
|
+
r[t * 3] += _[w] * u + _[w + 1] * f + _[w + 2] * y, r[t * 3 + 1] += _[w + 3] * u + _[w + 4] * f + _[w + 5] * y, r[t * 3 + 2] += _[w + 6] * u + _[w + 7] * f + _[w + 8] * y;
|
|
2150
|
+
}
|
|
2151
|
+
const m = this._inverseMass[s];
|
|
2152
|
+
if (m > 0) {
|
|
2153
|
+
o[s * 3] += a * m, o[s * 3 + 1] += l * m, o[s * 3 + 2] += h * m;
|
|
2154
|
+
const u = n[i + 1] * h - n[i + 2] * l, f = n[i + 2] * a - n[i] * h, y = n[i] * l - n[i + 1] * a, w = s * 9;
|
|
2155
|
+
r[s * 3] += _[w] * u + _[w + 1] * f + _[w + 2] * y, r[s * 3 + 1] += _[w + 3] * u + _[w + 4] * f + _[w + 5] * y, r[s * 3 + 2] += _[w + 6] * u + _[w + 7] * f + _[w + 8] * y;
|
|
2156
|
+
}
|
|
2157
|
+
}
|
|
2158
|
+
/** Applies the angular `_impulse` to B and its negative to A. */
|
|
2159
|
+
_applyAngularPair(t, s) {
|
|
2160
|
+
this._inverseMass[t] > 0 && this._applyInertia(t, -1), this._inverseMass[s] > 0 && this._applyInertia(s, 1);
|
|
2161
|
+
}
|
|
2162
|
+
/** w[slot] += sign · I⁻¹ · `_impulse`. */
|
|
2163
|
+
_applyInertia(t, s) {
|
|
2164
|
+
const e = this._impulse, n = this._inverseInertia, i = this._angular, o = e[0] * s, r = e[1] * s, c = e[2] * s, a = t * 9;
|
|
2165
|
+
i[t * 3] += n[a] * o + n[a + 1] * r + n[a + 2] * c, i[t * 3 + 1] += n[a + 3] * o + n[a + 4] * r + n[a + 5] * c, i[t * 3 + 2] += n[a + 6] * o + n[a + 7] * r + n[a + 8] * c;
|
|
2166
|
+
}
|
|
2167
|
+
_rotate(t, s, e) {
|
|
2168
|
+
const n = this._rotation, i = t * 9, o = s[0], r = s[1], c = s[2];
|
|
2169
|
+
e[0] = n[i] * o + n[i + 1] * r + n[i + 2] * c, e[1] = n[i + 3] * o + n[i + 4] * r + n[i + 5] * c, e[2] = n[i + 6] * o + n[i + 7] * r + n[i + 8] * c;
|
|
2170
|
+
}
|
|
2171
|
+
_writeMotor(t, s) {
|
|
2172
|
+
if (s === null) {
|
|
2173
|
+
t.hasMotor = !1, t.motorImpulse = 0;
|
|
2174
|
+
return;
|
|
2175
|
+
}
|
|
2176
|
+
if (!s || typeof s != "object")
|
|
2177
|
+
throw new F("invalid-option", "[Nova3D] Joint motor must be an object or null.");
|
|
2178
|
+
t.motorSpeed = St(s.targetVelocity, "motor targetVelocity"), t.motorForce = Y(s.maxForce, "motor maxForce"), t.hasMotor = !0;
|
|
2179
|
+
}
|
|
2180
|
+
_removeJoint(t) {
|
|
2181
|
+
if (t.alive) {
|
|
2182
|
+
t.alive = !1;
|
|
2183
|
+
for (const s of [t.a, t.b]) {
|
|
2184
|
+
const e = this._joints[s];
|
|
2185
|
+
e && (e.splice(e.indexOf(t), 1), e.length === 0 && (this._joints[s] = null));
|
|
2186
|
+
}
|
|
2187
|
+
this._wakeSlot(t.a), this._wakeSlot(t.b), t.generation = t.generation % Wt + 1, this._jointFree.push(this._jointRecords.indexOf(t)), this._jointCount--;
|
|
2188
|
+
}
|
|
2189
|
+
}
|
|
2190
|
+
_joint(t) {
|
|
2191
|
+
if (this._assertAlive(), typeof t != "number" || !Number.isInteger(t) || t < 0)
|
|
2192
|
+
throw new F("invalid-option", "[Nova3D] Invalid physics joint handle.");
|
|
2193
|
+
const s = t % W, e = Math.floor(t / W), n = this._jointRecords[s];
|
|
2194
|
+
if (!n || !n.alive || n.generation !== e)
|
|
2195
|
+
throw new F("invalid-option", "[Nova3D] Stale or foreign physics joint handle.");
|
|
2196
|
+
return n;
|
|
2197
|
+
}
|
|
2198
|
+
/** Writes the pose in `_pose` to `slot`, normalizing the quaternion. */
|
|
2199
|
+
_writePose(t) {
|
|
2200
|
+
const s = this._pose, e = Math.sqrt(s[3] * s[3] + s[4] * s[4] + s[5] * s[5] + s[6] * s[6]);
|
|
2201
|
+
for (let i = 0; i < 3; i++)
|
|
2202
|
+
this._position[t * 3 + i] = s[i];
|
|
2203
|
+
for (let i = 0; i < 4; i++)
|
|
2204
|
+
this._orientation[t * 4 + i] = s[3 + i] / e;
|
|
2205
|
+
const n = t * 4;
|
|
2206
|
+
Tt(this._rotation, t * 9, this._orientation[n], this._orientation[n + 1], this._orientation[n + 2], this._orientation[n + 3]);
|
|
2207
|
+
}
|
|
2208
|
+
_writePoseValues(t, s, e) {
|
|
2209
|
+
this._pose.set(s), this._pose.set(e, 3), this._writePose(t);
|
|
2210
|
+
}
|
|
2211
|
+
/** Recomputes inverse mass and the world inverse inertia from type, mass and shape. */
|
|
2212
|
+
_updateMass(t) {
|
|
2213
|
+
const s = this._localInverseInertia;
|
|
2214
|
+
if (this._type[t] !== R)
|
|
2215
|
+
this._inverseMass[t] = 0, s.fill(0, t * 6, t * 6 + 6);
|
|
2216
|
+
else {
|
|
2217
|
+
const e = this._mass[t], n = this._shapes[t].unitInertia, i = this._matrix;
|
|
2218
|
+
i[0] = n[0] * e, i[4] = n[1] * e, i[8] = n[2] * e, i[1] = i[3] = n[3] * e, i[2] = i[6] = n[4] * e, i[5] = i[7] = n[5] * e;
|
|
2219
|
+
const o = new Float64Array(9);
|
|
2220
|
+
Ct(o, i), this._inverseMass[t] = 1 / e, s[t * 6] = o[0], s[t * 6 + 1] = o[4], s[t * 6 + 2] = o[8], s[t * 6 + 3] = o[1], s[t * 6 + 4] = o[2], s[t * 6 + 5] = o[5];
|
|
2221
|
+
}
|
|
2222
|
+
if (this._type[t] === R && !this._awake[t]) {
|
|
2223
|
+
this._inverseMass[t] = 0, this._inverseInertia.fill(0, t * 9, t * 9 + 9);
|
|
2224
|
+
return;
|
|
2225
|
+
}
|
|
2226
|
+
this._updateInertia(t);
|
|
2227
|
+
}
|
|
2228
|
+
/** World inverse inertia R·I⁻¹·Rᵀ; zero for static, kinematic and sleeping bodies. */
|
|
2229
|
+
_updateInertia(t) {
|
|
2230
|
+
const s = this._inverseInertia, e = t * 9;
|
|
2231
|
+
if (this._inverseMass[t] === 0) {
|
|
2232
|
+
s.fill(0, e, e + 9);
|
|
2233
|
+
return;
|
|
2234
|
+
}
|
|
2235
|
+
const n = this._rotation, i = this._localInverseInertia, o = t * 6, r = i[o], c = i[o + 1], a = i[o + 2], l = i[o + 3], h = i[o + 4], _ = i[o + 5];
|
|
2236
|
+
for (let p = 0; p < 3; p++) {
|
|
2237
|
+
const m = n[e + p * 3], u = n[e + p * 3 + 1], f = n[e + p * 3 + 2], y = m * r + u * l + f * h, w = m * l + u * c + f * _, v = m * h + u * _ + f * a;
|
|
2238
|
+
for (let I = 0; I < 3; I++)
|
|
2239
|
+
s[e + p * 3 + I] = y * n[e + I * 3] + w * n[e + I * 3 + 1] + v * n[e + I * 3 + 2];
|
|
2240
|
+
}
|
|
2241
|
+
}
|
|
2242
|
+
_wakeSlot(t) {
|
|
2243
|
+
t <= 0 || this._type[t] !== R || (this._sleepTime[t] = 0, !this._awake[t] && (this._awake[t] = 1, this._inverseMass[t] = 1 / this._mass[t], this._updateInertia(t)));
|
|
2244
|
+
}
|
|
2245
|
+
_sleepSlot(t) {
|
|
2246
|
+
this._awake[t] = 0, this._linear.fill(0, t * 3, t * 3 + 3), this._angular.fill(0, t * 3, t * 3 + 3), this._inverseMass[t] = 0, this._inverseInertia.fill(0, t * 9, t * 9 + 9);
|
|
2247
|
+
}
|
|
2248
|
+
/** Wakes the body and every dynamic body sharing a pair with it. */
|
|
2249
|
+
_wakeTouching(t) {
|
|
2250
|
+
this._wakeSlot(t);
|
|
2251
|
+
for (let s = 0; s < this._pairList.length; s++) {
|
|
2252
|
+
const e = this._pairList[s];
|
|
2253
|
+
e.a === t ? this._wakeSlot(e.b) : e.b === t && this._wakeSlot(e.a);
|
|
2254
|
+
}
|
|
2255
|
+
}
|
|
2256
|
+
_leafTransform(t, s, e) {
|
|
2257
|
+
const n = this._rotation, i = t * 9;
|
|
2258
|
+
if (s.identity) {
|
|
2259
|
+
e[0] = this._position[t * 3], e[1] = this._position[t * 3 + 1], e[2] = this._position[t * 3 + 2];
|
|
2260
|
+
for (let a = 0; a < 9; a++)
|
|
2261
|
+
e[3 + a] = n[i + a];
|
|
2262
|
+
return;
|
|
2263
|
+
}
|
|
2264
|
+
const o = s.position;
|
|
2265
|
+
e[0] = this._position[t * 3] + n[i] * o[0] + n[i + 1] * o[1] + n[i + 2] * o[2], e[1] = this._position[t * 3 + 1] + n[i + 3] * o[0] + n[i + 4] * o[1] + n[i + 5] * o[2], e[2] = this._position[t * 3 + 2] + n[i + 6] * o[0] + n[i + 7] * o[1] + n[i + 8] * o[2];
|
|
2266
|
+
const r = s.quaternion, c = this._matrix;
|
|
2267
|
+
Tt(c, 0, r[0], r[1], r[2], r[3]);
|
|
2268
|
+
for (let a = 0; a < 3; a++)
|
|
2269
|
+
for (let l = 0; l < 3; l++)
|
|
2270
|
+
e[3 + a * 3 + l] = n[i + a * 3] * c[l] + n[i + a * 3 + 1] * c[3 + l] + n[i + a * 3 + 2] * c[6 + l];
|
|
2271
|
+
}
|
|
2272
|
+
/** World AABB of a leaf, grown by half the speculative distance on each side. */
|
|
2273
|
+
_leafBounds(t, s, e) {
|
|
2274
|
+
if (t.kind === U) {
|
|
2275
|
+
e[0] = -_t, e[1] = -_t, e[2] = -_t, e[3] = _t, e[4] = _t, e[5] = _t;
|
|
2276
|
+
return;
|
|
2277
|
+
}
|
|
2278
|
+
const n = t.min, i = t.max, o = this._speculative / 2;
|
|
2279
|
+
for (let r = 0; r < 3; r++) {
|
|
2280
|
+
let c = s[r], a = 0;
|
|
2281
|
+
for (let l = 0; l < 3; l++) {
|
|
2282
|
+
const h = s[3 + r * 3 + l];
|
|
2283
|
+
c += h * (n[l] + i[l]) / 2, a += Math.abs(h) * (i[l] - n[l]) / 2;
|
|
2284
|
+
}
|
|
2285
|
+
e[r] = c - a - o, e[3 + r] = c + a + o;
|
|
2286
|
+
}
|
|
2287
|
+
}
|
|
2288
|
+
_updateBounds(t) {
|
|
2289
|
+
const s = this._bounds, e = t * 6;
|
|
2290
|
+
s[e] = s[e + 1] = s[e + 2] = 1 / 0, s[e + 3] = s[e + 4] = s[e + 5] = -1 / 0;
|
|
2291
|
+
const n = this._leafBoundsA;
|
|
2292
|
+
for (const i of this._shapes[t].leaves) {
|
|
2293
|
+
this._leafTransform(t, i, this._leafA), this._leafBounds(i, this._leafA, n);
|
|
2294
|
+
for (let o = 0; o < 3; o++)
|
|
2295
|
+
s[e + o] = Math.min(s[e + o], n[o]), s[e + 3 + o] = Math.max(s[e + 3 + o], n[3 + o]);
|
|
2296
|
+
}
|
|
2297
|
+
}
|
|
2298
|
+
_rayLeaf(t, s, e, n, i, o, r, c, a) {
|
|
2299
|
+
switch (t.kind) {
|
|
2300
|
+
case ut:
|
|
2301
|
+
case pt:
|
|
2302
|
+
return ks(s, e, n, i, o, r, t.radius, t.kind === pt ? t.halfHeight : 0, c, a);
|
|
2303
|
+
case Q:
|
|
2304
|
+
return Is(t.hull, s, e, n, i, o, r, c, a);
|
|
2305
|
+
case U: {
|
|
2306
|
+
const l = t.planeNormal, h = l[0] * s + l[1] * e + l[2] * n - t.planeOffset;
|
|
2307
|
+
if (h <= 0)
|
|
2308
|
+
return a.t = 0, a.nx = l[0], a.ny = l[1], a.nz = l[2], !0;
|
|
2309
|
+
const _ = l[0] * i + l[1] * o + l[2] * r;
|
|
2310
|
+
if (_ >= 0)
|
|
2311
|
+
return !1;
|
|
2312
|
+
const p = -h / _;
|
|
2313
|
+
return p > c ? !1 : (a.t = p, a.nx = l[0], a.ny = l[1], a.nz = l[2], !0);
|
|
2314
|
+
}
|
|
2315
|
+
case tt: {
|
|
2316
|
+
const l = t.mesh, h = this._rayStack;
|
|
2317
|
+
let _ = 0;
|
|
2318
|
+
h[_++] = 0;
|
|
2319
|
+
let p = c, m = !1;
|
|
2320
|
+
const u = a.nx, f = a.ny, y = a.nz;
|
|
2321
|
+
let w = u, v = f, I = y;
|
|
2322
|
+
for (; _ > 0; ) {
|
|
2323
|
+
const M = h[--_];
|
|
2324
|
+
if (!Zt(l.nodeBounds, M * 6, s, e, n, i, o, r, p))
|
|
2325
|
+
continue;
|
|
2326
|
+
const b = l.nodeCount[M];
|
|
2327
|
+
if (b === 0) {
|
|
2328
|
+
if (_ + 2 > h.length)
|
|
2329
|
+
throw new F("invalid-option", "[Nova3D] Triangle mesh tree is too deep.");
|
|
2330
|
+
h[_++] = M + 1, h[_++] = l.nodeStart[M];
|
|
2331
|
+
continue;
|
|
2332
|
+
}
|
|
2333
|
+
for (let A = 0; A < b; A++)
|
|
2334
|
+
Ms(l, l.order[l.nodeStart[M] + A], s, e, n, i, o, r, p, a) && (p = a.t, w = a.nx, v = a.ny, I = a.nz, m = !0);
|
|
2335
|
+
}
|
|
2336
|
+
return a.t = p, a.nx = w, a.ny = v, a.nz = I, m;
|
|
2337
|
+
}
|
|
2338
|
+
default:
|
|
2339
|
+
return !1;
|
|
2340
|
+
}
|
|
2341
|
+
}
|
|
2342
|
+
_reserveBodies(t) {
|
|
2343
|
+
if (t <= this._capacity)
|
|
2344
|
+
return;
|
|
2345
|
+
const s = Math.max(t, this._capacity * 2, 16);
|
|
2346
|
+
this._capacity = s, this._generation = q(this._generation, s), this._type = q(this._type, s), this._awake = q(this._awake, s), this._canSleep = q(this._canSleep, s), this._sensor = q(this._sensor, s), this._hasTarget = q(this._hasTarget, s), this._group = q(this._group, s), this._mask = q(this._mask, s), this._position = q(this._position, s * 3), this._orientation = q(this._orientation, s * 4), this._rotation = q(this._rotation, s * 9), this._linear = q(this._linear, s * 3), this._angular = q(this._angular, s * 3), this._biasLinear = q(this._biasLinear, s * 3), this._biasAngular = q(this._biasAngular, s * 3), this._force = q(this._force, s * 3), this._torque = q(this._torque, s * 3), this._target = q(this._target, s * 7), this._mass = q(this._mass, s), this._inverseMass = q(this._inverseMass, s), this._localInverseInertia = q(this._localInverseInertia, s * 6), this._inverseInertia = q(this._inverseInertia, s * 9), this._linearDamping = q(this._linearDamping, s), this._angularDamping = q(this._angularDamping, s), this._friction = q(this._friction, s), this._restitution = q(this._restitution, s), this._gravityScale = q(this._gravityScale, s), this._sleepTime = q(this._sleepTime, s), this._bounds = q(this._bounds, s * 6), this._island = q(this._island, s), this._islandRest = q(this._islandRest, s), this._order = q(this._order, s);
|
|
2347
|
+
}
|
|
2348
|
+
_resolve(t) {
|
|
2349
|
+
if (typeof t != "number" || !Number.isInteger(t) || t < W)
|
|
2350
|
+
return -1;
|
|
2351
|
+
const s = t % W;
|
|
2352
|
+
return s <= 0 || s >= this._capacity || this._type[s] === rt || this._generation[s] !== Math.floor(t / W) ? -1 : s;
|
|
2353
|
+
}
|
|
2354
|
+
_slot(t) {
|
|
2355
|
+
this._assertAlive();
|
|
2356
|
+
const s = this._resolve(t);
|
|
2357
|
+
if (s < 0)
|
|
2358
|
+
throw new F("invalid-option", "[Nova3D] Stale or foreign physics body handle.");
|
|
2359
|
+
return s;
|
|
2360
|
+
}
|
|
2361
|
+
_assertAlive() {
|
|
2362
|
+
if (this._destroyed)
|
|
2363
|
+
throw new F("destroyed", "[Nova3D] Physics world is destroyed.");
|
|
2364
|
+
}
|
|
2365
|
+
}
|
|
2366
|
+
function Yt(d, t) {
|
|
2367
|
+
const s = Math.hypot(d[0], d[1], d[2]);
|
|
2368
|
+
if (!(s > 1e-12))
|
|
2369
|
+
throw new F("invalid-option", `[Nova3D] Physics ${t} must be nonzero.`);
|
|
2370
|
+
return [d[0] / s, d[1] / s, d[2] / s];
|
|
2371
|
+
}
|
|
2372
|
+
function Nt(d, t, s, e, n, i, o, r) {
|
|
2373
|
+
const c = n ? -1 : 1, a = r ? -1 : 1, l = s[e] * c, h = s[e + 1] * c, _ = s[e + 2] * c, p = s[e + 3], m = i[o] * a, u = i[o + 1] * a, f = i[o + 2] * a, y = i[o + 3];
|
|
2374
|
+
d[t] = p * m + l * y + h * f - _ * u, d[t + 1] = p * u - l * f + h * y + _ * m, d[t + 2] = p * f + l * u - h * m + _ * y, d[t + 3] = p * y - l * m - h * u - _ * f;
|
|
2375
|
+
}
|
|
2376
|
+
function Hs(d, t) {
|
|
2377
|
+
const s = d[0], e = d[1], n = d[2];
|
|
2378
|
+
let i = 0, o = 0, r = 0;
|
|
2379
|
+
if (Math.abs(s) > Math.abs(e)) {
|
|
2380
|
+
const c = Math.sqrt(s * s + n * n);
|
|
2381
|
+
i = n / c, r = -s / c;
|
|
2382
|
+
} else {
|
|
2383
|
+
const c = Math.sqrt(e * e + n * n);
|
|
2384
|
+
o = n / c, r = -e / c;
|
|
2385
|
+
}
|
|
2386
|
+
t[0] = i, t[1] = o, t[2] = r, t[3] = e * r - n * o, t[4] = n * i - s * r, t[5] = s * o - e * i;
|
|
2387
|
+
}
|
|
2388
|
+
function Qt(d, t, s, e) {
|
|
2389
|
+
const n = e[0], i = e[1], o = e[2], r = [0, -o, i, o, 0, -n, -i, n, 0];
|
|
2390
|
+
for (let c = 0; c < 3; c++)
|
|
2391
|
+
for (let a = 0; a < 3; a++) {
|
|
2392
|
+
let l = 0;
|
|
2393
|
+
for (let h = 0; h < 3; h++) {
|
|
2394
|
+
let _ = 0;
|
|
2395
|
+
for (let p = 0; p < 3; p++)
|
|
2396
|
+
_ += t[s + h * 3 + p] * r[a * 3 + p];
|
|
2397
|
+
l += r[c * 3 + h] * _;
|
|
2398
|
+
}
|
|
2399
|
+
d[c * 3 + a] += l;
|
|
2400
|
+
}
|
|
2401
|
+
}
|
|
2402
|
+
function Ct(d, t) {
|
|
2403
|
+
const s = t[0], e = t[1], n = t[2], i = t[3], o = t[4], r = t[5], c = t[6], a = t[7], l = t[8], h = s * (o * l - r * a) - e * (i * l - r * c) + n * (i * a - o * c);
|
|
2404
|
+
if (!(Math.abs(h) > 1e-30)) {
|
|
2405
|
+
d.fill(0);
|
|
2406
|
+
return;
|
|
2407
|
+
}
|
|
2408
|
+
const _ = 1 / h;
|
|
2409
|
+
d[0] = (o * l - r * a) * _, d[1] = (n * a - e * l) * _, d[2] = (e * r - n * o) * _, d[3] = (r * c - i * l) * _, d[4] = (s * l - n * c) * _, d[5] = (n * i - s * r) * _, d[6] = (i * a - o * c) * _, d[7] = (e * c - s * a) * _, d[8] = (s * o - e * i) * _;
|
|
2410
|
+
}
|
|
2411
|
+
function Zt(d, t, s, e, n, i, o, r, c) {
|
|
2412
|
+
let a = 0, l = c;
|
|
2413
|
+
for (let h = 0; h < 3; h++) {
|
|
2414
|
+
const _ = h === 0 ? s : h === 1 ? e : n, p = h === 0 ? i : h === 1 ? o : r, m = d[t + h], u = d[t + 3 + h];
|
|
2415
|
+
if (Math.abs(p) < 1e-15) {
|
|
2416
|
+
if (_ < m || _ > u)
|
|
2417
|
+
return !1;
|
|
2418
|
+
continue;
|
|
2419
|
+
}
|
|
2420
|
+
let f = (m - _) / p, y = (u - _) / p;
|
|
2421
|
+
if (f > y) {
|
|
2422
|
+
const w = f;
|
|
2423
|
+
f = y, y = w;
|
|
2424
|
+
}
|
|
2425
|
+
if (a = Math.max(a, f), l = Math.min(l, y), a > l)
|
|
2426
|
+
return !1;
|
|
2427
|
+
}
|
|
2428
|
+
return !0;
|
|
2429
|
+
}
|
|
2430
|
+
const js = ct({ velocityIterations: !0, positionCorrection: !0, linearSlop: !0, speculativeDistance: !0, restitutionThreshold: !0, sleepLinearVelocity: !0, sleepAngularVelocity: !0, timeToSleep: !0 });
|
|
2431
|
+
function he(d = {}) {
|
|
2432
|
+
dt(d, js, "basic physics");
|
|
2433
|
+
const t = et(d.velocityIterations, 10, 1, 100, "velocityIterations");
|
|
2434
|
+
if (!Number.isInteger(t))
|
|
2435
|
+
throw new F("invalid-option", "[Nova3D] Basic physics velocityIterations must be an integer.");
|
|
2436
|
+
const s = {
|
|
2437
|
+
velocityIterations: t,
|
|
2438
|
+
positionCorrection: et(d.positionCorrection, 0.2, 1e-6, 1, "positionCorrection"),
|
|
2439
|
+
linearSlop: et(d.linearSlop, 5e-3, 0, 1, "linearSlop"),
|
|
2440
|
+
speculativeDistance: et(d.speculativeDistance, 0.02, 0, 10, "speculativeDistance"),
|
|
2441
|
+
restitutionThreshold: et(d.restitutionThreshold, 0.5, 0, 1e6, "restitutionThreshold"),
|
|
2442
|
+
sleepLinearVelocity: et(d.sleepLinearVelocity, 0.05, 0, 1e6, "sleepLinearVelocity"),
|
|
2443
|
+
sleepAngularVelocity: et(d.sleepAngularVelocity, 0.05, 0, 1e6, "sleepAngularVelocity"),
|
|
2444
|
+
timeToSleep: et(d.timeToSleep, 0.5, 0, 1e6, "timeToSleep")
|
|
2445
|
+
}, e = Object.freeze({
|
|
2446
|
+
shapes: Object.freeze([...zs]),
|
|
2447
|
+
movingShapes: Object.freeze([...Ps]),
|
|
2448
|
+
joints: Object.freeze([...Ts]),
|
|
2449
|
+
sleeping: !0,
|
|
2450
|
+
deterministic: !0
|
|
2451
|
+
}), n = Object.freeze({
|
|
2452
|
+
name: "basic",
|
|
2453
|
+
capabilities: e,
|
|
2454
|
+
createWorld: (i) => new Rs(n, i, s)
|
|
2455
|
+
});
|
|
2456
|
+
return n;
|
|
2457
|
+
}
|
|
2458
|
+
const Os = ct({ color: !0 }), qt = 24, nt = 10, ts = 11;
|
|
2459
|
+
function at(d, t, s, e, n, i = 0, o = Math.PI * 2, r = qt) {
|
|
2460
|
+
for (let c = 0; c < r; c++)
|
|
2461
|
+
for (const a of [i + (o - i) * c / r, i + (o - i) * (c + 1) / r]) {
|
|
2462
|
+
const l = [n[0], n[1], n[2]];
|
|
2463
|
+
l[s] += Math.cos(a) * t, l[e] += Math.sin(a) * t, d.push(l[0], l[1], l[2]);
|
|
2464
|
+
}
|
|
2465
|
+
}
|
|
2466
|
+
function $s(d, t, s, e) {
|
|
2467
|
+
const [n, i, o, r] = d, c = r * t + i * e - o * s, a = r * s + o * t - n * e, l = r * e + n * s - i * t, h = -n * t - i * s - o * e;
|
|
2468
|
+
return [c * r - h * n - a * o + l * i, a * r - h * i - l * n + c * o, l * r - h * o - c * i + a * n];
|
|
2469
|
+
}
|
|
2470
|
+
function os(d) {
|
|
2471
|
+
const t = [];
|
|
2472
|
+
switch (d.type) {
|
|
2473
|
+
case "sphere":
|
|
2474
|
+
at(t, d.radius, 0, 1, [0, 0, 0]), at(t, d.radius, 0, 2, [0, 0, 0]), at(t, d.radius, 1, 2, [0, 0, 0]);
|
|
2475
|
+
break;
|
|
2476
|
+
case "box": {
|
|
2477
|
+
const [s, e, n] = d.halfExtents;
|
|
2478
|
+
for (let i = 0; i < 8; i++)
|
|
2479
|
+
for (let o = 0; o < 3; o++) {
|
|
2480
|
+
if (i & 1 << o)
|
|
2481
|
+
continue;
|
|
2482
|
+
const r = i | 1 << o;
|
|
2483
|
+
t.push(i & 1 ? s : -s, i & 2 ? e : -e, i & 4 ? n : -n, r & 1 ? s : -s, r & 2 ? e : -e, r & 4 ? n : -n);
|
|
2484
|
+
}
|
|
2485
|
+
break;
|
|
2486
|
+
}
|
|
2487
|
+
case "capsule":
|
|
2488
|
+
case "cylinder": {
|
|
2489
|
+
const s = d.radius, e = d.halfHeight;
|
|
2490
|
+
at(t, s, 0, 2, [0, e, 0]), at(t, s, 0, 2, [0, -e, 0]);
|
|
2491
|
+
for (const [n, i] of [[s, 0], [-s, 0], [0, s], [0, -s]])
|
|
2492
|
+
t.push(n, -e, i, n, e, i);
|
|
2493
|
+
if (d.type === "capsule")
|
|
2494
|
+
for (const n of [0, 2])
|
|
2495
|
+
at(t, s, n, 1, [0, e, 0], 0, Math.PI, qt / 2), at(t, s, n, 1, [0, -e, 0], Math.PI, Math.PI * 2, qt / 2);
|
|
2496
|
+
break;
|
|
2497
|
+
}
|
|
2498
|
+
case "plane": {
|
|
2499
|
+
const s = d.normal ?? [0, 1, 0], e = Math.hypot(s[0], s[1], s[2]), n = s[0] / e, i = s[1] / e, o = s[2] / e, r = d.offset ?? 0;
|
|
2500
|
+
let c = Math.abs(n) < 0.9 ? 0 : -o, a = Math.abs(n) < 0.9 ? o : 0, l = Math.abs(n) < 0.9 ? -i : n;
|
|
2501
|
+
const h = Math.hypot(c, a, l);
|
|
2502
|
+
c /= h, a /= h, l /= h;
|
|
2503
|
+
const _ = i * l - o * a, p = o * c - n * l, m = n * a - i * c;
|
|
2504
|
+
for (let u = 0; u < ts; u++) {
|
|
2505
|
+
const f = -nt + 2 * nt * u / (ts - 1);
|
|
2506
|
+
for (const [y, w, v, I, M, b] of [[c, a, l, _, p, m], [_, p, m, c, a, l]])
|
|
2507
|
+
t.push(n * r + y * f - I * nt, i * r + w * f - M * nt, o * r + v * f - b * nt), t.push(n * r + y * f + I * nt, i * r + w * f + M * nt, o * r + v * f + b * nt);
|
|
2508
|
+
}
|
|
2509
|
+
break;
|
|
2510
|
+
}
|
|
2511
|
+
case "convex-hull": {
|
|
2512
|
+
const s = ns(d.points);
|
|
2513
|
+
for (let e = 0; e < s.edgeCount; e++) {
|
|
2514
|
+
const n = s.edges[e * 2] * 3, i = s.edges[e * 2 + 1] * 3;
|
|
2515
|
+
t.push(s.vertices[n], s.vertices[n + 1], s.vertices[n + 2], s.vertices[i], s.vertices[i + 1], s.vertices[i + 2]);
|
|
2516
|
+
}
|
|
2517
|
+
break;
|
|
2518
|
+
}
|
|
2519
|
+
case "triangle-mesh": {
|
|
2520
|
+
const s = d.positions, e = d.indices ? d.indices.length : s.length / 3 - s.length / 3 % 3, n = (i) => (d.indices ? d.indices[i] : i) * 3;
|
|
2521
|
+
for (let i = 0; i + 2 < e; i += 3)
|
|
2522
|
+
for (let o = 0; o < 3; o++) {
|
|
2523
|
+
const r = n(i + o), c = n(i + (o + 1) % 3);
|
|
2524
|
+
t.push(s[r], s[r + 1], s[r + 2], s[c], s[c + 1], s[c + 2]);
|
|
2525
|
+
}
|
|
2526
|
+
break;
|
|
2527
|
+
}
|
|
2528
|
+
case "compound":
|
|
2529
|
+
for (const s of d.children) {
|
|
2530
|
+
const e = os(s.shape), n = s.quaternion ?? [0, 0, 0, 1], i = s.position ?? [0, 0, 0];
|
|
2531
|
+
for (let o = 0; o < e.length; o += 3) {
|
|
2532
|
+
const [r, c, a] = $s(n, e[o], e[o + 1], e[o + 2]);
|
|
2533
|
+
t.push(r + i[0], c + i[1], a + i[2]);
|
|
2534
|
+
}
|
|
2535
|
+
}
|
|
2536
|
+
break;
|
|
2537
|
+
}
|
|
2538
|
+
return new Float32Array(t);
|
|
2539
|
+
}
|
|
2540
|
+
class Ks extends ds {
|
|
2541
|
+
_templates = /* @__PURE__ */ new Map();
|
|
2542
|
+
_color;
|
|
2543
|
+
_part = null;
|
|
2544
|
+
_dirty = !0;
|
|
2545
|
+
_world = null;
|
|
2546
|
+
_pose = new Float64Array(7);
|
|
2547
|
+
constructor(t, s, e) {
|
|
2548
|
+
super(t, s), this._color = us(ps(e, "physics debug", Os).color, "#22ff88");
|
|
2549
|
+
}
|
|
2550
|
+
/** @internal */
|
|
2551
|
+
_add(t, s) {
|
|
2552
|
+
this._templates.set(t, os(s)), this._dirty = !0;
|
|
2553
|
+
}
|
|
2554
|
+
/** @internal */
|
|
2555
|
+
_remove(t) {
|
|
2556
|
+
this._templates.delete(t) && (this._dirty = !0);
|
|
2557
|
+
}
|
|
2558
|
+
/**
|
|
2559
|
+
* Writes every collider at its body pose and uploads the lines.
|
|
2560
|
+
* @internal
|
|
2561
|
+
*/
|
|
2562
|
+
_sync(t) {
|
|
2563
|
+
if (this._world = t, this.destroyed)
|
|
2564
|
+
return;
|
|
2565
|
+
this._dirty && this._rebuild();
|
|
2566
|
+
const s = this._part, e = s.positions, n = this._pose;
|
|
2567
|
+
let i = 0;
|
|
2568
|
+
for (const [o, r] of this._templates) {
|
|
2569
|
+
t.getTransform(o, n);
|
|
2570
|
+
const c = n[0], a = n[1], l = n[2], h = n[3], _ = n[4], p = n[5], m = n[6], u = 1 - 2 * (_ * _ + p * p), f = 2 * (h * _ - m * p), y = 2 * (h * p + m * _), w = 2 * (h * _ + m * p), v = 1 - 2 * (h * h + p * p), I = 2 * (_ * p - m * h), M = 2 * (h * p - m * _), b = 2 * (_ * p + m * h), A = 1 - 2 * (h * h + _ * _);
|
|
2571
|
+
for (let g = 0; g < r.length; g += 3) {
|
|
2572
|
+
const x = r[g], k = r[g + 1], S = r[g + 2];
|
|
2573
|
+
e[i++] = u * x + f * k + y * S + c, e[i++] = w * x + v * k + I * S + a, e[i++] = M * x + b * k + A * S + l;
|
|
2574
|
+
}
|
|
2575
|
+
}
|
|
2576
|
+
i > 0 && s.geometry.updateRange(0, s.columns);
|
|
2577
|
+
}
|
|
2578
|
+
/** @internal */
|
|
2579
|
+
_refresh() {
|
|
2580
|
+
this._world && !this._world.destroyed && this._sync(this._world);
|
|
2581
|
+
}
|
|
2582
|
+
_rebuild() {
|
|
2583
|
+
this._dirty = !1;
|
|
2584
|
+
let t = 0;
|
|
2585
|
+
for (const s of this._templates.values())
|
|
2586
|
+
t += s.length;
|
|
2587
|
+
if (this._part) {
|
|
2588
|
+
const s = this._part;
|
|
2589
|
+
this._parts.splice(this._parts.indexOf(s), 1), s.mesh.destroy(), s.geometry.destroy(), s.material.destroy(), this._part = null;
|
|
2590
|
+
}
|
|
2591
|
+
this._part = this._addPart(new Float32Array(Math.max(t, 6)), void 0, this._color, "dynamic"), this._part.mesh.setVisible(t > 0);
|
|
2592
|
+
}
|
|
2593
|
+
}
|
|
2594
|
+
const kt = 1, Z = 2, ss = 3, Us = [0, -9.81, 0], Js = ct({ backend: !0, gravity: !0, fixedStep: !0, maxSubSteps: !0, interpolate: !0, clock: !0, contactStay: !0, debug: !0 }), Gs = ct({ type: !0, shape: !0, mass: !0, linearDamping: !0, angularDamping: !0, friction: !0, restitution: !0, gravityScale: !0, linearVelocity: !0, angularVelocity: !0, collisionGroup: !0, collisionMask: !0, sensor: !0, canSleep: !0, start: !0, count: !0 }), Ws = ct({ friction: !0, restitution: !0 }), Xs = ct({ type: !0, bodyA: !0, bodyB: !0, anchor: !0, anchorB: !0, axis: !0, limits: !0, motor: !0, minDistance: !0, maxDistance: !0, collideConnected: !0 }), Ys = ct({ targetVelocity: !0, maxForce: !0 }), Qs = {
|
|
2595
|
+
sphere: /* @__PURE__ */ new Set(["type", "radius"]),
|
|
2596
|
+
box: /* @__PURE__ */ new Set(["type", "halfExtents"]),
|
|
2597
|
+
capsule: /* @__PURE__ */ new Set(["type", "radius", "halfHeight"]),
|
|
2598
|
+
cylinder: /* @__PURE__ */ new Set(["type", "radius", "halfHeight"]),
|
|
2599
|
+
plane: /* @__PURE__ */ new Set(["type", "normal", "offset"]),
|
|
2600
|
+
"convex-hull": /* @__PURE__ */ new Set(["type", "points"]),
|
|
2601
|
+
"triangle-mesh": /* @__PURE__ */ new Set(["type", "positions", "indices"]),
|
|
2602
|
+
compound: /* @__PURE__ */ new Set(["type", "children"])
|
|
2603
|
+
}, Zs = /* @__PURE__ */ new Set(["shape", "position", "quaternion"]);
|
|
2604
|
+
function rs(d) {
|
|
2605
|
+
const t = Qs[d.type];
|
|
2606
|
+
if (t && dt(d, t, `${d.type} shape`), d.type === "compound" && Array.isArray(d.children))
|
|
2607
|
+
for (const s of d.children)
|
|
2608
|
+
dt(s, Zs, "compound child"), rs(s.shape);
|
|
2609
|
+
}
|
|
2610
|
+
function as(d) {
|
|
2611
|
+
return d.quaternion ?? (d.rotation === void 0 ? void 0 : hs(d.rotation));
|
|
2612
|
+
}
|
|
2613
|
+
class It {
|
|
2614
|
+
/** @internal */
|
|
2615
|
+
constructor(t, s, e, n, i, o, r) {
|
|
2616
|
+
this.world = t, this.node = s, this.handle = e, this.shape = n, this._slot = i, this._friction = o, this._restitution = r;
|
|
2617
|
+
}
|
|
2618
|
+
/** @internal */
|
|
2619
|
+
_slot;
|
|
2620
|
+
_destroyed = !1;
|
|
2621
|
+
_friction;
|
|
2622
|
+
_restitution;
|
|
2623
|
+
/** Coulomb friction coefficient. */
|
|
2624
|
+
get friction() {
|
|
2625
|
+
return this._friction;
|
|
2626
|
+
}
|
|
2627
|
+
/** Restitution in [0, 1]. */
|
|
2628
|
+
get restitution() {
|
|
2629
|
+
return this._restitution;
|
|
2630
|
+
}
|
|
2631
|
+
get destroyed() {
|
|
2632
|
+
return this._destroyed || this.world.destroyed;
|
|
2633
|
+
}
|
|
2634
|
+
get type() {
|
|
2635
|
+
return this._backend().getBodyType(this.handle);
|
|
2636
|
+
}
|
|
2637
|
+
get sleeping() {
|
|
2638
|
+
return this._backend().getSleeping(this.handle);
|
|
2639
|
+
}
|
|
2640
|
+
/** Switches the motion type; the node keeps its current pose. */
|
|
2641
|
+
setType(t) {
|
|
2642
|
+
this.world._setBodyType(this, t);
|
|
2643
|
+
}
|
|
2644
|
+
getLinearVelocity() {
|
|
2645
|
+
return this._backend().getLinearVelocity(this.handle, [0, 0, 0]);
|
|
2646
|
+
}
|
|
2647
|
+
setLinearVelocity(t) {
|
|
2648
|
+
this._backend().setLinearVelocity(this.handle, t), this.world._kick();
|
|
2649
|
+
}
|
|
2650
|
+
getAngularVelocity() {
|
|
2651
|
+
return this._backend().getAngularVelocity(this.handle, [0, 0, 0]);
|
|
2652
|
+
}
|
|
2653
|
+
setAngularVelocity(t) {
|
|
2654
|
+
this._backend().setAngularVelocity(this.handle, t), this.world._kick();
|
|
2655
|
+
}
|
|
2656
|
+
applyForce(t, s) {
|
|
2657
|
+
this._backend().applyForce(this.handle, t, s), this.world._kick();
|
|
2658
|
+
}
|
|
2659
|
+
applyImpulse(t, s) {
|
|
2660
|
+
this._backend().applyImpulse(this.handle, t, s), this.world._kick();
|
|
2661
|
+
}
|
|
2662
|
+
applyTorque(t) {
|
|
2663
|
+
this._backend().applyTorque(this.handle, t), this.world._kick();
|
|
2664
|
+
}
|
|
2665
|
+
applyTorqueImpulse(t) {
|
|
2666
|
+
this._backend().applyTorqueImpulse(this.handle, t), this.world._kick();
|
|
2667
|
+
}
|
|
2668
|
+
setMass(t) {
|
|
2669
|
+
this._backend().setMass(this.handle, t);
|
|
2670
|
+
}
|
|
2671
|
+
/** Patches the surface material; omitted fields keep their value. */
|
|
2672
|
+
set(t) {
|
|
2673
|
+
dt(t, Ws, "physics body");
|
|
2674
|
+
const s = t.friction ?? this._friction, e = t.restitution ?? this._restitution;
|
|
2675
|
+
this._backend().setMaterial(this.handle, s, e), this._friction = s, this._restitution = e;
|
|
2676
|
+
}
|
|
2677
|
+
wake() {
|
|
2678
|
+
this._backend().wake(this.handle), this.world._kick();
|
|
2679
|
+
}
|
|
2680
|
+
/**
|
|
2681
|
+
* Teleports body and node to a world pose (`rotation` or `quaternion`); omitted
|
|
2682
|
+
* parts keep the current pose. `scale` changes only the node; the collider keeps
|
|
2683
|
+
* its shape.
|
|
2684
|
+
*/
|
|
2685
|
+
setTransform(t) {
|
|
2686
|
+
this.world._teleport(this, t);
|
|
2687
|
+
}
|
|
2688
|
+
/** Removes the body from the world; the node stays. */
|
|
2689
|
+
destroy() {
|
|
2690
|
+
this._destroyed || (this.world.destroyed || this.world._removeBody(this), this._destroyed = !0);
|
|
2691
|
+
}
|
|
2692
|
+
/** @internal */
|
|
2693
|
+
_markDestroyed() {
|
|
2694
|
+
this._destroyed = !0;
|
|
2695
|
+
}
|
|
2696
|
+
_backend() {
|
|
2697
|
+
if (this.destroyed)
|
|
2698
|
+
throw new F("destroyed", "[Nova3D] Physics body is destroyed.");
|
|
2699
|
+
return this.world._world;
|
|
2700
|
+
}
|
|
2701
|
+
}
|
|
2702
|
+
class Mt {
|
|
2703
|
+
/** @internal */
|
|
2704
|
+
constructor(t, s, e, n, i, o, r) {
|
|
2705
|
+
this.world = t, this.mesh = s, this.start = e, this.count = n, this.type = i, this.shape = o, this._handles = Array.from({ length: n }).fill(0), this._poses = new Float64Array(n * 10), this._current = new Float64Array(n * 7), this._previous = r ? new Float64Array(n * 7) : null;
|
|
2706
|
+
}
|
|
2707
|
+
/** @internal */
|
|
2708
|
+
_handles;
|
|
2709
|
+
/** @internal */
|
|
2710
|
+
_poses;
|
|
2711
|
+
/** @internal */
|
|
2712
|
+
_previous;
|
|
2713
|
+
/** @internal */
|
|
2714
|
+
_current;
|
|
2715
|
+
/** @internal */
|
|
2716
|
+
_owner = -1;
|
|
2717
|
+
_destroyed = !1;
|
|
2718
|
+
get destroyed() {
|
|
2719
|
+
return this._destroyed || this.world.destroyed;
|
|
2720
|
+
}
|
|
2721
|
+
/** Backend handle of instance `start + offset`. */
|
|
2722
|
+
handle(t) {
|
|
2723
|
+
return this._check(t), this._handles[t];
|
|
2724
|
+
}
|
|
2725
|
+
/** Whether the body of instance `start + offset` sleeps. */
|
|
2726
|
+
getSleeping(t) {
|
|
2727
|
+
return this._check(t), this.world._world.getSleeping(this._handles[t]);
|
|
2728
|
+
}
|
|
2729
|
+
applyImpulse(t, s, e) {
|
|
2730
|
+
this._check(t), this.world._world.applyImpulse(this._handles[t], s, e), this.world._kick();
|
|
2731
|
+
}
|
|
2732
|
+
setLinearVelocity(t, s) {
|
|
2733
|
+
this._check(t), this.world._world.setLinearVelocity(this._handles[t], s), this.world._kick();
|
|
2734
|
+
}
|
|
2735
|
+
/**
|
|
2736
|
+
* Teleports the body of instance `start + offset` to a world pose; omitted parts
|
|
2737
|
+
* keep the current pose. `scale` changes only the instance; the collider keeps its shape.
|
|
2738
|
+
*/
|
|
2739
|
+
setTransform(t, s) {
|
|
2740
|
+
this._check(t), es(s);
|
|
2741
|
+
const e = this._handles[t], n = this.world._world.getTransform(e, new Float64Array(7)), i = s.position ?? [n[0], n[1], n[2]], o = as(s) ?? [n[3], n[4], n[5], n[6]];
|
|
2742
|
+
this.world._world.setTransform(e, i, o), s.scale !== void 0 && (this.mesh.setTransform(this.start + t, { scale: s.scale }), this._poses.set(this.mesh.getTransform(this.start + t).scale, t * 10 + 7)), this.world._resetInstance(this, t), this.world._kick();
|
|
2743
|
+
}
|
|
2744
|
+
destroy() {
|
|
2745
|
+
this._destroyed || (this.world.destroyed || this.world._removeInstances(this), this._destroyed = !0);
|
|
2746
|
+
}
|
|
2747
|
+
/** @internal */
|
|
2748
|
+
_markDestroyed() {
|
|
2749
|
+
this._destroyed = !0;
|
|
2750
|
+
}
|
|
2751
|
+
_check(t) {
|
|
2752
|
+
if (this.destroyed)
|
|
2753
|
+
throw new F("destroyed", "[Nova3D] Physics instances are destroyed.");
|
|
2754
|
+
if (!Number.isInteger(t) || t < 0 || t >= this.count)
|
|
2755
|
+
throw new F("invalid-option", "[Nova3D] Physics instance offset out of range.");
|
|
2756
|
+
}
|
|
2757
|
+
}
|
|
2758
|
+
class te {
|
|
2759
|
+
/** @internal */
|
|
2760
|
+
constructor(t, s, e, n, i) {
|
|
2761
|
+
this.world = t, this.type = s, this.handle = e, this.bodyA = n, this.bodyB = i;
|
|
2762
|
+
}
|
|
2763
|
+
_destroyed = !1;
|
|
2764
|
+
get destroyed() {
|
|
2765
|
+
return this._destroyed || this.world.destroyed || this.bodyA.destroyed || (this.bodyB?.destroyed ?? !1);
|
|
2766
|
+
}
|
|
2767
|
+
/** Hinge and slider joints; null turns the motor off. */
|
|
2768
|
+
setMotor(t) {
|
|
2769
|
+
if (this.destroyed)
|
|
2770
|
+
throw new F("destroyed", "[Nova3D] Physics joint is destroyed.");
|
|
2771
|
+
this.world._world.setJointMotor(this.handle, t), this.world._kick();
|
|
2772
|
+
}
|
|
2773
|
+
destroy() {
|
|
2774
|
+
this._destroyed || (this._destroyed = !0, !this.world.destroyed && !this.bodyA.destroyed && !(this.bodyB?.destroyed ?? !1) && (this.world._world.destroyJoint(this.handle), this.world._kick()));
|
|
2775
|
+
}
|
|
2776
|
+
}
|
|
2777
|
+
function se(d, t, s, e) {
|
|
2778
|
+
const n = d ?? t;
|
|
2779
|
+
if (typeof n != "number" || !Number.isFinite(n) || n <= 0 || n > s)
|
|
2780
|
+
throw new F("invalid-option", `[Nova3D] Physics ${e} must be within (0, ${s}].`);
|
|
2781
|
+
return n;
|
|
2782
|
+
}
|
|
2783
|
+
function Bt(d, t, s, e, n, i) {
|
|
2784
|
+
const o = i[0];
|
|
2785
|
+
for (let a = 0; a < 3; a++)
|
|
2786
|
+
d[t + a] = s[n + a] + (e[n + a] - s[n + a]) * o;
|
|
2787
|
+
const r = s[n + 3] * e[n + 3] + s[n + 4] * e[n + 4] + s[n + 5] * e[n + 5] + s[n + 6] * e[n + 6] < 0 ? -1 : 1;
|
|
2788
|
+
let c = 0;
|
|
2789
|
+
for (let a = 3; a < 7; a++) {
|
|
2790
|
+
const l = s[n + a] + (e[n + a] * r - s[n + a]) * o;
|
|
2791
|
+
d[t + a] = l, c += l * l;
|
|
2792
|
+
}
|
|
2793
|
+
c = Math.sqrt(c);
|
|
2794
|
+
for (let a = 3; a < 7; a++)
|
|
2795
|
+
d[t + a] /= c;
|
|
2796
|
+
}
|
|
2797
|
+
class ee {
|
|
2798
|
+
/** @internal */
|
|
2799
|
+
constructor(t, s, e) {
|
|
2800
|
+
if (this._app = t, this.scene = s, !t || t.destroyed || typeof t._ownsScene != "function" || !t._ownsScene(s))
|
|
2801
|
+
throw new F("owner", "[Nova3D] Physics worlds need a live app and one of its scenes.");
|
|
2802
|
+
if (!e || typeof e != "object")
|
|
2803
|
+
throw new F("invalid-option", "[Nova3D] Physics world options are required.");
|
|
2804
|
+
for (const o of Object.keys(e))
|
|
2805
|
+
if (!Js.has(o))
|
|
2806
|
+
throw new F("invalid-option", `[Nova3D] Unknown physics world option ${o}.`);
|
|
2807
|
+
const n = e.backend;
|
|
2808
|
+
if (!n || typeof n.createWorld != "function" || !n.capabilities)
|
|
2809
|
+
throw new F("invalid-option", "[Nova3D] Physics world needs a backend.");
|
|
2810
|
+
this.backend = n, this.fixedStep = se(e.fixedStep, 1 / 60, 1, "fixedStep");
|
|
2811
|
+
const i = e.maxSubSteps ?? 4;
|
|
2812
|
+
if (!Number.isInteger(i) || i < 1 || i > 64)
|
|
2813
|
+
throw new F("invalid-option", "[Nova3D] Physics maxSubSteps must be an integer within [1, 64].");
|
|
2814
|
+
if (this.maxSubSteps = i, this.interpolate = e.interpolate ?? !1, this.clock = e.clock ?? "app", this.clock !== "app" && this.clock !== "manual")
|
|
2815
|
+
throw new F("invalid-option", "[Nova3D] Physics clock must be app or manual.");
|
|
2816
|
+
if (typeof this.interpolate != "boolean")
|
|
2817
|
+
throw new F("invalid-option", "[Nova3D] Physics interpolate must be boolean.");
|
|
2818
|
+
this._world = n.createWorld({ gravity: e.gravity ?? Us, contactStay: e.contactStay ?? !1 });
|
|
2819
|
+
try {
|
|
2820
|
+
e.debug && (this._debug = new Ks(t, s, e.debug === !0 ? {} : e.debug)), this._cleanup.push(t._own(() => this.destroy())), this.clock === "app" && this._cleanup.push(t.onUpdate(this._onFrame));
|
|
2821
|
+
} catch (o) {
|
|
2822
|
+
this._debug?.destroy(), this._world.destroy();
|
|
2823
|
+
for (const r of this._cleanup)
|
|
2824
|
+
r();
|
|
2825
|
+
throw o;
|
|
2826
|
+
}
|
|
2827
|
+
this._syncLease();
|
|
2828
|
+
}
|
|
2829
|
+
backend;
|
|
2830
|
+
/** @internal */
|
|
2831
|
+
_world;
|
|
2832
|
+
fixedStep;
|
|
2833
|
+
maxSubSteps;
|
|
2834
|
+
interpolate;
|
|
2835
|
+
clock;
|
|
2836
|
+
_destroyed = !1;
|
|
2837
|
+
_paused = !1;
|
|
2838
|
+
_accumulator = 0;
|
|
2839
|
+
/** Time handed to `_advance`; a field so the call never boxes it. */
|
|
2840
|
+
_delta = 0;
|
|
2841
|
+
_steps = 0;
|
|
2842
|
+
_awake = !0;
|
|
2843
|
+
_lease;
|
|
2844
|
+
_cleanup = [];
|
|
2845
|
+
_listeners = /* @__PURE__ */ new Set();
|
|
2846
|
+
/** Snapshot of `_listeners`, rebuilt on change, iterated without allocation. */
|
|
2847
|
+
_listenerList = [];
|
|
2848
|
+
// Node bodies, structure of arrays by slot.
|
|
2849
|
+
_capacity = 0;
|
|
2850
|
+
_bodies = [];
|
|
2851
|
+
_kinds = new Uint8Array(0);
|
|
2852
|
+
_previous = new Float64Array(0);
|
|
2853
|
+
_current = new Float64Array(0);
|
|
2854
|
+
_written = new Float64Array(0);
|
|
2855
|
+
_kinematicStart = new Float64Array(0);
|
|
2856
|
+
_kinematicEnd = new Float64Array(0);
|
|
2857
|
+
_freeSlots = [];
|
|
2858
|
+
_slotCount = 0;
|
|
2859
|
+
_kinematicCount = 0;
|
|
2860
|
+
_instances = [];
|
|
2861
|
+
_boundNodes = /* @__PURE__ */ new Set();
|
|
2862
|
+
/** Handle → owner index · 2²² + instance offset. */
|
|
2863
|
+
_lookup = /* @__PURE__ */ new Map();
|
|
2864
|
+
_owners = [];
|
|
2865
|
+
_freeOwners = [];
|
|
2866
|
+
_debug = null;
|
|
2867
|
+
// Scratch.
|
|
2868
|
+
_matrix = Et();
|
|
2869
|
+
_inverse = Et();
|
|
2870
|
+
_rotation = ls();
|
|
2871
|
+
_pose = new Float64Array(7);
|
|
2872
|
+
/** Blend weight read by `blendPose`, kept in an array so no call boxes it. */
|
|
2873
|
+
_weight = new Float64Array(1);
|
|
2874
|
+
_position = [0, 0, 0];
|
|
2875
|
+
_quaternion = [0, 0, 0, 1];
|
|
2876
|
+
_patch = { position: this._position, quaternion: this._quaternion };
|
|
2877
|
+
_rayHit = { body: 0, distance: 0, point: [0, 0, 0], normal: [0, 0, 0] };
|
|
2878
|
+
_refA = { handle: 0, body: null, instances: null, index: -1 };
|
|
2879
|
+
_refB = { handle: 0, body: null, instances: null, index: -1 };
|
|
2880
|
+
_contact = { phase: "begin", a: this._refA, b: this._refB, point: new Float64Array(3), normal: new Float64Array(3), impulse: 0, sensor: !1 };
|
|
2881
|
+
_onEvent = (t) => {
|
|
2882
|
+
if (!this._resolveRef(t.bodyA, this._refA) || !this._resolveRef(t.bodyB, this._refB))
|
|
2883
|
+
return;
|
|
2884
|
+
const s = this._contact;
|
|
2885
|
+
s.phase = t.phase, s.point = t.point, s.normal = t.normal, s.impulse = t.impulse, s.sensor = t.sensor;
|
|
2886
|
+
const e = this._listenerList;
|
|
2887
|
+
for (let n = 0; n < e.length; n++)
|
|
2888
|
+
e[n](s);
|
|
2889
|
+
};
|
|
2890
|
+
_onFrame = (t) => {
|
|
2891
|
+
if (!this._destroyed) {
|
|
2892
|
+
if (this.scene.destroyed) {
|
|
2893
|
+
this.destroy();
|
|
2894
|
+
return;
|
|
2895
|
+
}
|
|
2896
|
+
this._paused || (this._delta = t.deltaTime, this._advance());
|
|
2897
|
+
}
|
|
2898
|
+
};
|
|
2899
|
+
get destroyed() {
|
|
2900
|
+
return this._destroyed;
|
|
2901
|
+
}
|
|
2902
|
+
get paused() {
|
|
2903
|
+
return this._paused;
|
|
2904
|
+
}
|
|
2905
|
+
/** Remainder of the accumulator as a fraction of `fixedStep`, the interpolation factor. */
|
|
2906
|
+
get alpha() {
|
|
2907
|
+
return this._accumulator / this.fixedStep;
|
|
2908
|
+
}
|
|
2909
|
+
/** Fixed steps taken since creation. */
|
|
2910
|
+
get stepCount() {
|
|
2911
|
+
return this._steps;
|
|
2912
|
+
}
|
|
2913
|
+
/** Debug line helper when the world was created with `debug`. */
|
|
2914
|
+
get debug() {
|
|
2915
|
+
return this._debug;
|
|
2916
|
+
}
|
|
2917
|
+
setPaused(t) {
|
|
2918
|
+
if (this._assertAlive(), typeof t != "boolean")
|
|
2919
|
+
throw new F("invalid-option", "[Nova3D] Physics paused must be boolean.");
|
|
2920
|
+
this._paused = t, this._syncLease();
|
|
2921
|
+
}
|
|
2922
|
+
getGravity() {
|
|
2923
|
+
return this._assertAlive(), this._world.getGravity([0, 0, 0]);
|
|
2924
|
+
}
|
|
2925
|
+
setGravity(t) {
|
|
2926
|
+
this._assertAlive(), this._world.setGravity(t), this._kick();
|
|
2927
|
+
}
|
|
2928
|
+
/**
|
|
2929
|
+
* Binds a body to `node` at the node's world pose (scale is not applied to the shape).
|
|
2930
|
+
* Dynamic bodies write the node's local position and rotation after every update;
|
|
2931
|
+
* kinematic bodies follow the node; static bodies keep their pose until `setTransform`.
|
|
2932
|
+
* Owned by the world: destroyed with it or with its node.
|
|
2933
|
+
*/
|
|
2934
|
+
createBody(t, s) {
|
|
2935
|
+
if (this._assertAlive(), !(t instanceof Vt) || t.destroyed || t.scene !== this.scene)
|
|
2936
|
+
throw new F("owner", "[Nova3D] Physics bodies need a live node of the world scene.");
|
|
2937
|
+
if (this._boundNodes.has(t))
|
|
2938
|
+
throw new F("state", "[Nova3D] Node already has a physics body.");
|
|
2939
|
+
const e = this._describe(s, !1);
|
|
2940
|
+
this._readNodePose(t, this._pose);
|
|
2941
|
+
const n = this._world.createBody({ ...e, position: [this._pose[0], this._pose[1], this._pose[2]], quaternion: [this._pose[3], this._pose[4], this._pose[5], this._pose[6]] });
|
|
2942
|
+
let i = this._freeSlots.pop();
|
|
2943
|
+
i === void 0 && (i = this._slotCount++, this._reserve(this._slotCount));
|
|
2944
|
+
const o = new It(this, t, n, e.shape, i, e.friction ?? 0.5, e.restitution ?? 0);
|
|
2945
|
+
this._bodies[i] = o, this._boundNodes.add(t);
|
|
2946
|
+
const r = e.type === "dynamic" ? kt : e.type === "kinematic" ? Z : ss;
|
|
2947
|
+
this._kinds[i] = r, r === Z && this._kinematicCount++;
|
|
2948
|
+
for (const c of [this._previous, this._current, this._written, this._kinematicStart, this._kinematicEnd])
|
|
2949
|
+
c.set(this._pose, i * 7);
|
|
2950
|
+
return this._register(n, o, 0), this._debug?._add(n, e.shape), this._kick(), o;
|
|
2951
|
+
}
|
|
2952
|
+
/**
|
|
2953
|
+
* Creates one body per instance of `mesh` in `[start, start + count)` at the current
|
|
2954
|
+
* instance poses. After every update the poses are written back with one
|
|
2955
|
+
* `updatePoses` call; instance scale is kept. No objects are created per body.
|
|
2956
|
+
* Owned by the world: destroyed with it or with its node.
|
|
2957
|
+
*/
|
|
2958
|
+
createInstancedBodies(t, s) {
|
|
2959
|
+
if (this._assertAlive(), !(t instanceof cs) || t.destroyed || t.scene !== this.scene)
|
|
2960
|
+
throw new F("owner", "[Nova3D] Instanced bodies need a live instanced mesh of the world scene.");
|
|
2961
|
+
const e = s?.type ?? "dynamic";
|
|
2962
|
+
if (e !== "dynamic" && e !== "static")
|
|
2963
|
+
throw new F("invalid-option", "[Nova3D] Instanced bodies must be dynamic or static.");
|
|
2964
|
+
const n = s.start ?? 0, i = s.count ?? t.count - n;
|
|
2965
|
+
if (!Number.isInteger(n) || !Number.isInteger(i) || n < 0 || i < 1 || n + i > t.capacity)
|
|
2966
|
+
throw new F("budget", "[Nova3D] Instanced body range exceeds the mesh capacity.");
|
|
2967
|
+
for (let a = 0; a < this._instances.length; a++) {
|
|
2968
|
+
const l = this._instances[a];
|
|
2969
|
+
if (l.mesh === t && n < l.start + l.count && l.start < n + i)
|
|
2970
|
+
throw new F("state", "[Nova3D] Instances already have physics bodies.");
|
|
2971
|
+
}
|
|
2972
|
+
const o = this._describe(s, !0), r = new Mt(this, t, n, i, e, o.shape, this.interpolate);
|
|
2973
|
+
this._meshWorld(t);
|
|
2974
|
+
const c = [];
|
|
2975
|
+
try {
|
|
2976
|
+
for (let a = 0; a < i; a++) {
|
|
2977
|
+
const l = t.getTransform(n + a), h = a * 10;
|
|
2978
|
+
r._poses.set(l.position, h), r._poses.set(l.quaternion, h + 3), r._poses.set(l.scale, h + 7), this._toWorld(r._poses, h, this._pose);
|
|
2979
|
+
const _ = this._world.createBody({ ...o, position: [this._pose[0], this._pose[1], this._pose[2]], quaternion: [this._pose[3], this._pose[4], this._pose[5], this._pose[6]] });
|
|
2980
|
+
c.push(_), r._handles[a] = _, r._current.set(this._pose, a * 7), r._previous?.set(this._pose, a * 7);
|
|
2981
|
+
}
|
|
2982
|
+
} catch (a) {
|
|
2983
|
+
for (const l of c)
|
|
2984
|
+
this._world.destroyBody(l);
|
|
2985
|
+
throw a;
|
|
2986
|
+
}
|
|
2987
|
+
this._instances.push(r);
|
|
2988
|
+
for (let a = 0; a < i; a++)
|
|
2989
|
+
this._register(r._handles[a], r, a), this._debug?._add(r._handles[a], o.shape);
|
|
2990
|
+
return this._kick(), r;
|
|
2991
|
+
}
|
|
2992
|
+
/** Owned by the world: destroyed with it or with either body. */
|
|
2993
|
+
createJoint(t) {
|
|
2994
|
+
this._assertAlive(), dt(t, Xs, "physics joint"), t.motor !== void 0 && dt(t.motor, Ys, "physics joint motor");
|
|
2995
|
+
const s = t.bodyA, e = t.bodyB ?? null;
|
|
2996
|
+
for (const m of [s, e])
|
|
2997
|
+
if (m !== null && (!(m instanceof It) || m.world !== this || m.destroyed))
|
|
2998
|
+
throw new F("owner", "[Nova3D] Joint bodies must be live bodies of this world.");
|
|
2999
|
+
if (!this.backend.capabilities.joints.includes(t.type))
|
|
3000
|
+
throw new F("unsupported", `[Nova3D] The ${this.backend.name} physics backend does not support ${String(t.type)} joints.`);
|
|
3001
|
+
const n = this._world.getTransform(s.handle, new Float64Array(7)), i = e ? this._world.getTransform(e.handle, new Float64Array(7)) : new Float64Array([0, 0, 0, 0, 0, 0, 1]), o = t.anchor ?? [n[0], n[1], n[2]], r = t.type === "distance" ? t.anchorB ?? (e ? [i[0], i[1], i[2]] : o) : o, c = (m, u, f) => {
|
|
3002
|
+
const y = f ? u[0] : u[0] - m[0], w = f ? u[1] : u[1] - m[1], v = f ? u[2] : u[2] - m[2], I = -m[3], M = -m[4], b = -m[5], A = m[6], g = A * y + M * v - b * w, x = A * w + b * y - I * v, k = A * v + I * w - M * y, S = -I * y - M * w - b * v;
|
|
3003
|
+
return [g * A - S * I - x * b + k * M, x * A - S * M - k * I + g * b, k * A - S * b - g * M + x * I];
|
|
3004
|
+
}, a = { bodyA: s.handle, bodyB: e ? e.handle : null, collideConnected: t.collideConnected ?? !1 };
|
|
3005
|
+
let l;
|
|
3006
|
+
const h = c(n, o, !1), _ = e ? c(i, r, !1) : r;
|
|
3007
|
+
switch (t.type) {
|
|
3008
|
+
case "fixed":
|
|
3009
|
+
case "ball":
|
|
3010
|
+
l = { ...a, type: t.type, anchorA: h, anchorB: _ };
|
|
3011
|
+
break;
|
|
3012
|
+
case "hinge":
|
|
3013
|
+
case "slider": {
|
|
3014
|
+
const m = t.axis;
|
|
3015
|
+
if (!m)
|
|
3016
|
+
throw new F("invalid-option", "[Nova3D] Hinge and slider joints need an axis.");
|
|
3017
|
+
l = { ...a, type: t.type, anchorA: h, anchorB: _, axisA: c(n, m, !0), axisB: e ? c(i, m, !0) : m, limits: t.limits, motor: t.motor };
|
|
3018
|
+
break;
|
|
3019
|
+
}
|
|
3020
|
+
case "distance": {
|
|
3021
|
+
const m = Math.hypot(r[0] - o[0], r[1] - o[1], r[2] - o[2]);
|
|
3022
|
+
l = { ...a, type: "distance", anchorA: h, anchorB: _, minDistance: t.minDistance ?? m, maxDistance: t.maxDistance ?? m };
|
|
3023
|
+
break;
|
|
3024
|
+
}
|
|
3025
|
+
default:
|
|
3026
|
+
throw new F("invalid-option", "[Nova3D] Unsupported physics joint type.");
|
|
3027
|
+
}
|
|
3028
|
+
const p = this._world.createJoint(l);
|
|
3029
|
+
return this._kick(), new te(this, t.type, p, s, e);
|
|
3030
|
+
}
|
|
3031
|
+
/** Listens to contact events after every fixed step; the record is reused between calls. */
|
|
3032
|
+
onContact(t) {
|
|
3033
|
+
if (this._assertAlive(), typeof t != "function")
|
|
3034
|
+
throw new F("invalid-option", "[Nova3D] Contact listener must be a function.");
|
|
3035
|
+
return this._listeners.add(t), this._listenerList = [...this._listeners], () => {
|
|
3036
|
+
this._listeners.delete(t), this._listenerList = [...this._listeners];
|
|
3037
|
+
};
|
|
3038
|
+
}
|
|
3039
|
+
/** Nearest body hit along the ray, in world space. */
|
|
3040
|
+
raycast(t, s = {}) {
|
|
3041
|
+
if (this._assertAlive(), !t || typeof t != "object")
|
|
3042
|
+
throw new F("invalid-option", "[Nova3D] Ray is required.");
|
|
3043
|
+
const e = this._rayHit;
|
|
3044
|
+
if (!this._world.raycast(t.origin, t.direction, s.maxDistance ?? 1 / 0, s.mask ?? 4294967295, e))
|
|
3045
|
+
return null;
|
|
3046
|
+
const n = { handle: 0, body: null, instances: null, index: -1 };
|
|
3047
|
+
return this._resolveRef(e.body, n) ? Object.freeze({ ...n, distance: e.distance, point: [e.point[0], e.point[1], e.point[2]], normal: [e.normal[0], e.normal[1], e.normal[2]] }) : null;
|
|
3048
|
+
}
|
|
3049
|
+
/** Manual clock: advances by `deltaTime` seconds through the fixed-step accumulator. */
|
|
3050
|
+
update(t) {
|
|
3051
|
+
if (this._assertAlive(), this.clock !== "manual")
|
|
3052
|
+
throw new F("state", "[Nova3D] update is only available with the manual clock.");
|
|
3053
|
+
if (!(typeof t == "number" && Number.isFinite(t) && t >= 0))
|
|
3054
|
+
throw new F("invalid-option", "[Nova3D] Physics deltaTime must be a nonnegative finite number.");
|
|
3055
|
+
this._paused || (this._delta = t, this._advance());
|
|
3056
|
+
}
|
|
3057
|
+
destroy() {
|
|
3058
|
+
if (!this._destroyed) {
|
|
3059
|
+
this._destroyed = !0, this._lease?.release(), this._lease = void 0;
|
|
3060
|
+
for (const t of this._cleanup.splice(0))
|
|
3061
|
+
t();
|
|
3062
|
+
this._listeners.clear(), this._listenerList = [], this._debug?.destroy(), this._debug = null;
|
|
3063
|
+
for (const t of this._bodies)
|
|
3064
|
+
t?._markDestroyed();
|
|
3065
|
+
for (let t = 0; t < this._instances.length; t++)
|
|
3066
|
+
this._instances[t]._markDestroyed();
|
|
3067
|
+
this._bodies = [], this._boundNodes.clear(), this._instances.length = 0, this._lookup.clear(), this._owners.length = 0, this._world.destroy();
|
|
3068
|
+
}
|
|
3069
|
+
}
|
|
3070
|
+
// ---------------------------------------------------------------- internal
|
|
3071
|
+
/** @internal */
|
|
3072
|
+
_kick() {
|
|
3073
|
+
this._awake = !0, this._syncLease();
|
|
3074
|
+
}
|
|
3075
|
+
/** @internal */
|
|
3076
|
+
_setBodyType(t, s) {
|
|
3077
|
+
if (this._assertBody(t), s !== "static" && !this.backend.capabilities.movingShapes.includes(t.shape.type))
|
|
3078
|
+
throw new F("invalid-option", `[Nova3D] The ${this.backend.name} physics backend cannot move ${t.shape.type} shapes.`);
|
|
3079
|
+
this._world.setBodyType(t.handle, s);
|
|
3080
|
+
const e = t._slot;
|
|
3081
|
+
this._kinds[e] === Z && this._kinematicCount--;
|
|
3082
|
+
const n = s === "dynamic" ? kt : s === "kinematic" ? Z : ss;
|
|
3083
|
+
this._kinds[e] = n, n === Z && this._kinematicCount++, this._world.getTransform(t.handle, this._current, e * 7), this._previous.set(this._current.subarray(e * 7, e * 7 + 7), e * 7), this._kinematicStart.set(this._current.subarray(e * 7, e * 7 + 7), e * 7), this._kinematicEnd.set(this._current.subarray(e * 7, e * 7 + 7), e * 7), this._kick();
|
|
3084
|
+
}
|
|
3085
|
+
/** @internal */
|
|
3086
|
+
_teleport(t, s) {
|
|
3087
|
+
this._assertBody(t), es(s);
|
|
3088
|
+
const e = t._slot, n = this._world.getTransform(t.handle, this._pose), i = s.position ?? [n[0], n[1], n[2]], o = as(s) ?? [n[3], n[4], n[5], n[6]];
|
|
3089
|
+
s.scale !== void 0 && t.node.setTransform({ scale: s.scale }), this._world.setTransform(t.handle, i, o), this._world.getTransform(t.handle, this._current, e * 7);
|
|
3090
|
+
for (const r of [this._previous, this._kinematicStart, this._kinematicEnd])
|
|
3091
|
+
r.set(this._current.subarray(e * 7, e * 7 + 7), e * 7);
|
|
3092
|
+
this._writeNode(t, this._current, e * 7), this._kick();
|
|
3093
|
+
}
|
|
3094
|
+
/** @internal */
|
|
3095
|
+
_resetInstance(t, s) {
|
|
3096
|
+
this._world.getTransform(t._handles[s], t._current, s * 7), t._previous?.set(t._current.subarray(s * 7, s * 7 + 7), s * 7);
|
|
3097
|
+
}
|
|
3098
|
+
/** @internal */
|
|
3099
|
+
_removeBody(t) {
|
|
3100
|
+
const s = t._slot;
|
|
3101
|
+
this._bodies[s] === t && (this._kinds[s] === Z && this._kinematicCount--, this._unregister(t.handle), this._debug?._remove(t.handle), this._world.destroyBody(t.handle), this._bodies[s] = null, this._boundNodes.delete(t.node), this._kinds[s] = 0, this._freeSlots.push(s), this._kick());
|
|
3102
|
+
}
|
|
3103
|
+
/** @internal */
|
|
3104
|
+
_removeInstances(t) {
|
|
3105
|
+
const s = this._instances.indexOf(t);
|
|
3106
|
+
if (!(s < 0)) {
|
|
3107
|
+
this._instances.splice(s, 1);
|
|
3108
|
+
for (let e = 0; e < t.count; e++)
|
|
3109
|
+
this._unregister(t._handles[e]), this._debug?._remove(t._handles[e]), this._world.destroyBody(t._handles[e]);
|
|
3110
|
+
this._kick();
|
|
3111
|
+
}
|
|
3112
|
+
}
|
|
3113
|
+
_describe(t, s) {
|
|
3114
|
+
if (!t || typeof t != "object")
|
|
3115
|
+
throw new F("invalid-option", "[Nova3D] Physics body options are required.");
|
|
3116
|
+
for (const a of Object.keys(t))
|
|
3117
|
+
if (!Gs.has(a) || !s && (a === "start" || a === "count"))
|
|
3118
|
+
throw new F("invalid-option", `[Nova3D] Unknown physics body option ${a}.`);
|
|
3119
|
+
t.shape && typeof t.shape == "object" && rs(t.shape);
|
|
3120
|
+
const e = t.type ?? "dynamic", n = t.shape;
|
|
3121
|
+
if (!n || typeof n != "object")
|
|
3122
|
+
throw new F("invalid-option", "[Nova3D] Physics bodies need a shape.");
|
|
3123
|
+
const i = this.backend.capabilities;
|
|
3124
|
+
if (!i.shapes.includes(n.type))
|
|
3125
|
+
throw new F("unsupported", `[Nova3D] The ${this.backend.name} physics backend does not support ${String(n.type)} shapes.`);
|
|
3126
|
+
if (e !== "static" && !i.movingShapes.includes(n.type))
|
|
3127
|
+
throw new F("invalid-option", `[Nova3D] The ${this.backend.name} physics backend cannot move ${n.type} shapes.`);
|
|
3128
|
+
const { start: o, count: r, ...c } = t;
|
|
3129
|
+
return { ...c, type: e, shape: n };
|
|
3130
|
+
}
|
|
3131
|
+
_register(t, s, e) {
|
|
3132
|
+
let n;
|
|
3133
|
+
s instanceof Mt && s._owner >= 0 ? n = s._owner : (n = this._freeOwners.pop() ?? this._owners.length, this._owners[n] = s, s instanceof Mt && (s._owner = n)), this._lookup.set(t, n * 4194304 + e);
|
|
3134
|
+
}
|
|
3135
|
+
_unregister(t) {
|
|
3136
|
+
const s = this._lookup.get(t);
|
|
3137
|
+
if (s === void 0)
|
|
3138
|
+
return;
|
|
3139
|
+
this._lookup.delete(t);
|
|
3140
|
+
const e = Math.floor(s / 4194304), n = this._owners[e];
|
|
3141
|
+
if (n instanceof Mt) {
|
|
3142
|
+
for (let i = 0; i < n.count; i++)
|
|
3143
|
+
if (this._lookup.has(n._handles[i]))
|
|
3144
|
+
return;
|
|
3145
|
+
}
|
|
3146
|
+
this._owners[e] = null, this._freeOwners.push(e);
|
|
3147
|
+
}
|
|
3148
|
+
_resolveRef(t, s) {
|
|
3149
|
+
const e = this._lookup.get(t);
|
|
3150
|
+
if (e === void 0)
|
|
3151
|
+
return !1;
|
|
3152
|
+
const n = this._owners[Math.floor(e / 4194304)];
|
|
3153
|
+
return s.handle = t, n instanceof It ? (s.body = n, s.instances = null, s.index = -1) : (s.body = null, s.instances = n, s.index = n ? n.start + e % 4194304 : -1), n !== null;
|
|
3154
|
+
}
|
|
3155
|
+
_reserve(t) {
|
|
3156
|
+
if (t <= this._capacity)
|
|
3157
|
+
return;
|
|
3158
|
+
const s = Math.max(t, this._capacity * 2, 16), e = (i, o) => {
|
|
3159
|
+
const r = new Float64Array(s * o);
|
|
3160
|
+
return r.set(i), r;
|
|
3161
|
+
};
|
|
3162
|
+
this._previous = e(this._previous, 7), this._current = e(this._current, 7), this._written = e(this._written, 7), this._kinematicStart = e(this._kinematicStart, 7), this._kinematicEnd = e(this._kinematicEnd, 7);
|
|
3163
|
+
const n = new Uint8Array(s);
|
|
3164
|
+
n.set(this._kinds), this._kinds = n, this._capacity = s;
|
|
3165
|
+
}
|
|
3166
|
+
/** Runs whole fixed steps for the accumulated time, then syncs nodes and instances. */
|
|
3167
|
+
_advance() {
|
|
3168
|
+
const t = this._delta;
|
|
3169
|
+
if (this.scene.destroyed) {
|
|
3170
|
+
this.destroy();
|
|
3171
|
+
return;
|
|
3172
|
+
}
|
|
3173
|
+
const s = this.fixedStep;
|
|
3174
|
+
this._accumulator += Math.min(t, s * this.maxSubSteps * 2);
|
|
3175
|
+
let e = Math.floor(this._accumulator / s + 1e-9);
|
|
3176
|
+
if (e > this.maxSubSteps ? (e = this.maxSubSteps, this._accumulator = this._accumulator % s) : this._accumulator = Math.max(0, this._accumulator - e * s), e > 0) {
|
|
3177
|
+
this._readKinematicNodes();
|
|
3178
|
+
for (let n = 0; n < e; n++)
|
|
3179
|
+
if (this._weight[0] = (n + 1) / e, this._driveKinematic(), n === e - 1 && this.interpolate && this._readPoses(!0), this._world.step(s), this._steps++, this._listeners.size > 0 ? this._world.drainContacts(this._onEvent) : this._world.drainContacts(ne), this._destroyed)
|
|
3180
|
+
return;
|
|
3181
|
+
this._finishKinematic(), this._readPoses(!1);
|
|
3182
|
+
}
|
|
3183
|
+
this._sync();
|
|
3184
|
+
}
|
|
3185
|
+
/** Reads the world pose of every kinematic node once per update. */
|
|
3186
|
+
_readKinematicNodes() {
|
|
3187
|
+
if (this._kinematicCount !== 0)
|
|
3188
|
+
for (let t = 0; t < this._slotCount; t++) {
|
|
3189
|
+
const s = this._bodies[t];
|
|
3190
|
+
s && this._kinds[t] === Z && !s.node.destroyed && (this._readNodePose(s.node, this._pose), this._kinematicEnd.set(this._pose, t * 7));
|
|
3191
|
+
}
|
|
3192
|
+
}
|
|
3193
|
+
/** Targets the share `t` of this update's kinematic motion. */
|
|
3194
|
+
_driveKinematic() {
|
|
3195
|
+
if (this._kinematicCount === 0)
|
|
3196
|
+
return;
|
|
3197
|
+
const t = this._pose;
|
|
3198
|
+
for (let s = 0; s < this._slotCount; s++)
|
|
3199
|
+
this._kinds[s] !== Z || !this._bodies[s] || (Bt(t, 0, this._kinematicStart, this._kinematicEnd, s * 7, this._weight), this._position[0] = t[0], this._position[1] = t[1], this._position[2] = t[2], this._quaternion[0] = t[3], this._quaternion[1] = t[4], this._quaternion[2] = t[5], this._quaternion[3] = t[6], this._world.setKinematicTarget(this._bodies[s].handle, this._position, this._quaternion));
|
|
3200
|
+
}
|
|
3201
|
+
_finishKinematic() {
|
|
3202
|
+
if (this._kinematicCount > 0)
|
|
3203
|
+
for (let t = 0; t < this._slotCount; t++)
|
|
3204
|
+
this._kinds[t] === Z && zt(this._kinematicStart, t * 7, this._kinematicEnd, t * 7);
|
|
3205
|
+
}
|
|
3206
|
+
/** Reads dynamic poses into `previous` (before the last step) or `current`. */
|
|
3207
|
+
_readPoses(t) {
|
|
3208
|
+
const s = this._world, e = t ? this._previous : this._current;
|
|
3209
|
+
for (let n = 0; n < this._slotCount; n++) {
|
|
3210
|
+
const i = this._bodies[n];
|
|
3211
|
+
i && this._kinds[n] === kt && s.getTransform(i.handle, e, n * 7);
|
|
3212
|
+
}
|
|
3213
|
+
for (let n = 0; n < this._instances.length; n++) {
|
|
3214
|
+
const i = this._instances[n];
|
|
3215
|
+
if (i.type !== "dynamic")
|
|
3216
|
+
continue;
|
|
3217
|
+
const o = t ? i._previous : i._current;
|
|
3218
|
+
for (let r = 0; r < i.count; r++)
|
|
3219
|
+
s.getTransform(i._handles[r], o, r * 7);
|
|
3220
|
+
}
|
|
3221
|
+
}
|
|
3222
|
+
/** Writes rendered poses to nodes and instance meshes, and refreshes debug lines. */
|
|
3223
|
+
_sync() {
|
|
3224
|
+
this._weight[0] = this.interpolate ? this._accumulator / this.fixedStep : 1;
|
|
3225
|
+
const t = this._pose;
|
|
3226
|
+
let s = this._kinematicCount > 0;
|
|
3227
|
+
for (let e = 0; e < this._slotCount; e++) {
|
|
3228
|
+
const n = this._bodies[e];
|
|
3229
|
+
if (!n || this._kinds[e] !== kt)
|
|
3230
|
+
continue;
|
|
3231
|
+
if (n.node.destroyed) {
|
|
3232
|
+
n.destroy();
|
|
3233
|
+
continue;
|
|
3234
|
+
}
|
|
3235
|
+
this._world.getSleeping(n.handle) || (s = !0), this.interpolate ? Bt(t, 0, this._previous, this._current, e * 7, this._weight) : zt(t, 0, this._current, e * 7);
|
|
3236
|
+
const i = this._written, o = e * 7;
|
|
3237
|
+
t[0] === i[o] && t[1] === i[o + 1] && t[2] === i[o + 2] && t[3] === i[o + 3] && t[4] === i[o + 4] && t[5] === i[o + 5] && t[6] === i[o + 6] || (i.set(t, o), this._writeNode(n, t, 0));
|
|
3238
|
+
}
|
|
3239
|
+
for (let e = this._instances.length - 1; e >= 0; e--) {
|
|
3240
|
+
const n = this._instances[e];
|
|
3241
|
+
if (n.mesh.destroyed) {
|
|
3242
|
+
n.destroy();
|
|
3243
|
+
continue;
|
|
3244
|
+
}
|
|
3245
|
+
if (n.type !== "dynamic")
|
|
3246
|
+
continue;
|
|
3247
|
+
const i = this._meshWorld(n.mesh), o = n._poses;
|
|
3248
|
+
let r = !1;
|
|
3249
|
+
for (let c = 0; c < n.count; c++) {
|
|
3250
|
+
this._world.getSleeping(n._handles[c]) || (s = !0), n._previous ? Bt(t, 0, n._previous, n._current, c * 7, this._weight) : zt(t, 0, n._current, c * 7);
|
|
3251
|
+
const a = c * 10;
|
|
3252
|
+
if (i)
|
|
3253
|
+
for (let l = 0; l < 7; l++)
|
|
3254
|
+
o[a + l] !== t[l] && (o[a + l] = t[l], r = !0);
|
|
3255
|
+
else
|
|
3256
|
+
r = this._toMesh(t, o, a) || r;
|
|
3257
|
+
}
|
|
3258
|
+
r && n.mesh.updatePoses(n.start, o, n.count);
|
|
3259
|
+
}
|
|
3260
|
+
this._awake = s, this._debug && !this._debug.destroyed && this._debug.visible && this._debug._sync(this._world), this._syncLease();
|
|
3261
|
+
}
|
|
3262
|
+
/** Converts a world pose to the node's local transform and writes position and rotation. */
|
|
3263
|
+
_writeNode(t, s, e) {
|
|
3264
|
+
const n = t.node, i = n.parent;
|
|
3265
|
+
if (i instanceof Vt) {
|
|
3266
|
+
if (i.getWorldMatrix(this._matrix), !Rt(this._inverse, this._matrix))
|
|
3267
|
+
return;
|
|
3268
|
+
const o = this._inverse, r = s[e], c = s[e + 1], a = s[e + 2];
|
|
3269
|
+
this._position[0] = o[0] * r + o[4] * c + o[8] * a + o[12], this._position[1] = o[1] * r + o[5] * c + o[9] * a + o[13], this._position[2] = o[2] * r + o[6] * c + o[10] * a + o[14];
|
|
3270
|
+
const l = vt(this._rotation, this._matrix);
|
|
3271
|
+
Pt(this._quaternion, -l[0], -l[1], -l[2], l[3], s[e + 3], s[e + 4], s[e + 5], s[e + 6]);
|
|
3272
|
+
} else
|
|
3273
|
+
this._position[0] = s[e], this._position[1] = s[e + 1], this._position[2] = s[e + 2], this._quaternion[0] = s[e + 3], this._quaternion[1] = s[e + 4], this._quaternion[2] = s[e + 5], this._quaternion[3] = s[e + 6];
|
|
3274
|
+
n._setTransform(this._patch);
|
|
3275
|
+
}
|
|
3276
|
+
/** World position and rotation of a node; scale is dropped. */
|
|
3277
|
+
_readNodePose(t, s) {
|
|
3278
|
+
t.getWorldMatrix(this._matrix);
|
|
3279
|
+
const e = this._matrix;
|
|
3280
|
+
s[0] = e[12], s[1] = e[13], s[2] = e[14];
|
|
3281
|
+
const n = vt(this._rotation, e), i = Math.hypot(n[0], n[1], n[2], n[3]) || 1;
|
|
3282
|
+
s[3] = n[0] / i, s[4] = n[1] / i, s[5] = n[2] / i, s[6] = n[3] / i;
|
|
3283
|
+
}
|
|
3284
|
+
/** Loads the mesh world matrix and its inverse; returns whether it is the identity. */
|
|
3285
|
+
_meshWorld(t) {
|
|
3286
|
+
t.getWorldMatrix(this._matrix);
|
|
3287
|
+
const s = this._matrix;
|
|
3288
|
+
let e = !0;
|
|
3289
|
+
for (let n = 0; n < 16 && e; n++)
|
|
3290
|
+
e = s[n] === (n % 5 === 0 ? 1 : 0);
|
|
3291
|
+
return e || (Rt(this._inverse, s), vt(this._rotation, s)), e;
|
|
3292
|
+
}
|
|
3293
|
+
/** Instance-local pose (10-stride) to a world pose, with the loaded mesh matrix. */
|
|
3294
|
+
_toWorld(t, s, e) {
|
|
3295
|
+
const n = this._matrix, i = t[s], o = t[s + 1], r = t[s + 2];
|
|
3296
|
+
e[0] = n[0] * i + n[4] * o + n[8] * r + n[12], e[1] = n[1] * i + n[5] * o + n[9] * r + n[13], e[2] = n[2] * i + n[6] * o + n[10] * r + n[14];
|
|
3297
|
+
const c = vt(this._rotation, n), a = this._quaternion;
|
|
3298
|
+
Pt(a, c[0], c[1], c[2], c[3], t[s + 3], t[s + 4], t[s + 5], t[s + 6]);
|
|
3299
|
+
const l = Math.hypot(a[0], a[1], a[2], a[3]);
|
|
3300
|
+
e[3] = a[0] / l, e[4] = a[1] / l, e[5] = a[2] / l, e[6] = a[3] / l;
|
|
3301
|
+
}
|
|
3302
|
+
/** World pose to instance-local (10-stride), with the loaded inverse; returns whether it changed. */
|
|
3303
|
+
_toMesh(t, s, e) {
|
|
3304
|
+
const n = this._inverse, i = t[0], o = t[1], r = t[2], c = this._rotation, a = this._quaternion;
|
|
3305
|
+
Pt(a, -c[0], -c[1], -c[2], c[3], t[3], t[4], t[5], t[6]);
|
|
3306
|
+
let l = !1;
|
|
3307
|
+
for (let h = 0; h < 3; h++) {
|
|
3308
|
+
const _ = n[h] * i + n[4 + h] * o + n[8 + h] * r + n[12 + h];
|
|
3309
|
+
s[e + h] !== _ && (s[e + h] = _, l = !0);
|
|
3310
|
+
}
|
|
3311
|
+
for (let h = 0; h < 4; h++)
|
|
3312
|
+
s[e + 3 + h] !== a[h] && (s[e + 3 + h] = a[h], l = !0);
|
|
3313
|
+
return l;
|
|
3314
|
+
}
|
|
3315
|
+
_syncLease() {
|
|
3316
|
+
!this._destroyed && this.clock === "app" && !this._paused && this._awake ? this._lease ??= this._app._acquireLoop("nova3d.physics") : (this._lease?.release(), this._lease = void 0);
|
|
3317
|
+
}
|
|
3318
|
+
_assertBody(t) {
|
|
3319
|
+
if (this._assertAlive(), !(t instanceof It) || t.world !== this || t.destroyed)
|
|
3320
|
+
throw new F("owner", "[Nova3D] Physics body is destroyed or belongs to another world.");
|
|
3321
|
+
}
|
|
3322
|
+
_assertAlive() {
|
|
3323
|
+
if (this._destroyed)
|
|
3324
|
+
throw new F("destroyed", "[Nova3D] Physics world is destroyed.");
|
|
3325
|
+
}
|
|
3326
|
+
}
|
|
3327
|
+
function ne() {
|
|
3328
|
+
}
|
|
3329
|
+
function zt(d, t, s, e) {
|
|
3330
|
+
for (let n = 0; n < 7; n++)
|
|
3331
|
+
d[t + n] = s[e + n];
|
|
3332
|
+
}
|
|
3333
|
+
function Pt(d, t, s, e, n, i, o, r, c) {
|
|
3334
|
+
d[0] = n * i + t * c + s * r - e * o, d[1] = n * o - t * r + s * c + e * i, d[2] = n * r + t * o - s * i + e * c, d[3] = n * c - t * i - s * o - e * r;
|
|
3335
|
+
}
|
|
3336
|
+
function _e(d, t) {
|
|
3337
|
+
return new ee(_s(d), d, t);
|
|
3338
|
+
}
|
|
3339
|
+
export {
|
|
3340
|
+
It as Nova3DPhysicsBody,
|
|
3341
|
+
Mt as Nova3DPhysicsInstances,
|
|
3342
|
+
te as Nova3DPhysicsJoint,
|
|
3343
|
+
ee as Nova3DPhysicsWorld,
|
|
3344
|
+
he as createBasicPhysics,
|
|
3345
|
+
_e as createPhysicsWorld
|
|
3346
|
+
};
|