agentscape3d-engine 0.0.0-stage → 1.0.0-beta.2
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/AssetCompiler-A99wKf7H.js +2424 -0
- package/dist/AssetCompiler-A99wKf7H.js.map +1 -0
- package/dist/AssetInputContracts-uKYeQu-X.js +245 -0
- package/dist/AssetInputContracts-uKYeQu-X.js.map +1 -0
- package/dist/AssetRecipe-DCaLLXvG.js +67 -0
- package/dist/AssetRecipe-DCaLLXvG.js.map +1 -0
- package/dist/BrowserCodeWorker.js +53850 -0
- package/dist/BrowserCodeWorker.js.map +1 -0
- package/dist/KinematicHypothesisScreen-4v7GBwdv.js +241 -0
- package/dist/KinematicHypothesisScreen-4v7GBwdv.js.map +1 -0
- package/dist/SceneSerializer-CLCzQjL_.js +350 -0
- package/dist/SceneSerializer-CLCzQjL_.js.map +1 -0
- package/dist/StylePack-CD_BC-Mv.js +6317 -0
- package/dist/StylePack-CD_BC-Mv.js.map +1 -0
- package/dist/WorldArchive-dYf1OpSe.js +417 -0
- package/dist/WorldArchive-dYf1OpSe.js.map +1 -0
- package/dist/WorldIO-Dqz4MqTQ.js +149 -0
- package/dist/WorldIO-Dqz4MqTQ.js.map +1 -0
- package/dist/blankWorld-OoOvN_IK.js +75 -0
- package/dist/blankWorld-OoOvN_IK.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-B3HCflvO.js +128 -0
- package/dist/disposeObject3D-B3HCflvO.js.map +1 -0
- package/dist/environments-B1WaICAN.js +4197 -0
- package/dist/environments-B1WaICAN.js.map +1 -0
- package/dist/gltfIO-BMK1hc2D.js +9 -0
- package/dist/gltfIO-BMK1hc2D.js.map +1 -0
- package/dist/grandUrbanBlock-Bdjgc6ZT.js +515 -0
- package/dist/grandUrbanBlock-Bdjgc6ZT.js.map +1 -0
- package/dist/index.d.ts +275 -0
- package/dist/index.js +16239 -0
- package/dist/index.js.map +1 -0
- package/dist/magicCabin-DPQi_jh-.js +11019 -0
- package/dist/magicCabin-DPQi_jh-.js.map +1 -0
- package/dist/mcp.d.ts +2 -0
- package/dist/mcp.js +1 -0
- package/dist/monumentHall-IOLbRZQC.js +403 -0
- package/dist/monumentHall-IOLbRZQC.js.map +1 -0
- package/dist/node.d.ts +16 -0
- package/dist/node.js +26 -0
- package/dist/rolldown-runtime-D3KUYPsf.js +12 -0
- package/dist/ruinedCourtyard-BtaF_aOi.js +696 -0
- package/dist/ruinedCourtyard-BtaF_aOi.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 +8 -0
- package/dist/runtime/application/buildTaskObservation.js +117 -0
- package/dist/runtime/application/code-execution/AuthoringSandboxEntry.js +46 -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 +72 -0
- package/dist/runtime/application/createSession.js +66 -0
- package/dist/runtime/application/createWorldAuthoringContext.js +400 -0
- package/dist/runtime/application/generation/GenerationOrchestrator.js +629 -0
- package/dist/runtime/application/generation/GenerationRuntime.js +214 -0
- package/dist/runtime/application/generation/PromptHybridWorldOrchestrator.js +285 -0
- package/dist/runtime/application/native-scene/CodeProject.js +119 -0
- package/dist/runtime/application/native-scene/CodeProjectModules.js +128 -0
- package/dist/runtime/application/native-scene/NativeEnvironmentGeometry.js +62 -0
- package/dist/runtime/application/native-scene/NativeOverlayCheckpoint.js +127 -0
- package/dist/runtime/application/native-scene/NativeRenderDiscovery.js +51 -0
- package/dist/runtime/application/native-scene/NativeSceneHost.js +319 -0
- package/dist/runtime/application/native-scene/NativeSceneOverlay.js +116 -0
- package/dist/runtime/application/native-scene/NativeThreeModule.js +16 -0
- package/dist/runtime/application/object-forge/SceneObjectForge.js +232 -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 +79 -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 +45 -0
- package/dist/runtime/application/scene/SceneEditService.js +144 -0
- package/dist/runtime/application/scene/SceneFacade.js +261 -0
- package/dist/runtime/application/scene/SceneInteractionAdapters.js +40 -0
- package/dist/runtime/application/scene/SceneJobController.js +229 -0
- package/dist/runtime/application/scene/SceneLifecycle.js +57 -0
- package/dist/runtime/application/scene/ScenePackage.js +162 -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 +87 -0
- package/dist/runtime/application/scene/WorldDirectory.js +20 -0
- package/dist/runtime/application/scene/WorldDocument.js +74 -0
- package/dist/runtime/application/scene/WorldIO.js +103 -0
- package/dist/runtime/application/scene/WorldStorage.js +137 -0
- package/dist/runtime/application/skills/SkillRegistry.js +189 -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 +174 -0
- package/dist/runtime/application/world-authoring/ModelRef.js +62 -0
- package/dist/runtime/apps/mcp-server/AUTHORING.md +71 -0
- package/dist/runtime/apps/mcp-server/AgentMcpCompat.js +77 -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 +132 -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 +150 -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 +80 -0
- package/dist/runtime/apps/mcp-server/StudioBridgeHttp.js +58 -0
- package/dist/runtime/apps/mcp-server/StudioLiveBridge.js +190 -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 +65 -0
- package/dist/runtime/apps/mcp-server/registerTools.js +225 -0
- package/dist/runtime/apps/mcp-server/sandbox/run.mjs +23 -0
- package/dist/runtime/apps/mcp-server/security.js +21 -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/WorldDiskStorage.js +51 -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/foundation/EventBus.js +18 -0
- package/dist/runtime/foundation/JsonGateway.js +47 -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 +399 -0
- package/dist/runtime/modules/asset/README.md +54 -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 +100 -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/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 +47 -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 +245 -0
- package/dist/runtime/modules/physics/JoltPhysicsBackend.js +850 -0
- package/dist/runtime/modules/physics/PhysicsApiSurface.js +651 -0
- package/dist/runtime/modules/physics/PhysicsBackend.js +88 -0
- package/dist/runtime/modules/physics/RapierPhysicsBackend.js +410 -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/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 +80 -0
- package/dist/runtime/modules/world/runtime/EntityCapabilityRegistry.js +150 -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 +207 -0
- package/dist/runtime/modules/world/runtime/SceneSerializer.js +246 -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 +502 -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 +665 -0
- package/dist/runtime/modules/world/runtime/affordance/ObjectAffordances.js +107 -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 +305 -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 +222 -0
- package/dist/runtime/modules/world/runtime/interaction/InteractionApproach.js +130 -0
- package/dist/runtime/modules/world/runtime/interaction/InteractionContract.js +57 -0
- package/dist/runtime/modules/world/runtime/interaction/RecoveryRuntime.js +123 -0
- package/dist/runtime/modules/world/runtime/interaction/SettleRuntime.js +120 -0
- package/dist/runtime/modules/world/runtime/semantic/SemanticWorldView.js +102 -0
- package/dist/runtime/modules/world/runtime/simulation/SimulationClock.js +89 -0
- package/dist/runtime/modules/world/runtime/simulation/SimulationSession.js +99 -0
- package/dist/runtime/modules/world/runtime/simulation/ThermalSystem.js +269 -0
- package/dist/runtime/modules/world/runtime/spatial/SpatialSnapshot.js +56 -0
- package/dist/runtime/modules/world/runtime/systems/AudioSystem.js +125 -0
- package/dist/runtime/modules/world/runtime/systems/Instrument.js +38 -0
- package/dist/runtime/modules/world/runtime/systems/InteractionSystem.js +728 -0
- package/dist/runtime/modules/world/runtime/systems/LocomotionSystem.js +269 -0
- package/dist/runtime/modules/world/runtime/systems/NavigationSystem.js +469 -0
- package/dist/runtime/modules/world/runtime/systems/PhysicsSystem.js +1673 -0
- package/dist/runtime/modules/world/runtime/systems/RenderingSystem.js +457 -0
- package/dist/runtime/modules/world/runtime/systems/SpatialSystem.js +284 -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 +69 -0
- package/dist/runtime/modules/world/verification/RepairEngine.js +49 -0
- package/dist/runtime/modules/world/verification/WorldAcceptance.js +158 -0
- package/dist/runtime/modules/world/verification/WorldValidator.js +65 -0
- package/dist/runtime/package-lock.json +16048 -0
- package/dist/runtime/package.json +105 -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-BWpTl0Wj.js +359 -0
- package/dist/schema-BWpTl0Wj.js.map +1 -0
- package/dist/suzhouGarden-H9tiPgxq.js +6150 -0
- package/dist/suzhouGarden-H9tiPgxq.js.map +1 -0
- package/dist/woodlandWorkshop-D6zzSbHr.js +483 -0
- package/dist/woodlandWorkshop-D6zzSbHr.js.map +1 -0
- package/dist/yuanmingyuan-D6IHqjZ-.js +4955 -0
- package/dist/yuanmingyuan-D6IHqjZ-.js.map +1 -0
- package/package.json +70 -4
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { compileRuleGraph, evaluateRuleGraph, executeRuleEffects } from './RuleGraph.js';
|
|
2
|
+
|
|
3
|
+
export class RuleRuntime {
|
|
4
|
+
constructor(runtime, { maxCascadeDepth = 16 } = {}) {
|
|
5
|
+
this.runtime = runtime;
|
|
6
|
+
this.events = runtime.events;
|
|
7
|
+
this.maxCascadeDepth = maxCascadeDepth;
|
|
8
|
+
this.graph = compileRuleGraph([]);
|
|
9
|
+
this.generation = 0;
|
|
10
|
+
this.unsubscribe = null;
|
|
11
|
+
this.queue = Promise.resolve();
|
|
12
|
+
this.active = false;
|
|
13
|
+
this.transactionEvents = null;
|
|
14
|
+
this.transactionDepth = 0;
|
|
15
|
+
this.waitingEvents = [];
|
|
16
|
+
this.eventSuspensions = 0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
load(rulesOrGraph = []) {
|
|
20
|
+
const rules = rulesOrGraph?.schema === 'agentscape.rule-graph' ? rulesOrGraph.rules : rulesOrGraph;
|
|
21
|
+
const graph = compileRuleGraph(rules);
|
|
22
|
+
this.graph = graph;
|
|
23
|
+
this.generation += 1;
|
|
24
|
+
return structuredClone(graph);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
start() {
|
|
28
|
+
if (this.unsubscribe) return;
|
|
29
|
+
this.active = true;
|
|
30
|
+
this.unsubscribe = this.events.on('*', (event) => {
|
|
31
|
+
if (!this.active || this.eventSuspensions || event.type === 'rule.error' || !this.graph.rules.some((rule) => rule.event === event.type)) return;
|
|
32
|
+
// Rules currently consume only the event type and cascade metadata, not mutable payloads.
|
|
33
|
+
const depth = Math.max(this.transactionDepth, Number(event.meta?.ruleCascadeDepth) || 0);
|
|
34
|
+
const entry = { generation:this.generation, event:{ type:event.type, meta:{ ruleCascadeDepth:depth } } };
|
|
35
|
+
if (this.transactionEvents) this.transactionEvents.push(entry);
|
|
36
|
+
else this.enqueue(entry);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
stop() {
|
|
41
|
+
this.active = false;
|
|
42
|
+
this.generation += 1;
|
|
43
|
+
this.unsubscribe?.();
|
|
44
|
+
this.unsubscribe = null;
|
|
45
|
+
this.transactionEvents = null;
|
|
46
|
+
this.transactionDepth = 0;
|
|
47
|
+
this.waitingEvents.length = 0;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
beginTransaction(depth = 0) {
|
|
51
|
+
this.transactionEvents = [];
|
|
52
|
+
this.transactionDepth = Math.max(0, Number(depth) || 0);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
endTransaction(committed) {
|
|
56
|
+
const events = committed ? this.transactionEvents || [] : [];
|
|
57
|
+
this.transactionEvents = null;
|
|
58
|
+
this.transactionDepth = 0;
|
|
59
|
+
const waiting = this.waitingEvents.splice(0);
|
|
60
|
+
for (const entry of [...waiting, ...events]) this.enqueue(entry);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
suspendEvents() { this.eventSuspensions += 1; }
|
|
64
|
+
resumeEvents() { this.eventSuspensions = Math.max(0, this.eventSuspensions - 1); }
|
|
65
|
+
|
|
66
|
+
enqueue(entry) {
|
|
67
|
+
this.queue = this.queue.then(() => {
|
|
68
|
+
if (!this.active || entry.generation !== this.generation || this.eventSuspensions) return;
|
|
69
|
+
// An event queued before a new write must wait without occupying the world lock.
|
|
70
|
+
if (this.runtime.mutationOwner) {
|
|
71
|
+
this.waitingEvents.push(entry);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
return this.dispatchEvent(entry.event, { cascadeDepth:entry.event.meta.ruleCascadeDepth });
|
|
75
|
+
}).catch((error) => {
|
|
76
|
+
this.events.emit('rule.error', {
|
|
77
|
+
error:{ code:error.code || 'RULE_RUNTIME_ERROR', message:error.message },
|
|
78
|
+
sourceEvent:entry.event.type,
|
|
79
|
+
meta:{ ruleCascadeDepth:entry.event.meta.ruleCascadeDepth + 1 }
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
readState(targetId, stateKey) {
|
|
85
|
+
return this.runtime.store?.get?.(targetId)?.state?.[stateKey];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async dispatchEvent(event, { cascadeDepth = 0 } = {}) {
|
|
89
|
+
if (!event?.type) return { status:'no-rule-event' };
|
|
90
|
+
if (cascadeDepth >= this.maxCascadeDepth) {
|
|
91
|
+
const error = new Error(`Rule cascade depth exceeded: ${event.type}`);
|
|
92
|
+
error.code = 'RULE_CASCADE_DEPTH_EXCEEDED';
|
|
93
|
+
throw error;
|
|
94
|
+
}
|
|
95
|
+
const effects = evaluateRuleGraph(this.graph, event.type, (id, key) => this.readState(id, key));
|
|
96
|
+
const seen = new Set();
|
|
97
|
+
const uniqueEffects = effects.filter((effect) => {
|
|
98
|
+
const key = JSON.stringify([effect.targetId, effect.stateKey, effect.value]);
|
|
99
|
+
if (seen.has(key)) return false;
|
|
100
|
+
seen.add(key);
|
|
101
|
+
return true;
|
|
102
|
+
});
|
|
103
|
+
if (!uniqueEffects.length) return { status:'no-rule-match', event:event.type, effects:[] };
|
|
104
|
+
const result = await executeRuleEffects(this.runtime, uniqueEffects, {
|
|
105
|
+
source:'rule-runtime', eventId:event.type, ruleCascadeDepth:cascadeDepth + 1
|
|
106
|
+
});
|
|
107
|
+
if (result.effects?.every((effect) => effect.changed === false)) {
|
|
108
|
+
return { status:'no-rule-match', event:event.type, effects:[] };
|
|
109
|
+
}
|
|
110
|
+
this.events.emit('rule.effects-applied', {
|
|
111
|
+
eventType:event.type, count:uniqueEffects.length, meta:{ ruleCascadeDepth:cascadeDepth + 1 }, result
|
|
112
|
+
});
|
|
113
|
+
return { status:'rules-applied', event:event.type, effects:uniqueEffects, result };
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
|
|
3
|
+
// Broad-phase only: the SpatialSystem remains the source of truth for exact
|
|
4
|
+
// ON / INSIDE geometry. Reject only pairs that cannot possibly match.
|
|
5
|
+
const mayRestOn = (subjectBox, surface) => {
|
|
6
|
+
const halfX=surface.size[0]/2+0.05;
|
|
7
|
+
const halfZ=surface.size[1]/2+0.05;
|
|
8
|
+
return subjectBox.min.x <= surface.center.x+halfX &&
|
|
9
|
+
subjectBox.max.x >= surface.center.x-halfX &&
|
|
10
|
+
subjectBox.min.z <= surface.center.z+halfZ &&
|
|
11
|
+
subjectBox.max.z >= surface.center.z-halfZ &&
|
|
12
|
+
subjectBox.min.y >= surface.center.y-0.03 &&
|
|
13
|
+
subjectBox.min.y <= surface.center.y+0.12;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const intersectsExpanded = (left, right, margin = 0) =>
|
|
17
|
+
left.min.x <= right.max.x + margin && left.max.x >= right.min.x - margin &&
|
|
18
|
+
left.min.y <= right.max.y + margin && left.max.y >= right.min.y - margin &&
|
|
19
|
+
left.min.z <= right.max.z + margin && left.max.z >= right.min.z - margin;
|
|
20
|
+
|
|
21
|
+
const sameValue = (left, right) => {
|
|
22
|
+
if (Object.is(left, right)) return true;
|
|
23
|
+
if (!left || !right || typeof left !== 'object' || typeof right !== 'object') return false;
|
|
24
|
+
if (Array.isArray(left) || Array.isArray(right)) {
|
|
25
|
+
return Array.isArray(left) && Array.isArray(right) && left.length === right.length && left.every((value, index) => sameValue(value, right[index]));
|
|
26
|
+
}
|
|
27
|
+
const leftKeys = Object.keys(left), rightKeys = Object.keys(right);
|
|
28
|
+
return leftKeys.length === rightKeys.length && leftKeys.every((key) => Object.hasOwn(right, key) && sameValue(left[key], right[key]));
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const sameEdges = (left, right) => {
|
|
32
|
+
if (left.size !== right.size) return false;
|
|
33
|
+
const iterator = right.entries();
|
|
34
|
+
for (const [key, edge] of left) {
|
|
35
|
+
const next = iterator.next().value;
|
|
36
|
+
if (!next || key !== next[0]) return false;
|
|
37
|
+
const other = next[1];
|
|
38
|
+
if (edge.subject !== other.subject || edge.predicate !== other.predicate || edge.object !== other.object) return false;
|
|
39
|
+
const a = edge.meta || {}, b = other.meta || {};
|
|
40
|
+
const aKeys = Object.keys(a), bKeys = Object.keys(b);
|
|
41
|
+
if (aKeys.length !== bKeys.length || aKeys.some((name) => !sameValue(a[name], b[name]))) return false;
|
|
42
|
+
}
|
|
43
|
+
return true;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export class SceneGraph {
|
|
47
|
+
constructor({ store, spatial, events = null } = {}) {
|
|
48
|
+
this.store = store;
|
|
49
|
+
this.spatial = spatial;
|
|
50
|
+
this.events = events;
|
|
51
|
+
this.edges = new Map();
|
|
52
|
+
this.environmentFacts = [];
|
|
53
|
+
this.batchDepth = 0;
|
|
54
|
+
this.dirty = true;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
key(subject, predicate, object) { return `${subject}|${predicate}|${object}`; }
|
|
58
|
+
|
|
59
|
+
set(subject, predicate, object, meta = {}) {
|
|
60
|
+
const edge = { subject, predicate, object, meta: { ...meta } };
|
|
61
|
+
this.edges.set(this.key(subject, predicate, object), edge);
|
|
62
|
+
return edge;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
delete(subject, predicate, object) { return this.edges.delete(this.key(subject, predicate, object)); }
|
|
66
|
+
clear() { this.edges.clear(); }
|
|
67
|
+
reset() { this.edges.clear(); this.environmentFacts = []; this.dirty = false; this.batchDepth = 0; }
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
setEnvironmentSemantics(environmentId, value = null) {
|
|
71
|
+
this.environmentFacts = environmentSemanticFacts(environmentId, value);
|
|
72
|
+
this.changed();
|
|
73
|
+
return this.environmentFacts.map((fact) => ({ ...fact, meta:{...fact.meta} }));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
removeObject(id) {
|
|
77
|
+
for (const [key, edge] of this.edges) {
|
|
78
|
+
if (edge.subject === id || edge.object === id) this.edges.delete(key);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
list({ subject, predicate, object } = {}) {
|
|
83
|
+
return [...this.edges.values()].filter((edge) =>
|
|
84
|
+
(!subject || edge.subject === subject) &&
|
|
85
|
+
(!predicate || edge.predicate === predicate) &&
|
|
86
|
+
(!object || edge.object === object)
|
|
87
|
+
).map((edge) => ({ ...edge, meta: { ...edge.meta } }));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
invalidate() { this.dirty = true; }
|
|
91
|
+
|
|
92
|
+
changed() {
|
|
93
|
+
this.invalidate();
|
|
94
|
+
if (this.batchDepth === 0) this.update();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async batch(operation) {
|
|
98
|
+
this.batchDepth += 1;
|
|
99
|
+
try {
|
|
100
|
+
return await operation();
|
|
101
|
+
} finally {
|
|
102
|
+
this.batchDepth -= 1;
|
|
103
|
+
if (this.batchDepth === 0) this.update();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// update() means callers need a current graph. It may rebuild even inside a batch.
|
|
108
|
+
update(snapshot = null) {
|
|
109
|
+
if (this.dirty) this.rebuild(snapshot);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
rebuild(snapshot = null) {
|
|
113
|
+
const previous = new Map(this.edges);
|
|
114
|
+
this.clear();
|
|
115
|
+
for (const fact of this.environmentFacts) this.set(fact.subject, fact.predicate, fact.object, fact.meta);
|
|
116
|
+
const records = this.store.list().filter(([, record]) => record.active !== false);
|
|
117
|
+
const spatialSnapshot = snapshot || this.spatial.snapshot();
|
|
118
|
+
const surfaces = new Map();
|
|
119
|
+
const containmentBounds = new Map();
|
|
120
|
+
const relationBounds = new Map();
|
|
121
|
+
|
|
122
|
+
// Keep the expensive exact geometry checks out of unrelated pairs. A target
|
|
123
|
+
// can expose surfaces/receptacles outside its visual bounds, so index those
|
|
124
|
+
// world-space regions as well as the object bounds.
|
|
125
|
+
const cellSize = 4;
|
|
126
|
+
const cellKey = (x, y, z) => `${Math.floor(x / cellSize)},${Math.floor(y / cellSize)},${Math.floor(z / cellSize)}`;
|
|
127
|
+
const relationGrid = new Map();
|
|
128
|
+
const addRelationBound = (id, box) => {
|
|
129
|
+
if (!box) return;
|
|
130
|
+
const bounds = relationBounds.get(id) || [];
|
|
131
|
+
bounds.push(box);
|
|
132
|
+
relationBounds.set(id, bounds);
|
|
133
|
+
const minX = Math.floor(box.min.x / cellSize), maxX = Math.floor(box.max.x / cellSize);
|
|
134
|
+
const minY = Math.floor(box.min.y / cellSize), maxY = Math.floor(box.max.y / cellSize);
|
|
135
|
+
const minZ = Math.floor(box.min.z / cellSize), maxZ = Math.floor(box.max.z / cellSize);
|
|
136
|
+
for (let x = minX; x <= maxX; x++) for (let y = minY; y <= maxY; y++) for (let z = minZ; z <= maxZ; z++) {
|
|
137
|
+
const key = cellKey(x * cellSize, y * cellSize, z * cellSize);
|
|
138
|
+
let bucket = relationGrid.get(key);
|
|
139
|
+
if (!bucket) relationGrid.set(key, bucket = new Set());
|
|
140
|
+
bucket.add(id);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
for (const [id, record] of records) {
|
|
145
|
+
surfaces.set(id, (record.manifest.surfaces || [])
|
|
146
|
+
.map((surface) => this.spatial.getSupportSurface(id, surface.id, spatialSnapshot))
|
|
147
|
+
.filter(Boolean));
|
|
148
|
+
const receptacles=record.manifest.receptacles||[];
|
|
149
|
+
const zones=receptacles.length
|
|
150
|
+
? receptacles.map((entry)=>this.spatial.getReceptacle(id,entry.id,spatialSnapshot)?.box)
|
|
151
|
+
: [spatialSnapshot.get(id).box];
|
|
152
|
+
containmentBounds.set(id,zones.filter(Boolean).map((box)=>box.clone().expandByScalar(0.02)));
|
|
153
|
+
addRelationBound(id, spatialSnapshot.get(id).box);
|
|
154
|
+
for (const surface of surfaces.get(id)) {
|
|
155
|
+
addRelationBound(id, new THREE.Box3(
|
|
156
|
+
new THREE.Vector3(surface.center.x - surface.size[0] / 2, surface.center.y - 0.12, surface.center.z - surface.size[1] / 2),
|
|
157
|
+
new THREE.Vector3(surface.center.x + surface.size[0] / 2, surface.center.y + 0.12, surface.center.z + surface.size[1] / 2)
|
|
158
|
+
));
|
|
159
|
+
}
|
|
160
|
+
for (const box of zones) if (box) addRelationBound(id, box);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const deriveDirected = (subjectId, subject, targetId, target) => {
|
|
164
|
+
for (const support of surfaces.get(targetId)) {
|
|
165
|
+
if (!mayRestOn(subject.box,support)) continue;
|
|
166
|
+
const status = this.spatial.supportGeometry(subjectId,targetId,{surfaceId:support.id,snapshot:spatialSnapshot});
|
|
167
|
+
if (status.supported) {
|
|
168
|
+
const meta = { surfaceId:support.id, gap:Number(status.gap.toFixed(3)), evidence:'spatial-geometry' };
|
|
169
|
+
this.set(subjectId, 'ON', targetId, meta);
|
|
170
|
+
this.set(targetId, 'SUPPORTS', subjectId, meta);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
if (containmentBounds.get(targetId).some((box)=>box.containsBox(subject.box))) {
|
|
174
|
+
const containment = this.spatial.containmentGeometry(subjectId,targetId,{snapshot:spatialSnapshot});
|
|
175
|
+
if (containment.inside) {
|
|
176
|
+
const meta = { ...(containment.receptacleId ? { receptacleId:containment.receptacleId } : {}), evidence:'spatial-geometry' };
|
|
177
|
+
this.set(subjectId, 'INSIDE', targetId, meta);
|
|
178
|
+
this.set(targetId, 'CONTAINS', subjectId, meta);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
const candidates = new Set();
|
|
184
|
+
const nearDistances = new Map();
|
|
185
|
+
for (let i = 0; i < records.length; i++) {
|
|
186
|
+
const [id] = records[i], a = spatialSnapshot.get(id);
|
|
187
|
+
// Keep the single pairwise distance pass used for NEAR semantics. The
|
|
188
|
+
// spatial index below limits the much more expensive geometry checks.
|
|
189
|
+
for (let j = i + 1; j < records.length; j++) {
|
|
190
|
+
const [otherId] = records[j], b = spatialSnapshot.get(otherId);
|
|
191
|
+
const distance = a.center.distanceTo(b.center);
|
|
192
|
+
if (distance <= 2) {
|
|
193
|
+
const pair = `${id}\0${otherId}`;
|
|
194
|
+
candidates.add(pair);
|
|
195
|
+
nearDistances.set(pair, distance);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
const seenTargets = new Set();
|
|
199
|
+
const box = a.box;
|
|
200
|
+
const minX = Math.floor((box.min.x - 0.12) / cellSize), maxX = Math.floor((box.max.x + 0.12) / cellSize);
|
|
201
|
+
const minY = Math.floor((box.min.y - 0.12) / cellSize), maxY = Math.floor((box.max.y + 0.12) / cellSize);
|
|
202
|
+
const minZ = Math.floor((box.min.z - 0.12) / cellSize), maxZ = Math.floor((box.max.z + 0.12) / cellSize);
|
|
203
|
+
for (let x = minX; x <= maxX; x++) for (let y = minY; y <= maxY; y++) for (let z = minZ; z <= maxZ; z++) {
|
|
204
|
+
for (const targetId of relationGrid.get(cellKey(x * cellSize, y * cellSize, z * cellSize)) || []) {
|
|
205
|
+
if (targetId === id || seenTargets.has(targetId)) continue;
|
|
206
|
+
seenTargets.add(targetId);
|
|
207
|
+
if (relationBounds.get(targetId)?.some((bound) => intersectsExpanded(box, bound, 0.12))) {
|
|
208
|
+
const pair = id < targetId ? `${id}\0${targetId}` : `${targetId}\0${id}`;
|
|
209
|
+
candidates.add(pair);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
for (const pair of candidates) {
|
|
215
|
+
const [id, otherId] = pair.split('\0');
|
|
216
|
+
const a = spatialSnapshot.get(id), b = spatialSnapshot.get(otherId);
|
|
217
|
+
const nearDistance = nearDistances.get(pair);
|
|
218
|
+
if (nearDistance !== undefined) {
|
|
219
|
+
const meta = { distance: Number(nearDistance.toFixed(3)) };
|
|
220
|
+
this.set(id, 'NEAR', otherId, meta);
|
|
221
|
+
this.set(otherId, 'NEAR', id, meta);
|
|
222
|
+
}
|
|
223
|
+
deriveDirected(id, a, otherId, b);
|
|
224
|
+
deriveDirected(otherId, b, id, a);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
this.dirty = false;
|
|
228
|
+
if (!sameEdges(previous, this.edges)) this.events?.emit('sceneGraph.updated', { edges: this.edges.size });
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
describe(id) {
|
|
232
|
+
return {
|
|
233
|
+
outgoing: this.list({ subject: id }),
|
|
234
|
+
incoming: this.list({ object: id })
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const semanticKey = (label) => encodeURIComponent(String(label).trim().toLocaleLowerCase());
|
|
240
|
+
const instanceKey = (id) => encodeURIComponent(String(id).trim());
|
|
241
|
+
const finiteVec3 = (value) => Array.isArray(value) && value.length === 3 && value.every(Number.isFinite);
|
|
242
|
+
|
|
243
|
+
function semanticPayload(value) {
|
|
244
|
+
if (Array.isArray(value)) return { categories:value, instances:[], granularity:'category', sourceKind:'category-list', provenance:null };
|
|
245
|
+
if ([1,2].includes(value?.schemaVersion) && Array.isArray(value.categories) && Array.isArray(value.instances)) {
|
|
246
|
+
return {
|
|
247
|
+
categories:value.categories, instances:value.instances,
|
|
248
|
+
granularity:value.instances.length ? 'instance' : 'category',
|
|
249
|
+
sourceKind:`runtime-semantics-v${value.schemaVersion}`,
|
|
250
|
+
schemaVersion:value.schemaVersion,
|
|
251
|
+
provenance:value.provenance && typeof value.provenance==='object' ? structuredClone(value.provenance) : null
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
return { categories:[], instances:[], granularity:'none', sourceKind:value == null ? 'none' : 'unsupported', provenance:null };
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function environmentSemanticFacts(environmentId, value) {
|
|
258
|
+
const {categories,instances,granularity,sourceKind,provenance}=semanticPayload(value);
|
|
259
|
+
const subject=`environment:${String(environmentId || 'environment')}`;
|
|
260
|
+
const seenCategories=new Set();
|
|
261
|
+
const facts=[];
|
|
262
|
+
const addCategory=(rawLabel) => {
|
|
263
|
+
if (typeof rawLabel !== 'string') return null;
|
|
264
|
+
const label=rawLabel.trim();
|
|
265
|
+
if (!label) return null;
|
|
266
|
+
const key=label.toLocaleLowerCase();
|
|
267
|
+
const categoryId=`semantic-category:${semanticKey(label)}`;
|
|
268
|
+
if (!seenCategories.has(key)) {
|
|
269
|
+
seenCategories.add(key);
|
|
270
|
+
facts.push({
|
|
271
|
+
subject,predicate:'HAS_CATEGORY',object:categoryId,
|
|
272
|
+
meta:{label,granularity,sourceKind,...(provenance?{provenance:structuredClone(provenance)}:{})}
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
return categoryId;
|
|
276
|
+
};
|
|
277
|
+
for (const item of categories) addCategory(item);
|
|
278
|
+
|
|
279
|
+
const seenInstances=new Set();
|
|
280
|
+
for (const item of instances) {
|
|
281
|
+
if (!item || typeof item !== 'object' || Array.isArray(item)) continue;
|
|
282
|
+
const id=typeof item.id === 'string' ? item.id.trim() : '';
|
|
283
|
+
const label=typeof item.label === 'string' ? item.label.trim() : '';
|
|
284
|
+
if (!id || !label) continue;
|
|
285
|
+
let spatialMeta=null;
|
|
286
|
+
if (finiteVec3(item.center) && finiteVec3(item.bbox?.min) && finiteVec3(item.bbox?.max)) {
|
|
287
|
+
spatialMeta={center:[...item.center],bbox:{min:[...item.bbox.min],max:[...item.bbox.max]}};
|
|
288
|
+
} else if (item.localization?.kind==='point-scale' && finiteVec3(item.localization.center) && Number.isFinite(item.localization.scale) && item.localization.scale>0) {
|
|
289
|
+
spatialMeta={localization:structuredClone(item.localization)};
|
|
290
|
+
} else continue;
|
|
291
|
+
const instanceId=`semantic-instance:${instanceKey(id)}`;
|
|
292
|
+
if (seenInstances.has(instanceId)) continue;
|
|
293
|
+
seenInstances.add(instanceId);
|
|
294
|
+
const categoryId=addCategory(label);
|
|
295
|
+
const meta={
|
|
296
|
+
id,label,...spatialMeta,
|
|
297
|
+
...(Number.isFinite(item.confidence)?{confidence:item.confidence}:{}),
|
|
298
|
+
...(item.evidence && typeof item.evidence==='object'?{evidence:structuredClone(item.evidence)}:{}),
|
|
299
|
+
sourceKind,...(provenance?{provenance:structuredClone(provenance)}:{})
|
|
300
|
+
};
|
|
301
|
+
facts.push({subject,predicate:'HAS_INSTANCE',object:instanceId,meta});
|
|
302
|
+
facts.push({subject:instanceId,predicate:'INSTANCE_OF',object:categoryId,meta:{label,sourceKind}});
|
|
303
|
+
}
|
|
304
|
+
return facts;
|
|
305
|
+
}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import { Errors } from '../../errors.js';
|
|
3
|
+
import { getInteractionContract } from './InteractionContract.js';
|
|
4
|
+
|
|
5
|
+
export class ArticulationRuntime {
|
|
6
|
+
constructor({ store, physics, events, assertSupports }) {
|
|
7
|
+
this.store = store;
|
|
8
|
+
this.physics = physics;
|
|
9
|
+
this.events = events;
|
|
10
|
+
this.assertSupports = assertSupports;
|
|
11
|
+
this.tasks = new Map();
|
|
12
|
+
this.results = new Map();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
key(id, partName) { return `${id}:${partName}`; }
|
|
16
|
+
|
|
17
|
+
findPartForAction(record, action, partName = null) {
|
|
18
|
+
const parts = Object.entries(record.manifest.parts || {}).filter(([name, part]) =>
|
|
19
|
+
(!partName || name === partName) && part.actions?.includes(action) && Number.isFinite(part.targets?.[action])
|
|
20
|
+
);
|
|
21
|
+
if (parts.length !== 1) throw Errors.actionUnsupported(record.id, partName ? `${action}:${partName}` : action);
|
|
22
|
+
return parts[0];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
actionSweepBounds(targetId, action, partName = null, samples = 9) {
|
|
26
|
+
const record = this.store.get(targetId);
|
|
27
|
+
const [name, part] = this.findPartForAction(record, action, partName);
|
|
28
|
+
const node = record.object.getObjectByName(part.node);
|
|
29
|
+
const rest = this.physics.getPartRestPose(targetId, name);
|
|
30
|
+
if (!node || !node.parent || !rest) return { checked:false, reason:'PART_REST_POSE_UNAVAILABLE', partName:name };
|
|
31
|
+
if (part.joint.type === 'revolute' && Math.hypot(...(part.joint.childAnchor || [0,0,0])) > 1e-5) {
|
|
32
|
+
return { checked:false, reason:'REVOLUTE_CHILD_ANCHOR_UNSUPPORTED', partName:name };
|
|
33
|
+
}
|
|
34
|
+
const target = part.targets[action];
|
|
35
|
+
const live = this.physics.getArticulationState(targetId,name,{target});
|
|
36
|
+
if (!live) return { checked:false, reason:'JOINT_COORDINATE_UNAVAILABLE', partName:name };
|
|
37
|
+
const axis = new THREE.Vector3(...live.localAxis);
|
|
38
|
+
const currentCoordinate = live.coordinate;
|
|
39
|
+
const restPosition = new THREE.Vector3(...rest.position);
|
|
40
|
+
const restRotation = new THREE.Quaternion(...rest.rotation);
|
|
41
|
+
const originalPosition = node.position.clone();
|
|
42
|
+
const originalRotation = node.quaternion.clone();
|
|
43
|
+
const swept = new THREE.Box3();
|
|
44
|
+
try {
|
|
45
|
+
for (let i = 0; i < samples; i++) {
|
|
46
|
+
const alpha = samples === 1 ? 1 : i / (samples - 1);
|
|
47
|
+
const coordinate = currentCoordinate + (target - currentCoordinate) * alpha;
|
|
48
|
+
if (part.joint.type === 'prismatic') {
|
|
49
|
+
node.position.copy(restPosition).addScaledVector(axis, coordinate);
|
|
50
|
+
node.quaternion.copy(restRotation);
|
|
51
|
+
} else {
|
|
52
|
+
node.position.copy(restPosition);
|
|
53
|
+
node.quaternion.setFromAxisAngle(axis, coordinate).multiply(restRotation);
|
|
54
|
+
}
|
|
55
|
+
node.updateMatrixWorld(true);
|
|
56
|
+
swept.union(new THREE.Box3().setFromObject(node));
|
|
57
|
+
}
|
|
58
|
+
} finally {
|
|
59
|
+
node.position.copy(originalPosition);
|
|
60
|
+
node.quaternion.copy(originalRotation);
|
|
61
|
+
node.updateMatrixWorld(true);
|
|
62
|
+
}
|
|
63
|
+
if (swept.isEmpty()) return { checked:false, reason:'PART_SWEEP_EMPTY', partName:name };
|
|
64
|
+
swept.expandByScalar(.02);
|
|
65
|
+
return { checked:true, partName:name, action, currentCoordinate, target, bounds:{ min:swept.min.toArray(), max:swept.max.toArray() }, box:swept };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
finish(task, result) {
|
|
69
|
+
const key = this.key(task.id, task.partName);
|
|
70
|
+
if (this.tasks.get(key) !== task) return;
|
|
71
|
+
this.tasks.delete(key);
|
|
72
|
+
const report = { ...result, id:task.id, partName:task.partName, action:task.action, target:task.target };
|
|
73
|
+
this.results.set(key, report);
|
|
74
|
+
this.events.emit('interaction', { ...report, action:'articulation-completion', articulationAction:report.action });
|
|
75
|
+
task.resolve(report);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
wait(id, partName, action, target, { timeout = 4, stableDuration = .18, stallWindow = .5, stallTolerance = .004 } = {}) {
|
|
79
|
+
const key = this.key(id, partName);
|
|
80
|
+
const existing = this.tasks.get(key);
|
|
81
|
+
if (existing && existing.action === action && Math.abs(existing.target-target) <= 1e-9) return existing.promise;
|
|
82
|
+
if (existing) this.finish(existing, { status:'action-unverified', reason:'SUPERSEDED', targetReached:false, settled:false, elapsed:Number(existing.elapsed.toFixed(3)) });
|
|
83
|
+
const state = this.physics.getArticulationState(id, partName, { target });
|
|
84
|
+
if (!state) return Promise.resolve({ status:'action-unverified', reason:'JOINT_STATE_UNAVAILABLE', id, partName, action, target, targetReached:false, settled:false, elapsed:0 });
|
|
85
|
+
let resolveTask;
|
|
86
|
+
const task = { id, partName, action, target, timeout, stableDuration, stallWindow, stallTolerance, elapsed:0, stable:0, initialCoordinate:state.coordinate, samples:[{ time:0, coordinate:state.coordinate }], resolve:null, promise:null };
|
|
87
|
+
task.promise = new Promise((resolve) => { resolveTask = resolve; });
|
|
88
|
+
task.resolve = resolveTask;
|
|
89
|
+
this.tasks.set(key, task);
|
|
90
|
+
return task.promise;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
promoteCompletion(report) {
|
|
94
|
+
if (report?.status !== 'action-completed' || !report.targetReached || !this.store.has(report.id)) return false;
|
|
95
|
+
const record = this.store.get(report.id);
|
|
96
|
+
if (record.state.partTargets?.[report.partName] !== report.action) return false;
|
|
97
|
+
record.state.parts ||= {};
|
|
98
|
+
record.state.parts[report.partName] = report.action;
|
|
99
|
+
delete record.state.partTargets[report.partName];
|
|
100
|
+
if (!Object.keys(record.state.partTargets).length) delete record.state.partTargets;
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
finalizeAttempt(report) {
|
|
105
|
+
if (!report || !['action-failed','action-unverified'].includes(report.status) || !this.store.has(report.id)) return false;
|
|
106
|
+
const record = this.store.get(report.id);
|
|
107
|
+
if (record.state.partTargets?.[report.partName] !== report.action) return false;
|
|
108
|
+
this.physics.holdArticulationCurrent?.(report.id,report.partName);
|
|
109
|
+
delete record.state.partTargets[report.partName];
|
|
110
|
+
if (!Object.keys(record.state.partTargets).length) delete record.state.partTargets;
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
status(id, partName = null) {
|
|
115
|
+
const record = this.store.get(id);
|
|
116
|
+
const entries = Object.entries(record.manifest.parts || {}).filter(([name,part]) =>
|
|
117
|
+
(!partName || name === partName) && part.joint && part.physics && part.joint.type !== 'fixed'
|
|
118
|
+
);
|
|
119
|
+
if (!entries.length) throw Errors.actionUnsupported(id, partName ? `status:${partName}` : 'articulation-status');
|
|
120
|
+
const parts = entries.map(([name,part]) => {
|
|
121
|
+
const key = this.key(id,name);
|
|
122
|
+
const pending = this.tasks.get(key);
|
|
123
|
+
const last = this.results.get(key) || null;
|
|
124
|
+
const requestedAction = record.state.partTargets?.[name] || null;
|
|
125
|
+
const verifiedAction = record.state.parts?.[name] || null;
|
|
126
|
+
const targetAction = pending?.action || requestedAction || verifiedAction;
|
|
127
|
+
const target = targetAction && Number.isFinite(part.targets?.[targetAction]) ? part.targets[targetAction] : null;
|
|
128
|
+
const live = this.physics.getArticulationState(id,name,{target});
|
|
129
|
+
return {
|
|
130
|
+
partName:name,
|
|
131
|
+
status:pending ? 'moving' : (last?.status || (verifiedAction ? 'verified-state' : 'idle')),
|
|
132
|
+
requestedAction,verifiedAction,
|
|
133
|
+
...(pending ? { pending:{action:pending.action,target:pending.target,elapsed:Number(pending.elapsed.toFixed(3))} } : {}),
|
|
134
|
+
...(last ? { last:structuredClone(last) } : {}),
|
|
135
|
+
...(live ? { live:{coordinate:live.coordinate,target:live.target,error:live.error,tolerance:live.tolerance,coordinateReference:live.coordinateReference} } : {})
|
|
136
|
+
};
|
|
137
|
+
});
|
|
138
|
+
return { id, parts };
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
failureAttribution(id, partName) {
|
|
142
|
+
const contacts=(this.physics.articulationContacts?.(id,partName) || []).filter((item)=>item.external);
|
|
143
|
+
const blockerMap=new Map();
|
|
144
|
+
for (const item of contacts) {
|
|
145
|
+
const target=item.target || {};
|
|
146
|
+
if (!['object','environment'].includes(target.kind)) continue;
|
|
147
|
+
const key=target.kind==='object' ? `object:${target.objectId}:${target.partName || '$root'}` : `environment:${target.environmentId}:${target.colliderIndex ?? -1}`;
|
|
148
|
+
if (!blockerMap.has(key)) blockerMap.set(key,structuredClone(target));
|
|
149
|
+
}
|
|
150
|
+
return { status:contacts.length ? 'contact-evidence' : 'unattributed', evidence:'current-contact-at-failure', contactEvidence:contacts, blockerCandidates:[...blockerMap.values()] };
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
execute(id, action, { partName = null } = {}) {
|
|
154
|
+
const record = this.assertSupports(id, action);
|
|
155
|
+
const [name, part] = this.findPartForAction(record, action, partName);
|
|
156
|
+
const contract = getInteractionContract(record.manifest, name, action);
|
|
157
|
+
if (contract.effects[0]?.kind !== 'set-articulation-target' || contract.verifierTarget.target !== part.targets[action]) throw Errors.actionUnsupported(id, action);
|
|
158
|
+
if (!this.physics.setArticulationTarget(id, name, part.targets[action])) throw Errors.actionUnsupported(id, action);
|
|
159
|
+
record.state.partTargets ||= {};
|
|
160
|
+
record.state.partTargets[name] = action;
|
|
161
|
+
this.results.delete(this.key(id,name));
|
|
162
|
+
this.wait(id,name,action,part.targets[action]);
|
|
163
|
+
this.events.emit('interaction', { action, id, part:name, target:part.targets[action] });
|
|
164
|
+
return { id, part:name, action, capability:contract.capability, target:part.targets[action], requested:true, interactionContractId:contract.id, verifierTarget:structuredClone(contract.verifierTarget) };
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
update(dt) {
|
|
168
|
+
const wrap = (jointType, value) => jointType === 'revolute' ? Math.atan2(Math.sin(value), Math.cos(value)) : value;
|
|
169
|
+
for (const task of [...this.tasks.values()]) {
|
|
170
|
+
task.elapsed += dt;
|
|
171
|
+
const guarded = task.guard?.();
|
|
172
|
+
if (guarded) {
|
|
173
|
+
this.physics.holdArticulationCurrent(task.id, task.partName);
|
|
174
|
+
this.finish(task, { status:'action-unverified', reason:guarded, targetReached:false, settled:false });
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
const state = this.physics.getArticulationState(task.id, task.partName, { target:task.target });
|
|
178
|
+
if (!state || !Number.isFinite(state.coordinate) || !Number.isFinite(state.error)) {
|
|
179
|
+
this.finish(task, { status:'action-unverified', reason:'JOINT_STATE_UNAVAILABLE', targetReached:false, settled:false, elapsed:Number(task.elapsed.toFixed(3)) });
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
const limits = state.limits;
|
|
183
|
+
if (limits?.length === 2 && (state.coordinate < limits[0]-state.tolerance || state.coordinate > limits[1]+state.tolerance)) {
|
|
184
|
+
this.finish(task, { status:'action-failed', reason:'LIMIT_VIOLATION', targetReached:false, settled:false, coordinate:state.coordinate, error:state.error, tolerance:state.tolerance, limits, elapsed:Number(task.elapsed.toFixed(3)) });
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
const reached = state.error <= state.tolerance;
|
|
188
|
+
task.stable = reached ? task.stable + dt : 0;
|
|
189
|
+
task.samples.push({ time:task.elapsed, coordinate:state.coordinate });
|
|
190
|
+
const cutoff = task.elapsed - task.stallWindow;
|
|
191
|
+
while (task.samples.length > 2 && task.samples[1].time <= cutoff) task.samples.shift();
|
|
192
|
+
const oldest = task.samples[0];
|
|
193
|
+
const recentMovement = Math.abs(wrap(state.jointType, state.coordinate-oldest.coordinate));
|
|
194
|
+
const observedWindow = task.elapsed-oldest.time;
|
|
195
|
+
const stableCutoff = task.elapsed-task.stableDuration;
|
|
196
|
+
const stableReference = task.samples.find((sample) => sample.time >= stableCutoff) || oldest;
|
|
197
|
+
const settleMovement = Math.abs(wrap(state.jointType, state.coordinate-stableReference.coordinate));
|
|
198
|
+
const settleTolerance = state.tolerance*.25;
|
|
199
|
+
const progress = Math.abs(wrap(state.jointType, task.initialCoordinate-task.target)) - state.error;
|
|
200
|
+
if (task.stable >= task.stableDuration && settleMovement <= settleTolerance) {
|
|
201
|
+
this.finish(task, { status:'action-completed', targetReached:true, settled:true, coordinate:state.coordinate, error:state.error, tolerance:state.tolerance, settleMovement:Number(settleMovement.toFixed(6)), settleTolerance:Number(settleTolerance.toFixed(6)), progress:Number(progress.toFixed(6)), elapsed:Number(task.elapsed.toFixed(3)), coordinateReference:state.coordinateReference });
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
if (!reached && task.elapsed >= task.stallWindow && observedWindow >= task.stallWindow*.8 && recentMovement < task.stallTolerance) {
|
|
205
|
+
const attribution = this.failureAttribution(task.id, task.partName);
|
|
206
|
+
this.finish(task, { status:'action-failed', reason:'STALL', targetReached:false, settled:false, coordinate:state.coordinate, error:state.error, tolerance:state.tolerance, recentMovement:Number(recentMovement.toFixed(6)), stallWindow:task.stallWindow, progress:Number(progress.toFixed(6)), elapsed:Number(task.elapsed.toFixed(3)), coordinateReference:state.coordinateReference, attribution });
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
if (task.elapsed >= task.timeout) {
|
|
210
|
+
this.finish(task, { status:'action-unverified', reason:'TIMEOUT', targetReached:false, settled:false, coordinate:state.coordinate, error:state.error, tolerance:state.tolerance, recentMovement:Number(recentMovement.toFixed(6)), progress:Number(progress.toFixed(6)), elapsed:Number(task.elapsed.toFixed(3)), coordinateReference:state.coordinateReference });
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|