pub struct OcctKernel { /* private fields */ }Expand description
The OCCT CAD kernel, backed by a sandboxed WASM module.
Create an instance with OcctKernel::new(), then call methods to
create and manipulate shapes. All shapes live in an arena inside the
WASM module and are referenced by ShapeHandle.
§Example
use occt_wasm::{OcctKernel, ShapeHandle};
let mut kernel = OcctKernel::new().unwrap();
let box_shape = kernel.make_box(10.0, 20.0, 30.0).unwrap();
let volume = kernel.get_volume(box_shape).unwrap();
assert!((volume - 6000.0).abs() < 1.0);Implementations§
Source§impl OcctKernel
impl OcctKernel
Sourcepub fn new() -> OcctResult<Self>
pub fn new() -> OcctResult<Self>
Create a new OCCT kernel instance.
Decompresses the embedded WASM binary, compiles it with wasmtime,
and initializes the OCCT runtime. This takes ~100-500ms depending
on the platform.
Examples found in repository?
examples/cli.rs (line 42)
41fn run(step_out: Option<&std::path::Path>) -> Result<(), OcctError> {
42 let mut kernel = OcctKernel::new()?;
43
44 // --- Create shapes ---
45 let box_shape = kernel.make_box(30.0, 20.0, 15.0)?;
46 let cyl = kernel.make_cylinder(6.0, 25.0)?;
47 let sphere = kernel.make_sphere(4.0)?;
48 let moved_sphere = kernel.translate(sphere, 15.0, 10.0, 15.0)?;
49
50 println!("Created: box 30x20x15, cylinder r=6 h=25, sphere r=4");
51
52 // --- Boolean operations ---
53 let with_hole = kernel.cut(box_shape, cyl)?;
54 let final_shape = kernel.fuse(with_hole, moved_sphere)?;
55
56 // --- Measurements ---
57 let vol = kernel.get_volume(final_shape)?;
58 let area = kernel.get_surface_area(final_shape)?;
59 let bbox = kernel.get_bounding_box(final_shape, true)?;
60
61 println!("\nResult:");
62 println!(" Volume: {vol:.2} mm^3");
63 println!(" Surface area: {area:.2} mm^2");
64 println!(
65 " Bounding box: [{:.1}, {:.1}, {:.1}] to [{:.1}, {:.1}, {:.1}]",
66 bbox.min.x, bbox.min.y, bbox.min.z, bbox.max.x, bbox.max.y, bbox.max.z
67 );
68
69 // --- Topology counts ---
70 let faces = kernel.get_sub_shapes(final_shape, "Face")?;
71 let edges = kernel.get_sub_shapes(final_shape, "Edge")?;
72 let verts = kernel.get_sub_shapes(final_shape, "Vertex")?;
73 println!(
74 " Topology: {} faces, {} edges, {} vertices",
75 faces.len(),
76 edges.len(),
77 verts.len()
78 );
79
80 // --- Tessellate (renderer-ready mesh) ---
81 let mesh = kernel.tessellate(final_shape, 0.1, 0.5)?;
82 println!(
83 " Mesh: {} vertices, {} triangles",
84 mesh.positions.len() / 3,
85 mesh.indices.len() / 3
86 );
87
88 // --- STEP export ---
89 let step_data = kernel.export_step(final_shape)?;
90 if let Some(path) = step_out {
91 fs::write(path, &step_data).map_err(|e| OcctError::Operation {
92 operation: "export_step_write".to_owned(),
93 message: format!("write {}: {e}", path.display()),
94 })?;
95 println!("\nSTEP exported to: {}", path.display());
96 } else {
97 println!("\nTip: pass --step output.step to export the result");
98 }
99
100 // --- STEP round-trip ---
101 let reimported = kernel.import_step(&step_data)?;
102 let reimported_vol = kernel.get_volume(reimported)?;
103 println!(
104 " Round-trip: export -> import, volume delta = {:.6}",
105 (vol - reimported_vol).abs()
106 );
107
108 Ok(())
109}Source§impl OcctKernel
Generated kernel methods.
impl OcctKernel
Generated kernel methods.
All facade methods wrapped as safe Rust functions.
Sourcepub fn make_box(&mut self, dx: f64, dy: f64, dz: f64) -> OcctResult<ShapeHandle>
pub fn make_box(&mut self, dx: f64, dy: f64, dz: f64) -> OcctResult<ShapeHandle>
Examples found in repository?
examples/cli.rs (line 45)
41fn run(step_out: Option<&std::path::Path>) -> Result<(), OcctError> {
42 let mut kernel = OcctKernel::new()?;
43
44 // --- Create shapes ---
45 let box_shape = kernel.make_box(30.0, 20.0, 15.0)?;
46 let cyl = kernel.make_cylinder(6.0, 25.0)?;
47 let sphere = kernel.make_sphere(4.0)?;
48 let moved_sphere = kernel.translate(sphere, 15.0, 10.0, 15.0)?;
49
50 println!("Created: box 30x20x15, cylinder r=6 h=25, sphere r=4");
51
52 // --- Boolean operations ---
53 let with_hole = kernel.cut(box_shape, cyl)?;
54 let final_shape = kernel.fuse(with_hole, moved_sphere)?;
55
56 // --- Measurements ---
57 let vol = kernel.get_volume(final_shape)?;
58 let area = kernel.get_surface_area(final_shape)?;
59 let bbox = kernel.get_bounding_box(final_shape, true)?;
60
61 println!("\nResult:");
62 println!(" Volume: {vol:.2} mm^3");
63 println!(" Surface area: {area:.2} mm^2");
64 println!(
65 " Bounding box: [{:.1}, {:.1}, {:.1}] to [{:.1}, {:.1}, {:.1}]",
66 bbox.min.x, bbox.min.y, bbox.min.z, bbox.max.x, bbox.max.y, bbox.max.z
67 );
68
69 // --- Topology counts ---
70 let faces = kernel.get_sub_shapes(final_shape, "Face")?;
71 let edges = kernel.get_sub_shapes(final_shape, "Edge")?;
72 let verts = kernel.get_sub_shapes(final_shape, "Vertex")?;
73 println!(
74 " Topology: {} faces, {} edges, {} vertices",
75 faces.len(),
76 edges.len(),
77 verts.len()
78 );
79
80 // --- Tessellate (renderer-ready mesh) ---
81 let mesh = kernel.tessellate(final_shape, 0.1, 0.5)?;
82 println!(
83 " Mesh: {} vertices, {} triangles",
84 mesh.positions.len() / 3,
85 mesh.indices.len() / 3
86 );
87
88 // --- STEP export ---
89 let step_data = kernel.export_step(final_shape)?;
90 if let Some(path) = step_out {
91 fs::write(path, &step_data).map_err(|e| OcctError::Operation {
92 operation: "export_step_write".to_owned(),
93 message: format!("write {}: {e}", path.display()),
94 })?;
95 println!("\nSTEP exported to: {}", path.display());
96 } else {
97 println!("\nTip: pass --step output.step to export the result");
98 }
99
100 // --- STEP round-trip ---
101 let reimported = kernel.import_step(&step_data)?;
102 let reimported_vol = kernel.get_volume(reimported)?;
103 println!(
104 " Round-trip: export -> import, volume delta = {:.6}",
105 (vol - reimported_vol).abs()
106 );
107
108 Ok(())
109}pub fn make_box_from_corners( &mut self, x1: f64, y1: f64, z1: f64, x2: f64, y2: f64, z2: f64, ) -> OcctResult<ShapeHandle>
Sourcepub fn make_cylinder(
&mut self,
radius: f64,
height: f64,
) -> OcctResult<ShapeHandle>
pub fn make_cylinder( &mut self, radius: f64, height: f64, ) -> OcctResult<ShapeHandle>
Examples found in repository?
examples/cli.rs (line 46)
41fn run(step_out: Option<&std::path::Path>) -> Result<(), OcctError> {
42 let mut kernel = OcctKernel::new()?;
43
44 // --- Create shapes ---
45 let box_shape = kernel.make_box(30.0, 20.0, 15.0)?;
46 let cyl = kernel.make_cylinder(6.0, 25.0)?;
47 let sphere = kernel.make_sphere(4.0)?;
48 let moved_sphere = kernel.translate(sphere, 15.0, 10.0, 15.0)?;
49
50 println!("Created: box 30x20x15, cylinder r=6 h=25, sphere r=4");
51
52 // --- Boolean operations ---
53 let with_hole = kernel.cut(box_shape, cyl)?;
54 let final_shape = kernel.fuse(with_hole, moved_sphere)?;
55
56 // --- Measurements ---
57 let vol = kernel.get_volume(final_shape)?;
58 let area = kernel.get_surface_area(final_shape)?;
59 let bbox = kernel.get_bounding_box(final_shape, true)?;
60
61 println!("\nResult:");
62 println!(" Volume: {vol:.2} mm^3");
63 println!(" Surface area: {area:.2} mm^2");
64 println!(
65 " Bounding box: [{:.1}, {:.1}, {:.1}] to [{:.1}, {:.1}, {:.1}]",
66 bbox.min.x, bbox.min.y, bbox.min.z, bbox.max.x, bbox.max.y, bbox.max.z
67 );
68
69 // --- Topology counts ---
70 let faces = kernel.get_sub_shapes(final_shape, "Face")?;
71 let edges = kernel.get_sub_shapes(final_shape, "Edge")?;
72 let verts = kernel.get_sub_shapes(final_shape, "Vertex")?;
73 println!(
74 " Topology: {} faces, {} edges, {} vertices",
75 faces.len(),
76 edges.len(),
77 verts.len()
78 );
79
80 // --- Tessellate (renderer-ready mesh) ---
81 let mesh = kernel.tessellate(final_shape, 0.1, 0.5)?;
82 println!(
83 " Mesh: {} vertices, {} triangles",
84 mesh.positions.len() / 3,
85 mesh.indices.len() / 3
86 );
87
88 // --- STEP export ---
89 let step_data = kernel.export_step(final_shape)?;
90 if let Some(path) = step_out {
91 fs::write(path, &step_data).map_err(|e| OcctError::Operation {
92 operation: "export_step_write".to_owned(),
93 message: format!("write {}: {e}", path.display()),
94 })?;
95 println!("\nSTEP exported to: {}", path.display());
96 } else {
97 println!("\nTip: pass --step output.step to export the result");
98 }
99
100 // --- STEP round-trip ---
101 let reimported = kernel.import_step(&step_data)?;
102 let reimported_vol = kernel.get_volume(reimported)?;
103 println!(
104 " Round-trip: export -> import, volume delta = {:.6}",
105 (vol - reimported_vol).abs()
106 );
107
108 Ok(())
109}Sourcepub fn make_sphere(&mut self, radius: f64) -> OcctResult<ShapeHandle>
pub fn make_sphere(&mut self, radius: f64) -> OcctResult<ShapeHandle>
Examples found in repository?
examples/cli.rs (line 47)
41fn run(step_out: Option<&std::path::Path>) -> Result<(), OcctError> {
42 let mut kernel = OcctKernel::new()?;
43
44 // --- Create shapes ---
45 let box_shape = kernel.make_box(30.0, 20.0, 15.0)?;
46 let cyl = kernel.make_cylinder(6.0, 25.0)?;
47 let sphere = kernel.make_sphere(4.0)?;
48 let moved_sphere = kernel.translate(sphere, 15.0, 10.0, 15.0)?;
49
50 println!("Created: box 30x20x15, cylinder r=6 h=25, sphere r=4");
51
52 // --- Boolean operations ---
53 let with_hole = kernel.cut(box_shape, cyl)?;
54 let final_shape = kernel.fuse(with_hole, moved_sphere)?;
55
56 // --- Measurements ---
57 let vol = kernel.get_volume(final_shape)?;
58 let area = kernel.get_surface_area(final_shape)?;
59 let bbox = kernel.get_bounding_box(final_shape, true)?;
60
61 println!("\nResult:");
62 println!(" Volume: {vol:.2} mm^3");
63 println!(" Surface area: {area:.2} mm^2");
64 println!(
65 " Bounding box: [{:.1}, {:.1}, {:.1}] to [{:.1}, {:.1}, {:.1}]",
66 bbox.min.x, bbox.min.y, bbox.min.z, bbox.max.x, bbox.max.y, bbox.max.z
67 );
68
69 // --- Topology counts ---
70 let faces = kernel.get_sub_shapes(final_shape, "Face")?;
71 let edges = kernel.get_sub_shapes(final_shape, "Edge")?;
72 let verts = kernel.get_sub_shapes(final_shape, "Vertex")?;
73 println!(
74 " Topology: {} faces, {} edges, {} vertices",
75 faces.len(),
76 edges.len(),
77 verts.len()
78 );
79
80 // --- Tessellate (renderer-ready mesh) ---
81 let mesh = kernel.tessellate(final_shape, 0.1, 0.5)?;
82 println!(
83 " Mesh: {} vertices, {} triangles",
84 mesh.positions.len() / 3,
85 mesh.indices.len() / 3
86 );
87
88 // --- STEP export ---
89 let step_data = kernel.export_step(final_shape)?;
90 if let Some(path) = step_out {
91 fs::write(path, &step_data).map_err(|e| OcctError::Operation {
92 operation: "export_step_write".to_owned(),
93 message: format!("write {}: {e}", path.display()),
94 })?;
95 println!("\nSTEP exported to: {}", path.display());
96 } else {
97 println!("\nTip: pass --step output.step to export the result");
98 }
99
100 // --- STEP round-trip ---
101 let reimported = kernel.import_step(&step_data)?;
102 let reimported_vol = kernel.get_volume(reimported)?;
103 println!(
104 " Round-trip: export -> import, volume delta = {:.6}",
105 (vol - reimported_vol).abs()
106 );
107
108 Ok(())
109}pub fn make_cone( &mut self, r1: f64, r2: f64, height: f64, ) -> OcctResult<ShapeHandle>
pub fn make_torus( &mut self, major_radius: f64, minor_radius: f64, ) -> OcctResult<ShapeHandle>
pub fn make_ellipsoid( &mut self, rx: f64, ry: f64, rz: f64, ) -> OcctResult<ShapeHandle>
pub fn make_rectangle( &mut self, width: f64, height: f64, ) -> OcctResult<ShapeHandle>
Sourcepub fn fuse(
&mut self,
a: ShapeHandle,
b: ShapeHandle,
) -> OcctResult<ShapeHandle>
pub fn fuse( &mut self, a: ShapeHandle, b: ShapeHandle, ) -> OcctResult<ShapeHandle>
Examples found in repository?
examples/cli.rs (line 54)
41fn run(step_out: Option<&std::path::Path>) -> Result<(), OcctError> {
42 let mut kernel = OcctKernel::new()?;
43
44 // --- Create shapes ---
45 let box_shape = kernel.make_box(30.0, 20.0, 15.0)?;
46 let cyl = kernel.make_cylinder(6.0, 25.0)?;
47 let sphere = kernel.make_sphere(4.0)?;
48 let moved_sphere = kernel.translate(sphere, 15.0, 10.0, 15.0)?;
49
50 println!("Created: box 30x20x15, cylinder r=6 h=25, sphere r=4");
51
52 // --- Boolean operations ---
53 let with_hole = kernel.cut(box_shape, cyl)?;
54 let final_shape = kernel.fuse(with_hole, moved_sphere)?;
55
56 // --- Measurements ---
57 let vol = kernel.get_volume(final_shape)?;
58 let area = kernel.get_surface_area(final_shape)?;
59 let bbox = kernel.get_bounding_box(final_shape, true)?;
60
61 println!("\nResult:");
62 println!(" Volume: {vol:.2} mm^3");
63 println!(" Surface area: {area:.2} mm^2");
64 println!(
65 " Bounding box: [{:.1}, {:.1}, {:.1}] to [{:.1}, {:.1}, {:.1}]",
66 bbox.min.x, bbox.min.y, bbox.min.z, bbox.max.x, bbox.max.y, bbox.max.z
67 );
68
69 // --- Topology counts ---
70 let faces = kernel.get_sub_shapes(final_shape, "Face")?;
71 let edges = kernel.get_sub_shapes(final_shape, "Edge")?;
72 let verts = kernel.get_sub_shapes(final_shape, "Vertex")?;
73 println!(
74 " Topology: {} faces, {} edges, {} vertices",
75 faces.len(),
76 edges.len(),
77 verts.len()
78 );
79
80 // --- Tessellate (renderer-ready mesh) ---
81 let mesh = kernel.tessellate(final_shape, 0.1, 0.5)?;
82 println!(
83 " Mesh: {} vertices, {} triangles",
84 mesh.positions.len() / 3,
85 mesh.indices.len() / 3
86 );
87
88 // --- STEP export ---
89 let step_data = kernel.export_step(final_shape)?;
90 if let Some(path) = step_out {
91 fs::write(path, &step_data).map_err(|e| OcctError::Operation {
92 operation: "export_step_write".to_owned(),
93 message: format!("write {}: {e}", path.display()),
94 })?;
95 println!("\nSTEP exported to: {}", path.display());
96 } else {
97 println!("\nTip: pass --step output.step to export the result");
98 }
99
100 // --- STEP round-trip ---
101 let reimported = kernel.import_step(&step_data)?;
102 let reimported_vol = kernel.get_volume(reimported)?;
103 println!(
104 " Round-trip: export -> import, volume delta = {:.6}",
105 (vol - reimported_vol).abs()
106 );
107
108 Ok(())
109}Sourcepub fn cut(&mut self, a: ShapeHandle, b: ShapeHandle) -> OcctResult<ShapeHandle>
pub fn cut(&mut self, a: ShapeHandle, b: ShapeHandle) -> OcctResult<ShapeHandle>
Examples found in repository?
examples/cli.rs (line 53)
41fn run(step_out: Option<&std::path::Path>) -> Result<(), OcctError> {
42 let mut kernel = OcctKernel::new()?;
43
44 // --- Create shapes ---
45 let box_shape = kernel.make_box(30.0, 20.0, 15.0)?;
46 let cyl = kernel.make_cylinder(6.0, 25.0)?;
47 let sphere = kernel.make_sphere(4.0)?;
48 let moved_sphere = kernel.translate(sphere, 15.0, 10.0, 15.0)?;
49
50 println!("Created: box 30x20x15, cylinder r=6 h=25, sphere r=4");
51
52 // --- Boolean operations ---
53 let with_hole = kernel.cut(box_shape, cyl)?;
54 let final_shape = kernel.fuse(with_hole, moved_sphere)?;
55
56 // --- Measurements ---
57 let vol = kernel.get_volume(final_shape)?;
58 let area = kernel.get_surface_area(final_shape)?;
59 let bbox = kernel.get_bounding_box(final_shape, true)?;
60
61 println!("\nResult:");
62 println!(" Volume: {vol:.2} mm^3");
63 println!(" Surface area: {area:.2} mm^2");
64 println!(
65 " Bounding box: [{:.1}, {:.1}, {:.1}] to [{:.1}, {:.1}, {:.1}]",
66 bbox.min.x, bbox.min.y, bbox.min.z, bbox.max.x, bbox.max.y, bbox.max.z
67 );
68
69 // --- Topology counts ---
70 let faces = kernel.get_sub_shapes(final_shape, "Face")?;
71 let edges = kernel.get_sub_shapes(final_shape, "Edge")?;
72 let verts = kernel.get_sub_shapes(final_shape, "Vertex")?;
73 println!(
74 " Topology: {} faces, {} edges, {} vertices",
75 faces.len(),
76 edges.len(),
77 verts.len()
78 );
79
80 // --- Tessellate (renderer-ready mesh) ---
81 let mesh = kernel.tessellate(final_shape, 0.1, 0.5)?;
82 println!(
83 " Mesh: {} vertices, {} triangles",
84 mesh.positions.len() / 3,
85 mesh.indices.len() / 3
86 );
87
88 // --- STEP export ---
89 let step_data = kernel.export_step(final_shape)?;
90 if let Some(path) = step_out {
91 fs::write(path, &step_data).map_err(|e| OcctError::Operation {
92 operation: "export_step_write".to_owned(),
93 message: format!("write {}: {e}", path.display()),
94 })?;
95 println!("\nSTEP exported to: {}", path.display());
96 } else {
97 println!("\nTip: pass --step output.step to export the result");
98 }
99
100 // --- STEP round-trip ---
101 let reimported = kernel.import_step(&step_data)?;
102 let reimported_vol = kernel.get_volume(reimported)?;
103 println!(
104 " Round-trip: export -> import, volume delta = {:.6}",
105 (vol - reimported_vol).abs()
106 );
107
108 Ok(())
109}pub fn common( &mut self, a: ShapeHandle, b: ShapeHandle, ) -> OcctResult<ShapeHandle>
pub fn section( &mut self, a: ShapeHandle, b: ShapeHandle, ) -> OcctResult<ShapeHandle>
pub fn intersect( &mut self, a: ShapeHandle, b: ShapeHandle, ) -> OcctResult<ShapeHandle>
pub fn fuse_all(&mut self, shape_ids: &[ShapeHandle]) -> OcctResult<ShapeHandle>
pub fn cut_all( &mut self, shape_id: ShapeHandle, tool_ids: &[ShapeHandle], ) -> OcctResult<ShapeHandle>
pub fn boolean_pipeline( &mut self, base_id: ShapeHandle, op_codes: &[i32], tool_ids: &[ShapeHandle], ) -> OcctResult<ShapeHandle>
pub fn split( &mut self, shape_id: ShapeHandle, tool_ids: &[ShapeHandle], ) -> OcctResult<ShapeHandle>
pub fn extrude( &mut self, shape_id: ShapeHandle, dx: f64, dy: f64, dz: f64, ) -> OcctResult<ShapeHandle>
pub fn revolve( &mut self, shape_id: ShapeHandle, px: f64, py: f64, pz: f64, dx: f64, dy: f64, dz: f64, angle_rad: f64, ) -> OcctResult<ShapeHandle>
pub fn fillet( &mut self, solid_id: ShapeHandle, edge_ids: &[ShapeHandle], radius: f64, ) -> OcctResult<ShapeHandle>
pub fn chamfer( &mut self, solid_id: ShapeHandle, edge_ids: &[ShapeHandle], distance: f64, ) -> OcctResult<ShapeHandle>
pub fn chamfer_dist_angle( &mut self, solid_id: ShapeHandle, edge_ids: &[ShapeHandle], distance: f64, angle_deg: f64, ) -> OcctResult<ShapeHandle>
pub fn shell( &mut self, solid_id: ShapeHandle, face_ids: &[ShapeHandle], thickness: f64, tolerance: f64, ) -> OcctResult<ShapeHandle>
pub fn offset( &mut self, solid_id: ShapeHandle, distance: f64, tolerance: f64, ) -> OcctResult<ShapeHandle>
pub fn draft( &mut self, shape_id: ShapeHandle, face_id: ShapeHandle, angle_rad: f64, dx: f64, dy: f64, dz: f64, ) -> OcctResult<ShapeHandle>
pub fn thicken( &mut self, shape_id: ShapeHandle, thickness: f64, tolerance: f64, ) -> OcctResult<ShapeHandle>
pub fn defeature( &mut self, shape_id: ShapeHandle, face_ids: &[ShapeHandle], tolerance: f64, ) -> OcctResult<ShapeHandle>
pub fn reverse_shape(&mut self, id: ShapeHandle) -> OcctResult<ShapeHandle>
pub fn simplify(&mut self, id: ShapeHandle) -> OcctResult<ShapeHandle>
pub fn fillet_variable( &mut self, solid_id: ShapeHandle, edge_id: ShapeHandle, start_radius: f64, end_radius: f64, ) -> OcctResult<ShapeHandle>
pub fn fillet_batch( &mut self, solid_ids: &[ShapeHandle], edge_counts: &[i32], flat_edge_ids: &[ShapeHandle], radii: &[f64], ) -> OcctResult<Vec<u32>>
pub fn offset_wire2_d( &mut self, wire_id: ShapeHandle, offset: f64, join_type: i32, ) -> OcctResult<ShapeHandle>
Sourcepub fn translate(
&mut self,
id: ShapeHandle,
dx: f64,
dy: f64,
dz: f64,
) -> OcctResult<ShapeHandle>
pub fn translate( &mut self, id: ShapeHandle, dx: f64, dy: f64, dz: f64, ) -> OcctResult<ShapeHandle>
Examples found in repository?
examples/cli.rs (line 48)
41fn run(step_out: Option<&std::path::Path>) -> Result<(), OcctError> {
42 let mut kernel = OcctKernel::new()?;
43
44 // --- Create shapes ---
45 let box_shape = kernel.make_box(30.0, 20.0, 15.0)?;
46 let cyl = kernel.make_cylinder(6.0, 25.0)?;
47 let sphere = kernel.make_sphere(4.0)?;
48 let moved_sphere = kernel.translate(sphere, 15.0, 10.0, 15.0)?;
49
50 println!("Created: box 30x20x15, cylinder r=6 h=25, sphere r=4");
51
52 // --- Boolean operations ---
53 let with_hole = kernel.cut(box_shape, cyl)?;
54 let final_shape = kernel.fuse(with_hole, moved_sphere)?;
55
56 // --- Measurements ---
57 let vol = kernel.get_volume(final_shape)?;
58 let area = kernel.get_surface_area(final_shape)?;
59 let bbox = kernel.get_bounding_box(final_shape, true)?;
60
61 println!("\nResult:");
62 println!(" Volume: {vol:.2} mm^3");
63 println!(" Surface area: {area:.2} mm^2");
64 println!(
65 " Bounding box: [{:.1}, {:.1}, {:.1}] to [{:.1}, {:.1}, {:.1}]",
66 bbox.min.x, bbox.min.y, bbox.min.z, bbox.max.x, bbox.max.y, bbox.max.z
67 );
68
69 // --- Topology counts ---
70 let faces = kernel.get_sub_shapes(final_shape, "Face")?;
71 let edges = kernel.get_sub_shapes(final_shape, "Edge")?;
72 let verts = kernel.get_sub_shapes(final_shape, "Vertex")?;
73 println!(
74 " Topology: {} faces, {} edges, {} vertices",
75 faces.len(),
76 edges.len(),
77 verts.len()
78 );
79
80 // --- Tessellate (renderer-ready mesh) ---
81 let mesh = kernel.tessellate(final_shape, 0.1, 0.5)?;
82 println!(
83 " Mesh: {} vertices, {} triangles",
84 mesh.positions.len() / 3,
85 mesh.indices.len() / 3
86 );
87
88 // --- STEP export ---
89 let step_data = kernel.export_step(final_shape)?;
90 if let Some(path) = step_out {
91 fs::write(path, &step_data).map_err(|e| OcctError::Operation {
92 operation: "export_step_write".to_owned(),
93 message: format!("write {}: {e}", path.display()),
94 })?;
95 println!("\nSTEP exported to: {}", path.display());
96 } else {
97 println!("\nTip: pass --step output.step to export the result");
98 }
99
100 // --- STEP round-trip ---
101 let reimported = kernel.import_step(&step_data)?;
102 let reimported_vol = kernel.get_volume(reimported)?;
103 println!(
104 " Round-trip: export -> import, volume delta = {:.6}",
105 (vol - reimported_vol).abs()
106 );
107
108 Ok(())
109}pub fn rotate( &mut self, id: ShapeHandle, px: f64, py: f64, pz: f64, dx: f64, dy: f64, dz: f64, angle_rad: f64, ) -> OcctResult<ShapeHandle>
pub fn scale( &mut self, id: ShapeHandle, px: f64, py: f64, pz: f64, factor: f64, ) -> OcctResult<ShapeHandle>
pub fn mirror( &mut self, id: ShapeHandle, px: f64, py: f64, pz: f64, nx: f64, ny: f64, nz: f64, ) -> OcctResult<ShapeHandle>
pub fn copy(&mut self, id: ShapeHandle) -> OcctResult<ShapeHandle>
pub fn linear_pattern( &mut self, id: ShapeHandle, dx: f64, dy: f64, dz: f64, spacing: f64, count: i32, ) -> OcctResult<ShapeHandle>
pub fn circular_pattern( &mut self, id: ShapeHandle, cx: f64, cy: f64, cz: f64, ax: f64, ay: f64, az: f64, angle: f64, count: i32, ) -> OcctResult<ShapeHandle>
pub fn transform( &mut self, id: ShapeHandle, matrix: &[f64], ) -> OcctResult<ShapeHandle>
pub fn general_transform( &mut self, id: ShapeHandle, matrix: &[f64], ) -> OcctResult<ShapeHandle>
pub fn translate_batch( &mut self, ids: &[ShapeHandle], offsets: &[f64], ) -> OcctResult<Vec<u32>>
pub fn compose_transform( &mut self, m1: &[f64], m2: &[f64], ) -> OcctResult<Vec<f64>>
pub fn transform_batch( &mut self, ids: &[ShapeHandle], matrices: &[f64], ) -> OcctResult<Vec<u32>>
pub fn rotate_batch( &mut self, ids: &[ShapeHandle], params: &[f64], ) -> OcctResult<Vec<u32>>
pub fn scale_batch( &mut self, ids: &[ShapeHandle], params: &[f64], ) -> OcctResult<Vec<u32>>
pub fn mirror_batch( &mut self, ids: &[ShapeHandle], params: &[f64], ) -> OcctResult<Vec<u32>>
pub fn make_vertex(&mut self, x: f64, y: f64, z: f64) -> OcctResult<ShapeHandle>
pub fn make_edge( &mut self, v1: ShapeHandle, v2: ShapeHandle, ) -> OcctResult<ShapeHandle>
pub fn make_wire(&mut self, edge_ids: &[ShapeHandle]) -> OcctResult<ShapeHandle>
pub fn make_face(&mut self, wire_id: ShapeHandle) -> OcctResult<ShapeHandle>
pub fn make_face_on_surface( &mut self, face_id: ShapeHandle, wire_id: ShapeHandle, ) -> OcctResult<ShapeHandle>
pub fn make_solid(&mut self, shell_id: ShapeHandle) -> OcctResult<ShapeHandle>
pub fn sew( &mut self, shape_ids: &[ShapeHandle], tolerance: f64, ) -> OcctResult<ShapeHandle>
pub fn make_compound( &mut self, shape_ids: &[ShapeHandle], ) -> OcctResult<ShapeHandle>
pub fn make_line_edge( &mut self, x1: f64, y1: f64, z1: f64, x2: f64, y2: f64, z2: f64, ) -> OcctResult<ShapeHandle>
pub fn make_circle_edge( &mut self, cx: f64, cy: f64, cz: f64, nx: f64, ny: f64, nz: f64, radius: f64, ) -> OcctResult<ShapeHandle>
pub fn make_circle_arc( &mut self, cx: f64, cy: f64, cz: f64, nx: f64, ny: f64, nz: f64, radius: f64, start_angle: f64, end_angle: f64, ) -> OcctResult<ShapeHandle>
pub fn make_arc_edge( &mut self, x1: f64, y1: f64, z1: f64, x2: f64, y2: f64, z2: f64, x3: f64, y3: f64, z3: f64, ) -> OcctResult<ShapeHandle>
pub fn make_ellipse_edge( &mut self, cx: f64, cy: f64, cz: f64, nx: f64, ny: f64, nz: f64, major_radius: f64, minor_radius: f64, ) -> OcctResult<ShapeHandle>
pub fn make_bezier_edge( &mut self, flat_points: &[f64], ) -> OcctResult<ShapeHandle>
pub fn make_ellipse_arc( &mut self, cx: f64, cy: f64, cz: f64, nx: f64, ny: f64, nz: f64, major_radius: f64, minor_radius: f64, start_angle: f64, end_angle: f64, ) -> OcctResult<ShapeHandle>
pub fn make_helix_wire( &mut self, px: f64, py: f64, pz: f64, dx: f64, dy: f64, dz: f64, pitch: f64, height: f64, radius: f64, ) -> OcctResult<ShapeHandle>
pub fn make_non_planar_face( &mut self, wire_id: ShapeHandle, ) -> OcctResult<ShapeHandle>
pub fn add_holes_in_face( &mut self, face_id: ShapeHandle, hole_wire_ids: &[ShapeHandle], ) -> OcctResult<ShapeHandle>
pub fn remove_holes_from_face( &mut self, face_id: ShapeHandle, hole_indices: &[i32], ) -> OcctResult<ShapeHandle>
pub fn solid_from_shell( &mut self, shell_id: ShapeHandle, ) -> OcctResult<ShapeHandle>
pub fn build_solid_from_faces( &mut self, face_ids: &[ShapeHandle], tolerance: f64, ) -> OcctResult<ShapeHandle>
pub fn sew_and_solidify( &mut self, face_ids: &[ShapeHandle], tolerance: f64, ) -> OcctResult<ShapeHandle>
pub fn build_tri_face( &mut self, ax: f64, ay: f64, az: f64, bx: f64, by: f64, bz: f64, cx2: f64, cy2: f64, cz2: f64, ) -> OcctResult<ShapeHandle>
pub fn make_tangent_arc( &mut self, x1: f64, y1: f64, z1: f64, tx: f64, ty: f64, tz: f64, x2: f64, y2: f64, z2: f64, ) -> OcctResult<ShapeHandle>
pub fn bspline_surface( &mut self, flat_points: &[f64], rows: i32, cols: i32, ) -> OcctResult<ShapeHandle>
pub fn get_shape_type(&mut self, id: ShapeHandle) -> OcctResult<String>
Sourcepub fn get_sub_shapes(
&mut self,
id: ShapeHandle,
shape_type: &str,
) -> OcctResult<Vec<u32>>
pub fn get_sub_shapes( &mut self, id: ShapeHandle, shape_type: &str, ) -> OcctResult<Vec<u32>>
Examples found in repository?
examples/cli.rs (line 70)
41fn run(step_out: Option<&std::path::Path>) -> Result<(), OcctError> {
42 let mut kernel = OcctKernel::new()?;
43
44 // --- Create shapes ---
45 let box_shape = kernel.make_box(30.0, 20.0, 15.0)?;
46 let cyl = kernel.make_cylinder(6.0, 25.0)?;
47 let sphere = kernel.make_sphere(4.0)?;
48 let moved_sphere = kernel.translate(sphere, 15.0, 10.0, 15.0)?;
49
50 println!("Created: box 30x20x15, cylinder r=6 h=25, sphere r=4");
51
52 // --- Boolean operations ---
53 let with_hole = kernel.cut(box_shape, cyl)?;
54 let final_shape = kernel.fuse(with_hole, moved_sphere)?;
55
56 // --- Measurements ---
57 let vol = kernel.get_volume(final_shape)?;
58 let area = kernel.get_surface_area(final_shape)?;
59 let bbox = kernel.get_bounding_box(final_shape, true)?;
60
61 println!("\nResult:");
62 println!(" Volume: {vol:.2} mm^3");
63 println!(" Surface area: {area:.2} mm^2");
64 println!(
65 " Bounding box: [{:.1}, {:.1}, {:.1}] to [{:.1}, {:.1}, {:.1}]",
66 bbox.min.x, bbox.min.y, bbox.min.z, bbox.max.x, bbox.max.y, bbox.max.z
67 );
68
69 // --- Topology counts ---
70 let faces = kernel.get_sub_shapes(final_shape, "Face")?;
71 let edges = kernel.get_sub_shapes(final_shape, "Edge")?;
72 let verts = kernel.get_sub_shapes(final_shape, "Vertex")?;
73 println!(
74 " Topology: {} faces, {} edges, {} vertices",
75 faces.len(),
76 edges.len(),
77 verts.len()
78 );
79
80 // --- Tessellate (renderer-ready mesh) ---
81 let mesh = kernel.tessellate(final_shape, 0.1, 0.5)?;
82 println!(
83 " Mesh: {} vertices, {} triangles",
84 mesh.positions.len() / 3,
85 mesh.indices.len() / 3
86 );
87
88 // --- STEP export ---
89 let step_data = kernel.export_step(final_shape)?;
90 if let Some(path) = step_out {
91 fs::write(path, &step_data).map_err(|e| OcctError::Operation {
92 operation: "export_step_write".to_owned(),
93 message: format!("write {}: {e}", path.display()),
94 })?;
95 println!("\nSTEP exported to: {}", path.display());
96 } else {
97 println!("\nTip: pass --step output.step to export the result");
98 }
99
100 // --- STEP round-trip ---
101 let reimported = kernel.import_step(&step_data)?;
102 let reimported_vol = kernel.get_volume(reimported)?;
103 println!(
104 " Round-trip: export -> import, volume delta = {:.6}",
105 (vol - reimported_vol).abs()
106 );
107
108 Ok(())
109}pub fn distance_between( &mut self, a: ShapeHandle, b: ShapeHandle, ) -> OcctResult<f64>
pub fn is_same(&mut self, a: ShapeHandle, b: ShapeHandle) -> OcctResult<bool>
pub fn is_equal(&mut self, a: ShapeHandle, b: ShapeHandle) -> OcctResult<bool>
pub fn is_null(&mut self, id: ShapeHandle) -> OcctResult<bool>
pub fn hash_code( &mut self, id: ShapeHandle, upper_bound: i32, ) -> OcctResult<i32>
pub fn shape_orientation(&mut self, id: ShapeHandle) -> OcctResult<String>
pub fn iter_shapes(&mut self, id: ShapeHandle) -> OcctResult<Vec<u32>>
pub fn edge_to_face_map( &mut self, id: ShapeHandle, hash_upper_bound: i32, ) -> OcctResult<Vec<i32>>
pub fn downcast( &mut self, id: ShapeHandle, target_type: &str, ) -> OcctResult<ShapeHandle>
pub fn adjacent_faces( &mut self, shape_id: ShapeHandle, face_id: ShapeHandle, ) -> OcctResult<Vec<u32>>
Sourcepub fn get_bounding_box(
&mut self,
id: ShapeHandle,
use_triangulation: bool,
) -> OcctResult<BoundingBox>
pub fn get_bounding_box( &mut self, id: ShapeHandle, use_triangulation: bool, ) -> OcctResult<BoundingBox>
Examples found in repository?
examples/cli.rs (line 59)
41fn run(step_out: Option<&std::path::Path>) -> Result<(), OcctError> {
42 let mut kernel = OcctKernel::new()?;
43
44 // --- Create shapes ---
45 let box_shape = kernel.make_box(30.0, 20.0, 15.0)?;
46 let cyl = kernel.make_cylinder(6.0, 25.0)?;
47 let sphere = kernel.make_sphere(4.0)?;
48 let moved_sphere = kernel.translate(sphere, 15.0, 10.0, 15.0)?;
49
50 println!("Created: box 30x20x15, cylinder r=6 h=25, sphere r=4");
51
52 // --- Boolean operations ---
53 let with_hole = kernel.cut(box_shape, cyl)?;
54 let final_shape = kernel.fuse(with_hole, moved_sphere)?;
55
56 // --- Measurements ---
57 let vol = kernel.get_volume(final_shape)?;
58 let area = kernel.get_surface_area(final_shape)?;
59 let bbox = kernel.get_bounding_box(final_shape, true)?;
60
61 println!("\nResult:");
62 println!(" Volume: {vol:.2} mm^3");
63 println!(" Surface area: {area:.2} mm^2");
64 println!(
65 " Bounding box: [{:.1}, {:.1}, {:.1}] to [{:.1}, {:.1}, {:.1}]",
66 bbox.min.x, bbox.min.y, bbox.min.z, bbox.max.x, bbox.max.y, bbox.max.z
67 );
68
69 // --- Topology counts ---
70 let faces = kernel.get_sub_shapes(final_shape, "Face")?;
71 let edges = kernel.get_sub_shapes(final_shape, "Edge")?;
72 let verts = kernel.get_sub_shapes(final_shape, "Vertex")?;
73 println!(
74 " Topology: {} faces, {} edges, {} vertices",
75 faces.len(),
76 edges.len(),
77 verts.len()
78 );
79
80 // --- Tessellate (renderer-ready mesh) ---
81 let mesh = kernel.tessellate(final_shape, 0.1, 0.5)?;
82 println!(
83 " Mesh: {} vertices, {} triangles",
84 mesh.positions.len() / 3,
85 mesh.indices.len() / 3
86 );
87
88 // --- STEP export ---
89 let step_data = kernel.export_step(final_shape)?;
90 if let Some(path) = step_out {
91 fs::write(path, &step_data).map_err(|e| OcctError::Operation {
92 operation: "export_step_write".to_owned(),
93 message: format!("write {}: {e}", path.display()),
94 })?;
95 println!("\nSTEP exported to: {}", path.display());
96 } else {
97 println!("\nTip: pass --step output.step to export the result");
98 }
99
100 // --- STEP round-trip ---
101 let reimported = kernel.import_step(&step_data)?;
102 let reimported_vol = kernel.get_volume(reimported)?;
103 println!(
104 " Round-trip: export -> import, volume delta = {:.6}",
105 (vol - reimported_vol).abs()
106 );
107
108 Ok(())
109}Sourcepub fn get_volume(&mut self, id: ShapeHandle) -> OcctResult<f64>
pub fn get_volume(&mut self, id: ShapeHandle) -> OcctResult<f64>
Examples found in repository?
examples/cli.rs (line 57)
41fn run(step_out: Option<&std::path::Path>) -> Result<(), OcctError> {
42 let mut kernel = OcctKernel::new()?;
43
44 // --- Create shapes ---
45 let box_shape = kernel.make_box(30.0, 20.0, 15.0)?;
46 let cyl = kernel.make_cylinder(6.0, 25.0)?;
47 let sphere = kernel.make_sphere(4.0)?;
48 let moved_sphere = kernel.translate(sphere, 15.0, 10.0, 15.0)?;
49
50 println!("Created: box 30x20x15, cylinder r=6 h=25, sphere r=4");
51
52 // --- Boolean operations ---
53 let with_hole = kernel.cut(box_shape, cyl)?;
54 let final_shape = kernel.fuse(with_hole, moved_sphere)?;
55
56 // --- Measurements ---
57 let vol = kernel.get_volume(final_shape)?;
58 let area = kernel.get_surface_area(final_shape)?;
59 let bbox = kernel.get_bounding_box(final_shape, true)?;
60
61 println!("\nResult:");
62 println!(" Volume: {vol:.2} mm^3");
63 println!(" Surface area: {area:.2} mm^2");
64 println!(
65 " Bounding box: [{:.1}, {:.1}, {:.1}] to [{:.1}, {:.1}, {:.1}]",
66 bbox.min.x, bbox.min.y, bbox.min.z, bbox.max.x, bbox.max.y, bbox.max.z
67 );
68
69 // --- Topology counts ---
70 let faces = kernel.get_sub_shapes(final_shape, "Face")?;
71 let edges = kernel.get_sub_shapes(final_shape, "Edge")?;
72 let verts = kernel.get_sub_shapes(final_shape, "Vertex")?;
73 println!(
74 " Topology: {} faces, {} edges, {} vertices",
75 faces.len(),
76 edges.len(),
77 verts.len()
78 );
79
80 // --- Tessellate (renderer-ready mesh) ---
81 let mesh = kernel.tessellate(final_shape, 0.1, 0.5)?;
82 println!(
83 " Mesh: {} vertices, {} triangles",
84 mesh.positions.len() / 3,
85 mesh.indices.len() / 3
86 );
87
88 // --- STEP export ---
89 let step_data = kernel.export_step(final_shape)?;
90 if let Some(path) = step_out {
91 fs::write(path, &step_data).map_err(|e| OcctError::Operation {
92 operation: "export_step_write".to_owned(),
93 message: format!("write {}: {e}", path.display()),
94 })?;
95 println!("\nSTEP exported to: {}", path.display());
96 } else {
97 println!("\nTip: pass --step output.step to export the result");
98 }
99
100 // --- STEP round-trip ---
101 let reimported = kernel.import_step(&step_data)?;
102 let reimported_vol = kernel.get_volume(reimported)?;
103 println!(
104 " Round-trip: export -> import, volume delta = {:.6}",
105 (vol - reimported_vol).abs()
106 );
107
108 Ok(())
109}Sourcepub fn get_surface_area(&mut self, id: ShapeHandle) -> OcctResult<f64>
pub fn get_surface_area(&mut self, id: ShapeHandle) -> OcctResult<f64>
Examples found in repository?
examples/cli.rs (line 58)
41fn run(step_out: Option<&std::path::Path>) -> Result<(), OcctError> {
42 let mut kernel = OcctKernel::new()?;
43
44 // --- Create shapes ---
45 let box_shape = kernel.make_box(30.0, 20.0, 15.0)?;
46 let cyl = kernel.make_cylinder(6.0, 25.0)?;
47 let sphere = kernel.make_sphere(4.0)?;
48 let moved_sphere = kernel.translate(sphere, 15.0, 10.0, 15.0)?;
49
50 println!("Created: box 30x20x15, cylinder r=6 h=25, sphere r=4");
51
52 // --- Boolean operations ---
53 let with_hole = kernel.cut(box_shape, cyl)?;
54 let final_shape = kernel.fuse(with_hole, moved_sphere)?;
55
56 // --- Measurements ---
57 let vol = kernel.get_volume(final_shape)?;
58 let area = kernel.get_surface_area(final_shape)?;
59 let bbox = kernel.get_bounding_box(final_shape, true)?;
60
61 println!("\nResult:");
62 println!(" Volume: {vol:.2} mm^3");
63 println!(" Surface area: {area:.2} mm^2");
64 println!(
65 " Bounding box: [{:.1}, {:.1}, {:.1}] to [{:.1}, {:.1}, {:.1}]",
66 bbox.min.x, bbox.min.y, bbox.min.z, bbox.max.x, bbox.max.y, bbox.max.z
67 );
68
69 // --- Topology counts ---
70 let faces = kernel.get_sub_shapes(final_shape, "Face")?;
71 let edges = kernel.get_sub_shapes(final_shape, "Edge")?;
72 let verts = kernel.get_sub_shapes(final_shape, "Vertex")?;
73 println!(
74 " Topology: {} faces, {} edges, {} vertices",
75 faces.len(),
76 edges.len(),
77 verts.len()
78 );
79
80 // --- Tessellate (renderer-ready mesh) ---
81 let mesh = kernel.tessellate(final_shape, 0.1, 0.5)?;
82 println!(
83 " Mesh: {} vertices, {} triangles",
84 mesh.positions.len() / 3,
85 mesh.indices.len() / 3
86 );
87
88 // --- STEP export ---
89 let step_data = kernel.export_step(final_shape)?;
90 if let Some(path) = step_out {
91 fs::write(path, &step_data).map_err(|e| OcctError::Operation {
92 operation: "export_step_write".to_owned(),
93 message: format!("write {}: {e}", path.display()),
94 })?;
95 println!("\nSTEP exported to: {}", path.display());
96 } else {
97 println!("\nTip: pass --step output.step to export the result");
98 }
99
100 // --- STEP round-trip ---
101 let reimported = kernel.import_step(&step_data)?;
102 let reimported_vol = kernel.get_volume(reimported)?;
103 println!(
104 " Round-trip: export -> import, volume delta = {:.6}",
105 (vol - reimported_vol).abs()
106 );
107
108 Ok(())
109}pub fn get_length(&mut self, id: ShapeHandle) -> OcctResult<f64>
pub fn get_center_of_mass(&mut self, id: ShapeHandle) -> OcctResult<Vec<f64>>
pub fn get_surface_center_of_mass( &mut self, face_id: ShapeHandle, ) -> OcctResult<Vec<f64>>
pub fn vertex_position( &mut self, vertex_id: ShapeHandle, ) -> OcctResult<Vec<f64>>
pub fn surface_type(&mut self, face_id: ShapeHandle) -> OcctResult<String>
pub fn surface_normal( &mut self, face_id: ShapeHandle, u: f64, v: f64, ) -> OcctResult<Vec<f64>>
pub fn point_on_surface( &mut self, face_id: ShapeHandle, u: f64, v: f64, ) -> OcctResult<Vec<f64>>
pub fn outer_wire(&mut self, face_id: ShapeHandle) -> OcctResult<ShapeHandle>
pub fn get_linear_center_of_mass( &mut self, id: ShapeHandle, ) -> OcctResult<Vec<f64>>
pub fn surface_curvature( &mut self, face_id: ShapeHandle, u: f64, v: f64, ) -> OcctResult<Vec<f64>>
pub fn uv_bounds(&mut self, face_id: ShapeHandle) -> OcctResult<Vec<f64>>
pub fn get_face_cylinder_data( &mut self, face_id: ShapeHandle, ) -> OcctResult<Vec<f64>>
pub fn uv_from_point( &mut self, face_id: ShapeHandle, x: f64, y: f64, z: f64, ) -> OcctResult<Vec<f64>>
pub fn project_point_on_face( &mut self, face_id: ShapeHandle, x: f64, y: f64, z: f64, ) -> OcctResult<Vec<f64>>
pub fn classify_point_on_face( &mut self, face_id: ShapeHandle, u: f64, v: f64, ) -> OcctResult<String>
pub fn curve_type(&mut self, id: ShapeHandle) -> OcctResult<String>
pub fn curve_point_at_param( &mut self, id: ShapeHandle, param: f64, ) -> OcctResult<Vec<f64>>
pub fn curve_tangent( &mut self, id: ShapeHandle, param: f64, ) -> OcctResult<Vec<f64>>
pub fn curve_parameters(&mut self, id: ShapeHandle) -> OcctResult<Vec<f64>>
pub fn curve_is_closed(&mut self, id: ShapeHandle) -> OcctResult<bool>
pub fn curve_length(&mut self, id: ShapeHandle) -> OcctResult<f64>
pub fn interpolate_points( &mut self, flat_points: &[f64], periodic: bool, ) -> OcctResult<ShapeHandle>
pub fn curve_is_periodic(&mut self, id: ShapeHandle) -> OcctResult<bool>
pub fn approximate_points( &mut self, flat_points: &[f64], tolerance: f64, ) -> OcctResult<ShapeHandle>
pub fn lift_curve2d_to_plane( &mut self, flat_points2d: &[f64], plane_ox: f64, plane_oy: f64, plane_oz: f64, plane_zx: f64, plane_zy: f64, plane_zz: f64, plane_xx: f64, plane_xy: f64, plane_xz: f64, ) -> OcctResult<ShapeHandle>
pub fn get_nurbs_curve_data( &mut self, edge_id: ShapeHandle, ) -> OcctResult<NurbsCurveData>
pub fn has_triangulation(&mut self, id: ShapeHandle) -> OcctResult<bool>
pub fn query_batch(&mut self, ids: &[ShapeHandle]) -> OcctResult<Vec<f64>>
pub fn pipe( &mut self, profile_id: ShapeHandle, spine_id: ShapeHandle, ) -> OcctResult<ShapeHandle>
pub fn simple_pipe( &mut self, profile_id: ShapeHandle, spine_id: ShapeHandle, ) -> OcctResult<ShapeHandle>
pub fn revolve_vec( &mut self, shape_id: ShapeHandle, cx: f64, cy: f64, cz: f64, dx: f64, dy: f64, dz: f64, angle: f64, ) -> OcctResult<ShapeHandle>
pub fn loft( &mut self, wire_ids: &[ShapeHandle], is_solid: bool, ruled: bool, ) -> OcctResult<ShapeHandle>
pub fn loft_with_vertices( &mut self, wire_ids: &[ShapeHandle], is_solid: bool, ruled: bool, start_vertex_id: ShapeHandle, end_vertex_id: ShapeHandle, ) -> OcctResult<ShapeHandle>
pub fn sweep( &mut self, wire_id: ShapeHandle, spine_id: ShapeHandle, transition_mode: i32, ) -> OcctResult<ShapeHandle>
pub fn sweep_pipe_shell( &mut self, profile_id: ShapeHandle, spine_id: ShapeHandle, freenet: bool, smooth: bool, ) -> OcctResult<ShapeHandle>
pub fn draft_prism( &mut self, shape_id: ShapeHandle, dx: f64, dy: f64, dz: f64, angle_deg: f64, ) -> OcctResult<ShapeHandle>
pub fn fix_shape(&mut self, id: ShapeHandle) -> OcctResult<ShapeHandle>
pub fn unify_same_domain(&mut self, id: ShapeHandle) -> OcctResult<ShapeHandle>
pub fn is_valid(&mut self, id: ShapeHandle) -> OcctResult<bool>
pub fn heal_solid( &mut self, id: ShapeHandle, tolerance: f64, ) -> OcctResult<ShapeHandle>
pub fn heal_face( &mut self, id: ShapeHandle, tolerance: f64, ) -> OcctResult<ShapeHandle>
pub fn heal_wire( &mut self, id: ShapeHandle, tolerance: f64, ) -> OcctResult<ShapeHandle>
pub fn fix_face_orientations( &mut self, id: ShapeHandle, ) -> OcctResult<ShapeHandle>
pub fn build_curves3d(&mut self, wire_id: ShapeHandle) -> OcctResult<()>
pub fn fix_wire_on_face( &mut self, wire_id: ShapeHandle, face_id: ShapeHandle, tolerance: f64, ) -> OcctResult<ShapeHandle>
pub fn remove_degenerate_edges( &mut self, id: ShapeHandle, ) -> OcctResult<ShapeHandle>
Sourcepub fn import_step(&mut self, data: &str) -> OcctResult<ShapeHandle>
pub fn import_step(&mut self, data: &str) -> OcctResult<ShapeHandle>
Examples found in repository?
examples/cli.rs (line 101)
41fn run(step_out: Option<&std::path::Path>) -> Result<(), OcctError> {
42 let mut kernel = OcctKernel::new()?;
43
44 // --- Create shapes ---
45 let box_shape = kernel.make_box(30.0, 20.0, 15.0)?;
46 let cyl = kernel.make_cylinder(6.0, 25.0)?;
47 let sphere = kernel.make_sphere(4.0)?;
48 let moved_sphere = kernel.translate(sphere, 15.0, 10.0, 15.0)?;
49
50 println!("Created: box 30x20x15, cylinder r=6 h=25, sphere r=4");
51
52 // --- Boolean operations ---
53 let with_hole = kernel.cut(box_shape, cyl)?;
54 let final_shape = kernel.fuse(with_hole, moved_sphere)?;
55
56 // --- Measurements ---
57 let vol = kernel.get_volume(final_shape)?;
58 let area = kernel.get_surface_area(final_shape)?;
59 let bbox = kernel.get_bounding_box(final_shape, true)?;
60
61 println!("\nResult:");
62 println!(" Volume: {vol:.2} mm^3");
63 println!(" Surface area: {area:.2} mm^2");
64 println!(
65 " Bounding box: [{:.1}, {:.1}, {:.1}] to [{:.1}, {:.1}, {:.1}]",
66 bbox.min.x, bbox.min.y, bbox.min.z, bbox.max.x, bbox.max.y, bbox.max.z
67 );
68
69 // --- Topology counts ---
70 let faces = kernel.get_sub_shapes(final_shape, "Face")?;
71 let edges = kernel.get_sub_shapes(final_shape, "Edge")?;
72 let verts = kernel.get_sub_shapes(final_shape, "Vertex")?;
73 println!(
74 " Topology: {} faces, {} edges, {} vertices",
75 faces.len(),
76 edges.len(),
77 verts.len()
78 );
79
80 // --- Tessellate (renderer-ready mesh) ---
81 let mesh = kernel.tessellate(final_shape, 0.1, 0.5)?;
82 println!(
83 " Mesh: {} vertices, {} triangles",
84 mesh.positions.len() / 3,
85 mesh.indices.len() / 3
86 );
87
88 // --- STEP export ---
89 let step_data = kernel.export_step(final_shape)?;
90 if let Some(path) = step_out {
91 fs::write(path, &step_data).map_err(|e| OcctError::Operation {
92 operation: "export_step_write".to_owned(),
93 message: format!("write {}: {e}", path.display()),
94 })?;
95 println!("\nSTEP exported to: {}", path.display());
96 } else {
97 println!("\nTip: pass --step output.step to export the result");
98 }
99
100 // --- STEP round-trip ---
101 let reimported = kernel.import_step(&step_data)?;
102 let reimported_vol = kernel.get_volume(reimported)?;
103 println!(
104 " Round-trip: export -> import, volume delta = {:.6}",
105 (vol - reimported_vol).abs()
106 );
107
108 Ok(())
109}Sourcepub fn export_step(&mut self, id: ShapeHandle) -> OcctResult<String>
pub fn export_step(&mut self, id: ShapeHandle) -> OcctResult<String>
Examples found in repository?
examples/cli.rs (line 89)
41fn run(step_out: Option<&std::path::Path>) -> Result<(), OcctError> {
42 let mut kernel = OcctKernel::new()?;
43
44 // --- Create shapes ---
45 let box_shape = kernel.make_box(30.0, 20.0, 15.0)?;
46 let cyl = kernel.make_cylinder(6.0, 25.0)?;
47 let sphere = kernel.make_sphere(4.0)?;
48 let moved_sphere = kernel.translate(sphere, 15.0, 10.0, 15.0)?;
49
50 println!("Created: box 30x20x15, cylinder r=6 h=25, sphere r=4");
51
52 // --- Boolean operations ---
53 let with_hole = kernel.cut(box_shape, cyl)?;
54 let final_shape = kernel.fuse(with_hole, moved_sphere)?;
55
56 // --- Measurements ---
57 let vol = kernel.get_volume(final_shape)?;
58 let area = kernel.get_surface_area(final_shape)?;
59 let bbox = kernel.get_bounding_box(final_shape, true)?;
60
61 println!("\nResult:");
62 println!(" Volume: {vol:.2} mm^3");
63 println!(" Surface area: {area:.2} mm^2");
64 println!(
65 " Bounding box: [{:.1}, {:.1}, {:.1}] to [{:.1}, {:.1}, {:.1}]",
66 bbox.min.x, bbox.min.y, bbox.min.z, bbox.max.x, bbox.max.y, bbox.max.z
67 );
68
69 // --- Topology counts ---
70 let faces = kernel.get_sub_shapes(final_shape, "Face")?;
71 let edges = kernel.get_sub_shapes(final_shape, "Edge")?;
72 let verts = kernel.get_sub_shapes(final_shape, "Vertex")?;
73 println!(
74 " Topology: {} faces, {} edges, {} vertices",
75 faces.len(),
76 edges.len(),
77 verts.len()
78 );
79
80 // --- Tessellate (renderer-ready mesh) ---
81 let mesh = kernel.tessellate(final_shape, 0.1, 0.5)?;
82 println!(
83 " Mesh: {} vertices, {} triangles",
84 mesh.positions.len() / 3,
85 mesh.indices.len() / 3
86 );
87
88 // --- STEP export ---
89 let step_data = kernel.export_step(final_shape)?;
90 if let Some(path) = step_out {
91 fs::write(path, &step_data).map_err(|e| OcctError::Operation {
92 operation: "export_step_write".to_owned(),
93 message: format!("write {}: {e}", path.display()),
94 })?;
95 println!("\nSTEP exported to: {}", path.display());
96 } else {
97 println!("\nTip: pass --step output.step to export the result");
98 }
99
100 // --- STEP round-trip ---
101 let reimported = kernel.import_step(&step_data)?;
102 let reimported_vol = kernel.get_volume(reimported)?;
103 println!(
104 " Round-trip: export -> import, volume delta = {:.6}",
105 (vol - reimported_vol).abs()
106 );
107
108 Ok(())
109}pub fn export_stl( &mut self, id: ShapeHandle, linear_deflection: f64, ascii: bool, ) -> OcctResult<String>
pub fn import_stl(&mut self, data: &str) -> OcctResult<ShapeHandle>
pub fn to_brep(&mut self, id: ShapeHandle) -> OcctResult<String>
pub fn from_brep(&mut self, data: &str) -> OcctResult<ShapeHandle>
pub fn translate_with_history( &mut self, id: ShapeHandle, dx: f64, dy: f64, dz: f64, input_face_hashes: &[i32], hash_upper_bound: i32, ) -> OcctResult<EvolutionData>
pub fn fuse_with_history( &mut self, a: ShapeHandle, b: ShapeHandle, input_face_hashes: &[i32], hash_upper_bound: i32, ) -> OcctResult<EvolutionData>
pub fn cut_with_history( &mut self, a: ShapeHandle, b: ShapeHandle, input_face_hashes: &[i32], hash_upper_bound: i32, ) -> OcctResult<EvolutionData>
pub fn fillet_with_history( &mut self, solid_id: ShapeHandle, edge_ids: &[ShapeHandle], radius: f64, input_face_hashes: &[i32], hash_upper_bound: i32, ) -> OcctResult<EvolutionData>
pub fn rotate_with_history( &mut self, id: ShapeHandle, px: f64, py: f64, pz: f64, dx: f64, dy: f64, dz: f64, angle: f64, input_face_hashes: &[i32], hash_upper_bound: i32, ) -> OcctResult<EvolutionData>
pub fn mirror_with_history( &mut self, id: ShapeHandle, px: f64, py: f64, pz: f64, nx: f64, ny: f64, nz: f64, input_face_hashes: &[i32], hash_upper_bound: i32, ) -> OcctResult<EvolutionData>
pub fn scale_with_history( &mut self, id: ShapeHandle, cx: f64, cy: f64, cz: f64, factor: f64, input_face_hashes: &[i32], hash_upper_bound: i32, ) -> OcctResult<EvolutionData>
pub fn intersect_with_history( &mut self, a: ShapeHandle, b: ShapeHandle, input_face_hashes: &[i32], hash_upper_bound: i32, ) -> OcctResult<EvolutionData>
pub fn chamfer_with_history( &mut self, solid_id: ShapeHandle, edge_ids: &[ShapeHandle], distance: f64, input_face_hashes: &[i32], hash_upper_bound: i32, ) -> OcctResult<EvolutionData>
pub fn shell_with_history( &mut self, solid_id: ShapeHandle, face_ids: &[ShapeHandle], thickness: f64, tolerance: f64, input_face_hashes: &[i32], hash_upper_bound: i32, ) -> OcctResult<EvolutionData>
pub fn offset_with_history( &mut self, solid_id: ShapeHandle, distance: f64, tolerance: f64, input_face_hashes: &[i32], hash_upper_bound: i32, ) -> OcctResult<EvolutionData>
pub fn thicken_with_history( &mut self, shape_id: ShapeHandle, thickness: f64, tolerance: f64, input_face_hashes: &[i32], hash_upper_bound: i32, ) -> OcctResult<EvolutionData>
Sourcepub fn tessellate(
&mut self,
id: ShapeHandle,
linear_deflection: f64,
angular_deflection: f64,
) -> OcctResult<Mesh>
pub fn tessellate( &mut self, id: ShapeHandle, linear_deflection: f64, angular_deflection: f64, ) -> OcctResult<Mesh>
Examples found in repository?
examples/cli.rs (line 81)
41fn run(step_out: Option<&std::path::Path>) -> Result<(), OcctError> {
42 let mut kernel = OcctKernel::new()?;
43
44 // --- Create shapes ---
45 let box_shape = kernel.make_box(30.0, 20.0, 15.0)?;
46 let cyl = kernel.make_cylinder(6.0, 25.0)?;
47 let sphere = kernel.make_sphere(4.0)?;
48 let moved_sphere = kernel.translate(sphere, 15.0, 10.0, 15.0)?;
49
50 println!("Created: box 30x20x15, cylinder r=6 h=25, sphere r=4");
51
52 // --- Boolean operations ---
53 let with_hole = kernel.cut(box_shape, cyl)?;
54 let final_shape = kernel.fuse(with_hole, moved_sphere)?;
55
56 // --- Measurements ---
57 let vol = kernel.get_volume(final_shape)?;
58 let area = kernel.get_surface_area(final_shape)?;
59 let bbox = kernel.get_bounding_box(final_shape, true)?;
60
61 println!("\nResult:");
62 println!(" Volume: {vol:.2} mm^3");
63 println!(" Surface area: {area:.2} mm^2");
64 println!(
65 " Bounding box: [{:.1}, {:.1}, {:.1}] to [{:.1}, {:.1}, {:.1}]",
66 bbox.min.x, bbox.min.y, bbox.min.z, bbox.max.x, bbox.max.y, bbox.max.z
67 );
68
69 // --- Topology counts ---
70 let faces = kernel.get_sub_shapes(final_shape, "Face")?;
71 let edges = kernel.get_sub_shapes(final_shape, "Edge")?;
72 let verts = kernel.get_sub_shapes(final_shape, "Vertex")?;
73 println!(
74 " Topology: {} faces, {} edges, {} vertices",
75 faces.len(),
76 edges.len(),
77 verts.len()
78 );
79
80 // --- Tessellate (renderer-ready mesh) ---
81 let mesh = kernel.tessellate(final_shape, 0.1, 0.5)?;
82 println!(
83 " Mesh: {} vertices, {} triangles",
84 mesh.positions.len() / 3,
85 mesh.indices.len() / 3
86 );
87
88 // --- STEP export ---
89 let step_data = kernel.export_step(final_shape)?;
90 if let Some(path) = step_out {
91 fs::write(path, &step_data).map_err(|e| OcctError::Operation {
92 operation: "export_step_write".to_owned(),
93 message: format!("write {}: {e}", path.display()),
94 })?;
95 println!("\nSTEP exported to: {}", path.display());
96 } else {
97 println!("\nTip: pass --step output.step to export the result");
98 }
99
100 // --- STEP round-trip ---
101 let reimported = kernel.import_step(&step_data)?;
102 let reimported_vol = kernel.get_volume(reimported)?;
103 println!(
104 " Round-trip: export -> import, volume delta = {:.6}",
105 (vol - reimported_vol).abs()
106 );
107
108 Ok(())
109}pub fn mesh_shape( &mut self, id: ShapeHandle, linear_deflection: f64, angular_deflection: f64, ) -> OcctResult<Mesh>
pub fn mesh_batch( &mut self, ids: &[ShapeHandle], linear_deflection: f64, angular_deflection: f64, ) -> OcctResult<MeshBatch>
pub fn wireframe( &mut self, id: ShapeHandle, deflection: f64, ) -> OcctResult<EdgeData>
pub fn project_edges( &mut self, shape_id: ShapeHandle, ox: f64, oy: f64, oz: f64, dx: f64, dy: f64, dz: f64, xx: f64, xy: f64, xz: f64, has_x_axis: bool, ) -> OcctResult<ProjectionData>
pub fn release(&mut self, id: ShapeHandle) -> OcctResult<()>
pub fn release_all(&mut self) -> OcctResult<()>
pub fn get_shape_count(&mut self) -> OcctResult<u32>
pub fn make_null_shape(&mut self) -> OcctResult<ShapeHandle>
pub fn xcaf_new_document(&mut self) -> OcctResult<u32>
pub fn xcaf_close(&mut self, doc_id: ShapeHandle) -> OcctResult<()>
pub fn xcaf_add_shape( &mut self, doc_id: ShapeHandle, shape_id: ShapeHandle, ) -> OcctResult<i32>
pub fn xcaf_add_component( &mut self, doc_id: ShapeHandle, parent_label_id: i32, shape_id: ShapeHandle, tx: f64, ty: f64, tz: f64, rx: f64, ry: f64, rz: f64, ) -> OcctResult<i32>
pub fn xcaf_set_color( &mut self, doc_id: ShapeHandle, label_id: i32, r: f64, g: f64, b: f64, ) -> OcctResult<()>
pub fn xcaf_set_name( &mut self, doc_id: ShapeHandle, label_id: i32, name: &str, ) -> OcctResult<()>
pub fn xcaf_get_label_info( &mut self, doc_id: ShapeHandle, label_id: i32, ) -> OcctResult<LabelInfo>
pub fn xcaf_get_child_labels( &mut self, doc_id: ShapeHandle, parent_label_id: i32, ) -> OcctResult<Vec<i32>>
pub fn xcaf_get_root_labels( &mut self, doc_id: ShapeHandle, ) -> OcctResult<Vec<i32>>
pub fn xcaf_export_step(&mut self, doc_id: ShapeHandle) -> OcctResult<String>
pub fn xcaf_import_step(&mut self, step_data: &str) -> OcctResult<u32>
pub fn xcaf_export_gltf( &mut self, doc_id: ShapeHandle, lin_deflection: f64, ang_deflection: f64, ) -> OcctResult<String>
Trait Implementations§
Source§impl Drop for OcctKernel
impl Drop for OcctKernel
Auto Trait Implementations§
impl Freeze for OcctKernel
impl !RefUnwindSafe for OcctKernel
impl Send for OcctKernel
impl Sync for OcctKernel
impl Unpin for OcctKernel
impl UnsafeUnpin for OcctKernel
impl !UnwindSafe for OcctKernel
Blanket Implementations§
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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