Skip to content

Commit

Permalink
Do reverse transform after meshing
Browse files Browse the repository at this point in the history
  • Loading branch information
mkeeter committed Mar 27, 2024
1 parent e7097c0 commit d0b1eca
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions fidget/src/mesh/octree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,22 @@ impl Octree {
/// The shape is evaluated on the region `[-1, 1]` on all axes
pub fn build<S: Shape + Clone>(shape: &S, settings: Settings) -> Self {
// Transform the shape given our bounds
let shape = shape
.clone()
.apply_transform(settings.bounds.transform().into());
let out = Self::build_inner(&shape, settings);
// TODO correct for vertex offsets
out
let t = settings.bounds.transform();
if t == nalgebra::Transform::identity() {
Self::build_inner(shape, settings)
} else {
let shape = shape.clone().apply_transform(t.into());
let mut out = Self::build_inner(&shape, settings);

// Apply the reverse transform to vertex coordinates
let ti = t.matrix().try_inverse().unwrap();
for v in &mut out.verts {
let p: nalgebra::Point3<f32> = v.pos.into();
let q = ti.transform_point(&p);
v.pos = q.coords;
}
out
}
}

fn build_inner<S: Shape + Clone>(shape: &S, settings: Settings) -> Self {
Expand Down

0 comments on commit d0b1eca

Please sign in to comment.