pivy: highlevel graphics api

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

pivy: highlevel graphics api

Post by looo »

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 3205 times
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: pivy: highlevel graphics api

Post by triplus »

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
Founder
Posts: 13659
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: pivy: highlevel graphics api

Post by yorik »

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...
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: pivy: highlevel graphics api

Post by looo »

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
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: pivy: highlevel graphics api

Post by triplus »

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.
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: pivy: highlevel graphics api

Post by looo »

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
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: pivy: highlevel graphics api

Post by looo »

@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
Founder
Posts: 13659
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: pivy: highlevel graphics api

Post by yorik »

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
Veteran
Posts: 2596
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: pivy: highlevel graphics api

Post by Chris_G »

looo wrote: Sun Jun 10, 2018 5:59 pmping
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'
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: pivy: highlevel graphics api

Post by looo »

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)
Post Reply