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,642 @@
|
|
|
1
|
+
/* 吴苑澄观 · 主程序
|
|
2
|
+
* 渲染器 / 后处理、分阶段加载、双模式漫游、12 个定点观察视角、
|
|
3
|
+
* 景点标注、小地图、性能 HUD、画质与天气自适应。
|
|
4
|
+
*/
|
|
5
|
+
import * as THREE from 'three';
|
|
6
|
+
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
|
|
7
|
+
import { EffectComposer } from 'three/addons/postprocessing/EffectComposer.js';
|
|
8
|
+
import { RenderPass } from 'three/addons/postprocessing/RenderPass.js';
|
|
9
|
+
import { UnrealBloomPass } from 'three/addons/postprocessing/UnrealBloomPass.js';
|
|
10
|
+
import { ShaderPass } from 'three/addons/postprocessing/ShaderPass.js';
|
|
11
|
+
import { OutputPass } from 'three/addons/postprocessing/OutputPass.js';
|
|
12
|
+
import {
|
|
13
|
+
WORLD, QUALITY, POIS, HOTSPOTS, LOD_LEVELS,
|
|
14
|
+
buildTextures, buildMaterials, Batch, waterSDF, terrainHeight, clamp,
|
|
15
|
+
} from './core.js';
|
|
16
|
+
import { buildBuildings } from './buildings.js';
|
|
17
|
+
import { buildRockery } from './rockery.js';
|
|
18
|
+
import { createWater } from './water.js';
|
|
19
|
+
import { createNature } from './nature.js';
|
|
20
|
+
import { createSky } from './sky.js';
|
|
21
|
+
import { LODManager } from './lod.js';
|
|
22
|
+
|
|
23
|
+
const $ = s => document.querySelector(s);
|
|
24
|
+
const $$ = s => Array.from(document.querySelectorAll(s));
|
|
25
|
+
const nextFrame = () => new Promise(r => requestAnimationFrame(() => setTimeout(r, 0)));
|
|
26
|
+
const lerp = THREE.MathUtils.lerp;
|
|
27
|
+
|
|
28
|
+
/* 电影调色:轻微 S 曲线、冷暖分离、暗角与胶片颗粒 */
|
|
29
|
+
const GradeShader = {
|
|
30
|
+
uniforms: {
|
|
31
|
+
tDiffuse: { value: null }, uTime: { value: 0 },
|
|
32
|
+
uResolution: { value: new THREE.Vector2(1, 1) }, uStrength: { value: 1 },
|
|
33
|
+
},
|
|
34
|
+
vertexShader: `varying vec2 vUv; void main(){ vUv = uv; gl_Position = projectionMatrix * modelViewMatrix * vec4(position,1.0); }`,
|
|
35
|
+
fragmentShader: `
|
|
36
|
+
precision highp float;
|
|
37
|
+
uniform sampler2D tDiffuse; uniform float uTime; uniform vec2 uResolution; uniform float uStrength;
|
|
38
|
+
varying vec2 vUv;
|
|
39
|
+
void main(){
|
|
40
|
+
vec3 c = texture2D(tDiffuse, vUv).rgb;
|
|
41
|
+
vec3 o = c;
|
|
42
|
+
c = clamp((c - 0.5) * 1.052 + 0.5, 0.0, 1.0);
|
|
43
|
+
float l = dot(c, vec3(0.2126, 0.7152, 0.0722));
|
|
44
|
+
c += vec3(0.015, 0.005, -0.012) * smoothstep(0.55, 1.0, l);
|
|
45
|
+
c += vec3(-0.007, 0.001, 0.016) * (1.0 - smoothstep(0.0, 0.45, l));
|
|
46
|
+
vec2 q = vUv - 0.5;
|
|
47
|
+
c *= 1.0 - dot(q, q) * 0.46;
|
|
48
|
+
float g = fract(sin(dot(vUv * uResolution + uTime * 29.0, vec2(12.9898, 78.233))) * 43758.5453);
|
|
49
|
+
c += (g - 0.5) * 0.009;
|
|
50
|
+
gl_FragColor = vec4(mix(o, c, uStrength), 1.0);
|
|
51
|
+
}`,
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
function guessInitialQuality() {
|
|
55
|
+
const p = new URLSearchParams(location.search);
|
|
56
|
+
const forced = p.get('q');
|
|
57
|
+
if (QUALITY[forced]) return forced;
|
|
58
|
+
const dpr = window.devicePixelRatio || 1;
|
|
59
|
+
const cores = navigator.hardwareConcurrency || 4;
|
|
60
|
+
const mem = navigator.deviceMemory || 4;
|
|
61
|
+
const area = window.innerWidth * window.innerHeight;
|
|
62
|
+
if (cores <= 2 || mem <= 2 || /Android|iPhone|iPad/i.test(navigator.userAgent)) return 'low';
|
|
63
|
+
if (cores <= 4 || mem <= 4 || area > 2600000 || dpr > 2.5) return 'medium';
|
|
64
|
+
return 'high';
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const state = {
|
|
68
|
+
quality: guessInitialQuality(), auto: true, walk: false, labels: true,
|
|
69
|
+
hour: WORLD.sunDefaultHour, weather: 'clear', poi: 'overview',
|
|
70
|
+
fps: 60, frames: 0, acc: 0, lowFor: 0, highFor: 0, cooldown: 0,
|
|
71
|
+
started: false, lodViz: false, lodVizParam: new URLSearchParams(location.search).get('lod') === '1',
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
let renderer, scene, camera, controls, composer, bloomPass, gradePass, outputPass, renderPass;
|
|
75
|
+
let sky, water, nature, lod, mainGroup, plaques = [], labelEls = [], gpuTimer = null;
|
|
76
|
+
let tween = null, toastTimer = null;
|
|
77
|
+
let labelT = 0, mapT = 0;
|
|
78
|
+
const keys = new Set();
|
|
79
|
+
const clock = new THREE.Clock();
|
|
80
|
+
const walkState = { yaw: 0, pitch: -0.10, eye: 1.70, vx: 0, vz: 0, locked: false };
|
|
81
|
+
|
|
82
|
+
function progress(p, text) {
|
|
83
|
+
const bar = $('#load-bar'), pct = $('#load-pct'), label = $('#load-label');
|
|
84
|
+
if (bar) bar.style.width = `${Math.round(p * 100)}%`;
|
|
85
|
+
if (pct) pct.textContent = `${Math.round(p * 100)}%`;
|
|
86
|
+
if (label) label.textContent = text;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/* ================================================================== *
|
|
90
|
+
* 启动
|
|
91
|
+
* ================================================================== */
|
|
92
|
+
async function boot() {
|
|
93
|
+
const canvas = $('#scene');
|
|
94
|
+
renderer = new THREE.WebGLRenderer({ canvas, antialias: true, powerPreference: 'high-performance', stencil: false });
|
|
95
|
+
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, QUALITY[state.quality].dpr));
|
|
96
|
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
|
97
|
+
renderer.outputColorSpace = THREE.SRGBColorSpace;
|
|
98
|
+
renderer.toneMapping = THREE.ACESFilmicToneMapping;
|
|
99
|
+
renderer.toneMappingExposure = 1.08;
|
|
100
|
+
renderer.shadowMap.enabled = true;
|
|
101
|
+
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
|
|
102
|
+
renderer.shadowMap.autoUpdate = false; // 静态场景:仅时辰 / 画质变化时重绘阴影
|
|
103
|
+
renderer.shadowMap.needsUpdate = true;
|
|
104
|
+
renderer.info.autoReset = false;
|
|
105
|
+
|
|
106
|
+
scene = new THREE.Scene();
|
|
107
|
+
camera = new THREE.PerspectiveCamera(POIS[0].fov, window.innerWidth / window.innerHeight, 0.1, 3200);
|
|
108
|
+
camera.position.set(...POIS[0].pos);
|
|
109
|
+
camera.lookAt(...POIS[0].target);
|
|
110
|
+
|
|
111
|
+
progress(0.04, '初始化渲染器与相机');
|
|
112
|
+
await nextFrame();
|
|
113
|
+
|
|
114
|
+
/* 材质贴图集 */
|
|
115
|
+
progress(0.09, '生成白粉墙 / 黛瓦 / 太湖石等 PBR 纹理');
|
|
116
|
+
await nextFrame();
|
|
117
|
+
const T = buildTextures((p, k) => progress(0.09 + p * 0.17, `生成程序化材质:${k}`), QUALITY[state.quality].texScale);
|
|
118
|
+
const M = buildMaterials(T);
|
|
119
|
+
T && Object.values(T).forEach(t => {
|
|
120
|
+
t.map.anisotropy = QUALITY[state.quality].aniso;
|
|
121
|
+
t.normalMap.anisotropy = QUALITY[state.quality].aniso;
|
|
122
|
+
t.roughnessMap.anisotropy = QUALITY[state.quality].aniso;
|
|
123
|
+
});
|
|
124
|
+
await nextFrame();
|
|
125
|
+
|
|
126
|
+
/* 天空与光照 */
|
|
127
|
+
progress(0.28, '布置江南午后天光、软阴影与大气雾');
|
|
128
|
+
await nextFrame();
|
|
129
|
+
sky = createSky(scene, renderer, M);
|
|
130
|
+
sky.setHour(state.hour);
|
|
131
|
+
sky.setQuality(QUALITY[state.quality]);
|
|
132
|
+
|
|
133
|
+
/* 分批构建:建筑 → 假山 → 植被 → 水体 */
|
|
134
|
+
lod = new LODManager(camera, scene);
|
|
135
|
+
lod.setQuality(QUALITY[state.quality]);
|
|
136
|
+
const B = new Batch(40);
|
|
137
|
+
mainGroup = new THREE.Group(); mainGroup.name = '园林静态几何'; scene.add(mainGroup);
|
|
138
|
+
const ctx = {
|
|
139
|
+
B, M, scene, plaques, lod, BatchClass: Batch, quality: QUALITY[state.quality],
|
|
140
|
+
waterfalls: [], streams: [],
|
|
141
|
+
onProgress: (p, name) => progress(0.31 + p * 0.25, `构建建筑:${name}`),
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
progress(0.31, '构建中轴礼序与九大景区建筑群');
|
|
145
|
+
await nextFrame();
|
|
146
|
+
buildBuildings(ctx);
|
|
147
|
+
await nextFrame();
|
|
148
|
+
|
|
149
|
+
progress(0.57, '生成太湖石假山、洞壑与池岸驳岸');
|
|
150
|
+
await nextFrame();
|
|
151
|
+
ctx.onProgress = (p, name) => progress(0.57 + p * 0.13, `${name}`);
|
|
152
|
+
buildRockery(ctx);
|
|
153
|
+
const buildStats = B.build(mainGroup);
|
|
154
|
+
console.log(`[场景] 静态合批 ${buildStats.meshes} 组 / ${Math.round(buildStats.tris)} 三角形`);
|
|
155
|
+
await nextFrame();
|
|
156
|
+
|
|
157
|
+
progress(0.71, '生成地形、园路、林木花木与远景借景');
|
|
158
|
+
await nextFrame();
|
|
159
|
+
nature = createNature(scene, M, ctx);
|
|
160
|
+
|
|
161
|
+
progress(0.84, '布置水面、跌水与天气联动');
|
|
162
|
+
await nextFrame();
|
|
163
|
+
water = createWater(scene, ctx);
|
|
164
|
+
water.setSky(sky.getState());
|
|
165
|
+
|
|
166
|
+
/* LOD 注册 */
|
|
167
|
+
[mainGroup, nature.trunkGroup, nature.pathGroup].forEach(g => g && lod.addBatchGroup(g));
|
|
168
|
+
lod.setQuality(QUALITY[state.quality]);
|
|
169
|
+
if (state.lodVizParam) setLodViz(true);
|
|
170
|
+
|
|
171
|
+
progress(0.90, '装配漫游交互、后处理与画质分级');
|
|
172
|
+
await nextFrame();
|
|
173
|
+
controls = new OrbitControls(camera, renderer.domElement);
|
|
174
|
+
controls.enableDamping = true;
|
|
175
|
+
controls.dampingFactor = 0.055;
|
|
176
|
+
controls.rotateSpeed = 0.55;
|
|
177
|
+
controls.zoomSpeed = 0.9;
|
|
178
|
+
controls.panSpeed = 0.75;
|
|
179
|
+
controls.screenSpacePanning = false;
|
|
180
|
+
controls.minDistance = 2.5;
|
|
181
|
+
controls.maxDistance = 420;
|
|
182
|
+
// 允许适度仰视(定点视角常需从人眼高度仰望檐口与远塔),
|
|
183
|
+
// 过严的 89° 上限会把相机强行抬到目标之上,破坏人眼视高构图
|
|
184
|
+
controls.minPolarAngle = 0.05;
|
|
185
|
+
controls.maxPolarAngle = Math.PI * 0.62;
|
|
186
|
+
controls.target.set(...POIS[0].target);
|
|
187
|
+
controls.update();
|
|
188
|
+
|
|
189
|
+
composer = new EffectComposer(renderer);
|
|
190
|
+
renderPass = new RenderPass(scene, camera);
|
|
191
|
+
bloomPass = new UnrealBloomPass(new THREE.Vector2(window.innerWidth, window.innerHeight), 0.26, 0.66, 0.92);
|
|
192
|
+
outputPass = new OutputPass();
|
|
193
|
+
gradePass = new ShaderPass(GradeShader);
|
|
194
|
+
gradePass.uniforms.uResolution.value.set(window.innerWidth, window.innerHeight);
|
|
195
|
+
composer.addPass(renderPass);
|
|
196
|
+
composer.addPass(bloomPass);
|
|
197
|
+
composer.addPass(outputPass);
|
|
198
|
+
composer.addPass(gradePass);
|
|
199
|
+
composer.setSize(window.innerWidth, window.innerHeight);
|
|
200
|
+
|
|
201
|
+
buildLabels();
|
|
202
|
+
bindUI();
|
|
203
|
+
applyQuality(state.quality, true);
|
|
204
|
+
setWeather(state.weather, true);
|
|
205
|
+
onResize();
|
|
206
|
+
window.addEventListener('resize', onResize);
|
|
207
|
+
|
|
208
|
+
progress(1, '场景就绪');
|
|
209
|
+
await nextFrame();
|
|
210
|
+
$('#loader').classList.add('hidden');
|
|
211
|
+
setTimeout(() => { const l = $('#loader'); if (l) l.style.display = 'none'; }, 900);
|
|
212
|
+
state.started = true;
|
|
213
|
+
state.loadedAt = performance.now();
|
|
214
|
+
gpuTimer = initGpuTimer();
|
|
215
|
+
lod.update(0, true);
|
|
216
|
+
|
|
217
|
+
window.__garden = {
|
|
218
|
+
goToPOI, applyQuality, setWeather, setLodViz, state, camera, controls, renderer,
|
|
219
|
+
scene, sky, water, nature, lod, M, POIS, QUALITY, LOD_LEVELS,
|
|
220
|
+
setHour: h => { state.hour = h; sky.setHour(h); water.setSky(sky.getState()); $('#time-slider').value = h; $('#time-val').textContent = fmtHour(h); },
|
|
221
|
+
stats: buildStats,
|
|
222
|
+
};
|
|
223
|
+
clock.start();
|
|
224
|
+
requestAnimationFrame(loop);
|
|
225
|
+
const p = new URLSearchParams(location.search).get('poi');
|
|
226
|
+
if (p && POIS.some(v => v.id === p)) goToPOI(p, true);
|
|
227
|
+
toast('场景已就绪 · 拖拽旋转 / 滚轮缩放 / WASD 平移 / F 漫游 / 1–9 定点观察');
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/* ================================================================== *
|
|
231
|
+
* 景点标注
|
|
232
|
+
* ================================================================== */
|
|
233
|
+
function buildLabels() {
|
|
234
|
+
const wrap = $('#labels');
|
|
235
|
+
wrap.innerHTML = '';
|
|
236
|
+
labelEls = HOTSPOTS.map(h => {
|
|
237
|
+
const el = document.createElement('div');
|
|
238
|
+
el.className = 'poi-label';
|
|
239
|
+
el.innerHTML = `<span class="dot"></span><span class="txt">${h.name}</span>`;
|
|
240
|
+
el.addEventListener('click', e => { e.stopPropagation(); showInfo(h.name, '', h.desc); });
|
|
241
|
+
wrap.appendChild(el);
|
|
242
|
+
return { el, data: h };
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
const projV = new THREE.Vector3();
|
|
246
|
+
function updateLabels() {
|
|
247
|
+
const wrap = $('#labels');
|
|
248
|
+
if (!state.labels) { wrap.style.display = 'none'; return; }
|
|
249
|
+
wrap.style.display = 'block';
|
|
250
|
+
const w = window.innerWidth, h = window.innerHeight;
|
|
251
|
+
labelEls.forEach(({ el, data }) => {
|
|
252
|
+
projV.set(...data.pos).project(camera);
|
|
253
|
+
const d = camera.position.distanceTo(new THREE.Vector3(...data.pos));
|
|
254
|
+
if (projV.z > 1 || projV.z < -1 || d > 180 || Math.abs(projV.x) > 1.05 || Math.abs(projV.y) > 1.05) {
|
|
255
|
+
el.style.opacity = '0'; el.style.pointerEvents = 'none'; return;
|
|
256
|
+
}
|
|
257
|
+
el.style.transform = `translate(-50%, -50%) translate(${(projV.x * 0.5 + 0.5) * w}px, ${(-projV.y * 0.5 + 0.5) * h}px)`;
|
|
258
|
+
el.style.opacity = String(clamp((180 - d) / 90, 0.15, 0.95));
|
|
259
|
+
el.style.pointerEvents = 'auto';
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/* ================================================================== *
|
|
264
|
+
* 定点观察视角
|
|
265
|
+
* ================================================================== */
|
|
266
|
+
function buildViewButtons() {
|
|
267
|
+
const grid = $('#view-grid');
|
|
268
|
+
grid.innerHTML = POIS.map((p, i) =>
|
|
269
|
+
`<button class="view-btn${i === 0 ? ' active' : ''}" data-poi="${p.id}" title="${p.dir}">${p.key} · ${p.name}</button>`
|
|
270
|
+
).join('');
|
|
271
|
+
}
|
|
272
|
+
function goToPOI(id, instant) {
|
|
273
|
+
const p = POIS.find(v => v.id === id) || POIS[0];
|
|
274
|
+
state.poi = id;
|
|
275
|
+
$$('.view-btn').forEach(b => b.classList.toggle('active', b.dataset.poi === id));
|
|
276
|
+
if (state.walk) toggleWalk(false);
|
|
277
|
+
if (instant) {
|
|
278
|
+
camera.position.set(...p.pos);
|
|
279
|
+
controls.target.set(...p.target);
|
|
280
|
+
camera.fov = p.fov; camera.updateProjectionMatrix();
|
|
281
|
+
camera.lookAt(controls.target);
|
|
282
|
+
controls.update(); tween = null;
|
|
283
|
+
} else {
|
|
284
|
+
tween = {
|
|
285
|
+
t: 0, dur: 1.45,
|
|
286
|
+
fromPos: camera.position.clone(), toPos: new THREE.Vector3(...p.pos),
|
|
287
|
+
fromTarget: controls.target.clone(), toTarget: new THREE.Vector3(...p.target),
|
|
288
|
+
fromFov: camera.fov, toFov: p.fov,
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
showInfo(p.name, p.dir, p.desc, true);
|
|
292
|
+
lod && lod.update(0, true);
|
|
293
|
+
}
|
|
294
|
+
function updateTween(dt) {
|
|
295
|
+
if (!tween) return;
|
|
296
|
+
tween.t = Math.min(1, tween.t + dt / tween.dur);
|
|
297
|
+
const k = tween.t < 0.5 ? 4 * tween.t ** 3 : 1 - Math.pow(-2 * tween.t + 2, 3) / 2;
|
|
298
|
+
camera.position.lerpVectors(tween.fromPos, tween.toPos, k);
|
|
299
|
+
controls.target.lerpVectors(tween.fromTarget, tween.toTarget, k);
|
|
300
|
+
camera.fov = lerp(tween.fromFov, tween.toFov, k);
|
|
301
|
+
camera.updateProjectionMatrix();
|
|
302
|
+
camera.lookAt(controls.target);
|
|
303
|
+
if (tween.t >= 1) tween = null;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/* ================================================================== *
|
|
307
|
+
* 漫游
|
|
308
|
+
* ================================================================== */
|
|
309
|
+
function toggleWalk(on) {
|
|
310
|
+
const target = on === undefined ? !state.walk : on;
|
|
311
|
+
state.walk = target;
|
|
312
|
+
controls.enabled = !target;
|
|
313
|
+
$('#walk-btn').classList.toggle('active', target);
|
|
314
|
+
$('#walk-btn').textContent = target ? '退出漫游 [F]' : '自由漫游 [F]';
|
|
315
|
+
$('#walk-hint').classList.toggle('show', target);
|
|
316
|
+
if (target) {
|
|
317
|
+
const dir = new THREE.Vector3().subVectors(controls.target, camera.position).normalize();
|
|
318
|
+
walkState.yaw = Math.atan2(dir.x, -dir.z);
|
|
319
|
+
walkState.pitch = Math.asin(clamp(dir.y, -1, 1));
|
|
320
|
+
walkState.locked = false;
|
|
321
|
+
toast('第一人称漫游:点击画面锁定鼠标,WASD 移动,Shift 加速,Q/E 调整视高');
|
|
322
|
+
} else {
|
|
323
|
+
if (document.pointerLockElement) document.exitPointerLock();
|
|
324
|
+
controls.target.copy(camera.position).add(new THREE.Vector3(
|
|
325
|
+
Math.sin(walkState.yaw), Math.tan(walkState.pitch) * 0.4, -Math.cos(walkState.yaw)).multiplyScalar(12));
|
|
326
|
+
controls.update();
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
function updateWalk(dt) {
|
|
330
|
+
if (!state.walk) return;
|
|
331
|
+
const speed = (keys.has('ShiftLeft') || keys.has('ShiftRight')) ? 15 : 6.0;
|
|
332
|
+
const f = (keys.has('KeyW') ? 1 : 0) - (keys.has('KeyS') ? 1 : 0);
|
|
333
|
+
const s = (keys.has('KeyD') ? 1 : 0) - (keys.has('KeyA') ? 1 : 0);
|
|
334
|
+
const fx = Math.sin(walkState.yaw), fz = -Math.cos(walkState.yaw);
|
|
335
|
+
const rx = Math.cos(walkState.yaw), rz = Math.sin(walkState.yaw);
|
|
336
|
+
const tx = fx * f + rx * s, tz = fz * f + rz * s;
|
|
337
|
+
const l = Math.hypot(tx, tz) || 1;
|
|
338
|
+
const mag = Math.min(1, Math.hypot(f, s));
|
|
339
|
+
walkState.vx = lerp(walkState.vx, tx / l * speed * mag, 1 - Math.exp(-dt * 9));
|
|
340
|
+
walkState.vz = lerp(walkState.vz, tz / l * speed * mag, 1 - Math.exp(-dt * 9));
|
|
341
|
+
camera.position.x = clamp(camera.position.x + walkState.vx * dt, WORLD.bounds.minX, WORLD.bounds.maxX);
|
|
342
|
+
camera.position.z = clamp(camera.position.z + walkState.vz * dt, WORLD.bounds.minZ, WORLD.bounds.maxZ);
|
|
343
|
+
if (keys.has('KeyQ')) walkState.eye = clamp(walkState.eye - dt * 4, 0.9, 14);
|
|
344
|
+
if (keys.has('KeyE')) walkState.eye = clamp(walkState.eye + dt * 4, 0.9, 14);
|
|
345
|
+
// 水面区域按贴水石桥/平台处理,避免沉入池底
|
|
346
|
+
const ground = waterSDF(camera.position.x, camera.position.z) < 0
|
|
347
|
+
? WORLD.waterY + 0.12 : terrainHeight(camera.position.x, camera.position.z);
|
|
348
|
+
camera.position.y = lerp(camera.position.y, ground + walkState.eye, 1 - Math.exp(-dt * 10));
|
|
349
|
+
const cp = Math.cos(walkState.pitch);
|
|
350
|
+
const dir = new THREE.Vector3(Math.sin(walkState.yaw) * cp, Math.sin(walkState.pitch), -Math.cos(walkState.yaw) * cp);
|
|
351
|
+
camera.lookAt(camera.position.clone().add(dir));
|
|
352
|
+
}
|
|
353
|
+
function panOrbit(dt) {
|
|
354
|
+
if (state.walk || tween) return;
|
|
355
|
+
const f = (keys.has('KeyW') ? 1 : 0) - (keys.has('KeyS') ? 1 : 0);
|
|
356
|
+
const s = (keys.has('KeyD') ? 1 : 0) - (keys.has('KeyA') ? 1 : 0);
|
|
357
|
+
if (!f && !s) return;
|
|
358
|
+
const d = new THREE.Vector3().subVectors(controls.target, camera.position).normalize();
|
|
359
|
+
d.y = 0; d.normalize();
|
|
360
|
+
const right = new THREE.Vector3(-d.z, 0, d.x);
|
|
361
|
+
const v = d.multiplyScalar(f).add(right.multiplyScalar(s)).multiplyScalar(dt * 22);
|
|
362
|
+
camera.position.add(v); controls.target.add(v);
|
|
363
|
+
controls.target.x = clamp(controls.target.x, WORLD.bounds.minX, WORLD.bounds.maxX);
|
|
364
|
+
controls.target.z = clamp(controls.target.z, WORLD.bounds.minZ, WORLD.bounds.maxZ);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/* ================================================================== *
|
|
368
|
+
* 画质 / 天气 / LOD 可视化
|
|
369
|
+
* ================================================================== */
|
|
370
|
+
function applyQuality(name, silent) {
|
|
371
|
+
state.quality = name;
|
|
372
|
+
const q = QUALITY[name];
|
|
373
|
+
const pr = Math.min(window.devicePixelRatio || 1, q.dpr);
|
|
374
|
+
renderer.setPixelRatio(pr);
|
|
375
|
+
composer && composer.setPixelRatio(pr);
|
|
376
|
+
sky.setQuality(q);
|
|
377
|
+
nature && nature.applyQuality(q);
|
|
378
|
+
lod && lod.setQuality(q);
|
|
379
|
+
if (bloomPass) bloomPass.enabled = q.bloom;
|
|
380
|
+
if (gradePass) gradePass.enabled = q.grade;
|
|
381
|
+
$$('.q-btn').forEach(b => b.classList.toggle('active', b.dataset.quality === name));
|
|
382
|
+
$('#quality-val').textContent = q.label;
|
|
383
|
+
onResize();
|
|
384
|
+
if (!silent) toast(`画质「${q.label}」· 阴影 ${q.shadow}² · 像素比 ${pr.toFixed(1)} · LOD 距离 ×${q.lodScale}`);
|
|
385
|
+
}
|
|
386
|
+
function setWeather(w, silent) {
|
|
387
|
+
state.weather = w;
|
|
388
|
+
sky.setWeather(w);
|
|
389
|
+
water.setSky(sky.getState());
|
|
390
|
+
nature.setWeather(w, sky.getState());
|
|
391
|
+
$$('.w-btn').forEach(b => b.classList.toggle('active', b.dataset.weather === w));
|
|
392
|
+
$('#weather-val').textContent = { clear: '晴', mist: '薄霭', rain: '细雨' }[w];
|
|
393
|
+
if (!silent) toast(`天气切换为「${{ clear: '晴', mist: '薄霭', rain: '细雨' }[w]}」· 云量、雾密度与湿表面已联动`);
|
|
394
|
+
}
|
|
395
|
+
function setLodViz(on) {
|
|
396
|
+
state.lodViz = on;
|
|
397
|
+
lod.setVisualize(on);
|
|
398
|
+
$('#lod-btn').classList.toggle('active', on);
|
|
399
|
+
$('#lod-legend').classList.toggle('show', on);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/* ================================================================== *
|
|
403
|
+
* UI
|
|
404
|
+
* ================================================================== */
|
|
405
|
+
function toast(msg) {
|
|
406
|
+
const el = $('#toast');
|
|
407
|
+
el.textContent = msg; el.classList.add('show');
|
|
408
|
+
clearTimeout(toastTimer);
|
|
409
|
+
toastTimer = setTimeout(() => el.classList.remove('show'), 3600);
|
|
410
|
+
}
|
|
411
|
+
function showInfo(title, dir, desc, quiet) {
|
|
412
|
+
$('#info-title').textContent = title;
|
|
413
|
+
$('#info-dir').textContent = dir || '';
|
|
414
|
+
$('#info-dir').style.display = dir ? 'block' : 'none';
|
|
415
|
+
$('#info-desc').textContent = desc || '';
|
|
416
|
+
$('#info-card').classList.add('show');
|
|
417
|
+
if (!quiet) $('#info-card').scrollTop = 0;
|
|
418
|
+
}
|
|
419
|
+
function bindUI() {
|
|
420
|
+
buildViewButtons();
|
|
421
|
+
$$('.view-btn').forEach(b => b.addEventListener('click', () => goToPOI(b.dataset.poi)));
|
|
422
|
+
$$('.q-btn').forEach(b => b.addEventListener('click', () => applyQuality(b.dataset.quality)));
|
|
423
|
+
$$('.w-btn').forEach(b => b.addEventListener('click', () => setWeather(b.dataset.weather)));
|
|
424
|
+
$('#time-slider').addEventListener('input', e => {
|
|
425
|
+
state.hour = parseFloat(e.target.value);
|
|
426
|
+
sky.setHour(state.hour);
|
|
427
|
+
water.setSky(sky.getState());
|
|
428
|
+
$('#time-val').textContent = fmtHour(state.hour);
|
|
429
|
+
});
|
|
430
|
+
$('#walk-btn').addEventListener('click', () => toggleWalk());
|
|
431
|
+
$('#lod-btn').addEventListener('click', () => setLodViz(!state.lodViz));
|
|
432
|
+
$('#labels-toggle').addEventListener('click', () => {
|
|
433
|
+
state.labels = !state.labels;
|
|
434
|
+
$('#labels-toggle').classList.toggle('active', state.labels);
|
|
435
|
+
$('#labels-toggle').textContent = state.labels ? '景点标注' : '标注已关';
|
|
436
|
+
});
|
|
437
|
+
$('#auto-toggle').addEventListener('click', () => {
|
|
438
|
+
state.auto = !state.auto;
|
|
439
|
+
$('#auto-toggle').classList.toggle('active', state.auto);
|
|
440
|
+
});
|
|
441
|
+
$('#info-close').addEventListener('click', () => $('#info-card').classList.remove('show'));
|
|
442
|
+
$('#help-btn').addEventListener('click', () => $('#spec-modal').classList.add('show'));
|
|
443
|
+
$('#spec-close').addEventListener('click', () => $('#spec-modal').classList.remove('show'));
|
|
444
|
+
$('#spec-modal').addEventListener('click', e => { if (e.target.id === 'spec-modal') e.currentTarget.classList.remove('show'); });
|
|
445
|
+
$('#reset-btn').addEventListener('click', () => goToPOI('overview'));
|
|
446
|
+
$$('.fold-head').forEach(h => h.addEventListener('click', () => h.parentElement.classList.toggle('folded')));
|
|
447
|
+
|
|
448
|
+
const keyMap = {};
|
|
449
|
+
POIS.forEach(p => { keyMap[p.key] = p.id; });
|
|
450
|
+
window.addEventListener('keydown', e => {
|
|
451
|
+
if (e.target.tagName === 'INPUT') return;
|
|
452
|
+
keys.add(e.code);
|
|
453
|
+
if (e.code === 'KeyF') toggleWalk();
|
|
454
|
+
if (e.code === 'KeyG') setLodViz(!state.lodViz);
|
|
455
|
+
if (e.code === 'KeyL') $('#labels-toggle').click();
|
|
456
|
+
if (e.code === 'KeyH') $('#help-btn').click();
|
|
457
|
+
if (e.code === 'Escape') $('#spec-modal').classList.remove('show');
|
|
458
|
+
const k = e.key;
|
|
459
|
+
if (keyMap[k]) goToPOI(keyMap[k]);
|
|
460
|
+
});
|
|
461
|
+
window.addEventListener('keyup', e => keys.delete(e.code));
|
|
462
|
+
window.addEventListener('blur', () => keys.clear());
|
|
463
|
+
renderer.domElement.addEventListener('click', () => {
|
|
464
|
+
if (state.walk && !walkState.locked && document.pointerLockElement !== renderer.domElement)
|
|
465
|
+
renderer.domElement.requestPointerLock?.();
|
|
466
|
+
});
|
|
467
|
+
document.addEventListener('pointerlockchange', () => {
|
|
468
|
+
walkState.locked = document.pointerLockElement === renderer.domElement;
|
|
469
|
+
});
|
|
470
|
+
document.addEventListener('mousemove', e => {
|
|
471
|
+
if (!state.walk || !walkState.locked) return;
|
|
472
|
+
walkState.yaw -= e.movementX * 0.0022;
|
|
473
|
+
walkState.pitch = clamp(walkState.pitch - e.movementY * 0.0022, -1.35, 1.35);
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
const fmtHour = h => `${String(Math.floor(h)).padStart(2, '0')}:${String(Math.round((h % 1) * 60)).padStart(2, '0')}`;
|
|
477
|
+
|
|
478
|
+
/* ================================================================== *
|
|
479
|
+
* 小地图
|
|
480
|
+
* ================================================================== */
|
|
481
|
+
const mini = { ctx: null };
|
|
482
|
+
function drawMinimap() {
|
|
483
|
+
if (!mini.ctx) mini.ctx = $('#minimap').getContext('2d');
|
|
484
|
+
const c = mini.ctx, W = 212, H = 168;
|
|
485
|
+
const mx = x => (x - WORLD.garden.minX - 20) / (WORLD.garden.maxX - WORLD.garden.minX + 40) * W;
|
|
486
|
+
const mz = z => (z - WORLD.garden.minZ - 20) / (WORLD.garden.maxZ - WORLD.garden.minZ + 40) * H;
|
|
487
|
+
c.clearRect(0, 0, W, H);
|
|
488
|
+
c.fillStyle = '#1c2a24'; c.fillRect(0, 0, W, H);
|
|
489
|
+
// 水系
|
|
490
|
+
c.fillStyle = '#2e5559';
|
|
491
|
+
const pools = [[0, -12, 62, 35], [-52, 6, 22, 20], [46, 8, 21, 16], [16, -42, 27, 14], [-28, -46, 19, 12]];
|
|
492
|
+
pools.forEach(([x, z, rx, rz]) => {
|
|
493
|
+
c.beginPath(); c.ellipse(mx(x), mz(z), rx / 260 * W, rz / 230 * H, 0, 0, Math.PI * 2); c.fill();
|
|
494
|
+
});
|
|
495
|
+
// 园墙
|
|
496
|
+
c.strokeStyle = 'rgba(226,216,190,.72)'; c.lineWidth = 1.6;
|
|
497
|
+
c.strokeRect(mx(-110), mz(-95), mx(110) - mx(-110), mz(95) - mz(-95));
|
|
498
|
+
// 中轴
|
|
499
|
+
c.strokeStyle = 'rgba(217,185,121,.55)'; c.lineWidth = 1;
|
|
500
|
+
c.setLineDash([4, 3]);
|
|
501
|
+
c.beginPath(); c.moveTo(mx(0), mz(95)); c.lineTo(mx(0), mz(22)); c.stroke();
|
|
502
|
+
c.setLineDash([]);
|
|
503
|
+
// 三岛
|
|
504
|
+
c.fillStyle = '#6c7a4c';
|
|
505
|
+
[[-8, -12, 11, 8], [-34, -24, 7, 5], [28, -18, 7, 5]].forEach(([x, z, rx, rz]) => {
|
|
506
|
+
c.beginPath(); c.ellipse(mx(x), mz(z), rx / 260 * W, rz / 230 * H, 0, 0, Math.PI * 2); c.fill();
|
|
507
|
+
});
|
|
508
|
+
// 主要建筑
|
|
509
|
+
const bl = [
|
|
510
|
+
[0, 92, 14, 4, '宫门'], [0, 80, 20, 8, '轿厅'], [0, 58, 28, 12, '澄观堂'],
|
|
511
|
+
[0, 30, 24, 10, '远香堂'], [-30, 18, 11, 6, '涵碧榭'], [20, -60, 18, 10, '见山楼'],
|
|
512
|
+
[-8, -12, 7, 7, '雪香云蔚'], [44, 6, 7, 7, '荷风四面'], [-82, 34, 6, 6, '竹里馆'],
|
|
513
|
+
[68, -54, 6, 6, '丛桂'], [-64, -40, 20, 18, '云根叠翠'], [38, -34, 18, 5, '不系舟'],
|
|
514
|
+
];
|
|
515
|
+
c.font = '8px system-ui, sans-serif'; c.textAlign = 'center';
|
|
516
|
+
bl.forEach(([x, z, w, d, n]) => {
|
|
517
|
+
const px = mx(x - w / 2), py = mz(z - d / 2);
|
|
518
|
+
const pw = w / 260 * W, ph = d / 230 * H;
|
|
519
|
+
c.fillStyle = 'rgba(214,196,156,.80)'; c.fillRect(px, py, pw, ph);
|
|
520
|
+
c.fillStyle = '#f0e6cc'; c.fillText(n, px + pw / 2, py + ph / 2 + 3);
|
|
521
|
+
});
|
|
522
|
+
// 借景塔方向
|
|
523
|
+
c.strokeStyle = 'rgba(135,169,154,.5)'; c.setLineDash([3, 3]);
|
|
524
|
+
c.beginPath(); c.moveTo(mx(44), mz(6)); c.lineTo(mx(-96), mz(-90)); c.stroke();
|
|
525
|
+
c.setLineDash([]);
|
|
526
|
+
c.fillStyle = '#87a99a'; c.fillText('借景 · 北寺塔', mx(-70), mz(-84));
|
|
527
|
+
// 相机
|
|
528
|
+
const dir = new THREE.Vector3().subVectors(controls.target, camera.position);
|
|
529
|
+
const a = Math.atan2(dir.x, -dir.z);
|
|
530
|
+
const cx = mx(camera.position.x), cy = mz(camera.position.z);
|
|
531
|
+
c.save(); c.translate(cx, cy); c.rotate(a);
|
|
532
|
+
c.fillStyle = '#ffcf7a'; c.beginPath(); c.moveTo(0, -8); c.lineTo(5, 6); c.lineTo(-5, 6); c.closePath(); c.fill();
|
|
533
|
+
c.restore();
|
|
534
|
+
c.strokeStyle = 'rgba(255,207,122,.45)'; c.beginPath(); c.arc(cx, cy, 10, 0, Math.PI * 2); c.stroke();
|
|
535
|
+
c.fillStyle = '#9aa894'; c.textAlign = 'left'; c.font = '9px system-ui';
|
|
536
|
+
c.fillText('N ↑', 6, 13); c.fillText('220m × 190m · 4.18ha', 6, H - 7);
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
/* ================================================================== *
|
|
540
|
+
* 性能 HUD 与自适应降级
|
|
541
|
+
* ================================================================== */
|
|
542
|
+
function initGpuTimer() {
|
|
543
|
+
const gl = renderer.getContext();
|
|
544
|
+
const ext = gl.getExtension('EXT_disjoint_timer_query_webgl2');
|
|
545
|
+
if (!ext) return null;
|
|
546
|
+
return { gl, ext, query: null, lastMs: 0 };
|
|
547
|
+
}
|
|
548
|
+
function gpuBegin() {
|
|
549
|
+
if (!gpuTimer || gpuTimer.query) return;
|
|
550
|
+
const q = gpuTimer.gl.createQuery();
|
|
551
|
+
gpuTimer.gl.beginQuery(gpuTimer.ext.TIME_ELAPSED_EXT, q);
|
|
552
|
+
gpuTimer.query = q;
|
|
553
|
+
}
|
|
554
|
+
function gpuEnd() { if (gpuTimer && gpuTimer.query) gpuTimer.gl.endQuery(gpuTimer.ext.TIME_ELAPSED_EXT); }
|
|
555
|
+
function gpuPoll() {
|
|
556
|
+
if (!gpuTimer || !gpuTimer.query) return;
|
|
557
|
+
const { gl, ext, query } = gpuTimer;
|
|
558
|
+
if (!gl.getQueryParameter(query, gl.QUERY_RESULT_AVAILABLE)) return;
|
|
559
|
+
if (!gl.getParameter(ext.GPU_DISJOINT_EXT)) gpuTimer.lastMs = gl.getQueryParameter(query, gl.QUERY_RESULT) / 1e6;
|
|
560
|
+
gl.deleteQuery(query); gpuTimer.query = null;
|
|
561
|
+
}
|
|
562
|
+
let hudT = 0;
|
|
563
|
+
function updateHUD(dt) {
|
|
564
|
+
state.frames++; state.acc += dt; hudT += dt;
|
|
565
|
+
if (hudT < 0.35) return;
|
|
566
|
+
const fps = state.frames / state.acc;
|
|
567
|
+
state.fps = lerp(state.fps, fps, 0.5);
|
|
568
|
+
state.frames = 0; state.acc = 0; hudT = 0;
|
|
569
|
+
const frameMs = Math.max(1000 / Math.max(fps, 1), gpuTimer?.lastMs || 0);
|
|
570
|
+
const adaptFps = 1000 / Math.max(frameMs, 1);
|
|
571
|
+
$('#fps').textContent = Math.round(state.fps);
|
|
572
|
+
$('#fps').className = state.fps > 50 ? 'good' : state.fps > 32 ? 'mid' : 'bad';
|
|
573
|
+
$('#ms').textContent = frameMs.toFixed(1);
|
|
574
|
+
$('#calls').textContent = renderer.info.render.calls;
|
|
575
|
+
$('#tris').textContent = (renderer.info.render.triangles / 1000).toFixed(0) + 'k';
|
|
576
|
+
$('#lodinfo').textContent = lod.summary();
|
|
577
|
+
$('#campos').textContent = `${camera.position.x.toFixed(0)}, ${camera.position.y.toFixed(0)}, ${camera.position.z.toFixed(0)}`;
|
|
578
|
+
|
|
579
|
+
state.cooldown = Math.max(0, state.cooldown - 0.35);
|
|
580
|
+
if (!state.auto || state.cooldown > 0) return;
|
|
581
|
+
if (adaptFps < 38) { state.lowFor += 0.35; state.highFor = 0; }
|
|
582
|
+
else if (adaptFps > 56) { state.highFor += 0.35; state.lowFor = 0; }
|
|
583
|
+
else { state.lowFor *= 0.7; state.highFor *= 0.7; }
|
|
584
|
+
if (state.lowFor > 2.1) {
|
|
585
|
+
if (state.quality === 'high') applyQuality('medium');
|
|
586
|
+
else if (state.quality === 'medium') applyQuality('low');
|
|
587
|
+
state.lowFor = 0; state.cooldown = 6;
|
|
588
|
+
toast('检测到帧率偏低,已自动降低细节密度以保证漫游流畅');
|
|
589
|
+
} else if (state.highFor > 12 && state.quality === 'low') {
|
|
590
|
+
applyQuality('medium'); state.highFor = 0; state.cooldown = 10;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
/* ================================================================== *
|
|
595
|
+
* 主循环
|
|
596
|
+
* ================================================================== */
|
|
597
|
+
function loop() {
|
|
598
|
+
requestAnimationFrame(loop);
|
|
599
|
+
const rawDt = clock.getDelta();
|
|
600
|
+
const dt = Math.min(rawDt, 0.1);
|
|
601
|
+
const realDt = Math.min(rawDt, 0.5);
|
|
602
|
+
const t = clock.elapsedTime;
|
|
603
|
+
renderer.info.reset();
|
|
604
|
+
|
|
605
|
+
if (tween) updateTween(realDt);
|
|
606
|
+
else if (!state.walk) { panOrbit(dt); controls.update(); }
|
|
607
|
+
updateWalk(dt);
|
|
608
|
+
|
|
609
|
+
sky.update(t, camera);
|
|
610
|
+
water.setTime(t);
|
|
611
|
+
water.setCamera(camera);
|
|
612
|
+
water.setSky(sky.getState());
|
|
613
|
+
nature.update(t, camera);
|
|
614
|
+
if (gradePass) gradePass.uniforms.uTime.value = t;
|
|
615
|
+
lod.update(dt);
|
|
616
|
+
|
|
617
|
+
labelT += realDt; if (labelT > 1 / 15) { labelT = 0; updateLabels(); }
|
|
618
|
+
mapT += realDt; if (mapT > 1 / 5) { mapT = 0; drawMinimap(); }
|
|
619
|
+
|
|
620
|
+
gpuBegin();
|
|
621
|
+
composer.render();
|
|
622
|
+
gpuEnd();
|
|
623
|
+
gpuPoll();
|
|
624
|
+
updateHUD(dt); // 在渲染之后读取 renderer.info,保证 draw call / 三角形为真实统计
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
function onResize() {
|
|
628
|
+
if (!renderer || !camera) return;
|
|
629
|
+
const w = window.innerWidth, h = window.innerHeight;
|
|
630
|
+
camera.aspect = w / h;
|
|
631
|
+
camera.updateProjectionMatrix();
|
|
632
|
+
renderer.setSize(w, h);
|
|
633
|
+
composer && composer.setSize(w, h);
|
|
634
|
+
gradePass && gradePass.uniforms.uResolution.value.set(w, h);
|
|
635
|
+
renderer.shadowMap.needsUpdate = true;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
boot().catch(err => {
|
|
639
|
+
console.error('[场景启动失败]', err);
|
|
640
|
+
const l = $('#load-label');
|
|
641
|
+
if (l) l.textContent = '场景启动失败:' + (err && err.message ? err.message : err);
|
|
642
|
+
});
|