Skip to main content

Module scene

Module scene 

Source
Expand description

Scene — the convenience navigation layer over the raw StepModel.

The generated model is faithful but tedious to walk by hand (arenas and reference enums); model.scene() wraps it in lightweight Copy handles where forward and backward moves are plain handle.method() calls. The backward index (RefGraph) is built lazily on the first backward move — a forward-only import never pays for it.

The core is enumeration plus scoped navigation. Model-level all_<type>() iterators (all_solids, all_products, …) enumerate one type across the whole file; each handle then navigates its own neighbourhood (solid.faces(), face.surface(), occurrence.definition(), …). Coverage spans b-rep geometry (geometry), the product/assembly tree and PLM metadata (product), display meshes (mesh), PMI (pmi), presentation (presentation), units (units), and the NURBS views (nurbs).

Kinds outside the handled set come back as *Kind::Other; what a handle cannot resolve into the shape it exposes lands in Scene::warnings, never silently skipped.

Anything beyond the handles is reached through the raw model via Scene::model.

let source = std::fs::read("part.step").unwrap();
let (model, _report) = step_io::read(&source).unwrap();
let scene = model.scene();

// Assembly: definitions and their placed occurrences, top-down. Keep the
// placement on the instance — do not bake it into shared geometry.
for def in scene.root_definitions() {
    for occ in def.occurrences() {
        let _child = occ.definition(); // recurse from here
        let _matrix = occ.transform().and_then(|t| t.matrix());
    }
}

// Geometry: solid → face → surface, bound → edge → curve → vertex.
// Presentation (colour / layer / visibility) rides on the same handles.
for solid in scene.all_solids() {
    let _colour = solid.color();
    for face in solid.faces() {
        let _surface = face.surface().kind(); // analytic form; `Other` beyond the set
        let _patch = face.to_nurbs(); // the NURBS view, on demand
        for bound in face.bounds() {
            for (edge, _forward) in bound.oriented_edges() {
                let _curve = edge.curve().kind();
                let _ends = (edge.start(), edge.end());
            }
        }
    }
}

// Display meshes, linked back to the b-rep solid they render.
for group in scene.all_mesh_groups() {
    let _brep = group.solid();
    for mesh in group.meshes() {
        let (_pts, _tris) = (mesh.points(), mesh.triangles());
    }
}

// PMI: dimensions, tolerances, and the annotated features.
for dim in scene.dimensions() {
    let (_kind, _value) = (dim.kind(), dim.value());
}
for tol in scene.tolerances() {
    let (_kind, _datums) = (tol.kind(), tol.datums());
}
for feat in scene.features() {
    let _geometry = feat.geometry(); // the faces/edges it annotates
}

// Product metadata: versions, approvals, documents, people.
for product in scene.all_products() {
    let _versions = product.versions();
    let _approvals = product.approvals();
    let _documents = product.documents();
    let _people = product.contributors();
}

// Coordinates come in the file's units — scaling is the consumer's job.
let _to_si = scene.units().length.map(|u| u.to_si);
for w in scene.warnings() {
    eprintln!("step-io: {w}");
}

Re-exports§

pub use mesh::Mesh;
pub use mesh::MeshGroup;
pub use mesh::MeshNormals;
pub use nurbs::NurbsCurve;
pub use nurbs::NurbsSurface;
pub use pmi::Datum;
pub use pmi::Dimension;
pub use pmi::DimensionKind;
pub use pmi::Feature;
pub use pmi::FeatureGeometry;
pub use pmi::FeatureKind;
pub use pmi::Tolerance;
pub use pmi::ToleranceKind;
pub use presentation::Rgb;
pub use product::Approval;
pub use product::ApprovalDate;
pub use product::Approver;
pub use product::Contributor;
pub use product::Document;
pub use product::MappedInstance;
pub use product::Occurrence;
pub use product::Person;
pub use product::Placement;
pub use product::Scope;
pub use product::SecurityClassification;
pub use product::Target;
pub use product::Transform;
pub use product::Version;
pub use units::Unit;
pub use units::Units;

Modules§

geometry
Read-only b-rep geometry navigation handles over a Scene.
mesh
Read-only handles over tessellated (display-mesh) geometry.
nurbs
Opt-in NURBS (rational B-spline) views over analytic STEP curves.
pmi
PMI — the product and manufacturing information annotating a shape.
presentation
Presentation — the colour, transparency, layer, and visibility of a shape.
product
Read-only product / assembly navigation handles over a Scene.
units
The model’s units — the length and angle units and precision a kernel needs to interpret coordinates.

Structs§

Scene
The read API entry point: a StepModel paired with its (lazy) RefGraph and a log of navigation warnings.