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,650 @@
1
+ /* 吴苑澄观 · 地形、园路、植被花木与远景借景
2
+ * 高度场地形(顶点色草土湿岸)、花街园路、松柳竹桂银杏玉兰梅枫芭蕉、
3
+ * 荷叶荷花芦苇书带草苔、远景林带与灵岩山山脊。植被全部 GPU Instancing。
4
+ */
5
+ import * as THREE from 'three';
6
+ import {
7
+ boxGeo, transform, tube, clamp, smooth, fbm, mulberry32, rr,
8
+ WORLD, QUALITY, waterSDF, terrainHeight, POOLS, ISLES,
9
+ } from './core.js';
10
+ import { put, addPavingPatch } from './arch.js';
11
+
12
+ /* 建筑占地避让(与 buildings.js 布点一致) */
13
+ const FOOTPRINTS = [
14
+ [0, 104, 34, 20], [0, 92, 18, 6], [0, 80, 23, 11], [0, 68, 32, 18],
15
+ [0, 58, 31, 15], [0, 46, 28, 12], [0, 30, 27, 13], [0, 22, 26, 7],
16
+ [-30, 18, 14, 9], [58, 26, 12, 9], [20, -60, 22, 14], [68, -54, 10, 10],
17
+ [-82, 34, 9, 9], [44, 6, 10, 10], [38, -34, 21, 7], [-64, -40, 34, 30],
18
+ [-48, 10, 18, 18], [-80, 44, 14, 5], [-84, 58, 8, 36], [-100, 48, 6, 40],
19
+ [44, 12, 22, 22], [0, -12, 26, 18], [-34, -24, 16, 13], [28, -18, 16, 13],
20
+ ];
21
+ function freeLand(x, z, pad = 1.2) {
22
+ if (Math.abs(x) > 106 || Math.abs(z) > 91) return false;
23
+ if (waterSDF(x, z) < pad) return false;
24
+ for (const [bx, bz, bw, bd] of FOOTPRINTS) {
25
+ if (Math.abs(x - bx) < bw / 2 + pad && Math.abs(z - bz) < bd / 2 + pad) return false;
26
+ }
27
+ return true;
28
+ }
29
+
30
+ /* ------------------------------------------------------------------ *
31
+ * 1. 地形(高度场 + 顶点色)
32
+ * ------------------------------------------------------------------ */
33
+ function buildTerrain(scene, M) {
34
+ const [W, D] = WORLD.ground;
35
+ const segX = 168, segZ = 148;
36
+ const geo = new THREE.PlaneGeometry(W, D, segX, segZ);
37
+ geo.rotateX(-Math.PI / 2);
38
+ const p = geo.getAttribute('position');
39
+ const colors = new Float32Array(p.count * 3);
40
+ const grass = new THREE.Color(0x6d7c4c), dry = new THREE.Color(0x9a9464);
41
+ const moss = new THREE.Color(0x4c6840), wet = new THREE.Color(0x5c6046);
42
+ const outer = new THREE.Color(0x71805a);
43
+ const c = new THREE.Color();
44
+ for (let i = 0; i < p.count; i++) {
45
+ const x = p.getX(i), z = p.getZ(i);
46
+ p.setY(i, terrainHeight(x, z));
47
+ const n = fbm(x * 0.02 + 5, z * 0.02 + 9, 61, 4);
48
+ const w = waterSDF(x, z);
49
+ c.copy(grass).lerp(dry, clamp((n - 0.42) * 1.5, 0, 0.55));
50
+ c.lerp(moss, smooth(0.58, 0.82, fbm(x * 0.05, z * 0.05, 73, 3)) * 0.45);
51
+ if (w < 2.6) c.lerp(wet, 1 - smooth(-0.4, 2.6, w));
52
+ // 西北叠石山地:混入石灰/苔色,避免大片土黄与湖石脱节
53
+ const rocky = Math.exp(-((x + 64) ** 2 / 1900 + (z + 40) ** 2 / 1500));
54
+ if (rocky > 0.02) c.lerp(new THREE.Color(0x7f8776), rocky * 0.62);
55
+ const inGarden = Math.abs(x) < 112 && Math.abs(z) < 97;
56
+ if (!inGarden) c.lerp(outer, 0.42);
57
+ const shade = 0.88 + n * 0.24;
58
+ colors[i * 3] = c.r * shade; colors[i * 3 + 1] = c.g * shade; colors[i * 3 + 2] = c.b * shade;
59
+ }
60
+ p.needsUpdate = true;
61
+ geo.setAttribute('color', new THREE.Float32BufferAttribute(colors, 3));
62
+ geo.computeVertexNormals();
63
+ const uv = geo.getAttribute('uv');
64
+ for (let i = 0; i < uv.count; i++) uv.setXY(i, uv.getX(i) * 26, uv.getY(i) * 23);
65
+ const mesh = new THREE.Mesh(geo, M.ground);
66
+ mesh.name = '地形';
67
+ mesh.receiveShadow = true;
68
+ mesh.castShadow = false;
69
+ scene.add(mesh);
70
+ return mesh;
71
+ }
72
+
73
+ /* ------------------------------------------------------------------ *
74
+ * 2. 园路网(花街铺地贴片)
75
+ * ------------------------------------------------------------------ */
76
+ function buildPathPatches(scene, M, BatchClass) {
77
+ const B = new BatchClass(40);
78
+ const paths = [
79
+ [[0, 94], [0, 84], [0, 74], [0, 64]], // 中轴
80
+ [[-18, 68], [-18, 46], [-18, 38], [-16, 30]], // 西侧游廊路
81
+ [[18, 68], [18, 46], [18, 38], [16, 30]], // 东侧游廊路
82
+ [[-18, 46], [-40, 42], [-62, 44], [-80, 50], [-84, 64]], // 通往竹里馆
83
+ [[18, 46], [40, 42], [60, 38], [70, 30]], // 通往荷池
84
+ [[-56, 25], [-70, 22], [-84, 16], [-92, 6]], // 西岸
85
+ [[52, 21], [64, 20], [78, 16], [88, 6]], // 东岸
86
+ [[4, -50], [20, -50], [36, -50], [52, -56], [66, -60]], // 北岸
87
+ [[-30, -48], [-16, -50], [4, -50]], // 北岸西段
88
+ [[-70, -18], [-78, -30], [-86, -44], [-90, -62]], // 山后小径
89
+ ];
90
+ paths.forEach((pts, pi) => {
91
+ for (let i = 0; i < pts.length - 1; i++) {
92
+ const [x1, z1] = pts[i], [x2, z2] = pts[i + 1];
93
+ const len = Math.hypot(x2 - x1, z2 - z1);
94
+ const steps = Math.max(1, Math.round(len / 2.4));
95
+ for (let k = 0; k < steps; k++) {
96
+ const t = (k + 0.5) / steps;
97
+ const x = x1 + (x2 - x1) * t, z = z1 + (z2 - z1) * t;
98
+ if (waterSDF(x, z) < 0.5) continue;
99
+ const y = terrainHeight(x, z) + 0.055;
100
+ addPavingPatch(B, M, x, z, len / steps + 0.12, pi === 0 ? 4.2 : 2.4, y,
101
+ -Math.atan2(z2 - z1, x2 - x1), 0);
102
+ }
103
+ }
104
+ });
105
+ const g = new THREE.Group(); g.name = '花街园路'; scene.add(g);
106
+ B.build(g);
107
+ return g;
108
+ }
109
+
110
+ /* ------------------------------------------------------------------ *
111
+ * 3. 植被几何与实例收集器
112
+ * ------------------------------------------------------------------ */
113
+ function tuftGeo() {
114
+ const g = new THREE.IcosahedronGeometry(1, 1);
115
+ const p = g.getAttribute('position');
116
+ const rnd = mulberry32(8821);
117
+ for (let i = 0; i < p.count; i++) {
118
+ const k = 0.82 + rnd() * 0.34;
119
+ p.setXYZ(i, p.getX(i) * k, p.getY(i) * k * 0.86, p.getZ(i) * k);
120
+ }
121
+ p.needsUpdate = true; g.computeVertexNormals();
122
+ return g;
123
+ }
124
+ function bladeGeo() {
125
+ // 两片交叉草叶,带根深尖浅的顶点色
126
+ const pos = [], col = [], idx = [];
127
+ const add = (x0, z0, ang) => {
128
+ const ca = Math.cos(ang), sa = Math.sin(ang);
129
+ const b = pos.length / 3;
130
+ const w = 0.075, h = 0.62;
131
+ pos.push(-w * ca, 0, -w * sa, w * ca, 0, w * sa, -w * 0.30 * ca, h, -w * 0.30 * sa,
132
+ w * 0.30 * ca, h, w * 0.30 * sa);
133
+ col.push(0.24, 0.34, 0.16, 0.24, 0.34, 0.16, 0.52, 0.66, 0.30, 0.52, 0.66, 0.30);
134
+ idx.push(b, b + 1, b + 2, b + 1, b + 3, b + 2);
135
+ };
136
+ add(0, 0, 0); add(0, 0, Math.PI / 2);
137
+ const g = new THREE.BufferGeometry();
138
+ g.setAttribute('position', new THREE.Float32BufferAttribute(pos, 3));
139
+ g.setAttribute('color', new THREE.Float32BufferAttribute(col, 3));
140
+ g.setIndex(idx); g.computeVertexNormals();
141
+ return g;
142
+ }
143
+ function lotusLeafGeo() {
144
+ const N = 20, pos = [0, 0.02, 0], col = [0.30, 0.52, 0.24], idx = [];
145
+ for (let i = 0; i <= N; i++) {
146
+ const a = i * Math.PI * 2 / N;
147
+ const notch = (i === 0 || i === N) ? 0.18 : 1;
148
+ const r = (0.46 + Math.sin(a * 5) * 0.012) * notch;
149
+ pos.push(Math.cos(a) * r, 0.035 + Math.sin(a * 7) * 0.012, Math.sin(a) * r);
150
+ col.push(0.30 + (i % 3) * 0.02, 0.50 + (i % 4) * 0.018, 0.24);
151
+ }
152
+ for (let i = 1; i <= N; i++) idx.push(0, i, i + 1);
153
+ const g = new THREE.BufferGeometry();
154
+ g.setAttribute('position', new THREE.Float32BufferAttribute(pos, 3));
155
+ g.setAttribute('color', new THREE.Float32BufferAttribute(col, 3));
156
+ g.setIndex(idx); g.computeVertexNormals();
157
+ return g;
158
+ }
159
+ function petalGeo() {
160
+ const s = new THREE.Shape();
161
+ s.moveTo(0, 0);
162
+ s.bezierCurveTo(0.14, 0.12, 0.16, 0.34, 0, 0.46);
163
+ s.bezierCurveTo(-0.16, 0.34, -0.14, 0.12, 0, 0);
164
+ const g = new THREE.ExtrudeGeometry(s, { depth: 0.012, bevelEnabled: false, curveSegments: 5 });
165
+ g.rotateX(-Math.PI / 2 + 0.42);
166
+ return g;
167
+ }
168
+
169
+ const GRASS_VERT = `
170
+ uniform vec3 uCam; uniform float uTime; uniform float uNear; uniform float uFar;
171
+ attribute vec3 color;
172
+ varying vec3 vCol; varying float vFog;
173
+ void main(){
174
+ vec4 base = modelMatrix * instanceMatrix * vec4(0.0, 0.0, 0.0, 1.0);
175
+ float d = distance(uCam, base.xyz);
176
+ float k = 1.0 - smoothstep(uNear, uFar, d);
177
+ vec3 p = position * k;
178
+ p.x += sin(uTime * 1.3 + base.x * 0.35 + base.z * 0.2) * 0.07 * p.y;
179
+ vec4 wp = modelMatrix * instanceMatrix * vec4(p, 1.0);
180
+ vCol = color;
181
+ vFog = clamp(1.0 - exp(-0.0020 * d), 0.0, 1.0);
182
+ gl_Position = projectionMatrix * viewMatrix * wp;
183
+ }`;
184
+ const GRASS_FRAG = `
185
+ precision highp float;
186
+ uniform vec3 uFogColor; uniform float uWet;
187
+ varying vec3 vCol; varying float vFog;
188
+ void main(){
189
+ vec3 c = vCol * mix(1.0, 0.72, uWet);
190
+ c = mix(c, uFogColor, vFog * 0.85);
191
+ gl_FragColor = vec4(c, 1.0);
192
+ }`;
193
+
194
+ class InstCollector {
195
+ constructor(geo, mat, name) { this.geo = geo; this.mat = mat; this.name = name; this.list = []; }
196
+ add(pos, rot, scale, color) {
197
+ this.list.push({ pos, rot, scale, color });
198
+ }
199
+ build(scene, opts = {}) {
200
+ if (!this.list.length) return null;
201
+ const im = new THREE.InstancedMesh(this.geo, this.mat, this.list.length);
202
+ im.name = this.name;
203
+ im.castShadow = !!opts.castShadow;
204
+ im.receiveShadow = !!opts.receiveShadow;
205
+ im.frustumCulled = !!opts.frustumCulled;
206
+ const m = new THREE.Matrix4(), q = new THREE.Quaternion(), e = new THREE.Euler();
207
+ const c = new THREE.Color();
208
+ this.list.forEach((it, i) => {
209
+ e.set(it.rot[0], it.rot[1], it.rot[2]);
210
+ q.setFromEuler(e);
211
+ m.compose(new THREE.Vector3(...it.pos), q, new THREE.Vector3(...it.scale));
212
+ im.setMatrixAt(i, m);
213
+ if (it.color !== undefined) im.setColorAt(i, c.set(it.color));
214
+ });
215
+ im.instanceMatrix.needsUpdate = true;
216
+ if (im.instanceColor) im.instanceColor.needsUpdate = true;
217
+ scene.add(im);
218
+ return im;
219
+ }
220
+ }
221
+
222
+ /* ------------------------------------------------------------------ *
223
+ * 4. 树木:主干(合批)+ 叶簇(Instancing)
224
+ * ------------------------------------------------------------------ */
225
+ const SPECIES = {
226
+ pine: { leaf: 0x35543a, scale: [1.0, 0.42, 1.0], clusters: 5, trunk: 0x4a3a2a, h: 7.5 },
227
+ willow: { leaf: 0x7c9a52, scale: [0.62, 0.36, 0.62], clusters: 9, trunk: 0x5a4a34, h: 8.5 },
228
+ osmanthus: { leaf: 0x456b3c, scale: [1.0, 0.78, 1.0], clusters: 8, trunk: 0x55452f, h: 6.2 },
229
+ gingko: { leaf: 0x9aa548, scale: [0.85, 1.10, 0.85], clusters: 7, trunk: 0x615540, h: 9.0 },
230
+ magnolia: { leaf: 0x548044, scale: [0.85, 0.95, 0.85], clusters: 7, trunk: 0x5b4c38, h: 7.0 },
231
+ plum: { leaf: 0x6b7a48, scale: [0.72, 0.60, 0.72], clusters: 6, trunk: 0x41372c, h: 5.2 },
232
+ maple: { leaf: 0x9b5138, scale: [0.92, 0.84, 0.92], clusters: 7, trunk: 0x4d4030, h: 6.4 },
233
+ peach: { leaf: 0xc48a92, scale: [0.80, 0.66, 0.80], clusters: 7, trunk: 0x55402f, h: 5.4 },
234
+ };
235
+ function addTree(ctx, sp, x, z, s, seed, collectors, trunkBatch, M) {
236
+ const cfg = SPECIES[sp];
237
+ const rnd = mulberry32(seed);
238
+ const y = terrainHeight(x, z);
239
+ const H = cfg.h * s;
240
+ const lean = (rnd() - 0.5) * 0.5;
241
+ // 主干:三段渐细圆柱
242
+ const seg = 3;
243
+ for (let i = 0; i < seg; i++) {
244
+ const t0 = i / seg, t1 = (i + 1) / seg;
245
+ const r0 = 0.30 * s * (1 - t0 * 0.55), r1 = 0.30 * s * (1 - t1 * 0.55);
246
+ const g = new THREE.CylinderGeometry(r1, r0, H * (t1 - t0) + 0.06, 8);
247
+ put(trunkBatch, g, M.bark,
248
+ [x + lean * t0 * s, y + H * (t0 + t1) / 2, z + lean * t0 * s * 0.4],
249
+ [(rnd() - 0.5) * 0.06, rnd() * 6.28, lean * 0.35]);
250
+ }
251
+ // 分枝
252
+ for (let k = 0; k < 3; k++) {
253
+ const a = rnd() * Math.PI * 2;
254
+ const L = H * (0.22 + rnd() * 0.18);
255
+ const g = new THREE.CylinderGeometry(0.045 * s, 0.10 * s, L, 6);
256
+ put(trunkBatch, g, M.bark,
257
+ [x + Math.cos(a) * L * 0.35, y + H * (0.58 + k * 0.10), z + Math.sin(a) * L * 0.35],
258
+ [Math.sin(a) * 0.7, 0, -Math.cos(a) * 0.7]);
259
+ }
260
+ // 叶簇
261
+ const leaf = collectors[sp];
262
+ const n = Math.round(cfg.clusters * (0.8 + rnd() * 0.5));
263
+ for (let i = 0; i < n; i++) {
264
+ const a = rnd() * Math.PI * 2;
265
+ const r = (sp === 'pine' || sp === 'willow' ? 1.0 : 0.75) * (0.35 + rnd() * 0.72) * H * 0.42;
266
+ const hy = sp === 'pine' ? H * (0.52 + (i % 3) * 0.16) : H * (0.62 + (rnd() - 0.5) * 0.42);
267
+ const sz = (0.62 + rnd() * 0.62) * s * (sp === 'pine' ? 1.45 : 1.0);
268
+ const col = new THREE.Color(cfg.leaf);
269
+ col.offsetHSL((rnd() - 0.5) * 0.035, (rnd() - 0.5) * 0.10, (rnd() - 0.5) * 0.12);
270
+ leaf.add([x + Math.cos(a) * r + lean * s, y + hy, z + Math.sin(a) * r],
271
+ [rnd() * 0.4, rnd() * 6.28, rnd() * 0.4],
272
+ [cfg.scale[0] * sz, cfg.scale[1] * sz, cfg.scale[2] * sz], col);
273
+ if (sp === 'willow') {
274
+ // 下垂柳条
275
+ for (let k = 0; k < 3; k++) {
276
+ const t = (k + 1) / 4;
277
+ leaf.add([x + Math.cos(a) * r * 1.15, y + hy - t * H * 0.40, z + Math.sin(a) * r * 1.15],
278
+ [0, rnd() * 6.28, 0], [0.22 * s, (0.42 + rnd() * 0.3) * s, 0.22 * s], col);
279
+ }
280
+ }
281
+ }
282
+ // 玉兰 / 梅 / 桃花:点缀花簇
283
+ if (sp === 'magnolia' || sp === 'plum' || sp === 'peach') {
284
+ const flower = collectors.flower;
285
+ const fc = sp === 'magnolia' ? 0xf3ece0 : sp === 'plum' ? 0xe9c9cf : 0xe8a3ab;
286
+ for (let i = 0; i < 9; i++) {
287
+ const a = rnd() * Math.PI * 2, r = rnd() * H * 0.32;
288
+ flower.add([x + Math.cos(a) * r, y + H * (0.60 + rnd() * 0.34), z + Math.sin(a) * r],
289
+ [0, rnd() * 6.28, 0], [0.16 * s, 0.16 * s, 0.16 * s], new THREE.Color(fc));
290
+ }
291
+ }
292
+ return { x, z, y, H };
293
+ }
294
+
295
+ /* ------------------------------------------------------------------ *
296
+ * 5. 竹、芭蕉、荷、芦苇、草、苔
297
+ * ------------------------------------------------------------------ */
298
+ function buildBamboo(scene, M, ctx, collectors, count) {
299
+ const rnd = mulberry32(3301);
300
+ const cane = collectors.bambooCane, leaf = collectors.bambooLeaf;
301
+ const regions = [
302
+ { x: -84, z: 40, rx: 14, rz: 24, n: Math.round(count * 0.36) },
303
+ { x: -94, z: -8, rx: 12, rz: 22, n: Math.round(count * 0.20) },
304
+ { x: 76, z: -66, rx: 16, rz: 16, n: Math.round(count * 0.16) },
305
+ { x: -34, z: -24, rx: 6, rz: 5, n: Math.round(count * 0.10) }, // 方丈岛
306
+ { x: 42, z: -62, rx: 14, rz: 10, n: Math.round(count * 0.18) },
307
+ ];
308
+ regions.forEach(rg => {
309
+ for (let i = 0; i < rg.n; i++) {
310
+ let x = rg.x + (rnd() - 0.5) * rg.rx * 2, z = rg.z + (rnd() - 0.5) * rg.rz * 2;
311
+ if (waterSDF(x, z) < 0.1) continue;
312
+ // 月洞门 → 假山主峰的框景视线通廊:把竹子推到通廊两侧,避免竹竿贴脸遮挡画面
313
+ if (Math.abs(x + 79) < 9 && z > 14 && z < 62) x += (x > -79 ? 11 : -11) + (rnd() - 0.5) * 2;
314
+ if (waterSDF(x, z) < 0.1) continue;
315
+ for (const [bx, bz, bw, bd] of FOOTPRINTS) {
316
+ if (Math.abs(x - bx) < bw / 2 && Math.abs(z - bz) < bd / 2) { x += 3; break; }
317
+ }
318
+ const y = terrainHeight(x, z);
319
+ const h = 4.4 + rnd() * 3.8;
320
+ cane.add([x, y + h / 2, z], [(rnd() - 0.5) * 0.06, rnd() * 6.28, (rnd() - 0.5) * 0.06],
321
+ [1, h / 6, 1], new THREE.Color().setHSL(0.24 + rnd() * 0.05, 0.30, 0.34 + rnd() * 0.14));
322
+ for (let k = 0; k < 5; k++) {
323
+ const a = rnd() * Math.PI * 2;
324
+ leaf.add([x + Math.cos(a) * (0.5 + rnd()), y + h * (0.62 + k * 0.075), z + Math.sin(a) * (0.5 + rnd())],
325
+ [rnd() * 0.5, rnd() * 6.28, rnd() * 0.4],
326
+ [0.55 + rnd() * 0.35, 0.12, 0.55 + rnd() * 0.35],
327
+ new THREE.Color().setHSL(0.25 + rnd() * 0.06, 0.34, 0.30 + rnd() * 0.16));
328
+ }
329
+ }
330
+ });
331
+ }
332
+ function buildBanana(scene, M, ctx, BatchClass) {
333
+ const B = new BatchClass(40);
334
+ const rnd = mulberry32(4411);
335
+ const leafMat = new THREE.MeshStandardMaterial({ color: 0x67924a, roughness: 0.88, side: THREE.DoubleSide });
336
+ leafMat.name = 'bananaLeaf';
337
+ const spots = [[-93, 36], [-95, 28], [-88, 20], [-68, 54], [62, 20], [70, 14], [26, 40], [-26, 40], [80, -32]];
338
+ spots.forEach(([x, z], i) => {
339
+ const y = terrainHeight(x, z);
340
+ put(B, new THREE.CylinderGeometry(0.10, 0.16, 1.5, 7), M.bark, [x, y + 0.75, z]);
341
+ for (let k = 0; k < 6; k++) {
342
+ const a = k * Math.PI / 3 + rnd() * 0.4;
343
+ const len = 1.5 + rnd() * 0.9;
344
+ const shape = new THREE.Shape();
345
+ shape.moveTo(0, 0);
346
+ shape.bezierCurveTo(0.26, len * 0.25, 0.30, len * 0.7, 0, len);
347
+ shape.bezierCurveTo(-0.30, len * 0.7, -0.26, len * 0.25, 0, 0);
348
+ const g = new THREE.ExtrudeGeometry(shape, { depth: 0.02, bevelEnabled: false, curveSegments: 5 });
349
+ g.rotateX(-Math.PI / 2 + 0.55);
350
+ put(B, g, leafMat, [x, y + 1.45, z], [0, a, 0], 0, { noShadow: true });
351
+ }
352
+ });
353
+ const g = new THREE.Group(); g.name = '芭蕉'; scene.add(g); B.build(g);
354
+ return g;
355
+ }
356
+ function buildLotus(scene, collectors, quality) {
357
+ const rnd = mulberry32(5511);
358
+ const leaf = collectors.lotus, flower = collectors.lotusFlower, reed = collectors.reed;
359
+ const beds = [
360
+ { x: 46, z: 8, n: 260 }, { x: 12, z: 4, n: 180 }, { x: -20, z: 2, n: 170 },
361
+ { x: 34, z: -26, n: 140 }, { x: -46, z: -36, n: 120 }, { x: 8, z: -38, n: 110 },
362
+ ];
363
+ const total = Math.round(beds.reduce((a, b) => a + b.n, 0) * (0.45 + quality.leaves * 0.55));
364
+ let made = 0;
365
+ beds.forEach(b => {
366
+ const n = Math.round(b.n * (0.45 + quality.leaves * 0.55));
367
+ for (let i = 0; i < n; i++) {
368
+ const a = rnd() * Math.PI * 2, r = Math.sqrt(rnd()) * 13;
369
+ const x = b.x + Math.cos(a) * r, z = b.z + Math.sin(a) * r;
370
+ if (waterSDF(x, z) > -0.35) continue;
371
+ const s = 0.55 + rnd() * 0.95;
372
+ const y = WORLD.waterY + 0.03 + rnd() * 0.06;
373
+ const col = new THREE.Color().setHSL(0.27 + rnd() * 0.05, 0.34, 0.30 + rnd() * 0.14);
374
+ leaf.add([x, y, z], [0, rnd() * 6.28, (rnd() - 0.5) * 0.10], [s, s, s], col);
375
+ if (rnd() < 0.14) {
376
+ flower.add([x, y + 0.16, z], [0, rnd() * 6.28, 0], [s * 0.8, s * 0.8, s * 0.8],
377
+ new THREE.Color(rnd() < 0.7 ? 0xf2d2d8 : 0xf6ece0));
378
+ }
379
+ made++;
380
+ }
381
+ });
382
+ // 芦苇与菖蒲(岸边)
383
+ for (let i = 0; i < 220; i++) {
384
+ const x = (rnd() - 0.5) * 180, z = (rnd() - 0.5) * 100;
385
+ const d = waterSDF(x, z);
386
+ if (d > -0.15 || d < -2.6) continue;
387
+ const s = 0.8 + rnd() * 1.2;
388
+ reed.add([x, WORLD.waterY + 0.4 * s, z], [0, rnd() * 6.28, 0], [s, s, s],
389
+ new THREE.Color().setHSL(0.19 + rnd() * 0.08, 0.30, 0.32 + rnd() * 0.16));
390
+ }
391
+ return made;
392
+ }
393
+ function buildGrass(scene, M, quality, fogColor) {
394
+ const rnd = mulberry32(6611);
395
+ const count = quality.grass;
396
+ const geo = bladeGeo();
397
+ const mat = new THREE.ShaderMaterial({
398
+ uniforms: {
399
+ uCam: { value: new THREE.Vector3() },
400
+ uTime: { value: 0 },
401
+ uNear: { value: 26 * quality.lodScale },
402
+ uFar: { value: 62 * quality.lodScale },
403
+ uFogColor: { value: fogColor.clone() },
404
+ uWet: { value: 0 },
405
+ },
406
+ vertexShader: GRASS_VERT, fragmentShader: GRASS_FRAG,
407
+ side: THREE.DoubleSide, vertexColors: false,
408
+ });
409
+ const im = new THREE.InstancedMesh(geo, mat, count);
410
+ im.name = '书带草';
411
+ im.frustumCulled = false;
412
+ const m = new THREE.Matrix4(), q = new THREE.Quaternion(), e = new THREE.Euler();
413
+ let used = 0;
414
+ for (let i = 0; i < count * 3 && used < count; i++) {
415
+ const x = (rnd() - 0.5) * 216, z = (rnd() - 0.5) * 186;
416
+ if (waterSDF(x, z) < 0.3) continue;
417
+ let blocked = false;
418
+ for (const [bx, bz, bw, bd] of FOOTPRINTS) {
419
+ if (Math.abs(x - bx) < bw / 2 + 0.4 && Math.abs(z - bz) < bd / 2 + 0.4) { blocked = true; break; }
420
+ }
421
+ if (blocked) continue;
422
+ const y = terrainHeight(x, z);
423
+ const s = 0.55 + rnd() * 1.15;
424
+ e.set(0, rnd() * 6.28, (rnd() - 0.5) * 0.2);
425
+ q.setFromEuler(e);
426
+ m.compose(new THREE.Vector3(x, y, z), q, new THREE.Vector3(s, s, s));
427
+ im.setMatrixAt(used, m);
428
+ used++;
429
+ }
430
+ im.count = used;
431
+ im.userData.maxCount = used;
432
+ im.instanceMatrix.needsUpdate = true;
433
+ scene.add(im);
434
+ return im;
435
+ }
436
+
437
+ /* ------------------------------------------------------------------ *
438
+ * 6. 远景林带与借景远山
439
+ * ------------------------------------------------------------------ */
440
+ function buildDistantForest(scene, M, quality) {
441
+ const rnd = mulberry32(7711);
442
+ // 低模树:不规则双团树冠 + 细干,合并为单几何(远景剪影比纯圆锥自然)
443
+ const parts = [];
444
+ const trunk = new THREE.CylinderGeometry(0.30, 0.52, 2.6, 5);
445
+ trunk.translate(0, 1.3, 0); parts.push(trunk);
446
+ const crown = new THREE.IcosahedronGeometry(1, 0);
447
+ crown.scale(2.05, 2.55, 1.95); crown.translate(0, 4.1, 0); parts.push(crown);
448
+ const crown2 = new THREE.IcosahedronGeometry(1, 0);
449
+ crown2.scale(1.30, 1.45, 1.28); crown2.translate(0.55, 5.9, -0.30); parts.push(crown2);
450
+ // 简易合并(都用同样属性)
451
+ const pos = [], nrm = [], uv = [], idx = [];
452
+ parts.forEach(p => {
453
+ const g = p.index ? p.toNonIndexed() : p;
454
+ const pp = g.getAttribute('position'), nn = g.getAttribute('normal'), uu = g.getAttribute('uv');
455
+ const off = pos.length / 3;
456
+ for (let i = 0; i < pp.count; i++) {
457
+ pos.push(pp.getX(i), pp.getY(i), pp.getZ(i));
458
+ nrm.push(nn.getX(i), nn.getY(i), nn.getZ(i));
459
+ uv.push(uu ? uu.getX(i) : 0, uu ? uu.getY(i) : 0);
460
+ idx.push(off + i);
461
+ }
462
+ if (g !== p) g.dispose();
463
+ });
464
+ const geo = new THREE.BufferGeometry();
465
+ geo.setAttribute('position', new THREE.Float32BufferAttribute(pos, 3));
466
+ geo.setAttribute('normal', new THREE.Float32BufferAttribute(nrm, 3));
467
+ geo.setAttribute('uv', new THREE.Float32BufferAttribute(uv, 2));
468
+ geo.setIndex(idx);
469
+ const mat = new THREE.MeshLambertMaterial({ color: 0x72836a });
470
+ const n = Math.round(640 * quality.trees);
471
+ const im = new THREE.InstancedMesh(geo, mat, n);
472
+ im.name = '远景林带(L3 低模)';
473
+ im.frustumCulled = false;
474
+ const m = new THREE.Matrix4(), q = new THREE.Quaternion(), e = new THREE.Euler();
475
+ const c = new THREE.Color();
476
+ for (let i = 0; i < n; i++) {
477
+ const a = rnd() * Math.PI * 2;
478
+ const r = 145 + rnd() * 105; // 全部落在 640×560 地形范围内
479
+ let x = Math.cos(a) * r, z = Math.sin(a) * r * 0.92;
480
+ // 北寺塔方向留出视线通廊:把树推离视廊而不是跳过(避免留下单位矩阵实例)
481
+ if (x < -120 && z < -120 && Math.abs(x - z * 0.78) < 55) x -= 95;
482
+ const y = terrainHeight(x, z);
483
+ const s = 0.70 + rnd() * 0.85;
484
+ e.set(0, rnd() * 6.28, 0); q.setFromEuler(e);
485
+ m.compose(new THREE.Vector3(x, y - 0.4, z), q, new THREE.Vector3(s, s * (0.82 + rnd() * 0.5), s));
486
+ im.setMatrixAt(i, m);
487
+ // 低饱和灰绿,随大气雾自然消隐
488
+ im.setColorAt(i, c.setHSL(0.26 + rnd() * 0.07, 0.12 + rnd() * 0.16, 0.34 + rnd() * 0.18));
489
+ }
490
+ im.instanceMatrix.needsUpdate = true;
491
+ im.userData.maxCount = n;
492
+ if (im.instanceColor) im.instanceColor.needsUpdate = true;
493
+ scene.add(im);
494
+ return im;
495
+ }
496
+ function buildMountains(scene) {
497
+ const group = new THREE.Group(); group.name = '借景远山 · 灵岩山脊';
498
+ // 山脊全部落在地形网格内(z ≥ −280),避免地形边缘出现硬切直线
499
+ const layers = [
500
+ { z: -212, h: 18, color: 0x778b88, amp: 1.0 },
501
+ { z: -246, h: 28, color: 0x8b9c9b, amp: 1.4 },
502
+ { z: -276, h: 40, color: 0xa3b1ae, amp: 1.8 },
503
+ ];
504
+ layers.forEach((L, li) => {
505
+ const N = 90, pos = [], col = [], idx = [];
506
+ const c = new THREE.Color(L.color);
507
+ for (let i = 0; i <= N; i++) {
508
+ const x = -310 + i * 620 / N;
509
+ const ridge = (Math.sin(x * 0.011 + li * 1.7) * 0.5 + Math.sin(x * 0.027 + li * 2.3) * 0.28
510
+ + Math.sin(x * 0.005 + 1.1) * 0.42 + 0.8) * L.h * L.amp;
511
+ const baseY = terrainHeight(x, L.z) - 4;
512
+ pos.push(x, baseY, L.z, x, baseY + ridge, L.z + Math.sin(x * 0.01) * 8);
513
+ col.push(c.r * 0.72, c.g * 0.72, c.b * 0.72, c.r, c.g, c.b);
514
+ }
515
+ for (let i = 0; i < N; i++) {
516
+ const a = i * 2;
517
+ idx.push(a, a + 1, a + 2, a + 1, a + 3, a + 2);
518
+ }
519
+ const g = new THREE.BufferGeometry();
520
+ g.setAttribute('position', new THREE.Float32BufferAttribute(pos, 3));
521
+ g.setAttribute('color', new THREE.Float32BufferAttribute(col, 3));
522
+ g.setIndex(idx); g.computeVertexNormals();
523
+ const m = new THREE.MeshBasicMaterial({ vertexColors: true, side: THREE.DoubleSide, fog: true });
524
+ const mesh = new THREE.Mesh(g, m);
525
+ mesh.name = '山脊层' + li;
526
+ group.add(mesh);
527
+ });
528
+ scene.add(group);
529
+ return group;
530
+ }
531
+
532
+ /* ------------------------------------------------------------------ *
533
+ * 7. 主入口
534
+ * ------------------------------------------------------------------ */
535
+ export function createNature(scene, M, ctx) {
536
+ const quality = ctx.quality;
537
+ const BatchClass = ctx.BatchClass;
538
+ const terrain = buildTerrain(scene, M);
539
+ const pathGroup = buildPathPatches(scene, M, BatchClass);
540
+
541
+ // 收集器
542
+ const leafGeo = tuftGeo();
543
+ const collectors = {};
544
+ Object.keys(SPECIES).forEach(k => {
545
+ const mat = new THREE.MeshStandardMaterial({
546
+ color: SPECIES[k].leaf, roughness: 0.92, flatShading: true, side: THREE.DoubleSide,
547
+ });
548
+ mat.name = 'leaf_' + k;
549
+ collectors[k] = new InstCollector(leafGeo, mat, '叶簇_' + k);
550
+ });
551
+ collectors.flower = new InstCollector(new THREE.IcosahedronGeometry(1, 0),
552
+ new THREE.MeshStandardMaterial({ color: 0xffffff, roughness: 0.85, flatShading: true }), '花簇');
553
+ const bambooMat = new THREE.MeshStandardMaterial({ color: 0x8aa264, roughness: 0.78 });
554
+ collectors.bambooCane = new InstCollector(new THREE.CylinderGeometry(0.055, 0.065, 6, 6, 1), bambooMat, '竹竿');
555
+ collectors.bambooLeaf = new InstCollector(new THREE.PlaneGeometry(1, 0.26),
556
+ new THREE.MeshStandardMaterial({ color: 0x6e924c, roughness: 0.9, side: THREE.DoubleSide }), '竹叶');
557
+ const lotusMat = new THREE.MeshStandardMaterial({ color: 0xffffff, roughness: 0.86, side: THREE.DoubleSide, vertexColors: true });
558
+ collectors.lotus = new InstCollector(lotusLeafGeo(), lotusMat, '荷叶');
559
+ collectors.lotusFlower = new InstCollector(petalGeo(), new THREE.MeshStandardMaterial({
560
+ color: 0xffffff, roughness: 0.82, side: THREE.DoubleSide }), '荷花');
561
+ collectors.reed = new InstCollector(new THREE.ConeGeometry(0.10, 1.4, 4), new THREE.MeshStandardMaterial({
562
+ color: 0x7d8c52, roughness: 0.9 }), '芦苇');
563
+
564
+ // 树干合批
565
+ const trunkBatch = new BatchClass(40);
566
+ // 景区化植物配置
567
+ const regions = [
568
+ { x0: -102, x1: -44, z0: -74, z1: -12, sp: ['pine', 'plum', 'pine', 'maple'], n: 34, s: [0.8, 1.3] }, // 云根叠翠
569
+ { x0: -104, x1: -66, z0: 22, z1: 76, sp: ['plum', 'osmanthus'], n: 22, s: [0.7, 1.0] }, // 竹里馆
570
+ { x0: 30, x1: 100, z0: 6, z1: 34, sp: ['willow', 'peach', 'magnolia'], n: 24, s: [0.85, 1.2] }, // 荷风
571
+ { x0: 48, x1: 100, z0: -84, z1: -36, sp: ['osmanthus', 'gingko', 'maple'], n: 26, s: [0.8, 1.2] }, // 小山丛桂
572
+ { x0: -30, x1: 34, z0: 34, z1: 74, sp: ['magnolia', 'osmanthus'], n: 18, s: [0.8, 1.1] }, // 前庭
573
+ { x0: -100, x1: -32, z0: -8, z1: 24, sp: ['willow', 'plum', 'pine'], n: 20, s: [0.8, 1.1] },// 漱石枕流
574
+ { x0: -20, x1: 60, z0: -88, z1: -56, sp: ['pine', 'osmanthus', 'gingko'], n: 22, s: [0.8, 1.15] }, // 北岸
575
+ { x0: 66, x1: 104, z0: -30, z1: 4, sp: ['willow', 'peach'], n: 14, s: [0.8, 1.1] }, // 东岸
576
+ ];
577
+ const rnd = mulberry32(9911);
578
+ let treeCount = 0;
579
+ regions.forEach((rg, ri) => {
580
+ const n = Math.round(rg.n * (0.55 + quality.trees * 0.45));
581
+ let local = 0;
582
+ for (let i = 0; i < n * 10 && local < n; i++) {
583
+ const x = rg.x0 + rnd() * (rg.x1 - rg.x0), z = rg.z0 + rnd() * (rg.z1 - rg.z0);
584
+ if (!freeLand(x, z, 2.4)) continue;
585
+ const ft = clamp((51 - z) / 91, 0, 1);
586
+ if (ft > 0.02 && ft < 1 && Math.abs(x + 81.3 - 17.3 * ft) < 6) continue;
587
+ const sp = rg.sp[Math.floor(rnd() * rg.sp.length)];
588
+ const s = rg.s[0] + rnd() * (rg.s[1] - rg.s[0]);
589
+ addTree(ctx, sp, x, z, s, 10000 + ri * 1000 + i, collectors, trunkBatch, M);
590
+ treeCount++; local++;
591
+ }
592
+ });
593
+ // 中轴对植玉兰(对称礼序)
594
+ [[-9, 68], [9, 68], [-9, 48], [9, 48], [-11, 40], [11, 40]].forEach(([x, z], i) => {
595
+ addTree(ctx, 'magnolia', x, z, 0.95, 20000 + i, collectors, trunkBatch, M);
596
+ });
597
+ // 水边垂柳(对景构图)
598
+ [[-24, 20], [-16, 20], [22, 20], [34, 18], [52, 14], [-58, 2], [8, -46], [-20, -46], [60, -20]].forEach(([x, z], i) => {
599
+ if (freeLand(x, z, 0.6) || waterSDF(x, z) > -1.2)
600
+ addTree(ctx, 'willow', x, z, 1.05, 21000 + i, collectors, trunkBatch, M);
601
+ });
602
+
603
+ const trunkGroup = new THREE.Group(); trunkGroup.name = '树干与枝'; scene.add(trunkGroup);
604
+ const trunkStats = trunkBatch.build(trunkGroup);
605
+
606
+ // 竹、荷、芦苇先填充实例数据,再统一创建 InstancedMesh(一次性成型)
607
+ buildBamboo(scene, M, ctx, collectors, Math.round(520 * quality.trees));
608
+ buildLotus(scene, collectors, quality);
609
+ const instances = [];
610
+ Object.values(collectors).forEach(c => {
611
+ const im = c.build(scene, { castShadow: c.name.startsWith('叶簇'), receiveShadow: false, frustumCulled: false });
612
+ if (im) instances.push(im);
613
+ });
614
+
615
+ const banana = buildBanana(scene, M, ctx, BatchClass);
616
+ const grassMat = new THREE.Color(0xb9c2ba);
617
+ // 始终按最高档容量分配实例缓冲,画质切换只改 count,避免重建几何
618
+ const grass = buildGrass(scene, M, QUALITY.high, grassMat);
619
+ const forest = buildDistantForest(scene, M, QUALITY.high);
620
+ const mountains = buildMountains(scene);
621
+
622
+ const api = {
623
+ terrain, pathGroup, trunkGroup, trunkStats, instances, grass, forest, mountains, treeCount,
624
+ applyQuality(q) {
625
+ grass.material.uniforms.uNear.value = 26 * q.lodScale;
626
+ grass.material.uniforms.uFar.value = 62 * q.lodScale;
627
+ const target = Math.round(q.grass);
628
+ grass.count = Math.min(grass.userData.maxCount, target);
629
+ const ft = Math.round(640 * q.trees);
630
+ forest.count = Math.min(forest.userData.maxCount, ft);
631
+ grass.material.uniforms.uWet.value = api._wet || 0;
632
+ },
633
+ setWeather(w, sky) {
634
+ api._wet = w === 'rain' ? 1 : 0;
635
+ grass.material.uniforms.uWet.value = api._wet;
636
+ if (grass.material.uniforms.uFogColor) grass.material.uniforms.uFogColor.value.copy(sky.fogColor);
637
+ const k = w === 'rain' ? 0.76 : w === 'mist' ? 0.90 : 1.0;
638
+ Object.keys(SPECIES).forEach(key => {
639
+ const c = collectors[key];
640
+ if (c.mat) { c.mat.color.set(SPECIES[key].leaf).multiplyScalar(k); }
641
+ });
642
+ },
643
+ update(t, camera) {
644
+ grass.material.uniforms.uTime.value = t;
645
+ grass.material.uniforms.uCam.value.copy(camera.position);
646
+ },
647
+ };
648
+ api.applyQuality(quality);
649
+ return api;
650
+ }