create-threenative 0.2.8 → 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/agent-docs/references/assertion-reference.md +87 -35
- package/agent-docs/references/auto-exposure.md +57 -0
- package/agent-docs/references/capability-reference.md +1097 -23
- 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 +1210 -27
- package/dist/index.d.ts +28 -3
- package/dist/index.js +396 -166
- package/dist/threenative.js +986 -235
- 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/AGENTS.md +8 -9
- package/templates/rain/CLAUDE.md +8 -9
- package/templates/rain/native-playtests/boot.playtest.json +11 -1
- package/templates/rain/package.json +12 -9
- package/templates/rain/playtests/automation.playtest.json +1 -1
- package/templates/rain/playtests/performance.playtest.json +11 -1
- package/templates/rain/playtests/tiers.playtest.json +15 -0
- package/templates/rain/playtests/weather.playtest.json +1 -1
- package/templates/rain/src/game.ts +1 -34
- package/templates/rain/src/render/autoExposure.ts +225 -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/postprocessing.ts +3 -0
- package/templates/rain/src/render/quality.ts +27 -1
- package/templates/rain/src/render/worldEnvironment.ts +433 -30
- package/templates/rain/src/scenes/Boot.ts +14 -0
- package/templates/rain/src/state.ts +5 -1
- package/templates/rain/src/ui/GameUi.tsx +6 -6
- package/templates/rain/tools/generate-shaders.mjs +1 -1
- package/templates/rain/vite.config.ts +10 -2
- 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/AGENTS.md +8 -6
- package/templates/snow/CLAUDE.md +8 -6
- package/templates/snow/package.json +11 -9
- 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/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/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 +33 -1
- package/templates/snow/src/render/materialAssignments.ts +160 -0
- package/templates/snow/src/render/materialLighting.ts +155 -0
- package/templates/snow/src/render/postprocessing.ts +16 -2
- package/templates/snow/src/render/quality.ts +59 -1
- package/templates/snow/src/render/sky.ts +21 -2
- package/templates/snow/src/render/worldEnvironment.ts +433 -30
- package/templates/snow/src/scenes/Snow.ts +29 -1
- package/templates/snow/threenative.config.ts +3 -0
- package/templates/snow/vite.config.ts +10 -2
- 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,281 @@
|
|
|
1
|
+
import { BufferAttribute, BufferGeometry } from 'three';
|
|
2
|
+
|
|
3
|
+
// ../three-native/src/addons/buffer-geometry-utils.ts
|
|
4
|
+
|
|
5
|
+
// ../three-native/src/addons/merge-geometries.ts
|
|
6
|
+
function denormalize(value, array) {
|
|
7
|
+
if (array instanceof Uint32Array) return value / 4294967295;
|
|
8
|
+
if (array instanceof Uint16Array) return value / 65535;
|
|
9
|
+
if (array instanceof Uint8Array) return value / 255;
|
|
10
|
+
if (array instanceof Int32Array) return Math.max(value / 2147483647, -1);
|
|
11
|
+
if (array instanceof Int16Array) return Math.max(value / 32767, -1);
|
|
12
|
+
if (array instanceof Int8Array) return Math.max(value / 127, -1);
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
function normalize(value, array) {
|
|
16
|
+
if (array instanceof Uint32Array) return Math.round(value * 4294967295);
|
|
17
|
+
if (array instanceof Uint16Array) return Math.round(value * 65535);
|
|
18
|
+
if (array instanceof Uint8Array) return Math.round(value * 255);
|
|
19
|
+
if (array instanceof Int32Array) return Math.round(value * 2147483647);
|
|
20
|
+
if (array instanceof Int16Array) return Math.round(value * 32767);
|
|
21
|
+
if (array instanceof Int8Array) return Math.round(value * 127);
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
function component(attribute, index, k) {
|
|
25
|
+
if (attribute.isInterleavedBufferAttribute) return attribute.getComponent(index, k);
|
|
26
|
+
const value = attribute.array[index * attribute.itemSize + k];
|
|
27
|
+
return attribute.normalized ? denormalize(value, attribute.array) : value;
|
|
28
|
+
}
|
|
29
|
+
function store(array, source, at, value) {
|
|
30
|
+
array[at] = source.normalized ? normalize(value, array) : value;
|
|
31
|
+
}
|
|
32
|
+
function mergedIndex(geometries) {
|
|
33
|
+
let length = 0;
|
|
34
|
+
for (const geometry of geometries) length += geometry.index.count;
|
|
35
|
+
const values = new Float64Array(length);
|
|
36
|
+
let at = 0;
|
|
37
|
+
let offset = 0;
|
|
38
|
+
let wide = false;
|
|
39
|
+
for (const geometry of geometries) {
|
|
40
|
+
const index = geometry.index;
|
|
41
|
+
const count = index.count;
|
|
42
|
+
const array = index.isInterleavedBufferAttribute || index.normalized ? void 0 : index.array;
|
|
43
|
+
const step = index.itemSize;
|
|
44
|
+
for (let j = 0; j < count; ++j) {
|
|
45
|
+
const value = (array ? array[j * step] : component(index, j, 0)) + offset;
|
|
46
|
+
wide ||= value >= 65535;
|
|
47
|
+
values[at++] = value;
|
|
48
|
+
}
|
|
49
|
+
offset += geometry.attributes.position.count;
|
|
50
|
+
}
|
|
51
|
+
return wide ? new Uint32Array(values) : new Uint16Array(values);
|
|
52
|
+
}
|
|
53
|
+
var PREFIX = "THREE.BufferGeometryUtils:";
|
|
54
|
+
function defineBufferGeometryUtils(engine) {
|
|
55
|
+
function mergeAttributes2(attributes) {
|
|
56
|
+
let Typed;
|
|
57
|
+
let itemSize;
|
|
58
|
+
let normalized;
|
|
59
|
+
let gpuType = -1;
|
|
60
|
+
let arrayLength = 0;
|
|
61
|
+
for (const attribute of attributes) {
|
|
62
|
+
const made = attribute.array.constructor;
|
|
63
|
+
Typed ??= made;
|
|
64
|
+
if (Typed !== made) {
|
|
65
|
+
console.error(
|
|
66
|
+
`${PREFIX} .mergeAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes.`
|
|
67
|
+
);
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
itemSize ??= attribute.itemSize;
|
|
71
|
+
if (itemSize !== attribute.itemSize) {
|
|
72
|
+
console.error(
|
|
73
|
+
`${PREFIX} .mergeAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes.`
|
|
74
|
+
);
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
normalized ??= attribute.normalized;
|
|
78
|
+
if (normalized !== attribute.normalized) {
|
|
79
|
+
console.error(
|
|
80
|
+
`${PREFIX} .mergeAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes.`
|
|
81
|
+
);
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
if (gpuType === -1) gpuType = attribute.gpuType;
|
|
85
|
+
if (gpuType !== attribute.gpuType) {
|
|
86
|
+
console.error(
|
|
87
|
+
`${PREFIX} .mergeAttributes() failed. BufferAttribute.gpuType must be consistent across matching attributes.`
|
|
88
|
+
);
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
arrayLength += attribute.count * itemSize;
|
|
92
|
+
}
|
|
93
|
+
if (Typed === void 0 || itemSize === void 0) return null;
|
|
94
|
+
const array = new Typed(arrayLength);
|
|
95
|
+
let offset = 0;
|
|
96
|
+
for (const attribute of attributes) {
|
|
97
|
+
if (attribute.isInterleavedBufferAttribute) {
|
|
98
|
+
for (let j = 0; j < attribute.count; j++)
|
|
99
|
+
for (let c = 0; c < itemSize; c++)
|
|
100
|
+
array[offset + j * itemSize + c] = attribute.getComponent(j, c);
|
|
101
|
+
} else array.set(attribute.array, offset);
|
|
102
|
+
offset += attribute.count * itemSize;
|
|
103
|
+
}
|
|
104
|
+
const result = new engine.BufferAttribute(array, itemSize, normalized);
|
|
105
|
+
if (gpuType !== void 0 && result.gpuType !== gpuType) result.gpuType = gpuType;
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
function collect(geometries, merged, useGroups) {
|
|
109
|
+
const first = geometries[0];
|
|
110
|
+
const isIndexed = first.index !== null;
|
|
111
|
+
const attributesUsed = new Set(Object.keys(first.attributes));
|
|
112
|
+
const morphAttributesUsed = new Set(Object.keys(first.morphAttributes));
|
|
113
|
+
const attributes = {};
|
|
114
|
+
const morphAttributes = {};
|
|
115
|
+
let offset = 0;
|
|
116
|
+
for (const [i, geometry] of geometries.entries()) {
|
|
117
|
+
const at = `${PREFIX} .mergeGeometries() failed with geometry at index ${i}.`;
|
|
118
|
+
if (isIndexed !== (geometry.index !== null))
|
|
119
|
+
return `${at} All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them.`;
|
|
120
|
+
let attributesCount = 0;
|
|
121
|
+
for (const name of Object.keys(geometry.attributes)) {
|
|
122
|
+
if (!attributesUsed.has(name))
|
|
123
|
+
return `${at} All geometries must have compatible attributes; make sure "${name}" attribute exists among all geometries, or in none of them.`;
|
|
124
|
+
attributes[name] ??= [];
|
|
125
|
+
attributes[name].push(geometry.attributes[name]);
|
|
126
|
+
attributesCount++;
|
|
127
|
+
}
|
|
128
|
+
if (attributesCount !== attributesUsed.size)
|
|
129
|
+
return `${at} Make sure all geometries have the same number of attributes.`;
|
|
130
|
+
if (first.morphTargetsRelative !== geometry.morphTargetsRelative)
|
|
131
|
+
return `${at} .morphTargetsRelative must be consistent throughout all geometries.`;
|
|
132
|
+
for (const name of Object.keys(geometry.morphAttributes)) {
|
|
133
|
+
if (!morphAttributesUsed.has(name))
|
|
134
|
+
return `${at} .morphAttributes must be consistent throughout all geometries.`;
|
|
135
|
+
morphAttributes[name] ??= [];
|
|
136
|
+
morphAttributes[name].push(geometry.morphAttributes[name]);
|
|
137
|
+
}
|
|
138
|
+
if (useGroups) {
|
|
139
|
+
const count = isIndexed ? geometry.index?.count : geometry.attributes.position?.count;
|
|
140
|
+
if (count === void 0)
|
|
141
|
+
return `${at} The geometry must have either an index or a position attribute`;
|
|
142
|
+
merged.addGroup(offset, count, i);
|
|
143
|
+
offset += count;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return { attributes, morphAttributes, isIndexed };
|
|
147
|
+
}
|
|
148
|
+
function mergeInEngine(merged, parts, found) {
|
|
149
|
+
if (typeof merged.__mergeFrom !== "function") return void 0;
|
|
150
|
+
const answer = merged.__mergeFrom(parts, found.isIndexed, Object.keys(found.attributes));
|
|
151
|
+
if (answer === "?") return void 0;
|
|
152
|
+
if (answer === "") return "";
|
|
153
|
+
const [field, name] = answer.split("\n");
|
|
154
|
+
const rule = field === "array" ? "of consistent array types" : "consistent";
|
|
155
|
+
console.error(
|
|
156
|
+
`${PREFIX} .mergeAttributes() failed. BufferAttribute.${field} must be ${rule} across matching attributes.`
|
|
157
|
+
);
|
|
158
|
+
return name;
|
|
159
|
+
}
|
|
160
|
+
function mergeInPort(merged, parts, found) {
|
|
161
|
+
if (found.isIndexed)
|
|
162
|
+
merged.setIndex(new engine.BufferAttribute(mergedIndex(parts), 1));
|
|
163
|
+
for (const [name, list] of Object.entries(found.attributes)) {
|
|
164
|
+
const attribute = mergeAttributes2(list);
|
|
165
|
+
if (!attribute) return name;
|
|
166
|
+
merged.setAttribute(name, attribute);
|
|
167
|
+
}
|
|
168
|
+
return "";
|
|
169
|
+
}
|
|
170
|
+
function mergeGeometries2(geometries, useGroups = false) {
|
|
171
|
+
const merged = new engine.BufferGeometry();
|
|
172
|
+
const found = collect(geometries, merged, useGroups);
|
|
173
|
+
if (typeof found === "string") {
|
|
174
|
+
console.error(found);
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
const refused = mergeInEngine(merged, geometries, found) ?? mergeInPort(merged, geometries, found);
|
|
178
|
+
if (refused !== "") {
|
|
179
|
+
console.error(
|
|
180
|
+
`${PREFIX} .mergeGeometries() failed while trying to merge the ${refused} attribute.`
|
|
181
|
+
);
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
for (const [name, perGeometry] of Object.entries(found.morphAttributes)) {
|
|
185
|
+
const numMorphTargets = perGeometry[0].length;
|
|
186
|
+
if (numMorphTargets === 0) continue;
|
|
187
|
+
const targets = [];
|
|
188
|
+
for (let i = 0; i < numMorphTargets; ++i) {
|
|
189
|
+
const attribute = mergeAttributes2(perGeometry.map((list) => list[i]));
|
|
190
|
+
if (!attribute) {
|
|
191
|
+
console.error(
|
|
192
|
+
`${PREFIX} .mergeGeometries() failed while trying to merge the ${name} morphAttribute.`
|
|
193
|
+
);
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
targets.push(attribute);
|
|
197
|
+
}
|
|
198
|
+
merged.morphAttributes[name] = targets;
|
|
199
|
+
}
|
|
200
|
+
return merged;
|
|
201
|
+
}
|
|
202
|
+
function mergeVertices2(geometry, tolerance = 1e-4) {
|
|
203
|
+
const used = Math.max(tolerance, Number.EPSILON);
|
|
204
|
+
const hashToIndex = /* @__PURE__ */ new Map();
|
|
205
|
+
const indices = geometry.getIndex();
|
|
206
|
+
const positions = geometry.attributes.position;
|
|
207
|
+
const vertexCount = indices ? indices.count : positions.count;
|
|
208
|
+
const names = Object.keys(geometry.attributes);
|
|
209
|
+
const arrays = {};
|
|
210
|
+
const morphArrays = {};
|
|
211
|
+
const made = (attribute) => new attribute.array.constructor(
|
|
212
|
+
attribute.count * attribute.itemSize
|
|
213
|
+
);
|
|
214
|
+
for (const name of names) {
|
|
215
|
+
arrays[name] = made(geometry.attributes[name]);
|
|
216
|
+
const morphs = geometry.morphAttributes[name];
|
|
217
|
+
if (morphs) morphArrays[name] = morphs.map(made);
|
|
218
|
+
}
|
|
219
|
+
const hashMultiplier = 10 ** Math.log10(1 / used);
|
|
220
|
+
const hashAdditive = used * 0.5 * hashMultiplier;
|
|
221
|
+
const newIndices = [];
|
|
222
|
+
let nextIndex = 0;
|
|
223
|
+
for (let i = 0; i < vertexCount; i++) {
|
|
224
|
+
const index = indices ? indices.getX(i) : i;
|
|
225
|
+
let hash = "";
|
|
226
|
+
for (const name of names) {
|
|
227
|
+
const attribute = geometry.attributes[name];
|
|
228
|
+
for (let k = 0; k < attribute.itemSize; k++)
|
|
229
|
+
hash += `${~~(component(attribute, index, k) * hashMultiplier + hashAdditive)},`;
|
|
230
|
+
}
|
|
231
|
+
const known = hashToIndex.get(hash);
|
|
232
|
+
if (known !== void 0) {
|
|
233
|
+
newIndices.push(known);
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
for (const name of names) {
|
|
237
|
+
const attribute = geometry.attributes[name];
|
|
238
|
+
const morphs = geometry.morphAttributes[name];
|
|
239
|
+
for (let k = 0; k < attribute.itemSize; k++) {
|
|
240
|
+
const at = nextIndex * attribute.itemSize + k;
|
|
241
|
+
store(arrays[name], attribute, at, component(attribute, index, k));
|
|
242
|
+
morphs?.forEach((morph, m) => {
|
|
243
|
+
const target = morphArrays[name][m];
|
|
244
|
+
store(target, morph, nextIndex * morph.itemSize + k, component(morph, index, k));
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
hashToIndex.set(hash, nextIndex);
|
|
249
|
+
newIndices.push(nextIndex);
|
|
250
|
+
nextIndex++;
|
|
251
|
+
}
|
|
252
|
+
const result = geometry.clone();
|
|
253
|
+
const rebuilt = (array, source) => new engine.BufferAttribute(
|
|
254
|
+
array.slice(0, nextIndex * source.itemSize),
|
|
255
|
+
source.itemSize,
|
|
256
|
+
source.normalized
|
|
257
|
+
);
|
|
258
|
+
for (const name of names) {
|
|
259
|
+
result.setAttribute(
|
|
260
|
+
name,
|
|
261
|
+
rebuilt(arrays[name], geometry.attributes[name])
|
|
262
|
+
);
|
|
263
|
+
const morphs = geometry.morphAttributes[name];
|
|
264
|
+
if (morphs)
|
|
265
|
+
result.morphAttributes[name] = morphs.map(
|
|
266
|
+
(morph, m) => rebuilt(morphArrays[name][m], morph)
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
result.setIndex(newIndices);
|
|
270
|
+
return result;
|
|
271
|
+
}
|
|
272
|
+
return { mergeGeometries: mergeGeometries2, mergeAttributes: mergeAttributes2, mergeVertices: mergeVertices2 };
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// ../three-native/src/addons/buffer-geometry-utils.ts
|
|
276
|
+
var { mergeGeometries, mergeAttributes, mergeVertices } = defineBufferGeometryUtils({
|
|
277
|
+
BufferAttribute,
|
|
278
|
+
BufferGeometry
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
export { mergeAttributes, mergeGeometries, mergeVertices };
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { Mesh, Vector3, Euler, Matrix3, Matrix4, Float32BufferAttribute, BufferGeometry } from 'three';
|
|
2
|
+
|
|
3
|
+
// ../three-native/src/addons/decal-geometry.ts
|
|
4
|
+
|
|
5
|
+
// ../three-native/src/addons/decal.ts
|
|
6
|
+
function defineDecalGeometry(T) {
|
|
7
|
+
const { BufferGeometry: BufferGeometry2, Euler: Euler2, Float32BufferAttribute: Float32BufferAttribute2, Matrix3: Matrix32, Matrix4: Matrix42, Mesh: Mesh2, Vector3: Vector32 } = T;
|
|
8
|
+
class DecalVertex2 {
|
|
9
|
+
constructor(position, normal = null) {
|
|
10
|
+
this.position = position;
|
|
11
|
+
this.normal = normal;
|
|
12
|
+
}
|
|
13
|
+
position;
|
|
14
|
+
normal;
|
|
15
|
+
clone() {
|
|
16
|
+
return new DecalVertex2(
|
|
17
|
+
this.position.clone(),
|
|
18
|
+
this.normal === null ? null : this.normal.clone()
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function clip(v0, v1, p, s) {
|
|
23
|
+
const d0 = v0.position.dot(p) - s;
|
|
24
|
+
const d1 = v1.position.dot(p) - s;
|
|
25
|
+
const s0 = d0 / (d0 - d1);
|
|
26
|
+
const position = new Vector32(
|
|
27
|
+
v0.position.x + s0 * (v1.position.x - v0.position.x),
|
|
28
|
+
v0.position.y + s0 * (v1.position.y - v0.position.y),
|
|
29
|
+
v0.position.z + s0 * (v1.position.z - v0.position.z)
|
|
30
|
+
);
|
|
31
|
+
let normal = null;
|
|
32
|
+
if (v0.normal !== null && v1.normal !== null)
|
|
33
|
+
normal = new Vector32(
|
|
34
|
+
v0.normal.x + s0 * (v1.normal.x - v0.normal.x),
|
|
35
|
+
v0.normal.y + s0 * (v1.normal.y - v0.normal.y),
|
|
36
|
+
v0.normal.z + s0 * (v1.normal.z - v0.normal.z)
|
|
37
|
+
);
|
|
38
|
+
return new DecalVertex2(position, normal);
|
|
39
|
+
}
|
|
40
|
+
function clipGeometry(inVertices, plane, size) {
|
|
41
|
+
const outVertices = [];
|
|
42
|
+
const s = 0.5 * Math.abs(size.dot(plane));
|
|
43
|
+
for (let i = 0; i < inVertices.length; i += 3) {
|
|
44
|
+
const a = inVertices[i];
|
|
45
|
+
const b = inVertices[i + 1];
|
|
46
|
+
const c = inVertices[i + 2];
|
|
47
|
+
const v1Out = a.position.dot(plane) - s > 0;
|
|
48
|
+
const v2Out = b.position.dot(plane) - s > 0;
|
|
49
|
+
const v3Out = c.position.dot(plane) - s > 0;
|
|
50
|
+
const total = (v1Out ? 1 : 0) + (v2Out ? 1 : 0) + (v3Out ? 1 : 0);
|
|
51
|
+
if (total === 0) {
|
|
52
|
+
outVertices.push(a, b, c);
|
|
53
|
+
} else if (total === 1) {
|
|
54
|
+
let nV1;
|
|
55
|
+
let nV2;
|
|
56
|
+
let nV3;
|
|
57
|
+
let nV4;
|
|
58
|
+
if (v1Out) {
|
|
59
|
+
nV1 = b;
|
|
60
|
+
nV2 = c;
|
|
61
|
+
nV3 = clip(a, nV1, plane, s);
|
|
62
|
+
nV4 = clip(a, nV2, plane, s);
|
|
63
|
+
} else if (v2Out) {
|
|
64
|
+
nV1 = a;
|
|
65
|
+
nV2 = c;
|
|
66
|
+
nV3 = clip(b, nV1, plane, s);
|
|
67
|
+
nV4 = clip(b, nV2, plane, s);
|
|
68
|
+
outVertices.push(nV3, nV2.clone(), nV1.clone(), nV2.clone(), nV3.clone(), nV4);
|
|
69
|
+
continue;
|
|
70
|
+
} else {
|
|
71
|
+
nV1 = a;
|
|
72
|
+
nV2 = b;
|
|
73
|
+
nV3 = clip(c, nV1, plane, s);
|
|
74
|
+
nV4 = clip(c, nV2, plane, s);
|
|
75
|
+
}
|
|
76
|
+
outVertices.push(nV1.clone(), nV2.clone(), nV3, nV4, nV3.clone(), nV2.clone());
|
|
77
|
+
} else if (total === 2) {
|
|
78
|
+
if (!v1Out) {
|
|
79
|
+
const nV1 = a.clone();
|
|
80
|
+
outVertices.push(nV1, clip(nV1, b, plane, s), clip(nV1, c, plane, s));
|
|
81
|
+
}
|
|
82
|
+
if (!v2Out) {
|
|
83
|
+
const nV1 = b.clone();
|
|
84
|
+
outVertices.push(nV1, clip(nV1, c, plane, s), clip(nV1, a, plane, s));
|
|
85
|
+
}
|
|
86
|
+
if (!v3Out) {
|
|
87
|
+
const nV1 = c.clone();
|
|
88
|
+
outVertices.push(nV1, clip(nV1, a, plane, s), clip(nV1, b, plane, s));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return outVertices;
|
|
93
|
+
}
|
|
94
|
+
class DecalGeometry2 extends BufferGeometry2 {
|
|
95
|
+
constructor(mesh = new Mesh2(), position = new Vector32(), orientation = new Euler2(), size = new Vector32(1, 1, 1)) {
|
|
96
|
+
super();
|
|
97
|
+
const vertices = [];
|
|
98
|
+
const normals = [];
|
|
99
|
+
const uvs = [];
|
|
100
|
+
const plane = new Vector32();
|
|
101
|
+
const normalMatrix = new Matrix32().getNormalMatrix(mesh.matrixWorld);
|
|
102
|
+
const projectorMatrix = new Matrix42();
|
|
103
|
+
projectorMatrix.makeRotationFromEuler(orientation);
|
|
104
|
+
projectorMatrix.setPosition(position);
|
|
105
|
+
const projectorMatrixInverse = new Matrix42().copy(projectorMatrix).invert();
|
|
106
|
+
const pushDecalVertex = (decalVertices, vertex, normal) => {
|
|
107
|
+
vertex.applyMatrix4(mesh.matrixWorld);
|
|
108
|
+
vertex.applyMatrix4(projectorMatrixInverse);
|
|
109
|
+
if (normal !== void 0) {
|
|
110
|
+
normal.applyNormalMatrix(normalMatrix);
|
|
111
|
+
decalVertices.push(new DecalVertex2(vertex.clone(), normal.clone()));
|
|
112
|
+
} else {
|
|
113
|
+
decalVertices.push(new DecalVertex2(vertex.clone()));
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
const generate = () => {
|
|
117
|
+
let decalVertices = [];
|
|
118
|
+
const vertex = new Vector32();
|
|
119
|
+
const normal = new Vector32();
|
|
120
|
+
const geometry = mesh.geometry;
|
|
121
|
+
const positionAttribute = geometry.getAttribute("position");
|
|
122
|
+
const normalAttribute = geometry.getAttribute("normal");
|
|
123
|
+
if (!positionAttribute) return;
|
|
124
|
+
if (geometry.index !== null) {
|
|
125
|
+
const index = geometry.index;
|
|
126
|
+
for (let i = 0; i < index.count; i += 1) {
|
|
127
|
+
vertex.fromBufferAttribute(positionAttribute, index.getX(i));
|
|
128
|
+
if (normalAttribute) {
|
|
129
|
+
normal.fromBufferAttribute(normalAttribute, index.getX(i));
|
|
130
|
+
pushDecalVertex(decalVertices, vertex, normal);
|
|
131
|
+
} else {
|
|
132
|
+
pushDecalVertex(decalVertices, vertex);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
} else {
|
|
136
|
+
for (let i = 0; i < positionAttribute.count; i += 1) {
|
|
137
|
+
vertex.fromBufferAttribute(positionAttribute, i);
|
|
138
|
+
if (normalAttribute) {
|
|
139
|
+
normal.fromBufferAttribute(normalAttribute, i);
|
|
140
|
+
pushDecalVertex(decalVertices, vertex, normal);
|
|
141
|
+
} else {
|
|
142
|
+
pushDecalVertex(decalVertices, vertex);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
for (const axis of [
|
|
147
|
+
[1, 0, 0],
|
|
148
|
+
[-1, 0, 0],
|
|
149
|
+
[0, 1, 0],
|
|
150
|
+
[0, -1, 0],
|
|
151
|
+
[0, 0, 1],
|
|
152
|
+
[0, 0, -1]
|
|
153
|
+
])
|
|
154
|
+
decalVertices = clipGeometry(decalVertices, plane.set(axis[0], axis[1], axis[2]), size);
|
|
155
|
+
for (const decalVertex of decalVertices) {
|
|
156
|
+
uvs.push(0.5 + decalVertex.position.x / size.x, 0.5 + decalVertex.position.y / size.y);
|
|
157
|
+
decalVertex.position.applyMatrix4(projectorMatrix);
|
|
158
|
+
vertices.push(decalVertex.position.x, decalVertex.position.y, decalVertex.position.z);
|
|
159
|
+
if (decalVertex.normal !== null)
|
|
160
|
+
normals.push(decalVertex.normal.x, decalVertex.normal.y, decalVertex.normal.z);
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
generate();
|
|
164
|
+
this.setAttribute("position", new Float32BufferAttribute2(new Float32Array(vertices), 3));
|
|
165
|
+
this.setAttribute("uv", new Float32BufferAttribute2(new Float32Array(uvs), 2));
|
|
166
|
+
if (normals.length > 0)
|
|
167
|
+
this.setAttribute("normal", new Float32BufferAttribute2(new Float32Array(normals), 3));
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return { DecalGeometry: DecalGeometry2, DecalVertex: DecalVertex2 };
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// ../three-native/src/addons/decal-geometry.ts
|
|
174
|
+
var { DecalGeometry, DecalVertex } = defineDecalGeometry({
|
|
175
|
+
BufferGeometry,
|
|
176
|
+
Euler,
|
|
177
|
+
Float32BufferAttribute,
|
|
178
|
+
Matrix3,
|
|
179
|
+
Matrix4,
|
|
180
|
+
Mesh,
|
|
181
|
+
Vector3
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
export { DecalGeometry, DecalVertex };
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { __tnLoadGltf } from 'three';
|
|
2
|
+
|
|
3
|
+
// ../three-native/src/addons/gltf-loader-web.ts
|
|
4
|
+
var load = __tnLoadGltf;
|
|
5
|
+
function readGltf(data) {
|
|
6
|
+
if (typeof data === "string") return { bin: void 0, json: JSON.parse(data) };
|
|
7
|
+
const bytes = new Uint8Array(data);
|
|
8
|
+
if (bytes.byteLength < 20 || bytes[0] !== 103 || bytes[1] !== 108)
|
|
9
|
+
return { bin: void 0, json: JSON.parse(new TextDecoder().decode(bytes)) };
|
|
10
|
+
const view = new DataView(data);
|
|
11
|
+
const jsonEnd = 20 + view.getUint32(12, true);
|
|
12
|
+
const json = JSON.parse(new TextDecoder().decode(bytes.subarray(20, jsonEnd)));
|
|
13
|
+
const hasBin = jsonEnd + 8 <= bytes.byteLength && view.getUint32(jsonEnd + 4, true) === 5130562;
|
|
14
|
+
return {
|
|
15
|
+
bin: hasBin ? bytes.subarray(jsonEnd + 8, jsonEnd + 8 + view.getUint32(jsonEnd, true)) : void 0,
|
|
16
|
+
json
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function externalImageUris(data) {
|
|
20
|
+
let json;
|
|
21
|
+
try {
|
|
22
|
+
json = readGltf(data).json;
|
|
23
|
+
} catch {
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
const uris = (json.images ?? []).flatMap(
|
|
27
|
+
({ uri }) => typeof uri === "string" && !uri.startsWith("data:") ? [uri] : []
|
|
28
|
+
);
|
|
29
|
+
return [...new Set(uris)];
|
|
30
|
+
}
|
|
31
|
+
function refuse(what) {
|
|
32
|
+
throw new Error(`TN_NATIVE_GLTF_${what}_UNSUPPORTED: the engine glTF loader does not take this`);
|
|
33
|
+
}
|
|
34
|
+
var HOSTED_PLUGIN = "TN_discrete_lod";
|
|
35
|
+
var ELEMENTS = { 5121: Uint8Array, 5123: Uint16Array, 5125: Uint32Array };
|
|
36
|
+
function readIndices(json, bin, index) {
|
|
37
|
+
const accessor = json.accessors?.[index];
|
|
38
|
+
const view = json.bufferViews?.[accessor?.bufferView ?? -1];
|
|
39
|
+
const Element = ELEMENTS[accessor?.componentType];
|
|
40
|
+
if (accessor === void 0 || view === void 0 || Element === void 0 || accessor.type !== "SCALAR" || accessor.sparse !== void 0 || typeof accessor.count !== "number" || (view.byteStride ?? 0) !== 0)
|
|
41
|
+
throw new Error(
|
|
42
|
+
`TN_WASM_GLTF_LOD_ACCESSOR: accessor ${String(index)} is not a plain index accessor`
|
|
43
|
+
);
|
|
44
|
+
if (bin === void 0)
|
|
45
|
+
throw new Error("TN_WASM_GLTF_LOD_ACCESSOR: only a GLB's binary chunk is read for a LOD chain");
|
|
46
|
+
const start = (view.byteOffset ?? 0) + (accessor.byteOffset ?? 0);
|
|
47
|
+
const end = start + accessor.count * Element.BYTES_PER_ELEMENT;
|
|
48
|
+
if (!Number.isInteger(start) || end > bin.byteLength)
|
|
49
|
+
throw new Error(
|
|
50
|
+
`TN_WASM_GLTF_LOD_ACCESSOR: accessor ${String(index)} reads past the binary chunk`
|
|
51
|
+
);
|
|
52
|
+
return { array: new Element(bin.slice(start, end).buffer) };
|
|
53
|
+
}
|
|
54
|
+
function associate(json, scene, into) {
|
|
55
|
+
const expected = [];
|
|
56
|
+
const visit = (node) => {
|
|
57
|
+
const def = json.nodes?.[node];
|
|
58
|
+
if (def === void 0)
|
|
59
|
+
throw new Error(`TN_WASM_GLTF_LOD_MISMATCH: node ${String(node)} is missing`);
|
|
60
|
+
if (def.mesh !== void 0)
|
|
61
|
+
for (let primitives = 0; primitives < (json.meshes?.[def.mesh]?.primitives?.length ?? 0); primitives += 1)
|
|
62
|
+
expected.push({ meshes: def.mesh, nodes: node, primitives });
|
|
63
|
+
for (const child of def.children ?? []) visit(child);
|
|
64
|
+
};
|
|
65
|
+
for (const node of json.scenes?.[json.scene ?? 0]?.nodes ?? []) visit(node);
|
|
66
|
+
const meshes = [];
|
|
67
|
+
const walk = (object) => {
|
|
68
|
+
if (object.isMesh === true) meshes.push(object);
|
|
69
|
+
for (const child of object.children) walk(child);
|
|
70
|
+
};
|
|
71
|
+
walk(scene);
|
|
72
|
+
if (meshes.length !== expected.length)
|
|
73
|
+
throw new Error(
|
|
74
|
+
`TN_WASM_GLTF_LOD_MISMATCH: the file has ${String(expected.length)} primitive(s) and the engine scene ${String(meshes.length)} mesh(es)`
|
|
75
|
+
);
|
|
76
|
+
for (const [i, mesh] of meshes.entries()) into.set(mesh, expected[i]);
|
|
77
|
+
}
|
|
78
|
+
function hostPlugins(factories, data) {
|
|
79
|
+
if (factories.length === 0) return void 0;
|
|
80
|
+
const { bin, json } = readGltf(data);
|
|
81
|
+
const parser = {
|
|
82
|
+
associations: /* @__PURE__ */ new Map(),
|
|
83
|
+
getDependency: async (type, index) => {
|
|
84
|
+
if (type === "accessor") return readIndices(json, bin, index);
|
|
85
|
+
throw new Error(
|
|
86
|
+
`TN_WASM_GLTF_DEPENDENCY_UNSUPPORTED: the engine glTF loader returns no '${type}'`
|
|
87
|
+
);
|
|
88
|
+
},
|
|
89
|
+
json
|
|
90
|
+
};
|
|
91
|
+
const plugins = factories.map((factory) => factory(parser));
|
|
92
|
+
for (const plugin of plugins) if (plugin.name !== HOSTED_PLUGIN) refuse("PLUGIN");
|
|
93
|
+
return { parser, plugins };
|
|
94
|
+
}
|
|
95
|
+
var GLTFLoader = class {
|
|
96
|
+
path = "";
|
|
97
|
+
/** A plugin defect (a chain the file declares and cannot deliver) rejects the load; core's plugin logs it on stock three. */
|
|
98
|
+
failClosed = true;
|
|
99
|
+
#factories = [];
|
|
100
|
+
setPath(path) {
|
|
101
|
+
this.path = path;
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
104
|
+
setResourcePath() {
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
setCrossOrigin() {
|
|
108
|
+
return this;
|
|
109
|
+
}
|
|
110
|
+
setRequestHeader() {
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
113
|
+
setKTX2Loader() {
|
|
114
|
+
return refuse("KTX2");
|
|
115
|
+
}
|
|
116
|
+
setMeshoptDecoder() {
|
|
117
|
+
return refuse("MESHOPT");
|
|
118
|
+
}
|
|
119
|
+
setDRACOLoader() {
|
|
120
|
+
return refuse("DRACO");
|
|
121
|
+
}
|
|
122
|
+
/** Takes a plugin factory; only `TN_discrete_lod` is hosted, any other is refused by name when parsing. */
|
|
123
|
+
register(factory) {
|
|
124
|
+
this.#factories.push(factory);
|
|
125
|
+
return this;
|
|
126
|
+
}
|
|
127
|
+
/** `onLoad` or `onError` runs once, as three's does; images named by uri are fetched first. */
|
|
128
|
+
parse(data, path, onLoad, onError) {
|
|
129
|
+
const settle = async (files) => {
|
|
130
|
+
let result;
|
|
131
|
+
try {
|
|
132
|
+
if (load === void 0)
|
|
133
|
+
throw new Error("TN_WASM_GLTF_UNAVAILABLE: this web engine has no glTF loader");
|
|
134
|
+
const bytes = typeof data === "string" ? new TextEncoder().encode(data) : new Uint8Array(data);
|
|
135
|
+
const hosted = hostPlugins(this.#factories, data);
|
|
136
|
+
const model = load(bytes, files);
|
|
137
|
+
result = {
|
|
138
|
+
scene: model.scene,
|
|
139
|
+
scenes: [model.scene],
|
|
140
|
+
animations: [...model.animations],
|
|
141
|
+
cameras: [],
|
|
142
|
+
asset: { version: "2.0" },
|
|
143
|
+
parser: void 0,
|
|
144
|
+
userData: {}
|
|
145
|
+
};
|
|
146
|
+
if (hosted !== void 0) {
|
|
147
|
+
associate(hosted.parser.json, model.scene, hosted.parser.associations);
|
|
148
|
+
for (const plugin of hosted.plugins) await plugin.afterRoot?.(result);
|
|
149
|
+
}
|
|
150
|
+
} catch (error) {
|
|
151
|
+
if (onError === void 0) throw error;
|
|
152
|
+
onError(error);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
onLoad(result);
|
|
156
|
+
};
|
|
157
|
+
const uris = externalImageUris(data);
|
|
158
|
+
if (uris.length === 0) {
|
|
159
|
+
void settle(/* @__PURE__ */ new Map());
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
Promise.all(
|
|
163
|
+
uris.map(async (uri) => {
|
|
164
|
+
const response = await fetch(path + uri);
|
|
165
|
+
if (!response.ok) throw new Error(`TN_WASM_GLTF_FETCH: ${response.status} ${path + uri}`);
|
|
166
|
+
return [decodeURIComponent(uri), new Uint8Array(await response.arrayBuffer())];
|
|
167
|
+
})
|
|
168
|
+
).then(
|
|
169
|
+
(files) => settle(new Map(files)),
|
|
170
|
+
(error) => {
|
|
171
|
+
if (onError === void 0) throw error;
|
|
172
|
+
onError(error);
|
|
173
|
+
}
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
parseAsync(data, path) {
|
|
177
|
+
return new Promise((resolve, reject) => this.parse(data, path, resolve, reject));
|
|
178
|
+
}
|
|
179
|
+
async loadAsync(url) {
|
|
180
|
+
const response = await fetch(this.path + url);
|
|
181
|
+
if (!response.ok) throw new Error(`TN_WASM_GLTF_FETCH: ${response.status} ${url}`);
|
|
182
|
+
const resolved = this.path + url;
|
|
183
|
+
return this.parseAsync(
|
|
184
|
+
await response.arrayBuffer(),
|
|
185
|
+
resolved.slice(0, resolved.lastIndexOf("/") + 1)
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
load(url, onLoad, _onProgress, onError) {
|
|
189
|
+
this.loadAsync(url).then(onLoad, (error) => {
|
|
190
|
+
if (onError === void 0) throw error;
|
|
191
|
+
onError(error);
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
export { GLTFLoader, externalImageUris };
|