ricosjp / truck

Truck is a Rust CAD Kernel.
Apache License 2.0
1.02k stars 53 forks source link

How to export sphere to stp file #33

Open happydpc opened 2 years ago

happydpc commented 2 years ago

According to the code, there are two ways to create a sphere:

let uhcircle = NURBSCurve::new(BSplineCurve::new(knot_vec, control_points));
    let sphere = RevolutedCurve::by_revolution(
        uhcircle, Point3::origin(), Vector3::unit_x(),
    );
let sphere = Sphere::new(center, radius);

but they all don't impl the ModelShape trait, how to export sphere to step file ?

ytanimura commented 2 years ago

Sorry for the late reply, STEP must always be spit out with the topology included, not just the geometry. I have made a sample code, but there seems to be an internal bug going on, so please wait a little longer.

happydpc commented 2 years ago

Good job on this work, Thanks.

ytanimura commented 2 years ago

I am very sorry for the delay. One can output the sphere step by the following code and it displays properly in FreeCAD for example.

use std::f64::consts::PI;
use truck_modeling::*;
use truck_stepio::out;

fn main() {
    let vertex = builder::vertex(Point3::new(0.0, 0.0, 1.0));
    let wire = builder::rsweep(&vertex, Point3::origin(), Vector3::unit_y(), Rad(PI));
    let shell = builder::rsweep(&wire, Point3::origin(), Vector3::unit_z(), Rad(PI * 2.0));
    let step_string =
        out::CompleteStepDisplay::new(out::StepModel::new(&shell.compress()), Default::default())
            .to_string();
    std::fs::write("output.stp", &step_string).unwrap();
}

However, in truck it is a bit abuse and does not close spherical as topological data. We would like to fix this, but we need to take care of a problem at the same time before we can officially support it.