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-10-12 18:05:38 +0300
committerJulien Duroure <julien.duroure@gmail.com>2019-10-12 18:05:38 +0300
commitb9b1814a4c26f73aae7f306c9ff2e21b7b7bdcee (patch)
treee31ef1b44456b78f815fe722c59314b1bf86ecd7 /io_scene_gltf2/blender/exp/gltf2_blender_gather_skins.py
parent67e42c79e5c3f2724d33b7dc2f0fb4ab84d10e7f (diff)
glTF exporter: option to export only deformation bones
Diffstat (limited to 'io_scene_gltf2/blender/exp/gltf2_blender_gather_skins.py')
-rwxr-xr-xio_scene_gltf2/blender/exp/gltf2_blender_gather_skins.py71
1 files changed, 58 insertions, 13 deletions
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_skins.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_skins.py
index 59af7d72..18503fdd 100755
--- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_skins.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_skins.py
@@ -67,11 +67,14 @@ def __gather_inverse_bind_matrices(blender_object, export_settings):
axis_basis_change = mathutils.Matrix(
((1.0, 0.0, 0.0, 0.0), (0.0, 0.0, 1.0, 0.0), (0.0, -1.0, 0.0, 0.0), (0.0, 0.0, 0.0, 1.0)))
- # build the hierarchy of nodes out of the bones
- root_bones = []
- for blender_bone in blender_object.pose.bones:
- if not blender_bone.parent:
- root_bones.append(blender_bone)
+ if export_settings['gltf_def_bones'] is False:
+ # build the hierarchy of nodes out of the bones
+ root_bones = []
+ for blender_bone in blender_object.pose.bones:
+ if not blender_bone.parent:
+ root_bones.append(blender_bone)
+ else:
+ _, children_, root_bones = get_bone_tree(None, blender_object)
matrices = []
@@ -86,8 +89,13 @@ def __gather_inverse_bind_matrices(blender_object, export_settings):
).inverted()
matrices.append(inverse_bind_matrix)
- for child in bone.children:
- __collect_matrices(child)
+ if export_settings['gltf_def_bones'] is False:
+ for child in bone.children:
+ __collect_matrices(child)
+ else:
+ if bone.name in children_.keys():
+ for child in children_[bone.name]:
+ __collect_matrices(blender_object.pose.bones[child])
# start with the "root" bones and recurse into children, in the same ordering as the how joints are gathered
for root_bone in root_bones:
@@ -114,18 +122,28 @@ def __gather_inverse_bind_matrices(blender_object, export_settings):
def __gather_joints(blender_object, export_settings):
root_joints = []
- # build the hierarchy of nodes out of the bones
- for blender_bone in blender_object.pose.bones:
- if not blender_bone.parent:
- root_joints.append(gltf2_blender_gather_joints.gather_joint(blender_bone, export_settings))
+ if export_settings['gltf_def_bones'] is False:
+ # build the hierarchy of nodes out of the bones
+ for blender_bone in blender_object.pose.bones:
+ if not blender_bone.parent:
+ root_joints.append(gltf2_blender_gather_joints.gather_joint(blender_bone, export_settings))
+ else:
+ _, children_, root_joints = get_bone_tree(None, blender_object)
+ root_joints = [gltf2_blender_gather_joints.gather_joint(i, export_settings) for i in root_joints]
# joints is a flat list containing all nodes belonging to the skin
joints = []
def __collect_joints(node):
joints.append(node)
- for child in node.children:
- __collect_joints(child)
+ if export_settings['gltf_def_bones'] is False:
+ for child in node.children:
+ __collect_joints(child)
+ else:
+ if node.name in children_.keys():
+ for child in children_[node.name]:
+ __collect_joints(gltf2_blender_gather_joints.gather_joint(blender_object.pose.bones[child], export_settings))
+
for joint in root_joints:
__collect_joints(joint)
@@ -140,3 +158,30 @@ def __gather_skeleton(blender_object, export_settings):
# In the future support the result of https://github.com/KhronosGroup/glTF/pull/1195
return None # gltf2_blender_gather_nodes.gather_node(blender_object, blender_scene, export_settings)
+@cached
+def get_bone_tree(blender_dummy, blender_object):
+
+ bones = []
+ children = {}
+ root_bones = []
+
+ def get_parent(bone):
+ bones.append(bone.name)
+ if bone.parent is not None:
+ if bone.parent.name not in children.keys():
+ children[bone.parent.name] = []
+ children[bone.parent.name].append(bone.name)
+ get_parent(bone.parent)
+ else:
+ root_bones.append(bone.name)
+
+ for bone in [b for b in blender_object.data.bones if b.use_deform is True]:
+ get_parent(bone)
+
+ # remove duplicates
+ for k, v in children.items():
+ children[k] = list(set(v))
+ list_ = list(set(bones))
+ root_ = list(set(root_bones))
+ return [blender_object.data.bones[b] for b in list_], children, [blender_object.pose.bones[b] for b in root_]
+