agentscape3d-engine 0.0.0-stage → 1.0.0-beta.3
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/LICENSE +21 -0
- package/README.md +19 -2
- package/cli.mjs +53 -0
- package/dist/ArticulationVerifier-BfGxXY8V.js +337 -0
- package/dist/ArticulationVerifier-BfGxXY8V.js.map +1 -0
- package/dist/AssetCompiler-BLj09iu1.js +2424 -0
- package/dist/AssetCompiler-BLj09iu1.js.map +1 -0
- package/dist/AssetModule-DME-XaFS.js +2637 -0
- package/dist/AssetModule-DME-XaFS.js.map +1 -0
- package/dist/AssetRecipe-g8dZBhgJ.js +298 -0
- package/dist/AssetRecipe-g8dZBhgJ.js.map +1 -0
- package/dist/BrowserCodeWorker.js +53856 -0
- package/dist/BrowserCodeWorker.js.map +1 -0
- package/dist/CarryCapability-CXwHU5ay.js +104 -0
- package/dist/CarryCapability-CXwHU5ay.js.map +1 -0
- package/dist/KinematicHypothesisScreen-C3TKiuYR.js +241 -0
- package/dist/KinematicHypothesisScreen-C3TKiuYR.js.map +1 -0
- package/dist/ObjectTransform-BlQUNK7c.js +61 -0
- package/dist/ObjectTransform-BlQUNK7c.js.map +1 -0
- package/dist/RapierPhysicsBackend-B2wQe_Vl.js +3259 -0
- package/dist/RapierPhysicsBackend-B2wQe_Vl.js.map +1 -0
- package/dist/RenderingSystem-WIr1ZuGu.js +1042 -0
- package/dist/RenderingSystem-WIr1ZuGu.js.map +1 -0
- package/dist/ScenePresentation-LsYiDxbm.js +152 -0
- package/dist/ScenePresentation-LsYiDxbm.js.map +1 -0
- package/dist/SceneProject-K7HH1s8o.js +2687 -0
- package/dist/SceneProject-K7HH1s8o.js.map +1 -0
- package/dist/SceneSerializer-zOzbX4jZ.js +932 -0
- package/dist/SceneSerializer-zOzbX4jZ.js.map +1 -0
- package/dist/SimulationProfile-DSYZbBLQ.js +165 -0
- package/dist/SimulationProfile-DSYZbBLQ.js.map +1 -0
- package/dist/StylePack-DcRa_kU0.js +88 -0
- package/dist/StylePack-DcRa_kU0.js.map +1 -0
- package/dist/WorldArchive-BiFGLt--.js +451 -0
- package/dist/WorldArchive-BiFGLt--.js.map +1 -0
- package/dist/WorldCommands-Debj7V4L.js +2207 -0
- package/dist/WorldCommands-Debj7V4L.js.map +1 -0
- package/dist/WorldIO-Ch8QBfKY.js +151 -0
- package/dist/WorldIO-Ch8QBfKY.js.map +1 -0
- package/dist/admission-CVEvsrdz.js +121 -0
- package/dist/admission-CVEvsrdz.js.map +1 -0
- package/dist/blankWorld-B0MW6g7q.js +75 -0
- package/dist/blankWorld-B0MW6g7q.js.map +1 -0
- package/dist/core.d.ts +68 -0
- package/dist/core.js +209 -0
- package/dist/core.js.map +1 -0
- package/dist/disposeObject3D-DIMzy0FA.js +128 -0
- package/dist/disposeObject3D-DIMzy0FA.js.map +1 -0
- package/dist/environments-HOe3sJXH.js +567 -0
- package/dist/environments-HOe3sJXH.js.map +1 -0
- package/dist/gltfIO-BzVKLyaL.js +339 -0
- package/dist/gltfIO-BzVKLyaL.js.map +1 -0
- package/dist/grandUrbanBlock-DRndRZjF.js +515 -0
- package/dist/grandUrbanBlock-DRndRZjF.js.map +1 -0
- package/dist/index.d.ts +345 -0
- package/dist/index.js +16952 -0
- package/dist/index.js.map +1 -0
- package/dist/magicCabin-CfBZjx2Q.js +11019 -0
- package/dist/magicCabin-CfBZjx2Q.js.map +1 -0
- package/dist/manifests-D0LwbJ36.js +866 -0
- package/dist/manifests-D0LwbJ36.js.map +1 -0
- package/dist/mcp.d.ts +2 -0
- package/dist/mcp.js +1 -0
- package/dist/monumentHall-awZiGtda.js +403 -0
- package/dist/monumentHall-awZiGtda.js.map +1 -0
- package/dist/node.d.ts +16 -0
- package/dist/node.js +26 -0
- package/dist/parts-DrEcfJRl.js +37 -0
- package/dist/parts-DrEcfJRl.js.map +1 -0
- package/dist/rolldown-runtime-D3KUYPsf.js +12 -0
- package/dist/ruinedCourtyard-DuF7NmUU.js +696 -0
- package/dist/ruinedCourtyard-DuF7NmUU.js.map +1 -0
- package/dist/runtime/application/AgentTools.js +28 -0
- package/dist/runtime/application/README.md +14 -0
- package/dist/runtime/application/agent/ProgressiveAgentTools.js +92 -0
- package/dist/runtime/application/agent/StudioMcpAllowlist.js +10 -0
- package/dist/runtime/application/agent/StudioProjectTools.js +18 -0
- package/dist/runtime/application/agent/TaskEvidence.js +199 -0
- package/dist/runtime/application/buildTaskObservation.js +117 -0
- package/dist/runtime/application/code-execution/AuthoringSandboxEntry.js +50 -0
- package/dist/runtime/application/code-execution/BrowserCodeExecutor.js +35 -0
- package/dist/runtime/application/code-execution/BrowserCodeWorker.js +17 -0
- package/dist/runtime/application/code-execution/RemoteAuthoringDocument.js +82 -0
- package/dist/runtime/application/createSession.js +66 -0
- package/dist/runtime/application/createWorldAuthoringContext.js +400 -0
- package/dist/runtime/application/generation/GenerationOrchestrator.js +630 -0
- package/dist/runtime/application/generation/GenerationRuntime.js +215 -0
- package/dist/runtime/application/generation/PromptHybridWorldOrchestrator.js +289 -0
- package/dist/runtime/application/native-scene/CodeProject.js +215 -0
- package/dist/runtime/application/native-scene/CodeProjectModules.js +143 -0
- package/dist/runtime/application/native-scene/ExampleWorldCatalog.js +35 -0
- package/dist/runtime/application/native-scene/NativeArticulation.js +53 -0
- package/dist/runtime/application/native-scene/NativeEditableRegistry.js +150 -0
- package/dist/runtime/application/native-scene/NativeEnvironmentGeometry.js +85 -0
- package/dist/runtime/application/native-scene/NativeLightingInspection.js +33 -0
- package/dist/runtime/application/native-scene/NativeMaterialInspection.js +52 -0
- package/dist/runtime/application/native-scene/NativeOverlayCheckpoint.js +127 -0
- package/dist/runtime/application/native-scene/NativePhysicsGeometry.js +64 -0
- package/dist/runtime/application/native-scene/NativeRenderDiscovery.js +51 -0
- package/dist/runtime/application/native-scene/NativeSceneHost.js +406 -0
- package/dist/runtime/application/native-scene/NativeSceneInspection.js +203 -0
- package/dist/runtime/application/native-scene/NativeSceneOverlay.js +116 -0
- package/dist/runtime/application/native-scene/NativeSceneQuery.js +123 -0
- package/dist/runtime/application/native-scene/NativeSceneReview.js +132 -0
- package/dist/runtime/application/native-scene/NativeThreeModule.js +16 -0
- package/dist/runtime/application/native-scene/SceneObserver.js +97 -0
- package/dist/runtime/application/native-scene/VisualCapturePolicy.js +4 -0
- package/dist/runtime/application/object-forge/SceneObjectForge.js +263 -0
- package/dist/runtime/application/programmatic-assets/ProgrammaticAssetBuilder.js +59 -0
- package/dist/runtime/application/programmatic-assets/ProgrammaticAssetContract.js +22 -0
- package/dist/runtime/application/programmatic-assets/ThreeCodeAsset.js +40 -0
- package/dist/runtime/application/scene/CapabilityResolver.js +90 -0
- package/dist/runtime/application/scene/NativeEditableContracts.js +18 -0
- package/dist/runtime/application/scene/RequestWindow.js +54 -0
- package/dist/runtime/application/scene/SceneAgentTools.js +21 -0
- package/dist/runtime/application/scene/SceneContracts.js +49 -0
- package/dist/runtime/application/scene/SceneEditService.js +154 -0
- package/dist/runtime/application/scene/SceneFacade.js +356 -0
- package/dist/runtime/application/scene/SceneInteractionAdapters.js +41 -0
- package/dist/runtime/application/scene/SceneJobController.js +320 -0
- package/dist/runtime/application/scene/SceneLifecycle.js +57 -0
- package/dist/runtime/application/scene/ScenePackage.js +173 -0
- package/dist/runtime/application/scene/ScenePersistence.js +50 -0
- package/dist/runtime/application/scene/SceneProject.js +95 -0
- package/dist/runtime/application/scene/SceneSkillNames.js +5 -0
- package/dist/runtime/application/scene/StarterScene.js +56 -0
- package/dist/runtime/application/scene/WorldArchive.js +89 -0
- package/dist/runtime/application/scene/WorldDirectory.js +20 -0
- package/dist/runtime/application/scene/WorldDocument.js +76 -0
- package/dist/runtime/application/scene/WorldIO.js +103 -0
- package/dist/runtime/application/scene/WorldStorage.js +155 -0
- package/dist/runtime/application/skills/SkillRegistry.js +193 -0
- package/dist/runtime/application/skills/packs/acceptanceSkills.js +32 -0
- package/dist/runtime/application/skills/packs/affordanceSkills.js +36 -0
- package/dist/runtime/application/skills/packs/assetSkills.js +46 -0
- package/dist/runtime/application/skills/packs/authoringSkills.js +16 -0
- package/dist/runtime/application/skills/packs/batchSkills.js +22 -0
- package/dist/runtime/application/skills/packs/codeSkills.js +106 -0
- package/dist/runtime/application/skills/packs/generationSkills.js +45 -0
- package/dist/runtime/application/skills/packs/interactionSkills.js +46 -0
- package/dist/runtime/application/skills/packs/recoverySkills.js +80 -0
- package/dist/runtime/application/skills/packs/sceneSkills.js +24 -0
- package/dist/runtime/application/skills/packs/spatialSkills.js +35 -0
- package/dist/runtime/application/skills/packs/verificationSkills.js +14 -0
- package/dist/runtime/application/skills/packs/worldSkills.js +45 -0
- package/dist/runtime/application/skills/registerCoreSkills.js +31 -0
- package/dist/runtime/application/skills/skillPrimitives.js +4 -0
- package/dist/runtime/application/tasks/CabinetCupTask.js +76 -0
- package/dist/runtime/application/tasks.jsonl +67 -0
- package/dist/runtime/application/world-authoring/AuthoringAssetProducer.js +42 -0
- package/dist/runtime/application/world-authoring/AuthoringDiff.js +149 -0
- package/dist/runtime/application/world-authoring/AuthoringDocument.js +825 -0
- package/dist/runtime/application/world-authoring/AuthoringExecutionHost.js +109 -0
- package/dist/runtime/application/world-authoring/AuthoringIdentity.js +17 -0
- package/dist/runtime/application/world-authoring/AuthoringModelResolver.js +29 -0
- package/dist/runtime/application/world-authoring/AuthoringPatch.js +118 -0
- package/dist/runtime/application/world-authoring/AuthoringPromotionController.js +334 -0
- package/dist/runtime/application/world-authoring/AuthoringPromotionSource.js +126 -0
- package/dist/runtime/application/world-authoring/AuthoringRevisionHistory.js +144 -0
- package/dist/runtime/application/world-authoring/HeadlessImageExport.js +92 -0
- package/dist/runtime/application/world-authoring/ModelRef.js +62 -0
- package/dist/runtime/application/world-authoring/SceneGLBExport.js +88 -0
- package/dist/runtime/apps/mcp-server/AUTHORING.md +71 -0
- package/dist/runtime/apps/mcp-server/AgentMcpCompat.js +68 -0
- package/dist/runtime/apps/mcp-server/AuthoringSandboxEntry.js +1 -0
- package/dist/runtime/apps/mcp-server/AuthoringSandboxWorker.mjs +30 -0
- package/dist/runtime/apps/mcp-server/BuildEnvironment.js +17 -0
- package/dist/runtime/apps/mcp-server/CodeExecutor.js +71 -0
- package/dist/runtime/apps/mcp-server/DEPLOYMENT-PC2.md +42 -0
- package/dist/runtime/apps/mcp-server/DockerBuildRunner.js +66 -0
- package/dist/runtime/apps/mcp-server/FileAssetRepository.js +159 -0
- package/dist/runtime/apps/mcp-server/HeadlessAssetIO.js +8 -0
- package/dist/runtime/apps/mcp-server/HeadlessGLTFLoader.js +47 -0
- package/dist/runtime/apps/mcp-server/HeadlessWorldHost.js +157 -0
- package/dist/runtime/apps/mcp-server/IsolatedAuthoringExecutor.js +6 -0
- package/dist/runtime/apps/mcp-server/PROGRAMMATIC-ASSETS.md +116 -0
- package/dist/runtime/apps/mcp-server/ProgrammaticAssets.js +60 -0
- package/dist/runtime/apps/mcp-server/README.md +269 -0
- package/dist/runtime/apps/mcp-server/RemoteAuthoringDocument.js +1 -0
- package/dist/runtime/apps/mcp-server/SandboxBundle.js +13 -0
- package/dist/runtime/apps/mcp-server/SessionManager.js +148 -0
- package/dist/runtime/apps/mcp-server/StudioBridgeHttp.js +75 -0
- package/dist/runtime/apps/mcp-server/StudioLiveBridge.js +246 -0
- package/dist/runtime/apps/mcp-server/StudioProjectToolContracts.js +58 -0
- package/dist/runtime/apps/mcp-server/TransferHttp.js +47 -0
- package/dist/runtime/apps/mcp-server/TransferLimits.js +6 -0
- package/dist/runtime/apps/mcp-server/TransferStore.js +134 -0
- package/dist/runtime/apps/mcp-server/TrustedAuthoringWorker.mjs +16 -0
- package/dist/runtime/apps/mcp-server/VALIDATION.md +45 -0
- package/dist/runtime/apps/mcp-server/acceptance-evidence.json +332 -0
- package/dist/runtime/apps/mcp-server/errorDiagnostics.js +32 -0
- package/dist/runtime/apps/mcp-server/examples/code-house.js +24 -0
- package/dist/runtime/apps/mcp-server/examples/procedural-assets.js +85 -0
- package/dist/runtime/apps/mcp-server/main.mjs +82 -0
- package/dist/runtime/apps/mcp-server/registerTools.js +274 -0
- package/dist/runtime/apps/mcp-server/sandbox/run.mjs +23 -0
- package/dist/runtime/apps/mcp-server/security.js +23 -0
- package/dist/runtime/apps/mcp-server/tasks.jsonl +9 -0
- package/dist/runtime/apps/server/CapabilityAdapterRegistry.js +157 -0
- package/dist/runtime/apps/server/README.md +7 -0
- package/dist/runtime/apps/server/WorldRepository.js +338 -0
- package/dist/runtime/apps/server/WorldRepositoryHttp.js +96 -0
- package/dist/runtime/apps/server/openai-compatible-agent-gateway.mjs +278 -0
- package/dist/runtime/apps/server/tasks.jsonl +10 -0
- package/dist/runtime/apps/shared/node/WorldDiskStorage.js +62 -0
- package/dist/runtime/foundation/EventBus.js +26 -0
- package/dist/runtime/foundation/JsonGateway.js +47 -0
- package/dist/runtime/foundation/PngRgba.js +99 -0
- package/dist/runtime/foundation/PolicyEngine.js +21 -0
- package/dist/runtime/foundation/README.md +7 -0
- package/dist/runtime/foundation/TraceRecorder.js +76 -0
- package/dist/runtime/foundation/errors.js +8 -0
- package/dist/runtime/foundation/simulation/SimulationProfile.js +143 -0
- package/dist/runtime/foundation/version.js +2 -0
- package/dist/runtime/modules/agent/README.md +11 -0
- package/dist/runtime/modules/agent/ToolCallingAgent.js +19 -0
- package/dist/runtime/modules/agent/bootstrapWorld.js +10 -0
- package/dist/runtime/modules/agent/buildRecoveryProposals.js +533 -0
- package/dist/runtime/modules/agent/execution/AgentExecutionRules.js +128 -0
- package/dist/runtime/modules/agent/execution/AgentRunResults.js +55 -0
- package/dist/runtime/modules/agent/execution/AgentRunSession.js +393 -0
- package/dist/runtime/modules/agent/execution/AgentToolInvoker.js +40 -0
- package/dist/runtime/modules/agent/gateway/HttpLLMGateway.js +19 -0
- package/dist/runtime/modules/agent/prompt/index.js +52 -0
- package/dist/runtime/modules/agent/tasks.jsonl +94 -0
- package/dist/runtime/modules/artifact/ArtifactContentGate.js +144 -0
- package/dist/runtime/modules/artifact/ArtifactDescriptor.js +280 -0
- package/dist/runtime/modules/artifact/ArtifactImporter.js +185 -0
- package/dist/runtime/modules/artifact/ArtifactModule.js +111 -0
- package/dist/runtime/modules/artifact/ArtifactRegistry.js +197 -0
- package/dist/runtime/modules/artifact/IncrementalSha256.js +129 -0
- package/dist/runtime/modules/artifact/MemoryArtifactByteStore.js +115 -0
- package/dist/runtime/modules/artifact/README.md +7 -0
- package/dist/runtime/modules/artifact/storage/IndexedDbArtifactStore.js +67 -0
- package/dist/runtime/modules/artifact/tasks.jsonl +31 -0
- package/dist/runtime/modules/asset/AssetModule.js +416 -0
- package/dist/runtime/modules/asset/README.md +67 -0
- package/dist/runtime/modules/asset/loading/AssetLoader.js +157 -0
- package/dist/runtime/modules/asset/loading/GltfAssetLoader.js +61 -0
- package/dist/runtime/modules/asset/loading/builtins/BuiltinAssets.js +95 -0
- package/dist/runtime/modules/asset/loading/builtins/HouseDoor.js +33 -0
- package/dist/runtime/modules/asset/loading/builtins/IndustrialCabinet.js +103 -0
- package/dist/runtime/modules/asset/model/AssetInputContracts.js +139 -0
- package/dist/runtime/modules/asset/model/AssetRef.js +12 -0
- package/dist/runtime/modules/asset/model/MechanicalAssetDraft.js +172 -0
- package/dist/runtime/modules/asset/model/ProceduralTextureContract.js +24 -0
- package/dist/runtime/modules/asset/model/admission.js +117 -0
- package/dist/runtime/modules/asset/model/errors.js +6 -0
- package/dist/runtime/modules/asset/model/parts.js +27 -0
- package/dist/runtime/modules/asset/model/resourceBudget.js +10 -0
- package/dist/runtime/modules/asset/model/schema.js +150 -0
- package/dist/runtime/modules/asset/persistence/AssetManifestStore.js +78 -0
- package/dist/runtime/modules/asset/persistence/CompiledAssetStore.js +84 -0
- package/dist/runtime/modules/asset/persistence/LocalAssetLibrary.js +86 -0
- package/dist/runtime/modules/asset/persistence/LocalAssetLibraryStore.js +81 -0
- package/dist/runtime/modules/asset/production/AssetProductionPipeline.js +272 -0
- package/dist/runtime/modules/asset/production/AssetRecipe.js +91 -0
- package/dist/runtime/modules/asset/production/ProceduralTexture.js +85 -0
- package/dist/runtime/modules/asset/production/adapters/EmbodiedGenAdapter.js +45 -0
- package/dist/runtime/modules/asset/production/adapters/EmbodiedGenBundleAdapter.js +590 -0
- package/dist/runtime/modules/asset/production/compiler/AssetCompiler.js +173 -0
- package/dist/runtime/modules/asset/production/compiler/evidence/AnimationMotionEvidence.js +124 -0
- package/dist/runtime/modules/asset/production/compiler/evidence/StaticPanelEvidence.js +56 -0
- package/dist/runtime/modules/asset/production/compiler/gltfIO.js +6 -0
- package/dist/runtime/modules/asset/production/compiler/partGeometry.js +74 -0
- package/dist/runtime/modules/asset/production/compiler/passes/ArticulatedCollisionPass.js +63 -0
- package/dist/runtime/modules/asset/production/compiler/passes/ArticulationCandidatePass.js +48 -0
- package/dist/runtime/modules/asset/production/compiler/passes/AuthoringIntentPass.js +16 -0
- package/dist/runtime/modules/asset/production/compiler/passes/ColliderFallbackPass.js +30 -0
- package/dist/runtime/modules/asset/production/compiler/passes/CompileQualityPass.js +75 -0
- package/dist/runtime/modules/asset/production/compiler/passes/ExplicitDefinitionPass.js +20 -0
- package/dist/runtime/modules/asset/production/compiler/passes/GLTFInspectPass.js +34 -0
- package/dist/runtime/modules/asset/production/compiler/passes/GeometryPass.js +32 -0
- package/dist/runtime/modules/asset/production/compiler/passes/JointFramePass.js +116 -0
- package/dist/runtime/modules/asset/production/compiler/passes/KinematicEvidencePass.js +84 -0
- package/dist/runtime/modules/asset/production/compiler/passes/ManifestPass.js +63 -0
- package/dist/runtime/modules/asset/production/compiler/passes/NormalizeTransformPass.js +16 -0
- package/dist/runtime/modules/asset/production/compiler/passes/OptimizeGLBPass.js +23 -0
- package/dist/runtime/modules/asset/production/compiler/passes/PartColliderPass.js +50 -0
- package/dist/runtime/modules/asset/production/compiler/passes/PartGeometryEnrichmentPass.js +60 -0
- package/dist/runtime/modules/asset/production/compiler/passes/PartProposalPass.js +93 -0
- package/dist/runtime/modules/asset/production/compiler/passes/RemoteEnrichmentPass.js +32 -0
- package/dist/runtime/modules/asset/production/compiler/passes/ResourceBudgetPass.js +55 -0
- package/dist/runtime/modules/asset/production/compiler/passes/SegmentMaterializePass.js +203 -0
- package/dist/runtime/modules/asset/production/compiler/passes/SegmentationEvidencePass.js +43 -0
- package/dist/runtime/modules/asset/production/compiler/passes/SemanticHeuristicPass.js +33 -0
- package/dist/runtime/modules/asset/production/compiler/passes/StructurePass.js +60 -0
- package/dist/runtime/modules/asset/production/compiler/providers/HttpCompilerProvider.js +23 -0
- package/dist/runtime/modules/asset/production/verification/KinematicHypothesisScreen.js +198 -0
- package/dist/runtime/modules/asset/registry/AssetCatalog.js +72 -0
- package/dist/runtime/modules/asset/registry/AssetRegistry.js +51 -0
- package/dist/runtime/modules/asset/registry/manifests/index.js +173 -0
- package/dist/runtime/modules/asset/tasks.jsonl +87 -0
- package/dist/runtime/modules/generation/README.md +9 -0
- package/dist/runtime/modules/generation/connector/ConnectorArtifactClient.js +45 -0
- package/dist/runtime/modules/generation/connector/ConnectorCapabilityAdapter.js +169 -0
- package/dist/runtime/modules/generation/connector/ConnectorClient.js +192 -0
- package/dist/runtime/modules/generation/connector/ConnectorJobClient.js +167 -0
- package/dist/runtime/modules/generation/connector/ConnectorJobEventClient.js +179 -0
- package/dist/runtime/modules/generation/connector/ConnectorSession.js +202 -0
- package/dist/runtime/modules/generation/jobs/GenerationJobProjection.js +239 -0
- package/dist/runtime/modules/generation/jobs/GenerationJobReconciler.js +99 -0
- package/dist/runtime/modules/generation/jobs/GenerationJobStore.js +91 -0
- package/dist/runtime/modules/generation/jobs/GenerationJobTransportOverlay.js +50 -0
- package/dist/runtime/modules/generation/providers/ProviderRegistry.js +304 -0
- package/dist/runtime/modules/generation/tasks.jsonl +35 -0
- package/dist/runtime/modules/navigation/NavigationBackend.js +17 -0
- package/dist/runtime/modules/navigation/RecastNavigationBackend.js +263 -0
- package/dist/runtime/modules/physics/JoltPhysicsBackend.js +850 -0
- package/dist/runtime/modules/physics/PhysicsApiSurface.js +660 -0
- package/dist/runtime/modules/physics/PhysicsBackend.js +88 -0
- package/dist/runtime/modules/physics/RapierPhysicsBackend.js +414 -0
- package/dist/runtime/modules/rendering/README.md +7 -0
- package/dist/runtime/modules/rendering/RendererProbe.js +153 -0
- package/dist/runtime/modules/rendering/WebGpuPostFxPipeline.js +140 -0
- package/dist/runtime/modules/rendering/captureStill.js +54 -0
- package/dist/runtime/modules/rendering/createRenderer.js +76 -0
- package/dist/runtime/modules/rendering/disposeObject3D.js +37 -0
- package/dist/runtime/modules/rendering/loadGaussianSplatVisual.js +74 -0
- package/dist/runtime/modules/rendering/spatial/ThreeBvhRuntime.js +107 -0
- package/dist/runtime/modules/rendering/style/StylePack.js +34 -0
- package/dist/runtime/modules/rendering/style/StyleSystem.js +173 -0
- package/dist/runtime/modules/rendering/tasks.jsonl +7 -0
- package/dist/runtime/modules/world/README.md +13 -0
- package/dist/runtime/modules/world/build/WorldBuilder.js +170 -0
- package/dist/runtime/modules/world/compiler/PipelineEngine.js +32 -0
- package/dist/runtime/modules/world/compiler/WorldAdmission.js +43 -0
- package/dist/runtime/modules/world/compiler/WorldBehaviorCompiler.js +68 -0
- package/dist/runtime/modules/world/compiler/WorldCompilation.js +157 -0
- package/dist/runtime/modules/world/compiler/WorldComposer.js +201 -0
- package/dist/runtime/modules/world/compiler/WorldPhysicsAdmission.js +76 -0
- package/dist/runtime/modules/world/compiler/WorldRecompiler.js +356 -0
- package/dist/runtime/modules/world/compiler/WorldRetry.js +75 -0
- package/dist/runtime/modules/world/compiler/createWorldPipeline.js +379 -0
- package/dist/runtime/modules/world/content/blankWorld.js +35 -0
- package/dist/runtime/modules/world/content/environments.js +84 -0
- package/dist/runtime/modules/world/content/grandUrbanBlock.js +189 -0
- package/dist/runtime/modules/world/content/magic-cabin/README.md +28 -0
- package/dist/runtime/modules/world/content/magic-cabin/affordances.js +64 -0
- package/dist/runtime/modules/world/content/magic-cabin/cabinContents.js +7078 -0
- package/dist/runtime/modules/world/content/magic-cabin/lighting.js +26 -0
- package/dist/runtime/modules/world/content/magic-cabin/materials.js +20 -0
- package/dist/runtime/modules/world/content/magicCabin.js +190 -0
- package/dist/runtime/modules/world/content/monumentHall.js +154 -0
- package/dist/runtime/modules/world/content/ruinedCourtyard.js +196 -0
- package/dist/runtime/modules/world/content/suzhouGarden/README.md +141 -0
- package/dist/runtime/modules/world/content/suzhouGarden/index.js +137 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/arch.js +491 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/buildings.js +670 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/core.js +578 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/lod.js +127 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/main.js +642 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/nature.js +650 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/rockery.js +280 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/sky.js +242 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/water.js +215 -0
- package/dist/runtime/modules/world/content/woodlandWorkshop.js +192 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/README.md +36 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/arch.js +351 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/buildings.js +490 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/core.js +505 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/index.js +101 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/nature.js +435 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/sky.js +169 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/water.js +245 -0
- package/dist/runtime/modules/world/errors.js +9 -0
- package/dist/runtime/modules/world/generated/GeneratedWorldCoordinates.js +50 -0
- package/dist/runtime/modules/world/generated/GeneratedWorldLoader.js +297 -0
- package/dist/runtime/modules/world/runtime/CommandHistory.js +111 -0
- package/dist/runtime/modules/world/runtime/EntityCapabilityRegistry.js +165 -0
- package/dist/runtime/modules/world/runtime/NativeNavigationGeometry.js +84 -0
- package/dist/runtime/modules/world/runtime/NativePhysicsSnapshot.js +245 -0
- package/dist/runtime/modules/world/runtime/ObjectStore.js +31 -0
- package/dist/runtime/modules/world/runtime/ObjectTransform.js +62 -0
- package/dist/runtime/modules/world/runtime/ObservedEntity.js +37 -0
- package/dist/runtime/modules/world/runtime/ProjectCapabilities.js +240 -0
- package/dist/runtime/modules/world/runtime/SceneExtensions.js +36 -0
- package/dist/runtime/modules/world/runtime/ScenePresentation.js +101 -0
- package/dist/runtime/modules/world/runtime/SceneSerializer.js +281 -0
- package/dist/runtime/modules/world/runtime/WorldAuthority.js +41 -0
- package/dist/runtime/modules/world/runtime/WorldCollisionSignature.js +14 -0
- package/dist/runtime/modules/world/runtime/WorldCommands.js +503 -0
- package/dist/runtime/modules/world/runtime/WorldObservation.js +71 -0
- package/dist/runtime/modules/world/runtime/WorldQueries.js +340 -0
- package/dist/runtime/modules/world/runtime/WorldRecovery.js +78 -0
- package/dist/runtime/modules/world/runtime/WorldRuntime.js +806 -0
- package/dist/runtime/modules/world/runtime/affordance/ObjectAffordances.js +110 -0
- package/dist/runtime/modules/world/runtime/affordance/WorldAffordances.js +130 -0
- package/dist/runtime/modules/world/runtime/behavior/BehaviorCompiler.js +79 -0
- package/dist/runtime/modules/world/runtime/behavior/ProjectStateMachine.js +195 -0
- package/dist/runtime/modules/world/runtime/behavior/RuleGraph.js +70 -0
- package/dist/runtime/modules/world/runtime/behavior/RuleRuntime.js +115 -0
- package/dist/runtime/modules/world/runtime/graph/SceneGraph.js +390 -0
- package/dist/runtime/modules/world/runtime/interaction/ArticulationRuntime.js +214 -0
- package/dist/runtime/modules/world/runtime/interaction/CarryCapability.js +65 -0
- package/dist/runtime/modules/world/runtime/interaction/CarryRuntime.js +244 -0
- package/dist/runtime/modules/world/runtime/interaction/InteractionApproach.js +147 -0
- package/dist/runtime/modules/world/runtime/interaction/InteractionContract.js +57 -0
- package/dist/runtime/modules/world/runtime/interaction/ManipulationActions.js +7 -0
- package/dist/runtime/modules/world/runtime/interaction/NativePhysicalTarget.js +31 -0
- package/dist/runtime/modules/world/runtime/interaction/RecoveryRuntime.js +123 -0
- package/dist/runtime/modules/world/runtime/interaction/SettleRuntime.js +134 -0
- package/dist/runtime/modules/world/runtime/semantic/NativePhysicsState.js +89 -0
- package/dist/runtime/modules/world/runtime/semantic/SemanticWorldView.js +129 -0
- package/dist/runtime/modules/world/runtime/simulation/SimulationClock.js +89 -0
- package/dist/runtime/modules/world/runtime/simulation/SimulationSession.js +104 -0
- package/dist/runtime/modules/world/runtime/simulation/ThermalSystem.js +269 -0
- package/dist/runtime/modules/world/runtime/simulation/WorldTimeline.js +110 -0
- package/dist/runtime/modules/world/runtime/spatial/SpatialSnapshot.js +56 -0
- package/dist/runtime/modules/world/runtime/spatial/VisualMeshBounds.js +41 -0
- package/dist/runtime/modules/world/runtime/systems/AudioSystem.js +306 -0
- package/dist/runtime/modules/world/runtime/systems/Instrument.js +39 -0
- package/dist/runtime/modules/world/runtime/systems/InteractionSystem.js +806 -0
- package/dist/runtime/modules/world/runtime/systems/LocomotionSystem.js +281 -0
- package/dist/runtime/modules/world/runtime/systems/NavigationSystem.js +561 -0
- package/dist/runtime/modules/world/runtime/systems/PhysicsSystem.js +1752 -0
- package/dist/runtime/modules/world/runtime/systems/RenderingSystem.js +527 -0
- package/dist/runtime/modules/world/runtime/systems/SpatialSystem.js +402 -0
- package/dist/runtime/modules/world/spec/WorldIR.js +165 -0
- package/dist/runtime/modules/world/spec/WorldIRToolSchema.js +86 -0
- package/dist/runtime/modules/world/spec/WorldPlannerProposal.js +51 -0
- package/dist/runtime/modules/world/spec/WorldRevision.js +231 -0
- package/dist/runtime/modules/world/spec/WorldSpec.js +86 -0
- package/dist/runtime/modules/world/tasks.jsonl +530 -0
- package/dist/runtime/modules/world/verification/ArticulationVerifier.js +254 -0
- package/dist/runtime/modules/world/verification/Finding.js +105 -0
- package/dist/runtime/modules/world/verification/InteractionEvidence.js +73 -0
- package/dist/runtime/modules/world/verification/RepairEngine.js +49 -0
- package/dist/runtime/modules/world/verification/VisualLayoutAcceptance.js +58 -0
- package/dist/runtime/modules/world/verification/WorldAcceptance.js +176 -0
- package/dist/runtime/modules/world/verification/WorldValidator.js +67 -0
- package/dist/runtime/package-lock.json +16071 -0
- package/dist/runtime/package.json +106 -0
- package/dist/runtime/public/assets/cabinet.glb +0 -0
- package/dist/runtime/public/assets/grand-urban-block/clean_asphalt_diff_1k.jpg +0 -0
- package/dist/runtime/public/assets/grand-urban-block/clean_asphalt_nor_gl_1k.jpg +0 -0
- package/dist/runtime/public/assets/grand-urban-block/concrete_pavement_diff_1k.jpg +0 -0
- package/dist/runtime/public/assets/grand-urban-block/urban_street_01_1k.hdr +0 -0
- package/dist/runtime/public/assets/monument-hall/marble_diff_1k.jpg +0 -0
- package/dist/runtime/public/assets/monument-hall/marble_nor_gl_1k.jpg +0 -0
- package/dist/runtime/public/assets/monument-hall/marble_rough_1k.jpg +0 -0
- package/dist/runtime/public/assets/monument-hall/solitude_interior_1k.hdr +0 -0
- package/dist/runtime/public/assets/ruined-courtyard/courtyard_1k.hdr +0 -0
- package/dist/runtime/public/assets/ruined-courtyard/mossy_cobblestone_diff_1k.jpg +0 -0
- package/dist/runtime/public/assets/ruined-courtyard/mossy_cobblestone_nor_gl_1k.jpg +0 -0
- package/dist/runtime/public/assets/ruined-courtyard/mossy_sandstone_diff_1k.jpg +0 -0
- package/dist/schema-DT7K9NjP.js +165 -0
- package/dist/schema-DT7K9NjP.js.map +1 -0
- package/dist/suzhouGarden-Y3hny8j6.js +6150 -0
- package/dist/suzhouGarden-Y3hny8j6.js.map +1 -0
- package/dist/version-CHc-i8ch.js +5 -0
- package/dist/version-CHc-i8ch.js.map +1 -0
- package/dist/woodlandWorkshop-DsScU-cx.js +483 -0
- package/dist/woodlandWorkshop-DsScU-cx.js.map +1 -0
- package/dist/yuanmingyuan-DsFnPzzR.js +4955 -0
- package/dist/yuanmingyuan-DsFnPzzR.js.map +1 -0
- package/package.json +75 -4
|
@@ -0,0 +1,850 @@
|
|
|
1
|
+
import { PhysicsBackend } from './PhysicsBackend.js';
|
|
2
|
+
|
|
3
|
+
let joltModulePromise=null;
|
|
4
|
+
const loadJolt=()=>joltModulePromise ||= import('jolt-physics').then(({default:initJolt})=>initJolt());
|
|
5
|
+
|
|
6
|
+
const LAYER=0;
|
|
7
|
+
const UNIT=[1,1,1];
|
|
8
|
+
const ZERO=[0,0,0];
|
|
9
|
+
const IDENTITY=[0,0,0,1];
|
|
10
|
+
|
|
11
|
+
const cloneSpec=(spec)=>structuredClone(spec);
|
|
12
|
+
const tuple3=(value=ZERO)=>Array.isArray(value)?value:[value.x,value.y,value.z];
|
|
13
|
+
const tuple4=(value=IDENTITY)=>Array.isArray(value)?value:[value.x,value.y,value.z,value.w];
|
|
14
|
+
const array3=(value)=>[value.GetX(),value.GetY(),value.GetZ()];
|
|
15
|
+
const array4=(value)=>[value.GetX(),value.GetY(),value.GetZ(),value.GetW()];
|
|
16
|
+
const bodyIdNumber=(body)=>body.native.GetID().GetIndexAndSequenceNumber();
|
|
17
|
+
const nativeBodyIdNumber=(id)=>id.GetIndexAndSequenceNumber();
|
|
18
|
+
|
|
19
|
+
const quatMultiply=(a,b)=>[
|
|
20
|
+
a[3]*b[0]+a[0]*b[3]+a[1]*b[2]-a[2]*b[1],
|
|
21
|
+
a[3]*b[1]-a[0]*b[2]+a[1]*b[3]+a[2]*b[0],
|
|
22
|
+
a[3]*b[2]+a[0]*b[1]-a[1]*b[0]+a[2]*b[3],
|
|
23
|
+
a[3]*b[3]-a[0]*b[0]-a[1]*b[1]-a[2]*b[2]
|
|
24
|
+
];
|
|
25
|
+
const rotateVector=(q,v)=>{
|
|
26
|
+
const [x,y,z,w]=q;
|
|
27
|
+
const tx=2*(y*v[2]-z*v[1]);
|
|
28
|
+
const ty=2*(z*v[0]-x*v[2]);
|
|
29
|
+
const tz=2*(x*v[1]-y*v[0]);
|
|
30
|
+
return [
|
|
31
|
+
v[0]+w*tx+(y*tz-z*ty),
|
|
32
|
+
v[1]+w*ty+(z*tx-x*tz),
|
|
33
|
+
v[2]+w*tz+(x*ty-y*tx)
|
|
34
|
+
];
|
|
35
|
+
};
|
|
36
|
+
const worldPoseForCollider=(bodyPose,collider)=>{
|
|
37
|
+
const localPosition=collider.spec.translation||ZERO;
|
|
38
|
+
const localRotation=collider.spec.rotation||IDENTITY;
|
|
39
|
+
const offset=rotateVector(bodyPose.rotation,localPosition);
|
|
40
|
+
return {
|
|
41
|
+
position:[bodyPose.position[0]+offset[0],bodyPose.position[1]+offset[1],bodyPose.position[2]+offset[2]],
|
|
42
|
+
rotation:quatMultiply(bodyPose.rotation,localRotation)
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const shapeDescription=(spec)=>{
|
|
47
|
+
if(spec.shape==='box') return {kind:'box',halfExtents:{x:spec.halfExtents[0],y:spec.halfExtents[1],z:spec.halfExtents[2]},borderRadius:0};
|
|
48
|
+
if(spec.shape==='cylinder') return {kind:'cylinder',halfHeight:spec.halfHeight,radius:spec.radius,borderRadius:0};
|
|
49
|
+
if(spec.shape==='capsule') return {kind:'capsule',halfHeight:spec.halfHeight,radius:spec.radius,borderRadius:0};
|
|
50
|
+
if(spec.shape==='convexHull') return {kind:'convexHull',vertices:[...spec.vertices],borderRadius:0};
|
|
51
|
+
return {kind:'unknown',type:spec.shape};
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const motionType=(Jolt,type)=>type==='dynamic' ? Jolt.EMotionType_Dynamic
|
|
55
|
+
: type==='kinematic' ? Jolt.EMotionType_Kinematic
|
|
56
|
+
: Jolt.EMotionType_Static;
|
|
57
|
+
const semanticMotionType=(Jolt,type)=>type===Jolt.EMotionType_Dynamic ? 'dynamic'
|
|
58
|
+
: type===Jolt.EMotionType_Kinematic ? 'kinematic'
|
|
59
|
+
: 'fixed';
|
|
60
|
+
|
|
61
|
+
const activation=(Jolt,wake=true)=>wake ? Jolt.EActivation_Activate : Jolt.EActivation_DontActivate;
|
|
62
|
+
const allowedDofs=(Jolt,lockTranslation=null,lockRotation=null)=>{
|
|
63
|
+
let dofs=0;
|
|
64
|
+
if(!lockTranslation?.[0]) dofs|=Jolt.EAllowedDOFs_TranslationX;
|
|
65
|
+
if(!lockTranslation?.[1]) dofs|=Jolt.EAllowedDOFs_TranslationY;
|
|
66
|
+
if(!lockTranslation?.[2]) dofs|=Jolt.EAllowedDOFs_TranslationZ;
|
|
67
|
+
if(!lockRotation?.[0]) dofs|=Jolt.EAllowedDOFs_RotationX;
|
|
68
|
+
if(!lockRotation?.[1]) dofs|=Jolt.EAllowedDOFs_RotationY;
|
|
69
|
+
if(!lockRotation?.[2]) dofs|=Jolt.EAllowedDOFs_RotationZ;
|
|
70
|
+
return dofs;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const pairKey=(a,b)=>a<b?`${a}:${b}`:`${b}:${a}`;
|
|
74
|
+
const normalized3=(value)=>{
|
|
75
|
+
const [x,y,z]=tuple3(value); const length=Math.hypot(x,y,z);
|
|
76
|
+
if(length<=1e-12) throw new TypeError('Joint axis must be non-zero');
|
|
77
|
+
return [x/length,y/length,z/length];
|
|
78
|
+
};
|
|
79
|
+
const perpendicular3=(axis)=>{
|
|
80
|
+
const [x,y,z]=normalized3(axis);
|
|
81
|
+
const basis=Math.abs(x)<=Math.abs(y)&&Math.abs(x)<=Math.abs(z)?[1,0,0]:Math.abs(y)<=Math.abs(z)?[0,1,0]:[0,0,1];
|
|
82
|
+
return normalized3([y*basis[2]-z*basis[1],z*basis[0]-x*basis[2],x*basis[1]-y*basis[0]]);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const withVec3=(Jolt,value,fn)=>{
|
|
86
|
+
const v=new Jolt.Vec3(value[0],value[1],value[2]);
|
|
87
|
+
try{return fn(v);}finally{Jolt.destroy(v);}
|
|
88
|
+
};
|
|
89
|
+
const withRVec3=(Jolt,value,fn)=>{
|
|
90
|
+
const v=new Jolt.RVec3(value[0],value[1],value[2]);
|
|
91
|
+
try{return fn(v);}finally{Jolt.destroy(v);}
|
|
92
|
+
};
|
|
93
|
+
const withQuat=(Jolt,value,fn)=>{
|
|
94
|
+
const q=new Jolt.Quat(value[0],value[1],value[2],value[3]);
|
|
95
|
+
try{return fn(q);}finally{Jolt.destroy(q);}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
function createShapeSettings(Jolt,spec,userData=0){
|
|
99
|
+
let settings;
|
|
100
|
+
if(spec.shape==='box') {
|
|
101
|
+
const half=new Jolt.Vec3(...spec.halfExtents);
|
|
102
|
+
settings=new Jolt.BoxShapeSettings(half,0,null);
|
|
103
|
+
Jolt.destroy(half);
|
|
104
|
+
} else if(spec.shape==='cylinder') {
|
|
105
|
+
settings=new Jolt.CylinderShapeSettings(spec.halfHeight,spec.radius,0,null);
|
|
106
|
+
} else if(spec.shape==='capsule') {
|
|
107
|
+
settings=new Jolt.CapsuleShapeSettings(spec.halfHeight,spec.radius,null);
|
|
108
|
+
} else if(spec.shape==='convexHull') {
|
|
109
|
+
settings=new Jolt.ConvexHullShapeSettings();
|
|
110
|
+
const point=new Jolt.Vec3(0,0,0);
|
|
111
|
+
try {
|
|
112
|
+
for(let i=0;i<spec.vertices.length;i+=3){
|
|
113
|
+
point.Set(spec.vertices[i],spec.vertices[i+1],spec.vertices[i+2]);
|
|
114
|
+
settings.mPoints.push_back(point);
|
|
115
|
+
}
|
|
116
|
+
} finally { Jolt.destroy(point); }
|
|
117
|
+
} else {
|
|
118
|
+
throw new TypeError(`JoltPhysicsBackend unsupported collider shape: ${spec.shape}`);
|
|
119
|
+
}
|
|
120
|
+
settings.mUserData=userData;
|
|
121
|
+
return settings;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function createOwnedShape(Jolt,spec,userData=0){
|
|
125
|
+
const settings=createShapeSettings(Jolt,spec,userData);
|
|
126
|
+
try {
|
|
127
|
+
const result=settings.Create();
|
|
128
|
+
try {
|
|
129
|
+
if(!result.IsValid()) throw new Error(`Jolt rejected ${spec.shape} shape`);
|
|
130
|
+
const shape=result.Get();
|
|
131
|
+
shape.AddRef();
|
|
132
|
+
result.Clear();
|
|
133
|
+
return shape;
|
|
134
|
+
} finally { Jolt.destroy(result); }
|
|
135
|
+
} finally { Jolt.destroy(settings); }
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function createBodyShape(Jolt,specs){
|
|
139
|
+
if(!specs.length){ const shape=new Jolt.EmptyShape(); shape.AddRef(); return shape; }
|
|
140
|
+
if(specs.length===1 && !specs[0].translation && !specs[0].rotation) return createOwnedShape(Jolt,specs[0],1);
|
|
141
|
+
|
|
142
|
+
const compound=new Jolt.StaticCompoundShapeSettings();
|
|
143
|
+
try {
|
|
144
|
+
for(const [index,spec] of specs.entries()){
|
|
145
|
+
const settings=createShapeSettings(Jolt,spec,index+1);
|
|
146
|
+
const position=new Jolt.Vec3(...(spec.translation||ZERO));
|
|
147
|
+
const rotation=new Jolt.Quat(...(spec.rotation||IDENTITY));
|
|
148
|
+
try {
|
|
149
|
+
compound.AddShapeShapeSettings(position,rotation,settings,index+1);
|
|
150
|
+
} finally {
|
|
151
|
+
Jolt.destroy(position);
|
|
152
|
+
Jolt.destroy(rotation);
|
|
153
|
+
}
|
|
154
|
+
// Compound owns the child settings after AddShapeShapeSettings.
|
|
155
|
+
}
|
|
156
|
+
const result=compound.Create();
|
|
157
|
+
try {
|
|
158
|
+
if(!result.IsValid()) throw new Error('Jolt rejected compound collider shape');
|
|
159
|
+
const shape=result.Get();
|
|
160
|
+
shape.AddRef();
|
|
161
|
+
result.Clear();
|
|
162
|
+
return shape;
|
|
163
|
+
} finally { Jolt.destroy(result); }
|
|
164
|
+
} finally { Jolt.destroy(compound); }
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const destroyOwnedShape=(shape)=>shape?.Release?.();
|
|
168
|
+
|
|
169
|
+
function createTransform(Jolt,position,rotation){
|
|
170
|
+
const p=new Jolt.RVec3(...tuple3(position));
|
|
171
|
+
const q=new Jolt.Quat(...tuple4(rotation));
|
|
172
|
+
try { return Jolt.RMat44.prototype.sRotationTranslation(q,p); }
|
|
173
|
+
finally { Jolt.destroy(q); Jolt.destroy(p); }
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function createQueryFilters(Jolt,world){
|
|
177
|
+
return {
|
|
178
|
+
broadPhase:new Jolt.DefaultBroadPhaseLayerFilter(world.jolt.GetObjectVsBroadPhaseLayerFilter(),LAYER),
|
|
179
|
+
object:new Jolt.DefaultObjectLayerFilter(world.jolt.GetObjectLayerPairFilter(),LAYER),
|
|
180
|
+
body:new Jolt.BodyFilter(),
|
|
181
|
+
shape:new Jolt.ShapeFilter()
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
function destroyQueryFilters(Jolt,filters){
|
|
185
|
+
Jolt.destroy(filters.shape); Jolt.destroy(filters.body); Jolt.destroy(filters.object); Jolt.destroy(filters.broadPhase);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export class JoltPhysicsBackend extends PhysicsBackend {
|
|
189
|
+
constructor({gravity={x:0,y:-9.81,z:0}}={}){
|
|
190
|
+
super('jolt',['rigid-body','collision','scene-query','articulated-body','joints','character-controller'],{
|
|
191
|
+
executionModes:['realtime','validation-only'],
|
|
192
|
+
qualities:{realtime:true,deterministic:true}
|
|
193
|
+
});
|
|
194
|
+
this.gravity=gravity;
|
|
195
|
+
this.Jolt=null;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
async init(){ this.Jolt=await loadJolt(); return this; }
|
|
199
|
+
|
|
200
|
+
createWorld(){
|
|
201
|
+
if(!this.Jolt) throw new Error('JoltPhysicsBackend.init() must complete before createWorld()');
|
|
202
|
+
const Jolt=this.Jolt;
|
|
203
|
+
const objectFilter=new Jolt.ObjectLayerPairFilterTable(1);
|
|
204
|
+
objectFilter.EnableCollision(LAYER,LAYER);
|
|
205
|
+
const broadPhaseLayer=new Jolt.BroadPhaseLayer(0);
|
|
206
|
+
const broadPhaseInterface=new Jolt.BroadPhaseLayerInterfaceTable(1,1);
|
|
207
|
+
broadPhaseInterface.MapObjectToBroadPhaseLayer(LAYER,broadPhaseLayer);
|
|
208
|
+
Jolt.destroy(broadPhaseLayer);
|
|
209
|
+
const broadPhaseFilter=new Jolt.ObjectVsBroadPhaseLayerFilterTable(broadPhaseInterface,1,objectFilter,1);
|
|
210
|
+
const settings=new Jolt.JoltSettings();
|
|
211
|
+
settings.mObjectLayerPairFilter=objectFilter;
|
|
212
|
+
settings.mBroadPhaseLayerInterface=broadPhaseInterface;
|
|
213
|
+
settings.mObjectVsBroadPhaseLayerFilter=broadPhaseFilter;
|
|
214
|
+
const jolt=new Jolt.JoltInterface(settings);
|
|
215
|
+
Jolt.destroy(settings);
|
|
216
|
+
const physicsSystem=jolt.GetPhysicsSystem();
|
|
217
|
+
const gravity=new Jolt.Vec3(this.gravity.x,this.gravity.y,this.gravity.z);
|
|
218
|
+
physicsSystem.SetGravity(gravity);
|
|
219
|
+
Jolt.destroy(gravity);
|
|
220
|
+
return {
|
|
221
|
+
jolt,physicsSystem,bodyInterface:physicsSystem.GetBodyInterface(),
|
|
222
|
+
bodies:new Map(),colliders:new Map(),joints:new Map(),
|
|
223
|
+
nextColliderKey:1,nextJointKey:1,nextSubGroupId:1,disabledJointPairs:new Map(),
|
|
224
|
+
groupFilter:null,groupFilterCapacity:0
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
step(world,dt){
|
|
229
|
+
for(const body of world.bodies.values()){
|
|
230
|
+
if(!body.nextPose) continue;
|
|
231
|
+
const pose=body.nextPose;
|
|
232
|
+
body.nextPose=null;
|
|
233
|
+
this.setBodyPose(body,{position:pose.position,rotation:pose.rotation,next:false,wake:true});
|
|
234
|
+
}
|
|
235
|
+
world.jolt.Step(dt,1);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
debugSnapshot(world,{nativeGeometry=true}={}){
|
|
239
|
+
return {
|
|
240
|
+
backend:this.identity,
|
|
241
|
+
// The production Jolt build does not expose its optional DebugRenderer.
|
|
242
|
+
// Normalized body/collider/joint state is supplied by PhysicsSystem.
|
|
243
|
+
nativeGeometry:null,
|
|
244
|
+
metrics:{ bodyCount:world?.bodies?.size ?? 0, colliderCount:world?.colliders?.size ?? 0, jointCount:world?.joints?.size ?? 0 },
|
|
245
|
+
nativeGeometryAvailable:false,
|
|
246
|
+
nativeGeometryRequested:Boolean(nativeGeometry)
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
dispose(world){
|
|
251
|
+
if(!world) return;
|
|
252
|
+
for(const joint of [...world.joints.values()]) this._removeJoint(world,joint);
|
|
253
|
+
for(const body of [...world.bodies.values()]) this.removeBody(world,body);
|
|
254
|
+
this.Jolt.destroy(world.jolt);
|
|
255
|
+
world.bodies.clear(); world.colliders.clear(); world.joints.clear(); world.disabledJointPairs.clear();
|
|
256
|
+
world.groupFilter=null; world.groupFilterCapacity=0;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
createBody(world,{type='fixed',position=ZERO,rotation=IDENTITY,canSleep=true,lockTranslation=null,lockRotation=null}={}){
|
|
260
|
+
const Jolt=this.Jolt;
|
|
261
|
+
const empty=new Jolt.EmptyShape();
|
|
262
|
+
const p=new Jolt.RVec3(...position);
|
|
263
|
+
const q=new Jolt.Quat(...rotation);
|
|
264
|
+
const settings=new Jolt.BodyCreationSettings(empty,p,q,motionType(Jolt,type),LAYER);
|
|
265
|
+
if(type==='dynamic') settings.mAllowedDOFs=allowedDofs(Jolt,lockTranslation,lockRotation);
|
|
266
|
+
const subGroupId=world.nextSubGroupId++;
|
|
267
|
+
Jolt.destroy(p); Jolt.destroy(q);
|
|
268
|
+
const native=world.bodyInterface.CreateBody(settings);
|
|
269
|
+
if(type==='dynamic') native.SetAllowSleeping(Boolean(canSleep));
|
|
270
|
+
Jolt.destroy(settings);
|
|
271
|
+
world.bodyInterface.AddBody(native.GetID(),activation(Jolt,type!=='fixed'));
|
|
272
|
+
const body={kind:'jolt-body',world,native,key:native.GetID().GetIndexAndSequenceNumber(),subGroupId,colliders:[],nextPose:null,collisionFilter:null};
|
|
273
|
+
world.bodies.set(body.key,body);
|
|
274
|
+
if(world.groupFilter) this._rebuildGroupFilter(world,subGroupId+1);
|
|
275
|
+
return body;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
removeBody(world,body){
|
|
279
|
+
if(!body || !world.bodies.has(body.key)) return;
|
|
280
|
+
for(const joint of [...world.joints.values()]) if(joint.parentBody===body||joint.childBody===body) this._removeJoint(world,joint);
|
|
281
|
+
for(const collider of body.colliders) {
|
|
282
|
+
destroyOwnedShape(collider.nativeShape);
|
|
283
|
+
world.colliders.delete(collider.key);
|
|
284
|
+
}
|
|
285
|
+
const id=body.native.GetID();
|
|
286
|
+
if(world.bodyInterface.IsAdded(id)) world.bodyInterface.RemoveBody(id);
|
|
287
|
+
world.bodyInterface.DestroyBody(id);
|
|
288
|
+
body.colliders.length=0;
|
|
289
|
+
world.bodies.delete(body.key);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
createColliders(world,body,specs=[],{mass,friction,restitution}={}){
|
|
293
|
+
const Jolt=this.Jolt;
|
|
294
|
+
const semantic=specs.map((spec,index)=>{
|
|
295
|
+
const record={
|
|
296
|
+
kind:'jolt-collider',body,index,key:world.nextColliderKey++,spec:cloneSpec(spec),
|
|
297
|
+
nativeShape:createOwnedShape(Jolt,spec,index+1)
|
|
298
|
+
};
|
|
299
|
+
return record;
|
|
300
|
+
});
|
|
301
|
+
let bodyShape;
|
|
302
|
+
try { bodyShape=createBodyShape(Jolt,specs); }
|
|
303
|
+
catch(error){ for(const collider of semantic) destroyOwnedShape(collider.nativeShape); throw error; }
|
|
304
|
+
|
|
305
|
+
try {
|
|
306
|
+
world.bodyInterface.SetShape(body.native.GetID(),bodyShape,true,activation(Jolt,true));
|
|
307
|
+
} finally { destroyOwnedShape(bodyShape); }
|
|
308
|
+
|
|
309
|
+
for(const old of body.colliders){ destroyOwnedShape(old.nativeShape); world.colliders.delete(old.key); }
|
|
310
|
+
body.colliders=semantic;
|
|
311
|
+
for(const collider of semantic) world.colliders.set(collider.key,collider);
|
|
312
|
+
|
|
313
|
+
if(friction!=null) world.bodyInterface.SetFriction(body.native.GetID(),friction);
|
|
314
|
+
if(restitution!=null) world.bodyInterface.SetRestitution(body.native.GetID(),restitution);
|
|
315
|
+
if(mass!=null && mass>0 && this.bodyType(body)==='dynamic') body.native.GetMotionProperties()?.ScaleToMass(mass);
|
|
316
|
+
return [...semantic];
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
colliders(body){ return body ? [...body.colliders] : []; }
|
|
320
|
+
bodyKey(body){ return body?.key ?? null; }
|
|
321
|
+
colliderKey(collider){ return collider?.key ?? null; }
|
|
322
|
+
colliderParent(collider){ return collider?.body ?? null; }
|
|
323
|
+
|
|
324
|
+
colliderSnapshot(collider){
|
|
325
|
+
if(!collider) return null;
|
|
326
|
+
const pose=worldPoseForCollider(this.bodyPose(collider.body),collider);
|
|
327
|
+
return {
|
|
328
|
+
ref:collider,key:collider.key,parent:collider.body,
|
|
329
|
+
position:{x:pose.position[0],y:pose.position[1],z:pose.position[2]},
|
|
330
|
+
rotation:{x:pose.rotation[0],y:pose.rotation[1],z:pose.rotation[2],w:pose.rotation[3]},
|
|
331
|
+
shape:shapeDescription(collider.spec),shapeRef:collider
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
bodyType(body){ return semanticMotionType(this.Jolt,body.world.bodyInterface.GetMotionType(body.native.GetID())); }
|
|
336
|
+
setBodyType(body,type){ body.world.bodyInterface.SetMotionType(body.native.GetID(),motionType(this.Jolt,type),activation(this.Jolt,true)); return true; }
|
|
337
|
+
|
|
338
|
+
bodyPose(body,{next=false}={}){
|
|
339
|
+
if(next && body.nextPose) return {position:[...body.nextPose.position],rotation:[...body.nextPose.rotation]};
|
|
340
|
+
return {position:array3(body.native.GetPosition()),rotation:array4(body.native.GetRotation())};
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
setBodyPose(body,{position=null,rotation=null,next=false,wake=true}={}){
|
|
344
|
+
if(!body) return false;
|
|
345
|
+
const current=next&&body.nextPose ? body.nextPose : this.bodyPose(body);
|
|
346
|
+
const target={position:position ? (Array.isArray(position)?[...position]:[position.x,position.y,position.z]) : [...current.position],
|
|
347
|
+
rotation:rotation ? (Array.isArray(rotation)?[...rotation]:[rotation.x,rotation.y,rotation.z,rotation.w]) : [...current.rotation]};
|
|
348
|
+
if(next){ body.nextPose=target; return true; }
|
|
349
|
+
const Jolt=this.Jolt;
|
|
350
|
+
const p=new Jolt.RVec3(...target.position);
|
|
351
|
+
const q=new Jolt.Quat(...target.rotation);
|
|
352
|
+
try { body.world.bodyInterface.SetPositionAndRotation(body.native.GetID(),p,q,activation(Jolt,wake)); }
|
|
353
|
+
finally { Jolt.destroy(q); Jolt.destroy(p); }
|
|
354
|
+
body.nextPose=null;
|
|
355
|
+
return true;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
translateBody(body,delta,{clearLinearVelocity=true,wake=true}={}){
|
|
359
|
+
const pose=this.bodyPose(body);
|
|
360
|
+
this.setBodyPose(body,{position:[pose.position[0]+delta[0],pose.position[1]+delta[1],pose.position[2]+delta[2]],wake});
|
|
361
|
+
if(clearLinearVelocity) this.clearBodyMotion(body,{linear:true,angular:false,wake});
|
|
362
|
+
return true;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
clearBodyMotion(body,{wake=false,linear=true,angular=true}={}){
|
|
366
|
+
const Jolt=this.Jolt;
|
|
367
|
+
if(linear) withVec3(Jolt,ZERO,(v)=>body.world.bodyInterface.SetLinearVelocity(body.native.GetID(),v));
|
|
368
|
+
if(angular) withVec3(Jolt,ZERO,(v)=>body.world.bodyInterface.SetAngularVelocity(body.native.GetID(),v));
|
|
369
|
+
if(wake) this.wakeBody(body);
|
|
370
|
+
return true;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
bodyMotion(body){
|
|
374
|
+
const linear=body.world.bodyInterface.GetLinearVelocity(body.native.GetID());
|
|
375
|
+
const angular=body.world.bodyInterface.GetAngularVelocity(body.native.GetID());
|
|
376
|
+
const lv=array3(linear),av=array3(angular);
|
|
377
|
+
return {
|
|
378
|
+
sleeping:!body.world.bodyInterface.IsActive(body.native.GetID()),
|
|
379
|
+
linearVelocity:lv,angularVelocity:av,
|
|
380
|
+
linearSpeed:Math.hypot(...lv),angularSpeed:Math.hypot(...av)
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
setBodyMotion(body,{linearVelocity=null,angularVelocity=null,wake=true}={}){
|
|
384
|
+
if(!body || this.bodyType(body)!=='dynamic') return false;
|
|
385
|
+
const Jolt=this.Jolt,id=body.native.GetID();
|
|
386
|
+
if(linearVelocity) withVec3(Jolt,linearVelocity,(v)=>body.world.bodyInterface.SetLinearVelocity(id,v));
|
|
387
|
+
if(angularVelocity) withVec3(Jolt,angularVelocity,(v)=>body.world.bodyInterface.SetAngularVelocity(id,v));
|
|
388
|
+
if(wake) this.wakeBody(body);
|
|
389
|
+
return true;
|
|
390
|
+
}
|
|
391
|
+
applyImpulse(body,impulse,{point=null,wake=true}={}){
|
|
392
|
+
if(!body || this.bodyType(body)!=='dynamic') return false;
|
|
393
|
+
const Jolt=this.Jolt,id=body.native.GetID();
|
|
394
|
+
if(point){
|
|
395
|
+
const impulseVec=new Jolt.Vec3(...impulse),position=new Jolt.RVec3(...point);
|
|
396
|
+
try { body.world.bodyInterface.AddImpulse(id,impulseVec,position); }
|
|
397
|
+
finally { Jolt.destroy(position); Jolt.destroy(impulseVec); }
|
|
398
|
+
} else withVec3(Jolt,impulse,(v)=>body.world.bodyInterface.AddImpulse(id,v));
|
|
399
|
+
if(wake) this.wakeBody(body);
|
|
400
|
+
return true;
|
|
401
|
+
}
|
|
402
|
+
applyForce(body,force,{point=null,wake=true}={}){
|
|
403
|
+
if(!body || this.bodyType(body)!=='dynamic') return false;
|
|
404
|
+
const Jolt=this.Jolt,id=body.native.GetID(),mode=activation(Jolt,wake);
|
|
405
|
+
if(point){
|
|
406
|
+
const forceVec=new Jolt.Vec3(...force),position=new Jolt.RVec3(...point);
|
|
407
|
+
try { body.world.bodyInterface.AddForce(id,forceVec,position,mode); }
|
|
408
|
+
finally { Jolt.destroy(position); Jolt.destroy(forceVec); }
|
|
409
|
+
} else withVec3(Jolt,force,(v)=>body.world.bodyInterface.AddForce(id,v,mode));
|
|
410
|
+
return true;
|
|
411
|
+
}
|
|
412
|
+
applyTorque(body,torque,{wake=true}={}){
|
|
413
|
+
if(!body || this.bodyType(body)!=='dynamic') return false;
|
|
414
|
+
const Jolt=this.Jolt,id=body.native.GetID();
|
|
415
|
+
withVec3(Jolt,torque,(v)=>body.world.bodyInterface.AddTorque(id,v,activation(Jolt,wake)));
|
|
416
|
+
return true;
|
|
417
|
+
}
|
|
418
|
+
setBodyMaterial(body,{friction=null,restitution=null}={}){
|
|
419
|
+
if(!body) return false;
|
|
420
|
+
const api=body.world.bodyInterface,id=body.native.GetID();
|
|
421
|
+
if(friction!=null) api.SetFriction(id,friction);
|
|
422
|
+
if(restitution!=null) api.SetRestitution(id,restitution);
|
|
423
|
+
return true;
|
|
424
|
+
}
|
|
425
|
+
setBodyDynamics(body,{linearDamping=null,angularDamping=null,gravityScale=null,wake=true}={}){
|
|
426
|
+
if(!body || this.bodyType(body)!=='dynamic') return false;
|
|
427
|
+
const motion=body.native.GetMotionProperties?.();
|
|
428
|
+
if(linearDamping!=null) motion?.SetLinearDamping(linearDamping);
|
|
429
|
+
if(angularDamping!=null) motion?.SetAngularDamping(angularDamping);
|
|
430
|
+
if(gravityScale!=null) body.world.bodyInterface.SetGravityFactor(body.native.GetID(),gravityScale);
|
|
431
|
+
if(wake) this.wakeBody(body);
|
|
432
|
+
return true;
|
|
433
|
+
}
|
|
434
|
+
setBodyCcd(body,enabled){
|
|
435
|
+
if(!body || this.bodyType(body)!=='dynamic') return false;
|
|
436
|
+
body.world.bodyInterface.SetMotionQuality(body.native.GetID(),enabled ? this.Jolt.EMotionQuality_LinearCast : this.Jolt.EMotionQuality_Discrete);
|
|
437
|
+
return true;
|
|
438
|
+
}
|
|
439
|
+
setBodySensor(body,enabled){
|
|
440
|
+
if(!body) return false;
|
|
441
|
+
body.world.bodyInterface.SetIsSensor(body.native.GetID(),Boolean(enabled));
|
|
442
|
+
return true;
|
|
443
|
+
}
|
|
444
|
+
setBodyCollisionFilter(body,filter=null){
|
|
445
|
+
if(!body) return false;
|
|
446
|
+
body.collisionFilter=filter ? {membership:filter.membership & 0xffff,filter:filter.filter & 0xffff} : null;
|
|
447
|
+
this._rebuildGroupFilter(body.world,body.world.nextSubGroupId+1);
|
|
448
|
+
return true;
|
|
449
|
+
}
|
|
450
|
+
sleepBody(body){ if(!body || this.bodyType(body)!=='dynamic') return false; body.world.bodyInterface.DeactivateBody(body.native.GetID()); return true; }
|
|
451
|
+
wakeBody(body){ body?.world.bodyInterface.ActivateBody(body.native.GetID()); return Boolean(body); }
|
|
452
|
+
|
|
453
|
+
_assignCollisionGroup(world,body){
|
|
454
|
+
if(!world.groupFilter||!body) return;
|
|
455
|
+
const group=new this.Jolt.CollisionGroup(world.groupFilter,1,body.subGroupId);
|
|
456
|
+
try { world.bodyInterface.SetCollisionGroup(body.native.GetID(),group); }
|
|
457
|
+
finally { this.Jolt.destroy(group); }
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
_bodyPairAllowed(world,left,right){
|
|
461
|
+
if(world.disabledJointPairs.has(pairKey(left.subGroupId,right.subGroupId))) return false;
|
|
462
|
+
const a=left.collisionFilter || {membership:0xffff,filter:0xffff};
|
|
463
|
+
const b=right.collisionFilter || {membership:0xffff,filter:0xffff};
|
|
464
|
+
return (a.membership & b.filter)!==0 && (b.membership & a.filter)!==0;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
_rebuildGroupFilter(world,requiredCapacity=0){
|
|
468
|
+
let capacity=Math.max(16,world.groupFilterCapacity||0);
|
|
469
|
+
while(capacity<Math.max(requiredCapacity,world.nextSubGroupId+1)) capacity*=2;
|
|
470
|
+
const filter=new this.Jolt.GroupFilterTable(capacity);
|
|
471
|
+
const bodies=[...world.bodies.values()];
|
|
472
|
+
for(let i=0;i<bodies.length;i++) for(let j=i+1;j<bodies.length;j++) {
|
|
473
|
+
if(!this._bodyPairAllowed(world,bodies[i],bodies[j])) filter.DisableCollision(bodies[i].subGroupId,bodies[j].subGroupId);
|
|
474
|
+
}
|
|
475
|
+
world.groupFilter=filter;
|
|
476
|
+
world.groupFilterCapacity=capacity;
|
|
477
|
+
for(const body of bodies) this._assignCollisionGroup(world,body);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
_jointWorldFrame(parentBody,childBody,part){
|
|
481
|
+
const parentPose=this.bodyPose(parentBody);
|
|
482
|
+
const childPose=this.bodyPose(childBody);
|
|
483
|
+
const parentAnchor=tuple3(part.joint.parentAnchor||ZERO);
|
|
484
|
+
const childAnchor=tuple3(part.joint.childAnchor||ZERO);
|
|
485
|
+
const parentOffset=rotateVector(parentPose.rotation,parentAnchor);
|
|
486
|
+
const childOffset=rotateVector(childPose.rotation,childAnchor);
|
|
487
|
+
const axis=normalized3(rotateVector(parentPose.rotation,part.joint.axis||[1,0,0]));
|
|
488
|
+
return {
|
|
489
|
+
parentPoint:[parentPose.position[0]+parentOffset[0],parentPose.position[1]+parentOffset[1],parentPose.position[2]+parentOffset[2]],
|
|
490
|
+
childPoint:[childPose.position[0]+childOffset[0],childPose.position[1]+childOffset[1],childPose.position[2]+childOffset[2]],
|
|
491
|
+
axis,normal:perpendicular3(axis)
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
createJoint(world,part,parentBody,childBody){
|
|
496
|
+
const Jolt=this.Jolt;
|
|
497
|
+
const frame=this._jointWorldFrame(parentBody,childBody,part);
|
|
498
|
+
const childPose=this.bodyPose(childBody);
|
|
499
|
+
let settings,native,type;
|
|
500
|
+
if(part.joint.type==='revolute'){
|
|
501
|
+
settings=new Jolt.HingeConstraintSettings(); type='revolute';
|
|
502
|
+
settings.mSpace=Jolt.EConstraintSpace_WorldSpace;
|
|
503
|
+
settings.mPoint1.Set(...frame.parentPoint); settings.mPoint2.Set(...frame.childPoint);
|
|
504
|
+
settings.mHingeAxis1.Set(...frame.axis); settings.mHingeAxis2.Set(...frame.axis);
|
|
505
|
+
settings.mNormalAxis1.Set(...frame.normal); settings.mNormalAxis2.Set(...frame.normal);
|
|
506
|
+
if(part.joint.limits){ settings.mLimitsMin=part.joint.limits[0]; settings.mLimitsMax=part.joint.limits[1]; }
|
|
507
|
+
native=Jolt.castObject(settings.Create(parentBody.native,childBody.native),Jolt.HingeConstraint);
|
|
508
|
+
} else if(part.joint.type==='prismatic'){
|
|
509
|
+
settings=new Jolt.SliderConstraintSettings(); type='prismatic';
|
|
510
|
+
settings.mSpace=Jolt.EConstraintSpace_WorldSpace;
|
|
511
|
+
settings.mAutoDetectPoint=false;
|
|
512
|
+
settings.mPoint1.Set(...frame.parentPoint); settings.mPoint2.Set(...frame.childPoint);
|
|
513
|
+
settings.mSliderAxis1.Set(...frame.axis); settings.mSliderAxis2.Set(...frame.axis);
|
|
514
|
+
settings.mNormalAxis1.Set(...frame.normal); settings.mNormalAxis2.Set(...frame.normal);
|
|
515
|
+
if(part.joint.limits){ settings.mLimitsMin=part.joint.limits[0]; settings.mLimitsMax=part.joint.limits[1]; }
|
|
516
|
+
native=Jolt.castObject(settings.Create(parentBody.native,childBody.native),Jolt.SliderConstraint);
|
|
517
|
+
} else if(part.joint.type==='fixed'){
|
|
518
|
+
settings=new Jolt.FixedConstraintSettings(); type='fixed';
|
|
519
|
+
settings.mSpace=Jolt.EConstraintSpace_WorldSpace;
|
|
520
|
+
settings.mAutoDetectPoint=false;
|
|
521
|
+
settings.mPoint1.Set(...frame.parentPoint); settings.mPoint2.Set(...frame.childPoint);
|
|
522
|
+
const axisX=normalized3(rotateVector(childPose.rotation,[1,0,0]));
|
|
523
|
+
const axisY=normalized3(rotateVector(childPose.rotation,[0,1,0]));
|
|
524
|
+
settings.mAxisX1.Set(...axisX); settings.mAxisX2.Set(...axisX);
|
|
525
|
+
settings.mAxisY1.Set(...axisY); settings.mAxisY2.Set(...axisY);
|
|
526
|
+
native=settings.Create(parentBody.native,childBody.native);
|
|
527
|
+
} else {
|
|
528
|
+
throw new TypeError(`JoltPhysicsBackend unsupported joint type: ${part.joint.type}`);
|
|
529
|
+
}
|
|
530
|
+
Jolt.destroy(settings);
|
|
531
|
+
world.physicsSystem.AddConstraint(native);
|
|
532
|
+
const joint={kind:'jolt-joint',key:world.nextJointKey++,type,native,parentBody,childBody,pair:pairKey(parentBody.subGroupId,childBody.subGroupId)};
|
|
533
|
+
world.joints.set(joint.key,joint);
|
|
534
|
+
const pairCount=world.disabledJointPairs.get(joint.pair)||0;
|
|
535
|
+
world.disabledJointPairs.set(joint.pair,pairCount+1);
|
|
536
|
+
this._rebuildGroupFilter(world,Math.max(parentBody.subGroupId,childBody.subGroupId)+1);
|
|
537
|
+
return joint;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
_removeJoint(world,joint){
|
|
541
|
+
if(!joint || !world.joints.has(joint.key)) return;
|
|
542
|
+
// AddConstraint() owns the constraint reference. We never AddRef() here,
|
|
543
|
+
// so RemoveConstraint() must be the only release path. Calling Release()
|
|
544
|
+
// again corrupts Jolt ownership and can crash later during DestroyBody().
|
|
545
|
+
world.physicsSystem.RemoveConstraint(joint.native);
|
|
546
|
+
world.joints.delete(joint.key);
|
|
547
|
+
const count=(world.disabledJointPairs.get(joint.pair)||1)-1;
|
|
548
|
+
if(count<=0) world.disabledJointPairs.delete(joint.pair);
|
|
549
|
+
else world.disabledJointPairs.set(joint.pair,count);
|
|
550
|
+
if(world.groupFilter) this._rebuildGroupFilter(world);
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
setJointTarget(joint,target,{stiffness=40,damping=8}={}){
|
|
554
|
+
if(!joint || joint.type==='fixed') return false;
|
|
555
|
+
const Jolt=this.Jolt;
|
|
556
|
+
if(target == null) { joint.native.SetMotorState(Jolt.EMotorState_Off); return true; }
|
|
557
|
+
const motor=joint.native.GetMotorSettings();
|
|
558
|
+
motor.mSpringSettings.mMode=Jolt.ESpringMode_StiffnessAndDamping;
|
|
559
|
+
motor.mSpringSettings.mStiffness=stiffness;
|
|
560
|
+
motor.mSpringSettings.mDamping=damping;
|
|
561
|
+
joint.native.SetMotorState(Jolt.EMotorState_Position);
|
|
562
|
+
if(joint.type==='revolute') joint.native.SetTargetAngle(target);
|
|
563
|
+
else if(joint.type==='prismatic') joint.native.SetTargetPosition(target);
|
|
564
|
+
else return false;
|
|
565
|
+
this.wakeBody(joint.parentBody); this.wakeBody(joint.childBody);
|
|
566
|
+
return true;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
createCharacterController(world,{
|
|
570
|
+
offset=.02,autostepHeight=.3,autostepMinWidth=.2,snapToGround=.3,
|
|
571
|
+
maxSlopeClimbAngle=Math.PI/4,minSlopeSlideAngle=Math.PI/6
|
|
572
|
+
}={}){
|
|
573
|
+
return {
|
|
574
|
+
kind:'jolt-character-controller',world,
|
|
575
|
+
offset,autostepHeight,autostepMinWidth,snapToGround,maxSlopeClimbAngle,minSlopeSlideAngle
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
removeCharacterController(){ /* Stateless adapter: CharacterVirtual instances are per-move. */ }
|
|
580
|
+
|
|
581
|
+
cancelCharacterMovement(body){
|
|
582
|
+
const pose=this.bodyPose(body);
|
|
583
|
+
if(!pose) return false;
|
|
584
|
+
return this.setBodyPose(body,{...pose,next:true});
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
_characterSupportRadius(collider){
|
|
588
|
+
const shape=collider?.spec;
|
|
589
|
+
if(!shape) return .1;
|
|
590
|
+
if(shape.shape==='capsule'||shape.shape==='cylinder') return Math.max(.01,shape.radius||.1);
|
|
591
|
+
if(shape.shape==='box') return Math.max(.01,Math.min(shape.halfExtents?.[0]||.1,shape.halfExtents?.[2]||.1));
|
|
592
|
+
if(shape.shape==='convexHull'&&shape.vertices?.length){
|
|
593
|
+
let radius=Infinity;
|
|
594
|
+
for(let i=0;i<shape.vertices.length;i+=3) radius=Math.min(radius,Math.hypot(shape.vertices[i],shape.vertices[i+2]));
|
|
595
|
+
return Number.isFinite(radius)&&radius>1e-3?radius:.1;
|
|
596
|
+
}
|
|
597
|
+
return .1;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
moveCharacter(controller,body,desiredTranslation,{predicate=null}={}){
|
|
601
|
+
if(!controller||controller.world!==body?.world||this.bodyType(body)!=='kinematic'){
|
|
602
|
+
return {success:false,code:'CHARACTER_BODY_UNAVAILABLE',movement:[0,0,0],grounded:false,collisions:[]};
|
|
603
|
+
}
|
|
604
|
+
const colliders=this.colliders(body);
|
|
605
|
+
if(colliders.length!==1){
|
|
606
|
+
return {success:false,code:'CHARACTER_BODY_UNAVAILABLE',movement:[0,0,0],grounded:false,collisions:[]};
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
const Jolt=this.Jolt,world=body.world,pose=this.bodyPose(body);
|
|
610
|
+
const settings=new Jolt.CharacterVirtualSettings();
|
|
611
|
+
settings.mMass=1000;
|
|
612
|
+
settings.mMaxSlopeAngle=controller.maxSlopeClimbAngle;
|
|
613
|
+
settings.mMaxStrength=100;
|
|
614
|
+
settings.mShape=body.native.GetShape();
|
|
615
|
+
settings.mCharacterPadding=controller.offset;
|
|
616
|
+
settings.mPredictiveContactDistance=Math.max(.05,controller.offset*2);
|
|
617
|
+
const up=new Jolt.Vec3(0,1,0);
|
|
618
|
+
const supportingVolume=new Jolt.Plane(up,-this._characterSupportRadius(colliders[0]));
|
|
619
|
+
settings.mSupportingVolume=supportingVolume;
|
|
620
|
+
const position=new Jolt.RVec3(...pose.position);
|
|
621
|
+
const rotation=new Jolt.Quat(...pose.rotation);
|
|
622
|
+
const character=new Jolt.CharacterVirtual(settings,position,rotation,world.physicsSystem);
|
|
623
|
+
Jolt.destroy(rotation); Jolt.destroy(position); Jolt.destroy(supportingVolume); Jolt.destroy(up); Jolt.destroy(settings);
|
|
624
|
+
|
|
625
|
+
const update=new Jolt.ExtendedUpdateSettings();
|
|
626
|
+
update.mStickToFloorStepDown.Set(0,-controller.snapToGround,0);
|
|
627
|
+
update.mWalkStairsStepUp.Set(0,controller.autostepHeight,0);
|
|
628
|
+
update.mWalkStairsMinStepForward=controller.autostepMinWidth;
|
|
629
|
+
update.mWalkStairsStepForwardTest=Math.max(.05,controller.autostepMinWidth);
|
|
630
|
+
update.mWalkStairsStepDownExtra.Set(0,-Math.min(controller.snapToGround,.1),0);
|
|
631
|
+
|
|
632
|
+
const bpFilter=new Jolt.DefaultBroadPhaseLayerFilter(world.jolt.GetObjectVsBroadPhaseLayerFilter(),LAYER);
|
|
633
|
+
const objectFilter=new Jolt.DefaultObjectLayerFilter(world.jolt.GetObjectLayerPairFilter(),LAYER);
|
|
634
|
+
const bodyFilter=new Jolt.IgnoreMultipleBodiesFilter();
|
|
635
|
+
bodyFilter.IgnoreBody(body.native.GetID());
|
|
636
|
+
if(predicate){
|
|
637
|
+
for(const otherBody of world.bodies.values()){
|
|
638
|
+
if(otherBody===body||!otherBody.colliders.length) continue;
|
|
639
|
+
if(otherBody.colliders.every((collider)=>!predicate(collider))) bodyFilter.IgnoreBody(otherBody.native.GetID());
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
const shapeFilter=new Jolt.ShapeFilter();
|
|
643
|
+
const zeroGravity=new Jolt.Vec3(0,0,0);
|
|
644
|
+
const velocity=new Jolt.Vec3(...tuple3(desiredTranslation));
|
|
645
|
+
character.SetLinearVelocity(velocity);
|
|
646
|
+
Jolt.destroy(velocity);
|
|
647
|
+
|
|
648
|
+
try {
|
|
649
|
+
character.ExtendedUpdate(1,zeroGravity,update,bpFilter,objectFilter,bodyFilter,shapeFilter,world.jolt.GetTempAllocator());
|
|
650
|
+
if(controller.snapToGround>0){
|
|
651
|
+
const stepDown=new Jolt.Vec3(0,-controller.snapToGround,0);
|
|
652
|
+
try { character.StickToFloor(stepDown,bpFilter,objectFilter,bodyFilter,shapeFilter,world.jolt.GetTempAllocator()); }
|
|
653
|
+
finally { Jolt.destroy(stepDown); }
|
|
654
|
+
}
|
|
655
|
+
character.RefreshContacts(bpFilter,objectFilter,bodyFilter,shapeFilter,world.jolt.GetTempAllocator());
|
|
656
|
+
const resultPosition=character.GetPosition();
|
|
657
|
+
const next=[resultPosition.GetX(),resultPosition.GetY(),resultPosition.GetZ()];
|
|
658
|
+
const movement=[next[0]-pose.position[0],next[1]-pose.position[1],next[2]-pose.position[2]];
|
|
659
|
+
const collisions=[];
|
|
660
|
+
const contacts=character.GetActiveContacts();
|
|
661
|
+
for(let index=0;index<contacts.size();index++){
|
|
662
|
+
const contact=contacts.at(index);
|
|
663
|
+
const collider=this._colliderFromHit(world,contact.mBodyB,contact.mSubShapeIDB);
|
|
664
|
+
if(!collider||collider.body===body||(predicate&&!predicate(collider))) continue;
|
|
665
|
+
const normal=contact.mContactNormal;
|
|
666
|
+
collisions.push({
|
|
667
|
+
collider,colliderKey:this.colliderKey(collider),
|
|
668
|
+
toi:Number.isFinite(contact.mFraction)?contact.mFraction:0,
|
|
669
|
+
normal:[normal.GetX(),normal.GetY(),normal.GetZ()]
|
|
670
|
+
});
|
|
671
|
+
}
|
|
672
|
+
this.setBodyPose(body,{position:next,rotation:pose.rotation,next:true});
|
|
673
|
+
return {
|
|
674
|
+
success:true,movement,
|
|
675
|
+
grounded:character.GetGroundState()===Jolt.EGroundState_OnGround,
|
|
676
|
+
collisions
|
|
677
|
+
};
|
|
678
|
+
} finally {
|
|
679
|
+
Jolt.destroy(zeroGravity); Jolt.destroy(shapeFilter); Jolt.destroy(bodyFilter); Jolt.destroy(objectFilter); Jolt.destroy(bpFilter); Jolt.destroy(update); character.Release();
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
syncSceneQueries(){ /* Jolt BodyInterface updates broadphase on pose/shape changes. */ }
|
|
684
|
+
|
|
685
|
+
createQueryShape(spec){ return {kind:'jolt-query-shape',spec:cloneSpec(spec),nativeShape:createOwnedShape(this.Jolt,spec)}; }
|
|
686
|
+
disposeQueryShape(shape){ if(shape?.kind==='jolt-query-shape'){ destroyOwnedShape(shape.nativeShape); shape.nativeShape=null; } }
|
|
687
|
+
|
|
688
|
+
_nativeShape(ref){
|
|
689
|
+
if(ref?.kind==='jolt-collider' || ref?.kind==='jolt-query-shape') return ref.nativeShape;
|
|
690
|
+
throw new TypeError('JoltPhysicsBackend requires a Jolt semantic shape handle');
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
_colliderFromHit(world,bodyId,subShapeId){
|
|
694
|
+
const body=world.bodies.get(nativeBodyIdNumber(bodyId));
|
|
695
|
+
if(!body || !body.colliders.length) return null;
|
|
696
|
+
if(body.colliders.length===1) return body.colliders[0];
|
|
697
|
+
const userData=body.native.GetShape().GetSubShapeUserData(subShapeId);
|
|
698
|
+
return body.colliders[userData-1] || null;
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
_allShapeHits(world,shapeRef,position,rotation,{maxSeparationDistance=0}={}){
|
|
702
|
+
const Jolt=this.Jolt;
|
|
703
|
+
const nativeShape=this._nativeShape(shapeRef);
|
|
704
|
+
const scale=new Jolt.Vec3(...UNIT);
|
|
705
|
+
const transform=createTransform(Jolt,position,rotation);
|
|
706
|
+
const settings=new Jolt.CollideShapeSettings();
|
|
707
|
+
settings.mMaxSeparationDistance=maxSeparationDistance;
|
|
708
|
+
const baseOffset=new Jolt.RVec3(...ZERO);
|
|
709
|
+
const collector=new Jolt.CollideShapeAllHitCollisionCollector();
|
|
710
|
+
const filters=createQueryFilters(Jolt,world);
|
|
711
|
+
try {
|
|
712
|
+
world.physicsSystem.GetNarrowPhaseQuery().CollideShape(
|
|
713
|
+
nativeShape,scale,transform,settings,baseOffset,collector,
|
|
714
|
+
filters.broadPhase,filters.object,filters.body,filters.shape
|
|
715
|
+
);
|
|
716
|
+
const hits=[];
|
|
717
|
+
if(collector.HadHit()){
|
|
718
|
+
for(let i=0;i<collector.mHits.size();i++){
|
|
719
|
+
const hit=collector.mHits.at(i);
|
|
720
|
+
hits.push({
|
|
721
|
+
collider:this._colliderFromHit(world,hit.mBodyID2,hit.mSubShapeID2),
|
|
722
|
+
penetrationDepth:hit.mPenetrationDepth,
|
|
723
|
+
normal:array3(hit.mPenetrationAxis)
|
|
724
|
+
});
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
return hits;
|
|
728
|
+
} finally {
|
|
729
|
+
destroyQueryFilters(Jolt,filters); Jolt.destroy(collector); Jolt.destroy(baseOffset); Jolt.destroy(settings); Jolt.destroy(transform); Jolt.destroy(scale);
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
intersectionsWithShape(world,position,rotation,shape,callback,{excludeCollider=null,excludeBody=null,predicate=null}={}){
|
|
734
|
+
const seen=new Set();
|
|
735
|
+
for(const hit of this._allShapeHits(world,shape,position,rotation)){
|
|
736
|
+
const collider=hit.collider;
|
|
737
|
+
if(!collider || seen.has(collider.key)) continue;
|
|
738
|
+
seen.add(collider.key);
|
|
739
|
+
if(excludeCollider && collider.key===excludeCollider.key) continue;
|
|
740
|
+
if(excludeBody && collider.body.key===excludeBody.key) continue;
|
|
741
|
+
if(predicate && !predicate(collider)) continue;
|
|
742
|
+
if(callback(collider)===false) break;
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
castCollider(world,source,velocity,{excludeCollider=null,excludeBody=null,predicate=null,maxToi=1}={}){
|
|
747
|
+
const Jolt=this.Jolt;
|
|
748
|
+
const sourcePose=this.colliderSnapshot(source);
|
|
749
|
+
const scale=new Jolt.Vec3(...UNIT);
|
|
750
|
+
const transform=createTransform(Jolt,[sourcePose.position.x,sourcePose.position.y,sourcePose.position.z],sourcePose.rotation);
|
|
751
|
+
const direction=new Jolt.Vec3(velocity[0],velocity[1],velocity[2]);
|
|
752
|
+
const cast=new Jolt.RShapeCast(source.nativeShape,scale,transform,direction);
|
|
753
|
+
const settings=new Jolt.ShapeCastSettings();
|
|
754
|
+
const baseOffset=new Jolt.RVec3(...ZERO);
|
|
755
|
+
const collector=new Jolt.CastShapeAllHitCollisionCollector();
|
|
756
|
+
const filters=createQueryFilters(Jolt,world);
|
|
757
|
+
try {
|
|
758
|
+
world.physicsSystem.GetNarrowPhaseQuery().CastShape(cast,settings,baseOffset,collector,filters.broadPhase,filters.object,filters.body,filters.shape);
|
|
759
|
+
let best=null;
|
|
760
|
+
if(collector.HadHit()){
|
|
761
|
+
for(let i=0;i<collector.mHits.size();i++){
|
|
762
|
+
const hit=collector.mHits.at(i);
|
|
763
|
+
if(hit.mFraction<0 || hit.mFraction>maxToi) continue;
|
|
764
|
+
const collider=this._colliderFromHit(world,hit.mBodyID2,hit.mSubShapeID2);
|
|
765
|
+
if(!collider || collider.key===source.key) continue;
|
|
766
|
+
if(excludeCollider && collider.key===excludeCollider.key) continue;
|
|
767
|
+
if(excludeBody && collider.body.key===excludeBody.key) continue;
|
|
768
|
+
if(predicate && !predicate(collider)) continue;
|
|
769
|
+
if(!best || hit.mFraction<best.timeOfImpact) best={collider,timeOfImpact:hit.mFraction};
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
return best;
|
|
773
|
+
} finally {
|
|
774
|
+
destroyQueryFilters(Jolt,filters); Jolt.destroy(collector); Jolt.destroy(baseOffset); Jolt.destroy(settings); Jolt.destroy(cast); Jolt.destroy(direction); Jolt.destroy(transform); Jolt.destroy(scale);
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
raycast(world,origin,direction,maxDistance,{predicate=null}={}){
|
|
779
|
+
const Jolt=this.Jolt;
|
|
780
|
+
const length=Math.hypot(direction[0],direction[1],direction[2]);
|
|
781
|
+
if(length<=1e-12 || maxDistance<=0) return null;
|
|
782
|
+
const ray=new Jolt.RRayCast();
|
|
783
|
+
ray.mOrigin.Set(origin[0],origin[1],origin[2]);
|
|
784
|
+
ray.mDirection.Set(direction[0]/length*maxDistance,direction[1]/length*maxDistance,direction[2]/length*maxDistance);
|
|
785
|
+
const settings=new Jolt.RayCastSettings();
|
|
786
|
+
const collector=new Jolt.CastRayAllHitCollisionCollector();
|
|
787
|
+
const filters=createQueryFilters(Jolt,world);
|
|
788
|
+
try {
|
|
789
|
+
world.physicsSystem.GetNarrowPhaseQuery().CastRay(ray,settings,collector,filters.broadPhase,filters.object,filters.body,filters.shape);
|
|
790
|
+
let best=null;
|
|
791
|
+
if(collector.HadHit()){
|
|
792
|
+
for(let i=0;i<collector.mHits.size();i++){
|
|
793
|
+
const hit=collector.mHits.at(i);
|
|
794
|
+
const collider=this._colliderFromHit(world,hit.mBodyID,hit.mSubShapeID2);
|
|
795
|
+
if(!collider || (predicate && !predicate(collider))) continue;
|
|
796
|
+
const toi=hit.mFraction*maxDistance;
|
|
797
|
+
if(!best || toi<best.timeOfImpact) best={collider,timeOfImpact:toi};
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
return best;
|
|
801
|
+
} finally { destroyQueryFilters(Jolt,filters); Jolt.destroy(collector); Jolt.destroy(settings); Jolt.destroy(ray); }
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
contactPairs(world,source){
|
|
805
|
+
const pose=this.colliderSnapshot(source);
|
|
806
|
+
const hits=this._allShapeHits(world,source,[pose.position.x,pose.position.y,pose.position.z],pose.rotation,{maxSeparationDistance:1e-4});
|
|
807
|
+
const byCollider=new Map();
|
|
808
|
+
for(const hit of hits){
|
|
809
|
+
const other=hit.collider;
|
|
810
|
+
if(!other || other.body.key===source.body.key || other.key===source.key) continue;
|
|
811
|
+
if(source.body.world.disabledJointPairs.has(pairKey(source.body.subGroupId,other.body.subGroupId))) continue;
|
|
812
|
+
const previous=byCollider.get(other.key);
|
|
813
|
+
if(!previous || hit.penetrationDepth>previous.penetrationDepth) byCollider.set(other.key,hit);
|
|
814
|
+
}
|
|
815
|
+
return [...byCollider.values()].map((hit)=>({
|
|
816
|
+
other:hit.collider,manifoldCount:1,contactCount:1,activeContactCount:1,
|
|
817
|
+
minDistance:hit.penetrationDepth>0 ? -hit.penetrationDepth : 0,totalImpulse:null,normal:hit.normal,
|
|
818
|
+
evidenceKind:'geometric-contact',impulseAvailable:false
|
|
819
|
+
}));
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
penetrations(world,source){
|
|
823
|
+
const pose=this.colliderSnapshot(source);
|
|
824
|
+
return this._allShapeHits(world,source,[pose.position.x,pose.position.y,pose.position.z],pose.rotation)
|
|
825
|
+
.filter((hit)=>hit.collider && hit.collider.body.key!==source.body.key && hit.penetrationDepth>0)
|
|
826
|
+
.map((hit)=>({other:hit.collider,distance:-hit.penetrationDepth}));
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
shapesIntersect(leftShape,leftPosition,leftRotation,rightShape,rightPosition,rightRotation){
|
|
830
|
+
const Jolt=this.Jolt;
|
|
831
|
+
const transformed=new Jolt.TransformedShape();
|
|
832
|
+
transformed.set_mShape(this._nativeShape(rightShape));
|
|
833
|
+
const rightPositionNative=new Jolt.RVec3(...rightPosition);
|
|
834
|
+
const rightRotationNative=new Jolt.Quat(...(Array.isArray(rightRotation)?rightRotation:[rightRotation.x,rightRotation.y,rightRotation.z,rightRotation.w]));
|
|
835
|
+
const scale=new Jolt.Vec3(...UNIT);
|
|
836
|
+
transformed.SetWorldTransform(rightPositionNative,rightRotationNative,scale);
|
|
837
|
+
const leftRotationArray=Array.isArray(leftRotation)?leftRotation:[leftRotation.x,leftRotation.y,leftRotation.z,leftRotation.w];
|
|
838
|
+
const leftTransform=createTransform(Jolt,leftPosition,leftRotationArray);
|
|
839
|
+
const settings=new Jolt.CollideShapeSettings();
|
|
840
|
+
const baseOffset=new Jolt.RVec3(...ZERO);
|
|
841
|
+
const collector=new Jolt.CollideShapeAnyHitCollisionCollector();
|
|
842
|
+
const shapeFilter=new Jolt.ShapeFilter();
|
|
843
|
+
try {
|
|
844
|
+
transformed.CollideShape(this._nativeShape(leftShape),scale,leftTransform,settings,baseOffset,collector,shapeFilter);
|
|
845
|
+
return collector.HadHit();
|
|
846
|
+
} finally {
|
|
847
|
+
Jolt.destroy(shapeFilter); Jolt.destroy(collector); Jolt.destroy(baseOffset); Jolt.destroy(settings); Jolt.destroy(leftTransform); Jolt.destroy(scale); Jolt.destroy(rightRotationNative); Jolt.destroy(rightPositionNative); Jolt.destroy(transformed);
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
}
|