create-threenative 0.2.6 → 0.2.7
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 +2 -2
- package/agent-docs/references/build-profiles.md +126 -0
- package/agent-docs/references/capability-reference.md +431 -20
- package/agent-docs/references/performance-basics.md +8 -5
- package/agent-docs/references/sculpt-from-a-reference.md +1 -1
- package/agent-docs/references/trace-a-slow-frame.md +1 -1
- package/agent-docs/references/visual-baseline.md +8 -4
- package/agent-files/.agents/skills/file-engine-bug/SKILL.md +15 -4
- package/agent-files/.agents/skills/threenative-assets/SKILL.md +5 -5
- package/agent-files/.agents/skills/threenative-capabilities/SKILL.md +1 -1
- package/agent-files/.agents/skills/threenative-context/SKILL.md +1 -1
- package/agent-files/.agents/skills/threenative-performance/SKILL.md +3 -3
- package/agent-files/.agents/skills/threenative-playtest/SKILL.md +1 -1
- package/agent-files/.agents/skills/threenative-ui/SKILL.md +1 -1
- package/agent-files/.agents/skills/threenative-visuals/SKILL.md +4 -4
- package/capabilities.json +555 -21
- package/dist/index.d.ts +30 -1
- package/dist/index.js +294 -55
- package/dist/threenative.js +714 -154
- package/package.json +6 -6
- package/template-assets/assets/mannequin-combat.glb +0 -0
- package/template-assets/assets/mannequin.glb +0 -0
- package/template-assets/assets/player-viewmodel.glb +0 -0
- package/template-assets/assets/sky.jpg +0 -0
- package/template-assets/clearwater/README.md +141 -0
- package/template-assets/clearwater/install.mjs +50 -0
- package/template-assets/clearwater/src/clearwater.ts +180 -0
- package/template-assets/clearwater/src/clearwaterDemo.ts +28 -0
- package/template-assets/clearwater/src/clearwaterLifetime.ts +28 -0
- package/{LICENSE → template-assets/clearwater/src/render/CLEARWATER-LICENSE.txt} +4 -1
- package/template-assets/clearwater/src/render/clearwater.ts +278 -0
- package/template-assets/clearwater/src/render/clearwaterCaustics.ts +138 -0
- package/template-assets/clearwater/src/render/clearwaterDemo.ts +65 -0
- package/template-assets/clearwater/src/render/clearwaterOptics.ts +33 -0
- package/template-assets/clearwater/src/render/clearwaterOptions.ts +177 -0
- package/template-assets/clearwater/src/render/clearwaterPass.ts +51 -0
- package/template-assets/patches/three@0.185.1.patch +2101 -138
- package/template-assets/worldEnvironment.ts +52 -1
- package/templates/action-rpg/AGENTS.md +42 -42
- package/templates/action-rpg/CLAUDE.md +42 -42
- package/templates/action-rpg/kit.json +1 -1
- package/templates/action-rpg/package.json +13 -7
- package/templates/action-rpg/playtests/combat.playtest.json +162 -23
- package/templates/action-rpg/playtests/performance.playtest.json +4 -3
- package/templates/action-rpg/playtests/survives.playtest.json +25 -8
- package/templates/action-rpg/src/conventions.ts +24 -18
- package/templates/action-rpg/src/entities/Enemy.ts +74 -24
- package/templates/action-rpg/src/entities/Fighter.ts +127 -0
- package/templates/action-rpg/src/entities/Player.ts +102 -32
- package/templates/action-rpg/src/game.ts +3 -3
- package/templates/action-rpg/src/render/camera.ts +18 -16
- package/templates/action-rpg/src/render/dungeon.ts +192 -0
- package/templates/action-rpg/src/render/lighting.ts +45 -28
- package/templates/action-rpg/src/render/loading.ts +4 -4
- package/templates/action-rpg/src/render/materials.ts +191 -47
- package/templates/action-rpg/src/render/palette.ts +14 -13
- package/templates/action-rpg/src/render/postprocessing.ts +12 -2
- package/templates/action-rpg/src/render/props.ts +117 -0
- package/templates/action-rpg/src/render/quality.ts +40 -82
- package/templates/action-rpg/src/render/sky.ts +36 -13
- package/templates/action-rpg/src/render/touch-controls.ts +1 -1
- package/templates/action-rpg/src/render/worldEnvironment.ts +52 -1
- package/templates/action-rpg/src/scenes/Play.ts +61 -39
- package/templates/action-rpg/src/style.css +9 -7
- package/templates/action-rpg/src/ui/AbilityBar.tsx +3 -1
- package/templates/action-rpg/src/ui/Hud.tsx +3 -3
- package/templates/action-rpg/threenative.config.ts +14 -1
- package/templates/action-rpg/vite.config.ts +4 -1
- package/templates/minimal/AGENTS.md +10 -10
- package/templates/minimal/CLAUDE.md +10 -10
- package/templates/minimal/package.json +12 -6
- package/templates/minimal/playtests/play.playtest.json +6 -5
- package/templates/minimal/playtests/sky.playtest.json +27 -0
- package/templates/minimal/src/conventions.ts +6 -3
- package/templates/minimal/src/entities/Player.ts +73 -27
- package/templates/minimal/src/main.ts +2 -3
- package/templates/minimal/src/render/camera.ts +22 -4
- package/templates/minimal/src/render/lighting.ts +24 -48
- package/templates/minimal/src/render/materials.ts +158 -13
- package/templates/minimal/src/render/palette.ts +10 -7
- package/templates/minimal/src/render/postprocessing.ts +12 -25
- package/templates/minimal/src/render/quality.ts +35 -69
- package/templates/minimal/src/render/sky.ts +35 -54
- package/templates/minimal/src/render/touch-controls.ts +1 -1
- package/templates/minimal/src/render/worldEnvironment.ts +52 -1
- package/templates/minimal/src/scenes/Play.ts +121 -111
- package/templates/minimal/src/state.ts +0 -4
- package/templates/minimal/src/style.css +0 -10
- package/templates/minimal/threenative.config.ts +14 -1
- package/templates/minimal/vite.config.ts +4 -1
- package/templates/platformer/AGENTS.md +18 -56
- package/templates/platformer/CLAUDE.md +18 -56
- package/templates/platformer/kit.json +2 -2
- package/templates/platformer/package.json +13 -9
- package/templates/platformer/playtests/buffer.playtest.json +15 -5
- package/templates/platformer/playtests/collect.playtest.json +8 -34
- package/templates/platformer/playtests/coyote.playtest.json +12 -34
- package/templates/platformer/playtests/damage.playtest.json +40 -15
- package/templates/platformer/playtests/hud.playtest.json +34 -0
- package/templates/platformer/playtests/move.playtest.json +24 -0
- package/templates/platformer/playtests/performance.playtest.json +24 -7
- package/templates/platformer/playtests/respawn.playtest.json +46 -11
- package/templates/platformer/playtests/stomp.playtest.json +49 -12
- package/templates/platformer/playtests/survives.playtest.json +3 -19
- package/templates/platformer/playtests/world.playtest.json +26 -0
- package/templates/platformer/src/entities/Fox.ts +273 -0
- package/templates/platformer/src/entities/Pickup.ts +43 -60
- package/templates/platformer/src/entities/Walker.ts +88 -0
- package/templates/platformer/src/game.ts +11 -8
- package/templates/platformer/src/level/Checkpoints.ts +29 -16
- package/templates/platformer/src/level/Stage.ts +469 -0
- package/templates/platformer/src/render/blocks.ts +94 -0
- package/templates/platformer/src/render/camera.ts +28 -3
- package/templates/platformer/src/render/fox.ts +196 -0
- package/templates/platformer/src/render/lighting.ts +42 -33
- package/templates/platformer/src/render/materials.ts +115 -5
- package/templates/platformer/src/render/palette.ts +68 -53
- package/templates/platformer/src/render/pickups.ts +142 -0
- package/templates/platformer/src/render/postprocessing.ts +12 -2
- package/templates/platformer/src/render/props.ts +147 -0
- package/templates/platformer/src/render/quality.ts +47 -99
- package/templates/platformer/src/render/scenery.ts +172 -0
- package/templates/platformer/src/render/sky.ts +120 -31
- package/templates/platformer/src/render/touch-controls.ts +5 -2
- package/templates/platformer/src/render/walkers.ts +96 -0
- package/templates/platformer/src/render/waterfall.ts +85 -0
- package/templates/platformer/src/render/worldEnvironment.ts +52 -1
- package/templates/platformer/src/scenes/Boot.ts +3 -4
- package/templates/platformer/src/scenes/Play.ts +362 -0
- package/templates/platformer/src/state.ts +16 -14
- package/templates/platformer/src/style.css +9 -8
- package/templates/platformer/src/ui/Hud.tsx +62 -29
- package/templates/platformer/src/ui/Menu.tsx +2 -2
- package/templates/platformer/threenative.config.ts +14 -1
- package/templates/platformer/vite.config.ts +4 -1
- package/templates/puzzle/AGENTS.md +19 -20
- package/templates/puzzle/CLAUDE.md +19 -20
- package/templates/puzzle/assets/native-proof.glb +0 -0
- package/templates/puzzle/assets/native-proof.png +0 -0
- package/templates/puzzle/kit.json +1 -1
- package/templates/puzzle/package.json +13 -7
- package/templates/puzzle/playtests/axis.playtest.json +20 -0
- package/templates/puzzle/playtests/blocked.playtest.json +73 -0
- package/templates/puzzle/playtests/caused.playtest.json +65 -0
- package/templates/puzzle/playtests/lit.playtest.json +74 -0
- package/templates/puzzle/playtests/performance.playtest.json +24 -7
- package/templates/{starter/playtests/respawn.playtest.json → puzzle/playtests/push.playtest.json} +24 -19
- package/templates/puzzle/playtests/replay.playtest.json +81 -0
- package/templates/puzzle/playtests/restart.playtest.json +108 -0
- package/templates/puzzle/playtests/seal.playtest.json +98 -0
- package/templates/puzzle/playtests/settle.playtest.json +100 -0
- package/templates/puzzle/playtests/survives.playtest.json +6 -29
- package/templates/{starter/playtests/hot-reload.playtest.json → puzzle/playtests/travel.playtest.json} +6 -5
- package/templates/puzzle/src/entities/Crate.ts +99 -42
- package/templates/puzzle/src/entities/Seal.ts +69 -0
- package/templates/puzzle/src/entities/Warden.ts +135 -0
- package/templates/puzzle/src/game.ts +15 -11
- package/templates/puzzle/src/render/camera.ts +66 -31
- package/templates/puzzle/src/render/crateShape.ts +70 -0
- package/templates/puzzle/src/render/lighting.ts +41 -41
- package/templates/puzzle/src/render/loading.ts +4 -4
- package/templates/puzzle/src/render/materials.ts +131 -27
- package/templates/puzzle/src/render/palette.ts +19 -29
- package/templates/puzzle/src/render/postprocessing.ts +15 -3
- package/templates/puzzle/src/render/quality.ts +71 -80
- package/templates/puzzle/src/render/shapes.ts +109 -108
- package/templates/puzzle/src/render/sky.ts +18 -10
- package/templates/puzzle/src/render/touch-controls.ts +8 -51
- package/templates/puzzle/src/render/vault.ts +315 -0
- package/templates/puzzle/src/render/warden.ts +46 -0
- package/templates/puzzle/src/render/worldEnvironment.ts +52 -1
- package/templates/puzzle/src/scenes/Play.ts +793 -0
- package/templates/puzzle/src/state.ts +55 -24
- package/templates/puzzle/src/style.css +7 -8
- package/templates/puzzle/src/ui/App.tsx +2 -2
- package/templates/puzzle/src/ui/Hud.tsx +92 -40
- package/templates/puzzle/src/ui/Menu.tsx +40 -2
- package/templates/puzzle/threenative.config.ts +14 -1
- package/templates/puzzle/vite.config.ts +4 -1
- package/templates/racing/AGENTS.md +19 -20
- package/templates/racing/CLAUDE.md +19 -20
- package/templates/racing/package.json +13 -7
- package/templates/racing/playtests/boost.playtest.json +33 -12
- package/templates/racing/playtests/outcome.playtest.json +32 -50
- package/templates/racing/playtests/performance.playtest.json +2 -1
- package/templates/racing/playtests/ranking.playtest.json +5 -14
- package/templates/racing/playtests/rescue.playtest.json +2 -2
- package/templates/racing/playtests/reverse.playtest.json +30 -8
- package/templates/racing/playtests/shortcut.playtest.json +54 -9
- package/templates/racing/playtests/touch-controls.playtest.json +32 -5
- package/templates/racing/src/entities/CarBody.ts +327 -0
- package/templates/racing/src/entities/LineDriver.ts +220 -0
- package/templates/racing/src/entities/RacingCar.ts +150 -89
- package/templates/racing/src/entities/Rival.ts +61 -24
- package/templates/racing/src/game.ts +5 -0
- package/templates/racing/src/render/camera.ts +49 -7
- package/templates/racing/src/render/lighting.ts +36 -37
- package/templates/racing/src/render/materials.ts +239 -19
- package/templates/racing/src/render/palette.ts +19 -21
- package/templates/racing/src/render/postprocessing.ts +12 -2
- package/templates/racing/src/render/quality.ts +43 -82
- package/templates/racing/src/render/shapes.ts +20 -6
- package/templates/racing/src/render/sky.ts +47 -39
- package/templates/racing/src/render/touch-controls.ts +1 -1
- package/templates/racing/src/render/worldEnvironment.ts +52 -1
- package/templates/racing/src/scenes/Race.ts +107 -54
- package/templates/racing/src/state.ts +2 -0
- package/templates/racing/src/track/Checkline.ts +22 -7
- package/templates/racing/src/track/Lap.ts +64 -36
- package/templates/racing/src/track/Ranking.ts +20 -11
- package/templates/racing/src/track/Track.ts +809 -361
- package/templates/racing/src/track/TrackSector.ts +40 -11
- package/templates/racing/src/track/circuit.ts +477 -0
- package/templates/racing/src/track/rescue.ts +16 -4
- package/templates/racing/threenative.config.ts +14 -1
- package/templates/racing/vite.config.ts +4 -1
- package/templates/rts/AGENTS.md +96 -0
- package/templates/rts/CLAUDE.md +98 -0
- package/templates/rts/kit.json +7 -0
- package/templates/{defense → rts}/package.json +13 -7
- package/templates/{defense → rts}/playtests/performance.playtest.json +28 -26
- package/templates/rts/playtests/rts-ai-attack.playtest.json +24 -0
- package/templates/rts/playtests/rts-attack.playtest.json +75 -0
- package/templates/rts/playtests/rts-build.playtest.json +68 -0
- package/templates/rts/playtests/rts-orders.playtest.json +150 -0
- package/templates/rts/playtests/rts-train.playtest.json +62 -0
- package/templates/rts/playtests/survives.playtest.json +58 -0
- package/templates/rts/public/favicon.svg +4 -0
- package/templates/rts/src/game.ts +64 -0
- package/templates/rts/src/orders.ts +22 -0
- package/templates/rts/src/render/army.ts +346 -0
- package/templates/rts/src/render/camera.ts +123 -0
- package/templates/rts/src/render/lighting.ts +61 -0
- package/templates/rts/src/render/loading.ts +33 -0
- package/templates/rts/src/render/materials.ts +152 -0
- package/templates/rts/src/render/models.ts +705 -0
- package/templates/rts/src/render/palette.ts +17 -0
- package/templates/rts/src/render/picking.ts +93 -0
- package/templates/{defense → rts}/src/render/postprocessing.ts +15 -3
- package/templates/rts/src/render/quality.ts +128 -0
- package/templates/rts/src/render/resources.ts +141 -0
- package/templates/rts/src/render/sky.ts +44 -0
- package/templates/rts/src/render/terrain.ts +116 -0
- package/templates/{defense → rts}/src/render/worldEnvironment.ts +52 -1
- package/templates/rts/src/scenes/Play.ts +650 -0
- package/templates/rts/src/sim/ai.ts +1140 -0
- package/templates/rts/src/sim/combat.ts +416 -0
- package/templates/rts/src/sim/construction.ts +374 -0
- package/templates/rts/src/sim/economy.ts +167 -0
- package/templates/rts/src/sim/game.ts +1082 -0
- package/templates/rts/src/sim/movement.ts +371 -0
- package/templates/rts/src/sim/nav.ts +276 -0
- package/templates/rts/src/sim/production.ts +180 -0
- package/templates/rts/src/sim/terrain.ts +170 -0
- package/templates/rts/src/sim/types.ts +647 -0
- package/templates/rts/src/sim/vision.ts +46 -0
- package/templates/rts/src/state.ts +100 -0
- package/templates/{defense → rts}/src/style.css +21 -8
- package/templates/rts/src/ui/App.tsx +21 -0
- package/templates/rts/src/ui/Commands.tsx +129 -0
- package/templates/rts/src/ui/GameUi.tsx +22 -0
- package/templates/rts/src/ui/Hud.tsx +165 -0
- package/templates/rts/src/ui/Minimap.tsx +84 -0
- package/templates/rts/tailwind.config.ts +2 -0
- package/templates/rts/threenative.config.ts +56 -0
- package/templates/rts/tsconfig.json +17 -0
- package/templates/{defense → rts}/vite.config.ts +4 -1
- package/templates/runner/AGENTS.md +6 -10
- package/templates/runner/CLAUDE.md +6 -10
- package/templates/runner/README.md +3 -3
- package/templates/runner/package.json +13 -7
- package/templates/runner/playtests/performance.playtest.json +2 -2
- package/templates/runner/src/conventions.ts +4 -3
- package/templates/runner/src/entities/Runner.ts +54 -7
- package/templates/runner/src/game.ts +2 -0
- package/templates/runner/src/render/camera.ts +4 -2
- package/templates/runner/src/render/dust.ts +5 -2
- package/templates/runner/src/render/lighting.ts +41 -45
- package/templates/runner/src/render/loading.ts +2 -2
- package/templates/runner/src/render/materials.ts +165 -25
- package/templates/runner/src/render/palette.ts +17 -28
- package/templates/runner/src/render/postprocessing.ts +12 -2
- package/templates/runner/src/render/quality.ts +42 -96
- package/templates/runner/src/render/shapes.ts +59 -37
- package/templates/runner/src/render/sky.ts +32 -41
- package/templates/runner/src/render/touch-controls.ts +1 -1
- package/templates/runner/src/render/worldEnvironment.ts +52 -1
- package/templates/runner/src/scenes/Run.ts +26 -6
- package/templates/runner/src/track.ts +6 -1
- package/templates/runner/threenative.config.ts +14 -1
- package/templates/runner/vite.config.ts +4 -1
- package/templates/sailing/AGENTS.md +12 -12
- package/templates/sailing/CLAUDE.md +12 -12
- package/templates/sailing/assets/ship.glb +0 -0
- package/templates/sailing/package.json +13 -7
- package/templates/sailing/playtests/float-after-the-run-ends.playtest.json +10 -6
- package/templates/sailing/playtests/sails.playtest.json +33 -0
- package/templates/sailing/playtests/win.playtest.json +156 -8
- package/templates/sailing/src/conventions.ts +29 -2
- package/templates/sailing/src/entities/Ship.ts +381 -57
- package/templates/sailing/src/game.ts +14 -0
- package/templates/sailing/src/render/camera.ts +63 -9
- package/templates/sailing/src/render/lighting.ts +49 -27
- package/templates/sailing/src/render/materials.ts +50 -15
- package/templates/sailing/src/render/ocean.ts +647 -60
- package/templates/sailing/src/render/palette.ts +16 -12
- package/templates/sailing/src/render/postprocessing.ts +12 -2
- package/templates/sailing/src/render/props.ts +316 -442
- package/templates/sailing/src/render/quality.ts +14 -4
- package/templates/sailing/src/render/sky.ts +116 -23
- package/templates/sailing/src/render/worldEnvironment.ts +52 -1
- package/templates/sailing/src/scenes/Boot.ts +21 -0
- package/templates/sailing/src/scenes/Sailing.ts +173 -39
- package/templates/sailing/src/state.ts +6 -0
- package/templates/sailing/src/ui/Hud.tsx +41 -9
- package/templates/sailing/threenative.config.ts +14 -1
- package/templates/sailing/vite.config.ts +4 -1
- package/templates/shooter/AGENTS.md +27 -42
- package/templates/shooter/CLAUDE.md +27 -42
- package/templates/shooter/index.html +1 -0
- package/templates/shooter/package.json +13 -7
- package/templates/shooter/playtests/aim-alignment.playtest.json +58 -0
- package/templates/shooter/playtests/breakable-shatters.playtest.json +62 -0
- package/templates/shooter/playtests/bullet-holes.playtest.json +56 -0
- package/templates/shooter/playtests/camera-tracks-body-vertically.playtest.json +61 -0
- package/templates/shooter/playtests/crouch-lowers-the-eye.playtest.json +41 -0
- package/templates/shooter/playtests/death-no-snap.playtest.json +77 -0
- package/templates/shooter/playtests/debug-ads.playtest.json +58 -0
- package/templates/shooter/playtests/debug-clear.playtest.json +383 -0
- package/templates/shooter/playtests/debug-endurance.playtest.json +61 -0
- package/templates/shooter/playtests/debug-fire.playtest.json +119 -0
- package/templates/shooter/playtests/debug-restart.playtest.json +24 -0
- package/templates/shooter/playtests/enemy-body-is-a-body.playtest.json +79 -0
- package/templates/shooter/playtests/enemy-death-settles.playtest.json +64 -0
- package/templates/shooter/playtests/enemy-flinches-when-hit.playtest.json +75 -0
- package/templates/shooter/playtests/enemy-foot-contact.playtest.json +41 -0
- package/templates/shooter/playtests/enemy-material-is-not-shared.playtest.json +59 -0
- package/templates/shooter/playtests/enemy-reaches-walkway.playtest.json +80 -0
- package/templates/shooter/playtests/enemy-rifle-grip.playtest.json +101 -0
- package/templates/shooter/playtests/enemy-scale.playtest.json +56 -0
- package/templates/shooter/playtests/enemy-stops-without-snapping.playtest.json +486 -0
- package/templates/shooter/playtests/enemy-stride-matches-speed.playtest.json +198 -0
- package/templates/shooter/playtests/enemy-stride-under-crouch.playtest.json +87 -0
- package/templates/shooter/playtests/enemy-uses-crouch-clips.playtest.json +74 -0
- package/templates/shooter/playtests/five-soldiers.playtest.json +83 -0
- package/templates/shooter/playtests/flash-retires.playtest.json +62 -0
- package/templates/shooter/playtests/headshot-hits-head.playtest.json +132 -0
- package/templates/shooter/playtests/hold-to-fire.playtest.json +45 -0
- package/templates/shooter/playtests/input-control.playtest.json +43 -98
- package/templates/shooter/playtests/minimap-state.playtest.json +75 -0
- package/templates/shooter/playtests/performance.playtest.json +62 -26
- package/templates/{starter/playtests/forward.playtest.json → shooter/playtests/round-clock.playtest.json} +11 -16
- package/templates/shooter/playtests/shot-tracks-crosshair.playtest.json +79 -0
- package/templates/shooter/playtests/survives.playtest.json +36 -30
- package/templates/shooter/playtests/walkway-reachable.playtest.json +67 -0
- package/templates/shooter/src/entities/Breakables.ts +412 -0
- package/templates/shooter/src/entities/Enemy.ts +2095 -0
- package/templates/shooter/src/entities/FpsPlayer.ts +283 -0
- package/templates/shooter/src/entities/Rifle.ts +442 -0
- package/templates/shooter/src/entities/Target.ts +199 -83
- package/templates/shooter/src/entities/TouchControls.ts +276 -0
- package/templates/shooter/src/game.ts +75 -41
- package/templates/shooter/src/main.ts +0 -1
- package/templates/shooter/src/postPhysics.ts +36 -0
- package/templates/shooter/src/render/camera.ts +78 -74
- package/templates/shooter/src/render/decals.ts +142 -82
- package/templates/shooter/src/render/facade.ts +1373 -0
- package/templates/shooter/src/render/gunfx.ts +704 -0
- package/templates/shooter/src/render/lighting.ts +52 -38
- package/templates/shooter/src/render/loading.ts +2 -2
- package/templates/shooter/src/render/materials.ts +100 -88
- package/templates/shooter/src/render/occlusion.ts +108 -0
- package/templates/shooter/src/render/palette.ts +10 -10
- package/templates/shooter/src/render/palm.ts +455 -0
- package/templates/shooter/src/render/pooled-billboards.ts +144 -0
- package/templates/shooter/src/render/postprocessing.ts +15 -3
- package/templates/shooter/src/render/quality.ts +40 -82
- package/templates/shooter/src/render/scale.ts +148 -15
- package/templates/shooter/src/render/shapes.ts +138 -613
- package/templates/shooter/src/render/sky.ts +35 -35
- package/templates/shooter/src/render/town-schematic.ts +120 -0
- package/templates/shooter/src/render/town.ts +986 -0
- package/templates/shooter/src/render/townMaterials.ts +160 -0
- package/templates/shooter/src/render/vehicles.ts +741 -0
- package/templates/shooter/src/render/worldEnvironment.ts +52 -1
- package/templates/shooter/src/scenes/Play.ts +727 -650
- package/templates/shooter/src/state.ts +26 -41
- package/templates/shooter/src/style.css +207 -11
- package/templates/shooter/src/surfaces.ts +131 -0
- package/templates/shooter/src/ui/App.tsx +9 -10
- package/templates/shooter/src/ui/Crosshair.tsx +25 -18
- package/templates/shooter/src/ui/GameUi.tsx +6 -9
- package/templates/shooter/src/ui/Hud.tsx +428 -39
- package/templates/shooter/src/ui/Minimap.tsx +164 -0
- package/templates/shooter/src/ui/TouchOverlay.tsx +54 -0
- package/templates/shooter/src/ui/main.tsx +2 -3
- package/templates/shooter/threenative.config.ts +14 -1
- package/templates/shooter/vite.config.ts +4 -1
- package/templates/starter/AGENTS.md +17 -17
- package/templates/starter/CLAUDE.md +17 -17
- package/templates/starter/native-playtests/render-chain.playtest.json +13 -45
- package/templates/starter/package.json +13 -7
- package/templates/starter/playtests/play.playtest.json +2 -1
- package/templates/starter/playtests/survives.playtest.json +1 -1
- package/templates/starter/src/conventions.ts +6 -3
- package/templates/starter/src/entities/Goal.ts +35 -42
- package/templates/starter/src/entities/Player.ts +99 -16
- package/templates/starter/src/render/arena.ts +131 -0
- package/templates/starter/src/render/lighting.ts +27 -44
- package/templates/starter/src/render/materials.ts +164 -35
- package/templates/starter/src/render/palette.ts +16 -16
- package/templates/starter/src/render/postprocessing.ts +6 -7
- package/templates/starter/src/render/quality.ts +43 -101
- package/templates/starter/src/render/shapes.ts +1 -1
- package/templates/starter/src/render/sky.ts +39 -45
- package/templates/starter/src/render/touch-controls.ts +3 -1
- package/templates/starter/src/render/worldEnvironment.ts +52 -1
- package/templates/starter/src/scenes/Play.ts +82 -81
- package/templates/starter/threenative.config.ts +14 -1
- package/templates/starter/vite.config.ts +4 -1
- package/templates/tower-defense/.codex/config.toml +19 -0
- package/templates/tower-defense/.cursor/mcp.json +32 -0
- package/templates/tower-defense/.gemini/settings.json +32 -0
- package/templates/tower-defense/.mcp.json +32 -0
- package/templates/tower-defense/.vscode/mcp.json +36 -0
- package/templates/tower-defense/.zed/settings.json +36 -0
- package/templates/{defense → tower-defense}/AGENTS.md +14 -12
- package/templates/{defense → tower-defense}/CLAUDE.md +14 -12
- package/templates/tower-defense/README.md +16 -0
- package/templates/tower-defense/index.html +12 -0
- package/templates/tower-defense/kit.json +7 -0
- package/templates/tower-defense/opencode.json +41 -0
- package/templates/tower-defense/package.json +56 -0
- package/templates/tower-defense/playtests/arsenal.playtest.json +214 -0
- package/templates/tower-defense/playtests/defeat.playtest.json +85 -0
- package/templates/tower-defense/playtests/look.playtest.json +130 -0
- package/templates/tower-defense/playtests/performance.playtest.json +77 -0
- package/templates/tower-defense/playtests/placement.playtest.json +115 -0
- package/templates/{defense → tower-defense}/playtests/pointer-placement.playtest.json +21 -49
- package/templates/tower-defense/playtests/strike.playtest.json +98 -0
- package/templates/tower-defense/playtests/survives.playtest.json +85 -0
- package/templates/tower-defense/playtests/target-priority.playtest.json +177 -0
- package/templates/tower-defense/playtests/upgrade-recycle.playtest.json +124 -0
- package/templates/tower-defense/playtests/victory.playtest.json +810 -0
- package/templates/tower-defense/src/balance.ts +187 -0
- package/templates/tower-defense/src/board/Board.ts +100 -0
- package/templates/tower-defense/src/board/Route.ts +84 -0
- package/templates/tower-defense/src/camera-rig.ts +62 -0
- package/templates/tower-defense/src/economy.ts +64 -0
- package/templates/tower-defense/src/effects/Effects.ts +284 -0
- package/templates/tower-defense/src/enemies/Enemy.ts +198 -0
- package/templates/tower-defense/src/game.ts +72 -0
- package/templates/tower-defense/src/intents.ts +21 -0
- package/templates/tower-defense/src/main.ts +15 -0
- package/templates/tower-defense/src/physics.ts +6 -0
- package/templates/tower-defense/src/render/camera.ts +38 -0
- package/templates/tower-defense/src/render/lighting.ts +42 -0
- package/templates/{defense → tower-defense}/src/render/loading.ts +3 -3
- package/templates/tower-defense/src/render/materials.ts +103 -0
- package/templates/tower-defense/src/render/palette.ts +58 -0
- package/templates/tower-defense/src/render/postprocessing.ts +46 -0
- package/templates/tower-defense/src/render/quality.ts +128 -0
- package/templates/tower-defense/src/render/shapes.ts +550 -0
- package/templates/tower-defense/src/render/sky.ts +27 -0
- package/templates/tower-defense/src/render/worldEnvironment.ts +809 -0
- package/templates/tower-defense/src/scenes/Battle.ts +539 -0
- package/templates/{shooter → tower-defense}/src/scenes/Boot.ts +3 -3
- package/templates/tower-defense/src/state.ts +88 -0
- package/templates/tower-defense/src/style.css +137 -0
- package/templates/tower-defense/src/towers/Tower.ts +230 -0
- package/templates/tower-defense/src/towers/targeting.ts +97 -0
- package/templates/tower-defense/src/ui/Hud.tsx +270 -0
- package/templates/tower-defense/src/ui/Menu.tsx +134 -0
- package/templates/tower-defense/src/ui/icons.tsx +54 -0
- package/templates/tower-defense/src/ui/main.tsx +14 -0
- package/templates/tower-defense/src/waves.ts +90 -0
- package/templates/{defense → tower-defense}/threenative.config.ts +14 -1
- package/templates/tower-defense/vite.config.ts +41 -0
- package/agent-files/.claude/skills/file-engine-bug/SKILL.md +0 -59
- package/agent-files/.claude/skills/ponytail/SKILL.md +0 -68
- package/agent-files/.claude/skills/prd-creator/SKILL.md +0 -40
- package/agent-files/.claude/skills/threenative-assets/SKILL.md +0 -53
- package/agent-files/.claude/skills/threenative-capabilities/SKILL.md +0 -27
- package/agent-files/.claude/skills/threenative-context/SKILL.md +0 -65
- package/agent-files/.claude/skills/threenative-performance/SKILL.md +0 -58
- package/agent-files/.claude/skills/threenative-playtest/SKILL.md +0 -44
- package/agent-files/.claude/skills/threenative-ui/SKILL.md +0 -20
- package/agent-files/.claude/skills/threenative-visuals/SKILL.md +0 -41
- package/agent-files/AGENT-ROLES.md +0 -26
- package/templates/action-rpg/src/render/shapes.ts +0 -269
- package/templates/action-rpg/src/render/types.ts +0 -3
- package/templates/action-rpg/src/scenes/Boot.ts +0 -12
- package/templates/defense/README.md +0 -10
- package/templates/defense/kit.json +0 -7
- package/templates/defense/playtests/leak.playtest.json +0 -23
- package/templates/defense/playtests/placement.playtest.json +0 -40
- package/templates/defense/playtests/scan.playtest.json +0 -20
- package/templates/defense/playtests/survive.playtest.json +0 -45
- package/templates/defense/playtests/survives.playtest.json +0 -36
- package/templates/defense/src/attackers/Attacker.ts +0 -120
- package/templates/defense/src/board/Route.ts +0 -94
- package/templates/defense/src/conventions.ts +0 -18
- package/templates/defense/src/economy.ts +0 -36
- package/templates/defense/src/entities/Player.ts +0 -52
- package/templates/defense/src/game.ts +0 -51
- package/templates/defense/src/physics.ts +0 -13
- package/templates/defense/src/placement/Buildable.ts +0 -49
- package/templates/defense/src/render/camera.ts +0 -16
- package/templates/defense/src/render/lighting.ts +0 -37
- package/templates/defense/src/render/materials.ts +0 -22
- package/templates/defense/src/render/palette.ts +0 -28
- package/templates/defense/src/render/quality.ts +0 -170
- package/templates/defense/src/render/shapes.ts +0 -246
- package/templates/defense/src/render/sky.ts +0 -45
- package/templates/defense/src/scenes/Boot.ts +0 -12
- package/templates/defense/src/scenes/Defense.ts +0 -231
- package/templates/defense/src/state.ts +0 -56
- package/templates/defense/src/towers/Tower.ts +0 -95
- package/templates/defense/src/towers/targeting.ts +0 -53
- package/templates/defense/src/ui/Hud.tsx +0 -62
- package/templates/defense/src/ui/Menu.tsx +0 -7
- package/templates/defense/src/waves.ts +0 -40
- package/templates/minimal/playtests/atmosphere.playtest.json +0 -32
- package/templates/minimal/src/render/hud.ts +0 -69
- package/templates/platformer/playtests/avoidance.playtest.json +0 -28
- package/templates/platformer/playtests/chase.playtest.json +0 -21
- package/templates/platformer/playtests/collision-layers.playtest.json +0 -36
- package/templates/platformer/playtests/oneway.playtest.json +0 -44
- package/templates/platformer/playtests/patrol.playtest.json +0 -13
- package/templates/platformer/playtests/physics.playtest.json +0 -14
- package/templates/platformer/playtests/stomp-rise.playtest.json +0 -55
- package/templates/platformer/playtests/terminal-loop-fail.playtest.json +0 -41
- package/templates/platformer/playtests/terminal-loop-win.playtest.json +0 -52
- package/templates/platformer/src/conventions.ts +0 -18
- package/templates/platformer/src/entities/Character.ts +0 -286
- package/templates/platformer/src/entities/Chaser.ts +0 -118
- package/templates/platformer/src/entities/Patrol.ts +0 -93
- package/templates/platformer/src/level/Platform.ts +0 -46
- package/templates/platformer/src/render/rig.ts +0 -60
- package/templates/platformer/src/render/terrain.ts +0 -31
- package/templates/platformer/src/scenes/Level.ts +0 -241
- package/templates/puzzle/README.md +0 -43
- package/templates/puzzle/playtests/carry.playtest.json +0 -71
- package/templates/puzzle/playtests/swing.playtest.json +0 -38
- package/templates/puzzle/src/conventions.ts +0 -25
- package/templates/puzzle/src/entities/Ball.ts +0 -70
- package/templates/puzzle/src/entities/Gripper.ts +0 -69
- package/templates/puzzle/src/entities/Pendulum.ts +0 -89
- package/templates/puzzle/src/physics.ts +0 -19
- package/templates/puzzle/src/room.ts +0 -83
- package/templates/puzzle/src/scenes/Boot.ts +0 -12
- package/templates/puzzle/src/scenes/Puzzle.ts +0 -158
- package/templates/shooter/playtests/combat.playtest.json +0 -48
- package/templates/shooter/playtests/fail.playtest.json +0 -31
- package/templates/shooter/playtests/per-item.playtest.json +0 -59
- package/templates/shooter/playtests/shooter.playtest.json +0 -99
- package/templates/shooter/playtests/touch-controls.playtest.json +0 -42
- package/templates/shooter/playtests/weapon-cycle.playtest.json +0 -164
- package/templates/shooter/src/combat/damage.ts +0 -40
- package/templates/shooter/src/conventions.ts +0 -51
- package/templates/shooter/src/entities/Pickup.ts +0 -70
- package/templates/shooter/src/entities/Player.ts +0 -310
- package/templates/shooter/src/level/SpawnPoints.ts +0 -28
- package/templates/shooter/src/playtest-events.ts +0 -15
- package/templates/shooter/src/render/touch-controls.ts +0 -305
- package/templates/shooter/src/render/types.ts +0 -3
- package/templates/shooter/src/render/ui.css +0 -330
- package/templates/shooter/src/render/ui.ts +0 -75
- package/templates/shooter/src/render/vfx.ts +0 -215
- package/templates/shooter/src/ui/Menu.tsx +0 -41
- package/templates/shooter/src/waves.ts +0 -50
- package/templates/shooter/src/weapons/Hitscan.ts +0 -42
- package/templates/shooter/src/weapons/Projectile.ts +0 -92
- package/templates/shooter/src/weapons/Viewmodel.ts +0 -275
- package/templates/starter/playtests/assets.playtest.json +0 -65
- package/templates/starter/playtests/buffer.playtest.json +0 -79
- package/templates/starter/playtests/cloth.playtest.json +0 -113
- package/templates/starter/playtests/coyote.playtest.json +0 -87
- package/templates/starter/playtests/gameover.playtest.json +0 -66
- package/templates/starter/playtests/goal.playtest.json +0 -67
- package/templates/starter/playtests/look.playtest.json +0 -175
- package/templates/starter/playtests/models-baseline.png +0 -0
- package/templates/starter/playtests/models.playtest.json +0 -74
- package/templates/starter/playtests/monitoring.playtest.json +0 -72
- package/templates/starter/playtests/odometer.playtest.json +0 -54
- package/templates/starter/playtests/restart.playtest.json +0 -91
- package/templates/starter/playtests/seed.playtest.json +0 -54
- package/templates/starter/playtests/textures-baseline.png +0 -0
- package/templates/starter/playtests/textures.playtest.json +0 -74
- package/templates/starter/playtests/touch-controls.playtest.json +0 -42
- package/templates/starter/playtests/zoom-pinch.playtest.json +0 -86
- package/templates/starter/playtests/zoom-wheel.playtest.json +0 -59
- package/templates/starter/src/render/coast.ts +0 -199
- package/templates/starter/src/render/hero.ts +0 -88
- package/templates/starter/src/render/implicitSurface.ts +0 -199
- package/templates/starter/src/render/kuwahara.ts +0 -174
- package/templates/starter/src/render/outline.ts +0 -141
- package/templates/starter/src/render/painterly.ts +0 -86
- package/templates/starter/src/render/rockRidge.ts +0 -198
- package/templates/starter/src/render/rockRidge.worker.ts +0 -77
- package/templates/starter/src/render/scenery.ts +0 -40
- package/templates/starter/src/render/textureLifetime.ts +0 -53
- package/templates/starter/src/render/water.ts +0 -38
- package/templates/starter/src/render/watercolor.ts +0 -85
- /package/templates/{starter → puzzle}/playtests/boot-failure.playtest.json +0 -0
- /package/templates/{starter → puzzle}/playtests/pause.playtest.json +0 -0
- /package/templates/{defense → rts}/.codex/config.toml +0 -0
- /package/templates/{defense → rts}/.cursor/mcp.json +0 -0
- /package/templates/{defense → rts}/.gemini/settings.json +0 -0
- /package/templates/{defense → rts}/.mcp.json +0 -0
- /package/templates/{defense → rts}/.vscode/mcp.json +0 -0
- /package/templates/{defense → rts}/.zed/settings.json +0 -0
- /package/templates/{defense → rts}/index.html +0 -0
- /package/templates/{defense → rts}/opencode.json +0 -0
- /package/templates/{defense → rts}/src/main.ts +0 -0
- /package/templates/{defense → rts}/src/ui/main.tsx +0 -0
- /package/templates/{defense → tower-defense}/public/favicon.svg +0 -0
- /package/templates/{defense → tower-defense}/src/playtest-events.ts +0 -0
- /package/templates/{defense → tower-defense}/src/ui/App.tsx +0 -0
- /package/templates/{defense → tower-defense}/src/ui/GameUi.tsx +0 -0
- /package/templates/{defense → tower-defense}/tailwind.config.ts +0 -0
- /package/templates/{defense → tower-defense}/tsconfig.json +0 -0
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
// Generated source: the starter owns this painterly algorithm and may replace it freely.
|
|
2
|
-
import { HalfFloatType } from "three";
|
|
3
|
-
import * as tsl from "three/tsl";
|
|
4
|
-
import type { Node } from "three/webgpu";
|
|
5
|
-
import { createTextureScope } from "./textureLifetime.js";
|
|
6
|
-
export type KernelOffset = { readonly x: number; readonly y: number };
|
|
7
|
-
export interface IKuwaharaStageOptions {
|
|
8
|
-
readonly anisotropy?: number;
|
|
9
|
-
readonly radius?: number;
|
|
10
|
-
readonly resolutionScale?: number;
|
|
11
|
-
readonly strength?: number;
|
|
12
|
-
}
|
|
13
|
-
export interface IKuwaharaStage {
|
|
14
|
-
readonly after: "outline";
|
|
15
|
-
readonly build: (input: unknown) => unknown;
|
|
16
|
-
readonly dispose: () => void;
|
|
17
|
-
readonly minimumTier: "medium";
|
|
18
|
-
readonly name: "kuwahara";
|
|
19
|
-
}
|
|
20
|
-
function sectorSampleOffsets(radius: number): readonly KernelOffset[] {
|
|
21
|
-
const bounded = boundedRadius(radius);
|
|
22
|
-
const halfWidth = Math.floor(bounded / 2);
|
|
23
|
-
const offsets: KernelOffset[] = [];
|
|
24
|
-
for (let radial = 1; radial <= bounded; radial += 1)
|
|
25
|
-
for (let tangent = -halfWidth; tangent <= halfWidth; tangent += 1)
|
|
26
|
-
offsets.push({ x: radial, y: tangent });
|
|
27
|
-
return offsets;
|
|
28
|
-
}
|
|
29
|
-
export function createKuwaharaStage(options: IKuwaharaStageOptions = {}): IKuwaharaStage {
|
|
30
|
-
const anisotropy = finiteRange(options.anisotropy ?? 0.72, 0, 1, false, "kuwahara anisotropy");
|
|
31
|
-
const radius = boundedRadius(options.radius ?? 5);
|
|
32
|
-
const resolutionScale = finiteRange(
|
|
33
|
-
options.resolutionScale ?? 0.5,
|
|
34
|
-
0,
|
|
35
|
-
1,
|
|
36
|
-
true,
|
|
37
|
-
"kuwahara resolutionScale",
|
|
38
|
-
);
|
|
39
|
-
const strength = finiteRange(options.strength ?? 0.82, 0, 1, false, "kuwahara strength");
|
|
40
|
-
const textureScope = createTextureScope();
|
|
41
|
-
const dispose = textureScope.dispose;
|
|
42
|
-
return {
|
|
43
|
-
after: "outline",
|
|
44
|
-
build: (input) => {
|
|
45
|
-
if (!isNode(input)) throw new Error("kuwahara input is missing");
|
|
46
|
-
if (strength === 0) return input;
|
|
47
|
-
dispose();
|
|
48
|
-
const source = textureScope.texture(input) as unknown as ITextureNode;
|
|
49
|
-
const texel = tsl.screenSize.reciprocal();
|
|
50
|
-
const sampleUv = (x: Node<"float"> | number, y: Node<"float"> | number): Node<"vec2"> =>
|
|
51
|
-
tsl.screenUV.add(texel.mul(tsl.vec2(x, y))).clamp(0, 1) as Node<"vec2">;
|
|
52
|
-
const sampleColour = (x: number, y: number): Node<"float"> =>
|
|
53
|
-
tsl.luminance(source.sample(sampleUv(x, y)).rgb);
|
|
54
|
-
const gradientX = sampleColour(1, 0).sub(sampleColour(-1, 0)).mul(0.5);
|
|
55
|
-
const gradientY = sampleColour(0, 1).sub(sampleColour(0, -1)).mul(0.5);
|
|
56
|
-
const tensor = makeHalfFloatScratch(
|
|
57
|
-
textureScope,
|
|
58
|
-
tsl.vec4(gradientX.mul(gradientX), gradientX.mul(gradientY), gradientY.mul(gradientY), 1),
|
|
59
|
-
resolutionScale,
|
|
60
|
-
);
|
|
61
|
-
const tensorSample = tensor.sample(tsl.screenUV);
|
|
62
|
-
const orientation = tsl
|
|
63
|
-
.atan(tensorSample.y.mul(2), tensorSample.x.sub(tensorSample.z))
|
|
64
|
-
.mul(0.5);
|
|
65
|
-
const axis = tsl.vec2(tsl.cos(orientation), tsl.sin(orientation));
|
|
66
|
-
const sectorOffsets = sectorSampleOffsets(radius);
|
|
67
|
-
const sector = (sectorIndex: number) => {
|
|
68
|
-
let mean: Node<"vec3"> = tsl.vec3(0);
|
|
69
|
-
let secondMoment: Node<"vec3"> = tsl.vec3(0);
|
|
70
|
-
const angle = (sectorIndex / 8) * Math.PI * 2;
|
|
71
|
-
const sectorAxis = tsl.vec2(
|
|
72
|
-
axis.x.mul(Math.cos(angle)).sub(axis.y.mul(Math.sin(angle))),
|
|
73
|
-
axis.y.mul(Math.cos(angle)).add(axis.x.mul(Math.sin(angle))),
|
|
74
|
-
);
|
|
75
|
-
for (const localOffset of sectorOffsets) {
|
|
76
|
-
const offset = transformKernelOffsetNode(
|
|
77
|
-
tsl.vec2(localOffset.x, localOffset.y),
|
|
78
|
-
sectorAxis,
|
|
79
|
-
anisotropy,
|
|
80
|
-
);
|
|
81
|
-
const colour = source.sample(sampleUv(offset.x, offset.y)).rgb;
|
|
82
|
-
mean = mean.add(colour);
|
|
83
|
-
secondMoment = secondMoment.add(colour.mul(colour));
|
|
84
|
-
}
|
|
85
|
-
const average = mean.div(sectorOffsets.length);
|
|
86
|
-
const variance = secondMoment.div(sectorOffsets.length).sub(average.mul(average)).max(0);
|
|
87
|
-
return { mean: average, score: tsl.luminance(variance) };
|
|
88
|
-
};
|
|
89
|
-
let best = sector(0);
|
|
90
|
-
for (let sectorIndex = 1; sectorIndex < 8; sectorIndex += 1) {
|
|
91
|
-
const candidate = sector(sectorIndex);
|
|
92
|
-
const candidateWins = candidate.score.lessThan(best.score);
|
|
93
|
-
best = {
|
|
94
|
-
mean: tsl.select(candidateWins, candidate.mean, best.mean) as Node<"vec3">,
|
|
95
|
-
score: tsl.select(candidateWins, candidate.score, best.score) as Node<"float">,
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
const base = source.sample(tsl.screenUV);
|
|
99
|
-
const paint = makeHalfFloatScratch(
|
|
100
|
-
textureScope,
|
|
101
|
-
tsl.vec4(best.mean, base.a),
|
|
102
|
-
resolutionScale,
|
|
103
|
-
);
|
|
104
|
-
return mixColour(base, paint.sample(tsl.screenUV).rgb, strength);
|
|
105
|
-
},
|
|
106
|
-
dispose,
|
|
107
|
-
minimumTier: "medium",
|
|
108
|
-
name: "kuwahara",
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
interface ITextureNode extends Node<"vec4"> {
|
|
112
|
-
sample(uv: Node<"vec2">): Node<"vec4">;
|
|
113
|
-
}
|
|
114
|
-
function makeHalfFloatScratch(
|
|
115
|
-
scope: ReturnType<typeof createTextureScope>,
|
|
116
|
-
node: Node<"vec4">,
|
|
117
|
-
resolutionScale: number,
|
|
118
|
-
): IRawScratch {
|
|
119
|
-
let scratch: IRawScratch | undefined;
|
|
120
|
-
try {
|
|
121
|
-
scratch = scope.own(
|
|
122
|
-
tsl.rtt(node, null, null, { type: HalfFloatType }) as unknown as IRawScratch,
|
|
123
|
-
);
|
|
124
|
-
scratch.setResolutionScale(resolutionScale);
|
|
125
|
-
} catch (error) {
|
|
126
|
-
scope.dispose();
|
|
127
|
-
throw new Error(
|
|
128
|
-
`kuwahara scratch allocation failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
129
|
-
);
|
|
130
|
-
}
|
|
131
|
-
if (scratch.renderTarget.texture.type !== HalfFloatType) {
|
|
132
|
-
scope.dispose();
|
|
133
|
-
throw new Error("kuwahara scratch format is not half-float");
|
|
134
|
-
}
|
|
135
|
-
return scratch;
|
|
136
|
-
}
|
|
137
|
-
interface IRawScratch extends ITextureNode {
|
|
138
|
-
readonly renderTarget: { readonly texture: { readonly type: number }; dispose: () => void };
|
|
139
|
-
setResolutionScale(scale: number): void;
|
|
140
|
-
}
|
|
141
|
-
function transformKernelOffsetNode(
|
|
142
|
-
offset: Node<"vec2">,
|
|
143
|
-
axis: Node<"vec2">,
|
|
144
|
-
anisotropy: number,
|
|
145
|
-
): Node<"vec2"> {
|
|
146
|
-
const scaled = tsl.vec2(offset.x.mul(1 + anisotropy), offset.y.mul(1 - anisotropy));
|
|
147
|
-
return tsl.vec2(
|
|
148
|
-
axis.x.mul(scaled.x).sub(axis.y.mul(scaled.y)),
|
|
149
|
-
axis.y.mul(scaled.x).add(axis.x.mul(scaled.y)),
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
function mixColour(base: Node<"vec4">, paint: Node<"vec3">, strength: number): Node<"vec4"> {
|
|
153
|
-
return tsl.mix(base, tsl.vec4(paint, base.a), strength) as Node<"vec4">;
|
|
154
|
-
}
|
|
155
|
-
function boundedRadius(value: number): number {
|
|
156
|
-
if (!Number.isInteger(value) || value < 1 || value > 9)
|
|
157
|
-
throw new Error("kuwahara radius must be an integer from 1 through 9");
|
|
158
|
-
return value;
|
|
159
|
-
}
|
|
160
|
-
function finiteRange(
|
|
161
|
-
value: number,
|
|
162
|
-
minimum: number,
|
|
163
|
-
maximum: number,
|
|
164
|
-
exclusiveMinimum: boolean,
|
|
165
|
-
name: string,
|
|
166
|
-
): number {
|
|
167
|
-
const lower = exclusiveMinimum ? value <= minimum : value < minimum;
|
|
168
|
-
if (!Number.isFinite(value) || lower || value > maximum)
|
|
169
|
-
throw new Error(`${name} must be finite and in range`);
|
|
170
|
-
return value;
|
|
171
|
-
}
|
|
172
|
-
function isNode(value: unknown): value is Node {
|
|
173
|
-
return !!value && typeof value === "object" && (value as { isNode?: boolean }).isNode === true;
|
|
174
|
-
}
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
// Generated source. This stage is ordinary Three.js TSL; the engine only orders and measures it.
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
cameraFar,
|
|
5
|
-
cameraNear,
|
|
6
|
-
color,
|
|
7
|
-
luminance,
|
|
8
|
-
mix,
|
|
9
|
-
perspectiveDepthToViewZ,
|
|
10
|
-
screenSize,
|
|
11
|
-
screenUV,
|
|
12
|
-
texture,
|
|
13
|
-
vec2,
|
|
14
|
-
vec4,
|
|
15
|
-
} from "three/tsl";
|
|
16
|
-
import type { Node } from "three/webgpu";
|
|
17
|
-
import { createTextureScope } from "./textureLifetime.js";
|
|
18
|
-
|
|
19
|
-
export interface IOutlineStageOptions {
|
|
20
|
-
/** The depth attachment written by the scene pass. */
|
|
21
|
-
readonly depthNode: Node;
|
|
22
|
-
/** Ink colour and thresholds are this game's look decisions. */
|
|
23
|
-
readonly inkColor?: number;
|
|
24
|
-
readonly strength?: number;
|
|
25
|
-
readonly threshold?: number;
|
|
26
|
-
readonly softness?: number;
|
|
27
|
-
readonly depthWeight?: number;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface IOutlineStage {
|
|
31
|
-
readonly after: "bloom";
|
|
32
|
-
readonly build: (input: unknown) => unknown;
|
|
33
|
-
readonly dispose: () => void;
|
|
34
|
-
readonly name: "outline";
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Eight-tap Sobel edge ink, normalised to the physical framebuffer pixel size.
|
|
39
|
-
*
|
|
40
|
-
* Colour edges catch the painted prop boundaries while linearised depth catches silhouettes
|
|
41
|
-
* whose two sides happen to have similar colours. The stage samples the original chain input
|
|
42
|
-
* and never owns a material, palette or renderer fallback.
|
|
43
|
-
*/
|
|
44
|
-
export function createOutlineStage(options: IOutlineStageOptions): IOutlineStage {
|
|
45
|
-
if (!isNode(options.depthNode)) throw new Error("outline depth source is missing");
|
|
46
|
-
const strength = finiteNonNegative(options.strength ?? 0.8, "outline strength");
|
|
47
|
-
const threshold = finiteNonNegative(options.threshold ?? 0.12, "outline threshold");
|
|
48
|
-
const softness = finitePositive(options.softness ?? 0.16, "outline softness");
|
|
49
|
-
const depthWeight = finiteUnit(options.depthWeight ?? 0.65, "outline depthWeight");
|
|
50
|
-
const colourWeight = 1 - depthWeight;
|
|
51
|
-
const ink = color(options.inkColor ?? 0x142331);
|
|
52
|
-
const textureScope = createTextureScope();
|
|
53
|
-
|
|
54
|
-
return {
|
|
55
|
-
after: "bloom",
|
|
56
|
-
build: (input) => {
|
|
57
|
-
textureScope.dispose();
|
|
58
|
-
if (!isNode(input)) throw new Error("outline input is missing");
|
|
59
|
-
if (strength === 0) return input;
|
|
60
|
-
const source = textureScope.texture(input) as unknown as ITextureNode;
|
|
61
|
-
const depthSource = texture(options.depthNode as never);
|
|
62
|
-
const texel = screenSize.reciprocal();
|
|
63
|
-
const sampleUv = (x: number, y: number): Node<"vec2"> =>
|
|
64
|
-
screenUV.add(texel.mul(vec2(x, y))).clamp(0, 1) as Node<"vec2">;
|
|
65
|
-
const sampleColour = (x: number, y: number): Node<"float"> =>
|
|
66
|
-
luminance(source.sample(sampleUv(x, y)).rgb);
|
|
67
|
-
const sampleDepth = (x: number, y: number): Node<"float"> =>
|
|
68
|
-
perspectiveDepthToViewZ(depthSource.sample(sampleUv(x, y)).r, cameraNear, cameraFar);
|
|
69
|
-
|
|
70
|
-
// Sobel's eight neighbours use physical-pixel offsets, so a resize does not change the
|
|
71
|
-
// apparent line width. This is the same eight-tap neighbourhood for colour and depth.
|
|
72
|
-
const colourX = sampleColour(-1, -1)
|
|
73
|
-
.negate()
|
|
74
|
-
.add(sampleColour(-1, 0).mul(-2))
|
|
75
|
-
.add(sampleColour(-1, 1).negate())
|
|
76
|
-
.add(sampleColour(1, -1))
|
|
77
|
-
.add(sampleColour(1, 0).mul(2))
|
|
78
|
-
.add(sampleColour(1, 1));
|
|
79
|
-
const colourY = sampleColour(-1, -1)
|
|
80
|
-
.negate()
|
|
81
|
-
.add(sampleColour(0, -1).mul(-2))
|
|
82
|
-
.add(sampleColour(1, -1).negate())
|
|
83
|
-
.add(sampleColour(-1, 1))
|
|
84
|
-
.add(sampleColour(0, 1).mul(2))
|
|
85
|
-
.add(sampleColour(1, 1));
|
|
86
|
-
const depthX = sampleDepth(-1, -1)
|
|
87
|
-
.negate()
|
|
88
|
-
.add(sampleDepth(-1, 0).mul(-2))
|
|
89
|
-
.add(sampleDepth(-1, 1).negate())
|
|
90
|
-
.add(sampleDepth(1, -1))
|
|
91
|
-
.add(sampleDepth(1, 0).mul(2))
|
|
92
|
-
.add(sampleDepth(1, 1));
|
|
93
|
-
const depthY = sampleDepth(-1, -1)
|
|
94
|
-
.negate()
|
|
95
|
-
.add(sampleDepth(0, -1).mul(-2))
|
|
96
|
-
.add(sampleDepth(1, -1).negate())
|
|
97
|
-
.add(sampleDepth(-1, 1))
|
|
98
|
-
.add(sampleDepth(0, 1).mul(2))
|
|
99
|
-
.add(sampleDepth(1, 1));
|
|
100
|
-
const centreDepth = sampleDepth(0, 0).abs().max(1);
|
|
101
|
-
const colourEdge = colourX.mul(colourX).add(colourY.mul(colourY)).sqrt();
|
|
102
|
-
const depthEdge = depthX.mul(depthX).add(depthY.mul(depthY)).sqrt().div(centreDepth);
|
|
103
|
-
const edge = colourEdge.mul(colourWeight).add(depthEdge.mul(depthWeight));
|
|
104
|
-
const mask = edge
|
|
105
|
-
.smoothstep(threshold, threshold + softness)
|
|
106
|
-
.mul(strength)
|
|
107
|
-
.clamp(0, 1);
|
|
108
|
-
const base = source.sample(screenUV);
|
|
109
|
-
return mix(base, vec4(ink, base.a), mask);
|
|
110
|
-
},
|
|
111
|
-
dispose: textureScope.dispose,
|
|
112
|
-
name: "outline",
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
interface ITextureNode extends Node<"vec4"> {
|
|
117
|
-
sample(uv: Node<"vec2">): Node<"vec4">;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function isNode(value: unknown): value is Node {
|
|
121
|
-
return (
|
|
122
|
-
typeof value === "object" && value !== null && (value as { isNode?: boolean }).isNode === true
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
function finiteNonNegative(value: number, name: string): number {
|
|
127
|
-
if (!Number.isFinite(value) || value < 0)
|
|
128
|
-
throw new Error(`${name} must be finite and non-negative`);
|
|
129
|
-
return value;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function finitePositive(value: number, name: string): number {
|
|
133
|
-
if (!Number.isFinite(value) || value <= 0) throw new Error(`${name} must be finite and positive`);
|
|
134
|
-
return value;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function finiteUnit(value: number, name: string): number {
|
|
138
|
-
if (!Number.isFinite(value) || value < 0 || value > 1)
|
|
139
|
-
throw new Error(`${name} must be finite and between 0 and 1`);
|
|
140
|
-
return value;
|
|
141
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
// The starter's painterly look: an ink outline, a Kuwahara smear, and a watercolour wash.
|
|
2
|
-
//
|
|
3
|
-
// This file exists because `worldEnvironment.ts` may not contain it. That file is the render-chain
|
|
4
|
-
// plumbing every kit copies verbatim, and `shared-render-sources.spec.ts` fails when one kit's copy
|
|
5
|
-
// stops matching the others — which is exactly what happens when a kit's own art direction is
|
|
6
|
-
// written into it. Bloom and vignette live in there because they are grading primitives every kit
|
|
7
|
-
// wants; kuwahara, outline and watercolour are one kit's aesthetic, and an aesthetic shipped into
|
|
8
|
-
// ten kits so that one can use it is the preset system the charter closed with evidence.
|
|
9
|
-
//
|
|
10
|
-
// So the plumbing exposes a seam — `authoredStageNames` and `authoredStages` — and this is what the
|
|
11
|
-
// starter passes through it.
|
|
12
|
-
|
|
13
|
-
import { createKuwaharaStage } from "./kuwahara.js";
|
|
14
|
-
import { createOutlineStage } from "./outline.js";
|
|
15
|
-
import { createWatercolorStage } from "./watercolor.js";
|
|
16
|
-
import type { ChainStage, IWorldEnvironmentStageContext } from "./worldEnvironment.js";
|
|
17
|
-
|
|
18
|
-
/** The knobs the quality presets set. Every one is this kit's, not the framework's. */
|
|
19
|
-
export interface IPainterlyOptions {
|
|
20
|
-
readonly outlineEnabled?: boolean;
|
|
21
|
-
readonly outlineInkColor?: number;
|
|
22
|
-
readonly outlineStrength?: number;
|
|
23
|
-
readonly outlineThreshold?: number;
|
|
24
|
-
readonly outlineSoftness?: number;
|
|
25
|
-
readonly outlineDepthWeight?: number;
|
|
26
|
-
readonly kuwaharaEnabled?: boolean;
|
|
27
|
-
readonly kuwaharaRadius?: number;
|
|
28
|
-
readonly kuwaharaResolutionScale?: number;
|
|
29
|
-
readonly kuwaharaAnisotropy?: number;
|
|
30
|
-
readonly kuwaharaStrength?: number;
|
|
31
|
-
readonly watercolorEnabled?: boolean;
|
|
32
|
-
readonly watercolorLevels?: number;
|
|
33
|
-
readonly watercolorPaperStrength?: number;
|
|
34
|
-
readonly watercolorShadowStrength?: number;
|
|
35
|
-
readonly watercolorShadowTint?: number;
|
|
36
|
-
readonly watercolorStrength?: number;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Which stages run, in chain order.
|
|
41
|
-
*
|
|
42
|
-
* The chain reads this before the scene pass exists — with nothing requested it sets an exposure
|
|
43
|
-
* and never builds a pass at all — so it has to be answerable from the options alone.
|
|
44
|
-
*/
|
|
45
|
-
export function painterlyStageNames(options: IPainterlyOptions): readonly string[] {
|
|
46
|
-
const names: string[] = [];
|
|
47
|
-
if (options.outlineEnabled === true) names.push("outline");
|
|
48
|
-
if (options.kuwaharaEnabled === true) names.push("kuwahara");
|
|
49
|
-
if (options.watercolorEnabled === true) names.push("watercolor");
|
|
50
|
-
return names;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* The complete authored graph, dormant stages included.
|
|
55
|
-
*
|
|
56
|
-
* All three are always defined even when only one is requested, because `watercolor after
|
|
57
|
-
* kuwahara` and `kuwahara after outline` are anchors that must keep naming a stage that exists —
|
|
58
|
-
* otherwise enabling one stage on its own resolves against a name the chain never heard of.
|
|
59
|
-
*/
|
|
60
|
-
export function painterlyStages(
|
|
61
|
-
options: IPainterlyOptions,
|
|
62
|
-
): (context: IWorldEnvironmentStageContext) => readonly ChainStage[] {
|
|
63
|
-
return ({ depthNode }) => [
|
|
64
|
-
createOutlineStage({
|
|
65
|
-
depthNode,
|
|
66
|
-
depthWeight: options.outlineDepthWeight ?? 0.65,
|
|
67
|
-
inkColor: options.outlineInkColor ?? 0x142331,
|
|
68
|
-
softness: options.outlineSoftness ?? 0.16,
|
|
69
|
-
strength: options.outlineStrength ?? 0.8,
|
|
70
|
-
threshold: options.outlineThreshold ?? 0.12,
|
|
71
|
-
}),
|
|
72
|
-
createKuwaharaStage({
|
|
73
|
-
anisotropy: options.kuwaharaAnisotropy ?? 0.72,
|
|
74
|
-
radius: options.kuwaharaRadius ?? 5,
|
|
75
|
-
resolutionScale: options.kuwaharaResolutionScale ?? 0.5,
|
|
76
|
-
strength: options.kuwaharaStrength ?? 0.82,
|
|
77
|
-
}),
|
|
78
|
-
createWatercolorStage({
|
|
79
|
-
levels: options.watercolorLevels ?? 8,
|
|
80
|
-
paperStrength: options.watercolorPaperStrength ?? 0.2,
|
|
81
|
-
shadowStrength: options.watercolorShadowStrength ?? 0.16,
|
|
82
|
-
shadowTint: options.watercolorShadowTint ?? 0x6d5a52,
|
|
83
|
-
strength: options.watercolorStrength ?? 0.72,
|
|
84
|
-
}),
|
|
85
|
-
];
|
|
86
|
-
}
|
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
// Generated source. The field, seed and refinement quality belong to this game.
|
|
2
|
-
import { BufferAttribute, BufferGeometry, Group, type Material, Mesh } from "three";
|
|
3
|
-
import { auditImplicitSurface, buildImplicitSurface } from "./implicitSurface.js";
|
|
4
|
-
import {
|
|
5
|
-
type IRockRidgeWorkerInput,
|
|
6
|
-
type IRockRidgeWorkerMessage,
|
|
7
|
-
createRockRidgeWorkerSource,
|
|
8
|
-
} from "./rockRidge.worker.js";
|
|
9
|
-
// biome-ignore format: compact generated bounds keep the render source under its smell budget.
|
|
10
|
-
const ROCK_RIDGE_BOUNDS = { maxX: 54, maxY: 18, maxZ: -42, minX: -54, minY: -32, minZ: -74 } as const;
|
|
11
|
-
const PREVIEW_SETTINGS = { cellSize: 10, latticeCap: 30_000, protectBoundary: true } as const;
|
|
12
|
-
const REFINED_SETTINGS = { cellSize: 8, latticeCap: 100_000, protectBoundary: true } as const;
|
|
13
|
-
// biome-ignore format: the generated field stays within the render-source smell budget.
|
|
14
|
-
export function sampleGraniteField(x: number, y: number, z: number, seed: number, bounds: IRockRidgeWorkerInput["bounds"]): number {
|
|
15
|
-
const phase = ((seed >>> 0) % 4096) * 0.0015;
|
|
16
|
-
const noise = (index: number): number => {
|
|
17
|
-
let value = Math.imul((index | 0) ^ (seed | 0), 0x45d9f3b);
|
|
18
|
-
value = Math.imul(value ^ (value >>> 16), 0x45d9f3b);
|
|
19
|
-
return ((value ^ (value >>> 16)) >>> 0) / 4_294_967_295;
|
|
20
|
-
};
|
|
21
|
-
const smoothMin = (a: number, b: number, radius: number): number => {
|
|
22
|
-
const h = Math.max(radius - Math.abs(a - b), 0) / radius;
|
|
23
|
-
return Math.min(a, b) - h * h * h * radius / 6;
|
|
24
|
-
};
|
|
25
|
-
const centerZ = -58 + Math.sin(x * 0.08 + phase) * 1.2 + Math.cos(x * 0.17 - phase) * 0.7;
|
|
26
|
-
const top = -5 + Math.sin(x * 0.13 + phase * 2) * 0.8;
|
|
27
|
-
const contactY = -20;
|
|
28
|
-
const bottom = contactY - 2 + Math.cos(x * 0.07 - phase) * 0.45;
|
|
29
|
-
let field = Math.hypot(x / 50, (y - (top + bottom) * 0.5) / ((top - bottom) * 0.5), (z - centerZ) / 12) - 1;
|
|
30
|
-
for (let index = -4; index <= 4; index += 1) {
|
|
31
|
-
const jitter = noise(index + 31);
|
|
32
|
-
const lobeX = index * 11 + (jitter - 0.5) * 3;
|
|
33
|
-
const lobeZ = centerZ + (noise(index + 61) - 0.5) * 3;
|
|
34
|
-
const lobeY = -5 + (noise(index + 91) - 0.5) * 2;
|
|
35
|
-
const lobe = Math.hypot((x - lobeX) / (6.4 + noise(index + 121) * 2.2), (y - lobeY) / (8.5 + noise(index + 151) * 3), (z - lobeZ) / (6.5 + noise(index + 181) * 2)) - 1;
|
|
36
|
-
field = smoothMin(field, lobe, 0.22);
|
|
37
|
-
}
|
|
38
|
-
const edge = Math.min(x - bounds.minX, bounds.maxX - x, y - bounds.minY, bounds.maxY - y, z - bounds.minZ, bounds.maxZ - z);
|
|
39
|
-
return Math.max(field, 0.06 - edge / 4);
|
|
40
|
-
}
|
|
41
|
-
function hashArray(array: Float32Array | Uint32Array): string {
|
|
42
|
-
const bytes = new Uint8Array(array.buffer, array.byteOffset, array.byteLength);
|
|
43
|
-
let hash = 2_166_136_261;
|
|
44
|
-
for (const byte of bytes) hash = Math.imul(hash ^ byte, 16_777_619);
|
|
45
|
-
return (hash >>> 0).toString(16).padStart(8, "0");
|
|
46
|
-
}
|
|
47
|
-
// biome-ignore format: compact generated validation keeps the render source under its smell budget.
|
|
48
|
-
function topologyError(report: ReturnType<typeof auditImplicitSurface>): Error | undefined {
|
|
49
|
-
if (report.boundaryEdges === 0 && report.degenerateTriangles === 0 && report.windingConflicts === 0 && report.signedVolume > 0)
|
|
50
|
-
return undefined;
|
|
51
|
-
const error = new Error(`boundary=${report.boundaryEdges}, degenerate=${report.degenerateTriangles}, winding=${report.windingConflicts}, volume=${report.signedVolume}`);
|
|
52
|
-
error.name = "TN_ROCK_RIDGE_TOPOLOGY_INVALID";
|
|
53
|
-
return error;
|
|
54
|
-
}
|
|
55
|
-
// biome-ignore format: compact generated mesh attachment keeps the render source under its smell budget.
|
|
56
|
-
function makeMesh(result: ReturnType<typeof buildImplicitSurface>, material: Material, generation: number): { mesh: Mesh; report: ReturnType<typeof auditImplicitSurface> } {
|
|
57
|
-
const report = auditImplicitSurface(result.indices, result.positions);
|
|
58
|
-
const error = topologyError(report);
|
|
59
|
-
if (error !== undefined) throw error;
|
|
60
|
-
const geometry = new BufferGeometry();
|
|
61
|
-
geometry.setAttribute("position", new BufferAttribute(result.positions, 3));
|
|
62
|
-
geometry.setIndex(new BufferAttribute(result.indices, 1));
|
|
63
|
-
geometry.computeVertexNormals();
|
|
64
|
-
geometry.computeBoundingBox();
|
|
65
|
-
geometry.computeBoundingSphere();
|
|
66
|
-
const mesh = new Mesh(geometry, material);
|
|
67
|
-
mesh.name = `granite-ridge-${generation === 0 ? "preview" : "refined"}`;
|
|
68
|
-
mesh.castShadow = false;
|
|
69
|
-
mesh.receiveShadow = false;
|
|
70
|
-
return { mesh, report };
|
|
71
|
-
}
|
|
72
|
-
// biome-ignore format: compact generated controller contract keeps the render source under budget.
|
|
73
|
-
export interface IRockRidgeController { readonly object: Group; readonly state: "preview" | "refined" | "error" | "disposed"; debug(): Record<string, unknown>; dispose(): void; rebuild(seed?: number): void; }
|
|
74
|
-
// biome-ignore format: the controller is a single generated render source with a fixed budget.
|
|
75
|
-
export function createRockRidge(ridgeMaterial: Material, initialSeed: number, options: { deferRefinement?: boolean } = {}): IRockRidgeController {
|
|
76
|
-
const object = new Group();
|
|
77
|
-
object.name = "granite-ridge";
|
|
78
|
-
const preview = buildImplicitSurface({
|
|
79
|
-
...PREVIEW_SETTINGS, bounds: ROCK_RIDGE_BOUNDS, closed: true,
|
|
80
|
-
sample: (x, y, z) => sampleGraniteField(x, y, z, initialSeed, ROCK_RIDGE_BOUNDS),
|
|
81
|
-
});
|
|
82
|
-
let visible = makeMesh(preview, ridgeMaterial, 0);
|
|
83
|
-
object.add(visible.mesh);
|
|
84
|
-
const state = {
|
|
85
|
-
phase: "preview" as IRockRidgeController["state"],
|
|
86
|
-
visibleGeneration: 0,
|
|
87
|
-
requestedGeneration: 0,
|
|
88
|
-
lastError: undefined as string | undefined,
|
|
89
|
-
report: { ...visible.report, buildMs: preview.report.buildMs, cellSize: preview.report.cellSize },
|
|
90
|
-
};
|
|
91
|
-
const workers = new Set<Worker>();
|
|
92
|
-
const workerSource = createRockRidgeWorkerSource(sampleGraniteField);
|
|
93
|
-
const stop = (worker: Worker): void => {
|
|
94
|
-
if (!workers.delete(worker)) return;
|
|
95
|
-
worker.terminate();
|
|
96
|
-
};
|
|
97
|
-
const fail = (error: unknown): void => {
|
|
98
|
-
state.phase = "error";
|
|
99
|
-
state.lastError = error instanceof Error ? `${error.name}: ${error.message}` : String(error);
|
|
100
|
-
for (const worker of [...workers]) stop(worker);
|
|
101
|
-
};
|
|
102
|
-
const swap = (result: ReturnType<typeof buildImplicitSurface>, generation: number, buildMs: number, cellSize: number): void => {
|
|
103
|
-
const next = makeMesh(result, ridgeMaterial, generation);
|
|
104
|
-
const previous = visible.mesh;
|
|
105
|
-
object.add(next.mesh);
|
|
106
|
-
visible = next;
|
|
107
|
-
state.visibleGeneration = generation;
|
|
108
|
-
state.report = { ...next.report, buildMs, cellSize };
|
|
109
|
-
object.remove(previous);
|
|
110
|
-
previous.geometry.dispose();
|
|
111
|
-
};
|
|
112
|
-
const dispatch = (seed: number, settings: typeof REFINED_SETTINGS): void => {
|
|
113
|
-
const generation = state.requestedGeneration + 1;
|
|
114
|
-
state.requestedGeneration = generation;
|
|
115
|
-
if (typeof Worker === "undefined" || typeof URL.createObjectURL !== "function") {
|
|
116
|
-
const error = new Error("TN_ROCK_RIDGE_WORKER_FAILED: classic Worker support is required.");
|
|
117
|
-
fail(error);
|
|
118
|
-
throw error;
|
|
119
|
-
}
|
|
120
|
-
const url = URL.createObjectURL(new Blob([workerSource], { type: "text/javascript" }));
|
|
121
|
-
let worker: Worker;
|
|
122
|
-
try {
|
|
123
|
-
worker = new Worker(url);
|
|
124
|
-
} catch (error) {
|
|
125
|
-
URL.revokeObjectURL(url);
|
|
126
|
-
fail(error);
|
|
127
|
-
throw error;
|
|
128
|
-
}
|
|
129
|
-
URL.revokeObjectURL(url);
|
|
130
|
-
workers.add(worker);
|
|
131
|
-
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: stale-result and error guards stay atomic.
|
|
132
|
-
worker.onmessage = (event: MessageEvent<IRockRidgeWorkerMessage>) => {
|
|
133
|
-
stop(worker);
|
|
134
|
-
const message = event.data;
|
|
135
|
-
if (state.phase === "disposed" || message.generation !== state.requestedGeneration) return;
|
|
136
|
-
if (message.error !== undefined || message.positions === undefined || message.indices === undefined || message.report === undefined) {
|
|
137
|
-
fail(new Error(`${message.name ?? "TN_ROCK_RIDGE_WORKER_FAILED"}: ${message.error ?? "missing result"}`));
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
try {
|
|
141
|
-
const result = { positions: message.positions, indices: message.indices, report: message.report } as ReturnType<typeof buildImplicitSurface>;
|
|
142
|
-
const report = auditImplicitSurface(result.indices, result.positions);
|
|
143
|
-
const error = topologyError(report);
|
|
144
|
-
if (error !== undefined) throw error;
|
|
145
|
-
if (report.boundaryEdges !== message.report.boundaryEdges || report.degenerateTriangles !== message.report.degenerateTriangles || report.windingConflicts !== message.report.windingConflicts)
|
|
146
|
-
throw new Error("TN_ROCK_RIDGE_WORKER_FAILED: report does not match final arrays.");
|
|
147
|
-
swap(result, message.generation, message.report.buildMs, message.report.cellSize);
|
|
148
|
-
state.phase = "refined";
|
|
149
|
-
} catch (error) {
|
|
150
|
-
fail(error);
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
worker.onerror = (event) => {
|
|
154
|
-
stop(worker);
|
|
155
|
-
if (state.phase !== "disposed" && generation === state.requestedGeneration)
|
|
156
|
-
fail(new Error(`TN_ROCK_RIDGE_WORKER_FAILED: ${event.message || "worker error"}`));
|
|
157
|
-
};
|
|
158
|
-
try {
|
|
159
|
-
const input: IRockRidgeWorkerInput = {
|
|
160
|
-
bounds: ROCK_RIDGE_BOUNDS, cellSize: settings.cellSize, generation,
|
|
161
|
-
latticeCap: settings.latticeCap, protectBoundary: settings.protectBoundary, seed,
|
|
162
|
-
};
|
|
163
|
-
worker.postMessage(input);
|
|
164
|
-
} catch (error) {
|
|
165
|
-
stop(worker);
|
|
166
|
-
fail(error);
|
|
167
|
-
throw error;
|
|
168
|
-
}
|
|
169
|
-
};
|
|
170
|
-
if (options.deferRefinement !== true) dispatch(initialSeed, REFINED_SETTINGS);
|
|
171
|
-
return {
|
|
172
|
-
object,
|
|
173
|
-
get state() {
|
|
174
|
-
return state.phase;
|
|
175
|
-
},
|
|
176
|
-
debug: () => ({
|
|
177
|
-
state: state.phase,
|
|
178
|
-
generation: state.visibleGeneration,
|
|
179
|
-
requestedGeneration: state.requestedGeneration,
|
|
180
|
-
positionHash: hashArray(visible.mesh.geometry.getAttribute("position").array as Float32Array),
|
|
181
|
-
indexHash: hashArray(visible.mesh.geometry.index?.array as Uint32Array),
|
|
182
|
-
topology: state.report,
|
|
183
|
-
...(state.lastError === undefined ? {} : { error: state.lastError }),
|
|
184
|
-
}),
|
|
185
|
-
dispose: () => {
|
|
186
|
-
if (state.phase === "disposed") return;
|
|
187
|
-
state.phase = "disposed";
|
|
188
|
-
state.requestedGeneration += 1;
|
|
189
|
-
for (const worker of [...workers]) stop(worker);
|
|
190
|
-
object.remove(visible.mesh);
|
|
191
|
-
visible.mesh.geometry.dispose();
|
|
192
|
-
},
|
|
193
|
-
rebuild: (seed = initialSeed) => {
|
|
194
|
-
if (state.phase === "disposed") return;
|
|
195
|
-
dispatch(seed, REFINED_SETTINGS);
|
|
196
|
-
},
|
|
197
|
-
};
|
|
198
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
// Generated source. The worker is a classic Blob worker so browser and native use one path.
|
|
2
|
-
import { createImplicitSurfaceWorkerSource } from "./implicitSurface.js";
|
|
3
|
-
|
|
4
|
-
export interface IRockRidgeWorkerInput {
|
|
5
|
-
readonly bounds: Readonly<Record<"maxX" | "maxY" | "maxZ" | "minX" | "minY" | "minZ", number>>;
|
|
6
|
-
readonly cellSize: number;
|
|
7
|
-
readonly generation: number;
|
|
8
|
-
readonly latticeCap: number;
|
|
9
|
-
readonly protectBoundary: boolean;
|
|
10
|
-
readonly seed: number;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface IRockRidgeWorkerReport {
|
|
14
|
-
readonly boundaryEdges: number;
|
|
15
|
-
readonly buildMs: number;
|
|
16
|
-
readonly cellSize: number;
|
|
17
|
-
readonly degenerateTriangles: number;
|
|
18
|
-
readonly signedVolume: number;
|
|
19
|
-
readonly triangles: number;
|
|
20
|
-
readonly vertices: number;
|
|
21
|
-
readonly windingConflicts: number;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface IRockRidgeWorkerMessage {
|
|
25
|
-
readonly error?: string;
|
|
26
|
-
readonly generation: number;
|
|
27
|
-
readonly indices?: Uint32Array;
|
|
28
|
-
readonly name?: string;
|
|
29
|
-
readonly positions?: Float32Array;
|
|
30
|
-
readonly report?: IRockRidgeWorkerReport;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function createRockRidgeWorkerSource(
|
|
34
|
-
sampleField: (
|
|
35
|
-
x: number,
|
|
36
|
-
y: number,
|
|
37
|
-
z: number,
|
|
38
|
-
seed: number,
|
|
39
|
-
bounds: IRockRidgeWorkerInput["bounds"],
|
|
40
|
-
) => number,
|
|
41
|
-
): string {
|
|
42
|
-
const extractor = createImplicitSurfaceWorkerSource();
|
|
43
|
-
const field = sampleField.toString();
|
|
44
|
-
return `${extractor}
|
|
45
|
-
const sampleGraniteField = ${field};
|
|
46
|
-
self.onmessage = function (event) {
|
|
47
|
-
const input = event.data;
|
|
48
|
-
try {
|
|
49
|
-
const result = buildImplicitSurface({
|
|
50
|
-
bounds: input.bounds,
|
|
51
|
-
cellSize: input.cellSize,
|
|
52
|
-
closed: true,
|
|
53
|
-
latticeCap: input.latticeCap,
|
|
54
|
-
protectBoundary: input.protectBoundary,
|
|
55
|
-
sample: function (x, y, z) {
|
|
56
|
-
return sampleGraniteField(x, y, z, input.seed, input.bounds);
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
self.postMessage(
|
|
60
|
-
{
|
|
61
|
-
generation: input.generation,
|
|
62
|
-
indices: result.indices,
|
|
63
|
-
positions: result.positions,
|
|
64
|
-
report: result.report,
|
|
65
|
-
},
|
|
66
|
-
[result.indices.buffer, result.positions.buffer],
|
|
67
|
-
);
|
|
68
|
-
} catch (error) {
|
|
69
|
-
self.postMessage({
|
|
70
|
-
error: error instanceof Error ? error.message : String(error),
|
|
71
|
-
generation: input.generation,
|
|
72
|
-
name: error instanceof Error ? error.name : "TN_ROCK_RIDGE_WORKER_FAILED",
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
`;
|
|
77
|
-
}
|