CadQuery / CQ-editor

CadQuery GUI editor based on PyQT
Apache License 2.0
757 stars 116 forks source link

Add clipping plane support for X/Y/Z dimensions. #391

Open petejohanson opened 1 year ago

petejohanson commented 1 year ago

Adding this as a draft to get some feedback on the approach/direction. This would close #311 when completed.

Outstanding questions:

I also know the GUI for the clipping plane widget is lame, I will clean it up, but wanted some early feedback first.

Thanks for the great project!

codecov[bot] commented 1 year ago

Codecov Report

Merging #391 (b111555) into master (88d2f7e) will decrease coverage by 0.27%. The diff coverage is 78.31%.

:exclamation: Current head b111555 differs from pull request most recent head e55569b. Consider uploading reports for the commit e55569b to get more accurate results

@@            Coverage Diff             @@
##           master     #391      +/-   ##
==========================================
- Coverage   88.93%   88.67%   -0.27%     
==========================================
  Files          19       20       +1     
  Lines        1537     1616      +79     
  Branches      185      189       +4     
==========================================
+ Hits         1367     1433      +66     
- Misses        137      152      +15     
+ Partials       33       31       -2     
Impacted Files Coverage Δ
cq_editor/widgets/viewer.py 85.16% <66.66%> (-3.36%) :arrow_down:
cq_editor/widgets/clipping_planes.py 84.00% <84.00%> (ø)
cq_editor/main_window.py 93.71% <100.00%> (+0.12%) :arrow_up:

... and 1 file with indirect coverage changes

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

adam-urbanczyk commented 1 year ago

Adding this as a draft to get some feedback on the approach/direction. This would close #311 when completed.

Thanks, I will definitely merge this.

Outstanding questions:

* Should we set a capping color, or just leave it transparent?

Maybe use the part color + hatch?

* Should we also set a texture for the capping? Some viewers will use a diagonal hatch type pattern.

See above

* Right now, I'm setting the clipping plane for the whole viewer, which results in the X/Y/Z _helper_ objects also getting clipped. I personally actually _like_ this because you can see where the clipping plane ends, but if folks don't like that I can try to look at adding the clipping plane only to certain objects.

Sounds fine

* I used the color from the dimension for the cap color on each dimension. Thoughts?

Would part color be a possibility? I did not look into the OCCT API for this.

I also know the GUI for the clipping plane widget is lame, I will clean it up, but wanted some early feedback first.

Hm, maybe add the planes as helpers and control their properties via the existing property editor?

petejohanson commented 1 year ago

Adding this as a draft to get some feedback on the approach/direction. This would close #311 when completed.

Thanks, I will definitely merge this.

🎉

Outstanding questions:

* Should we set a capping color, or just leave it transparent?

Maybe use the part color + hatch?

So, I tried to just use the hatch API, and it failed to hatch. Some quick googling showed that some GL implementations don't actually support this, and the suggestion was just to use a texture map instead.

* Should we also set a texture for the capping? Some viewers will use a diagonal hatch type pattern.

See above

* Right now, I'm setting the clipping plane for the whole viewer, which results in the X/Y/Z _helper_ objects also getting clipped. I personally actually _like_ this because you can see where the clipping plane ends, but if folks don't like that I can try to look at adding the clipping plane only to certain objects.

Sounds fine

* I used the color from the dimension for the cap color on each dimension. Thoughts?

Would part color be a possibility? I did not look into the OCCT API for this.

Yeah. This was my next thing to investigate. I will investigate if I can hook into the object added signal and then add a custom clipping plane to each part with a matching color.

I also know the GUI for the clipping plane widget is lame, I will clean it up, but wanted some early feedback first.

Hm, maybe add the planes as helpers and control their properties via the existing property editor?

That's an interesting idea... Let me explore the helpers and property editor to see if I can make this work. I could see that being more consistent.

adam-urbanczyk commented 1 year ago

It is possible to just use the object material it seems. See:

https://dev.opencascade.org/doc/occt-7.1.0/refman/html/class_graphic3d___clip_plane.html#a836e6040401113f600a419edef323831

and

https://draw.sview.ru/visualization-clipplane/

petejohanson commented 1 year ago

So... tried to tweak things to implement per-object colors for the clipping plane... but assemblies get added to the viewer and the color I get out of it ends up being... the default color, even though it's an object composed of other objects with distinct colors:

image

I need to see if I can "break up" the assembly that comes in and add clipping planes to each.

petejohanson commented 1 year ago

Yeah, I'm not seeing any easy way to add a different clipping plane to the portions of the OCP.XCAFPrs.XCAFPrs_AISObject. I'm open to suggestions, since I'm very new to all of the internals of this.

adam-urbanczyk commented 1 year ago

I need to see if I can "break up" the assembly that comes in and add clipping planes to each.

I don't understand what you mean here. AFAICT this is supported by OCCT already, no need to implement. Did you try setting e.g. https://dev.opencascade.org/doc/refman/html/class_graphic3d___clip_plane.html#a836e6040401113f600a419edef323831

petejohanson commented 1 year ago

I need to see if I can "break up" the assembly that comes in and add clipping planes to each.

I don't understand what you mean here. AFAICT this is supported by OCCT already, no need to implement. Did you try setting e.g. https://dev.opencascade.org/doc/refman/html/class_graphic3d___clip_plane.html#a836e6040401113f600a419edef323831

I tried hooking into the display and display_many methods on the viewer to add the clipping pane to each AIS object created there... Which "works" but you end up with one single AIS object for a whole assembly, so no easy way to apply a different clipping pane w/ different color to each element in the assembly.

Does that make sense?

adam-urbanczyk commented 1 year ago

Yes and no. My claim (based on quickly inspecting OCCT code) is that this will be solved by using the SetUseObjectMaterial method. Did you try it? Does your experience confirm or contradict this claim?

petejohanson commented 1 year ago

Using that method results in this:

image

petejohanson commented 1 year ago

Playing a bit more, it seems that using that method, it uses the color of the first item added to the assembly as the material... So, not horrible as an experience? And for non-assemblies, it is properly picking up the color/material for each of those. Pushing the minor tweaks to use that for others to weigh in on.

Still need to work changing this to put objects in and use the existing property editor for changing the settings for each clipping plane.

adam-urbanczyk commented 1 year ago

Yes, it looks good enough.