forked from 1b-agent/fieldcraft-upstream
engine: read the files commands name through fieldcraft_io::fs
file.open, geometry.open, geometry.import.mesh and reopening a model's geometry read through the io crate's file edge instead of SolidCraft's vfs, so in the browser they see the files the page holds (the same store saves write to). Natively it is the same capped regular-file read. fieldcraft-geometry drops its path-based readers (read_file, open_design_file, read_3mf_file): it works on bytes, and reading files is the io crate's job. Part of #119 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NmAttHhUZTokgPeEJia8sm
This commit is contained in:
1 parent
8f27ad225a
commit
0638f91f00
5 files changed
+16
-34
No files matched your search
@@ -2,9 +2,8 @@
|
||||
//! with SolidCraft, and hand back its bodies with persistent face names.
|
||||
//!
|
||||
//! The design is rebuilt from its authoritative inputs (sketches, features, parameters); cached
|
||||
//! display meshes in the file are never used. [`open_design`] takes bytes; [`open_design_file`]
|
||||
//! reads a path through SolidCraft's file access, which in the browser is the in-memory files the
|
||||
//! web host loaded.
|
||||
//! display meshes in the file are never used. [`open_design`] takes the file's bytes (reading
|
||||
//! files is `fieldcraft_io::fs`'s job, which in the browser holds the page's files).
|
||||
|
||||
use solidcraft_doc::{Document, Model, naming};
|
||||
use solidcraft_kernel::{KernelError, guard};
|
||||
@@ -45,11 +44,6 @@ pub fn open_design(bytes: &[u8]) -> Result<Design> {
|
||||
rebuild(&doc)
|
||||
}
|
||||
|
||||
/// Read a design file (a regular file of at most [`MAX_DESIGN_BYTES`]) and rebuild it.
|
||||
pub fn open_design_file(path: &str) -> Result<Design> {
|
||||
open_design(&crate::read_file(path, MAX_DESIGN_BYTES)?)
|
||||
}
|
||||
|
||||
/// Rebuild an in-memory document (the design half of [`open_design`]).
|
||||
pub(crate) fn rebuild(doc: &Document) -> Result<Design> {
|
||||
let model = guard("rebuild design", || {
|
||||
@@ -165,8 +159,5 @@ mod tests {
|
||||
assert!(open_design(bytes).is_err(), "{bytes:?}");
|
||||
}
|
||||
assert!(open_design(&vec![b' '; MAX_DESIGN_BYTES + 1]).is_err());
|
||||
for path in ["", "/", "/dev/zero", "/no/such/design.solidcraft"] {
|
||||
assert!(open_design_file(path).is_err(), "{path}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ pub mod sample;
|
||||
#[cfg(feature = "scripts")]
|
||||
mod script;
|
||||
|
||||
pub use design::{Design, FeatureError, MAX_DESIGN_BYTES, open_design, open_design_file};
|
||||
pub use design::{Design, FeatureError, MAX_DESIGN_BYTES, open_design};
|
||||
pub mod tagged_mesh;
|
||||
#[cfg(feature = "scripts")]
|
||||
pub use script::{MAX_SCRIPT_BYTES, script_design};
|
||||
@@ -47,14 +47,6 @@ impl From<KernelError> for Error {
|
||||
}
|
||||
}
|
||||
|
||||
/// Read a regular file of at most `max_bytes` through SolidCraft's file access (in the browser,
|
||||
/// the in-memory files the web host loaded). Opening a design or a 3MF package from these bytes
|
||||
/// ([`open_design`], [`tagged_mesh::read_3mf`]) lets the caller record a hash of exactly what it
|
||||
/// opened.
|
||||
pub fn read_file(path: &str, max_bytes: usize) -> Result<Vec<u8>> {
|
||||
solidcraft_io::vfs::read(path, max_bytes).map_err(|e| Error::Invalid(format!("cannot read `{path}`: {e}")))
|
||||
}
|
||||
|
||||
/// SolidCraft's linear modelling tolerance (mm): points closer than this are the same point.
|
||||
const LINEAR_TOLERANCE: f64 = solidcraft_geom::LINEAR_TOL;
|
||||
|
||||
|
||||
@@ -344,12 +344,6 @@ fn surface(mut o: Object, k: usize, id: u32, xf: &Xf, unit: f64) -> Result<Tagge
|
||||
Ok(TaggedSurface { name, mesh: SurfaceMesh { positions: o.positions, triangles: o.triangles, tri_face: o.tags, weld_distance: 0.0 }, faces })
|
||||
}
|
||||
|
||||
/// [`read_3mf`] of a file: a regular file of at most [`MAX_FILE_BYTES`] (SolidCraft's virtual
|
||||
/// file system, so the browser's in-memory files work too).
|
||||
pub fn read_3mf_file(path: &str) -> Result<Vec<TaggedSurface>> {
|
||||
read_3mf(&crate::read_file(path, MAX_FILE_BYTES)?)
|
||||
}
|
||||
|
||||
/// The surfaces of a 3MF package, one per build item, in millimetres.
|
||||
pub fn read_3mf(bytes: &[u8]) -> Result<Vec<TaggedSurface>> {
|
||||
if bytes.len() > MAX_FILE_BYTES {
|
||||
|
||||
Reference in new issue
Block a user