Skip to content

armgit / forma

Public Imported from GitHub
0

A 1.2 MB pure-Rust rewrite of headless Blender built for AI agents — 3D B-rep modeling engine, CLI, and MCP server

Merge remote-tracking branch 'origin/main' into pr-99

wrong-nebula919a0e18ea41
diff --cc crates/forma-cli/src/main.rs
index 0d765c6,ea42f00..7671ecc
--- a/crates/forma-cli/src/main.rs
+++ b/crates/forma-cli/src/main.rs
@@@ -20,9 -20,10 +20,10 @@@ fn print_help()
"forma {VERSION} — pure-Rust headless 3D polyhedral modeling engine for AI agents\n\
\n\
USAGE:\n\
- forma eval [--dialect pipe|compact] [--unit m|cm|mm|um|in|ft] [--strict|--no-strict] [--no-fs] [--allow-import-dir DIR] [--json] [--scene] [--out path.(glb|obj|stl|3mf|step|blend)] [--render preview.png] [--size 512] [--view quad|front|back|right|left|top|iso] [--draw blueprint.svg] [file|-]\n\
- forma eval [--dialect pipe|compact] [--unit m|cm|mm|um|in|ft] [--strict|--no-strict] [--critique] [--raw-box] [--json] [--scene] [--out path.(glb|obj|stl|3mf|step|blend)] [--render preview.png] [--size 512] [--view quad|front|back|right|left|top|iso] [--draw blueprint.svg] [file|-]\n\
- forma lint [--dialect pipe|compact] [--unit m|cm|mm|um|in|ft] [--strict|--no-strict] [--raw-box] [--json] [file|-]\n\
- forma render [--scene] [--size 512] [--view quad|front|back|right|left|top|iso] --out preview.png [file|-]\n\
- forma draw [--scene] --out blueprint.svg [file|-]\n\
++ forma eval [--dialect pipe|compact] [--unit m|cm|mm|um|in|ft] [--strict|--no-strict] [--no-fs] [--allow-import-dir DIR] [--critique] [--raw-box] [--json] [--scene] [--out path.(glb|obj|stl|3mf|step|blend)] [--render preview.png] [--size 512] [--view quad|front|back|right|left|top|iso] [--draw blueprint.svg] [file|-]\n\
++ forma lint [--dialect pipe|compact] [--unit m|cm|mm|um|in|ft] [--strict|--no-strict] [--no-fs] [--allow-import-dir DIR] [--raw-box] [--json] [file|-]\n\
+ forma render [--scene] [--no-fs] [--allow-import-dir DIR] [--size 512] [--view quad|front|back|right|left|top|iso] --out preview.png [file|-]\n\
+ forma draw [--scene] [--no-fs] [--allow-import-dir DIR] --out blueprint.svg [file|-]\n\
forma spec [--dialect pipe|compact] [--topic TOPIC] [--gbnf]\n\
forma version | --version | -V\n\
forma --help\n\
@@@ -127,8 -129,8 +129,10 @@@ fn main()
let mut dialect = Dialect::Pipe;
let mut unit: Option<Unit> = None;
let mut strict = true;
+ let mut allow_fs_import = true;
+ let mut fs_import_root: Option<PathBuf> = None;
+ let mut critique = is_lint_cmd;
+ let mut include_raw_box = false;
let mut as_json = false;
let mut export_scene = false;
let mut out_path: Option<PathBuf> = None;
@@@ -220,18 -222,14 +224,26 @@@
strict = false;
i += 1;
}
+ "--no-fs" => {
+ allow_fs_import = false;
+ i += 1;
+ }
+ "--allow-import-dir" | "--fs-root" => {
+ if i + 1 >= args.len() {
+ eprintln!("ERR: {} requires a directory path", args[i]);
+ process::exit(2);
+ }
+ fs_import_root = Some(PathBuf::from(&args[i + 1]));
+ i += 2;
+ }
+ "--critique" => {
+ critique = true;
+ i += 1;
+ }
+ "--raw-box" => {
+ include_raw_box = true;
+ i += 1;
+ }
"--json" => {
as_json = true;
i += 1;
diff --cc crates/forma-core/src/scene.rs
index e9136c1,9fd2d21..f7fe7dc
--- a/crates/forma-core/src/scene.rs
+++ b/crates/forma-core/src/scene.rs
@@@ -203,26 -260,19 +262,38 @@@ impl Scene
return Err(format!(
"filesystem import disabled in sandboxed mode; upload '{path_or_key}' in request assets"
));
- }
- let target_path = Path::new(path_or_key);
- if let Some(ref root) = self.fs_import_root {
- let canon_root = std::fs::canonicalize(root).map_err(|e| {
- format!(
- "invalid filesystem import root '{}': {e}",
- root.display()
- )
- })?;
- let canon_file = std::fs::canonicalize(target_path)
- .map_err(|e| format!("cannot resolve import path '{path_or_key}': {e}"))?;
- if !canon_file.starts_with(&canon_root) {
- return Err(format!(
- "filesystem import path '{path_or_key}' escapes allowed directory '{}'",
- root.display()
- ));
+ } else {
- crate::import::import_mesh_with_opts(Path::new(path_or_key), yup)?
++ let target_path = Path::new(path_or_key);
++ if let Some(ref root) = self.fs_import_root {
++ let canon_root = std::fs::canonicalize(root).map_err(|e| {
++ format!(
++ "invalid filesystem import root '{}': {e}",
++ root.display()
++ )
++ })?;
++ let canon_file = std::fs::canonicalize(target_path)
++ .map_err(|e| format!("cannot resolve import path '{path_or_key}': {e}"))?;
++ if !canon_file.starts_with(&canon_root) {
++ return Err(format!(
++ "filesystem import path '{path_or_key}' escapes allowed directory '{}'",
++ root.display()
++ ));
++ }
++ crate::import::import_mesh_with_opts(&canon_file, yup)?
++ } else {
++ crate::import::import_mesh_with_opts(target_path, yup)?
+ }
- return crate::import::import_mesh_with_opts(&canon_file, yup);
+ };
+ // glTF positions are always metres (and `.glb` export scales to
+ // metres), so convert them back to the scene unit. `.obj`/`.stl`
+ // carry no unit and are read as model units, matching their export.
+ let is_glb = ext.map_or(self.assets.contains_key(path_or_key), |e| e.eq_ignore_ascii_case("glb"));
+ let k = self.unit.meters_per_unit();
+ if is_glb && k != 1.0 {
+ let s = 1.0 / k;
+ mesh.scale(Vec3::new(s, s, s));
}
- crate::import::import_mesh_with_opts(target_path, yup)
+ Ok(mesh)
}
/// Load a mesh from attached in-memory assets or (if `allow_fs_import`) from disk.