Home › Forum › Community Help › Using SOFA › specifying an animation
Tagged: 64_bits, SOFA_1806, Windows_10
This topic contains 3 replies, has 2 voices, and was last updated by Fayad 1 week, 5 days ago.
-
AuthorPosts
-
21 January 2019 at 7 h 40 min #12801
I want to specify a point to move from point A to point B in increments, so basically animating the point to move in a specific path. I tried achieving this with python by having a sleep delay for a fraction of a second, but that resulted in the pausing of SOFA and it not responding. I understand that this is because the sleep was not done in the background. Is there a way of specifying an animation path for a point to follow?
21 January 2019 at 21 h 29 min #12853Hi Fayad,
One solution to your problem is to use an animation controller that will update the animation at regular interval using the time of the simulation of the wall clock time depending on what you need.
You can get inspiration from the drafted animation system we implemented in the STLIB:
https://stlib.readthedocs.io/en/latest/_autosummary/splib.animation.htmlHere is a simple example:
# coding: utf-8 # splib is available here: https://github.com/SofaDefrost/STLIB import splib ## This function is called by the animation manager at each timestep, the factor ## is updated to indicate how much has progress the animation. ## The factor is between [0, 1] 0 is the begin of the animation, 1 is the end. def myanimate(target, factor, src, dst): t = [(dst[0]-src[0]) * factor + src[0], (dst[1]-src[1]) * factor + src[1], (dst[2]-src[2]) * factor + src[2]] print("I'm updating the position using: ", factor, " new pos is", t) target.position = t def createScene(rootNode): from splib.animation import animate, AnimationManager ## This will create a single AnimationManager python script controller that will animate all the ## animation on the scene. AnimationManager(rootNode) # The object t = rootNode.createObject("MechanicalObject", position=[0,0,0]) t.showObject=True t.showObjectScale=10 # This fire up an animation, # The movement is computed using the "myanimate" function # The target of the animation is the 't' object # This animation will have 0.5 second duration (simulation time) # 'ping-pong' means that the animation will repeat to-from. animate(myanimate, {"target" : t, "src" : [-1.0,-1.0,0], "dst" : [+1.0, 2.0,0]}, duration=5.0, mode="pingpong" )
Hope this helps.
Regards,
Damien.6 February 2019 at 16 h 23 min #13006H Fayad,
Is this problem solved ?
Regards,
Damien11 February 2019 at 11 h 49 min #13024Yes thanks.
Best,
Fayad -
AuthorPosts
You must be logged in to reply to this topic.