Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exportSvg doesn't hide edges that are partially visible #593

Open
MarcSallent opened this issue Jan 18, 2021 · 8 comments
Open

exportSvg doesn't hide edges that are partially visible #593

MarcSallent opened this issue Jan 18, 2021 · 8 comments
Labels

Comments

@MarcSallent
Copy link

MarcSallent commented Jan 18, 2021

This code generates two boxes, one of them crossing the other one. When exporting to SVG with exportSvg, edges that start in a visible area and then intersect the other object are rendered incorrectly.
If they go behind the other object, they are rendered correctly.

Incorrect
from cadquery import cq, Compound
nl = list()
nl.append(cq.Workplane("XY").box(.1, 2, .1, centered=(True, True, True)).val())
nl.append(cq.Workplane("XY").box(2, 1, 1, centered=(True, True, True)).val())
comp = Compound.makeCompound(nl)
cq.Workplane(comp).exportSvg("boxes.svg")

image

Correct
from cadquery import cq, Compound
nl = list()
nl.append(cq.Workplane("XY").box(.1, 2, .1, centered=(True , True, True)).translate((0,0,-1)).val())
nl.append(cq.Workplane("XY").box(2, 1, 1, centered=(True, True, True)).val())
comp = Compound.makeCompound(nl)
cq.Workplane(comp).exportSvg("boxes2.svg")

image

Cadquery 2.0 - Python 3.7 - Windows,

@MarcSallent
Copy link
Author

To add more info doing Union on the solids works as expected

ra = (cq.Workplane("XY")
      .box(.1, 2, .1, centered=(True , True, True))
      .union(cq.Workplane("XY")
             .box(2, 1, 1, centered=(True, True, True))
             )
      )
ra.exportSvg("boxes3.svg")

@adam-urbanczyk
Copy link
Member

This seems to do the trick for me:

from cadquery import cq, Compound
nl = list()
nl.append(cq.Workplane("XY").box(.1, 2, .1, centered=(True, True, True)).val())
nl.append(cq.Workplane("XY").box(2, 1, 1, centered=(True, True, True)).val())
comp = Compound.makeCompound(nl).fuse()

cq.Workplane(comp).exportSvg("boxes.svg")

@adam-urbanczyk
Copy link
Member

You want to have internal edges, I assume. Another bool op needs to be used. I think one from here: #449

@MarcSallent
Copy link
Author

I will try #449 , but I now understand that an edge crossing a solid through one of their faces (not holes) is not a natural occurence, so maybe this is not actually an issue / worth solving.
Seeing that fuse() or union() perform as expected, I would understand that this issue is closed. (I was avoiding using them to make the export faster)

@adam-urbanczyk
Copy link
Member

I'll leave the issue open. It might be good to at leas mention this in the docs.

@njourdane
Copy link

njourdane commented Apr 16, 2021

I have a similar problem. This code generates glitched svg images:

import cadquery as cq
from cadquery.cq import Workplane as WP

def rod(wp):
    return WP(wp).circle(1).extrude(8)

fig = WP('XY').box(5, 5, 5).add(rod('XY')).add(rod('XZ'))

show_object(fig)
cq.exporters.export(fig, 'figure.svg', opt={
    'projectionDir': (0.3, -0.2, 0.1),
    'showHidden': False
})

CQ-editor VS svg-export:

imageimage

And if I use union instead add it works as expected:

fig = WP('XY').box(5, 5, 5).union(rod('XY')).union(rod('XZ'))

image

Does it really make sense to have different behaviors for add and union? Is it for performance purpose?

It might be good to at leas mention this in the docs.

Feel free to use those code / images in the docs if necessary.

@marcus7070
Copy link
Member

Does it really make sense to have different behaviors for add and union?

I can see why a user would think they are related methods, but internally they are pretty much unrelated. If you look at the source you can see they do completely different things. It would be very rare you use add.

@adam-urbanczyk
Copy link
Member

The solution is to implement #449 and use it before SVG export. The HLR algo does not know what to do with interfering but unrelated solids. It is arguably a very weird use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants