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:
Diffstat (limited to 'io_scene_gltf2/blender/imp/gltf2_blender_gltf.py')
-rwxr-xr-xio_scene_gltf2/blender/imp/gltf2_blender_gltf.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_gltf.py b/io_scene_gltf2/blender/imp/gltf2_blender_gltf.py
index 53b200b2..0f603bf3 100755
--- a/io_scene_gltf2/blender/imp/gltf2_blender_gltf.py
+++ b/io_scene_gltf2/blender/imp/gltf2_blender_gltf.py
@@ -256,7 +256,14 @@ class BlenderGlTF():
for node_idx, node in enumerate(gltf.data.nodes):
node.animations = {}
+ track_names = set()
for anim_idx, anim in enumerate(gltf.data.animations):
+ # Pick pair-wise unique name for each animation to use as a name
+ # for its NLA tracks.
+ desired_name = anim.name or "Anim_%d" % anim_idx
+ anim.track_name = BlenderGlTF.find_unused_name(track_names, desired_name)
+ track_names.add(anim.track_name)
+
for channel_idx, channel in enumerate(anim.channels):
if channel.target.node is None:
continue
@@ -274,3 +281,25 @@ class BlenderGlTF():
mesh.blender_name = None
mesh.is_weight_animated = False
+ @staticmethod
+ def find_unused_name(haystack, desired_name):
+ """Finds a name not in haystack and <= 63 UTF-8 bytes.
+ (the limit on the size of a Blender name.)
+ If a is taken, tries a.001, then a.002, etc.
+ """
+ stem = desired_name[:63]
+ suffix = ''
+ cntr = 1
+ while True:
+ name = stem + suffix
+
+ if len(name.encode('utf-8')) > 63:
+ stem = stem[:-1]
+ continue
+
+ if name not in haystack:
+ return name
+
+ suffix = '.%03d' % cntr
+ cntr += 1
+