I am trying to port an armature importer add-on from Blender 2.79 to Blender 2.8x.
After the bone is being created the bone matrix is set.
But the assignment of the bone matrix has a different behaviour in Blender 2.82a compared to the older Blender 2.79b.
I created a small script that works for both Blender versions to reproduce this behaviour:
import bpy
from mathutils import *
def new_armature(name: str) -> bpy.types.Object:
armature = bpy.data.armatures.new(name)
obj = bpy.data.objects.new(name, armature)
if bpy.app.version[1] >= 80:
bpy.context.scene.collection.objects.link(obj)
bpy.context.view_layer.objects.active = obj
else:
bpy.context.scene.objects.link(obj)
bpy.context.scene.objects.active = obj
return obj
obj = new_armature('human')
armature = obj.data
bpy.ops.object.mode_set(mode='EDIT')
new_bone = armature.edit_bones.new('Bone.000')
new_bone.head = Vector([0, 0, 0])
new_bone.tail = Vector([1, 0, 0])
bone_matrix = Matrix(([0,0,1,0],[0,-1,0,-6],[-1,0,0,6],[0,0,0,1]))
print("bone_matrix:\n", bone_matrix)
new_bone.matrix = bone_matrix
print("new_bone.matrix:\n", new_bone.matrix)
Running that script in Blender 2.79b and Blender 2.82a gives me the following outputs:
user@desktop:~/workspace/blender$ blender2.79b --python test2.py --background
Read prefs: /home/user/.config/blender/2.79/config/userpref.blend
found bundled python: /opt/blender/2.79b/2.79/python
bone_matrix:
<Matrix 4x4 ( 0.0000, 0.0000, 1.0000, 0.0000)
( 0.0000, -1.0000, 0.0000, -6.0000)
(-1.0000, 0.0000, 0.0000, 6.0000)
( 0.0000, 0.0000, 0.0000, 1.0000)>
new_bone.matrix:
<Matrix 4x4 (0.0000, 0.0000, 1.0000, 0.0000)
(0.0000, -1.0000, 0.0000, -6.0000)
(1.0000, 0.0000, -0.0000, 6.0000)
(0.0000, 0.0000, 0.0000, 1.0000)>
Blender quit
user@desktop:~/workspace/blender$ blender2.82a --python test2.py --background
Blender 2.82 (sub 7) (hash 375c7dc4caf4 built 2020-03-12 05:30:40)
Read prefs: /home/user/.config/blender/2.82/config/userpref.blend
found bundled python: /opt/blender/2.82a/2.82/python
bone_matrix:
<Matrix 4x4 ( 0.0000, 0.0000, 1.0000, 0.0000)
( 0.0000, -1.0000, 0.0000, -6.0000)
(-1.0000, 0.0000, 0.0000, 6.0000)
( 0.0000, 0.0000, 0.0000, 1.0000)>
new_bone.matrix:
<Matrix 4x4 (-1.0000, 0.0000, 0.0000, 0.0000)
( 0.0000, -1.0000, 0.0000, -6.0000)
( 0.0000, 0.0000, 1.0000, 6.0000)
( 0.0000, 0.0000, 0.0000, 1.0000)>
Blender quit
As you can see, the new_bone.matrix
matrix differes between these versions.
Updating the scene also does not change anything.
Can you give me a hint how to get the Blender 2.79b behaviour in Blender 2.82a?
My platform is Linux with Kubuntu 19.10 x64.