Home › Forum › SOFA › Using SOFA › [SOLVED] specifying an animation
Tagged: 64_bits, SOFA_1806, Windows_10
- This topic has 3 replies, 2 voices, and was last updated 5 years, 7 months ago by
Anonymous.
-
AuthorPosts
-
21 January 2019 at 07:40 #12801
Anonymous
InactiveI 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:29 #12853Damien Marchal
BlockedHi 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:23 #13006Damien Marchal
BlockedH Fayad,
Is this problem solved ?
Regards,
Damien11 February 2019 at 11:49 #13024Anonymous
InactiveYes thanks.
Best,
Fayad -
AuthorPosts
- You must be logged in to reply to this topic.