Home › Forum › SOFA › Using SOFA › [SOLVED] SofaPython3 pygame rendering example not working
Tagged: 64_bits, Linux_ubuntu, Plugin_other, SOFA_other, SofaPython3
- This topic has 9 replies, 5 voices, and was last updated 3 years, 7 months ago by Hugo.
-
AuthorPosts
-
14 January 2021 at 12:36 #18218beichunBlocked
Hi. I am running the pygame example of SofaPython3 plugin and got the following error:
Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python3.7/threading.py", line 926, in _bootstrap_inner self.run() File "/usr/lib/python3.7/threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "/home/beichun/my-sofa/SofaPython3/examples/pygame_renderingloop/backend_pygame.py", line 27, in startUI fct(display, time) File "/home/beichun/my-sofa/SofaPython3/examples/pygame_renderingloop/backend_pygame.py", line 35, in draw Sofa.Simulation.glewInit() AttributeError: module 'Sofa.Simulation' has no attribute 'glewInit'
Is there a quick fix to this? Thanks.
14 January 2021 at 22:36 #18230HugoKeymasterHey @beichun
I have not tried this example yet. I will test it and give you feedback.
Which branch of SOFA/SofaPython3 are you using?
Best,
Hugo
15 January 2021 at 07:18 #18234beichunBlockedHi @Hugo,
Thanks for your reply.
I’m using the master branch for both SOFA and SofaPython3.25 January 2021 at 03:18 #18383beichunBlockedHi, any updates on this?
I saw the pygame example is removed from SofaPython3 repo. I wonder if there is any workaround if I still want to use the same feature.5 February 2021 at 09:47 #18513jnbrunetModeratorHey @beichun
We removed this example since it was broken and to fix it would required us to pull GUI dependencies from SOFA into the bindings of
sofa::simulation
only to initalize GL (see here).For now, if you want to make it work, you can create c++ bindings that does just that: initialize glew and call sofa::simulation::draw() whenever you need the scene to be draw in your qt context.
There has been a recent PR here that isolate OpenGL code from SOFA into a single module. It would therefore be possible to add bindings for this specific module in SofaPython3 without creating a dependency between the binding of
sofa::simulation
and OpenGl. This is however not in our development plan for SP3 and would require someone from the community to spend some of its time on this.I hope that answers your question.
J-N5 February 2021 at 12:30 #18535psomersBlockedHey @jnbrunet
Thanks for clearing this up. For the convenience of those that find this thread and want to do their own hack before someone adds proper bindings, here is what I did:
in SofaPython3\bindings\Sofa\src\SofaPython3\Sofa\Simulation\Submodule_Simulation.cpp add
#ifndef SOFA_NO_OPENGL #include <sofa/gl/DrawToolGL.h> #endif
and
#ifndef SOFA_NO_OPENGL simulation.def("draw", [](Node* n){ auto* vparam = sofa::core::visual::VisualParams::defaultInstance(); vparam->drawTool() = new sofa::gl::DrawToolGL(); vparam->setSupported(sofa::core::visual::API_OpenGL); sofa::simulation::getSimulation()->draw(vparam, n); }); simulation.def("glewInit", []() { glewInit(); }); #endif
in SofaPython3\bindings\Sofa\src\SofaPython3\Sofa\Simulation\CMakeLists.txt add
find_package(Sofa.GL REQUIRED) # in the SP3_add_python_module call: DEPENDS SofaCore SofaSimulationCore SofaSimulationGraph SofaPython3::Plugin Sofa.GL
25 February 2021 at 23:30 #18753HugoKeymasterThanks for backing up people reading your post @psomers
I close the topic in the mean if this is fine for you two. If I missed somehting, please do not hesitate to reopen it.Best wishes,
Hugo
1 March 2021 at 11:17 #18755psomersBlockedThanks Hugo,
May be worth throwing here that a fix has been added to SofaPython3 for this.
https://github.com/sofa-framework/SofaPython3/pull/109So definitely a closed issue.
Cheers,
Peter9 April 2021 at 17:29 #19120etagliabueBlockedHi everyone,
I know this issue has been already closed but I have a related question. I am wondering if it would be possible to replicate the pygame example using the old SofaPython (thus, python2). As far as I understand, I could use pygame and pyopengl to create a separate OpenGL context, but I am not sure that I will be able to redirect a view of my simulation there (I am missing something that does the same as
Sofa.SofaGL.draw
, line 47). Do you have any suggestion or ideas?Unfortunately, I need to stick to python2 version to interface my simulation with another program.
Thanks!
9 April 2021 at 17:57 #19123HugoKeymasterCiao @eleonora
Unfortunately, with the SofaPython plugin (2.7), no binding was existing to trigger the SOFA draw process (corresponding to:
sofa::simulation::getSimulation()->draw(vparam, node);
).I guess this could be added to the SP2 API. But I am no master of python bindings 🙁
Sorry about thisHugo
-
AuthorPosts
- You must be logged in to reply to this topic.