Home › Forum › SOFA › Using SOFA › How can I use python to create a scene?
Tagged: 64_bits, Linux_ubuntu, SOFA_1912
- This topic has 9 replies, 3 voices, and was last updated 4 years, 7 months ago by Hugo.
-
AuthorPosts
-
26 April 2020 at 07:19 #15941PengYuBlocked
I just start to use Sofa. The document just shows creating scene using xml and c++?
I wonder how can I creating a scene using python?26 April 2020 at 11:43 #15948HugoKeymasterHi @rainvector
Welcome to the SOFA forum!
You should consider reading through the documentation for your first steps it would help.
For your question, a dedicated article is available here. Good start with SOFA!Best wishes,
Hugo
27 April 2020 at 13:22 #15957PengYuBlocked@Hugo Thanks for your reply.
I tried to follow the steps.
When I openfountain.scn
, the scene is loaded correctly (the particles is generated). However, I got the errors as below.The
fountain.py
is in the same directory withfountain.scn.
27 April 2020 at 21:21 #15962HugoKeymasterHi @rainvector
This is (unfortunately) normal. So no worry.
The fountain scene is buggy. It supposed to spray new particles when some get out from the bowl. But the code was not that robust! I will try to find some time and fix it.Best wishes,
Hugo
28 April 2020 at 06:29 #15964PengYuBlocked@Hugo I’m still confused about creating scene using python scripts.
I have two questions.
1. Is it necessary to create a.scn
file for each scene?
2. Do I have to setRequiredPlugin
in a.scn
file?
3. In a python scripts likehouseofcards.py
, it starts fromcreateScene(node)
other thancreateScene(sofa.PythonScriptController)
. Is it ok?
According to the document, I should create a.scn
file and usePythonScriptController
to reference the corresponding python scripts.
I still realize that.scn
file is not really necessary, for instance I can directly openhouseofCrad.py
and don’t need ahouseofCards.scn
. However, when animating the scene, the cards and floor don’t have collision detection. And I got the following warning
How can I solve this kind of problems to handle the collisions? @Hugo I’m still confused about creating scene usin python scripts.
I have two questions.
1. Is it necessary to create a.scn
file for each scene?
2. Do I have to setRequiredPlugin
in a.scn
file?
3. In a python scripts likehouseofcards.py
, it starts fromcreateScene(node)
other thancreateScene(sofa.PythonScriptController)
. Is it ok?
According to the document, I should create a.scn
file and usePythonScriptController
to reference the corresponding python scripts.
I still realize that.scn
file is not really necessary, for instance I can directly openhouseofCrad.py
and don’t need ahouseofCards.scn
. However, when animating the scene, the cards and floor don’t have collision detection. And I got the following warning
How can I solve this kind of problems to handle the collisions?28 April 2020 at 08:24 #15966PengYuBlocked@Hugo I’m still confused about creating scene using python scripts.
I have three questions.
1. Is it necessary to create a.scn
file for each scene?
2. Do I have to setRequiredPlugin
in a.scn
file?
3. In a python scripts likehouseofcards.py
, it starts fromcreateScene(node)
other thancreateScene(sofa.PythonScriptController)
. Is it ok?According to the document, I should create a
.scn
file and usePythonScriptController
to reference the corresponding python scripts.
I still realize that.scn
file is not really necessary, for instance I can directly openhouseofCrad.py
and don’t need ahouseofCards.scn
. However, when animating the scene, the cards and floor don’t have collision detection. And I got the following warning
How can I solve this kind of problems to handle the collisions?29 April 2020 at 10:28 #15973SarahBlockedI’m not sure if I can answer all your questions, as I’m not a SOFA expert. But in my experience
1. I don’t think it is not necessary to use a.scn
file.2. I don’t know if you would need to set
RequiredPlugin
in a.scn
file, but from the error message it seems as though you should. And similarly for.py
file but than in pythonrootNode.createObject('RegquiredPlugin', pluginName='...')
3. It is fine to start .py files with createScene(node) and you don’t need to use a PythonScriptController for the initial build up of the scene but can use it to control various parametrs during the simulation.
I’m not sure why the collision in
.py
was not detected. But maybe you could check that is referring to the correct plugin in python and that it can find it, you could also add the SofaPython Plugin but I don’t think it is necessary. I’m not an expert, but I hope this helps a little.29 April 2020 at 18:02 #15976PengYuBlockedHi @Sarah, thanks for your reply.
1. I can load a scene which is only defined in a python file like
houseOfCards.py
in directoryapplications/plugin/SofaPlugin/examples/
.2. I add the plugins in the warning log using
rootNode.createObject('RegquiredPlugin', pluginName='...')
, but the collision is still not work. And I want to know How can I find a detailed SofaPython API. Te functions in SofaPython plugin are not clear for me.3. What’s the entry point of python scripts? I just find some entry points in PythonScriptController components according to the documents in SofaPython directory.
Thanks again. I am new to Sofa. It often crash for no reason and generating many strange errors. Do you have some advices for learning it?
30 April 2020 at 22:31 #15991HugoKeymasterHi @rainvector and @sarah
Well done @sarah for your answers.
1. yes, .py scenes can be directly loaded
2. RequiredPlugin (be careful in the typos, you wrote it wrong: ReGquiredPlugin) must be added when using codes which are not in the core of SOFA, or which were modularized. Follow the error messages for this.
3. See the SofaPython.pdf in the plugin applications/plugins/SofaPython repository. Take a look also to the examples/ folder in this repository.NOTE: this plugin will be deprecated starting from v20.06 since Python 2.7 is deprecated. A new plugin is now available: SofaPython3. More information and documentation on the transition will soon be made available.
Best wishes,
Hugo
-
AuthorPosts
- You must be logged in to reply to this topic.