"Solid" clipping plane

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
pablogil
Posts: 519
Joined: Wed Nov 26, 2014 3:19 pm
Location: Badajoz (Spain)
Contact:

"Solid" clipping plane

Postby pablogil » Wed Oct 26, 2016 10:29 am

Hi,

I really like and often use the clipping plane but I don't like how it cuts the solids, I mean, if it's a solid the cut is supposed to continue solid and, therefore show a "solid cutted part"... something like:
object_cliping.png
object_cliping.png (62.09 KiB) Viewed 884 times


Would it be easy to code? and, is it interesting also for you?

Thanks
Dark and Light stylesheets v2.0 to theme your FreeCAD UI, more information here
looo
Posts: 778
Joined: Mon Nov 11, 2013 5:29 pm

Re: "Solid" clipping plane

Postby looo » Wed Oct 26, 2016 10:59 am

This would be nice to have (especially for sketching on an object). But I don't think coin already provides some methods for this. Maybe it's possible to write an extension for coin. I think the right way to do it is described here: https://www.opengl.org/archives/resourc ... ode10.html

there was already a topic about this: viewtopic.php?f=3&t=4371
pablogil
Posts: 519
Joined: Wed Nov 26, 2014 3:19 pm
Location: Badajoz (Spain)
Contact:

Re: "Solid" clipping plane

Postby pablogil » Wed Oct 26, 2016 11:28 am

looo wrote:This would be nice to have (especially for sketching on an object). But I don't think coin already provides some methods for this. Maybe it's possible to write an extension for coin. I think the right way to do it is described here: https://www.opengl.org/archives/resourc ... ode10.html

there was already a topic about this: viewtopic.php?f=3&t=4371

Wow, thanks for pointing me out this old thread, I have no tried seeing if there was a previous one about the subject... sorry about that.

I have also read the OpenGL method you linked and seems a nice and probably easy way to accomplish it but I'm not programmer so I have no idea, any of you?

Thanks
Dark and Light stylesheets v2.0 to theme your FreeCAD UI, more information here
ickby
Posts: 2462
Joined: Wed Oct 05, 2011 7:36 am

Re: "Solid" clipping plane

Postby ickby » Wed Oct 26, 2016 11:35 am

It is a bit more complicated. The thing is that the shown stencil technique works with the opengl objects, hence this happens for every object that gets clipped. In FreeCAD however this makes only sense for solids. Not for Meshes or Shells, which are by definition void. Hence one would need to create a object dependend clipping system. Otherwise the current situation would just be inverted, from "Why are Solids shown void?" to "Why are empty objects shown filled?".
User avatar
bernd
Posts: 3924
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: "Solid" clipping plane

Postby bernd » Wed Oct 26, 2016 12:27 pm

There is a work around. In preferences 3D view deactivate the backlight color. In the view properties of the cliped object change Lighning from Two side to one side. The inner part of the object will be black thus it looks like the cut plan is black.

screen.jpg
screen.jpg (168.56 KiB) Viewed 843 times
pablogil
Posts: 519
Joined: Wed Nov 26, 2014 3:19 pm
Location: Badajoz (Spain)
Contact:

Re: "Solid" clipping plane

Postby pablogil » Wed Oct 26, 2016 5:08 pm

ickby wrote:It is a bit more complicated. The thing is that the shown stencil technique works with the opengl objects, hence this happens for every object that gets clipped. In FreeCAD however this makes only sense for solids. Not for Meshes or Shells, which are by definition void. Hence one would need to create a object dependend clipping system. Otherwise the current situation would just be inverted, from "Why are Solids shown void?" to "Why are empty objects shown filled?".

I understand but maybe an simple checkbox in the Clipping plane tool to turn it off and on could do the trick. Then it would turn not into if the concept is wrong or not, but how the user wants to view this specific cut...

bernd wrote:There is a work around. In preferences 3D view deactivate the backlight color. In the view properties of the cliped object change Lighning from Two side to one side. The inner part of the object will be black thus it looks like the cut plan is black.

Yes, I saw it on the link @loo shared with me, a really clever trick but it only works with one clipping, if you turn, for instance, two of them then you can "see" the trick:
double_clipping.png
double_clipping.png (55.07 KiB) Viewed 807 times
Dark and Light stylesheets v2.0 to theme your FreeCAD UI, more information here
looo
Posts: 778
Joined: Mon Nov 11, 2013 5:29 pm

Re: "Solid" clipping plane

Postby looo » Thu Apr 20, 2017 12:12 pm

ickby wrote:It is a bit more complicated. The thing is that the shown stencil technique works with the opengl objects, hence this happens for every object that gets clipped.


Are you sure this is true? With pivy it's possible to add a SoClipPlane as a node somewhere in the scenegraph. Only nodes after the clip-plane are shown clipped.
And the stencil-technique is applied to one plane if I understand it. So if we can figure out the opengl plane corresponding to the SoClipPlane it should be possible to "close" only the clipped solid.

Code: Select all

from pivy import coin
import FreeCAD as App
import FreeCADGui as Gui
doc = App.newDocument()
sg = Gui.ActiveDocument.ActiveView.getSceneGraph()
root = coin.SoSeparator()
sphere = coin.SoSphere()
cube = coin.SoCube()
normal = coin.SbVec3f(0,0, 1)
point = coin.SbVec3f(0, 0, 0)
plane = coin.SbPlane(normal, point)
clip = coin.SoClipPlane()
clip.plane = plane
trans = coin.SoTransform()
trans.translation.setValue(coin.SbVec3f(2, 0, 0))
sg.addChild(cube)
sg.addChild(clip)
sg.addChild(trans)
sg.addChild(sphere)



I am now trying to add the opengl stencil-buffer technique which can be found here. First I wanted to try it with PyOpenGl. But the problem I encounter is this line in the example:

Code: Select all

EarthSurface->Draw();

I think this should be equivalent to rendering the scene behind the clipped plane. But somehow I can't apply the SoGLRenderAction at a node which is not the root.
looo
Posts: 778
Joined: Mon Nov 11, 2013 5:29 pm

Re: "Solid" clipping plane

Postby looo » Thu Apr 20, 2017 1:56 pm

Maybe this is what I need: SoNode::GLRenderBelowPath
But also this doesn't work with python:

Code: Select all

Traceback (most recent call last):
  File "SoClipPlane.py", line 49, in myCallbackRoutine
    cap.stencilBuffer(action)
  File "SoClipPlane.py", line 28, in stencilBuffer
    self.node.GLRenderBelowPath(action)
  File "~/conda/envs/freecad/lib/python3.5/site-packages/pivy/coin.py", line 4804, in GLRenderBelowPath
    return _coin.SoNode_GLRenderBelowPath(self, action)
TypeError: in method 'SoNode_GLRenderBelowPath', argument 2 of type 'SoGLRenderAction *'
ickby
Posts: 2462
Joined: Wed Oct 05, 2011 7:36 am

Re: "Solid" clipping plane

Postby ickby » Thu Apr 20, 2017 2:17 pm

I'm not really sure, I'm not very familiar with OpenGL. But i always thought that the opengl clipping works on the whole scene. Don't know how coin does handle it with it's clipping. But would be nice if you find a way to make this work :)
looo
Posts: 778
Joined: Mon Nov 11, 2013 5:29 pm

Re: "Solid" clipping plane

Postby looo » Fri Apr 21, 2017 10:59 am

ickby wrote:Don't know how coin does handle it with it's clipping. But would be nice if you find a way to make this work


Ok, a basic example works now:
https://github.com/looooo/pivy/blob/mas ... ipPlane.py
capping.png
capping.png (17.38 KiB) Viewed 164 times


With OpenGL it works this way:
1. draw front faces and decrease stencil-buffer where the front_face is drawn
2. disable drawing to Color-buffer and draw the back-face to the stencil-buffer (increase)
3. render a plane where the stencil-buffer is not 0 (for a solid this is every location where only the back-face is visible)

The trick to not clip the whole scene is to enable a clip plane somewhere in the render-transversal and disable after a certain node/group is drawn.

How to implement this in coin is another question but I think by looking at the implementation of the SoClipPlane this shouldn't be a too big problem. Another thing I was reading about is the use of SoOffScreenRenderer with the stencil-buffer.... https://github.com/looooo/coin3d/blob/m ... p#L219L237