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.
Files changed (396) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +19 -2
  3. package/cli.mjs +53 -0
  4. package/dist/AssetCompiler-A99wKf7H.js +2424 -0
  5. package/dist/AssetCompiler-A99wKf7H.js.map +1 -0
  6. package/dist/AssetInputContracts-uKYeQu-X.js +245 -0
  7. package/dist/AssetInputContracts-uKYeQu-X.js.map +1 -0
  8. package/dist/AssetRecipe-DCaLLXvG.js +67 -0
  9. package/dist/AssetRecipe-DCaLLXvG.js.map +1 -0
  10. package/dist/BrowserCodeWorker.js +53850 -0
  11. package/dist/BrowserCodeWorker.js.map +1 -0
  12. package/dist/KinematicHypothesisScreen-4v7GBwdv.js +241 -0
  13. package/dist/KinematicHypothesisScreen-4v7GBwdv.js.map +1 -0
  14. package/dist/SceneSerializer-CLCzQjL_.js +350 -0
  15. package/dist/SceneSerializer-CLCzQjL_.js.map +1 -0
  16. package/dist/StylePack-CD_BC-Mv.js +6317 -0
  17. package/dist/StylePack-CD_BC-Mv.js.map +1 -0
  18. package/dist/WorldArchive-dYf1OpSe.js +417 -0
  19. package/dist/WorldArchive-dYf1OpSe.js.map +1 -0
  20. package/dist/WorldIO-Dqz4MqTQ.js +149 -0
  21. package/dist/WorldIO-Dqz4MqTQ.js.map +1 -0
  22. package/dist/blankWorld-OoOvN_IK.js +75 -0
  23. package/dist/blankWorld-OoOvN_IK.js.map +1 -0
  24. package/dist/core.d.ts +68 -0
  25. package/dist/core.js +209 -0
  26. package/dist/core.js.map +1 -0
  27. package/dist/disposeObject3D-B3HCflvO.js +128 -0
  28. package/dist/disposeObject3D-B3HCflvO.js.map +1 -0
  29. package/dist/environments-B1WaICAN.js +4197 -0
  30. package/dist/environments-B1WaICAN.js.map +1 -0
  31. package/dist/gltfIO-BMK1hc2D.js +9 -0
  32. package/dist/gltfIO-BMK1hc2D.js.map +1 -0
  33. package/dist/grandUrbanBlock-Bdjgc6ZT.js +515 -0
  34. package/dist/grandUrbanBlock-Bdjgc6ZT.js.map +1 -0
  35. package/dist/index.d.ts +275 -0
  36. package/dist/index.js +16239 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/magicCabin-DPQi_jh-.js +11019 -0
  39. package/dist/magicCabin-DPQi_jh-.js.map +1 -0
  40. package/dist/mcp.d.ts +2 -0
  41. package/dist/mcp.js +1 -0
  42. package/dist/monumentHall-IOLbRZQC.js +403 -0
  43. package/dist/monumentHall-IOLbRZQC.js.map +1 -0
  44. package/dist/node.d.ts +16 -0
  45. package/dist/node.js +26 -0
  46. package/dist/rolldown-runtime-D3KUYPsf.js +12 -0
  47. package/dist/ruinedCourtyard-BtaF_aOi.js +696 -0
  48. package/dist/ruinedCourtyard-BtaF_aOi.js.map +1 -0
  49. package/dist/runtime/application/AgentTools.js +28 -0
  50. package/dist/runtime/application/README.md +14 -0
  51. package/dist/runtime/application/agent/ProgressiveAgentTools.js +92 -0
  52. package/dist/runtime/application/agent/StudioMcpAllowlist.js +8 -0
  53. package/dist/runtime/application/buildTaskObservation.js +117 -0
  54. package/dist/runtime/application/code-execution/AuthoringSandboxEntry.js +46 -0
  55. package/dist/runtime/application/code-execution/BrowserCodeExecutor.js +35 -0
  56. package/dist/runtime/application/code-execution/BrowserCodeWorker.js +17 -0
  57. package/dist/runtime/application/code-execution/RemoteAuthoringDocument.js +72 -0
  58. package/dist/runtime/application/createSession.js +66 -0
  59. package/dist/runtime/application/createWorldAuthoringContext.js +400 -0
  60. package/dist/runtime/application/generation/GenerationOrchestrator.js +629 -0
  61. package/dist/runtime/application/generation/GenerationRuntime.js +214 -0
  62. package/dist/runtime/application/generation/PromptHybridWorldOrchestrator.js +285 -0
  63. package/dist/runtime/application/native-scene/CodeProject.js +119 -0
  64. package/dist/runtime/application/native-scene/CodeProjectModules.js +128 -0
  65. package/dist/runtime/application/native-scene/NativeEnvironmentGeometry.js +62 -0
  66. package/dist/runtime/application/native-scene/NativeOverlayCheckpoint.js +127 -0
  67. package/dist/runtime/application/native-scene/NativeRenderDiscovery.js +51 -0
  68. package/dist/runtime/application/native-scene/NativeSceneHost.js +319 -0
  69. package/dist/runtime/application/native-scene/NativeSceneOverlay.js +116 -0
  70. package/dist/runtime/application/native-scene/NativeThreeModule.js +16 -0
  71. package/dist/runtime/application/object-forge/SceneObjectForge.js +232 -0
  72. package/dist/runtime/application/programmatic-assets/ProgrammaticAssetBuilder.js +59 -0
  73. package/dist/runtime/application/programmatic-assets/ProgrammaticAssetContract.js +22 -0
  74. package/dist/runtime/application/programmatic-assets/ThreeCodeAsset.js +40 -0
  75. package/dist/runtime/application/scene/CapabilityResolver.js +79 -0
  76. package/dist/runtime/application/scene/RequestWindow.js +54 -0
  77. package/dist/runtime/application/scene/SceneAgentTools.js +21 -0
  78. package/dist/runtime/application/scene/SceneContracts.js +45 -0
  79. package/dist/runtime/application/scene/SceneEditService.js +144 -0
  80. package/dist/runtime/application/scene/SceneFacade.js +261 -0
  81. package/dist/runtime/application/scene/SceneInteractionAdapters.js +40 -0
  82. package/dist/runtime/application/scene/SceneJobController.js +229 -0
  83. package/dist/runtime/application/scene/SceneLifecycle.js +57 -0
  84. package/dist/runtime/application/scene/ScenePackage.js +162 -0
  85. package/dist/runtime/application/scene/ScenePersistence.js +50 -0
  86. package/dist/runtime/application/scene/SceneProject.js +95 -0
  87. package/dist/runtime/application/scene/SceneSkillNames.js +5 -0
  88. package/dist/runtime/application/scene/StarterScene.js +56 -0
  89. package/dist/runtime/application/scene/WorldArchive.js +87 -0
  90. package/dist/runtime/application/scene/WorldDirectory.js +20 -0
  91. package/dist/runtime/application/scene/WorldDocument.js +74 -0
  92. package/dist/runtime/application/scene/WorldIO.js +103 -0
  93. package/dist/runtime/application/scene/WorldStorage.js +137 -0
  94. package/dist/runtime/application/skills/SkillRegistry.js +189 -0
  95. package/dist/runtime/application/skills/packs/acceptanceSkills.js +32 -0
  96. package/dist/runtime/application/skills/packs/affordanceSkills.js +36 -0
  97. package/dist/runtime/application/skills/packs/assetSkills.js +46 -0
  98. package/dist/runtime/application/skills/packs/authoringSkills.js +16 -0
  99. package/dist/runtime/application/skills/packs/batchSkills.js +22 -0
  100. package/dist/runtime/application/skills/packs/codeSkills.js +106 -0
  101. package/dist/runtime/application/skills/packs/generationSkills.js +45 -0
  102. package/dist/runtime/application/skills/packs/interactionSkills.js +46 -0
  103. package/dist/runtime/application/skills/packs/recoverySkills.js +80 -0
  104. package/dist/runtime/application/skills/packs/sceneSkills.js +24 -0
  105. package/dist/runtime/application/skills/packs/spatialSkills.js +35 -0
  106. package/dist/runtime/application/skills/packs/verificationSkills.js +14 -0
  107. package/dist/runtime/application/skills/packs/worldSkills.js +45 -0
  108. package/dist/runtime/application/skills/registerCoreSkills.js +31 -0
  109. package/dist/runtime/application/skills/skillPrimitives.js +4 -0
  110. package/dist/runtime/application/tasks/CabinetCupTask.js +76 -0
  111. package/dist/runtime/application/tasks.jsonl +67 -0
  112. package/dist/runtime/application/world-authoring/AuthoringAssetProducer.js +42 -0
  113. package/dist/runtime/application/world-authoring/AuthoringDiff.js +149 -0
  114. package/dist/runtime/application/world-authoring/AuthoringDocument.js +825 -0
  115. package/dist/runtime/application/world-authoring/AuthoringExecutionHost.js +109 -0
  116. package/dist/runtime/application/world-authoring/AuthoringIdentity.js +17 -0
  117. package/dist/runtime/application/world-authoring/AuthoringModelResolver.js +29 -0
  118. package/dist/runtime/application/world-authoring/AuthoringPatch.js +118 -0
  119. package/dist/runtime/application/world-authoring/AuthoringPromotionController.js +334 -0
  120. package/dist/runtime/application/world-authoring/AuthoringPromotionSource.js +126 -0
  121. package/dist/runtime/application/world-authoring/AuthoringRevisionHistory.js +144 -0
  122. package/dist/runtime/application/world-authoring/HeadlessImageExport.js +174 -0
  123. package/dist/runtime/application/world-authoring/ModelRef.js +62 -0
  124. package/dist/runtime/apps/mcp-server/AUTHORING.md +71 -0
  125. package/dist/runtime/apps/mcp-server/AgentMcpCompat.js +77 -0
  126. package/dist/runtime/apps/mcp-server/AuthoringSandboxEntry.js +1 -0
  127. package/dist/runtime/apps/mcp-server/AuthoringSandboxWorker.mjs +30 -0
  128. package/dist/runtime/apps/mcp-server/BuildEnvironment.js +17 -0
  129. package/dist/runtime/apps/mcp-server/CodeExecutor.js +71 -0
  130. package/dist/runtime/apps/mcp-server/DEPLOYMENT-PC2.md +42 -0
  131. package/dist/runtime/apps/mcp-server/DockerBuildRunner.js +66 -0
  132. package/dist/runtime/apps/mcp-server/FileAssetRepository.js +159 -0
  133. package/dist/runtime/apps/mcp-server/HeadlessAssetIO.js +8 -0
  134. package/dist/runtime/apps/mcp-server/HeadlessGLTFLoader.js +47 -0
  135. package/dist/runtime/apps/mcp-server/HeadlessWorldHost.js +132 -0
  136. package/dist/runtime/apps/mcp-server/IsolatedAuthoringExecutor.js +6 -0
  137. package/dist/runtime/apps/mcp-server/PROGRAMMATIC-ASSETS.md +116 -0
  138. package/dist/runtime/apps/mcp-server/ProgrammaticAssets.js +60 -0
  139. package/dist/runtime/apps/mcp-server/README.md +150 -0
  140. package/dist/runtime/apps/mcp-server/RemoteAuthoringDocument.js +1 -0
  141. package/dist/runtime/apps/mcp-server/SandboxBundle.js +13 -0
  142. package/dist/runtime/apps/mcp-server/SessionManager.js +80 -0
  143. package/dist/runtime/apps/mcp-server/StudioBridgeHttp.js +58 -0
  144. package/dist/runtime/apps/mcp-server/StudioLiveBridge.js +190 -0
  145. package/dist/runtime/apps/mcp-server/TrustedAuthoringWorker.mjs +16 -0
  146. package/dist/runtime/apps/mcp-server/VALIDATION.md +45 -0
  147. package/dist/runtime/apps/mcp-server/acceptance-evidence.json +332 -0
  148. package/dist/runtime/apps/mcp-server/errorDiagnostics.js +32 -0
  149. package/dist/runtime/apps/mcp-server/examples/code-house.js +24 -0
  150. package/dist/runtime/apps/mcp-server/examples/procedural-assets.js +85 -0
  151. package/dist/runtime/apps/mcp-server/main.mjs +65 -0
  152. package/dist/runtime/apps/mcp-server/registerTools.js +225 -0
  153. package/dist/runtime/apps/mcp-server/sandbox/run.mjs +23 -0
  154. package/dist/runtime/apps/mcp-server/security.js +21 -0
  155. package/dist/runtime/apps/mcp-server/tasks.jsonl +9 -0
  156. package/dist/runtime/apps/server/CapabilityAdapterRegistry.js +157 -0
  157. package/dist/runtime/apps/server/README.md +7 -0
  158. package/dist/runtime/apps/server/WorldDiskStorage.js +51 -0
  159. package/dist/runtime/apps/server/openai-compatible-agent-gateway.mjs +278 -0
  160. package/dist/runtime/apps/server/tasks.jsonl +10 -0
  161. package/dist/runtime/foundation/EventBus.js +18 -0
  162. package/dist/runtime/foundation/JsonGateway.js +47 -0
  163. package/dist/runtime/foundation/PolicyEngine.js +21 -0
  164. package/dist/runtime/foundation/README.md +7 -0
  165. package/dist/runtime/foundation/TraceRecorder.js +76 -0
  166. package/dist/runtime/foundation/errors.js +8 -0
  167. package/dist/runtime/foundation/simulation/SimulationProfile.js +143 -0
  168. package/dist/runtime/foundation/version.js +2 -0
  169. package/dist/runtime/modules/agent/README.md +11 -0
  170. package/dist/runtime/modules/agent/ToolCallingAgent.js +19 -0
  171. package/dist/runtime/modules/agent/bootstrapWorld.js +10 -0
  172. package/dist/runtime/modules/agent/buildRecoveryProposals.js +533 -0
  173. package/dist/runtime/modules/agent/execution/AgentExecutionRules.js +128 -0
  174. package/dist/runtime/modules/agent/execution/AgentRunResults.js +55 -0
  175. package/dist/runtime/modules/agent/execution/AgentRunSession.js +393 -0
  176. package/dist/runtime/modules/agent/execution/AgentToolInvoker.js +40 -0
  177. package/dist/runtime/modules/agent/gateway/HttpLLMGateway.js +19 -0
  178. package/dist/runtime/modules/agent/prompt/index.js +52 -0
  179. package/dist/runtime/modules/agent/tasks.jsonl +94 -0
  180. package/dist/runtime/modules/artifact/ArtifactContentGate.js +144 -0
  181. package/dist/runtime/modules/artifact/ArtifactDescriptor.js +280 -0
  182. package/dist/runtime/modules/artifact/ArtifactImporter.js +185 -0
  183. package/dist/runtime/modules/artifact/ArtifactModule.js +111 -0
  184. package/dist/runtime/modules/artifact/ArtifactRegistry.js +197 -0
  185. package/dist/runtime/modules/artifact/IncrementalSha256.js +129 -0
  186. package/dist/runtime/modules/artifact/MemoryArtifactByteStore.js +115 -0
  187. package/dist/runtime/modules/artifact/README.md +7 -0
  188. package/dist/runtime/modules/artifact/storage/IndexedDbArtifactStore.js +67 -0
  189. package/dist/runtime/modules/artifact/tasks.jsonl +31 -0
  190. package/dist/runtime/modules/asset/AssetModule.js +399 -0
  191. package/dist/runtime/modules/asset/README.md +54 -0
  192. package/dist/runtime/modules/asset/loading/AssetLoader.js +157 -0
  193. package/dist/runtime/modules/asset/loading/GltfAssetLoader.js +61 -0
  194. package/dist/runtime/modules/asset/loading/builtins/BuiltinAssets.js +95 -0
  195. package/dist/runtime/modules/asset/loading/builtins/HouseDoor.js +33 -0
  196. package/dist/runtime/modules/asset/loading/builtins/IndustrialCabinet.js +103 -0
  197. package/dist/runtime/modules/asset/model/AssetInputContracts.js +100 -0
  198. package/dist/runtime/modules/asset/model/AssetRef.js +12 -0
  199. package/dist/runtime/modules/asset/model/MechanicalAssetDraft.js +172 -0
  200. package/dist/runtime/modules/asset/model/admission.js +117 -0
  201. package/dist/runtime/modules/asset/model/errors.js +6 -0
  202. package/dist/runtime/modules/asset/model/parts.js +27 -0
  203. package/dist/runtime/modules/asset/model/resourceBudget.js +10 -0
  204. package/dist/runtime/modules/asset/model/schema.js +150 -0
  205. package/dist/runtime/modules/asset/persistence/AssetManifestStore.js +78 -0
  206. package/dist/runtime/modules/asset/persistence/CompiledAssetStore.js +84 -0
  207. package/dist/runtime/modules/asset/persistence/LocalAssetLibrary.js +86 -0
  208. package/dist/runtime/modules/asset/persistence/LocalAssetLibraryStore.js +81 -0
  209. package/dist/runtime/modules/asset/production/AssetProductionPipeline.js +272 -0
  210. package/dist/runtime/modules/asset/production/AssetRecipe.js +47 -0
  211. package/dist/runtime/modules/asset/production/adapters/EmbodiedGenAdapter.js +45 -0
  212. package/dist/runtime/modules/asset/production/adapters/EmbodiedGenBundleAdapter.js +590 -0
  213. package/dist/runtime/modules/asset/production/compiler/AssetCompiler.js +173 -0
  214. package/dist/runtime/modules/asset/production/compiler/evidence/AnimationMotionEvidence.js +124 -0
  215. package/dist/runtime/modules/asset/production/compiler/evidence/StaticPanelEvidence.js +56 -0
  216. package/dist/runtime/modules/asset/production/compiler/gltfIO.js +6 -0
  217. package/dist/runtime/modules/asset/production/compiler/partGeometry.js +74 -0
  218. package/dist/runtime/modules/asset/production/compiler/passes/ArticulatedCollisionPass.js +63 -0
  219. package/dist/runtime/modules/asset/production/compiler/passes/ArticulationCandidatePass.js +48 -0
  220. package/dist/runtime/modules/asset/production/compiler/passes/AuthoringIntentPass.js +16 -0
  221. package/dist/runtime/modules/asset/production/compiler/passes/ColliderFallbackPass.js +30 -0
  222. package/dist/runtime/modules/asset/production/compiler/passes/CompileQualityPass.js +75 -0
  223. package/dist/runtime/modules/asset/production/compiler/passes/ExplicitDefinitionPass.js +20 -0
  224. package/dist/runtime/modules/asset/production/compiler/passes/GLTFInspectPass.js +34 -0
  225. package/dist/runtime/modules/asset/production/compiler/passes/GeometryPass.js +32 -0
  226. package/dist/runtime/modules/asset/production/compiler/passes/JointFramePass.js +116 -0
  227. package/dist/runtime/modules/asset/production/compiler/passes/KinematicEvidencePass.js +84 -0
  228. package/dist/runtime/modules/asset/production/compiler/passes/ManifestPass.js +63 -0
  229. package/dist/runtime/modules/asset/production/compiler/passes/NormalizeTransformPass.js +16 -0
  230. package/dist/runtime/modules/asset/production/compiler/passes/OptimizeGLBPass.js +23 -0
  231. package/dist/runtime/modules/asset/production/compiler/passes/PartColliderPass.js +50 -0
  232. package/dist/runtime/modules/asset/production/compiler/passes/PartGeometryEnrichmentPass.js +60 -0
  233. package/dist/runtime/modules/asset/production/compiler/passes/PartProposalPass.js +93 -0
  234. package/dist/runtime/modules/asset/production/compiler/passes/RemoteEnrichmentPass.js +32 -0
  235. package/dist/runtime/modules/asset/production/compiler/passes/ResourceBudgetPass.js +55 -0
  236. package/dist/runtime/modules/asset/production/compiler/passes/SegmentMaterializePass.js +203 -0
  237. package/dist/runtime/modules/asset/production/compiler/passes/SegmentationEvidencePass.js +43 -0
  238. package/dist/runtime/modules/asset/production/compiler/passes/SemanticHeuristicPass.js +33 -0
  239. package/dist/runtime/modules/asset/production/compiler/passes/StructurePass.js +60 -0
  240. package/dist/runtime/modules/asset/production/compiler/providers/HttpCompilerProvider.js +23 -0
  241. package/dist/runtime/modules/asset/production/verification/KinematicHypothesisScreen.js +198 -0
  242. package/dist/runtime/modules/asset/registry/AssetCatalog.js +72 -0
  243. package/dist/runtime/modules/asset/registry/AssetRegistry.js +51 -0
  244. package/dist/runtime/modules/asset/registry/manifests/index.js +173 -0
  245. package/dist/runtime/modules/asset/tasks.jsonl +87 -0
  246. package/dist/runtime/modules/generation/README.md +9 -0
  247. package/dist/runtime/modules/generation/connector/ConnectorArtifactClient.js +45 -0
  248. package/dist/runtime/modules/generation/connector/ConnectorCapabilityAdapter.js +169 -0
  249. package/dist/runtime/modules/generation/connector/ConnectorClient.js +192 -0
  250. package/dist/runtime/modules/generation/connector/ConnectorJobClient.js +167 -0
  251. package/dist/runtime/modules/generation/connector/ConnectorJobEventClient.js +179 -0
  252. package/dist/runtime/modules/generation/connector/ConnectorSession.js +202 -0
  253. package/dist/runtime/modules/generation/jobs/GenerationJobProjection.js +239 -0
  254. package/dist/runtime/modules/generation/jobs/GenerationJobReconciler.js +99 -0
  255. package/dist/runtime/modules/generation/jobs/GenerationJobStore.js +91 -0
  256. package/dist/runtime/modules/generation/jobs/GenerationJobTransportOverlay.js +50 -0
  257. package/dist/runtime/modules/generation/providers/ProviderRegistry.js +304 -0
  258. package/dist/runtime/modules/generation/tasks.jsonl +35 -0
  259. package/dist/runtime/modules/navigation/NavigationBackend.js +17 -0
  260. package/dist/runtime/modules/navigation/RecastNavigationBackend.js +245 -0
  261. package/dist/runtime/modules/physics/JoltPhysicsBackend.js +850 -0
  262. package/dist/runtime/modules/physics/PhysicsApiSurface.js +651 -0
  263. package/dist/runtime/modules/physics/PhysicsBackend.js +88 -0
  264. package/dist/runtime/modules/physics/RapierPhysicsBackend.js +410 -0
  265. package/dist/runtime/modules/rendering/README.md +7 -0
  266. package/dist/runtime/modules/rendering/RendererProbe.js +153 -0
  267. package/dist/runtime/modules/rendering/WebGpuPostFxPipeline.js +140 -0
  268. package/dist/runtime/modules/rendering/createRenderer.js +76 -0
  269. package/dist/runtime/modules/rendering/disposeObject3D.js +37 -0
  270. package/dist/runtime/modules/rendering/loadGaussianSplatVisual.js +74 -0
  271. package/dist/runtime/modules/rendering/spatial/ThreeBvhRuntime.js +107 -0
  272. package/dist/runtime/modules/rendering/style/StylePack.js +34 -0
  273. package/dist/runtime/modules/rendering/style/StyleSystem.js +173 -0
  274. package/dist/runtime/modules/rendering/tasks.jsonl +7 -0
  275. package/dist/runtime/modules/world/README.md +13 -0
  276. package/dist/runtime/modules/world/build/WorldBuilder.js +170 -0
  277. package/dist/runtime/modules/world/compiler/PipelineEngine.js +32 -0
  278. package/dist/runtime/modules/world/compiler/WorldAdmission.js +43 -0
  279. package/dist/runtime/modules/world/compiler/WorldBehaviorCompiler.js +68 -0
  280. package/dist/runtime/modules/world/compiler/WorldCompilation.js +157 -0
  281. package/dist/runtime/modules/world/compiler/WorldComposer.js +201 -0
  282. package/dist/runtime/modules/world/compiler/WorldPhysicsAdmission.js +76 -0
  283. package/dist/runtime/modules/world/compiler/WorldRecompiler.js +356 -0
  284. package/dist/runtime/modules/world/compiler/WorldRetry.js +75 -0
  285. package/dist/runtime/modules/world/compiler/createWorldPipeline.js +379 -0
  286. package/dist/runtime/modules/world/content/blankWorld.js +35 -0
  287. package/dist/runtime/modules/world/content/environments.js +84 -0
  288. package/dist/runtime/modules/world/content/grandUrbanBlock.js +189 -0
  289. package/dist/runtime/modules/world/content/magic-cabin/README.md +28 -0
  290. package/dist/runtime/modules/world/content/magic-cabin/affordances.js +64 -0
  291. package/dist/runtime/modules/world/content/magic-cabin/cabinContents.js +7078 -0
  292. package/dist/runtime/modules/world/content/magic-cabin/lighting.js +26 -0
  293. package/dist/runtime/modules/world/content/magic-cabin/materials.js +20 -0
  294. package/dist/runtime/modules/world/content/magicCabin.js +190 -0
  295. package/dist/runtime/modules/world/content/monumentHall.js +154 -0
  296. package/dist/runtime/modules/world/content/ruinedCourtyard.js +196 -0
  297. package/dist/runtime/modules/world/content/suzhouGarden/README.md +141 -0
  298. package/dist/runtime/modules/world/content/suzhouGarden/index.js +137 -0
  299. package/dist/runtime/modules/world/content/suzhouGarden/src/arch.js +491 -0
  300. package/dist/runtime/modules/world/content/suzhouGarden/src/buildings.js +670 -0
  301. package/dist/runtime/modules/world/content/suzhouGarden/src/core.js +578 -0
  302. package/dist/runtime/modules/world/content/suzhouGarden/src/lod.js +127 -0
  303. package/dist/runtime/modules/world/content/suzhouGarden/src/main.js +642 -0
  304. package/dist/runtime/modules/world/content/suzhouGarden/src/nature.js +650 -0
  305. package/dist/runtime/modules/world/content/suzhouGarden/src/rockery.js +280 -0
  306. package/dist/runtime/modules/world/content/suzhouGarden/src/sky.js +242 -0
  307. package/dist/runtime/modules/world/content/suzhouGarden/src/water.js +215 -0
  308. package/dist/runtime/modules/world/content/woodlandWorkshop.js +192 -0
  309. package/dist/runtime/modules/world/content/yuanmingyuan/README.md +36 -0
  310. package/dist/runtime/modules/world/content/yuanmingyuan/arch.js +351 -0
  311. package/dist/runtime/modules/world/content/yuanmingyuan/buildings.js +490 -0
  312. package/dist/runtime/modules/world/content/yuanmingyuan/core.js +505 -0
  313. package/dist/runtime/modules/world/content/yuanmingyuan/index.js +101 -0
  314. package/dist/runtime/modules/world/content/yuanmingyuan/nature.js +435 -0
  315. package/dist/runtime/modules/world/content/yuanmingyuan/sky.js +169 -0
  316. package/dist/runtime/modules/world/content/yuanmingyuan/water.js +245 -0
  317. package/dist/runtime/modules/world/errors.js +9 -0
  318. package/dist/runtime/modules/world/generated/GeneratedWorldCoordinates.js +50 -0
  319. package/dist/runtime/modules/world/generated/GeneratedWorldLoader.js +297 -0
  320. package/dist/runtime/modules/world/runtime/CommandHistory.js +80 -0
  321. package/dist/runtime/modules/world/runtime/EntityCapabilityRegistry.js +150 -0
  322. package/dist/runtime/modules/world/runtime/ObjectStore.js +31 -0
  323. package/dist/runtime/modules/world/runtime/ObjectTransform.js +62 -0
  324. package/dist/runtime/modules/world/runtime/ObservedEntity.js +37 -0
  325. package/dist/runtime/modules/world/runtime/ProjectCapabilities.js +207 -0
  326. package/dist/runtime/modules/world/runtime/SceneSerializer.js +246 -0
  327. package/dist/runtime/modules/world/runtime/WorldAuthority.js +41 -0
  328. package/dist/runtime/modules/world/runtime/WorldCollisionSignature.js +14 -0
  329. package/dist/runtime/modules/world/runtime/WorldCommands.js +502 -0
  330. package/dist/runtime/modules/world/runtime/WorldObservation.js +71 -0
  331. package/dist/runtime/modules/world/runtime/WorldQueries.js +340 -0
  332. package/dist/runtime/modules/world/runtime/WorldRecovery.js +78 -0
  333. package/dist/runtime/modules/world/runtime/WorldRuntime.js +665 -0
  334. package/dist/runtime/modules/world/runtime/affordance/ObjectAffordances.js +107 -0
  335. package/dist/runtime/modules/world/runtime/affordance/WorldAffordances.js +130 -0
  336. package/dist/runtime/modules/world/runtime/behavior/BehaviorCompiler.js +79 -0
  337. package/dist/runtime/modules/world/runtime/behavior/ProjectStateMachine.js +195 -0
  338. package/dist/runtime/modules/world/runtime/behavior/RuleGraph.js +70 -0
  339. package/dist/runtime/modules/world/runtime/behavior/RuleRuntime.js +115 -0
  340. package/dist/runtime/modules/world/runtime/graph/SceneGraph.js +305 -0
  341. package/dist/runtime/modules/world/runtime/interaction/ArticulationRuntime.js +214 -0
  342. package/dist/runtime/modules/world/runtime/interaction/CarryCapability.js +65 -0
  343. package/dist/runtime/modules/world/runtime/interaction/CarryRuntime.js +222 -0
  344. package/dist/runtime/modules/world/runtime/interaction/InteractionApproach.js +130 -0
  345. package/dist/runtime/modules/world/runtime/interaction/InteractionContract.js +57 -0
  346. package/dist/runtime/modules/world/runtime/interaction/RecoveryRuntime.js +123 -0
  347. package/dist/runtime/modules/world/runtime/interaction/SettleRuntime.js +120 -0
  348. package/dist/runtime/modules/world/runtime/semantic/SemanticWorldView.js +102 -0
  349. package/dist/runtime/modules/world/runtime/simulation/SimulationClock.js +89 -0
  350. package/dist/runtime/modules/world/runtime/simulation/SimulationSession.js +99 -0
  351. package/dist/runtime/modules/world/runtime/simulation/ThermalSystem.js +269 -0
  352. package/dist/runtime/modules/world/runtime/spatial/SpatialSnapshot.js +56 -0
  353. package/dist/runtime/modules/world/runtime/systems/AudioSystem.js +125 -0
  354. package/dist/runtime/modules/world/runtime/systems/Instrument.js +38 -0
  355. package/dist/runtime/modules/world/runtime/systems/InteractionSystem.js +728 -0
  356. package/dist/runtime/modules/world/runtime/systems/LocomotionSystem.js +269 -0
  357. package/dist/runtime/modules/world/runtime/systems/NavigationSystem.js +469 -0
  358. package/dist/runtime/modules/world/runtime/systems/PhysicsSystem.js +1673 -0
  359. package/dist/runtime/modules/world/runtime/systems/RenderingSystem.js +457 -0
  360. package/dist/runtime/modules/world/runtime/systems/SpatialSystem.js +284 -0
  361. package/dist/runtime/modules/world/spec/WorldIR.js +165 -0
  362. package/dist/runtime/modules/world/spec/WorldIRToolSchema.js +86 -0
  363. package/dist/runtime/modules/world/spec/WorldPlannerProposal.js +51 -0
  364. package/dist/runtime/modules/world/spec/WorldRevision.js +231 -0
  365. package/dist/runtime/modules/world/spec/WorldSpec.js +86 -0
  366. package/dist/runtime/modules/world/tasks.jsonl +530 -0
  367. package/dist/runtime/modules/world/verification/ArticulationVerifier.js +254 -0
  368. package/dist/runtime/modules/world/verification/Finding.js +105 -0
  369. package/dist/runtime/modules/world/verification/InteractionEvidence.js +69 -0
  370. package/dist/runtime/modules/world/verification/RepairEngine.js +49 -0
  371. package/dist/runtime/modules/world/verification/WorldAcceptance.js +158 -0
  372. package/dist/runtime/modules/world/verification/WorldValidator.js +65 -0
  373. package/dist/runtime/package-lock.json +16048 -0
  374. package/dist/runtime/package.json +105 -0
  375. package/dist/runtime/public/assets/cabinet.glb +0 -0
  376. package/dist/runtime/public/assets/grand-urban-block/clean_asphalt_diff_1k.jpg +0 -0
  377. package/dist/runtime/public/assets/grand-urban-block/clean_asphalt_nor_gl_1k.jpg +0 -0
  378. package/dist/runtime/public/assets/grand-urban-block/concrete_pavement_diff_1k.jpg +0 -0
  379. package/dist/runtime/public/assets/grand-urban-block/urban_street_01_1k.hdr +0 -0
  380. package/dist/runtime/public/assets/monument-hall/marble_diff_1k.jpg +0 -0
  381. package/dist/runtime/public/assets/monument-hall/marble_nor_gl_1k.jpg +0 -0
  382. package/dist/runtime/public/assets/monument-hall/marble_rough_1k.jpg +0 -0
  383. package/dist/runtime/public/assets/monument-hall/solitude_interior_1k.hdr +0 -0
  384. package/dist/runtime/public/assets/ruined-courtyard/courtyard_1k.hdr +0 -0
  385. package/dist/runtime/public/assets/ruined-courtyard/mossy_cobblestone_diff_1k.jpg +0 -0
  386. package/dist/runtime/public/assets/ruined-courtyard/mossy_cobblestone_nor_gl_1k.jpg +0 -0
  387. package/dist/runtime/public/assets/ruined-courtyard/mossy_sandstone_diff_1k.jpg +0 -0
  388. package/dist/schema-BWpTl0Wj.js +359 -0
  389. package/dist/schema-BWpTl0Wj.js.map +1 -0
  390. package/dist/suzhouGarden-H9tiPgxq.js +6150 -0
  391. package/dist/suzhouGarden-H9tiPgxq.js.map +1 -0
  392. package/dist/woodlandWorkshop-D6zzSbHr.js +483 -0
  393. package/dist/woodlandWorkshop-D6zzSbHr.js.map +1 -0
  394. package/dist/yuanmingyuan-D6IHqjZ-.js +4955 -0
  395. package/dist/yuanmingyuan-D6IHqjZ-.js.map +1 -0
  396. package/package.json +70 -4
@@ -0,0 +1,642 @@
1
+ /* 吴苑澄观 · 主程序
2
+ * 渲染器 / 后处理、分阶段加载、双模式漫游、12 个定点观察视角、
3
+ * 景点标注、小地图、性能 HUD、画质与天气自适应。
4
+ */
5
+ import * as THREE from 'three';
6
+ import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
7
+ import { EffectComposer } from 'three/addons/postprocessing/EffectComposer.js';
8
+ import { RenderPass } from 'three/addons/postprocessing/RenderPass.js';
9
+ import { UnrealBloomPass } from 'three/addons/postprocessing/UnrealBloomPass.js';
10
+ import { ShaderPass } from 'three/addons/postprocessing/ShaderPass.js';
11
+ import { OutputPass } from 'three/addons/postprocessing/OutputPass.js';
12
+ import {
13
+ WORLD, QUALITY, POIS, HOTSPOTS, LOD_LEVELS,
14
+ buildTextures, buildMaterials, Batch, waterSDF, terrainHeight, clamp,
15
+ } from './core.js';
16
+ import { buildBuildings } from './buildings.js';
17
+ import { buildRockery } from './rockery.js';
18
+ import { createWater } from './water.js';
19
+ import { createNature } from './nature.js';
20
+ import { createSky } from './sky.js';
21
+ import { LODManager } from './lod.js';
22
+
23
+ const $ = s => document.querySelector(s);
24
+ const $$ = s => Array.from(document.querySelectorAll(s));
25
+ const nextFrame = () => new Promise(r => requestAnimationFrame(() => setTimeout(r, 0)));
26
+ const lerp = THREE.MathUtils.lerp;
27
+
28
+ /* 电影调色:轻微 S 曲线、冷暖分离、暗角与胶片颗粒 */
29
+ const GradeShader = {
30
+ uniforms: {
31
+ tDiffuse: { value: null }, uTime: { value: 0 },
32
+ uResolution: { value: new THREE.Vector2(1, 1) }, uStrength: { value: 1 },
33
+ },
34
+ vertexShader: `varying vec2 vUv; void main(){ vUv = uv; gl_Position = projectionMatrix * modelViewMatrix * vec4(position,1.0); }`,
35
+ fragmentShader: `
36
+ precision highp float;
37
+ uniform sampler2D tDiffuse; uniform float uTime; uniform vec2 uResolution; uniform float uStrength;
38
+ varying vec2 vUv;
39
+ void main(){
40
+ vec3 c = texture2D(tDiffuse, vUv).rgb;
41
+ vec3 o = c;
42
+ c = clamp((c - 0.5) * 1.052 + 0.5, 0.0, 1.0);
43
+ float l = dot(c, vec3(0.2126, 0.7152, 0.0722));
44
+ c += vec3(0.015, 0.005, -0.012) * smoothstep(0.55, 1.0, l);
45
+ c += vec3(-0.007, 0.001, 0.016) * (1.0 - smoothstep(0.0, 0.45, l));
46
+ vec2 q = vUv - 0.5;
47
+ c *= 1.0 - dot(q, q) * 0.46;
48
+ float g = fract(sin(dot(vUv * uResolution + uTime * 29.0, vec2(12.9898, 78.233))) * 43758.5453);
49
+ c += (g - 0.5) * 0.009;
50
+ gl_FragColor = vec4(mix(o, c, uStrength), 1.0);
51
+ }`,
52
+ };
53
+
54
+ function guessInitialQuality() {
55
+ const p = new URLSearchParams(location.search);
56
+ const forced = p.get('q');
57
+ if (QUALITY[forced]) return forced;
58
+ const dpr = window.devicePixelRatio || 1;
59
+ const cores = navigator.hardwareConcurrency || 4;
60
+ const mem = navigator.deviceMemory || 4;
61
+ const area = window.innerWidth * window.innerHeight;
62
+ if (cores <= 2 || mem <= 2 || /Android|iPhone|iPad/i.test(navigator.userAgent)) return 'low';
63
+ if (cores <= 4 || mem <= 4 || area > 2600000 || dpr > 2.5) return 'medium';
64
+ return 'high';
65
+ }
66
+
67
+ const state = {
68
+ quality: guessInitialQuality(), auto: true, walk: false, labels: true,
69
+ hour: WORLD.sunDefaultHour, weather: 'clear', poi: 'overview',
70
+ fps: 60, frames: 0, acc: 0, lowFor: 0, highFor: 0, cooldown: 0,
71
+ started: false, lodViz: false, lodVizParam: new URLSearchParams(location.search).get('lod') === '1',
72
+ };
73
+
74
+ let renderer, scene, camera, controls, composer, bloomPass, gradePass, outputPass, renderPass;
75
+ let sky, water, nature, lod, mainGroup, plaques = [], labelEls = [], gpuTimer = null;
76
+ let tween = null, toastTimer = null;
77
+ let labelT = 0, mapT = 0;
78
+ const keys = new Set();
79
+ const clock = new THREE.Clock();
80
+ const walkState = { yaw: 0, pitch: -0.10, eye: 1.70, vx: 0, vz: 0, locked: false };
81
+
82
+ function progress(p, text) {
83
+ const bar = $('#load-bar'), pct = $('#load-pct'), label = $('#load-label');
84
+ if (bar) bar.style.width = `${Math.round(p * 100)}%`;
85
+ if (pct) pct.textContent = `${Math.round(p * 100)}%`;
86
+ if (label) label.textContent = text;
87
+ }
88
+
89
+ /* ================================================================== *
90
+ * 启动
91
+ * ================================================================== */
92
+ async function boot() {
93
+ const canvas = $('#scene');
94
+ renderer = new THREE.WebGLRenderer({ canvas, antialias: true, powerPreference: 'high-performance', stencil: false });
95
+ renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, QUALITY[state.quality].dpr));
96
+ renderer.setSize(window.innerWidth, window.innerHeight);
97
+ renderer.outputColorSpace = THREE.SRGBColorSpace;
98
+ renderer.toneMapping = THREE.ACESFilmicToneMapping;
99
+ renderer.toneMappingExposure = 1.08;
100
+ renderer.shadowMap.enabled = true;
101
+ renderer.shadowMap.type = THREE.PCFSoftShadowMap;
102
+ renderer.shadowMap.autoUpdate = false; // 静态场景:仅时辰 / 画质变化时重绘阴影
103
+ renderer.shadowMap.needsUpdate = true;
104
+ renderer.info.autoReset = false;
105
+
106
+ scene = new THREE.Scene();
107
+ camera = new THREE.PerspectiveCamera(POIS[0].fov, window.innerWidth / window.innerHeight, 0.1, 3200);
108
+ camera.position.set(...POIS[0].pos);
109
+ camera.lookAt(...POIS[0].target);
110
+
111
+ progress(0.04, '初始化渲染器与相机');
112
+ await nextFrame();
113
+
114
+ /* 材质贴图集 */
115
+ progress(0.09, '生成白粉墙 / 黛瓦 / 太湖石等 PBR 纹理');
116
+ await nextFrame();
117
+ const T = buildTextures((p, k) => progress(0.09 + p * 0.17, `生成程序化材质:${k}`), QUALITY[state.quality].texScale);
118
+ const M = buildMaterials(T);
119
+ T && Object.values(T).forEach(t => {
120
+ t.map.anisotropy = QUALITY[state.quality].aniso;
121
+ t.normalMap.anisotropy = QUALITY[state.quality].aniso;
122
+ t.roughnessMap.anisotropy = QUALITY[state.quality].aniso;
123
+ });
124
+ await nextFrame();
125
+
126
+ /* 天空与光照 */
127
+ progress(0.28, '布置江南午后天光、软阴影与大气雾');
128
+ await nextFrame();
129
+ sky = createSky(scene, renderer, M);
130
+ sky.setHour(state.hour);
131
+ sky.setQuality(QUALITY[state.quality]);
132
+
133
+ /* 分批构建:建筑 → 假山 → 植被 → 水体 */
134
+ lod = new LODManager(camera, scene);
135
+ lod.setQuality(QUALITY[state.quality]);
136
+ const B = new Batch(40);
137
+ mainGroup = new THREE.Group(); mainGroup.name = '园林静态几何'; scene.add(mainGroup);
138
+ const ctx = {
139
+ B, M, scene, plaques, lod, BatchClass: Batch, quality: QUALITY[state.quality],
140
+ waterfalls: [], streams: [],
141
+ onProgress: (p, name) => progress(0.31 + p * 0.25, `构建建筑:${name}`),
142
+ };
143
+
144
+ progress(0.31, '构建中轴礼序与九大景区建筑群');
145
+ await nextFrame();
146
+ buildBuildings(ctx);
147
+ await nextFrame();
148
+
149
+ progress(0.57, '生成太湖石假山、洞壑与池岸驳岸');
150
+ await nextFrame();
151
+ ctx.onProgress = (p, name) => progress(0.57 + p * 0.13, `${name}`);
152
+ buildRockery(ctx);
153
+ const buildStats = B.build(mainGroup);
154
+ console.log(`[场景] 静态合批 ${buildStats.meshes} 组 / ${Math.round(buildStats.tris)} 三角形`);
155
+ await nextFrame();
156
+
157
+ progress(0.71, '生成地形、园路、林木花木与远景借景');
158
+ await nextFrame();
159
+ nature = createNature(scene, M, ctx);
160
+
161
+ progress(0.84, '布置水面、跌水与天气联动');
162
+ await nextFrame();
163
+ water = createWater(scene, ctx);
164
+ water.setSky(sky.getState());
165
+
166
+ /* LOD 注册 */
167
+ [mainGroup, nature.trunkGroup, nature.pathGroup].forEach(g => g && lod.addBatchGroup(g));
168
+ lod.setQuality(QUALITY[state.quality]);
169
+ if (state.lodVizParam) setLodViz(true);
170
+
171
+ progress(0.90, '装配漫游交互、后处理与画质分级');
172
+ await nextFrame();
173
+ controls = new OrbitControls(camera, renderer.domElement);
174
+ controls.enableDamping = true;
175
+ controls.dampingFactor = 0.055;
176
+ controls.rotateSpeed = 0.55;
177
+ controls.zoomSpeed = 0.9;
178
+ controls.panSpeed = 0.75;
179
+ controls.screenSpacePanning = false;
180
+ controls.minDistance = 2.5;
181
+ controls.maxDistance = 420;
182
+ // 允许适度仰视(定点视角常需从人眼高度仰望檐口与远塔),
183
+ // 过严的 89° 上限会把相机强行抬到目标之上,破坏人眼视高构图
184
+ controls.minPolarAngle = 0.05;
185
+ controls.maxPolarAngle = Math.PI * 0.62;
186
+ controls.target.set(...POIS[0].target);
187
+ controls.update();
188
+
189
+ composer = new EffectComposer(renderer);
190
+ renderPass = new RenderPass(scene, camera);
191
+ bloomPass = new UnrealBloomPass(new THREE.Vector2(window.innerWidth, window.innerHeight), 0.26, 0.66, 0.92);
192
+ outputPass = new OutputPass();
193
+ gradePass = new ShaderPass(GradeShader);
194
+ gradePass.uniforms.uResolution.value.set(window.innerWidth, window.innerHeight);
195
+ composer.addPass(renderPass);
196
+ composer.addPass(bloomPass);
197
+ composer.addPass(outputPass);
198
+ composer.addPass(gradePass);
199
+ composer.setSize(window.innerWidth, window.innerHeight);
200
+
201
+ buildLabels();
202
+ bindUI();
203
+ applyQuality(state.quality, true);
204
+ setWeather(state.weather, true);
205
+ onResize();
206
+ window.addEventListener('resize', onResize);
207
+
208
+ progress(1, '场景就绪');
209
+ await nextFrame();
210
+ $('#loader').classList.add('hidden');
211
+ setTimeout(() => { const l = $('#loader'); if (l) l.style.display = 'none'; }, 900);
212
+ state.started = true;
213
+ state.loadedAt = performance.now();
214
+ gpuTimer = initGpuTimer();
215
+ lod.update(0, true);
216
+
217
+ window.__garden = {
218
+ goToPOI, applyQuality, setWeather, setLodViz, state, camera, controls, renderer,
219
+ scene, sky, water, nature, lod, M, POIS, QUALITY, LOD_LEVELS,
220
+ setHour: h => { state.hour = h; sky.setHour(h); water.setSky(sky.getState()); $('#time-slider').value = h; $('#time-val').textContent = fmtHour(h); },
221
+ stats: buildStats,
222
+ };
223
+ clock.start();
224
+ requestAnimationFrame(loop);
225
+ const p = new URLSearchParams(location.search).get('poi');
226
+ if (p && POIS.some(v => v.id === p)) goToPOI(p, true);
227
+ toast('场景已就绪 · 拖拽旋转 / 滚轮缩放 / WASD 平移 / F 漫游 / 1–9 定点观察');
228
+ }
229
+
230
+ /* ================================================================== *
231
+ * 景点标注
232
+ * ================================================================== */
233
+ function buildLabels() {
234
+ const wrap = $('#labels');
235
+ wrap.innerHTML = '';
236
+ labelEls = HOTSPOTS.map(h => {
237
+ const el = document.createElement('div');
238
+ el.className = 'poi-label';
239
+ el.innerHTML = `<span class="dot"></span><span class="txt">${h.name}</span>`;
240
+ el.addEventListener('click', e => { e.stopPropagation(); showInfo(h.name, '', h.desc); });
241
+ wrap.appendChild(el);
242
+ return { el, data: h };
243
+ });
244
+ }
245
+ const projV = new THREE.Vector3();
246
+ function updateLabels() {
247
+ const wrap = $('#labels');
248
+ if (!state.labels) { wrap.style.display = 'none'; return; }
249
+ wrap.style.display = 'block';
250
+ const w = window.innerWidth, h = window.innerHeight;
251
+ labelEls.forEach(({ el, data }) => {
252
+ projV.set(...data.pos).project(camera);
253
+ const d = camera.position.distanceTo(new THREE.Vector3(...data.pos));
254
+ if (projV.z > 1 || projV.z < -1 || d > 180 || Math.abs(projV.x) > 1.05 || Math.abs(projV.y) > 1.05) {
255
+ el.style.opacity = '0'; el.style.pointerEvents = 'none'; return;
256
+ }
257
+ el.style.transform = `translate(-50%, -50%) translate(${(projV.x * 0.5 + 0.5) * w}px, ${(-projV.y * 0.5 + 0.5) * h}px)`;
258
+ el.style.opacity = String(clamp((180 - d) / 90, 0.15, 0.95));
259
+ el.style.pointerEvents = 'auto';
260
+ });
261
+ }
262
+
263
+ /* ================================================================== *
264
+ * 定点观察视角
265
+ * ================================================================== */
266
+ function buildViewButtons() {
267
+ const grid = $('#view-grid');
268
+ grid.innerHTML = POIS.map((p, i) =>
269
+ `<button class="view-btn${i === 0 ? ' active' : ''}" data-poi="${p.id}" title="${p.dir}">${p.key} · ${p.name}</button>`
270
+ ).join('');
271
+ }
272
+ function goToPOI(id, instant) {
273
+ const p = POIS.find(v => v.id === id) || POIS[0];
274
+ state.poi = id;
275
+ $$('.view-btn').forEach(b => b.classList.toggle('active', b.dataset.poi === id));
276
+ if (state.walk) toggleWalk(false);
277
+ if (instant) {
278
+ camera.position.set(...p.pos);
279
+ controls.target.set(...p.target);
280
+ camera.fov = p.fov; camera.updateProjectionMatrix();
281
+ camera.lookAt(controls.target);
282
+ controls.update(); tween = null;
283
+ } else {
284
+ tween = {
285
+ t: 0, dur: 1.45,
286
+ fromPos: camera.position.clone(), toPos: new THREE.Vector3(...p.pos),
287
+ fromTarget: controls.target.clone(), toTarget: new THREE.Vector3(...p.target),
288
+ fromFov: camera.fov, toFov: p.fov,
289
+ };
290
+ }
291
+ showInfo(p.name, p.dir, p.desc, true);
292
+ lod && lod.update(0, true);
293
+ }
294
+ function updateTween(dt) {
295
+ if (!tween) return;
296
+ tween.t = Math.min(1, tween.t + dt / tween.dur);
297
+ const k = tween.t < 0.5 ? 4 * tween.t ** 3 : 1 - Math.pow(-2 * tween.t + 2, 3) / 2;
298
+ camera.position.lerpVectors(tween.fromPos, tween.toPos, k);
299
+ controls.target.lerpVectors(tween.fromTarget, tween.toTarget, k);
300
+ camera.fov = lerp(tween.fromFov, tween.toFov, k);
301
+ camera.updateProjectionMatrix();
302
+ camera.lookAt(controls.target);
303
+ if (tween.t >= 1) tween = null;
304
+ }
305
+
306
+ /* ================================================================== *
307
+ * 漫游
308
+ * ================================================================== */
309
+ function toggleWalk(on) {
310
+ const target = on === undefined ? !state.walk : on;
311
+ state.walk = target;
312
+ controls.enabled = !target;
313
+ $('#walk-btn').classList.toggle('active', target);
314
+ $('#walk-btn').textContent = target ? '退出漫游 [F]' : '自由漫游 [F]';
315
+ $('#walk-hint').classList.toggle('show', target);
316
+ if (target) {
317
+ const dir = new THREE.Vector3().subVectors(controls.target, camera.position).normalize();
318
+ walkState.yaw = Math.atan2(dir.x, -dir.z);
319
+ walkState.pitch = Math.asin(clamp(dir.y, -1, 1));
320
+ walkState.locked = false;
321
+ toast('第一人称漫游:点击画面锁定鼠标,WASD 移动,Shift 加速,Q/E 调整视高');
322
+ } else {
323
+ if (document.pointerLockElement) document.exitPointerLock();
324
+ controls.target.copy(camera.position).add(new THREE.Vector3(
325
+ Math.sin(walkState.yaw), Math.tan(walkState.pitch) * 0.4, -Math.cos(walkState.yaw)).multiplyScalar(12));
326
+ controls.update();
327
+ }
328
+ }
329
+ function updateWalk(dt) {
330
+ if (!state.walk) return;
331
+ const speed = (keys.has('ShiftLeft') || keys.has('ShiftRight')) ? 15 : 6.0;
332
+ const f = (keys.has('KeyW') ? 1 : 0) - (keys.has('KeyS') ? 1 : 0);
333
+ const s = (keys.has('KeyD') ? 1 : 0) - (keys.has('KeyA') ? 1 : 0);
334
+ const fx = Math.sin(walkState.yaw), fz = -Math.cos(walkState.yaw);
335
+ const rx = Math.cos(walkState.yaw), rz = Math.sin(walkState.yaw);
336
+ const tx = fx * f + rx * s, tz = fz * f + rz * s;
337
+ const l = Math.hypot(tx, tz) || 1;
338
+ const mag = Math.min(1, Math.hypot(f, s));
339
+ walkState.vx = lerp(walkState.vx, tx / l * speed * mag, 1 - Math.exp(-dt * 9));
340
+ walkState.vz = lerp(walkState.vz, tz / l * speed * mag, 1 - Math.exp(-dt * 9));
341
+ camera.position.x = clamp(camera.position.x + walkState.vx * dt, WORLD.bounds.minX, WORLD.bounds.maxX);
342
+ camera.position.z = clamp(camera.position.z + walkState.vz * dt, WORLD.bounds.minZ, WORLD.bounds.maxZ);
343
+ if (keys.has('KeyQ')) walkState.eye = clamp(walkState.eye - dt * 4, 0.9, 14);
344
+ if (keys.has('KeyE')) walkState.eye = clamp(walkState.eye + dt * 4, 0.9, 14);
345
+ // 水面区域按贴水石桥/平台处理,避免沉入池底
346
+ const ground = waterSDF(camera.position.x, camera.position.z) < 0
347
+ ? WORLD.waterY + 0.12 : terrainHeight(camera.position.x, camera.position.z);
348
+ camera.position.y = lerp(camera.position.y, ground + walkState.eye, 1 - Math.exp(-dt * 10));
349
+ const cp = Math.cos(walkState.pitch);
350
+ const dir = new THREE.Vector3(Math.sin(walkState.yaw) * cp, Math.sin(walkState.pitch), -Math.cos(walkState.yaw) * cp);
351
+ camera.lookAt(camera.position.clone().add(dir));
352
+ }
353
+ function panOrbit(dt) {
354
+ if (state.walk || tween) return;
355
+ const f = (keys.has('KeyW') ? 1 : 0) - (keys.has('KeyS') ? 1 : 0);
356
+ const s = (keys.has('KeyD') ? 1 : 0) - (keys.has('KeyA') ? 1 : 0);
357
+ if (!f && !s) return;
358
+ const d = new THREE.Vector3().subVectors(controls.target, camera.position).normalize();
359
+ d.y = 0; d.normalize();
360
+ const right = new THREE.Vector3(-d.z, 0, d.x);
361
+ const v = d.multiplyScalar(f).add(right.multiplyScalar(s)).multiplyScalar(dt * 22);
362
+ camera.position.add(v); controls.target.add(v);
363
+ controls.target.x = clamp(controls.target.x, WORLD.bounds.minX, WORLD.bounds.maxX);
364
+ controls.target.z = clamp(controls.target.z, WORLD.bounds.minZ, WORLD.bounds.maxZ);
365
+ }
366
+
367
+ /* ================================================================== *
368
+ * 画质 / 天气 / LOD 可视化
369
+ * ================================================================== */
370
+ function applyQuality(name, silent) {
371
+ state.quality = name;
372
+ const q = QUALITY[name];
373
+ const pr = Math.min(window.devicePixelRatio || 1, q.dpr);
374
+ renderer.setPixelRatio(pr);
375
+ composer && composer.setPixelRatio(pr);
376
+ sky.setQuality(q);
377
+ nature && nature.applyQuality(q);
378
+ lod && lod.setQuality(q);
379
+ if (bloomPass) bloomPass.enabled = q.bloom;
380
+ if (gradePass) gradePass.enabled = q.grade;
381
+ $$('.q-btn').forEach(b => b.classList.toggle('active', b.dataset.quality === name));
382
+ $('#quality-val').textContent = q.label;
383
+ onResize();
384
+ if (!silent) toast(`画质「${q.label}」· 阴影 ${q.shadow}² · 像素比 ${pr.toFixed(1)} · LOD 距离 ×${q.lodScale}`);
385
+ }
386
+ function setWeather(w, silent) {
387
+ state.weather = w;
388
+ sky.setWeather(w);
389
+ water.setSky(sky.getState());
390
+ nature.setWeather(w, sky.getState());
391
+ $$('.w-btn').forEach(b => b.classList.toggle('active', b.dataset.weather === w));
392
+ $('#weather-val').textContent = { clear: '晴', mist: '薄霭', rain: '细雨' }[w];
393
+ if (!silent) toast(`天气切换为「${{ clear: '晴', mist: '薄霭', rain: '细雨' }[w]}」· 云量、雾密度与湿表面已联动`);
394
+ }
395
+ function setLodViz(on) {
396
+ state.lodViz = on;
397
+ lod.setVisualize(on);
398
+ $('#lod-btn').classList.toggle('active', on);
399
+ $('#lod-legend').classList.toggle('show', on);
400
+ }
401
+
402
+ /* ================================================================== *
403
+ * UI
404
+ * ================================================================== */
405
+ function toast(msg) {
406
+ const el = $('#toast');
407
+ el.textContent = msg; el.classList.add('show');
408
+ clearTimeout(toastTimer);
409
+ toastTimer = setTimeout(() => el.classList.remove('show'), 3600);
410
+ }
411
+ function showInfo(title, dir, desc, quiet) {
412
+ $('#info-title').textContent = title;
413
+ $('#info-dir').textContent = dir || '';
414
+ $('#info-dir').style.display = dir ? 'block' : 'none';
415
+ $('#info-desc').textContent = desc || '';
416
+ $('#info-card').classList.add('show');
417
+ if (!quiet) $('#info-card').scrollTop = 0;
418
+ }
419
+ function bindUI() {
420
+ buildViewButtons();
421
+ $$('.view-btn').forEach(b => b.addEventListener('click', () => goToPOI(b.dataset.poi)));
422
+ $$('.q-btn').forEach(b => b.addEventListener('click', () => applyQuality(b.dataset.quality)));
423
+ $$('.w-btn').forEach(b => b.addEventListener('click', () => setWeather(b.dataset.weather)));
424
+ $('#time-slider').addEventListener('input', e => {
425
+ state.hour = parseFloat(e.target.value);
426
+ sky.setHour(state.hour);
427
+ water.setSky(sky.getState());
428
+ $('#time-val').textContent = fmtHour(state.hour);
429
+ });
430
+ $('#walk-btn').addEventListener('click', () => toggleWalk());
431
+ $('#lod-btn').addEventListener('click', () => setLodViz(!state.lodViz));
432
+ $('#labels-toggle').addEventListener('click', () => {
433
+ state.labels = !state.labels;
434
+ $('#labels-toggle').classList.toggle('active', state.labels);
435
+ $('#labels-toggle').textContent = state.labels ? '景点标注' : '标注已关';
436
+ });
437
+ $('#auto-toggle').addEventListener('click', () => {
438
+ state.auto = !state.auto;
439
+ $('#auto-toggle').classList.toggle('active', state.auto);
440
+ });
441
+ $('#info-close').addEventListener('click', () => $('#info-card').classList.remove('show'));
442
+ $('#help-btn').addEventListener('click', () => $('#spec-modal').classList.add('show'));
443
+ $('#spec-close').addEventListener('click', () => $('#spec-modal').classList.remove('show'));
444
+ $('#spec-modal').addEventListener('click', e => { if (e.target.id === 'spec-modal') e.currentTarget.classList.remove('show'); });
445
+ $('#reset-btn').addEventListener('click', () => goToPOI('overview'));
446
+ $$('.fold-head').forEach(h => h.addEventListener('click', () => h.parentElement.classList.toggle('folded')));
447
+
448
+ const keyMap = {};
449
+ POIS.forEach(p => { keyMap[p.key] = p.id; });
450
+ window.addEventListener('keydown', e => {
451
+ if (e.target.tagName === 'INPUT') return;
452
+ keys.add(e.code);
453
+ if (e.code === 'KeyF') toggleWalk();
454
+ if (e.code === 'KeyG') setLodViz(!state.lodViz);
455
+ if (e.code === 'KeyL') $('#labels-toggle').click();
456
+ if (e.code === 'KeyH') $('#help-btn').click();
457
+ if (e.code === 'Escape') $('#spec-modal').classList.remove('show');
458
+ const k = e.key;
459
+ if (keyMap[k]) goToPOI(keyMap[k]);
460
+ });
461
+ window.addEventListener('keyup', e => keys.delete(e.code));
462
+ window.addEventListener('blur', () => keys.clear());
463
+ renderer.domElement.addEventListener('click', () => {
464
+ if (state.walk && !walkState.locked && document.pointerLockElement !== renderer.domElement)
465
+ renderer.domElement.requestPointerLock?.();
466
+ });
467
+ document.addEventListener('pointerlockchange', () => {
468
+ walkState.locked = document.pointerLockElement === renderer.domElement;
469
+ });
470
+ document.addEventListener('mousemove', e => {
471
+ if (!state.walk || !walkState.locked) return;
472
+ walkState.yaw -= e.movementX * 0.0022;
473
+ walkState.pitch = clamp(walkState.pitch - e.movementY * 0.0022, -1.35, 1.35);
474
+ });
475
+ }
476
+ const fmtHour = h => `${String(Math.floor(h)).padStart(2, '0')}:${String(Math.round((h % 1) * 60)).padStart(2, '0')}`;
477
+
478
+ /* ================================================================== *
479
+ * 小地图
480
+ * ================================================================== */
481
+ const mini = { ctx: null };
482
+ function drawMinimap() {
483
+ if (!mini.ctx) mini.ctx = $('#minimap').getContext('2d');
484
+ const c = mini.ctx, W = 212, H = 168;
485
+ const mx = x => (x - WORLD.garden.minX - 20) / (WORLD.garden.maxX - WORLD.garden.minX + 40) * W;
486
+ const mz = z => (z - WORLD.garden.minZ - 20) / (WORLD.garden.maxZ - WORLD.garden.minZ + 40) * H;
487
+ c.clearRect(0, 0, W, H);
488
+ c.fillStyle = '#1c2a24'; c.fillRect(0, 0, W, H);
489
+ // 水系
490
+ c.fillStyle = '#2e5559';
491
+ const pools = [[0, -12, 62, 35], [-52, 6, 22, 20], [46, 8, 21, 16], [16, -42, 27, 14], [-28, -46, 19, 12]];
492
+ pools.forEach(([x, z, rx, rz]) => {
493
+ c.beginPath(); c.ellipse(mx(x), mz(z), rx / 260 * W, rz / 230 * H, 0, 0, Math.PI * 2); c.fill();
494
+ });
495
+ // 园墙
496
+ c.strokeStyle = 'rgba(226,216,190,.72)'; c.lineWidth = 1.6;
497
+ c.strokeRect(mx(-110), mz(-95), mx(110) - mx(-110), mz(95) - mz(-95));
498
+ // 中轴
499
+ c.strokeStyle = 'rgba(217,185,121,.55)'; c.lineWidth = 1;
500
+ c.setLineDash([4, 3]);
501
+ c.beginPath(); c.moveTo(mx(0), mz(95)); c.lineTo(mx(0), mz(22)); c.stroke();
502
+ c.setLineDash([]);
503
+ // 三岛
504
+ c.fillStyle = '#6c7a4c';
505
+ [[-8, -12, 11, 8], [-34, -24, 7, 5], [28, -18, 7, 5]].forEach(([x, z, rx, rz]) => {
506
+ c.beginPath(); c.ellipse(mx(x), mz(z), rx / 260 * W, rz / 230 * H, 0, 0, Math.PI * 2); c.fill();
507
+ });
508
+ // 主要建筑
509
+ const bl = [
510
+ [0, 92, 14, 4, '宫门'], [0, 80, 20, 8, '轿厅'], [0, 58, 28, 12, '澄观堂'],
511
+ [0, 30, 24, 10, '远香堂'], [-30, 18, 11, 6, '涵碧榭'], [20, -60, 18, 10, '见山楼'],
512
+ [-8, -12, 7, 7, '雪香云蔚'], [44, 6, 7, 7, '荷风四面'], [-82, 34, 6, 6, '竹里馆'],
513
+ [68, -54, 6, 6, '丛桂'], [-64, -40, 20, 18, '云根叠翠'], [38, -34, 18, 5, '不系舟'],
514
+ ];
515
+ c.font = '8px system-ui, sans-serif'; c.textAlign = 'center';
516
+ bl.forEach(([x, z, w, d, n]) => {
517
+ const px = mx(x - w / 2), py = mz(z - d / 2);
518
+ const pw = w / 260 * W, ph = d / 230 * H;
519
+ c.fillStyle = 'rgba(214,196,156,.80)'; c.fillRect(px, py, pw, ph);
520
+ c.fillStyle = '#f0e6cc'; c.fillText(n, px + pw / 2, py + ph / 2 + 3);
521
+ });
522
+ // 借景塔方向
523
+ c.strokeStyle = 'rgba(135,169,154,.5)'; c.setLineDash([3, 3]);
524
+ c.beginPath(); c.moveTo(mx(44), mz(6)); c.lineTo(mx(-96), mz(-90)); c.stroke();
525
+ c.setLineDash([]);
526
+ c.fillStyle = '#87a99a'; c.fillText('借景 · 北寺塔', mx(-70), mz(-84));
527
+ // 相机
528
+ const dir = new THREE.Vector3().subVectors(controls.target, camera.position);
529
+ const a = Math.atan2(dir.x, -dir.z);
530
+ const cx = mx(camera.position.x), cy = mz(camera.position.z);
531
+ c.save(); c.translate(cx, cy); c.rotate(a);
532
+ c.fillStyle = '#ffcf7a'; c.beginPath(); c.moveTo(0, -8); c.lineTo(5, 6); c.lineTo(-5, 6); c.closePath(); c.fill();
533
+ c.restore();
534
+ c.strokeStyle = 'rgba(255,207,122,.45)'; c.beginPath(); c.arc(cx, cy, 10, 0, Math.PI * 2); c.stroke();
535
+ c.fillStyle = '#9aa894'; c.textAlign = 'left'; c.font = '9px system-ui';
536
+ c.fillText('N ↑', 6, 13); c.fillText('220m × 190m · 4.18ha', 6, H - 7);
537
+ }
538
+
539
+ /* ================================================================== *
540
+ * 性能 HUD 与自适应降级
541
+ * ================================================================== */
542
+ function initGpuTimer() {
543
+ const gl = renderer.getContext();
544
+ const ext = gl.getExtension('EXT_disjoint_timer_query_webgl2');
545
+ if (!ext) return null;
546
+ return { gl, ext, query: null, lastMs: 0 };
547
+ }
548
+ function gpuBegin() {
549
+ if (!gpuTimer || gpuTimer.query) return;
550
+ const q = gpuTimer.gl.createQuery();
551
+ gpuTimer.gl.beginQuery(gpuTimer.ext.TIME_ELAPSED_EXT, q);
552
+ gpuTimer.query = q;
553
+ }
554
+ function gpuEnd() { if (gpuTimer && gpuTimer.query) gpuTimer.gl.endQuery(gpuTimer.ext.TIME_ELAPSED_EXT); }
555
+ function gpuPoll() {
556
+ if (!gpuTimer || !gpuTimer.query) return;
557
+ const { gl, ext, query } = gpuTimer;
558
+ if (!gl.getQueryParameter(query, gl.QUERY_RESULT_AVAILABLE)) return;
559
+ if (!gl.getParameter(ext.GPU_DISJOINT_EXT)) gpuTimer.lastMs = gl.getQueryParameter(query, gl.QUERY_RESULT) / 1e6;
560
+ gl.deleteQuery(query); gpuTimer.query = null;
561
+ }
562
+ let hudT = 0;
563
+ function updateHUD(dt) {
564
+ state.frames++; state.acc += dt; hudT += dt;
565
+ if (hudT < 0.35) return;
566
+ const fps = state.frames / state.acc;
567
+ state.fps = lerp(state.fps, fps, 0.5);
568
+ state.frames = 0; state.acc = 0; hudT = 0;
569
+ const frameMs = Math.max(1000 / Math.max(fps, 1), gpuTimer?.lastMs || 0);
570
+ const adaptFps = 1000 / Math.max(frameMs, 1);
571
+ $('#fps').textContent = Math.round(state.fps);
572
+ $('#fps').className = state.fps > 50 ? 'good' : state.fps > 32 ? 'mid' : 'bad';
573
+ $('#ms').textContent = frameMs.toFixed(1);
574
+ $('#calls').textContent = renderer.info.render.calls;
575
+ $('#tris').textContent = (renderer.info.render.triangles / 1000).toFixed(0) + 'k';
576
+ $('#lodinfo').textContent = lod.summary();
577
+ $('#campos').textContent = `${camera.position.x.toFixed(0)}, ${camera.position.y.toFixed(0)}, ${camera.position.z.toFixed(0)}`;
578
+
579
+ state.cooldown = Math.max(0, state.cooldown - 0.35);
580
+ if (!state.auto || state.cooldown > 0) return;
581
+ if (adaptFps < 38) { state.lowFor += 0.35; state.highFor = 0; }
582
+ else if (adaptFps > 56) { state.highFor += 0.35; state.lowFor = 0; }
583
+ else { state.lowFor *= 0.7; state.highFor *= 0.7; }
584
+ if (state.lowFor > 2.1) {
585
+ if (state.quality === 'high') applyQuality('medium');
586
+ else if (state.quality === 'medium') applyQuality('low');
587
+ state.lowFor = 0; state.cooldown = 6;
588
+ toast('检测到帧率偏低,已自动降低细节密度以保证漫游流畅');
589
+ } else if (state.highFor > 12 && state.quality === 'low') {
590
+ applyQuality('medium'); state.highFor = 0; state.cooldown = 10;
591
+ }
592
+ }
593
+
594
+ /* ================================================================== *
595
+ * 主循环
596
+ * ================================================================== */
597
+ function loop() {
598
+ requestAnimationFrame(loop);
599
+ const rawDt = clock.getDelta();
600
+ const dt = Math.min(rawDt, 0.1);
601
+ const realDt = Math.min(rawDt, 0.5);
602
+ const t = clock.elapsedTime;
603
+ renderer.info.reset();
604
+
605
+ if (tween) updateTween(realDt);
606
+ else if (!state.walk) { panOrbit(dt); controls.update(); }
607
+ updateWalk(dt);
608
+
609
+ sky.update(t, camera);
610
+ water.setTime(t);
611
+ water.setCamera(camera);
612
+ water.setSky(sky.getState());
613
+ nature.update(t, camera);
614
+ if (gradePass) gradePass.uniforms.uTime.value = t;
615
+ lod.update(dt);
616
+
617
+ labelT += realDt; if (labelT > 1 / 15) { labelT = 0; updateLabels(); }
618
+ mapT += realDt; if (mapT > 1 / 5) { mapT = 0; drawMinimap(); }
619
+
620
+ gpuBegin();
621
+ composer.render();
622
+ gpuEnd();
623
+ gpuPoll();
624
+ updateHUD(dt); // 在渲染之后读取 renderer.info,保证 draw call / 三角形为真实统计
625
+ }
626
+
627
+ function onResize() {
628
+ if (!renderer || !camera) return;
629
+ const w = window.innerWidth, h = window.innerHeight;
630
+ camera.aspect = w / h;
631
+ camera.updateProjectionMatrix();
632
+ renderer.setSize(w, h);
633
+ composer && composer.setSize(w, h);
634
+ gradePass && gradePass.uniforms.uResolution.value.set(w, h);
635
+ renderer.shadowMap.needsUpdate = true;
636
+ }
637
+
638
+ boot().catch(err => {
639
+ console.error('[场景启动失败]', err);
640
+ const l = $('#load-label');
641
+ if (l) l.textContent = '场景启动失败:' + (err && err.message ? err.message : err);
642
+ });