pivy SoRayPickAction

Need help, or want to share a macro? Post here!
looo
Posts: 2741
Joined: Mon Nov 11, 2013 5:29 pm

pivy SoRayPickAction

Postby looo » Tue Sep 23, 2014 8:17 pm

In the coin documentation for SoRayPickAction it is recommended to get the scene with view.getSceneManager().getSceneGraph() to have the camera-node in the path of a SoRayPickAction. I haven't found something like this in freecad. Is there a way to get the camera of the view into the traversing path?
ickby
Posts: 2914
Joined: Wed Oct 05, 2011 7:36 am

Re: pivy SoRayPickAction

Postby ickby » Wed Sep 24, 2014 3:57 am

Hello,

This depends on your free cad version. If you are on stable you can use the method getscnegraph() of the view3DInventorViewer to get the scene including the camera. On current master there was a change yesterday that changed this. Now the getscenegraph() method returns only the geometry scene. If you want the one with the camera you need to call getSoRenderManager().getscenegraph() on the View3DInventorViewer
looo
Posts: 2741
Joined: Mon Nov 11, 2013 5:29 pm

Re: pivy SoRayPickAction

Postby looo » Wed Sep 24, 2014 10:09 pm

Thanks, I have compiled a newer version and the SoRenderManager is working. But now another problem occurs: For the raypick I will need the ViewportRegion. Any idea where I can find it?

OS: Debian GNU/Linux unstable (sid)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.15.4075 (Git)
Branch: master
Hash: dfd2eb33273dd7dfb802f3cde2bd384206903685
Python version: 2.7.8
Qt version: 4.8.6
Coin version: 4.0.0a
ickby
Posts: 2914
Joined: Wed Oct 05, 2011 7:36 am

Re: pivy SoRayPickAction

Postby ickby » Thu Sep 25, 2014 3:37 am

GetSoRenderManager()->getViewportRegion() should work
looo
Posts: 2741
Joined: Mon Nov 11, 2013 5:29 pm

Re: pivy SoRayPickAction

Postby looo » Thu Sep 25, 2014 6:50 am

My freecad crashed with this command. (GUI.ActiveDocument.ActiveView.getViewer(). getSoRenderManager().getViewportRegion()) Previously I had to import soqt to get the viewportregion. Maybe there is something similuar with the new system?
ickby
Posts: 2914
Joined: Wed Oct 05, 2011 7:36 am

Re: pivy SoRayPickAction

Postby ickby » Thu Sep 25, 2014 6:54 am

does getViewer() return a valid object? and returns getSoRenderManager a valid object?

SoQt is not needed anymore, you will need to import coin, but I suppose that you did so already?
wmayer
Site Admin
Posts: 14620
Joined: Thu Feb 19, 2009 10:32 am

Re: pivy SoRayPickAction

Postby wmayer » Thu Sep 25, 2014 3:10 pm

What was your exact Python code to get the viewport with the old soqt stuff?
looo
Posts: 2741
Joined: Mon Nov 11, 2013 5:29 pm

Re: pivy SoRayPickAction

Postby looo » Thu Sep 25, 2014 6:01 pm

does getViewer() return a valid object? and returns getSoRenderManager a valid object?
the crash is happening when doing this comand: RenderManager.getViewportRegion(). No problem with the getViewer() and getSoRenderManager().
SoQt is not needed anymore, you will need to import coin, but I suppose that you did so already?
I tried both (with coin imported and withoout) but always get the crash afer doing the getViewportRegion() command and moving the mouse over the scene.
What was your exact Python code to get the viewport with the old soqt stuff
I haven't got it anymore. I will try to reproduce on another machine and post here.
looo
Posts: 2741
Joined: Mon Nov 11, 2013 5:29 pm

Re: pivy SoRayPickAction

Postby looo » Sat Sep 27, 2014 4:08 pm

here is the way how I get the Viewportregion in older freecad version:

from pivy.gui import soqt
view = Gui.ActiveDocument.ActiveView
viewer = view.getViewer()
viewportregion = viewer.getViewportRegion()

Version info:

OS: Ubuntu 14.04.1 LTS
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.15.3989 (Git)
Branch: master
Hash: 7318a1d443c34c29b16aa44c89b371123ffc6f9f
Python version: 2.7.6
Qt version: 4.8.6
Coin version: 4.0.0a
SoQt version: 1.6.0a
OCC version: 6.7.1
looo
Posts: 2741
Joined: Mon Nov 11, 2013 5:29 pm

Re: pivy SoRayPickAction

Postby looo » Sat Sep 27, 2014 8:12 pm

same error with daily build in ubuntu. after getting the viewport and moving the mouse freecad crashes.