Skip to content

Comments

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

Open
antonysigma wants to merge 1 commit intoCadQuery:masterfrom
antonysigma:project-to-viewpoint
Open

(Part 2/3) Project 3D part to plane#2002
antonysigma wants to merge 1 commit intoCadQuery:masterfrom
antonysigma:project-to-viewpoint

Conversation

@antonysigma
Copy link

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 on lines +56 to +58
# Expected DXF output to be identical to SVG output
exportSVG3rdAngleProjection(drilled, "")
exportDXF3rdAngleProjection(drilled, "")
Copy link
Author

Choose a reason for hiding this comment

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

Help wanted to move this example code to examples/ folder.

Comment on lines 15 to 19
cq.exporters.exportDXF(
visible_edges,
f"{prefix}{name}.dxf",
doc_units=6,
)
Copy link
Author

Choose a reason for hiding this comment

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

Dimensioning in Librecad:

Image

Comment on lines 14 to 55
hlr = HLRBRep_Algo()
hlr.Add(shape.val().wrapped)

coordinate_system = gp_Ax2(gp_Pnt(), gp_Dir(*projectionDir))

projector = HLRAlgo_Projector(coordinate_system)

hlr.Projector(projector)
hlr.Update()
hlr.Hide()

hlr_shapes = HLRBRep_HLRToShape(hlr)

visible = []

visible_sharp_edges = hlr_shapes.VCompound()
if not visible_sharp_edges.IsNull():
visible.append(visible_sharp_edges)

visible_smooth_edges = hlr_shapes.Rg1LineVCompound()
if not visible_smooth_edges.IsNull():
visible.append(visible_smooth_edges)

visible_contour_edges = hlr_shapes.OutLineVCompound()
if not visible_contour_edges.IsNull():
visible.append(visible_contour_edges)

hidden = []

hidden_sharp_edges = hlr_shapes.HCompound()
if not hidden_sharp_edges.IsNull():
hidden.append(hidden_sharp_edges)

hidden_contour_edges = hlr_shapes.OutLineHCompound()
if not hidden_contour_edges.IsNull():
hidden.append(hidden_contour_edges)

# Fix the underlying geometry - otherwise we will get segfaults
for el in visible:
BRepLib.BuildCurves3d_s(el, TOLERANCE)
for el in hidden:
BRepLib.BuildCurves3d_s(el, TOLERANCE)
Copy link
Author

Choose a reason for hiding this comment

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

Help wanted to reduce duplicated code.. This part is 90% similar to the code in exporters/svg.py, so it would be better if we can consolidate it.

Also, should I create a new file occ_impl/projection.py? Or, should I move it to occ_impl/geom.py?

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
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