From 0d680021f95fbaa54098c67eb3bb94957eb31442 Mon Sep 17 00:00:00 2001 From: Nyle Garcia Date: Tue, 17 Nov 2026 21:38:41 -0600 Subject: [PATCH 01/12] feat(dev): experimental 3MF output for Print shell model exports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - assets::threemf: GLB triangles (stl::glb_mesh, transforms baked, Z-up) as a core-spec 3MF in metres; vertices shared by exact f32 equality, degenerate triangles left out; XML streamed into a deflated zip. - assets::print: write_meshes writes the STL and/or 3MF next to the GLB from one triangle read; ModelDone reports them as `meshes`. - three_mf in ModelOptions (not part of the cache key) and AssetExportModelRequest (serde default) in the real/mock backends and TS mirror/mock; samples regenerated. - CLI `dev export-model --3mf` (experimental), refused with --preset full. - Export dialog: "Also write a 3MF (experimental)" switch with badge, "Save as…" button, a line saying where the STL/3MF go. - zip 9 (deflate via flate2/zlib-rs only) in starorg-data. - Docs: user guide and addendum. --- Cargo.lock | 2 + app/src-tauri/src/contract/assets.rs | 3 + app/src-tauri/src/contract/mock_assets.rs | 11 +- app/src-tauri/src/contract/real/assets.rs | 15 +- app/src-tauri/src/contract/tests_assets.rs | 5 + app/src-tauri/tests/real_assets.rs | 1 + app/src/components/assets/AssetPanel.svelte | 18 ++- app/src/components/assets/ModelViewer.svelte | 2 +- app/src/lib/contract/assets.ts | 2 + app/src/lib/contract/mock-assets.ts | 5 +- app/src/lib/contract/samples.gen.json | 4 +- app/tests/assetmock.test.ts | 2 +- crates/starorg-cli/src/asset_cmds.rs | 61 ++++---- crates/starorg-cli/src/lib.rs | 4 + crates/starorg-cli/tests/dev_assets.rs | 24 ++++ crates/starorg-data/Cargo.toml | 3 + crates/starorg-data/src/assets.rs | 5 +- crates/starorg-data/src/assets/model.rs | 28 ++-- crates/starorg-data/src/assets/print.rs | 69 +++++++++ crates/starorg-data/src/assets/stl.rs | 11 +- crates/starorg-data/src/assets/tests.rs | 123 +++++++++++++++- crates/starorg-data/src/assets/threemf.rs | 136 ++++++++++++++++++ docs/plans/specs/starorg-codex-v1-addendum.md | 15 +- docs/user-guide.md | 7 +- 24 files changed, 485 insertions(+), 71 deletions(-) create mode 100644 crates/starorg-data/src/assets/print.rs create mode 100644 crates/starorg-data/src/assets/threemf.rs diff --git a/Cargo.lock b/Cargo.lock index 6997b35..ec97e97 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4823,6 +4823,7 @@ dependencies = [ "tempfile", "thiserror 2.0.21", "ww2ogg", + "zip", ] [[package]] @@ -6986,6 +6987,7 @@ checksum = "e3476fd497ac8af5b1ec7b51acab7bef380f7e8dd8e0487595bafd839417a302" dependencies = [ "constant_time_eq", "crc32fast", + "flate2", "getrandom 0.4.3", "indexmap 2.14.2", "libc", diff --git a/app/src-tauri/src/contract/assets.rs b/app/src-tauri/src/contract/assets.rs index 35b379e..7fd0ccf 100644 --- a/app/src-tauri/src/contract/assets.rs +++ b/app/src-tauri/src/contract/assets.rs @@ -185,6 +185,9 @@ pub struct AssetExportModelRequest { pub lod: u32, /// Also an STL next to the GLB. pub stl: bool, + /// Also a 3MF next to the GLB (Print shell only, like the STL). + #[serde(default)] + pub three_mf: bool, /// Export even with less free memory than the preset may need (after `needs-decision`). pub force: bool, /// Full only: the paint to wear, a [`ModelPaint::tag`] from `asset_model_paints` diff --git a/app/src-tauri/src/contract/mock_assets.rs b/app/src-tauri/src/contract/mock_assets.rs index 191108c..f95ff7e 100644 --- a/app/src-tauri/src/contract/mock_assets.rs +++ b/app/src-tauri/src/contract/mock_assets.rs @@ -21,6 +21,10 @@ pub const EXPORTS: &str = "/synthetic/exports"; pub const CACHE_DEFAULT: &str = "/synthetic/cache/assets"; pub const CACHE_OTHER: &str = "/synthetic/other-drive/asset-cache"; pub const CACHE_MAX: u64 = 2 * 1024 * 1024 * 1024; +/// The mock's STL and 3MF of a print-shell export: an AEGS_Javelin LOD 0's STL, and a 3MF a +/// quarter of it (an RSI_Skylark's 3MF was 0.25 of its STL). +pub const STL_BYTES: u64 = 183_149_634; +pub const THREE_MF_BYTES: u64 = 45_000_000; /// Mock asset state (per backend). #[derive(Debug, Default)] @@ -1002,6 +1006,7 @@ impl AssetBackend for MockBackend { preset: req.preset, lod: starorg_data::assets::model::effective_lod(lod, &self.known_lods(&req.what)), stl: req.stl, + three_mf: req.three_mf, paint: req.paint.clone(), layers: req.layers, }; @@ -1032,8 +1037,10 @@ impl AssetBackend for MockBackend { "{EXPORTS}/{}", starorg_data::assets::model::file_name(name, &o) )), - files: 1 + req.stl as u32, - bytes: bytes + if req.stl { 183_149_634 } else { 0 }, + files: 1 + req.stl as u32 + req.three_mf as u32, + bytes: bytes + + if req.stl { STL_BYTES } else { 0 } + + if req.three_mf { THREE_MF_BYTES } else { 0 }, cached: held.is_some(), failed: Vec::new(), note: None, diff --git a/app/src-tauri/src/contract/real/assets.rs b/app/src-tauri/src/contract/real/assets.rs index 3092c1a..ee3b7fb 100644 --- a/app/src-tauri/src/contract/real/assets.rs +++ b/app/src-tauri/src/contract/real/assets.rs @@ -919,6 +919,7 @@ impl AssetBackend for RealBackend { preset: req.preset, lod: model::effective_lod(asked, &self.known_lods(&key, &req.what)), stl: req.stl, + three_mf: req.three_mf, paint: req.paint.clone(), layers: req.layers, }; @@ -972,12 +973,12 @@ impl AssetBackend for RealBackend { let n = std::fs::copy(&hit, &out).map_err(io)?; let mut files = 1; let mut bytes = n; - if o.stl { + if o.stl || o.three_mf { let glb = std::fs::read(&hit).map_err(io)?; - let (_, len) = - starorg_data::assets::stl::glb_file_to_stl(&glb, &out.with_extension("stl")) - .map_err(|e| err(ErrorCode::Internal, e.message))?; - files += 1; + let (n, len) = starorg_data::assets::print::write_meshes(&glb, &out, &o) + .map_err(|e| err(ErrorCode::Internal, e.message))? + .files_bytes(); + files += n; bytes += len; } return Ok(export_result( @@ -1024,8 +1025,8 @@ impl AssetBackend for RealBackend { d.peak_rss.map(|b| b / 1_048_576).unwrap_or(0) ), ); - let files = 1 + d.stl_path.is_some() as u32; - let bytes = d.bytes + d.stl_bytes.unwrap_or(0); + let (n, len) = starorg_data::assets::print::files_bytes(&d.meshes); + let (files, bytes) = (1 + n, d.bytes + len); Ok(export_result(Some(d.path), files, bytes, false)) } diff --git a/app/src-tauri/src/contract/tests_assets.rs b/app/src-tauri/src/contract/tests_assets.rs index 06e7d5c..dfad734 100644 --- a/app/src-tauri/src/contract/tests_assets.rs +++ b/app/src-tauri/src/contract/tests_assets.rs @@ -215,6 +215,7 @@ pub(super) fn asset_samples() -> Vec<(&'static str, Value)> { preset, lod, stl, + three_mf: stl, force: false, paint: None, layers: false, @@ -451,6 +452,7 @@ fn every_asset_command_but_the_cache_refuses_while_developer_mode_is_off() { preset: ModelPreset::Full, lod: 1, stl: false, + three_mf: false, force: false, paint: None, layers: false, @@ -539,6 +541,7 @@ fn the_mock_caches_previews_sounds_and_models_and_switches_folders() { preset: ModelPreset::Full, lod: 1, stl: false, + three_mf: false, force: false, paint: None, layers: false, @@ -663,6 +666,7 @@ fn the_model_view_steps_through_lods_with_estimates_the_guard_and_the_cache() { preset: ModelPreset::PrintShell, lod: 3, stl: false, + three_mf: false, force: false, paint: None, layers: false, @@ -796,6 +800,7 @@ fn a_full_export_wears_a_paint_and_refuses_one_the_ship_lacks() { preset, lod: 1, stl: false, + three_mf: false, force: false, paint: Some(paint.into()), layers: true, diff --git a/app/src-tauri/tests/real_assets.rs b/app/src-tauri/tests/real_assets.rs index 0de825c..ee8a1b9 100644 --- a/app/src-tauri/tests/real_assets.rs +++ b/app/src-tauri/tests/real_assets.rs @@ -391,6 +391,7 @@ fn extract_and_exports_respect_dialogs_and_the_game_folder() { preset: ModelPreset::PrintShell, lod: 0, stl: false, + three_mf: false, force: false, paint: None, layers: false, diff --git a/app/src/components/assets/AssetPanel.svelte b/app/src/components/assets/AssetPanel.svelte index a1c6bf2..19241b7 100644 --- a/app/src/components/assets/AssetPanel.svelte +++ b/app/src/components/assets/AssetPanel.svelte @@ -12,7 +12,9 @@ import Download from '@lucide/svelte/icons/download'; import LoaderCircle from '@lucide/svelte/icons/loader-circle'; import ChevronDown from '@lucide/svelte/icons/chevron-down'; + import FlaskConical from '@lucide/svelte/icons/flask-conical'; import * as Dialog from '@/components/ui/dialog'; + import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import Segmented from '@/components/common/Segmented.svelte'; import SwitchRow from '@/components/common/SwitchRow.svelte'; @@ -87,6 +89,7 @@ let preset = $state('print-shell'); let lod = $state(0); let stl = $state(false); + let threeMf = $state(false); /** Full only: the paint ('' = the fitted one) and StarBreaker's layer materials. */ let paint = $state(''); let layers = $state(false); @@ -97,7 +100,10 @@ function setPreset(p: ModelPreset) { preset = p; lod = DEFAULT_LOD[p]; - if (p === 'full') stl = false; + if (p === 'full') { + stl = false; + threeMf = false; + } } // A new record forgets the last one's paints and choice. $effect(() => { @@ -132,6 +138,8 @@ const p = paints?.paints.find((x) => x.tag.toLowerCase() === e.toLowerCase()); return p ? paintLabel(p) : 'default'; }); + /** The extra files written next to the GLB: `STL/3MF`, `STL`, `3MF` or ''. */ + const meshNames = $derived(preset === 'full' ? '' : [stl && 'STL', threeMf && '3MF'].filter(Boolean).join('/')); /** Set when the backend says free memory is short: the dialog asks before going on. */ let memWarn = $state(null); async function exportModel(force = false) { @@ -140,7 +148,7 @@ exporting = true; try { const full = preset === 'full'; - const r = await assetApi.exportModel({ target: $state.snapshot(target), what: guid, name, preset, lod, stl, force, paint: full && paint ? paint : null, layers: full && layers }); + const r = await assetApi.exportModel({ target: $state.snapshot(target), what: guid, name, preset, lod, stl: !full && stl, three_mf: !full && threeMf, force, paint: full && paint ? paint : null, layers: full && layers }); if (r.cancelled) toast('info', 'Export cancelled', 'Nothing was written.'); else toast('success', `Exported ${name}${r.cached ? ' from the cache' : ''}`, [bytesText(r.bytes), r.note, r.path, r.failed.length ? `${r.failed.length} failed` : ''].filter(Boolean).join(' · ')); } catch (e) { @@ -239,6 +247,9 @@ (stl = v)} disabled={preset === 'full'} /> + (threeMf = v)} disabled={preset === 'full'}> + + {#if preset === 'full'}