pivy: highlevel graphics api

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

pivy: highlevel graphics api

Postby looo » Thu Apr 13, 2017 9:28 am

Pivy is a nice tool to create 3d-graphics, interactions, animations.... But there is much time needed to get used to it. I think the python interface of FreeCAD could benefit from a high-level graphics interface. Therefor I have started to transport some basic stuff to pivy. This is at the moment mostly a copy of tools I am using in the glider-workbench.
The tools will be available via from pivy import graphics

If anyone has custom pivy /coin3d code which is useful for others please let me know, or directly add it to pivy.graphics and create a PR. Any ideas are welcome.

First little demonstration of an interaction (highlighting, selecting, dragging): it's this example: https://github.com/looooo/pivy/blob/mas ... raction.py
interaction.gif
interaction.gif (495.26 KiB) Viewed 1471 times
triplus
Posts: 8364
Joined: Mon Dec 12, 2011 4:45 pm

Re: pivy: highlevel graphics api

Postby triplus » Thu Apr 13, 2017 12:13 pm

FreeCAD user interaction capability options are indeed currently a bit lacking in my opinion. To evolve the user experience further. Luckily things are changing. Although slowly but nonetheless they are.

P.S. Looking at your example i can't help to think about spline (surface).
User avatar
yorik
Site Admin
Posts: 11263
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: pivy: highlevel graphics api

Postby yorik » Thu Apr 13, 2017 8:13 pm

Does your code involves changes in the pivy swig code looo? Because otherwise it might be better to be hosted inside freecad than pivy, otherwise it will be a headache to make that reach all the distributions out there, before we can use it in freecad...
looo
Posts: 2610
Joined: Mon Nov 11, 2013 5:29 pm

Re: pivy: highlevel graphics api

Postby looo » Thu Apr 13, 2017 9:17 pm

yorik wrote:Does your code involves changes in the pivy swig code looo?
I worked on some swig stuff too, but there were not many changes done. I have never tested this with the official 0.5.0 version of pivy.

as it is possible to run the code without freecad, I think it's not a bad idea to have it available via pivy. I will try to update the pip version of pivy to a newer version (0.6.x) if there is some interest in these tools.
triplus
Posts: 8364
Joined: Mon Dec 12, 2011 4:45 pm

Re: pivy: highlevel graphics api

Postby triplus » Thu Apr 13, 2017 10:53 pm

I am guessing if the tools will be made available (more or less made available by default) there is a chance to be used in foreseeable future.
looo
Posts: 2610
Joined: Mon Nov 11, 2013 5:29 pm

Re: pivy: highlevel graphics api

Postby looo » Mon Dec 18, 2017 4:03 pm

btw.: everything is available via: https://github.com/FreeCAD/pivy/blob/ma ... _init__.py

you only have to use the pivy-fork available here: https://github.com/FreeCAD/pivy
looo
Posts: 2610
Joined: Mon Nov 11, 2013 5:29 pm

Re: pivy: highlevel graphics api

Postby looo » Sun Jun 10, 2018 5:59 pm

@yorik can you explain briefly how to use the draft snapper. I would like to use the interaction nodes for the editing-mode of some draft objects.
yorik wrote:
User avatar
yorik
Site Admin
Posts: 11263
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: pivy: highlevel graphics api

Postby yorik » Mon Jun 11, 2018 2:03 pm

looo wrote:
Sun Jun 10, 2018 5:59 pm
@yorik can you explain briefly how to use the draft snapper
Sure. There are two ways to use the snapper. This is the simple one:

Code: Select all

def cb(point):
    if point:
        print "got a 3D point: ",point

FreeCADGui.Snapper.getPoint(callback=cb)
There are more options to play with (add another callback function for mouse move, or add extra UI task controls): https://github.com/FreeCAD/FreeCAD/blob ... p.py#L1114

And the more complex one is to use directly FreeCADGui.Snapper.snap() which will simply set the mouse cursor and screen widget if a snapping location was obtained, and return a (snapped) 3D point. You must take care yourself of calling this on each mouse move, update any needed ui control, and call FreeCADGui.Snapper.off() when you are done, to restore the normal mouse cursor and clean the screen widgets.
User avatar
Chris_G
Posts: 1034
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: pivy: highlevel graphics api

Postby Chris_G » Sun Dec 02, 2018 5:41 pm

looo wrote:
Sun Jun 10, 2018 5:59 pm
ping
Hi looo,
I wanted to play with your graphics api, but I get an error (pivy 0.6.4 installed from FC-daily ppa) :

Code: Select all

>>> from pivy import graphics
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/pivy/graphics/__init__.py", line 3, in <module>
    from .colors import COLORS
ModuleNotFoundError: No module named 'pivy.graphics.colors'
looo
Posts: 2610
Joined: Mon Nov 11, 2013 5:29 pm

Re: pivy: highlevel graphics api

Postby looo » Sun Dec 02, 2018 8:36 pm

sorry for this one. I think it should work with the master-branch. At least it works for me with conda-packages (pivy 0.6.5a0)