agentscape3d-engine 0.0.0-stage → 1.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +19 -2
- package/cli.mjs +53 -0
- package/dist/AssetCompiler-A99wKf7H.js +2424 -0
- package/dist/AssetCompiler-A99wKf7H.js.map +1 -0
- package/dist/AssetInputContracts-uKYeQu-X.js +245 -0
- package/dist/AssetInputContracts-uKYeQu-X.js.map +1 -0
- package/dist/AssetRecipe-DCaLLXvG.js +67 -0
- package/dist/AssetRecipe-DCaLLXvG.js.map +1 -0
- package/dist/BrowserCodeWorker.js +53850 -0
- package/dist/BrowserCodeWorker.js.map +1 -0
- package/dist/KinematicHypothesisScreen-4v7GBwdv.js +241 -0
- package/dist/KinematicHypothesisScreen-4v7GBwdv.js.map +1 -0
- package/dist/SceneSerializer-CLCzQjL_.js +350 -0
- package/dist/SceneSerializer-CLCzQjL_.js.map +1 -0
- package/dist/StylePack-CD_BC-Mv.js +6317 -0
- package/dist/StylePack-CD_BC-Mv.js.map +1 -0
- package/dist/WorldArchive-dYf1OpSe.js +417 -0
- package/dist/WorldArchive-dYf1OpSe.js.map +1 -0
- package/dist/WorldIO-Dqz4MqTQ.js +149 -0
- package/dist/WorldIO-Dqz4MqTQ.js.map +1 -0
- package/dist/blankWorld-OoOvN_IK.js +75 -0
- package/dist/blankWorld-OoOvN_IK.js.map +1 -0
- package/dist/core.d.ts +68 -0
- package/dist/core.js +209 -0
- package/dist/core.js.map +1 -0
- package/dist/disposeObject3D-B3HCflvO.js +128 -0
- package/dist/disposeObject3D-B3HCflvO.js.map +1 -0
- package/dist/environments-B1WaICAN.js +4197 -0
- package/dist/environments-B1WaICAN.js.map +1 -0
- package/dist/gltfIO-BMK1hc2D.js +9 -0
- package/dist/gltfIO-BMK1hc2D.js.map +1 -0
- package/dist/grandUrbanBlock-Bdjgc6ZT.js +515 -0
- package/dist/grandUrbanBlock-Bdjgc6ZT.js.map +1 -0
- package/dist/index.d.ts +275 -0
- package/dist/index.js +16239 -0
- package/dist/index.js.map +1 -0
- package/dist/magicCabin-DPQi_jh-.js +11019 -0
- package/dist/magicCabin-DPQi_jh-.js.map +1 -0
- package/dist/mcp.d.ts +2 -0
- package/dist/mcp.js +1 -0
- package/dist/monumentHall-IOLbRZQC.js +403 -0
- package/dist/monumentHall-IOLbRZQC.js.map +1 -0
- package/dist/node.d.ts +16 -0
- package/dist/node.js +26 -0
- package/dist/rolldown-runtime-D3KUYPsf.js +12 -0
- package/dist/ruinedCourtyard-BtaF_aOi.js +696 -0
- package/dist/ruinedCourtyard-BtaF_aOi.js.map +1 -0
- package/dist/runtime/application/AgentTools.js +28 -0
- package/dist/runtime/application/README.md +14 -0
- package/dist/runtime/application/agent/ProgressiveAgentTools.js +92 -0
- package/dist/runtime/application/agent/StudioMcpAllowlist.js +8 -0
- package/dist/runtime/application/buildTaskObservation.js +117 -0
- package/dist/runtime/application/code-execution/AuthoringSandboxEntry.js +46 -0
- package/dist/runtime/application/code-execution/BrowserCodeExecutor.js +35 -0
- package/dist/runtime/application/code-execution/BrowserCodeWorker.js +17 -0
- package/dist/runtime/application/code-execution/RemoteAuthoringDocument.js +72 -0
- package/dist/runtime/application/createSession.js +66 -0
- package/dist/runtime/application/createWorldAuthoringContext.js +400 -0
- package/dist/runtime/application/generation/GenerationOrchestrator.js +629 -0
- package/dist/runtime/application/generation/GenerationRuntime.js +214 -0
- package/dist/runtime/application/generation/PromptHybridWorldOrchestrator.js +285 -0
- package/dist/runtime/application/native-scene/CodeProject.js +119 -0
- package/dist/runtime/application/native-scene/CodeProjectModules.js +128 -0
- package/dist/runtime/application/native-scene/NativeEnvironmentGeometry.js +62 -0
- package/dist/runtime/application/native-scene/NativeOverlayCheckpoint.js +127 -0
- package/dist/runtime/application/native-scene/NativeRenderDiscovery.js +51 -0
- package/dist/runtime/application/native-scene/NativeSceneHost.js +319 -0
- package/dist/runtime/application/native-scene/NativeSceneOverlay.js +116 -0
- package/dist/runtime/application/native-scene/NativeThreeModule.js +16 -0
- package/dist/runtime/application/object-forge/SceneObjectForge.js +232 -0
- package/dist/runtime/application/programmatic-assets/ProgrammaticAssetBuilder.js +59 -0
- package/dist/runtime/application/programmatic-assets/ProgrammaticAssetContract.js +22 -0
- package/dist/runtime/application/programmatic-assets/ThreeCodeAsset.js +40 -0
- package/dist/runtime/application/scene/CapabilityResolver.js +79 -0
- package/dist/runtime/application/scene/RequestWindow.js +54 -0
- package/dist/runtime/application/scene/SceneAgentTools.js +21 -0
- package/dist/runtime/application/scene/SceneContracts.js +45 -0
- package/dist/runtime/application/scene/SceneEditService.js +144 -0
- package/dist/runtime/application/scene/SceneFacade.js +261 -0
- package/dist/runtime/application/scene/SceneInteractionAdapters.js +40 -0
- package/dist/runtime/application/scene/SceneJobController.js +229 -0
- package/dist/runtime/application/scene/SceneLifecycle.js +57 -0
- package/dist/runtime/application/scene/ScenePackage.js +162 -0
- package/dist/runtime/application/scene/ScenePersistence.js +50 -0
- package/dist/runtime/application/scene/SceneProject.js +95 -0
- package/dist/runtime/application/scene/SceneSkillNames.js +5 -0
- package/dist/runtime/application/scene/StarterScene.js +56 -0
- package/dist/runtime/application/scene/WorldArchive.js +87 -0
- package/dist/runtime/application/scene/WorldDirectory.js +20 -0
- package/dist/runtime/application/scene/WorldDocument.js +74 -0
- package/dist/runtime/application/scene/WorldIO.js +103 -0
- package/dist/runtime/application/scene/WorldStorage.js +137 -0
- package/dist/runtime/application/skills/SkillRegistry.js +189 -0
- package/dist/runtime/application/skills/packs/acceptanceSkills.js +32 -0
- package/dist/runtime/application/skills/packs/affordanceSkills.js +36 -0
- package/dist/runtime/application/skills/packs/assetSkills.js +46 -0
- package/dist/runtime/application/skills/packs/authoringSkills.js +16 -0
- package/dist/runtime/application/skills/packs/batchSkills.js +22 -0
- package/dist/runtime/application/skills/packs/codeSkills.js +106 -0
- package/dist/runtime/application/skills/packs/generationSkills.js +45 -0
- package/dist/runtime/application/skills/packs/interactionSkills.js +46 -0
- package/dist/runtime/application/skills/packs/recoverySkills.js +80 -0
- package/dist/runtime/application/skills/packs/sceneSkills.js +24 -0
- package/dist/runtime/application/skills/packs/spatialSkills.js +35 -0
- package/dist/runtime/application/skills/packs/verificationSkills.js +14 -0
- package/dist/runtime/application/skills/packs/worldSkills.js +45 -0
- package/dist/runtime/application/skills/registerCoreSkills.js +31 -0
- package/dist/runtime/application/skills/skillPrimitives.js +4 -0
- package/dist/runtime/application/tasks/CabinetCupTask.js +76 -0
- package/dist/runtime/application/tasks.jsonl +67 -0
- package/dist/runtime/application/world-authoring/AuthoringAssetProducer.js +42 -0
- package/dist/runtime/application/world-authoring/AuthoringDiff.js +149 -0
- package/dist/runtime/application/world-authoring/AuthoringDocument.js +825 -0
- package/dist/runtime/application/world-authoring/AuthoringExecutionHost.js +109 -0
- package/dist/runtime/application/world-authoring/AuthoringIdentity.js +17 -0
- package/dist/runtime/application/world-authoring/AuthoringModelResolver.js +29 -0
- package/dist/runtime/application/world-authoring/AuthoringPatch.js +118 -0
- package/dist/runtime/application/world-authoring/AuthoringPromotionController.js +334 -0
- package/dist/runtime/application/world-authoring/AuthoringPromotionSource.js +126 -0
- package/dist/runtime/application/world-authoring/AuthoringRevisionHistory.js +144 -0
- package/dist/runtime/application/world-authoring/HeadlessImageExport.js +174 -0
- package/dist/runtime/application/world-authoring/ModelRef.js +62 -0
- package/dist/runtime/apps/mcp-server/AUTHORING.md +71 -0
- package/dist/runtime/apps/mcp-server/AgentMcpCompat.js +77 -0
- package/dist/runtime/apps/mcp-server/AuthoringSandboxEntry.js +1 -0
- package/dist/runtime/apps/mcp-server/AuthoringSandboxWorker.mjs +30 -0
- package/dist/runtime/apps/mcp-server/BuildEnvironment.js +17 -0
- package/dist/runtime/apps/mcp-server/CodeExecutor.js +71 -0
- package/dist/runtime/apps/mcp-server/DEPLOYMENT-PC2.md +42 -0
- package/dist/runtime/apps/mcp-server/DockerBuildRunner.js +66 -0
- package/dist/runtime/apps/mcp-server/FileAssetRepository.js +159 -0
- package/dist/runtime/apps/mcp-server/HeadlessAssetIO.js +8 -0
- package/dist/runtime/apps/mcp-server/HeadlessGLTFLoader.js +47 -0
- package/dist/runtime/apps/mcp-server/HeadlessWorldHost.js +132 -0
- package/dist/runtime/apps/mcp-server/IsolatedAuthoringExecutor.js +6 -0
- package/dist/runtime/apps/mcp-server/PROGRAMMATIC-ASSETS.md +116 -0
- package/dist/runtime/apps/mcp-server/ProgrammaticAssets.js +60 -0
- package/dist/runtime/apps/mcp-server/README.md +150 -0
- package/dist/runtime/apps/mcp-server/RemoteAuthoringDocument.js +1 -0
- package/dist/runtime/apps/mcp-server/SandboxBundle.js +13 -0
- package/dist/runtime/apps/mcp-server/SessionManager.js +80 -0
- package/dist/runtime/apps/mcp-server/StudioBridgeHttp.js +58 -0
- package/dist/runtime/apps/mcp-server/StudioLiveBridge.js +190 -0
- package/dist/runtime/apps/mcp-server/TrustedAuthoringWorker.mjs +16 -0
- package/dist/runtime/apps/mcp-server/VALIDATION.md +45 -0
- package/dist/runtime/apps/mcp-server/acceptance-evidence.json +332 -0
- package/dist/runtime/apps/mcp-server/errorDiagnostics.js +32 -0
- package/dist/runtime/apps/mcp-server/examples/code-house.js +24 -0
- package/dist/runtime/apps/mcp-server/examples/procedural-assets.js +85 -0
- package/dist/runtime/apps/mcp-server/main.mjs +65 -0
- package/dist/runtime/apps/mcp-server/registerTools.js +225 -0
- package/dist/runtime/apps/mcp-server/sandbox/run.mjs +23 -0
- package/dist/runtime/apps/mcp-server/security.js +21 -0
- package/dist/runtime/apps/mcp-server/tasks.jsonl +9 -0
- package/dist/runtime/apps/server/CapabilityAdapterRegistry.js +157 -0
- package/dist/runtime/apps/server/README.md +7 -0
- package/dist/runtime/apps/server/WorldDiskStorage.js +51 -0
- package/dist/runtime/apps/server/openai-compatible-agent-gateway.mjs +278 -0
- package/dist/runtime/apps/server/tasks.jsonl +10 -0
- package/dist/runtime/foundation/EventBus.js +18 -0
- package/dist/runtime/foundation/JsonGateway.js +47 -0
- package/dist/runtime/foundation/PolicyEngine.js +21 -0
- package/dist/runtime/foundation/README.md +7 -0
- package/dist/runtime/foundation/TraceRecorder.js +76 -0
- package/dist/runtime/foundation/errors.js +8 -0
- package/dist/runtime/foundation/simulation/SimulationProfile.js +143 -0
- package/dist/runtime/foundation/version.js +2 -0
- package/dist/runtime/modules/agent/README.md +11 -0
- package/dist/runtime/modules/agent/ToolCallingAgent.js +19 -0
- package/dist/runtime/modules/agent/bootstrapWorld.js +10 -0
- package/dist/runtime/modules/agent/buildRecoveryProposals.js +533 -0
- package/dist/runtime/modules/agent/execution/AgentExecutionRules.js +128 -0
- package/dist/runtime/modules/agent/execution/AgentRunResults.js +55 -0
- package/dist/runtime/modules/agent/execution/AgentRunSession.js +393 -0
- package/dist/runtime/modules/agent/execution/AgentToolInvoker.js +40 -0
- package/dist/runtime/modules/agent/gateway/HttpLLMGateway.js +19 -0
- package/dist/runtime/modules/agent/prompt/index.js +52 -0
- package/dist/runtime/modules/agent/tasks.jsonl +94 -0
- package/dist/runtime/modules/artifact/ArtifactContentGate.js +144 -0
- package/dist/runtime/modules/artifact/ArtifactDescriptor.js +280 -0
- package/dist/runtime/modules/artifact/ArtifactImporter.js +185 -0
- package/dist/runtime/modules/artifact/ArtifactModule.js +111 -0
- package/dist/runtime/modules/artifact/ArtifactRegistry.js +197 -0
- package/dist/runtime/modules/artifact/IncrementalSha256.js +129 -0
- package/dist/runtime/modules/artifact/MemoryArtifactByteStore.js +115 -0
- package/dist/runtime/modules/artifact/README.md +7 -0
- package/dist/runtime/modules/artifact/storage/IndexedDbArtifactStore.js +67 -0
- package/dist/runtime/modules/artifact/tasks.jsonl +31 -0
- package/dist/runtime/modules/asset/AssetModule.js +399 -0
- package/dist/runtime/modules/asset/README.md +54 -0
- package/dist/runtime/modules/asset/loading/AssetLoader.js +157 -0
- package/dist/runtime/modules/asset/loading/GltfAssetLoader.js +61 -0
- package/dist/runtime/modules/asset/loading/builtins/BuiltinAssets.js +95 -0
- package/dist/runtime/modules/asset/loading/builtins/HouseDoor.js +33 -0
- package/dist/runtime/modules/asset/loading/builtins/IndustrialCabinet.js +103 -0
- package/dist/runtime/modules/asset/model/AssetInputContracts.js +100 -0
- package/dist/runtime/modules/asset/model/AssetRef.js +12 -0
- package/dist/runtime/modules/asset/model/MechanicalAssetDraft.js +172 -0
- package/dist/runtime/modules/asset/model/admission.js +117 -0
- package/dist/runtime/modules/asset/model/errors.js +6 -0
- package/dist/runtime/modules/asset/model/parts.js +27 -0
- package/dist/runtime/modules/asset/model/resourceBudget.js +10 -0
- package/dist/runtime/modules/asset/model/schema.js +150 -0
- package/dist/runtime/modules/asset/persistence/AssetManifestStore.js +78 -0
- package/dist/runtime/modules/asset/persistence/CompiledAssetStore.js +84 -0
- package/dist/runtime/modules/asset/persistence/LocalAssetLibrary.js +86 -0
- package/dist/runtime/modules/asset/persistence/LocalAssetLibraryStore.js +81 -0
- package/dist/runtime/modules/asset/production/AssetProductionPipeline.js +272 -0
- package/dist/runtime/modules/asset/production/AssetRecipe.js +47 -0
- package/dist/runtime/modules/asset/production/adapters/EmbodiedGenAdapter.js +45 -0
- package/dist/runtime/modules/asset/production/adapters/EmbodiedGenBundleAdapter.js +590 -0
- package/dist/runtime/modules/asset/production/compiler/AssetCompiler.js +173 -0
- package/dist/runtime/modules/asset/production/compiler/evidence/AnimationMotionEvidence.js +124 -0
- package/dist/runtime/modules/asset/production/compiler/evidence/StaticPanelEvidence.js +56 -0
- package/dist/runtime/modules/asset/production/compiler/gltfIO.js +6 -0
- package/dist/runtime/modules/asset/production/compiler/partGeometry.js +74 -0
- package/dist/runtime/modules/asset/production/compiler/passes/ArticulatedCollisionPass.js +63 -0
- package/dist/runtime/modules/asset/production/compiler/passes/ArticulationCandidatePass.js +48 -0
- package/dist/runtime/modules/asset/production/compiler/passes/AuthoringIntentPass.js +16 -0
- package/dist/runtime/modules/asset/production/compiler/passes/ColliderFallbackPass.js +30 -0
- package/dist/runtime/modules/asset/production/compiler/passes/CompileQualityPass.js +75 -0
- package/dist/runtime/modules/asset/production/compiler/passes/ExplicitDefinitionPass.js +20 -0
- package/dist/runtime/modules/asset/production/compiler/passes/GLTFInspectPass.js +34 -0
- package/dist/runtime/modules/asset/production/compiler/passes/GeometryPass.js +32 -0
- package/dist/runtime/modules/asset/production/compiler/passes/JointFramePass.js +116 -0
- package/dist/runtime/modules/asset/production/compiler/passes/KinematicEvidencePass.js +84 -0
- package/dist/runtime/modules/asset/production/compiler/passes/ManifestPass.js +63 -0
- package/dist/runtime/modules/asset/production/compiler/passes/NormalizeTransformPass.js +16 -0
- package/dist/runtime/modules/asset/production/compiler/passes/OptimizeGLBPass.js +23 -0
- package/dist/runtime/modules/asset/production/compiler/passes/PartColliderPass.js +50 -0
- package/dist/runtime/modules/asset/production/compiler/passes/PartGeometryEnrichmentPass.js +60 -0
- package/dist/runtime/modules/asset/production/compiler/passes/PartProposalPass.js +93 -0
- package/dist/runtime/modules/asset/production/compiler/passes/RemoteEnrichmentPass.js +32 -0
- package/dist/runtime/modules/asset/production/compiler/passes/ResourceBudgetPass.js +55 -0
- package/dist/runtime/modules/asset/production/compiler/passes/SegmentMaterializePass.js +203 -0
- package/dist/runtime/modules/asset/production/compiler/passes/SegmentationEvidencePass.js +43 -0
- package/dist/runtime/modules/asset/production/compiler/passes/SemanticHeuristicPass.js +33 -0
- package/dist/runtime/modules/asset/production/compiler/passes/StructurePass.js +60 -0
- package/dist/runtime/modules/asset/production/compiler/providers/HttpCompilerProvider.js +23 -0
- package/dist/runtime/modules/asset/production/verification/KinematicHypothesisScreen.js +198 -0
- package/dist/runtime/modules/asset/registry/AssetCatalog.js +72 -0
- package/dist/runtime/modules/asset/registry/AssetRegistry.js +51 -0
- package/dist/runtime/modules/asset/registry/manifests/index.js +173 -0
- package/dist/runtime/modules/asset/tasks.jsonl +87 -0
- package/dist/runtime/modules/generation/README.md +9 -0
- package/dist/runtime/modules/generation/connector/ConnectorArtifactClient.js +45 -0
- package/dist/runtime/modules/generation/connector/ConnectorCapabilityAdapter.js +169 -0
- package/dist/runtime/modules/generation/connector/ConnectorClient.js +192 -0
- package/dist/runtime/modules/generation/connector/ConnectorJobClient.js +167 -0
- package/dist/runtime/modules/generation/connector/ConnectorJobEventClient.js +179 -0
- package/dist/runtime/modules/generation/connector/ConnectorSession.js +202 -0
- package/dist/runtime/modules/generation/jobs/GenerationJobProjection.js +239 -0
- package/dist/runtime/modules/generation/jobs/GenerationJobReconciler.js +99 -0
- package/dist/runtime/modules/generation/jobs/GenerationJobStore.js +91 -0
- package/dist/runtime/modules/generation/jobs/GenerationJobTransportOverlay.js +50 -0
- package/dist/runtime/modules/generation/providers/ProviderRegistry.js +304 -0
- package/dist/runtime/modules/generation/tasks.jsonl +35 -0
- package/dist/runtime/modules/navigation/NavigationBackend.js +17 -0
- package/dist/runtime/modules/navigation/RecastNavigationBackend.js +245 -0
- package/dist/runtime/modules/physics/JoltPhysicsBackend.js +850 -0
- package/dist/runtime/modules/physics/PhysicsApiSurface.js +651 -0
- package/dist/runtime/modules/physics/PhysicsBackend.js +88 -0
- package/dist/runtime/modules/physics/RapierPhysicsBackend.js +410 -0
- package/dist/runtime/modules/rendering/README.md +7 -0
- package/dist/runtime/modules/rendering/RendererProbe.js +153 -0
- package/dist/runtime/modules/rendering/WebGpuPostFxPipeline.js +140 -0
- package/dist/runtime/modules/rendering/createRenderer.js +76 -0
- package/dist/runtime/modules/rendering/disposeObject3D.js +37 -0
- package/dist/runtime/modules/rendering/loadGaussianSplatVisual.js +74 -0
- package/dist/runtime/modules/rendering/spatial/ThreeBvhRuntime.js +107 -0
- package/dist/runtime/modules/rendering/style/StylePack.js +34 -0
- package/dist/runtime/modules/rendering/style/StyleSystem.js +173 -0
- package/dist/runtime/modules/rendering/tasks.jsonl +7 -0
- package/dist/runtime/modules/world/README.md +13 -0
- package/dist/runtime/modules/world/build/WorldBuilder.js +170 -0
- package/dist/runtime/modules/world/compiler/PipelineEngine.js +32 -0
- package/dist/runtime/modules/world/compiler/WorldAdmission.js +43 -0
- package/dist/runtime/modules/world/compiler/WorldBehaviorCompiler.js +68 -0
- package/dist/runtime/modules/world/compiler/WorldCompilation.js +157 -0
- package/dist/runtime/modules/world/compiler/WorldComposer.js +201 -0
- package/dist/runtime/modules/world/compiler/WorldPhysicsAdmission.js +76 -0
- package/dist/runtime/modules/world/compiler/WorldRecompiler.js +356 -0
- package/dist/runtime/modules/world/compiler/WorldRetry.js +75 -0
- package/dist/runtime/modules/world/compiler/createWorldPipeline.js +379 -0
- package/dist/runtime/modules/world/content/blankWorld.js +35 -0
- package/dist/runtime/modules/world/content/environments.js +84 -0
- package/dist/runtime/modules/world/content/grandUrbanBlock.js +189 -0
- package/dist/runtime/modules/world/content/magic-cabin/README.md +28 -0
- package/dist/runtime/modules/world/content/magic-cabin/affordances.js +64 -0
- package/dist/runtime/modules/world/content/magic-cabin/cabinContents.js +7078 -0
- package/dist/runtime/modules/world/content/magic-cabin/lighting.js +26 -0
- package/dist/runtime/modules/world/content/magic-cabin/materials.js +20 -0
- package/dist/runtime/modules/world/content/magicCabin.js +190 -0
- package/dist/runtime/modules/world/content/monumentHall.js +154 -0
- package/dist/runtime/modules/world/content/ruinedCourtyard.js +196 -0
- package/dist/runtime/modules/world/content/suzhouGarden/README.md +141 -0
- package/dist/runtime/modules/world/content/suzhouGarden/index.js +137 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/arch.js +491 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/buildings.js +670 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/core.js +578 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/lod.js +127 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/main.js +642 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/nature.js +650 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/rockery.js +280 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/sky.js +242 -0
- package/dist/runtime/modules/world/content/suzhouGarden/src/water.js +215 -0
- package/dist/runtime/modules/world/content/woodlandWorkshop.js +192 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/README.md +36 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/arch.js +351 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/buildings.js +490 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/core.js +505 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/index.js +101 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/nature.js +435 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/sky.js +169 -0
- package/dist/runtime/modules/world/content/yuanmingyuan/water.js +245 -0
- package/dist/runtime/modules/world/errors.js +9 -0
- package/dist/runtime/modules/world/generated/GeneratedWorldCoordinates.js +50 -0
- package/dist/runtime/modules/world/generated/GeneratedWorldLoader.js +297 -0
- package/dist/runtime/modules/world/runtime/CommandHistory.js +80 -0
- package/dist/runtime/modules/world/runtime/EntityCapabilityRegistry.js +150 -0
- package/dist/runtime/modules/world/runtime/ObjectStore.js +31 -0
- package/dist/runtime/modules/world/runtime/ObjectTransform.js +62 -0
- package/dist/runtime/modules/world/runtime/ObservedEntity.js +37 -0
- package/dist/runtime/modules/world/runtime/ProjectCapabilities.js +207 -0
- package/dist/runtime/modules/world/runtime/SceneSerializer.js +246 -0
- package/dist/runtime/modules/world/runtime/WorldAuthority.js +41 -0
- package/dist/runtime/modules/world/runtime/WorldCollisionSignature.js +14 -0
- package/dist/runtime/modules/world/runtime/WorldCommands.js +502 -0
- package/dist/runtime/modules/world/runtime/WorldObservation.js +71 -0
- package/dist/runtime/modules/world/runtime/WorldQueries.js +340 -0
- package/dist/runtime/modules/world/runtime/WorldRecovery.js +78 -0
- package/dist/runtime/modules/world/runtime/WorldRuntime.js +665 -0
- package/dist/runtime/modules/world/runtime/affordance/ObjectAffordances.js +107 -0
- package/dist/runtime/modules/world/runtime/affordance/WorldAffordances.js +130 -0
- package/dist/runtime/modules/world/runtime/behavior/BehaviorCompiler.js +79 -0
- package/dist/runtime/modules/world/runtime/behavior/ProjectStateMachine.js +195 -0
- package/dist/runtime/modules/world/runtime/behavior/RuleGraph.js +70 -0
- package/dist/runtime/modules/world/runtime/behavior/RuleRuntime.js +115 -0
- package/dist/runtime/modules/world/runtime/graph/SceneGraph.js +305 -0
- package/dist/runtime/modules/world/runtime/interaction/ArticulationRuntime.js +214 -0
- package/dist/runtime/modules/world/runtime/interaction/CarryCapability.js +65 -0
- package/dist/runtime/modules/world/runtime/interaction/CarryRuntime.js +222 -0
- package/dist/runtime/modules/world/runtime/interaction/InteractionApproach.js +130 -0
- package/dist/runtime/modules/world/runtime/interaction/InteractionContract.js +57 -0
- package/dist/runtime/modules/world/runtime/interaction/RecoveryRuntime.js +123 -0
- package/dist/runtime/modules/world/runtime/interaction/SettleRuntime.js +120 -0
- package/dist/runtime/modules/world/runtime/semantic/SemanticWorldView.js +102 -0
- package/dist/runtime/modules/world/runtime/simulation/SimulationClock.js +89 -0
- package/dist/runtime/modules/world/runtime/simulation/SimulationSession.js +99 -0
- package/dist/runtime/modules/world/runtime/simulation/ThermalSystem.js +269 -0
- package/dist/runtime/modules/world/runtime/spatial/SpatialSnapshot.js +56 -0
- package/dist/runtime/modules/world/runtime/systems/AudioSystem.js +125 -0
- package/dist/runtime/modules/world/runtime/systems/Instrument.js +38 -0
- package/dist/runtime/modules/world/runtime/systems/InteractionSystem.js +728 -0
- package/dist/runtime/modules/world/runtime/systems/LocomotionSystem.js +269 -0
- package/dist/runtime/modules/world/runtime/systems/NavigationSystem.js +469 -0
- package/dist/runtime/modules/world/runtime/systems/PhysicsSystem.js +1673 -0
- package/dist/runtime/modules/world/runtime/systems/RenderingSystem.js +457 -0
- package/dist/runtime/modules/world/runtime/systems/SpatialSystem.js +284 -0
- package/dist/runtime/modules/world/spec/WorldIR.js +165 -0
- package/dist/runtime/modules/world/spec/WorldIRToolSchema.js +86 -0
- package/dist/runtime/modules/world/spec/WorldPlannerProposal.js +51 -0
- package/dist/runtime/modules/world/spec/WorldRevision.js +231 -0
- package/dist/runtime/modules/world/spec/WorldSpec.js +86 -0
- package/dist/runtime/modules/world/tasks.jsonl +530 -0
- package/dist/runtime/modules/world/verification/ArticulationVerifier.js +254 -0
- package/dist/runtime/modules/world/verification/Finding.js +105 -0
- package/dist/runtime/modules/world/verification/InteractionEvidence.js +69 -0
- package/dist/runtime/modules/world/verification/RepairEngine.js +49 -0
- package/dist/runtime/modules/world/verification/WorldAcceptance.js +158 -0
- package/dist/runtime/modules/world/verification/WorldValidator.js +65 -0
- package/dist/runtime/package-lock.json +16048 -0
- package/dist/runtime/package.json +105 -0
- package/dist/runtime/public/assets/cabinet.glb +0 -0
- package/dist/runtime/public/assets/grand-urban-block/clean_asphalt_diff_1k.jpg +0 -0
- package/dist/runtime/public/assets/grand-urban-block/clean_asphalt_nor_gl_1k.jpg +0 -0
- package/dist/runtime/public/assets/grand-urban-block/concrete_pavement_diff_1k.jpg +0 -0
- package/dist/runtime/public/assets/grand-urban-block/urban_street_01_1k.hdr +0 -0
- package/dist/runtime/public/assets/monument-hall/marble_diff_1k.jpg +0 -0
- package/dist/runtime/public/assets/monument-hall/marble_nor_gl_1k.jpg +0 -0
- package/dist/runtime/public/assets/monument-hall/marble_rough_1k.jpg +0 -0
- package/dist/runtime/public/assets/monument-hall/solitude_interior_1k.hdr +0 -0
- package/dist/runtime/public/assets/ruined-courtyard/courtyard_1k.hdr +0 -0
- package/dist/runtime/public/assets/ruined-courtyard/mossy_cobblestone_diff_1k.jpg +0 -0
- package/dist/runtime/public/assets/ruined-courtyard/mossy_cobblestone_nor_gl_1k.jpg +0 -0
- package/dist/runtime/public/assets/ruined-courtyard/mossy_sandstone_diff_1k.jpg +0 -0
- package/dist/schema-BWpTl0Wj.js +359 -0
- package/dist/schema-BWpTl0Wj.js.map +1 -0
- package/dist/suzhouGarden-H9tiPgxq.js +6150 -0
- package/dist/suzhouGarden-H9tiPgxq.js.map +1 -0
- package/dist/woodlandWorkshop-D6zzSbHr.js +483 -0
- package/dist/woodlandWorkshop-D6zzSbHr.js.map +1 -0
- package/dist/yuanmingyuan-D6IHqjZ-.js +4955 -0
- package/dist/yuanmingyuan-D6IHqjZ-.js.map +1 -0
- package/package.json +70 -4
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
/* 地形、园路、植被、荷塘、残石与远景林带 */
|
|
2
|
+
import * as THREE from 'three';
|
|
3
|
+
import { mergeGeometries } from 'three/addons/utils/BufferGeometryUtils.js';
|
|
4
|
+
import { fbm, R, mulberry32, chamferBoxGeo, WORLD, POIS } from './core.js';
|
|
5
|
+
|
|
6
|
+
const clamp = (v, a, b) => v < a ? a : v > b ? b : v;
|
|
7
|
+
const smoothstep = (a, b, v) => { const t = clamp((v - a) / (b - a), 0, 1); return t * t * (3 - 2 * t); };
|
|
8
|
+
|
|
9
|
+
const LAKE_C = [18, 112], LAKE_R = [128, 42];
|
|
10
|
+
export function lakeShoreAngle(a) {
|
|
11
|
+
return 1 + 0.10 * Math.sin(a * 3 + 1.3) + 0.06 * Math.sin(a * 7 + 0.4)
|
|
12
|
+
+ 0.025 * Math.sin(a * 13 + 2.1);
|
|
13
|
+
}
|
|
14
|
+
export function lakeDepthFactor(x, z) {
|
|
15
|
+
const qx = (x - LAKE_C[0]) / LAKE_R[0], qz = (z - LAKE_C[1]) / LAKE_R[1];
|
|
16
|
+
const a = Math.atan2(qz, qx), d = Math.hypot(qx, qz);
|
|
17
|
+
return 1 - smoothstep(lakeShoreAngle(a) - 0.06, lakeShoreAngle(a) + 0.22, d);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function terrainHeight(x, z) {
|
|
21
|
+
const n = (fbm(x / 105 + 2.3, z / 105 + 4.1, 5, 4, 8) - 0.5) * 3.4;
|
|
22
|
+
const hillNW = 12 * Math.exp(-(((x + 205) / 88) ** 2 + ((z + 135) / 74) ** 2));
|
|
23
|
+
const hillE = 7 * Math.exp(-(((x - 228) / 74) ** 2 + ((z + 78) / 95) ** 2));
|
|
24
|
+
const xianfa = 6.5 * Math.exp(-(((x - 140) / 27) ** 2 + ((z + 36) / 24) ** 2));
|
|
25
|
+
const soft = (fbm(x / 36 + 8.2, z / 36 + 1.7, 23, 3, 8) - 0.5) * 0.5;
|
|
26
|
+
// 核心建筑区趋于平整
|
|
27
|
+
const fx = 1 - smoothstep(165, 215, Math.abs(x));
|
|
28
|
+
const fz = 1 - smoothstep(95, 145, Math.abs(z + 2));
|
|
29
|
+
const flat = fx * fz;
|
|
30
|
+
let h = (n + hillNW + hillE + xianfa + soft) * (1 - flat * 0.96);
|
|
31
|
+
h += flat * soft * 0.12;
|
|
32
|
+
h -= lakeDepthFactor(x, z) * 2.6;
|
|
33
|
+
return h;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const PATHS = [
|
|
37
|
+
[[-175, 22], [-120, 20], [-60, 22], [10, 20], [70, 20], [165, 16]],
|
|
38
|
+
[[40, -70], [40, -20], [40, 20], [40, 60], [40, 92]],
|
|
39
|
+
[[-72, -30], [-72, 10], [-70, 40], [-62, 62]],
|
|
40
|
+
[[-152, -30], [-152, 20], [-138, 30], [-110, 22]],
|
|
41
|
+
[[-20, 40], [0, 66], [18, 92], [50, 104], [100, 100]],
|
|
42
|
+
[[-118, -40], [-106, -10], [-100, 14]],
|
|
43
|
+
[[100, 20], [130, 6], [160, -12]],
|
|
44
|
+
];
|
|
45
|
+
function pathDist(x, z) {
|
|
46
|
+
let best = 1e9;
|
|
47
|
+
for (const seg of PATHS) {
|
|
48
|
+
for (let i = 0; i < seg.length - 1; i++) {
|
|
49
|
+
const [ax, az] = seg[i], [bx, bz] = seg[i + 1];
|
|
50
|
+
const dx = bx - ax, dz = bz - az;
|
|
51
|
+
const t = clamp(((x - ax) * dx + (z - az) * dz) / (dx * dx + dz * dz), 0, 1);
|
|
52
|
+
best = Math.min(best, Math.hypot(x - (ax + t * dx), z - (az + t * dz)));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return best;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const EXCLUDE = [
|
|
59
|
+
[-110, 110, -25, 25], // 大水法片区
|
|
60
|
+
[10, 70, -48, 24],
|
|
61
|
+
[-110, -34, -14, 16], // 海晏堂
|
|
62
|
+
[-105, -40, 30, 48], // 生肖钟
|
|
63
|
+
[-165, -115, -14, 24], // 谐奇趣
|
|
64
|
+
[-132, -104, -50, -30], // 方外观
|
|
65
|
+
[-180, -124, -26, 26], // 黄花阵
|
|
66
|
+
[122, 160, -24, 4], // 线法山
|
|
67
|
+
];
|
|
68
|
+
/* 预设机位与其视线走廊保持通透,避免树冠贴在镜头前 */
|
|
69
|
+
const SIGHTLINES = POIS.map(p => [p.pos[0], p.pos[2], p.target[0], p.target[2]]);
|
|
70
|
+
function sightDist(x, z) {
|
|
71
|
+
let best = 1e9;
|
|
72
|
+
for (const [ax, az, bx, bz] of SIGHTLINES) {
|
|
73
|
+
const dx = bx - ax, dz = bz - az;
|
|
74
|
+
const t = clamp(((x - ax) * dx + (z - az) * dz) / (dx * dx + dz * dz), 0, 1);
|
|
75
|
+
best = Math.min(best, Math.hypot(x - (ax + t * dx), z - (az + t * dz)));
|
|
76
|
+
}
|
|
77
|
+
return best;
|
|
78
|
+
}
|
|
79
|
+
function blocked(x, z, pad = 0) {
|
|
80
|
+
for (const [x1, x2, z1, z2] of EXCLUDE) if (x > x1 - pad && x < x2 + pad && z > z1 - pad && z < z2 + pad) return true;
|
|
81
|
+
if (lakeDepthFactor(x, z) > 0.12) return true;
|
|
82
|
+
if (pathDist(x, z) < 2.6) return true;
|
|
83
|
+
if (sightDist(x, z) < 8.5) return true;
|
|
84
|
+
for (const p of POIS) if (Math.hypot(x - p.pos[0], z - p.pos[2]) < 15) return true;
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function withColor(g, col) {
|
|
89
|
+
const geo = g.index ? g.toNonIndexed() : g;
|
|
90
|
+
const n = geo.getAttribute('position').count;
|
|
91
|
+
const arr = new Float32Array(n * 3);
|
|
92
|
+
for (let i = 0; i < n; i++) { arr[i * 3] = col[0]; arr[i * 3 + 1] = col[1]; arr[i * 3 + 2] = col[2]; }
|
|
93
|
+
geo.setAttribute('color', new THREE.Float32BufferAttribute(arr, 3));
|
|
94
|
+
return geo;
|
|
95
|
+
}
|
|
96
|
+
function treeGeometry(kind) {
|
|
97
|
+
const parts = [];
|
|
98
|
+
const trunk = new THREE.CylinderGeometry(0.19, 0.31, 3.6, 7, 1);
|
|
99
|
+
trunk.translate(0, 1.8, 0);
|
|
100
|
+
parts.push(withColor(trunk, [0.30, 0.22, 0.16]));
|
|
101
|
+
if (kind === 0) { // 国槐 / 银杏
|
|
102
|
+
const blobs = [
|
|
103
|
+
[0, 4.8, 0, 2.15], [1.5, 4.3, 0.5, 1.55], [-1.4, 4.6, -0.5, 1.6],
|
|
104
|
+
[0.5, 6.0, -1.0, 1.5], [-0.6, 5.8, 1.2, 1.45], [1.0, 5.5, 1.4, 1.2],
|
|
105
|
+
];
|
|
106
|
+
blobs.forEach(([x, y, z, r], i) => {
|
|
107
|
+
const g = new THREE.IcosahedronGeometry(r, 1);
|
|
108
|
+
g.scale(1, 0.86, 1); g.translate(x, y, z);
|
|
109
|
+
parts.push(withColor(g, [0.26 + (i % 3) * 0.035, 0.42 + (i % 4) * 0.035, 0.20 + (i % 2) * 0.02]));
|
|
110
|
+
});
|
|
111
|
+
for (let i = 0; i < 4; i++) {
|
|
112
|
+
const a = i / 4 * Math.PI * 2;
|
|
113
|
+
const g = new THREE.CylinderGeometry(0.06, 0.11, 1.7, 5);
|
|
114
|
+
g.rotateZ(Math.sin(a) * 0.6); g.rotateX(Math.cos(a) * 0.6);
|
|
115
|
+
g.translate(Math.cos(a) * 0.7, 3.2, Math.sin(a) * 0.7);
|
|
116
|
+
parts.push(withColor(g, [0.30, 0.22, 0.16]));
|
|
117
|
+
}
|
|
118
|
+
} else if (kind === 1) { // 松
|
|
119
|
+
for (let i = 0; i < 3; i++) {
|
|
120
|
+
const g = new THREE.ConeGeometry(2.3 - i * 0.5, 2.6, 9, 1);
|
|
121
|
+
g.translate(0, 3.0 + i * 1.5, 0);
|
|
122
|
+
parts.push(withColor(g, [0.15 + i * 0.02, 0.29 + i * 0.03, 0.17]));
|
|
123
|
+
}
|
|
124
|
+
} else { // 垂柳
|
|
125
|
+
const top = new THREE.IcosahedronGeometry(2.4, 1);
|
|
126
|
+
top.scale(1.3, 0.62, 1.3); top.translate(0, 4.9, 0);
|
|
127
|
+
parts.push(withColor(top, [0.31, 0.47, 0.23]));
|
|
128
|
+
for (let i = 0; i < 14; i++) {
|
|
129
|
+
const a = i / 14 * Math.PI * 2, r = 1.5 + (i % 3) * 0.35;
|
|
130
|
+
const g = new THREE.CylinderGeometry(0.035, 0.07, 3.3 + (i % 4) * 0.5, 4, 1);
|
|
131
|
+
g.translate(Math.cos(a) * r, 3.2, Math.sin(a) * r);
|
|
132
|
+
parts.push(withColor(g, [0.30, 0.46, 0.22]));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const merged = mergeGeometries(parts, false);
|
|
136
|
+
parts.forEach(p => p.dispose());
|
|
137
|
+
return merged;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/* 远景林带专用低模:仅主干 + 2 团树冠,约为近景树的 1/5 面数 */
|
|
141
|
+
function beltGeometry() {
|
|
142
|
+
const parts = [];
|
|
143
|
+
const trunk = new THREE.CylinderGeometry(0.18, 0.28, 3.4, 5, 1);
|
|
144
|
+
trunk.translate(0, 1.7, 0);
|
|
145
|
+
parts.push(withColor(trunk, [0.30, 0.22, 0.16]));
|
|
146
|
+
for (let i = 0; i < 2; i++) {
|
|
147
|
+
const g = new THREE.IcosahedronGeometry(i ? 1.6 : 2.0, 0);
|
|
148
|
+
g.scale(1, 0.9, 1);
|
|
149
|
+
g.translate(0, 3.7 + i * 1.5, 0);
|
|
150
|
+
parts.push(withColor(g, [0.22 + i * 0.04, 0.36 + i * 0.05, 0.21]));
|
|
151
|
+
}
|
|
152
|
+
const merged = mergeGeometries(parts, false);
|
|
153
|
+
parts.forEach(p => p.dispose());
|
|
154
|
+
return merged;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function grassTexture() {
|
|
158
|
+
// Server-side world initialization has no DOM. The actual grass blade
|
|
159
|
+
// texture is generated in the browser; physics/navigation only need geometry.
|
|
160
|
+
if (typeof document === 'undefined') {
|
|
161
|
+
const texture = new THREE.DataTexture(new Uint8Array([135, 159, 88, 255]), 1, 1);
|
|
162
|
+
texture.colorSpace = THREE.SRGBColorSpace;
|
|
163
|
+
texture.needsUpdate = true;
|
|
164
|
+
return texture;
|
|
165
|
+
}
|
|
166
|
+
const cv = document.createElement('canvas'); cv.width = cv.height = 64;
|
|
167
|
+
const c = cv.getContext('2d');
|
|
168
|
+
c.clearRect(0, 0, 64, 64);
|
|
169
|
+
for (let i = 0; i < 9; i++) {
|
|
170
|
+
const x = 6 + i * 6.5 + R() * 3, h = 26 + R() * 26;
|
|
171
|
+
const g = c.createLinearGradient(x, 64, x, 64 - h);
|
|
172
|
+
g.addColorStop(0, '#5c7138'); g.addColorStop(0.55, '#8ea354'); g.addColorStop(1, '#c8cd84');
|
|
173
|
+
c.fillStyle = g;
|
|
174
|
+
c.beginPath(); c.moveTo(x - 2.2, 64); c.quadraticCurveTo(x - 2, 64 - h * 0.6, x + (R() - 0.5) * 8, 64 - h);
|
|
175
|
+
c.quadraticCurveTo(x + 2.4, 64 - h * 0.55, x + 2.2, 64); c.closePath(); c.fill();
|
|
176
|
+
}
|
|
177
|
+
const t = new THREE.CanvasTexture(cv);
|
|
178
|
+
t.colorSpace = THREE.SRGBColorSpace;
|
|
179
|
+
return t;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export function createNature(scene, M, ctx) {
|
|
183
|
+
const group = new THREE.Group(); group.name = 'nature'; scene.add(group);
|
|
184
|
+
|
|
185
|
+
/* --- 地形 --- */
|
|
186
|
+
const [GW, GD] = WORLD.groundSize;
|
|
187
|
+
const tg = new THREE.PlaneGeometry(GW, GD, 168, 132);
|
|
188
|
+
tg.rotateX(-Math.PI / 2);
|
|
189
|
+
const pos = tg.getAttribute('position');
|
|
190
|
+
const colors = new Float32Array(pos.count * 3);
|
|
191
|
+
const cGrass = new THREE.Color().setRGB(0.76, 0.85, 0.52);
|
|
192
|
+
const cDry = new THREE.Color().setRGB(0.98, 0.88, 0.64);
|
|
193
|
+
const cPath = new THREE.Color().setRGB(1.10, 1.02, 0.86);
|
|
194
|
+
const cWet = new THREE.Color().setRGB(0.52, 0.60, 0.44);
|
|
195
|
+
const tmp = new THREE.Color();
|
|
196
|
+
for (let i = 0; i < pos.count; i++) {
|
|
197
|
+
const x = pos.getX(i), z = pos.getZ(i);
|
|
198
|
+
const h = terrainHeight(x, z);
|
|
199
|
+
pos.setY(i, h);
|
|
200
|
+
const n = fbm(x / 28 + 3.1, z / 28 + 7.4, 61, 4, 8);
|
|
201
|
+
tmp.copy(cGrass).lerp(cDry, clamp((n - 0.4) * 1.5, 0, 1));
|
|
202
|
+
const pd = pathDist(x, z);
|
|
203
|
+
tmp.lerp(cPath, (1 - smoothstep(2.2, 4.0, pd)) * 0.9);
|
|
204
|
+
const wet = lakeDepthFactor(x, z);
|
|
205
|
+
tmp.lerp(cWet, wet * 0.7);
|
|
206
|
+
tmp.multiplyScalar(0.94 + n * 0.22);
|
|
207
|
+
colors[i * 3] = tmp.r; colors[i * 3 + 1] = tmp.g; colors[i * 3 + 2] = tmp.b;
|
|
208
|
+
}
|
|
209
|
+
tg.setAttribute('color', new THREE.Float32BufferAttribute(colors, 3));
|
|
210
|
+
tg.computeVertexNormals();
|
|
211
|
+
const groundMat = M.ground.clone();
|
|
212
|
+
groundMat.vertexColors = true;
|
|
213
|
+
groundMat.map.wrapS = groundMat.map.wrapT = THREE.RepeatWrapping;
|
|
214
|
+
groundMat.map.repeat.set(1, 1);
|
|
215
|
+
const ground = new THREE.Mesh(tg, groundMat);
|
|
216
|
+
ground.receiveShadow = true;
|
|
217
|
+
ground.name = 'terrain';
|
|
218
|
+
group.add(ground);
|
|
219
|
+
|
|
220
|
+
/* --- 园路碎石与路缘 --- */
|
|
221
|
+
const pebbleGeo = new THREE.IcosahedronGeometry(0.24, 0);
|
|
222
|
+
const pebbleMat = new THREE.MeshStandardMaterial({ color: 0xa79c86, roughness: 1 });
|
|
223
|
+
const pebbles = new THREE.InstancedMesh(pebbleGeo, pebbleMat, 900);
|
|
224
|
+
const dummy = new THREE.Object3D();
|
|
225
|
+
for (let i = 0; i < 900; i++) {
|
|
226
|
+
let x, z, tries = 0;
|
|
227
|
+
do { x = (R() - 0.5) * 340; z = (R() - 0.5) * 200 + 8; tries++; } while (blocked(x, z, -1.5) && tries < 12);
|
|
228
|
+
dummy.position.set(x, terrainHeight(x, z) + 0.06, z);
|
|
229
|
+
dummy.rotation.set(R() * 3, R() * 6, R() * 3);
|
|
230
|
+
dummy.scale.setScalar(0.4 + R() * 1.1);
|
|
231
|
+
dummy.updateMatrix(); pebbles.setMatrixAt(i, dummy.matrix);
|
|
232
|
+
}
|
|
233
|
+
pebbles.castShadow = false; pebbles.receiveShadow = true;
|
|
234
|
+
group.add(pebbles);
|
|
235
|
+
|
|
236
|
+
/* --- 树木 --- */
|
|
237
|
+
const treeGeos = [treeGeometry(0), treeGeometry(1), treeGeometry(2)];
|
|
238
|
+
const treeMat = new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 0.95, side: THREE.FrontSide });
|
|
239
|
+
const positions = [[], [], []];
|
|
240
|
+
const rnd = mulberry32(990011);
|
|
241
|
+
for (let i = 0; i < 1350; i++) {
|
|
242
|
+
const x = (rnd() - 0.5) * 460, z = (rnd() - 0.5) * 350;
|
|
243
|
+
const dist = Math.hypot(x, z);
|
|
244
|
+
if (dist < 18 || dist > 250) continue;
|
|
245
|
+
if (blocked(x, z, 3)) continue;
|
|
246
|
+
if (rnd() < smoothstep(0, 90, dist) * 0.34) continue;
|
|
247
|
+
const nearWater = lakeDepthFactor(x + 7, z - 7) > 0.02 || Math.abs(z - 100) < 26;
|
|
248
|
+
const kind = nearWater && rnd() < 0.62 ? 2 : (rnd() < 0.26 ? 1 : 0);
|
|
249
|
+
positions[kind].push({ x, y: terrainHeight(x, z), z, s: 0.62 + rnd() * 0.55, rot: rnd() * 6.28, tint: 0.82 + rnd() * 0.36 });
|
|
250
|
+
}
|
|
251
|
+
const treeMeshes = [];
|
|
252
|
+
positions.forEach((list, k) => {
|
|
253
|
+
if (!list.length) return;
|
|
254
|
+
const mesh = new THREE.InstancedMesh(treeGeos[k], treeMat, list.length);
|
|
255
|
+
mesh.castShadow = true; mesh.receiveShadow = true;
|
|
256
|
+
list.sort(() => R() - 0.5);
|
|
257
|
+
list.forEach((p, i) => {
|
|
258
|
+
dummy.position.set(p.x, p.y, p.z);
|
|
259
|
+
dummy.rotation.set(0, p.rot, 0);
|
|
260
|
+
dummy.scale.setScalar(p.s);
|
|
261
|
+
dummy.updateMatrix(); mesh.setMatrixAt(i, dummy.matrix);
|
|
262
|
+
const tc = new THREE.Color().setRGB(p.tint, p.tint * (0.94 + R() * 0.12), p.tint * 0.93);
|
|
263
|
+
mesh.setColorAt(i, tc);
|
|
264
|
+
});
|
|
265
|
+
mesh.instanceMatrix.needsUpdate = true;
|
|
266
|
+
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
|
|
267
|
+
mesh.userData.fullCount = list.length;
|
|
268
|
+
mesh.userData.maxCount = list.length;
|
|
269
|
+
group.add(mesh);
|
|
270
|
+
treeMeshes.push(mesh);
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
/* --- 远景林带(不投影) --- */
|
|
274
|
+
const beltGeo = beltGeometry();
|
|
275
|
+
const belt = new THREE.InstancedMesh(beltGeo, treeMat, 300);
|
|
276
|
+
for (let i = 0; i < 300; i++) {
|
|
277
|
+
const a = (i / 300) * Math.PI * 2;
|
|
278
|
+
const rad = 238 + rnd() * 34;
|
|
279
|
+
const x = Math.cos(a) * rad, z = Math.sin(a) * rad * 0.78;
|
|
280
|
+
dummy.position.set(x, terrainHeight(x, z) - 0.3, z);
|
|
281
|
+
dummy.rotation.set(0, rnd() * 6.28, 0);
|
|
282
|
+
dummy.scale.setScalar(0.72 + rnd() * 0.62);
|
|
283
|
+
dummy.updateMatrix(); belt.setMatrixAt(i, dummy.matrix);
|
|
284
|
+
belt.setColorAt(i, new THREE.Color().setRGB(0.62 + rnd() * 0.25, 0.68 + rnd() * 0.22, 0.56 + rnd() * 0.2));
|
|
285
|
+
}
|
|
286
|
+
belt.castShadow = false; belt.receiveShadow = false;
|
|
287
|
+
belt.userData.fullCount = 300; belt.userData.maxCount = 300;
|
|
288
|
+
belt.instanceMatrix.needsUpdate = true;
|
|
289
|
+
group.add(belt);
|
|
290
|
+
treeMeshes.push(belt);
|
|
291
|
+
|
|
292
|
+
/* --- 草丛 --- */
|
|
293
|
+
const blade = new THREE.PlaneGeometry(0.72, 0.82);
|
|
294
|
+
blade.translate(0, 0.41, 0);
|
|
295
|
+
const blade2 = blade.clone(); blade2.rotateY(Math.PI / 2);
|
|
296
|
+
const grassGeo = mergeGeometries([blade.toNonIndexed(), blade2.toNonIndexed()], false);
|
|
297
|
+
const grassMat = new THREE.MeshStandardMaterial({
|
|
298
|
+
map: grassTexture(), alphaTest: 0.42, side: THREE.DoubleSide,
|
|
299
|
+
roughness: 1, transparent: false, depthWrite: true, color: 0xffffff,
|
|
300
|
+
});
|
|
301
|
+
// 顶点级距离 LOD:远处草簇收缩为零面积,免去无效 overdraw 与片元开销
|
|
302
|
+
grassMat.onBeforeCompile = shader => {
|
|
303
|
+
shader.uniforms.uFadeNear = { value: 62 };
|
|
304
|
+
shader.uniforms.uFadeFar = { value: 145 };
|
|
305
|
+
shader.vertexShader = shader.vertexShader
|
|
306
|
+
.replace('#include <common>', '#include <common>\nuniform float uFadeNear;\nuniform float uFadeFar;')
|
|
307
|
+
.replace('#include <begin_vertex>', `#include <begin_vertex>
|
|
308
|
+
#ifdef USE_INSTANCING
|
|
309
|
+
vec4 grassWorld = modelMatrix * instanceMatrix * vec4(transformed, 1.0);
|
|
310
|
+
#else
|
|
311
|
+
vec4 grassWorld = modelMatrix * vec4(transformed, 1.0);
|
|
312
|
+
#endif
|
|
313
|
+
float grassD = distance(grassWorld.xz, cameraPosition.xz);
|
|
314
|
+
transformed *= 1.0 - smoothstep(uFadeNear, uFadeFar, grassD);`);
|
|
315
|
+
grassMat.userData.shader = shader;
|
|
316
|
+
};
|
|
317
|
+
const grassCount = 9000;
|
|
318
|
+
const grass = new THREE.InstancedMesh(grassGeo, grassMat, grassCount);
|
|
319
|
+
let placed = 0, guard = 0;
|
|
320
|
+
while (placed < grassCount && guard < grassCount * 6) {
|
|
321
|
+
guard++;
|
|
322
|
+
const x = (R() - 0.5) * 340, z = (R() - 0.5) * 220 + 4;
|
|
323
|
+
if (blocked(x, z, 1)) continue;
|
|
324
|
+
const h = terrainHeight(x, z);
|
|
325
|
+
if (h < -0.4) continue;
|
|
326
|
+
dummy.position.set(x, h + 0.01, z);
|
|
327
|
+
dummy.rotation.set(0, R() * 6.28, 0);
|
|
328
|
+
dummy.scale.setScalar(0.55 + R() * 0.9);
|
|
329
|
+
dummy.updateMatrix(); grass.setMatrixAt(placed, dummy.matrix);
|
|
330
|
+
const g = 0.72 + R() * 0.5;
|
|
331
|
+
grass.setColorAt(placed, new THREE.Color().setRGB(g * 0.9, g, g * 0.68));
|
|
332
|
+
placed++;
|
|
333
|
+
}
|
|
334
|
+
grass.count = placed;
|
|
335
|
+
grass.castShadow = false; grass.receiveShadow = false;
|
|
336
|
+
grass.userData.fullCount = placed; grass.userData.maxCount = placed;
|
|
337
|
+
grass.instanceMatrix.needsUpdate = true;
|
|
338
|
+
group.add(grass);
|
|
339
|
+
|
|
340
|
+
/* --- 芦苇、荷叶、莲花 --- */
|
|
341
|
+
const reedGeo = mergeGeometries([
|
|
342
|
+
new THREE.CylinderGeometry(0.025, 0.045, 2.0, 4).translate(0, 1, 0).toNonIndexed(),
|
|
343
|
+
new THREE.CylinderGeometry(0.09, 0.07, 0.42, 6).translate(0, 2.1, 0).toNonIndexed(),
|
|
344
|
+
], false);
|
|
345
|
+
const reedMat = new THREE.MeshStandardMaterial({ color: 0x7b8a4a, roughness: 1 });
|
|
346
|
+
const reeds = new THREE.InstancedMesh(reedGeo, reedMat, 420);
|
|
347
|
+
const lilyMat = new THREE.MeshStandardMaterial({ color: 0x4c7040, roughness: 0.9, side: THREE.DoubleSide });
|
|
348
|
+
const lily = new THREE.InstancedMesh(new THREE.CircleGeometry(0.62, 10), lilyMat, 220);
|
|
349
|
+
const flowerMat = new THREE.MeshStandardMaterial({ color: 0xe8b7c2, roughness: 0.75 });
|
|
350
|
+
const flowers = new THREE.InstancedMesh(new THREE.IcosahedronGeometry(0.24, 0), flowerMat, 90);
|
|
351
|
+
let ri = 0, li = 0, fi = 0, rg = 0;
|
|
352
|
+
while ((ri < 420 || li < 220) && rg < 9000) {
|
|
353
|
+
rg++;
|
|
354
|
+
const a = R() * Math.PI * 2;
|
|
355
|
+
const edge = lakeShoreAngle(a) * (0.72 + R() * 0.32);
|
|
356
|
+
const x = LAKE_C[0] + Math.cos(a) * LAKE_R[0] * edge;
|
|
357
|
+
const z = LAKE_C[1] + Math.sin(a) * LAKE_R[1] * edge;
|
|
358
|
+
if (R() < 0.55 && ri < 420) {
|
|
359
|
+
dummy.position.set(x, -0.5, z); dummy.rotation.set((R() - 0.5) * 0.2, R() * 6.28, (R() - 0.5) * 0.2);
|
|
360
|
+
dummy.scale.setScalar(0.6 + R() * 0.75); dummy.updateMatrix(); reeds.setMatrixAt(ri++, dummy.matrix);
|
|
361
|
+
} else if (li < 220) {
|
|
362
|
+
dummy.position.set(x + (R() - 0.5) * 5, -0.52 + R() * 0.04, z + (R() - 0.5) * 4);
|
|
363
|
+
dummy.rotation.set(-Math.PI / 2, 0, R() * 6.28);
|
|
364
|
+
dummy.scale.setScalar(0.6 + R() * 0.7); dummy.updateMatrix(); lily.setMatrixAt(li++, dummy.matrix);
|
|
365
|
+
if (fi < 90 && R() < 0.42) {
|
|
366
|
+
dummy.position.y += 0.18; dummy.rotation.set(0, R() * 6.28, 0);
|
|
367
|
+
dummy.scale.setScalar(0.7 + R() * 0.8); dummy.updateMatrix(); flowers.setMatrixAt(fi++, dummy.matrix);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
reeds.count = ri; lily.count = li; flowers.count = fi;
|
|
372
|
+
[reeds, lily, flowers].forEach(m => { m.instanceMatrix.needsUpdate = true; m.castShadow = false; group.add(m); });
|
|
373
|
+
|
|
374
|
+
/* --- 散落残石与倾倒柱身 --- */
|
|
375
|
+
const rub = ctx.rubble;
|
|
376
|
+
const rubble = new THREE.InstancedMesh(chamferBoxGeo(1, 1, 1, 0.06), M.stone, rub.length);
|
|
377
|
+
rub.forEach((p, i) => {
|
|
378
|
+
dummy.position.set(p.pos[0], terrainHeight(p.pos[0], p.pos[2]) + p.s * 0.28, p.pos[2]);
|
|
379
|
+
dummy.rotation.set((R() - 0.5) * 0.7, p.rot, (R() - 0.5) * 0.7);
|
|
380
|
+
dummy.scale.set(p.s * (1 + R() * 0.7), p.s * (0.4 + R() * 0.5), p.s * (0.7 + R() * 0.6));
|
|
381
|
+
dummy.updateMatrix(); rubble.setMatrixAt(i, dummy.matrix);
|
|
382
|
+
});
|
|
383
|
+
rubble.castShadow = true; rubble.receiveShadow = true;
|
|
384
|
+
rubble.instanceMatrix.needsUpdate = true;
|
|
385
|
+
group.add(rubble);
|
|
386
|
+
const drums = new THREE.InstancedMesh(new THREE.CylinderGeometry(0.52, 0.52, 1.5, 14), M.marbleD, 26);
|
|
387
|
+
for (let i = 0; i < 26; i++) {
|
|
388
|
+
const nearHai = i < 13;
|
|
389
|
+
const a = R() * 6.28, rad = 12 + R() * 18;
|
|
390
|
+
const x = (nearHai ? -72 : 40) + Math.cos(a) * rad;
|
|
391
|
+
const z = (nearHai ? 8 : -2) + Math.sin(a) * rad * 0.6;
|
|
392
|
+
dummy.position.set(x, terrainHeight(x, z) + 0.5, z);
|
|
393
|
+
dummy.rotation.set(Math.PI / 2 + (R() - 0.5) * 0.35, R() * 6.28, R() * 0.5);
|
|
394
|
+
dummy.scale.setScalar(0.75 + R() * 0.5);
|
|
395
|
+
dummy.updateMatrix(); drums.setMatrixAt(i, dummy.matrix);
|
|
396
|
+
}
|
|
397
|
+
drums.castShadow = true; drums.receiveShadow = true;
|
|
398
|
+
drums.instanceMatrix.needsUpdate = true;
|
|
399
|
+
group.add(drums);
|
|
400
|
+
|
|
401
|
+
/* --- 湖畔石桥 --- */
|
|
402
|
+
const bridge = new THREE.Group();
|
|
403
|
+
const stone = M.marbleD;
|
|
404
|
+
for (let i = 0; i < 9; i++) {
|
|
405
|
+
const bx = 62 + i * 3.1;
|
|
406
|
+
const arch = Math.sin((i / 8) * Math.PI) * 1.4;
|
|
407
|
+
const seg = new THREE.Mesh(boxGeoProxy(3.2, 0.32, 3.4), stone);
|
|
408
|
+
seg.position.set(bx, -0.1 + arch, 92);
|
|
409
|
+
seg.castShadow = true; seg.receiveShadow = true;
|
|
410
|
+
bridge.add(seg);
|
|
411
|
+
}
|
|
412
|
+
for (const s of [-1, 1]) for (let i = 0; i < 9; i++) {
|
|
413
|
+
const rail = new THREE.Mesh(boxGeoProxy(3.2, 0.12, 0.18), stone);
|
|
414
|
+
rail.position.set(62 + i * 3.1, 0.65 + Math.sin((i / 8) * Math.PI) * 1.4, 92 + s * 1.7);
|
|
415
|
+
bridge.add(rail);
|
|
416
|
+
const post = new THREE.Mesh(boxGeoProxy(0.22, 0.72, 0.22), stone);
|
|
417
|
+
post.position.set(62 + i * 3.1, 0.5 + Math.sin((i / 8) * Math.PI) * 1.4, 92 + s * 1.7);
|
|
418
|
+
bridge.add(post);
|
|
419
|
+
}
|
|
420
|
+
group.add(bridge);
|
|
421
|
+
|
|
422
|
+
return {
|
|
423
|
+
group, ground, treeMeshes, grass, reeds, lily, flowers, pebbles,
|
|
424
|
+
applyQuality(q) {
|
|
425
|
+
treeMeshes.forEach(m => { m.count = Math.max(1, Math.floor(m.userData.maxCount * q.trees)); });
|
|
426
|
+
grass.count = Math.min(grass.userData.maxCount, q.grass);
|
|
427
|
+
const sh = grassMat.userData.shader;
|
|
428
|
+
if (sh) { sh.uniforms.uFadeNear.value = q.fadeFar * 0.42; sh.uniforms.uFadeFar.value = q.fadeFar; }
|
|
429
|
+
groundMat.map.anisotropy = q.aniso;
|
|
430
|
+
groundMat.map.needsUpdate = true;
|
|
431
|
+
},
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
function boxGeoProxy(w, h, d) { return new THREE.BoxGeometry(w, h, d); }
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/* 天空、云层、黄金时刻日照与大气雾 */
|
|
2
|
+
import * as THREE from 'three';
|
|
3
|
+
|
|
4
|
+
const SKY_VERT = `
|
|
5
|
+
varying vec3 vDir;
|
|
6
|
+
void main() {
|
|
7
|
+
vDir = normalize(position);
|
|
8
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
9
|
+
}`;
|
|
10
|
+
|
|
11
|
+
const SKY_FRAG = `
|
|
12
|
+
precision highp float;
|
|
13
|
+
varying vec3 vDir;
|
|
14
|
+
uniform vec3 uSunDir;
|
|
15
|
+
uniform vec3 uSunColor;
|
|
16
|
+
uniform vec3 uZenith;
|
|
17
|
+
uniform vec3 uHorizon;
|
|
18
|
+
uniform float uTime;
|
|
19
|
+
uniform float uHaze;
|
|
20
|
+
|
|
21
|
+
float hash(vec2 p){ return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453123); }
|
|
22
|
+
float noise(vec2 p){
|
|
23
|
+
vec2 i = floor(p), f = fract(p);
|
|
24
|
+
vec2 u = f*f*(3.0-2.0*f);
|
|
25
|
+
return mix(mix(hash(i), hash(i+vec2(1.0,0.0)), u.x),
|
|
26
|
+
mix(hash(i+vec2(0.0,1.0)), hash(i+vec2(1.0,1.0)), u.x), u.y);
|
|
27
|
+
}
|
|
28
|
+
float fbm(vec2 p){
|
|
29
|
+
float v = 0.0, a = 0.5;
|
|
30
|
+
for(int i=0;i<5;i++){ v += a*noise(p); p *= 2.03; a *= 0.5; }
|
|
31
|
+
return v;
|
|
32
|
+
}
|
|
33
|
+
void main() {
|
|
34
|
+
vec3 d = normalize(vDir);
|
|
35
|
+
float h = max(d.y, 0.0);
|
|
36
|
+
vec3 col = mix(uHorizon, uZenith, pow(h, 0.62));
|
|
37
|
+
// 地平线暖色带与大气散射
|
|
38
|
+
float glowBand = exp(-h * 9.0);
|
|
39
|
+
col = mix(col, uHorizon * 1.06, glowBand * 0.55);
|
|
40
|
+
float sd = max(dot(d, normalize(uSunDir)), 0.0);
|
|
41
|
+
col += uSunColor * pow(sd, 7.0) * 0.22 * uHaze;
|
|
42
|
+
col += uSunColor * pow(sd, 130.0) * 0.85;
|
|
43
|
+
col += uSunColor * pow(sd, 2600.0) * 7.0;
|
|
44
|
+
// 卷积云:以方向投影到云层平面
|
|
45
|
+
vec2 cp = d.xz / max(d.y + 0.14, 0.05);
|
|
46
|
+
float n = fbm(cp * 0.20 + vec2(uTime * 0.0025, uTime * 0.0012));
|
|
47
|
+
float n2 = fbm(cp * 0.62 + vec2(-uTime * 0.003, 0.0));
|
|
48
|
+
float cloud = smoothstep(0.48, 0.68, n * 0.78 + n2 * 0.22) * smoothstep(-0.01, 0.10, h);
|
|
49
|
+
vec3 cloudCol = mix(uHorizon * 1.02, vec3(1.0, 0.97, 0.92), 0.35 + pow(sd, 4.0) * 0.5);
|
|
50
|
+
col = mix(col, cloudCol, cloud * 0.55);
|
|
51
|
+
// 贴地薄雾
|
|
52
|
+
col = mix(col, uHorizon, exp(-max(d.y, -0.05) * 22.0) * 0.32);
|
|
53
|
+
gl_FragColor = vec4(col, 1.0);
|
|
54
|
+
#include <tonemapping_fragment>
|
|
55
|
+
#include <colorspace_fragment>
|
|
56
|
+
}`;
|
|
57
|
+
|
|
58
|
+
const KEYS = [
|
|
59
|
+
{ h: 5.5, zen: '#3c5480', hor: '#d99a76', sun: '#ff9a5e', inten: 0.5, expo: 0.78, hemi: 0.35 },
|
|
60
|
+
{ h: 8, zen: '#4a7db5', hor: '#ddc6a6', sun: '#ffd9a3', inten: 2.7, expo: 1.02, hemi: 0.56 },
|
|
61
|
+
{ h: 12, zen: '#3974bb', hor: '#c6dbe9', sun: '#fff4e2', inten: 3.8, expo: 1.08, hemi: 0.70 },
|
|
62
|
+
{ h: 16.4, zen: '#4d79ab', hor: '#d7b18c', sun: '#ffcf94', inten: 3.5, expo: 1.16, hemi: 0.60 },
|
|
63
|
+
{ h: 18.3, zen: '#3f5482', hor: '#d98b69', sun: '#ff945c', inten: 1.15, expo: 0.98, hemi: 0.42 },
|
|
64
|
+
{ h: 19.6, zen: '#222f55', hor: '#7d5a68', sun: '#ff7b52', inten: 0.22, expo: 0.85, hemi: 0.28 },
|
|
65
|
+
];
|
|
66
|
+
|
|
67
|
+
const c = hex => new THREE.Color(hex);
|
|
68
|
+
|
|
69
|
+
export function createSky(scene, renderer) {
|
|
70
|
+
const uniforms = {
|
|
71
|
+
uSunDir: { value: new THREE.Vector3(-0.6, 0.4, 0.5) },
|
|
72
|
+
uSunColor: { value: c('#ffc78a') },
|
|
73
|
+
uZenith: { value: c('#6287b4') },
|
|
74
|
+
uHorizon: { value: c('#e9bd8b') },
|
|
75
|
+
uTime: { value: 0 },
|
|
76
|
+
uHaze: { value: 1 },
|
|
77
|
+
};
|
|
78
|
+
const sky = new THREE.Mesh(
|
|
79
|
+
new THREE.SphereGeometry(1400, 40, 22),
|
|
80
|
+
new THREE.ShaderMaterial({
|
|
81
|
+
uniforms, vertexShader: SKY_VERT, fragmentShader: SKY_FRAG,
|
|
82
|
+
side: THREE.BackSide, depthWrite: false, fog: false,
|
|
83
|
+
})
|
|
84
|
+
);
|
|
85
|
+
sky.renderOrder = -1000;
|
|
86
|
+
sky.frustumCulled = false;
|
|
87
|
+
scene.add(sky);
|
|
88
|
+
|
|
89
|
+
const sun = new THREE.DirectionalLight(0xffc78a, 3.05);
|
|
90
|
+
sun.castShadow = true;
|
|
91
|
+
sun.shadow.mapSize.set(4096, 4096);
|
|
92
|
+
const sc = sun.shadow.camera;
|
|
93
|
+
sc.left = -125; sc.right = 125; sc.top = 125; sc.bottom = -125;
|
|
94
|
+
sc.near = 1; sc.far = 520;
|
|
95
|
+
sun.shadow.bias = -0.00035;
|
|
96
|
+
sun.shadow.normalBias = 0.035;
|
|
97
|
+
sun.shadow.radius = 2.2;
|
|
98
|
+
sun.target.position.set(-10, 0, 0);
|
|
99
|
+
scene.add(sun, sun.target);
|
|
100
|
+
|
|
101
|
+
const hemi = new THREE.HemisphereLight(0xbdd6ea, 0x9a8160, 0.66);
|
|
102
|
+
scene.add(hemi);
|
|
103
|
+
// 微弱环境光托起背光立面的暗部,避免深阴影形成纯黑块
|
|
104
|
+
const ambient = new THREE.AmbientLight(0xc9d4dd, 0.42);
|
|
105
|
+
scene.add(ambient);
|
|
106
|
+
const fill = new THREE.DirectionalLight(0x9dbcd8, 0.55);
|
|
107
|
+
fill.position.set(90, 70, -100);
|
|
108
|
+
scene.add(fill);
|
|
109
|
+
|
|
110
|
+
const fog = new THREE.FogExp2(0xd8c4ac, 0.00155);
|
|
111
|
+
scene.fog = fog;
|
|
112
|
+
|
|
113
|
+
const lamps = [];
|
|
114
|
+
[[-72, 6, 12], [40, 4, 6], [40, 6, -28], [-138, 5, 12]].forEach(([x, y, z]) => {
|
|
115
|
+
const p = new THREE.PointLight(0xffb56b, 0, 26, 2);
|
|
116
|
+
p.position.set(x, y, z);
|
|
117
|
+
scene.add(p);
|
|
118
|
+
lamps.push(p);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
const api = {
|
|
122
|
+
uniforms, sun, hemi, fill, fog, sky, lamps,
|
|
123
|
+
sunDir: new THREE.Vector3(),
|
|
124
|
+
setHour(hour) {
|
|
125
|
+
const t = Math.min(Math.max(hour, KEYS[0].h), KEYS[KEYS.length - 1].h);
|
|
126
|
+
let i = 0;
|
|
127
|
+
while (i < KEYS.length - 2 && t > KEYS[i + 1].h) i++;
|
|
128
|
+
const a = KEYS[i], b = KEYS[i + 1];
|
|
129
|
+
const k = (t - a.h) / (b.h - a.h);
|
|
130
|
+
const lerpC = (ca, cb) => c(ca).lerp(c(cb), k);
|
|
131
|
+
const zen = lerpC(a.zen, b.zen), hor = lerpC(a.hor, b.hor), sunC = lerpC(a.sun, b.sun);
|
|
132
|
+
uniforms.uZenith.value.copy(zen);
|
|
133
|
+
uniforms.uHorizon.value.copy(hor);
|
|
134
|
+
uniforms.uSunColor.value.copy(sunC);
|
|
135
|
+
const p = (t - 6) / 12;
|
|
136
|
+
const elev = Math.sin(Math.max(0, Math.min(1, p)) * Math.PI) * 0.86 + 0.045;
|
|
137
|
+
const az = Math.PI * (0.12 + Math.max(0, Math.min(1, p)) * 0.74);
|
|
138
|
+
const dir = new THREE.Vector3(Math.cos(az), elev, Math.sin(az) * 0.72).normalize();
|
|
139
|
+
api.sunDir.copy(dir);
|
|
140
|
+
uniforms.uSunDir.value.copy(dir);
|
|
141
|
+
sun.position.copy(dir).multiplyScalar(210);
|
|
142
|
+
sun.target.position.set(-10, 0, 0);
|
|
143
|
+
sun.color.copy(sunC);
|
|
144
|
+
sun.intensity = THREE.MathUtils.lerp(a.inten, b.inten, k);
|
|
145
|
+
hemi.intensity = THREE.MathUtils.lerp(a.hemi, b.hemi, k);
|
|
146
|
+
hemi.color.copy(zen).lerp(c('#dce9f2'), 0.45);
|
|
147
|
+
fill.intensity = 0.46 + (1 - elev) * 0.38;
|
|
148
|
+
renderer.toneMappingExposure = THREE.MathUtils.lerp(a.expo, b.expo, k);
|
|
149
|
+
fog.color.copy(hor).lerp(zen, 0.24);
|
|
150
|
+
fog.density = 0.00092 + (1 - elev) * 0.00048;
|
|
151
|
+
uniforms.uHaze.value = 0.55 + (1 - elev) * 0.85;
|
|
152
|
+
const dusk = THREE.MathUtils.clamp((18.1 - t) / 2.2, 0, 1) * THREE.MathUtils.clamp((t - 16.8) / 1.6, 0, 1);
|
|
153
|
+
lamps.forEach(l => { l.intensity = dusk * 16; });
|
|
154
|
+
api.dusk = dusk;
|
|
155
|
+
renderer.shadowMap.needsUpdate = true;
|
|
156
|
+
},
|
|
157
|
+
setShadowSize(size) {
|
|
158
|
+
if (sun.shadow.mapSize.x === size) return;
|
|
159
|
+
sun.shadow.mapSize.set(size, size);
|
|
160
|
+
if (sun.shadow.map) { sun.shadow.map.dispose(); sun.shadow.map = null; }
|
|
161
|
+
renderer.shadowMap.needsUpdate = true;
|
|
162
|
+
},
|
|
163
|
+
update(dt, camera) {
|
|
164
|
+
uniforms.uTime.value += dt;
|
|
165
|
+
sky.position.copy(camera.position);
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
return api;
|
|
169
|
+
}
|