fix: bone roll replication

More info about the issue:
https://devtalk.blender.org/t/how-to-query-determine-the-roll-of-a-bone-in-pose-object-mode/14251/2

Related to #155
This commit is contained in:
Swann 2020-12-24 10:53:16 +01:00
parent 8a8cc0b322
commit 2c016833fd
No known key found for this signature in database
GPG Key ID: E1D3641A7C43AACB

View File

@ -25,6 +25,16 @@ from .. import presence, operators, utils
from .bl_datablock import BlDatablock from .bl_datablock import BlDatablock
def get_roll(bone: bpy.types.Bone) -> float:
""" Compute the actuall roll of a pose bone
:arg pose_bone: target pose bone
:type pose_bone: bpy.types.PoseBone
:return: float
"""
return bone.AxisRollFromMatrix(bone.matrix_local.to_3x3())[1]
class BlArmature(BlDatablock): class BlArmature(BlDatablock):
bl_id = "armatures" bl_id = "armatures"
bl_class = bpy.types.Armature bl_class = bpy.types.Armature
@ -34,7 +44,7 @@ class BlArmature(BlDatablock):
bl_check_common = False bl_check_common = False
bl_icon = 'ARMATURE_DATA' bl_icon = 'ARMATURE_DATA'
bl_reload_parent = False bl_reload_parent = False
def _construct(self, data): def _construct(self, data):
return bpy.data.armatures.new(data["name"]) return bpy.data.armatures.new(data["name"])
@ -44,8 +54,8 @@ class BlArmature(BlDatablock):
'uuid', 'uuid',
data['user'], data['user'],
bpy.data.objects bpy.data.objects
) )
if parent_object is None: if parent_object is None:
parent_object = bpy.data.objects.new( parent_object = bpy.data.objects.new(
data['user_name'], target) data['user_name'], target)
@ -94,16 +104,16 @@ class BlArmature(BlDatablock):
new_bone.head = bone_data['head_local'] new_bone.head = bone_data['head_local']
new_bone.tail_radius = bone_data['tail_radius'] new_bone.tail_radius = bone_data['tail_radius']
new_bone.head_radius = bone_data['head_radius'] new_bone.head_radius = bone_data['head_radius']
# new_bone.roll = bone_data['roll'] new_bone.roll = bone_data['roll']
if 'parent' in bone_data: if 'parent' in bone_data:
new_bone.parent = target.edit_bones[data['bones'] new_bone.parent = target.edit_bones[data['bones']
[bone]['parent']] [bone]['parent']]
new_bone.use_connect = bone_data['use_connect'] new_bone.use_connect = bone_data['use_connect']
loader = Loader() loader = Loader()
loader.load(new_bone, bone_data) loader.load(new_bone, bone_data)
if bpy.context.mode != 'OBJECT': if bpy.context.mode != 'OBJECT':
bpy.ops.object.mode_set(mode='OBJECT') bpy.ops.object.mode_set(mode='OBJECT')
bpy.context.view_layer.objects.active = current_active_object bpy.context.view_layer.objects.active = current_active_object
@ -127,8 +137,6 @@ class BlArmature(BlDatablock):
'parent', 'parent',
'name', 'name',
'layers', 'layers',
# 'roll',
] ]
data = dumper.dump(instance) data = dumper.dump(instance)
@ -136,6 +144,7 @@ class BlArmature(BlDatablock):
if bone.parent: if bone.parent:
data['bones'][bone.name]['parent'] = bone.parent.name data['bones'][bone.name]['parent'] = bone.parent.name
# get the parent Object # get the parent Object
# TODO: Use id_data instead
object_users = utils.get_datablock_users(instance)[0] object_users = utils.get_datablock_users(instance)[0]
data['user'] = object_users.uuid data['user'] = object_users.uuid
data['user_name'] = object_users.name data['user_name'] = object_users.name
@ -146,6 +155,8 @@ class BlArmature(BlDatablock):
item.name for item in container_users if isinstance(item, bpy.types.Collection)] item.name for item in container_users if isinstance(item, bpy.types.Collection)]
data['user_scene'] = [ data['user_scene'] = [
item.name for item in container_users if isinstance(item, bpy.types.Scene)] item.name for item in container_users if isinstance(item, bpy.types.Scene)]
for bone in instance.bones:
data['bones'][bone.name]['roll'] = get_roll(bone)
return data return data