diff options
Diffstat (limited to 'io_scene_gltf2/blender/imp/gltf2_blender_animation_utils.py')
-rw-r--r-- | io_scene_gltf2/blender/imp/gltf2_blender_animation_utils.py | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_animation_utils.py b/io_scene_gltf2/blender/imp/gltf2_blender_animation_utils.py index 888d88a4..c835ceb7 100644 --- a/io_scene_gltf2/blender/imp/gltf2_blender_animation_utils.py +++ b/io_scene_gltf2/blender/imp/gltf2_blender_animation_utils.py @@ -12,7 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -def simulate_stash(obj, gltf_animation_name, action, start_frame): +import bpy + +def simulate_stash(obj, track_name, action, start_frame=None): # Simulate stash : # * add a track # * add an action on track @@ -20,20 +22,26 @@ def simulate_stash(obj, gltf_animation_name, action, start_frame): # * remove active action from object tracks = obj.animation_data.nla_tracks new_track = tracks.new(prev=None) - new_track.name = gltf_animation_name if gltf_animation_name is not None else action.name + new_track.name = track_name + if start_frame is None: + start_frame = bpy.context.scene.frame_start strip = new_track.strips.new(action.name, start_frame, action) new_track.lock = True new_track.mute = True obj.animation_data.action = None -def restore_last_action(obj): - - if not obj.animation_data: - return - tracks = obj.animation_data.nla_tracks - if len(tracks) == 0: +def restore_animation_on_object(obj, anim_name): + if not getattr(obj, 'animation_data', None): return - if len(tracks[0].strips) == 0: + + for track in obj.animation_data.nla_tracks: + if track.name != anim_name: + continue + if not track.strips: + continue + + obj.animation_data.action = track.strips[0].action return - obj.animation_data.action = tracks[0].strips[0].action + + obj.animation_data.action = None |