truck icon indicating copy to clipboard operation
truck copied to clipboard

Cylindrical Mesh Improvements

Open MattFerraro opened this issue 1 month ago • 0 comments

I was able to generate a Cylinder Mesh using this code:

use truck_meshalgo::tessellation::{MeshableShape, MeshedShape};
use truck_modeling::builder::{rsweep, try_attach_plane, tsweep, vertex};
use truck_modeling::{Point3, Vector3};
use truck_polymesh::{obj, EuclideanSpace, Rad};

fn main() {
    let point = vertex(Point3::new(50.0, 0.0, 0.0));
    let circle = rsweep(&point, Point3::origin(), Vector3::unit_z(), Rad(7.0));
    let disk = try_attach_plane(&[circle]).unwrap();
    let cylinder = tsweep(&disk, Vector3::new(0.0, 0.0, 50.0));

    // save the cylinder to a file
    let mesh = cylinder.triangulation(0.01).to_polygon();
    let file = std::fs::File::create("test_cylinder.obj").unwrap();
    obj::write(&mesh, file).unwrap();
}

With the following dependencies in Cargo.toml:

truck-meshalgo = { git = "https://github.com/ricosjp/truck.git", rev = "c84318b8dec" }
truck-modeling = { git = "https://github.com/ricosjp/truck.git", rev = "c84318b8dec" }
truck-shapeops = { git = "https://github.com/ricosjp/truck.git", rev = "c84318b8dec" }
truck-polymesh = { git = "https://github.com/ricosjp/truck.git", rev = "c84318b8dec" }
truck-topology = { git = "https://github.com/ricosjp/truck.git", rev = "c84318b8dec" }
truck-stepio = { git = "https://github.com/ricosjp/truck.git", rev = "c84318b8dec" }

When I import the mesh into 3D printer slicing software (PrusaSlicer) I see that there appears to be a triangle missing from the top: Screenshot 2024-06-02 at 9 09 27 PM

When I open the mesh using MeshLab I don't see any missing triangles, but I can see that the triangle layout contains some artifacts: Screenshot 2024-06-02 at 9 07 47 PM

The biggest artifacts are three large seams that produce "eyes" on the straight edge. I think these are probably not desirable.

A secondary concern is that this mesh uses 24,578 faces, which I believe is too many. Many of these faces are on the straight edge and so could be combined with no loss in fidelity.

I know that Truck is not optimized for meshes and downstream tools could easily be used to remesh the model, but I'm using Truck to build a CAD program which needs to be able to render the shapes in real time for the user. To do that I need to generate meshes, and big meshes take a lot longer to render to the screen.

MattFerraro avatar Jun 03 '24 01:06 MattFerraro