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

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

petejohanson
Copy link

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

Outstanding questions:

  • Should we set a capping color, or just leave it transparent?
  • Should we also set a texture for the capping? Some viewers will use a diagonal hatch type pattern.
  • 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.
  • I used the color from the dimension for the cap color on each dimension. Thoughts?

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

codecov bot commented Mar 21, 2023

Codecov Report

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

❗ 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%) ⬇️
cq_editor/widgets/clipping_planes.py 84.00% <84.00%> (ø)
cq_editor/main_window.py 93.71% <100.00%> (+0.12%) ⬆️

... and 1 file with indirect coverage changes

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

@adam-urbanczyk
Copy link
Member

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
Copy link
Author

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
Copy link
Member

adam-urbanczyk commented Mar 21, 2023

@petejohanson
Copy link
Author

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
Copy link
Author

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
Copy link
Member

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
Copy link
Author

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
Copy link
Member

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
Copy link
Author

Using that method results in this:

image

@petejohanson
Copy link
Author

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.

* New widget for viewing the clipping plane settings.
* Update the viewer to add clipping planes.
@adam-urbanczyk
Copy link
Member

Yes, it looks good enough.

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.

Add clipping plane support
2 participants