import bmesh
import bpy
import mathutils
import math
# create skin container
asset_arm_name = '' + '_sk'
bpy.ops.object.armature_add()
narmature = bpy.context.scene.objects.active
narmature.name = asset_arm_name
arm = narmature.data
arm.name = asset_arm_name
# enter edit mode to start creating bones
arm_obj = bpy.data.objects[asset_arm_name]
bpy.context.scene.objects.active = None
bpy.context.scene.objects.active = arm_obj
bpy.ops.object.mode_set(mode='EDIT', toggle=False)
edit_bones = arm_obj.data.edit_bones
arm.edit_bones.remove(arm.edit_bones[0]) #remove default bone
tr = mathutils.Matrix([ ( 0.0000, 1.0000, 0.0000, 10.0000),( 1.0000, 0.0000, 0.0000, 21.0000),( 0.0000, 0.0000, -1.0000, 0.0000),(-0.0000, 0.0000, -0.0000, 1.0000)])
bone = edit_bones.new('bone')
bone.tail=[0,1,0]
bone.transform(tr)
###
bpy.ops.object.mode_set() # back to object mode
###
print('=====================')
print(tr)
p,r,s = tr.decompose()
print(p,r,s)
print(r.to_euler()) # the rotation given is : <Euler (x=3.1416, y=-0.0000, z=1.5708), order='XYZ'>
x=arm_obj.pose.bones[0].bone.matrix_local.copy()
print(x)
p,r,s = x.decompose()
print(p,r,s)
print(r.to_euler()) # the rotation in the bone is: <Euler (x=0.0000, y=0.0000, z=-1.5708), order='XYZ'>
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.