Changing the scene file during the simulation and applying the changes without breaking the simulation #2887
-
Hi, How can I enable or disable a component (e.g the ODESolver) in the middle of the simulation by adding a key control? Is there any way other than using the Best, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hi @zbounik You can although destroy components in python if you would like, but this might have strong side-effects.. nodeToDelete = self.rootNode.getChild(str(name))
for obj in nodeToDelete.objects:
nodeToDelete.removeObject(obj)
self.rootNode.removeChild(str(name)) |
Beta Was this translation helpful? Give feedback.
-
Hi @zbounik The current way of changing a simulation at runtime to react to key pressed is to use a controller. The simplest is to go with python. Here is an example: import Sofa
from Sofa.constants import Key
class MyController(Sofa.Core.Controller):
def __init__(self, *args, **kwargs):
Sofa.Core.Controller.__init__(self, *args, **kwargs)
self.target_node = kwargs.get("target", None)
def onKeypressedEvent(self, event):
if event["key"] == Key.P:
self.target_node.setActive(False)
elif event["key"] == Key.B:
self.target_node.setSleeping(False)
elif event["key"] == Key.A:
self.target_node.removeObject(self.target_node.child2.position)
def createScene(root):
root.addChild("child1")
root.child1.addObject("MechanicalObject")
root.child1.addChild("child2")
root.child1.child2.addObject("MechanicalObject", name="position")
root.addObject(MyController(name="PauseScene", target=root.child1)) |
Beta Was this translation helpful? Give feedback.
Hi @zbounik
Activating/de-activating is possible only for nodes (see the associated data
activated
orsleeping
).You can although destroy components in python if you would like, but this might have strong side-effects..
e.g.