zhuda-laya-engine 0.0.0-stage → 2.1.0
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/AGENTS.md +236 -0
- package/CHANGELOG.md +431 -0
- package/LICENSE +41 -0
- package/README.md +247 -2
- package/assets/branding/layaair-tribute-mark.svg +5 -0
- package/assets/branding/zhuda-layaair-mark.svg +34 -0
- package/assets/prefabs/CoinFountainVfx.lh +197 -0
- package/assets/prefabs/ConfirmActionButton.lh +87 -0
- package/assets/prefabs/LevelUpAuraVfx.lh +136 -0
- package/assets/prefabs/MineExplosionParticle.lh +352 -0
- package/assets/prefabs/NineSliceDialogFrame.lh +171 -0
- package/assets/prefabs/SwordSlashTrailVfx.lh +117 -0
- package/assets/prefabs/TacticalHudBar.lh +134 -0
- package/assets/prefabs/TelemetryDashboard.lh +87 -0
- package/assets/prefabs/UnityCrystalGuardian.lh +144 -0
- package/assets/prefabs/ZhudaSpine42Mascot.lh +183 -0
- package/assets/scenes/MinesweeperStage.ls +1180 -0
- package/dist/asset-calibration-report.json +969 -0
- package/dist/build-manifest.json +254 -0
- package/dist/sdk/zhuda-laya-csg.cjs +710 -0
- package/dist/sdk/zhuda-laya-csg.esm.js +683 -0
- package/dist/sdk/zhuda-laya-csg.min.cjs +7 -0
- package/dist/sdk/zhuda-laya-csg.min.esm.js +7 -0
- package/dist/sdk/zhuda-laya-demo.cjs +5990 -0
- package/dist/sdk/zhuda-laya-demo.esm.js +5956 -0
- package/dist/sdk/zhuda-laya-demo.min.cjs +12 -0
- package/dist/sdk/zhuda-laya-demo.min.esm.js +12 -0
- package/dist/sdk/zhuda-laya-engine.cjs +52628 -0
- package/dist/sdk/zhuda-laya-engine.esm.js +51848 -0
- package/dist/sdk/zhuda-laya-engine.min.cjs +2710 -0
- package/dist/sdk/zhuda-laya-engine.min.esm.js +2710 -0
- package/docs/3d-acceptance.md +47 -0
- package/docs/3d-integration.md +190 -0
- package/docs/README.md +112 -0
- package/docs/SUPPORT.md +21 -0
- package/docs/agent-development.md +219 -0
- package/docs/animation-control.md +213 -0
- package/docs/asset-loading.md +97 -0
- package/docs/assets/reference-games.jpg +0 -0
- package/docs/assets/solana-qr.png +0 -0
- package/docs/assets/sponsor-pass.svg +32 -0
- package/docs/audio.md +319 -0
- package/docs/backend-delivery.md +218 -0
- package/docs/basis-textures.md +94 -0
- package/docs/browser-sdk-releases.json +204 -0
- package/docs/browser-sdk.md +187 -0
- package/docs/cinematics.md +267 -0
- package/docs/cloth.md +280 -0
- package/docs/combat-runtime.md +82 -0
- package/docs/consumer-route.md +169 -0
- package/docs/consumer-tooling.md +518 -0
- package/docs/crowd-runtime.md +195 -0
- package/docs/developer-tooling.md +191 -0
- package/docs/film-scenes.md +1504 -0
- package/docs/filmic-rendering.md +743 -0
- package/docs/flythrough.md +89 -0
- package/docs/gpu-depth.md +207 -0
- package/docs/grass.md +127 -0
- package/docs/hdr-environment.md +76 -0
- package/docs/instanced-meshes.md +137 -0
- package/docs/layout-and-media.md +37 -0
- package/docs/layout-wireframe.md +80 -0
- package/docs/lighting-depth.md +185 -0
- package/docs/minigame-packaging.md +79 -0
- package/docs/model-editor.md +66 -0
- package/docs/model-lod.md +122 -0
- package/docs/model-pipeline.md +74 -0
- package/docs/model-showcase.md +365 -0
- package/docs/overview.md +183 -0
- package/docs/plans/README.md +133 -0
- package/docs/plans/TASK-TEMPLATE.md +64 -0
- package/docs/plans/TASK-spine38-isolated-topology-20261106.md +89 -0
- package/docs/plans/TEMPLATE.md +44 -0
- package/docs/plans/VERIFICATION-TEMPLATE.md +45 -0
- package/docs/plans/asset-packaging.md +140 -0
- package/docs/plans/cinematic-production/task.md +97 -0
- package/docs/plans/cinematic-production/verification.md +49 -0
- package/docs/plans/consumer-delivery-followups.md +129 -0
- package/docs/plans/desktop-and-agent-gates/hardening-task.md +85 -0
- package/docs/plans/desktop-and-agent-gates/hardening-verification.md +109 -0
- package/docs/plans/desktop-and-agent-gates/task.md +94 -0
- package/docs/plans/desktop-and-agent-gates/verification.md +60 -0
- package/docs/plans/prefab-toolchain.md +73 -0
- package/docs/plans/preview-runtime-hardening.md +68 -0
- package/docs/platform-adapters.md +113 -0
- package/docs/post-quality.md +242 -0
- package/docs/prefab-editor.md +194 -0
- package/docs/prefab-library.md +94 -0
- package/docs/prefab-workflow.md +75 -0
- package/docs/procedural-assets.md +463 -0
- package/docs/procedural-prefabs.md +133 -0
- package/docs/quality-route.md +386 -0
- package/docs/release-policy.md +79 -0
- package/docs/routes/README.md +180 -0
- package/docs/routes/TEMPLATE.md +54 -0
- package/docs/routes/action-adventure-3d-minigame.md +238 -0
- package/docs/routes/apocalypse-survival-3d.md +219 -0
- package/docs/routes/aqua-freeze-2d-minigame.md +183 -0
- package/docs/routes/astral-minimal-film-look.md +141 -0
- package/docs/routes/cascade-slot.md +93 -0
- package/docs/routes/clip-free-garments.md +229 -0
- package/docs/routes/drop-merge-2d-minigame.md +200 -0
- package/docs/routes/dungeon-line-slot.md +87 -0
- package/docs/routes/film-as-data.md +131 -0
- package/docs/routes/film-fight-that-lands.md +198 -0
- package/docs/routes/film-ink-lines.md +120 -0
- package/docs/routes/floating-island.md +229 -0
- package/docs/routes/game-2d.md +168 -0
- package/docs/routes/game-rules-first.md +89 -0
- package/docs/routes/game-to-prefabs.md +249 -0
- package/docs/routes/go-game-server.md +95 -0
- package/docs/routes/good-looking-3d-scene.md +99 -0
- package/docs/routes/high-quality-character.md +263 -0
- package/docs/routes/humanoid-from-shapes.md +97 -0
- package/docs/routes/hunting-action-3d.md +76 -0
- package/docs/routes/idle-gacha-2d.md +67 -0
- package/docs/routes/interactive-film-viewer.md +141 -0
- package/docs/routes/isometric-mystery-2d.md +217 -0
- package/docs/routes/key-art-to-animated-title.md +132 -0
- package/docs/routes/laya-ide-project-cli-web.md +125 -0
- package/docs/routes/layered-cloth-on-body.md +240 -0
- package/docs/routes/low-poly-character-from-shapes.md +475 -0
- package/docs/routes/match-three-2d.md +64 -0
- package/docs/routes/merge-2d.md +59 -0
- package/docs/routes/mini-game-build.md +80 -0
- package/docs/routes/mobile-always-landscape.md +149 -0
- package/docs/routes/mobile-web-fullscreen.md +255 -0
- package/docs/routes/model-from-dcc.md +106 -0
- package/docs/routes/new-game-project.md +100 -0
- package/docs/routes/onboarding-tutorial-2d.md +54 -0
- package/docs/routes/online-lockstep-match.md +473 -0
- package/docs/routes/outdoor-landscape.md +134 -0
- package/docs/routes/outfit-swap-3d.md +144 -0
- package/docs/routes/papercraft-diorama.md +186 -0
- package/docs/routes/platform-fighter-2d.md +235 -0
- package/docs/routes/platformer-2d.md +69 -0
- package/docs/routes/pole-rescue-arcade-3d.md +198 -0
- package/docs/routes/pose-atlas-motion.md +188 -0
- package/docs/routes/prototype-to-center.md +162 -0
- package/docs/routes/raft-brawl-3d-minigame.md +205 -0
- package/docs/routes/rhythm-2d.md +82 -0
- package/docs/routes/rigged-phone-character.md +120 -0
- package/docs/routes/screen-fit-game-box.md +127 -0
- package/docs/routes/shared-islands.md +195 -0
- package/docs/routes/side-view-duel.md +266 -0
- package/docs/routes/single-html-page.md +83 -0
- package/docs/routes/smooth-character-motion.md +162 -0
- package/docs/routes/spine-character.md +175 -0
- package/docs/routes/story-counting-2d.md +219 -0
- package/docs/routes/survivors-2d.md +60 -0
- package/docs/routes/third-person-town-3d.md +240 -0
- package/docs/routes/tower-defence-3d.md +67 -0
- package/docs/routes/ui-test-by-probe.md +219 -0
- package/docs/routes/underwater.md +138 -0
- package/docs/routes/visual-content-prefab.md +101 -0
- package/docs/runtime-hardening.md +108 -0
- package/docs/shader-warm-up.md +125 -0
- package/docs/spring-bones.md +79 -0
- package/docs/stylized-shading.md +171 -0
- package/docs/terrain-shader.md +130 -0
- package/docs/vrm.md +128 -0
- package/docs/walking.md +97 -0
- package/docs/webgpu.md +225 -0
- package/docs/white-label-themes.md +212 -0
- package/docs/zh-CN/README.md +130 -0
- package/examples/browser-sdk/2d-webgpu.html +46 -0
- package/examples/browser-sdk/2d.html +46 -0
- package/examples/browser-sdk/3d-gltf-webgpu.html +50 -0
- package/examples/browser-sdk/3d-gltf.html +50 -0
- package/examples/browser-sdk/3d-webgpu.html +46 -0
- package/examples/browser-sdk/3d.html +46 -0
- package/examples/cinematic-capture/Main.ts +294 -0
- package/examples/cinematic-capture/README.md +27 -0
- package/examples/model-inspector/README.md +15 -0
- package/examples/model-inspector/asset.gltf +158 -0
- package/examples/windows-webgpu/README.md +57 -0
- package/examples/windows-webgpu/bundle.mjs +122 -0
- package/examples/windows-webgpu/main.mjs +302 -0
- package/examples/windows-webgpu/package-lock.json +2353 -0
- package/examples/windows-webgpu/package.json +40 -0
- package/examples/windows-webgpu/squirrel.mjs +66 -0
- package/package.json +259 -4
- package/packages/ci-gate/export-film.mjs +347 -0
- package/packages/ci-gate/verify-sequence.mjs +285 -0
- package/packages/compiler/agent-contract.mjs +545 -0
- package/packages/compiler/ast-scanner.mjs +254 -0
- package/packages/compiler/backend-loader.mjs +62 -0
- package/packages/compiler/branding-assets.mjs +32 -0
- package/packages/compiler/branding.mjs +324 -0
- package/packages/compiler/browser-auto-example.mjs +31 -0
- package/packages/compiler/browser-model-example.mjs +53 -0
- package/packages/compiler/browser-process.mjs +344 -0
- package/packages/compiler/browser-sdk-example.mjs +50 -0
- package/packages/compiler/browser-sdk.mjs +342 -0
- package/packages/compiler/chrome-host.mjs +196 -0
- package/packages/compiler/cli.mjs +22 -0
- package/packages/compiler/compiler-runtime.mjs +41 -0
- package/packages/compiler/consumer-accept.mjs +89 -0
- package/packages/compiler/consumer-build.mjs +641 -0
- package/packages/compiler/consumer-guards.mjs +422 -0
- package/packages/compiler/consumer-publication.mjs +56 -0
- package/packages/compiler/consumer-scripts.mjs +134 -0
- package/packages/compiler/consumer-starter-2d.mjs +54 -0
- package/packages/compiler/consumer-starter-minigame.mjs +30 -0
- package/packages/compiler/editor-http.mjs +210 -0
- package/packages/compiler/editor-request.ts +12 -0
- package/packages/compiler/film-host-client.ts +249 -0
- package/packages/compiler/flythrough-file.mjs +144 -0
- package/packages/compiler/json-locate.mjs +85 -0
- package/packages/compiler/layout-contract.mjs +472 -0
- package/packages/compiler/minigame-bootstrap.mjs +24 -0
- package/packages/compiler/minigame-bridge.mjs +66 -0
- package/packages/compiler/minigame-guards.mjs +107 -0
- package/packages/compiler/minigame-toolchain.mjs +241 -0
- package/packages/compiler/model-crown.mjs +173 -0
- package/packages/compiler/model-editor-client.ts +809 -0
- package/packages/compiler/model-editor.mjs +242 -0
- package/packages/compiler/model-lod.mjs +547 -0
- package/packages/compiler/prefab-check.mjs +288 -0
- package/packages/compiler/prefab-checks.mjs +74 -0
- package/packages/compiler/prefab-dependencies.mjs +102 -0
- package/packages/compiler/prefab-editor-client.ts +950 -0
- package/packages/compiler/prefab-editor-preview.ts +89 -0
- package/packages/compiler/prefab-editor-server.mjs +585 -0
- package/packages/compiler/prefab-editor.mjs +43 -0
- package/packages/compiler/prefab-environment.mjs +107 -0
- package/packages/compiler/prefab-lifecycle.mjs +60 -0
- package/packages/compiler/prefab-preview.mjs +159 -0
- package/packages/compiler/prefab-watch.mjs +459 -0
- package/packages/compiler/runtime3d-types.mjs +91 -0
- package/packages/compiler/stage-probe.mjs +557 -0
- package/packages/compiler/visual-asset-audit.mjs +609 -0
- package/packages/compiler/visual-contract-audit.mjs +173 -0
- package/packages/compiler/webgpu-loader.mjs +153 -0
- package/packages/compiler/zhuda-build.mjs +714 -0
- package/packages/compiler/zhuda-doctor.mjs +186 -0
- package/packages/compiler/zhuda-init.mjs +353 -0
- package/packages/compiler/zhuda-layout.mjs +163 -0
- package/packages/compiler/zhuda-minigame.mjs +636 -0
- package/packages/core/BenchmarkEngine.ts +2 -0
- package/packages/core/BitmapFontContract.ts +159 -0
- package/packages/core/DeclarativeSDK.ts +686 -0
- package/packages/core/IframeSoundAdapter.ts +1824 -0
- package/packages/core/NoSleepAdapter.ts +302 -0
- package/packages/core/PixelCalibrationEngine.ts +602 -0
- package/packages/core/Prefab.ts +314 -0
- package/packages/core/RealmGuards.ts +111 -0
- package/packages/core/ResponsiveLayout.ts +149 -0
- package/packages/core/RuntimeGuards.ts +261 -0
- package/packages/core/SpineCharacter.ts +243 -0
- package/packages/core/SpineVisualContract.ts +238 -0
- package/packages/core/SplashSignal.ts +72 -0
- package/packages/core/StaticAssetPipeline.ts +3 -0
- package/packages/core/TopologyGraph.ts +693 -0
- package/packages/core/UnityBridgePipeline.ts +2 -0
- package/packages/core/VideoSurface.ts +75 -0
- package/packages/core/ViewportMatrixEngine.ts +237 -0
- package/packages/core/VisualFocusContract.ts +76 -0
- package/packages/core/VisualMigrationPipeline.ts +245 -0
- package/packages/core/WebViewSurface.ts +116 -0
- package/packages/core/audio/OfflineMix.ts +186 -0
- package/packages/core/audio/Spatial.ts +312 -0
- package/packages/core/audio/StreamVoice.ts +161 -0
- package/packages/core/csg/Bsp.ts +310 -0
- package/packages/core/csg/index.ts +589 -0
- package/packages/core/effects/Effect2D.ts +286 -0
- package/packages/core/effects/Effect3D.ts +213 -0
- package/packages/core/effects/EffectBudget.ts +695 -0
- package/packages/core/effects/EffectDirector.ts +254 -0
- package/packages/core/effects/EffectPresets.ts +843 -0
- package/packages/core/effects/EffectPresets2D.ts +1011 -0
- package/packages/core/effects/EffectSprites.ts +143 -0
- package/packages/core/effects/ParticleEventLink.ts +53 -0
- package/packages/core/effects/README.md +108 -0
- package/packages/core/effects/VfxMaterial.ts +253 -0
- package/packages/core/film/BakeKey.ts +21 -0
- package/packages/core/film/ColorValues.ts +44 -0
- package/packages/core/film/FilmLint.ts +353 -0
- package/packages/core/film/FilmPrefab.ts +82 -0
- package/packages/core/film/FilmReview.ts +84 -0
- package/packages/core/film/FilmScene.ts +3442 -0
- package/packages/core/film/FilmStage.ts +2148 -0
- package/packages/core/film/Flythrough.ts +169 -0
- package/packages/core/film/FlythroughReport.ts +326 -0
- package/packages/core/film/FrameMetrics.ts +167 -0
- package/packages/core/film/LiveLook.ts +242 -0
- package/packages/core/film/LookQuality.ts +94 -0
- package/packages/core/film/Projection.ts +74 -0
- package/packages/core/film/SceneLook.ts +363 -0
- package/packages/core/film/index.ts +12 -0
- package/packages/core/index.ts +48 -0
- package/packages/core/particles/EffectEnvelope.ts +52 -0
- package/packages/core/particles/LayaParticleRenderer.ts +182 -0
- package/packages/core/particles/LayaParticleRenderer3D.ts +218 -0
- package/packages/core/particles/ParticleExtras.ts +163 -0
- package/packages/core/particles/ParticleMesh3D.ts +156 -0
- package/packages/core/particles/ParticleSystem.ts +324 -0
- package/packages/core/particles/ParticleSystem3D.ts +411 -0
- package/packages/core/particles/ParticleTypes.ts +230 -0
- package/packages/core/particles/ParticleTypes3D.ts +115 -0
- package/packages/core/particles/README.md +181 -0
- package/packages/core/particles/RibbonPath3D.ts +234 -0
- package/packages/core/particles/RibbonTrail.ts +145 -0
- package/packages/core/particles/RibbonTrail3D.ts +166 -0
- package/packages/core/particles/index.ts +12 -0
- package/packages/core/prefabs/PrefabLibrary.ts +692 -0
- package/packages/core/prefabs/PrefabTree3D.ts +291 -0
- package/packages/core/prefabs/index.ts +10 -0
- package/packages/core/procedural/Geometry.ts +1871 -0
- package/packages/core/procedural/Hand.ts +1510 -0
- package/packages/core/procedural/Isosurface.ts +1035 -0
- package/packages/core/procedural/ModuleHarness.ts +180 -0
- package/packages/core/procedural/Noise.ts +123 -0
- package/packages/core/procedural/PhotoMaterial.ts +283 -0
- package/packages/core/procedural/ProceduralAssetProvider.ts +105 -0
- package/packages/core/procedural/ProceduralMaterial.ts +184 -0
- package/packages/core/procedural/PropFactory.ts +307 -0
- package/packages/core/procedural/Random.ts +70 -0
- package/packages/core/procedural/SynthAudio.ts +221 -0
- package/packages/core/procedural/TerrainMesh.ts +207 -0
- package/packages/core/procedural/TextureRecipe.ts +464 -0
- package/packages/core/procedural/TriplanarMaterial.ts +169 -0
- package/packages/core/procedural/Variation.ts +94 -0
- package/packages/core/procedural/index.ts +15 -0
- package/packages/core/runtime3d/ActionFrames.ts +245 -0
- package/packages/core/runtime3d/AnimationBlend.ts +282 -0
- package/packages/core/runtime3d/AnimationBlendMath.ts +98 -0
- package/packages/core/runtime3d/AssetProvider.ts +775 -0
- package/packages/core/runtime3d/AssetShowcase.ts +190 -0
- package/packages/core/runtime3d/Assets.ts +801 -0
- package/packages/core/runtime3d/AsyncDeadline.ts +53 -0
- package/packages/core/runtime3d/AsyncOperation.ts +39 -0
- package/packages/core/runtime3d/BackendChoice.ts +359 -0
- package/packages/core/runtime3d/BakedCrowd.ts +575 -0
- package/packages/core/runtime3d/BasisTexture.ts +657 -0
- package/packages/core/runtime3d/CameraCollision.ts +69 -0
- package/packages/core/runtime3d/CameraEffects.ts +752 -0
- package/packages/core/runtime3d/CameraRig.ts +70 -0
- package/packages/core/runtime3d/CharacterController.ts +272 -0
- package/packages/core/runtime3d/CinematicCapture.ts +457 -0
- package/packages/core/runtime3d/Clocks.ts +724 -0
- package/packages/core/runtime3d/Cloth.ts +183 -0
- package/packages/core/runtime3d/Clouds.ts +462 -0
- package/packages/core/runtime3d/ColorLut.ts +351 -0
- package/packages/core/runtime3d/CombatQueries.ts +240 -0
- package/packages/core/runtime3d/ComputePass.ts +582 -0
- package/packages/core/runtime3d/CrowdPresentation.ts +368 -0
- package/packages/core/runtime3d/DebugDraw.ts +567 -0
- package/packages/core/runtime3d/DebugStats.ts +35 -0
- package/packages/core/runtime3d/Decals.ts +309 -0
- package/packages/core/runtime3d/DensityVolume.ts +238 -0
- package/packages/core/runtime3d/DistanceBricks.ts +349 -0
- package/packages/core/runtime3d/Dither.ts +199 -0
- package/packages/core/runtime3d/DrawWarmUp.ts +217 -0
- package/packages/core/runtime3d/EdgeSmoothing.ts +108 -0
- package/packages/core/runtime3d/EnvironmentProbe.ts +656 -0
- package/packages/core/runtime3d/Filmic.ts +973 -0
- package/packages/core/runtime3d/Foliage.ts +367 -0
- package/packages/core/runtime3d/GltfIntake.ts +914 -0
- package/packages/core/runtime3d/GltfSecondUv.ts +153 -0
- package/packages/core/runtime3d/GraphicsGuard.ts +171 -0
- package/packages/core/runtime3d/Grass.ts +1080 -0
- package/packages/core/runtime3d/GroundTruthAO.ts +360 -0
- package/packages/core/runtime3d/HalfFloat.ts +44 -0
- package/packages/core/runtime3d/HdrEnvironment.ts +588 -0
- package/packages/core/runtime3d/Ik.ts +392 -0
- package/packages/core/runtime3d/InputBuffer.ts +165 -0
- package/packages/core/runtime3d/InstancedMesh.ts +460 -0
- package/packages/core/runtime3d/Laya342Adapters.ts +1095 -0
- package/packages/core/runtime3d/Laya342GltfAdapter.ts +751 -0
- package/packages/core/runtime3d/LensFinish.ts +153 -0
- package/packages/core/runtime3d/LensFlare.ts +490 -0
- package/packages/core/runtime3d/LightFog.ts +1008 -0
- package/packages/core/runtime3d/LightingDepth.ts +544 -0
- package/packages/core/runtime3d/Lightmap.ts +238 -0
- package/packages/core/runtime3d/Math3D.ts +84 -0
- package/packages/core/runtime3d/MeshQuery.ts +547 -0
- package/packages/core/runtime3d/MeshoptModelDecoder.ts +354 -0
- package/packages/core/runtime3d/MiniGameSplash.ts +70 -0
- package/packages/core/runtime3d/ModelAnimationSampler.ts +97 -0
- package/packages/core/runtime3d/ModelCompatibility.ts +890 -0
- package/packages/core/runtime3d/ModelDecoder.ts +294 -0
- package/packages/core/runtime3d/ModelInspector.ts +226 -0
- package/packages/core/runtime3d/ModelLod.ts +163 -0
- package/packages/core/runtime3d/ModelPlacements.ts +426 -0
- package/packages/core/runtime3d/ObjectMotion.ts +217 -0
- package/packages/core/runtime3d/PhysicalCamera.ts +190 -0
- package/packages/core/runtime3d/PointShadow.ts +500 -0
- package/packages/core/runtime3d/PointShadowSchedule.ts +201 -0
- package/packages/core/runtime3d/Pool.ts +120 -0
- package/packages/core/runtime3d/ProbeVolume.ts +695 -0
- package/packages/core/runtime3d/QualityGovernor.ts +385 -0
- package/packages/core/runtime3d/QualityMemory.ts +200 -0
- package/packages/core/runtime3d/RenderScale.ts +356 -0
- package/packages/core/runtime3d/RenderSpaces.ts +105 -0
- package/packages/core/runtime3d/Renderer.ts +377 -0
- package/packages/core/runtime3d/ResultPlayback.ts +239 -0
- package/packages/core/runtime3d/Runtime.ts +507 -0
- package/packages/core/runtime3d/RuntimeDriver.ts +127 -0
- package/packages/core/runtime3d/SceneLifecycle.ts +211 -0
- package/packages/core/runtime3d/SceneMutation.ts +107 -0
- package/packages/core/runtime3d/SceneQueries.ts +191 -0
- package/packages/core/runtime3d/ScreenReflections.ts +595 -0
- package/packages/core/runtime3d/SelectionOutline.ts +389 -0
- package/packages/core/runtime3d/ShaderErrors.ts +104 -0
- package/packages/core/runtime3d/ShaderRegistry.ts +34 -0
- package/packages/core/runtime3d/ShaderWarmUp.ts +473 -0
- package/packages/core/runtime3d/ShadowUpdates.ts +287 -0
- package/packages/core/runtime3d/SkinBinding.ts +235 -0
- package/packages/core/runtime3d/Smaa.ts +386 -0
- package/packages/core/runtime3d/SmaaTables.ts +244 -0
- package/packages/core/runtime3d/SpringBones.ts +184 -0
- package/packages/core/runtime3d/SurfaceBuffer.ts +76 -0
- package/packages/core/runtime3d/Surfaces.ts +1105 -0
- package/packages/core/runtime3d/Themes.ts +344 -0
- package/packages/core/runtime3d/Timeline.ts +362 -0
- package/packages/core/runtime3d/ToneCurves.ts +292 -0
- package/packages/core/runtime3d/TransformGizmo.ts +539 -0
- package/packages/core/runtime3d/TriangleMask.ts +250 -0
- package/packages/core/runtime3d/Underwater.ts +778 -0
- package/packages/core/runtime3d/Utf8.ts +87 -0
- package/packages/core/runtime3d/Vrm.ts +773 -0
- package/packages/core/runtime3d/VrmDocument.ts +1830 -0
- package/packages/core/runtime3d/WalkGrid.ts +471 -0
- package/packages/core/runtime3d/WebGPU342Adapters.ts +280 -0
- package/packages/core/runtime3d/index.ts +147 -0
- package/packages/core/shaders/Laya342ShaderTemplates.ts +6 -0
- package/packages/core/shaders/LitSurfaceMaterial.ts +1076 -0
- package/packages/core/shaders/LitSurfaceTemplates.ts +13 -0
- package/packages/core/shaders/ReflectiveSurface.ts +285 -0
- package/packages/core/shaders/ShaderMaterials.ts +387 -0
- package/packages/core/shaders/ToonMaterial.ts +559 -0
- package/packages/core/shaders/WaterRipples.ts +170 -0
- package/packages/core/shaders/WaterSurface.ts +480 -0
- package/packages/core/shaders/ZhudaCommon.ts +109 -0
- package/packages/core/shaders/index.ts +6 -0
- package/packages/core/simulation/Cloth.ts +1541 -0
- package/packages/core/simulation/ParticleCore.ts +498 -0
- package/packages/core/simulation/SpringBones.ts +553 -0
- package/packages/core/simulation/index.ts +3 -0
- package/packages/core/terrain/Heightfield.ts +385 -0
- package/packages/core/terrain/Terrain2D.ts +324 -0
- package/packages/core/terrain/Terrain3D.ts +452 -0
- package/packages/core/terrain/TerrainShell.ts +94 -0
- package/packages/core/terrain/index.ts +3 -0
- package/packages/demo/BenchmarkEngine.ts +184 -0
- package/packages/demo/PixelCalibrationEngine.ts +36 -0
- package/packages/demo/ProceduralStarter.ts +312 -0
- package/packages/demo/StaticAssetPipeline.ts +1631 -0
- package/packages/demo/UnityBridgePipeline.ts +485 -0
- package/packages/demo/index.ts +6 -0
- package/packages/mcp-server/arguments.mjs +81 -0
- package/packages/mcp-server/corpus.mjs +627 -0
- package/packages/mcp-server/film-host.mjs +627 -0
- package/packages/mcp-server/film-session.mjs +95 -0
- package/packages/mcp-server/film-tools.mjs +460 -0
- package/packages/mcp-server/index.mjs +931 -0
- package/packages/mcp-server/quality-route.mjs +332 -0
- package/packages/mcp-server/roots.mjs +72 -0
- package/packages/mcp-server/runtime.mjs +81 -0
- package/packages/types/BitmapFontContract.d.ts +19 -0
- package/packages/types/DeclarativeSDK.d.ts +137 -0
- package/packages/types/IframeSoundAdapter.d.ts +173 -0
- package/packages/types/NoSleepAdapter.d.ts +50 -0
- package/packages/types/PixelCalibrationEngine.d.ts +83 -0
- package/packages/types/Prefab.d.ts +11 -0
- package/packages/types/RealmGuards.d.ts +26 -0
- package/packages/types/ResponsiveLayout.d.ts +10 -0
- package/packages/types/RuntimeGuards.d.ts +55 -0
- package/packages/types/SpineCharacter.d.ts +94 -0
- package/packages/types/SpineVisualContract.d.ts +50 -0
- package/packages/types/SplashSignal.d.ts +27 -0
- package/packages/types/TopologyGraph.d.ts +76 -0
- package/packages/types/VideoSurface.d.ts +21 -0
- package/packages/types/ViewportMatrixEngine.d.ts +27 -0
- package/packages/types/VisualFocusContract.d.ts +32 -0
- package/packages/types/VisualMigrationPipeline.d.ts +53 -0
- package/packages/types/WebViewSurface.d.ts +26 -0
- package/packages/types/audio/OfflineMix.d.ts +10 -0
- package/packages/types/audio/Spatial.d.ts +63 -0
- package/packages/types/audio/StreamVoice.d.ts +31 -0
- package/packages/types/browser.d.ts +44 -0
- package/packages/types/csg/Bsp.d.ts +85 -0
- package/packages/types/csg/index.d.ts +81 -0
- package/packages/types/demo/BenchmarkEngine.d.ts +61 -0
- package/packages/types/demo/PixelCalibrationEngine.d.ts +13 -0
- package/packages/types/demo/ProceduralStarter.d.ts +11 -0
- package/packages/types/demo/StaticAssetPipeline.d.ts +87 -0
- package/packages/types/demo/UnityBridgePipeline.d.ts +49 -0
- package/packages/types/demo/index.d.ts +7 -0
- package/packages/types/editor-preview.d.ts +27 -0
- package/packages/types/effects/Effect2D.d.ts +65 -0
- package/packages/types/effects/Effect3D.d.ts +42 -0
- package/packages/types/effects/EffectBudget.d.ts +179 -0
- package/packages/types/effects/EffectDirector.d.ts +68 -0
- package/packages/types/effects/EffectPresets.d.ts +27 -0
- package/packages/types/effects/EffectPresets2D.d.ts +32 -0
- package/packages/types/effects/EffectSprites.d.ts +23 -0
- package/packages/types/effects/ParticleEventLink.d.ts +16 -0
- package/packages/types/effects/VfxMaterial.d.ts +52 -0
- package/packages/types/film/BakeKey.d.ts +9 -0
- package/packages/types/film/ColorValues.d.ts +25 -0
- package/packages/types/film/FilmLint.d.ts +40 -0
- package/packages/types/film/FilmPrefab.d.ts +22 -0
- package/packages/types/film/FilmReview.d.ts +27 -0
- package/packages/types/film/FilmScene.d.ts +1214 -0
- package/packages/types/film/FilmStage.d.ts +237 -0
- package/packages/types/film/Flythrough.d.ts +44 -0
- package/packages/types/film/FlythroughReport.d.ts +132 -0
- package/packages/types/film/FrameMetrics.d.ts +49 -0
- package/packages/types/film/LiveLook.d.ts +60 -0
- package/packages/types/film/LookQuality.d.ts +24 -0
- package/packages/types/film/Projection.d.ts +20 -0
- package/packages/types/film/SceneLook.d.ts +122 -0
- package/packages/types/film/index.d.ts +13 -0
- package/packages/types/index.d.ts +49 -0
- package/packages/types/particles/EffectEnvelope.d.ts +18 -0
- package/packages/types/particles/LayaParticleRenderer.d.ts +30 -0
- package/packages/types/particles/LayaParticleRenderer3D.d.ts +29 -0
- package/packages/types/particles/ParticleExtras.d.ts +50 -0
- package/packages/types/particles/ParticleMesh3D.d.ts +24 -0
- package/packages/types/particles/ParticleSystem.d.ts +52 -0
- package/packages/types/particles/ParticleSystem3D.d.ts +69 -0
- package/packages/types/particles/ParticleTypes.d.ts +89 -0
- package/packages/types/particles/ParticleTypes3D.d.ts +56 -0
- package/packages/types/particles/RibbonPath3D.d.ts +32 -0
- package/packages/types/particles/RibbonTrail.d.ts +38 -0
- package/packages/types/particles/RibbonTrail3D.d.ts +22 -0
- package/packages/types/particles/index.d.ts +13 -0
- package/packages/types/prefabs/PrefabLibrary.d.ts +176 -0
- package/packages/types/prefabs/PrefabTree3D.d.ts +59 -0
- package/packages/types/prefabs/index.d.ts +4 -0
- package/packages/types/procedural/Geometry.d.ts +252 -0
- package/packages/types/procedural/Hand.d.ts +150 -0
- package/packages/types/procedural/Isosurface.d.ts +181 -0
- package/packages/types/procedural/ModuleHarness.d.ts +90 -0
- package/packages/types/procedural/Noise.d.ts +15 -0
- package/packages/types/procedural/PhotoMaterial.d.ts +49 -0
- package/packages/types/procedural/ProceduralAssetProvider.d.ts +31 -0
- package/packages/types/procedural/ProceduralMaterial.d.ts +63 -0
- package/packages/types/procedural/PropFactory.d.ts +94 -0
- package/packages/types/procedural/Random.d.ts +26 -0
- package/packages/types/procedural/SynthAudio.d.ts +49 -0
- package/packages/types/procedural/TerrainMesh.d.ts +55 -0
- package/packages/types/procedural/TextureRecipe.d.ts +125 -0
- package/packages/types/procedural/TriplanarMaterial.d.ts +27 -0
- package/packages/types/procedural/Variation.d.ts +23 -0
- package/packages/types/procedural/index.d.ts +16 -0
- package/packages/types/runtime3d/ActionFrames.d.ts +62 -0
- package/packages/types/runtime3d/AnimationBlend.d.ts +57 -0
- package/packages/types/runtime3d/AnimationBlendMath.d.ts +27 -0
- package/packages/types/runtime3d/AssetProvider.d.ts +167 -0
- package/packages/types/runtime3d/AssetShowcase.d.ts +44 -0
- package/packages/types/runtime3d/Assets.d.ts +166 -0
- package/packages/types/runtime3d/AsyncDeadline.d.ts +6 -0
- package/packages/types/runtime3d/AsyncOperation.d.ts +3 -0
- package/packages/types/runtime3d/BackendChoice.d.ts +130 -0
- package/packages/types/runtime3d/BakedCrowd.d.ts +156 -0
- package/packages/types/runtime3d/BasisTexture.d.ts +169 -0
- package/packages/types/runtime3d/CameraCollision.d.ts +20 -0
- package/packages/types/runtime3d/CameraEffects.d.ts +134 -0
- package/packages/types/runtime3d/CameraRig.d.ts +27 -0
- package/packages/types/runtime3d/CharacterController.d.ts +71 -0
- package/packages/types/runtime3d/CinematicCapture.d.ts +103 -0
- package/packages/types/runtime3d/Clocks.d.ts +200 -0
- package/packages/types/runtime3d/Cloth.d.ts +57 -0
- package/packages/types/runtime3d/Clouds.d.ts +69 -0
- package/packages/types/runtime3d/ColorLut.d.ts +73 -0
- package/packages/types/runtime3d/CombatQueries.d.ts +50 -0
- package/packages/types/runtime3d/ComputePass.d.ts +134 -0
- package/packages/types/runtime3d/CrowdPresentation.d.ts +104 -0
- package/packages/types/runtime3d/DebugDraw.d.ts +161 -0
- package/packages/types/runtime3d/DebugStats.d.ts +24 -0
- package/packages/types/runtime3d/Decals.d.ts +65 -0
- package/packages/types/runtime3d/DensityVolume.d.ts +39 -0
- package/packages/types/runtime3d/DistanceBricks.d.ts +97 -0
- package/packages/types/runtime3d/Dither.d.ts +78 -0
- package/packages/types/runtime3d/DrawWarmUp.d.ts +93 -0
- package/packages/types/runtime3d/EdgeSmoothing.d.ts +10 -0
- package/packages/types/runtime3d/EnvironmentProbe.d.ts +139 -0
- package/packages/types/runtime3d/Filmic.d.ts +243 -0
- package/packages/types/runtime3d/Foliage.d.ts +95 -0
- package/packages/types/runtime3d/GltfIntake.d.ts +236 -0
- package/packages/types/runtime3d/GltfSecondUv.d.ts +54 -0
- package/packages/types/runtime3d/GraphicsGuard.d.ts +18 -0
- package/packages/types/runtime3d/Grass.d.ts +226 -0
- package/packages/types/runtime3d/GroundTruthAO.d.ts +64 -0
- package/packages/types/runtime3d/HalfFloat.d.ts +13 -0
- package/packages/types/runtime3d/HdrEnvironment.d.ts +144 -0
- package/packages/types/runtime3d/Ik.d.ts +123 -0
- package/packages/types/runtime3d/InputBuffer.d.ts +49 -0
- package/packages/types/runtime3d/InstancedMesh.d.ts +116 -0
- package/packages/types/runtime3d/Laya342Adapters.d.ts +306 -0
- package/packages/types/runtime3d/Laya342GltfAdapter.d.ts +105 -0
- package/packages/types/runtime3d/LensFinish.d.ts +38 -0
- package/packages/types/runtime3d/LensFlare.d.ts +114 -0
- package/packages/types/runtime3d/LightFog.d.ts +190 -0
- package/packages/types/runtime3d/LightingDepth.d.ts +128 -0
- package/packages/types/runtime3d/Lightmap.d.ts +55 -0
- package/packages/types/runtime3d/Math3D.d.ts +19 -0
- package/packages/types/runtime3d/MeshQuery.d.ts +107 -0
- package/packages/types/runtime3d/MeshoptModelDecoder.d.ts +34 -0
- package/packages/types/runtime3d/MiniGameSplash.d.ts +4 -0
- package/packages/types/runtime3d/ModelAnimationSampler.d.ts +26 -0
- package/packages/types/runtime3d/ModelCompatibility.d.ts +169 -0
- package/packages/types/runtime3d/ModelDecoder.d.ts +66 -0
- package/packages/types/runtime3d/ModelInspector.d.ts +77 -0
- package/packages/types/runtime3d/ModelLod.d.ts +61 -0
- package/packages/types/runtime3d/ModelPlacements.d.ts +77 -0
- package/packages/types/runtime3d/ObjectMotion.d.ts +43 -0
- package/packages/types/runtime3d/PhysicalCamera.d.ts +51 -0
- package/packages/types/runtime3d/PointShadow.d.ts +71 -0
- package/packages/types/runtime3d/PointShadowSchedule.d.ts +74 -0
- package/packages/types/runtime3d/Pool.d.ts +33 -0
- package/packages/types/runtime3d/ProbeVolume.d.ts +123 -0
- package/packages/types/runtime3d/QualityGovernor.d.ts +201 -0
- package/packages/types/runtime3d/QualityMemory.d.ts +83 -0
- package/packages/types/runtime3d/RenderScale.d.ts +69 -0
- package/packages/types/runtime3d/RenderSpaces.d.ts +44 -0
- package/packages/types/runtime3d/Renderer.d.ts +62 -0
- package/packages/types/runtime3d/ResultPlayback.d.ts +70 -0
- package/packages/types/runtime3d/Runtime.d.ts +136 -0
- package/packages/types/runtime3d/RuntimeDriver.d.ts +42 -0
- package/packages/types/runtime3d/SceneLifecycle.d.ts +84 -0
- package/packages/types/runtime3d/SceneMutation.d.ts +34 -0
- package/packages/types/runtime3d/SceneQueries.d.ts +71 -0
- package/packages/types/runtime3d/ScreenReflections.d.ts +78 -0
- package/packages/types/runtime3d/SelectionOutline.d.ts +68 -0
- package/packages/types/runtime3d/ShaderErrors.d.ts +27 -0
- package/packages/types/runtime3d/ShaderRegistry.d.ts +10 -0
- package/packages/types/runtime3d/ShaderWarmUp.d.ts +162 -0
- package/packages/types/runtime3d/ShadowUpdates.d.ts +125 -0
- package/packages/types/runtime3d/SkinBinding.d.ts +53 -0
- package/packages/types/runtime3d/Smaa.d.ts +60 -0
- package/packages/types/runtime3d/SmaaTables.d.ts +12 -0
- package/packages/types/runtime3d/SpringBones.d.ts +69 -0
- package/packages/types/runtime3d/SurfaceBuffer.d.ts +28 -0
- package/packages/types/runtime3d/Surfaces.d.ts +326 -0
- package/packages/types/runtime3d/Themes.d.ts +70 -0
- package/packages/types/runtime3d/Timeline.d.ts +88 -0
- package/packages/types/runtime3d/ToneCurves.d.ts +59 -0
- package/packages/types/runtime3d/TransformGizmo.d.ts +139 -0
- package/packages/types/runtime3d/TriangleMask.d.ts +84 -0
- package/packages/types/runtime3d/Underwater.d.ts +120 -0
- package/packages/types/runtime3d/Utf8.d.ts +12 -0
- package/packages/types/runtime3d/Vrm.d.ts +120 -0
- package/packages/types/runtime3d/VrmDocument.d.ts +381 -0
- package/packages/types/runtime3d/WalkGrid.d.ts +94 -0
- package/packages/types/runtime3d/WebGPU342Adapters.d.ts +27 -0
- package/packages/types/runtime3d/index.d.ts +102 -0
- package/packages/types/shaders/Laya342ShaderTemplates.d.ts +3 -0
- package/packages/types/shaders/LitSurfaceMaterial.d.ts +257 -0
- package/packages/types/shaders/LitSurfaceTemplates.d.ts +7 -0
- package/packages/types/shaders/ReflectiveSurface.d.ts +58 -0
- package/packages/types/shaders/ShaderMaterials.d.ts +60 -0
- package/packages/types/shaders/ToonMaterial.d.ts +176 -0
- package/packages/types/shaders/WaterRipples.d.ts +48 -0
- package/packages/types/shaders/WaterSurface.d.ts +110 -0
- package/packages/types/shaders/ZhudaCommon.d.ts +31 -0
- package/packages/types/shaders/index.d.ts +7 -0
- package/packages/types/simulation/Cloth.d.ts +381 -0
- package/packages/types/simulation/ParticleCore.d.ts +125 -0
- package/packages/types/simulation/SpringBones.d.ts +107 -0
- package/packages/types/simulation/index.d.ts +4 -0
- package/packages/types/terrain/Heightfield.d.ts +67 -0
- package/packages/types/terrain/Terrain2D.d.ts +81 -0
- package/packages/types/terrain/Terrain3D.d.ts +80 -0
- package/packages/types/terrain/TerrainShell.d.ts +8 -0
- package/packages/types/terrain/index.d.ts +4 -0
- package/packages/types/vendor/LayaAir.runtime.d.ts +97440 -0
- package/packages/types/vendor/REPAIRS.md +30 -0
- package/packages/types/vendor/restored-3.4.2.json +142 -0
- package/packages/types/vendor/spine.runtime.d.ts +1507 -0
- package/packages/types/vendor/wechat-media.d.ts +877 -0
- package/packages/types/zhuda-2d-ui.d.ts +244 -0
- package/packages/types/zhuda-3d-physics.d.ts +34 -0
- package/packages/types/zhuda-audio.d.ts +128 -0
- package/packages/types/zhuda-bootstrap.d.ts +100 -0
- package/packages/types/zhuda-branding.d.ts +6 -0
- package/packages/types/zhuda-core.d.ts +46 -0
- package/packages/types/zhuda-declarative.d.ts +81 -0
- package/packages/types/zhuda-effects.d.ts +302 -0
- package/packages/types/zhuda-layout.d.ts +96 -0
- package/packages/types/zhuda-particles.d.ts +477 -0
- package/packages/types/zhuda-spine42.d.ts +23 -0
- package/packages/types/zhuda-static-assets.d.ts +389 -0
- package/packages/types/zhuda-video.d.ts +24 -0
- package/packages/types/zhuda-visual-contract.d.ts +52 -0
- package/packages/types/zhuda-webview.d.ts +43 -0
- package/vendor/basis/LICENSE.txt +55 -0
- package/vendor/basis/README.md +25 -0
- package/vendor/basis/basis_transcoder.js +19 -0
- package/vendor/basis/basis_transcoder.wasm +0 -0
- package/vendor/laya-3.4.2/WEBGPU-LICENSES.txt +1259 -0
- package/vendor/laya-3.4.2/libs/laya.ani.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.box2D.js +1209 -0
- package/vendor/laya-3.4.2/libs/laya.bridge.js +2273 -0
- package/vendor/laya-3.4.2/libs/laya.bullet.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.core.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.d3.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.device.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.gltf.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.ik.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.light2D.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.line2D.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.native-spine42.js +7672 -0
- package/vendor/laya-3.4.2/libs/laya.navMesh2d.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.navMesh3d.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.navMeshCommon.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.particle.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.particle3D.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.particleCommon.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.physics2D.js +3774 -0
- package/vendor/laya-3.4.2/libs/laya.physics3D.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.postProcess.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.spine.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.spine3D.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.tilemap.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.trail2D.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.trail3D.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.trailCommon.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.ui.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.ui2.js +9904 -0
- package/vendor/laya-3.4.2/libs/laya.vfx.js +6754 -0
- package/vendor/laya-3.4.2/libs/laya.webgl_2D.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.webgl_3D.js +1 -0
- package/vendor/laya-3.4.2/libs/laya.webgpu_2D.js +18576 -0
- package/vendor/laya-3.4.2/libs/laya.webgpu_3D.js +6729 -0
- package/vendor/laya-3.4.2/libs/nagabind.js +395 -0
- package/vendor/laya-3.4.2/libs/nagabind_bg.wasm +0 -0
- package/vendor/laya-3.4.2/libs/shader_compiler_web.js +22 -0
- package/vendor/laya-3.4.2/libs/shader_compiler_web.wasm +0 -0
- package/vendor/laya-3.4.2/libs/spine-core-3.8.js +1 -0
- package/vendor/laya-3.4.2/libs/spine-core-4.2.js +10216 -0
- package/vendor/laya-3.4.2/webgpu-provenance.json +41 -0
- package/vendor/meshoptimizer/LICENSE.txt +21 -0
- package/vendor/meshoptimizer/README.md +13 -0
- package/vendor/threejs-post/LICENSE.txt +53 -0
- package/vendor/threejs-post/README.md +54 -0
- package/zhuda.config.json +22 -0
|
@@ -0,0 +1,2148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser side of film scenes: mounts a validated `ZhudaFilmScene` into Laya
|
|
3
|
+
* and renders it through `ZhudaCinematicCapture`, so previews, review shots
|
|
4
|
+
* and final frames share one deterministic path. Requires the Laya runtime.
|
|
5
|
+
*/
|
|
6
|
+
import { zhudaBakeKey } from './BakeKey.ts';
|
|
7
|
+
import { zhudaUtf8Decode } from '../runtime3d/Utf8.ts';
|
|
8
|
+
import { projectZhudaFilmPoint } from './Projection.ts';
|
|
9
|
+
import type { ZhudaFilmVec3 } from './FilmScene.ts';
|
|
10
|
+
export { zhudaBakeKey } from './BakeKey.ts';
|
|
11
|
+
import { ZhudaEngine, Zhuda3D } from '../DeclarativeSDK.ts';
|
|
12
|
+
import {
|
|
13
|
+
ZhudaDynamicMesh,
|
|
14
|
+
computeMeshTangents,
|
|
15
|
+
createSurfaceMaterial,
|
|
16
|
+
createSurfaceTexture,
|
|
17
|
+
disposeSurfaceMaterial,
|
|
18
|
+
type MeshData,
|
|
19
|
+
} from '../runtime3d/Surfaces.ts';
|
|
20
|
+
import { ZhudaPhysicalCameraRig } from '../runtime3d/PhysicalCamera.ts';
|
|
21
|
+
import { ZhudaFilmicPipeline } from '../runtime3d/Filmic.ts';
|
|
22
|
+
import {
|
|
23
|
+
ZhudaCinematicCapture,
|
|
24
|
+
type CinematicFramePixels,
|
|
25
|
+
type CinematicLinearChain,
|
|
26
|
+
} from '../runtime3d/CinematicCapture.ts';
|
|
27
|
+
import type { ZhudaRuntimeSession } from '../runtime3d/Runtime.ts';
|
|
28
|
+
import { ZhudaModelLibrary, type AssetLease, type ModelInstance } from '../runtime3d/Assets.ts';
|
|
29
|
+
import type { ZhudaAssetCache } from '../runtime3d/Assets.ts';
|
|
30
|
+
import { createProviderAssetCache, type AssetProvider } from '../runtime3d/AssetProvider.ts';
|
|
31
|
+
import { ZhudaReflectiveSurface } from '../shaders/ReflectiveSurface.ts';
|
|
32
|
+
import { ZhudaWaterSurface } from '../shaders/WaterSurface.ts';
|
|
33
|
+
import { mountZhudaModel } from '../runtime3d/ModelPlacements.ts';
|
|
34
|
+
import { ZhudaLightFog } from '../runtime3d/LightFog.ts';
|
|
35
|
+
import { ZhudaUnderwater, ZHUDA_UNDERWATER_LAYER } from '../runtime3d/Underwater.ts';
|
|
36
|
+
import { ZhudaDecal } from '../runtime3d/Decals.ts';
|
|
37
|
+
import { ZhudaGrassField } from '../runtime3d/Grass.ts';
|
|
38
|
+
import { ZhudaEffect3D } from '../effects/Effect3D.ts';
|
|
39
|
+
import { ZhudaTriangleBvh } from '../runtime3d/MeshQuery.ts';
|
|
40
|
+
import {
|
|
41
|
+
ZhudaAutoExposure,
|
|
42
|
+
ZhudaDepthOfField,
|
|
43
|
+
ZhudaMotionBlur,
|
|
44
|
+
} from '../runtime3d/CameraEffects.ts';
|
|
45
|
+
import { ZhudaClouds } from '../runtime3d/Clouds.ts';
|
|
46
|
+
import { ZhudaScreenReflections } from '../runtime3d/ScreenReflections.ts';
|
|
47
|
+
import { zhudaDecodeColor } from './ColorValues.ts';
|
|
48
|
+
import { ZhudaPointShadow } from '../runtime3d/PointShadow.ts';
|
|
49
|
+
import { ZhudaProbeVolume, zhudaProbeCounts } from '../runtime3d/ProbeVolume.ts';
|
|
50
|
+
import { ZhudaEnvironmentProbe } from '../runtime3d/EnvironmentProbe.ts';
|
|
51
|
+
import { ZhudaLensFinish } from '../runtime3d/LensFinish.ts';
|
|
52
|
+
import { ZhudaEdgeSmoothing } from '../runtime3d/EdgeSmoothing.ts';
|
|
53
|
+
import { ZhudaSmaa } from '../runtime3d/Smaa.ts';
|
|
54
|
+
import {
|
|
55
|
+
ZhudaColorLut,
|
|
56
|
+
parseZhudaCubeLut,
|
|
57
|
+
zhudaIdentityCubeLut,
|
|
58
|
+
type ZhudaCubeLut,
|
|
59
|
+
} from '../runtime3d/ColorLut.ts';
|
|
60
|
+
import { ZhudaLensFlare } from '../runtime3d/LensFlare.ts';
|
|
61
|
+
import {
|
|
62
|
+
ZhudaLightingDepth,
|
|
63
|
+
setZhudaSpotPenumbra,
|
|
64
|
+
zhudaLightingDepthInstalled,
|
|
65
|
+
} from '../runtime3d/LightingDepth.ts';
|
|
66
|
+
import { ZhudaShadowUpdates } from '../runtime3d/ShadowUpdates.ts';
|
|
67
|
+
import { ZhudaModelInspector } from '../runtime3d/ModelInspector.ts';
|
|
68
|
+
import { ZhudaModelAnimationSampler } from '../runtime3d/ModelAnimationSampler.ts';
|
|
69
|
+
import {
|
|
70
|
+
createZhudaLightmap,
|
|
71
|
+
decodeRadianceHdr,
|
|
72
|
+
type ZhudaHdrImage,
|
|
73
|
+
} from '../runtime3d/Lightmap.ts';
|
|
74
|
+
import {
|
|
75
|
+
bakeZhudaTextureSet,
|
|
76
|
+
type ZhudaBakedTextureSet,
|
|
77
|
+
type ZhudaTextureRecipe,
|
|
78
|
+
} from '../procedural/TextureRecipe.ts';
|
|
79
|
+
import { createZhudaProceduralMaterial } from '../procedural/ProceduralMaterial.ts';
|
|
80
|
+
import { createZhudaTriplanarMaterial } from '../procedural/TriplanarMaterial.ts';
|
|
81
|
+
import {
|
|
82
|
+
createZhudaTerrainMesh,
|
|
83
|
+
zhudaTerrainHeightAt,
|
|
84
|
+
zhudaTerrainHeights,
|
|
85
|
+
} from '../procedural/TerrainMesh.ts';
|
|
86
|
+
import {
|
|
87
|
+
createZhudaBoxMesh,
|
|
88
|
+
createZhudaExtrudeMesh,
|
|
89
|
+
createZhudaSweepMesh,
|
|
90
|
+
createZhudaLatheMesh,
|
|
91
|
+
mergeZhudaMeshes,
|
|
92
|
+
transformZhudaMesh,
|
|
93
|
+
} from '../procedural/Geometry.ts';
|
|
94
|
+
import {
|
|
95
|
+
ZhudaPropRegistry,
|
|
96
|
+
mergeZhudaPlacedProps,
|
|
97
|
+
instantiateZhudaPropBatches,
|
|
98
|
+
type ZhudaPropDefinition,
|
|
99
|
+
} from '../procedural/PropFactory.ts';
|
|
100
|
+
import {
|
|
101
|
+
parseZhudaFilmScene,
|
|
102
|
+
resolveZhudaFilmCamera,
|
|
103
|
+
resolveZhudaFilmLook,
|
|
104
|
+
sampleZhudaFilmMotion,
|
|
105
|
+
type ZhudaFilmCamera,
|
|
106
|
+
type ZhudaFilmMaterial,
|
|
107
|
+
type ZhudaFilmLook,
|
|
108
|
+
type ZhudaFilmScene,
|
|
109
|
+
type ZhudaResolvedFilmLook,
|
|
110
|
+
zhudaFilmLookFixedReason,
|
|
111
|
+
zhudaFilmLookRebuildReason,
|
|
112
|
+
zhudaFilmBounceBox,
|
|
113
|
+
} from './FilmScene.ts';
|
|
114
|
+
import { setZhudaDither, zhudaDitherStatus } from '../runtime3d/Dither.ts';
|
|
115
|
+
import { zhudaLookForQuality, type ZhudaLookQuality } from './LookQuality.ts';
|
|
116
|
+
import {
|
|
117
|
+
ZhudaHemisphereAmbientSlot,
|
|
118
|
+
updateZhudaLookInPlace,
|
|
119
|
+
zhudaLookLighting,
|
|
120
|
+
zhudaSunRadiance,
|
|
121
|
+
zhudaTowardSun,
|
|
122
|
+
type ZhudaAppliedLookParts,
|
|
123
|
+
} from './LiveLook.ts';
|
|
124
|
+
|
|
125
|
+
export interface ZhudaFilmStageOptions {
|
|
126
|
+
/** Props a scene may place, by id. */
|
|
127
|
+
props?: readonly ZhudaPropDefinition<any>[];
|
|
128
|
+
/** Named texture recipes a scene may reference. */
|
|
129
|
+
recipes?: Readonly<Record<string, ZhudaTextureRecipe>>;
|
|
130
|
+
/**
|
|
131
|
+
* Baked texture sets keyed by recipe and size. Pass the same map to the next
|
|
132
|
+
* stage so an edited scene does not bake unchanged recipes again.
|
|
133
|
+
*/
|
|
134
|
+
bakeCache?: Map<string, ZhudaBakedTextureSet>;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** What a ray asked of a film stage met. */
|
|
138
|
+
export interface ZhudaFilmRayHit {
|
|
139
|
+
/** The id of the scene node met. */
|
|
140
|
+
readonly node: string;
|
|
141
|
+
/** Metres from the ray's origin. */
|
|
142
|
+
readonly distance: number;
|
|
143
|
+
readonly position: [number, number, number];
|
|
144
|
+
/** The surface normal there, unit length, on the side the ray came from. */
|
|
145
|
+
readonly normal: [number, number, number];
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export interface ZhudaFilmStage {
|
|
149
|
+
readonly scene: ZhudaFilmScene;
|
|
150
|
+
readonly scene3D: any;
|
|
151
|
+
readonly camera: any;
|
|
152
|
+
readonly lens: ZhudaPhysicalCameraRig;
|
|
153
|
+
/** Material names in use and how many meshes each one draws. */
|
|
154
|
+
readonly batches: readonly { material: string; meshes: number }[];
|
|
155
|
+
/** Models placed by the scene, in node order, with the clips each one has. */
|
|
156
|
+
readonly models: readonly {
|
|
157
|
+
id: string;
|
|
158
|
+
asset: string;
|
|
159
|
+
meshes: number;
|
|
160
|
+
lightmap: boolean;
|
|
161
|
+
clips: readonly { name: string; durationSeconds: number }[];
|
|
162
|
+
}[];
|
|
163
|
+
/**
|
|
164
|
+
* Poses the scene for a shot time in seconds: animation clips, moving
|
|
165
|
+
* models and the lights that follow them. `ZhudaFilmRenderer` calls it for
|
|
166
|
+
* every sample.
|
|
167
|
+
*/
|
|
168
|
+
setTime(seconds: number): void;
|
|
169
|
+
/**
|
|
170
|
+
* Moves the camera and sets its lens; ignores depth of field until a render
|
|
171
|
+
* asks for it. The focal length becomes the camera's field of view at the
|
|
172
|
+
* next `prepare`.
|
|
173
|
+
*/
|
|
174
|
+
setCamera(camera: ZhudaFilmCamera): void;
|
|
175
|
+
/**
|
|
176
|
+
* Gives the camera the field of view of the lens for a picture of this
|
|
177
|
+
* aspect (width over height), and draws what the main camera reads (a
|
|
178
|
+
* reflector's mirrored view) for the camera last set. A page calls it once
|
|
179
|
+
* a frame, after `setTime` and `setCamera`; `ZhudaFilmRenderer` calls it
|
|
180
|
+
* before every sample.
|
|
181
|
+
*/
|
|
182
|
+
prepare(aspect: number, frame?: { width: number; height: number; index: number }): void;
|
|
183
|
+
/**
|
|
184
|
+
* Where a point of the world is in a picture of this size for the camera
|
|
185
|
+
* last set: pixels from the picture's top-left corner (CSS pixels for a
|
|
186
|
+
* size in CSS pixels), its depth in metres, and whether it is inside the
|
|
187
|
+
* picture. Null behind the camera. For markers, labels and bars the page
|
|
188
|
+
* draws over the scene; the arithmetic is `projectZhudaFilmPoint`.
|
|
189
|
+
*/
|
|
190
|
+
worldToScreen(
|
|
191
|
+
point: ZhudaFilmVec3,
|
|
192
|
+
size: { width: number; height: number },
|
|
193
|
+
): { x: number; y: number; depth: number; inView: boolean } | null;
|
|
194
|
+
/** Hands the stage something to release when it is disposed (before the scene goes). */
|
|
195
|
+
adopt(release: () => void): void;
|
|
196
|
+
/**
|
|
197
|
+
* The HDR chain's handle for averaging the samples of a frame in
|
|
198
|
+
* scene-linear light; undefined for a look without a grade.
|
|
199
|
+
*/
|
|
200
|
+
linearChain(): CinematicLinearChain | undefined;
|
|
201
|
+
/** What stands in the scene (props, boxes, shapes) as world axis-aligned boxes. */
|
|
202
|
+
readonly solids: readonly { readonly min: number[]; readonly max: number[] }[];
|
|
203
|
+
/**
|
|
204
|
+
* The nearest thing a ray meets among the scene's props, boxes, shapes and
|
|
205
|
+
* ground, either face: the node, the distance in metres, the point and the
|
|
206
|
+
* surface normal there; null when it meets none within `maxMeters`. Models,
|
|
207
|
+
* water, mirrors, grass and decals are not asked. A prop with levels
|
|
208
|
+
* answers with its nearest level.
|
|
209
|
+
*/
|
|
210
|
+
raycast(
|
|
211
|
+
origin: readonly number[],
|
|
212
|
+
direction: readonly number[],
|
|
213
|
+
maxMeters?: number,
|
|
214
|
+
): ZhudaFilmRayHit | null;
|
|
215
|
+
/** The look in use, fully resolved (`scene.look` is the authored one). */
|
|
216
|
+
readonly look: ZhudaResolvedFilmLook;
|
|
217
|
+
/**
|
|
218
|
+
* Changes the look while the stage runs (a day passing, weather turning).
|
|
219
|
+
* The look is validated first; a rejected one changes nothing. When only
|
|
220
|
+
* continuous values differ (see `zhudaFilmLookRebuildReason`) they are set
|
|
221
|
+
* in place, cheap enough for every frame, and `'updated'` is returned.
|
|
222
|
+
* Otherwise the look alone (sky, fog, shadows setup, HDR chain, light fog)
|
|
223
|
+
* is rebuilt and `'rebuilt'` is returned. The water glint and light shafts
|
|
224
|
+
* follow the new sun either way. A panorama or environment cannot be added,
|
|
225
|
+
* removed or changed: remount for that.
|
|
226
|
+
*/
|
|
227
|
+
setLook(look: ZhudaFilmLook): 'updated' | 'rebuilt';
|
|
228
|
+
/** The quality level in use: 3 is the look as authored. */
|
|
229
|
+
readonly quality: ZhudaLookQuality;
|
|
230
|
+
/**
|
|
231
|
+
* Draws the authored look at a lower cost (see `zhudaLookForQuality`), or
|
|
232
|
+
* back at 3 as authored. `setLook` keeps taking the authored look and the
|
|
233
|
+
* level stays on top of it. A scene with water keeps a bare HDR chain at
|
|
234
|
+
* level 0, because the water draws in HDR.
|
|
235
|
+
*/
|
|
236
|
+
setQuality(level: ZhudaLookQuality): 'updated' | 'rebuilt' | 'unchanged';
|
|
237
|
+
/**
|
|
238
|
+
* Changes a light of the scene while it runs: a lamp switched on or off,
|
|
239
|
+
* a flame that flickers. Its glow in the light fog follows. `id` is a
|
|
240
|
+
* `light` node's id; values left out stay as they are.
|
|
241
|
+
*/
|
|
242
|
+
setLight(
|
|
243
|
+
id: string,
|
|
244
|
+
values: {
|
|
245
|
+
enabled?: boolean;
|
|
246
|
+
intensity?: number;
|
|
247
|
+
color?: readonly [number, number, number];
|
|
248
|
+
range?: number;
|
|
249
|
+
},
|
|
250
|
+
): void;
|
|
251
|
+
dispose(): void;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export interface ZhudaFilmAssetsOptions {
|
|
255
|
+
/** Download and parse deadline per asset (default 30000 ms). */
|
|
256
|
+
timeoutMs?: number;
|
|
257
|
+
/** Unused models and lightmaps kept warm for the next mount (default 16). */
|
|
258
|
+
maxIdle?: number;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Models and lightmaps a film scene names by logical asset id. One instance
|
|
263
|
+
* serves every stage a host mounts, so an edited scene does not download or
|
|
264
|
+
* parse unchanged assets again. The provider is borrowed.
|
|
265
|
+
*/
|
|
266
|
+
export class ZhudaFilmAssets {
|
|
267
|
+
readonly models: ZhudaModelLibrary;
|
|
268
|
+
/** Decoded lightmap pictures; each stage uploads and owns its own texture. */
|
|
269
|
+
readonly lightmaps: ZhudaAssetCache<ZhudaHdrImage>;
|
|
270
|
+
/** Decoded sky panoramas (PNG or JPEG); each stage uploads its own texture. */
|
|
271
|
+
readonly pictures: ZhudaAssetCache<ImageBitmap>;
|
|
272
|
+
/** Parsed colour tables (`.cube` files); each stage uploads its own texture. */
|
|
273
|
+
readonly colorTables: ZhudaAssetCache<ZhudaCubeLut>;
|
|
274
|
+
private disposed = false;
|
|
275
|
+
constructor(provider: AssetProvider, options: ZhudaFilmAssetsOptions = {}) {
|
|
276
|
+
const maxIdle = options.maxIdle ?? 16;
|
|
277
|
+
this.models = new ZhudaModelLibrary({
|
|
278
|
+
provider,
|
|
279
|
+
maxIdle,
|
|
280
|
+
timeoutMs: options.timeoutMs ?? 30_000,
|
|
281
|
+
});
|
|
282
|
+
this.lightmaps = createProviderAssetCache(
|
|
283
|
+
provider,
|
|
284
|
+
(asset) => decodeRadianceHdr(asset.bytes),
|
|
285
|
+
() => {},
|
|
286
|
+
maxIdle,
|
|
287
|
+
);
|
|
288
|
+
this.pictures = createProviderAssetCache(
|
|
289
|
+
provider,
|
|
290
|
+
(asset) =>
|
|
291
|
+
createImageBitmap(new Blob([new Uint8Array(asset.bytes)]), {
|
|
292
|
+
premultiplyAlpha: 'none',
|
|
293
|
+
colorSpaceConversion: 'none',
|
|
294
|
+
}),
|
|
295
|
+
(bitmap) => bitmap.close(),
|
|
296
|
+
2,
|
|
297
|
+
);
|
|
298
|
+
this.colorTables = createProviderAssetCache(
|
|
299
|
+
provider,
|
|
300
|
+
(asset) => parseZhudaCubeLut(zhudaUtf8Decode(asset.bytes)),
|
|
301
|
+
() => {},
|
|
302
|
+
2,
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
/** Dispose every stage first. A refusal (something is still held) can be tried again. */
|
|
306
|
+
dispose(): void {
|
|
307
|
+
if (this.disposed) return;
|
|
308
|
+
// Every part is asked, also after one refused; the library counts as disposed
|
|
309
|
+
// only once none did, so a second call finishes what the first could not.
|
|
310
|
+
let refused: unknown;
|
|
311
|
+
for (const part of [this.models, this.lightmaps, this.pictures, this.colorTables])
|
|
312
|
+
try {
|
|
313
|
+
part.dispose();
|
|
314
|
+
} catch (error) {
|
|
315
|
+
refused ??= error;
|
|
316
|
+
}
|
|
317
|
+
if (refused !== undefined) throw refused;
|
|
318
|
+
this.disposed = true;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
interface LoadedFilmModel {
|
|
323
|
+
instance: ModelInstance;
|
|
324
|
+
lightmap?: AssetLease<ZhudaHdrImage>;
|
|
325
|
+
direction?: AssetLease<ZhudaHdrImage>;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function releaseLoaded(loaded: Iterable<LoadedFilmModel>) {
|
|
329
|
+
for (const item of loaded) {
|
|
330
|
+
try {
|
|
331
|
+
item.instance.dispose();
|
|
332
|
+
} catch {
|
|
333
|
+
// Keep releasing the rest.
|
|
334
|
+
}
|
|
335
|
+
item.lightmap?.release();
|
|
336
|
+
item.direction?.release();
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Mounts a scene that places models: loads every model and lightmap through
|
|
342
|
+
* `assets`, then builds the stage. Cancelling `signal`, a timeout or a failed
|
|
343
|
+
* asset releases everything already loaded and rejects; nothing is added to
|
|
344
|
+
* `rootScene` in that case.
|
|
345
|
+
*/
|
|
346
|
+
export async function loadZhudaFilmScene(
|
|
347
|
+
rootScene: any,
|
|
348
|
+
input: ZhudaFilmScene,
|
|
349
|
+
options: ZhudaFilmStageOptions & { assets?: ZhudaFilmAssets; signal?: AbortSignal },
|
|
350
|
+
): Promise<ZhudaFilmStage> {
|
|
351
|
+
const registry = new ZhudaPropRegistry();
|
|
352
|
+
for (const definition of options.props ?? []) registry.register(definition);
|
|
353
|
+
const scene = parseZhudaFilmScene(input, {
|
|
354
|
+
props: registry.ids(),
|
|
355
|
+
recipes: Object.keys(options.recipes ?? {}),
|
|
356
|
+
});
|
|
357
|
+
const nodes = scene.nodes.flatMap((node) => (node.type === 'model' ? [node] : []));
|
|
358
|
+
if (nodes.length && !options.assets)
|
|
359
|
+
throw Error('Film scene places models; give loadZhudaFilmScene an assets library');
|
|
360
|
+
const library = options.assets as ZhudaFilmAssets;
|
|
361
|
+
const results = await Promise.allSettled(
|
|
362
|
+
nodes.map(async (node): Promise<LoadedFilmModel> => {
|
|
363
|
+
const picture = (id: string | undefined) =>
|
|
364
|
+
id === undefined ? undefined : library.lightmaps.acquire(id, { signal: options.signal });
|
|
365
|
+
const [instance, lightmap, direction] = await Promise.allSettled([
|
|
366
|
+
library.models.instantiate(node.asset, { signal: options.signal }),
|
|
367
|
+
picture(node.lightmap),
|
|
368
|
+
picture(node.lightmapDirection),
|
|
369
|
+
]);
|
|
370
|
+
if (
|
|
371
|
+
instance.status === 'fulfilled' &&
|
|
372
|
+
lightmap.status === 'fulfilled' &&
|
|
373
|
+
direction.status === 'fulfilled'
|
|
374
|
+
)
|
|
375
|
+
return { instance: instance.value, lightmap: lightmap.value, direction: direction.value };
|
|
376
|
+
if (instance.status === 'fulfilled') instance.value.dispose();
|
|
377
|
+
if (lightmap.status === 'fulfilled') lightmap.value?.release();
|
|
378
|
+
if (direction.status === 'fulfilled') direction.value?.release();
|
|
379
|
+
const failed = [instance, lightmap, direction].find(
|
|
380
|
+
(result) => result.status === 'rejected',
|
|
381
|
+
) as PromiseRejectedResult;
|
|
382
|
+
const which =
|
|
383
|
+
instance.status === 'rejected'
|
|
384
|
+
? node.asset
|
|
385
|
+
: lightmap.status === 'rejected'
|
|
386
|
+
? node.lightmap
|
|
387
|
+
: node.lightmapDirection;
|
|
388
|
+
if (options.signal?.aborted) throw failed.reason;
|
|
389
|
+
throw Error(
|
|
390
|
+
`Film scene model ${node.id}: cannot load ${which}: ${failed.reason?.message ?? failed.reason}`,
|
|
391
|
+
{ cause: failed.reason },
|
|
392
|
+
);
|
|
393
|
+
}),
|
|
394
|
+
);
|
|
395
|
+
const loaded = new Map<string, LoadedFilmModel>();
|
|
396
|
+
results.forEach((result, i) => {
|
|
397
|
+
if (result.status === 'fulfilled') loaded.set(nodes[i].id, result.value);
|
|
398
|
+
});
|
|
399
|
+
const failure = results.find((result) => result.status === 'rejected');
|
|
400
|
+
if (failure || options.signal?.aborted) {
|
|
401
|
+
releaseLoaded(loaded.values());
|
|
402
|
+
if (options.signal?.aborted)
|
|
403
|
+
throw options.signal.reason ?? new DOMException('Film scene load cancelled', 'AbortError');
|
|
404
|
+
throw (failure as PromiseRejectedResult).reason;
|
|
405
|
+
}
|
|
406
|
+
// The stage owns the loaded assets from here, including on a failed mount.
|
|
407
|
+
const resolved = resolveZhudaFilmLook(scene.look);
|
|
408
|
+
let panorama: AssetLease<ImageBitmap> | undefined;
|
|
409
|
+
if (resolved.panorama) {
|
|
410
|
+
if (!options.assets) {
|
|
411
|
+
releaseLoaded(loaded.values());
|
|
412
|
+
throw Error('Film scene uses a panorama; give loadZhudaFilmScene an assets library');
|
|
413
|
+
}
|
|
414
|
+
try {
|
|
415
|
+
panorama = await options.assets.pictures.acquire(resolved.panorama.asset, {
|
|
416
|
+
signal: options.signal,
|
|
417
|
+
});
|
|
418
|
+
} catch (error) {
|
|
419
|
+
releaseLoaded(loaded.values());
|
|
420
|
+
if (options.signal?.aborted) throw error;
|
|
421
|
+
throw Error(
|
|
422
|
+
`Film scene panorama: cannot load ${resolved.panorama.asset}: ${(error as Error)?.message ?? error}`,
|
|
423
|
+
{ cause: error },
|
|
424
|
+
);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
let colorTable: AssetLease<ZhudaCubeLut> | undefined;
|
|
428
|
+
if (resolved.grade && resolved.grade.lut) {
|
|
429
|
+
const asset = resolved.grade.lut.asset;
|
|
430
|
+
try {
|
|
431
|
+
if (!options.assets)
|
|
432
|
+
throw Error('Film scene uses a colour table; give loadZhudaFilmScene an assets library');
|
|
433
|
+
colorTable = await options.assets.colorTables.acquire(asset, { signal: options.signal });
|
|
434
|
+
} catch (error) {
|
|
435
|
+
releaseLoaded(loaded.values());
|
|
436
|
+
panorama?.release();
|
|
437
|
+
if (options.signal?.aborted || !options.assets) throw error;
|
|
438
|
+
throw Error(
|
|
439
|
+
`Film scene colour table: cannot load ${asset}: ${(error as Error)?.message ?? error}`,
|
|
440
|
+
{ cause: error },
|
|
441
|
+
);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
// Pictures that materials are made of, each decoded once however many materials name it.
|
|
445
|
+
const pictureLeases = new Map<string, AssetLease<ImageBitmap>>();
|
|
446
|
+
const releasePictures = () => {
|
|
447
|
+
for (const lease of pictureLeases.values()) lease.release();
|
|
448
|
+
pictureLeases.clear();
|
|
449
|
+
};
|
|
450
|
+
const wanted = new Set<string>();
|
|
451
|
+
for (const material of Object.values(scene.materials ?? {}))
|
|
452
|
+
if ('picture' in material) {
|
|
453
|
+
wanted.add(material.picture);
|
|
454
|
+
if (material.normal) wanted.add(material.normal);
|
|
455
|
+
}
|
|
456
|
+
if (wanted.size) {
|
|
457
|
+
try {
|
|
458
|
+
if (!options.assets)
|
|
459
|
+
throw Error('Film scene uses picture materials; give loadZhudaFilmScene an assets library');
|
|
460
|
+
for (const id of wanted) {
|
|
461
|
+
try {
|
|
462
|
+
pictureLeases.set(
|
|
463
|
+
id,
|
|
464
|
+
await options.assets.pictures.acquire(id, { signal: options.signal }),
|
|
465
|
+
);
|
|
466
|
+
} catch (error) {
|
|
467
|
+
if (options.signal?.aborted) throw error;
|
|
468
|
+
throw Error(
|
|
469
|
+
`Film scene material picture: cannot load ${id}: ${(error as Error)?.message ?? error}`,
|
|
470
|
+
{ cause: error },
|
|
471
|
+
);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
} catch (error) {
|
|
475
|
+
releaseLoaded(loaded.values());
|
|
476
|
+
panorama?.release();
|
|
477
|
+
colorTable?.release();
|
|
478
|
+
releasePictures();
|
|
479
|
+
throw error;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
let stage: ZhudaFilmStage;
|
|
483
|
+
try {
|
|
484
|
+
stage = buildFilmStage(
|
|
485
|
+
rootScene,
|
|
486
|
+
scene,
|
|
487
|
+
options,
|
|
488
|
+
loaded,
|
|
489
|
+
colorTable?.value,
|
|
490
|
+
new Map([...pictureLeases].map(([id, lease]) => [id, lease.value])),
|
|
491
|
+
);
|
|
492
|
+
} catch (error) {
|
|
493
|
+
panorama?.release();
|
|
494
|
+
colorTable?.release();
|
|
495
|
+
releasePictures();
|
|
496
|
+
throw error;
|
|
497
|
+
}
|
|
498
|
+
if (pictureLeases.size) stage.adopt(releasePictures);
|
|
499
|
+
if (colorTable) {
|
|
500
|
+
const lease = colorTable;
|
|
501
|
+
stage.adopt(() => lease.release());
|
|
502
|
+
}
|
|
503
|
+
if (panorama && resolved.panorama) {
|
|
504
|
+
const lease = panorama;
|
|
505
|
+
stage.adopt(() => lease.release());
|
|
506
|
+
try {
|
|
507
|
+
applyPanorama(stage, lease.value, resolved.panorama);
|
|
508
|
+
} catch (error) {
|
|
509
|
+
stage.dispose();
|
|
510
|
+
throw error;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
const environment = resolved.environment;
|
|
514
|
+
if (environment) {
|
|
515
|
+
try {
|
|
516
|
+
// New meshes are registered on the next native frame; draw two before
|
|
517
|
+
// looking at the surroundings.
|
|
518
|
+
ZhudaEngine.flushRenderFrames(2);
|
|
519
|
+
const probe = new ZhudaEnvironmentProbe(stage.scene3D);
|
|
520
|
+
stage.adopt(() => probe.dispose());
|
|
521
|
+
// The reflecting surface of a reflector is an overlay, not scenery.
|
|
522
|
+
await probe.capture({ ...environment, excludedLayers: [29, 30] }, options.signal);
|
|
523
|
+
} catch (error) {
|
|
524
|
+
stage.dispose();
|
|
525
|
+
throw error;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
const bounce = resolved.bounceLight;
|
|
529
|
+
const box = bounce
|
|
530
|
+
? bounce.min && bounce.max
|
|
531
|
+
? { min: bounce.min, max: bounce.max }
|
|
532
|
+
: zhudaFilmBounceBox(scene)
|
|
533
|
+
: null;
|
|
534
|
+
if (bounce && box) {
|
|
535
|
+
try {
|
|
536
|
+
ZhudaEngine.flushRenderFrames(2);
|
|
537
|
+
const volume = new ZhudaProbeVolume(stage.scene3D, {
|
|
538
|
+
min: box.min,
|
|
539
|
+
max: box.max,
|
|
540
|
+
counts: zhudaProbeCounts(box.min, box.max, bounce.spacing),
|
|
541
|
+
strength: bounce.strength,
|
|
542
|
+
visibility: bounce.visibility,
|
|
543
|
+
excludedLayers: [29, 30],
|
|
544
|
+
solids: stage.solids,
|
|
545
|
+
});
|
|
546
|
+
stage.adopt(() => volume.dispose());
|
|
547
|
+
await volume.bake(options.signal);
|
|
548
|
+
} catch (error) {
|
|
549
|
+
stage.dispose();
|
|
550
|
+
throw error;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
return stage;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* Builds the scene under `rootScene`. Every Laya object is released by
|
|
558
|
+
* `dispose()`, including on a failure part-way through. Scenes that place
|
|
559
|
+
* models load assets first: use `loadZhudaFilmScene`.
|
|
560
|
+
*/
|
|
561
|
+
export function mountZhudaFilmScene(
|
|
562
|
+
rootScene: any,
|
|
563
|
+
input: ZhudaFilmScene,
|
|
564
|
+
options: ZhudaFilmStageOptions = {},
|
|
565
|
+
): ZhudaFilmStage {
|
|
566
|
+
if (Array.isArray(input?.nodes) && input.nodes.some((node) => node?.type === 'model'))
|
|
567
|
+
throw Error('Film scene places models; mount it with loadZhudaFilmScene');
|
|
568
|
+
if (input?.look?.environment)
|
|
569
|
+
throw Error('Film scene captures an environment; mount it with loadZhudaFilmScene');
|
|
570
|
+
if (input?.look?.panorama)
|
|
571
|
+
throw Error('Film scene uses a panorama; mount it with loadZhudaFilmScene');
|
|
572
|
+
if (input?.look?.grade && input.look.grade.lut)
|
|
573
|
+
throw Error('Film scene uses a colour table; mount it with loadZhudaFilmScene');
|
|
574
|
+
return buildFilmStage(rootScene, input, options, new Map());
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
function buildFilmStage(
|
|
578
|
+
rootScene: any,
|
|
579
|
+
input: ZhudaFilmScene,
|
|
580
|
+
options: ZhudaFilmStageOptions,
|
|
581
|
+
loaded: Map<string, LoadedFilmModel>,
|
|
582
|
+
colorTable?: ZhudaCubeLut,
|
|
583
|
+
pictures: Map<string, ImageBitmap> = new Map(),
|
|
584
|
+
): ZhudaFilmStage {
|
|
585
|
+
const cleanups: (() => void)[] = [() => releaseLoaded(loaded.values())];
|
|
586
|
+
let disposed = false;
|
|
587
|
+
const dispose = () => {
|
|
588
|
+
if (disposed) return;
|
|
589
|
+
disposed = true;
|
|
590
|
+
for (const cleanup of cleanups.splice(0).reverse()) {
|
|
591
|
+
try {
|
|
592
|
+
cleanup();
|
|
593
|
+
} catch {
|
|
594
|
+
// Keep releasing the rest.
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
};
|
|
598
|
+
try {
|
|
599
|
+
return buildFilmStageContents(
|
|
600
|
+
rootScene,
|
|
601
|
+
input,
|
|
602
|
+
options,
|
|
603
|
+
loaded,
|
|
604
|
+
cleanups,
|
|
605
|
+
dispose,
|
|
606
|
+
colorTable,
|
|
607
|
+
pictures,
|
|
608
|
+
);
|
|
609
|
+
} catch (error) {
|
|
610
|
+
dispose();
|
|
611
|
+
throw error;
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
function buildFilmStageContents(
|
|
616
|
+
rootScene: any,
|
|
617
|
+
input: ZhudaFilmScene,
|
|
618
|
+
options: ZhudaFilmStageOptions,
|
|
619
|
+
loaded: Map<string, LoadedFilmModel>,
|
|
620
|
+
cleanups: (() => void)[],
|
|
621
|
+
dispose: () => void,
|
|
622
|
+
colorTable?: ZhudaCubeLut,
|
|
623
|
+
pictures: Map<string, ImageBitmap> = new Map(),
|
|
624
|
+
): ZhudaFilmStage {
|
|
625
|
+
const l = (globalThis as any).Laya;
|
|
626
|
+
if (!l?.Scene3D) throw Error('Film scenes need the Laya 3D runtime');
|
|
627
|
+
const registry = new ZhudaPropRegistry();
|
|
628
|
+
for (const definition of options.props ?? []) registry.register(definition);
|
|
629
|
+
const recipes = options.recipes ?? {};
|
|
630
|
+
const scene = parseZhudaFilmScene(input, {
|
|
631
|
+
props: registry.ids(),
|
|
632
|
+
recipes: Object.keys(recipes),
|
|
633
|
+
});
|
|
634
|
+
const bakeCache = options.bakeCache ?? new Map<string, ZhudaBakedTextureSet>();
|
|
635
|
+
let look = resolveZhudaFilmLook(scene.look);
|
|
636
|
+
let currentScene = scene;
|
|
637
|
+
const materials = new Map<string, any>();
|
|
638
|
+
{
|
|
639
|
+
const scene3D = Zhuda3D.createScene3D(rootScene, { ambientColor: [...look.ambient, 1] });
|
|
640
|
+
cleanups.push(() => scene3D.destroy(true));
|
|
641
|
+
const hemisphere = new ZhudaHemisphereAmbientSlot(scene3D);
|
|
642
|
+
cleanups.push(() => hemisphere.release());
|
|
643
|
+
hemisphere.set(look.ambient, look.ambientGround);
|
|
644
|
+
const camera = Zhuda3D.createCamera(scene3D, {
|
|
645
|
+
position: [0, 0, 0],
|
|
646
|
+
clearColor: [...look.sky, 1],
|
|
647
|
+
near: 0.05,
|
|
648
|
+
far: 4000,
|
|
649
|
+
});
|
|
650
|
+
const sun = Zhuda3D.createDirectionalLight(scene3D, {
|
|
651
|
+
rotationEuler: [-look.sun.elevationDeg, look.sun.azimuthDeg, 0],
|
|
652
|
+
intensity: look.sun.intensity,
|
|
653
|
+
color: [...look.sun.color, 1] as [number, number, number, number],
|
|
654
|
+
});
|
|
655
|
+
// The look's own objects (sky, fog, shadow setup, HDR chain, light fog):
|
|
656
|
+
// released together, so `setLook` can rebuild them without the scene.
|
|
657
|
+
const lookCleanups: (() => void)[] = [];
|
|
658
|
+
const releaseLook = () => {
|
|
659
|
+
for (const cleanup of lookCleanups.splice(0).reverse()) {
|
|
660
|
+
try {
|
|
661
|
+
cleanup();
|
|
662
|
+
} catch {
|
|
663
|
+
// Keep releasing the rest.
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
};
|
|
667
|
+
cleanups.push(releaseLook);
|
|
668
|
+
let effects = applyResolvedFilmLook(l, scene3D, camera, sun.light, look, lookCleanups, {
|
|
669
|
+
colorTable,
|
|
670
|
+
});
|
|
671
|
+
let lightFog = effects.lightFog;
|
|
672
|
+
// What moves with shot time; filled in below, applied by `setTime`.
|
|
673
|
+
const timed: ((seconds: number) => void)[] = [];
|
|
674
|
+
const modelPose = new Map<string, { position: number[]; yawDeg: number }>();
|
|
675
|
+
const followPosition = (node: {
|
|
676
|
+
position: number[];
|
|
677
|
+
follows?: { node: string; offset?: number[] };
|
|
678
|
+
}) => {
|
|
679
|
+
const pose = node.follows && modelPose.get(node.follows.node);
|
|
680
|
+
if (!pose) return node.position;
|
|
681
|
+
const [ox, oy, oz] = node.follows!.offset ?? [0, 0, 0],
|
|
682
|
+
yaw = (pose.yawDeg * Math.PI) / 180,
|
|
683
|
+
c = Math.cos(yaw),
|
|
684
|
+
s = Math.sin(yaw);
|
|
685
|
+
return [
|
|
686
|
+
pose.position[0] + ox * c + oz * s,
|
|
687
|
+
pose.position[1] + oy,
|
|
688
|
+
pose.position[2] - ox * s + oz * c,
|
|
689
|
+
];
|
|
690
|
+
};
|
|
691
|
+
const resolveMaterial = (name: string): any => {
|
|
692
|
+
const existing = materials.get(name);
|
|
693
|
+
if (existing) return existing;
|
|
694
|
+
const spec: ZhudaFilmMaterial | undefined =
|
|
695
|
+
scene.materials?.[name] ?? (recipes[name] ? { recipe: name } : undefined);
|
|
696
|
+
if (!spec) throw Error(`Film scene: no material ${name}; add it to scene.materials`);
|
|
697
|
+
let material: any;
|
|
698
|
+
if ('picture' in spec) {
|
|
699
|
+
const made: any[] = [];
|
|
700
|
+
const texture = (id: string, role: 'color' | 'normal') => {
|
|
701
|
+
const bitmap = pictures.get(id);
|
|
702
|
+
if (!bitmap)
|
|
703
|
+
throw Error(
|
|
704
|
+
`Film scene material ${name}: picture ${id} is not loaded; mount with loadZhudaFilmScene and an assets library`,
|
|
705
|
+
);
|
|
706
|
+
const pixels = zhudaBitmapPixels(bitmap);
|
|
707
|
+
// LayaAir reads a normal map's green as pointing down the picture.
|
|
708
|
+
if (role === 'normal' && (spec.normalConvention ?? 'opengl') === 'opengl')
|
|
709
|
+
for (let i = 1; i < pixels.length; i += 4) pixels[i] = 255 - pixels[i];
|
|
710
|
+
const created = createSurfaceTexture(bitmap.width, bitmap.height, pixels, role, {
|
|
711
|
+
mipmap: true,
|
|
712
|
+
});
|
|
713
|
+
made.push(created);
|
|
714
|
+
return created;
|
|
715
|
+
};
|
|
716
|
+
try {
|
|
717
|
+
const albedo = texture(spec.picture, 'color');
|
|
718
|
+
const normal = spec.normal ? texture(spec.normal, 'normal') : undefined;
|
|
719
|
+
material = createSurfaceMaterial({
|
|
720
|
+
type: 'pbr',
|
|
721
|
+
color: spec.tint ?? [1, 1, 1, 1],
|
|
722
|
+
metallic: spec.metallic ?? 0,
|
|
723
|
+
roughness: spec.roughness ?? 0.8,
|
|
724
|
+
textures: { albedo, ...(normal ? { normal } : {}) },
|
|
725
|
+
...(spec.blend ? { blend: spec.blend } : {}),
|
|
726
|
+
...(spec.alphaCutoff !== undefined ? { alphaCutoff: spec.alphaCutoff } : {}),
|
|
727
|
+
...(spec.doubleSided ? { doubleSided: true } : {}),
|
|
728
|
+
});
|
|
729
|
+
} catch (error) {
|
|
730
|
+
for (const one of made) one.destroy();
|
|
731
|
+
throw error;
|
|
732
|
+
}
|
|
733
|
+
material.tilingOffset = new l.Vector4(1 / spec.tileMeters[0], 1 / spec.tileMeters[1], 0, 0);
|
|
734
|
+
if (spec.normal && spec.normalStrength !== undefined)
|
|
735
|
+
material.normalTextureScale = spec.normalStrength;
|
|
736
|
+
const own = material;
|
|
737
|
+
cleanups.push(() => {
|
|
738
|
+
disposeSurfaceMaterial(own);
|
|
739
|
+
for (const one of made) one.destroy();
|
|
740
|
+
});
|
|
741
|
+
} else if ('recipe' in spec) {
|
|
742
|
+
const recipe = typeof spec.recipe === 'string' ? recipes[spec.recipe] : spec.recipe;
|
|
743
|
+
if (!recipe) throw Error(`Film scene: unknown recipe ${String(spec.recipe)}`);
|
|
744
|
+
const size = spec.size ?? 256,
|
|
745
|
+
key = zhudaBakeKey(recipe, size);
|
|
746
|
+
let set = bakeCache.get(key);
|
|
747
|
+
if (!set) {
|
|
748
|
+
set = bakeZhudaTextureSet(recipe, { size });
|
|
749
|
+
bakeCache.set(key, set);
|
|
750
|
+
}
|
|
751
|
+
let fine: ZhudaBakedTextureSet | undefined;
|
|
752
|
+
if (spec.detail) {
|
|
753
|
+
const other =
|
|
754
|
+
typeof spec.detail.recipe === 'string'
|
|
755
|
+
? recipes[spec.detail.recipe]
|
|
756
|
+
: spec.detail.recipe;
|
|
757
|
+
if (!other) throw Error(`Film scene: unknown recipe ${String(spec.detail.recipe)}`);
|
|
758
|
+
const side = spec.detail.size ?? 256,
|
|
759
|
+
fineKey = zhudaBakeKey(other, side);
|
|
760
|
+
fine = bakeCache.get(fineKey);
|
|
761
|
+
if (!fine) {
|
|
762
|
+
fine = bakeZhudaTextureSet(other, { size: side });
|
|
763
|
+
bakeCache.set(fineKey, fine);
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
let over: ZhudaBakedTextureSet | undefined;
|
|
767
|
+
if (spec.top) {
|
|
768
|
+
const other =
|
|
769
|
+
typeof spec.top.recipe === 'string' ? recipes[spec.top.recipe] : spec.top.recipe;
|
|
770
|
+
if (!other) throw Error(`Film scene: unknown recipe ${String(spec.top.recipe)}`);
|
|
771
|
+
const side = spec.top.size ?? 256,
|
|
772
|
+
topKey = zhudaBakeKey(other, side);
|
|
773
|
+
over = bakeCache.get(topKey);
|
|
774
|
+
if (!over) {
|
|
775
|
+
over = bakeZhudaTextureSet(other, { size: side });
|
|
776
|
+
bakeCache.set(topKey, over);
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
const baked =
|
|
780
|
+
spec.projection === 'triplanar'
|
|
781
|
+
? createZhudaTriplanarMaterial(set, {
|
|
782
|
+
...(spec.tint ? { tint: spec.tint } : {}),
|
|
783
|
+
...(over ? { top: { set: over, from: spec.top!.from, to: spec.top!.to } } : {}),
|
|
784
|
+
})
|
|
785
|
+
: createZhudaProceduralMaterial(set, {
|
|
786
|
+
...(spec.tint ? { tint: spec.tint } : {}),
|
|
787
|
+
...(fine
|
|
788
|
+
? {
|
|
789
|
+
detail: {
|
|
790
|
+
set: fine,
|
|
791
|
+
meters: spec.detail!.meters,
|
|
792
|
+
albedo: spec.detail!.albedo,
|
|
793
|
+
normal: spec.detail!.normal,
|
|
794
|
+
},
|
|
795
|
+
}
|
|
796
|
+
: {}),
|
|
797
|
+
...(spec.blend ? { blend: spec.blend } : {}),
|
|
798
|
+
...(spec.alphaCutoff !== undefined ? { alphaCutoff: spec.alphaCutoff } : {}),
|
|
799
|
+
...(spec.doubleSided ? { doubleSided: true } : {}),
|
|
800
|
+
// One repeat of the picture spans many tiles and is not a multiple of one: its own
|
|
801
|
+
// repeat is rare in a view and never lines up with the tiles.
|
|
802
|
+
...(spec.variation
|
|
803
|
+
? {
|
|
804
|
+
variation: {
|
|
805
|
+
amount: spec.variation,
|
|
806
|
+
meters: Math.max(24, Math.max(...set.tileMeters) * 13.7),
|
|
807
|
+
},
|
|
808
|
+
}
|
|
809
|
+
: {}),
|
|
810
|
+
});
|
|
811
|
+
cleanups.push(() => baked.dispose());
|
|
812
|
+
material = baked.material;
|
|
813
|
+
} else {
|
|
814
|
+
material = createSurfaceMaterial({
|
|
815
|
+
type: 'pbr',
|
|
816
|
+
color: [...spec.color, spec.opacity ?? 1],
|
|
817
|
+
...(spec.blend ? { blend: spec.blend } : {}),
|
|
818
|
+
...(spec.alphaCutoff !== undefined ? { alphaCutoff: spec.alphaCutoff } : {}),
|
|
819
|
+
...(spec.doubleSided ? { doubleSided: true } : {}),
|
|
820
|
+
metallic: spec.metallic ?? 0,
|
|
821
|
+
roughness: spec.roughness ?? 0.6,
|
|
822
|
+
emission: spec.emission,
|
|
823
|
+
clearCoat: spec.clearCoat,
|
|
824
|
+
clearCoatRoughness: spec.clearCoatRoughness,
|
|
825
|
+
anisotropy: spec.anisotropy,
|
|
826
|
+
});
|
|
827
|
+
cleanups.push(() => disposeSurfaceMaterial(material));
|
|
828
|
+
}
|
|
829
|
+
materials.set(name, material);
|
|
830
|
+
return material;
|
|
831
|
+
};
|
|
832
|
+
|
|
833
|
+
/** Where the camera was last set; unset until it first is (shot time is applied before that). */
|
|
834
|
+
let eyeNow: readonly [number, number, number] | undefined;
|
|
835
|
+
/** Models and props with a cull distance or levels, by what chooses what they draw. */
|
|
836
|
+
const culled: {
|
|
837
|
+
update(eye: readonly [number, number, number]): unknown;
|
|
838
|
+
invalidate(): void;
|
|
839
|
+
}[] = [];
|
|
840
|
+
const solids: { min: number[]; max: number[] }[] = [];
|
|
841
|
+
const shapes: { node: string; mesh: MeshData; bvh?: ZhudaTriangleBvh }[] = [];
|
|
842
|
+
const raycast = (
|
|
843
|
+
origin: readonly number[],
|
|
844
|
+
direction: readonly number[],
|
|
845
|
+
maxMeters = 100000,
|
|
846
|
+
): ZhudaFilmRayHit | null => {
|
|
847
|
+
const triple = (v: readonly number[], name: string) => {
|
|
848
|
+
if (!Array.isArray(v) || v.length !== 3 || !v.every((n) => Number.isFinite(n)))
|
|
849
|
+
throw Error(`Film stage ray ${name}: [x, y, z] required`);
|
|
850
|
+
};
|
|
851
|
+
triple(origin, 'origin');
|
|
852
|
+
triple(direction, 'direction');
|
|
853
|
+
const length = Math.hypot(direction[0], direction[1], direction[2]);
|
|
854
|
+
if (!(length > 0)) throw Error('Film stage ray direction: must not be zero');
|
|
855
|
+
if (!(maxMeters > 0)) throw Error('Film stage ray maxMeters: must be above 0');
|
|
856
|
+
const ray = {
|
|
857
|
+
origin: { x: origin[0], y: origin[1], z: origin[2] },
|
|
858
|
+
direction: { x: direction[0] / length, y: direction[1] / length, z: direction[2] / length },
|
|
859
|
+
};
|
|
860
|
+
let best: ZhudaFilmRayHit | null = null;
|
|
861
|
+
for (const shape of shapes) {
|
|
862
|
+
shape.bvh ??= new ZhudaTriangleBvh({
|
|
863
|
+
positions: shape.mesh.positions,
|
|
864
|
+
indices: shape.mesh.indices,
|
|
865
|
+
});
|
|
866
|
+
const hit = shape.bvh.raycast(ray, best ? best.distance : maxMeters);
|
|
867
|
+
if (!hit || (best && hit.distance >= best.distance)) continue;
|
|
868
|
+
const sign = hit.frontFace ? 1 : -1;
|
|
869
|
+
best = {
|
|
870
|
+
node: shape.node,
|
|
871
|
+
distance: hit.distance,
|
|
872
|
+
position: [hit.position.x, hit.position.y, hit.position.z],
|
|
873
|
+
normal: [sign * hit.normal.x, sign * hit.normal.y, sign * hit.normal.z],
|
|
874
|
+
};
|
|
875
|
+
}
|
|
876
|
+
return best;
|
|
877
|
+
};
|
|
878
|
+
// A prop with a distance of its own is built by itself; the rest are merged, a mesh a material.
|
|
879
|
+
type SceneNode = (typeof scene.nodes)[number];
|
|
880
|
+
type PropNode = Extract<SceneNode, { type: 'prop' }>;
|
|
881
|
+
const ownDistance = (node: SceneNode) =>
|
|
882
|
+
node.type === 'prop' && (node.cullMeters !== undefined || node.lod !== undefined);
|
|
883
|
+
const placeProp = (node: PropNode, params = node.params) =>
|
|
884
|
+
registry.place(node.prop, {
|
|
885
|
+
position: node.position,
|
|
886
|
+
yawDeg: node.yawDeg,
|
|
887
|
+
seed: node.seed,
|
|
888
|
+
params,
|
|
889
|
+
instance: node.id,
|
|
890
|
+
});
|
|
891
|
+
const placed = scene.nodes.flatMap((node) =>
|
|
892
|
+
node.type === 'prop' && !ownDistance(node) && node.castShadow !== false
|
|
893
|
+
? [placeProp(node)]
|
|
894
|
+
: [],
|
|
895
|
+
);
|
|
896
|
+
const batches = new Map<string, number>();
|
|
897
|
+
// What stands in the scene, as world axis-aligned boxes (for probes to keep out of),
|
|
898
|
+
// and its triangles by node, for a ray asked of the stage.
|
|
899
|
+
const stand = (
|
|
900
|
+
prop: {
|
|
901
|
+
colliders: readonly { min: readonly number[]; max: readonly number[] }[];
|
|
902
|
+
parts: readonly { mesh: MeshData }[];
|
|
903
|
+
},
|
|
904
|
+
id: string,
|
|
905
|
+
) => {
|
|
906
|
+
for (const collider of prop.colliders)
|
|
907
|
+
solids.push({ min: [...collider.min], max: [...collider.max] });
|
|
908
|
+
for (const part of prop.parts) shapes.push({ node: id, mesh: part.mesh });
|
|
909
|
+
};
|
|
910
|
+
const propIds = scene.nodes.flatMap((node) =>
|
|
911
|
+
node.type === 'prop' && !ownDistance(node) && node.castShadow !== false ? [node.id] : [],
|
|
912
|
+
);
|
|
913
|
+
placed.forEach((prop, i) => stand(prop, propIds[i]));
|
|
914
|
+
if (placed.length) {
|
|
915
|
+
const props = instantiateZhudaPropBatches(
|
|
916
|
+
mergeZhudaPlacedProps(placed),
|
|
917
|
+
resolveMaterial,
|
|
918
|
+
scene3D,
|
|
919
|
+
);
|
|
920
|
+
cleanups.push(() => props.dispose());
|
|
921
|
+
for (const mesh of props.meshes) {
|
|
922
|
+
castsShadow(mesh.node);
|
|
923
|
+
const name = materialName(mesh.node.meshRenderer.sharedMaterial, materials);
|
|
924
|
+
batches.set(name, (batches.get(name) ?? 0) + 1);
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
const count = (meshes: readonly { node: any }[]) => {
|
|
928
|
+
for (const mesh of meshes) {
|
|
929
|
+
const name = materialName(mesh.node.meshRenderer.sharedMaterial, materials);
|
|
930
|
+
batches.set(name, (batches.get(name) ?? 0) + 1);
|
|
931
|
+
}
|
|
932
|
+
};
|
|
933
|
+
// Props that cast no shadow and have no distance of their own: merged together.
|
|
934
|
+
const quiet = scene.nodes.flatMap((node) =>
|
|
935
|
+
node.type === 'prop' && !ownDistance(node) && node.castShadow === false
|
|
936
|
+
? [placeProp(node)]
|
|
937
|
+
: [],
|
|
938
|
+
);
|
|
939
|
+
const quietIds = scene.nodes.flatMap((node) =>
|
|
940
|
+
node.type === 'prop' && !ownDistance(node) && node.castShadow === false ? [node.id] : [],
|
|
941
|
+
);
|
|
942
|
+
quiet.forEach((prop, i) => stand(prop, quietIds[i]));
|
|
943
|
+
if (quiet.length) {
|
|
944
|
+
const props = instantiateZhudaPropBatches(
|
|
945
|
+
mergeZhudaPlacedProps(quiet),
|
|
946
|
+
resolveMaterial,
|
|
947
|
+
scene3D,
|
|
948
|
+
);
|
|
949
|
+
cleanups.push(() => props.dispose());
|
|
950
|
+
for (const mesh of props.meshes) mesh.node.meshRenderer.receiveShadow = true;
|
|
951
|
+
count(props.meshes);
|
|
952
|
+
}
|
|
953
|
+
// Props with levels or a cull distance: every level built now, one drawn at a time.
|
|
954
|
+
for (const node of scene.nodes) {
|
|
955
|
+
if (node.type !== 'prop' || !ownDistance(node)) continue;
|
|
956
|
+
const from = (node.lod ?? []).map((level) => level.fromMeters);
|
|
957
|
+
const levels = [
|
|
958
|
+
node.params,
|
|
959
|
+
...(node.lod ?? []).map((l) => ({ ...node.params, ...l.params })),
|
|
960
|
+
].map((params, i) => {
|
|
961
|
+
const one = placeProp(node, params);
|
|
962
|
+
if (i === 0) stand(one, node.id);
|
|
963
|
+
const made = instantiateZhudaPropBatches(
|
|
964
|
+
mergeZhudaPlacedProps([one]),
|
|
965
|
+
resolveMaterial,
|
|
966
|
+
scene3D,
|
|
967
|
+
);
|
|
968
|
+
cleanups.push(() => made.dispose());
|
|
969
|
+
for (const mesh of made.meshes) {
|
|
970
|
+
if (node.castShadow === false) mesh.node.meshRenderer.receiveShadow = true;
|
|
971
|
+
else castsShadow(mesh.node);
|
|
972
|
+
mesh.node.active = i === 0;
|
|
973
|
+
}
|
|
974
|
+
if (i === 0) count(made.meshes);
|
|
975
|
+
return made.meshes;
|
|
976
|
+
});
|
|
977
|
+
const at = node.position,
|
|
978
|
+
cull = node.cullMeters;
|
|
979
|
+
let shown = 0;
|
|
980
|
+
culled.push({
|
|
981
|
+
update(eye) {
|
|
982
|
+
const d = Math.hypot(eye[0] - at[0], eye[1] - at[1], eye[2] - at[2]);
|
|
983
|
+
let level = 0;
|
|
984
|
+
while (level < from.length && d >= from[level]) level++;
|
|
985
|
+
const next = cull !== undefined && d > cull ? -1 : level;
|
|
986
|
+
if (next === shown) return;
|
|
987
|
+
shown = next;
|
|
988
|
+
levels.forEach((meshes, i) => {
|
|
989
|
+
for (const mesh of meshes) mesh.node.active = i === next;
|
|
990
|
+
});
|
|
991
|
+
},
|
|
992
|
+
invalidate() {},
|
|
993
|
+
});
|
|
994
|
+
}
|
|
995
|
+
// Boxes and ground: one merged mesh per material, like props.
|
|
996
|
+
const primitives = new Map<string, MeshData[]>();
|
|
997
|
+
const terrains = new Map<
|
|
998
|
+
string,
|
|
999
|
+
{
|
|
1000
|
+
heights: Float32Array;
|
|
1001
|
+
size: [number, number];
|
|
1002
|
+
cells: [number, number];
|
|
1003
|
+
position: readonly number[];
|
|
1004
|
+
}
|
|
1005
|
+
>();
|
|
1006
|
+
for (const node of scene.nodes) {
|
|
1007
|
+
let mesh: MeshData, material: string;
|
|
1008
|
+
if (node.type === 'box') {
|
|
1009
|
+
material = node.material;
|
|
1010
|
+
mesh = transformZhudaMesh(
|
|
1011
|
+
createZhudaBoxMesh({
|
|
1012
|
+
width: node.size[0],
|
|
1013
|
+
height: node.size[1],
|
|
1014
|
+
depth: node.size[2],
|
|
1015
|
+
origin: 'bottom',
|
|
1016
|
+
bevel: node.bevel,
|
|
1017
|
+
}),
|
|
1018
|
+
{ position: node.position, yawDeg: node.yawDeg },
|
|
1019
|
+
);
|
|
1020
|
+
} else if (node.type === 'lathe') {
|
|
1021
|
+
material = node.material;
|
|
1022
|
+
mesh = transformZhudaMesh(
|
|
1023
|
+
createZhudaLatheMesh({ profile: node.profile, segments: node.segments }),
|
|
1024
|
+
{ position: node.position, yawDeg: node.yawDeg },
|
|
1025
|
+
);
|
|
1026
|
+
} else if (node.type === 'extrude') {
|
|
1027
|
+
material = node.material;
|
|
1028
|
+
mesh = transformZhudaMesh(
|
|
1029
|
+
createZhudaExtrudeMesh({ outline: node.outline, height: node.height }),
|
|
1030
|
+
{ position: node.position, yawDeg: node.yawDeg },
|
|
1031
|
+
);
|
|
1032
|
+
} else if (node.type === 'sweep') {
|
|
1033
|
+
material = node.material;
|
|
1034
|
+
mesh = transformZhudaMesh(
|
|
1035
|
+
createZhudaSweepMesh({ profile: node.profile, path: node.path, closed: node.closed }),
|
|
1036
|
+
{ position: node.position, yawDeg: node.yawDeg },
|
|
1037
|
+
);
|
|
1038
|
+
} else if (node.type === 'terrain') {
|
|
1039
|
+
material = node.material;
|
|
1040
|
+
const options = {
|
|
1041
|
+
size: node.size,
|
|
1042
|
+
cells: node.cells,
|
|
1043
|
+
heights: node.heights,
|
|
1044
|
+
noise: node.noise,
|
|
1045
|
+
};
|
|
1046
|
+
terrains.set(node.id, {
|
|
1047
|
+
heights: zhudaTerrainHeights(options),
|
|
1048
|
+
size: node.size,
|
|
1049
|
+
cells: node.cells,
|
|
1050
|
+
position: node.position,
|
|
1051
|
+
});
|
|
1052
|
+
mesh = transformZhudaMesh(createZhudaTerrainMesh(options), { position: node.position });
|
|
1053
|
+
} else if (node.type === 'ground') {
|
|
1054
|
+
material = node.material;
|
|
1055
|
+
mesh = transformZhudaMesh(
|
|
1056
|
+
createZhudaBoxMesh({
|
|
1057
|
+
width: node.size[0],
|
|
1058
|
+
height: 0.1,
|
|
1059
|
+
depth: node.size[1],
|
|
1060
|
+
origin: 'bottom',
|
|
1061
|
+
}),
|
|
1062
|
+
{ position: [0, (node.y ?? 0) - 0.1, 0] },
|
|
1063
|
+
);
|
|
1064
|
+
} else continue;
|
|
1065
|
+
if (node.type !== 'ground' && node.type !== 'terrain') {
|
|
1066
|
+
const min = [Infinity, Infinity, Infinity],
|
|
1067
|
+
max = [-Infinity, -Infinity, -Infinity];
|
|
1068
|
+
for (let i = 0; i < mesh.positions.length; i += 3)
|
|
1069
|
+
for (let k = 0; k < 3; k++) {
|
|
1070
|
+
min[k] = Math.min(min[k], mesh.positions[i + k]);
|
|
1071
|
+
max[k] = Math.max(max[k], mesh.positions[i + k]);
|
|
1072
|
+
}
|
|
1073
|
+
solids.push({ min, max });
|
|
1074
|
+
}
|
|
1075
|
+
shapes.push({ node: node.id, mesh });
|
|
1076
|
+
const list = primitives.get(material);
|
|
1077
|
+
if (list) list.push(mesh);
|
|
1078
|
+
else primitives.set(material, [mesh]);
|
|
1079
|
+
}
|
|
1080
|
+
for (const [name, meshes] of primitives) {
|
|
1081
|
+
const material = resolveMaterial(name);
|
|
1082
|
+
for (const data of mergeZhudaMeshes(meshes)) {
|
|
1083
|
+
const mesh = new ZhudaDynamicMesh(
|
|
1084
|
+
{ ...data, tangents: computeMeshTangents(data) },
|
|
1085
|
+
scene3D,
|
|
1086
|
+
);
|
|
1087
|
+
mesh.node.meshRenderer.sharedMaterial = material;
|
|
1088
|
+
castsShadow(mesh.node);
|
|
1089
|
+
cleanups.push(() => mesh.dispose());
|
|
1090
|
+
batches.set(name, (batches.get(name) ?? 0) + 1);
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
// Grass on level ground, kept off what stands on it. It is grown for where the
|
|
1095
|
+
// camera is whenever the camera is set, and blown by shot time.
|
|
1096
|
+
const fields: ZhudaGrassField[] = [];
|
|
1097
|
+
let grassSeconds = 0;
|
|
1098
|
+
for (const node of scene.nodes) {
|
|
1099
|
+
if (node.type !== 'grass') continue;
|
|
1100
|
+
const clear = node.clear ?? [];
|
|
1101
|
+
const land = node.on ? terrains.get(node.on) : undefined;
|
|
1102
|
+
if (node.on && !land) throw Error(`Film scene grass ${node.id}: no terrain ${node.on}`);
|
|
1103
|
+
const groundAt = land
|
|
1104
|
+
? (x: number, z: number) =>
|
|
1105
|
+
land.position[1] +
|
|
1106
|
+
(zhudaTerrainHeightAt(
|
|
1107
|
+
land.heights,
|
|
1108
|
+
land.size,
|
|
1109
|
+
land.cells,
|
|
1110
|
+
x - land.position[0],
|
|
1111
|
+
z - land.position[2],
|
|
1112
|
+
) ?? 0)
|
|
1113
|
+
: () => node.y ?? 0;
|
|
1114
|
+
// What reaches down to the ground where it stands, as rectangles of it.
|
|
1115
|
+
const feet =
|
|
1116
|
+
node.avoidSolids === false
|
|
1117
|
+
? []
|
|
1118
|
+
: solids.filter((box) => {
|
|
1119
|
+
const y = groundAt((box.min[0] + box.max[0]) / 2, (box.min[2] + box.max[2]) / 2);
|
|
1120
|
+
return box.min[1] <= y + 0.25 && box.max[1] > y + 0.02;
|
|
1121
|
+
});
|
|
1122
|
+
const {
|
|
1123
|
+
id: _id,
|
|
1124
|
+
type: _type,
|
|
1125
|
+
y: _y,
|
|
1126
|
+
on: _on,
|
|
1127
|
+
clear: _clear,
|
|
1128
|
+
avoidSolids: _avoid,
|
|
1129
|
+
...options
|
|
1130
|
+
} = node;
|
|
1131
|
+
const field = new ZhudaGrassField(scene3D, {
|
|
1132
|
+
...options,
|
|
1133
|
+
ground: groundAt,
|
|
1134
|
+
grows: (x, z) =>
|
|
1135
|
+
(!land ||
|
|
1136
|
+
zhudaTerrainHeightAt(
|
|
1137
|
+
land.heights,
|
|
1138
|
+
land.size,
|
|
1139
|
+
land.cells,
|
|
1140
|
+
x - land.position[0],
|
|
1141
|
+
z - land.position[2],
|
|
1142
|
+
) !== null) &&
|
|
1143
|
+
!clear.some((r) => x >= r.minX && x <= r.maxX && z >= r.minZ && z <= r.maxZ) &&
|
|
1144
|
+
!feet.some(
|
|
1145
|
+
(box) => x >= box.min[0] && x <= box.max[0] && z >= box.min[2] && z <= box.max[2],
|
|
1146
|
+
),
|
|
1147
|
+
});
|
|
1148
|
+
fields.push(field);
|
|
1149
|
+
cleanups.push(() => field.dispose());
|
|
1150
|
+
}
|
|
1151
|
+
if (fields.length)
|
|
1152
|
+
timed.push((seconds) => {
|
|
1153
|
+
grassSeconds = seconds;
|
|
1154
|
+
if (eyeNow) for (const field of fields) field.fill(eyeNow, seconds);
|
|
1155
|
+
});
|
|
1156
|
+
|
|
1157
|
+
// Ready particle effects, placed and stepped to the shot's time.
|
|
1158
|
+
const particleEffects: ZhudaEffect3D[] = [];
|
|
1159
|
+
for (const node of scene.nodes) {
|
|
1160
|
+
if (node.type !== 'effect') continue;
|
|
1161
|
+
const effect = new ZhudaEffect3D(scene3D, node.preset, {
|
|
1162
|
+
position: node.position,
|
|
1163
|
+
yawDeg: node.yawDeg,
|
|
1164
|
+
scale: node.scale,
|
|
1165
|
+
seed: node.seed,
|
|
1166
|
+
});
|
|
1167
|
+
particleEffects.push(effect);
|
|
1168
|
+
cleanups.push(() => effect.dispose());
|
|
1169
|
+
const start = node.startSec ?? 0;
|
|
1170
|
+
timed.push((seconds) => effect.seek(seconds - start));
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
// Marks on surfaces, after the surfaces they lie on.
|
|
1174
|
+
for (const node of scene.nodes) {
|
|
1175
|
+
if (node.type !== 'decal') continue;
|
|
1176
|
+
const { id: _id, type: _type, ...options } = node;
|
|
1177
|
+
const decal = new ZhudaDecal(scene3D, options);
|
|
1178
|
+
cleanups.push(() => decal.dispose());
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
// Models: clones from the shared library; baked lightmaps through Laya's
|
|
1182
|
+
// native lightmap path (`Scene3D.lightmaps`, renderer `lightmapIndex`).
|
|
1183
|
+
const models: ZhudaFilmStage['models'][number][] = [];
|
|
1184
|
+
const modelHolders = new Map<string, any>();
|
|
1185
|
+
const lightmaps: any[] = [];
|
|
1186
|
+
const lightmapped: { renderer: any; index: number }[] = [];
|
|
1187
|
+
for (const node of scene.nodes) {
|
|
1188
|
+
if (node.type !== 'model') continue;
|
|
1189
|
+
const item = loaded.get(node.id);
|
|
1190
|
+
if (!item) throw Error(`Film scene model ${node.id}: not loaded`);
|
|
1191
|
+
const holder = new l.Sprite3D(`ZhudaFilmModel:${node.id}`);
|
|
1192
|
+
scene3D.addChild(holder);
|
|
1193
|
+
cleanups.push(() => holder.destroy(false));
|
|
1194
|
+
holder.transform.position = new l.Vector3(...node.position);
|
|
1195
|
+
holder.transform.rotationEuler = new l.Vector3(0, node.yawDeg ?? 0, 0);
|
|
1196
|
+
const scale = node.scale ?? 1;
|
|
1197
|
+
holder.transform.localScale = new l.Vector3(scale, scale, scale);
|
|
1198
|
+
modelPose.set(node.id, { position: [...node.position], yawDeg: node.yawDeg ?? 0 });
|
|
1199
|
+
if (node.motion) {
|
|
1200
|
+
const keys = node.motion;
|
|
1201
|
+
timed.push((seconds) => {
|
|
1202
|
+
const pose = sampleZhudaFilmMotion(keys, seconds, node.yawDeg ?? 0);
|
|
1203
|
+
modelPose.set(node.id, pose);
|
|
1204
|
+
holder.transform.position = new l.Vector3(...pose.position);
|
|
1205
|
+
holder.transform.rotationEuler = new l.Vector3(0, pose.yawDeg, 0);
|
|
1206
|
+
// Whatever is culled by distance reads where the model is now.
|
|
1207
|
+
for (const lod of culled) lod.invalidate();
|
|
1208
|
+
if (eyeNow) for (const lod of culled) lod.update(eyeNow);
|
|
1209
|
+
});
|
|
1210
|
+
}
|
|
1211
|
+
const mounted = mountZhudaModel(holder, item.instance, {
|
|
1212
|
+
placements: node.placements,
|
|
1213
|
+
instanced: node.instanced,
|
|
1214
|
+
cellMeters: node.cellMeters,
|
|
1215
|
+
castShadow: node.castShadow,
|
|
1216
|
+
cullMeters: node.cullMeters,
|
|
1217
|
+
translucent: node.translucent,
|
|
1218
|
+
emission: node.emission,
|
|
1219
|
+
label: `ZhudaFilmModel:${node.id}`,
|
|
1220
|
+
});
|
|
1221
|
+
cleanups.push(() => mounted.dispose());
|
|
1222
|
+
// A cull distance: what is drawn is chosen again whenever the camera is set.
|
|
1223
|
+
if (mounted.lod) culled.push(mounted.lod);
|
|
1224
|
+
const clips = new ZhudaModelInspector(item.instance).inspect().animations;
|
|
1225
|
+
if (node.animation) {
|
|
1226
|
+
const animation = node.animation;
|
|
1227
|
+
const clip = clips.find((entry) => entry.name === animation.clip);
|
|
1228
|
+
if (!clip)
|
|
1229
|
+
throw Error(
|
|
1230
|
+
`Film scene model ${node.id}: ${node.asset} has no clip ${animation.clip}; it has: ${
|
|
1231
|
+
clips.map((entry) => entry.name).join(', ') || 'none'
|
|
1232
|
+
}`,
|
|
1233
|
+
);
|
|
1234
|
+
const sampler = new ZhudaModelAnimationSampler(
|
|
1235
|
+
item.instance,
|
|
1236
|
+
clip.path,
|
|
1237
|
+
clip.name,
|
|
1238
|
+
clip.layer,
|
|
1239
|
+
);
|
|
1240
|
+
cleanups.push(() => sampler.dispose());
|
|
1241
|
+
timed.push((seconds) =>
|
|
1242
|
+
sampler.sample(
|
|
1243
|
+
Math.max(0, (animation.offsetSec ?? 0) + seconds * (animation.speed ?? 1)),
|
|
1244
|
+
animation.loop ?? true,
|
|
1245
|
+
),
|
|
1246
|
+
);
|
|
1247
|
+
}
|
|
1248
|
+
const renderers = mounted.renderers;
|
|
1249
|
+
if (!renderers.length) throw Error(`Film scene model ${node.id}: ${node.asset} has no mesh`);
|
|
1250
|
+
if (item.lightmap) {
|
|
1251
|
+
for (const renderer of renderers)
|
|
1252
|
+
if (!hasSecondUv(l, renderer))
|
|
1253
|
+
throw Error(
|
|
1254
|
+
`Film scene model ${node.id}: ${node.asset} has a mesh without a second UV set (TEXCOORD_1); a lightmap needs one`,
|
|
1255
|
+
);
|
|
1256
|
+
const baked = createZhudaLightmap(
|
|
1257
|
+
item.lightmap.value,
|
|
1258
|
+
node.lightmapIntensity ?? 1,
|
|
1259
|
+
item.direction?.value,
|
|
1260
|
+
);
|
|
1261
|
+
cleanups.push(() => baked.dispose());
|
|
1262
|
+
const index = lightmaps.push(baked.lightmap) - 1;
|
|
1263
|
+
for (const renderer of renderers) lightmapped.push({ renderer, index });
|
|
1264
|
+
}
|
|
1265
|
+
modelHolders.set(node.id, holder);
|
|
1266
|
+
models.push({
|
|
1267
|
+
id: node.id,
|
|
1268
|
+
asset: node.asset,
|
|
1269
|
+
meshes: renderers.length,
|
|
1270
|
+
lightmap: !!item.lightmap,
|
|
1271
|
+
clips: clips.map((entry) => ({ name: entry.name, durationSeconds: entry.durationSeconds })),
|
|
1272
|
+
});
|
|
1273
|
+
}
|
|
1274
|
+
if (lightmaps.length) {
|
|
1275
|
+
scene3D.lightmaps = lightmaps;
|
|
1276
|
+
// Clear the list before the textures go (cleanups run in reverse).
|
|
1277
|
+
cleanups.push(() => (scene3D.lightmaps = []));
|
|
1278
|
+
for (const { renderer, index } of lightmapped) {
|
|
1279
|
+
renderer.lightmapScaleOffset = new l.Vector4(1, 1, 0, 0);
|
|
1280
|
+
renderer.lightmapIndex = index;
|
|
1281
|
+
renderer.setLightmapIndex?.(index);
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
// Reflector: a mirrored scene camera plus an additive surface.
|
|
1286
|
+
let reflector: ZhudaReflectiveSurface | undefined;
|
|
1287
|
+
for (const node of scene.nodes) {
|
|
1288
|
+
if (node.type !== 'reflector') continue;
|
|
1289
|
+
const surface = new ZhudaReflectiveSurface(scene3D, {
|
|
1290
|
+
position: node.position,
|
|
1291
|
+
size: node.size,
|
|
1292
|
+
strength: node.strength,
|
|
1293
|
+
wetness: node.wetness,
|
|
1294
|
+
roughness: node.roughness,
|
|
1295
|
+
ripple: node.ripple,
|
|
1296
|
+
patternMeters: node.patternMeters,
|
|
1297
|
+
resolution: node.resolution,
|
|
1298
|
+
});
|
|
1299
|
+
cleanups.push(() => surface.dispose());
|
|
1300
|
+
surface.camera.clearFlag = camera.clearFlag;
|
|
1301
|
+
surface.camera.clearColor = camera.clearColor;
|
|
1302
|
+
for (const id of node.hides ?? []) setLayer(modelHolders.get(id), surface.layer);
|
|
1303
|
+
reflector = surface;
|
|
1304
|
+
}
|
|
1305
|
+
let water: ZhudaWaterSurface | undefined;
|
|
1306
|
+
for (const node of scene.nodes) {
|
|
1307
|
+
if (node.type !== 'water') continue;
|
|
1308
|
+
const surface = new ZhudaWaterSurface(scene3D, {
|
|
1309
|
+
position: node.position,
|
|
1310
|
+
size: node.size,
|
|
1311
|
+
flow: node.flow,
|
|
1312
|
+
color: node.color && zhudaDecodeColor(node.color),
|
|
1313
|
+
clarity: node.clarity,
|
|
1314
|
+
waveMeters: node.waveMeters,
|
|
1315
|
+
waves: node.waves,
|
|
1316
|
+
refraction: node.refraction,
|
|
1317
|
+
reflection: node.reflection,
|
|
1318
|
+
glow: node.glow,
|
|
1319
|
+
foamDepth: node.foamDepth,
|
|
1320
|
+
resolution: node.resolution,
|
|
1321
|
+
sun: { toward: zhudaTowardSun(l, sun.light), color: zhudaSunRadiance(look) },
|
|
1322
|
+
});
|
|
1323
|
+
cleanups.push(() => surface.dispose());
|
|
1324
|
+
surface.camera.clearFlag = camera.clearFlag;
|
|
1325
|
+
surface.camera.clearColor = camera.clearColor;
|
|
1326
|
+
for (const id of node.hides ?? []) setLayer(modelHolders.get(id), surface.layer);
|
|
1327
|
+
// The water reads the scene behind it and how far away that is.
|
|
1328
|
+
const before = { depth: camera.depthTextureMode, opaque: camera.opaquePass };
|
|
1329
|
+
camera.depthTextureMode |= l.DepthTextureMode.Depth;
|
|
1330
|
+
camera.opaquePass = true;
|
|
1331
|
+
cleanups.push(() => {
|
|
1332
|
+
camera.depthTextureMode = before.depth;
|
|
1333
|
+
camera.opaquePass = before.opaque;
|
|
1334
|
+
});
|
|
1335
|
+
timed.push((seconds) => surface.setTime(seconds));
|
|
1336
|
+
if (node.ripples?.length)
|
|
1337
|
+
surface.setRipples(
|
|
1338
|
+
node.ripples.map(({ position: [x, z], radius, strength, velocity }) => ({
|
|
1339
|
+
x,
|
|
1340
|
+
z,
|
|
1341
|
+
radius,
|
|
1342
|
+
strength,
|
|
1343
|
+
velocity,
|
|
1344
|
+
})),
|
|
1345
|
+
);
|
|
1346
|
+
water = surface;
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
// Practical lights: native point and spot light components.
|
|
1350
|
+
const realTime = scene.nodes.filter((node) => node.type === 'light' && !node.fogOnly).length;
|
|
1351
|
+
const capacity = l.Config3D?.maxLightCount ?? 32;
|
|
1352
|
+
// The sun is a light too.
|
|
1353
|
+
if (realTime + 1 > capacity)
|
|
1354
|
+
throw Error(
|
|
1355
|
+
`Film scene has ${realTime} real-time lights but the runtime was booted for ${capacity} (one is the sun); boot with maxLights`,
|
|
1356
|
+
);
|
|
1357
|
+
// What `setLight` changed, and the native light of each node that has one.
|
|
1358
|
+
const lightValues = new Map<
|
|
1359
|
+
string,
|
|
1360
|
+
{ enabled: boolean; intensity: number; color: [number, number, number]; range: number }
|
|
1361
|
+
>();
|
|
1362
|
+
const nativeLights = new Map<string, any>();
|
|
1363
|
+
for (const node of scene.nodes)
|
|
1364
|
+
if (node.type === 'light')
|
|
1365
|
+
lightValues.set(node.id, {
|
|
1366
|
+
enabled: true,
|
|
1367
|
+
intensity: node.intensity ?? 2,
|
|
1368
|
+
color: [...(node.color ?? [1, 0.82, 0.6])] as [number, number, number],
|
|
1369
|
+
range: node.range ?? 12,
|
|
1370
|
+
});
|
|
1371
|
+
// Point lights that cast shadows, up to eight, in one set of pictures. Each
|
|
1372
|
+
// light's six are drawn in `prepare`, when everything that casts is in
|
|
1373
|
+
// place, and again when its reach or something that moves with time changed.
|
|
1374
|
+
const pointCasters = scene.nodes.filter((node) => {
|
|
1375
|
+
const light = node as {
|
|
1376
|
+
type: string;
|
|
1377
|
+
kind?: string;
|
|
1378
|
+
castsShadow?: boolean;
|
|
1379
|
+
fogOnly?: boolean;
|
|
1380
|
+
};
|
|
1381
|
+
return (
|
|
1382
|
+
light.type === 'light' && light.kind === 'point' && light.castsShadow && !light.fogOnly
|
|
1383
|
+
);
|
|
1384
|
+
}).length;
|
|
1385
|
+
const pointShadow = pointCasters
|
|
1386
|
+
? new ZhudaPointShadow(scene3D, { lights: pointCasters })
|
|
1387
|
+
: undefined;
|
|
1388
|
+
if (pointShadow) cleanups.push(() => pointShadow.dispose());
|
|
1389
|
+
const pointShadows: {
|
|
1390
|
+
id: string;
|
|
1391
|
+
light: number;
|
|
1392
|
+
/** The light's node: a lamp that follows a model is where the model has carried it. */
|
|
1393
|
+
node: { position: number[]; follows?: { node: string; offset?: number[] } };
|
|
1394
|
+
range: number;
|
|
1395
|
+
dirty: boolean;
|
|
1396
|
+
}[] = [];
|
|
1397
|
+
let shadowTime = 0;
|
|
1398
|
+
for (const node of scene.nodes) {
|
|
1399
|
+
if (node.type !== 'light' || node.fogOnly) continue;
|
|
1400
|
+
const holder = new l.Sprite3D(`ZhudaFilmLight:${node.id}`);
|
|
1401
|
+
scene3D.addChild(holder);
|
|
1402
|
+
cleanups.push(() => holder.destroy(true));
|
|
1403
|
+
holder.transform.position = new l.Vector3(...node.position);
|
|
1404
|
+
if (node.follows)
|
|
1405
|
+
timed.push(() => (holder.transform.position = new l.Vector3(...followPosition(node))));
|
|
1406
|
+
const light = holder.addComponent(node.kind === 'spot' ? l.SpotLightCom : l.PointLightCom);
|
|
1407
|
+
nativeLights.set(node.id, light);
|
|
1408
|
+
const [r, g, b] = node.color ?? [1, 0.82, 0.6];
|
|
1409
|
+
light.color = new l.Color(r, g, b, 1);
|
|
1410
|
+
light.intensity = node.intensity ?? 2;
|
|
1411
|
+
light.range = node.range ?? 12;
|
|
1412
|
+
if (node.kind === 'spot') {
|
|
1413
|
+
light.spotAngle = node.spotAngleDeg ?? 60;
|
|
1414
|
+
if (node.penumbra !== undefined) {
|
|
1415
|
+
setZhudaSpotPenumbra(light, node.penumbra);
|
|
1416
|
+
cleanups.push(() => setZhudaSpotPenumbra(light, null));
|
|
1417
|
+
}
|
|
1418
|
+
const [tx, ty, tz] = node.target!,
|
|
1419
|
+
[px, py, pz] = node.position;
|
|
1420
|
+
// A light aimed straight down or up needs another up vector.
|
|
1421
|
+
const vertical = Math.hypot(tx - px, tz - pz) < 1e-6 * Math.max(1, Math.abs(ty - py));
|
|
1422
|
+
holder.transform.lookAt(
|
|
1423
|
+
new l.Vector3(tx, ty, tz),
|
|
1424
|
+
vertical ? new l.Vector3(0, 0, 1) : new l.Vector3(0, 1, 0),
|
|
1425
|
+
);
|
|
1426
|
+
if (node.castsShadow) {
|
|
1427
|
+
light.shadowMode = l.ShadowMode.SoftHigh;
|
|
1428
|
+
light.shadowStrength = 1;
|
|
1429
|
+
light.shadowResolution = 2048;
|
|
1430
|
+
light.shadowDistance = node.range ?? 12;
|
|
1431
|
+
cleanups.push(() => (light.shadowMode = l.ShadowMode.None));
|
|
1432
|
+
}
|
|
1433
|
+
} else if (node.castsShadow) {
|
|
1434
|
+
pointShadows.push({
|
|
1435
|
+
id: node.id,
|
|
1436
|
+
light: pointShadows.length,
|
|
1437
|
+
node,
|
|
1438
|
+
range: node.range ?? 12,
|
|
1439
|
+
dirty: true,
|
|
1440
|
+
});
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
|
|
1444
|
+
// Lights in the fog, after the models they may follow.
|
|
1445
|
+
const fogNodes = scene.nodes.flatMap((node) =>
|
|
1446
|
+
node.type === 'light' && node.kind === 'point' ? [node] : [],
|
|
1447
|
+
);
|
|
1448
|
+
const fogLights = () =>
|
|
1449
|
+
lightFog?.setLights(
|
|
1450
|
+
fogNodes.map((node) => {
|
|
1451
|
+
const now = lightValues.get(node.id)!;
|
|
1452
|
+
return {
|
|
1453
|
+
position: followPosition(node) as [number, number, number],
|
|
1454
|
+
// The lamp's glow in the fog in the colour its light has on surfaces.
|
|
1455
|
+
color: zhudaDecodeColor(now.color),
|
|
1456
|
+
intensity: now.enabled ? now.intensity : 0,
|
|
1457
|
+
range: now.range,
|
|
1458
|
+
};
|
|
1459
|
+
}),
|
|
1460
|
+
);
|
|
1461
|
+
if (fogNodes.some((node) => node.follows)) timed.push(fogLights);
|
|
1462
|
+
const setTime = (seconds: number) => {
|
|
1463
|
+
if (!Number.isFinite(seconds) || seconds < 0) throw Error('Invalid film time');
|
|
1464
|
+
for (const apply of timed) apply(seconds);
|
|
1465
|
+
// The samples of a still differ in time: each moves the ray noise elsewhere.
|
|
1466
|
+
effects.reflections?.setPhase(seconds);
|
|
1467
|
+
effects.clouds?.setTime(seconds);
|
|
1468
|
+
effects.underwater?.setTime(seconds);
|
|
1469
|
+
// What moves with time may cast on the lamp's pictures: draw them again.
|
|
1470
|
+
if (pointShadows.length && timed.length && seconds !== shadowTime) {
|
|
1471
|
+
shadowTime = seconds;
|
|
1472
|
+
for (const casting of pointShadows) casting.dirty = true;
|
|
1473
|
+
}
|
|
1474
|
+
};
|
|
1475
|
+
fogLights();
|
|
1476
|
+
setTime(0);
|
|
1477
|
+
|
|
1478
|
+
const first = resolveZhudaFilmCamera(scene.camera);
|
|
1479
|
+
const lens = new ZhudaPhysicalCameraRig(camera, {
|
|
1480
|
+
focalLengthMm: first.focalLengthMm,
|
|
1481
|
+
fStop: first.fStop,
|
|
1482
|
+
focusDistanceM: first.focusDistanceM,
|
|
1483
|
+
});
|
|
1484
|
+
cleanups.push(() => lens.dispose());
|
|
1485
|
+
let current = resolveZhudaFilmCamera(scene.camera);
|
|
1486
|
+
const prepare = (aspect: number, frame?: { width: number; height: number; index: number }) => {
|
|
1487
|
+
// The focal length last set becomes the camera's field of view here, so a page that only
|
|
1488
|
+
// calls setCamera and prepare draws through the lens. A capture has applied it already and
|
|
1489
|
+
// holds a sample of the aperture: the lens is left alone then.
|
|
1490
|
+
if (!lens.sampling) lens.apply(aspect);
|
|
1491
|
+
// Particles face the camera of this frame.
|
|
1492
|
+
for (const effect of particleEffects) effect.render(camera);
|
|
1493
|
+
// A still or a sample of a video draws the sun's shadows whatever `shadows.update` says.
|
|
1494
|
+
effects.shadowUpdates?.redraw();
|
|
1495
|
+
for (const casting of pointShadows)
|
|
1496
|
+
if (casting.dirty) {
|
|
1497
|
+
casting.dirty = false;
|
|
1498
|
+
pointShadow!.render(followPosition(casting.node), casting.range, casting.light);
|
|
1499
|
+
}
|
|
1500
|
+
if (frame) effects.finish?.setFrame(frame.width, frame.height, frame.index);
|
|
1501
|
+
if (frame) lightFog?.setFrame(frame.index);
|
|
1502
|
+
lightFog?.update(current.eye, current.target, camera.fieldOfView, aspect);
|
|
1503
|
+
lightFog?.renderShafts();
|
|
1504
|
+
effects.underwater?.update(
|
|
1505
|
+
current.eye,
|
|
1506
|
+
current.target,
|
|
1507
|
+
camera.fieldOfView,
|
|
1508
|
+
aspect,
|
|
1509
|
+
camera.farPlane,
|
|
1510
|
+
);
|
|
1511
|
+
effects.reflections?.update(current.eye, current.target, camera.fieldOfView, aspect);
|
|
1512
|
+
effects.clouds?.update(current.eye, current.target, camera.fieldOfView, aspect);
|
|
1513
|
+
// A film frame is not smeared from the camera of the frame drawn before it:
|
|
1514
|
+
// a video gets its motion blur from its samples.
|
|
1515
|
+
effects.motionBlur?.resetHistory();
|
|
1516
|
+
effects.motionBlur?.update(current.eye, current.target, camera.fieldOfView, aspect);
|
|
1517
|
+
// A film frame does not depend on the frames drawn before it.
|
|
1518
|
+
effects.exposure?.setFrameSeconds(3600);
|
|
1519
|
+
for (const surface of [reflector, water]) {
|
|
1520
|
+
if (!surface) continue;
|
|
1521
|
+
surface.update(current.eye, current.target, camera.fieldOfView, aspect);
|
|
1522
|
+
surface.render();
|
|
1523
|
+
}
|
|
1524
|
+
};
|
|
1525
|
+
const setCamera = (value: ZhudaFilmCamera) => {
|
|
1526
|
+
const c = resolveZhudaFilmCamera(value);
|
|
1527
|
+
current = c;
|
|
1528
|
+
camera.transform.position = new l.Vector3(...c.eye);
|
|
1529
|
+
camera.transform.lookAt(new l.Vector3(...c.target), new l.Vector3(0, 1, 0));
|
|
1530
|
+
eyeNow = [c.eye[0], c.eye[1], c.eye[2]];
|
|
1531
|
+
for (const lod of culled) lod.update(c.eye);
|
|
1532
|
+
for (const field of fields) field.fill(c.eye, grassSeconds);
|
|
1533
|
+
lens.configure({
|
|
1534
|
+
focalLengthMm: c.focalLengthMm,
|
|
1535
|
+
fStop: c.fStop,
|
|
1536
|
+
focusDistanceM: c.focusDistanceM,
|
|
1537
|
+
});
|
|
1538
|
+
};
|
|
1539
|
+
setCamera(scene.camera);
|
|
1540
|
+
|
|
1541
|
+
let live = true;
|
|
1542
|
+
cleanups.push(() => (live = false));
|
|
1543
|
+
const mirrors = [reflector, water].filter((surface) => !!surface) as {
|
|
1544
|
+
camera: any;
|
|
1545
|
+
}[];
|
|
1546
|
+
const afterLook = () => {
|
|
1547
|
+
hemisphere.set(look.ambient, look.ambientGround);
|
|
1548
|
+
for (const surface of mirrors) {
|
|
1549
|
+
surface.camera.clearFlag = camera.clearFlag;
|
|
1550
|
+
surface.camera.clearColor = camera.clearColor;
|
|
1551
|
+
}
|
|
1552
|
+
water?.setSun({ toward: zhudaTowardSun(l, sun.light), color: zhudaSunRadiance(look) });
|
|
1553
|
+
};
|
|
1554
|
+
const buildLook = (resolved: ZhudaResolvedFilmLook) => {
|
|
1555
|
+
effects = applyResolvedFilmLook(l, scene3D, camera, sun.light, resolved, lookCleanups, {
|
|
1556
|
+
colorTable,
|
|
1557
|
+
});
|
|
1558
|
+
lightFog = effects.lightFog;
|
|
1559
|
+
// A new HDR chain restored the camera's depth settings: the water still reads depth.
|
|
1560
|
+
if (water) {
|
|
1561
|
+
camera.depthTextureMode |= l.DepthTextureMode.Depth;
|
|
1562
|
+
camera.opaquePass = true;
|
|
1563
|
+
}
|
|
1564
|
+
fogLights();
|
|
1565
|
+
updateZhudaLookInPlace(l, { scene3D, camera, sun: sun.light, parts: effects }, resolved);
|
|
1566
|
+
};
|
|
1567
|
+
// The authored look and the quality level drawn on top of it.
|
|
1568
|
+
let authored = look;
|
|
1569
|
+
// The colour table loaded with the scene: the only one a later look may name.
|
|
1570
|
+
const loadedTable = look.grade && look.grade.lut ? look.grade.lut.asset : null;
|
|
1571
|
+
let quality: ZhudaLookQuality = 3;
|
|
1572
|
+
const keepGrade = scene.nodes.some((node) => node.type === 'water');
|
|
1573
|
+
// Bounce light is captured once, at mount: a quality level neither removes nor adds it.
|
|
1574
|
+
const atQuality = (resolved: ZhudaResolvedFilmLook) => {
|
|
1575
|
+
const next = zhudaLookForQuality(resolved, quality, { keepGrade });
|
|
1576
|
+
next.bounceLight = structuredClone(resolved.bounceLight);
|
|
1577
|
+
return next;
|
|
1578
|
+
};
|
|
1579
|
+
const setLook = (next: ZhudaFilmLook): 'updated' | 'rebuilt' => {
|
|
1580
|
+
if (!live) throw Error('Disposed film stage');
|
|
1581
|
+
const candidate = parseZhudaFilmScene(
|
|
1582
|
+
{ ...currentScene, look: next },
|
|
1583
|
+
{ props: registry.ids(), recipes: Object.keys(recipes) },
|
|
1584
|
+
);
|
|
1585
|
+
const mode = drawLook(atQuality(resolveZhudaFilmLook(candidate.look)));
|
|
1586
|
+
authored = resolveZhudaFilmLook(candidate.look);
|
|
1587
|
+
currentScene = candidate;
|
|
1588
|
+
return mode;
|
|
1589
|
+
};
|
|
1590
|
+
const setQuality = (level: ZhudaLookQuality): 'updated' | 'rebuilt' | 'unchanged' => {
|
|
1591
|
+
if (!live) throw Error('Disposed film stage');
|
|
1592
|
+
if (![0, 1, 2, 3].includes(level)) throw Error('Look quality: use 0, 1, 2 or 3');
|
|
1593
|
+
if (level === quality) return 'unchanged';
|
|
1594
|
+
const previous = quality;
|
|
1595
|
+
quality = level;
|
|
1596
|
+
try {
|
|
1597
|
+
return drawLook(atQuality(authored));
|
|
1598
|
+
} catch (error) {
|
|
1599
|
+
quality = previous;
|
|
1600
|
+
throw error;
|
|
1601
|
+
}
|
|
1602
|
+
};
|
|
1603
|
+
const setLight = (
|
|
1604
|
+
id: string,
|
|
1605
|
+
values: {
|
|
1606
|
+
enabled?: boolean;
|
|
1607
|
+
intensity?: number;
|
|
1608
|
+
color?: readonly [number, number, number];
|
|
1609
|
+
range?: number;
|
|
1610
|
+
},
|
|
1611
|
+
) => {
|
|
1612
|
+
if (!live) throw Error('Disposed film stage');
|
|
1613
|
+
const now = lightValues.get(id);
|
|
1614
|
+
if (!now) throw Error(`Film stage: no light ${id}`);
|
|
1615
|
+
const next = { ...now };
|
|
1616
|
+
if (values.enabled !== undefined) {
|
|
1617
|
+
if (typeof values.enabled !== 'boolean') throw Error('setLight: enabled is true or false');
|
|
1618
|
+
next.enabled = values.enabled;
|
|
1619
|
+
}
|
|
1620
|
+
if (values.intensity !== undefined) {
|
|
1621
|
+
if (!(values.intensity >= 0 && values.intensity <= 100000))
|
|
1622
|
+
throw Error('setLight: intensity 0..100000');
|
|
1623
|
+
next.intensity = values.intensity;
|
|
1624
|
+
}
|
|
1625
|
+
if (values.range !== undefined) {
|
|
1626
|
+
if (!(values.range > 0 && values.range <= 10000)) throw Error('setLight: range above 0');
|
|
1627
|
+
next.range = values.range;
|
|
1628
|
+
}
|
|
1629
|
+
if (values.color !== undefined) {
|
|
1630
|
+
if (
|
|
1631
|
+
!Array.isArray(values.color) ||
|
|
1632
|
+
values.color.length !== 3 ||
|
|
1633
|
+
!values.color.every((c) => Number.isFinite(c) && c >= 0)
|
|
1634
|
+
)
|
|
1635
|
+
throw Error('setLight: color needs three numbers from 0');
|
|
1636
|
+
next.color = [...values.color] as [number, number, number];
|
|
1637
|
+
}
|
|
1638
|
+
lightValues.set(id, next);
|
|
1639
|
+
const casting = pointShadows.find((entry) => entry.id === id);
|
|
1640
|
+
if (casting && casting.range !== next.range) {
|
|
1641
|
+
casting.range = next.range;
|
|
1642
|
+
casting.dirty = true;
|
|
1643
|
+
}
|
|
1644
|
+
const native = nativeLights.get(id);
|
|
1645
|
+
if (native) {
|
|
1646
|
+
native.color = new l.Color(...next.color, 1);
|
|
1647
|
+
// Off is zero light, not a removed component: the light keeps its slot.
|
|
1648
|
+
native.intensity = next.enabled ? next.intensity : 0;
|
|
1649
|
+
native.range = next.range;
|
|
1650
|
+
}
|
|
1651
|
+
fogLights();
|
|
1652
|
+
};
|
|
1653
|
+
const drawLook = (resolved: ZhudaResolvedFilmLook): 'updated' | 'rebuilt' => {
|
|
1654
|
+
const fixed = zhudaFilmLookFixedReason(look, resolved, loadedTable);
|
|
1655
|
+
if (fixed)
|
|
1656
|
+
throw Error(`Film stage: setLook cannot change the ${fixed}; mount the scene again`);
|
|
1657
|
+
const reason = zhudaFilmLookRebuildReason(look, resolved);
|
|
1658
|
+
if (reason === null)
|
|
1659
|
+
updateZhudaLookInPlace(l, { scene3D, camera, sun: sun.light, parts: effects }, resolved);
|
|
1660
|
+
else {
|
|
1661
|
+
releaseLook();
|
|
1662
|
+
try {
|
|
1663
|
+
buildLook(resolved);
|
|
1664
|
+
} catch (error) {
|
|
1665
|
+
// Put the previous look back so the stage keeps drawing.
|
|
1666
|
+
releaseLook();
|
|
1667
|
+
buildLook(look);
|
|
1668
|
+
afterLook();
|
|
1669
|
+
throw error;
|
|
1670
|
+
}
|
|
1671
|
+
}
|
|
1672
|
+
look = resolved;
|
|
1673
|
+
afterLook();
|
|
1674
|
+
return reason === null ? 'updated' : 'rebuilt';
|
|
1675
|
+
};
|
|
1676
|
+
return {
|
|
1677
|
+
get scene() {
|
|
1678
|
+
return currentScene;
|
|
1679
|
+
},
|
|
1680
|
+
get look() {
|
|
1681
|
+
return look;
|
|
1682
|
+
},
|
|
1683
|
+
setLook,
|
|
1684
|
+
get quality() {
|
|
1685
|
+
return quality;
|
|
1686
|
+
},
|
|
1687
|
+
setQuality,
|
|
1688
|
+
setLight,
|
|
1689
|
+
scene3D,
|
|
1690
|
+
camera,
|
|
1691
|
+
lens,
|
|
1692
|
+
batches: [...batches]
|
|
1693
|
+
.map(([material, meshes]) => ({ material, meshes }))
|
|
1694
|
+
.sort((a, b) => a.material.localeCompare(b.material)),
|
|
1695
|
+
models,
|
|
1696
|
+
setTime,
|
|
1697
|
+
setCamera,
|
|
1698
|
+
prepare,
|
|
1699
|
+
worldToScreen: (point: ZhudaFilmVec3, size: { width: number; height: number }) => {
|
|
1700
|
+
const p = projectZhudaFilmPoint(current, point, size.width / size.height);
|
|
1701
|
+
return p.depth > 0
|
|
1702
|
+
? { x: p.x * size.width, y: p.y * size.height, depth: p.depth, inView: p.inView }
|
|
1703
|
+
: null;
|
|
1704
|
+
},
|
|
1705
|
+
adopt: (release: () => void) => void cleanups.push(release),
|
|
1706
|
+
linearChain: () => effects.film?.linearChain(),
|
|
1707
|
+
solids,
|
|
1708
|
+
raycast,
|
|
1709
|
+
dispose,
|
|
1710
|
+
};
|
|
1711
|
+
}
|
|
1712
|
+
}
|
|
1713
|
+
|
|
1714
|
+
/** A decoded picture's pixels, straight RGBA row by row from the top. */
|
|
1715
|
+
function zhudaBitmapPixels(bitmap: ImageBitmap): Uint8Array {
|
|
1716
|
+
const canvas = new OffscreenCanvas(bitmap.width, bitmap.height);
|
|
1717
|
+
const context = canvas.getContext('2d', { willReadFrequently: true, colorSpace: 'srgb' });
|
|
1718
|
+
if (!context) throw Error('Film scene: no 2D canvas to read a picture with');
|
|
1719
|
+
context.drawImage(bitmap, 0, 0);
|
|
1720
|
+
const data = context.getImageData(0, 0, bitmap.width, bitmap.height).data;
|
|
1721
|
+
return new Uint8Array(data.buffer.slice(0));
|
|
1722
|
+
}
|
|
1723
|
+
|
|
1724
|
+
/** The picture as the sky: Laya's panoramic sky material on a dome the stage owns. */
|
|
1725
|
+
function applyPanorama(
|
|
1726
|
+
stage: ZhudaFilmStage,
|
|
1727
|
+
bitmap: ImageBitmap,
|
|
1728
|
+
panorama: { exposure: number; rotationDeg: number },
|
|
1729
|
+
) {
|
|
1730
|
+
const l = (globalThis as any).Laya;
|
|
1731
|
+
// No mip levels and no anisotropic filtering. LayaAir's panoramic sky finds
|
|
1732
|
+
// the picture's column with an arc tangent, which jumps from one edge of the
|
|
1733
|
+
// picture to the other along one meridian. To the graphics card the whole
|
|
1734
|
+
// width of the picture then lies between two neighbouring pixels: with mip
|
|
1735
|
+
// levels it reads the smallest one there, with anisotropic filtering it
|
|
1736
|
+
// spreads its reads along the whole row, and either way the sky shows the
|
|
1737
|
+
// average of the picture as a line from the horizon to the zenith.
|
|
1738
|
+
const texture = new l.Texture2D(
|
|
1739
|
+
bitmap.width,
|
|
1740
|
+
bitmap.height,
|
|
1741
|
+
l.TextureFormat.R8G8B8A8,
|
|
1742
|
+
false,
|
|
1743
|
+
false,
|
|
1744
|
+
true,
|
|
1745
|
+
);
|
|
1746
|
+
texture.setImageData(bitmap, false, false);
|
|
1747
|
+
texture.filterMode = l.FilterMode.Bilinear;
|
|
1748
|
+
texture.anisoLevel = 1;
|
|
1749
|
+
texture.wrapModeU = l.WrapMode.Repeat;
|
|
1750
|
+
texture.wrapModeV = l.WrapMode.Clamp;
|
|
1751
|
+
const sky = new l.SkyPanoramicMaterial();
|
|
1752
|
+
sky.panoramicTexture = texture;
|
|
1753
|
+
sky.exposure = panorama.exposure;
|
|
1754
|
+
sky.rotation = panorama.rotationDeg;
|
|
1755
|
+
const dome = new l.SkyDome();
|
|
1756
|
+
const renderer = stage.scene3D.skyRenderer;
|
|
1757
|
+
renderer.mesh = dome;
|
|
1758
|
+
renderer.material = sky;
|
|
1759
|
+
stage.camera.clearFlag = l.CameraClearFlags.Sky;
|
|
1760
|
+
stage.adopt(() => {
|
|
1761
|
+
renderer.material = null;
|
|
1762
|
+
renderer.mesh = null;
|
|
1763
|
+
sky.destroy();
|
|
1764
|
+
dome.destroy();
|
|
1765
|
+
texture.destroy();
|
|
1766
|
+
});
|
|
1767
|
+
}
|
|
1768
|
+
|
|
1769
|
+
function setLayer(node: any, layer: number) {
|
|
1770
|
+
if (!node) return;
|
|
1771
|
+
node.layer = layer;
|
|
1772
|
+
for (let i = 0; i < (node.numChildren || 0); i++) setLayer(node.getChildAt(i), layer);
|
|
1773
|
+
}
|
|
1774
|
+
|
|
1775
|
+
function hasSecondUv(l: any, renderer: any): boolean {
|
|
1776
|
+
const owner = renderer.owner;
|
|
1777
|
+
const mesh =
|
|
1778
|
+
owner?.meshFilter?.sharedMesh ??
|
|
1779
|
+
owner?.getComponent?.(l.MeshFilter)?.sharedMesh ??
|
|
1780
|
+
renderer.sharedMesh;
|
|
1781
|
+
const declaration = mesh?.getVertexDeclaration?.();
|
|
1782
|
+
return !!declaration?.getVertexElementByUsage?.(l.VertexMesh.MESH_TEXTURECOORDINATE1);
|
|
1783
|
+
}
|
|
1784
|
+
|
|
1785
|
+
function castsShadow(node: any) {
|
|
1786
|
+
node.meshRenderer.castShadow = true;
|
|
1787
|
+
node.meshRenderer.receiveShadow = true;
|
|
1788
|
+
}
|
|
1789
|
+
|
|
1790
|
+
/** Shadows, procedural sky and fog, all native Laya 3.4.2 features. */
|
|
1791
|
+
/**
|
|
1792
|
+
* Shared with `ZhudaSceneLook`: shadows, sky, fog and the HDR chain of a
|
|
1793
|
+
* resolved look. `given.colorTable` is the parsed table of `grade.lut`;
|
|
1794
|
+
* without it the picture is as without a table.
|
|
1795
|
+
*/
|
|
1796
|
+
export function applyResolvedFilmLook(
|
|
1797
|
+
l: any,
|
|
1798
|
+
scene3D: any,
|
|
1799
|
+
camera: any,
|
|
1800
|
+
sun: any,
|
|
1801
|
+
look: ZhudaResolvedFilmLook,
|
|
1802
|
+
cleanups: (() => void)[],
|
|
1803
|
+
given: { colorTable?: ZhudaCubeLut } = {},
|
|
1804
|
+
): ZhudaAppliedLookParts & { finish?: ZhudaLensFinish } {
|
|
1805
|
+
let colorTable: ZhudaColorLut | undefined;
|
|
1806
|
+
let flare: ZhudaLensFlare | undefined;
|
|
1807
|
+
let lightFog: ZhudaLightFog | undefined;
|
|
1808
|
+
let underwater: ZhudaUnderwater | undefined;
|
|
1809
|
+
let reflections: ZhudaScreenReflections | undefined;
|
|
1810
|
+
let exposure: ZhudaAutoExposure | undefined;
|
|
1811
|
+
let depthOfField: ZhudaDepthOfField | undefined;
|
|
1812
|
+
let motionBlur: ZhudaMotionBlur | undefined;
|
|
1813
|
+
let clouds: ZhudaClouds | undefined;
|
|
1814
|
+
let finish: ZhudaLensFinish | undefined;
|
|
1815
|
+
let skyMaterial: any;
|
|
1816
|
+
let film: ZhudaFilmicPipeline | undefined;
|
|
1817
|
+
let shadowUpdates: ZhudaShadowUpdates | undefined;
|
|
1818
|
+
if (look.shadows) {
|
|
1819
|
+
sun.shadowMode = look.shadows.softness === 'hard' ? l.ShadowMode.Hard : l.ShadowMode.SoftHigh;
|
|
1820
|
+
sun.shadowDistance = look.shadows.distance;
|
|
1821
|
+
sun.shadowResolution = look.shadows.resolution;
|
|
1822
|
+
sun.shadowStrength = look.shadows.strength;
|
|
1823
|
+
sun.shadowCascadesMode =
|
|
1824
|
+
look.shadows.cascades === 4
|
|
1825
|
+
? l.ShadowCascadesMode.FourCascades
|
|
1826
|
+
: look.shadows.cascades === 1
|
|
1827
|
+
? l.ShadowCascadesMode.NoCascades
|
|
1828
|
+
: l.ShadowCascadesMode.TwoCascades;
|
|
1829
|
+
// Switch shadows off before the scene is destroyed (see the stage tests).
|
|
1830
|
+
cleanups.push(() => (sun.shadowMode = l.ShadowMode.None));
|
|
1831
|
+
// Every frame is LayaAir's own path; the others need the rule on the scene.
|
|
1832
|
+
if (look.shadows.update !== 'every') {
|
|
1833
|
+
// The maps are kept for the look's camera; see `ZhudaShadowUpdates`.
|
|
1834
|
+
const rule = (shadowUpdates = new ZhudaShadowUpdates(
|
|
1835
|
+
scene3D,
|
|
1836
|
+
{ mode: look.shadows.update, interval: look.shadows.interval },
|
|
1837
|
+
camera,
|
|
1838
|
+
));
|
|
1839
|
+
cleanups.push(() => rule.dispose());
|
|
1840
|
+
}
|
|
1841
|
+
} else sun.shadowMode = l.ShadowMode.None;
|
|
1842
|
+
// A panorama replaces the procedural sky (it is applied after loading).
|
|
1843
|
+
if (look.atmosphere && !look.panorama) {
|
|
1844
|
+
const sky = (skyMaterial = new l.SkyProceduralMaterial());
|
|
1845
|
+
sky.sunDisk = l.SkyProceduralMaterial.SUN_HIGH_QUALITY;
|
|
1846
|
+
sky.sunSize = look.atmosphere.sunSize;
|
|
1847
|
+
sky.atmosphereThickness = look.atmosphere.thickness;
|
|
1848
|
+
sky.skyTint = new l.Color(...look.atmosphere.skyTint, 1);
|
|
1849
|
+
sky.groundTint = new l.Color(...look.atmosphere.groundTint, 1);
|
|
1850
|
+
sky.exposure = look.atmosphere.exposure;
|
|
1851
|
+
// Own the dome: the shared SkyDome.instance would be destroyed with this
|
|
1852
|
+
// scene and break every scene drawn after it.
|
|
1853
|
+
const dome = new l.SkyDome();
|
|
1854
|
+
const previousMesh = scene3D.skyRenderer.mesh;
|
|
1855
|
+
scene3D.skyRenderer.mesh = dome;
|
|
1856
|
+
scene3D.skyRenderer.material = sky;
|
|
1857
|
+
camera.clearFlag = l.CameraClearFlags.Sky;
|
|
1858
|
+
cleanups.push(() => {
|
|
1859
|
+
scene3D.skyRenderer.material = null;
|
|
1860
|
+
try {
|
|
1861
|
+
scene3D.skyRenderer.mesh = null;
|
|
1862
|
+
} catch {
|
|
1863
|
+
// A scene that has drawn (a game changing its look while it runs)
|
|
1864
|
+
// cannot hold no sky mesh in Laya 3.4.2: give it back the one it had.
|
|
1865
|
+
if (previousMesh && !previousMesh.destroyed) scene3D.skyRenderer.mesh = previousMesh;
|
|
1866
|
+
}
|
|
1867
|
+
sky.destroy();
|
|
1868
|
+
dome.destroy();
|
|
1869
|
+
});
|
|
1870
|
+
}
|
|
1871
|
+
if (look.grade) {
|
|
1872
|
+
if (look.screenReflections) {
|
|
1873
|
+
const mirror = (reflections = new ZhudaScreenReflections({
|
|
1874
|
+
...look.screenReflections,
|
|
1875
|
+
// A display value like every colour of the look; the effect takes light.
|
|
1876
|
+
skyColor: zhudaDecodeColor(look.screenReflections.skyColor),
|
|
1877
|
+
}));
|
|
1878
|
+
cleanups.push(() => mirror.dispose());
|
|
1879
|
+
}
|
|
1880
|
+
if (look.clouds) {
|
|
1881
|
+
const sky = (clouds = new ZhudaClouds({
|
|
1882
|
+
...look.clouds,
|
|
1883
|
+
sunToward: zhudaTowardSun(l, sun),
|
|
1884
|
+
sunColor: zhudaSunRadiance(look),
|
|
1885
|
+
skyColor: zhudaDecodeColor(look.ambient),
|
|
1886
|
+
}));
|
|
1887
|
+
cleanups.push(() => sky.dispose());
|
|
1888
|
+
}
|
|
1889
|
+
if (look.depthOfField) {
|
|
1890
|
+
const lens = (depthOfField = new ZhudaDepthOfField(look.depthOfField));
|
|
1891
|
+
cleanups.push(() => lens.dispose());
|
|
1892
|
+
}
|
|
1893
|
+
if (look.motionBlur) {
|
|
1894
|
+
const blur = (motionBlur = new ZhudaMotionBlur(look.motionBlur));
|
|
1895
|
+
cleanups.push(() => blur.dispose());
|
|
1896
|
+
}
|
|
1897
|
+
if (look.autoExposure) {
|
|
1898
|
+
const eye = (exposure = new ZhudaAutoExposure(look.autoExposure));
|
|
1899
|
+
cleanups.push(() => eye.dispose());
|
|
1900
|
+
}
|
|
1901
|
+
if (look.lightFog) {
|
|
1902
|
+
const { shafts, ...plain } = look.lightFog;
|
|
1903
|
+
const fog = (lightFog = new ZhudaLightFog({
|
|
1904
|
+
...plain,
|
|
1905
|
+
// A display value like every colour of the look; the fog's own shader takes light.
|
|
1906
|
+
color: zhudaDecodeColor(plain.color),
|
|
1907
|
+
...(shafts ? { shafts } : {}),
|
|
1908
|
+
}));
|
|
1909
|
+
fog.setEdgeSmoothing(!!look.grade && look.grade.antialias === 'msaa');
|
|
1910
|
+
if (shafts) {
|
|
1911
|
+
// `getForward` is the direction the light travels (checked against
|
|
1912
|
+
// the real shadows by verify:film-fog).
|
|
1913
|
+
const travel = new l.Vector3();
|
|
1914
|
+
sun.owner.transform.getForward(travel);
|
|
1915
|
+
const length = Math.hypot(travel.x, travel.y, travel.z) || 1;
|
|
1916
|
+
fog.attachSun(scene3D, {
|
|
1917
|
+
toward: [-travel.x / length, -travel.y / length, -travel.z / length],
|
|
1918
|
+
color: zhudaSunRadiance(look),
|
|
1919
|
+
});
|
|
1920
|
+
}
|
|
1921
|
+
// Cleanups run in reverse: the pipeline releases its chain first.
|
|
1922
|
+
cleanups.push(() => fog.dispose());
|
|
1923
|
+
}
|
|
1924
|
+
if (look.underwater) {
|
|
1925
|
+
const water = (underwater = new ZhudaUnderwater(
|
|
1926
|
+
scene3D,
|
|
1927
|
+
{ ...look.underwater, color: zhudaDecodeColor(look.underwater.color) },
|
|
1928
|
+
{
|
|
1929
|
+
sky: zhudaDecodeColor(look.ambient),
|
|
1930
|
+
sun: { toward: zhudaTowardSun(l, sun), color: zhudaSunRadiance(look) },
|
|
1931
|
+
},
|
|
1932
|
+
));
|
|
1933
|
+
// The surface seen from below lets the sun through: it casts no beam shadow.
|
|
1934
|
+
lightFog?.excludeFromShafts(ZHUDA_UNDERWATER_LAYER);
|
|
1935
|
+
cleanups.push(() => water.dispose());
|
|
1936
|
+
}
|
|
1937
|
+
if (look.grade.grain > 0 || look.grade.vignette > 0 || look.grade.fringe > 0) {
|
|
1938
|
+
const lens = (finish = new ZhudaLensFinish({
|
|
1939
|
+
grain: look.grade.grain,
|
|
1940
|
+
vignette: look.grade.vignette,
|
|
1941
|
+
fringe: look.grade.fringe,
|
|
1942
|
+
}));
|
|
1943
|
+
cleanups.push(() => lens.dispose());
|
|
1944
|
+
}
|
|
1945
|
+
// Edges are smoothed on the finished picture, before the lens marks it.
|
|
1946
|
+
let smoothing: ZhudaEdgeSmoothing | ZhudaSmaa | undefined;
|
|
1947
|
+
if (look.grade.antialias === 'fxaa' || look.grade.antialias === 'smaa') {
|
|
1948
|
+
const edges = (smoothing =
|
|
1949
|
+
look.grade.antialias === 'smaa' ? new ZhudaSmaa() : new ZhudaEdgeSmoothing());
|
|
1950
|
+
cleanups.push(() => edges.dispose());
|
|
1951
|
+
}
|
|
1952
|
+
// The colour table first of what follows the curve: edges and the lens
|
|
1953
|
+
// work on the colours it gives.
|
|
1954
|
+
if (look.grade.lut) {
|
|
1955
|
+
const table = (colorTable = new ZhudaColorLut(given.colorTable ?? zhudaIdentityCubeLut(2), {
|
|
1956
|
+
intensity: look.grade.lut.intensity,
|
|
1957
|
+
}));
|
|
1958
|
+
cleanups.push(() => table.dispose());
|
|
1959
|
+
}
|
|
1960
|
+
if (look.lensFlare) {
|
|
1961
|
+
const lens = (flare = new ZhudaLensFlare(look.lensFlare));
|
|
1962
|
+
lens.setLight({ toward: zhudaTowardSun(l, sun), color: zhudaSunRadiance(look) });
|
|
1963
|
+
cleanups.push(() => lens.dispose());
|
|
1964
|
+
}
|
|
1965
|
+
const pipeline = (film = new ZhudaFilmicPipeline(camera, {
|
|
1966
|
+
// Reflections first: the fog then lies over them as over everything else.
|
|
1967
|
+
sceneEffects: [
|
|
1968
|
+
// The sky first: what mirrors the screen then mirrors the clouds too.
|
|
1969
|
+
...(clouds ? [clouds.effect] : []),
|
|
1970
|
+
...(reflections ? [reflections.effect] : []),
|
|
1971
|
+
...(lightFog ? [lightFog.effect] : []),
|
|
1972
|
+
// The water after the fog: beams and haze under water are dimmed and tinted by it.
|
|
1973
|
+
...(underwater ? [underwater.effect] : []),
|
|
1974
|
+
// The lens after the air; the eye last, on what the lens drew.
|
|
1975
|
+
...(depthOfField ? [depthOfField.effect] : []),
|
|
1976
|
+
...(motionBlur ? [motionBlur.effect] : []),
|
|
1977
|
+
// The flare is light inside the lens: it is not blurred by the lens's focus or motion.
|
|
1978
|
+
...(flare ? [flare.effect] : []),
|
|
1979
|
+
...(exposure ? [exposure.effect] : []),
|
|
1980
|
+
],
|
|
1981
|
+
finishEffects: [
|
|
1982
|
+
...(colorTable ? [colorTable.effect] : []),
|
|
1983
|
+
...(smoothing ? [smoothing.effect] : []),
|
|
1984
|
+
...(finish ? [finish.effect] : []),
|
|
1985
|
+
],
|
|
1986
|
+
toneMapping: look.grade.toneMapping,
|
|
1987
|
+
temperature: look.grade.temperature,
|
|
1988
|
+
tint: look.grade.tint,
|
|
1989
|
+
lift: look.grade.lift,
|
|
1990
|
+
gamma: look.grade.gamma,
|
|
1991
|
+
gain: look.grade.gain,
|
|
1992
|
+
bloomThreshold: look.grade.bloomThreshold,
|
|
1993
|
+
bloomSoftKnee: look.grade.bloomSoftKnee,
|
|
1994
|
+
bloomAnamorphic: look.grade.bloomAnamorphic,
|
|
1995
|
+
bloomDiffusion: look.grade.bloomDiffusion,
|
|
1996
|
+
aoMethod: look.grade.aoMethod,
|
|
1997
|
+
exposure: look.grade.exposure,
|
|
1998
|
+
contrast: look.grade.contrast,
|
|
1999
|
+
saturation: look.grade.saturation,
|
|
2000
|
+
bloom: look.grade.bloom > 0,
|
|
2001
|
+
bloomIntensity: look.grade.bloom,
|
|
2002
|
+
ao: look.grade.ao > 0,
|
|
2003
|
+
aoIntensity: look.grade.ao,
|
|
2004
|
+
aoRadius: look.grade.aoRadius,
|
|
2005
|
+
temporalAA: false,
|
|
2006
|
+
msaa: look.grade.antialias === 'msaa',
|
|
2007
|
+
}));
|
|
2008
|
+
cleanups.push(() => pipeline.dispose());
|
|
2009
|
+
// The chain is HDR to its end: the picture is rounded to eight bits once, where it is turned for the screen.
|
|
2010
|
+
if (look.grade.dither) {
|
|
2011
|
+
if (zhudaDitherStatus(l).ready) {
|
|
2012
|
+
setZhudaDither(scene3D, 'screen');
|
|
2013
|
+
cleanups.push(() => {
|
|
2014
|
+
if (!scene3D.destroyed) setZhudaDither(scene3D, false);
|
|
2015
|
+
});
|
|
2016
|
+
} else
|
|
2017
|
+
console.warn(`[zhuda] look.grade.dither is not applied: ${zhudaDitherStatus(l).reason}`);
|
|
2018
|
+
}
|
|
2019
|
+
}
|
|
2020
|
+
// After the HDR chain, which puts the camera's depth setting back as it
|
|
2021
|
+
// found it when it goes: contact shadows ask for the depth picture.
|
|
2022
|
+
let lighting: ZhudaLightingDepth | undefined;
|
|
2023
|
+
{
|
|
2024
|
+
const asked = zhudaLookLighting(look);
|
|
2025
|
+
if (zhudaLightingDepthInstalled(l)) {
|
|
2026
|
+
const depth = (lighting = new ZhudaLightingDepth(scene3D, asked, camera));
|
|
2027
|
+
cleanups.push(() => depth.dispose());
|
|
2028
|
+
} else if (
|
|
2029
|
+
asked.falloff !== 'laya' ||
|
|
2030
|
+
asked.shadowSpread > 1 ||
|
|
2031
|
+
asked.cascadeBlend ||
|
|
2032
|
+
asked.contactShadows > 0
|
|
2033
|
+
)
|
|
2034
|
+
throw Error(
|
|
2035
|
+
'The look asks for lightFalloff, shadows.spread, shadows.blend or shadows.contact: these need installLaya342LightingDepth() before Laya.init (ZhudaEngine.boot does it)',
|
|
2036
|
+
);
|
|
2037
|
+
}
|
|
2038
|
+
if (look.fog) {
|
|
2039
|
+
scene3D.enableFog = true;
|
|
2040
|
+
scene3D.fogMode = l.FogMode.Linear;
|
|
2041
|
+
scene3D.fogColor = new l.Color(...look.fog.color, 1);
|
|
2042
|
+
scene3D.fogStart = look.fog.start;
|
|
2043
|
+
scene3D.fogEnd = look.fog.end;
|
|
2044
|
+
cleanups.push(() => (scene3D.enableFog = false));
|
|
2045
|
+
}
|
|
2046
|
+
return {
|
|
2047
|
+
lightFog,
|
|
2048
|
+
underwater,
|
|
2049
|
+
reflections,
|
|
2050
|
+
exposure,
|
|
2051
|
+
depthOfField,
|
|
2052
|
+
motionBlur,
|
|
2053
|
+
clouds,
|
|
2054
|
+
finish,
|
|
2055
|
+
colorTable,
|
|
2056
|
+
flare,
|
|
2057
|
+
lighting,
|
|
2058
|
+
sky: skyMaterial,
|
|
2059
|
+
film,
|
|
2060
|
+
shadowUpdates,
|
|
2061
|
+
};
|
|
2062
|
+
}
|
|
2063
|
+
|
|
2064
|
+
function materialName(material: unknown, materials: Map<string, any>): string {
|
|
2065
|
+
for (const [name, value] of materials) if (value === material) return name;
|
|
2066
|
+
return 'unknown';
|
|
2067
|
+
}
|
|
2068
|
+
|
|
2069
|
+
export interface ZhudaFilmRenderOptions {
|
|
2070
|
+
width: number;
|
|
2071
|
+
height: number;
|
|
2072
|
+
/** 1 for previews; more samples add anti-aliasing and depth of field. */
|
|
2073
|
+
samples?: number;
|
|
2074
|
+
/** Depth of field from the camera's fStop (default: on when samples > 1). */
|
|
2075
|
+
aperture?: boolean;
|
|
2076
|
+
/** Shot time of frame 0 in seconds (default 0): where a still or preview looks. */
|
|
2077
|
+
timeSec?: number;
|
|
2078
|
+
timeoutMs?: number;
|
|
2079
|
+
signal?: AbortSignal;
|
|
2080
|
+
}
|
|
2081
|
+
|
|
2082
|
+
/**
|
|
2083
|
+
* Renders frames of a mounted stage. The runtime is paused for the renderer's
|
|
2084
|
+
* lifetime and restored on `dispose()`.
|
|
2085
|
+
*/
|
|
2086
|
+
export class ZhudaFilmRenderer {
|
|
2087
|
+
private readonly wasPaused: boolean;
|
|
2088
|
+
private disposed = false;
|
|
2089
|
+
constructor(
|
|
2090
|
+
private readonly stage: ZhudaFilmStage,
|
|
2091
|
+
private readonly runtime: ZhudaRuntimeSession,
|
|
2092
|
+
) {
|
|
2093
|
+
// Laya registers newly added meshes on its next frame. Captures freeze the
|
|
2094
|
+
// scene, so run two native frames first or a fresh stage can render
|
|
2095
|
+
// nothing but its clear colour (intermittently, depending on timing).
|
|
2096
|
+
ZhudaEngine.flushRenderFrames(2);
|
|
2097
|
+
this.wasPaused = runtime.paused;
|
|
2098
|
+
runtime.setPaused(true);
|
|
2099
|
+
}
|
|
2100
|
+
/** Renders one frame with the camera given (or the scene camera). */
|
|
2101
|
+
async render(
|
|
2102
|
+
options: ZhudaFilmRenderOptions & { camera?: ZhudaFilmCamera; index?: number; fps?: number },
|
|
2103
|
+
): Promise<CinematicFramePixels> {
|
|
2104
|
+
if (this.disposed) throw Error('Film renderer disposed');
|
|
2105
|
+
const samples = options.samples ?? 1;
|
|
2106
|
+
const capture = new ZhudaCinematicCapture(this.stage.scene3D, this.stage.lens, this.runtime, {
|
|
2107
|
+
width: options.width,
|
|
2108
|
+
height: options.height,
|
|
2109
|
+
timeoutMs: options.timeoutMs,
|
|
2110
|
+
});
|
|
2111
|
+
try {
|
|
2112
|
+
const camera = options.camera ?? this.stage.scene.camera;
|
|
2113
|
+
return await capture.renderFrame({
|
|
2114
|
+
index: options.index ?? 0,
|
|
2115
|
+
fps: options.fps ?? 24,
|
|
2116
|
+
samples,
|
|
2117
|
+
signal: options.signal,
|
|
2118
|
+
aperture: options.aperture ?? samples > 1,
|
|
2119
|
+
jitter: samples > 1,
|
|
2120
|
+
// Out-of-focus and moving highlights keep their light only when the
|
|
2121
|
+
// samples are averaged before tone mapping.
|
|
2122
|
+
linear: samples > 1 ? this.stage.linearChain() : undefined,
|
|
2123
|
+
sample: (seconds) => {
|
|
2124
|
+
this.stage.setTime((options.timeSec ?? 0) + seconds);
|
|
2125
|
+
this.stage.setCamera(camera);
|
|
2126
|
+
},
|
|
2127
|
+
prepare: () =>
|
|
2128
|
+
this.stage.prepare(options.width / options.height, {
|
|
2129
|
+
width: options.width,
|
|
2130
|
+
height: options.height,
|
|
2131
|
+
index: (options.index ?? 0) + Math.round((options.timeSec ?? 0) * (options.fps ?? 24)),
|
|
2132
|
+
}),
|
|
2133
|
+
});
|
|
2134
|
+
} finally {
|
|
2135
|
+
capture.dispose();
|
|
2136
|
+
}
|
|
2137
|
+
}
|
|
2138
|
+
dispose(): void {
|
|
2139
|
+
if (this.disposed) return;
|
|
2140
|
+
this.disposed = true;
|
|
2141
|
+
this.runtime.setPaused(this.wasPaused);
|
|
2142
|
+
}
|
|
2143
|
+
}
|
|
2144
|
+
|
|
2145
|
+
/** Waits for the engine to settle before the first capture (helper for hosts). */
|
|
2146
|
+
export function flushZhudaFilmFrames(count = 3): void {
|
|
2147
|
+
ZhudaEngine.flushRenderFrames(count);
|
|
2148
|
+
}
|