Skip to content

(Part 2/3) Project 3D part to plane#2002

Open
antonysigma wants to merge 14 commits into
CadQuery:masterfrom
antonysigma:project-to-viewpoint
Open

(Part 2/3) Project 3D part to plane#2002
antonysigma wants to merge 14 commits into
CadQuery:masterfrom
antonysigma:project-to-viewpoint

Conversation

@antonysigma

Copy link
Copy Markdown

Simulate the API from Build123d project_to_viewpoint: Given a 3D vector representing the camera position pointing at the origin (0,0,0), render all visible edges/arcs/splines representing the outline of the 3D part projected to the camera.

Also render all hidden edges/arcs/splines.

Provide and example script tests/test_projection.py where a generic part (A bracket with rounded corners and a countersunk hole) is projected to top view, side view, front view, and orthogonal view, and then exported to DXF 2D drawings.

Reference: https://build123d.readthedocs.io/en/latest/tech_drawing_tutorial.html

Expected output from tests/test_projection.py:

image

Follow-up of MR #2001 .
Related to: #122, #1767

Comment thread tests/test_projection.py Outdated
Comment thread tests/test_projection.py Outdated
Comment thread cadquery/occ_impl/projection.py Outdated
@antonysigma antonysigma force-pushed the project-to-viewpoint branch 2 times, most recently from 97a6903 to d975b18 Compare February 27, 2026 21:23
@adam-urbanczyk

Copy link
Copy Markdown
Member

OK, let's get this going. @antonysigma could you run our version of black in the codebase?

@antonysigma antonysigma force-pushed the project-to-viewpoint branch from d975b18 to 8de8187 Compare March 12, 2026 17:43
@antonysigma

Copy link
Copy Markdown
Author

OK, let's get this going. @antonysigma could you run our version of black in the codebase?

Done running black and pushed the new commit. Let me know if you need anything else.

@adam-urbanczyk

Copy link
Copy Markdown
Member

Still failing on black, did you use our version of the tool?

@antonysigma antonysigma force-pushed the project-to-viewpoint branch from 8de8187 to c646aee Compare March 15, 2026 00:38
@antonysigma

Copy link
Copy Markdown
Author

Still failing on black, did you use our version of the tool?

My apologies. I mixed up darker with black. I pushed the revisions again.

@adam-urbanczyk

Copy link
Copy Markdown
Member

OK, next step to make the CI green is to fix mypy errors. Are you up to it @antonysigma ?

@antonysigma

Copy link
Copy Markdown
Author

OK, next step to make the CI green is to fix mypy errors. Are you up to it @antonysigma ?

I can help resolve new mypy errors caused by this PR, but I don't where the rest of the errors originated from. Were those errors introduced before my PR? Could you teach me how to program Appveyor's CI to ignore errors before my PR?

@adam-urbanczyk

Copy link
Copy Markdown
Member

There are no mypy issues on HEAD according to our CI. So I assume that everything is on your side. No need to do anything with appveyor,, you can run mypy locally and simply fix all the errors. If this sounds too complicated, we can probably help.

Simulate the API from Build123d `project_to_viewpoint`: Given a 3D
vector representing the camera position pointing at the origin
`(0,0,0)`, render all visible edges/arcs/splines representing the outline
of the 3D part projected to the camera.

Also render all hidden edges/arcs/splines.

Provide and example script `tests/test_projection.py` where a generic
part (A bracket with rounded corners and a countersunk hole) is
projected to top view, side view, front view, and orthogonal view, and
then exported to DXF 2D drawings.

Reference: https://build123d.readthedocs.io/en/latest/tech_drawing_tutorial.html
@antonysigma antonysigma force-pushed the project-to-viewpoint branch from c646aee to 4552668 Compare March 23, 2026 18:42

@antonysigma antonysigma left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Hi @adam-urbanczyk ,

Yes, I need help resolving mypy errors, especially those exists before this PR.

Please refer to the inline comments for the out-of-scope errors.

-Antony

Comment thread cadquery/occ_impl/exporters/svg.py
Comment thread cadquery/occ_impl/exporters/svg.py
@codecov

codecov Bot commented Apr 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.79%. Comparing base (09773f4) to head (1263b15).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2002      +/-   ##
==========================================
+ Coverage   95.76%   95.79%   +0.02%     
==========================================
  Files          30       30              
  Lines        9376     9432      +56     
  Branches     1395     1404       +9     
==========================================
+ Hits         8979     9035      +56     
  Misses        242      242              
  Partials      155      155              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread cadquery/occ_impl/shapes.py Outdated
Comment thread cadquery/occ_impl/shapes.py Outdated
@antonysigma

Copy link
Copy Markdown
Author

Thank you for doing the dirty laundry for me. It is certainly a daunting process for me to understand the legacy DXF code in the repo, not to mention patching it. I appreciate the effort.

Comment thread cadquery/occ_impl/shapes.py


def hlr(
shape, pnt: VectorLike, dir: VectorLike, focus: float | None = None,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would like to provide an "up" direction with default (0, 0, 1) either in this PR or follow up. Otherwise we continue to have the problem of uncontrolled orientation.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1

hlr = HLRBRep_Algo()
hlr.Add(shape.wrapped)

coordinate_system = gp_Ax2(Vector(pnt).toPnt(), Vector(dir).toDir())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I could take a look at adding the "up" direction. I had started on that in #1277. We can either define a fallback as in #1277 or return a ValueError when up and dir are parallel.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sure, go for it.

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.

3 participants