Skip to content

Commit

Permalink
FuseSolids is working in the simplest case
Browse files Browse the repository at this point in the history
  • Loading branch information
MattFerraro committed May 15, 2024
1 parent 2e491ec commit e5e2a06
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 12 deletions.
11 changes: 9 additions & 2 deletions packages/cadmium/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,17 @@ fn stacked_cubes() {
let mut mesh = solid.truck_solid.triangulation(0.1).to_polygon();
mesh.put_together_same_attrs(0.1);
let v = mesh.volume();
println!("\nvolume: {}", v);
println!("ID: {solid_id} volume: {v}");
}
let solid_ids: Vec<String> = el.solids.keys().cloned().collect();
let s0 = solid_ids[0].clone();
let s1 = solid_ids[1].clone();

// el.git_log();
el.append(Operation::FuseSolids {
solid1: s0,
solid2: s1,
});
el.git_log();
}

fn simple_cube() {
Expand Down
65 changes: 55 additions & 10 deletions packages/cadmium/src/oplog/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use crate::extrusion::fuse;
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
use std::collections::HashMap;
use std::hash::{Hash, Hasher};
use std::process::id;
use std::vec;
use truck_meshalgo::analyzers::CalcVolume;
use truck_meshalgo::filters::OptimizingFilter;
use truck_meshalgo::tessellation::{MeshableShape, MeshedShape};
use truck_polymesh::faces;
use truck_topology::{
FaceDisplayFormat, ShellDisplayFormat, SolidDisplayFormat, VertexDisplayFormat,
Expand Down Expand Up @@ -295,6 +299,29 @@ impl EvolutionLog {
unreachable!()
};
}
Operation::FuseSolids { solid1, solid2 } => {
let solid1 = self.solids.get(&solid1).unwrap();
let solid2 = self.solids.get(&solid2).unwrap();
let fused: Option<
truck_topology::Solid<
truck_meshalgo::prelude::cgmath::Point3<f64>,
truck_modeling::Curve,
truck_modeling::Surface,
>,
> = fuse(&solid1.truck_solid, &solid2.truck_solid);
match fused {
Some(fused) => {
let new_solid = Solid::from_truck_solid("alpha".to_owned(), fused);
let new_op = Operation::CreateSolid {
nonce: "Fused Solid".to_string(),
solid: new_solid.clone(),
};
self.append(new_op);
self.solids.insert(self.cursor.clone(), new_solid);
}
_ => {}
}
}
_ => {}
}

Expand Down Expand Up @@ -803,6 +830,11 @@ pub enum Operation {
nonce: String,
solid: Solid,
},

FuseSolids {
solid1: Sha,
solid2: Sha,
},
}

impl Operation {
Expand Down Expand Up @@ -940,6 +972,9 @@ impl Operation {
Operation::CreateSolid { nonce, solid } => {
hasher.update(format!("{nonce}-{solid:?}").as_bytes())
}
Operation::FuseSolids { solid1, solid2 } => {
hasher.update(format!("{solid1}-{solid2}").as_bytes())
}
}

format!("{:x}", hasher.finalize())
Expand Down Expand Up @@ -1199,17 +1234,27 @@ impl Operation {
)
}
Operation::CreateSolid { nonce, solid } => {
let mut mesh = solid.truck_solid.triangulation(0.1).to_polygon();
// mesh.put_together_same_attrs(0.1);
format!(
"CreateSolid: {nonce} {:?}",
solid.truck_solid.display(SDF::ShellsList {
shell_format: ShDF::FacesList {
face_format: FDF::LoopsList {
wire_format: WDF::VerticesList {
vertex_format: VDF::AsPoint
}
}
}
})
"CreateSolid: {nonce} Volume: {:?}",
mesh.volume(),
// solid.truck_solid.display(SDF::ShellsList {
// shell_format: ShDF::FacesList {
// face_format: FDF::LoopsList {
// wire_format: WDF::VerticesList {
// vertex_format: VDF::AsPoint
// }
// }
// }
// })
)
}
Operation::FuseSolids { solid1, solid2 } => {
format!(
"FuseSolids: {} {}",
solid1.to_owned()[..num_chars].to_string(),
solid2.to_owned()[..num_chars].to_string()
)
}
}
Expand Down

0 comments on commit e5e2a06

Please sign in to comment.