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,88 @@
|
|
|
1
|
+
export const PHYSICS_BACKEND_CAPABILITIES = Object.freeze([
|
|
2
|
+
'rigid-body','articulated-body','character-controller','collision','joints','scene-query'
|
|
3
|
+
]);
|
|
4
|
+
|
|
5
|
+
const missing=(identity,method)=>{ throw new Error(`Physics backend ${identity} ${method}() must be implemented`); };
|
|
6
|
+
|
|
7
|
+
export class PhysicsBackend {
|
|
8
|
+
constructor(identity, capabilities = [], { executionModes=['realtime'], qualities={} } = {}) {
|
|
9
|
+
if (!identity) throw new TypeError('PhysicsBackend identity is required');
|
|
10
|
+
this.identity = identity;
|
|
11
|
+
this.capabilities = Object.freeze([...new Set(capabilities)]);
|
|
12
|
+
this.executionModes = Object.freeze([...new Set(executionModes)]);
|
|
13
|
+
this.qualities = Object.freeze({ realtime:qualities.realtime===true, deterministic:qualities.deterministic===true });
|
|
14
|
+
}
|
|
15
|
+
hasCapability(capability) { return this.capabilities.includes(capability); }
|
|
16
|
+
supportsExecutionMode(mode) { return this.executionModes.includes(mode); }
|
|
17
|
+
async init() { missing(this.identity,'init'); }
|
|
18
|
+
createWorld() { missing(this.identity,'createWorld'); }
|
|
19
|
+
step() { missing(this.identity,'step'); }
|
|
20
|
+
dispose() { missing(this.identity,'dispose'); }
|
|
21
|
+
|
|
22
|
+
// Deep runtime contract. Handles returned here are opaque to PhysicsSystem.
|
|
23
|
+
createBody() { missing(this.identity,'createBody'); }
|
|
24
|
+
removeBody() { missing(this.identity,'removeBody'); }
|
|
25
|
+
createColliders() { missing(this.identity,'createColliders'); }
|
|
26
|
+
colliders() { missing(this.identity,'colliders'); }
|
|
27
|
+
bodyKey() { missing(this.identity,'bodyKey'); }
|
|
28
|
+
colliderKey() { missing(this.identity,'colliderKey'); }
|
|
29
|
+
colliderParent() { missing(this.identity,'colliderParent'); }
|
|
30
|
+
colliderSnapshot() { missing(this.identity,'colliderSnapshot'); }
|
|
31
|
+
bodyType() { missing(this.identity,'bodyType'); }
|
|
32
|
+
setBodyType() { missing(this.identity,'setBodyType'); }
|
|
33
|
+
bodyPose() { missing(this.identity,'bodyPose'); }
|
|
34
|
+
setBodyPose() { missing(this.identity,'setBodyPose'); }
|
|
35
|
+
translateBody() { missing(this.identity,'translateBody'); }
|
|
36
|
+
clearBodyMotion() { missing(this.identity,'clearBodyMotion'); }
|
|
37
|
+
bodyMotion() { missing(this.identity,'bodyMotion'); }
|
|
38
|
+
setBodyMotion() { missing(this.identity,'setBodyMotion'); }
|
|
39
|
+
applyImpulse() { missing(this.identity,'applyImpulse'); }
|
|
40
|
+
applyForce() { missing(this.identity,'applyForce'); }
|
|
41
|
+
applyTorque() { missing(this.identity,'applyTorque'); }
|
|
42
|
+
setBodyMaterial() { missing(this.identity,'setBodyMaterial'); }
|
|
43
|
+
setBodyDynamics() { missing(this.identity,'setBodyDynamics'); }
|
|
44
|
+
setBodyCcd() { missing(this.identity,'setBodyCcd'); }
|
|
45
|
+
setBodySensor() { missing(this.identity,'setBodySensor'); }
|
|
46
|
+
setBodyCollisionFilter() { missing(this.identity,'setBodyCollisionFilter'); }
|
|
47
|
+
sleepBody() { missing(this.identity,'sleepBody'); }
|
|
48
|
+
wakeBody() { missing(this.identity,'wakeBody'); }
|
|
49
|
+
createJoint() { missing(this.identity,'createJoint'); }
|
|
50
|
+
setJointTarget() { missing(this.identity,'setJointTarget'); }
|
|
51
|
+
|
|
52
|
+
createCharacterController() { missing(this.identity,'createCharacterController'); }
|
|
53
|
+
removeCharacterController() { missing(this.identity,'removeCharacterController'); }
|
|
54
|
+
cancelCharacterMovement() { missing(this.identity,'cancelCharacterMovement'); }
|
|
55
|
+
moveCharacter() { missing(this.identity,'moveCharacter'); }
|
|
56
|
+
|
|
57
|
+
syncSceneQueries() { missing(this.identity,'syncSceneQueries'); }
|
|
58
|
+
createQueryShape() { missing(this.identity,'createQueryShape'); }
|
|
59
|
+
disposeQueryShape() { missing(this.identity,'disposeQueryShape'); }
|
|
60
|
+
intersectionsWithShape() { missing(this.identity,'intersectionsWithShape'); }
|
|
61
|
+
castCollider() { missing(this.identity,'castCollider'); }
|
|
62
|
+
raycast() { missing(this.identity,'raycast'); }
|
|
63
|
+
contactPairs() { missing(this.identity,'contactPairs'); }
|
|
64
|
+
penetrations() { missing(this.identity,'penetrations'); }
|
|
65
|
+
shapesIntersect() { missing(this.identity,'shapesIntersect'); }
|
|
66
|
+
evidenceGeometry(kind) { return `${this.identity}-${kind}`; }
|
|
67
|
+
|
|
68
|
+
// Optional observation contract. Backends may expose native debug geometry/metrics
|
|
69
|
+
// without leaking solver-private world handles to callers such as Observatory.
|
|
70
|
+
debugSnapshot(_world, _options = {}) {
|
|
71
|
+
return { backend:this.identity, nativeGeometry:null, metrics:{} };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
export class TransformPhysicsBackend extends PhysicsBackend {
|
|
78
|
+
constructor({ identity='transform' } = {}) {
|
|
79
|
+
super(identity, [], {
|
|
80
|
+
executionModes:['render-only'],
|
|
81
|
+
qualities:{realtime:true,deterministic:true}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
async init() { return this; }
|
|
85
|
+
createWorld() { return null; }
|
|
86
|
+
step() { return false; }
|
|
87
|
+
dispose() {}
|
|
88
|
+
}
|
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
import RAPIER from '@dimforge/rapier3d-compat';
|
|
2
|
+
import { PHYSICS_BACKEND_CAPABILITIES, PhysicsBackend } from './PhysicsBackend.js';
|
|
3
|
+
|
|
4
|
+
const v3=(value=[0,0,0])=>Array.isArray(value)
|
|
5
|
+
? {x:value[0],y:value[1],z:value[2]}
|
|
6
|
+
: {x:value.x,y:value.y,z:value.z};
|
|
7
|
+
const q4=(value=[0,0,0,1])=>Array.isArray(value)
|
|
8
|
+
? {x:value[0],y:value[1],z:value[2],w:value[3]}
|
|
9
|
+
: {x:value.x,y:value.y,z:value.z,w:value.w};
|
|
10
|
+
const array3=(value)=>[value.x,value.y,value.z];
|
|
11
|
+
const array4=(value)=>[value.x,value.y,value.z,value.w];
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
const createBodyDesc=(type,position,{canSleep=true,lockTranslation=null,lockRotation=null}={})=>{
|
|
15
|
+
const desc=type==='dynamic' ? RAPIER.RigidBodyDesc.dynamic()
|
|
16
|
+
: type==='kinematic' ? RAPIER.RigidBodyDesc.kinematicPositionBased()
|
|
17
|
+
: RAPIER.RigidBodyDesc.fixed();
|
|
18
|
+
if(type==='dynamic') {
|
|
19
|
+
desc.setCanSleep(Boolean(canSleep));
|
|
20
|
+
if(lockTranslation) desc.restrictTranslations(!lockTranslation[0],!lockTranslation[1],!lockTranslation[2]);
|
|
21
|
+
if(lockRotation) desc.restrictRotations(!lockRotation[0],!lockRotation[1],!lockRotation[2]);
|
|
22
|
+
}
|
|
23
|
+
if(position) {
|
|
24
|
+
const p=v3(position);
|
|
25
|
+
desc.setTranslation(p.x,p.y,p.z);
|
|
26
|
+
}
|
|
27
|
+
return desc;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const createColliderDesc=(spec)=>{
|
|
31
|
+
let desc;
|
|
32
|
+
if(spec.shape==='box') desc=RAPIER.ColliderDesc.cuboid(...spec.halfExtents);
|
|
33
|
+
else if(spec.shape==='cylinder') desc=RAPIER.ColliderDesc.cylinder(spec.halfHeight,spec.radius);
|
|
34
|
+
else if(spec.shape==='capsule') desc=RAPIER.ColliderDesc.capsule(spec.halfHeight,spec.radius);
|
|
35
|
+
else if(spec.shape==='convexHull') desc=RAPIER.ColliderDesc.convexHull(new Float32Array(spec.vertices));
|
|
36
|
+
else if(spec.shape==='trimesh') desc=RAPIER.ColliderDesc.trimesh(new Float32Array(spec.vertices),new Uint32Array(spec.indices));
|
|
37
|
+
else return null;
|
|
38
|
+
if(!desc) throw new Error(`Rapier rejected collider shape: ${spec.shape}`);
|
|
39
|
+
return desc;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const createJoint=(world,part,parentBody,childBody)=>{
|
|
43
|
+
const vec=(a=[0,0,0])=>({x:a[0],y:a[1],z:a[2]});
|
|
44
|
+
let data;
|
|
45
|
+
if(part.joint.type==='revolute') data=RAPIER.JointData.revolute(vec(part.joint.parentAnchor),vec(part.joint.childAnchor),vec(part.joint.axis));
|
|
46
|
+
else if(part.joint.type==='prismatic') data=RAPIER.JointData.prismatic(vec(part.joint.parentAnchor),vec(part.joint.childAnchor),vec(part.joint.axis));
|
|
47
|
+
else if(part.joint.type==='fixed') {
|
|
48
|
+
const parent=parentBody.rotation(),child=childBody.rotation();
|
|
49
|
+
const inverseParent={x:-parent.x,y:-parent.y,z:-parent.z,w:parent.w};
|
|
50
|
+
const multiply=(a,b)=>({x:a.w*b.x+a.x*b.w+a.y*b.z-a.z*b.y,y:a.w*b.y-a.x*b.z+a.y*b.w+a.z*b.x,z:a.w*b.z+a.x*b.y-a.y*b.x+a.z*b.w,w:a.w*b.w-a.x*b.x-a.y*b.y-a.z*b.z});
|
|
51
|
+
data=RAPIER.JointData.fixed(vec(part.joint.parentAnchor),multiply(inverseParent,child),vec(part.joint.childAnchor),{x:0,y:0,z:0,w:1});
|
|
52
|
+
} else throw new TypeError(`RapierPhysicsBackend unsupported joint type: ${part.joint.type}`);
|
|
53
|
+
const joint=world.createImpulseJoint(data,parentBody,childBody,true);
|
|
54
|
+
joint.setContactsEnabled(false);
|
|
55
|
+
if(part.joint.type!=='fixed' && part.joint.limits) joint.setLimits(part.joint.limits[0],part.joint.limits[1]);
|
|
56
|
+
return joint;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const createQueryShape=(spec)=>{
|
|
60
|
+
if(spec.shape==='box') return new RAPIER.Cuboid(...spec.halfExtents);
|
|
61
|
+
if(spec.shape==='cylinder') return new RAPIER.Cylinder(spec.halfHeight,spec.radius);
|
|
62
|
+
if(spec.shape==='capsule') return new RAPIER.Capsule(spec.halfHeight,spec.radius);
|
|
63
|
+
if(spec.shape==='convexHull') return new RAPIER.ConvexPolyhedron(new Float32Array(spec.vertices));
|
|
64
|
+
return null;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const describeShape=(shape)=>{
|
|
68
|
+
if(!shape) return {kind:'unknown'};
|
|
69
|
+
if(shape.type===RAPIER.ShapeType.Cuboid) return {
|
|
70
|
+
kind:'box', halfExtents:v3(shape.halfExtents), borderRadius:Number(shape.borderRadius)||0
|
|
71
|
+
};
|
|
72
|
+
if(shape.type===RAPIER.ShapeType.Cylinder) return {
|
|
73
|
+
kind:'cylinder', halfHeight:shape.halfHeight, radius:shape.radius, borderRadius:Number(shape.borderRadius)||0
|
|
74
|
+
};
|
|
75
|
+
if(shape.type===RAPIER.ShapeType.Capsule) return {
|
|
76
|
+
kind:'capsule', halfHeight:shape.halfHeight, radius:shape.radius, borderRadius:Number(shape.borderRadius)||0
|
|
77
|
+
};
|
|
78
|
+
if(shape.type===RAPIER.ShapeType.ConvexPolyhedron) return {
|
|
79
|
+
kind:'convexHull', vertices:Array.from(shape.vertices || []), borderRadius:Number(shape.borderRadius)||0
|
|
80
|
+
};
|
|
81
|
+
if(shape.type===RAPIER.ShapeType.TriMesh) return {
|
|
82
|
+
kind:'trimesh', vertices:Array.from(shape.vertices || []), indices:Array.from(shape.indices || [])
|
|
83
|
+
};
|
|
84
|
+
return {kind:'unknown',type:shape.type};
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// Share only immutable WASM initialization, never a physics World.
|
|
88
|
+
let rapierReady;
|
|
89
|
+
const loadRapier=()=>rapierReady ??= Promise.resolve().then(()=>RAPIER.init()).catch(error=>{rapierReady=undefined;throw error;});
|
|
90
|
+
|
|
91
|
+
export class RapierPhysicsBackend extends PhysicsBackend {
|
|
92
|
+
constructor({ gravity={x:0,y:-9.81,z:0} } = {}) {
|
|
93
|
+
super('rapier', PHYSICS_BACKEND_CAPABILITIES, {
|
|
94
|
+
executionModes:['realtime','validation-only'],
|
|
95
|
+
qualities:{realtime:true,deterministic:true}
|
|
96
|
+
});
|
|
97
|
+
this.gravity=gravity;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async init() { await loadRapier(); return this; }
|
|
101
|
+
createWorld() { return new RAPIER.World(this.gravity); }
|
|
102
|
+
step(world, dt) {
|
|
103
|
+
world.timestep=dt;
|
|
104
|
+
world.step();
|
|
105
|
+
world.bodies.forEach((body)=>{ if(body.isDynamic()) { body.resetForces(false); body.resetTorques(false); } });
|
|
106
|
+
}
|
|
107
|
+
dispose(world) { world?.free?.(); }
|
|
108
|
+
debugSnapshot(world,{nativeGeometry=true}={}) {
|
|
109
|
+
return {
|
|
110
|
+
backend:this.identity,
|
|
111
|
+
nativeGeometry:nativeGeometry && world?.debugRender ? world.debugRender() : null,
|
|
112
|
+
metrics:{}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
createBody(world,{type='fixed',position=null,rotation=null,canSleep=true,lockTranslation=null,lockRotation=null}={}) {
|
|
117
|
+
const body=world.createRigidBody(createBodyDesc(type,position,{canSleep,lockTranslation,lockRotation}));
|
|
118
|
+
if(rotation) body.setRotation(q4(rotation),true);
|
|
119
|
+
return body;
|
|
120
|
+
}
|
|
121
|
+
removeBody(world,body) { if(body) world.removeRigidBody(body); }
|
|
122
|
+
createColliders(world,body,specs=[],{mass,friction,restitution}={}) {
|
|
123
|
+
const colliderMass=mass!=null && specs.length ? mass/specs.length : null;
|
|
124
|
+
const created=[];
|
|
125
|
+
for(const spec of specs) {
|
|
126
|
+
const desc=createColliderDesc(spec);
|
|
127
|
+
if(!desc) continue;
|
|
128
|
+
if(spec.translation) desc.setTranslation(...spec.translation);
|
|
129
|
+
if(spec.rotation) desc.setRotation(q4(spec.rotation));
|
|
130
|
+
if(colliderMass!=null) desc.setMass(colliderMass);
|
|
131
|
+
if(friction!=null) desc.setFriction(friction);
|
|
132
|
+
if(restitution!=null) desc.setRestitution(restitution);
|
|
133
|
+
created.push(world.createCollider(desc,body));
|
|
134
|
+
}
|
|
135
|
+
return created;
|
|
136
|
+
}
|
|
137
|
+
colliders(body) {
|
|
138
|
+
if(!body) return [];
|
|
139
|
+
return Array.from({length:body.numColliders()},(_,index)=>body.collider(index));
|
|
140
|
+
}
|
|
141
|
+
bodyKey(body) { return body?.handle ?? null; }
|
|
142
|
+
colliderKey(collider) { return collider?.handle ?? null; }
|
|
143
|
+
colliderParent(collider) { return collider?.parent?.() || null; }
|
|
144
|
+
colliderSnapshot(collider) {
|
|
145
|
+
if(!collider) return null;
|
|
146
|
+
const position=collider.translation();
|
|
147
|
+
const rotation=collider.rotation();
|
|
148
|
+
return {
|
|
149
|
+
ref:collider,
|
|
150
|
+
key:this.colliderKey(collider),
|
|
151
|
+
parent:this.colliderParent(collider),
|
|
152
|
+
position:v3(position),
|
|
153
|
+
rotation:q4(rotation),
|
|
154
|
+
shape:describeShape(collider.shape),
|
|
155
|
+
shapeRef:collider.shape
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
bodyType(body) { return body?.isKinematic?.() ? 'kinematic' : body?.isDynamic?.() ? 'dynamic' : 'fixed'; }
|
|
159
|
+
setBodyType(body,type) {
|
|
160
|
+
if(type==='kinematic') body.setBodyType(RAPIER.RigidBodyType.KinematicPositionBased,true);
|
|
161
|
+
else if(type==='dynamic') body.setBodyType(RAPIER.RigidBodyType.Dynamic,true);
|
|
162
|
+
else body.setBodyType(RAPIER.RigidBodyType.Fixed,true);
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
165
|
+
bodyPose(body,{next=false}={}) {
|
|
166
|
+
if(!body) return null;
|
|
167
|
+
const position=next && body.nextTranslation ? body.nextTranslation() : body.translation();
|
|
168
|
+
const rotation=next && body.nextRotation ? body.nextRotation() : body.rotation();
|
|
169
|
+
return {position:array3(position),rotation:array4(rotation)};
|
|
170
|
+
}
|
|
171
|
+
setBodyPose(body,{position=null,rotation=null,next=false,wake=true}={}) {
|
|
172
|
+
if(!body) return false;
|
|
173
|
+
if(next) {
|
|
174
|
+
if(position) body.setNextKinematicTranslation(v3(position));
|
|
175
|
+
if(rotation) body.setNextKinematicRotation(q4(rotation));
|
|
176
|
+
} else {
|
|
177
|
+
if(position) body.setTranslation(v3(position),wake);
|
|
178
|
+
if(rotation) body.setRotation(q4(rotation),wake);
|
|
179
|
+
}
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
translateBody(body,delta,{clearLinearVelocity=true,wake=true}={}) {
|
|
183
|
+
const pose=this.bodyPose(body);
|
|
184
|
+
if(!pose) return false;
|
|
185
|
+
this.setBodyPose(body,{position:[pose.position[0]+delta[0],pose.position[1]+delta[1],pose.position[2]+delta[2]],wake});
|
|
186
|
+
if(clearLinearVelocity) body.setLinvel?.({x:0,y:0,z:0},wake);
|
|
187
|
+
if(wake) body.wakeUp?.();
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
clearBodyMotion(body,{wake=false}={}) {
|
|
191
|
+
if(!body) return false;
|
|
192
|
+
body.setLinvel?.({x:0,y:0,z:0},wake);
|
|
193
|
+
body.setAngvel?.({x:0,y:0,z:0},wake);
|
|
194
|
+
if(wake) body.wakeUp?.();
|
|
195
|
+
return true;
|
|
196
|
+
}
|
|
197
|
+
bodyMotion(body) {
|
|
198
|
+
if(!body) return null;
|
|
199
|
+
const linear=body.linvel(),angular=body.angvel();
|
|
200
|
+
return {
|
|
201
|
+
sleeping:body.isSleeping(),
|
|
202
|
+
linearVelocity:array3(linear),
|
|
203
|
+
angularVelocity:array3(angular),
|
|
204
|
+
linearSpeed:Math.hypot(linear.x,linear.y,linear.z),
|
|
205
|
+
angularSpeed:Math.hypot(angular.x,angular.y,angular.z)
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
setBodyMotion(body,{linearVelocity=null,angularVelocity=null,wake=true}={}) {
|
|
209
|
+
if(!body || this.bodyType(body)!=='dynamic') return false;
|
|
210
|
+
if(linearVelocity) body.setLinvel(v3(linearVelocity),wake);
|
|
211
|
+
if(angularVelocity) body.setAngvel(v3(angularVelocity),wake);
|
|
212
|
+
return true;
|
|
213
|
+
}
|
|
214
|
+
applyImpulse(body,impulse,{point=null,wake=true}={}) {
|
|
215
|
+
if(!body || this.bodyType(body)!=='dynamic') return false;
|
|
216
|
+
if(point) body.applyImpulseAtPoint(v3(impulse),v3(point),wake);
|
|
217
|
+
else body.applyImpulse(v3(impulse),wake);
|
|
218
|
+
return true;
|
|
219
|
+
}
|
|
220
|
+
applyForce(body,force,{point=null,wake=true}={}) {
|
|
221
|
+
if(!body || this.bodyType(body)!=='dynamic') return false;
|
|
222
|
+
if(point) body.addForceAtPoint(v3(force),v3(point),wake);
|
|
223
|
+
else body.addForce(v3(force),wake);
|
|
224
|
+
return true;
|
|
225
|
+
}
|
|
226
|
+
applyTorque(body,torque,{wake=true}={}) {
|
|
227
|
+
if(!body || this.bodyType(body)!=='dynamic') return false;
|
|
228
|
+
body.addTorque(v3(torque),wake);
|
|
229
|
+
return true;
|
|
230
|
+
}
|
|
231
|
+
setBodyMaterial(body,{friction=null,restitution=null}={}) {
|
|
232
|
+
if(!body) return false;
|
|
233
|
+
for(const collider of this.colliders(body)) {
|
|
234
|
+
if(friction!=null) collider.setFriction(friction);
|
|
235
|
+
if(restitution!=null) collider.setRestitution(restitution);
|
|
236
|
+
}
|
|
237
|
+
return true;
|
|
238
|
+
}
|
|
239
|
+
setBodyDynamics(body,{linearDamping=null,angularDamping=null,gravityScale=null,wake=true}={}) {
|
|
240
|
+
if(!body || this.bodyType(body)!=='dynamic') return false;
|
|
241
|
+
if(linearDamping!=null) body.setLinearDamping(linearDamping);
|
|
242
|
+
if(angularDamping!=null) body.setAngularDamping(angularDamping);
|
|
243
|
+
if(gravityScale!=null) body.setGravityScale(gravityScale,wake);
|
|
244
|
+
return true;
|
|
245
|
+
}
|
|
246
|
+
setBodyCcd(body,enabled) {
|
|
247
|
+
if(!body || this.bodyType(body)!=='dynamic') return false;
|
|
248
|
+
body.enableCcd(Boolean(enabled));
|
|
249
|
+
return true;
|
|
250
|
+
}
|
|
251
|
+
setBodySensor(body,enabled) {
|
|
252
|
+
if(!body) return false;
|
|
253
|
+
for(const collider of this.colliders(body)) collider.setSensor(Boolean(enabled));
|
|
254
|
+
return true;
|
|
255
|
+
}
|
|
256
|
+
setBodyCollisionFilter(body,filter=null) {
|
|
257
|
+
if(!body) return false;
|
|
258
|
+
const groups=filter ? ((((filter.membership & 0xffff) << 16) | (filter.filter & 0xffff)) >>> 0) : 0xffffffff;
|
|
259
|
+
for(const collider of this.colliders(body)) collider.setCollisionGroups(groups);
|
|
260
|
+
return true;
|
|
261
|
+
}
|
|
262
|
+
sleepBody(body) { if(!body || this.bodyType(body)!=='dynamic') return false; body.sleep(); return true; }
|
|
263
|
+
wakeBody(body) { body?.wakeUp?.(); return Boolean(body); }
|
|
264
|
+
|
|
265
|
+
createJoint(world,part,parentBody,childBody) { return createJoint(world,part,parentBody,childBody); }
|
|
266
|
+
setJointTarget(joint,target,{stiffness=40,damping=8}={}) {
|
|
267
|
+
if(!joint || joint.type?.()===RAPIER.JointType.Fixed) return false;
|
|
268
|
+
// A null target restores the unmotorized joint used before the first action.
|
|
269
|
+
joint.configureMotorPosition(target ?? 0,target == null ? 0 : stiffness,target == null ? 0 : damping);
|
|
270
|
+
return true;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
createCharacterController(world,{
|
|
274
|
+
offset=.02,autostepHeight=.3,autostepMinWidth=.2,snapToGround=.3,
|
|
275
|
+
maxSlopeClimbAngle=Math.PI/4,minSlopeSlideAngle=Math.PI/6
|
|
276
|
+
}={}) {
|
|
277
|
+
const controller=world.createCharacterController(offset);
|
|
278
|
+
controller.enableAutostep(autostepHeight,autostepMinWidth,false);
|
|
279
|
+
controller.enableSnapToGround(snapToGround);
|
|
280
|
+
controller.setMaxSlopeClimbAngle(maxSlopeClimbAngle);
|
|
281
|
+
controller.setMinSlopeSlideAngle(minSlopeSlideAngle);
|
|
282
|
+
controller.setApplyImpulsesToDynamicBodies(false);
|
|
283
|
+
return controller;
|
|
284
|
+
}
|
|
285
|
+
removeCharacterController(world,controller) { if(world&&controller) world.removeCharacterController(controller); }
|
|
286
|
+
cancelCharacterMovement(body) {
|
|
287
|
+
const pose=this.bodyPose(body);
|
|
288
|
+
if(!pose) return false;
|
|
289
|
+
return this.setBodyPose(body,{...pose,next:true});
|
|
290
|
+
}
|
|
291
|
+
moveCharacter(controller,body,desiredTranslation,{predicate=null}={}) {
|
|
292
|
+
if(!controller || this.bodyType(body)!=='kinematic') {
|
|
293
|
+
return {success:false,code:'CHARACTER_BODY_UNAVAILABLE',movement:[0,0,0],grounded:false,collisions:[]};
|
|
294
|
+
}
|
|
295
|
+
const colliders=this.colliders(body);
|
|
296
|
+
if(colliders.length!==1) {
|
|
297
|
+
return {success:false,code:'CHARACTER_BODY_UNAVAILABLE',movement:[0,0,0],grounded:false,collisions:[]};
|
|
298
|
+
}
|
|
299
|
+
controller.computeColliderMovement(colliders[0],v3(desiredTranslation),undefined,undefined,predicate || undefined);
|
|
300
|
+
const movement=controller.computedMovement();
|
|
301
|
+
const pose=this.bodyPose(body);
|
|
302
|
+
this.setBodyPose(body,{
|
|
303
|
+
position:[pose.position[0]+movement.x,pose.position[1]+movement.y,pose.position[2]+movement.z],
|
|
304
|
+
next:true
|
|
305
|
+
});
|
|
306
|
+
const collisions=[];
|
|
307
|
+
for(let index=0;index<controller.numComputedCollisions();index++) {
|
|
308
|
+
const hit=controller.computedCollision(index);
|
|
309
|
+
if(!hit?.collider) continue;
|
|
310
|
+
collisions.push({colliderKey:this.colliderKey(hit.collider),toi:hit.toi,normal:[hit.normal1.x,hit.normal1.y,hit.normal1.z]});
|
|
311
|
+
}
|
|
312
|
+
return {success:true,movement:array3(movement),grounded:controller.computedGrounded(),collisions};
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
syncSceneQueries(world) {
|
|
316
|
+
if(!world) return;
|
|
317
|
+
if(typeof world.updateSceneQueries==='function') world.updateSceneQueries();
|
|
318
|
+
else world.propagateModifiedBodyPositionsToColliders?.();
|
|
319
|
+
}
|
|
320
|
+
createQueryShape(spec) { return createQueryShape(spec); }
|
|
321
|
+
disposeQueryShape(shape) { shape?.free?.(); }
|
|
322
|
+
intersectionsWithShape(world,position,rotation,shape,callback,{
|
|
323
|
+
excludeCollider=null,excludeBody=null,predicate=null
|
|
324
|
+
}={}) {
|
|
325
|
+
this.syncSceneQueries(world);
|
|
326
|
+
let active=true;
|
|
327
|
+
world?.forEachCollider((other)=>{
|
|
328
|
+
if(!active || other.isEnabled?.()===false) return;
|
|
329
|
+
if(excludeCollider && this.colliderKey(other)===this.colliderKey(excludeCollider)) return;
|
|
330
|
+
const parent=this.colliderParent(other);
|
|
331
|
+
if(excludeBody && this.bodyKey(parent)===this.bodyKey(excludeBody)) return;
|
|
332
|
+
if(predicate && !predicate(other)) return;
|
|
333
|
+
if(!other.intersectsShape(shape,v3(position),q4(rotation))) return;
|
|
334
|
+
active=callback(other)!==false;
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
castCollider(world,source,velocity,{
|
|
338
|
+
excludeCollider=null,excludeBody=null,predicate=null,targetDistance=0,maxToi=1,stopAtPenetration=false
|
|
339
|
+
}={}) {
|
|
340
|
+
this.syncSceneQueries(world);
|
|
341
|
+
let best=null;
|
|
342
|
+
const zero={x:0,y:0,z:0};
|
|
343
|
+
world?.forEachCollider((other)=>{
|
|
344
|
+
if(other.isEnabled?.()===false) return;
|
|
345
|
+
if(this.colliderKey(other)===this.colliderKey(source)) return;
|
|
346
|
+
if(excludeCollider && this.colliderKey(other)===this.colliderKey(excludeCollider)) return;
|
|
347
|
+
const parent=this.colliderParent(other);
|
|
348
|
+
if(excludeBody && this.bodyKey(parent)===this.bodyKey(excludeBody)) return;
|
|
349
|
+
if(predicate && !predicate(other)) return;
|
|
350
|
+
const hit=source.castCollider(v3(velocity),other,zero,targetDistance,maxToi,stopAtPenetration);
|
|
351
|
+
if(!hit) return;
|
|
352
|
+
const colliderKey=this.colliderKey(other);
|
|
353
|
+
if(!best || hit.time_of_impact<best.timeOfImpact) best={colliderKey,timeOfImpact:hit.time_of_impact};
|
|
354
|
+
});
|
|
355
|
+
return best ? {...best,collider:world.getCollider(best.colliderKey)} : null;
|
|
356
|
+
}
|
|
357
|
+
raycast(world,origin,direction,maxDistance,{solid=true,predicate=null}={}) {
|
|
358
|
+
this.syncSceneQueries(world);
|
|
359
|
+
const ray=new RAPIER.Ray(v3(origin),v3(direction));
|
|
360
|
+
let best=null;
|
|
361
|
+
world?.forEachCollider((collider)=>{
|
|
362
|
+
if(collider.isEnabled?.()===false) return;
|
|
363
|
+
if(predicate && !predicate(collider)) return;
|
|
364
|
+
const toi=collider.castRay(ray,maxDistance,solid);
|
|
365
|
+
if(!Number.isFinite(toi) || toi<0) return;
|
|
366
|
+
const colliderKey=this.colliderKey(collider);
|
|
367
|
+
if(!best || toi<best.timeOfImpact) best={colliderKey,timeOfImpact:toi};
|
|
368
|
+
});
|
|
369
|
+
return best ? {...best,collider:world.getCollider(best.colliderKey)} : null;
|
|
370
|
+
}
|
|
371
|
+
contactPairs(world,source) {
|
|
372
|
+
const pairs=[];
|
|
373
|
+
world.contactPairsWith(source,(other)=>{
|
|
374
|
+
let manifoldCount=0,contactCount=0,activeContactCount=0,minDistance=Infinity,totalImpulse=0,normal=null;
|
|
375
|
+
world.contactPair(source,other,(manifold,flipped)=>{
|
|
376
|
+
manifoldCount+=1;
|
|
377
|
+
const rawNormal=manifold.normal();
|
|
378
|
+
normal=flipped ? [-rawNormal.x,-rawNormal.y,-rawNormal.z] : [rawNormal.x,rawNormal.y,rawNormal.z];
|
|
379
|
+
for(let index=0;index<manifold.numContacts();index++) {
|
|
380
|
+
const distance=manifold.contactDist(index);
|
|
381
|
+
const impulse=Math.abs(manifold.contactImpulse(index)||0);
|
|
382
|
+
contactCount+=1;
|
|
383
|
+
if(distance<=1e-6 || impulse>1e-8) activeContactCount+=1;
|
|
384
|
+
minDistance=Math.min(minDistance,distance);
|
|
385
|
+
totalImpulse+=impulse;
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
if(manifoldCount && activeContactCount) pairs.push({
|
|
389
|
+
otherKey:this.colliderKey(other),manifoldCount,contactCount,activeContactCount,
|
|
390
|
+
minDistance:Number.isFinite(minDistance)?minDistance:null,totalImpulse,normal,
|
|
391
|
+
evidenceKind:'solver-contact',impulseAvailable:true
|
|
392
|
+
});
|
|
393
|
+
});
|
|
394
|
+
return pairs.map((pair)=>({...pair,other:world.getCollider(pair.otherKey)}));
|
|
395
|
+
}
|
|
396
|
+
penetrations(world,source) {
|
|
397
|
+
const sourceSnapshot=this.colliderSnapshot(source);
|
|
398
|
+
const sourceBody=sourceSnapshot?.parent;
|
|
399
|
+
if(!sourceSnapshot) return [];
|
|
400
|
+
const hits=[];
|
|
401
|
+
this.intersectionsWithShape(world,sourceSnapshot.position,sourceSnapshot.rotation,sourceSnapshot.shapeRef,(other)=>{
|
|
402
|
+
const otherBody=this.colliderParent(other);
|
|
403
|
+
if(!otherBody || this.bodyKey(otherBody)===this.bodyKey(sourceBody)) return true;
|
|
404
|
+
const contact=source.contactCollider(other,0);
|
|
405
|
+
if(contact && contact.distance<0) hits.push({otherKey:this.colliderKey(other),distance:contact.distance});
|
|
406
|
+
return true;
|
|
407
|
+
},{excludeCollider:source});
|
|
408
|
+
return hits.map((hit)=>({...hit,other:world.getCollider(hit.otherKey)}));
|
|
409
|
+
}
|
|
410
|
+
shapesIntersect(leftShape,leftPosition,leftRotation,rightShape,rightPosition,rightRotation) {
|
|
411
|
+
return leftShape.intersectsShape(v3(leftPosition),q4(leftRotation),rightShape,v3(rightPosition),q4(rightRotation));
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Rendering
|
|
2
|
+
|
|
3
|
+
正式渲染能力:createRenderer、后处理、Gaussian Splat 加载、资源释放与 RendererProbe。
|
|
4
|
+
保持平铺文件。RendererProbe 服务正式运行诊断;实验 WebGPU probes 已归 apps/observatory/probes/rendering。
|
|
5
|
+
World 的 RenderingSystem 负责 World 展示适配,并由 application/createSession.js 装配到 WorldRuntime。modules/rendering 不依赖 World;Generated World 坐标转换由 World 的 RenderingSystem 应用。
|
|
6
|
+
|
|
7
|
+
任务见 tasks.jsonl。验证:npm run test -- tests/rendering tests/observatory。
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { rendererDiagnostics } from './createRenderer.js';
|
|
2
|
+
|
|
3
|
+
const WEBGPU_LIMIT_KEYS = Object.freeze([
|
|
4
|
+
'maxTextureDimension2D',
|
|
5
|
+
'maxBindGroups',
|
|
6
|
+
'maxBufferSize',
|
|
7
|
+
'maxUniformBufferBindingSize',
|
|
8
|
+
'maxStorageBufferBindingSize',
|
|
9
|
+
'maxComputeWorkgroupStorageSize',
|
|
10
|
+
'maxComputeInvocationsPerWorkgroup',
|
|
11
|
+
'maxStorageBuffersPerShaderStage',
|
|
12
|
+
'maxComputeWorkgroupSizeX',
|
|
13
|
+
'maxComputeWorkgroupSizeY',
|
|
14
|
+
'maxComputeWorkgroupSizeZ',
|
|
15
|
+
'maxComputeWorkgroupsPerDimension'
|
|
16
|
+
]);
|
|
17
|
+
|
|
18
|
+
const scalar = (value) => typeof value === 'bigint'
|
|
19
|
+
? (value <= BigInt(Number.MAX_SAFE_INTEGER) ? Number(value) : value.toString())
|
|
20
|
+
: value;
|
|
21
|
+
|
|
22
|
+
function deviceDiagnostics(renderer) {
|
|
23
|
+
const backend = renderer?.backend;
|
|
24
|
+
if (backend?.isWebGPUBackend !== true) {
|
|
25
|
+
return {
|
|
26
|
+
compatibilityMode: null,
|
|
27
|
+
timestampSupported: Boolean(backend?.disjoint),
|
|
28
|
+
features: [],
|
|
29
|
+
limits: {}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const device = backend.device;
|
|
34
|
+
const limits = {};
|
|
35
|
+
for (const key of WEBGPU_LIMIT_KEYS) {
|
|
36
|
+
const value = device?.limits?.[key];
|
|
37
|
+
if (value != null) limits[key] = scalar(value);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
compatibilityMode: backend.compatibilityMode === true,
|
|
42
|
+
timestampSupported: Boolean(device?.features?.has?.('timestamp-query')),
|
|
43
|
+
features: device?.features ? [...device.features].map(String).sort() : [],
|
|
44
|
+
limits
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export class RendererProbe {
|
|
49
|
+
constructor(renderer, {
|
|
50
|
+
requestedMode = 'auto',
|
|
51
|
+
timingIntervalMs = 1000,
|
|
52
|
+
onDeviceLost = null,
|
|
53
|
+
onError = null
|
|
54
|
+
} = {}) {
|
|
55
|
+
if (!renderer) throw new TypeError('RendererProbe requires a renderer');
|
|
56
|
+
this.renderer = renderer;
|
|
57
|
+
this.info = rendererDiagnostics(renderer, requestedMode);
|
|
58
|
+
this.device = deviceDiagnostics(renderer);
|
|
59
|
+
this.health = 'ready';
|
|
60
|
+
this.lastError = null;
|
|
61
|
+
this.gpuTimeMs = null;
|
|
62
|
+
this.frameIntervals=[];
|
|
63
|
+
this.lastFrameAt=null;
|
|
64
|
+
this.renderCpuMs=[];
|
|
65
|
+
this.timingIntervalMs = Math.max(250, Number(timingIntervalMs) || 1000);
|
|
66
|
+
this.nextTimingAt = 0;
|
|
67
|
+
this.timingPromise = null;
|
|
68
|
+
this.onDeviceLost = typeof onDeviceLost === 'function' ? onDeviceLost : null;
|
|
69
|
+
this.onError = typeof onError === 'function' ? onError : null;
|
|
70
|
+
this.previousDeviceLost = renderer.onDeviceLost;
|
|
71
|
+
this.previousError = renderer.onError;
|
|
72
|
+
|
|
73
|
+
renderer.onDeviceLost = (detail) => {
|
|
74
|
+
this.previousDeviceLost?.call(renderer, detail);
|
|
75
|
+
this.health = 'lost';
|
|
76
|
+
this.lastError = normalizeRendererError(detail, 'device-lost');
|
|
77
|
+
this.onDeviceLost?.(this.lastError);
|
|
78
|
+
};
|
|
79
|
+
renderer.onError = (detail) => {
|
|
80
|
+
this.previousError?.call(renderer, detail);
|
|
81
|
+
if (this.health !== 'lost') this.health = 'degraded';
|
|
82
|
+
this.lastError = normalizeRendererError(detail, 'backend-error');
|
|
83
|
+
this.onError?.(this.lastError);
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
afterRender(timestamp = 0, renderCpuMs = null) {
|
|
88
|
+
if(Number.isFinite(timestamp)) {
|
|
89
|
+
const interval=this.lastFrameAt==null?null:timestamp-this.lastFrameAt;
|
|
90
|
+
// Background-tab suspension starts a fresh window instead of inflating frame percentiles.
|
|
91
|
+
if(interval>1000){this.frameIntervals.length=0;this.renderCpuMs.length=0;}
|
|
92
|
+
else if(interval>0)pushSample(this.frameIntervals,interval);
|
|
93
|
+
this.lastFrameAt=timestamp;
|
|
94
|
+
}
|
|
95
|
+
if(Number.isFinite(renderCpuMs) && renderCpuMs>=0)pushSample(this.renderCpuMs,renderCpuMs);
|
|
96
|
+
if (!this.renderer?.backend?.trackTimestamp || this.health === 'lost') return;
|
|
97
|
+
if (this.timingPromise || timestamp < this.nextTimingAt) return;
|
|
98
|
+
this.nextTimingAt = timestamp + this.timingIntervalMs;
|
|
99
|
+
this.timingPromise = Promise.resolve(this.renderer.resolveTimestampsAsync?.('render'))
|
|
100
|
+
.then((value) => {
|
|
101
|
+
if (Number.isFinite(value)) this.gpuTimeMs = value;
|
|
102
|
+
})
|
|
103
|
+
.catch((error) => {
|
|
104
|
+
this.lastError = normalizeRendererError(error, 'timestamp-error');
|
|
105
|
+
})
|
|
106
|
+
.finally(() => { this.timingPromise = null; });
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
snapshot() {
|
|
110
|
+
return Object.freeze({
|
|
111
|
+
...this.info,
|
|
112
|
+
health: this.health,
|
|
113
|
+
gpuTiming: Boolean(this.renderer?.backend?.trackTimestamp),
|
|
114
|
+
gpuTimeMs: this.gpuTimeMs,
|
|
115
|
+
frameIntervalMs:percentiles(this.frameIntervals),
|
|
116
|
+
renderCpuMs:percentiles(this.renderCpuMs),
|
|
117
|
+
workload:{
|
|
118
|
+
drawCalls:this.renderer?.info?.render?.drawCalls ?? this.renderer?.info?.render?.calls ?? null,
|
|
119
|
+
triangles:this.renderer?.info?.render?.triangles ?? null,
|
|
120
|
+
geometries:this.renderer?.info?.memory?.geometries ?? null,
|
|
121
|
+
textures:this.renderer?.info?.memory?.textures ?? null
|
|
122
|
+
},
|
|
123
|
+
compatibilityMode: this.device.compatibilityMode,
|
|
124
|
+
timestampSupported: this.device.timestampSupported,
|
|
125
|
+
features: [...this.device.features],
|
|
126
|
+
limits: { ...this.device.limits },
|
|
127
|
+
lastError: this.lastError ? { ...this.lastError } : null
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
dispose() {
|
|
132
|
+
if (!this.renderer) return;
|
|
133
|
+
this.renderer.onDeviceLost = this.previousDeviceLost;
|
|
134
|
+
this.renderer.onError = this.previousError;
|
|
135
|
+
this.renderer = null;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function pushSample(samples,value) {if(samples.length===240)samples.shift();samples.push(value);}
|
|
140
|
+
function percentiles(samples) {
|
|
141
|
+
if(!samples.length)return {samples:0,p50:null,p95:null};
|
|
142
|
+
const sorted=[...samples].sort((a,b)=>a-b);
|
|
143
|
+
return {samples:sorted.length,p50:sorted[Math.ceil(sorted.length*.5)-1],p95:sorted[Math.ceil(sorted.length*.95)-1]};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function normalizeRendererError(detail, fallbackType) {
|
|
147
|
+
return Object.freeze({
|
|
148
|
+
type: String(detail?.type || fallbackType),
|
|
149
|
+
api: detail?.api ? String(detail.api) : null,
|
|
150
|
+
reason: detail?.reason ? String(detail.reason) : null,
|
|
151
|
+
message: String(detail?.message || detail?.error?.message || detail || 'Unknown renderer error')
|
|
152
|
+
});
|
|
153
|
+
}
|