create-threenative 0.2.7 → 0.2.9
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/README.md +3 -1
- package/agent-docs/references/assertion-reference.md +87 -35
- package/agent-docs/references/auto-exposure.md +57 -0
- package/agent-docs/references/capability-reference.md +1306 -62
- package/agent-docs/references/debug-surface.md +6 -0
- package/agent-docs/references/finding-assets.md +46 -10
- package/agent-docs/references/performance-basics.md +5 -4
- package/agent-docs/references/terrain-authoring.md +140 -0
- package/agent-files/.agents/skills/threenative-assets/SKILL.md +2 -1
- package/capabilities.json +1505 -79
- package/dist/index.d.ts +28 -3
- package/dist/index.js +402 -167
- package/dist/threenative.js +989 -237
- package/dist/web-engine-buffer-geometry-utils.js +281 -0
- package/dist/web-engine-decal-geometry.js +184 -0
- package/dist/web-engine-gltf-loader.js +196 -0
- package/dist/web-engine-hdr-loader.js +190 -0
- package/dist/web-engine-lut-cube-loader.js +122 -0
- package/dist/web-engine-mesh-bvh-webgpu.js +29 -0
- package/dist/web-engine-mesh-bvh.js +32 -0
- package/dist/web-engine-post-effects.js +168 -0
- package/dist/web-engine-runtime.js +42506 -0
- package/package.json +11 -8
- package/template-assets/autoExposure.ts +225 -0
- package/template-assets/exposure.ts +111 -0
- package/template-assets/exposureGraph.ts +178 -0
- package/template-assets/exposureReadback.ts +79 -0
- package/template-assets/patches/@tailwindcss__node@4.3.3.patch +22 -0
- package/template-assets/patches/three@0.185.1.patch +6594 -700
- package/template-assets/patches/vite@8.2.0.patch +422 -0
- package/template-assets/worldEnvironment.ts +433 -30
- package/templates/action-rpg/AGENTS.md +11 -10
- package/templates/action-rpg/CLAUDE.md +11 -10
- package/templates/action-rpg/package.json +11 -9
- package/templates/action-rpg/playtests/performance.playtest.json +7 -1
- package/templates/action-rpg/src/progress.ts +0 -4
- package/templates/action-rpg/src/render/autoExposure.ts +225 -0
- package/templates/action-rpg/src/render/backlightControls.ts +66 -0
- package/templates/action-rpg/src/render/backlightMaterial.ts +147 -0
- package/templates/action-rpg/src/render/environmentContribution.ts +188 -0
- package/templates/action-rpg/src/render/environmentRadiance.ts +36 -0
- package/templates/action-rpg/src/render/environmentSampleCache.ts +43 -0
- package/templates/action-rpg/src/render/environmentSampling.ts +193 -0
- package/templates/action-rpg/src/render/environmentSnapshot.ts +53 -0
- package/templates/action-rpg/src/render/exposure.ts +111 -0
- package/templates/action-rpg/src/render/exposureGraph.ts +178 -0
- package/templates/action-rpg/src/render/exposureReadback.ts +79 -0
- package/templates/action-rpg/src/render/heightFog.ts +118 -0
- package/templates/action-rpg/src/render/lighting.ts +26 -1
- package/templates/action-rpg/src/render/materialAssignments.ts +160 -0
- package/templates/action-rpg/src/render/materialLighting.ts +155 -0
- package/templates/action-rpg/src/render/postprocessing.ts +17 -2
- package/templates/action-rpg/src/render/quality.ts +61 -2
- package/templates/action-rpg/src/render/sky.ts +21 -1
- package/templates/action-rpg/src/render/vfx.ts +133 -58
- package/templates/action-rpg/src/render/worldEnvironment.ts +433 -30
- package/templates/action-rpg/src/scenes/Play.ts +81 -16
- package/templates/action-rpg/threenative.config.ts +3 -0
- package/templates/action-rpg/vite.config.ts +10 -2
- package/templates/minimal/AGENTS.md +9 -10
- package/templates/minimal/CLAUDE.md +9 -10
- package/templates/minimal/package.json +9 -8
- package/templates/minimal/playtests/play.playtest.json +7 -1
- package/templates/minimal/playtests/sky.playtest.json +10 -1
- package/templates/minimal/src/render/autoExposure.ts +225 -0
- package/templates/minimal/src/render/backlightControls.ts +66 -0
- package/templates/minimal/src/render/backlightMaterial.ts +147 -0
- package/templates/minimal/src/render/environmentContribution.ts +188 -0
- package/templates/minimal/src/render/environmentRadiance.ts +36 -0
- package/templates/minimal/src/render/environmentSampleCache.ts +43 -0
- package/templates/minimal/src/render/environmentSampling.ts +193 -0
- package/templates/minimal/src/render/environmentSnapshot.ts +53 -0
- package/templates/minimal/src/render/exposure.ts +111 -0
- package/templates/minimal/src/render/exposureGraph.ts +178 -0
- package/templates/minimal/src/render/exposureReadback.ts +79 -0
- package/templates/minimal/src/render/heightFog.ts +118 -0
- package/templates/minimal/src/render/lighting.ts +25 -1
- package/templates/minimal/src/render/materialAssignments.ts +102 -0
- package/templates/minimal/src/render/materialLighting.ts +146 -0
- package/templates/minimal/src/render/postprocessing.ts +16 -2
- package/templates/minimal/src/render/quality.ts +60 -2
- package/templates/minimal/src/render/sky.ts +21 -1
- package/templates/minimal/src/render/worldEnvironment.ts +433 -30
- package/templates/minimal/src/scenes/Play.ts +50 -1
- package/templates/minimal/vite.config.ts +10 -2
- package/templates/platformer/AGENTS.md +7 -5
- package/templates/platformer/CLAUDE.md +7 -5
- package/templates/platformer/package.json +11 -9
- package/templates/platformer/playtests/performance.playtest.json +7 -1
- package/templates/platformer/src/render/autoExposure.ts +225 -0
- package/templates/platformer/src/render/backlightControls.ts +66 -0
- package/templates/platformer/src/render/backlightMaterial.ts +147 -0
- package/templates/platformer/src/render/environmentContribution.ts +188 -0
- package/templates/platformer/src/render/environmentRadiance.ts +36 -0
- package/templates/platformer/src/render/environmentSampleCache.ts +43 -0
- package/templates/platformer/src/render/environmentSampling.ts +193 -0
- package/templates/platformer/src/render/environmentSnapshot.ts +53 -0
- package/templates/platformer/src/render/exposure.ts +111 -0
- package/templates/platformer/src/render/exposureGraph.ts +178 -0
- package/templates/platformer/src/render/exposureReadback.ts +79 -0
- package/templates/platformer/src/render/heightFog.ts +118 -0
- package/templates/platformer/src/render/lighting.ts +26 -1
- package/templates/platformer/src/render/materialAssignments.ts +160 -0
- package/templates/platformer/src/render/materialLighting.ts +155 -0
- package/templates/platformer/src/render/materials.ts +7 -2
- package/templates/platformer/src/render/palette.ts +3 -3
- package/templates/platformer/src/render/postprocessing.ts +17 -2
- package/templates/platformer/src/render/quality.ts +61 -2
- package/templates/platformer/src/render/sky.ts +72 -23
- package/templates/platformer/src/render/skyEnvironment.ts +50 -0
- package/templates/platformer/src/render/worldEnvironment.ts +433 -30
- package/templates/platformer/src/scenes/Play.ts +70 -6
- package/templates/platformer/vite.config.ts +10 -2
- package/templates/puzzle/AGENTS.md +10 -9
- package/templates/puzzle/CLAUDE.md +10 -9
- package/templates/puzzle/package.json +11 -9
- package/templates/puzzle/playtests/boot-failure.playtest.json +2 -2
- package/templates/puzzle/playtests/lit.playtest.json +7 -1
- package/templates/puzzle/playtests/performance.playtest.json +7 -1
- package/templates/puzzle/src/render/autoExposure.ts +225 -0
- package/templates/puzzle/src/render/backlightControls.ts +66 -0
- package/templates/puzzle/src/render/backlightMaterial.ts +147 -0
- package/templates/puzzle/src/render/environmentContribution.ts +188 -0
- package/templates/puzzle/src/render/environmentRadiance.ts +36 -0
- package/templates/puzzle/src/render/environmentSampleCache.ts +43 -0
- package/templates/puzzle/src/render/environmentSampling.ts +193 -0
- package/templates/puzzle/src/render/environmentSnapshot.ts +53 -0
- package/templates/puzzle/src/render/exposure.ts +111 -0
- package/templates/puzzle/src/render/exposureGraph.ts +178 -0
- package/templates/puzzle/src/render/exposureReadback.ts +79 -0
- package/templates/puzzle/src/render/heightFog.ts +118 -0
- package/templates/puzzle/src/render/lighting.ts +33 -1
- package/templates/puzzle/src/render/materialAssignments.ts +160 -0
- package/templates/puzzle/src/render/materialLighting.ts +155 -0
- package/templates/puzzle/src/render/materials.ts +1 -1
- package/templates/puzzle/src/render/postprocessing.ts +8 -2
- package/templates/puzzle/src/render/quality.ts +62 -1
- package/templates/puzzle/src/render/sky.ts +20 -1
- package/templates/puzzle/src/render/worldEnvironment.ts +433 -30
- package/templates/puzzle/src/scenes/Play.ts +51 -2
- package/templates/puzzle/vite.config.ts +10 -2
- package/templates/racing/AGENTS.md +8 -7
- package/templates/racing/CLAUDE.md +8 -7
- package/templates/racing/package.json +11 -9
- package/templates/racing/playtests/performance.playtest.json +7 -1
- package/templates/racing/playtests/survives.playtest.json +6 -0
- package/templates/racing/src/render/autoExposure.ts +225 -0
- package/templates/racing/src/render/backlightControls.ts +66 -0
- package/templates/racing/src/render/backlightMaterial.ts +147 -0
- package/templates/racing/src/render/environmentContribution.ts +188 -0
- package/templates/racing/src/render/environmentRadiance.ts +36 -0
- package/templates/racing/src/render/environmentSampleCache.ts +43 -0
- package/templates/racing/src/render/environmentSampling.ts +193 -0
- package/templates/racing/src/render/environmentSnapshot.ts +53 -0
- package/templates/racing/src/render/exposure.ts +111 -0
- package/templates/racing/src/render/exposureGraph.ts +178 -0
- package/templates/racing/src/render/exposureReadback.ts +79 -0
- package/templates/racing/src/render/heightFog.ts +118 -0
- package/templates/racing/src/render/lighting.ts +29 -1
- package/templates/racing/src/render/materialAssignments.ts +160 -0
- package/templates/racing/src/render/materialLighting.ts +155 -0
- package/templates/racing/src/render/palette.ts +1 -10
- package/templates/racing/src/render/postprocessing.ts +17 -2
- package/templates/racing/src/render/quality.ts +61 -2
- package/templates/racing/src/render/shapes.ts +0 -25
- package/templates/racing/src/render/sky.ts +21 -1
- package/templates/racing/src/render/worldEnvironment.ts +433 -30
- package/templates/racing/src/scenes/Race.ts +91 -3
- package/templates/racing/src/track/circuit.ts +0 -9
- package/templates/racing/vite.config.ts +10 -2
- package/templates/rain/.codex/config.toml +19 -0
- package/templates/rain/.cursor/mcp.json +32 -0
- package/templates/rain/.gemini/settings.json +32 -0
- package/templates/rain/.mcp.json +32 -0
- package/templates/rain/.vscode/mcp.json +36 -0
- package/templates/rain/.zed/settings.json +36 -0
- package/templates/rain/AGENTS.md +95 -0
- package/templates/rain/CLAUDE.md +97 -0
- package/templates/rain/assets/rain-loop.wav +0 -0
- package/templates/rain/assets/thunder.wav +0 -0
- package/templates/rain/assets/wind-loop.wav +0 -0
- package/templates/rain/index.html +18 -0
- package/templates/rain/kit.json +7 -0
- package/templates/rain/native-playtests/boot.playtest.json +23 -0
- package/templates/rain/native-playtests/lightning.playtest.json +173 -0
- package/templates/rain/opencode.json +41 -0
- package/templates/rain/package.json +59 -0
- package/templates/rain/playtests/auto-lightning-clear.playtest.json +66 -0
- package/templates/rain/playtests/auto-lightning.playtest.json +26 -0
- package/templates/rain/playtests/automation.playtest.json +133 -0
- package/templates/rain/playtests/cinematic.playtest.json +59 -0
- package/templates/rain/playtests/flash.playtest.json +27 -0
- package/templates/rain/playtests/fly.playtest.json +54 -0
- package/templates/rain/playtests/lightning.playtest.json +220 -0
- package/templates/rain/playtests/loading.playtest.json +57 -0
- package/templates/rain/playtests/paused.playtest.json +59 -0
- package/templates/rain/playtests/performance.playtest.json +32 -0
- package/templates/rain/playtests/reduced-motion.playtest.json +87 -0
- package/templates/rain/playtests/simulation.playtest.json +20 -0
- package/templates/rain/playtests/storm.playtest.json +150 -0
- package/templates/rain/playtests/survives.playtest.json +58 -0
- package/templates/rain/playtests/tiers.playtest.json +194 -0
- package/templates/rain/playtests/weather.playtest.json +77 -0
- package/templates/rain/public/favicon.svg +5 -0
- package/templates/rain/src/audio/storm.ts +314 -0
- package/templates/rain/src/game.ts +81 -0
- package/templates/rain/src/main.ts +15 -0
- package/templates/rain/src/render/autoExposure.ts +225 -0
- package/templates/rain/src/render/bloom-shader.ts +65 -0
- package/templates/rain/src/render/camera.ts +160 -0
- package/templates/rain/src/render/clouds-shader.ts +242 -0
- package/templates/rain/src/render/clouds.ts +142 -0
- package/templates/rain/src/render/exposure.ts +111 -0
- package/templates/rain/src/render/exposureGraph.ts +178 -0
- package/templates/rain/src/render/exposureReadback.ts +79 -0
- package/templates/rain/src/render/lighting.ts +39 -0
- package/templates/rain/src/render/lightning.ts +360 -0
- package/templates/rain/src/render/loading.ts +327 -0
- package/templates/rain/src/render/materials.ts +19 -0
- package/templates/rain/src/render/noise-volume.ts +159 -0
- package/templates/rain/src/render/palette.ts +18 -0
- package/templates/rain/src/render/post-shader.ts +178 -0
- package/templates/rain/src/render/postprocessing.ts +229 -0
- package/templates/rain/src/render/quality.ts +161 -0
- package/templates/rain/src/render/rain.ts +299 -0
- package/templates/rain/src/render/sky.ts +28 -0
- package/templates/rain/src/render/world-shader.ts +680 -0
- package/templates/rain/src/render/world.ts +146 -0
- package/templates/rain/src/render/worldEnvironment.ts +1212 -0
- package/templates/rain/src/scenes/Boot.ts +348 -0
- package/templates/rain/src/state.ts +261 -0
- package/templates/rain/src/style.css +1160 -0
- package/templates/rain/src/ui/App.tsx +29 -0
- package/templates/rain/src/ui/GameUi.tsx +187 -0
- package/templates/rain/src/ui/Hud.tsx +327 -0
- package/templates/rain/src/ui/LoadingOverlay.tsx +46 -0
- package/templates/rain/src/ui/Menu.tsx +370 -0
- package/templates/rain/src/ui/automation.ts +60 -0
- package/templates/rain/src/ui/main.tsx +7 -0
- package/templates/rain/src/ui/tempest.ts +149 -0
- package/templates/rain/tailwind.config.ts +2 -0
- package/templates/rain/threenative.config.ts +66 -0
- package/templates/rain/tools/generate-shaders.mjs +656 -0
- package/templates/rain/tools/make-storm-audio.mjs +387 -0
- package/templates/rain/tools/storm-dsp.mjs +177 -0
- package/templates/rain/tools/tempest-bloom.frag +10 -0
- package/templates/rain/tools/tempest-clouds.frag +86 -0
- package/templates/rain/tools/tempest-post.frag +47 -0
- package/templates/rain/tools/tempest-world.frag +210 -0
- package/templates/rain/tools/verify-noise-volume.mjs +61 -0
- package/templates/rain/tsconfig.json +17 -0
- package/templates/rain/vite.config.ts +45 -0
- package/templates/rts/AGENTS.md +10 -11
- package/templates/rts/CLAUDE.md +10 -11
- package/templates/rts/package.json +10 -8
- package/templates/rts/playtests/performance.playtest.json +7 -1
- package/templates/rts/playtests/rts-ai-attack.playtest.json +10 -1
- package/templates/rts/playtests/rts-attack.playtest.json +10 -1
- package/templates/rts/playtests/rts-build.playtest.json +10 -1
- package/templates/rts/playtests/rts-orders.playtest.json +7 -1
- package/templates/rts/playtests/rts-train.playtest.json +10 -1
- package/templates/rts/src/render/army.ts +10 -2
- package/templates/rts/src/render/autoExposure.ts +225 -0
- package/templates/rts/src/render/backlightControls.ts +66 -0
- package/templates/rts/src/render/backlightMaterial.ts +147 -0
- package/templates/rts/src/render/environmentContribution.ts +188 -0
- package/templates/rts/src/render/environmentRadiance.ts +36 -0
- package/templates/rts/src/render/environmentSampleCache.ts +43 -0
- package/templates/rts/src/render/environmentSampling.ts +193 -0
- package/templates/rts/src/render/environmentSnapshot.ts +53 -0
- package/templates/rts/src/render/exposure.ts +111 -0
- package/templates/rts/src/render/exposureGraph.ts +178 -0
- package/templates/rts/src/render/exposureReadback.ts +79 -0
- package/templates/rts/src/render/heightFog.ts +118 -0
- package/templates/rts/src/render/lighting.ts +26 -1
- package/templates/rts/src/render/materialAssignments.ts +160 -0
- package/templates/rts/src/render/materialLighting.ts +155 -0
- package/templates/rts/src/render/postprocessing.ts +8 -2
- package/templates/rts/src/render/quality.ts +61 -2
- package/templates/rts/src/render/sky.ts +21 -1
- package/templates/rts/src/render/worldEnvironment.ts +433 -30
- package/templates/rts/src/scenes/Play.ts +54 -3
- package/templates/rts/src/sim/ai.ts +0 -1
- package/templates/rts/src/sim/terrain.ts +0 -4
- package/templates/rts/vite.config.ts +10 -2
- package/templates/runner/AGENTS.md +10 -8
- package/templates/runner/CLAUDE.md +10 -8
- package/templates/runner/package.json +11 -9
- package/templates/runner/playtests/performance.playtest.json +10 -1
- package/templates/runner/src/physics.ts +0 -1
- package/templates/runner/src/render/autoExposure.ts +225 -0
- package/templates/runner/src/render/backlightControls.ts +66 -0
- package/templates/runner/src/render/backlightMaterial.ts +147 -0
- package/templates/runner/src/render/environmentContribution.ts +188 -0
- package/templates/runner/src/render/environmentRadiance.ts +36 -0
- package/templates/runner/src/render/environmentSampleCache.ts +43 -0
- package/templates/runner/src/render/environmentSampling.ts +193 -0
- package/templates/runner/src/render/environmentSnapshot.ts +53 -0
- package/templates/runner/src/render/exposure.ts +111 -0
- package/templates/runner/src/render/exposureGraph.ts +178 -0
- package/templates/runner/src/render/exposureReadback.ts +79 -0
- package/templates/runner/src/render/heightFog.ts +118 -0
- package/templates/runner/src/render/lighting.ts +26 -1
- package/templates/runner/src/render/materialAssignments.ts +160 -0
- package/templates/runner/src/render/materialLighting.ts +155 -0
- package/templates/runner/src/render/postprocessing.ts +17 -2
- package/templates/runner/src/render/quality.ts +61 -2
- package/templates/runner/src/render/sky.ts +21 -1
- package/templates/runner/src/render/worldEnvironment.ts +433 -30
- package/templates/runner/src/scenes/Run.ts +67 -2
- package/templates/runner/threenative.config.ts +3 -0
- package/templates/runner/vite.config.ts +10 -2
- package/templates/sailing/AGENTS.md +14 -13
- package/templates/sailing/CLAUDE.md +14 -13
- package/templates/sailing/native-playtests/survives.playtest.json +7 -0
- package/templates/sailing/package.json +11 -9
- package/templates/sailing/playtests/live/render-motion.playtest.json +30 -0
- package/templates/sailing/src/entities/Ship.ts +38 -18
- package/templates/sailing/src/render/autoExposure.ts +225 -0
- package/templates/sailing/src/render/backlightControls.ts +66 -0
- package/templates/sailing/src/render/backlightMaterial.ts +147 -0
- package/templates/sailing/src/render/camera.ts +12 -4
- package/templates/sailing/src/render/environmentContribution.ts +188 -0
- package/templates/sailing/src/render/environmentRadiance.ts +36 -0
- package/templates/sailing/src/render/environmentSampleCache.ts +43 -0
- package/templates/sailing/src/render/environmentSampling.ts +193 -0
- package/templates/sailing/src/render/environmentSetup.ts +24 -0
- package/templates/sailing/src/render/environmentSnapshot.ts +53 -0
- package/templates/sailing/src/render/exposure.ts +111 -0
- package/templates/sailing/src/render/exposureGraph.ts +178 -0
- package/templates/sailing/src/render/exposureReadback.ts +79 -0
- package/templates/sailing/src/render/heightFog.ts +118 -0
- package/templates/sailing/src/render/lighting.ts +26 -1
- package/templates/sailing/src/render/materialAssignments.ts +160 -0
- package/templates/sailing/src/render/materialLighting.ts +155 -0
- package/templates/sailing/src/render/ocean.ts +71 -53
- package/templates/sailing/src/render/postprocessing.ts +16 -2
- package/templates/sailing/src/render/props.ts +0 -45
- package/templates/sailing/src/render/quality.ts +61 -1
- package/templates/sailing/src/render/sky.ts +21 -1
- package/templates/sailing/src/render/worldEnvironment.ts +433 -30
- package/templates/sailing/src/scenes/Boot.ts +12 -1
- package/templates/sailing/src/scenes/Sailing.ts +87 -2
- package/templates/sailing/src/scenes/ocean-readiness.ts +68 -0
- package/templates/sailing/threenative.config.ts +3 -0
- package/templates/sailing/vite.config.ts +10 -2
- package/templates/shooter/AGENTS.md +8 -6
- package/templates/shooter/CLAUDE.md +8 -6
- package/templates/shooter/package.json +11 -9
- package/templates/shooter/playtests/performance.playtest.json +7 -1
- package/templates/shooter/src/entities/Enemy.ts +0 -15
- package/templates/shooter/src/entities/Rifle.ts +38 -1
- package/templates/shooter/src/render/autoExposure.ts +225 -0
- package/templates/shooter/src/render/backlightControls.ts +66 -0
- package/templates/shooter/src/render/backlightMaterial.ts +147 -0
- package/templates/shooter/src/render/camera.ts +1 -12
- package/templates/shooter/src/render/decals.ts +299 -5
- package/templates/shooter/src/render/environmentContribution.ts +188 -0
- package/templates/shooter/src/render/environmentRadiance.ts +36 -0
- package/templates/shooter/src/render/environmentSampleCache.ts +43 -0
- package/templates/shooter/src/render/environmentSampling.ts +193 -0
- package/templates/shooter/src/render/environmentSnapshot.ts +53 -0
- package/templates/shooter/src/render/exposure.ts +111 -0
- package/templates/shooter/src/render/exposureGraph.ts +178 -0
- package/templates/shooter/src/render/exposureReadback.ts +79 -0
- package/templates/shooter/src/render/gunfx.ts +0 -1
- package/templates/shooter/src/render/heightFog.ts +118 -0
- package/templates/shooter/src/render/lighting.ts +26 -1
- package/templates/shooter/src/render/materialAssignments.ts +160 -0
- package/templates/shooter/src/render/materialLighting.ts +155 -0
- package/templates/shooter/src/render/postprocessing.ts +17 -2
- package/templates/shooter/src/render/quality.ts +61 -2
- package/templates/shooter/src/render/scale.ts +2 -93
- package/templates/shooter/src/render/sky.ts +21 -1
- package/templates/shooter/src/render/vehicles.ts +0 -17
- package/templates/shooter/src/render/worldEnvironment.ts +433 -30
- package/templates/shooter/src/scenes/Play.ts +64 -2
- package/templates/shooter/vite.config.ts +10 -2
- package/templates/snow/.codex/config.toml +19 -0
- package/templates/snow/.cursor/mcp.json +32 -0
- package/templates/snow/.gemini/settings.json +32 -0
- package/templates/snow/.mcp.json +32 -0
- package/templates/snow/.vscode/mcp.json +36 -0
- package/templates/snow/.zed/settings.json +36 -0
- package/templates/snow/AGENTS.md +90 -0
- package/templates/snow/CLAUDE.md +92 -0
- package/templates/snow/README.md +26 -0
- package/templates/snow/assets/crunch.wav +0 -0
- package/templates/snow/assets/wind.wav +0 -0
- package/templates/snow/index.html +12 -0
- package/templates/snow/kit.json +7 -0
- package/templates/snow/native-playtests/snow-physics.playtest.json +150 -0
- package/templates/snow/native-playtests/survives.playtest.json +47 -0
- package/templates/snow/opencode.json +41 -0
- package/templates/snow/package.json +60 -0
- package/templates/snow/playtests/footsteps.playtest.json +95 -0
- package/templates/snow/playtests/performance.playtest.json +36 -0
- package/templates/snow/playtests/snow-physics.playtest.json +154 -0
- package/templates/snow/playtests/survives.playtest.json +56 -0
- package/templates/snow/playtests/touch-controls.playtest.json +71 -0
- package/templates/snow/playtests/weather.playtest.json +119 -0
- package/templates/snow/public/favicon.svg +5 -0
- package/templates/snow/src/audio.ts +58 -0
- package/templates/snow/src/commands.ts +8 -0
- package/templates/snow/src/entities/Explorer.ts +279 -0
- package/templates/snow/src/game.ts +69 -0
- package/templates/snow/src/main.ts +15 -0
- package/templates/snow/src/render/autoExposure.ts +225 -0
- package/templates/snow/src/render/backlightControls.ts +66 -0
- package/templates/snow/src/render/backlightMaterial.ts +147 -0
- package/templates/snow/src/render/bootPrint.ts +50 -0
- package/templates/snow/src/render/camera.ts +84 -0
- package/templates/snow/src/render/environmentContribution.ts +188 -0
- package/templates/snow/src/render/environmentRadiance.ts +36 -0
- package/templates/snow/src/render/environmentSampleCache.ts +43 -0
- package/templates/snow/src/render/environmentSampling.ts +193 -0
- package/templates/snow/src/render/environmentSnapshot.ts +53 -0
- package/templates/snow/src/render/explorer.ts +321 -0
- package/templates/snow/src/render/exposure.ts +111 -0
- package/templates/snow/src/render/exposureGraph.ts +178 -0
- package/templates/snow/src/render/exposureReadback.ts +79 -0
- package/templates/snow/src/render/heightFog.ts +118 -0
- package/templates/snow/src/render/lighting.ts +82 -0
- package/templates/snow/src/render/loading.ts +325 -0
- package/templates/snow/src/render/materialAssignments.ts +160 -0
- package/templates/snow/src/render/materialLighting.ts +155 -0
- package/templates/snow/src/render/materials.ts +36 -0
- package/templates/snow/src/render/palette.ts +17 -0
- package/templates/snow/src/render/postprocessing.ts +58 -0
- package/templates/snow/src/render/props.ts +42 -0
- package/templates/snow/src/render/quality.ts +193 -0
- package/templates/snow/src/render/scenery.ts +244 -0
- package/templates/snow/src/render/sky.ts +76 -0
- package/templates/snow/src/render/snowSurface.ts +259 -0
- package/templates/snow/src/render/touch-controls.ts +143 -0
- package/templates/snow/src/render/weather.ts +279 -0
- package/templates/snow/src/render/worldEnvironment.ts +1212 -0
- package/templates/snow/src/scenes/Boot.ts +12 -0
- package/templates/snow/src/scenes/Snow.ts +663 -0
- package/templates/snow/src/state.ts +46 -0
- package/templates/snow/src/style.css +143 -0
- package/templates/snow/src/terrain.ts +64 -0
- package/templates/snow/src/ui/App.tsx +15 -0
- package/templates/snow/src/ui/Controls.tsx +322 -0
- package/templates/snow/src/ui/GameUi.tsx +354 -0
- package/templates/snow/src/ui/icons.tsx +54 -0
- package/templates/snow/src/ui/main.tsx +7 -0
- package/templates/snow/tailwind.config.ts +2 -0
- package/templates/snow/threenative.config.ts +54 -0
- package/templates/snow/tsconfig.json +17 -0
- package/templates/snow/vite.config.ts +45 -0
- package/templates/starter/AGENTS.md +11 -16
- package/templates/starter/CLAUDE.md +11 -16
- package/templates/starter/native-playtests/react-hud.playtest.json +1 -1
- package/templates/starter/native-playtests/render-chain.playtest.json +51 -8
- package/templates/starter/native-playtests/smooth-motion.playtest.json +64 -0
- package/templates/starter/package.json +11 -9
- package/templates/starter/playtests/live/smooth-motion.playtest.json +63 -0
- package/templates/starter/playtests/movement.playtest.json +192 -0
- package/templates/starter/playtests/play.playtest.json +18 -2
- package/templates/starter/playtests/production-readiness.playtest.json +1 -1
- package/templates/starter/public/grade.cube +735 -0
- package/templates/starter/src/entities/Crate.ts +4 -0
- package/templates/starter/src/entities/Player.ts +79 -18
- package/templates/starter/src/game.ts +1 -0
- package/templates/starter/src/render/adaptiveQuality.ts +28 -41
- package/templates/starter/src/render/autoExposure.ts +225 -0
- package/templates/starter/src/render/backlightControls.ts +66 -0
- package/templates/starter/src/render/backlightMaterial.ts +147 -0
- package/templates/starter/src/render/environmentContribution.ts +188 -0
- package/templates/starter/src/render/environmentRadiance.ts +36 -0
- package/templates/starter/src/render/environmentSampleCache.ts +43 -0
- package/templates/starter/src/render/environmentSampling.ts +193 -0
- package/templates/starter/src/render/environmentSnapshot.ts +53 -0
- package/templates/starter/src/render/exposure.ts +111 -0
- package/templates/starter/src/render/exposureGraph.ts +178 -0
- package/templates/starter/src/render/exposureReadback.ts +79 -0
- package/templates/starter/src/render/grade.ts +157 -0
- package/templates/starter/src/render/heightFog.ts +118 -0
- package/templates/starter/src/render/lighting.ts +26 -1
- package/templates/starter/src/render/materialAssignments.ts +160 -0
- package/templates/starter/src/render/materialLighting.ts +155 -0
- package/templates/starter/src/render/postprocessing.ts +84 -4
- package/templates/starter/src/render/quality.ts +80 -8
- package/templates/starter/src/render/qualityPolicy.ts +54 -0
- package/templates/starter/src/render/rendererGate.ts +36 -0
- package/templates/starter/src/render/sky.ts +23 -1
- package/templates/starter/src/render/temporalAA.ts +197 -0
- package/templates/starter/src/render/temporalAAFrame.ts +179 -0
- package/templates/starter/src/render/temporalAAHooks.ts +101 -0
- package/templates/starter/src/render/temporalAAInput.ts +56 -0
- package/templates/starter/src/render/temporalAAResolve.ts +65 -0
- package/templates/starter/src/render/temporalAAStage.ts +76 -0
- package/templates/starter/src/render/temporalCurrentArea.ts +31 -0
- package/templates/starter/src/render/temporalCurrentFootprint.ts +198 -0
- package/templates/starter/src/render/temporalCurrentFootprintMath.ts +41 -0
- package/templates/starter/src/render/temporalCurrentProducer.ts +161 -0
- package/templates/starter/src/render/temporalCurrentReplay.ts +160 -0
- package/templates/starter/src/render/temporalCurrentSelection.ts +89 -0
- package/templates/starter/src/render/temporalCurrentVisibility.ts +170 -0
- package/templates/starter/src/render/temporalDepthSamples.ts +34 -0
- package/templates/starter/src/render/temporalRejectionCounter.ts +179 -0
- package/templates/starter/src/render/temporalResolve.ts +139 -0
- package/templates/starter/src/render/temporalResolveDepth.ts +193 -0
- package/templates/starter/src/render/temporalResolveMath.ts +196 -0
- package/templates/starter/src/render/volumetricFog.ts +124 -0
- package/templates/starter/src/render/volumetricFogOptions.ts +96 -0
- package/templates/starter/src/render/volumetricFogTransport.ts +176 -0
- package/templates/starter/src/render/volumetricFogVolume.ts +139 -0
- package/templates/starter/src/render/worldEnvironment.ts +433 -30
- package/templates/starter/src/scenes/Play.ts +110 -1
- package/templates/starter/src/state.ts +1 -0
- package/templates/starter/src/ui/Hud.tsx +1 -1
- package/templates/starter/src/ui/Menu.tsx +1 -1
- package/templates/starter/tools/make-grade-lut.mjs +101 -0
- package/templates/starter/vite.config.ts +10 -2
- package/templates/tower-defense/AGENTS.md +10 -9
- package/templates/tower-defense/CLAUDE.md +10 -9
- package/templates/tower-defense/package.json +11 -9
- package/templates/tower-defense/playtests/performance.playtest.json +7 -1
- package/templates/tower-defense/src/render/autoExposure.ts +225 -0
- package/templates/tower-defense/src/render/backlightControls.ts +66 -0
- package/templates/tower-defense/src/render/backlightMaterial.ts +147 -0
- package/templates/tower-defense/src/render/environmentContribution.ts +188 -0
- package/templates/tower-defense/src/render/environmentRadiance.ts +36 -0
- package/templates/tower-defense/src/render/environmentSampleCache.ts +43 -0
- package/templates/tower-defense/src/render/environmentSampling.ts +193 -0
- package/templates/tower-defense/src/render/environmentSnapshot.ts +53 -0
- package/templates/tower-defense/src/render/exposure.ts +111 -0
- package/templates/tower-defense/src/render/exposureGraph.ts +178 -0
- package/templates/tower-defense/src/render/exposureReadback.ts +79 -0
- package/templates/tower-defense/src/render/lighting.ts +33 -1
- package/templates/tower-defense/src/render/materialAssignments.ts +160 -0
- package/templates/tower-defense/src/render/materialLighting.ts +155 -0
- package/templates/tower-defense/src/render/postprocessing.ts +8 -2
- package/templates/tower-defense/src/render/quality.ts +61 -2
- package/templates/tower-defense/src/render/shapes.ts +0 -3
- package/templates/tower-defense/src/render/worldEnvironment.ts +433 -30
- package/templates/tower-defense/src/scenes/Battle.ts +65 -2
- package/templates/tower-defense/vite.config.ts +10 -2
- package/templates/minimal/src/scenes/Boot.ts +0 -5
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
// Generated for you. Ordinary Three.js, and one lightning bolt lives in this file.
|
|
2
|
+
//
|
|
3
|
+
// The reference study drew a strike as CPU geometry: a seeded generator walks a 30 segment channel
|
|
4
|
+
// from a random point in the sky down to a ground point, throwing off short side branches as it
|
|
5
|
+
// goes, and each segment becomes a quad carrying its own two endpoints. The vertex stage projects
|
|
6
|
+
// those two endpoints by hand and widens the quad across the segment in screen space, so the ribbon
|
|
7
|
+
// is always camera facing and always the same number of pixels wide however far away it is; the
|
|
8
|
+
// fragment stage is one gaussian core inside one wide halo. Nothing is simulated — a strike is
|
|
9
|
+
// geometry that already exists, and it is only visible while the caller's flash envelope is above
|
|
10
|
+
// zero.
|
|
11
|
+
//
|
|
12
|
+
// The engine owns the frame loop, the scene and the renderer, so this file owns the bolt geometry,
|
|
13
|
+
// its uniforms and its own lifetime — and draws nothing itself. No render loop, no raw GL, no
|
|
14
|
+
// engine package import, so the same file runs wherever the game runs.
|
|
15
|
+
// Conventions: one world unit is one metre, so a strike lands at a real point on the coast.
|
|
16
|
+
import {
|
|
17
|
+
AdditiveBlending,
|
|
18
|
+
BufferAttribute,
|
|
19
|
+
BufferGeometry,
|
|
20
|
+
DoubleSide,
|
|
21
|
+
DynamicDrawUsage,
|
|
22
|
+
Mesh,
|
|
23
|
+
type PerspectiveCamera,
|
|
24
|
+
type Scene,
|
|
25
|
+
Vector3,
|
|
26
|
+
} from "three";
|
|
27
|
+
import {
|
|
28
|
+
Fn,
|
|
29
|
+
abs,
|
|
30
|
+
attribute,
|
|
31
|
+
cameraFar,
|
|
32
|
+
cameraNear,
|
|
33
|
+
clamp,
|
|
34
|
+
dot,
|
|
35
|
+
exp,
|
|
36
|
+
float,
|
|
37
|
+
frameGroup,
|
|
38
|
+
max,
|
|
39
|
+
mix,
|
|
40
|
+
normalize,
|
|
41
|
+
positionGeometry,
|
|
42
|
+
screenSize,
|
|
43
|
+
select,
|
|
44
|
+
uniform,
|
|
45
|
+
varying,
|
|
46
|
+
vec2,
|
|
47
|
+
vec3,
|
|
48
|
+
vec4,
|
|
49
|
+
} from "three/tsl";
|
|
50
|
+
import { MeshBasicNodeMaterial, type Node } from "three/webgpu";
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Room for one bolt's worst case: the study's 30 channel segments, plus every branch it can throw.
|
|
54
|
+
* A branch starts at one of the interior channel points and is at most 9 segments long, so this is
|
|
55
|
+
* the true ceiling rather than a guess. The buffers are allocated once and reused, so a strike never
|
|
56
|
+
* reallocates a geometry and never orphans a GPU buffer.
|
|
57
|
+
*/
|
|
58
|
+
const MAX_SEGMENTS = 30 + 24 * 9;
|
|
59
|
+
const VERTICES_PER_SEGMENT = 6;
|
|
60
|
+
|
|
61
|
+
/** The two-triangle corner pattern the study's `boltGeometry` wrote, as three-component positions. */
|
|
62
|
+
const SEGMENT_CORNERS = new Float32Array([-1, 0, 0, 1, 0, 0, -1, 1, 0, -1, 1, 0, 1, 0, 0, 1, 1, 0]);
|
|
63
|
+
const CORNERS = new Float32Array(MAX_SEGMENTS * SEGMENT_CORNERS.length);
|
|
64
|
+
for (let at = 0; at < CORNERS.length; at += SEGMENT_CORNERS.length) {
|
|
65
|
+
CORNERS.set(SEGMENT_CORNERS, at);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** One segment of ribbon: its own two world endpoints and how bright it burns. */
|
|
69
|
+
export interface IBoltSegment {
|
|
70
|
+
readonly a: Vector3;
|
|
71
|
+
readonly b: Vector3;
|
|
72
|
+
/** 1 down the main channel, decaying towards nothing at the tip of a branch. */
|
|
73
|
+
readonly strength: number;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** One bolt, as the study's `makeBolt` returned it. */
|
|
77
|
+
export interface IBolt {
|
|
78
|
+
readonly segments: IBoltSegment[];
|
|
79
|
+
/** Where the bolt entered the sky, in metres — the caller's point for scene glow and thunder. */
|
|
80
|
+
readonly origin: Vector3;
|
|
81
|
+
readonly end: Vector3;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** The study's `mix`: `a + (b - a) * t`. */
|
|
85
|
+
function lerp(a: number, b: number, t: number): number {
|
|
86
|
+
return a + (b - a) * t;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The study's own `makeBolt`, constant for constant. `end` is the point on the ground the bolt
|
|
91
|
+
* strikes; `random` is the caller's, so the same source replayed gives the same bolt.
|
|
92
|
+
*
|
|
93
|
+
* The channel starts in the sky between 145 and 245 metres up, jittered around `end`, and walks down
|
|
94
|
+
* in 30 steps whose lateral jitter shrinks as it falls (`1 - f`), so a bolt reads as a strike
|
|
95
|
+
* tightening on its target rather than a random walk. Branches come off the middle of the channel
|
|
96
|
+
* only (`i > 3 && i < n - 3`), run to one side, and stop at the ground.
|
|
97
|
+
*/
|
|
98
|
+
export function makeBolt(end: Vector3, random: () => number): IBolt {
|
|
99
|
+
const segments: IBoltSegment[] = [];
|
|
100
|
+
const y = 145 + random() * 100;
|
|
101
|
+
let a = new Vector3(end.x + random() * 42 - 21, y, end.z + random() * 18 - 9);
|
|
102
|
+
const origin = a.clone();
|
|
103
|
+
const n = 30;
|
|
104
|
+
|
|
105
|
+
for (let i = 1; i <= n; i++) {
|
|
106
|
+
const f = i / n;
|
|
107
|
+
const b = new Vector3(
|
|
108
|
+
lerp(origin.x, end.x, f) + (random() - 0.5) * 13 * (1 - f),
|
|
109
|
+
lerp(y, end.y, f),
|
|
110
|
+
lerp(origin.z, end.z, f) + (random() - 0.5) * 8 * (1 - f),
|
|
111
|
+
);
|
|
112
|
+
segments.push({ a: a.clone(), b: b.clone(), strength: 1 });
|
|
113
|
+
|
|
114
|
+
if (i > 3 && i < n - 3 && random() < 0.39) {
|
|
115
|
+
const c = a.clone();
|
|
116
|
+
const dir = random() < 0.5 ? -1 : 1;
|
|
117
|
+
const length = 4 + Math.floor(random() * 6);
|
|
118
|
+
for (let j = 0; j < length && segments.length < MAX_SEGMENTS; j++) {
|
|
119
|
+
const d = new Vector3(
|
|
120
|
+
c.x + dir * (3 + random() * 10),
|
|
121
|
+
c.y - 3 - random() * 9,
|
|
122
|
+
c.z + (random() - 0.5) * 8,
|
|
123
|
+
);
|
|
124
|
+
if (d.y < 2) break;
|
|
125
|
+
segments.push({ a: c.clone(), b: d.clone(), strength: 0.45 * (1 - j / 12) });
|
|
126
|
+
c.copy(d);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
a = b;
|
|
130
|
+
}
|
|
131
|
+
return { segments, origin, end: end.clone() };
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export interface IStormLightning {
|
|
135
|
+
/** The real mesh, for the engine's culling pass and for a scene walk that counts what is drawn. */
|
|
136
|
+
readonly mesh: Mesh;
|
|
137
|
+
/**
|
|
138
|
+
* Builds one bolt down to `position` and hands back where it entered the sky, in metres, for the
|
|
139
|
+
* scene glow and the thunder delay. `random` is the caller's, so a strike is reproducible.
|
|
140
|
+
*/
|
|
141
|
+
strike(position: Vector3, random: () => number): Vector3;
|
|
142
|
+
/** Current flash envelope. The caller has already gated it on the photosensitivity switch. */
|
|
143
|
+
update(flash: number): void;
|
|
144
|
+
dispose(): void;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* The bolt pass: one draw of six-vertex quads, added to `scene`.
|
|
149
|
+
*
|
|
150
|
+
* The engine's `GPUParticles3D` cannot carry this: the bolt is not a particle system,
|
|
151
|
+
* it is CPU geometry with per-segment endpoints handed straight to the vertex stage. This is the
|
|
152
|
+
* smallest thing that holds the study's maths — one non-indexed `BufferGeometry` whose attribute
|
|
153
|
+
* buffers are allocated once, and a draw range that stays empty until a strike asks for it.
|
|
154
|
+
*/
|
|
155
|
+
export function createStormLightning(scene: Scene, camera: PerspectiveCamera): IStormLightning {
|
|
156
|
+
// The camera block the study passed to the bolt pass, and to the coast, from the same basis.
|
|
157
|
+
const uFlash = uniform(0, "float").setGroup(frameGroup);
|
|
158
|
+
const uCam = uniform(new Vector3(), "vec3").setGroup(frameGroup);
|
|
159
|
+
const uForward = uniform(new Vector3(), "vec3").setGroup(frameGroup);
|
|
160
|
+
const uRight = uniform(new Vector3(), "vec3").setGroup(frameGroup);
|
|
161
|
+
const uUp = uniform(new Vector3(), "vec3").setGroup(frameGroup);
|
|
162
|
+
const uAspect = uniform(0, "float").setGroup(frameGroup);
|
|
163
|
+
const uTan = uniform(0, "float").setGroup(frameGroup);
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* The study's `proj`. Its x and y are the ordinary perspective divide for this camera's field of
|
|
167
|
+
* view, and its z becomes the depth the coast already wrote from the same near and far planes — so
|
|
168
|
+
* a bolt behind the headland is hidden by it, which is the one comparison that pass existed for.
|
|
169
|
+
*/
|
|
170
|
+
function proj(p: Node<"vec3">) {
|
|
171
|
+
const v = p.sub(uCam);
|
|
172
|
+
const d = dot(v, uForward);
|
|
173
|
+
const depth = clamp(
|
|
174
|
+
cameraNear
|
|
175
|
+
.add(cameraFar)
|
|
176
|
+
.sub(cameraNear.mul(cameraFar).mul(2).div(d))
|
|
177
|
+
.div(cameraFar.sub(cameraNear))
|
|
178
|
+
.add(1)
|
|
179
|
+
.mul(0.5),
|
|
180
|
+
0,
|
|
181
|
+
1,
|
|
182
|
+
);
|
|
183
|
+
return vec4(dot(v, uRight).div(uAspect.mul(uTan)), dot(v, uUp).div(uTan), depth.mul(d), d);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// --- the vertex stage, transcribed from the study's BOLT_VERTEX --------------------------
|
|
187
|
+
|
|
188
|
+
const startNode = attribute<"vec3">("aStart", "vec3");
|
|
189
|
+
const endNode = attribute<"vec3">("aEnd", "vec3");
|
|
190
|
+
const strengthNode = attribute<"float">("aStrength", "float");
|
|
191
|
+
|
|
192
|
+
// `Fn` because the stage assigns into its own clip-space vector twice; outside a function body
|
|
193
|
+
// TSL has no stack to emit those assignments into, and drops the ribbon's width.
|
|
194
|
+
const ribbon = Fn(() => {
|
|
195
|
+
const a = proj(startNode).toVar();
|
|
196
|
+
const b = proj(endNode).toVar();
|
|
197
|
+
// The screen direction from one endpoint to the other, so the quad's width follows the bolt
|
|
198
|
+
// instead of the world axes. The epsilon is the study's own, for when the two endpoints land on
|
|
199
|
+
// top of each other and there is no direction at all.
|
|
200
|
+
const dir = normalize(
|
|
201
|
+
b.xy
|
|
202
|
+
.div(max(b.w, float(0.1)))
|
|
203
|
+
.sub(a.xy.div(max(a.w, float(0.1))))
|
|
204
|
+
.mul(screenSize)
|
|
205
|
+
.add(0.00001),
|
|
206
|
+
).toVar();
|
|
207
|
+
const side = vec2(dir.y.negate(), dir.x);
|
|
208
|
+
const clip = mix(a, b, positionGeometry.y).toVar();
|
|
209
|
+
// Width in pixels, a little wider for a strong segment: the study's `(7. + 5. * aStrength)`. The
|
|
210
|
+
// offset carries the vertex's own `w`, because the quad is authored in clip space.
|
|
211
|
+
const across = side
|
|
212
|
+
.mul(positionGeometry.x)
|
|
213
|
+
.mul(float(7).add(strengthNode.mul(5)))
|
|
214
|
+
.div(screenSize)
|
|
215
|
+
.mul(clip.w)
|
|
216
|
+
.mul(2);
|
|
217
|
+
clip.addAssign(vec4(across.x, across.y, float(0), float(0)));
|
|
218
|
+
// An endpoint behind the camera has no direction to stretch along; the study threw the quad off
|
|
219
|
+
// screen rather than letting it collapse to a dot on the near plane.
|
|
220
|
+
clip.assign(select(a.w.lessThan(0.2).or(b.w.lessThan(0.2)), vec4(2, 2, 2, 1), clip));
|
|
221
|
+
return clip;
|
|
222
|
+
})();
|
|
223
|
+
|
|
224
|
+
const geometry = new BufferGeometry();
|
|
225
|
+
geometry.setAttribute("position", dynamic(new BufferAttribute(CORNERS, 3)));
|
|
226
|
+
geometry.setAttribute(
|
|
227
|
+
"aStart",
|
|
228
|
+
dynamic(new BufferAttribute(new Float32Array(CORNERS.length), 3)),
|
|
229
|
+
);
|
|
230
|
+
geometry.setAttribute("aEnd", dynamic(new BufferAttribute(new Float32Array(CORNERS.length), 3)));
|
|
231
|
+
geometry.setAttribute(
|
|
232
|
+
"aStrength",
|
|
233
|
+
dynamic(new BufferAttribute(new Float32Array(CORNERS.length / 3), 1)),
|
|
234
|
+
);
|
|
235
|
+
// No bolt has been struck yet, so there is nothing to draw.
|
|
236
|
+
geometry.setDrawRange(0, 0);
|
|
237
|
+
|
|
238
|
+
const material = new MeshBasicNodeMaterial();
|
|
239
|
+
// The ribbons are wound by the projection, not by the vertex order, so either face can end up
|
|
240
|
+
// front facing; the study's pass drew both.
|
|
241
|
+
material.side = DoubleSide;
|
|
242
|
+
material.transparent = true;
|
|
243
|
+
material.depthWrite = false;
|
|
244
|
+
material.blending = AdditiveBlending;
|
|
245
|
+
material.vertexNode = ribbon;
|
|
246
|
+
|
|
247
|
+
const vAcross = varying(positionGeometry.x, "vAcross");
|
|
248
|
+
const vStrength = varying(strengthNode, "vStrength") as Node<"float">;
|
|
249
|
+
// One gaussian core inside one wide halo, the study's `core * 15. + halo * 2.`, added on top of
|
|
250
|
+
// whatever the coast already drew — which is what makes a bolt read as light, not as paint.
|
|
251
|
+
const core = exp(vAcross.mul(vAcross).negate().mul(750)).toVar();
|
|
252
|
+
const halo = exp(abs(vAcross).negate().mul(7)).mul(0.42).toVar();
|
|
253
|
+
material.fragmentNode = vec4(
|
|
254
|
+
vec3(0.55, 0.78, 1.35)
|
|
255
|
+
.mul(core.mul(15).add(halo.mul(2)))
|
|
256
|
+
.mul(vStrength.mul(uFlash)),
|
|
257
|
+
1,
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
const mesh = new Mesh(geometry, material);
|
|
261
|
+
// The buffers hold every possible bolt's worth of quads parked at the origin, so the geometry's
|
|
262
|
+
// own bounds say nothing about where a strike actually is.
|
|
263
|
+
mesh.frustumCulled = false;
|
|
264
|
+
mesh.renderOrder = 1;
|
|
265
|
+
scene.add(mesh);
|
|
266
|
+
|
|
267
|
+
const forward = new Vector3();
|
|
268
|
+
const right = new Vector3();
|
|
269
|
+
const up = new Vector3();
|
|
270
|
+
|
|
271
|
+
return {
|
|
272
|
+
mesh,
|
|
273
|
+
strike(position, random): Vector3 {
|
|
274
|
+
if (!isFiniteVector(position)) {
|
|
275
|
+
throw new Error(
|
|
276
|
+
`strike position must be a finite point in metres, got ${describe(position)}.`,
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
if (typeof random !== "function") {
|
|
280
|
+
throw new Error(`strike needs the caller's random source, got ${typeof random}.`);
|
|
281
|
+
}
|
|
282
|
+
// The study's `rng` always returns 0..1; a source that does not is a bug in the caller, and it
|
|
283
|
+
// would otherwise turn into a bolt of NaN geometry that renders as nothing.
|
|
284
|
+
const bolt = makeBolt(position, () => {
|
|
285
|
+
const value = random();
|
|
286
|
+
if (!Number.isFinite(value)) {
|
|
287
|
+
throw new Error("strike random source returned a non-finite number.");
|
|
288
|
+
}
|
|
289
|
+
return value;
|
|
290
|
+
});
|
|
291
|
+
write(bolt);
|
|
292
|
+
return bolt.origin;
|
|
293
|
+
},
|
|
294
|
+
update(flash: number): void {
|
|
295
|
+
if (!Number.isFinite(flash)) {
|
|
296
|
+
throw new Error(`flash must be a finite envelope value, got ${flash}.`);
|
|
297
|
+
}
|
|
298
|
+
// The same basis and field of view the coast is drawn with, so a bolt and the headland behind
|
|
299
|
+
// it agree on where the horizon is.
|
|
300
|
+
camera.getWorldDirection(forward);
|
|
301
|
+
right.set(1, 0, 0).applyQuaternion(camera.quaternion);
|
|
302
|
+
up.set(0, 1, 0).applyQuaternion(camera.quaternion);
|
|
303
|
+
uCam.value.copy(camera.position);
|
|
304
|
+
uForward.value.copy(forward);
|
|
305
|
+
uRight.value.copy(right);
|
|
306
|
+
uUp.value.copy(up);
|
|
307
|
+
uAspect.value = camera.aspect;
|
|
308
|
+
uTan.value = Math.tan((camera.fov * Math.PI) / 360);
|
|
309
|
+
uFlash.value = flash;
|
|
310
|
+
// Below a hair of flash there is nothing to see, and the study did not issue the draw.
|
|
311
|
+
mesh.visible = flash > 0.003 && geometry.drawRange.count > 0;
|
|
312
|
+
},
|
|
313
|
+
dispose(): void {
|
|
314
|
+
scene.remove(mesh);
|
|
315
|
+
geometry.dispose();
|
|
316
|
+
material.dispose();
|
|
317
|
+
},
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
/** Copies a bolt into the attribute buffers and opens the draw range to it. */
|
|
321
|
+
function write(bolt: IBolt): void {
|
|
322
|
+
const starts = geometry.getAttribute("aStart") as BufferAttribute;
|
|
323
|
+
const ends = geometry.getAttribute("aEnd") as BufferAttribute;
|
|
324
|
+
const strengths = geometry.getAttribute("aStrength") as BufferAttribute;
|
|
325
|
+
for (let s = 0; s < bolt.segments.length; s++) {
|
|
326
|
+
const segment = bolt.segments[s];
|
|
327
|
+
if (segment === undefined) continue;
|
|
328
|
+
for (let v = 0; v < VERTICES_PER_SEGMENT; v++) {
|
|
329
|
+
const at = (s * VERTICES_PER_SEGMENT + v) * 3;
|
|
330
|
+
starts.array[at] = segment.a.x;
|
|
331
|
+
starts.array[at + 1] = segment.a.y;
|
|
332
|
+
starts.array[at + 2] = segment.a.z;
|
|
333
|
+
ends.array[at] = segment.b.x;
|
|
334
|
+
ends.array[at + 1] = segment.b.y;
|
|
335
|
+
ends.array[at + 2] = segment.b.z;
|
|
336
|
+
strengths.array[s * VERTICES_PER_SEGMENT + v] = segment.strength;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
starts.needsUpdate = true;
|
|
340
|
+
ends.needsUpdate = true;
|
|
341
|
+
strengths.needsUpdate = true;
|
|
342
|
+
geometry.setDrawRange(0, bolt.segments.length * VERTICES_PER_SEGMENT);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/** The attribute buffers are rewritten on every strike, so they are uploaded, not orphaned. */
|
|
347
|
+
function dynamic(attributeBuffer: BufferAttribute): BufferAttribute {
|
|
348
|
+
attributeBuffer.setUsage(DynamicDrawUsage);
|
|
349
|
+
return attributeBuffer;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
function isFiniteVector(v: Vector3): boolean {
|
|
353
|
+
return (
|
|
354
|
+
v instanceof Vector3 && Number.isFinite(v.x) && Number.isFinite(v.y) && Number.isFinite(v.z)
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function describe(v: Vector3): string {
|
|
359
|
+
return isFiniteVector(v) ? `${v.x}, ${v.y}, ${v.z}` : String(v);
|
|
360
|
+
}
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Camera,
|
|
3
|
+
CanvasTexture,
|
|
4
|
+
ClampToEdgeWrapping,
|
|
5
|
+
Mesh,
|
|
6
|
+
MeshBasicMaterial,
|
|
7
|
+
type OrthographicCamera,
|
|
8
|
+
PlaneGeometry,
|
|
9
|
+
type Scene,
|
|
10
|
+
type Texture,
|
|
11
|
+
} from "three";
|
|
12
|
+
import { palette } from "./palette.js";
|
|
13
|
+
|
|
14
|
+
/* BEGIN THREENATIVE LOADING APPEARANCE */
|
|
15
|
+
/** The storm's own night behind the bar; all behavior is authored here. */
|
|
16
|
+
export const loading = {
|
|
17
|
+
backgroundColor: palette.night,
|
|
18
|
+
backgroundImage: undefined as string | undefined,
|
|
19
|
+
enabled: true,
|
|
20
|
+
fillImage: undefined as string | undefined,
|
|
21
|
+
logoImage: undefined as string | undefined,
|
|
22
|
+
progressColor: palette.accent,
|
|
23
|
+
showStatus: false,
|
|
24
|
+
trackColor: palette.zenith,
|
|
25
|
+
// The study's one-pixel line through the middle of the screen; `src/ui/LoadingOverlay.tsx`
|
|
26
|
+
// writes the title and the stage above it and the photosensitivity note below it.
|
|
27
|
+
bar: { anchorX: 0.5, anchorY: 0.5, height: 1, maxWidth: 290, minWidth: 1, width: 0.64 },
|
|
28
|
+
} as const;
|
|
29
|
+
/* END THREENATIVE LOADING APPEARANCE */
|
|
30
|
+
|
|
31
|
+
interface ILoadingHost {
|
|
32
|
+
readonly assets?: { texture(path: string): Promise<Texture> };
|
|
33
|
+
readonly camera: Camera;
|
|
34
|
+
readonly canvasLayer: {
|
|
35
|
+
readonly camera: OrthographicCamera;
|
|
36
|
+
readonly scene: Scene;
|
|
37
|
+
opaque: boolean;
|
|
38
|
+
};
|
|
39
|
+
readonly renderer: { compileAsync(scene: Scene, camera: Camera): Promise<void> };
|
|
40
|
+
readonly scene: Scene;
|
|
41
|
+
readonly startup: {
|
|
42
|
+
readonly progress: number;
|
|
43
|
+
readonly warmup?: { readonly status: "complete" | "incomplete" | "unavailable" };
|
|
44
|
+
whenReady(): Promise<void>;
|
|
45
|
+
};
|
|
46
|
+
readonly viewport?: {
|
|
47
|
+
readonly safeArea: { height: number; width: number; x: number; y: number };
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
interface ILoadingController {
|
|
52
|
+
update(): void;
|
|
53
|
+
finish(): void;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function noOp(layer: ILoadingHost["canvasLayer"]): ILoadingController {
|
|
57
|
+
layer.opaque = false;
|
|
58
|
+
return { finish: () => undefined, update: () => undefined };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function meshFor(
|
|
62
|
+
layer: ILoadingHost["canvasLayer"],
|
|
63
|
+
material: MeshBasicMaterial,
|
|
64
|
+
renderOrder: number,
|
|
65
|
+
): Mesh<PlaneGeometry, MeshBasicMaterial> {
|
|
66
|
+
const mesh = new Mesh(new PlaneGeometry(1, 1), material);
|
|
67
|
+
mesh.frustumCulled = false;
|
|
68
|
+
mesh.renderOrder = renderOrder;
|
|
69
|
+
layer.scene.add(mesh);
|
|
70
|
+
return mesh;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function imageAspect(texture: Texture | null | undefined): number {
|
|
74
|
+
const image = texture?.image as { height?: number; width?: number } | undefined;
|
|
75
|
+
const width = image?.width ?? 1;
|
|
76
|
+
const height = image?.height ?? 1;
|
|
77
|
+
return width > 0 && height > 0 ? width / height : 1;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function configureTexture(texture: Texture): void {
|
|
81
|
+
texture.wrapS = ClampToEdgeWrapping;
|
|
82
|
+
texture.wrapT = ClampToEdgeWrapping;
|
|
83
|
+
texture.needsUpdate = true;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function setFillUv(geometry: PlaneGeometry, progress: number, base: readonly number[]): void {
|
|
87
|
+
const uv = geometry.getAttribute("uv");
|
|
88
|
+
for (let index = 0; index < uv.count; index += 1) uv.setX(index, (base[index] ?? 0) * progress);
|
|
89
|
+
uv.needsUpdate = true;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function coverUv(
|
|
93
|
+
geometry: PlaneGeometry,
|
|
94
|
+
texture: Texture,
|
|
95
|
+
width: number,
|
|
96
|
+
height: number,
|
|
97
|
+
baseU: readonly number[],
|
|
98
|
+
baseV: readonly number[],
|
|
99
|
+
): void {
|
|
100
|
+
const imageRatio = imageAspect(texture);
|
|
101
|
+
const boxRatio = width / Math.max(1, height);
|
|
102
|
+
const visibleU = imageRatio > boxRatio ? boxRatio / imageRatio : 1;
|
|
103
|
+
const visibleV = imageRatio < boxRatio ? imageRatio / boxRatio : 1;
|
|
104
|
+
const offsetU = (1 - visibleU) / 2;
|
|
105
|
+
const offsetV = (1 - visibleV) / 2;
|
|
106
|
+
const uv = geometry.getAttribute("uv");
|
|
107
|
+
for (let index = 0; index < uv.count; index += 1) {
|
|
108
|
+
uv.setX(index, offsetU + (baseU[index] ?? 0) * visibleU);
|
|
109
|
+
uv.setY(index, offsetV + (baseV[index] ?? 0) * visibleV);
|
|
110
|
+
}
|
|
111
|
+
uv.needsUpdate = true;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function statusMesh(
|
|
115
|
+
layer: ILoadingHost["canvasLayer"],
|
|
116
|
+
):
|
|
117
|
+
| { mesh: Mesh<PlaneGeometry, MeshBasicMaterial>; texture: Texture; update(value: number): void }
|
|
118
|
+
| undefined {
|
|
119
|
+
if (!loading.showStatus || typeof document === "undefined") return undefined;
|
|
120
|
+
const canvas = document.createElement("canvas");
|
|
121
|
+
canvas.width = 180;
|
|
122
|
+
canvas.height = 48;
|
|
123
|
+
const context = canvas.getContext("2d");
|
|
124
|
+
if (context === null) return undefined;
|
|
125
|
+
const texture = new CanvasTexture(canvas);
|
|
126
|
+
const mesh = meshFor(
|
|
127
|
+
layer,
|
|
128
|
+
new MeshBasicMaterial({ depthTest: false, depthWrite: false, map: texture, transparent: true }),
|
|
129
|
+
4,
|
|
130
|
+
);
|
|
131
|
+
const update = (value: number): void => {
|
|
132
|
+
context.clearRect(0, 0, canvas.width, canvas.height);
|
|
133
|
+
context.fillStyle = "#ffffff";
|
|
134
|
+
context.font = "700 20px monospace";
|
|
135
|
+
context.textAlign = "center";
|
|
136
|
+
context.textBaseline = "middle";
|
|
137
|
+
context.fillText(`${Math.round(value * 100)}%`, canvas.width / 2, canvas.height / 2);
|
|
138
|
+
texture.needsUpdate = true;
|
|
139
|
+
};
|
|
140
|
+
update(0);
|
|
141
|
+
return { mesh, texture, update };
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function createLoadingScreen(host: ILoadingHost): ILoadingController {
|
|
145
|
+
const layer = host.canvasLayer;
|
|
146
|
+
if (!loading.enabled) return noOp(layer);
|
|
147
|
+
const camera = layer.camera;
|
|
148
|
+
const backdrop = meshFor(
|
|
149
|
+
layer,
|
|
150
|
+
new MeshBasicMaterial({ color: loading.backgroundColor, depthTest: false, depthWrite: false }),
|
|
151
|
+
0,
|
|
152
|
+
);
|
|
153
|
+
const track = meshFor(
|
|
154
|
+
layer,
|
|
155
|
+
new MeshBasicMaterial({ color: loading.trackColor, depthTest: false, depthWrite: false }),
|
|
156
|
+
1,
|
|
157
|
+
);
|
|
158
|
+
const fill = meshFor(
|
|
159
|
+
layer,
|
|
160
|
+
new MeshBasicMaterial({ color: loading.progressColor, depthTest: false, depthWrite: false }),
|
|
161
|
+
2,
|
|
162
|
+
);
|
|
163
|
+
const fillBaseU = Array.from({ length: fill.geometry.getAttribute("uv").count }, (_, index) =>
|
|
164
|
+
fill.geometry.getAttribute("uv").getX(index),
|
|
165
|
+
);
|
|
166
|
+
const fillBaseV = Array.from({ length: fill.geometry.getAttribute("uv").count }, (_, index) =>
|
|
167
|
+
fill.geometry.getAttribute("uv").getY(index),
|
|
168
|
+
);
|
|
169
|
+
const logo =
|
|
170
|
+
loading.logoImage === undefined
|
|
171
|
+
? undefined
|
|
172
|
+
: meshFor(
|
|
173
|
+
layer,
|
|
174
|
+
new MeshBasicMaterial({
|
|
175
|
+
color: 0xffffff,
|
|
176
|
+
depthTest: false,
|
|
177
|
+
depthWrite: false,
|
|
178
|
+
transparent: true,
|
|
179
|
+
}),
|
|
180
|
+
3,
|
|
181
|
+
);
|
|
182
|
+
const status = statusMesh(layer);
|
|
183
|
+
const parts = [
|
|
184
|
+
backdrop,
|
|
185
|
+
track,
|
|
186
|
+
fill,
|
|
187
|
+
...(logo === undefined ? [] : [logo]),
|
|
188
|
+
...(status === undefined ? [] : [status.mesh]),
|
|
189
|
+
];
|
|
190
|
+
const ownedTextures = new Set<Texture>(status === undefined ? [] : [status.texture]);
|
|
191
|
+
let width = 1;
|
|
192
|
+
let height = 1;
|
|
193
|
+
let barWidth = 1;
|
|
194
|
+
let barHeight: number = loading.bar.height;
|
|
195
|
+
let barX = 0;
|
|
196
|
+
let barY = 0;
|
|
197
|
+
let progress = 0;
|
|
198
|
+
let done = false;
|
|
199
|
+
let backdropTexture: Texture | undefined;
|
|
200
|
+
|
|
201
|
+
const layout = (): void => {
|
|
202
|
+
width = Math.max(1, camera.right - camera.left);
|
|
203
|
+
height = Math.max(1, camera.top - camera.bottom);
|
|
204
|
+
const safe = host.viewport?.safeArea ?? { height, width, x: 0, y: 0 };
|
|
205
|
+
const safeWidth = Math.max(1, Math.min(width, safe.width));
|
|
206
|
+
const safeHeight = Math.max(1, Math.min(height, safe.height));
|
|
207
|
+
const safeX = Math.max(0, Math.min(width - safeWidth, safe.x));
|
|
208
|
+
const safeY = Math.max(0, Math.min(height - safeHeight, safe.y));
|
|
209
|
+
barWidth = Math.max(2, Math.min(loading.bar.maxWidth, safeWidth * loading.bar.width));
|
|
210
|
+
barHeight = Math.max(2, Math.min(loading.bar.height, safeHeight * 0.05));
|
|
211
|
+
barX = safeX + safeWidth * loading.bar.anchorX;
|
|
212
|
+
barY = safeY + safeHeight * loading.bar.anchorY;
|
|
213
|
+
const worldX = (screenX: number): number => camera.left + screenX;
|
|
214
|
+
const worldY = (screenY: number): number => camera.top - screenY;
|
|
215
|
+
const visibleWidth = Math.max(loading.bar.minWidth, barWidth * progress);
|
|
216
|
+
backdrop.scale.set(width, height, 1);
|
|
217
|
+
backdrop.position.set(worldX(width / 2), worldY(height / 2), 0);
|
|
218
|
+
track.scale.set(barWidth, barHeight, 1);
|
|
219
|
+
track.position.set(worldX(barX), worldY(barY), 0);
|
|
220
|
+
fill.scale.set(visibleWidth, barHeight, 1);
|
|
221
|
+
fill.position.set(worldX(barX - barWidth / 2 + visibleWidth / 2), worldY(barY), 0);
|
|
222
|
+
if (logo?.visible) {
|
|
223
|
+
const logoWidth = Math.min(safeWidth * 0.42, 280);
|
|
224
|
+
logo.scale.set(
|
|
225
|
+
logoWidth,
|
|
226
|
+
Math.min(logoWidth / imageAspect(logo.material.map), safeHeight * 0.22),
|
|
227
|
+
1,
|
|
228
|
+
);
|
|
229
|
+
logo.position.set(worldX(barX), worldY(Math.max(safeY, barY - safeHeight * 0.2)), 0);
|
|
230
|
+
}
|
|
231
|
+
if (status !== undefined) {
|
|
232
|
+
status.mesh.scale.set(Math.min(180, safeWidth * 0.32), 48, 1);
|
|
233
|
+
status.mesh.position.set(worldX(barX), worldY(Math.min(height, barY + barHeight * 2.5)), 0);
|
|
234
|
+
}
|
|
235
|
+
if (backdropTexture !== undefined)
|
|
236
|
+
coverUv(backdrop.geometry, backdropTexture, width, height, fillBaseU, fillBaseV);
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
const updateProgress = (value: number): void => {
|
|
240
|
+
const bounded = Number.isFinite(value) ? Math.max(0, Math.min(1, value)) : 0;
|
|
241
|
+
// A missing or incomplete backend observation cannot prove that all first-use work is done.
|
|
242
|
+
// Keep the bar visibly indeterminate until readiness removes the cover; never turn unknown
|
|
243
|
+
// coverage into a false 100% claim.
|
|
244
|
+
const observationUnknown =
|
|
245
|
+
host.startup.warmup !== undefined && host.startup.warmup.status !== "complete";
|
|
246
|
+
progress = observationUnknown ? Math.min(0.9, bounded) : bounded;
|
|
247
|
+
setFillUv(fill.geometry, progress, fillBaseU);
|
|
248
|
+
status?.update(progress);
|
|
249
|
+
layout();
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
const attachTexture = (mesh: Mesh<PlaneGeometry, MeshBasicMaterial>, texture: Texture): void => {
|
|
253
|
+
if (done) return;
|
|
254
|
+
configureTexture(texture);
|
|
255
|
+
mesh.material.map = texture;
|
|
256
|
+
mesh.material.color.set(0xffffff);
|
|
257
|
+
mesh.material.needsUpdate = true;
|
|
258
|
+
ownedTextures.add(texture);
|
|
259
|
+
if (mesh === backdrop) backdropTexture = texture;
|
|
260
|
+
layout();
|
|
261
|
+
updateProgress(progress);
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
const load = (source: string | undefined, mesh: Mesh<PlaneGeometry, MeshBasicMaterial>): void => {
|
|
265
|
+
if (source === undefined || host.assets === undefined) return;
|
|
266
|
+
void host.assets
|
|
267
|
+
.texture(source)
|
|
268
|
+
.then((texture) => attachTexture(mesh, texture))
|
|
269
|
+
.catch(() => undefined);
|
|
270
|
+
};
|
|
271
|
+
load(loading.backgroundImage, backdrop);
|
|
272
|
+
load(loading.fillImage, fill);
|
|
273
|
+
if (logo !== undefined && loading.logoImage !== undefined && host.assets !== undefined) {
|
|
274
|
+
void host.assets
|
|
275
|
+
.texture(loading.logoImage)
|
|
276
|
+
.then((texture) => {
|
|
277
|
+
if (done) return;
|
|
278
|
+
configureTexture(texture);
|
|
279
|
+
logo.material.map = texture;
|
|
280
|
+
logo.material.needsUpdate = true;
|
|
281
|
+
logo.visible = true;
|
|
282
|
+
ownedTextures.add(texture);
|
|
283
|
+
layout();
|
|
284
|
+
})
|
|
285
|
+
.catch(() => undefined);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
layer.opaque = true;
|
|
289
|
+
layout();
|
|
290
|
+
updateProgress(0);
|
|
291
|
+
|
|
292
|
+
const finish = (): void => {
|
|
293
|
+
if (done) return;
|
|
294
|
+
done = true;
|
|
295
|
+
for (const mesh of parts) {
|
|
296
|
+
mesh.removeFromParent();
|
|
297
|
+
mesh.geometry.dispose();
|
|
298
|
+
mesh.material.dispose();
|
|
299
|
+
}
|
|
300
|
+
for (const texture of ownedTextures) texture.dispose();
|
|
301
|
+
layer.opaque = false;
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
void (async () => {
|
|
305
|
+
await host.startup.whenReady();
|
|
306
|
+
if (done) return;
|
|
307
|
+
// Prewarm the world's shaders, but do not wait for them here. `whenReady()` already means the
|
|
308
|
+
// world is safe to show, and compiling a lit, post-processed scene takes far longer than the
|
|
309
|
+
// launch window: hold the screen for it and a playtest — which advances a fixed step as fast
|
|
310
|
+
// as the machine allows — runs an entire scenario behind the launch screen, so every capture
|
|
311
|
+
// photographs the loading bar instead of the game. The prewarm still happens; it no longer
|
|
312
|
+
// decides when the player sees the world.
|
|
313
|
+
try {
|
|
314
|
+
void host.renderer.compileAsync(host.scene, host.camera).catch(() => undefined);
|
|
315
|
+
} catch {
|
|
316
|
+
// A renderer without compileAsync is not a reason to keep the world hidden.
|
|
317
|
+
}
|
|
318
|
+
finish();
|
|
319
|
+
})();
|
|
320
|
+
|
|
321
|
+
return {
|
|
322
|
+
finish,
|
|
323
|
+
update(): void {
|
|
324
|
+
if (!done) updateProgress(host.startup.progress);
|
|
325
|
+
},
|
|
326
|
+
};
|
|
327
|
+
}
|