mirror of
https://github.com/Theaninova/Bampy.git
synced 2026-01-03 15:22:50 +00:00
feat: testing
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use super::{
|
||||
axis::Axis,
|
||||
base_slices::BaseSlice,
|
||||
line::Line3,
|
||||
slice_path::{SlicePath, SurfacePathIterator},
|
||||
triangle::Triangle,
|
||||
FloatValue,
|
||||
@@ -60,7 +61,7 @@ impl Mesh {
|
||||
/ slice_height)
|
||||
.floor() as usize;
|
||||
|
||||
(0..layer_count).map(move |i| {
|
||||
(0..=layer_count).map(move |i| {
|
||||
let layer = i as FloatValue * slice_height + self.aabb.min[axis as usize];
|
||||
let mut base_slice = BaseSlice {
|
||||
i,
|
||||
@@ -107,4 +108,79 @@ impl Mesh {
|
||||
base_slice
|
||||
})
|
||||
}
|
||||
|
||||
pub fn outline_base_slice(&self, axis: Axis) -> BaseSlice {
|
||||
let mut base_slice = BaseSlice {
|
||||
i: 0,
|
||||
d: 0.0,
|
||||
axis,
|
||||
lines: vec![],
|
||||
};
|
||||
'triangle: for (triangle_index, triangle) in self.triangles.iter().enumerate() {
|
||||
let mut stack = Vec::<usize>::with_capacity(self.bvh.nodes.len());
|
||||
stack.push(0);
|
||||
let mut ab = false;
|
||||
let mut ac = false;
|
||||
let mut bc = false;
|
||||
while let Some(i) = stack.pop() {
|
||||
match self.bvh.nodes[i] {
|
||||
BvhNode::Node {
|
||||
parent_index: _,
|
||||
child_l_index,
|
||||
child_l_aabb,
|
||||
child_r_index,
|
||||
child_r_aabb,
|
||||
} => {
|
||||
let coords = [triangle.a, triangle.b, triangle.c];
|
||||
macro_rules! match_aabb {
|
||||
($side:expr) => {
|
||||
coords
|
||||
.iter()
|
||||
.map(|point| {
|
||||
$side.approx_contains_eps(point, FloatValue::EPSILON) as i32
|
||||
})
|
||||
.sum::<i32>()
|
||||
>= 2
|
||||
};
|
||||
}
|
||||
if match_aabb!(child_l_aabb) {
|
||||
stack.push(child_l_index);
|
||||
}
|
||||
if match_aabb!(child_r_aabb) {
|
||||
stack.push(child_r_index);
|
||||
}
|
||||
}
|
||||
BvhNode::Leaf {
|
||||
parent_index: _,
|
||||
shape_index,
|
||||
} => {
|
||||
if triangle_index == shape_index {
|
||||
continue;
|
||||
}
|
||||
let other = &self.triangles[shape_index];
|
||||
let a = other.has_point(triangle.a);
|
||||
let b = other.has_point(triangle.b);
|
||||
let c = other.has_point(triangle.c);
|
||||
ab = ab || (a && b);
|
||||
ac = ac || (a && c);
|
||||
bc = bc || (b && c);
|
||||
|
||||
if ab && ac && bc {
|
||||
continue 'triangle;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if !ab {
|
||||
base_slice.lines.push(Line3::new(triangle.a, triangle.b));
|
||||
}
|
||||
if !ac {
|
||||
base_slice.lines.push(Line3::new(triangle.a, triangle.c));
|
||||
}
|
||||
if !bc {
|
||||
base_slice.lines.push(Line3::new(triangle.b, triangle.c));
|
||||
}
|
||||
}
|
||||
base_slice
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user