Skip to content

Add 3D mesh visualization with plotters#51

Merged
nash1111 merged 1 commit intomainfrom
issue-50
Feb 8, 2026
Merged

Add 3D mesh visualization with plotters#51
nash1111 merged 1 commit intomainfrom
issue-50

Conversation

@nash1111
Copy link
Copy Markdown
Owner

@nash1111 nash1111 commented Feb 8, 2026

Summary

  • Add 3d_plot example that generates 5 PNG visualizations using plotters' 3D charting
  • Painter's algorithm for depth sorting + diffuse lighting shading
  • Add rendered images to README in gallery tables

Visualizations

Image Algorithm Description
marching_cubes_sphere.png Marching Cubes Sphere isosurface (884 faces)
marching_cubes_torus.png Marching Cubes Torus isosurface (1584 faces)
marching_cubes_gyroid.png Marching Cubes Gyroid isosurface (17429 faces)
voxel_mesh.png Voxel Mesh Sphere predicate, 4x4x4 resolution
octree_mesh.png Octree Sphere predicate, depth=3

Test plan

  • cargo run --release --example 3d_plot generates all 5 PNGs
  • cargo fmt --check clean
  • cargo clippy -- -D warnings clean

Closes #50

🤖 Generated with Claude Code

- 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>
Copilot AI review requested due to automatic review settings February 8, 2026 10:50
@nash1111 nash1111 merged commit 3d5585f into main Feb 8, 2026
4 checks passed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.rs to 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.

Comment on lines +75 to +80
// 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()
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +79 to +82
.partial_cmp(&face_center_depth(b, yaw, pitch))
.unwrap()
});

Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
.partial_cmp(&face_center_depth(b, yaw, pitch))
.unwrap()
});
.total_cmp(&face_center_depth(b, yaw, pitch))
});

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add 3D mesh visualization with plotters

2 participants