pub struct BinaryStlExporter;Expand description
Exports 3MF Model structures to binary STL files.
The exporter flattens all mesh objects referenced in build items into a single STL file, applying build item transformations to vertex coordinates.
This was previously named StlExporter. If you were using StlExporter, update your
code to use BinaryStlExporter.
Implementations§
Source§impl BinaryStlExporter
impl BinaryStlExporter
Sourcepub fn write<W: Write>(model: &Model, writer: W) -> Result<()>
pub fn write<W: Write>(model: &Model, writer: W) -> Result<()>
Writes a 3MF Model to binary STL format.
§Arguments
model- The 3MF model to exportwriter- Any type implementingWriteto receive STL data
§Returns
Ok(()) on successful export.
§Errors
Returns Lib3mfError::Io if any write operation fails.
§Format Details
- Header: 80 zero bytes (standard for most STL files)
- Normals: Written as (0, 0, 0) - viewers must compute face normals
- Transformations: Build item transforms are applied to vertex coordinates
- Attribute bytes: Written as 0 (no extended attributes)
§Behavior
- Only mesh objects from
model.build.itemsare exported - Non-mesh geometries (Components, BooleanShape, etc.) are skipped
- Each build item’s transformation matrix is applied to its mesh vertices
- All triangles from all build items are combined into a single STL file
§Examples
use lib3mf_converters::stl::BinaryStlExporter;
use lib3mf_core::model::Model;
use std::fs::File;
let output = File::create("exported.stl")?;
BinaryStlExporter::write(&model, output)?;
println!("Model exported successfully");Sourcepub fn write_with_resolver<W: Write, A: ArchiveReader>(
model: &Model,
resolver: PartResolver<'_, A>,
writer: W,
) -> Result<()>
pub fn write_with_resolver<W: Write, A: ArchiveReader>( model: &Model, resolver: PartResolver<'_, A>, writer: W, ) -> Result<()>
Writes a 3MF Model to binary STL format with support for multi-part 3MF files.
This method extends write by recursively resolving component references and external
model parts using a PartResolver. This is necessary for 3MF files with the Production
Extension that reference objects from external model parts.
§Arguments
model- The root 3MF model to exportresolver- APartResolverfor loading external model parts from the 3MF archivewriter- Any type implementingWriteto receive STL data
§Returns
Ok(()) on successful export.
§Errors
Returns Lib3mfError::Io if any write operation fails.
Returns errors from the resolver if external parts cannot be loaded.
§Behavior
- Recursively resolves component hierarchies using the PartResolver
- Follows external references via component
pathattributes - Applies accumulated transformations through the component tree
- Flattens all resolved meshes into a single STL file
§Examples
use lib3mf_converters::stl::BinaryStlExporter;
use lib3mf_core::archive::ZipArchiver;
use lib3mf_core::model::resolver::PartResolver;
use std::fs::File;
let archive_file = File::open("multipart.3mf")?;
let mut archiver = ZipArchiver::new(archive_file)?;
let resolver = PartResolver::new(&mut archiver, model.clone());
let output = File::create("output.stl")?;
BinaryStlExporter::write_with_resolver(&model, resolver, output)?;Auto Trait Implementations§
impl Freeze for BinaryStlExporter
impl RefUnwindSafe for BinaryStlExporter
impl Send for BinaryStlExporter
impl Sync for BinaryStlExporter
impl Unpin for BinaryStlExporter
impl UnwindSafe for BinaryStlExporter
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more