mirror of
https://github.com/Theaninova/Bampy.git
synced 2025-12-11 03:56:17 +00:00
feat: slicing
This commit is contained in:
@@ -56,7 +56,7 @@ pub fn slice(
|
||||
slicable_triangles.push(triangle);
|
||||
} else {
|
||||
slicable_triangles.push(triangle);
|
||||
surface_triangles.push(triangle);
|
||||
//surface_triangles.push(triangle);
|
||||
}
|
||||
}
|
||||
slicable_triangles.shrink_to_fit();
|
||||
@@ -65,7 +65,7 @@ pub fn slice(
|
||||
let slicer_options = SlicerOptions { layer_height };
|
||||
|
||||
console_log!("Creating Surfaces");
|
||||
let surfaces = split_surface(surface_triangles);
|
||||
// let surfaces = split_surface(surface_triangles);
|
||||
|
||||
console_log!("Computing BVH");
|
||||
let slicable = Mesh::from(slicable_triangles);
|
||||
|
||||
@@ -40,6 +40,8 @@ pub fn create_slices(options: &SlicerOptions, slicable: &Mesh<f32>) -> Vec<Slice
|
||||
child_r_index,
|
||||
child_r_aabb,
|
||||
} => {
|
||||
assert!(child_l_aabb.min.z <= child_l_aabb.max.z);
|
||||
assert!(child_r_aabb.min.z <= child_r_aabb.max.z);
|
||||
if layer >= child_l_aabb.min.z && layer <= child_l_aabb.max.z {
|
||||
stack.push(child_l_index);
|
||||
}
|
||||
|
||||
@@ -22,28 +22,29 @@ pub fn find_slice_rings(mut slice: BaseSlice) -> Vec<SliceRing> {
|
||||
|
||||
let mut previous_len = usize::MAX;
|
||||
while relative_ne!(ring.points[0], right) {
|
||||
if previous_len == ring.points.len() {
|
||||
if previous_len == slice.lines.len() {
|
||||
console_log!(
|
||||
"Error: Could not find a ring for slice at z = {}, {} items left.",
|
||||
slice.z,
|
||||
ring.points.len()
|
||||
slice.lines.len()
|
||||
);
|
||||
break;
|
||||
}
|
||||
previous_len = ring.points.len();
|
||||
previous_len = slice.lines.len();
|
||||
|
||||
slice.lines.retain_mut(|line| {
|
||||
if relative_eq!(line.start, right, epsilon = 0.001) {
|
||||
ring.points.push(line.end);
|
||||
right = line.end;
|
||||
false
|
||||
} else if relative_eq!(line.end, right, epsilon = 0.001) {
|
||||
//if relative_eq!(line.start, right, epsilon = 0.001) {
|
||||
ring.points.push(line.start);
|
||||
ring.points.push(line.end);
|
||||
right = line.end;
|
||||
false
|
||||
/*} else if relative_eq!(line.end, right, epsilon = 0.001) {
|
||||
ring.points.push(line.start);
|
||||
right = line.start;
|
||||
false
|
||||
} else {
|
||||
true
|
||||
}
|
||||
}*/
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use approx::{relative_eq, AbsDiffEq, RelativeEq};
|
||||
use approx::{assert_relative_ne, relative_eq, AbsDiffEq, RelativeEq};
|
||||
use bvh::{
|
||||
aabb::{Aabb, Bounded},
|
||||
bounding_hierarchy::BHShape,
|
||||
};
|
||||
use nalgebra::{ClosedAdd, ClosedMul, ClosedSub, Scalar, SimdPartialOrd, Vector3};
|
||||
use nalgebra::{ClosedAdd, ClosedMul, ClosedSub, Point3, Scalar, SimdPartialOrd, Vector3};
|
||||
use num::{Float, FromPrimitive};
|
||||
|
||||
use super::line::Line3;
|
||||
@@ -43,16 +43,24 @@ where
|
||||
+ FromPrimitive,
|
||||
{
|
||||
pub fn new(a: Vector3<T>, b: Vector3<T>, c: Vector3<T>) -> Self {
|
||||
let normal = (b - a).cross(&(c - a));
|
||||
let mut aabb = Aabb::with_bounds(a.into(), b.into());
|
||||
aabb.grow_mut(&c.into());
|
||||
Self {
|
||||
a,
|
||||
b,
|
||||
c,
|
||||
normal: normal.into(),
|
||||
normal: (b - a).cross(&(c - a)).into(),
|
||||
node_index: 0,
|
||||
aabb,
|
||||
aabb: Aabb::with_bounds(
|
||||
Point3::new(
|
||||
T::min(T::min(a.x, b.x), c.x),
|
||||
T::min(T::min(a.y, b.y), c.y),
|
||||
T::min(T::min(a.z, b.z), c.z),
|
||||
),
|
||||
Point3::new(
|
||||
T::max(T::max(a.x, b.x), c.x),
|
||||
T::max(T::max(a.y, b.y), c.y),
|
||||
T::max(T::max(a.z, b.z), c.z),
|
||||
),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,14 +88,14 @@ where
|
||||
|
||||
pub fn intersect_z(&self, z: T) -> Option<Line3<T>> {
|
||||
let mut intersection = Vec::with_capacity(3);
|
||||
let mut last = self.c;
|
||||
let mut last = &self.c;
|
||||
for point in [self.a, self.b, self.c].iter() {
|
||||
if relative_eq!(point.z, z) {
|
||||
intersection.push(*point);
|
||||
} else if last.z < z && point.z > z || last.z > z && point.z < z {
|
||||
} else if (last.z < z && point.z > z) || (last.z > z && point.z < z) {
|
||||
intersection.push(last.lerp(&point, (z - last.z) / (point.z - last.z)));
|
||||
}
|
||||
last = *point;
|
||||
last = point;
|
||||
}
|
||||
if intersection.len() == 2 {
|
||||
Some(Line3 {
|
||||
|
||||
@@ -101,9 +101,9 @@
|
||||
{@const visible = showSlices >= i / $layers.length}
|
||||
{@const color = new Color(0, i / $layers.length, 0.2)}
|
||||
{#if type === LayerType.Line}
|
||||
<T.Line {geometry} {visible}>
|
||||
<T.LineSegments {geometry} {visible}>
|
||||
<T.LineBasicMaterial {color} />
|
||||
</T.Line>
|
||||
</T.LineSegments>
|
||||
{:else if type === LayerType.Surface}
|
||||
<T.Mesh {geometry} {visible}>
|
||||
<T.MeshMatcapMaterial {color} side={DoubleSide} />
|
||||
|
||||
Reference in New Issue
Block a user