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,3442 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Film scenes as data. An agent (or a person) authors a `ZhudaFilmScene`,
|
|
3
|
+
* changes it with patches and renders it through the existing cinematic
|
|
4
|
+
* capture. Everything here is pure and runs in Node, a Worker or a browser.
|
|
5
|
+
*
|
|
6
|
+
* The scene only names things the host already owns: registered procedural
|
|
7
|
+
* props, texture recipes, flat PBR colours and logical asset ids (models and
|
|
8
|
+
* lightmaps an `AssetProvider` delivers). It never carries code, file paths
|
|
9
|
+
* or URLs.
|
|
10
|
+
*/
|
|
11
|
+
import { normalizeAssetId } from '../runtime3d/AssetProvider.ts';
|
|
12
|
+
import {
|
|
13
|
+
validateZhudaTextureRecipe,
|
|
14
|
+
type ZhudaTextureRecipe,
|
|
15
|
+
} from '../procedural/TextureRecipe.ts';
|
|
16
|
+
import {
|
|
17
|
+
validateZhudaExtrude,
|
|
18
|
+
validateZhudaLathe,
|
|
19
|
+
validateZhudaSweep,
|
|
20
|
+
} from '../procedural/Geometry.ts';
|
|
21
|
+
import { validateZhudaDecal, type ZhudaDecalShape } from '../runtime3d/Decals.ts';
|
|
22
|
+
import { validateZhudaGrass } from '../runtime3d/Grass.ts';
|
|
23
|
+
import { ZHUDA_EFFECT_PRESETS_3D, ZHUDA_EFFECT_PRESET_IDS_3D } from '../effects/EffectPresets.ts';
|
|
24
|
+
import {
|
|
25
|
+
validateZhudaTerrainMesh,
|
|
26
|
+
type ZhudaTerrainMeshOptions,
|
|
27
|
+
} from '../procedural/TerrainMesh.ts';
|
|
28
|
+
import {
|
|
29
|
+
resolveZhudaAutoExposure,
|
|
30
|
+
resolveZhudaDepthOfField,
|
|
31
|
+
resolveZhudaMotionBlur,
|
|
32
|
+
validateZhudaAutoExposure,
|
|
33
|
+
validateZhudaDepthOfField,
|
|
34
|
+
validateZhudaMotionBlur,
|
|
35
|
+
type ZhudaAutoExposureOptions,
|
|
36
|
+
type ZhudaDepthOfFieldOptions,
|
|
37
|
+
type ZhudaMotionBlurOptions,
|
|
38
|
+
} from '../runtime3d/CameraEffects.ts';
|
|
39
|
+
import { resolveZhudaClouds, validateZhudaClouds } from '../runtime3d/Clouds.ts';
|
|
40
|
+
import {
|
|
41
|
+
resolveZhudaUnderwater,
|
|
42
|
+
validateZhudaUnderwater,
|
|
43
|
+
type ZhudaResolvedUnderwater,
|
|
44
|
+
type ZhudaUnderwaterOptions,
|
|
45
|
+
} from '../runtime3d/Underwater.ts';
|
|
46
|
+
import { validateZhudaWaterRipples } from '../shaders/WaterRipples.ts';
|
|
47
|
+
import { ZHUDA_TONE_MAPPINGS, type ZhudaToneMapping } from '../runtime3d/ToneCurves.ts';
|
|
48
|
+
import {
|
|
49
|
+
ZHUDA_LENS_FLARE_SUN,
|
|
50
|
+
validateZhudaLensFlare,
|
|
51
|
+
type ZhudaLensFlareElement,
|
|
52
|
+
} from '../runtime3d/LensFlare.ts';
|
|
53
|
+
|
|
54
|
+
export type ZhudaFilmVec3 = [number, number, number];
|
|
55
|
+
|
|
56
|
+
export interface ZhudaFilmCamera {
|
|
57
|
+
eye: ZhudaFilmVec3;
|
|
58
|
+
target: ZhudaFilmVec3;
|
|
59
|
+
/** 35 mm full-frame equivalent focal length (default 35). */
|
|
60
|
+
focalLengthMm?: number;
|
|
61
|
+
/** Aperture used by final renders for depth of field (default 8). */
|
|
62
|
+
fStop?: number;
|
|
63
|
+
/** Metres; defaults to the eye-target distance. */
|
|
64
|
+
focusDistanceM?: number;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface ZhudaFilmSun {
|
|
68
|
+
/** Turns the sun about +Y, degrees. At 0 the light travels toward -Z. Defaults to the preset. */
|
|
69
|
+
azimuthDeg?: number;
|
|
70
|
+
/** Height above the horizon, degrees (0..90). Defaults to the preset. */
|
|
71
|
+
elevationDeg?: number;
|
|
72
|
+
intensity?: number;
|
|
73
|
+
/**
|
|
74
|
+
* Display RGB 0..1, as a colour picker shows it (sRGB): LayaAir decodes it,
|
|
75
|
+
* so 0.5 gives 21 % of the light. `intensity` is linear.
|
|
76
|
+
*/
|
|
77
|
+
color?: ZhudaFilmVec3;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export type ZhudaFilmLookPreset = 'day' | 'dawn' | 'dusk' | 'night' | 'overcast';
|
|
81
|
+
|
|
82
|
+
/** Sun shadows (native `DirectionLightCom` shadow maps). */
|
|
83
|
+
export interface ZhudaFilmShadows {
|
|
84
|
+
/** Metres from the camera that receive shadows (default 60). */
|
|
85
|
+
distance?: number;
|
|
86
|
+
/** 'soft' filters the edge (default); 'hard' does not. */
|
|
87
|
+
softness?: 'hard' | 'soft';
|
|
88
|
+
/** 0..1 (default 1). */
|
|
89
|
+
strength?: number;
|
|
90
|
+
/** Shadow map size (default 2048). */
|
|
91
|
+
resolution?: 1024 | 2048 | 4096;
|
|
92
|
+
/**
|
|
93
|
+
* Shadow map splits by distance: 1, 2 or 4 (default 2). More splits keep
|
|
94
|
+
* shadows near the camera sharp when `distance` is long.
|
|
95
|
+
*/
|
|
96
|
+
cascades?: 1 | 2 | 4;
|
|
97
|
+
/**
|
|
98
|
+
* When the shadow maps are drawn again (default 'every'): 'every' frame;
|
|
99
|
+
* 'interval': every `interval` frames, receivers keep the last maps in
|
|
100
|
+
* between, so a moving caster's shadow follows it in steps; 'manual': when
|
|
101
|
+
* the game asks (`ZhudaSceneLook.redrawShadows`) and when a new look
|
|
102
|
+
* changes the sun or the shadow settings, for a still camera over still
|
|
103
|
+
* casters. Stills and videos of a film draw them for every sample
|
|
104
|
+
* whatever this says. The maps are kept for the look's camera: a water's
|
|
105
|
+
* mirror left at its defaults reads them, and any other camera that draws
|
|
106
|
+
* the scene with shadows of its own makes the look's camera draw its maps
|
|
107
|
+
* again. See `ZhudaShadowUpdates`.
|
|
108
|
+
*/
|
|
109
|
+
update?: 'every' | 'interval' | 'manual';
|
|
110
|
+
/** Frames from one drawing to the next with `update: 'interval'`, 2..30 (default 3). */
|
|
111
|
+
interval?: number;
|
|
112
|
+
/**
|
|
113
|
+
* How wide the soft edge is, 1..4 times LayaAir's own (default 1). Above
|
|
114
|
+
* 1 the edge is sixteen reads on a disc turned differently in every pixel:
|
|
115
|
+
* wider, and a fine grain. With `softness: 'soft'`.
|
|
116
|
+
*/
|
|
117
|
+
spread?: number;
|
|
118
|
+
/**
|
|
119
|
+
* Blend from one cascade into the next, and fade the shadow out over the
|
|
120
|
+
* last metres instead of stopping (default false).
|
|
121
|
+
*/
|
|
122
|
+
blend?: boolean;
|
|
123
|
+
/**
|
|
124
|
+
* Contact shadows: how far toward the sun a point looks for something in
|
|
125
|
+
* its way, in metres, 0.02..2; 0 is none (default). They shade what the
|
|
126
|
+
* shadow map is too coarse to hold (the foot of a post, a kerb) and reach
|
|
127
|
+
* beyond `distance`. Eight reads of the depth picture for every lit pixel.
|
|
128
|
+
*/
|
|
129
|
+
contact?: number;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Procedural sky (native `SkyProceduralMaterial`); the sun disk follows the sun. */
|
|
133
|
+
export interface ZhudaFilmAtmosphere {
|
|
134
|
+
/** Air density, 0..5 (default 1); higher is redder near the horizon. */
|
|
135
|
+
thickness?: number;
|
|
136
|
+
/** Linear RGB 0..1. */
|
|
137
|
+
skyTint?: ZhudaFilmVec3;
|
|
138
|
+
/** Colour below the horizon, linear RGB 0..1. */
|
|
139
|
+
groundTint?: ZhudaFilmVec3;
|
|
140
|
+
/** 0..8 (default 1.3). */
|
|
141
|
+
exposure?: number;
|
|
142
|
+
/** Sun disk size, 0..1 (default 0.04). */
|
|
143
|
+
sunSize?: number;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** Linear distance fog (native scene fog). */
|
|
147
|
+
export interface ZhudaFilmFog {
|
|
148
|
+
/** Linear RGB 0..1; defaults to the sky or horizon colour. */
|
|
149
|
+
color?: ZhudaFilmVec3;
|
|
150
|
+
/** Metres where fog starts and where it is complete. */
|
|
151
|
+
start: number;
|
|
152
|
+
end: number;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** Filmic camera chain (existing `ZhudaFilmicPipeline`): HDR, ACES, bloom, AO. */
|
|
156
|
+
export interface ZhudaFilmGrade {
|
|
157
|
+
/** Linear exposure multiplier, 0.05..16 (default 1). */
|
|
158
|
+
exposure?: number;
|
|
159
|
+
/** 0.5..2 (default 1). */
|
|
160
|
+
contrast?: number;
|
|
161
|
+
/** 0..2 (default 1). */
|
|
162
|
+
saturation?: number;
|
|
163
|
+
/** Bloom intensity, 0..2; 0 turns bloom off (default 0.1). */
|
|
164
|
+
bloom?: number;
|
|
165
|
+
/** Ambient occlusion intensity, 0..4; 0 turns it off (default 0.5). */
|
|
166
|
+
ao?: number;
|
|
167
|
+
/** Ambient occlusion radius in metres, 0.05..5 (default 0.5). */
|
|
168
|
+
aoRadius?: number;
|
|
169
|
+
/**
|
|
170
|
+
* Edge smoothing of a frame that is drawn once (a preview, a running game):
|
|
171
|
+
* `msaa` multisamples the HDR target (default); `fxaa` smooths edges in one
|
|
172
|
+
* pass over the finished picture, far cheaper on a phone and a little
|
|
173
|
+
* softer; `smaa` finds the shape of each edge in three passes and leaves
|
|
174
|
+
* everything that is not an edge exactly as it was (`ZhudaSmaa`); `none`
|
|
175
|
+
* leaves edges as they fall. Stills and video average their samples as
|
|
176
|
+
* well, with any value.
|
|
177
|
+
*/
|
|
178
|
+
antialias?: 'msaa' | 'fxaa' | 'smaa' | 'none';
|
|
179
|
+
/**
|
|
180
|
+
* The curve from the scene's light to the screen's colours (default
|
|
181
|
+
* `aces`): `agx` keeps hues as colours brighten and is softer, `neutral`
|
|
182
|
+
* leaves colours below 0.76 as they are, `none` cuts off at white. See
|
|
183
|
+
* `ZhudaToneMapping`.
|
|
184
|
+
*/
|
|
185
|
+
toneMapping?: ZhudaToneMapping;
|
|
186
|
+
/**
|
|
187
|
+
* White balance, each -100..100 (default 0): `temperature` above 0 is
|
|
188
|
+
* warmer, `tint` above 0 toward magenta and below 0 toward green.
|
|
189
|
+
*/
|
|
190
|
+
temperature?: number;
|
|
191
|
+
tint?: number;
|
|
192
|
+
/**
|
|
193
|
+
* For red, green and blue, on the scene's light before the curve, as
|
|
194
|
+
* `(colour * gain + lift) ^ gamma`: `lift` -1..1 (default 0), `gamma`
|
|
195
|
+
* 0.1..10 (default 1; above 1 darkens the middle), `gain` 0..16 (default 1).
|
|
196
|
+
*/
|
|
197
|
+
lift?: ZhudaFilmVec3;
|
|
198
|
+
gamma?: ZhudaFilmVec3;
|
|
199
|
+
gain?: ZhudaFilmVec3;
|
|
200
|
+
/** Where bloom begins, as a display value, 0..16 (default 1.2: light above 1.55 of white). */
|
|
201
|
+
bloomThreshold?: number;
|
|
202
|
+
/** How gradually bloom sets in below the threshold, 0..1 (default 0.5). */
|
|
203
|
+
bloomSoftKnee?: number;
|
|
204
|
+
/** -1..1 (default 0): above 0 the bloom is stretched sideways, below 0 upright. */
|
|
205
|
+
bloomAnamorphic?: number;
|
|
206
|
+
/** How far the bloom spreads, 1..10 (default 4): each step more doubles its reach. */
|
|
207
|
+
bloomDiffusion?: number;
|
|
208
|
+
/**
|
|
209
|
+
* How ambient occlusion is worked out (default `sao`, LayaAir's own).
|
|
210
|
+
* `gtao`: by horizons in the depth picture: open ground and the sky are
|
|
211
|
+
* left as they are, and `ao` is then a power where 1 is what the geometry
|
|
212
|
+
* hides, and its default (see `ZhudaGroundTruthAO`).
|
|
213
|
+
*/
|
|
214
|
+
aoMethod?: 'sao' | 'gtao';
|
|
215
|
+
/**
|
|
216
|
+
* A colour table from a grading tool (a `.cube` file, named by asset id),
|
|
217
|
+
* applied to the finished picture; `intensity` 0..1 (default 1) is how
|
|
218
|
+
* much of it is taken. Loaded with the scene: mount with
|
|
219
|
+
* `loadZhudaFilmScene`. Off unless given.
|
|
220
|
+
*/
|
|
221
|
+
lut?: { asset: string; intensity?: number } | false;
|
|
222
|
+
/**
|
|
223
|
+
* A grain of less than one step of eight bits, added where the finished
|
|
224
|
+
* picture is written for the screen: slow gradients (a night sky, fog,
|
|
225
|
+
* the edge of a soft shadow) then show no bands. Black stays black. Off
|
|
226
|
+
* unless given. See `setZhudaDither`.
|
|
227
|
+
*/
|
|
228
|
+
dither?: boolean;
|
|
229
|
+
/**
|
|
230
|
+
* What a real camera adds, after tone mapping, each 0..1 and off by
|
|
231
|
+
* default: film grain, darker corners and colour fringing at the corners.
|
|
232
|
+
*/
|
|
233
|
+
grain?: number;
|
|
234
|
+
vignette?: number;
|
|
235
|
+
fringe?: number;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export interface ZhudaFilmLook {
|
|
239
|
+
/**
|
|
240
|
+
* A time of day. Every other field overrides the preset. Without a preset
|
|
241
|
+
* the look is the plain one: flat sky colour, no shadows, sky or fog.
|
|
242
|
+
*/
|
|
243
|
+
preset?: ZhudaFilmLookPreset;
|
|
244
|
+
/** Flat background colour (used when there is no atmosphere), display RGB 0..1. */
|
|
245
|
+
sky?: ZhudaFilmVec3;
|
|
246
|
+
/**
|
|
247
|
+
* Ambient light colour, display RGB 0..1 (sRGB, as a colour picker shows
|
|
248
|
+
* it): 0.5 gives 21 % of the light. With `ambientGround` it is the light
|
|
249
|
+
* from above.
|
|
250
|
+
*/
|
|
251
|
+
ambient?: ZhudaFilmVec3;
|
|
252
|
+
/**
|
|
253
|
+
* Light the ground throws back, display RGB 0..1 like `ambient`. With it
|
|
254
|
+
* the ambient light has a direction: `ambient` comes from above (the sky)
|
|
255
|
+
* and this from below, so undersides and shadows take the colour of the
|
|
256
|
+
* ground instead of one flat tone. The day, dawn, dusk and overcast presets
|
|
257
|
+
* give one; `false` makes the ambient light one flat colour again.
|
|
258
|
+
*/
|
|
259
|
+
ambientGround?: ZhudaFilmVec3 | false;
|
|
260
|
+
sun?: ZhudaFilmSun;
|
|
261
|
+
/**
|
|
262
|
+
* How the scene's lamps fall off with distance. `laya` (default):
|
|
263
|
+
* LayaAir's own, as bright at the lamp whatever its range. `physical`: by
|
|
264
|
+
* the square of the distance; a light's `intensity` is then its brightness
|
|
265
|
+
* at one metre (a quarter at two), up to 2000, and `range` is where it is
|
|
266
|
+
* brought to nothing.
|
|
267
|
+
*/
|
|
268
|
+
lightFalloff?: 'laya' | 'physical';
|
|
269
|
+
/** `false` turns sun shadows off. */
|
|
270
|
+
shadows?: ZhudaFilmShadows | false;
|
|
271
|
+
/** `false` uses the flat `sky` colour instead of a procedural sky. */
|
|
272
|
+
atmosphere?: ZhudaFilmAtmosphere | false;
|
|
273
|
+
fog?: ZhudaFilmFog | false;
|
|
274
|
+
/** HDR tone-mapped rendering with bloom and ambient occlusion; off unless given. */
|
|
275
|
+
grade?: ZhudaFilmGrade | false;
|
|
276
|
+
/**
|
|
277
|
+
* Fog near the ground that lights shine into: halos around lamps, haze
|
|
278
|
+
* down a street. Needs `grade`; off unless given.
|
|
279
|
+
*/
|
|
280
|
+
lightFog?: ZhudaFilmLightFog | false;
|
|
281
|
+
/**
|
|
282
|
+
* Reflections of what is on screen, on every surface: wet walls, props,
|
|
283
|
+
* ground beyond a `reflector`. The whole view reflects alike, by Fresnel
|
|
284
|
+
* (a forward renderer has no roughness buffer): use it for rain and for
|
|
285
|
+
* polished places. Needs `grade`; off unless given.
|
|
286
|
+
*/
|
|
287
|
+
screenReflections?: ZhudaFilmScreenReflections | false;
|
|
288
|
+
/**
|
|
289
|
+
* The picture's brightness follows what is in view, as eyes do: a dark
|
|
290
|
+
* alley is lifted, a noon square dimmed, over a second or so. `true` takes
|
|
291
|
+
* the defaults. In a film scene the adaptation is immediate (`speed` 0
|
|
292
|
+
* unless given): a still does not depend on the frames before it. Needs
|
|
293
|
+
* `grade`; off unless given.
|
|
294
|
+
*/
|
|
295
|
+
autoExposure?: ZhudaAutoExposureOptions | boolean;
|
|
296
|
+
/**
|
|
297
|
+
* Depth of field in a picture drawn once (a game): what is nearer or
|
|
298
|
+
* farther than `focusDistanceM` is blurred. A film still or video does not
|
|
299
|
+
* need it: it gets depth of field from the camera's `fStop` by drawing many
|
|
300
|
+
* samples. Needs `grade`; off unless given.
|
|
301
|
+
*/
|
|
302
|
+
depthOfField?: ZhudaDepthOfFieldOptions | false;
|
|
303
|
+
/**
|
|
304
|
+
* Motion blur from the camera's own movement in a picture drawn once (a
|
|
305
|
+
* game). `true` takes the defaults. A film video gets motion blur from its
|
|
306
|
+
* samples. Needs `grade`; off unless given.
|
|
307
|
+
*/
|
|
308
|
+
motionBlur?: ZhudaMotionBlurOptions | boolean;
|
|
309
|
+
/**
|
|
310
|
+
* A layer of clouds with depth, lit by the look's sun and sky (see
|
|
311
|
+
* `ZhudaClouds`): `true` takes the defaults. They drift with shot time (a
|
|
312
|
+
* game: with the time its look is updated by). Needs `grade`; off unless
|
|
313
|
+
* given.
|
|
314
|
+
*/
|
|
315
|
+
clouds?: ZhudaFilmClouds | boolean;
|
|
316
|
+
/**
|
|
317
|
+
* What the sun does inside the lens: a glow, a streak and ghosts along
|
|
318
|
+
* the line through the middle of the picture, as strong as the share of
|
|
319
|
+
* the sun that nothing stands in front of (see `ZhudaLensFlare`). `true`
|
|
320
|
+
* takes the flare made for a low sun. Its place and colour come from the
|
|
321
|
+
* look's sun. Needs `grade`; off unless given.
|
|
322
|
+
*/
|
|
323
|
+
lensFlare?: ZhudaFilmLensFlare | boolean;
|
|
324
|
+
/**
|
|
325
|
+
* Water the camera can be in (see `ZhudaUnderwater`): below
|
|
326
|
+
* `surfaceY` the view is dimmed per colour by the water and filled with
|
|
327
|
+
* its `color` (a display value), sunlight below the surface is dimmed and
|
|
328
|
+
* gathered into caustics, and the surface is seen from below with the sky
|
|
329
|
+
* in its window. `true` takes the defaults. Needs `grade`; off unless
|
|
330
|
+
* given.
|
|
331
|
+
*/
|
|
332
|
+
underwater?: ZhudaUnderwaterOptions | boolean;
|
|
333
|
+
/**
|
|
334
|
+
* Light bounced once off the scene: probes on a grid over its objects
|
|
335
|
+
* capture their surroundings when the scene is mounted, and light physically
|
|
336
|
+
* based materials in place of the ambient light (a sunlit red wall tints
|
|
337
|
+
* what faces it). Captured once: `setLook` does not update it. Off unless
|
|
338
|
+
* given.
|
|
339
|
+
*/
|
|
340
|
+
bounceLight?: ZhudaFilmBounceLight | false;
|
|
341
|
+
/**
|
|
342
|
+
* A photograph as the sky: a 2:1 panorama (equirectangular) named by
|
|
343
|
+
* logical asset id. Replaces `atmosphere`. Off unless given.
|
|
344
|
+
*/
|
|
345
|
+
panorama?: ZhudaFilmPanorama | false;
|
|
346
|
+
/**
|
|
347
|
+
* Captures the scene around one point and uses it as the environment:
|
|
348
|
+
* glossy surfaces reflect it and surfaces without a lightmap get its
|
|
349
|
+
* ambient light. Off unless given.
|
|
350
|
+
*/
|
|
351
|
+
environment?: ZhudaFilmEnvironment | false;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/** A panoramic picture drawn as the sky (Laya's native `SkyPanoramicMaterial`). */
|
|
355
|
+
export interface ZhudaFilmPanorama {
|
|
356
|
+
/** Logical id of a `.png` or `.jpg` picture twice as wide as it is tall. */
|
|
357
|
+
asset: string;
|
|
358
|
+
/** Brightness, 0..16 (default 1). */
|
|
359
|
+
exposure?: number;
|
|
360
|
+
/** Turns the picture about the vertical axis, degrees (default 0). */
|
|
361
|
+
rotationDeg?: number;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/** One environment probe (see `ZhudaEnvironmentProbe`). */
|
|
365
|
+
export interface ZhudaFilmEnvironment {
|
|
366
|
+
/** Where the surroundings are captured from: near the subject of the shot. */
|
|
367
|
+
position: ZhudaFilmVec3;
|
|
368
|
+
/** Scales reflections, 0..8 (default 1). */
|
|
369
|
+
reflection?: number;
|
|
370
|
+
/** Scales the ambient light on surfaces without a lightmap, 0..8 (default 1). */
|
|
371
|
+
ambient?: number;
|
|
372
|
+
/**
|
|
373
|
+
* Take only reflections from the capture and keep `look.ambient` as the
|
|
374
|
+
* ambient light (default false). For shots under trees or between walls,
|
|
375
|
+
* where the captured ambient light is as dark as the surroundings.
|
|
376
|
+
*/
|
|
377
|
+
reflectionOnly?: boolean;
|
|
378
|
+
/**
|
|
379
|
+
* The room the capture stands for, as the corners of a world box: a
|
|
380
|
+
* reflection is then looked up where the reflected ray meets the box (what
|
|
381
|
+
* is on a wall is mirrored at its place on the wall). For interiors and
|
|
382
|
+
* courtyards. Off unless given: the surroundings are infinitely far.
|
|
383
|
+
*/
|
|
384
|
+
box?: { min: ZhudaFilmVec3; max: ZhudaFilmVec3 } | false;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/** Height fog lit by the scene's `light` nodes (see `ZhudaLightFog`). */
|
|
388
|
+
export interface ZhudaFilmLightFog {
|
|
389
|
+
/** Extinction per metre at `baseY`, 0..1 (default 0.012). */
|
|
390
|
+
density?: number;
|
|
391
|
+
/** Height over which the fog thins to 1/e, 0.5..1000 metres (default 8). */
|
|
392
|
+
falloffMeters?: number;
|
|
393
|
+
/** Height where the density equals `density` (default 0). */
|
|
394
|
+
baseY?: number;
|
|
395
|
+
/**
|
|
396
|
+
* Colour of the fog itself, display RGB 0..1. Default: the colour the look's
|
|
397
|
+
* sky has near the horizon (the preset's measured `horizon`, or `look.sky`
|
|
398
|
+
* for a flat or panoramic sky), so that the fog melts into the sky.
|
|
399
|
+
*/
|
|
400
|
+
color?: ZhudaFilmVec3;
|
|
401
|
+
/** Strength of the glow around lights, 0..16 (default 1). */
|
|
402
|
+
scatter?: number;
|
|
403
|
+
/**
|
|
404
|
+
* How far along a view ray the fog is gathered, 1..100000 metres (default
|
|
405
|
+
* 600). Shorter keeps what is far away clear while the air round the scene
|
|
406
|
+
* stays hazy: a sea of cloud below a floating island, and things drawn
|
|
407
|
+
* without depth (particles) in front of the sky, which are otherwise
|
|
408
|
+
* fogged as if they were as far away as the sky.
|
|
409
|
+
*/
|
|
410
|
+
maxDistance?: number;
|
|
411
|
+
/**
|
|
412
|
+
* Beams of the sun or moon in the fog, cut by whatever stands in the light
|
|
413
|
+
* (`look.sun` gives direction, colour and intensity); off unless given.
|
|
414
|
+
*/
|
|
415
|
+
shafts?: ZhudaFilmLightShafts | false;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/** One copy of a model: x, y, z in metres, yaw in degrees, uniform scale. */
|
|
419
|
+
export type ZhudaFilmPlacement = [number, number, number, number, number];
|
|
420
|
+
|
|
421
|
+
export interface ZhudaFilmLightShafts {
|
|
422
|
+
/** Brightness of the beams, 0..64 (default 1). */
|
|
423
|
+
strength?: number;
|
|
424
|
+
/** Forward scattering, 0..0.95 (default 0.6): beams are brightest looking toward the light. */
|
|
425
|
+
anisotropy?: number;
|
|
426
|
+
/** How far from the camera beams are drawn, 5..2000 metres (default 60). */
|
|
427
|
+
distance?: number;
|
|
428
|
+
/** Steps along each view ray, 8..96 (default 40). */
|
|
429
|
+
steps?: number;
|
|
430
|
+
/**
|
|
431
|
+
* Size the beams are marched at against the picture, 0.25..1 (default 0.5);
|
|
432
|
+
* smoothed and brought up by depth below 1 (see `ZhudaLightShaftOptions`).
|
|
433
|
+
*/
|
|
434
|
+
scale?: number;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/** A baked recipe (a registered recipe name or an inline recipe) or a flat PBR colour. */
|
|
438
|
+
export type ZhudaFilmMaterial =
|
|
439
|
+
| {
|
|
440
|
+
/**
|
|
441
|
+
* A picture as the surface's colour: the logical id of a `.png` or
|
|
442
|
+
* `.jpg` among the scene's assets, repeated every `tileMeters`
|
|
443
|
+
* (a photographed or generated tile). `normal` is its normal map
|
|
444
|
+
* (`normalConvention` 'opengl', green up, as glTF and most libraries
|
|
445
|
+
* write it, the default; or 'directx'), `normalStrength` 0..2 its
|
|
446
|
+
* relief. The picture carries no roughness: `roughness` (default 0.8)
|
|
447
|
+
* and `metallic` (default 0) are the whole surface's. Needs
|
|
448
|
+
* `loadZhudaFilmScene` and an assets library (the MCP server's
|
|
449
|
+
* `--film-assets`).
|
|
450
|
+
*/
|
|
451
|
+
picture: string;
|
|
452
|
+
normal?: string;
|
|
453
|
+
normalConvention?: 'opengl' | 'directx';
|
|
454
|
+
normalStrength?: number;
|
|
455
|
+
/** Width and height in metres that one repeat of the picture covers. */
|
|
456
|
+
tileMeters: [number, number];
|
|
457
|
+
roughness?: number;
|
|
458
|
+
metallic?: number;
|
|
459
|
+
tint?: [number, number, number, number];
|
|
460
|
+
blend?: 'opaque' | 'cutout' | 'alpha' | 'additive';
|
|
461
|
+
alphaCutoff?: number;
|
|
462
|
+
doubleSided?: boolean;
|
|
463
|
+
}
|
|
464
|
+
| {
|
|
465
|
+
recipe: string | ZhudaTextureRecipe;
|
|
466
|
+
tint?: [number, number, number, number];
|
|
467
|
+
/**
|
|
468
|
+
* Bake size: 128, 256, 512, 1024 or 2048 (default 256). Baking runs on
|
|
469
|
+
* the CPU when the scene is mounted and its cost grows with the square
|
|
470
|
+
* of the size (about 2 s at 1024 and 6 s and 48 MB at 2048 for a
|
|
471
|
+
* two-layer recipe): for the large sizes pass a `bakeCache` filled ahead.
|
|
472
|
+
*/
|
|
473
|
+
size?: 128 | 256 | 512 | 1024 | 2048;
|
|
474
|
+
/**
|
|
475
|
+
* Slow changes of brightness across the surface, 0..1 (default 0), so
|
|
476
|
+
* that a large floor or road does not show its tiles as a grid. The
|
|
477
|
+
* changes are several tiles wide.
|
|
478
|
+
*/
|
|
479
|
+
variation?: number;
|
|
480
|
+
/**
|
|
481
|
+
* Fine detail for close range: a second recipe laid over this one,
|
|
482
|
+
* repeating every `meters` (grain, pores, scratches at a metre or two
|
|
483
|
+
* where the material itself tiles at tens). `albedo` (0..1, default
|
|
484
|
+
* 0.5) is how far its colour moves the surface's about its own mean,
|
|
485
|
+
* `normal` (0..2, default 1) how strong its relief is. Its bake `size`
|
|
486
|
+
* is 128 to 1024 (default 256). Far away it changes nothing. Not
|
|
487
|
+
* together with `variation`: they are the material's one detail map.
|
|
488
|
+
*/
|
|
489
|
+
detail?: {
|
|
490
|
+
recipe: string | ZhudaTextureRecipe;
|
|
491
|
+
meters: number;
|
|
492
|
+
size?: number;
|
|
493
|
+
albedo?: number;
|
|
494
|
+
normal?: number;
|
|
495
|
+
};
|
|
496
|
+
/**
|
|
497
|
+
* 'triplanar' lays the recipe on by where the surface is in the world
|
|
498
|
+
* (three flat projections mixed by which way it faces) instead of by
|
|
499
|
+
* the mesh's texture coordinates: a steep slope or a rock then shows
|
|
500
|
+
* it at its true size, not stretched. Default 'uv'. Three times the
|
|
501
|
+
* texture reads; not with `variation`, `detail`, `blend` or
|
|
502
|
+
* `doubleSided`.
|
|
503
|
+
*/
|
|
504
|
+
projection?: 'uv' | 'triplanar';
|
|
505
|
+
/**
|
|
506
|
+
* With `projection: 'triplanar'`: a second recipe where the surface
|
|
507
|
+
* faces up (moss on a stone's top, snow on a ledge). `from` and `to`
|
|
508
|
+
* are the upward share of the surface normal (1 level, 0 a wall)
|
|
509
|
+
* between which it comes in, defaults 0.55 and 0.8; `size` its bake
|
|
510
|
+
* size (default 256).
|
|
511
|
+
*/
|
|
512
|
+
top?: { recipe: string | ZhudaTextureRecipe; from?: number; to?: number; size?: number };
|
|
513
|
+
/**
|
|
514
|
+
* How the surface is put into the picture (default 'opaque'):
|
|
515
|
+
* 'cutout' draws it where its alpha is above `alphaCutoff` and nowhere
|
|
516
|
+
* else, with depth and shadows (leaves, grass, petals, lace); 'alpha'
|
|
517
|
+
* blends it over what is behind (mist, a sheet of falling water) and
|
|
518
|
+
* 'additive' adds its light (flame, a glow). Blended surfaces write no
|
|
519
|
+
* depth and are drawn after the solid ones, far to near by their mesh.
|
|
520
|
+
*/
|
|
521
|
+
blend?: 'opaque' | 'cutout' | 'alpha' | 'additive';
|
|
522
|
+
/** With 'cutout': the alpha at which the surface begins, 0..1 (default 0.5). */
|
|
523
|
+
alphaCutoff?: number;
|
|
524
|
+
/** Both faces are drawn: a leaf or a blade is one sheet, not two back to back. */
|
|
525
|
+
doubleSided?: boolean;
|
|
526
|
+
}
|
|
527
|
+
| {
|
|
528
|
+
color: ZhudaFilmVec3;
|
|
529
|
+
roughness?: number;
|
|
530
|
+
metallic?: number;
|
|
531
|
+
/**
|
|
532
|
+
* Self-lit colour (lamp heads, signs), display RGB 0..8. It is decoded
|
|
533
|
+
* like any colour, so above 1 the light grows as the 2.4th power: 2 is
|
|
534
|
+
* 5.3 times white, 4 is 28, 8 is 147. What exceeds the grade's range
|
|
535
|
+
* (56 after exposure) is drawn at that limit, near-white.
|
|
536
|
+
*/
|
|
537
|
+
emission?: ZhudaFilmVec3;
|
|
538
|
+
/** A clear layer over the surface (lacquer, varnish, a wet sheen), 0..1 (default 0). */
|
|
539
|
+
clearCoat?: number;
|
|
540
|
+
/** Roughness of that layer, 0..1 (default 0.1). */
|
|
541
|
+
clearCoatRoughness?: number;
|
|
542
|
+
/**
|
|
543
|
+
* How far the highlight is drawn out, 0..1 (default 0): brushed metal,
|
|
544
|
+
* hair, satin. On a `lathe` it becomes a ring about the axis.
|
|
545
|
+
*/
|
|
546
|
+
anisotropy?: number;
|
|
547
|
+
/**
|
|
548
|
+
* How the surface is put into the picture (default 'opaque'):
|
|
549
|
+
* 'cutout' draws it where its alpha is above `alphaCutoff` and nowhere
|
|
550
|
+
* else, with depth and shadows (leaves, grass, petals, lace); 'alpha'
|
|
551
|
+
* blends it over what is behind (mist, a sheet of falling water) and
|
|
552
|
+
* 'additive' adds its light (flame, a glow). Blended surfaces write no
|
|
553
|
+
* depth and are drawn after the solid ones, far to near by their mesh.
|
|
554
|
+
*/
|
|
555
|
+
blend?: 'opaque' | 'cutout' | 'alpha' | 'additive';
|
|
556
|
+
/** With 'cutout': the alpha at which the surface begins, 0..1 (default 0.5). */
|
|
557
|
+
alphaCutoff?: number;
|
|
558
|
+
/** Both faces are drawn: a leaf or a blade is one sheet, not two back to back. */
|
|
559
|
+
doubleSided?: boolean;
|
|
560
|
+
/** How solid the colour is, 0..1 (default 1): what 'alpha' blends by and 'cutout' compares. */
|
|
561
|
+
opacity?: number;
|
|
562
|
+
};
|
|
563
|
+
|
|
564
|
+
export type ZhudaFilmNode =
|
|
565
|
+
| {
|
|
566
|
+
id: string;
|
|
567
|
+
type: 'prop';
|
|
568
|
+
/** Id in the prop registry the host was given. */
|
|
569
|
+
prop: string;
|
|
570
|
+
position: ZhudaFilmVec3;
|
|
571
|
+
yawDeg?: number;
|
|
572
|
+
seed?: number;
|
|
573
|
+
params?: Record<string, unknown>;
|
|
574
|
+
/**
|
|
575
|
+
* False: the prop casts no shadow (it still takes them). For grass,
|
|
576
|
+
* petals, pebbles and whatever is too small for its shadow to show: a
|
|
577
|
+
* prop is drawn again in every split of the shadow map it reaches.
|
|
578
|
+
*/
|
|
579
|
+
castShadow?: boolean;
|
|
580
|
+
/** Beyond this distance from the camera to the prop's `position`, in metres, it is not drawn. */
|
|
581
|
+
cullMeters?: number;
|
|
582
|
+
/**
|
|
583
|
+
* Lighter versions for distance, nearest first, at most 4: from
|
|
584
|
+
* `fromMeters` on, the prop is built with `params` laid over its own
|
|
585
|
+
* (a `detail` of 0.5, fewer blades). Each is built when the scene is
|
|
586
|
+
* mounted; one is drawn at a time, chosen by the distance from the
|
|
587
|
+
* camera to the prop's `position` whenever the camera is set.
|
|
588
|
+
*/
|
|
589
|
+
lod?: { fromMeters: number; params: Record<string, unknown> }[];
|
|
590
|
+
}
|
|
591
|
+
| {
|
|
592
|
+
id: string;
|
|
593
|
+
type: 'box';
|
|
594
|
+
size: ZhudaFilmVec3;
|
|
595
|
+
/** Centre of the underside. */
|
|
596
|
+
position: ZhudaFilmVec3;
|
|
597
|
+
yawDeg?: number;
|
|
598
|
+
bevel?: number;
|
|
599
|
+
/** A scene material, or a recipe name the host knows. */
|
|
600
|
+
material: string;
|
|
601
|
+
}
|
|
602
|
+
| {
|
|
603
|
+
id: string;
|
|
604
|
+
type: 'lathe';
|
|
605
|
+
/**
|
|
606
|
+
* A body of revolution about the vertical axis (a bollard, a barrel, a
|
|
607
|
+
* dome, a bowl, a column): its outline as [radius, height] pairs in
|
|
608
|
+
* metres, 2..256 of them, from the bottom up along the outside. A
|
|
609
|
+
* hollow form goes on down the inside.
|
|
610
|
+
*/
|
|
611
|
+
profile: [number, number][];
|
|
612
|
+
/** Sides around the axis, 3..96 (default 24). */
|
|
613
|
+
segments?: number;
|
|
614
|
+
/** Where the axis meets height 0 of the outline. */
|
|
615
|
+
position: ZhudaFilmVec3;
|
|
616
|
+
yawDeg?: number;
|
|
617
|
+
material: string;
|
|
618
|
+
}
|
|
619
|
+
| {
|
|
620
|
+
id: string;
|
|
621
|
+
type: 'extrude';
|
|
622
|
+
/**
|
|
623
|
+
* A flat outline on the ground raised to `height` (a kerb, steps, a
|
|
624
|
+
* sign, a piece of wall): [x, z] pairs in metres about `position`,
|
|
625
|
+
* 3..256 of them, in either direction. It may be concave; it must not
|
|
626
|
+
* cross itself.
|
|
627
|
+
*/
|
|
628
|
+
outline: [number, number][];
|
|
629
|
+
/** Metres. */
|
|
630
|
+
height: number;
|
|
631
|
+
position: ZhudaFilmVec3;
|
|
632
|
+
yawDeg?: number;
|
|
633
|
+
material: string;
|
|
634
|
+
}
|
|
635
|
+
| {
|
|
636
|
+
id: string;
|
|
637
|
+
type: 'sweep';
|
|
638
|
+
/**
|
|
639
|
+
* A cross-section carried along a path (a kerb round a bend, a rail, a
|
|
640
|
+
* cornice, a wall that follows a street): [across, up] pairs in metres,
|
|
641
|
+
* 3..64 of them, in either direction; across is to the left of the way
|
|
642
|
+
* the path runs. It may be concave; it must not cross itself.
|
|
643
|
+
*/
|
|
644
|
+
profile: [number, number][];
|
|
645
|
+
/** The line it is carried along, 2..1024 [x, y, z] points in metres about `position`. */
|
|
646
|
+
path: ZhudaFilmVec3[];
|
|
647
|
+
/** The path returns to its first point (default false). */
|
|
648
|
+
closed?: boolean;
|
|
649
|
+
position: ZhudaFilmVec3;
|
|
650
|
+
yawDeg?: number;
|
|
651
|
+
material: string;
|
|
652
|
+
}
|
|
653
|
+
| {
|
|
654
|
+
id: string;
|
|
655
|
+
type: 'decal';
|
|
656
|
+
/**
|
|
657
|
+
* A mark laid on a flat surface (a stain, a wet patch, a scorch, a
|
|
658
|
+
* painted line): its centre on the surface, and its width and length
|
|
659
|
+
* in metres. It does not wrap round a corner.
|
|
660
|
+
*/
|
|
661
|
+
position: ZhudaFilmVec3;
|
|
662
|
+
size: [number, number];
|
|
663
|
+
/** The way the surface faces (default [0, 1, 0]: a floor). */
|
|
664
|
+
normal?: ZhudaFilmVec3;
|
|
665
|
+
/** Turns the mark about that direction, degrees. */
|
|
666
|
+
angleDeg?: number;
|
|
667
|
+
/** Display RGB 0..1 (default nearly black). */
|
|
668
|
+
color?: ZhudaFilmVec3;
|
|
669
|
+
/** How much of the surface it covers at its middle, 0..1 (default 0.8). */
|
|
670
|
+
opacity?: number;
|
|
671
|
+
/** 0..1 (default 0.6); low is wet or glossy. */
|
|
672
|
+
roughness?: number;
|
|
673
|
+
/** An oval with a broken edge (`blob`, default), a rectangle (`patch`) or a `ring`. */
|
|
674
|
+
shape?: ZhudaDecalShape;
|
|
675
|
+
/** Width of the soft edge as a share of the mark, 0..1 (default 0.35). */
|
|
676
|
+
edge?: number;
|
|
677
|
+
/** How ragged a blob's outline is, 0..1 (default 0.5). */
|
|
678
|
+
ragged?: number;
|
|
679
|
+
/** Which outline; the same seed gives the same mark (default 1). */
|
|
680
|
+
seed?: number;
|
|
681
|
+
}
|
|
682
|
+
| {
|
|
683
|
+
id: string;
|
|
684
|
+
type: 'ground';
|
|
685
|
+
/** Width (X) and depth (Z) in metres; the top surface sits at `y`. */
|
|
686
|
+
size: [number, number];
|
|
687
|
+
material: string;
|
|
688
|
+
/** Height of the top surface, metres (default 0): above a `terrain` it lies over, by a few centimetres. */
|
|
689
|
+
y?: number;
|
|
690
|
+
}
|
|
691
|
+
| {
|
|
692
|
+
id: string;
|
|
693
|
+
/**
|
|
694
|
+
* A ready particle effect (`ZhudaEffect3D`) from the built-in presets
|
|
695
|
+
* (`ZHUDA_EFFECT_PRESETS_3D`: campfire, torch, smoke-column, steam,
|
|
696
|
+
* sparks, explosion, hit, magic-aura, heal, portal, fireflies, rain,
|
|
697
|
+
* snow, dust-motes, falling-leaves, petals, bubbles, embers), at
|
|
698
|
+
* `position`, turned by `yawDeg`, every length times `scale` (0.05 to
|
|
699
|
+
* 50). It begins at `startSec` of shot time (default 0): a burst
|
|
700
|
+
* (explosion, hit) happens once from then, a loop runs on. A frame at
|
|
701
|
+
* the same shot time is the same frame. Particles are drawn unlit over
|
|
702
|
+
* the scene: they cast no shadow and light nothing (put a point light
|
|
703
|
+
* in a fire). At most 32 a scene.
|
|
704
|
+
*/
|
|
705
|
+
type: 'effect';
|
|
706
|
+
preset: string;
|
|
707
|
+
position: [number, number, number];
|
|
708
|
+
yawDeg?: number;
|
|
709
|
+
scale?: number;
|
|
710
|
+
startSec?: number;
|
|
711
|
+
seed?: number;
|
|
712
|
+
}
|
|
713
|
+
| {
|
|
714
|
+
id: string;
|
|
715
|
+
/**
|
|
716
|
+
* Ground with heights (`createZhudaTerrainMesh`): a grid of `cells`
|
|
717
|
+
* over `size` metres, centred on `position`, each corner at its own
|
|
718
|
+
* height above `position`'s. Give `heights` (a number a corner, row by
|
|
719
|
+
* row from -Z, each row from -X) or `noise` (fractal hills up to
|
|
720
|
+
* `heightM`, about `scaleM` across, with `flatten` rectangles pressed
|
|
721
|
+
* level for plots and roads, in the piece's own metres). It is lit,
|
|
722
|
+
* shadowed and asked by `film_scene_query` like a box; a `grass` node
|
|
723
|
+
* stands on it with `on`. Lay its recipe with `projection:
|
|
724
|
+
* 'triplanar'` where it is steep. One mesh of at most 254 cells a
|
|
725
|
+
* side; no caves or overhangs.
|
|
726
|
+
*/
|
|
727
|
+
type: 'terrain';
|
|
728
|
+
position: [number, number, number];
|
|
729
|
+
size: [number, number];
|
|
730
|
+
cells: [number, number];
|
|
731
|
+
heights?: number[];
|
|
732
|
+
noise?: NonNullable<ZhudaTerrainMeshOptions['noise']>;
|
|
733
|
+
material: string;
|
|
734
|
+
}
|
|
735
|
+
| {
|
|
736
|
+
id: string;
|
|
737
|
+
/**
|
|
738
|
+
* Grass a camera can walk through (`ZhudaGrassField`): narrow curved
|
|
739
|
+
* blades in clumps over turf, moved by the wind with shot time, lit and
|
|
740
|
+
* shadowed like the ground, thinned with distance. It stands on level
|
|
741
|
+
* ground at `y`.
|
|
742
|
+
*/
|
|
743
|
+
type: 'grass';
|
|
744
|
+
/** The land it may cover, world metres. */
|
|
745
|
+
area: { minX: number; maxX: number; minZ: number; maxZ: number };
|
|
746
|
+
/** Height of the ground it grows on (default 0). */
|
|
747
|
+
y?: number;
|
|
748
|
+
/** Or the id of a `terrain` node it stands on, at that ground's heights. */
|
|
749
|
+
on?: string;
|
|
750
|
+
/** Rectangles of the area where nothing grows (a road, a pond), at most 32. */
|
|
751
|
+
clear?: { minX: number; maxX: number; minZ: number; maxZ: number }[];
|
|
752
|
+
/**
|
|
753
|
+
* Nothing grows under what stands on the ground (default true): the
|
|
754
|
+
* boxes of the scene's props, `box`, `lathe`, `extrude` and `sweep`
|
|
755
|
+
* nodes that reach down to `y`. Models are not asked.
|
|
756
|
+
*/
|
|
757
|
+
avoidSolids?: boolean;
|
|
758
|
+
/** Blades on a square metre close to the eye, 20..1500 (default 400). */
|
|
759
|
+
density?: number;
|
|
760
|
+
/** Shortest and tallest blade, metres (default [0.14, 0.34]). */
|
|
761
|
+
heightM?: [number, number];
|
|
762
|
+
/** Width of a blade at its foot, metres, 0.005..0.2 (default 0.03). */
|
|
763
|
+
widthM?: number;
|
|
764
|
+
/** How far from the eye grass is drawn, metres, 10..300 (default 60). */
|
|
765
|
+
distanceM?: number;
|
|
766
|
+
/** Colour of a blade at its tip, at its foot, and of dry blades: display RGB. */
|
|
767
|
+
tip?: ZhudaFilmVec3;
|
|
768
|
+
root?: ZhudaFilmVec3;
|
|
769
|
+
dry?: ZhudaFilmVec3;
|
|
770
|
+
/** How much of the grass is dry, 0..1 (default 0.3). */
|
|
771
|
+
dryness?: number;
|
|
772
|
+
/** Where the wind blows toward (degrees from +X toward +Z), how far it bends a blade (0..1), how fast it moves. */
|
|
773
|
+
wind?: { directionDeg?: number; strength?: number; speed?: number };
|
|
774
|
+
seed?: number;
|
|
775
|
+
/** False leaves out the turf under the blades (default true). */
|
|
776
|
+
turf?: boolean;
|
|
777
|
+
}
|
|
778
|
+
| {
|
|
779
|
+
id: string;
|
|
780
|
+
type: 'model';
|
|
781
|
+
/** Logical id of a self-contained `.glb` the host's asset provider delivers. */
|
|
782
|
+
asset: string;
|
|
783
|
+
/** Where the model's origin goes. */
|
|
784
|
+
position: ZhudaFilmVec3;
|
|
785
|
+
yawDeg?: number;
|
|
786
|
+
/** Uniform scale, 0.001..1000 (default 1). */
|
|
787
|
+
scale?: number;
|
|
788
|
+
/**
|
|
789
|
+
* Logical id of a Radiance `.hdr` lightmap baked for this model: the
|
|
790
|
+
* diffuse light reaching its surfaces (direct and bounced), laid out by
|
|
791
|
+
* the meshes' second UV set. Replaces the flat ambient on this model.
|
|
792
|
+
*/
|
|
793
|
+
lightmap?: string;
|
|
794
|
+
/** Scales the lightmap, 0..16 (default 1). */
|
|
795
|
+
lightmapIntensity?: number;
|
|
796
|
+
/**
|
|
797
|
+
* Logical id of a Radiance `.hdr` picture of the dominant light
|
|
798
|
+
* direction per lightmap texel (`d * 0.5 + 0.5`, world space). With it,
|
|
799
|
+
* normal maps show relief under baked light. Needs `lightmap`; the
|
|
800
|
+
* model must not be turned (`yawDeg` 0).
|
|
801
|
+
*/
|
|
802
|
+
lightmapDirection?: string;
|
|
803
|
+
/** Plays a clip of the model as a function of shot time. */
|
|
804
|
+
animation?: ZhudaFilmAnimation;
|
|
805
|
+
/**
|
|
806
|
+
* Moves the model during the shot: two or more keys, the first at time
|
|
807
|
+
* 0, times increasing. Replaces `position` and `yawDeg` while it runs;
|
|
808
|
+
* the model holds the last key afterwards. Not with a lightmap.
|
|
809
|
+
*/
|
|
810
|
+
motion?: ZhudaFilmMotionKey[];
|
|
811
|
+
/**
|
|
812
|
+
* Copies of the model: one `[x, y, z, yawDeg, scale]` per copy, in
|
|
813
|
+
* metres relative to `position` (a forest floor of ferns, rocks along a
|
|
814
|
+
* bank, trees). The copies share the model's meshes and materials. With
|
|
815
|
+
* `placements` the model is drawn only at those places. Not with a
|
|
816
|
+
* lightmap, an animation or motion.
|
|
817
|
+
*/
|
|
818
|
+
placements?: ZhudaFilmPlacement[];
|
|
819
|
+
/**
|
|
820
|
+
* With `placements`: the copies are drawn in groups, one draw a group
|
|
821
|
+
* instead of one a copy (thousands of ferns or stones). Only for a
|
|
822
|
+
* model of plain meshes (no bones, no morph targets).
|
|
823
|
+
*/
|
|
824
|
+
instanced?: boolean;
|
|
825
|
+
/**
|
|
826
|
+
* With `instanced`: the side of the squares of ground the copies are
|
|
827
|
+
* grouped by, in metres, 0.5..100000 (default 32). Copies spread over
|
|
828
|
+
* kilometres want squares to match: a group is one draw, and a square
|
|
829
|
+
* that holds one copy is one draw a copy again.
|
|
830
|
+
*/
|
|
831
|
+
cellMeters?: number;
|
|
832
|
+
/**
|
|
833
|
+
* False: the model casts no shadow (it still takes them). For ground,
|
|
834
|
+
* paving and what is too small for its shadow to show: a model is
|
|
835
|
+
* drawn again in every split of the shadow map it reaches.
|
|
836
|
+
*/
|
|
837
|
+
castShadow?: boolean;
|
|
838
|
+
/**
|
|
839
|
+
* Beyond this distance from the camera, in metres, the model (each
|
|
840
|
+
* copy, or each group of instanced copies) is not drawn. Not with a
|
|
841
|
+
* lightmap.
|
|
842
|
+
*/
|
|
843
|
+
cullMeters?: number;
|
|
844
|
+
/**
|
|
845
|
+
* Leaves let light through: the cut-out (alpha-tested) materials of the
|
|
846
|
+
* model glow in their own colour when the sun or a lamp is behind
|
|
847
|
+
* them. Opaque materials of the same model (bark) are unchanged.
|
|
848
|
+
*/
|
|
849
|
+
translucent?: boolean;
|
|
850
|
+
/**
|
|
851
|
+
* Scales the light the model's own materials give off, 0..8 (default
|
|
852
|
+
* 1): 0 puts out lit windows and lanterns for a daytime shot of a
|
|
853
|
+
* model built for night, without another copy of the asset.
|
|
854
|
+
*/
|
|
855
|
+
emission?: number;
|
|
856
|
+
}
|
|
857
|
+
| {
|
|
858
|
+
id: string;
|
|
859
|
+
type: 'reflector';
|
|
860
|
+
/**
|
|
861
|
+
* A horizontal rectangle that mirrors the scene above it (wet paving,
|
|
862
|
+
* still water). `position` is its centre; `y` is the mirror height and
|
|
863
|
+
* should sit a few millimetres above the surface it covers.
|
|
864
|
+
*/
|
|
865
|
+
position: ZhudaFilmVec3;
|
|
866
|
+
/** Width (X) and depth (Z) in metres. */
|
|
867
|
+
size: [number, number];
|
|
868
|
+
/** Brightness of the reflection, 0..4 (default 1). */
|
|
869
|
+
strength?: number;
|
|
870
|
+
/** Share of the surface that is standing water, 0..1 (default 0.45). */
|
|
871
|
+
wetness?: number;
|
|
872
|
+
/** Blur on damp areas, 0..1 (default 0.35). */
|
|
873
|
+
roughness?: number;
|
|
874
|
+
/** How much damp areas break the reflection up, 0..1 (default 0.4). */
|
|
875
|
+
ripple?: number;
|
|
876
|
+
/** Size of the puddle pattern in metres, 0.1..100 (default 3). */
|
|
877
|
+
patternMeters?: number;
|
|
878
|
+
/** Longer side of the mirrored picture (default 1024). */
|
|
879
|
+
resolution?: 256 | 512 | 1024 | 2048;
|
|
880
|
+
/**
|
|
881
|
+
* Ids of model nodes the mirror must not draw. What lies below the
|
|
882
|
+
* mirror (the ground it covers, whatever kind of node that is) is cut
|
|
883
|
+
* from the mirrored view by itself; this is for things above it that
|
|
884
|
+
* should not show in the reflection.
|
|
885
|
+
*/
|
|
886
|
+
hides?: string[];
|
|
887
|
+
}
|
|
888
|
+
| {
|
|
889
|
+
id: string;
|
|
890
|
+
type: 'water';
|
|
891
|
+
/**
|
|
892
|
+
* Clear running water on a horizontal rectangle (see
|
|
893
|
+
* `ZhudaWaterSurface`): the bed shows through, bent by the waves and
|
|
894
|
+
* tinted with depth; the surface mirrors the scene, glints in the sun
|
|
895
|
+
* (`look.sun`) and foams where it is shallow. `position` is the centre;
|
|
896
|
+
* `y` is the water level. Banks and stones are models that cross it.
|
|
897
|
+
* Needs `grade`. One per scene, and not together with a reflector.
|
|
898
|
+
*/
|
|
899
|
+
position: ZhudaFilmVec3;
|
|
900
|
+
/** Width (X) and depth (Z) in metres. */
|
|
901
|
+
size: [number, number];
|
|
902
|
+
/** Flow in metres per second along X and Z (default [0, 0.6]). */
|
|
903
|
+
flow?: [number, number];
|
|
904
|
+
/** Colour of deep water, display RGB 0..1 (default a green-blue). */
|
|
905
|
+
color?: ZhudaFilmVec3;
|
|
906
|
+
/** Metres of water at which the bed has faded to about a third, 0.05..100 (default 1.5). */
|
|
907
|
+
clarity?: number;
|
|
908
|
+
/** Length of the waves in metres, 0.05..50 (default 0.9). */
|
|
909
|
+
waveMeters?: number;
|
|
910
|
+
/** Steepness of the waves, 0..1 (default 0.35). */
|
|
911
|
+
waves?: number;
|
|
912
|
+
/** How much the bed is bent by the waves, 0..1 (default 0.4). */
|
|
913
|
+
refraction?: number;
|
|
914
|
+
/** Brightness of the mirrored scene, 0..4 (default 1). */
|
|
915
|
+
reflection?: number;
|
|
916
|
+
/** How much deep water shines in its own colour, 0..4 (default 0.25). */
|
|
917
|
+
glow?: number;
|
|
918
|
+
/** Depth under which the water foams, 0..2 metres (default 0.12); 0 is no foam. */
|
|
919
|
+
foamDepth?: number;
|
|
920
|
+
/** Longer side of the mirrored picture (default 1024). */
|
|
921
|
+
resolution?: 256 | 512 | 1024 | 2048;
|
|
922
|
+
/** Ids of model nodes the mirror must not draw (the bed, if it shows in the reflection). */
|
|
923
|
+
hides?: string[];
|
|
924
|
+
/**
|
|
925
|
+
* Bodies in the water, at most four (`ZhudaWaterSurface.setRipples`):
|
|
926
|
+
* rings round each, a wake behind one with a `velocity` (a boat under
|
|
927
|
+
* way, a swimmer), froth at the waterline. They run on shot time.
|
|
928
|
+
*/
|
|
929
|
+
ripples?: {
|
|
930
|
+
/** Where the body is on the water: x, z in metres. */
|
|
931
|
+
position: [number, number];
|
|
932
|
+
/** Its radius at the waterline, 0.05..20 m. */
|
|
933
|
+
radius: number;
|
|
934
|
+
/** 0..2 (1 suits a swimmer or a small boat). */
|
|
935
|
+
strength: number;
|
|
936
|
+
/** Metres a second along X and Z, each -30..30 (default still). */
|
|
937
|
+
velocity?: [number, number];
|
|
938
|
+
}[];
|
|
939
|
+
}
|
|
940
|
+
| {
|
|
941
|
+
id: string;
|
|
942
|
+
type: 'light';
|
|
943
|
+
/** Point lights shine all around; spot lights shine at `target`. */
|
|
944
|
+
kind: 'point' | 'spot';
|
|
945
|
+
position: ZhudaFilmVec3;
|
|
946
|
+
/** Display RGB 0..1 (sRGB, as a colour picker shows it; default warm white). */
|
|
947
|
+
color?: ZhudaFilmVec3;
|
|
948
|
+
/**
|
|
949
|
+
* 0..20 (default 2). With the look's `lightFalloff: 'physical'` it is
|
|
950
|
+
* the brightness at one metre, 0..2000.
|
|
951
|
+
*/
|
|
952
|
+
intensity?: number;
|
|
953
|
+
/** Metres the light reaches, 0.1..200 (default 12). */
|
|
954
|
+
range?: number;
|
|
955
|
+
/** Spot lights: the point they aim at. */
|
|
956
|
+
target?: ZhudaFilmVec3;
|
|
957
|
+
/** Spot lights: full cone angle, 1..179 degrees (default 60). */
|
|
958
|
+
spotAngleDeg?: number;
|
|
959
|
+
/**
|
|
960
|
+
* Spot lights: how much of the cone is soft, 0..1 (default 0.5,
|
|
961
|
+
* LayaAir's own): 0 a hard rim, 1 soft from the middle out.
|
|
962
|
+
*/
|
|
963
|
+
penumbra?: number;
|
|
964
|
+
/**
|
|
965
|
+
* The light casts shadows: one spot light and up to eight point lights
|
|
966
|
+
* per scene may (more than four share their texture at half the
|
|
967
|
+
* sharpness). A spot uses LayaAir's own shadow map. A point light's
|
|
968
|
+
* surroundings are drawn once from the lamp (`ZhudaPointShadow`), and
|
|
969
|
+
* again when its `range` or something that moves with time changes: a
|
|
970
|
+
* lamp that `follows` a model casts from where the model has carried
|
|
971
|
+
* it. Nothing closer to it than 0.5 m casts (the lamp's own head).
|
|
972
|
+
*/
|
|
973
|
+
castsShadow?: boolean;
|
|
974
|
+
/**
|
|
975
|
+
* Keeps the light at `offset` (metres, in the model's own frame: +Z is
|
|
976
|
+
* the model's front before `yawDeg`) from a `model` node, following its
|
|
977
|
+
* `motion`. Point lights only; `position` is then ignored.
|
|
978
|
+
*/
|
|
979
|
+
follows?: { node: string; offset?: ZhudaFilmVec3 };
|
|
980
|
+
/**
|
|
981
|
+
* The light only shines into `look.lightFog` and does not light
|
|
982
|
+
* surfaces: for lamps whose light is already in a lightmap. Point
|
|
983
|
+
* lights only; such lights do not count against the 32 real-time lights.
|
|
984
|
+
*/
|
|
985
|
+
fogOnly?: boolean;
|
|
986
|
+
};
|
|
987
|
+
|
|
988
|
+
/** A clip of a model, sampled at `offsetSec + shotTime * speed`. */
|
|
989
|
+
export interface ZhudaFilmAnimation {
|
|
990
|
+
/** Name of an animation in the model file. */
|
|
991
|
+
clip: string;
|
|
992
|
+
/** Repeat the clip (default true); otherwise hold its last frame. */
|
|
993
|
+
loop?: boolean;
|
|
994
|
+
/** 0..8 (default 1). */
|
|
995
|
+
speed?: number;
|
|
996
|
+
/** Clip time at shot time 0, 0..3600 seconds (default 0). */
|
|
997
|
+
offsetSec?: number;
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
export interface ZhudaFilmMotionKey {
|
|
1001
|
+
/** Seconds from the start of the shot. */
|
|
1002
|
+
time: number;
|
|
1003
|
+
position: ZhudaFilmVec3;
|
|
1004
|
+
/** Defaults to the previous key's yaw (the node's `yawDeg` for the first). */
|
|
1005
|
+
yawDeg?: number;
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
/**
|
|
1009
|
+
* Where a moving node is at `time`: linear between keys, yaw the short way
|
|
1010
|
+
* around, the first and last keys held outside their range.
|
|
1011
|
+
*/
|
|
1012
|
+
export function sampleZhudaFilmMotion(
|
|
1013
|
+
keys: readonly ZhudaFilmMotionKey[],
|
|
1014
|
+
time: number,
|
|
1015
|
+
baseYawDeg = 0,
|
|
1016
|
+
): { position: ZhudaFilmVec3; yawDeg: number } {
|
|
1017
|
+
const yaws: number[] = [];
|
|
1018
|
+
keys.forEach((key, i) => yaws.push(key.yawDeg ?? (i ? yaws[i - 1] : baseYawDeg)));
|
|
1019
|
+
if (!(time > keys[0].time)) return { position: [...keys[0].position], yawDeg: yaws[0] };
|
|
1020
|
+
for (let i = 1; i < keys.length; i++) {
|
|
1021
|
+
if (time > keys[i].time) continue;
|
|
1022
|
+
const a = keys[i - 1],
|
|
1023
|
+
b = keys[i],
|
|
1024
|
+
u = (time - a.time) / (b.time - a.time);
|
|
1025
|
+
const turn = ((((yaws[i] - yaws[i - 1]) % 360) + 540) % 360) - 180;
|
|
1026
|
+
return {
|
|
1027
|
+
position: a.position.map((v, k) => v + (b.position[k] - v) * u) as ZhudaFilmVec3,
|
|
1028
|
+
yawDeg: yaws[i - 1] + turn * u,
|
|
1029
|
+
};
|
|
1030
|
+
}
|
|
1031
|
+
const last = keys.length - 1;
|
|
1032
|
+
return { position: [...keys[last].position], yawDeg: yaws[last] };
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
/** Screen-space reflections (see `ZhudaScreenReflections`). */
|
|
1036
|
+
export interface ZhudaFilmScreenReflections {
|
|
1037
|
+
/** Brightness of the reflections, 0..4 (default 1). */
|
|
1038
|
+
strength?: number;
|
|
1039
|
+
/** How wet the surfaces are, 0..1: how much shows when seen head-on (default 0.5). */
|
|
1040
|
+
wetness?: number;
|
|
1041
|
+
/** Metres a reflected ray is followed, 1..200 (default 30). */
|
|
1042
|
+
distance?: number;
|
|
1043
|
+
/** Steps along the ray, 8..64 (default 32). */
|
|
1044
|
+
steps?: number;
|
|
1045
|
+
/**
|
|
1046
|
+
* How much of the sky shows where a reflected ray finds nothing and points
|
|
1047
|
+
* upward, 0..1 (default 0). Give it to wet ground under an open sky; leave
|
|
1048
|
+
* it at 0 indoors and under cover, where the sky would shine through.
|
|
1049
|
+
*/
|
|
1050
|
+
sky?: number;
|
|
1051
|
+
/** The sky's colour for that, 0..1 (default: the sky's colour near the horizon). */
|
|
1052
|
+
skyColor?: ZhudaFilmVec3;
|
|
1053
|
+
/**
|
|
1054
|
+
* Each surface reflects by its own normal and roughness where its material
|
|
1055
|
+
* says them (default false: the whole view reflects alike).
|
|
1056
|
+
*/
|
|
1057
|
+
surfaces?: boolean;
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
/** The sun's flare (see `ZhudaLensFlare`); where it is and its colour come from the look. */
|
|
1061
|
+
export interface ZhudaFilmLensFlare {
|
|
1062
|
+
/** Scales every element, 0..16 (default 1). */
|
|
1063
|
+
strength?: number;
|
|
1064
|
+
/** The radius round the sun that is looked up in the depth picture, a share of the picture's height (default 0.012). */
|
|
1065
|
+
occlusionRadius?: number;
|
|
1066
|
+
/** One to twelve elements (default `ZHUDA_LENS_FLARE_SUN`). */
|
|
1067
|
+
elements?: readonly ZhudaLensFlareElement[];
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
/** A layer of clouds (see `ZhudaClouds`); their light comes from the look. */
|
|
1071
|
+
export interface ZhudaFilmClouds {
|
|
1072
|
+
/** How much of the sky is cloud, 0..1 (default 0.5). */
|
|
1073
|
+
coverage?: number;
|
|
1074
|
+
/** Height of the clouds' underside in metres, -20000..20000 (default 1500); below the eye, a sea of cloud. */
|
|
1075
|
+
baseMeters?: number;
|
|
1076
|
+
/** How thick the layer is in metres, 50..8000 (default 900). */
|
|
1077
|
+
thicknessMeters?: number;
|
|
1078
|
+
/** Size of a cloud in metres, 100..50000 (default 2600). */
|
|
1079
|
+
sizeMeters?: number;
|
|
1080
|
+
/** How dense the cloud is, 0..4 (default 1). */
|
|
1081
|
+
density?: number;
|
|
1082
|
+
/** The wind: metres a second along X and Z (default [8, 0]). */
|
|
1083
|
+
wind?: [number, number];
|
|
1084
|
+
/** Steps along each view ray, 8..64 (default 32). */
|
|
1085
|
+
steps?: number;
|
|
1086
|
+
/** How far clouds are drawn in metres, 1000..200000 (default 40000). */
|
|
1087
|
+
distanceMeters?: number;
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
/** Light bounced once off the scene (see `ZhudaProbeVolume`). */
|
|
1091
|
+
export interface ZhudaFilmBounceLight {
|
|
1092
|
+
/** Metres between probes, 1..20 (default 3). */
|
|
1093
|
+
spacing?: number;
|
|
1094
|
+
/** Multiplies the bounced light, 0..4 (default 1). */
|
|
1095
|
+
strength?: number;
|
|
1096
|
+
/** Corners of the box the probes fill; by default the scene's objects and lights, widened by 2 m. */
|
|
1097
|
+
min?: ZhudaFilmVec3;
|
|
1098
|
+
max?: ZhudaFilmVec3;
|
|
1099
|
+
/**
|
|
1100
|
+
* Each probe also keeps how far it sees, and a surface takes light only
|
|
1101
|
+
* from probes that see it: a wall thinner than `spacing` then no longer
|
|
1102
|
+
* lets the light of one side through to the other. One more depth pass a
|
|
1103
|
+
* probe at mount. Default false.
|
|
1104
|
+
*/
|
|
1105
|
+
visibility?: boolean;
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
export interface ZhudaFilmScene {
|
|
1109
|
+
schemaVersion: 1;
|
|
1110
|
+
id: string;
|
|
1111
|
+
camera: ZhudaFilmCamera;
|
|
1112
|
+
/**
|
|
1113
|
+
* Left out, the scene gets `ZHUDA_FILM_ABSENT_LOOK`: the day preset (sun,
|
|
1114
|
+
* shadows, sky, distance fog). An empty object is the bare look, kept for
|
|
1115
|
+
* tests: a flat sky colour and no shadows.
|
|
1116
|
+
*/
|
|
1117
|
+
look?: ZhudaFilmLook;
|
|
1118
|
+
materials?: Record<string, ZhudaFilmMaterial>;
|
|
1119
|
+
nodes: ZhudaFilmNode[];
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
/** Atomic change set. Removals run first, then upserts by node id. */
|
|
1123
|
+
export interface ZhudaFilmScenePatch {
|
|
1124
|
+
camera?: Partial<ZhudaFilmCamera>;
|
|
1125
|
+
look?: Partial<ZhudaFilmLook>;
|
|
1126
|
+
/** `null` removes a material. */
|
|
1127
|
+
materials?: Record<string, ZhudaFilmMaterial | null>;
|
|
1128
|
+
upsert?: ZhudaFilmNode[];
|
|
1129
|
+
remove?: string[];
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
export interface ZhudaFilmValidationContext {
|
|
1133
|
+
/** Prop ids the host can build. When omitted, prop ids are not checked. */
|
|
1134
|
+
props?: readonly string[];
|
|
1135
|
+
/** Recipe names the host can bake. When omitted, recipe names are not checked. */
|
|
1136
|
+
recipes?: readonly string[];
|
|
1137
|
+
/** Asset ids the host can deliver. When omitted, asset ids are not checked. */
|
|
1138
|
+
assets?: readonly string[];
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
export interface ZhudaFilmCameraKey {
|
|
1142
|
+
time: number;
|
|
1143
|
+
camera: ZhudaFilmCamera;
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
export const ZHUDA_FILM_LIMITS = Object.freeze({
|
|
1147
|
+
nodes: 512,
|
|
1148
|
+
materials: 64,
|
|
1149
|
+
extent: 10_000,
|
|
1150
|
+
idLength: 64,
|
|
1151
|
+
/**
|
|
1152
|
+
* Real-time lights a scene may ask for. The runtime must have been booted
|
|
1153
|
+
* with at least as many (`maxLights`; Laya's default is 32).
|
|
1154
|
+
*/
|
|
1155
|
+
lights: 128,
|
|
1156
|
+
/** Point lights one `lightFog` can hold, fog-only lights included. */
|
|
1157
|
+
fogLights: 128,
|
|
1158
|
+
/** Point lights that may cast shadows (one spot light may as well). */
|
|
1159
|
+
pointShadows: 8,
|
|
1160
|
+
models: 64,
|
|
1161
|
+
/** Copies of one model node; a scene holds at most `placementsTotal` in all. */
|
|
1162
|
+
placements: 20000,
|
|
1163
|
+
placementsTotal: 60000,
|
|
1164
|
+
});
|
|
1165
|
+
|
|
1166
|
+
/** What a scene that gives no `look` at all is drawn with. */
|
|
1167
|
+
export const ZHUDA_FILM_ABSENT_LOOK: Readonly<ZhudaFilmLook> = Object.freeze({ preset: 'day' });
|
|
1168
|
+
|
|
1169
|
+
/** The bare look of a `look` without a preset (phase 1 behaviour). */
|
|
1170
|
+
export const ZHUDA_FILM_DEFAULT_LOOK = Object.freeze({
|
|
1171
|
+
sky: [0.55, 0.65, 0.78] as ZhudaFilmVec3,
|
|
1172
|
+
ambient: [0.3, 0.3, 0.32] as ZhudaFilmVec3,
|
|
1173
|
+
sun: Object.freeze({
|
|
1174
|
+
azimuthDeg: 50,
|
|
1175
|
+
elevationDeg: 40,
|
|
1176
|
+
intensity: 1.2,
|
|
1177
|
+
color: [1, 0.97, 0.92] as ZhudaFilmVec3,
|
|
1178
|
+
}),
|
|
1179
|
+
});
|
|
1180
|
+
|
|
1181
|
+
type PresetLook = {
|
|
1182
|
+
sky: ZhudaFilmVec3;
|
|
1183
|
+
ambient: ZhudaFilmVec3;
|
|
1184
|
+
sun: Required<ZhudaFilmSun>;
|
|
1185
|
+
shadows: Required<ZhudaFilmShadows>;
|
|
1186
|
+
atmosphere: Required<ZhudaFilmAtmosphere>;
|
|
1187
|
+
fog: Required<ZhudaFilmFog> | false;
|
|
1188
|
+
/**
|
|
1189
|
+
* The preset's sky 5 to 10 degrees above the horizon, averaged around the
|
|
1190
|
+
* compass (measured from a draw of the preset in scene-linear light, kept
|
|
1191
|
+
* here as the display value that decodes to it). Ground fog takes this
|
|
1192
|
+
* colour by default so that it melts into the sky.
|
|
1193
|
+
*/
|
|
1194
|
+
/** Light from the ground below (the presets with a sun high enough give one). */
|
|
1195
|
+
ambientGround?: ZhudaFilmVec3;
|
|
1196
|
+
horizon: ZhudaFilmVec3;
|
|
1197
|
+
};
|
|
1198
|
+
const shadows = (strength: number): Required<ZhudaFilmShadows> => ({
|
|
1199
|
+
distance: 60,
|
|
1200
|
+
softness: 'soft',
|
|
1201
|
+
strength,
|
|
1202
|
+
resolution: 2048,
|
|
1203
|
+
cascades: 2,
|
|
1204
|
+
update: 'every',
|
|
1205
|
+
interval: 3,
|
|
1206
|
+
spread: 1,
|
|
1207
|
+
blend: false,
|
|
1208
|
+
contact: 0,
|
|
1209
|
+
});
|
|
1210
|
+
|
|
1211
|
+
/** Starting points for a time of day; any look field overrides them. */
|
|
1212
|
+
export const ZHUDA_FILM_LOOK_PRESETS: Readonly<Record<ZhudaFilmLookPreset, PresetLook>> =
|
|
1213
|
+
Object.freeze({
|
|
1214
|
+
day: {
|
|
1215
|
+
sky: [0.5, 0.66, 0.9],
|
|
1216
|
+
horizon: [0.642, 0.761, 0.891],
|
|
1217
|
+
// Sky light from above and the light the ground throws back: about a
|
|
1218
|
+
// third of the sun's on the ground, as under a clear sky.
|
|
1219
|
+
ambient: [0.62, 0.64, 0.7],
|
|
1220
|
+
ambientGround: [0.5, 0.47, 0.42],
|
|
1221
|
+
sun: { azimuthDeg: 40, elevationDeg: 55, intensity: 1.3, color: [1, 0.97, 0.92] },
|
|
1222
|
+
shadows: shadows(0.85),
|
|
1223
|
+
atmosphere: {
|
|
1224
|
+
thickness: 1,
|
|
1225
|
+
skyTint: [0.5, 0.5, 0.5],
|
|
1226
|
+
groundTint: [0.37, 0.35, 0.33],
|
|
1227
|
+
exposure: 1.3,
|
|
1228
|
+
sunSize: 0.04,
|
|
1229
|
+
},
|
|
1230
|
+
fog: { color: [0.72, 0.8, 0.9], start: 120, end: 600 },
|
|
1231
|
+
},
|
|
1232
|
+
dawn: {
|
|
1233
|
+
sky: [0.93, 0.6, 0.42],
|
|
1234
|
+
horizon: [0.832, 0.735, 0.381],
|
|
1235
|
+
ambient: [0.64, 0.58, 0.55],
|
|
1236
|
+
ambientGround: [0.46, 0.4, 0.36],
|
|
1237
|
+
sun: { azimuthDeg: -70, elevationDeg: 9, intensity: 1.35, color: [1, 0.72, 0.46] },
|
|
1238
|
+
shadows: shadows(0.8),
|
|
1239
|
+
atmosphere: {
|
|
1240
|
+
thickness: 1.9,
|
|
1241
|
+
skyTint: [0.55, 0.45, 0.45],
|
|
1242
|
+
groundTint: [0.3, 0.25, 0.22],
|
|
1243
|
+
exposure: 1.2,
|
|
1244
|
+
sunSize: 0.05,
|
|
1245
|
+
},
|
|
1246
|
+
fog: { color: [0.9, 0.66, 0.52], start: 60, end: 400 },
|
|
1247
|
+
},
|
|
1248
|
+
dusk: {
|
|
1249
|
+
sky: [0.82, 0.45, 0.35],
|
|
1250
|
+
horizon: [0.687, 0.517, 0.1],
|
|
1251
|
+
ambient: [0.58, 0.52, 0.55],
|
|
1252
|
+
ambientGround: [0.4, 0.34, 0.32],
|
|
1253
|
+
sun: { azimuthDeg: 110, elevationDeg: 6, intensity: 1.2, color: [1, 0.6, 0.38] },
|
|
1254
|
+
shadows: shadows(0.75),
|
|
1255
|
+
atmosphere: {
|
|
1256
|
+
thickness: 2.2,
|
|
1257
|
+
skyTint: [0.5, 0.4, 0.5],
|
|
1258
|
+
groundTint: [0.25, 0.2, 0.2],
|
|
1259
|
+
exposure: 1.1,
|
|
1260
|
+
sunSize: 0.06,
|
|
1261
|
+
},
|
|
1262
|
+
fog: { color: [0.7, 0.45, 0.4], start: 50, end: 350 },
|
|
1263
|
+
},
|
|
1264
|
+
night: {
|
|
1265
|
+
sky: [0.025, 0.04, 0.09],
|
|
1266
|
+
horizon: [0.156, 0.203, 0.306],
|
|
1267
|
+
ambient: [0.08, 0.1, 0.17],
|
|
1268
|
+
// Moonlight: a dim, cool key that still casts soft shadows.
|
|
1269
|
+
sun: { azimuthDeg: 125, elevationDeg: 38, intensity: 0.45, color: [0.62, 0.72, 1] },
|
|
1270
|
+
shadows: shadows(0.6),
|
|
1271
|
+
atmosphere: {
|
|
1272
|
+
thickness: 0.6,
|
|
1273
|
+
skyTint: [0.12, 0.16, 0.3],
|
|
1274
|
+
groundTint: [0.05, 0.06, 0.09],
|
|
1275
|
+
exposure: 0.35,
|
|
1276
|
+
sunSize: 0.02,
|
|
1277
|
+
},
|
|
1278
|
+
fog: { color: [0.05, 0.07, 0.12], start: 40, end: 260 },
|
|
1279
|
+
},
|
|
1280
|
+
overcast: {
|
|
1281
|
+
sky: [0.62, 0.66, 0.7],
|
|
1282
|
+
horizon: [0.742, 0.804, 0.715],
|
|
1283
|
+
ambient: [0.7, 0.71, 0.73],
|
|
1284
|
+
ambientGround: [0.52, 0.51, 0.49],
|
|
1285
|
+
sun: { azimuthDeg: 30, elevationDeg: 60, intensity: 0.55, color: [0.92, 0.94, 1] },
|
|
1286
|
+
shadows: shadows(0.3),
|
|
1287
|
+
atmosphere: {
|
|
1288
|
+
thickness: 1.4,
|
|
1289
|
+
skyTint: [0.55, 0.55, 0.58],
|
|
1290
|
+
groundTint: [0.4, 0.4, 0.42],
|
|
1291
|
+
exposure: 1,
|
|
1292
|
+
sunSize: 0,
|
|
1293
|
+
},
|
|
1294
|
+
fog: { color: [0.66, 0.69, 0.72], start: 30, end: 300 },
|
|
1295
|
+
},
|
|
1296
|
+
});
|
|
1297
|
+
|
|
1298
|
+
const ID = /^[a-z0-9][a-z0-9._-]*$/;
|
|
1299
|
+
const finite = (v: unknown): v is number => typeof v === 'number' && Number.isFinite(v);
|
|
1300
|
+
const object = (v: unknown): v is Record<string, unknown> =>
|
|
1301
|
+
!!v && typeof v === 'object' && !Array.isArray(v);
|
|
1302
|
+
const isId = (v: unknown) =>
|
|
1303
|
+
typeof v === 'string' && v.length <= ZHUDA_FILM_LIMITS.idLength && ID.test(v);
|
|
1304
|
+
|
|
1305
|
+
function vec3(
|
|
1306
|
+
value: unknown,
|
|
1307
|
+
path: string,
|
|
1308
|
+
issues: string[],
|
|
1309
|
+
extent: number = ZHUDA_FILM_LIMITS.extent,
|
|
1310
|
+
) {
|
|
1311
|
+
if (
|
|
1312
|
+
!Array.isArray(value) ||
|
|
1313
|
+
value.length !== 3 ||
|
|
1314
|
+
!value.every((n) => finite(n) && Math.abs(n) <= extent)
|
|
1315
|
+
)
|
|
1316
|
+
issues.push(`${path}: use three finite numbers within ±${extent}`);
|
|
1317
|
+
}
|
|
1318
|
+
function colour(value: unknown, path: string, issues: string[]) {
|
|
1319
|
+
if (
|
|
1320
|
+
!Array.isArray(value) ||
|
|
1321
|
+
value.length !== 3 ||
|
|
1322
|
+
!value.every((n) => finite(n) && n >= 0 && n <= 1)
|
|
1323
|
+
)
|
|
1324
|
+
issues.push(`${path}: use RGB with three values between 0 and 1`);
|
|
1325
|
+
}
|
|
1326
|
+
function unknownKeys(
|
|
1327
|
+
value: Record<string, unknown>,
|
|
1328
|
+
allowed: string[],
|
|
1329
|
+
path: string,
|
|
1330
|
+
issues: string[],
|
|
1331
|
+
) {
|
|
1332
|
+
for (const key of Object.keys(value))
|
|
1333
|
+
if (!allowed.includes(key)) {
|
|
1334
|
+
const near = nearestName(key, allowed);
|
|
1335
|
+
issues.push(`${path}.${key}: unknown field` + (near ? ` (did you mean ${near}?)` : ''));
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
/** The allowed name a mistyped one most likely meant, if any is close enough. */
|
|
1339
|
+
function nearestName(name: string, allowed: readonly string[]): string | undefined {
|
|
1340
|
+
const a = name.toLowerCase();
|
|
1341
|
+
let best: string | undefined,
|
|
1342
|
+
bestDistance = Infinity;
|
|
1343
|
+
for (const candidate of allowed) {
|
|
1344
|
+
const b = candidate.toLowerCase();
|
|
1345
|
+
if (a === b) return candidate;
|
|
1346
|
+
// One is the other plus an ending: `shadow` for `shadows`, `lightfogs` for `lightFog`.
|
|
1347
|
+
if (a.length >= 3 && b.length >= 3 && (a.startsWith(b) || b.startsWith(a))) {
|
|
1348
|
+
const extra = Math.abs(a.length - b.length);
|
|
1349
|
+
if (extra <= 2 && extra < bestDistance) [best, bestDistance] = [candidate, extra];
|
|
1350
|
+
continue;
|
|
1351
|
+
}
|
|
1352
|
+
if (Math.abs(a.length - b.length) > 2 || Math.min(a.length, b.length) < 4) continue;
|
|
1353
|
+
let row = Array.from({ length: b.length + 1 }, (_, i) => i);
|
|
1354
|
+
for (let i = 1; i <= a.length; i++) {
|
|
1355
|
+
const next = [i];
|
|
1356
|
+
for (let j = 1; j <= b.length; j++)
|
|
1357
|
+
next[j] = Math.min(
|
|
1358
|
+
row[j] + 1,
|
|
1359
|
+
next[j - 1] + 1,
|
|
1360
|
+
row[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1),
|
|
1361
|
+
);
|
|
1362
|
+
row = next;
|
|
1363
|
+
}
|
|
1364
|
+
if (row[b.length] <= 2 && row[b.length] < bestDistance)
|
|
1365
|
+
[best, bestDistance] = [candidate, row[b.length]];
|
|
1366
|
+
}
|
|
1367
|
+
return best;
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1370
|
+
function validateCamera(camera: unknown, path: string, issues: string[], partial = false) {
|
|
1371
|
+
if (!object(camera)) return void issues.push(`${path}: camera object required`);
|
|
1372
|
+
unknownKeys(camera, ['eye', 'target', 'focalLengthMm', 'fStop', 'focusDistanceM'], path, issues);
|
|
1373
|
+
if (!partial || camera.eye !== undefined) vec3(camera.eye, `${path}.eye`, issues);
|
|
1374
|
+
if (!partial || camera.target !== undefined) vec3(camera.target, `${path}.target`, issues);
|
|
1375
|
+
if (
|
|
1376
|
+
!partial &&
|
|
1377
|
+
Array.isArray(camera.eye) &&
|
|
1378
|
+
Array.isArray(camera.target) &&
|
|
1379
|
+
camera.eye.every((v, i) => v === (camera.target as number[])[i])
|
|
1380
|
+
)
|
|
1381
|
+
issues.push(`${path}: eye and target must differ`);
|
|
1382
|
+
if (
|
|
1383
|
+
camera.focalLengthMm !== undefined &&
|
|
1384
|
+
!(finite(camera.focalLengthMm) && camera.focalLengthMm >= 8 && camera.focalLengthMm <= 600)
|
|
1385
|
+
)
|
|
1386
|
+
issues.push(`${path}.focalLengthMm: use 8..600`);
|
|
1387
|
+
if (
|
|
1388
|
+
camera.fStop !== undefined &&
|
|
1389
|
+
!(finite(camera.fStop) && camera.fStop >= 0.7 && camera.fStop <= 64)
|
|
1390
|
+
)
|
|
1391
|
+
issues.push(`${path}.fStop: use 0.7..64`);
|
|
1392
|
+
if (
|
|
1393
|
+
camera.focusDistanceM !== undefined &&
|
|
1394
|
+
!(
|
|
1395
|
+
finite(camera.focusDistanceM) &&
|
|
1396
|
+
camera.focusDistanceM > 0.05 &&
|
|
1397
|
+
camera.focusDistanceM <= ZHUDA_FILM_LIMITS.extent
|
|
1398
|
+
)
|
|
1399
|
+
)
|
|
1400
|
+
issues.push(`${path}.focusDistanceM: use a distance above 0.05 m`);
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
function validateLook(
|
|
1404
|
+
look: unknown,
|
|
1405
|
+
path: string,
|
|
1406
|
+
issues: string[],
|
|
1407
|
+
context: ZhudaFilmValidationContext = {},
|
|
1408
|
+
) {
|
|
1409
|
+
if (!object(look)) return void issues.push(`${path}: look object required`);
|
|
1410
|
+
unknownKeys(
|
|
1411
|
+
look,
|
|
1412
|
+
[
|
|
1413
|
+
'preset',
|
|
1414
|
+
'sky',
|
|
1415
|
+
'ambient',
|
|
1416
|
+
'ambientGround',
|
|
1417
|
+
'lightFalloff',
|
|
1418
|
+
'sun',
|
|
1419
|
+
'shadows',
|
|
1420
|
+
'atmosphere',
|
|
1421
|
+
'fog',
|
|
1422
|
+
'grade',
|
|
1423
|
+
'lightFog',
|
|
1424
|
+
'screenReflections',
|
|
1425
|
+
'autoExposure',
|
|
1426
|
+
'depthOfField',
|
|
1427
|
+
'motionBlur',
|
|
1428
|
+
'clouds',
|
|
1429
|
+
'lensFlare',
|
|
1430
|
+
'underwater',
|
|
1431
|
+
'bounceLight',
|
|
1432
|
+
'environment',
|
|
1433
|
+
'panorama',
|
|
1434
|
+
],
|
|
1435
|
+
path,
|
|
1436
|
+
issues,
|
|
1437
|
+
);
|
|
1438
|
+
if (look.preset !== undefined && !Object.hasOwn(ZHUDA_FILM_LOOK_PRESETS, String(look.preset)))
|
|
1439
|
+
issues.push(`${path}.preset: use ${Object.keys(ZHUDA_FILM_LOOK_PRESETS).join(', ')}`);
|
|
1440
|
+
const range = (value: unknown, at: string, lo: number, hi: number) => {
|
|
1441
|
+
if (value !== undefined && !(finite(value) && value >= lo && value <= hi))
|
|
1442
|
+
issues.push(`${at}: use ${lo}..${hi}`);
|
|
1443
|
+
};
|
|
1444
|
+
if (look.shadows !== undefined && look.shadows !== false) {
|
|
1445
|
+
const sh = look.shadows;
|
|
1446
|
+
if (!object(sh)) issues.push(`${path}.shadows: object or false required`);
|
|
1447
|
+
else {
|
|
1448
|
+
unknownKeys(
|
|
1449
|
+
sh,
|
|
1450
|
+
[
|
|
1451
|
+
'distance',
|
|
1452
|
+
'softness',
|
|
1453
|
+
'strength',
|
|
1454
|
+
'resolution',
|
|
1455
|
+
'cascades',
|
|
1456
|
+
'update',
|
|
1457
|
+
'interval',
|
|
1458
|
+
'spread',
|
|
1459
|
+
'blend',
|
|
1460
|
+
'contact',
|
|
1461
|
+
],
|
|
1462
|
+
`${path}.shadows`,
|
|
1463
|
+
issues,
|
|
1464
|
+
);
|
|
1465
|
+
range(sh.distance, `${path}.shadows.distance`, 5, 500);
|
|
1466
|
+
range(sh.strength, `${path}.shadows.strength`, 0, 1);
|
|
1467
|
+
if (sh.softness !== undefined && sh.softness !== 'hard' && sh.softness !== 'soft')
|
|
1468
|
+
issues.push(`${path}.shadows.softness: use hard or soft`);
|
|
1469
|
+
if (sh.cascades !== undefined && ![1, 2, 4].includes(sh.cascades as number))
|
|
1470
|
+
issues.push(`${path}.shadows.cascades: use 1, 2 or 4`);
|
|
1471
|
+
if (sh.resolution !== undefined && ![1024, 2048, 4096].includes(sh.resolution as number))
|
|
1472
|
+
issues.push(`${path}.shadows.resolution: use 1024, 2048 or 4096`);
|
|
1473
|
+
if (sh.update !== undefined && !['every', 'interval', 'manual'].includes(sh.update as string))
|
|
1474
|
+
issues.push(`${path}.shadows.update: use every, interval or manual`);
|
|
1475
|
+
if (
|
|
1476
|
+
sh.interval !== undefined &&
|
|
1477
|
+
!(
|
|
1478
|
+
Number.isInteger(sh.interval) &&
|
|
1479
|
+
(sh.interval as number) >= 2 &&
|
|
1480
|
+
(sh.interval as number) <= 30
|
|
1481
|
+
)
|
|
1482
|
+
)
|
|
1483
|
+
issues.push(`${path}.shadows.interval: use a whole number of frames 2..30`);
|
|
1484
|
+
range(sh.spread, `${path}.shadows.spread`, 1, 4);
|
|
1485
|
+
if (sh.blend !== undefined && typeof sh.blend !== 'boolean')
|
|
1486
|
+
issues.push(`${path}.shadows.blend: use true or false`);
|
|
1487
|
+
if (sh.contact !== undefined && sh.contact !== 0)
|
|
1488
|
+
range(sh.contact, `${path}.shadows.contact`, 0.02, 2);
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
if (
|
|
1492
|
+
look.lightFalloff !== undefined &&
|
|
1493
|
+
!['laya', 'physical'].includes(look.lightFalloff as string)
|
|
1494
|
+
)
|
|
1495
|
+
issues.push(`${path}.lightFalloff: use laya or physical`);
|
|
1496
|
+
if (look.atmosphere !== undefined && look.atmosphere !== false) {
|
|
1497
|
+
const at = look.atmosphere;
|
|
1498
|
+
if (!object(at)) issues.push(`${path}.atmosphere: object or false required`);
|
|
1499
|
+
else {
|
|
1500
|
+
unknownKeys(
|
|
1501
|
+
at,
|
|
1502
|
+
['thickness', 'skyTint', 'groundTint', 'exposure', 'sunSize'],
|
|
1503
|
+
`${path}.atmosphere`,
|
|
1504
|
+
issues,
|
|
1505
|
+
);
|
|
1506
|
+
range(at.thickness, `${path}.atmosphere.thickness`, 0, 5);
|
|
1507
|
+
range(at.exposure, `${path}.atmosphere.exposure`, 0, 8);
|
|
1508
|
+
range(at.sunSize, `${path}.atmosphere.sunSize`, 0, 1);
|
|
1509
|
+
if (at.skyTint !== undefined) colour(at.skyTint, `${path}.atmosphere.skyTint`, issues);
|
|
1510
|
+
if (at.groundTint !== undefined)
|
|
1511
|
+
colour(at.groundTint, `${path}.atmosphere.groundTint`, issues);
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
if (look.fog !== undefined && look.fog !== false) {
|
|
1515
|
+
const fog = look.fog;
|
|
1516
|
+
if (!object(fog)) issues.push(`${path}.fog: object or false required`);
|
|
1517
|
+
else {
|
|
1518
|
+
unknownKeys(fog, ['color', 'start', 'end'], `${path}.fog`, issues);
|
|
1519
|
+
if (fog.color !== undefined) colour(fog.color, `${path}.fog.color`, issues);
|
|
1520
|
+
if (
|
|
1521
|
+
!(
|
|
1522
|
+
finite(fog.start) &&
|
|
1523
|
+
fog.start >= 0 &&
|
|
1524
|
+
finite(fog.end) &&
|
|
1525
|
+
fog.end > fog.start &&
|
|
1526
|
+
fog.end <= ZHUDA_FILM_LIMITS.extent
|
|
1527
|
+
)
|
|
1528
|
+
)
|
|
1529
|
+
issues.push(`${path}.fog: start >= 0 and end > start (metres)`);
|
|
1530
|
+
}
|
|
1531
|
+
}
|
|
1532
|
+
if (look.grade !== undefined && look.grade !== false) {
|
|
1533
|
+
const g = look.grade;
|
|
1534
|
+
if (!object(g)) issues.push(`${path}.grade: object or false required`);
|
|
1535
|
+
else {
|
|
1536
|
+
unknownKeys(
|
|
1537
|
+
g,
|
|
1538
|
+
[
|
|
1539
|
+
'exposure',
|
|
1540
|
+
'contrast',
|
|
1541
|
+
'saturation',
|
|
1542
|
+
'bloom',
|
|
1543
|
+
'ao',
|
|
1544
|
+
'aoRadius',
|
|
1545
|
+
'grain',
|
|
1546
|
+
'vignette',
|
|
1547
|
+
'fringe',
|
|
1548
|
+
'antialias',
|
|
1549
|
+
'toneMapping',
|
|
1550
|
+
'temperature',
|
|
1551
|
+
'tint',
|
|
1552
|
+
'lift',
|
|
1553
|
+
'gamma',
|
|
1554
|
+
'gain',
|
|
1555
|
+
'bloomThreshold',
|
|
1556
|
+
'bloomSoftKnee',
|
|
1557
|
+
'bloomAnamorphic',
|
|
1558
|
+
'bloomDiffusion',
|
|
1559
|
+
'aoMethod',
|
|
1560
|
+
'lut',
|
|
1561
|
+
'dither',
|
|
1562
|
+
],
|
|
1563
|
+
`${path}.grade`,
|
|
1564
|
+
issues,
|
|
1565
|
+
);
|
|
1566
|
+
range(g.exposure, `${path}.grade.exposure`, 0.05, 16);
|
|
1567
|
+
range(g.contrast, `${path}.grade.contrast`, 0.5, 2);
|
|
1568
|
+
range(g.saturation, `${path}.grade.saturation`, 0, 2);
|
|
1569
|
+
range(g.bloom, `${path}.grade.bloom`, 0, 2);
|
|
1570
|
+
range(g.ao, `${path}.grade.ao`, 0, 4);
|
|
1571
|
+
range(g.aoRadius, `${path}.grade.aoRadius`, 0.05, 5);
|
|
1572
|
+
range(g.grain, `${path}.grade.grain`, 0, 1);
|
|
1573
|
+
range(g.vignette, `${path}.grade.vignette`, 0, 1);
|
|
1574
|
+
range(g.fringe, `${path}.grade.fringe`, 0, 1);
|
|
1575
|
+
if (
|
|
1576
|
+
g.antialias !== undefined &&
|
|
1577
|
+
!['msaa', 'fxaa', 'smaa', 'none'].includes(g.antialias as string)
|
|
1578
|
+
)
|
|
1579
|
+
issues.push(`${path}.grade.antialias: use msaa, fxaa, smaa or none`);
|
|
1580
|
+
if (g.dither !== undefined && typeof g.dither !== 'boolean')
|
|
1581
|
+
issues.push(`${path}.grade.dither: use true or false`);
|
|
1582
|
+
if (
|
|
1583
|
+
g.toneMapping !== undefined &&
|
|
1584
|
+
!ZHUDA_TONE_MAPPINGS.includes(g.toneMapping as ZhudaToneMapping)
|
|
1585
|
+
)
|
|
1586
|
+
issues.push(`${path}.grade.toneMapping: use ${ZHUDA_TONE_MAPPINGS.join(', ')}`);
|
|
1587
|
+
range(g.temperature, `${path}.grade.temperature`, -100, 100);
|
|
1588
|
+
range(g.tint, `${path}.grade.tint`, -100, 100);
|
|
1589
|
+
for (const [key, lo, hi] of [
|
|
1590
|
+
['lift', -1, 1],
|
|
1591
|
+
['gamma', 0.1, 10],
|
|
1592
|
+
['gain', 0, 16],
|
|
1593
|
+
] as const) {
|
|
1594
|
+
const value: unknown = g[key];
|
|
1595
|
+
if (
|
|
1596
|
+
value !== undefined &&
|
|
1597
|
+
!(
|
|
1598
|
+
Array.isArray(value) &&
|
|
1599
|
+
value.length === 3 &&
|
|
1600
|
+
value.every((n) => finite(n) && n >= lo && n <= hi)
|
|
1601
|
+
)
|
|
1602
|
+
)
|
|
1603
|
+
issues.push(`${path}.grade.${key}: three numbers ${lo}..${hi}`);
|
|
1604
|
+
}
|
|
1605
|
+
range(g.bloomThreshold, `${path}.grade.bloomThreshold`, 0, 16);
|
|
1606
|
+
range(g.bloomSoftKnee, `${path}.grade.bloomSoftKnee`, 0, 1);
|
|
1607
|
+
range(g.bloomAnamorphic, `${path}.grade.bloomAnamorphic`, -1, 1);
|
|
1608
|
+
range(g.bloomDiffusion, `${path}.grade.bloomDiffusion`, 1, 10);
|
|
1609
|
+
if (g.aoMethod !== undefined && !['sao', 'gtao'].includes(g.aoMethod as string))
|
|
1610
|
+
issues.push(`${path}.grade.aoMethod: use sao or gtao`);
|
|
1611
|
+
if (g.lut !== undefined && g.lut !== false) {
|
|
1612
|
+
const lut: unknown = g.lut;
|
|
1613
|
+
if (!object(lut)) issues.push(`${path}.grade.lut: object or false required`);
|
|
1614
|
+
else {
|
|
1615
|
+
unknownKeys(lut, ['asset', 'intensity'], `${path}.grade.lut`, issues);
|
|
1616
|
+
try {
|
|
1617
|
+
if (typeof lut.asset !== 'string') throw Error('a string');
|
|
1618
|
+
normalizeAssetId(lut.asset);
|
|
1619
|
+
} catch {
|
|
1620
|
+
issues.push(`${path}.grade.lut.asset: an asset id required`);
|
|
1621
|
+
}
|
|
1622
|
+
range(lut.intensity, `${path}.grade.lut.intensity`, 0, 1);
|
|
1623
|
+
}
|
|
1624
|
+
}
|
|
1625
|
+
}
|
|
1626
|
+
}
|
|
1627
|
+
if (look.lightFog !== undefined && look.lightFog !== false) {
|
|
1628
|
+
const f = look.lightFog;
|
|
1629
|
+
if (!object(f)) issues.push(`${path}.lightFog: object or false required`);
|
|
1630
|
+
else {
|
|
1631
|
+
unknownKeys(
|
|
1632
|
+
f,
|
|
1633
|
+
['density', 'falloffMeters', 'baseY', 'color', 'scatter', 'maxDistance', 'shafts'],
|
|
1634
|
+
`${path}.lightFog`,
|
|
1635
|
+
issues,
|
|
1636
|
+
);
|
|
1637
|
+
if (f.shafts !== undefined && f.shafts !== false) {
|
|
1638
|
+
const s = f.shafts;
|
|
1639
|
+
if (!object(s)) issues.push(`${path}.lightFog.shafts: object or false required`);
|
|
1640
|
+
else {
|
|
1641
|
+
unknownKeys(
|
|
1642
|
+
s,
|
|
1643
|
+
['strength', 'anisotropy', 'distance', 'steps', 'scale'],
|
|
1644
|
+
`${path}.lightFog.shafts`,
|
|
1645
|
+
issues,
|
|
1646
|
+
);
|
|
1647
|
+
range(s.strength, `${path}.lightFog.shafts.strength`, 0, 64);
|
|
1648
|
+
range(s.anisotropy, `${path}.lightFog.shafts.anisotropy`, 0, 0.95);
|
|
1649
|
+
range(s.distance, `${path}.lightFog.shafts.distance`, 5, 2000);
|
|
1650
|
+
range(s.scale, `${path}.lightFog.shafts.scale`, 0.25, 1);
|
|
1651
|
+
if (
|
|
1652
|
+
s.steps !== undefined &&
|
|
1653
|
+
!(Number.isInteger(s.steps) && (s.steps as number) >= 8 && (s.steps as number) <= 96)
|
|
1654
|
+
)
|
|
1655
|
+
issues.push(`${path}.lightFog.shafts.steps: use a whole number 8..96`);
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
range(f.density, `${path}.lightFog.density`, 0, 1);
|
|
1659
|
+
range(f.falloffMeters, `${path}.lightFog.falloffMeters`, 0.5, 1000);
|
|
1660
|
+
range(f.baseY, `${path}.lightFog.baseY`, -ZHUDA_FILM_LIMITS.extent, ZHUDA_FILM_LIMITS.extent);
|
|
1661
|
+
range(f.scatter, `${path}.lightFog.scatter`, 0, 16);
|
|
1662
|
+
range(f.maxDistance, `${path}.lightFog.maxDistance`, 1, 100000);
|
|
1663
|
+
if (f.color !== undefined) colour(f.color, `${path}.lightFog.color`, issues);
|
|
1664
|
+
if (look.grade === undefined || look.grade === false)
|
|
1665
|
+
issues.push(`${path}.lightFog: needs grade (the fog is part of the HDR chain)`);
|
|
1666
|
+
}
|
|
1667
|
+
}
|
|
1668
|
+
if (look.screenReflections !== undefined && look.screenReflections !== false) {
|
|
1669
|
+
const s = look.screenReflections,
|
|
1670
|
+
at = `${path}.screenReflections`;
|
|
1671
|
+
if (!object(s)) issues.push(`${at}: object or false required`);
|
|
1672
|
+
else {
|
|
1673
|
+
unknownKeys(
|
|
1674
|
+
s,
|
|
1675
|
+
['strength', 'wetness', 'distance', 'steps', 'sky', 'skyColor', 'surfaces'],
|
|
1676
|
+
at,
|
|
1677
|
+
issues,
|
|
1678
|
+
);
|
|
1679
|
+
if (s.surfaces !== undefined && typeof s.surfaces !== 'boolean')
|
|
1680
|
+
issues.push(`${at}.surfaces: use true or false`);
|
|
1681
|
+
range(s.sky, `${at}.sky`, 0, 1);
|
|
1682
|
+
if (s.skyColor !== undefined) vec3(s.skyColor, `${at}.skyColor`, issues, 1);
|
|
1683
|
+
range(s.strength, `${at}.strength`, 0, 4);
|
|
1684
|
+
range(s.wetness, `${at}.wetness`, 0, 1);
|
|
1685
|
+
range(s.distance, `${at}.distance`, 1, 200);
|
|
1686
|
+
const steps: unknown = s.steps;
|
|
1687
|
+
if (
|
|
1688
|
+
steps !== undefined &&
|
|
1689
|
+
!(typeof steps === 'number' && Number.isInteger(steps) && steps >= 8 && steps <= 64)
|
|
1690
|
+
)
|
|
1691
|
+
issues.push(`${at}.steps: use a whole number 8..64`);
|
|
1692
|
+
if (look.grade === undefined || look.grade === false)
|
|
1693
|
+
issues.push(`${at}: needs grade (the reflections are part of the HDR chain)`);
|
|
1694
|
+
}
|
|
1695
|
+
}
|
|
1696
|
+
const lens = (
|
|
1697
|
+
name: 'autoExposure' | 'depthOfField' | 'motionBlur' | 'clouds' | 'lensFlare',
|
|
1698
|
+
validate: (options: any) => string[],
|
|
1699
|
+
plain: boolean,
|
|
1700
|
+
) => {
|
|
1701
|
+
const value: unknown = look[name];
|
|
1702
|
+
if (value === undefined || value === false) return;
|
|
1703
|
+
const at = `${path}.${name}`;
|
|
1704
|
+
if (value === true && plain) {
|
|
1705
|
+
// The defaults.
|
|
1706
|
+
} else if (!object(value)) {
|
|
1707
|
+
issues.push(`${at}: ${plain ? 'object, true or false' : 'object or false'} required`);
|
|
1708
|
+
return;
|
|
1709
|
+
} else for (const issue of validate(value)) issues.push(`${at}.${issue}`);
|
|
1710
|
+
if (look.grade === undefined || look.grade === false)
|
|
1711
|
+
issues.push(`${at}: needs grade (it is part of the HDR chain)`);
|
|
1712
|
+
};
|
|
1713
|
+
lens('autoExposure', validateZhudaAutoExposure, true);
|
|
1714
|
+
lens('depthOfField', validateZhudaDepthOfField, false);
|
|
1715
|
+
lens('motionBlur', validateZhudaMotionBlur, true);
|
|
1716
|
+
lens('clouds', validateZhudaClouds, true);
|
|
1717
|
+
lens('lensFlare', validateZhudaLensFlare, true);
|
|
1718
|
+
if (look.underwater !== undefined && look.underwater !== false) {
|
|
1719
|
+
const at = `${path}.underwater`;
|
|
1720
|
+
if (look.underwater !== true) {
|
|
1721
|
+
if (!object(look.underwater)) issues.push(`${at}: object, true or false required`);
|
|
1722
|
+
else
|
|
1723
|
+
for (const issue of validateZhudaUnderwater(look.underwater)) issues.push(`${at}.${issue}`);
|
|
1724
|
+
}
|
|
1725
|
+
if (look.grade === undefined || look.grade === false)
|
|
1726
|
+
issues.push(`${at}: needs grade (the water is part of the HDR chain)`);
|
|
1727
|
+
}
|
|
1728
|
+
if (object(look.clouds))
|
|
1729
|
+
for (const key of ['sunToward', 'sunColor', 'skyColor'])
|
|
1730
|
+
if (key in look.clouds)
|
|
1731
|
+
issues.push(`${path}.clouds.${key}: comes from the look's sun and ambient light`);
|
|
1732
|
+
if (look.bounceLight !== undefined && look.bounceLight !== false) {
|
|
1733
|
+
const b = look.bounceLight,
|
|
1734
|
+
at = `${path}.bounceLight`;
|
|
1735
|
+
if (!object(b)) issues.push(`${at}: object or false required`);
|
|
1736
|
+
else {
|
|
1737
|
+
unknownKeys(b, ['spacing', 'strength', 'min', 'max', 'visibility'], at, issues);
|
|
1738
|
+
if (b.visibility !== undefined && typeof b.visibility !== 'boolean')
|
|
1739
|
+
issues.push(`${at}.visibility: true or false`);
|
|
1740
|
+
range(b.spacing, `${at}.spacing`, 1, 20);
|
|
1741
|
+
range(b.strength, `${at}.strength`, 0, 4);
|
|
1742
|
+
if ((b.min === undefined) !== (b.max === undefined))
|
|
1743
|
+
issues.push(`${at}: give min and max together`);
|
|
1744
|
+
else if (b.min !== undefined) {
|
|
1745
|
+
vec3(b.min, `${at}.min`, issues);
|
|
1746
|
+
vec3(b.max, `${at}.max`, issues);
|
|
1747
|
+
const low = b.min as number[],
|
|
1748
|
+
high = b.max as number[];
|
|
1749
|
+
if (
|
|
1750
|
+
Array.isArray(low) &&
|
|
1751
|
+
Array.isArray(high) &&
|
|
1752
|
+
!low.every((value, i) => typeof value === 'number' && value < high[i])
|
|
1753
|
+
)
|
|
1754
|
+
issues.push(`${at}.min: below max on every axis`);
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
1758
|
+
if (look.panorama !== undefined && look.panorama !== false) {
|
|
1759
|
+
const p = look.panorama;
|
|
1760
|
+
if (!object(p)) issues.push(`${path}.panorama: object or false required`);
|
|
1761
|
+
else {
|
|
1762
|
+
unknownKeys(p, ['asset', 'exposure', 'rotationDeg'], `${path}.panorama`, issues);
|
|
1763
|
+
let id: string | undefined;
|
|
1764
|
+
try {
|
|
1765
|
+
id = normalizeAssetId(p.asset as string);
|
|
1766
|
+
} catch {
|
|
1767
|
+
// Reported below.
|
|
1768
|
+
}
|
|
1769
|
+
if (id === undefined || id !== p.asset || !/\.(png|jpe?g)$/i.test(id))
|
|
1770
|
+
issues.push(`${path}.panorama.asset: use a logical asset id ending in .png or .jpg`);
|
|
1771
|
+
else if (context.assets && !context.assets.includes(id))
|
|
1772
|
+
issues.push(`${path}.panorama.asset: unknown asset ${id}`);
|
|
1773
|
+
range(p.exposure, `${path}.panorama.exposure`, 0, 16);
|
|
1774
|
+
range(p.rotationDeg, `${path}.panorama.rotationDeg`, -360, 360);
|
|
1775
|
+
}
|
|
1776
|
+
}
|
|
1777
|
+
if (look.environment !== undefined && look.environment !== false) {
|
|
1778
|
+
const e = look.environment;
|
|
1779
|
+
if (!object(e)) issues.push(`${path}.environment: object or false required`);
|
|
1780
|
+
else {
|
|
1781
|
+
unknownKeys(
|
|
1782
|
+
e,
|
|
1783
|
+
['position', 'reflection', 'ambient', 'reflectionOnly', 'box'],
|
|
1784
|
+
`${path}.environment`,
|
|
1785
|
+
issues,
|
|
1786
|
+
);
|
|
1787
|
+
if (e.reflectionOnly !== undefined && typeof e.reflectionOnly !== 'boolean')
|
|
1788
|
+
issues.push(`${path}.environment.reflectionOnly: true or false`);
|
|
1789
|
+
vec3(e.position, `${path}.environment.position`, issues);
|
|
1790
|
+
range(e.reflection, `${path}.environment.reflection`, 0, 8);
|
|
1791
|
+
range(e.ambient, `${path}.environment.ambient`, 0, 8);
|
|
1792
|
+
if (e.box !== undefined && e.box !== false) {
|
|
1793
|
+
const at = `${path}.environment.box`;
|
|
1794
|
+
if (!object(e.box)) issues.push(`${at}: use { min, max } or false`);
|
|
1795
|
+
else {
|
|
1796
|
+
unknownKeys(e.box, ['min', 'max'], at, issues);
|
|
1797
|
+
const before = issues.length;
|
|
1798
|
+
vec3(e.box.min, `${at}.min`, issues);
|
|
1799
|
+
vec3(e.box.max, `${at}.max`, issues);
|
|
1800
|
+
if (
|
|
1801
|
+
issues.length === before &&
|
|
1802
|
+
!(e.box.min as number[]).every((v, i) => v < (e.box as any).max[i])
|
|
1803
|
+
)
|
|
1804
|
+
issues.push(`${at}.min: below max on every axis`);
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1808
|
+
}
|
|
1809
|
+
if (look.sky !== undefined) colour(look.sky, `${path}.sky`, issues);
|
|
1810
|
+
if (look.ambient !== undefined) colour(look.ambient, `${path}.ambient`, issues);
|
|
1811
|
+
if (look.ambientGround !== undefined && look.ambientGround !== false)
|
|
1812
|
+
colour(look.ambientGround, `${path}.ambientGround`, issues);
|
|
1813
|
+
if (look.sun !== undefined) {
|
|
1814
|
+
const sun = look.sun;
|
|
1815
|
+
if (!object(sun)) return void issues.push(`${path}.sun: object required`);
|
|
1816
|
+
unknownKeys(sun, ['azimuthDeg', 'elevationDeg', 'intensity', 'color'], `${path}.sun`, issues);
|
|
1817
|
+
if (
|
|
1818
|
+
sun.azimuthDeg !== undefined &&
|
|
1819
|
+
!(finite(sun.azimuthDeg) && Math.abs(sun.azimuthDeg) <= 360)
|
|
1820
|
+
)
|
|
1821
|
+
issues.push(`${path}.sun.azimuthDeg: use -360..360`);
|
|
1822
|
+
if (
|
|
1823
|
+
sun.elevationDeg !== undefined &&
|
|
1824
|
+
!(finite(sun.elevationDeg) && sun.elevationDeg >= 0 && sun.elevationDeg <= 90)
|
|
1825
|
+
)
|
|
1826
|
+
issues.push(`${path}.sun.elevationDeg: use 0..90`);
|
|
1827
|
+
if (
|
|
1828
|
+
sun.intensity !== undefined &&
|
|
1829
|
+
!(finite(sun.intensity) && sun.intensity >= 0 && sun.intensity <= 8)
|
|
1830
|
+
)
|
|
1831
|
+
issues.push(`${path}.sun.intensity: use 0..8`);
|
|
1832
|
+
if (sun.color !== undefined) colour(sun.color, `${path}.sun.color`, issues);
|
|
1833
|
+
}
|
|
1834
|
+
}
|
|
1835
|
+
|
|
1836
|
+
function validateMaterial(
|
|
1837
|
+
material: unknown,
|
|
1838
|
+
path: string,
|
|
1839
|
+
issues: string[],
|
|
1840
|
+
context: ZhudaFilmValidationContext,
|
|
1841
|
+
) {
|
|
1842
|
+
if (!object(material)) return void issues.push(`${path}: material object required`);
|
|
1843
|
+
if (
|
|
1844
|
+
material.blend !== undefined &&
|
|
1845
|
+
!['opaque', 'cutout', 'alpha', 'additive'].includes(material.blend as string)
|
|
1846
|
+
)
|
|
1847
|
+
issues.push(`${path}.blend: use opaque, cutout, alpha or additive`);
|
|
1848
|
+
if (
|
|
1849
|
+
material.alphaCutoff !== undefined &&
|
|
1850
|
+
!(finite(material.alphaCutoff) && material.alphaCutoff >= 0 && material.alphaCutoff <= 1)
|
|
1851
|
+
)
|
|
1852
|
+
issues.push(`${path}.alphaCutoff: use 0..1`);
|
|
1853
|
+
if (material.doubleSided !== undefined && typeof material.doubleSided !== 'boolean')
|
|
1854
|
+
issues.push(`${path}.doubleSided: true or false`);
|
|
1855
|
+
if ('picture' in material) {
|
|
1856
|
+
unknownKeys(
|
|
1857
|
+
material,
|
|
1858
|
+
[
|
|
1859
|
+
'picture',
|
|
1860
|
+
'normal',
|
|
1861
|
+
'normalConvention',
|
|
1862
|
+
'normalStrength',
|
|
1863
|
+
'tileMeters',
|
|
1864
|
+
'roughness',
|
|
1865
|
+
'metallic',
|
|
1866
|
+
'tint',
|
|
1867
|
+
'blend',
|
|
1868
|
+
'alphaCutoff',
|
|
1869
|
+
'doubleSided',
|
|
1870
|
+
],
|
|
1871
|
+
path,
|
|
1872
|
+
issues,
|
|
1873
|
+
);
|
|
1874
|
+
for (const key of ['picture', 'normal'] as const) {
|
|
1875
|
+
const value = material[key];
|
|
1876
|
+
if (value === undefined && key === 'normal') continue;
|
|
1877
|
+
let id: string | undefined;
|
|
1878
|
+
try {
|
|
1879
|
+
id = normalizeAssetId(value as string);
|
|
1880
|
+
} catch {
|
|
1881
|
+
// Reported below.
|
|
1882
|
+
}
|
|
1883
|
+
if (id === undefined || id !== value || !/\.(png|jpe?g)$/i.test(id))
|
|
1884
|
+
issues.push(`${path}.${key}: use a logical asset id ending in .png or .jpg`);
|
|
1885
|
+
else if (context.assets && !context.assets.includes(id))
|
|
1886
|
+
issues.push(`${path}.${key}: unknown asset ${id}`);
|
|
1887
|
+
}
|
|
1888
|
+
if (
|
|
1889
|
+
!Array.isArray(material.tileMeters) ||
|
|
1890
|
+
material.tileMeters.length !== 2 ||
|
|
1891
|
+
!material.tileMeters.every((n) => finite(n) && n >= 0.01 && n <= 10000)
|
|
1892
|
+
)
|
|
1893
|
+
issues.push(`${path}.tileMeters: use [width, height] in metres, 0.01..10000`);
|
|
1894
|
+
if (
|
|
1895
|
+
material.normalConvention !== undefined &&
|
|
1896
|
+
!['opengl', 'directx'].includes(material.normalConvention as string)
|
|
1897
|
+
)
|
|
1898
|
+
issues.push(`${path}.normalConvention: use opengl or directx`);
|
|
1899
|
+
for (const [key, max] of [
|
|
1900
|
+
['normalStrength', 2],
|
|
1901
|
+
['roughness', 1],
|
|
1902
|
+
['metallic', 1],
|
|
1903
|
+
] as const) {
|
|
1904
|
+
const value = material[key];
|
|
1905
|
+
if (value !== undefined && !(finite(value) && value >= 0 && value <= max))
|
|
1906
|
+
issues.push(`${path}.${key}: use 0..${max}`);
|
|
1907
|
+
}
|
|
1908
|
+
if (
|
|
1909
|
+
material.tint !== undefined &&
|
|
1910
|
+
!(
|
|
1911
|
+
Array.isArray(material.tint) &&
|
|
1912
|
+
material.tint.length === 4 &&
|
|
1913
|
+
material.tint.every((n) => finite(n) && n >= 0 && n <= 4)
|
|
1914
|
+
)
|
|
1915
|
+
)
|
|
1916
|
+
issues.push(`${path}.tint: use four values between 0 and 4`);
|
|
1917
|
+
} else if ('recipe' in material) {
|
|
1918
|
+
unknownKeys(
|
|
1919
|
+
material,
|
|
1920
|
+
[
|
|
1921
|
+
'recipe',
|
|
1922
|
+
'tint',
|
|
1923
|
+
'size',
|
|
1924
|
+
'variation',
|
|
1925
|
+
'detail',
|
|
1926
|
+
'blend',
|
|
1927
|
+
'alphaCutoff',
|
|
1928
|
+
'doubleSided',
|
|
1929
|
+
'projection',
|
|
1930
|
+
'top',
|
|
1931
|
+
],
|
|
1932
|
+
path,
|
|
1933
|
+
issues,
|
|
1934
|
+
);
|
|
1935
|
+
if (
|
|
1936
|
+
material.projection !== undefined &&
|
|
1937
|
+
!['uv', 'triplanar'].includes(material.projection as string)
|
|
1938
|
+
)
|
|
1939
|
+
issues.push(`${path}.projection: use uv or triplanar`);
|
|
1940
|
+
const triplanar = material.projection === 'triplanar';
|
|
1941
|
+
if (triplanar)
|
|
1942
|
+
for (const key of ['variation', 'detail', 'blend', 'alphaCutoff', 'doubleSided'] as const)
|
|
1943
|
+
if (material[key] !== undefined)
|
|
1944
|
+
issues.push(`${path}.${key}: not with projection triplanar`);
|
|
1945
|
+
const top: unknown = material.top;
|
|
1946
|
+
if (top !== undefined) {
|
|
1947
|
+
if (!triplanar) issues.push(`${path}.top: needs projection triplanar`);
|
|
1948
|
+
if (!object(top)) issues.push(`${path}.top: object required`);
|
|
1949
|
+
else {
|
|
1950
|
+
unknownKeys(top, ['recipe', 'from', 'to', 'size'], `${path}.top`, issues);
|
|
1951
|
+
if (typeof top.recipe === 'string') {
|
|
1952
|
+
if (context.recipes && !context.recipes.includes(top.recipe))
|
|
1953
|
+
issues.push(
|
|
1954
|
+
`${path}.top.recipe: unknown recipe ${top.recipe}; known: ${context.recipes.join(', ')}`,
|
|
1955
|
+
);
|
|
1956
|
+
} else
|
|
1957
|
+
for (const issue of validateZhudaTextureRecipe(top.recipe))
|
|
1958
|
+
issues.push(`${path}.top.recipe${issue.startsWith('.') ? '' : ': '}${issue}`);
|
|
1959
|
+
const from = top.from ?? 0.55,
|
|
1960
|
+
to = top.to ?? 0.8;
|
|
1961
|
+
if (!(finite(from) && finite(to) && from >= 0 && to <= 1 && from < to))
|
|
1962
|
+
issues.push(`${path}.top: from and to are 0..1, from below to`);
|
|
1963
|
+
if (top.size !== undefined && ![128, 256, 512, 1024].includes(top.size as number))
|
|
1964
|
+
issues.push(`${path}.top.size: use 128, 256, 512 or 1024`);
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1967
|
+
const variation: unknown = material.variation;
|
|
1968
|
+
if (
|
|
1969
|
+
variation !== undefined &&
|
|
1970
|
+
!(typeof variation === 'number' && variation >= 0 && variation <= 1)
|
|
1971
|
+
)
|
|
1972
|
+
issues.push(`${path}.variation: use 0..1`);
|
|
1973
|
+
const detail: unknown = material.detail;
|
|
1974
|
+
if (detail !== undefined) {
|
|
1975
|
+
if (!object(detail)) issues.push(`${path}.detail: object required`);
|
|
1976
|
+
else {
|
|
1977
|
+
unknownKeys(
|
|
1978
|
+
detail,
|
|
1979
|
+
['recipe', 'meters', 'size', 'albedo', 'normal'],
|
|
1980
|
+
`${path}.detail`,
|
|
1981
|
+
issues,
|
|
1982
|
+
);
|
|
1983
|
+
if (typeof detail.recipe === 'string') {
|
|
1984
|
+
if (context.recipes && !context.recipes.includes(detail.recipe))
|
|
1985
|
+
issues.push(
|
|
1986
|
+
`${path}.detail.recipe: unknown recipe ${detail.recipe}; known: ${context.recipes.join(', ')}`,
|
|
1987
|
+
);
|
|
1988
|
+
} else
|
|
1989
|
+
for (const issue of validateZhudaTextureRecipe(detail.recipe))
|
|
1990
|
+
issues.push(`${path}.detail.recipe${issue.startsWith('.') ? '' : ': '}${issue}`);
|
|
1991
|
+
if (!(finite(detail.meters) && detail.meters >= 0.01 && detail.meters <= 1000))
|
|
1992
|
+
issues.push(`${path}.detail.meters: use 0.01..1000`);
|
|
1993
|
+
if (detail.size !== undefined && ![128, 256, 512, 1024].includes(detail.size as number))
|
|
1994
|
+
issues.push(`${path}.detail.size: use 128, 256, 512 or 1024`);
|
|
1995
|
+
if (
|
|
1996
|
+
detail.albedo !== undefined &&
|
|
1997
|
+
!(finite(detail.albedo) && detail.albedo >= 0 && detail.albedo <= 1)
|
|
1998
|
+
)
|
|
1999
|
+
issues.push(`${path}.detail.albedo: use 0..1`);
|
|
2000
|
+
if (
|
|
2001
|
+
detail.normal !== undefined &&
|
|
2002
|
+
!(finite(detail.normal) && detail.normal >= 0 && detail.normal <= 2)
|
|
2003
|
+
)
|
|
2004
|
+
issues.push(`${path}.detail.normal: use 0..2`);
|
|
2005
|
+
if (typeof variation === 'number' && variation > 0)
|
|
2006
|
+
issues.push(`${path}.detail: not with variation (they are the one detail map)`);
|
|
2007
|
+
}
|
|
2008
|
+
}
|
|
2009
|
+
if (typeof material.recipe === 'string') {
|
|
2010
|
+
if (context.recipes && !context.recipes.includes(material.recipe))
|
|
2011
|
+
issues.push(
|
|
2012
|
+
`${path}.recipe: unknown recipe ${material.recipe}; known: ${context.recipes.join(', ')}`,
|
|
2013
|
+
);
|
|
2014
|
+
} else
|
|
2015
|
+
for (const issue of validateZhudaTextureRecipe(material.recipe))
|
|
2016
|
+
issues.push(`${path}.recipe${issue.startsWith('.') ? '' : ': '}${issue}`);
|
|
2017
|
+
if (
|
|
2018
|
+
material.tint !== undefined &&
|
|
2019
|
+
!(
|
|
2020
|
+
Array.isArray(material.tint) &&
|
|
2021
|
+
material.tint.length === 4 &&
|
|
2022
|
+
material.tint.every((n) => finite(n) && n >= 0 && n <= 4)
|
|
2023
|
+
)
|
|
2024
|
+
)
|
|
2025
|
+
issues.push(`${path}.tint: use four values between 0 and 4`);
|
|
2026
|
+
if (
|
|
2027
|
+
material.size !== undefined &&
|
|
2028
|
+
![128, 256, 512, 1024, 2048].includes(material.size as number)
|
|
2029
|
+
)
|
|
2030
|
+
issues.push(`${path}.size: use 128, 256, 512, 1024 or 2048`);
|
|
2031
|
+
} else if ('color' in material) {
|
|
2032
|
+
unknownKeys(
|
|
2033
|
+
material,
|
|
2034
|
+
[
|
|
2035
|
+
'color',
|
|
2036
|
+
'roughness',
|
|
2037
|
+
'metallic',
|
|
2038
|
+
'emission',
|
|
2039
|
+
'clearCoat',
|
|
2040
|
+
'clearCoatRoughness',
|
|
2041
|
+
'anisotropy',
|
|
2042
|
+
'blend',
|
|
2043
|
+
'alphaCutoff',
|
|
2044
|
+
'doubleSided',
|
|
2045
|
+
'opacity',
|
|
2046
|
+
],
|
|
2047
|
+
path,
|
|
2048
|
+
issues,
|
|
2049
|
+
);
|
|
2050
|
+
if (
|
|
2051
|
+
material.opacity !== undefined &&
|
|
2052
|
+
!(finite(material.opacity) && material.opacity >= 0 && material.opacity <= 1)
|
|
2053
|
+
)
|
|
2054
|
+
issues.push(`${path}.opacity: use 0..1`);
|
|
2055
|
+
colour(material.color, `${path}.color`, issues);
|
|
2056
|
+
if (
|
|
2057
|
+
material.emission !== undefined &&
|
|
2058
|
+
!(
|
|
2059
|
+
Array.isArray(material.emission) &&
|
|
2060
|
+
material.emission.length === 3 &&
|
|
2061
|
+
material.emission.every((n) => finite(n) && n >= 0 && n <= 8)
|
|
2062
|
+
)
|
|
2063
|
+
)
|
|
2064
|
+
issues.push(`${path}.emission: use RGB with three values between 0 and 8`);
|
|
2065
|
+
for (const key of [
|
|
2066
|
+
'roughness',
|
|
2067
|
+
'metallic',
|
|
2068
|
+
'clearCoat',
|
|
2069
|
+
'clearCoatRoughness',
|
|
2070
|
+
'anisotropy',
|
|
2071
|
+
] as const)
|
|
2072
|
+
if (
|
|
2073
|
+
material[key] !== undefined &&
|
|
2074
|
+
!(finite(material[key]) && (material[key] as number) >= 0 && (material[key] as number) <= 1)
|
|
2075
|
+
)
|
|
2076
|
+
issues.push(`${path}.${key}: use 0..1`);
|
|
2077
|
+
} else issues.push(`${path}: use { recipe } or { color }`);
|
|
2078
|
+
}
|
|
2079
|
+
|
|
2080
|
+
function validateNode(
|
|
2081
|
+
node: unknown,
|
|
2082
|
+
path: string,
|
|
2083
|
+
issues: string[],
|
|
2084
|
+
context: ZhudaFilmValidationContext,
|
|
2085
|
+
materials: ReadonlySet<string>,
|
|
2086
|
+
/** The look's `lightFalloff` is `physical`: a light's intensity is its brightness at one metre. */
|
|
2087
|
+
lampsByTheSquare = false,
|
|
2088
|
+
) {
|
|
2089
|
+
if (!object(node)) return void issues.push(`${path}: node object required`);
|
|
2090
|
+
if (!isId(node.id))
|
|
2091
|
+
issues.push(`${path}.id: use lowercase letters, digits, dot, dash or underscore`);
|
|
2092
|
+
const yaw = () => {
|
|
2093
|
+
if (node.yawDeg !== undefined && !(finite(node.yawDeg) && Math.abs(node.yawDeg) <= 360))
|
|
2094
|
+
issues.push(`${path}.yawDeg: use -360..360`);
|
|
2095
|
+
};
|
|
2096
|
+
const usesMaterial = () => {
|
|
2097
|
+
if (
|
|
2098
|
+
typeof node.material !== 'string' ||
|
|
2099
|
+
!(materials.has(node.material) || context.recipes?.includes(node.material))
|
|
2100
|
+
)
|
|
2101
|
+
issues.push(`${path}.material: name a scene material or a known recipe`);
|
|
2102
|
+
};
|
|
2103
|
+
switch (node.type) {
|
|
2104
|
+
case 'prop':
|
|
2105
|
+
unknownKeys(
|
|
2106
|
+
node,
|
|
2107
|
+
[
|
|
2108
|
+
'id',
|
|
2109
|
+
'type',
|
|
2110
|
+
'prop',
|
|
2111
|
+
'position',
|
|
2112
|
+
'yawDeg',
|
|
2113
|
+
'seed',
|
|
2114
|
+
'params',
|
|
2115
|
+
'castShadow',
|
|
2116
|
+
'cullMeters',
|
|
2117
|
+
'lod',
|
|
2118
|
+
],
|
|
2119
|
+
path,
|
|
2120
|
+
issues,
|
|
2121
|
+
);
|
|
2122
|
+
if (typeof node.prop !== 'string' || !node.prop)
|
|
2123
|
+
issues.push(`${path}.prop: prop id required`);
|
|
2124
|
+
else if (context.props && !context.props.includes(node.prop))
|
|
2125
|
+
issues.push(`${path}.prop: unknown prop ${node.prop}; known: ${context.props.join(', ')}`);
|
|
2126
|
+
vec3(node.position, `${path}.position`, issues);
|
|
2127
|
+
yaw();
|
|
2128
|
+
if (
|
|
2129
|
+
node.seed !== undefined &&
|
|
2130
|
+
!(Number.isSafeInteger(node.seed) && (node.seed as number) >= 0)
|
|
2131
|
+
)
|
|
2132
|
+
issues.push(`${path}.seed: use a non-negative integer`);
|
|
2133
|
+
if (node.params !== undefined && !object(node.params))
|
|
2134
|
+
issues.push(`${path}.params: object required`);
|
|
2135
|
+
if (node.castShadow !== undefined && typeof node.castShadow !== 'boolean')
|
|
2136
|
+
issues.push(`${path}.castShadow: true or false`);
|
|
2137
|
+
{
|
|
2138
|
+
let last = 0;
|
|
2139
|
+
if (node.lod !== undefined) {
|
|
2140
|
+
if (!Array.isArray(node.lod) || !node.lod.length || node.lod.length > 4)
|
|
2141
|
+
issues.push(`${path}.lod: one to four levels`);
|
|
2142
|
+
else
|
|
2143
|
+
node.lod.forEach((level, i) => {
|
|
2144
|
+
if (!object(level)) return issues.push(`${path}.lod[${i}]: object required`);
|
|
2145
|
+
unknownKeys(level, ['fromMeters', 'params'], `${path}.lod[${i}]`, issues);
|
|
2146
|
+
if (
|
|
2147
|
+
!(finite(level.fromMeters) && level.fromMeters > last && level.fromMeters <= 100000)
|
|
2148
|
+
)
|
|
2149
|
+
issues.push(`${path}.lod[${i}].fromMeters: must rise and stay within 0..100000`);
|
|
2150
|
+
else last = level.fromMeters;
|
|
2151
|
+
if (!object(level.params)) issues.push(`${path}.lod[${i}].params: object required`);
|
|
2152
|
+
});
|
|
2153
|
+
}
|
|
2154
|
+
if (
|
|
2155
|
+
node.cullMeters !== undefined &&
|
|
2156
|
+
!(finite(node.cullMeters) && node.cullMeters > last && node.cullMeters <= 100000)
|
|
2157
|
+
)
|
|
2158
|
+
issues.push(`${path}.cullMeters: beyond the last level and at most 100000`);
|
|
2159
|
+
}
|
|
2160
|
+
break;
|
|
2161
|
+
case 'box':
|
|
2162
|
+
unknownKeys(
|
|
2163
|
+
node,
|
|
2164
|
+
['id', 'type', 'size', 'position', 'yawDeg', 'bevel', 'material'],
|
|
2165
|
+
path,
|
|
2166
|
+
issues,
|
|
2167
|
+
);
|
|
2168
|
+
vec3(node.size, `${path}.size`, issues, 1000);
|
|
2169
|
+
if (Array.isArray(node.size) && node.size.some((n) => !(n > 0)))
|
|
2170
|
+
issues.push(`${path}.size: every side must be positive`);
|
|
2171
|
+
vec3(node.position, `${path}.position`, issues);
|
|
2172
|
+
yaw();
|
|
2173
|
+
if (node.bevel !== undefined && !(finite(node.bevel) && node.bevel >= 0))
|
|
2174
|
+
issues.push(`${path}.bevel: use a non-negative number`);
|
|
2175
|
+
usesMaterial();
|
|
2176
|
+
break;
|
|
2177
|
+
case 'lathe':
|
|
2178
|
+
unknownKeys(
|
|
2179
|
+
node,
|
|
2180
|
+
['id', 'type', 'profile', 'segments', 'position', 'yawDeg', 'material'],
|
|
2181
|
+
path,
|
|
2182
|
+
issues,
|
|
2183
|
+
);
|
|
2184
|
+
for (const issue of validateZhudaLathe({
|
|
2185
|
+
profile: node.profile as [number, number][],
|
|
2186
|
+
segments: node.segments as number | undefined,
|
|
2187
|
+
}))
|
|
2188
|
+
issues.push(`${path}.${issue}`);
|
|
2189
|
+
vec3(node.position, `${path}.position`, issues);
|
|
2190
|
+
yaw();
|
|
2191
|
+
usesMaterial();
|
|
2192
|
+
break;
|
|
2193
|
+
case 'extrude':
|
|
2194
|
+
unknownKeys(
|
|
2195
|
+
node,
|
|
2196
|
+
['id', 'type', 'outline', 'height', 'position', 'yawDeg', 'material'],
|
|
2197
|
+
path,
|
|
2198
|
+
issues,
|
|
2199
|
+
);
|
|
2200
|
+
for (const issue of validateZhudaExtrude({
|
|
2201
|
+
outline: node.outline as [number, number][],
|
|
2202
|
+
height: node.height as number,
|
|
2203
|
+
}))
|
|
2204
|
+
issues.push(`${path}.${issue}`);
|
|
2205
|
+
vec3(node.position, `${path}.position`, issues);
|
|
2206
|
+
yaw();
|
|
2207
|
+
usesMaterial();
|
|
2208
|
+
break;
|
|
2209
|
+
case 'sweep':
|
|
2210
|
+
unknownKeys(
|
|
2211
|
+
node,
|
|
2212
|
+
['id', 'type', 'profile', 'path', 'closed', 'position', 'yawDeg', 'material'],
|
|
2213
|
+
path,
|
|
2214
|
+
issues,
|
|
2215
|
+
);
|
|
2216
|
+
for (const issue of validateZhudaSweep({
|
|
2217
|
+
profile: node.profile as [number, number][],
|
|
2218
|
+
path: node.path as [number, number, number][],
|
|
2219
|
+
closed: node.closed as boolean | undefined,
|
|
2220
|
+
}))
|
|
2221
|
+
issues.push(`${path}.${issue}`);
|
|
2222
|
+
vec3(node.position, `${path}.position`, issues);
|
|
2223
|
+
yaw();
|
|
2224
|
+
usesMaterial();
|
|
2225
|
+
break;
|
|
2226
|
+
case 'decal': {
|
|
2227
|
+
const { id: _id, type: _type, ...decal } = node;
|
|
2228
|
+
for (const issue of validateZhudaDecal(decal as any)) issues.push(`${path}.${issue}`);
|
|
2229
|
+
break;
|
|
2230
|
+
}
|
|
2231
|
+
case 'ground':
|
|
2232
|
+
unknownKeys(node, ['id', 'type', 'size', 'material', 'y'], path, issues);
|
|
2233
|
+
if (node.y !== undefined && !(finite(node.y) && Math.abs(node.y) <= ZHUDA_FILM_LIMITS.extent))
|
|
2234
|
+
issues.push(`${path}.y: use a height in metres`);
|
|
2235
|
+
if (
|
|
2236
|
+
!Array.isArray(node.size) ||
|
|
2237
|
+
node.size.length !== 2 ||
|
|
2238
|
+
!node.size.every((n) => finite(n) && n > 0 && n <= ZHUDA_FILM_LIMITS.extent)
|
|
2239
|
+
)
|
|
2240
|
+
issues.push(`${path}.size: use [width, depth] in metres`);
|
|
2241
|
+
usesMaterial();
|
|
2242
|
+
break;
|
|
2243
|
+
case 'effect': {
|
|
2244
|
+
unknownKeys(
|
|
2245
|
+
node,
|
|
2246
|
+
['id', 'type', 'preset', 'position', 'yawDeg', 'scale', 'startSec', 'seed'],
|
|
2247
|
+
path,
|
|
2248
|
+
issues,
|
|
2249
|
+
);
|
|
2250
|
+
if (typeof node.preset !== 'string' || !(node.preset in ZHUDA_EFFECT_PRESETS_3D))
|
|
2251
|
+
issues.push(
|
|
2252
|
+
`${path}.preset: unknown effect ${String(node.preset)}; known: ${ZHUDA_EFFECT_PRESET_IDS_3D.join(', ')}`,
|
|
2253
|
+
);
|
|
2254
|
+
vec3(node.position, `${path}.position`, issues);
|
|
2255
|
+
yaw();
|
|
2256
|
+
if (
|
|
2257
|
+
node.scale !== undefined &&
|
|
2258
|
+
!(finite(node.scale) && node.scale >= 0.05 && node.scale <= 50)
|
|
2259
|
+
)
|
|
2260
|
+
issues.push(`${path}.scale: use 0.05..50`);
|
|
2261
|
+
if (
|
|
2262
|
+
node.startSec !== undefined &&
|
|
2263
|
+
!(finite(node.startSec) && node.startSec >= 0 && node.startSec <= 36000)
|
|
2264
|
+
)
|
|
2265
|
+
issues.push(`${path}.startSec: seconds of shot time from 0`);
|
|
2266
|
+
if (node.seed !== undefined && !(Number.isInteger(node.seed) && (node.seed as number) >= 0))
|
|
2267
|
+
issues.push(`${path}.seed: a whole number from 0`);
|
|
2268
|
+
break;
|
|
2269
|
+
}
|
|
2270
|
+
case 'terrain': {
|
|
2271
|
+
unknownKeys(
|
|
2272
|
+
node,
|
|
2273
|
+
['id', 'type', 'position', 'size', 'cells', 'heights', 'noise', 'material'],
|
|
2274
|
+
path,
|
|
2275
|
+
issues,
|
|
2276
|
+
);
|
|
2277
|
+
vec3(node.position, `${path}.position`, issues);
|
|
2278
|
+
for (const issue of validateZhudaTerrainMesh({
|
|
2279
|
+
size: node.size,
|
|
2280
|
+
cells: node.cells,
|
|
2281
|
+
heights: node.heights,
|
|
2282
|
+
noise: node.noise,
|
|
2283
|
+
} as ZhudaTerrainMeshOptions))
|
|
2284
|
+
issues.push(`${path}.${issue}`);
|
|
2285
|
+
usesMaterial();
|
|
2286
|
+
break;
|
|
2287
|
+
}
|
|
2288
|
+
case 'grass': {
|
|
2289
|
+
const own = ['id', 'type', 'y', 'on', 'clear', 'avoidSolids'];
|
|
2290
|
+
const passed = [
|
|
2291
|
+
'area',
|
|
2292
|
+
'density',
|
|
2293
|
+
'heightM',
|
|
2294
|
+
'widthM',
|
|
2295
|
+
'distanceM',
|
|
2296
|
+
'tip',
|
|
2297
|
+
'root',
|
|
2298
|
+
'dry',
|
|
2299
|
+
'dryness',
|
|
2300
|
+
'wind',
|
|
2301
|
+
'seed',
|
|
2302
|
+
'turf',
|
|
2303
|
+
];
|
|
2304
|
+
unknownKeys(node, [...own, ...passed], path, issues);
|
|
2305
|
+
const options: Record<string, unknown> = { ground: () => 0 };
|
|
2306
|
+
for (const key of passed) if (node[key] !== undefined) options[key] = node[key];
|
|
2307
|
+
for (const issue of validateZhudaGrass(options as never))
|
|
2308
|
+
issues.push(`${path}.${issue.replace(/^grass\./, '')}`);
|
|
2309
|
+
if (node.y !== undefined && !(finite(node.y) && Math.abs(node.y) <= ZHUDA_FILM_LIMITS.extent))
|
|
2310
|
+
issues.push(`${path}.y: a height in metres`);
|
|
2311
|
+
if (node.on !== undefined) {
|
|
2312
|
+
if (typeof node.on !== 'string') issues.push(`${path}.on: the id of a terrain node`);
|
|
2313
|
+
if (node.y !== undefined)
|
|
2314
|
+
issues.push(`${path}.y: not with on (the terrain gives the height)`);
|
|
2315
|
+
}
|
|
2316
|
+
if (node.avoidSolids !== undefined && typeof node.avoidSolids !== 'boolean')
|
|
2317
|
+
issues.push(`${path}.avoidSolids: true or false`);
|
|
2318
|
+
if (node.clear !== undefined) {
|
|
2319
|
+
const ok = (r: unknown) =>
|
|
2320
|
+
object(r) &&
|
|
2321
|
+
['minX', 'maxX', 'minZ', 'maxZ'].every((k) => finite(r[k])) &&
|
|
2322
|
+
(r.maxX as number) > (r.minX as number) &&
|
|
2323
|
+
(r.maxZ as number) > (r.minZ as number);
|
|
2324
|
+
if (!Array.isArray(node.clear) || node.clear.length > 32 || !node.clear.every(ok))
|
|
2325
|
+
issues.push(`${path}.clear: up to 32 rectangles, each minX < maxX and minZ < maxZ`);
|
|
2326
|
+
}
|
|
2327
|
+
break;
|
|
2328
|
+
}
|
|
2329
|
+
case 'model': {
|
|
2330
|
+
unknownKeys(
|
|
2331
|
+
node,
|
|
2332
|
+
[
|
|
2333
|
+
'id',
|
|
2334
|
+
'type',
|
|
2335
|
+
'asset',
|
|
2336
|
+
'position',
|
|
2337
|
+
'yawDeg',
|
|
2338
|
+
'scale',
|
|
2339
|
+
'lightmap',
|
|
2340
|
+
'lightmapIntensity',
|
|
2341
|
+
'lightmapDirection',
|
|
2342
|
+
'animation',
|
|
2343
|
+
'motion',
|
|
2344
|
+
'placements',
|
|
2345
|
+
'instanced',
|
|
2346
|
+
'cellMeters',
|
|
2347
|
+
'castShadow',
|
|
2348
|
+
'cullMeters',
|
|
2349
|
+
'translucent',
|
|
2350
|
+
'emission',
|
|
2351
|
+
],
|
|
2352
|
+
path,
|
|
2353
|
+
issues,
|
|
2354
|
+
);
|
|
2355
|
+
const asset = (key: 'asset' | 'lightmap' | 'lightmapDirection', extension: string) => {
|
|
2356
|
+
const value = node[key];
|
|
2357
|
+
let id: string | undefined;
|
|
2358
|
+
try {
|
|
2359
|
+
id = normalizeAssetId(value as string);
|
|
2360
|
+
} catch {
|
|
2361
|
+
// Reported below.
|
|
2362
|
+
}
|
|
2363
|
+
if (id === undefined || id !== value || !id.toLowerCase().endsWith(extension))
|
|
2364
|
+
issues.push(`${path}.${key}: use a logical asset id ending in ${extension}`);
|
|
2365
|
+
else if (context.assets && !context.assets.includes(id))
|
|
2366
|
+
issues.push(
|
|
2367
|
+
`${path}.${key}: unknown asset ${id}; known: ${
|
|
2368
|
+
context.assets.filter((name) => name.toLowerCase().endsWith(extension)).join(', ') ||
|
|
2369
|
+
'none'
|
|
2370
|
+
}`,
|
|
2371
|
+
);
|
|
2372
|
+
};
|
|
2373
|
+
asset('asset', '.glb');
|
|
2374
|
+
if (node.lightmap !== undefined) asset('lightmap', '.hdr');
|
|
2375
|
+
if (node.lightmapDirection !== undefined) {
|
|
2376
|
+
asset('lightmapDirection', '.hdr');
|
|
2377
|
+
if (node.lightmap === undefined) issues.push(`${path}.lightmapDirection: needs a lightmap`);
|
|
2378
|
+
if (node.yawDeg !== undefined && node.yawDeg !== 0)
|
|
2379
|
+
issues.push(`${path}.lightmapDirection: directions are in world space; keep yawDeg 0`);
|
|
2380
|
+
}
|
|
2381
|
+
vec3(node.position, `${path}.position`, issues);
|
|
2382
|
+
yaw();
|
|
2383
|
+
if (
|
|
2384
|
+
node.scale !== undefined &&
|
|
2385
|
+
!(finite(node.scale) && node.scale >= 0.001 && node.scale <= 1000)
|
|
2386
|
+
)
|
|
2387
|
+
issues.push(`${path}.scale: use 0.001..1000`);
|
|
2388
|
+
if (
|
|
2389
|
+
node.emission !== undefined &&
|
|
2390
|
+
!(finite(node.emission) && node.emission >= 0 && node.emission <= 8)
|
|
2391
|
+
)
|
|
2392
|
+
issues.push(`${path}.emission: use 0..8`);
|
|
2393
|
+
if (node.translucent !== undefined && typeof node.translucent !== 'boolean')
|
|
2394
|
+
issues.push(`${path}.translucent: true or false`);
|
|
2395
|
+
if (node.placements !== undefined) {
|
|
2396
|
+
const list = node.placements;
|
|
2397
|
+
if (!Array.isArray(list) || !list.length || list.length > ZHUDA_FILM_LIMITS.placements)
|
|
2398
|
+
issues.push(`${path}.placements: 1..${ZHUDA_FILM_LIMITS.placements} places required`);
|
|
2399
|
+
else {
|
|
2400
|
+
const bad = list.findIndex(
|
|
2401
|
+
(place) =>
|
|
2402
|
+
!Array.isArray(place) ||
|
|
2403
|
+
place.length !== 5 ||
|
|
2404
|
+
!place.every(finite) ||
|
|
2405
|
+
place.slice(0, 3).some((v) => Math.abs(v as number) > ZHUDA_FILM_LIMITS.extent) ||
|
|
2406
|
+
!((place[4] as number) >= 0.001 && (place[4] as number) <= 1000),
|
|
2407
|
+
);
|
|
2408
|
+
if (bad >= 0)
|
|
2409
|
+
issues.push(
|
|
2410
|
+
`${path}.placements[${bad}]: use [x, y, z, yawDeg, scale] with scale 0.001..1000`,
|
|
2411
|
+
);
|
|
2412
|
+
}
|
|
2413
|
+
for (const key of ['lightmap', 'lightmapDirection', 'animation', 'motion'] as const)
|
|
2414
|
+
if (node[key] !== undefined) issues.push(`${path}.placements: not with ${key}`);
|
|
2415
|
+
}
|
|
2416
|
+
if (node.instanced !== undefined) {
|
|
2417
|
+
if (typeof node.instanced !== 'boolean') issues.push(`${path}.instanced: true or false`);
|
|
2418
|
+
else if (node.instanced && node.placements === undefined)
|
|
2419
|
+
issues.push(`${path}.instanced: needs placements`);
|
|
2420
|
+
}
|
|
2421
|
+
if (node.cellMeters !== undefined) {
|
|
2422
|
+
if (!(finite(node.cellMeters) && node.cellMeters >= 0.5 && node.cellMeters <= 100000))
|
|
2423
|
+
issues.push(`${path}.cellMeters: use 0.5..100000`);
|
|
2424
|
+
else if (node.instanced !== true) issues.push(`${path}.cellMeters: needs instanced`);
|
|
2425
|
+
}
|
|
2426
|
+
if (node.castShadow !== undefined && typeof node.castShadow !== 'boolean')
|
|
2427
|
+
issues.push(`${path}.castShadow: true or false`);
|
|
2428
|
+
if (node.cullMeters !== undefined) {
|
|
2429
|
+
if (!(finite(node.cullMeters) && node.cullMeters > 0 && node.cullMeters <= 100000))
|
|
2430
|
+
issues.push(`${path}.cullMeters: use a distance above 0, at most 100000`);
|
|
2431
|
+
// A lightmapped renderer keeps its place in the scene's lightmap list.
|
|
2432
|
+
if (node.lightmap !== undefined) issues.push(`${path}.cullMeters: not with lightmap`);
|
|
2433
|
+
}
|
|
2434
|
+
if (node.animation !== undefined) {
|
|
2435
|
+
const a = node.animation;
|
|
2436
|
+
if (!object(a)) issues.push(`${path}.animation: object required`);
|
|
2437
|
+
else {
|
|
2438
|
+
unknownKeys(a, ['clip', 'loop', 'speed', 'offsetSec'], `${path}.animation`, issues);
|
|
2439
|
+
if (typeof a.clip !== 'string' || !a.clip || a.clip.length > 128)
|
|
2440
|
+
issues.push(`${path}.animation.clip: clip name required`);
|
|
2441
|
+
if (a.loop !== undefined && typeof a.loop !== 'boolean')
|
|
2442
|
+
issues.push(`${path}.animation.loop: true or false`);
|
|
2443
|
+
if (a.speed !== undefined && !(finite(a.speed) && a.speed >= 0 && a.speed <= 8))
|
|
2444
|
+
issues.push(`${path}.animation.speed: use 0..8`);
|
|
2445
|
+
if (
|
|
2446
|
+
a.offsetSec !== undefined &&
|
|
2447
|
+
!(finite(a.offsetSec) && a.offsetSec >= 0 && a.offsetSec <= 3600)
|
|
2448
|
+
)
|
|
2449
|
+
issues.push(`${path}.animation.offsetSec: use 0..3600`);
|
|
2450
|
+
}
|
|
2451
|
+
}
|
|
2452
|
+
if (node.motion !== undefined) {
|
|
2453
|
+
const keys = node.motion;
|
|
2454
|
+
if (!Array.isArray(keys) || keys.length < 2 || keys.length > 256)
|
|
2455
|
+
issues.push(`${path}.motion: use 2..256 keys`);
|
|
2456
|
+
else {
|
|
2457
|
+
keys.forEach((key, i) => {
|
|
2458
|
+
const at = `${path}.motion[${i}]`;
|
|
2459
|
+
if (!object(key)) return void issues.push(`${at}: key object required`);
|
|
2460
|
+
unknownKeys(key, ['time', 'position', 'yawDeg'], at, issues);
|
|
2461
|
+
const before = i ? (keys[i - 1] as { time?: unknown })?.time : undefined;
|
|
2462
|
+
if (
|
|
2463
|
+
!finite(key.time) ||
|
|
2464
|
+
(i === 0 ? key.time !== 0 : !(finite(before) && key.time > before)) ||
|
|
2465
|
+
key.time > 3600
|
|
2466
|
+
)
|
|
2467
|
+
issues.push(`${at}.time: start at 0 and increase (seconds, at most 3600)`);
|
|
2468
|
+
vec3(key.position, `${at}.position`, issues);
|
|
2469
|
+
if (key.yawDeg !== undefined && !(finite(key.yawDeg) && Math.abs(key.yawDeg) <= 3600))
|
|
2470
|
+
issues.push(`${at}.yawDeg: use -3600..3600`);
|
|
2471
|
+
});
|
|
2472
|
+
if (node.lightmap !== undefined)
|
|
2473
|
+
issues.push(`${path}.motion: a lightmapped model cannot move`);
|
|
2474
|
+
}
|
|
2475
|
+
}
|
|
2476
|
+
if (
|
|
2477
|
+
node.lightmapIntensity !== undefined &&
|
|
2478
|
+
!(
|
|
2479
|
+
node.lightmap !== undefined &&
|
|
2480
|
+
finite(node.lightmapIntensity) &&
|
|
2481
|
+
node.lightmapIntensity >= 0 &&
|
|
2482
|
+
node.lightmapIntensity <= 16
|
|
2483
|
+
)
|
|
2484
|
+
)
|
|
2485
|
+
issues.push(`${path}.lightmapIntensity: needs a lightmap, 0..16`);
|
|
2486
|
+
break;
|
|
2487
|
+
}
|
|
2488
|
+
case 'reflector': {
|
|
2489
|
+
unknownKeys(
|
|
2490
|
+
node,
|
|
2491
|
+
[
|
|
2492
|
+
'id',
|
|
2493
|
+
'type',
|
|
2494
|
+
'position',
|
|
2495
|
+
'size',
|
|
2496
|
+
'strength',
|
|
2497
|
+
'wetness',
|
|
2498
|
+
'roughness',
|
|
2499
|
+
'ripple',
|
|
2500
|
+
'patternMeters',
|
|
2501
|
+
'resolution',
|
|
2502
|
+
'hides',
|
|
2503
|
+
],
|
|
2504
|
+
path,
|
|
2505
|
+
issues,
|
|
2506
|
+
);
|
|
2507
|
+
vec3(node.position, `${path}.position`, issues);
|
|
2508
|
+
if (
|
|
2509
|
+
!Array.isArray(node.size) ||
|
|
2510
|
+
node.size.length !== 2 ||
|
|
2511
|
+
!node.size.every((n) => finite(n) && n >= 0.1 && n <= 4000)
|
|
2512
|
+
)
|
|
2513
|
+
issues.push(`${path}.size: use [width, depth] between 0.1 and 4000 metres`);
|
|
2514
|
+
const ranges: [string, number, number][] = [
|
|
2515
|
+
['strength', 0, 4],
|
|
2516
|
+
['wetness', 0, 1],
|
|
2517
|
+
['roughness', 0, 1],
|
|
2518
|
+
['ripple', 0, 1],
|
|
2519
|
+
['patternMeters', 0.1, 100],
|
|
2520
|
+
];
|
|
2521
|
+
for (const [key, min, max] of ranges) {
|
|
2522
|
+
const value = node[key];
|
|
2523
|
+
if (value !== undefined && !(finite(value) && value >= min && value <= max))
|
|
2524
|
+
issues.push(`${path}.${key}: use ${min}..${max}`);
|
|
2525
|
+
}
|
|
2526
|
+
if (
|
|
2527
|
+
node.resolution !== undefined &&
|
|
2528
|
+
![256, 512, 1024, 2048].includes(node.resolution as number)
|
|
2529
|
+
)
|
|
2530
|
+
issues.push(`${path}.resolution: use 256, 512, 1024 or 2048`);
|
|
2531
|
+
if (
|
|
2532
|
+
node.hides !== undefined &&
|
|
2533
|
+
!(Array.isArray(node.hides) && node.hides.every((id) => typeof id === 'string'))
|
|
2534
|
+
)
|
|
2535
|
+
issues.push(`${path}.hides: list model node ids`);
|
|
2536
|
+
break;
|
|
2537
|
+
}
|
|
2538
|
+
case 'water': {
|
|
2539
|
+
unknownKeys(
|
|
2540
|
+
node,
|
|
2541
|
+
[
|
|
2542
|
+
'id',
|
|
2543
|
+
'type',
|
|
2544
|
+
'position',
|
|
2545
|
+
'size',
|
|
2546
|
+
'flow',
|
|
2547
|
+
'color',
|
|
2548
|
+
'clarity',
|
|
2549
|
+
'waveMeters',
|
|
2550
|
+
'waves',
|
|
2551
|
+
'refraction',
|
|
2552
|
+
'reflection',
|
|
2553
|
+
'glow',
|
|
2554
|
+
'foamDepth',
|
|
2555
|
+
'resolution',
|
|
2556
|
+
'hides',
|
|
2557
|
+
'ripples',
|
|
2558
|
+
],
|
|
2559
|
+
path,
|
|
2560
|
+
issues,
|
|
2561
|
+
);
|
|
2562
|
+
vec3(node.position, `${path}.position`, issues);
|
|
2563
|
+
if (
|
|
2564
|
+
!Array.isArray(node.size) ||
|
|
2565
|
+
node.size.length !== 2 ||
|
|
2566
|
+
!node.size.every((n) => finite(n) && n >= 0.1 && n <= 4000)
|
|
2567
|
+
)
|
|
2568
|
+
issues.push(`${path}.size: use [width, depth] between 0.1 and 4000 metres`);
|
|
2569
|
+
if (
|
|
2570
|
+
node.flow !== undefined &&
|
|
2571
|
+
!(
|
|
2572
|
+
Array.isArray(node.flow) &&
|
|
2573
|
+
node.flow.length === 2 &&
|
|
2574
|
+
node.flow.every((n) => finite(n) && Math.abs(n) <= 20)
|
|
2575
|
+
)
|
|
2576
|
+
)
|
|
2577
|
+
issues.push(`${path}.flow: use [x, z] in metres per second, -20..20`);
|
|
2578
|
+
if (node.color !== undefined) colour(node.color, `${path}.color`, issues);
|
|
2579
|
+
const ranges: [string, number, number][] = [
|
|
2580
|
+
['clarity', 0.05, 100],
|
|
2581
|
+
['waveMeters', 0.05, 50],
|
|
2582
|
+
['waves', 0, 1],
|
|
2583
|
+
['refraction', 0, 1],
|
|
2584
|
+
['reflection', 0, 4],
|
|
2585
|
+
['glow', 0, 4],
|
|
2586
|
+
['foamDepth', 0, 2],
|
|
2587
|
+
];
|
|
2588
|
+
for (const [key, min, max] of ranges) {
|
|
2589
|
+
const value = node[key];
|
|
2590
|
+
if (value !== undefined && !(finite(value) && value >= min && value <= max))
|
|
2591
|
+
issues.push(`${path}.${key}: use ${min}..${max}`);
|
|
2592
|
+
}
|
|
2593
|
+
if (
|
|
2594
|
+
node.resolution !== undefined &&
|
|
2595
|
+
![256, 512, 1024, 2048].includes(node.resolution as number)
|
|
2596
|
+
)
|
|
2597
|
+
issues.push(`${path}.resolution: use 256, 512, 1024 or 2048`);
|
|
2598
|
+
if (
|
|
2599
|
+
node.hides !== undefined &&
|
|
2600
|
+
!(Array.isArray(node.hides) && node.hides.every((id) => typeof id === 'string'))
|
|
2601
|
+
)
|
|
2602
|
+
issues.push(`${path}.hides: list model node ids`);
|
|
2603
|
+
if (node.ripples !== undefined) {
|
|
2604
|
+
if (!Array.isArray(node.ripples)) issues.push(`${path}.ripples: use a list of bodies`);
|
|
2605
|
+
else {
|
|
2606
|
+
node.ripples.forEach((ripple, i) => {
|
|
2607
|
+
if (!object(ripple)) return;
|
|
2608
|
+
unknownKeys(
|
|
2609
|
+
ripple,
|
|
2610
|
+
['position', 'radius', 'strength', 'velocity'],
|
|
2611
|
+
`${path}.ripples[${i}]`,
|
|
2612
|
+
issues,
|
|
2613
|
+
);
|
|
2614
|
+
if (!(Array.isArray(ripple.position) && ripple.position.length === 2))
|
|
2615
|
+
issues.push(`${path}.ripples[${i}].position: use [x, z] in metres`);
|
|
2616
|
+
});
|
|
2617
|
+
issues.push(
|
|
2618
|
+
...validateZhudaWaterRipples(
|
|
2619
|
+
node.ripples.map((ripple) => {
|
|
2620
|
+
const r = (object(ripple) ? ripple : {}) as Record<string, unknown>;
|
|
2621
|
+
const [x, z] = Array.isArray(r.position)
|
|
2622
|
+
? (r.position as number[])
|
|
2623
|
+
: [Number.NaN, Number.NaN];
|
|
2624
|
+
return {
|
|
2625
|
+
x,
|
|
2626
|
+
z,
|
|
2627
|
+
radius: r.radius as number,
|
|
2628
|
+
strength: r.strength as number,
|
|
2629
|
+
velocity: r.velocity as [number, number] | undefined,
|
|
2630
|
+
};
|
|
2631
|
+
}),
|
|
2632
|
+
`${path}.ripples`,
|
|
2633
|
+
),
|
|
2634
|
+
);
|
|
2635
|
+
}
|
|
2636
|
+
}
|
|
2637
|
+
break;
|
|
2638
|
+
}
|
|
2639
|
+
case 'light':
|
|
2640
|
+
unknownKeys(
|
|
2641
|
+
node,
|
|
2642
|
+
[
|
|
2643
|
+
'id',
|
|
2644
|
+
'type',
|
|
2645
|
+
'kind',
|
|
2646
|
+
'position',
|
|
2647
|
+
'color',
|
|
2648
|
+
'intensity',
|
|
2649
|
+
'range',
|
|
2650
|
+
'target',
|
|
2651
|
+
'spotAngleDeg',
|
|
2652
|
+
'penumbra',
|
|
2653
|
+
'fogOnly',
|
|
2654
|
+
'follows',
|
|
2655
|
+
'castsShadow',
|
|
2656
|
+
],
|
|
2657
|
+
path,
|
|
2658
|
+
issues,
|
|
2659
|
+
);
|
|
2660
|
+
if (node.kind !== 'point' && node.kind !== 'spot')
|
|
2661
|
+
issues.push(`${path}.kind: use point or spot`);
|
|
2662
|
+
vec3(node.position, `${path}.position`, issues);
|
|
2663
|
+
if (node.follows !== undefined) {
|
|
2664
|
+
const f = node.follows;
|
|
2665
|
+
if (!object(f) || typeof f.node !== 'string')
|
|
2666
|
+
issues.push(`${path}.follows: use { node, offset }`);
|
|
2667
|
+
else {
|
|
2668
|
+
unknownKeys(f, ['node', 'offset'], `${path}.follows`, issues);
|
|
2669
|
+
if (f.offset !== undefined) vec3(f.offset, `${path}.follows.offset`, issues, 1000);
|
|
2670
|
+
if (node.kind !== 'point') issues.push(`${path}.follows: point lights only`);
|
|
2671
|
+
}
|
|
2672
|
+
}
|
|
2673
|
+
if (node.color !== undefined) colour(node.color, `${path}.color`, issues);
|
|
2674
|
+
{
|
|
2675
|
+
// By the square of the distance a lamp's number is its brightness at one metre.
|
|
2676
|
+
const most = lampsByTheSquare ? 2000 : 20;
|
|
2677
|
+
if (
|
|
2678
|
+
node.intensity !== undefined &&
|
|
2679
|
+
!(finite(node.intensity) && node.intensity >= 0 && node.intensity <= most)
|
|
2680
|
+
)
|
|
2681
|
+
issues.push(`${path}.intensity: use 0..${most}`);
|
|
2682
|
+
}
|
|
2683
|
+
if (
|
|
2684
|
+
node.penumbra !== undefined &&
|
|
2685
|
+
!(node.kind === 'spot' && finite(node.penumbra) && node.penumbra >= 0 && node.penumbra <= 1)
|
|
2686
|
+
)
|
|
2687
|
+
issues.push(`${path}.penumbra: spot lights only, 0..1`);
|
|
2688
|
+
if (
|
|
2689
|
+
node.range !== undefined &&
|
|
2690
|
+
!(finite(node.range) && node.range >= 0.1 && node.range <= 200)
|
|
2691
|
+
)
|
|
2692
|
+
issues.push(`${path}.range: use 0.1..200 metres`);
|
|
2693
|
+
if (node.kind === 'spot') {
|
|
2694
|
+
vec3(node.target, `${path}.target`, issues);
|
|
2695
|
+
if (
|
|
2696
|
+
Array.isArray(node.target) &&
|
|
2697
|
+
Array.isArray(node.position) &&
|
|
2698
|
+
node.target.every((v, i) => v === (node.position as number[])[i])
|
|
2699
|
+
)
|
|
2700
|
+
issues.push(`${path}.target: must differ from position`);
|
|
2701
|
+
} else if (node.target !== undefined) issues.push(`${path}.target: only spot lights aim`);
|
|
2702
|
+
if (
|
|
2703
|
+
node.spotAngleDeg !== undefined &&
|
|
2704
|
+
!(
|
|
2705
|
+
node.kind === 'spot' &&
|
|
2706
|
+
finite(node.spotAngleDeg) &&
|
|
2707
|
+
node.spotAngleDeg >= 1 &&
|
|
2708
|
+
node.spotAngleDeg <= 179
|
|
2709
|
+
)
|
|
2710
|
+
)
|
|
2711
|
+
issues.push(`${path}.spotAngleDeg: spot lights only, 1..179`);
|
|
2712
|
+
if (
|
|
2713
|
+
node.fogOnly !== undefined &&
|
|
2714
|
+
!(typeof node.fogOnly === 'boolean' && node.kind === 'point')
|
|
2715
|
+
)
|
|
2716
|
+
issues.push(`${path}.fogOnly: point lights only, true or false`);
|
|
2717
|
+
if (node.castsShadow !== undefined && typeof node.castsShadow !== 'boolean')
|
|
2718
|
+
issues.push(`${path}.castsShadow: true or false`);
|
|
2719
|
+
else if (node.castsShadow && node.kind === 'point' && node.fogOnly === true)
|
|
2720
|
+
issues.push(
|
|
2721
|
+
`${path}.castsShadow: not on a point light that is fogOnly (it lights no surface)`,
|
|
2722
|
+
);
|
|
2723
|
+
break;
|
|
2724
|
+
default:
|
|
2725
|
+
issues.push(
|
|
2726
|
+
`${path}.type: use prop, box, lathe, extrude, sweep, decal, ground, model, reflector, water or light`,
|
|
2727
|
+
);
|
|
2728
|
+
}
|
|
2729
|
+
}
|
|
2730
|
+
|
|
2731
|
+
/** Lists every problem with a path; an empty list means the scene is valid. */
|
|
2732
|
+
export function validateZhudaFilmScene(
|
|
2733
|
+
scene: unknown,
|
|
2734
|
+
context: ZhudaFilmValidationContext = {},
|
|
2735
|
+
): string[] {
|
|
2736
|
+
const issues: string[] = [];
|
|
2737
|
+
if (!object(scene)) return ['scene: object required'];
|
|
2738
|
+
unknownKeys(
|
|
2739
|
+
scene,
|
|
2740
|
+
['schemaVersion', 'id', 'camera', 'look', 'materials', 'nodes'],
|
|
2741
|
+
'scene',
|
|
2742
|
+
issues,
|
|
2743
|
+
);
|
|
2744
|
+
if (scene.schemaVersion !== 1) issues.push('scene.schemaVersion: must be 1');
|
|
2745
|
+
if (!isId(scene.id))
|
|
2746
|
+
issues.push('scene.id: use lowercase letters, digits, dot, dash or underscore');
|
|
2747
|
+
validateCamera(scene.camera, 'scene.camera', issues);
|
|
2748
|
+
if (scene.look !== undefined) validateLook(scene.look, 'scene.look', issues, context);
|
|
2749
|
+
const materials = new Set<string>();
|
|
2750
|
+
if (scene.materials !== undefined) {
|
|
2751
|
+
if (!object(scene.materials)) issues.push('scene.materials: object required');
|
|
2752
|
+
else {
|
|
2753
|
+
const entries = Object.entries(scene.materials);
|
|
2754
|
+
if (entries.length > ZHUDA_FILM_LIMITS.materials)
|
|
2755
|
+
issues.push(`scene.materials: at most ${ZHUDA_FILM_LIMITS.materials}`);
|
|
2756
|
+
for (const [name, material] of entries) {
|
|
2757
|
+
if (!isId(name)) issues.push(`scene.materials.${name}: invalid material name`);
|
|
2758
|
+
materials.add(name);
|
|
2759
|
+
validateMaterial(material, `scene.materials.${name}`, issues, context);
|
|
2760
|
+
}
|
|
2761
|
+
}
|
|
2762
|
+
}
|
|
2763
|
+
if (!Array.isArray(scene.nodes)) issues.push('scene.nodes: array required');
|
|
2764
|
+
else {
|
|
2765
|
+
if (scene.nodes.length > ZHUDA_FILM_LIMITS.nodes)
|
|
2766
|
+
issues.push(`scene.nodes: at most ${ZHUDA_FILM_LIMITS.nodes}`);
|
|
2767
|
+
const ids = new Set<string>();
|
|
2768
|
+
scene.nodes.forEach((node, i) => {
|
|
2769
|
+
validateNode(
|
|
2770
|
+
node,
|
|
2771
|
+
`scene.nodes[${i}]`,
|
|
2772
|
+
issues,
|
|
2773
|
+
context,
|
|
2774
|
+
materials,
|
|
2775
|
+
object(scene.look) && scene.look.lightFalloff === 'physical',
|
|
2776
|
+
);
|
|
2777
|
+
const id = object(node) ? node.id : undefined;
|
|
2778
|
+
if (typeof id === 'string') {
|
|
2779
|
+
if (ids.has(id)) issues.push(`scene.nodes[${i}].id: duplicate ${id}`);
|
|
2780
|
+
ids.add(id);
|
|
2781
|
+
}
|
|
2782
|
+
});
|
|
2783
|
+
const models = scene.nodes.filter((node) => object(node) && node.type === 'model').length;
|
|
2784
|
+
if (models > ZHUDA_FILM_LIMITS.models)
|
|
2785
|
+
issues.push(`scene.nodes: at most ${ZHUDA_FILM_LIMITS.models} models`);
|
|
2786
|
+
const modelIds = new Set(
|
|
2787
|
+
scene.nodes.flatMap((node) =>
|
|
2788
|
+
object(node) && node.type === 'model' && typeof node.id === 'string' ? [node.id] : [],
|
|
2789
|
+
),
|
|
2790
|
+
);
|
|
2791
|
+
scene.nodes.forEach((node, i) => {
|
|
2792
|
+
if (!object(node) || node.type !== 'light' || !object(node.follows)) return;
|
|
2793
|
+
if (typeof node.follows.node === 'string' && !modelIds.has(node.follows.node))
|
|
2794
|
+
issues.push(
|
|
2795
|
+
`scene.nodes[${i}].follows.node: ${node.follows.node} is not a model node in this scene`,
|
|
2796
|
+
);
|
|
2797
|
+
});
|
|
2798
|
+
if (scene.nodes.filter((node) => object(node) && node.type === 'effect').length > 32)
|
|
2799
|
+
issues.push('scene.nodes: at most 32 effect nodes');
|
|
2800
|
+
const terrainIds = new Set(
|
|
2801
|
+
scene.nodes.flatMap((node) =>
|
|
2802
|
+
object(node) && node.type === 'terrain' && typeof node.id === 'string' ? [node.id] : [],
|
|
2803
|
+
),
|
|
2804
|
+
);
|
|
2805
|
+
scene.nodes.forEach((node, i) => {
|
|
2806
|
+
if (!object(node) || node.type !== 'grass' || typeof node.on !== 'string') return;
|
|
2807
|
+
if (!terrainIds.has(node.on))
|
|
2808
|
+
issues.push(`scene.nodes[${i}].on: ${node.on} is not a terrain node in this scene`);
|
|
2809
|
+
});
|
|
2810
|
+
let reflectors = 0;
|
|
2811
|
+
scene.nodes.forEach((node, i) => {
|
|
2812
|
+
if (!object(node) || (node.type !== 'reflector' && node.type !== 'water')) return;
|
|
2813
|
+
if (++reflectors === 2)
|
|
2814
|
+
issues.push(
|
|
2815
|
+
`scene.nodes[${i}]: one reflector or water per scene (each is a second scene render)`,
|
|
2816
|
+
);
|
|
2817
|
+
const grade = object(scene.look) ? scene.look.grade : undefined;
|
|
2818
|
+
if (node.type === 'water' && (grade === undefined || grade === false))
|
|
2819
|
+
issues.push(`scene.nodes[${i}]: water needs look.grade (it reads the HDR scene behind it)`);
|
|
2820
|
+
if (Array.isArray(node.hides))
|
|
2821
|
+
for (const id of node.hides)
|
|
2822
|
+
if (typeof id === 'string' && !modelIds.has(id))
|
|
2823
|
+
issues.push(`scene.nodes[${i}].hides: ${id} is not a model node in this scene`);
|
|
2824
|
+
});
|
|
2825
|
+
const copies = scene.nodes.reduce(
|
|
2826
|
+
(sum: number, node) =>
|
|
2827
|
+
sum + (object(node) && Array.isArray(node.placements) ? node.placements.length : 0),
|
|
2828
|
+
0,
|
|
2829
|
+
);
|
|
2830
|
+
if (copies > ZHUDA_FILM_LIMITS.placementsTotal)
|
|
2831
|
+
issues.push(
|
|
2832
|
+
`scene.nodes: at most ${ZHUDA_FILM_LIMITS.placementsTotal} placements in all, got ${copies}`,
|
|
2833
|
+
);
|
|
2834
|
+
const lightNodes = scene.nodes.filter((node) => object(node) && node.type === 'light');
|
|
2835
|
+
// Only point lights shine into the fog; spot lights do not count here.
|
|
2836
|
+
if (
|
|
2837
|
+
lightNodes.filter((node) => (node as { kind?: unknown }).kind === 'point').length >
|
|
2838
|
+
ZHUDA_FILM_LIMITS.fogLights
|
|
2839
|
+
)
|
|
2840
|
+
issues.push(
|
|
2841
|
+
`scene.nodes: at most ${ZHUDA_FILM_LIMITS.fogLights} point lights including fog-only ones`,
|
|
2842
|
+
);
|
|
2843
|
+
const casting = (kind: string) =>
|
|
2844
|
+
lightNodes.filter((node) => {
|
|
2845
|
+
const light = node as { castsShadow?: unknown; kind?: unknown };
|
|
2846
|
+
return light.castsShadow === true && light.kind === kind;
|
|
2847
|
+
}).length;
|
|
2848
|
+
if (casting('spot') > 1) issues.push('scene.nodes: one spot light may cast shadows');
|
|
2849
|
+
if (casting('point') > ZHUDA_FILM_LIMITS.pointShadows)
|
|
2850
|
+
issues.push(
|
|
2851
|
+
`scene.nodes: at most ${ZHUDA_FILM_LIMITS.pointShadows} point lights may cast shadows`,
|
|
2852
|
+
);
|
|
2853
|
+
const lights = lightNodes.filter((node) => !(node as { fogOnly?: unknown }).fogOnly).length;
|
|
2854
|
+
if (lights > ZHUDA_FILM_LIMITS.lights)
|
|
2855
|
+
issues.push(`scene.nodes: at most ${ZHUDA_FILM_LIMITS.lights} real-time lights`);
|
|
2856
|
+
}
|
|
2857
|
+
return issues;
|
|
2858
|
+
}
|
|
2859
|
+
|
|
2860
|
+
/** Throws with every problem listed; returns a detached copy otherwise. */
|
|
2861
|
+
export function parseZhudaFilmScene(
|
|
2862
|
+
scene: unknown,
|
|
2863
|
+
context: ZhudaFilmValidationContext = {},
|
|
2864
|
+
): ZhudaFilmScene {
|
|
2865
|
+
const issues = validateZhudaFilmScene(scene, context);
|
|
2866
|
+
if (issues.length) throw Error('Invalid film scene:\n- ' + issues.join('\n- '));
|
|
2867
|
+
return structuredClone(scene) as ZhudaFilmScene;
|
|
2868
|
+
}
|
|
2869
|
+
|
|
2870
|
+
/** Applies a patch atomically: the input is untouched and an invalid result throws. */
|
|
2871
|
+
export function applyZhudaFilmScenePatch(
|
|
2872
|
+
scene: ZhudaFilmScene,
|
|
2873
|
+
patch: ZhudaFilmScenePatch,
|
|
2874
|
+
context: ZhudaFilmValidationContext = {},
|
|
2875
|
+
): ZhudaFilmScene {
|
|
2876
|
+
if (!object(patch as unknown)) throw Error('Invalid film patch: object required');
|
|
2877
|
+
const issues: string[] = [];
|
|
2878
|
+
unknownKeys(
|
|
2879
|
+
patch as Record<string, unknown>,
|
|
2880
|
+
['camera', 'look', 'materials', 'upsert', 'remove'],
|
|
2881
|
+
'patch',
|
|
2882
|
+
issues,
|
|
2883
|
+
);
|
|
2884
|
+
if (patch.camera !== undefined) validateCamera(patch.camera, 'patch.camera', issues, true);
|
|
2885
|
+
if (patch.remove !== undefined && !(Array.isArray(patch.remove) && patch.remove.every(isId)))
|
|
2886
|
+
issues.push('patch.remove: array of node ids required');
|
|
2887
|
+
if (patch.upsert !== undefined && !Array.isArray(patch.upsert))
|
|
2888
|
+
issues.push('patch.upsert: array of nodes required');
|
|
2889
|
+
if (patch.materials !== undefined && !object(patch.materials))
|
|
2890
|
+
issues.push('patch.materials: object required');
|
|
2891
|
+
if (issues.length) throw Error('Invalid film patch:\n- ' + issues.join('\n- '));
|
|
2892
|
+
const next = structuredClone(scene);
|
|
2893
|
+
if (patch.camera) next.camera = { ...next.camera, ...structuredClone(patch.camera) };
|
|
2894
|
+
if (patch.look) {
|
|
2895
|
+
const look = { ...(next.look ?? {}), ...structuredClone(patch.look) };
|
|
2896
|
+
for (const key of [
|
|
2897
|
+
'sun',
|
|
2898
|
+
'shadows',
|
|
2899
|
+
'atmosphere',
|
|
2900
|
+
'fog',
|
|
2901
|
+
'grade',
|
|
2902
|
+
'lightFog',
|
|
2903
|
+
'screenReflections',
|
|
2904
|
+
'autoExposure',
|
|
2905
|
+
'depthOfField',
|
|
2906
|
+
'motionBlur',
|
|
2907
|
+
'clouds',
|
|
2908
|
+
'lensFlare',
|
|
2909
|
+
'underwater',
|
|
2910
|
+
'bounceLight',
|
|
2911
|
+
'environment',
|
|
2912
|
+
'panorama',
|
|
2913
|
+
] as const) {
|
|
2914
|
+
const before = next.look?.[key],
|
|
2915
|
+
after = patch.look[key];
|
|
2916
|
+
if (typeof after === 'object' && typeof before === 'object' && after && before)
|
|
2917
|
+
(look as Record<string, unknown>)[key] = { ...before, ...after };
|
|
2918
|
+
}
|
|
2919
|
+
next.look = look;
|
|
2920
|
+
}
|
|
2921
|
+
if (patch.materials) {
|
|
2922
|
+
const materials = { ...(next.materials ?? {}) };
|
|
2923
|
+
for (const [name, material] of Object.entries(patch.materials))
|
|
2924
|
+
if (material === null) delete materials[name];
|
|
2925
|
+
else materials[name] = structuredClone(material);
|
|
2926
|
+
next.materials = materials;
|
|
2927
|
+
}
|
|
2928
|
+
if (patch.remove) {
|
|
2929
|
+
const missing = patch.remove.filter((id) => !next.nodes.some((node) => node.id === id));
|
|
2930
|
+
if (missing.length)
|
|
2931
|
+
throw Error('Invalid film patch:\n- patch.remove: unknown node ' + missing.join(', '));
|
|
2932
|
+
next.nodes = next.nodes.filter((node) => !patch.remove!.includes(node.id));
|
|
2933
|
+
}
|
|
2934
|
+
for (const node of patch.upsert ?? []) {
|
|
2935
|
+
const index = next.nodes.findIndex((existing) => existing.id === (node as { id?: string })?.id);
|
|
2936
|
+
if (index >= 0) next.nodes[index] = structuredClone(node);
|
|
2937
|
+
else next.nodes.push(structuredClone(node));
|
|
2938
|
+
}
|
|
2939
|
+
return parseZhudaFilmScene(next, context);
|
|
2940
|
+
}
|
|
2941
|
+
|
|
2942
|
+
/** Camera with every default filled in. */
|
|
2943
|
+
export function resolveZhudaFilmCamera(camera: ZhudaFilmCamera): Required<ZhudaFilmCamera> {
|
|
2944
|
+
const distance = Math.hypot(
|
|
2945
|
+
camera.target[0] - camera.eye[0],
|
|
2946
|
+
camera.target[1] - camera.eye[1],
|
|
2947
|
+
camera.target[2] - camera.eye[2],
|
|
2948
|
+
);
|
|
2949
|
+
return {
|
|
2950
|
+
eye: [...camera.eye],
|
|
2951
|
+
target: [...camera.target],
|
|
2952
|
+
focalLengthMm: camera.focalLengthMm ?? 35,
|
|
2953
|
+
fStop: camera.fStop ?? 8,
|
|
2954
|
+
focusDistanceM: camera.focusDistanceM ?? Math.max(distance, 0.06),
|
|
2955
|
+
};
|
|
2956
|
+
}
|
|
2957
|
+
|
|
2958
|
+
/** Look with every default filled in. */
|
|
2959
|
+
export interface ZhudaResolvedFilmLook {
|
|
2960
|
+
preset: ZhudaFilmLookPreset | null;
|
|
2961
|
+
sky: ZhudaFilmVec3;
|
|
2962
|
+
ambient: ZhudaFilmVec3;
|
|
2963
|
+
ambientGround: ZhudaFilmVec3 | false;
|
|
2964
|
+
sun: Required<ZhudaFilmSun>;
|
|
2965
|
+
lightFalloff: 'laya' | 'physical';
|
|
2966
|
+
shadows: Required<ZhudaFilmShadows> | false;
|
|
2967
|
+
atmosphere: Required<ZhudaFilmAtmosphere> | false;
|
|
2968
|
+
fog: Required<ZhudaFilmFog> | false;
|
|
2969
|
+
grade:
|
|
2970
|
+
| (Required<Omit<ZhudaFilmGrade, 'lut'>> & {
|
|
2971
|
+
lut: { asset: string; intensity: number } | false;
|
|
2972
|
+
})
|
|
2973
|
+
| false;
|
|
2974
|
+
lightFog:
|
|
2975
|
+
| (Required<Omit<ZhudaFilmLightFog, 'shafts'>> & {
|
|
2976
|
+
shafts: Required<ZhudaFilmLightShafts> | false;
|
|
2977
|
+
})
|
|
2978
|
+
| false;
|
|
2979
|
+
screenReflections: Required<ZhudaFilmScreenReflections> | false;
|
|
2980
|
+
autoExposure: Required<ZhudaAutoExposureOptions> | false;
|
|
2981
|
+
depthOfField: Required<ZhudaDepthOfFieldOptions> | false;
|
|
2982
|
+
motionBlur: Required<ZhudaMotionBlurOptions> | false;
|
|
2983
|
+
clouds: Required<ZhudaFilmClouds> | false;
|
|
2984
|
+
lensFlare:
|
|
2985
|
+
| { strength: number; occlusionRadius: number; elements: readonly ZhudaLensFlareElement[] }
|
|
2986
|
+
| false;
|
|
2987
|
+
/** Its `color` is a display value, decoded where the water is made. */
|
|
2988
|
+
underwater: ZhudaResolvedUnderwater | false;
|
|
2989
|
+
bounceLight:
|
|
2990
|
+
| (Required<Pick<ZhudaFilmBounceLight, 'spacing' | 'strength' | 'visibility'>> &
|
|
2991
|
+
Pick<ZhudaFilmBounceLight, 'min' | 'max'>)
|
|
2992
|
+
| false;
|
|
2993
|
+
environment: Required<ZhudaFilmEnvironment> | false;
|
|
2994
|
+
panorama: Required<ZhudaFilmPanorama> | false;
|
|
2995
|
+
}
|
|
2996
|
+
|
|
2997
|
+
/**
|
|
2998
|
+
* Look with every value filled in: the preset (if any) first, then the
|
|
2999
|
+
* scene's own fields. Without a preset, shadows, atmosphere and fog stay off
|
|
3000
|
+
* unless the scene turns them on.
|
|
3001
|
+
*/
|
|
3002
|
+
/** Fills in the shaft defaults of a resolved light fog. */
|
|
3003
|
+
function lightFogOf(fog: Required<ZhudaFilmLightFog> | false): ZhudaResolvedFilmLook['lightFog'] {
|
|
3004
|
+
if (!fog) return false;
|
|
3005
|
+
const shafts = fog.shafts;
|
|
3006
|
+
return {
|
|
3007
|
+
...fog,
|
|
3008
|
+
shafts:
|
|
3009
|
+
shafts && typeof shafts === 'object'
|
|
3010
|
+
? {
|
|
3011
|
+
strength: shafts.strength ?? 1,
|
|
3012
|
+
anisotropy: shafts.anisotropy ?? 0.6,
|
|
3013
|
+
distance: shafts.distance ?? 60,
|
|
3014
|
+
steps: shafts.steps ?? 40,
|
|
3015
|
+
scale: shafts.scale ?? 0.5,
|
|
3016
|
+
}
|
|
3017
|
+
: false,
|
|
3018
|
+
};
|
|
3019
|
+
}
|
|
3020
|
+
|
|
3021
|
+
export function resolveZhudaFilmLook(
|
|
3022
|
+
look: ZhudaFilmLook = ZHUDA_FILM_ABSENT_LOOK,
|
|
3023
|
+
): ZhudaResolvedFilmLook {
|
|
3024
|
+
const preset = look.preset ? ZHUDA_FILM_LOOK_PRESETS[look.preset] : null;
|
|
3025
|
+
const d = ZHUDA_FILM_DEFAULT_LOOK;
|
|
3026
|
+
const base = preset ?? {
|
|
3027
|
+
sky: [...d.sky] as ZhudaFilmVec3,
|
|
3028
|
+
ambient: [...d.ambient] as ZhudaFilmVec3,
|
|
3029
|
+
sun: { ...d.sun, color: [...d.sun.color] as ZhudaFilmVec3 } as Required<ZhudaFilmSun>,
|
|
3030
|
+
};
|
|
3031
|
+
const sky = look.sky ?? ([...base.sky] as ZhudaFilmVec3);
|
|
3032
|
+
const merge = <T extends object>(
|
|
3033
|
+
value: T | false | undefined,
|
|
3034
|
+
fallback: Required<T> | false,
|
|
3035
|
+
blank: Required<T>,
|
|
3036
|
+
): Required<T> | false => {
|
|
3037
|
+
if (value === false) return false;
|
|
3038
|
+
if (value === undefined) return fallback ? { ...fallback } : false;
|
|
3039
|
+
return { ...(fallback || blank), ...value } as Required<T>;
|
|
3040
|
+
};
|
|
3041
|
+
const gradeOf = (grade: ZhudaFilmGrade | false | undefined): ZhudaResolvedFilmLook['grade'] => {
|
|
3042
|
+
if (!grade) return false;
|
|
3043
|
+
const { lut, ...values } = grade;
|
|
3044
|
+
return {
|
|
3045
|
+
exposure: 1,
|
|
3046
|
+
contrast: 1,
|
|
3047
|
+
saturation: 1,
|
|
3048
|
+
bloom: 0.1,
|
|
3049
|
+
// By horizons the number is a power, and 1 is what the geometry hides.
|
|
3050
|
+
ao: values.aoMethod === 'gtao' ? 1 : 0.5,
|
|
3051
|
+
aoRadius: 0.5,
|
|
3052
|
+
grain: 0,
|
|
3053
|
+
vignette: 0,
|
|
3054
|
+
fringe: 0,
|
|
3055
|
+
antialias: 'msaa',
|
|
3056
|
+
toneMapping: 'aces',
|
|
3057
|
+
temperature: 0,
|
|
3058
|
+
tint: 0,
|
|
3059
|
+
lift: [0, 0, 0],
|
|
3060
|
+
gamma: [1, 1, 1],
|
|
3061
|
+
gain: [1, 1, 1],
|
|
3062
|
+
bloomThreshold: 1.2,
|
|
3063
|
+
bloomSoftKnee: 0.5,
|
|
3064
|
+
bloomAnamorphic: 0,
|
|
3065
|
+
bloomDiffusion: 4,
|
|
3066
|
+
aoMethod: 'sao',
|
|
3067
|
+
dither: false,
|
|
3068
|
+
...values,
|
|
3069
|
+
lut: lut ? { asset: lut.asset, intensity: lut.intensity ?? 1 } : false,
|
|
3070
|
+
};
|
|
3071
|
+
};
|
|
3072
|
+
const atmosphere = merge<ZhudaFilmAtmosphere>(look.atmosphere, preset?.atmosphere ?? false, {
|
|
3073
|
+
thickness: 1,
|
|
3074
|
+
skyTint: [0.5, 0.5, 0.5],
|
|
3075
|
+
groundTint: [0.37, 0.35, 0.33],
|
|
3076
|
+
exposure: 1.3,
|
|
3077
|
+
sunSize: 0.04,
|
|
3078
|
+
});
|
|
3079
|
+
const fog = (() => {
|
|
3080
|
+
if (look.fog === false) return false as const;
|
|
3081
|
+
const from = look.fog ?? (preset?.fog || undefined);
|
|
3082
|
+
if (!from) return false as const;
|
|
3083
|
+
return {
|
|
3084
|
+
color: from.color ?? (preset?.fog ? preset.fog.color : sky),
|
|
3085
|
+
start: from.start,
|
|
3086
|
+
end: from.end,
|
|
3087
|
+
} as Required<ZhudaFilmFog>;
|
|
3088
|
+
})();
|
|
3089
|
+
// Fog saturates to its own colour toward the horizon, so by default it takes
|
|
3090
|
+
// the colour the sky has there. One fixed dark blue suited night only: by
|
|
3091
|
+
// day it drew a black band along the horizon.
|
|
3092
|
+
const horizon: ZhudaFilmVec3 =
|
|
3093
|
+
preset && atmosphere && !(look.panorama && typeof look.panorama === 'object')
|
|
3094
|
+
? ([...preset.horizon] as ZhudaFilmVec3)
|
|
3095
|
+
: ([...sky] as ZhudaFilmVec3);
|
|
3096
|
+
return {
|
|
3097
|
+
preset: look.preset ?? null,
|
|
3098
|
+
sky,
|
|
3099
|
+
ambient: look.ambient ?? ([...base.ambient] as ZhudaFilmVec3),
|
|
3100
|
+
ambientGround:
|
|
3101
|
+
look.ambientGround === false
|
|
3102
|
+
? false
|
|
3103
|
+
: look.ambientGround
|
|
3104
|
+
? ([...look.ambientGround] as ZhudaFilmVec3)
|
|
3105
|
+
: preset?.ambientGround
|
|
3106
|
+
? ([...preset.ambientGround] as ZhudaFilmVec3)
|
|
3107
|
+
: false,
|
|
3108
|
+
sun: {
|
|
3109
|
+
azimuthDeg: look.sun?.azimuthDeg ?? base.sun.azimuthDeg,
|
|
3110
|
+
elevationDeg: look.sun?.elevationDeg ?? base.sun.elevationDeg,
|
|
3111
|
+
intensity: look.sun?.intensity ?? base.sun.intensity,
|
|
3112
|
+
color: look.sun?.color ?? ([...base.sun.color] as ZhudaFilmVec3),
|
|
3113
|
+
},
|
|
3114
|
+
lightFalloff: look.lightFalloff ?? 'laya',
|
|
3115
|
+
shadows: merge<ZhudaFilmShadows>(look.shadows, preset?.shadows ?? false, {
|
|
3116
|
+
distance: 60,
|
|
3117
|
+
softness: 'soft',
|
|
3118
|
+
strength: 1,
|
|
3119
|
+
resolution: 2048,
|
|
3120
|
+
cascades: 2,
|
|
3121
|
+
update: 'every',
|
|
3122
|
+
interval: 3,
|
|
3123
|
+
spread: 1,
|
|
3124
|
+
blend: false,
|
|
3125
|
+
contact: 0,
|
|
3126
|
+
}),
|
|
3127
|
+
atmosphere,
|
|
3128
|
+
fog,
|
|
3129
|
+
grade: gradeOf(look.grade),
|
|
3130
|
+
lightFog: lightFogOf(
|
|
3131
|
+
merge<ZhudaFilmLightFog>(look.lightFog, false, {
|
|
3132
|
+
density: 0.012,
|
|
3133
|
+
falloffMeters: 8,
|
|
3134
|
+
baseY: 0,
|
|
3135
|
+
color: horizon,
|
|
3136
|
+
scatter: 1,
|
|
3137
|
+
maxDistance: 600,
|
|
3138
|
+
shafts: false,
|
|
3139
|
+
}),
|
|
3140
|
+
),
|
|
3141
|
+
screenReflections: merge<ZhudaFilmScreenReflections>(look.screenReflections, false, {
|
|
3142
|
+
strength: 1,
|
|
3143
|
+
wetness: 0.5,
|
|
3144
|
+
distance: 30,
|
|
3145
|
+
steps: 32,
|
|
3146
|
+
sky: 0,
|
|
3147
|
+
skyColor: horizon,
|
|
3148
|
+
surfaces: false,
|
|
3149
|
+
}),
|
|
3150
|
+
autoExposure: look.autoExposure
|
|
3151
|
+
? resolveZhudaAutoExposure(look.autoExposure === true ? {} : look.autoExposure)
|
|
3152
|
+
: false,
|
|
3153
|
+
depthOfField: look.depthOfField ? resolveZhudaDepthOfField(look.depthOfField) : false,
|
|
3154
|
+
motionBlur: look.motionBlur
|
|
3155
|
+
? resolveZhudaMotionBlur(look.motionBlur === true ? {} : look.motionBlur)
|
|
3156
|
+
: false,
|
|
3157
|
+
clouds: look.clouds
|
|
3158
|
+
? ((({ sunToward: _t, sunColor: _c, skyColor: _s, ...own }) => own)(
|
|
3159
|
+
resolveZhudaClouds(look.clouds === true ? {} : look.clouds),
|
|
3160
|
+
) as Required<ZhudaFilmClouds>)
|
|
3161
|
+
: false,
|
|
3162
|
+
lensFlare: look.lensFlare
|
|
3163
|
+
? {
|
|
3164
|
+
strength: 1,
|
|
3165
|
+
occlusionRadius: 0.012,
|
|
3166
|
+
elements: ZHUDA_LENS_FLARE_SUN,
|
|
3167
|
+
...(look.lensFlare === true ? {} : look.lensFlare),
|
|
3168
|
+
}
|
|
3169
|
+
: false,
|
|
3170
|
+
underwater: look.underwater
|
|
3171
|
+
? resolveZhudaUnderwater({
|
|
3172
|
+
// A display colour, like every colour of a look (about the medium's own default as light).
|
|
3173
|
+
color: [0.17, 0.33, 0.38],
|
|
3174
|
+
...(look.underwater === true ? {} : look.underwater),
|
|
3175
|
+
})
|
|
3176
|
+
: false,
|
|
3177
|
+
bounceLight: look.bounceLight
|
|
3178
|
+
? {
|
|
3179
|
+
spacing: look.bounceLight.spacing ?? 3,
|
|
3180
|
+
strength: look.bounceLight.strength ?? 1,
|
|
3181
|
+
visibility: look.bounceLight.visibility ?? false,
|
|
3182
|
+
...(look.bounceLight.min && look.bounceLight.max
|
|
3183
|
+
? { min: [...look.bounceLight.min], max: [...look.bounceLight.max] }
|
|
3184
|
+
: {}),
|
|
3185
|
+
}
|
|
3186
|
+
: false,
|
|
3187
|
+
panorama:
|
|
3188
|
+
look.panorama && typeof look.panorama === 'object'
|
|
3189
|
+
? {
|
|
3190
|
+
asset: look.panorama.asset,
|
|
3191
|
+
exposure: look.panorama.exposure ?? 1,
|
|
3192
|
+
rotationDeg: look.panorama.rotationDeg ?? 0,
|
|
3193
|
+
}
|
|
3194
|
+
: false,
|
|
3195
|
+
environment:
|
|
3196
|
+
look.environment && typeof look.environment === 'object'
|
|
3197
|
+
? {
|
|
3198
|
+
position: [...look.environment.position] as ZhudaFilmVec3,
|
|
3199
|
+
reflection: look.environment.reflection ?? 1,
|
|
3200
|
+
ambient: look.environment.ambient ?? 1,
|
|
3201
|
+
reflectionOnly: look.environment.reflectionOnly ?? false,
|
|
3202
|
+
box: look.environment.box
|
|
3203
|
+
? {
|
|
3204
|
+
min: [...look.environment.box.min] as ZhudaFilmVec3,
|
|
3205
|
+
max: [...look.environment.box.max] as ZhudaFilmVec3,
|
|
3206
|
+
}
|
|
3207
|
+
: false,
|
|
3208
|
+
}
|
|
3209
|
+
: false,
|
|
3210
|
+
};
|
|
3211
|
+
}
|
|
3212
|
+
|
|
3213
|
+
/** Checks a keyed camera move: two to 256 keys, strictly increasing times from 0. */
|
|
3214
|
+
export function validateZhudaFilmCameraPath(keys: unknown): string[] {
|
|
3215
|
+
const issues: string[] = [];
|
|
3216
|
+
if (!Array.isArray(keys) || keys.length < 2 || keys.length > 256)
|
|
3217
|
+
return ['cameraPath: use 2..256 keys'];
|
|
3218
|
+
keys.forEach((key, i) => {
|
|
3219
|
+
if (!object(key)) return void issues.push(`cameraPath[${i}]: object required`);
|
|
3220
|
+
if (!finite(key.time) || key.time < 0) issues.push(`cameraPath[${i}].time: use seconds >= 0`);
|
|
3221
|
+
if (i === 0 && key.time !== 0) issues.push('cameraPath[0].time: must be 0');
|
|
3222
|
+
if (
|
|
3223
|
+
i > 0 &&
|
|
3224
|
+
finite(key.time) &&
|
|
3225
|
+
object(keys[i - 1]) &&
|
|
3226
|
+
!(key.time > (keys[i - 1] as { time: number }).time)
|
|
3227
|
+
)
|
|
3228
|
+
issues.push(`cameraPath[${i}].time: must increase`);
|
|
3229
|
+
validateCamera(key.camera, `cameraPath[${i}].camera`, issues);
|
|
3230
|
+
});
|
|
3231
|
+
return issues;
|
|
3232
|
+
}
|
|
3233
|
+
|
|
3234
|
+
const smooth = (t: number) => t * t * (3 - 2 * t);
|
|
3235
|
+
const mix = (a: number, b: number, t: number) => a + (b - a) * t;
|
|
3236
|
+
|
|
3237
|
+
/**
|
|
3238
|
+
* Camera at time `t` along keyed shots, eased in and out between keys
|
|
3239
|
+
* (smoothstep). Times outside the path hold the first or last key.
|
|
3240
|
+
*/
|
|
3241
|
+
export function sampleZhudaFilmCameraPath(
|
|
3242
|
+
keys: readonly ZhudaFilmCameraKey[],
|
|
3243
|
+
t: number,
|
|
3244
|
+
): Required<ZhudaFilmCamera> {
|
|
3245
|
+
if (!keys.length) throw Error('Camera path is empty');
|
|
3246
|
+
if (t <= keys[0].time) return resolveZhudaFilmCamera(keys[0].camera);
|
|
3247
|
+
const last = keys[keys.length - 1];
|
|
3248
|
+
if (t >= last.time) return resolveZhudaFilmCamera(last.camera);
|
|
3249
|
+
let i = 0;
|
|
3250
|
+
while (keys[i + 1].time < t) i++;
|
|
3251
|
+
const a = resolveZhudaFilmCamera(keys[i].camera),
|
|
3252
|
+
b = resolveZhudaFilmCamera(keys[i + 1].camera),
|
|
3253
|
+
k = smooth((t - keys[i].time) / (keys[i + 1].time - keys[i].time));
|
|
3254
|
+
const v = (p: ZhudaFilmVec3, q: ZhudaFilmVec3): ZhudaFilmVec3 => [
|
|
3255
|
+
mix(p[0], q[0], k),
|
|
3256
|
+
mix(p[1], q[1], k),
|
|
3257
|
+
mix(p[2], q[2], k),
|
|
3258
|
+
];
|
|
3259
|
+
return {
|
|
3260
|
+
eye: v(a.eye, b.eye),
|
|
3261
|
+
target: v(a.target, b.target),
|
|
3262
|
+
focalLengthMm: mix(a.focalLengthMm, b.focalLengthMm, k),
|
|
3263
|
+
fStop: mix(a.fStop, b.fStop, k),
|
|
3264
|
+
focusDistanceM: mix(a.focusDistanceM, b.focusDistanceM, k),
|
|
3265
|
+
};
|
|
3266
|
+
}
|
|
3267
|
+
|
|
3268
|
+
/**
|
|
3269
|
+
* What a mounted film stage cannot change, when `to` asks for it: the
|
|
3270
|
+
* environment, the panorama, a colour table other than the one loaded with
|
|
3271
|
+
* the scene (`loadedTable`: the asset of the look it was mounted with, or
|
|
3272
|
+
* null), or the bounce light, which is captured at mount. Null when the look
|
|
3273
|
+
* can be drawn. A look without a grade takes no table (quality level 0) and
|
|
3274
|
+
* may come back to the loaded one.
|
|
3275
|
+
*/
|
|
3276
|
+
export function zhudaFilmLookFixedReason(
|
|
3277
|
+
from: ZhudaResolvedFilmLook,
|
|
3278
|
+
to: ZhudaResolvedFilmLook,
|
|
3279
|
+
loadedTable: string | null,
|
|
3280
|
+
): 'environment' | 'panorama' | 'colorTable' | 'bounceLight' | null {
|
|
3281
|
+
const json = (value: unknown) => JSON.stringify(value);
|
|
3282
|
+
if (json(from.environment) !== json(to.environment)) return 'environment';
|
|
3283
|
+
if (json(from.panorama) !== json(to.panorama)) return 'panorama';
|
|
3284
|
+
const table = to.grade && to.grade.lut ? to.grade.lut.asset : null;
|
|
3285
|
+
if (table !== null && table !== loadedTable) return 'colorTable';
|
|
3286
|
+
if (json(from.bounceLight) !== json(to.bounceLight)) return 'bounceLight';
|
|
3287
|
+
return null;
|
|
3288
|
+
}
|
|
3289
|
+
|
|
3290
|
+
/**
|
|
3291
|
+
* What changing a running look from `from` to `to` has to rebuild, or `null`
|
|
3292
|
+
* when every difference can be set in place: the sun (direction, colour,
|
|
3293
|
+
* intensity), sky and ground light colours, the flat sky colour, the values
|
|
3294
|
+
* of the procedural sky and of distance fog, shadow distance, strength,
|
|
3295
|
+
* softness, resolution, cascades, spread, blend, contact shadows and how
|
|
3296
|
+
* often they are drawn, how lamps fall off, the
|
|
3297
|
+
* values of the grade (exposure, contrast, saturation, the tone curve, white
|
|
3298
|
+
* balance, lift, gamma and gain, bloom and its threshold, knee, shape and
|
|
3299
|
+
* spread, ambient occlusion, grain, vignette, fringe, how much of a colour
|
|
3300
|
+
* table is taken), the lens flare's strength and elements,
|
|
3301
|
+
* the light fog's density, falloff, height, colour, scatter and reach, the
|
|
3302
|
+
* strength and spread of its shafts, and the sun they follow. Anything else
|
|
3303
|
+
* names the first part that differs: switching shadows, sky, fog, grade,
|
|
3304
|
+
* light fog or sky-and-ground light on or off, switching bloom, ambient
|
|
3305
|
+
* occlusion, the lens finish, the lens flare or the shafts on or off,
|
|
3306
|
+
* another way of smoothing edges or of working out ambient occlusion, or
|
|
3307
|
+
* the shafts' distance, resolution or step count. `environment`, `panorama`
|
|
3308
|
+
* and the colour table (`colorTable`) need assets or a capture; a running
|
|
3309
|
+
* look cannot change them at all.
|
|
3310
|
+
*/
|
|
3311
|
+
export function zhudaFilmLookRebuildReason(
|
|
3312
|
+
from: ZhudaResolvedFilmLook,
|
|
3313
|
+
to: ZhudaResolvedFilmLook,
|
|
3314
|
+
):
|
|
3315
|
+
| 'environment'
|
|
3316
|
+
| 'panorama'
|
|
3317
|
+
| 'shadows'
|
|
3318
|
+
| 'atmosphere'
|
|
3319
|
+
| 'fog'
|
|
3320
|
+
| 'ambientGround'
|
|
3321
|
+
| 'grade'
|
|
3322
|
+
| 'lightFog'
|
|
3323
|
+
| 'screenReflections'
|
|
3324
|
+
| 'autoExposure'
|
|
3325
|
+
| 'depthOfField'
|
|
3326
|
+
| 'motionBlur'
|
|
3327
|
+
| 'clouds'
|
|
3328
|
+
| 'lensFlare'
|
|
3329
|
+
| 'underwater'
|
|
3330
|
+
| 'colorTable'
|
|
3331
|
+
| 'bounceLight'
|
|
3332
|
+
| null {
|
|
3333
|
+
const json = (value: unknown) => JSON.stringify(value);
|
|
3334
|
+
if (json(from.environment) !== json(to.environment)) return 'environment';
|
|
3335
|
+
if (json(from.panorama) !== json(to.panorama)) return 'panorama';
|
|
3336
|
+
// The table is loaded with the scene; how much of it is taken is set in place.
|
|
3337
|
+
const table = (look: ZhudaResolvedFilmLook) =>
|
|
3338
|
+
look.grade && look.grade.lut ? look.grade.lut.asset : null;
|
|
3339
|
+
if (table(from) !== table(to)) return 'colorTable';
|
|
3340
|
+
if (json(from.bounceLight) !== json(to.bounceLight)) return 'bounceLight';
|
|
3341
|
+
if (!from.shadows !== !to.shadows) return 'shadows';
|
|
3342
|
+
// Drawn every frame is LayaAir's own path; skipping frames puts a rule on the scene.
|
|
3343
|
+
if (
|
|
3344
|
+
from.shadows &&
|
|
3345
|
+
to.shadows &&
|
|
3346
|
+
(from.shadows.update === 'every') !== (to.shadows.update === 'every')
|
|
3347
|
+
)
|
|
3348
|
+
return 'shadows';
|
|
3349
|
+
if (!from.atmosphere !== !to.atmosphere) return 'atmosphere';
|
|
3350
|
+
if (!from.fog !== !to.fog) return 'fog';
|
|
3351
|
+
if (!from.ambientGround !== !to.ambientGround) return 'ambientGround';
|
|
3352
|
+
// The HDR chain is built with or without each effect; their strengths are set in place.
|
|
3353
|
+
const grade = (look: ZhudaResolvedFilmLook) =>
|
|
3354
|
+
look.grade
|
|
3355
|
+
? json([
|
|
3356
|
+
look.grade.bloom > 0,
|
|
3357
|
+
look.grade.ao > 0,
|
|
3358
|
+
look.grade.grain > 0 || look.grade.vignette > 0 || look.grade.fringe > 0,
|
|
3359
|
+
look.grade.antialias === 'fxaa' || look.grade.antialias === 'smaa'
|
|
3360
|
+
? look.grade.antialias
|
|
3361
|
+
: 'plain',
|
|
3362
|
+
look.grade.aoMethod,
|
|
3363
|
+
])
|
|
3364
|
+
: 'off';
|
|
3365
|
+
if (grade(from) !== grade(to)) return 'grade';
|
|
3366
|
+
// The fog's values are set in place; the light shafts' picture and loop are built.
|
|
3367
|
+
const fog = (look: ZhudaResolvedFilmLook) =>
|
|
3368
|
+
look.lightFog
|
|
3369
|
+
? json(
|
|
3370
|
+
look.lightFog.shafts ? { ...look.lightFog.shafts, strength: 0, anisotropy: 0 } : 'plain',
|
|
3371
|
+
)
|
|
3372
|
+
: 'off';
|
|
3373
|
+
if (fog(from) !== fog(to)) return 'lightFog';
|
|
3374
|
+
// Built or not built; its values are set in place.
|
|
3375
|
+
if (!from.screenReflections !== !to.screenReflections) return 'screenReflections';
|
|
3376
|
+
if (!from.autoExposure !== !to.autoExposure) return 'autoExposure';
|
|
3377
|
+
if (!from.depthOfField !== !to.depthOfField) return 'depthOfField';
|
|
3378
|
+
if (!from.motionBlur !== !to.motionBlur) return 'motionBlur';
|
|
3379
|
+
if (!from.clouds !== !to.clouds) return 'clouds';
|
|
3380
|
+
if (!from.lensFlare !== !to.lensFlare) return 'lensFlare';
|
|
3381
|
+
// The water's values are set in place; caustics and the surface from below are built or not.
|
|
3382
|
+
const water = (look: ZhudaResolvedFilmLook) =>
|
|
3383
|
+
look.underwater ? json([!!look.underwater.caustics, look.underwater.surface]) : 'off';
|
|
3384
|
+
if (water(from) !== water(to)) return 'underwater';
|
|
3385
|
+
return null;
|
|
3386
|
+
}
|
|
3387
|
+
|
|
3388
|
+
/**
|
|
3389
|
+
* The box a scene's bounce light fills by default: its objects and lights
|
|
3390
|
+
* (not the ground, a box used as ground, a reflector or water), widened by
|
|
3391
|
+
* 2 m around and 1.5 m above, down to the ground. Null when there is nothing
|
|
3392
|
+
* to light.
|
|
3393
|
+
*/
|
|
3394
|
+
export function zhudaFilmBounceBox(
|
|
3395
|
+
scene: ZhudaFilmScene,
|
|
3396
|
+
): { min: ZhudaFilmVec3; max: ZhudaFilmVec3 } | null {
|
|
3397
|
+
const low = [Infinity, Infinity, Infinity],
|
|
3398
|
+
high = [-Infinity, -Infinity, -Infinity];
|
|
3399
|
+
const take = (x: number, y: number, z: number, reach: number, height: number) => {
|
|
3400
|
+
low[0] = Math.min(low[0], x - reach);
|
|
3401
|
+
low[1] = Math.min(low[1], y);
|
|
3402
|
+
low[2] = Math.min(low[2], z - reach);
|
|
3403
|
+
high[0] = Math.max(high[0], x + reach);
|
|
3404
|
+
high[1] = Math.max(high[1], y + height);
|
|
3405
|
+
high[2] = Math.max(high[2], z + reach);
|
|
3406
|
+
};
|
|
3407
|
+
for (const node of scene.nodes) {
|
|
3408
|
+
const n = node as unknown as Record<string, any>;
|
|
3409
|
+
const [x, y, z] = (n.position ?? [0, 0, 0]) as number[];
|
|
3410
|
+
// A slab wider than 10 m and lower than 0.3 m is ground, not an object.
|
|
3411
|
+
if (n.type === 'box' && !(n.size[1] < 0.3 && Math.hypot(n.size[0], n.size[2]) > 10))
|
|
3412
|
+
take(x, y, z, Math.hypot(n.size[0], n.size[2]) / 2, n.size[1]);
|
|
3413
|
+
else if (n.type === 'lathe')
|
|
3414
|
+
take(
|
|
3415
|
+
x,
|
|
3416
|
+
y,
|
|
3417
|
+
z,
|
|
3418
|
+
Math.max(...n.profile.map((p: number[]) => p[0])),
|
|
3419
|
+
Math.max(...n.profile.map((p: number[]) => p[1])),
|
|
3420
|
+
);
|
|
3421
|
+
else if (n.type === 'extrude')
|
|
3422
|
+
take(x, y, z, Math.max(...n.outline.map((p: number[]) => Math.hypot(p[0], p[1]))), n.height);
|
|
3423
|
+
else if (n.type === 'sweep') {
|
|
3424
|
+
const reach = Math.max(...n.profile.map((p: number[]) => Math.hypot(p[0], p[1])));
|
|
3425
|
+
for (const point of n.path) take(x + point[0], y + point[1], z + point[2], reach, reach);
|
|
3426
|
+
}
|
|
3427
|
+
// Props and models: about the size of a shipping container around their place.
|
|
3428
|
+
else if (n.type === 'prop') take(x, y, z, 3.5, 3);
|
|
3429
|
+
else if (n.type === 'model') {
|
|
3430
|
+
const scale = n.scale ?? 1;
|
|
3431
|
+
for (const place of n.placements ?? [{ position: n.position }])
|
|
3432
|
+
if (place.position)
|
|
3433
|
+
take(place.position[0], place.position[1], place.position[2], 2 * scale, 3 * scale);
|
|
3434
|
+
} else if (n.type === 'light' && !n.fogOnly) take(x, y, z, 0.5, 0.5);
|
|
3435
|
+
}
|
|
3436
|
+
if (!Number.isFinite(low[0])) return null;
|
|
3437
|
+
const base = Math.min(0, low[1]);
|
|
3438
|
+
return {
|
|
3439
|
+
min: [low[0] - 2, base, low[2] - 2],
|
|
3440
|
+
max: [high[0] + 2, Math.max(high[1] + 1.5, base + 2), high[2] + 2],
|
|
3441
|
+
};
|
|
3442
|
+
}
|