-
Notifications
You must be signed in to change notification settings - Fork 71
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
How to use the Python bindings? #1
Comments
Hi carlo, thanks for reaching out! Unfortunately, the python bindings are incomplete at this point. The Node and Solver objects are not exposed at all, so there's no way to use them in python. This is partially due to the ownership model used by the node tree. Because child nodes are owned by parent nodes (destroying a node will destroy all children recursively) wrapping node objects for python is difficult. Python has to be notified whenever a node is deleted out from under it, as there is no way to forcefully delete a PyObject. This, among other things, annoyed me, so I rewrote a lot of the node code to use a refcount based model instead (see devel branch) but that's not in a usable state at the moment. So yeah. I can't give you a definite date as to when the python bindings become stable. My recommendation is if you need FABRIK in python and you can't wait months, it's not too hard to implement it yourself. |
I see! Thanks for the detailed answer. |
@carlo- I know it's been a while but the python API is slowly becoming usable. If you are still interested you can look at the sample I wrote. Setting it up is a bit jank at the moment but here's a step by step: Install dependencies for building with python (I'm on ubuntu): sudo apt install libpython3-dev The demo uses pygame, which needs the following packages to build: sudo apt install libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsdl1.2-dev libsmpeg-dev libportmidi-dev libswscale-dev libavformat-dev libavcodec-dev Clone and checkout a version that works. I'm just giving you the commit hash for one that I know works. git clone https://github.com/thecomet/ik
cd ik
git checkout e60e091d035e33a2ff491cdf8a0e77ec78a9d08f Build as a python module: mkdir build && cd build
cmake -DIK_PYTHON=ON ../
make Set up a virtualenv in the samples folder: cd ../samples/python-editor
virtualenv -p /usr/bin/python3 venv Get the absolute path to echo /home/thecomet/programming/ik/build/ik > venv/lib/python3.8/site-packages/ik.pth Activate the virtualenv and install pygame: source venv/bin/activate
pip install pygame Now you can run the demo: python ik-editor.py |
I tried following these instructions, but both I eventually noticed the error was referring to a git submodule, so from main project dir I ran:
Then returned to build dir and repeated the cmake and make commands, which completed and have produced an ik.so which I can import into python:
This was on current HEAD of Just completed the remaining virtualenv/pygame steps and the default ik-editor example works too. (I tried uncommenting the |
Hey! The human example works on 430fe60 if you want to give that a go. I'm sorry to have caused so much trouble, but sadly this library just isn't ready yet to be used properly. I am trying to satisfy many different needs and keep making pretty major changes. |
Thanks. This was far less effort compared to other IK projects I've been trying to use - simply having something that compiles is a big step forward. |
I am also trying to build e60e09, but it fails to compile with the "-DIK_PYTHON=ON" flag. |
@LiorKirsch I'm trying to reproduce this error but am unable to. I think you forgot to checkout e60e091 because Oh, when you check out a specific revision, also make sure to run |
Thanks for the help. Here is what I am doing: Here is the compilation error I get /ik/ik/src/python/ik_type_Node.c:1174:9: error: implicit declaration of function ‘Py_RETURN_RICHCOMPARE’; did you mean ‘Py_RETURN_NONE’? [-Wimplicit-function-declaration] |
@LiorKirsch What python version are you on? I'm not sure when they introduced that macro but I think it's 3.7 or later. You can probably just copy/paste the following into /* Rich comparison opcodes */
#define Py_LT 0
#define Py_LE 1
#define Py_EQ 2
#define Py_NE 3
#define Py_GT 4
#define Py_GE 5
/*
* Macro for implementing rich comparisons
*
* Needs to be a macro because any C-comparable type can be used.
*/
#define Py_RETURN_RICHCOMPARE(val1, val2, op) \
do { \
switch (op) { \
case Py_EQ: if ((val1) == (val2)) Py_RETURN_TRUE; Py_RETURN_FALSE; \
case Py_NE: if ((val1) != (val2)) Py_RETURN_TRUE; Py_RETURN_FALSE; \
case Py_LT: if ((val1) < (val2)) Py_RETURN_TRUE; Py_RETURN_FALSE; \
case Py_GT: if ((val1) > (val2)) Py_RETURN_TRUE; Py_RETURN_FALSE; \
case Py_LE: if ((val1) <= (val2)) Py_RETURN_TRUE; Py_RETURN_FALSE; \
case Py_GE: if ((val1) >= (val2)) Py_RETURN_TRUE; Py_RETURN_FALSE; \
} while (0) |
I can confirm that upgrading to python3.8 solved these errors. Many thanks. |
Hi @sulei1998 Sorry for the inconvenience. I did a history rewrite. The commit hash has changed to 35bcb3d git clone https://github.com/thecomet/ik
cd ik
git checkout 35bcb3d2a60f8214c83264eba3542884438038e2
git submodule init
git submodule update
mkdir build && cd build
cmake -DIK_PYTHON=ON ../
make -j |
Thanks for your quick reply! I followed your guide. git clone https://github.com/thecomet/ik
cd ik
git checkout 35bcb3d2a60f8214c83264eba3542884438038e2
git submodule init
git submodule update
mkdir build && cd build
cmake -DIK_PYTHON=ON ../
make -j
> But, I am still not able to compile it sucessefully. /usr/bin/ld: /usr/local/lib/libpython3.8.a(_warnings.o): relocation R_X86_64_PC32 against symbol `_PyRuntime' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: The last link failed: wrong value
collect2: error: ld returned 1 exit status
ik/CMakeFiles/ik.dir/build.make:157: recipe for target 'ik/ik.so.0.2.0' failed
make[2]: *** [ik/ik.so.0.2.0] Error 1
CMakeFiles/Makefile2:250: recipe for target 'ik/CMakeFiles/ik.dir/all' failed
make[1]: *** [ik/CMakeFiles/ik.dir/all] Error 2
Makefile:148: recipe for target 'all' failed
make: *** [all] Error 2 Could you give me some advice? |
@sulei1998 Most likely you don't have the shared library of libpython installed. You can try: cmake -DPython_USE_STATIC_LIBS=FALSE ../ to enforce finding the shared libs only. Make sure you have |
Thanks for your kind help! Now i can run the ik-editor.py! Have a good day! :) |
I'm interested in running the FABRIK solver from Python, but the bindings don't seem to work. I'm unable to initialize the solver (it seems that the call to the initializer is commented out) and other classes as well. Do you have any pointers on how to make it work?
The text was updated successfully, but these errors were encountered: