create-threenative 0.2.8 → 0.2.10
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 +13 -10
- 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 +11 -9
- 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 +13 -10
- 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 +13 -10
- 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 +13 -10
- 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 +25 -5
- package/templates/racing/src/render/worldEnvironment.ts +433 -30
- package/templates/racing/src/scenes/Race.ts +110 -13
- 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 +14 -10
- 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 +12 -9
- 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 +13 -10
- 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 +13 -10
- 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 +13 -10
- 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 +13 -10
- 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 +13 -10
- 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 +43 -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 +90 -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 +13 -10
- 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
package/dist/threenative.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire } from 'node:module';
|
|
3
3
|
import { spawnSync, execFileSync, spawn } from 'child_process';
|
|
4
|
-
import {
|
|
4
|
+
import { createHash, randomUUID } from 'crypto';
|
|
5
5
|
import { existsSync, realpathSync, readFileSync, statSync, openSync, readSync, closeSync, accessSync, constants } from 'fs';
|
|
6
|
-
import { mkdir, rm, open, readFile, writeFile, readdir, stat, rename, access, unlink } from 'fs/promises';
|
|
6
|
+
import { mkdir, rm, open, readFile, writeFile, readdir, stat, rename, copyFile, realpath, access, unlink } from 'fs/promises';
|
|
7
7
|
import { createRequire as createRequire$1 } from 'module';
|
|
8
|
-
import
|
|
8
|
+
import path5 from 'path';
|
|
9
9
|
import { pathToFileURL, fileURLToPath } from 'url';
|
|
10
|
+
import { GLB_BUFFER, NodeIO } from '@gltf-transform/core';
|
|
11
|
+
import { traceSegment, decodedMappings, TraceMap, encodedMappings, originalPositionFor, sourceContentFor } from '@jridgewell/trace-mapping';
|
|
10
12
|
import { compileAssets, parsePng, parseAudioConfig } from '@threenative/assets';
|
|
13
|
+
import { read, VK_FORMAT_ASTC_4x4_UNORM_BLOCK, VK_FORMAT_ASTC_4x4_SRGB_BLOCK, KHR_SUPERCOMPRESSION_NONE, KHR_DF_MODEL_ASTC, KHR_DF_TRANSFER_SRGB, KHR_DF_TRANSFER_LINEAR } from 'ktx-parse';
|
|
11
14
|
import { brotliCompressSync, constants as constants$1, gzipSync } from 'zlib';
|
|
12
15
|
import { platform, homedir } from 'os';
|
|
13
16
|
|
|
@@ -22,19 +25,19 @@ async function listFiles(target, prefix = "") {
|
|
|
22
25
|
for (const entry of entries.sort((left, right) => left.name < right.name ? -1 : 1)) {
|
|
23
26
|
const relative = prefix === "" ? entry.name : `${prefix}/${entry.name}`;
|
|
24
27
|
if (entry.isDirectory())
|
|
25
|
-
files.push(...await listFiles(
|
|
28
|
+
files.push(...await listFiles(path5.join(target, entry.name), relative));
|
|
26
29
|
else if (entry.isFile()) files.push(relative);
|
|
27
30
|
}
|
|
28
31
|
return files;
|
|
29
32
|
}
|
|
30
33
|
async function hashArtifact(target) {
|
|
31
|
-
const name =
|
|
34
|
+
const name = path5.basename(target);
|
|
32
35
|
if (!(await stat(target)).isDirectory()) {
|
|
33
36
|
return { kind: "file", name, sha256: sha256(await readFile(target)) };
|
|
34
37
|
}
|
|
35
38
|
const lines = [];
|
|
36
39
|
for (const file of await listFiles(target)) {
|
|
37
|
-
lines.push(`${file} ${sha256(await readFile(
|
|
40
|
+
lines.push(`${file} ${sha256(await readFile(path5.join(target, file)))}`);
|
|
38
41
|
}
|
|
39
42
|
return { kind: "directory", name, sha256: sha256(Buffer.from(lines.join("\n"), "utf8")) };
|
|
40
43
|
}
|
|
@@ -43,7 +46,7 @@ async function measureTreeBytes(target) {
|
|
|
43
46
|
if (!info.isDirectory()) return info.size;
|
|
44
47
|
let total = 0;
|
|
45
48
|
for (const entry of await readdir(target))
|
|
46
|
-
total += await measureTreeBytes(
|
|
49
|
+
total += await measureTreeBytes(path5.join(target, entry));
|
|
47
50
|
return total;
|
|
48
51
|
}
|
|
49
52
|
async function writeBuildReport(options) {
|
|
@@ -54,15 +57,15 @@ async function writeBuildReport(options) {
|
|
|
54
57
|
artifactBytes: await measureTreeBytes(artifact),
|
|
55
58
|
packagedAssetBytes: options.packagedAssetBytes
|
|
56
59
|
},
|
|
57
|
-
manifestSha256: await fileSha(
|
|
60
|
+
manifestSha256: await fileSha(path5.join(assets, "assets.manifest.json")),
|
|
58
61
|
performanceBudget: config.buildProfile?.performanceBudget ?? null,
|
|
59
62
|
profile: config.buildProfile?.name ?? null,
|
|
60
63
|
schemaVersion: 1,
|
|
61
64
|
target
|
|
62
65
|
};
|
|
63
|
-
const destination =
|
|
64
|
-
|
|
65
|
-
`${
|
|
66
|
+
const destination = path5.join(
|
|
67
|
+
path5.dirname(artifact),
|
|
68
|
+
`${path5.basename(artifact)}${BUILD_REPORT_SUFFIX}`
|
|
66
69
|
);
|
|
67
70
|
await writeFile(destination, `${JSON.stringify(report, null, 2)}
|
|
68
71
|
`);
|
|
@@ -79,7 +82,7 @@ var COMPRESSIBLE_EXTENSIONS = /* @__PURE__ */ new Set([".css", ".html", ".js", "
|
|
|
79
82
|
var MIN_BYTES = 1024;
|
|
80
83
|
async function walk(directory, files) {
|
|
81
84
|
for (const entry of await readdir(directory, { withFileTypes: true })) {
|
|
82
|
-
const file =
|
|
85
|
+
const file = path5.join(directory, entry.name);
|
|
83
86
|
if (entry.isDirectory()) await walk(file, files);
|
|
84
87
|
else if (entry.isFile()) files.push(file);
|
|
85
88
|
}
|
|
@@ -101,7 +104,7 @@ async function writeCompressionSidecars(outputDirectory) {
|
|
|
101
104
|
}
|
|
102
105
|
await walk(outputDirectory, files);
|
|
103
106
|
for (const file of files) {
|
|
104
|
-
if (!COMPRESSIBLE_EXTENSIONS.has(
|
|
107
|
+
if (!COMPRESSIBLE_EXTENSIONS.has(path5.extname(file).toLowerCase())) continue;
|
|
105
108
|
try {
|
|
106
109
|
const data = await readFile(file);
|
|
107
110
|
if (data.byteLength <= MIN_BYTES) continue;
|
|
@@ -109,24 +112,24 @@ async function writeCompressionSidecars(outputDirectory) {
|
|
|
109
112
|
await writeFile(`${file}.gz`, gzip(data));
|
|
110
113
|
} catch (error) {
|
|
111
114
|
throw new Error(
|
|
112
|
-
`TN_WEB_COMPRESSION_FAILED: ${
|
|
115
|
+
`TN_WEB_COMPRESSION_FAILED: ${path5.relative(outputDirectory, file)}: ${error.message}`
|
|
113
116
|
);
|
|
114
117
|
}
|
|
115
118
|
}
|
|
116
119
|
return mainEntryReport(outputDirectory, files);
|
|
117
120
|
}
|
|
118
121
|
async function mainEntryReport(outputDirectory, files) {
|
|
119
|
-
const html = files.find((file) =>
|
|
122
|
+
const html = files.find((file) => path5.basename(file) === "index.html");
|
|
120
123
|
if (html === void 0) return void 0;
|
|
121
124
|
const match = /<script[^>]+src="([^"]+\.m?js)"/u.exec(await readFile(html, "utf8"));
|
|
122
125
|
const source = match?.[1];
|
|
123
126
|
if (source === void 0) return void 0;
|
|
124
|
-
const entry =
|
|
127
|
+
const entry = path5.join(outputDirectory, source.replace(/^\//u, ""));
|
|
125
128
|
const raw = (await stat(entry)).size;
|
|
126
129
|
if (raw <= MIN_BYTES) return void 0;
|
|
127
130
|
return {
|
|
128
131
|
brotli: (await stat(`${entry}.br`)).size,
|
|
129
|
-
entry:
|
|
132
|
+
entry: path5.relative(outputDirectory, entry),
|
|
130
133
|
gzip: (await stat(`${entry}.gz`)).size,
|
|
131
134
|
raw
|
|
132
135
|
};
|
|
@@ -205,13 +208,13 @@ function defaultAppId(name) {
|
|
|
205
208
|
return `com.threenative.${segment}`;
|
|
206
209
|
}
|
|
207
210
|
function projectRequire(cwd) {
|
|
208
|
-
return createRequire$1(
|
|
211
|
+
return createRequire$1(path5.join(cwd, "package.json"));
|
|
209
212
|
}
|
|
210
213
|
function configLoaderSearch(cwd) {
|
|
211
214
|
return [
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
+
path5.join(cwd, "node_modules", "vite"),
|
|
216
|
+
path5.join(cwd, "node_modules", "esbuild"),
|
|
217
|
+
path5.resolve(path5.dirname(fileURLToPath(import.meta.url)), "..", "node_modules", "esbuild")
|
|
215
218
|
];
|
|
216
219
|
}
|
|
217
220
|
var CONFIG_BUILD_COMMAND = "pnpm exec threenative build --target web";
|
|
@@ -219,7 +222,7 @@ function configContext(cwd, layer, sources, searched, fix) {
|
|
|
219
222
|
return { cwd, fix, layer, searched, sources };
|
|
220
223
|
}
|
|
221
224
|
function packageContext(cwd) {
|
|
222
|
-
const packagePath =
|
|
225
|
+
const packagePath = path5.join(cwd, "package.json");
|
|
223
226
|
return configContext(
|
|
224
227
|
cwd,
|
|
225
228
|
"package manifest",
|
|
@@ -242,8 +245,8 @@ function validationContext(cwd, sources) {
|
|
|
242
245
|
cwd,
|
|
243
246
|
"config validation",
|
|
244
247
|
sources,
|
|
245
|
-
[
|
|
246
|
-
`fix '${
|
|
248
|
+
[path5.join(cwd, "package.json"), path5.join(cwd, CONFIG_FILE)],
|
|
249
|
+
`fix '${path5.join(cwd, CONFIG_FILE)}' and rerun ${CONFIG_BUILD_COMMAND}`
|
|
247
250
|
);
|
|
248
251
|
}
|
|
249
252
|
function configFailure(code, context, detail) {
|
|
@@ -283,7 +286,7 @@ function resolveEsbuild(cwd) {
|
|
|
283
286
|
}
|
|
284
287
|
}
|
|
285
288
|
async function importConfig(cwd) {
|
|
286
|
-
const sourcePath =
|
|
289
|
+
const sourcePath = path5.join(cwd, CONFIG_FILE);
|
|
287
290
|
try {
|
|
288
291
|
await access(sourcePath);
|
|
289
292
|
} catch {
|
|
@@ -344,7 +347,7 @@ async function importConfig(cwd) {
|
|
|
344
347
|
error instanceof Error ? error.message : String(error)
|
|
345
348
|
);
|
|
346
349
|
}
|
|
347
|
-
const compiledPath =
|
|
350
|
+
const compiledPath = path5.join(cwd, `.threenative.config.${process.pid}.${Date.now()}.mjs`);
|
|
348
351
|
try {
|
|
349
352
|
await writeFile(compiledPath, code, "utf8");
|
|
350
353
|
} catch (error) {
|
|
@@ -380,7 +383,7 @@ async function importConfig(cwd) {
|
|
|
380
383
|
async function readManifest(cwd) {
|
|
381
384
|
let parsed;
|
|
382
385
|
try {
|
|
383
|
-
parsed = JSON.parse(await readFile(
|
|
386
|
+
parsed = JSON.parse(await readFile(path5.join(cwd, "package.json"), "utf8"));
|
|
384
387
|
} catch (error) {
|
|
385
388
|
fail("TN_CONFIG_PACKAGE_INVALID", error instanceof Error ? error.message : String(error));
|
|
386
389
|
}
|
|
@@ -399,12 +402,12 @@ function packageNativeEntry(manifest) {
|
|
|
399
402
|
}
|
|
400
403
|
function validateNativeEntry(value, cwd) {
|
|
401
404
|
const entry = nonEmptyString(value, "TN_NATIVE_ENTRY_MISSING", "nativeEntry");
|
|
402
|
-
if (
|
|
405
|
+
if (path5.isAbsolute(entry)) {
|
|
403
406
|
fail("TN_CONFIG_NATIVE_ENTRY_INVALID", "nativeEntry must be project-relative.");
|
|
404
407
|
}
|
|
405
|
-
const resolved =
|
|
406
|
-
const relative =
|
|
407
|
-
if (relative === ".." || relative.startsWith(`..${
|
|
408
|
+
const resolved = path5.resolve(cwd, entry);
|
|
409
|
+
const relative = path5.relative(cwd, resolved);
|
|
410
|
+
if (relative === ".." || relative.startsWith(`..${path5.sep}`) || path5.isAbsolute(relative)) {
|
|
408
411
|
fail("TN_CONFIG_NATIVE_ENTRY_INVALID", "nativeEntry must stay inside the project.");
|
|
409
412
|
}
|
|
410
413
|
return entry;
|
|
@@ -448,18 +451,18 @@ async function validateApp(raw, name, cwd) {
|
|
|
448
451
|
}
|
|
449
452
|
async function validateProjectAsset(raw, cwd, label, options) {
|
|
450
453
|
const relative = nonEmptyString(raw, `${options.codePrefix}_INVALID`, label);
|
|
451
|
-
if (
|
|
454
|
+
if (path5.isAbsolute(relative)) {
|
|
452
455
|
fail(`${options.codePrefix}_PATH_INVALID`, `${label} must be project-relative: ${relative}`);
|
|
453
456
|
}
|
|
454
|
-
const resolved =
|
|
455
|
-
const withinProject =
|
|
456
|
-
if (withinProject === ".." || withinProject.startsWith(`..${
|
|
457
|
+
const resolved = path5.resolve(cwd, relative);
|
|
458
|
+
const withinProject = path5.relative(cwd, resolved);
|
|
459
|
+
if (withinProject === ".." || withinProject.startsWith(`..${path5.sep}`) || path5.isAbsolute(withinProject)) {
|
|
457
460
|
fail(
|
|
458
461
|
`${options.codePrefix}_PATH_INVALID`,
|
|
459
462
|
`${label} must stay inside the project: ${relative}`
|
|
460
463
|
);
|
|
461
464
|
}
|
|
462
|
-
const extension =
|
|
465
|
+
const extension = path5.extname(relative).slice(1).toLowerCase();
|
|
463
466
|
if (!options.formats.includes(extension)) {
|
|
464
467
|
fail(
|
|
465
468
|
options.codePrefix === "TN_CONFIG_ICON" ? `${options.codePrefix}_INVALID` : `${options.codePrefix}_FORMAT_INVALID`,
|
|
@@ -679,13 +682,23 @@ async function validateBootSplash(raw, cwd) {
|
|
|
679
682
|
...image === void 0 ? {} : { image }
|
|
680
683
|
};
|
|
681
684
|
}
|
|
682
|
-
|
|
685
|
+
function validateEngine(raw) {
|
|
686
|
+
if (raw === void 0) return "threenative";
|
|
687
|
+
if (raw === "threejs" || raw === "threenative") return raw;
|
|
688
|
+
if (raw === "native" || raw === "legacy")
|
|
689
|
+
return fail(
|
|
690
|
+
"TN_CONFIG_ENGINE_RENAMED",
|
|
691
|
+
`engine "${raw}" was renamed: use "${raw === "native" ? "threenative" : "threejs"}".`
|
|
692
|
+
);
|
|
693
|
+
return fail("TN_CONFIG_ENGINE_INVALID", 'engine must be "threenative" or "threejs".');
|
|
694
|
+
}
|
|
695
|
+
var UI_RENDERERS = ["native", "native-css", "web"];
|
|
683
696
|
function validateUi(raw) {
|
|
684
697
|
const ui = assertRecord(raw, "ui");
|
|
685
698
|
assertKeys(ui, "ui", ["renderer"]);
|
|
686
699
|
const renderer = ui.renderer === void 0 ? "web" : ui.renderer;
|
|
687
700
|
if (typeof renderer !== "string" || !UI_RENDERERS.includes(renderer)) {
|
|
688
|
-
fail("TN_CONFIG_UI_RENDERER_INVALID", "ui.renderer must be web or native.");
|
|
701
|
+
fail("TN_CONFIG_UI_RENDERER_INVALID", "ui.renderer must be web, native or native-css.");
|
|
689
702
|
}
|
|
690
703
|
return { renderer };
|
|
691
704
|
}
|
|
@@ -814,6 +827,17 @@ function textureQuality(value, label) {
|
|
|
814
827
|
return value;
|
|
815
828
|
}
|
|
816
829
|
function textureMaxSize(value) {
|
|
830
|
+
if (isRecord(value))
|
|
831
|
+
return Object.fromEntries(
|
|
832
|
+
Object.entries(value).map(([slot, cap]) => {
|
|
833
|
+
if (!/^[a-z][a-zA-Z]*Texture$/u.test(slot) || typeof cap !== "number" || !Number.isSafeInteger(cap) || cap < 4)
|
|
834
|
+
fail(
|
|
835
|
+
"TN_CONFIG_ASSETS_INVALID",
|
|
836
|
+
`assets.textures.maxSize.${slot} must name a glTF texture slot with a positive integer cap of at least 4.`
|
|
837
|
+
);
|
|
838
|
+
return [slot, cap];
|
|
839
|
+
})
|
|
840
|
+
);
|
|
817
841
|
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 4) {
|
|
818
842
|
fail(
|
|
819
843
|
"TN_CONFIG_ASSETS_INVALID",
|
|
@@ -867,7 +891,37 @@ function validateTextures(raw) {
|
|
|
867
891
|
...textures.overrides === void 0 ? {} : { overrides: validateTextureOverrides(textures.overrides) }
|
|
868
892
|
};
|
|
869
893
|
}
|
|
870
|
-
var
|
|
894
|
+
var ASSETS_CONFIG_KEYS = [
|
|
895
|
+
"audio",
|
|
896
|
+
"budget",
|
|
897
|
+
"exclude",
|
|
898
|
+
"concurrency",
|
|
899
|
+
"lod",
|
|
900
|
+
"models",
|
|
901
|
+
"nativePackage",
|
|
902
|
+
"source",
|
|
903
|
+
"output",
|
|
904
|
+
"targets",
|
|
905
|
+
"textures"
|
|
906
|
+
];
|
|
907
|
+
var MODELS_CONFIG_KEYS = [
|
|
908
|
+
"compact",
|
|
909
|
+
"lightmap",
|
|
910
|
+
"passes",
|
|
911
|
+
"quantize",
|
|
912
|
+
"sharedImages",
|
|
913
|
+
"simplify",
|
|
914
|
+
"textures",
|
|
915
|
+
"virtual"
|
|
916
|
+
];
|
|
917
|
+
var LIGHTMAP_CONFIG_KEYS = ["atlasSize", "padding"];
|
|
918
|
+
var MODEL_PASS_KEYS = [
|
|
919
|
+
"dedup",
|
|
920
|
+
"meshopt",
|
|
921
|
+
"prune",
|
|
922
|
+
"quantize",
|
|
923
|
+
"reorder"
|
|
924
|
+
];
|
|
871
925
|
var MODEL_QUANTIZE_KEYS = ["normalBits", "positionBits", "uvBits"];
|
|
872
926
|
var MODEL_VIRTUAL_KEYS = [
|
|
873
927
|
"groupSize",
|
|
@@ -885,16 +939,7 @@ function bitDepth(value, label) {
|
|
|
885
939
|
function validateModels(raw) {
|
|
886
940
|
if (raw === "none") return "none";
|
|
887
941
|
const models = assertRecord(raw, "assets.models");
|
|
888
|
-
assertKeys(models, "assets.models",
|
|
889
|
-
"compact",
|
|
890
|
-
"lightmap",
|
|
891
|
-
"passes",
|
|
892
|
-
"quantize",
|
|
893
|
-
"sharedImages",
|
|
894
|
-
"simplify",
|
|
895
|
-
"textures",
|
|
896
|
-
"virtual"
|
|
897
|
-
]);
|
|
942
|
+
assertKeys(models, "assets.models", MODELS_CONFIG_KEYS);
|
|
898
943
|
if (models.sharedImages !== void 0 && typeof models.sharedImages !== "boolean") {
|
|
899
944
|
fail("TN_CONFIG_ASSETS_INVALID", "assets.models.sharedImages must be true or false.");
|
|
900
945
|
}
|
|
@@ -902,17 +947,21 @@ function validateModels(raw) {
|
|
|
902
947
|
let lightmap;
|
|
903
948
|
if (models.lightmap !== void 0) {
|
|
904
949
|
const rawLightmap = assertRecord(models.lightmap, "assets.models.lightmap");
|
|
905
|
-
assertKeys(rawLightmap, "assets.models.lightmap",
|
|
950
|
+
assertKeys(rawLightmap, "assets.models.lightmap", LIGHTMAP_CONFIG_KEYS);
|
|
906
951
|
if (rawLightmap.atlasSize === void 0 || rawLightmap.padding === void 0) {
|
|
907
952
|
fail("TN_CONFIG_ASSETS_INVALID", "assets.models.lightmap requires atlasSize and padding.");
|
|
908
953
|
}
|
|
954
|
+
const atlasSize = positiveInteger(
|
|
955
|
+
rawLightmap.atlasSize,
|
|
956
|
+
1,
|
|
957
|
+
"TN_CONFIG_ASSETS_INVALID",
|
|
958
|
+
"assets.models.lightmap.atlasSize"
|
|
959
|
+
);
|
|
960
|
+
if (atlasSize % 4 !== 0) {
|
|
961
|
+
fail("TN_CONFIG_ASSETS_INVALID", "assets.models.lightmap.atlasSize must be a multiple of 4.");
|
|
962
|
+
}
|
|
909
963
|
lightmap = {
|
|
910
|
-
atlasSize
|
|
911
|
-
rawLightmap.atlasSize,
|
|
912
|
-
1,
|
|
913
|
-
"TN_CONFIG_ASSETS_INVALID",
|
|
914
|
-
"assets.models.lightmap.atlasSize"
|
|
915
|
-
),
|
|
964
|
+
atlasSize,
|
|
916
965
|
padding: positiveInteger(
|
|
917
966
|
rawLightmap.padding,
|
|
918
967
|
1,
|
|
@@ -1163,18 +1212,7 @@ function validateAudio(raw) {
|
|
|
1163
1212
|
}
|
|
1164
1213
|
function validateAssets(raw) {
|
|
1165
1214
|
const assets = assertRecord(raw, "assets");
|
|
1166
|
-
assertKeys(assets, "assets",
|
|
1167
|
-
"audio",
|
|
1168
|
-
"budget",
|
|
1169
|
-
"exclude",
|
|
1170
|
-
"concurrency",
|
|
1171
|
-
"lod",
|
|
1172
|
-
"models",
|
|
1173
|
-
"source",
|
|
1174
|
-
"output",
|
|
1175
|
-
"targets",
|
|
1176
|
-
"textures"
|
|
1177
|
-
]);
|
|
1215
|
+
assertKeys(assets, "assets", ASSETS_CONFIG_KEYS);
|
|
1178
1216
|
const targets = assets.targets === void 0 ? void 0 : validateAssetTargets(assets.targets);
|
|
1179
1217
|
const lod = assets.lod === void 0 ? void 0 : validateLod(assets.lod);
|
|
1180
1218
|
const models = assets.models === void 0 ? void 0 : validateModels(assets.models);
|
|
@@ -1182,6 +1220,9 @@ function validateAssets(raw) {
|
|
|
1182
1220
|
if (assets.exclude !== void 0 && (!Array.isArray(assets.exclude) || assets.exclude.some((glob) => typeof glob !== "string" || glob.trim() === ""))) {
|
|
1183
1221
|
fail("TN_CONFIG_ASSETS_INVALID", "assets.exclude must be an array of non-empty glob strings.");
|
|
1184
1222
|
}
|
|
1223
|
+
if (assets.nativePackage !== void 0 && typeof assets.nativePackage !== "boolean") {
|
|
1224
|
+
fail("TN_CONFIG_ASSETS_INVALID", "assets.nativePackage must be true or false.");
|
|
1225
|
+
}
|
|
1185
1226
|
return {
|
|
1186
1227
|
...assets.audio === void 0 ? {} : { audio: validateAudio(assets.audio) },
|
|
1187
1228
|
...assets.exclude === void 0 ? {} : { exclude: assets.exclude },
|
|
@@ -1202,6 +1243,7 @@ function validateAssets(raw) {
|
|
|
1202
1243
|
...targets === void 0 ? {} : { targets },
|
|
1203
1244
|
...lod === void 0 ? {} : { lod },
|
|
1204
1245
|
...models === void 0 ? {} : { models },
|
|
1246
|
+
...assets.nativePackage === void 0 ? {} : { nativePackage: assets.nativePackage },
|
|
1205
1247
|
...textures === void 0 ? {} : { textures }
|
|
1206
1248
|
};
|
|
1207
1249
|
}
|
|
@@ -1211,6 +1253,7 @@ var PROFILE_ASSET_KEYS = [
|
|
|
1211
1253
|
"budget",
|
|
1212
1254
|
"lod",
|
|
1213
1255
|
"models",
|
|
1256
|
+
"nativePackage",
|
|
1214
1257
|
"targets",
|
|
1215
1258
|
"textures"
|
|
1216
1259
|
];
|
|
@@ -1436,8 +1479,8 @@ function assertProfileCapReachable(assets, overlay, name) {
|
|
|
1436
1479
|
}
|
|
1437
1480
|
}
|
|
1438
1481
|
async function loadConfigInternal(root, selection) {
|
|
1439
|
-
const packagePath =
|
|
1440
|
-
const sourcePath =
|
|
1482
|
+
const packagePath = path5.join(root, "package.json");
|
|
1483
|
+
const sourcePath = path5.join(root, CONFIG_FILE);
|
|
1441
1484
|
const manifest = await withConfigContext(
|
|
1442
1485
|
packageContext(root),
|
|
1443
1486
|
"TN_CONFIG_PACKAGE_INVALID",
|
|
@@ -1462,6 +1505,7 @@ async function loadConfigInternal(root, selection) {
|
|
|
1462
1505
|
if (raw !== void 0) {
|
|
1463
1506
|
assertKeys(raw, "config", [
|
|
1464
1507
|
"app",
|
|
1508
|
+
"engine",
|
|
1465
1509
|
"display",
|
|
1466
1510
|
"bootSplash",
|
|
1467
1511
|
"window",
|
|
@@ -1489,6 +1533,7 @@ async function loadConfigInternal(root, selection) {
|
|
|
1489
1533
|
}
|
|
1490
1534
|
return {
|
|
1491
1535
|
app,
|
|
1536
|
+
engine: validateEngine(raw?.engine),
|
|
1492
1537
|
display: validateDisplay(raw?.display),
|
|
1493
1538
|
window: validateWindow(raw?.window, app.name),
|
|
1494
1539
|
nativeEntry: validateNativeEntry(configuredEntry ?? packageEntry ?? "src/game.ts", root),
|
|
@@ -1510,22 +1555,164 @@ async function loadConfigInternal(root, selection) {
|
|
|
1510
1555
|
);
|
|
1511
1556
|
}
|
|
1512
1557
|
async function loadConfig(cwd, selection) {
|
|
1513
|
-
const root =
|
|
1558
|
+
const root = path5.resolve(cwd);
|
|
1514
1559
|
return withConfigContext(
|
|
1515
|
-
validationContext(root, [
|
|
1560
|
+
validationContext(root, [path5.join(root, CONFIG_FILE), path5.join(root, "package.json")]),
|
|
1516
1561
|
"TN_CONFIG_VALIDATION_FAILED",
|
|
1517
1562
|
() => loadConfigInternal(root, selection)
|
|
1518
1563
|
);
|
|
1519
1564
|
}
|
|
1520
1565
|
|
|
1566
|
+
// src/native-css-compat.ts
|
|
1567
|
+
var UNSUPPORTED_PROPERTIES = {
|
|
1568
|
+
filter: "filters are not in the Core paint profile",
|
|
1569
|
+
"backdrop-filter": "backdrop blur is not in the Core paint profile",
|
|
1570
|
+
"-webkit-backdrop-filter": "backdrop blur is not in the Core paint profile",
|
|
1571
|
+
mask: "masks are not in the Core paint profile",
|
|
1572
|
+
"mask-image": "masks are not in the Core paint profile",
|
|
1573
|
+
"mask-size": "masks are not in the Core paint profile",
|
|
1574
|
+
"mask-position": "masks are not in the Core paint profile",
|
|
1575
|
+
"mask-repeat": "masks are not in the Core paint profile",
|
|
1576
|
+
"-webkit-mask": "masks are not in the Core paint profile",
|
|
1577
|
+
"-webkit-mask-image": "masks are not in the Core paint profile",
|
|
1578
|
+
"mix-blend-mode": "blend modes are not in the Core paint profile",
|
|
1579
|
+
"background-blend-mode": "blend modes are not in the Core paint profile",
|
|
1580
|
+
"clip-path": "clip-path (SVG shapes) is not in the Core paint profile",
|
|
1581
|
+
"shape-outside": "floats and shapes are not in the Core layout profile",
|
|
1582
|
+
columns: "multicolumn layout is not in the Core layout profile",
|
|
1583
|
+
"column-count": "multicolumn layout is not in the Core layout profile",
|
|
1584
|
+
"column-width": "multicolumn layout is not in the Core layout profile",
|
|
1585
|
+
perspective: "3D transforms are not in the Core paint profile",
|
|
1586
|
+
"scroll-snap-type": "scroll snapping is not in the Core interaction profile",
|
|
1587
|
+
"scroll-snap-align": "scroll snapping is not in the Core interaction profile"
|
|
1588
|
+
};
|
|
1589
|
+
var UNSUPPORTED_VALUES = [
|
|
1590
|
+
["float", /^(?!none\b)/u, "floats are not in the Core layout profile"],
|
|
1591
|
+
["position", /^sticky\b/u, "sticky positioning is not in the Core layout profile"],
|
|
1592
|
+
["display", /^(table|inline-table|table-)/u, "tables are not in the Core layout profile"],
|
|
1593
|
+
[
|
|
1594
|
+
"writing-mode",
|
|
1595
|
+
/^(?!horizontal-tb\b)/u,
|
|
1596
|
+
"alternate writing modes are not in the Core layout profile"
|
|
1597
|
+
],
|
|
1598
|
+
["transform-style", /preserve-3d/u, "3D transforms are not in the Core paint profile"],
|
|
1599
|
+
[
|
|
1600
|
+
"transform",
|
|
1601
|
+
/\b(translate3d|translatez|rotate3d|rotatex|rotatey|rotatez|scale3d|scalez|matrix3d|perspective)\s*\(/u,
|
|
1602
|
+
"3D transforms are not in the Core paint profile"
|
|
1603
|
+
],
|
|
1604
|
+
[
|
|
1605
|
+
"animation",
|
|
1606
|
+
/^(?!none\b)/u,
|
|
1607
|
+
"keyframe animations are not in the Core motion profile (transitions are)"
|
|
1608
|
+
],
|
|
1609
|
+
[
|
|
1610
|
+
"animation-name",
|
|
1611
|
+
/^(?!none\b)/u,
|
|
1612
|
+
"keyframe animations are not in the Core motion profile (transitions are)"
|
|
1613
|
+
],
|
|
1614
|
+
[
|
|
1615
|
+
"grid-template-columns",
|
|
1616
|
+
/\bsubgrid\b|\bmasonry\b/u,
|
|
1617
|
+
"subgrid and masonry are not in the Core layout profile"
|
|
1618
|
+
],
|
|
1619
|
+
[
|
|
1620
|
+
"grid-template-rows",
|
|
1621
|
+
/\bsubgrid\b|\bmasonry\b/u,
|
|
1622
|
+
"subgrid and masonry are not in the Core layout profile"
|
|
1623
|
+
]
|
|
1624
|
+
];
|
|
1625
|
+
var UNSUPPORTED_AT_RULES = {
|
|
1626
|
+
keyframes: "keyframe animations are not in the Core motion profile (transitions are)",
|
|
1627
|
+
"-webkit-keyframes": "keyframe animations are not in the Core motion profile (transitions are)",
|
|
1628
|
+
container: "container queries are not in the Core profile",
|
|
1629
|
+
page: "@page is not part of a HUD",
|
|
1630
|
+
namespace: "@namespace is not part of a HUD",
|
|
1631
|
+
"counter-style": "@counter-style is not in the Core profile"
|
|
1632
|
+
};
|
|
1633
|
+
var UNSUPPORTED_SELECTORS = [
|
|
1634
|
+
[/:has\(/u, ":has()", ":has() is not in the Core selector profile"]
|
|
1635
|
+
];
|
|
1636
|
+
function locate(css, offset) {
|
|
1637
|
+
let line = 1;
|
|
1638
|
+
let last = -1;
|
|
1639
|
+
for (let i = 0; i < offset; i++) {
|
|
1640
|
+
if (css.charCodeAt(i) === 10) {
|
|
1641
|
+
line += 1;
|
|
1642
|
+
last = i;
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1645
|
+
return { line, column: offset - last };
|
|
1646
|
+
}
|
|
1647
|
+
function mask(css) {
|
|
1648
|
+
return css.replaceAll(/\/\*[\s\S]*?\*\//gu, (m) => m.replaceAll(/[^\n]/gu, " ")).replaceAll(/(["'])(?:\\.|(?!\1)[^\\\n])*\1/gu, (m) => m[0] + " ".repeat(m.length - 2) + m[0]);
|
|
1649
|
+
}
|
|
1650
|
+
function findNativeCssViolations(file, css) {
|
|
1651
|
+
const source = mask(css);
|
|
1652
|
+
const findings = [];
|
|
1653
|
+
const add = (offset, what, why) => {
|
|
1654
|
+
findings.push({ file, ...locate(css, offset), what, why });
|
|
1655
|
+
};
|
|
1656
|
+
const stack = [];
|
|
1657
|
+
let start = 0;
|
|
1658
|
+
for (let i = 0; i < source.length; i++) {
|
|
1659
|
+
const ch = source[i];
|
|
1660
|
+
if (ch === "{") {
|
|
1661
|
+
const prelude = source.slice(start, i).trim();
|
|
1662
|
+
const at = /^@([-\w]+)/u.exec(prelude);
|
|
1663
|
+
const offset = start + (source.slice(start, i).length - source.slice(start, i).trimStart().length);
|
|
1664
|
+
if (at) {
|
|
1665
|
+
const reason = UNSUPPORTED_AT_RULES[at[1]?.toLowerCase() ?? ""];
|
|
1666
|
+
if (reason !== void 0) add(offset, `@${at[1]}`, reason);
|
|
1667
|
+
stack.push({ declarations: /^@(font-face|page|property|counter-style)\b/u.test(prelude) });
|
|
1668
|
+
} else {
|
|
1669
|
+
for (const [pattern, what, why] of UNSUPPORTED_SELECTORS) {
|
|
1670
|
+
if (pattern.test(prelude)) add(offset, what, why);
|
|
1671
|
+
}
|
|
1672
|
+
stack.push({ declarations: true });
|
|
1673
|
+
}
|
|
1674
|
+
start = i + 1;
|
|
1675
|
+
} else if (ch === ";" || ch === "}") {
|
|
1676
|
+
const top = stack[stack.length - 1];
|
|
1677
|
+
if (top?.declarations) {
|
|
1678
|
+
const declaration = source.slice(start, i);
|
|
1679
|
+
const colon = declaration.indexOf(":");
|
|
1680
|
+
if (colon > 0) {
|
|
1681
|
+
const property = declaration.slice(0, colon).trim().toLowerCase();
|
|
1682
|
+
const value = declaration.slice(colon + 1).trim().toLowerCase().replace(/\s*!important$/u, "");
|
|
1683
|
+
const offset = start + (declaration.length - declaration.trimStart().length);
|
|
1684
|
+
if (!property.startsWith("--")) {
|
|
1685
|
+
const reason = UNSUPPORTED_PROPERTIES[property];
|
|
1686
|
+
if (reason !== void 0) add(offset, property, reason);
|
|
1687
|
+
for (const [name, test, why] of UNSUPPORTED_VALUES) {
|
|
1688
|
+
if (name === property && test.test(value)) add(offset, `${property}: ${value}`, why);
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
}
|
|
1693
|
+
if (ch === "}") stack.pop();
|
|
1694
|
+
start = i + 1;
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
return findings;
|
|
1698
|
+
}
|
|
1699
|
+
function describeNativeCssFindings(findings) {
|
|
1700
|
+
return findings.map(
|
|
1701
|
+
(f) => ` ${f.file}:${f.line}:${f.column}${f.authored === void 0 ? "" : ` authored ${f.authored}`} ${f.what} \u2014 ${f.why}`
|
|
1702
|
+
).join("\n");
|
|
1703
|
+
}
|
|
1704
|
+
function webRuntimeDecoders(config) {
|
|
1705
|
+
return config.engine === "threejs" ? { ktx2: true, meshopt: true } : { ktx2: false, meshopt: false };
|
|
1706
|
+
}
|
|
1707
|
+
|
|
1521
1708
|
// src/build.ts
|
|
1522
1709
|
var TARGETS = ["web", "desktop", "android", "ios"];
|
|
1523
1710
|
function projectRequire2(cwd) {
|
|
1524
|
-
return createRequire$1(
|
|
1711
|
+
return createRequire$1(path5.join(cwd, "package.json"));
|
|
1525
1712
|
}
|
|
1526
1713
|
function packageRoot(cwd, packageName) {
|
|
1527
1714
|
try {
|
|
1528
|
-
return
|
|
1715
|
+
return path5.dirname(projectRequire2(cwd).resolve(`${packageName}/package.json`));
|
|
1529
1716
|
} catch {
|
|
1530
1717
|
throw new Error(`Cannot build because '${packageName}' is not installed in ${cwd}.`);
|
|
1531
1718
|
}
|
|
@@ -1536,17 +1723,17 @@ async function run(command, args, cwd) {
|
|
|
1536
1723
|
child.once("error", reject);
|
|
1537
1724
|
child.once("exit", (code) => {
|
|
1538
1725
|
if (code === 0) resolve();
|
|
1539
|
-
else reject(new Error(`${
|
|
1726
|
+
else reject(new Error(`${path5.basename(command)} exited with code ${code ?? "unknown"}.`));
|
|
1540
1727
|
});
|
|
1541
1728
|
});
|
|
1542
1729
|
}
|
|
1543
1730
|
async function projectName(cwd) {
|
|
1544
|
-
const manifest = JSON.parse(await readFile(
|
|
1731
|
+
const manifest = JSON.parse(await readFile(path5.join(cwd, "package.json"), "utf8"));
|
|
1545
1732
|
const name = manifest.name?.replace(/^@[^/]+\//u, "").replace(/[^a-zA-Z0-9._-]/gu, "-");
|
|
1546
1733
|
if (name === void 0 || name.length === 0) throw new Error("package.json must name the game.");
|
|
1547
1734
|
return name;
|
|
1548
1735
|
}
|
|
1549
|
-
async function assertNativeBundleCompatible(bundle, target) {
|
|
1736
|
+
async function assertNativeBundleCompatible(bundle, target, capabilities = resolveRuntimeAssetCapabilities(target)) {
|
|
1550
1737
|
const source = await readFile(bundle, "utf8");
|
|
1551
1738
|
const webOnlyUi = [
|
|
1552
1739
|
["React DOM", /\breact-dom(?:\/client)?\b|\bcreateRoot\s*\(/u],
|
|
@@ -1557,18 +1744,25 @@ async function assertNativeBundleCompatible(bundle, target) {
|
|
|
1557
1744
|
`TN_NATIVE_WEB_ONLY_UI: ${target} bundle contains ${webOnlyUi.map(([label]) => label).join(", ")}. Keep the portable game in src/game.ts and move DOM or React mounting to src/main.ts; native UI is owned by PRD-051.`
|
|
1558
1745
|
);
|
|
1559
1746
|
}
|
|
1560
|
-
if (target === "desktop") return;
|
|
1747
|
+
if (target === "desktop" && capabilities.webAssembly) return;
|
|
1561
1748
|
const wasm = [
|
|
1562
|
-
["WebAssembly", /\bWebAssembly\b/u],
|
|
1749
|
+
...capabilities.webAssembly ? [] : [["WebAssembly", /\bWebAssembly\b/u]],
|
|
1563
1750
|
["Rapier WASM", /rapier_wasm|RAPIER_VERSION|rawrapier/u],
|
|
1564
1751
|
["Recast WASM", /recast-navigation\.wasm|recastnavigationwasm/u]
|
|
1565
1752
|
].filter(([, pattern]) => pattern.test(source));
|
|
1566
1753
|
if (wasm.length === 0) return;
|
|
1567
1754
|
throw new Error(
|
|
1568
|
-
|
|
1755
|
+
`${target === "desktop" ? "TN_NATIVE_WASM_UNSUPPORTED" : "TN_NATIVE_WASM_ON_MOBILE"}: ${target} artifact ${capabilities.artifact} (${capabilities.engine}) bundle contains ${wasm.map(([label]) => label).join(", ")}. Move web-only WASM imports out of src/game.ts or provide a threenative-native conditional backend; mobile navigation is owned by PRD-052.`
|
|
1569
1756
|
);
|
|
1570
1757
|
}
|
|
1571
1758
|
function assertNativeUiRendererCompatible(target, renderer, platform2 = process.platform) {
|
|
1759
|
+
if (renderer === "native-css") {
|
|
1760
|
+
if (target === "android" || target === "desktop" && platform2 === "linux") return;
|
|
1761
|
+
const targetName = target === "desktop" ? `desktop on ${platform2}` : `${target} (the CSS backend runs on Linux desktop and Android only)`;
|
|
1762
|
+
throw new Error(
|
|
1763
|
+
`TN_UI_RENDERER_UNSUPPORTED: ui.renderer is "native-css", which is supported on Linux desktop and Android only in this release; set ui.renderer to "native" or "web" for ${targetName}.`
|
|
1764
|
+
);
|
|
1765
|
+
}
|
|
1572
1766
|
if (renderer === "native" || target === "android" || target === "ios") return;
|
|
1573
1767
|
if (target === "desktop" && (platform2 === "linux" || platform2 === "darwin" || platform2 === "win32")) {
|
|
1574
1768
|
return;
|
|
@@ -1589,17 +1783,148 @@ function namedAssets(logicalPaths) {
|
|
|
1589
1783
|
return rest > 0 ? `${shown} and ${rest} more` : shown;
|
|
1590
1784
|
}
|
|
1591
1785
|
function assetRoot(cwd, config) {
|
|
1592
|
-
return
|
|
1786
|
+
return path5.resolve(cwd, config.assets?.output ?? "public");
|
|
1787
|
+
}
|
|
1788
|
+
function isMobileRawAstc(bytes, gltf = false) {
|
|
1789
|
+
try {
|
|
1790
|
+
if (bytes.byteLength < 80) return false;
|
|
1791
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
1792
|
+
const width = view.getUint32(20, true);
|
|
1793
|
+
const height = view.getUint32(24, true);
|
|
1794
|
+
const count = view.getUint32(40, true);
|
|
1795
|
+
const indexEnd = 80 + count * 24;
|
|
1796
|
+
if (width === 0 || height === 0 || count !== Math.floor(Math.log2(Math.max(width, height))) + 1 || indexEnd > bytes.byteLength)
|
|
1797
|
+
return false;
|
|
1798
|
+
const dfd = view.getUint32(48, true);
|
|
1799
|
+
const dfdLength = view.getUint32(52, true);
|
|
1800
|
+
if (dfd < indexEnd || dfd % 4 !== 0 || dfdLength !== 44 || dfd + dfdLength > bytes.byteLength || view.getUint32(dfd, true) !== dfdLength || view.getUint16(dfd + 10, true) !== 40 || view.getBigUint64(64, true) !== 0n || view.getBigUint64(72, true) !== 0n)
|
|
1801
|
+
return false;
|
|
1802
|
+
const regions = [
|
|
1803
|
+
[0, indexEnd],
|
|
1804
|
+
[dfd, dfd + dfdLength]
|
|
1805
|
+
];
|
|
1806
|
+
const kvd = view.getUint32(56, true);
|
|
1807
|
+
const kvdLength = view.getUint32(60, true);
|
|
1808
|
+
if (kvdLength > 0) {
|
|
1809
|
+
if (kvd < indexEnd || kvd % 4 !== 0 || kvd + kvdLength > bytes.byteLength) return false;
|
|
1810
|
+
regions.push([kvd, kvd + kvdLength]);
|
|
1811
|
+
}
|
|
1812
|
+
for (let mip = 0; mip < count; mip += 1) {
|
|
1813
|
+
const offset = view.getBigUint64(80 + mip * 24, true);
|
|
1814
|
+
const expected = Math.ceil(Math.max(1, Math.floor(width / 2 ** mip)) / 4) * Math.ceil(Math.max(1, Math.floor(height / 2 ** mip)) / 4) * 16;
|
|
1815
|
+
if (!Number.isSafeInteger(expected) || view.getBigUint64(88 + mip * 24, true) !== BigInt(expected) || view.getBigUint64(96 + mip * 24, true) !== BigInt(expected) || offset % 16n !== 0n || offset + BigInt(expected) > BigInt(bytes.byteLength))
|
|
1816
|
+
return false;
|
|
1817
|
+
regions.push([Number(offset), Number(offset) + expected]);
|
|
1818
|
+
}
|
|
1819
|
+
regions.sort((a, b) => a[0] - b[0]);
|
|
1820
|
+
if (regions.some(([start], i) => i > 0 && start < (regions[i - 1]?.[1] ?? 0))) return false;
|
|
1821
|
+
const container = read(bytes);
|
|
1822
|
+
const descriptor = container.dataFormatDescriptor[0];
|
|
1823
|
+
const sample = descriptor?.samples[0];
|
|
1824
|
+
return [VK_FORMAT_ASTC_4x4_UNORM_BLOCK, VK_FORMAT_ASTC_4x4_SRGB_BLOCK].includes(
|
|
1825
|
+
container.vkFormat
|
|
1826
|
+
) && container.typeSize === 1 && container.pixelDepth === 0 && container.layerCount === 0 && container.faceCount === 1 && container.supercompressionScheme === KHR_SUPERCOMPRESSION_NONE && container.globalData === null && container.levelCount === count && container.levels.length === count && container.dataFormatDescriptor.length === 1 && descriptor?.vendorId === 0 && descriptor.descriptorType === 0 && descriptor.versionNumber === 2 && descriptor.colorModel === KHR_DF_MODEL_ASTC && (descriptor.flags === 0 || descriptor.flags === 1) && (!gltf || descriptor.flags === 0 && descriptor.colorPrimaries === (container.vkFormat === VK_FORMAT_ASTC_4x4_SRGB_BLOCK ? 1 : 0) && (container.keyValue.KTXorientation === void 0 || container.keyValue.KTXorientation === "rd")) && descriptor.transferFunction === (container.vkFormat === VK_FORMAT_ASTC_4x4_SRGB_BLOCK ? KHR_DF_TRANSFER_SRGB : KHR_DF_TRANSFER_LINEAR) && descriptor.texelBlockDimension.join() === "3,3,0,0" && descriptor.bytesPlane.join() === "16,0,0,0,0,0,0,0" && descriptor.samples.length === 1 && sample?.bitOffset === 0 && sample.bitLength === 127 && sample.channelType === 0 && sample.samplePosition.join() === "0,0,0,0" && sample.sampleLower === 0 && sample.sampleUpper === 4294967295;
|
|
1827
|
+
} catch {
|
|
1828
|
+
return false;
|
|
1829
|
+
}
|
|
1830
|
+
}
|
|
1831
|
+
var CompiledModelIO = class extends NodeIO {
|
|
1832
|
+
constructor(outputRoot, canonicalRoot) {
|
|
1833
|
+
super();
|
|
1834
|
+
this.outputRoot = outputRoot;
|
|
1835
|
+
this.canonicalRoot = canonicalRoot;
|
|
1836
|
+
this.setAllowNetwork(false);
|
|
1837
|
+
}
|
|
1838
|
+
outputRoot;
|
|
1839
|
+
canonicalRoot;
|
|
1840
|
+
async readURI(uri, type) {
|
|
1841
|
+
if (/^[a-z][a-z0-9+.-]*:/iu.test(uri))
|
|
1842
|
+
throw new Error("External resource protocols are forbidden.");
|
|
1843
|
+
const resolved = path5.resolve(uri);
|
|
1844
|
+
const relative = path5.relative(this.outputRoot, resolved);
|
|
1845
|
+
if (relative === ".." || relative.startsWith(`..${path5.sep}`) || path5.isAbsolute(relative))
|
|
1846
|
+
throw new Error("Model resource escapes the compiled root.");
|
|
1847
|
+
const canonical = await realpath(resolved);
|
|
1848
|
+
const realRelative = path5.relative(this.canonicalRoot, canonical);
|
|
1849
|
+
if (realRelative === ".." || realRelative.startsWith(`..${path5.sep}`) || path5.isAbsolute(realRelative))
|
|
1850
|
+
throw new Error("Model resource escapes the compiled root through a symlink.");
|
|
1851
|
+
return type === "text" ? readFile(canonical, "utf8") : readFile(canonical);
|
|
1852
|
+
}
|
|
1853
|
+
};
|
|
1854
|
+
async function inspectMobileModel(outputRoot, output) {
|
|
1855
|
+
const io = new CompiledModelIO(outputRoot, await realpath(outputRoot));
|
|
1856
|
+
const { json, resources } = await io.readAsJSON(path5.resolve(outputRoot, output));
|
|
1857
|
+
const extensions = /* @__PURE__ */ new Set([...json.extensionsUsed ?? [], ...json.extensionsRequired ?? []]);
|
|
1858
|
+
for (const view of json.bufferViews ?? [])
|
|
1859
|
+
for (const name of Object.keys(view.extensions ?? {})) extensions.add(name);
|
|
1860
|
+
for (const mesh of json.meshes ?? [])
|
|
1861
|
+
for (const primitive of mesh.primitives)
|
|
1862
|
+
for (const name of Object.keys(primitive.extensions ?? {})) extensions.add(name);
|
|
1863
|
+
if (extensions.has("KHR_texture_basisu"))
|
|
1864
|
+
throw new Error("Basis model textures require a decoder.");
|
|
1865
|
+
const astcImages = /* @__PURE__ */ new Set();
|
|
1866
|
+
for (const texture of json.textures ?? []) {
|
|
1867
|
+
if (texture.extensions?.KHR_texture_basisu !== void 0)
|
|
1868
|
+
throw new Error("Basis texture ownership is forbidden.");
|
|
1869
|
+
const astc = texture.extensions?.EXT_texture_astc;
|
|
1870
|
+
if (astc === void 0) continue;
|
|
1871
|
+
if (!Number.isSafeInteger(astc.source) || !json.images?.[astc.source ?? -1] || texture.source !== void 0)
|
|
1872
|
+
throw new Error("Invalid ASTC source or unsupported paired fallback.");
|
|
1873
|
+
astcImages.add(astc.source);
|
|
1874
|
+
}
|
|
1875
|
+
const hasAstcImages = astcImages.size > 0;
|
|
1876
|
+
if (extensions.has("EXT_texture_astc") !== hasAstcImages || hasAstcImages && (!(json.extensionsUsed ?? []).includes("EXT_texture_astc") || !(json.extensionsRequired ?? []).includes("EXT_texture_astc")))
|
|
1877
|
+
throw new Error("ASTC model extension membership is inconsistent.");
|
|
1878
|
+
for (const [index, image] of (json.images ?? []).entries()) {
|
|
1879
|
+
let bytes;
|
|
1880
|
+
if (typeof image.uri === "string") bytes = resources[image.uri];
|
|
1881
|
+
else {
|
|
1882
|
+
if (!Number.isSafeInteger(image.bufferView) || (image.bufferView ?? -1) < 0)
|
|
1883
|
+
throw new Error("Invalid model image bufferView index.");
|
|
1884
|
+
const view = json.bufferViews?.[image.bufferView ?? -1];
|
|
1885
|
+
const buffer = json.buffers?.[view?.buffer ?? -1];
|
|
1886
|
+
const resource = buffer === void 0 ? void 0 : resources[buffer.uri ?? GLB_BUFFER];
|
|
1887
|
+
const offset = view?.byteOffset ?? 0;
|
|
1888
|
+
const length = view?.byteLength;
|
|
1889
|
+
if (!view || !buffer || !resource || !Number.isSafeInteger(view.buffer) || buffer.uri === void 0 && view.buffer !== 0 || !Number.isSafeInteger(offset) || offset < 0 || !Number.isSafeInteger(length) || (length ?? 0) <= 0 || !Number.isSafeInteger(buffer.byteLength) || offset + (length ?? 0) > buffer.byteLength || offset + (length ?? 0) > resource.byteLength)
|
|
1890
|
+
throw new Error("Invalid model image buffer bounds.");
|
|
1891
|
+
bytes = resource.subarray(offset, offset + length);
|
|
1892
|
+
}
|
|
1893
|
+
if (!bytes || bytes.byteLength === 0) throw new Error("Missing model image payload.");
|
|
1894
|
+
const isKtx = image.mimeType === "image/ktx2" || Buffer.from(bytes.subarray(0, 12)).equals(Buffer.from("ab4b5458203230bb0d0a1a0a", "hex"));
|
|
1895
|
+
if (astcImages.has(index) || isKtx) {
|
|
1896
|
+
if (!astcImages.has(index) || image.mimeType !== "image/ktx2" || !isMobileRawAstc(bytes, true) || (json.textures ?? []).some((texture) => texture.source === index))
|
|
1897
|
+
throw new Error("Model KTX2 must be valid raw ASTC owned by EXT_texture_astc.");
|
|
1898
|
+
}
|
|
1899
|
+
}
|
|
1900
|
+
return [...extensions];
|
|
1593
1901
|
}
|
|
1594
|
-
async function
|
|
1595
|
-
|
|
1902
|
+
async function isCompiledMobileAstc(outputRoot, output) {
|
|
1903
|
+
const resolved = path5.resolve(outputRoot, output);
|
|
1904
|
+
const relative = path5.relative(outputRoot, resolved);
|
|
1905
|
+
if (relative === ".." || relative.startsWith(`..${path5.sep}`) || path5.isAbsolute(relative))
|
|
1906
|
+
return false;
|
|
1907
|
+
try {
|
|
1908
|
+
const canonicalRoot = await realpath(outputRoot);
|
|
1909
|
+
const canonical = await realpath(resolved);
|
|
1910
|
+
const realRelative = path5.relative(canonicalRoot, canonical);
|
|
1911
|
+
if (realRelative === ".." || realRelative.startsWith(`..${path5.sep}`) || path5.isAbsolute(realRelative))
|
|
1912
|
+
return false;
|
|
1913
|
+
return isMobileRawAstc(await readFile(canonical));
|
|
1914
|
+
} catch {
|
|
1915
|
+
return false;
|
|
1916
|
+
}
|
|
1917
|
+
}
|
|
1918
|
+
async function assertNativeAssetsCompatible(cwd, target, config, capabilities = resolveRuntimeAssetCapabilities(target)) {
|
|
1919
|
+
if (target === "web") return;
|
|
1596
1920
|
const outputRoot = assetRoot(cwd, config);
|
|
1597
|
-
const manifestPath =
|
|
1921
|
+
const manifestPath = path5.join(outputRoot, "assets.manifest.json");
|
|
1598
1922
|
let raw;
|
|
1599
1923
|
try {
|
|
1600
1924
|
raw = await readFile(manifestPath, "utf8");
|
|
1601
|
-
} catch {
|
|
1602
|
-
return;
|
|
1925
|
+
} catch (error) {
|
|
1926
|
+
if (error.code === "ENOENT") return;
|
|
1927
|
+
throw error;
|
|
1603
1928
|
}
|
|
1604
1929
|
let parsed;
|
|
1605
1930
|
try {
|
|
@@ -1609,27 +1934,61 @@ async function assertNativeAssetsCompatible(cwd, target, config) {
|
|
|
1609
1934
|
`TN_NATIVE_ASSET_MANIFEST_INVALID: '${manifestPath}' is not valid JSON: ${error instanceof Error ? error.message : String(error)}`
|
|
1610
1935
|
);
|
|
1611
1936
|
}
|
|
1612
|
-
const entries = parsed
|
|
1613
|
-
if (typeof entries !== "object" || entries === null) {
|
|
1937
|
+
const entries = parsed?.entries;
|
|
1938
|
+
if (typeof entries !== "object" || entries === null || Array.isArray(entries)) {
|
|
1614
1939
|
throw new Error(`TN_NATIVE_ASSET_MANIFEST_INVALID: '${manifestPath}' has no 'entries' object.`);
|
|
1615
1940
|
}
|
|
1616
1941
|
const rows = Object.entries(entries).map(
|
|
1617
1942
|
([logical, entry]) => [logical, entry ?? {}]
|
|
1618
1943
|
);
|
|
1619
|
-
|
|
1620
|
-
|
|
1944
|
+
if (!capabilities.decoders.ktx2 && (target === "android" || target === "ios")) {
|
|
1945
|
+
for (const [logical, entry] of rows) {
|
|
1946
|
+
if (typeof entry.output !== "string" || !(entry.kind === "model" || /\.gl(?:b|tf)$/iu.test(entry.output)))
|
|
1947
|
+
continue;
|
|
1948
|
+
try {
|
|
1949
|
+
const actual = await inspectMobileModel(outputRoot, entry.output);
|
|
1950
|
+
entry.extensions = [
|
|
1951
|
+
.../* @__PURE__ */ new Set([...Array.isArray(entry.extensions) ? entry.extensions : [], ...actual])
|
|
1952
|
+
];
|
|
1953
|
+
} catch (error) {
|
|
1954
|
+
throw new Error(
|
|
1955
|
+
`TN_NATIVE_KTX2_UNSUPPORTED: ${target} cannot admit model '${logical}': ${error instanceof Error ? error.message : String(error)}`
|
|
1956
|
+
);
|
|
1957
|
+
}
|
|
1958
|
+
}
|
|
1959
|
+
}
|
|
1960
|
+
const ktx2Rows = rows.filter(
|
|
1961
|
+
([, entry]) => typeof entry.output === "string" && /\.ktx2$/iu.test(entry.output) || Array.isArray(entry.extensions) && entry.extensions.includes("KHR_texture_basisu") || Array.isArray(entry.sharedImages) && entry.sharedImages.some(
|
|
1962
|
+
(image) => image !== null && typeof image === "object" && typeof image.output === "string" && /\.ktx2$/iu.test(image.output)
|
|
1963
|
+
)
|
|
1964
|
+
);
|
|
1965
|
+
const ktx2 = [];
|
|
1966
|
+
for (const [logical, entry] of ktx2Rows) {
|
|
1967
|
+
if (!capabilities.decoders.ktx2 && (target === "android" || target === "ios") && !(Array.isArray(entry.extensions) && entry.extensions.includes("KHR_texture_basisu"))) {
|
|
1968
|
+
const outputs = [
|
|
1969
|
+
...typeof entry.output === "string" && /\.ktx2$/iu.test(entry.output) ? [entry.output] : [],
|
|
1970
|
+
...Array.isArray(entry.sharedImages) ? entry.sharedImages.flatMap(
|
|
1971
|
+
(image) => image !== null && typeof image === "object" && typeof image.output === "string" && /\.ktx2$/iu.test(image.output) ? [image.output] : []
|
|
1972
|
+
) : []
|
|
1973
|
+
];
|
|
1974
|
+
if (outputs.length > 0 && (await Promise.all(outputs.map((output) => isCompiledMobileAstc(outputRoot, output)))).every(Boolean))
|
|
1975
|
+
continue;
|
|
1976
|
+
}
|
|
1977
|
+
ktx2.push(logical);
|
|
1978
|
+
}
|
|
1979
|
+
if (!capabilities.decoders.ktx2 && ktx2.length > 0) {
|
|
1621
1980
|
throw new Error(
|
|
1622
|
-
`TN_NATIVE_KTX2_UNSUPPORTED: ${target} cannot ship compiled KTX2 textures (${namedAssets(ktx2)}).
|
|
1981
|
+
`TN_NATIVE_KTX2_UNSUPPORTED: ${target} cannot ship compiled KTX2 textures (${namedAssets(ktx2)}). Selected artifact ${capabilities.artifact} (${capabilities.engine}) has no admitted Basis/KTX2 decoder in its bundle. Replace or transcode the authored KTX2 source for ${target === "desktop" ? "this runtime" : "mobile"}, or exclude it from ${target === "desktop" ? "this runtime's" : "mobile"} builds; keep compressed textures on the web target.`
|
|
1623
1982
|
);
|
|
1624
1983
|
}
|
|
1625
1984
|
const compressedModels = rows.filter(
|
|
1626
1985
|
([, entry]) => (Array.isArray(entry.extensions) ? entry.extensions : []).some(
|
|
1627
|
-
(extension) => typeof extension === "string" && COMPRESSED_MODEL_EXTENSIONS.includes(extension)
|
|
1986
|
+
(extension) => typeof extension === "string" && COMPRESSED_MODEL_EXTENSIONS.includes(extension) && !capabilities.decoders[extension === "KHR_draco_mesh_compression" ? "draco" : "meshopt"]
|
|
1628
1987
|
)
|
|
1629
1988
|
).map(([logical]) => logical);
|
|
1630
1989
|
if (compressedModels.length > 0) {
|
|
1631
1990
|
throw new Error(
|
|
1632
|
-
`TN_NATIVE_MESH_COMPRESSION_UNSUPPORTED: ${target} cannot ship compressed model geometry (${namedAssets(compressedModels)}).
|
|
1991
|
+
`TN_NATIVE_MESH_COMPRESSION_UNSUPPORTED: ${target} cannot ship compressed model geometry (${namedAssets(compressedModels)}). Selected artifact ${capabilities.artifact} (${capabilities.engine}) has no admitted ${rows.flatMap(([, entry]) => Array.isArray(entry.extensions) ? entry.extensions.filter((extension) => COMPRESSED_MODEL_EXTENSIONS.includes(String(extension))) : []).join(", ")} decoder in its bundle. Native compilation keeps shared images and decoder-free model rewrites while omitting Meshopt output; rebuild the native target, or keep compressed models on the web target.`
|
|
1633
1992
|
);
|
|
1634
1993
|
}
|
|
1635
1994
|
}
|
|
@@ -1641,21 +2000,21 @@ function announceProfile(config) {
|
|
|
1641
2000
|
`
|
|
1642
2001
|
);
|
|
1643
2002
|
}
|
|
1644
|
-
var UI_ENTRY =
|
|
2003
|
+
var UI_ENTRY = path5.join("src", "ui", "main.tsx");
|
|
1645
2004
|
var UI_PAGE_PREFIX = ".threenative-ui-";
|
|
1646
2005
|
async function buildUi(cwd, config) {
|
|
1647
|
-
const output =
|
|
1648
|
-
const entry =
|
|
2006
|
+
const output = path5.join(cwd, ".threenative", "build", "ui");
|
|
2007
|
+
const entry = path5.join(cwd, UI_ENTRY);
|
|
1649
2008
|
try {
|
|
1650
2009
|
if (!(await stat(entry)).isFile()) throw new Error("not a file");
|
|
1651
2010
|
} catch {
|
|
1652
2011
|
throw new Error(
|
|
1653
|
-
`TN_UI_ENTRY_MISSING: ui.renderer is "${config.ui.renderer}" but ${UI_ENTRY} does not exist. It is the entry every platform's web view loads; create it, or set ui.renderer to "native".`
|
|
2012
|
+
`TN_UI_ENTRY_MISSING: ui.renderer is "${config.ui.renderer}" but ${UI_ENTRY} does not exist. It is the entry every platform's web view loads, and the file the native-css renderer imports its stylesheet from; create it, or set ui.renderer to "native".`
|
|
1654
2013
|
);
|
|
1655
2014
|
}
|
|
1656
|
-
const buildRoot =
|
|
2015
|
+
const buildRoot = path5.join(cwd, ".threenative", "build");
|
|
1657
2016
|
await mkdir(buildRoot, { recursive: true });
|
|
1658
|
-
const page =
|
|
2017
|
+
const page = path5.join(cwd, `${UI_PAGE_PREFIX}${randomUUID()}.html`);
|
|
1659
2018
|
await writeFile(
|
|
1660
2019
|
page,
|
|
1661
2020
|
[
|
|
@@ -1668,24 +2027,284 @@ async function buildUi(cwd, config) {
|
|
|
1668
2027
|
" </head>",
|
|
1669
2028
|
" <body>",
|
|
1670
2029
|
' <div id="tn-ui"></div>',
|
|
1671
|
-
` <script type="module" src="/${UI_ENTRY.split(
|
|
2030
|
+
` <script type="module" src="/${UI_ENTRY.split(path5.sep).join("/")}"></script>`,
|
|
1672
2031
|
" </body>",
|
|
1673
2032
|
"</html>"
|
|
1674
2033
|
].join("\n")
|
|
1675
2034
|
);
|
|
1676
|
-
const driver =
|
|
1677
|
-
await writeFile(driver, uiBuildDriver(cwd, page, output));
|
|
2035
|
+
const driver = path5.join(buildRoot, "build-ui.mjs");
|
|
2036
|
+
await writeFile(driver, uiBuildDriver(cwd, page, output, config.ui.renderer === "native-css"));
|
|
1678
2037
|
try {
|
|
1679
2038
|
await run(process.execPath, [driver], cwd);
|
|
1680
2039
|
} finally {
|
|
1681
2040
|
await rm(page, { force: true });
|
|
1682
2041
|
}
|
|
1683
|
-
const generatedPage =
|
|
1684
|
-
const index =
|
|
2042
|
+
const generatedPage = path5.join(output, path5.basename(page));
|
|
2043
|
+
const index = path5.join(output, "index.html");
|
|
1685
2044
|
await rename(generatedPage, index);
|
|
1686
2045
|
return output;
|
|
1687
2046
|
}
|
|
1688
|
-
function
|
|
2047
|
+
async function extractUiStylesheets(uiDir, outDir, projectRoot) {
|
|
2048
|
+
await rm(outDir, { force: true, recursive: true });
|
|
2049
|
+
await mkdir(outDir);
|
|
2050
|
+
const stylesheets = [];
|
|
2051
|
+
const walk2 = async (dir) => {
|
|
2052
|
+
for (const entry of await readdir(dir, { withFileTypes: true })) {
|
|
2053
|
+
const child = path5.join(dir, entry.name);
|
|
2054
|
+
if (entry.isDirectory()) await walk2(child);
|
|
2055
|
+
else if (entry.isFile() && /\.css$/iu.test(entry.name)) stylesheets.push(child);
|
|
2056
|
+
}
|
|
2057
|
+
};
|
|
2058
|
+
await walk2(uiDir);
|
|
2059
|
+
if (stylesheets.length === 0) {
|
|
2060
|
+
throw new Error(
|
|
2061
|
+
"TN_CSS_UI_NO_STYLESHEET: the UI build emitted no .css; import your stylesheet from src/ui/main.tsx"
|
|
2062
|
+
);
|
|
2063
|
+
}
|
|
2064
|
+
let sheets = stylesheets.sort();
|
|
2065
|
+
const sheetNames = /* @__PURE__ */ new Set();
|
|
2066
|
+
for (const file of sheets) {
|
|
2067
|
+
const name = path5.basename(file);
|
|
2068
|
+
if (sheetNames.has(name)) {
|
|
2069
|
+
throw new Error(
|
|
2070
|
+
`TN_CSS_UI_STYLESHEET_AMBIGUOUS: ${file} emits ${name}, which another stylesheet already claimed`
|
|
2071
|
+
);
|
|
2072
|
+
}
|
|
2073
|
+
sheetNames.add(name);
|
|
2074
|
+
}
|
|
2075
|
+
const assets = /* @__PURE__ */ new Map();
|
|
2076
|
+
const findings = [];
|
|
2077
|
+
for (const file of sheets) {
|
|
2078
|
+
const css = await readFile(file, "utf8");
|
|
2079
|
+
await collectStylesheetAssets(uiDir, file, css, assets, projectRoot);
|
|
2080
|
+
findings.push(...await locateNativeCssViolations(uiDir, file, css, projectRoot));
|
|
2081
|
+
}
|
|
2082
|
+
const emitted = path5.join(uiDir, "assets");
|
|
2083
|
+
if (existsSync(emitted)) {
|
|
2084
|
+
for (const entry of await readdir(emitted, { withFileTypes: true })) {
|
|
2085
|
+
if (!entry.isFile() || !/\.(png|jpe?g|webp|gif)$/iu.test(entry.name)) continue;
|
|
2086
|
+
const source = path5.join(emitted, entry.name);
|
|
2087
|
+
const claimed = assets.get(entry.name);
|
|
2088
|
+
if (claimed !== void 0 && claimed !== source) {
|
|
2089
|
+
throw new Error(
|
|
2090
|
+
`TN_CSS_UI_ASSET_AMBIGUOUS: ${source} and ${path5.relative(uiDir, claimed)} would both ship as ${entry.name}`
|
|
2091
|
+
);
|
|
2092
|
+
}
|
|
2093
|
+
assets.set(entry.name, source);
|
|
2094
|
+
}
|
|
2095
|
+
}
|
|
2096
|
+
await writeFile(
|
|
2097
|
+
path5.join(path5.dirname(outDir), "native-css-compat.json"),
|
|
2098
|
+
`${JSON.stringify({ profile: "core", findings }, null, 2)}
|
|
2099
|
+
`
|
|
2100
|
+
);
|
|
2101
|
+
if (findings.length > 0) {
|
|
2102
|
+
throw new Error(
|
|
2103
|
+
`TN_CSS_UI_UNSUPPORTED_CSS: ${findings.length} active rule(s) outside the native-css Core profile (docs/guides/native-css-support.md):
|
|
2104
|
+
${describeNativeCssFindings(findings)}`
|
|
2105
|
+
);
|
|
2106
|
+
}
|
|
2107
|
+
let order;
|
|
2108
|
+
const manifestFile = path5.join(uiDir, ".vite", "manifest.json");
|
|
2109
|
+
if (existsSync(manifestFile)) {
|
|
2110
|
+
const manifest = JSON.parse(await readFile(manifestFile, "utf8"));
|
|
2111
|
+
const entries = Object.keys(manifest).filter(
|
|
2112
|
+
(key) => manifest[key]?.isEntry && path5.basename(manifest[key]?.src ?? "").startsWith(UI_PAGE_PREFIX)
|
|
2113
|
+
);
|
|
2114
|
+
if (entries.length !== 1)
|
|
2115
|
+
throw new Error("TN_CSS_UI_STYLESHEET_ORDER: the UI manifest must name exactly one UI entry");
|
|
2116
|
+
const visited = /* @__PURE__ */ new Set();
|
|
2117
|
+
const ordered = /* @__PURE__ */ new Set();
|
|
2118
|
+
const visit = (key) => {
|
|
2119
|
+
if (visited.has(key)) return;
|
|
2120
|
+
visited.add(key);
|
|
2121
|
+
const chunk = manifest[key];
|
|
2122
|
+
if (chunk === void 0)
|
|
2123
|
+
throw new Error(`TN_CSS_UI_STYLESHEET_ORDER: missing manifest chunk ${key}`);
|
|
2124
|
+
for (const imported of chunk.imports ?? []) visit(imported);
|
|
2125
|
+
for (const css of chunk.css ?? []) {
|
|
2126
|
+
const file = path5.resolve(uiDir, css);
|
|
2127
|
+
if (!stylesheets.includes(file))
|
|
2128
|
+
throw new Error(`TN_CSS_UI_STYLESHEET_ORDER: missing emitted stylesheet ${css}`);
|
|
2129
|
+
ordered.add(file);
|
|
2130
|
+
}
|
|
2131
|
+
};
|
|
2132
|
+
visit(entries[0]);
|
|
2133
|
+
const globalCss = manifest["style.css"]?.file;
|
|
2134
|
+
if (ordered.size === 0 && sheets.length === 1 && globalCss !== void 0) {
|
|
2135
|
+
const file = path5.resolve(uiDir, globalCss);
|
|
2136
|
+
if (sheets[0] === file) ordered.add(file);
|
|
2137
|
+
}
|
|
2138
|
+
const inactive = sheets.filter((file) => !ordered.has(file));
|
|
2139
|
+
if (inactive.length > 0)
|
|
2140
|
+
throw new Error(
|
|
2141
|
+
`TN_CSS_UI_LAZY_STYLESHEET_UNSUPPORTED: ${inactive.map((file) => path5.relative(uiDir, file)).join(", ")} is not loaded by the UI entry; import native-css styles statically from src/ui/main.tsx`
|
|
2142
|
+
);
|
|
2143
|
+
sheets = [...ordered];
|
|
2144
|
+
order = { version: 1, stylesheets: sheets.map((file) => path5.basename(file)) };
|
|
2145
|
+
}
|
|
2146
|
+
for (const file of sheets) {
|
|
2147
|
+
await copyFile(file, path5.join(outDir, path5.basename(file)));
|
|
2148
|
+
const sourceMap = `${file}.map`;
|
|
2149
|
+
if (existsSync(sourceMap)) {
|
|
2150
|
+
await copyFile(sourceMap, path5.join(outDir, path5.basename(sourceMap)));
|
|
2151
|
+
}
|
|
2152
|
+
}
|
|
2153
|
+
for (const [name, source] of assets) {
|
|
2154
|
+
await copyFile(source, path5.join(outDir, name));
|
|
2155
|
+
}
|
|
2156
|
+
if (order !== void 0)
|
|
2157
|
+
await writeFile(path5.join(outDir, "stylesheets.json"), `${JSON.stringify(order)}
|
|
2158
|
+
`);
|
|
2159
|
+
return readdir(outDir);
|
|
2160
|
+
}
|
|
2161
|
+
async function collectStylesheetAssets(build2, file, css, assets, projectRoot) {
|
|
2162
|
+
const source = css.replaceAll(
|
|
2163
|
+
/\/\*[\s\S]*?\*\//gu,
|
|
2164
|
+
(comment) => comment.replaceAll(/[^\r\n]/g, " ")
|
|
2165
|
+
);
|
|
2166
|
+
for (const match of source.matchAll(/url\(([^)]*)\)/giu)) {
|
|
2167
|
+
const target = (match[1] ?? "").trim().replace(/^["']|["']$/gu, "").trim();
|
|
2168
|
+
if (target === "" || target.startsWith("data:") || target.startsWith("#")) continue;
|
|
2169
|
+
try {
|
|
2170
|
+
const resolved = resolveStylesheetAsset(build2, file, target);
|
|
2171
|
+
const name = path5.basename(resolved);
|
|
2172
|
+
const claimed = assets.get(name);
|
|
2173
|
+
if (claimed !== void 0 && claimed !== resolved) {
|
|
2174
|
+
throw new Error(
|
|
2175
|
+
`TN_CSS_UI_ASSET_AMBIGUOUS: ${file} references ${target} as ${name}, which ${path5.relative(build2, claimed)} already claimed`
|
|
2176
|
+
);
|
|
2177
|
+
}
|
|
2178
|
+
assets.set(name, resolved);
|
|
2179
|
+
} catch (error) {
|
|
2180
|
+
if (error instanceof Error && /^TN_CSS_UI_ASSET_(?:UNSUPPORTED|AMBIGUOUS):/u.test(error.message)) {
|
|
2181
|
+
error.message += await stylesheetAssetLocation(
|
|
2182
|
+
build2,
|
|
2183
|
+
file,
|
|
2184
|
+
css,
|
|
2185
|
+
match.index,
|
|
2186
|
+
target,
|
|
2187
|
+
projectRoot
|
|
2188
|
+
);
|
|
2189
|
+
}
|
|
2190
|
+
throw error;
|
|
2191
|
+
}
|
|
2192
|
+
}
|
|
2193
|
+
}
|
|
2194
|
+
async function stylesheetTraceMap(build2, file, css) {
|
|
2195
|
+
try {
|
|
2196
|
+
const links = [...css.matchAll(/\/\*[#@]\s*sourceMappingURL\s*=\s*([^*]*?)\*\//gu)];
|
|
2197
|
+
if (links.length !== 1 || links[0]?.[1]?.trim() !== `${path5.basename(file)}.map`)
|
|
2198
|
+
return void 0;
|
|
2199
|
+
const [root, mapFile] = await Promise.all([realpath(build2), realpath(`${file}.map`)]);
|
|
2200
|
+
const inside = path5.relative(root, mapFile);
|
|
2201
|
+
if (inside === "" || inside === ".." || inside.startsWith(`..${path5.sep}`) || path5.isAbsolute(inside))
|
|
2202
|
+
return void 0;
|
|
2203
|
+
const serialized = await readFile(mapFile, "utf8");
|
|
2204
|
+
const raw = JSON.parse(serialized);
|
|
2205
|
+
if (raw.version !== 3 || // ECMA-426 permits an omitted file; the CSS annotation already identifies this sidecar.
|
|
2206
|
+
raw.file !== void 0 && raw.file !== path5.basename(file) || typeof raw.mappings !== "string" || !/^[A-Za-z0-9+/;,]*$/u.test(raw.mappings) || !Array.isArray(raw.sources) || !raw.sources.every((source) => typeof source === "string") || !Array.isArray(raw.names) || !raw.names.every((name) => typeof name === "string") || raw.sourceRoot !== void 0 && typeof raw.sourceRoot !== "string" || !Array.isArray(raw.sourcesContent) || raw.sourcesContent.length !== raw.sources.length || !raw.sourcesContent.every(
|
|
2207
|
+
(content) => content === null || typeof content === "string"
|
|
2208
|
+
))
|
|
2209
|
+
return void 0;
|
|
2210
|
+
const map = new TraceMap(serialized, pathToFileURL(`${file}.map`).href);
|
|
2211
|
+
const mappings = decodedMappings(map);
|
|
2212
|
+
const canonical = encodedMappings(
|
|
2213
|
+
new TraceMap({ version: 3, names: map.names, sources: map.sources, mappings })
|
|
2214
|
+
);
|
|
2215
|
+
if (canonical !== raw.mappings) return void 0;
|
|
2216
|
+
if (new Set(map.resolvedSources).size !== map.sources.length) return void 0;
|
|
2217
|
+
return map;
|
|
2218
|
+
} catch {
|
|
2219
|
+
return void 0;
|
|
2220
|
+
}
|
|
2221
|
+
}
|
|
2222
|
+
async function authoredStylesheetLocation(map, projectRoot, line, column) {
|
|
2223
|
+
try {
|
|
2224
|
+
const original = originalPositionFor(map, { line, column });
|
|
2225
|
+
if (typeof original.source !== "string" || original.line === null || original.column === null)
|
|
2226
|
+
return void 0;
|
|
2227
|
+
const sourceURL = new URL(original.source);
|
|
2228
|
+
if (sourceURL.protocol !== "file:") return void 0;
|
|
2229
|
+
const [project, authoredFile] = await Promise.all([
|
|
2230
|
+
realpath(projectRoot),
|
|
2231
|
+
realpath(fileURLToPath(sourceURL))
|
|
2232
|
+
]);
|
|
2233
|
+
const source = path5.relative(project, authoredFile);
|
|
2234
|
+
if (source === "" || source === ".." || source.startsWith(`..${path5.sep}`) || path5.isAbsolute(source))
|
|
2235
|
+
return void 0;
|
|
2236
|
+
const content = sourceContentFor(map, original.source);
|
|
2237
|
+
if (typeof content !== "string" || content !== await readFile(authoredFile, "utf8"))
|
|
2238
|
+
return void 0;
|
|
2239
|
+
return { file: authoredFile, source, line: original.line, column: original.column };
|
|
2240
|
+
} catch {
|
|
2241
|
+
return void 0;
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2244
|
+
function authoredLocationString(location) {
|
|
2245
|
+
return `${location.source}:${location.line}:${location.column + 1}`;
|
|
2246
|
+
}
|
|
2247
|
+
async function locateNativeCssViolations(build2, file, css, projectRoot) {
|
|
2248
|
+
const found = findNativeCssViolations(path5.relative(build2, file), css);
|
|
2249
|
+
if (projectRoot === void 0 || found.length === 0) return found;
|
|
2250
|
+
const map = await stylesheetTraceMap(build2, file, css);
|
|
2251
|
+
if (map === void 0) return found;
|
|
2252
|
+
return Promise.all(
|
|
2253
|
+
found.map(async (finding) => {
|
|
2254
|
+
const authored = await authoredStylesheetLocation(
|
|
2255
|
+
map,
|
|
2256
|
+
projectRoot,
|
|
2257
|
+
finding.line,
|
|
2258
|
+
// A finding counts columns from 1; a map records them from 0.
|
|
2259
|
+
finding.column - 1
|
|
2260
|
+
);
|
|
2261
|
+
return authored === void 0 ? finding : { ...finding, authored: authoredLocationString(authored) };
|
|
2262
|
+
})
|
|
2263
|
+
);
|
|
2264
|
+
}
|
|
2265
|
+
async function stylesheetAssetLocation(build2, file, css, offset, target, projectRoot) {
|
|
2266
|
+
const before = css.slice(0, offset);
|
|
2267
|
+
const line = before.split("\n").length;
|
|
2268
|
+
const column = offset - before.lastIndexOf("\n") - 1;
|
|
2269
|
+
const generated = `
|
|
2270
|
+
generated: ${file}:${line}:${column + 1}`;
|
|
2271
|
+
if (projectRoot === void 0) return generated;
|
|
2272
|
+
try {
|
|
2273
|
+
const map = await stylesheetTraceMap(build2, file, css);
|
|
2274
|
+
if (map === void 0) return generated;
|
|
2275
|
+
const segment = traceSegment(map, line - 1, column);
|
|
2276
|
+
if (segment === null || segment.length !== 4 && segment.length !== 5 || segment[0] !== column || !segment.every((value) => Number.isSafeInteger(value) && value >= 0) || (decodedMappings(map)[line - 1] ?? []).filter((entry) => entry[0] === column).length !== 1)
|
|
2277
|
+
return generated;
|
|
2278
|
+
const authored = await authoredStylesheetLocation(map, projectRoot, line, column);
|
|
2279
|
+
if (authored === void 0) return generated;
|
|
2280
|
+
const authoredLine = (await readFile(authored.file, "utf8")).replaceAll(/\/\*[\s\S]*?\*\//gu, (comment) => comment.replaceAll(/[^\r\n]/g, " ")).split(/\r?\n/u)[authored.line - 1];
|
|
2281
|
+
const authoredURL = authoredLine?.slice(authored.column).match(/^url\(([^)]*)\)/iu);
|
|
2282
|
+
if (authoredURL === null || authoredURL === void 0 || (authoredURL[1] ?? "").trim().replace(/^["']|["']$/gu, "").trim() !== target)
|
|
2283
|
+
return generated;
|
|
2284
|
+
return `${generated}
|
|
2285
|
+
authored: ${authoredLocationString(authored)}`;
|
|
2286
|
+
} catch {
|
|
2287
|
+
return generated;
|
|
2288
|
+
}
|
|
2289
|
+
}
|
|
2290
|
+
function resolveStylesheetAsset(build2, file, target) {
|
|
2291
|
+
const offMachine = "only a file inside the UI build ships with it";
|
|
2292
|
+
const refuse = (why) => {
|
|
2293
|
+
throw new Error(`TN_CSS_UI_ASSET_UNSUPPORTED: ${file} references ${target}; ${why}`);
|
|
2294
|
+
};
|
|
2295
|
+
if (/^[a-z][a-z0-9+.-]*:/iu.test(target) || target.startsWith("//")) return refuse(offMachine);
|
|
2296
|
+
if (path5.isAbsolute(target)) return refuse(offMachine);
|
|
2297
|
+
const resolved = path5.resolve(path5.dirname(file), target);
|
|
2298
|
+
const inside = path5.relative(build2, resolved);
|
|
2299
|
+
if (inside === "" || inside.startsWith("..") || path5.isAbsolute(inside)) {
|
|
2300
|
+
return refuse(offMachine);
|
|
2301
|
+
}
|
|
2302
|
+
if (!existsSync(resolved) || !statSync(resolved).isFile()) {
|
|
2303
|
+
return refuse(`the UI build holds no ${target}`);
|
|
2304
|
+
}
|
|
2305
|
+
return resolved;
|
|
2306
|
+
}
|
|
2307
|
+
function uiBuildDriver(cwd, page, output, cssSourcemaps = false) {
|
|
1689
2308
|
const literal = (value) => JSON.stringify(value);
|
|
1690
2309
|
return `${[
|
|
1691
2310
|
'import { build, loadConfigFromFile, mergeConfig } from "vite";',
|
|
@@ -1711,7 +2330,10 @@ function uiBuildDriver(cwd, page, output) {
|
|
|
1711
2330
|
// first `useState` on the phone throws `Cannot read properties of null`. `mergeConfig`
|
|
1712
2331
|
// concatenates arrays, so a project that deduped its own packages keeps every one of them.
|
|
1713
2332
|
' resolve: { dedupe: ["react", "react-dom"] },',
|
|
2333
|
+
// Native CSS diagnostics consume adjacent maps linked by the emitted stylesheet.
|
|
2334
|
+
...cssSourcemaps ? [" css: { devSourcemap: true, emitSourcemap: true },"] : [],
|
|
1714
2335
|
" build: {",
|
|
2336
|
+
...cssSourcemaps ? [" sourcemap: true,", " manifest: true,"] : [],
|
|
1715
2337
|
` outDir: ${literal(output)},`,
|
|
1716
2338
|
" emptyOutDir: true,",
|
|
1717
2339
|
` rollupOptions: { input: { index: ${literal(page)} } },`,
|
|
@@ -1724,22 +2346,40 @@ function uiBuildDriver(cwd, page, output) {
|
|
|
1724
2346
|
async function buildWeb(cwd, viteArgs = [], profile) {
|
|
1725
2347
|
const config = await loadConfig(cwd, { target: "web", profile });
|
|
1726
2348
|
announceProfile(config);
|
|
1727
|
-
await compileAssets({
|
|
2349
|
+
await compileAssets({
|
|
2350
|
+
config: config.assets,
|
|
2351
|
+
cwd,
|
|
2352
|
+
platform: "web",
|
|
2353
|
+
runtimeDecoders: webRuntimeDecoders(config),
|
|
2354
|
+
...config.engine !== "threejs" && { runtimeIdentity: "web:native-engine" }
|
|
2355
|
+
});
|
|
1728
2356
|
const assets = assetRoot(cwd, config);
|
|
1729
|
-
const outDir =
|
|
2357
|
+
const outDir = path5.resolve(cwd, viteOutDir(viteArgs));
|
|
1730
2358
|
const staging = stagingPath(outDir);
|
|
1731
|
-
const driver =
|
|
2359
|
+
const driver = path5.join(cwd, ".threenative", "build", "vite.web.mjs");
|
|
1732
2360
|
try {
|
|
1733
|
-
await mkdir(
|
|
1734
|
-
await mkdir(
|
|
1735
|
-
|
|
2361
|
+
await mkdir(path5.dirname(staging), { recursive: true });
|
|
2362
|
+
await mkdir(path5.dirname(driver), { recursive: true });
|
|
2363
|
+
const native = config.engine === "threenative";
|
|
2364
|
+
const configIndex = viteArgs.findIndex(
|
|
2365
|
+
(arg) => arg === "--config" || arg.startsWith("--config=")
|
|
2366
|
+
);
|
|
2367
|
+
const configArg = configIndex === -1 ? void 0 : viteArgs[configIndex];
|
|
2368
|
+
const configFile = configArg?.includes("=") ? configArg.slice(configArg.indexOf("=") + 1) : viteArgs[configIndex + 1];
|
|
2369
|
+
const forwardedArgs = native && configIndex !== -1 ? viteArgs.filter(
|
|
2370
|
+
(_, index) => index !== configIndex && (configArg !== "--config" || index !== configIndex + 1)
|
|
2371
|
+
) : viteArgs;
|
|
2372
|
+
await writeFile(
|
|
2373
|
+
driver,
|
|
2374
|
+
webBuildDriver(cwd, assets, native, configIndex === -1 ? void 0 : configFile)
|
|
2375
|
+
);
|
|
1736
2376
|
await run(
|
|
1737
2377
|
process.execPath,
|
|
1738
2378
|
[
|
|
1739
|
-
|
|
2379
|
+
path5.join(packageRoot(cwd, "vite"), "bin/vite.js"),
|
|
1740
2380
|
"build",
|
|
1741
|
-
...stagedViteArgs(
|
|
1742
|
-
...ownConfigArgs(
|
|
2381
|
+
...stagedViteArgs(forwardedArgs, staging),
|
|
2382
|
+
...ownConfigArgs(forwardedArgs, driver, !native && assets === path5.resolve(cwd, "public"))
|
|
1743
2383
|
],
|
|
1744
2384
|
cwd
|
|
1745
2385
|
);
|
|
@@ -1761,19 +2401,27 @@ async function buildWeb(cwd, viteArgs = [], profile) {
|
|
|
1761
2401
|
});
|
|
1762
2402
|
await publishStagedArtifact(outDir, staging);
|
|
1763
2403
|
} catch (error) {
|
|
1764
|
-
await rm(
|
|
2404
|
+
await rm(path5.dirname(staging), { force: true, recursive: true });
|
|
1765
2405
|
throw error;
|
|
1766
2406
|
}
|
|
1767
2407
|
}
|
|
1768
|
-
function webBuildDriver(cwd, assets) {
|
|
2408
|
+
function webBuildDriver(cwd, assets, native = false, configFile) {
|
|
1769
2409
|
const literal = (value) => JSON.stringify(value);
|
|
1770
2410
|
return `${[
|
|
1771
2411
|
'import { defineConfig, loadConfigFromFile, mergeConfig } from "vite";',
|
|
2412
|
+
...native ? [
|
|
2413
|
+
`import { createWebBrandPlugin } from ${literal(path5.join(packageRoot(cwd, "create-threenative"), "dist/index.js"))};`
|
|
2414
|
+
] : [],
|
|
1772
2415
|
"",
|
|
1773
2416
|
`const root = ${literal(cwd)};`,
|
|
1774
2417
|
`const assets = ${literal(assets)};`,
|
|
1775
2418
|
"export default defineConfig(async ({ command, mode }) => {",
|
|
1776
|
-
|
|
2419
|
+
` const own = (await loadConfigFromFile({ command, mode }, ${configFile === void 0 ? "undefined" : literal(path5.resolve(cwd, configFile))}, root))?.config ?? {};`,
|
|
2420
|
+
...native ? [
|
|
2421
|
+
' if (!(own.plugins ?? []).flat(Infinity).some((plugin) => plugin?.name === "threenative-web-brand"))',
|
|
2422
|
+
" own.plugins = [...(own.plugins ?? []), createWebBrandPlugin()];",
|
|
2423
|
+
' own.build = { target: "es2022", ...own.build };'
|
|
2424
|
+
] : [],
|
|
1777
2425
|
" return mergeConfig(own, own.publicDir === undefined ? { publicDir: assets } : {});",
|
|
1778
2426
|
"});",
|
|
1779
2427
|
""
|
|
@@ -1790,7 +2438,7 @@ async function pruneUnpackagedAssets(cwd, config, outDir) {
|
|
|
1790
2438
|
const selector = await packagingSelector(cwd);
|
|
1791
2439
|
if (selector === void 0) return;
|
|
1792
2440
|
for (const file of selector.selectManifestAssets(assets).dropped)
|
|
1793
|
-
await rm(
|
|
2441
|
+
await rm(path5.join(outDir, file), { force: true });
|
|
1794
2442
|
}
|
|
1795
2443
|
function viteOutDir(viteArgs) {
|
|
1796
2444
|
const index = viteArgs.findIndex((arg) => arg === "--outDir" || arg.startsWith("--outDir="));
|
|
@@ -1808,7 +2456,7 @@ function stagedViteArgs(viteArgs, staging) {
|
|
|
1808
2456
|
}
|
|
1809
2457
|
async function nativeEntry(cwd, config) {
|
|
1810
2458
|
const relative = (config ?? await loadConfig(cwd)).nativeEntry;
|
|
1811
|
-
const entry =
|
|
2459
|
+
const entry = path5.resolve(cwd, relative);
|
|
1812
2460
|
try {
|
|
1813
2461
|
if (!(await stat(entry)).isFile()) throw new Error("not a file");
|
|
1814
2462
|
} catch {
|
|
@@ -1817,25 +2465,25 @@ async function nativeEntry(cwd, config) {
|
|
|
1817
2465
|
return entry;
|
|
1818
2466
|
}
|
|
1819
2467
|
function resolvePackagingConfig(cwd, config) {
|
|
1820
|
-
const resolve = (value) => value === void 0 ? void 0 :
|
|
2468
|
+
const resolve = (value) => value === void 0 ? void 0 : path5.resolve(cwd, value);
|
|
1821
2469
|
const artifact = {
|
|
1822
2470
|
...config,
|
|
1823
2471
|
app: {
|
|
1824
2472
|
...config.app,
|
|
1825
|
-
...config.app.icon === void 0 ? {} : { icon:
|
|
2473
|
+
...config.app.icon === void 0 ? {} : { icon: path5.resolve(cwd, config.app.icon) },
|
|
1826
2474
|
...config.app.icons === void 0 ? {} : {
|
|
1827
2475
|
icons: {
|
|
1828
2476
|
...config.app.icons.android === void 0 ? {} : {
|
|
1829
2477
|
android: {
|
|
1830
|
-
...config.app.icons.android.foreground === void 0 ? {} : { foreground:
|
|
2478
|
+
...config.app.icons.android.foreground === void 0 ? {} : { foreground: path5.resolve(cwd, config.app.icons.android.foreground) },
|
|
1831
2479
|
...config.app.icons.android.background === void 0 ? {} : { background: config.app.icons.android.background },
|
|
1832
|
-
...config.app.icons.android.monochrome === void 0 ? {} : { monochrome:
|
|
2480
|
+
...config.app.icons.android.monochrome === void 0 ? {} : { monochrome: path5.resolve(cwd, config.app.icons.android.monochrome) }
|
|
1833
2481
|
}
|
|
1834
2482
|
},
|
|
1835
2483
|
...config.app.icons.ios === void 0 ? {} : {
|
|
1836
2484
|
ios: {
|
|
1837
|
-
...config.app.icons.ios.dark === void 0 ? {} : { dark:
|
|
1838
|
-
...config.app.icons.ios.tinted === void 0 ? {} : { tinted:
|
|
2485
|
+
...config.app.icons.ios.dark === void 0 ? {} : { dark: path5.resolve(cwd, config.app.icons.ios.dark) },
|
|
2486
|
+
...config.app.icons.ios.tinted === void 0 ? {} : { tinted: path5.resolve(cwd, config.app.icons.ios.tinted) }
|
|
1839
2487
|
}
|
|
1840
2488
|
},
|
|
1841
2489
|
...config.app.icons.web === void 0 ? {} : {
|
|
@@ -1852,39 +2500,62 @@ function resolvePackagingConfig(cwd, config) {
|
|
|
1852
2500
|
...config.bootSplash === void 0 ? {} : {
|
|
1853
2501
|
bootSplash: {
|
|
1854
2502
|
...config.bootSplash,
|
|
1855
|
-
...config.bootSplash.image === void 0 ? {} : { image:
|
|
2503
|
+
...config.bootSplash.image === void 0 ? {} : { image: path5.resolve(cwd, config.bootSplash.image) }
|
|
1856
2504
|
}
|
|
1857
2505
|
}
|
|
1858
2506
|
};
|
|
1859
2507
|
return artifact;
|
|
1860
2508
|
}
|
|
1861
2509
|
async function writePackagingConfig(cwd, config) {
|
|
1862
|
-
const directory =
|
|
2510
|
+
const directory = path5.join(cwd, ".threenative", "build");
|
|
1863
2511
|
await mkdir(directory, { recursive: true });
|
|
1864
2512
|
const artifact = resolvePackagingConfig(cwd, config);
|
|
1865
|
-
const output =
|
|
2513
|
+
const output = path5.join(directory, "config.json");
|
|
1866
2514
|
await writeFile(output, `${JSON.stringify(artifact, null, 2)}
|
|
1867
2515
|
`);
|
|
1868
2516
|
return output;
|
|
1869
2517
|
}
|
|
1870
|
-
function
|
|
1871
|
-
if (binary === void 0 || !existsSync(binary)) return
|
|
1872
|
-
let result;
|
|
2518
|
+
function runtimeEngine(binary, probe) {
|
|
2519
|
+
if (binary === void 0 || !existsSync(binary)) return "unknown";
|
|
1873
2520
|
try {
|
|
1874
|
-
result = probe(binary, ["--version"], { encoding: "utf8" });
|
|
2521
|
+
const result = probe(binary, ["--version"], { encoding: "utf8", timeout: 1e4 });
|
|
2522
|
+
if (result.status !== 0) return "unknown";
|
|
2523
|
+
const engine = /\+ (\S+) build/u.exec(String(result.stdout ?? ""))?.[1]?.toLowerCase();
|
|
2524
|
+
return engine === "v8" || engine === "quickjs" || engine === "jsc" ? engine : "unknown";
|
|
1875
2525
|
} catch {
|
|
1876
|
-
return
|
|
2526
|
+
return "unknown";
|
|
1877
2527
|
}
|
|
1878
|
-
if (result.status !== 0) return true;
|
|
1879
|
-
const engine = /\+ (\S+) build/u.exec(String(result.stdout ?? ""))?.[1] ?? "";
|
|
1880
|
-
return !/^(?:quickjs|jsc)$/iu.test(engine);
|
|
1881
2528
|
}
|
|
1882
|
-
|
|
1883
|
-
const
|
|
2529
|
+
function androidEngine(env) {
|
|
2530
|
+
const value = (env.THREENATIVE_GRADLE_ARGS ?? "").split(" ").map((arg) => /^(?:-P|--project-prop=)threenativeJsEngine=(.*)$/u.exec(arg)?.[1]).filter((entry) => entry !== void 0).at(-1);
|
|
2531
|
+
const engine = (value ?? "v8").toLowerCase();
|
|
2532
|
+
return engine === "v8" || engine === "quickjs" ? engine : "unknown";
|
|
2533
|
+
}
|
|
2534
|
+
function resolveRuntimeAssetCapabilities(target, binary, probe = spawnSync, env = process.env) {
|
|
2535
|
+
const selected = target === "desktop" ? binary : void 0;
|
|
2536
|
+
const engine = target === "web" ? "browser" : target === "android" ? androidEngine(env) : runtimeEngine(selected, probe);
|
|
2537
|
+
const artifact = target === "android" ? `android:${engine}` : selected === void 0 ? `${target}:unresolved` : path5.resolve(selected);
|
|
2538
|
+
let identity = artifact;
|
|
2539
|
+
if (selected !== void 0 && existsSync(selected)) {
|
|
2540
|
+
identity = `${target}:sha256:${createHash("sha256").update(readFileSync(selected)).digest("hex")}`;
|
|
2541
|
+
}
|
|
2542
|
+
const webAssembly = engine === "v8" || engine === "browser";
|
|
2543
|
+
const bundled = target === "web" || target === "desktop" && webAssembly;
|
|
2544
|
+
const androidV8 = target === "android" && engine === "v8";
|
|
2545
|
+
return {
|
|
2546
|
+
artifact,
|
|
2547
|
+
identity,
|
|
2548
|
+
engine,
|
|
2549
|
+
webAssembly,
|
|
2550
|
+
decoders: { ktx2: bundled || androidV8, meshopt: bundled || androidV8, draco: bundled }
|
|
2551
|
+
};
|
|
2552
|
+
}
|
|
2553
|
+
async function bundleNative(cwd, runtimeRoot, entry, target, nativeBackend, decoders) {
|
|
2554
|
+
const output = path5.join(cwd, ".threenative", "build", "game.js");
|
|
1884
2555
|
await run(
|
|
1885
2556
|
process.execPath,
|
|
1886
2557
|
[
|
|
1887
|
-
|
|
2558
|
+
path5.join(runtimeRoot, "scripts", "bundle.mjs"),
|
|
1888
2559
|
"--project",
|
|
1889
2560
|
cwd,
|
|
1890
2561
|
"--entry",
|
|
@@ -1893,7 +2564,12 @@ async function bundleNative(cwd, runtimeRoot, entry, target, nativeBackend) {
|
|
|
1893
2564
|
target,
|
|
1894
2565
|
"--output",
|
|
1895
2566
|
output,
|
|
1896
|
-
...nativeBackend ? ["--native-backend"] : []
|
|
2567
|
+
...nativeBackend ? ["--native-backend"] : [],
|
|
2568
|
+
// Only a mobile bundle reads it: desktop already chooses stubs through `--native-backend`.
|
|
2569
|
+
...target === "android" ? [
|
|
2570
|
+
"--decoders",
|
|
2571
|
+
Object.entries(decoders).filter(([, admitted]) => admitted).map(([codec]) => codec).join(",")
|
|
2572
|
+
] : []
|
|
1897
2573
|
],
|
|
1898
2574
|
cwd
|
|
1899
2575
|
);
|
|
@@ -1901,7 +2577,7 @@ async function bundleNative(cwd, runtimeRoot, entry, target, nativeBackend) {
|
|
|
1901
2577
|
}
|
|
1902
2578
|
async function packagingSelector(cwd) {
|
|
1903
2579
|
try {
|
|
1904
|
-
const module =
|
|
2580
|
+
const module = path5.join(
|
|
1905
2581
|
packageRoot(cwd, "@threenative/runtime-native"),
|
|
1906
2582
|
"scripts",
|
|
1907
2583
|
"asset-manifest.mjs"
|
|
@@ -1918,7 +2594,7 @@ async function measurePackagedAssetBytes(cwd, assets) {
|
|
|
1918
2594
|
let total = 0;
|
|
1919
2595
|
for (const file of selector.selectManifestAssets(assets, { log: () => {
|
|
1920
2596
|
} }).selected)
|
|
1921
|
-
total += (await stat(
|
|
2597
|
+
total += (await stat(path5.join(assets, file))).size;
|
|
1922
2598
|
return total;
|
|
1923
2599
|
}
|
|
1924
2600
|
function budgetSentence(metric, measured, limit) {
|
|
@@ -1951,33 +2627,109 @@ async function assertArtifactBudget(cwd, config, final, staged, assets) {
|
|
|
1951
2627
|
`);
|
|
1952
2628
|
}
|
|
1953
2629
|
}
|
|
2630
|
+
function engineDesktopPlayer(runtimeRoot, env = process.env, cwd = process.cwd()) {
|
|
2631
|
+
const explicit = env.THREENATIVE_ENGINE_PLAYER;
|
|
2632
|
+
if (explicit !== void 0) return path5.resolve(cwd, explicit);
|
|
2633
|
+
const filename = `tn-native-engine-player-v8${process.platform === "win32" ? ".exe" : ""}`;
|
|
2634
|
+
const checkout = path5.join(runtimeRoot, "build", "tn-engine-ui", filename);
|
|
2635
|
+
return existsSync(checkout) ? checkout : path5.join(runtimeRoot, "prebuilt", `${process.platform}-${process.arch}`, filename);
|
|
2636
|
+
}
|
|
2637
|
+
async function buildEngineDesktop(cwd, config, entry) {
|
|
2638
|
+
if (config.ui.renderer === "native-css") {
|
|
2639
|
+
throw new Error(
|
|
2640
|
+
`TN_ENGINE_NATIVE_UI_UNSUPPORTED: engine "threenative" on desktop draws a "web" UI through the engine player's overlay; set ui.renderer to "web" or "native", or set engine: "threejs" to keep the native-css host.`
|
|
2641
|
+
);
|
|
2642
|
+
}
|
|
2643
|
+
const runtimeRoot = packageRoot(cwd, "@threenative/runtime-native");
|
|
2644
|
+
const packager = path5.join(runtimeRoot, "scripts", "package-engine-desktop.mjs");
|
|
2645
|
+
const bundler = path5.join(runtimeRoot, "scripts", "bundle-native-engine.mjs");
|
|
2646
|
+
if (!existsSync(packager) || !existsSync(bundler)) {
|
|
2647
|
+
throw new Error(
|
|
2648
|
+
`TN_ENGINE_BUNDLER_MISSING: engine "threenative" on desktop bundles the game with ${bundler}, which an installed @threenative/runtime-native does not ship yet. Build from a ThreeNative checkout, or set engine: "threejs" in threenative.config.ts to package with the legacy host.`
|
|
2649
|
+
);
|
|
2650
|
+
}
|
|
2651
|
+
const ui = config.ui.renderer === "web" ? await buildUi(cwd, config) : void 0;
|
|
2652
|
+
const output = path5.join(cwd, "dist-native", await projectName(cwd));
|
|
2653
|
+
await packageStaged(output, cwd, [
|
|
2654
|
+
packager,
|
|
2655
|
+
"--project",
|
|
2656
|
+
cwd,
|
|
2657
|
+
"--entry",
|
|
2658
|
+
entry,
|
|
2659
|
+
"--player",
|
|
2660
|
+
engineDesktopPlayer(runtimeRoot, process.env, cwd),
|
|
2661
|
+
...ui === void 0 ? [] : ["--ui", ui],
|
|
2662
|
+
"--width",
|
|
2663
|
+
String(config.window.width),
|
|
2664
|
+
"--height",
|
|
2665
|
+
String(config.window.height),
|
|
2666
|
+
"--title",
|
|
2667
|
+
config.window.title,
|
|
2668
|
+
"--output",
|
|
2669
|
+
output
|
|
2670
|
+
]);
|
|
2671
|
+
}
|
|
1954
2672
|
async function buildNative(target, cwd, allowSourceBuild = false, mode = "debug", format = "apk", profile) {
|
|
1955
2673
|
const config = await loadConfig(cwd, { target, profile });
|
|
1956
2674
|
announceProfile(config);
|
|
1957
2675
|
assertNativeUiRendererCompatible(target, config.ui.renderer);
|
|
1958
|
-
const
|
|
2676
|
+
const entry = await nativeEntry(cwd, config);
|
|
2677
|
+
if (target === "desktop" && config.engine === "threenative") {
|
|
2678
|
+
await buildEngineDesktop(cwd, config, entry);
|
|
2679
|
+
return;
|
|
2680
|
+
}
|
|
2681
|
+
let selectedRuntime;
|
|
2682
|
+
if (target === "desktop") {
|
|
2683
|
+
const module = path5.join(
|
|
2684
|
+
packageRoot(cwd, "@threenative/runtime-native"),
|
|
2685
|
+
"scripts",
|
|
2686
|
+
"package-desktop.mjs"
|
|
2687
|
+
);
|
|
2688
|
+
const { resolveDesktopRuntime } = await import(pathToFileURL(module).href);
|
|
2689
|
+
const explicit = process.env.THREENATIVE_RUNTIME_BINARY;
|
|
2690
|
+
selectedRuntime = await resolveDesktopRuntime(
|
|
2691
|
+
explicit === void 0 ? void 0 : path5.resolve(cwd, explicit)
|
|
2692
|
+
);
|
|
2693
|
+
}
|
|
2694
|
+
const capabilities = resolveRuntimeAssetCapabilities(target, selectedRuntime);
|
|
1959
2695
|
await compileAssets({
|
|
1960
2696
|
config: config.assets,
|
|
1961
2697
|
cwd,
|
|
1962
2698
|
platform: target,
|
|
1963
|
-
|
|
2699
|
+
runtimeDecoders: capabilities.decoders,
|
|
2700
|
+
runtimeIdentity: capabilities.identity
|
|
1964
2701
|
});
|
|
1965
|
-
await assertNativeAssetsCompatible(cwd, target, config);
|
|
1966
|
-
const entry = await nativeEntry(cwd, config);
|
|
2702
|
+
await assertNativeAssetsCompatible(cwd, target, config, capabilities);
|
|
1967
2703
|
const orientation = config.display.orientation;
|
|
1968
2704
|
const configPath = await writePackagingConfig(cwd, config);
|
|
1969
2705
|
const runtimeRoot = packageRoot(cwd, "@threenative/runtime-native");
|
|
1970
|
-
const bundle = await bundleNative(
|
|
1971
|
-
|
|
2706
|
+
const bundle = await bundleNative(
|
|
2707
|
+
cwd,
|
|
2708
|
+
runtimeRoot,
|
|
2709
|
+
entry,
|
|
2710
|
+
target,
|
|
2711
|
+
!capabilities.webAssembly,
|
|
2712
|
+
capabilities.decoders
|
|
2713
|
+
);
|
|
2714
|
+
await assertNativeBundleCompatible(bundle, target, capabilities);
|
|
1972
2715
|
const assets = assetRoot(cwd, config);
|
|
1973
|
-
|
|
2716
|
+
let ui;
|
|
2717
|
+
if (config.ui.renderer !== "native") {
|
|
2718
|
+
const built = await buildUi(cwd, config);
|
|
2719
|
+
if (config.ui.renderer === "native-css") {
|
|
2720
|
+
ui = path5.join(cwd, ".threenative", "build", "ui-css");
|
|
2721
|
+
await extractUiStylesheets(built, ui, cwd);
|
|
2722
|
+
} else {
|
|
2723
|
+
ui = built;
|
|
2724
|
+
}
|
|
2725
|
+
}
|
|
1974
2726
|
if (target === "ios") {
|
|
1975
|
-
const output2 =
|
|
2727
|
+
const output2 = path5.join(cwd, "dist-native", `${await projectName(cwd)}.app`);
|
|
1976
2728
|
await packageStaged(
|
|
1977
2729
|
output2,
|
|
1978
2730
|
runtimeRoot,
|
|
1979
2731
|
[
|
|
1980
|
-
|
|
2732
|
+
path5.join(runtimeRoot, "scripts", "package-ios.mjs"),
|
|
1981
2733
|
"--bundle",
|
|
1982
2734
|
bundle,
|
|
1983
2735
|
"--assets",
|
|
@@ -1995,7 +2747,7 @@ async function buildNative(target, cwd, allowSourceBuild = false, mode = "debug"
|
|
|
1995
2747
|
return;
|
|
1996
2748
|
}
|
|
1997
2749
|
if (target === "android") {
|
|
1998
|
-
const output2 =
|
|
2750
|
+
const output2 = path5.join(
|
|
1999
2751
|
cwd,
|
|
2000
2752
|
"dist-native",
|
|
2001
2753
|
`${await projectName(cwd)}.${format === "aab" ? "aab" : "apk"}`
|
|
@@ -2004,7 +2756,7 @@ async function buildNative(target, cwd, allowSourceBuild = false, mode = "debug"
|
|
|
2004
2756
|
output2,
|
|
2005
2757
|
runtimeRoot,
|
|
2006
2758
|
[
|
|
2007
|
-
|
|
2759
|
+
path5.join(runtimeRoot, "scripts", "package-android.mjs"),
|
|
2008
2760
|
...allowSourceBuild ? ["--allow-source-build"] : [],
|
|
2009
2761
|
"--mode",
|
|
2010
2762
|
mode,
|
|
@@ -2030,12 +2782,12 @@ async function buildNative(target, cwd, allowSourceBuild = false, mode = "debug"
|
|
|
2030
2782
|
);
|
|
2031
2783
|
return;
|
|
2032
2784
|
}
|
|
2033
|
-
const output =
|
|
2785
|
+
const output = path5.join(cwd, "dist-native", await projectName(cwd));
|
|
2034
2786
|
await packageStaged(
|
|
2035
2787
|
output,
|
|
2036
2788
|
cwd,
|
|
2037
2789
|
[
|
|
2038
|
-
|
|
2790
|
+
path5.join(runtimeRoot, "scripts", "package-desktop.mjs"),
|
|
2039
2791
|
"--mode",
|
|
2040
2792
|
mode,
|
|
2041
2793
|
"--bundle",
|
|
@@ -2045,7 +2797,7 @@ async function buildNative(target, cwd, allowSourceBuild = false, mode = "debug"
|
|
|
2045
2797
|
...ui === void 0 ? [] : ["--ui", ui],
|
|
2046
2798
|
"--config",
|
|
2047
2799
|
configPath,
|
|
2048
|
-
...
|
|
2800
|
+
...selectedRuntime === void 0 ? [] : ["--runtime", selectedRuntime],
|
|
2049
2801
|
"--output",
|
|
2050
2802
|
output
|
|
2051
2803
|
],
|
|
@@ -2061,7 +2813,7 @@ async function packageStaged(output, cwd, args, report) {
|
|
|
2061
2813
|
const packager = [...args];
|
|
2062
2814
|
packager[index + 1] = staged;
|
|
2063
2815
|
try {
|
|
2064
|
-
await mkdir(
|
|
2816
|
+
await mkdir(path5.dirname(staged), { recursive: true });
|
|
2065
2817
|
await run(process.execPath, packager, cwd);
|
|
2066
2818
|
if (report !== void 0) {
|
|
2067
2819
|
const produced = await producedArtifact(staged);
|
|
@@ -2076,20 +2828,20 @@ async function packageStaged(output, cwd, args, report) {
|
|
|
2076
2828
|
});
|
|
2077
2829
|
}
|
|
2078
2830
|
} catch (error) {
|
|
2079
|
-
await rm(
|
|
2831
|
+
await rm(path5.dirname(staged), { force: true, recursive: true });
|
|
2080
2832
|
throw error;
|
|
2081
2833
|
}
|
|
2082
2834
|
await publishStagedArtifact(output, staged);
|
|
2083
2835
|
}
|
|
2084
2836
|
function stagingPath(final) {
|
|
2085
|
-
return
|
|
2837
|
+
return path5.join(path5.dirname(final), `.staging-${process.pid}`, path5.basename(final));
|
|
2086
2838
|
}
|
|
2087
2839
|
async function producedArtifact(staged) {
|
|
2088
|
-
const directory =
|
|
2089
|
-
const name =
|
|
2840
|
+
const directory = path5.dirname(staged);
|
|
2841
|
+
const name = path5.basename(staged);
|
|
2090
2842
|
const entries = existsSync(directory) ? await readdir(directory) : [];
|
|
2091
2843
|
for (const candidate of [name, `${name}.exe`, `${name}.app`, `${name}.tar.gz`, `${name}.zip`]) {
|
|
2092
|
-
if (entries.includes(candidate)) return
|
|
2844
|
+
if (entries.includes(candidate)) return path5.join(directory, candidate);
|
|
2093
2845
|
}
|
|
2094
2846
|
const other = entries.filter((entry) => !entry.endsWith(BUILD_REPORT_SUFFIX)).sort()[0];
|
|
2095
2847
|
if (other === void 0) {
|
|
@@ -2097,25 +2849,25 @@ async function producedArtifact(staged) {
|
|
|
2097
2849
|
`TN_BUILD_ARTIFACT_MISSING: the packager exited successfully but wrote no artifact to ${staged}.`
|
|
2098
2850
|
);
|
|
2099
2851
|
}
|
|
2100
|
-
return
|
|
2852
|
+
return path5.join(directory, other);
|
|
2101
2853
|
}
|
|
2102
2854
|
async function publishStagedArtifact(final, staging) {
|
|
2103
|
-
const from =
|
|
2855
|
+
const from = path5.dirname(staging);
|
|
2104
2856
|
const produced = existsSync(from) ? await readdir(from) : [];
|
|
2105
2857
|
if (!produced.some((name) => !name.endsWith(BUILD_REPORT_SUFFIX))) {
|
|
2106
2858
|
throw new Error(
|
|
2107
2859
|
`TN_BUILD_ARTIFACT_MISSING: the packager exited successfully but wrote no artifact to ${staging}; ${final} is unchanged.`
|
|
2108
2860
|
);
|
|
2109
2861
|
}
|
|
2110
|
-
const directory =
|
|
2862
|
+
const directory = path5.dirname(final);
|
|
2111
2863
|
for (const name of produced) {
|
|
2112
|
-
const source =
|
|
2113
|
-
const to =
|
|
2864
|
+
const source = path5.join(from, name);
|
|
2865
|
+
const to = path5.join(directory, name);
|
|
2114
2866
|
if (!existsSync(to)) {
|
|
2115
2867
|
await rename(source, to);
|
|
2116
2868
|
continue;
|
|
2117
2869
|
}
|
|
2118
|
-
const previous =
|
|
2870
|
+
const previous = path5.join(from, `${name}.previous`);
|
|
2119
2871
|
await rename(to, previous);
|
|
2120
2872
|
try {
|
|
2121
2873
|
await rename(source, to);
|
|
@@ -2126,7 +2878,7 @@ async function publishStagedArtifact(final, staging) {
|
|
|
2126
2878
|
}
|
|
2127
2879
|
await rm(from, { force: true, recursive: true });
|
|
2128
2880
|
}
|
|
2129
|
-
var BUILD_LOCK =
|
|
2881
|
+
var BUILD_LOCK = path5.join(".threenative", "build.lock");
|
|
2130
2882
|
function pidAlive(pid) {
|
|
2131
2883
|
try {
|
|
2132
2884
|
process.kill(pid, 0);
|
|
@@ -2173,9 +2925,9 @@ async function build(options) {
|
|
|
2173
2925
|
`${options.target} build does not accept ${options.viteArgs?.join(" ")}. iOS output is simulator-only; device signing remains OPEN.`
|
|
2174
2926
|
);
|
|
2175
2927
|
}
|
|
2176
|
-
const cwd =
|
|
2177
|
-
const lock =
|
|
2178
|
-
await mkdir(
|
|
2928
|
+
const cwd = path5.resolve(options.cwd ?? process.cwd());
|
|
2929
|
+
const lock = path5.join(cwd, BUILD_LOCK);
|
|
2930
|
+
await mkdir(path5.dirname(lock), { recursive: true });
|
|
2179
2931
|
await acquireBuildLock(lock);
|
|
2180
2932
|
try {
|
|
2181
2933
|
if (options.target === "web") await buildWeb(cwd, options.viteArgs, options.profile);
|
|
@@ -2307,13 +3059,13 @@ function binaryNames(platformName) {
|
|
|
2307
3059
|
function pathCandidates(environment, platformName) {
|
|
2308
3060
|
const raw = environment.PATH ?? environment.Path ?? "";
|
|
2309
3061
|
if (raw.trim().length === 0) return [];
|
|
2310
|
-
return raw.split(
|
|
3062
|
+
return raw.split(path5.delimiter).filter((directory) => directory.trim().length > 0).flatMap((directory) => binaryNames(platformName).map((name) => path5.join(directory, name)));
|
|
2311
3063
|
}
|
|
2312
3064
|
function conventionalCandidates(platformName, home) {
|
|
2313
3065
|
if (platformName === "darwin") {
|
|
2314
3066
|
return [
|
|
2315
3067
|
"/Applications/Blender.app/Contents/MacOS/Blender",
|
|
2316
|
-
|
|
3068
|
+
path5.join(home, "Applications/Blender.app/Contents/MacOS/Blender")
|
|
2317
3069
|
];
|
|
2318
3070
|
}
|
|
2319
3071
|
if (platformName === "win32") {
|
|
@@ -2323,7 +3075,7 @@ function conventionalCandidates(platformName, home) {
|
|
|
2323
3075
|
];
|
|
2324
3076
|
return roots.flatMap(
|
|
2325
3077
|
(root) => ["5.2", "5.1", "5.0", "4.5", "4.2"].map(
|
|
2326
|
-
(release) =>
|
|
3078
|
+
(release) => path5.join(root, "Blender Foundation", `Blender ${release}`, "blender.exe")
|
|
2327
3079
|
)
|
|
2328
3080
|
);
|
|
2329
3081
|
}
|
|
@@ -2332,7 +3084,7 @@ function conventionalCandidates(platformName, home) {
|
|
|
2332
3084
|
"/usr/local/bin/blender",
|
|
2333
3085
|
"/snap/bin/blender",
|
|
2334
3086
|
"/var/lib/flatpak/exports/bin/org.blender.Blender",
|
|
2335
|
-
|
|
3087
|
+
path5.join(home, ".local/bin/blender")
|
|
2336
3088
|
];
|
|
2337
3089
|
}
|
|
2338
3090
|
function parseBlenderVersion(output) {
|
|
@@ -2365,7 +3117,7 @@ function resolveBlender(environment = process.env, options = {}) {
|
|
|
2365
3117
|
const install = BLENDER_INSTALL_GUIDANCE;
|
|
2366
3118
|
const override = environment.THREENATIVE_BLENDER_PATH;
|
|
2367
3119
|
if (override !== void 0 && override.trim().length > 0) {
|
|
2368
|
-
const candidate =
|
|
3120
|
+
const candidate = path5.resolve(override.trim());
|
|
2369
3121
|
if (!executableFile(candidate)) {
|
|
2370
3122
|
return {
|
|
2371
3123
|
available: false,
|
|
@@ -2459,10 +3211,10 @@ var MCP_SERVERS = Object.freeze({
|
|
|
2459
3211
|
})
|
|
2460
3212
|
});
|
|
2461
3213
|
var MCP_PACKAGES = Object.freeze({
|
|
2462
|
-
assets: Object.freeze({ name: "threenative-asset-mcp", version: "0.
|
|
2463
|
-
sculpt: Object.freeze({ name: "threenative-sculpt-mcp", version: "0.
|
|
2464
|
-
engine: Object.freeze({ name: "threenative-engine-mcp", version: "0.2.
|
|
2465
|
-
blender: Object.freeze({ name: "threenative-blender-mcp", version: "0.1.
|
|
3214
|
+
assets: Object.freeze({ name: "threenative-asset-mcp", version: "0.14.0" }),
|
|
3215
|
+
sculpt: Object.freeze({ name: "threenative-sculpt-mcp", version: "0.2.2" }),
|
|
3216
|
+
engine: Object.freeze({ name: "threenative-engine-mcp", version: "0.2.6" }),
|
|
3217
|
+
blender: Object.freeze({ name: "threenative-blender-mcp", version: "0.1.6" })
|
|
2466
3218
|
});
|
|
2467
3219
|
var SERVER_FORMATS = Object.freeze({
|
|
2468
3220
|
// Claude Code (`.mcp.json`), Cursor and the Gemini CLI all read this one.
|
|
@@ -2597,14 +3349,14 @@ function requiredAndroidSdkFromRoot(root) {
|
|
|
2597
3349
|
if (root === void 0) return DEFAULT_ANDROID_COMPILE_SDK;
|
|
2598
3350
|
try {
|
|
2599
3351
|
return androidGradleSdk(
|
|
2600
|
-
readFileSync(
|
|
3352
|
+
readFileSync(path5.join(root, "android", "app", "build.gradle.kts"), "utf8")
|
|
2601
3353
|
) ?? DEFAULT_ANDROID_COMPILE_SDK;
|
|
2602
3354
|
} catch {
|
|
2603
3355
|
return DEFAULT_ANDROID_COMPILE_SDK;
|
|
2604
3356
|
}
|
|
2605
3357
|
}
|
|
2606
3358
|
var CORE_PACKAGE_NAME = "@threenative/core";
|
|
2607
|
-
var CORE_PACKAGE_VERSION = "0.3.
|
|
3359
|
+
var CORE_PACKAGE_VERSION = "0.3.6";
|
|
2608
3360
|
var CORE_RESOLVED_SERVERS = /* @__PURE__ */ new Set([
|
|
2609
3361
|
"threenative-engine",
|
|
2610
3362
|
"threenative-blender"
|
|
@@ -2775,11 +3527,11 @@ function nativeEntryCompat(value) {
|
|
|
2775
3527
|
return typeof entry === "string" && entry.length > 0 ? { nativeEntry: entry } : void 0;
|
|
2776
3528
|
}
|
|
2777
3529
|
function resolvePackageDirectoryFrom(start, name) {
|
|
2778
|
-
let directory =
|
|
3530
|
+
let directory = path5.resolve(start);
|
|
2779
3531
|
while (true) {
|
|
2780
|
-
const candidate =
|
|
2781
|
-
if (existsSync(
|
|
2782
|
-
const parent =
|
|
3532
|
+
const candidate = path5.join(directory, "node_modules", name);
|
|
3533
|
+
if (existsSync(path5.join(candidate, "package.json"))) return candidate;
|
|
3534
|
+
const parent = path5.dirname(directory);
|
|
2783
3535
|
if (parent === directory) return void 0;
|
|
2784
3536
|
directory = parent;
|
|
2785
3537
|
}
|
|
@@ -2800,13 +3552,13 @@ function resolvePackageDirectory(snapshot, name) {
|
|
|
2800
3552
|
}
|
|
2801
3553
|
}
|
|
2802
3554
|
function resolveBinaryFrom(start, name) {
|
|
2803
|
-
let directory =
|
|
3555
|
+
let directory = path5.resolve(start);
|
|
2804
3556
|
while (true) {
|
|
2805
|
-
const binDirectory =
|
|
2806
|
-
const candidates = process.platform === "win32" ? [
|
|
3557
|
+
const binDirectory = path5.join(directory, "node_modules", ".bin");
|
|
3558
|
+
const candidates = process.platform === "win32" ? [path5.join(binDirectory, `${name}.cmd`), path5.join(binDirectory, name)] : [path5.join(binDirectory, name)];
|
|
2807
3559
|
const found = candidates.find((candidate) => existsSync(candidate));
|
|
2808
3560
|
if (found !== void 0) return found;
|
|
2809
|
-
const parent =
|
|
3561
|
+
const parent = path5.dirname(directory);
|
|
2810
3562
|
if (parent === directory) return void 0;
|
|
2811
3563
|
directory = parent;
|
|
2812
3564
|
}
|
|
@@ -2879,7 +3631,7 @@ function mcpServerCheck(snapshot, spec, value, file) {
|
|
|
2879
3631
|
status: "fail"
|
|
2880
3632
|
};
|
|
2881
3633
|
}
|
|
2882
|
-
if (snapshot.projectRoot !== void 0 && !existsSync(
|
|
3634
|
+
if (snapshot.projectRoot !== void 0 && !existsSync(path5.resolve(snapshot.projectRoot, spec.expectedArgs))) {
|
|
2883
3635
|
return {
|
|
2884
3636
|
detail: `${spec.configName} points at missing ${spec.expectedArgs}; @threenative/core is not providing the configured server shim`,
|
|
2885
3637
|
fix: "Install @threenative/core again so the generated MCP server entry exists.",
|
|
@@ -2905,7 +3657,7 @@ function mcpServerCheck(snapshot, spec, value, file) {
|
|
|
2905
3657
|
status: "warn"
|
|
2906
3658
|
};
|
|
2907
3659
|
}
|
|
2908
|
-
const manifest = readJsonSync(
|
|
3660
|
+
const manifest = readJsonSync(path5.join(packageDirectory, "package.json"));
|
|
2909
3661
|
const installedVersion = record(manifest)?.version;
|
|
2910
3662
|
if (typeof installedVersion !== "string") {
|
|
2911
3663
|
return {
|
|
@@ -2936,7 +3688,7 @@ function probeMcpServer(projectRoot, spec) {
|
|
|
2936
3688
|
method: "initialize",
|
|
2937
3689
|
params: {
|
|
2938
3690
|
capabilities: {},
|
|
2939
|
-
clientInfo: { name: "threenative-doctor", version: "0.3.
|
|
3691
|
+
clientInfo: { name: "threenative-doctor", version: "0.3.6" },
|
|
2940
3692
|
protocolVersion: "2025-06-18"
|
|
2941
3693
|
}
|
|
2942
3694
|
});
|
|
@@ -3066,10 +3818,10 @@ function configuredTargets(snapshot) {
|
|
|
3066
3818
|
function directoryCanBeWritten(snapshot, relative) {
|
|
3067
3819
|
if (snapshot.directoryWritable !== void 0) return snapshot.directoryWritable(relative);
|
|
3068
3820
|
if (snapshot.projectRoot === void 0) return void 0;
|
|
3069
|
-
const root =
|
|
3070
|
-
let candidate =
|
|
3071
|
-
if (candidate !== root && !candidate.startsWith(`${root}${
|
|
3072
|
-
while (candidate !== root && !existsSync(candidate)) candidate =
|
|
3821
|
+
const root = path5.resolve(snapshot.projectRoot);
|
|
3822
|
+
let candidate = path5.resolve(root, relative);
|
|
3823
|
+
if (candidate !== root && !candidate.startsWith(`${root}${path5.sep}`)) return false;
|
|
3824
|
+
while (candidate !== root && !existsSync(candidate)) candidate = path5.dirname(candidate);
|
|
3073
3825
|
if (!existsSync(candidate)) return false;
|
|
3074
3826
|
try {
|
|
3075
3827
|
if (!statSync(candidate).isDirectory()) return false;
|
|
@@ -3097,21 +3849,20 @@ function assetPipelineCheck(snapshot) {
|
|
|
3097
3849
|
const mobileTargets = configuredTargets(snapshot).filter(
|
|
3098
3850
|
(target) => target === "android" || target === "ios"
|
|
3099
3851
|
);
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
}
|
|
3852
|
+
const lacking = (codec) => mobileTargets.filter((target) => !resolveRuntimeAssetCapabilities(target).decoders[codec]);
|
|
3853
|
+
const noKtx2 = lacking("ktx2");
|
|
3854
|
+
if (noKtx2.length > 0 && assets.textures !== "none") {
|
|
3855
|
+
details.push(
|
|
3856
|
+
`TN_NATIVE_KTX2_UNSUPPORTED: assets.textures compiles textures for ${noKtx2.join("/")}; that runtime requires assets.textures to be "none"`
|
|
3857
|
+
);
|
|
3858
|
+
status = "warn";
|
|
3859
|
+
}
|
|
3860
|
+
const noMeshopt = lacking("meshopt");
|
|
3861
|
+
if (noMeshopt.length > 0 && assets.models !== "none") {
|
|
3862
|
+
details.push(
|
|
3863
|
+
`TN_NATIVE_MESH_COMPRESSION_UNSUPPORTED: assets.models compiles model geometry for ${noMeshopt.join("/")}; that runtime requires assets.models to be "none"`
|
|
3864
|
+
);
|
|
3865
|
+
status = "warn";
|
|
3115
3866
|
}
|
|
3116
3867
|
return {
|
|
3117
3868
|
detail: details.join("; "),
|
|
@@ -3306,10 +4057,10 @@ function sha256File(file) {
|
|
|
3306
4057
|
}
|
|
3307
4058
|
}
|
|
3308
4059
|
function evidencePath(snapshot, relative) {
|
|
3309
|
-
if (snapshot.projectRoot === void 0 ||
|
|
3310
|
-
const root =
|
|
3311
|
-
const resolved =
|
|
3312
|
-
return resolved === root || resolved.startsWith(`${root}${
|
|
4060
|
+
if (snapshot.projectRoot === void 0 || path5.isAbsolute(relative)) return void 0;
|
|
4061
|
+
const root = path5.resolve(snapshot.projectRoot);
|
|
4062
|
+
const resolved = path5.resolve(root, relative);
|
|
4063
|
+
return resolved === root || resolved.startsWith(`${root}${path5.sep}`) ? resolved : void 0;
|
|
3313
4064
|
}
|
|
3314
4065
|
function evidenceExists(snapshot, relative, directory) {
|
|
3315
4066
|
const absolute = evidencePath(snapshot, relative);
|
|
@@ -3539,7 +4290,7 @@ function nativeRuntimeCheck(snapshot) {
|
|
|
3539
4290
|
};
|
|
3540
4291
|
}
|
|
3541
4292
|
const binary = `prebuilt/${key}/${nativeRuntimeFilename()}`;
|
|
3542
|
-
const exists = snapshot.runtimeFileExists?.(binary) ?? existsSync(
|
|
4293
|
+
const exists = snapshot.runtimeFileExists?.(binary) ?? existsSync(path5.join(snapshot.runtimeRoot, binary));
|
|
3543
4294
|
if (!exists) {
|
|
3544
4295
|
return {
|
|
3545
4296
|
detail: `unavailable \u2014 ${key} prebuilt binary is missing`,
|
|
@@ -3548,7 +4299,7 @@ function nativeRuntimeCheck(snapshot) {
|
|
|
3548
4299
|
status: "fail"
|
|
3549
4300
|
};
|
|
3550
4301
|
}
|
|
3551
|
-
const host = snapshot.nativeHost ?? probeNativeHost(
|
|
4302
|
+
const host = snapshot.nativeHost ?? probeNativeHost(path5.join(snapshot.runtimeRoot, binary));
|
|
3552
4303
|
const reported = host.runtimeVersion;
|
|
3553
4304
|
if (reported === void 0) {
|
|
3554
4305
|
return {
|
|
@@ -3625,7 +4376,7 @@ function javaVersion(output) {
|
|
|
3625
4376
|
return Number.isSafeInteger(major) ? { major, version } : void 0;
|
|
3626
4377
|
}
|
|
3627
4378
|
function androidSdkVersion(root, requiredSdk) {
|
|
3628
|
-
const sourceProperties =
|
|
4379
|
+
const sourceProperties = path5.join(
|
|
3629
4380
|
root,
|
|
3630
4381
|
"platforms",
|
|
3631
4382
|
`android-${requiredSdk}`,
|
|
@@ -3641,7 +4392,7 @@ function androidSdkVersion(root, requiredSdk) {
|
|
|
3641
4392
|
}
|
|
3642
4393
|
function probeAndroidToolchain(environment = process.env, requiredSdk = DEFAULT_ANDROID_COMPILE_SDK) {
|
|
3643
4394
|
const javaHome = environment.JAVA_HOME?.trim() || void 0;
|
|
3644
|
-
const java = javaHome === void 0 ? "java" :
|
|
4395
|
+
const java = javaHome === void 0 ? "java" : path5.join(javaHome, "bin", process.platform === "win32" ? "java.exe" : "java");
|
|
3645
4396
|
let jdkMajor;
|
|
3646
4397
|
let jdkVersion;
|
|
3647
4398
|
try {
|
|
@@ -3659,7 +4410,7 @@ function probeAndroidToolchain(environment = process.env, requiredSdk = DEFAULT_
|
|
|
3659
4410
|
const sdkCandidates = [
|
|
3660
4411
|
environment.ANDROID_HOME,
|
|
3661
4412
|
environment.ANDROID_SDK_ROOT,
|
|
3662
|
-
|
|
4413
|
+
path5.join(homedir(), "Android", "Sdk")
|
|
3663
4414
|
].map((candidate) => candidate?.trim()).filter((candidate) => candidate !== void 0 && candidate.length > 0);
|
|
3664
4415
|
const sdkRoot = sdkCandidates.find((candidate) => existsSync(candidate));
|
|
3665
4416
|
return {
|
|
@@ -3670,7 +4421,7 @@ function probeAndroidToolchain(environment = process.env, requiredSdk = DEFAULT_
|
|
|
3670
4421
|
}
|
|
3671
4422
|
function runtimeFileAvailable(snapshot, relative) {
|
|
3672
4423
|
if (snapshot.runtimeRoot === void 0) return false;
|
|
3673
|
-
return snapshot.runtimeFileExists?.(relative) ?? existsSync(
|
|
4424
|
+
return snapshot.runtimeFileExists?.(relative) ?? existsSync(path5.join(snapshot.runtimeRoot, relative));
|
|
3674
4425
|
}
|
|
3675
4426
|
function androidTargetCheck(snapshot) {
|
|
3676
4427
|
if (!runtimeFileAvailable(snapshot, "scripts/package-android.mjs")) {
|
|
@@ -3967,7 +4718,7 @@ function diagnoseProject(snapshot, options = {}) {
|
|
|
3967
4718
|
}
|
|
3968
4719
|
async function collectFiles(root, relative = "", depth = 0) {
|
|
3969
4720
|
if (depth > 3) return [];
|
|
3970
|
-
const absolute =
|
|
4721
|
+
const absolute = path5.join(root, relative);
|
|
3971
4722
|
if (!existsSync(absolute)) return [];
|
|
3972
4723
|
const entries = await readdir(absolute, { withFileTypes: true });
|
|
3973
4724
|
const files = [];
|
|
@@ -3988,7 +4739,7 @@ async function readJson(file) {
|
|
|
3988
4739
|
}
|
|
3989
4740
|
async function runtimeReleaseManifestUrl(runtimeRoot, version) {
|
|
3990
4741
|
try {
|
|
3991
|
-
const module = await import(pathToFileURL(
|
|
4742
|
+
const module = await import(pathToFileURL(path5.join(runtimeRoot, "scripts", "install-prebuilt.mjs")).href);
|
|
3992
4743
|
const releaseUrl = record(module)?.releaseManifestUrl;
|
|
3993
4744
|
if (typeof releaseUrl !== "function") return void 0;
|
|
3994
4745
|
const result = releaseUrl(version);
|
|
@@ -3998,19 +4749,19 @@ async function runtimeReleaseManifestUrl(runtimeRoot, version) {
|
|
|
3998
4749
|
}
|
|
3999
4750
|
}
|
|
4000
4751
|
async function readProject(root) {
|
|
4001
|
-
const projectRoot =
|
|
4002
|
-
const packageJson = await readJson(
|
|
4003
|
-
const typeScriptConfig =
|
|
4752
|
+
const projectRoot = path5.resolve(root);
|
|
4753
|
+
const packageJson = await readJson(path5.join(projectRoot, "package.json"));
|
|
4754
|
+
const typeScriptConfig = path5.join(projectRoot, "threenative.config.ts");
|
|
4004
4755
|
const config = existsSync(typeScriptConfig) ? await readTypeScriptConfig(projectRoot) : nativeEntryCompat(record(packageJson)?.threenative);
|
|
4005
4756
|
const files = new Set(await collectFiles(projectRoot));
|
|
4006
4757
|
const installedVersions = /* @__PURE__ */ new Map();
|
|
4007
4758
|
for (const name of declaredDependencies(packageJson)) {
|
|
4008
|
-
const manifest = await readJson(
|
|
4759
|
+
const manifest = await readJson(path5.join(projectRoot, "node_modules", name, "package.json"));
|
|
4009
4760
|
const version = record(manifest)?.version;
|
|
4010
4761
|
if (typeof version === "string") installedVersions.set(name, version);
|
|
4011
4762
|
}
|
|
4012
4763
|
const runtimeRoot = installedVersions.has(RUNTIME_PACKAGE) ? (() => {
|
|
4013
|
-
const candidate =
|
|
4764
|
+
const candidate = path5.join(projectRoot, "node_modules", RUNTIME_PACKAGE);
|
|
4014
4765
|
try {
|
|
4015
4766
|
return realpathSync(candidate);
|
|
4016
4767
|
} catch {
|
|
@@ -4023,7 +4774,7 @@ async function readProject(root) {
|
|
|
4023
4774
|
const mcpServerHealth = /* @__PURE__ */ new Map();
|
|
4024
4775
|
if (SHAPE_VERIFIABLE_HOSTS.some(({ file }) => files.has(file))) {
|
|
4025
4776
|
for (const spec of MCP_SERVER_SPECS) {
|
|
4026
|
-
if (existsSync(
|
|
4777
|
+
if (existsSync(path5.resolve(projectRoot, spec.expectedArgs))) {
|
|
4027
4778
|
mcpServerHealth.set(spec.configName, probeMcpServer(projectRoot, spec));
|
|
4028
4779
|
}
|
|
4029
4780
|
}
|
|
@@ -4036,7 +4787,7 @@ async function readProject(root) {
|
|
|
4036
4787
|
packageJson,
|
|
4037
4788
|
projectRoot,
|
|
4038
4789
|
readText: (relative) => {
|
|
4039
|
-
const file =
|
|
4790
|
+
const file = path5.join(projectRoot, relative);
|
|
4040
4791
|
try {
|
|
4041
4792
|
return existsSync(file) ? readFileSync(file, "utf8") : void 0;
|
|
4042
4793
|
} catch {
|
|
@@ -4062,14 +4813,14 @@ async function readProject(root) {
|
|
|
4062
4813
|
...runtimeRoot === void 0 ? {} : {
|
|
4063
4814
|
readRuntimeText: (relative) => {
|
|
4064
4815
|
try {
|
|
4065
|
-
return readFileSync(
|
|
4816
|
+
return readFileSync(path5.join(runtimeRoot, relative), "utf8");
|
|
4066
4817
|
} catch {
|
|
4067
4818
|
return void 0;
|
|
4068
4819
|
}
|
|
4069
4820
|
},
|
|
4070
|
-
runtimeFileExists: (relative) => existsSync(
|
|
4821
|
+
runtimeFileExists: (relative) => existsSync(path5.join(runtimeRoot, relative)),
|
|
4071
4822
|
nativeHost: probeNativeHost(
|
|
4072
|
-
|
|
4823
|
+
path5.join(runtimeRoot, "prebuilt", nativeRuntimeKey(), nativeRuntimeFilename())
|
|
4073
4824
|
),
|
|
4074
4825
|
...runtimeManifestUrl === void 0 ? {} : { runtimeManifestUrl },
|
|
4075
4826
|
runtimeRoot
|