Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Duroure <julien.duroure@gmail.com>2019-09-11 23:13:41 +0300
committerJulien Duroure <julien.duroure@gmail.com>2019-09-11 23:13:41 +0300
commit14f1c99e96adad81aea2a5a77eb51d22b96c9618 (patch)
tree3ba099f6e337df515abf47a52cb35c4985466f9e /io_scene_gltf2/blender/exp/gltf2_blender_gather.py
parent8db12f14561cf8bb123f7933738d5e62d1c50850 (diff)
glTF exporter: Merge animations into glTF animation(s) based on NLA track names
Option "NLA tracks" is active by default. If disable, all active action of scene will be merge into a single glTF animation
Diffstat (limited to 'io_scene_gltf2/blender/exp/gltf2_blender_gather.py')
-rwxr-xr-xio_scene_gltf2/blender/exp/gltf2_blender_gather.py58
1 files changed, 56 insertions, 2 deletions
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather.py
index 4d28a4bd..92fa9ce2 100755
--- a/io_scene_gltf2/blender/exp/gltf2_blender_gather.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather.py
@@ -15,6 +15,7 @@
import bpy
from io_scene_gltf2.io.com import gltf2_io
+from io_scene_gltf2.io.com.gltf2_io_debug import print_console
from io_scene_gltf2.blender.exp import gltf2_blender_gather_nodes
from io_scene_gltf2.blender.exp import gltf2_blender_gather_animations
from io_scene_gltf2.blender.exp.gltf2_blender_gather_cache import cached
@@ -60,12 +61,65 @@ def __gather_scene(blender_scene, export_settings):
def __gather_animations(blender_scene, export_settings):
animations = []
+ merged_tracks = {}
+
for blender_object in blender_scene.objects:
# First check if this object is exported or not. Do not export animation of not exported object
obj_node = gltf2_blender_gather_nodes.gather_node(blender_object, blender_scene, export_settings)
if obj_node is not None:
- animations += gltf2_blender_gather_animations.gather_animations(blender_object, export_settings)
- return animations
+ animations_, merged_tracks = gltf2_blender_gather_animations.gather_animations(blender_object, merged_tracks, len(animations), export_settings)
+ animations += animations_
+
+ if export_settings['gltf_nla_strips'] is False:
+ # Fake an animation witha all animations of the scene
+ merged_tracks = {}
+ merged_tracks['Animation'] = []
+ for idx, animation in enumerate(animations):
+ merged_tracks['Animation'].append(idx)
+
+
+ to_delete_idx = []
+ for merged_anim_track in merged_tracks.keys():
+ if len(merged_tracks[merged_anim_track]) < 2:
+ continue
+
+ base_animation_idx = None
+ offset_sampler = 0
+
+ for idx, anim_idx in enumerate(merged_tracks[merged_anim_track]):
+ if idx == 0:
+ base_animation_idx = anim_idx
+ animations[anim_idx].name = merged_anim_track
+ already_animated = []
+ for channel in animations[anim_idx].channels:
+ already_animated.append((channel.target.node, channel.target.path))
+ continue
+
+ to_delete_idx.append(anim_idx)
+
+ offset_sampler = len(animations[base_animation_idx].samplers)
+ for sampler in animations[anim_idx].samplers:
+ animations[base_animation_idx].samplers.append(sampler)
+
+ for channel in animations[anim_idx].channels:
+ if (channel.target.node, channel.target.path) in already_animated:
+ print_console("WARNING", "Some strips have same channel animation ({}), on node {} !".format(channel.target.path, channel.target.node.name))
+ continue
+ animations[base_animation_idx].channels.append(channel)
+ animations[base_animation_idx].channels[-1].sampler = animations[base_animation_idx].channels[-1].sampler + offset_sampler
+ already_animated.append((channel.target.node, channel.target.path))
+
+ new_animations = []
+ if len(to_delete_idx) != 0:
+ for idx, animation in enumerate(animations):
+ if idx in to_delete_idx:
+ continue
+ new_animations.append(animation)
+ else:
+ new_animations = animations
+
+
+ return new_animations
def __gather_extras(blender_object, export_settings):