Conversation
- Add 3d_plot example that renders 5 mesh visualizations as PNG: - Marching Cubes sphere, torus, and gyroid isosurfaces - Voxel mesh with sphere predicate - Octree mesh with sphere predicate - Uses plotters Cartesian3d with Polygon elements, painter's algorithm depth sorting, and diffuse lighting shading - Add rendered PNG images to README with gallery tables - Requires --release build due to font-kit/freetype debug mode issue Closes #50 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds a new 3D visualization example using Plotters’ 3D charts to render surface triangle meshes to PNGs, and updates the README to display the resulting gallery images.
Changes:
- Add
examples/3d_plot.rsto render Marching Cubes, voxel, and octree surface meshes to PNG with simple lighting + painter’s algorithm depth sorting. - Add generated image asset(s) under
examples/for inclusion in documentation. - Update README to document the new example command and embed the PNG gallery tables.
Reviewed changes
Copilot reviewed 2 out of 7 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| examples/3d_plot.rs | New Plotters-based 3D rendering example producing multiple PNG visualizations. |
| examples/voxel_mesh.png | Adds a rendered PNG output used in the README gallery. |
| README.md | Documents the new 3d_plot example and embeds generated images in tables. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Sort faces back-to-front (painter's algorithm) | ||
| let mut sorted_faces: Vec<&Face> = faces.iter().collect(); | ||
| sorted_faces.sort_by(|a, b| { | ||
| face_center_depth(a, yaw, pitch) | ||
| .partial_cmp(&face_center_depth(b, yaw, pitch)) | ||
| .unwrap() |
There was a problem hiding this comment.
sorted_faces.sort_by recomputes face_center_depth (and thus sin/cos) multiple times per comparison, which is unnecessarily expensive for larger meshes (e.g., gyroid). Consider precomputing a depth value per face (or caching yaw/pitch sin/cos) and sorting by that key instead.
| .partial_cmp(&face_center_depth(b, yaw, pitch)) | ||
| .unwrap() | ||
| }); | ||
|
|
There was a problem hiding this comment.
partial_cmp(...).unwrap() can panic if the depth is NaN (or otherwise not comparable). Prefer f64::total_cmp or handle the None case (e.g., treat it as equal) to make rendering robust.
| .partial_cmp(&face_center_depth(b, yaw, pitch)) | |
| .unwrap() | |
| }); | |
| .total_cmp(&face_center_depth(b, yaw, pitch)) | |
| }); |
Summary
3d_plotexample that generates 5 PNG visualizations using plotters' 3D chartingVisualizations
marching_cubes_sphere.pngmarching_cubes_torus.pngmarching_cubes_gyroid.pngvoxel_mesh.pngoctree_mesh.pngTest plan
cargo run --release --example 3d_plotgenerates all 5 PNGscargo fmt --checkcleancargo clippy -- -D warningscleanCloses #50
🤖 Generated with Claude Code