forked from 1b-agent/opencadstudio-upstream
feat(model): SLICE cuts meshes
SLICE now takes MESH, polygon mesh and polyface mesh objects. A mesh that closes a volume is sliced as a solid, so each side is capped and becomes a 3D solid. An open mesh, such as a pipe run imported without end caps, is clipped face by face and each side stays a mesh, open along the cut. Keeping one side or both works as for solids, in one undo step. Refs #1398 Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
9e55bcd3bf
commit
5e6290ce30
4 files changed
+220
-23
No files matched your search
@@ -2544,16 +2544,37 @@ impl OpenCADStudio {
|
||||
.filter(|handle| {
|
||||
matches!(
|
||||
scene.document.get_entity(*handle),
|
||||
Some(codec::EntityType::Solid3D(_) | codec::EntityType::Surface(_))
|
||||
Some(
|
||||
codec::EntityType::Solid3D(_)
|
||||
| codec::EntityType::Surface(_)
|
||||
| codec::EntityType::Mesh(_)
|
||||
| codec::EntityType::PolygonMesh(_)
|
||||
| codec::EntityType::PolyfaceMesh(_)
|
||||
)
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
scene.restore_solid_models(&targets);
|
||||
targets.retain(|handle| scene.solid_models.contains_key(handle));
|
||||
let mesh_extent = |handle: &codec::Handle| {
|
||||
let entity = scene.document.get_entity(*handle)?;
|
||||
let (vertices, _) = crate::entities::mesh::mesh_polygons(entity)?;
|
||||
vertices.iter().fold(None, |bounds, point| {
|
||||
let (mut min, mut max) = bounds.unwrap_or((*point, *point));
|
||||
for axis in 0..3 {
|
||||
min[axis] = f64::min(min[axis], point[axis]);
|
||||
max[axis] = f64::max(max[axis], point[axis]);
|
||||
}
|
||||
Some((min, max))
|
||||
})
|
||||
};
|
||||
targets.retain(|handle| {
|
||||
scene.solid_models.contains_key(handle) || mesh_extent(handle).is_some()
|
||||
});
|
||||
let bounds = targets
|
||||
.iter()
|
||||
.filter_map(|handle| {
|
||||
crate::scene::model::solid_model::extent(&scene.solid_models[handle])
|
||||
.filter_map(|handle| match scene.solid_models.get(handle) {
|
||||
Some(body) => crate::scene::model::solid_model::extent(body),
|
||||
None => mesh_extent(handle),
|
||||
})
|
||||
.fold(None::<([f64; 3], [f64; 3])>, |bounds, (low, high)| {
|
||||
Some(match bounds {
|
||||
|
||||
Reference in new issue
Block a user