agentscape3d-engine 0.0.0-stage → 1.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +19 -2
- package/cli.mjs +53 -0
- package/dist/ArticulationVerifier-BfGxXY8V.js +337 -0
- package/dist/ArticulationVerifier-BfGxXY8V.js.map +1 -0
- package/dist/AssetCompiler-BLj09iu1.js +2424 -0
- package/dist/AssetCompiler-BLj09iu1.js.map +1 -0
- package/dist/AssetModule-DME-XaFS.js +2637 -0
- package/dist/AssetModule-DME-XaFS.js.map +1 -0
- package/dist/AssetRecipe-g8dZBhgJ.js +298 -0
- package/dist/AssetRecipe-g8dZBhgJ.js.map +1 -0
- package/dist/BrowserCodeWorker.js +53856 -0
- package/dist/BrowserCodeWorker.js.map +1 -0
- package/dist/CarryCapability-CXwHU5ay.js +104 -0
- package/dist/CarryCapability-CXwHU5ay.js.map +1 -0
- package/dist/KinematicHypothesisScreen-C3TKiuYR.js +241 -0
- package/dist/KinematicHypothesisScreen-C3TKiuYR.js.map +1 -0
- package/dist/ObjectTransform-BlQUNK7c.js +61 -0
- package/dist/ObjectTransform-BlQUNK7c.js.map +1 -0
- package/dist/RapierPhysicsBackend-B2wQe_Vl.js +3259 -0
- package/dist/RapierPhysicsBackend-B2wQe_Vl.js.map +1 -0
- package/dist/RenderingSystem-WIr1ZuGu.js +1042 -0
- package/dist/RenderingSystem-WIr1ZuGu.js.map +1 -0
- package/dist/ScenePresentation-LsYiDxbm.js +152 -0
- package/dist/ScenePresentation-LsYiDxbm.js.map +1 -0
- package/dist/SceneProject-K7HH1s8o.js +2687 -0
- package/dist/SceneProject-K7HH1s8o.js.map +1 -0
- package/dist/SceneSerializer-zOzbX4jZ.js +932 -0
- package/dist/SceneSerializer-zOzbX4jZ.js.map +1 -0
- package/dist/SimulationProfile-DSYZbBLQ.js +165 -0
- package/dist/SimulationProfile-DSYZbBLQ.js.map +1 -0
- package/dist/StylePack-DcRa_kU0.js +88 -0
- package/dist/StylePack-DcRa_kU0.js.map +1 -0
- package/dist/WorldArchive-BiFGLt--.js +451 -0
- package/dist/WorldArchive-BiFGLt--.js.map +1 -0
- package/dist/WorldCommands-Debj7V4L.js +2207 -0
- package/dist/WorldCommands-Debj7V4L.js.map +1 -0
- package/dist/WorldIO-Ch8QBfKY.js +151 -0
- package/dist/WorldIO-Ch8QBfKY.js.map +1 -0
- package/dist/admission-CVEvsrdz.js +121 -0
- package/dist/admission-CVEvsrdz.js.map +1 -0
- package/dist/blankWorld-B0MW6g7q.js +75 -0
- package/dist/blankWorld-B0MW6g7q.js.map +1 -0
- package/dist/core.d.ts +68 -0
- package/dist/core.js +209 -0
- package/dist/core.js.map +1 -0
- package/dist/disposeObject3D-DIMzy0FA.js +128 -0
- package/dist/disposeObject3D-DIMzy0FA.js.map +1 -0
- package/dist/environments-HOe3sJXH.js +567 -0
- package/dist/environments-HOe3sJXH.js.map +1 -0
- package/dist/gltfIO-BzVKLyaL.js +339 -0
- package/dist/gltfIO-BzVKLyaL.js.map +1 -0
- package/dist/grandUrbanBlock-DRndRZjF.js +515 -0
- package/dist/grandUrbanBlock-DRndRZjF.js.map +1 -0
- package/dist/index.d.ts +345 -0
- package/dist/index.js +16952 -0
- package/dist/index.js.map +1 -0
- package/dist/magicCabin-CfBZjx2Q.js +11019 -0
- package/dist/magicCabin-CfBZjx2Q.js.map +1 -0
- package/dist/manifests-D0LwbJ36.js +866 -0
- package/dist/manifests-D0LwbJ36.js.map +1 -0
- package/dist/mcp.d.ts +2 -0
- package/dist/mcp.js +1 -0
- package/dist/monumentHall-awZiGtda.js +403 -0
- package/dist/monumentHall-awZiGtda.js.map +1 -0
- package/dist/node.d.ts +16 -0
- package/dist/node.js +26 -0
- package/dist/parts-DrEcfJRl.js +37 -0
- package/dist/parts-DrEcfJRl.js.map +1 -0
- package/dist/rolldown-runtime-D3KUYPsf.js +12 -0
- package/dist/ruinedCourtyard-DuF7NmUU.js +696 -0
- package/dist/ruinedCourtyard-DuF7NmUU.js.map +1 -0
- package/dist/runtime/application/AgentTools.js +28 -0
- package/dist/runtime/application/README.md +14 -0
- package/dist/runtime/application/agent/ProgressiveAgentTools.js +92 -0
- package/dist/runtime/application/agent/StudioMcpAllowlist.js +10 -0
- package/dist/runtime/application/agent/StudioProjectTools.js +18 -0
- package/dist/runtime/application/agent/TaskEvidence.js +199 -0
- package/dist/runtime/application/buildTaskObservation.js +117 -0
- package/dist/runtime/application/code-execution/AuthoringSandboxEntry.js +50 -0
- package/dist/runtime/application/code-execution/BrowserCodeExecutor.js +35 -0
- package/dist/runtime/application/code-execution/BrowserCodeWorker.js +17 -0
- package/dist/runtime/application/code-execution/RemoteAuthoringDocument.js +82 -0
- package/dist/runtime/application/createSession.js +66 -0
- package/dist/runtime/application/createWorldAuthoringContext.js +400 -0
- package/dist/runtime/application/generation/GenerationOrchestrator.js +630 -0
- package/dist/runtime/application/generation/GenerationRuntime.js +215 -0
- package/dist/runtime/application/generation/PromptHybridWorldOrchestrator.js +289 -0
- package/dist/runtime/application/native-scene/CodeProject.js +215 -0
- package/dist/runtime/application/native-scene/CodeProjectModules.js +143 -0
- package/dist/runtime/application/native-scene/ExampleWorldCatalog.js +35 -0
- package/dist/runtime/application/native-scene/NativeArticulation.js +53 -0
- package/dist/runtime/application/native-scene/NativeEditableRegistry.js +150 -0
- package/dist/runtime/application/native-scene/NativeEnvironmentGeometry.js +85 -0
- package/dist/runtime/application/native-scene/NativeLightingInspection.js +33 -0
- package/dist/runtime/application/native-scene/NativeMaterialInspection.js +52 -0
- package/dist/runtime/application/native-scene/NativeOverlayCheckpoint.js +127 -0
- package/dist/runtime/application/native-scene/NativePhysicsGeometry.js +64 -0
- package/dist/runtime/application/native-scene/NativeRenderDiscovery.js +51 -0
- package/dist/runtime/application/native-scene/NativeSceneHost.js +406 -0
- package/dist/runtime/application/native-scene/NativeSceneInspection.js +203 -0
- package/dist/runtime/application/native-scene/NativeSceneOverlay.js +116 -0
- package/dist/runtime/application/native-scene/NativeSceneQuery.js +123 -0
- package/dist/runtime/application/native-scene/NativeSceneReview.js +132 -0
- package/dist/runtime/application/native-scene/NativeThreeModule.js +16 -0
- package/dist/runtime/application/native-scene/SceneObserver.js +97 -0
- package/dist/runtime/application/native-scene/VisualCapturePolicy.js +4 -0
- package/dist/runtime/application/object-forge/SceneObjectForge.js +263 -0
- package/dist/runtime/application/programmatic-assets/ProgrammaticAssetBuilder.js +59 -0
- package/dist/runtime/application/programmatic-assets/ProgrammaticAssetContract.js +22 -0
- package/dist/runtime/application/programmatic-assets/ThreeCodeAsset.js +40 -0
- package/dist/runtime/application/scene/CapabilityResolver.js +90 -0
- package/dist/runtime/application/scene/NativeEditableContracts.js +18 -0
- package/dist/runtime/application/scene/RequestWindow.js +54 -0
- package/dist/runtime/application/scene/SceneAgentTools.js +21 -0
- package/dist/runtime/application/scene/SceneContracts.js +49 -0
- package/dist/runtime/application/scene/SceneEditService.js +154 -0
- package/dist/runtime/application/scene/SceneFacade.js +356 -0
- package/dist/runtime/application/scene/SceneInteractionAdapters.js +41 -0
- package/dist/runtime/application/scene/SceneJobController.js +320 -0
- package/dist/runtime/application/scene/SceneLifecycle.js +57 -0
- package/dist/runtime/application/scene/ScenePackage.js +173 -0
- package/dist/runtime/application/scene/ScenePersistence.js +50 -0
- package/dist/runtime/application/scene/SceneProject.js +95 -0
- package/dist/runtime/application/scene/SceneSkillNames.js +5 -0
- package/dist/runtime/application/scene/StarterScene.js +56 -0
- package/dist/runtime/application/scene/WorldArchive.js +89 -0
- package/dist/runtime/application/scene/WorldDirectory.js +20 -0
- package/dist/runtime/application/scene/WorldDocument.js +76 -0
- package/dist/runtime/application/scene/WorldIO.js +103 -0
- package/dist/runtime/application/scene/WorldStorage.js +155 -0
- package/dist/runtime/application/skills/SkillRegistry.js +193 -0
- package/dist/runtime/application/skills/packs/acceptanceSkills.js +32 -0
- package/dist/runtime/application/skills/packs/affordanceSkills.js +36 -0
- package/dist/runtime/application/skills/packs/assetSkills.js +46 -0
- package/dist/runtime/application/skills/packs/authoringSkills.js +16 -0
- package/dist/runtime/application/skills/packs/batchSkills.js +22 -0
- package/dist/runtime/application/skills/packs/codeSkills.js +106 -0
- package/dist/runtime/application/skills/packs/generationSkills.js +45 -0
- package/dist/runtime/application/skills/packs/interactionSkills.js +46 -0
- package/dist/runtime/application/skills/packs/recoverySkills.js +80 -0
- package/dist/runtime/application/skills/packs/sceneSkills.js +24 -0
- package/dist/runtime/application/skills/packs/spatialSkills.js +35 -0
- package/dist/runtime/application/skills/packs/verificationSkills.js +14 -0
- package/dist/runtime/application/skills/packs/worldSkills.js +45 -0
- package/dist/runtime/application/skills/registerCoreSkills.js +31 -0
- package/dist/runtime/application/skills/skillPrimitives.js +4 -0
- package/dist/runtime/application/tasks/CabinetCupTask.js +76 -0
- package/dist/runtime/application/tasks.jsonl +67 -0
- package/dist/runtime/application/world-authoring/AuthoringAssetProducer.js +42 -0
- package/dist/runtime/application/world-authoring/AuthoringDiff.js +149 -0
- package/dist/runtime/application/world-authoring/AuthoringDocument.js +825 -0
- package/dist/runtime/application/world-authoring/AuthoringExecutionHost.js +109 -0
- package/dist/runtime/application/world-authoring/AuthoringIdentity.js +17 -0
- package/dist/runtime/application/world-authoring/AuthoringModelResolver.js +29 -0
- package/dist/runtime/application/world-authoring/AuthoringPatch.js +118 -0
- package/dist/runtime/application/world-authoring/AuthoringPromotionController.js +334 -0
- package/dist/runtime/application/world-authoring/AuthoringPromotionSource.js +126 -0
- package/dist/runtime/application/world-authoring/AuthoringRevisionHistory.js +144 -0
- package/dist/runtime/application/world-authoring/HeadlessImageExport.js +92 -0
- package/dist/runtime/application/world-authoring/ModelRef.js +62 -0
- package/dist/runtime/application/world-authoring/SceneGLBExport.js +88 -0
- package/dist/runtime/apps/mcp-server/AUTHORING.md +71 -0
- package/dist/runtime/apps/mcp-server/AgentMcpCompat.js +68 -0
- package/dist/runtime/apps/mcp-server/AuthoringSandboxEntry.js +1 -0
- package/dist/runtime/apps/mcp-server/AuthoringSandboxWorker.mjs +30 -0
- package/dist/runtime/apps/mcp-server/BuildEnvironment.js +17 -0
- package/dist/runtime/apps/mcp-server/CodeExecutor.js +71 -0
- package/dist/runtime/apps/mcp-server/DEPLOYMENT-PC2.md +42 -0
- package/dist/runtime/apps/mcp-server/DockerBuildRunner.js +66 -0
- package/dist/runtime/apps/mcp-server/FileAssetRepository.js +159 -0
- package/dist/runtime/apps/mcp-server/HeadlessAssetIO.js +8 -0
- package/dist/runtime/apps/mcp-server/HeadlessGLTFLoader.js +47 -0
- package/dist/runtime/apps/mcp-server/HeadlessWorldHost.js +157 -0
- package/dist/runtime/apps/mcp-server/IsolatedAuthoringExecutor.js +6 -0
- package/dist/runtime/apps/mcp-server/PROGRAMMATIC-ASSETS.md +116 -0
- package/dist/runtime/apps/mcp-server/ProgrammaticAssets.js +60 -0
- package/dist/runtime/apps/mcp-server/README.md +269 -0
- package/dist/runtime/apps/mcp-server/RemoteAuthoringDocument.js +1 -0
- package/dist/runtime/apps/mcp-server/SandboxBundle.js +13 -0
- package/dist/runtime/apps/mcp-server/SessionManager.js +148 -0
- package/dist/runtime/apps/mcp-server/StudioBridgeHttp.js +75 -0
- package/dist/runtime/apps/mcp-server/StudioLiveBridge.js +246 -0
- package/dist/runtime/apps/mcp-server/StudioProjectToolContracts.js +58 -0
- package/dist/runtime/apps/mcp-server/TransferHttp.js +47 -0
- package/dist/runtime/apps/mcp-server/TransferLimits.js +6 -0
- package/dist/runtime/apps/mcp-server/TransferStore.js +134 -0
- package/dist/runtime/apps/mcp-server/TrustedAuthoringWorker.mjs +16 -0
- package/dist/runtime/apps/mcp-server/VALIDATION.md +45 -0
- package/dist/runtime/apps/mcp-server/acceptance-evidence.json +332 -0
- package/dist/runtime/apps/mcp-server/errorDiagnostics.js +32 -0
- package/dist/runtime/apps/mcp-server/examples/code-house.js +24 -0
- package/dist/runtime/apps/mcp-server/examples/procedural-assets.js +85 -0
- package/dist/runtime/apps/mcp-server/main.mjs +82 -0
- package/dist/runtime/apps/mcp-server/registerTools.js +274 -0
- package/dist/runtime/apps/mcp-server/sandbox/run.mjs +23 -0
- package/dist/runtime/apps/mcp-server/security.js +23 -0
- package/dist/runtime/apps/mcp-server/tasks.jsonl +9 -0
- package/dist/runtime/apps/server/CapabilityAdapterRegistry.js +157 -0
- package/dist/runtime/apps/server/README.md +7 -0
- package/dist/runtime/apps/server/WorldRepository.js +338 -0
- package/dist/runtime/apps/server/WorldRepositoryHttp.js +96 -0
- package/dist/runtime/apps/server/openai-compatible-agent-gateway.mjs +278 -0
- package/dist/runtime/apps/server/tasks.jsonl +10 -0
- package/dist/runtime/apps/shared/node/WorldDiskStorage.js +62 -0
- package/dist/runtime/foundation/EventBus.js +26 -0
- package/dist/runtime/foundation/JsonGateway.js +47 -0
- package/dist/runtime/foundation/PngRgba.js +99 -0
- package/dist/runtime/foundation/PolicyEngine.js +21 -0
- package/dist/runtime/foundation/README.md +7 -0
- package/dist/runtime/foundation/TraceRecorder.js +76 -0
- package/dist/runtime/foundation/errors.js +8 -0
- package/dist/runtime/foundation/simulation/SimulationProfile.js +143 -0
- package/dist/runtime/foundation/version.js +2 -0
- package/dist/runtime/modules/agent/README.md +11 -0
- package/dist/runtime/modules/agent/ToolCallingAgent.js +19 -0
- package/dist/runtime/modules/agent/bootstrapWorld.js +10 -0
- package/dist/runtime/modules/agent/buildRecoveryProposals.js +533 -0
- package/dist/runtime/modules/agent/execution/AgentExecutionRules.js +128 -0
- package/dist/runtime/modules/agent/execution/AgentRunResults.js +55 -0
- package/dist/runtime/modules/agent/execution/AgentRunSession.js +393 -0
- package/dist/runtime/modules/agent/execution/AgentToolInvoker.js +40 -0
- package/dist/runtime/modules/agent/gateway/HttpLLMGateway.js +19 -0
- package/dist/runtime/modules/agent/prompt/index.js +52 -0
- package/dist/runtime/modules/agent/tasks.jsonl +94 -0
- package/dist/runtime/modules/artifact/ArtifactContentGate.js +144 -0
- package/dist/runtime/modules/artifact/ArtifactDescriptor.js +280 -0
- package/dist/runtime/modules/artifact/ArtifactImporter.js +185 -0
- package/dist/runtime/modules/artifact/ArtifactModule.js +111 -0
- package/dist/runtime/modules/artifact/ArtifactRegistry.js +197 -0
- package/dist/runtime/modules/artifact/IncrementalSha256.js +129 -0
- package/dist/runtime/modules/artifact/MemoryArtifactByteStore.js +115 -0
- package/dist/runtime/modules/artifact/README.md +7 -0
- package/dist/runtime/modules/artifact/storage/IndexedDbArtifactStore.js +67 -0
- package/dist/runtime/modules/artifact/tasks.jsonl +31 -0
- package/dist/runtime/modules/asset/AssetModule.js +416 -0
- package/dist/runtime/modules/asset/README.md +67 -0
- package/dist/runtime/modules/asset/loading/AssetLoader.js +157 -0
- package/dist/runtime/modules/asset/loading/GltfAssetLoader.js +61 -0
- package/dist/runtime/modules/asset/loading/builtins/BuiltinAssets.js +95 -0
- package/dist/runtime/modules/asset/loading/builtins/HouseDoor.js +33 -0
- package/dist/runtime/modules/asset/loading/builtins/IndustrialCabinet.js +103 -0
- package/dist/runtime/modules/asset/model/AssetInputContracts.js +139 -0
- package/dist/runtime/modules/asset/model/AssetRef.js +12 -0
- package/dist/runtime/modules/asset/model/MechanicalAssetDraft.js +172 -0
- package/dist/runtime/modules/asset/model/ProceduralTextureContract.js +24 -0
- package/dist/runtime/modules/asset/model/admission.js +117 -0
- package/dist/runtime/modules/asset/model/errors.js +6 -0
- package/dist/runtime/modules/asset/model/parts.js +27 -0
- package/dist/runtime/modules/asset/model/resourceBudget.js +10 -0
- package/dist/runtime/modules/asset/model/schema.js +150 -0
- package/dist/runtime/modules/asset/persistence/AssetManifestStore.js +78 -0
- package/dist/runtime/modules/asset/persistence/CompiledAssetStore.js +84 -0
- package/dist/runtime/modules/asset/persistence/LocalAssetLibrary.js +86 -0
- package/dist/runtime/modules/asset/persistence/LocalAssetLibraryStore.js +81 -0
- package/dist/runtime/modules/asset/production/AssetProductionPipeline.js +272 -0
- package/dist/runtime/modules/asset/production/AssetRecipe.js +91 -0
- package/dist/runtime/modules/asset/production/ProceduralTexture.js +85 -0
- package/dist/runtime/modules/asset/production/adapters/EmbodiedGenAdapter.js +45 -0
- package/dist/runtime/modules/asset/production/adapters/EmbodiedGenBundleAdapter.js +590 -0
- package/dist/runtime/modules/asset/production/compiler/AssetCompiler.js +173 -0
- package/dist/runtime/modules/asset/production/compiler/evidence/AnimationMotionEvidence.js +124 -0
- package/dist/runtime/modules/asset/production/compiler/evidence/StaticPanelEvidence.js +56 -0
- package/dist/runtime/modules/asset/production/compiler/gltfIO.js +6 -0
- package/dist/runtime/modules/asset/production/compiler/partGeometry.js +74 -0
- package/dist/runtime/modules/asset/production/compiler/passes/ArticulatedCollisionPass.js +63 -0
- package/dist/runtime/modules/asset/production/compiler/passes/ArticulationCandidatePass.js +48 -0
- package/dist/runtime/modules/asset/production/compiler/passes/AuthoringIntentPass.js +16 -0
- package/dist/runtime/modules/asset/production/compiler/passes/ColliderFallbackPass.js +30 -0
- package/dist/runtime/modules/asset/production/compiler/passes/CompileQualityPass.js +75 -0
- package/dist/runtime/modules/asset/production/compiler/passes/ExplicitDefinitionPass.js +20 -0
- package/dist/runtime/modules/asset/production/compiler/passes/GLTFInspectPass.js +34 -0
- package/dist/runtime/modules/asset/production/compiler/passes/GeometryPass.js +32 -0
- package/dist/runtime/modules/asset/production/compiler/passes/JointFramePass.js +116 -0
- package/dist/runtime/modules/asset/production/compiler/passes/KinematicEvidencePass.js +84 -0
- package/dist/runtime/modules/asset/production/compiler/passes/ManifestPass.js +63 -0
- package/dist/runtime/modules/asset/production/compiler/passes/NormalizeTransformPass.js +16 -0
- package/dist/runtime/modules/asset/production/compiler/passes/OptimizeGLBPass.js +23 -0
- package/dist/runtime/modules/asset/production/compiler/passes/PartColliderPass.js +50 -0
- package/dist/runtime/modules/asset/production/compiler/passes/PartGeometryEnrichmentPass.js +60 -0
- package/dist/runtime/modules/asset/production/compiler/passes/PartProposalPass.js +93 -0
- package/dist/runtime/modules/asset/production/compiler/passes/RemoteEnrichmentPass.js +32 -0
- package/dist/runtime/modules/asset/production/compiler/passes/ResourceBudgetPass.js +55 -0
- package/dist/runtime/modules/asset/production/compiler/passes/SegmentMaterializePass.js +203 -0
- package/dist/runtime/modules/asset/production/compiler/passes/SegmentationEvidencePass.js +43 -0
- package/dist/runtime/modules/asset/production/compiler/passes/SemanticHeuristicPass.js +33 -0
- package/dist/runtime/modules/asset/production/compiler/passes/StructurePass.js +60 -0
- package/dist/runtime/modules/asset/production/compiler/providers/HttpCompilerProvider.js +23 -0
- package/dist/runtime/modules/asset/production/verification/KinematicHypothesisScreen.js +198 -0
- package/dist/runtime/modules/asset/registry/AssetCatalog.js +72 -0
- package/dist/runtime/modules/asset/registry/AssetRegistry.js +51 -0
- package/dist/runtime/modules/asset/registry/manifests/index.js +173 -0
- package/dist/runtime/modules/asset/tasks.jsonl +87 -0
- package/dist/runtime/modules/generation/README.md +9 -0
- package/dist/runtime/modules/generation/connector/ConnectorArtifactClient.js +45 -0
- package/dist/runtime/modules/generation/connector/ConnectorCapabilityAdapter.js +169 -0
- package/dist/runtime/modules/generation/connector/ConnectorClient.js +192 -0
- package/dist/runtime/modules/generation/connector/ConnectorJobClient.js +167 -0
- package/dist/runtime/modules/generation/connector/ConnectorJobEventClient.js +179 -0
- package/dist/runtime/modules/generation/connector/ConnectorSession.js +202 -0
- package/dist/runtime/modules/generation/jobs/GenerationJobProjection.js +239 -0
- package/dist/runtime/modules/generation/jobs/GenerationJobReconciler.js +99 -0
- package/dist/runtime/modules/generation/jobs/GenerationJobStore.js +91 -0
- package/dist/runtime/modules/generation/jobs/GenerationJobTransportOverlay.js +50 -0
- package/dist/runtime/modules/generation/providers/ProviderRegistry.js +304 -0
- package/dist/runtime/modules/generation/tasks.jsonl +35 -0
- package/dist/runtime/modules/navigation/NavigationBackend.js +17 -0
- package/dist/runtime/modules/navigation/RecastNavigationBackend.js +263 -0
- package/dist/runtime/modules/physics/JoltPhysicsBackend.js +850 -0
- package/dist/runtime/modules/physics/PhysicsApiSurface.js +660 -0
- package/dist/runtime/modules/physics/PhysicsBackend.js +88 -0
- package/dist/runtime/modules/physics/RapierPhysicsBackend.js +414 -0
- package/dist/runtime/modules/rendering/README.md +7 -0
- package/dist/runtime/modules/rendering/RendererProbe.js +153 -0
- package/dist/runtime/modules/rendering/WebGpuPostFxPipeline.js +140 -0
- package/dist/runtime/modules/rendering/captureStill.js +54 -0
- package/dist/runtime/modules/rendering/createRenderer.js +76 -0
- package/dist/runtime/modules/rendering/disposeObject3D.js +37 -0
- package/dist/runtime/modules/rendering/loadGaussianSplatVisual.js +74 -0
- package/dist/runtime/modules/rendering/spatial/ThreeBvhRuntime.js +107 -0
- package/dist/runtime/modules/rendering/style/StylePack.js +34 -0
- package/dist/runtime/modules/rendering/style/StyleSystem.js +173 -0
- package/dist/runtime/modules/rendering/tasks.jsonl +7 -0
- package/dist/runtime/modules/world/README.md +13 -0
- package/dist/runtime/modules/world/build/WorldBuilder.js +170 -0
- package/dist/runtime/modules/world/compiler/PipelineEngine.js +32 -0
- package/dist/runtime/modules/world/compiler/WorldAdmission.js +43 -0
- package/dist/runtime/modules/world/compiler/WorldBehaviorCompiler.js +68 -0
- package/dist/runtime/modules/world/compiler/WorldCompilation.js +157 -0
- package/dist/runtime/modules/world/compiler/WorldComposer.js +201 -0
- package/dist/runtime/modules/world/compiler/WorldPhysicsAdmission.js +76 -0
- package/dist/runtime/modules/world/compiler/WorldRecompiler.js +356 -0
- package/dist/runtime/modules/world/compiler/WorldRetry.js +75 -0
- package/dist/runtime/modules/world/compiler/createWorldPipeline.js +379 -0
- package/dist/runtime/modules/world/content/blankWorld.js +35 -0
- package/dist/runtime/modules/world/content/environments.js +84 -0
- package/dist/runtime/modules/world/content/grandUrbanBlock.js +189 -0
- package/dist/runtime/modules/world/content/magic-cabin/README.md +28 -0
- package/dist/runtime/modules/world/content/magic-cabin/affordances.js +64 -0
- package/dist/runtime/modules/world/content/magic-cabin/cabinContents.js +7078 -0
- package/dist/runtime/modules/world/content/magic-cabin/lighting.js +26 -0
- package/dist/runtime/modules/world/content/magic-cabin/materials.js +20 -0
- package/dist/runtime/modules/world/content/magicCabin.js +190 -0
- package/dist/runtime/modules/world/content/monumentHall.js +154 -0
- package/dist/runtime/modules/world/content/ruinedCourtyard.js +196 -0
- package/dist/runtime/modules/world/content/suzhouGarden/README.md +141 -0
- package/dist/runtime/modules/world/content/suzhouGarden/index.js +137 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/arch.js +491 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/buildings.js +670 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/core.js +578 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/lod.js +127 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/main.js +642 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/nature.js +650 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/rockery.js +280 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/sky.js +242 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/water.js +215 -0
- package/dist/runtime/modules/world/content/woodlandWorkshop.js +192 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/README.md +36 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/arch.js +351 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/buildings.js +490 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/core.js +505 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/index.js +101 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/nature.js +435 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/sky.js +169 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/water.js +245 -0
- package/dist/runtime/modules/world/errors.js +9 -0
- package/dist/runtime/modules/world/generated/GeneratedWorldCoordinates.js +50 -0
- package/dist/runtime/modules/world/generated/GeneratedWorldLoader.js +297 -0
- package/dist/runtime/modules/world/runtime/CommandHistory.js +111 -0
- package/dist/runtime/modules/world/runtime/EntityCapabilityRegistry.js +165 -0
- package/dist/runtime/modules/world/runtime/NativeNavigationGeometry.js +84 -0
- package/dist/runtime/modules/world/runtime/NativePhysicsSnapshot.js +245 -0
- package/dist/runtime/modules/world/runtime/ObjectStore.js +31 -0
- package/dist/runtime/modules/world/runtime/ObjectTransform.js +62 -0
- package/dist/runtime/modules/world/runtime/ObservedEntity.js +37 -0
- package/dist/runtime/modules/world/runtime/ProjectCapabilities.js +240 -0
- package/dist/runtime/modules/world/runtime/SceneExtensions.js +36 -0
- package/dist/runtime/modules/world/runtime/ScenePresentation.js +101 -0
- package/dist/runtime/modules/world/runtime/SceneSerializer.js +281 -0
- package/dist/runtime/modules/world/runtime/WorldAuthority.js +41 -0
- package/dist/runtime/modules/world/runtime/WorldCollisionSignature.js +14 -0
- package/dist/runtime/modules/world/runtime/WorldCommands.js +503 -0
- package/dist/runtime/modules/world/runtime/WorldObservation.js +71 -0
- package/dist/runtime/modules/world/runtime/WorldQueries.js +340 -0
- package/dist/runtime/modules/world/runtime/WorldRecovery.js +78 -0
- package/dist/runtime/modules/world/runtime/WorldRuntime.js +806 -0
- package/dist/runtime/modules/world/runtime/affordance/ObjectAffordances.js +110 -0
- package/dist/runtime/modules/world/runtime/affordance/WorldAffordances.js +130 -0
- package/dist/runtime/modules/world/runtime/behavior/BehaviorCompiler.js +79 -0
- package/dist/runtime/modules/world/runtime/behavior/ProjectStateMachine.js +195 -0
- package/dist/runtime/modules/world/runtime/behavior/RuleGraph.js +70 -0
- package/dist/runtime/modules/world/runtime/behavior/RuleRuntime.js +115 -0
- package/dist/runtime/modules/world/runtime/graph/SceneGraph.js +390 -0
- package/dist/runtime/modules/world/runtime/interaction/ArticulationRuntime.js +214 -0
- package/dist/runtime/modules/world/runtime/interaction/CarryCapability.js +65 -0
- package/dist/runtime/modules/world/runtime/interaction/CarryRuntime.js +244 -0
- package/dist/runtime/modules/world/runtime/interaction/InteractionApproach.js +147 -0
- package/dist/runtime/modules/world/runtime/interaction/InteractionContract.js +57 -0
- package/dist/runtime/modules/world/runtime/interaction/ManipulationActions.js +7 -0
- package/dist/runtime/modules/world/runtime/interaction/NativePhysicalTarget.js +31 -0
- package/dist/runtime/modules/world/runtime/interaction/RecoveryRuntime.js +123 -0
- package/dist/runtime/modules/world/runtime/interaction/SettleRuntime.js +134 -0
- package/dist/runtime/modules/world/runtime/semantic/NativePhysicsState.js +89 -0
- package/dist/runtime/modules/world/runtime/semantic/SemanticWorldView.js +129 -0
- package/dist/runtime/modules/world/runtime/simulation/SimulationClock.js +89 -0
- package/dist/runtime/modules/world/runtime/simulation/SimulationSession.js +104 -0
- package/dist/runtime/modules/world/runtime/simulation/ThermalSystem.js +269 -0
- package/dist/runtime/modules/world/runtime/simulation/WorldTimeline.js +110 -0
- package/dist/runtime/modules/world/runtime/spatial/SpatialSnapshot.js +56 -0
- package/dist/runtime/modules/world/runtime/spatial/VisualMeshBounds.js +41 -0
- package/dist/runtime/modules/world/runtime/systems/AudioSystem.js +306 -0
- package/dist/runtime/modules/world/runtime/systems/Instrument.js +39 -0
- package/dist/runtime/modules/world/runtime/systems/InteractionSystem.js +806 -0
- package/dist/runtime/modules/world/runtime/systems/LocomotionSystem.js +281 -0
- package/dist/runtime/modules/world/runtime/systems/NavigationSystem.js +561 -0
- package/dist/runtime/modules/world/runtime/systems/PhysicsSystem.js +1752 -0
- package/dist/runtime/modules/world/runtime/systems/RenderingSystem.js +527 -0
- package/dist/runtime/modules/world/runtime/systems/SpatialSystem.js +402 -0
- package/dist/runtime/modules/world/spec/WorldIR.js +165 -0
- package/dist/runtime/modules/world/spec/WorldIRToolSchema.js +86 -0
- package/dist/runtime/modules/world/spec/WorldPlannerProposal.js +51 -0
- package/dist/runtime/modules/world/spec/WorldRevision.js +231 -0
- package/dist/runtime/modules/world/spec/WorldSpec.js +86 -0
- package/dist/runtime/modules/world/tasks.jsonl +530 -0
- package/dist/runtime/modules/world/verification/ArticulationVerifier.js +254 -0
- package/dist/runtime/modules/world/verification/Finding.js +105 -0
- package/dist/runtime/modules/world/verification/InteractionEvidence.js +73 -0
- package/dist/runtime/modules/world/verification/RepairEngine.js +49 -0
- package/dist/runtime/modules/world/verification/VisualLayoutAcceptance.js +58 -0
- package/dist/runtime/modules/world/verification/WorldAcceptance.js +176 -0
- package/dist/runtime/modules/world/verification/WorldValidator.js +67 -0
- package/dist/runtime/package-lock.json +16071 -0
- package/dist/runtime/package.json +106 -0
- package/dist/runtime/public/assets/cabinet.glb +0 -0
- package/dist/runtime/public/assets/grand-urban-block/clean_asphalt_diff_1k.jpg +0 -0
- package/dist/runtime/public/assets/grand-urban-block/clean_asphalt_nor_gl_1k.jpg +0 -0
- package/dist/runtime/public/assets/grand-urban-block/concrete_pavement_diff_1k.jpg +0 -0
- package/dist/runtime/public/assets/grand-urban-block/urban_street_01_1k.hdr +0 -0
- package/dist/runtime/public/assets/monument-hall/marble_diff_1k.jpg +0 -0
- package/dist/runtime/public/assets/monument-hall/marble_nor_gl_1k.jpg +0 -0
- package/dist/runtime/public/assets/monument-hall/marble_rough_1k.jpg +0 -0
- package/dist/runtime/public/assets/monument-hall/solitude_interior_1k.hdr +0 -0
- package/dist/runtime/public/assets/ruined-courtyard/courtyard_1k.hdr +0 -0
- package/dist/runtime/public/assets/ruined-courtyard/mossy_cobblestone_diff_1k.jpg +0 -0
- package/dist/runtime/public/assets/ruined-courtyard/mossy_cobblestone_nor_gl_1k.jpg +0 -0
- package/dist/runtime/public/assets/ruined-courtyard/mossy_sandstone_diff_1k.jpg +0 -0
- package/dist/schema-DT7K9NjP.js +165 -0
- package/dist/schema-DT7K9NjP.js.map +1 -0
- package/dist/suzhouGarden-Y3hny8j6.js +6150 -0
- package/dist/suzhouGarden-Y3hny8j6.js.map +1 -0
- package/dist/version-CHc-i8ch.js +5 -0
- package/dist/version-CHc-i8ch.js.map +1 -0
- package/dist/woodlandWorkshop-DsScU-cx.js +483 -0
- package/dist/woodlandWorkshop-DsScU-cx.js.map +1 -0
- package/dist/yuanmingyuan-DsFnPzzR.js +4955 -0
- package/dist/yuanmingyuan-DsFnPzzR.js.map +1 -0
- package/package.json +75 -4
|
@@ -0,0 +1,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
|
+
}
|