Skip to content

Conversation

@Gip-Gip
Copy link

@Gip-Gip Gip-Gip commented Nov 18, 2025

An origin is now stored in a private field in sketches that allows the end user to place and extrude sketches at any coordinate in 3d space. Along with the origin is another private field which stores the transform data that is needed to transform each point when meshing.

High-level PR Summary

This PR adds the ability to position and orient 2D sketches in 3D space before extrusion by introducing an origin field (stored as a Vertex) to both Sketch and Mesh structures. The implementation includes transformation logic using quaternions to rotate sketch geometry according to the origin's normal vector, along with a new build_graphic_line_strings method for 3D visualization of sketch edges. The origin and its pre-computed transformation data are propagated through all sketch and mesh operations including CSG operations, extrusions, and conversions.

⏱️ Estimated Review Time: 30-90 minutes

💡 Review Order Suggestion
Order File Path
1 src/mesh/vertex.rs
2 src/sketch/mod.rs
3 src/sketch/shapes.rs
4 src/sketch/hershey.rs
5 src/sketch/extrudes.rs
6 src/mesh/mod.rs
7 src/mesh/flatten_slice.rs
8 src/sketch/offset.rs

Need help? Join our Discord

@gemini-code-assist
Copy link

Summary of Changes

Hello @Gip-Gip, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the geometric modeling capabilities by introducing a robust 3D origin and transformation system for Sketch objects. It enables users to define 2D sketches at arbitrary positions and orientations in 3D space, and then seamlessly extrude or convert them into 3D meshes that accurately reflect their intended spatial placement. Furthermore, it provides new utilities for generating 3D graphic line representations of sketches, which are invaluable for visualization and integration into 3D printing workflows.

Highlights

  • Sketch Origin and 3D Placement: The Sketch struct now includes an origin field (a Vertex) and an origin_transform to define its position and orientation in 3D space. This allows 2D sketches to be placed and manipulated anywhere in a 3D environment before being converted to meshes.
  • Integrated 3D Transformation: New macros (apply_origin_transform!, apply_origin_transform_graphicpoint!) and a helper function (prepare_origin_vec_and_quat) have been added to apply the sketch's origin transformation to its geometry, ensuring that extruded meshes and graphic representations are correctly positioned and oriented in 3D.
  • 3D Graphic Line Generation: A new build_graphic_line_strings method allows generating 3D line representations of sketches, respecting their defined origin. This functionality is crucial for visualization, debugging, or exporting data for 3D printing applications.
  • Mesh Origin Propagation: The Mesh struct has been updated to also store an origin, ensuring that 3D meshes created from sketches or other operations retain their spatial context and can be consistently transformed.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@recurseml recurseml bot left a comment

Choose a reason for hiding this comment

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

Review by RecurseML

🔍 Review performed on 278e025..acff835

✨ No bugs found, your code is sparkling clean

✅ Files analyzed, no issues (7)

src/mesh/flatten_slice.rs
src/mesh/mod.rs
src/mesh/vertex.rs
src/sketch/extrudes.rs
src/sketch/hershey.rs
src/sketch/offset.rs
src/sketch/shapes.rs

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces an origin to sketches and meshes, allowing them to be positioned and oriented in 3D space. The changes are extensive, touching CSG operations, extrusions, and conversions to propagate this new origin information. My review found a few issues. There are critical bugs in the new transformation macros that would lead to incorrect geometry when a 180-degree rotation is needed. Additionally, the revolve function has been partially updated but is missing the application of the origin transform to its generated geometry, making it inconsistent with other extrusion functions. I've provided detailed comments and suggestions for these issues.

Comment on lines 54 to 55
out_vertex.pos.coords = quat2 * $in_vertex.pos.coords;
out_vertex.normal = quat2 * $in_vertex.normal;

Choose a reason for hiding this comment

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

critical

There's a bug in the apply_origin_transform! macro when two quaternions are used for rotation. The second rotation quat2 is applied to the original vertex position and normal ($in_vertex), overwriting the result of the first rotation (quat1). It should be applied to the already-rotated out_vertex to compose the rotations correctly.

Suggested change
out_vertex.pos.coords = quat2 * $in_vertex.pos.coords;
out_vertex.normal = quat2 * $in_vertex.normal;
out_vertex.pos.coords = quat2 * out_vertex.pos.coords;
out_vertex.normal = quat2 * out_vertex.normal;

out_point.coords = quat1 * $in_point.coords;

if let Some(quat2) = quat2 {
out_point.coords = quat2 * $in_point.coords;

Choose a reason for hiding this comment

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

critical

Similar to the apply_origin_transform! macro, there's a bug here. The second rotation quat2 is applied to the original point coordinates ($in_point.coords), overwriting the result of the first rotation. It should be applied to the already-rotated out_point.coords.

Suggested change
out_point.coords = quat2 * $in_point.coords;
out_point.coords = quat2 * out_point.coords;

polygons: new_polygons,
bounding_box: OnceLock::new(),
metadata: self.metadata.clone(),
origin: self.origin,

Choose a reason for hiding this comment

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

high

The origin field is now correctly propagated to the Mesh created by revolve. However, the origin_transform is not being applied to the vertices of the revolved geometry. This means the resulting mesh will be located at the world origin, not at the sketch's origin, which is inconsistent with extrude_vector.

To fix this, self.origin_transform should be passed down to the revolve_ring and build_cap_polygon helper functions. Then, the apply_origin_transform! macro should be used on each created Vertex, similar to how it's done in extrude_geometry.

@Gip-Gip
Copy link
Author

Gip-Gip commented Nov 18, 2025

Fixed the quat bugs, I'm going to need to look further into the revolve function though it looks like it will have to take more finesse.

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.

1 participant