Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate higher quality meshes #87

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions packages/cadmium/src/solid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ use truck_polymesh::Point3 as TruckPoint3;
use truck_polymesh::Vector3 as TruckVector3;
use truck_topology::Solid as TruckSolid;

const MESH_TOLERANCE: f64 = 0.1;

#[derive(Tsify, Debug, Serialize, Deserialize, Clone)]
#[tsify(into_wasm_abi, from_wasm_abi)]
pub struct Solid {
Expand Down Expand Up @@ -64,8 +62,7 @@ impl Solid {
indices: vec![],
truck_solid,
};
let mut mesh = solid.truck_solid.triangulation(MESH_TOLERANCE).to_polygon();
mesh.put_together_same_attrs(0.1);
let mesh = solid.truck_solid.triangulation(0.01).to_polygon();

// the mesh is prepared for obj export, but we need to convert it
// to a format compatible for rendering
Expand Down Expand Up @@ -295,17 +292,15 @@ impl Solid {
}

pub fn to_obj_string(&self, tolerance: f64) -> String {
let mut mesh = self.truck_solid.triangulation(tolerance).to_polygon();
mesh.put_together_same_attrs(0.1);
let mesh = self.truck_solid.triangulation(tolerance).to_polygon();
let mut buf = Vec::new();
obj::write(&mesh, &mut buf).unwrap();
let string = String::from_utf8(buf).unwrap();
string
}

pub fn save_as_obj(&self, filename: &str, tolerance: f64) {
let mut mesh = self.truck_solid.triangulation(tolerance).to_polygon();
mesh.put_together_same_attrs(0.1);
let mesh = self.truck_solid.triangulation(tolerance).to_polygon();
let file = std::fs::File::create(filename).unwrap();
obj::write(&mesh, file).unwrap();
}
Expand Down
Loading