i am currently working on a project which is mapping kinect data on armature. i have added kinect module in blender and now having problem in mapping the data. As kinect gives you joint points so i calculate its angles(x,y,z) and calculate matrix from it. but mapping is not perfect when i replace matrix. i am posting code here code i bit long please help me i will be very grateful to you all Thanks

code :
Code: Select all
obj = bpy.data.objects
sc = bpy.context.scene
with nui.Runtime() as kinect:
kinect.skeleton_engine.enabled = True
switch=True
count=sc.frame_start
while (count<=sc.frame_end):
frame = kinect.skeleton_engine.get_next_frame()
for skeleton in frame.SkeletonData:
if skeleton.eTrackingState == nui.SkeletonTrackingState.TRACKED:
for ob in obj:
if ob.type=='ARMATURE':
bpy.ops.object.mode_set(mode='POSE')
abc=bpy.data.armatures
for ab in abc:
for a in ab.bones:
'''notcomplete bone mapping issues'''
bpy.context.object.pose.bones[a.name].rotation_mode='XYZ'
if a.headk == True:
skl=skeleton.SkeletonPositions[JointId.Head]
skl2=bpy.context.object.pose.bones[a.name].matrix
mhead=calMatrix(skl,skl2)
bpy.context.object.pose.bones[a.name].matrix=mhead
elif a.chest == True:
skl=skeleton.SkeletonPositions[JointId.ShoulderCenter]
'
skl2=bpy.context.object.pose.bones[a.name].matrix
mchest=calMatrix(skl,skl2)
bpy.context.object.pose.bones[a.name].matrix=mchest
elif a.rightshoulder == True:
skl=skeleton.SkeletonPositions[JointId.ShoulderRight]
skl2=bpy.context.object.pose.bones[a.name].matrix
mrshld=calMatrix(skl,skl2)
bpy.context.object.pose.bones[a.name].matrix=mrshld
elif a.leftshoulder == True:
skl=skeleton.SkeletonPositions[JointId.ShoulderLeft]
skl2=bpy.context.object.pose.bones[a.name].matrix
mlshld=calMatrix(skl,skl2)
bpy.context.object.pose.bones[a.name].matrix=mlshld
elif a.spine == True:
skl=skeleton.SkeletonPositions[JointId.Spine]
skl2=bpy.context.object.pose.bones[a.name].matrix
mspine=calMatrix(skl,skl2)
bpy.context.object.pose.bones[a.name].matrix=mspine
elif a.rightarm == True:
skl=skeleton.SkeletonPositions[JointId.ElbowRight]
skl2=bpy.context.object.pose.bones[a.name].matrix
mrarm=calMatrix(skl,skl2)
bpy.context.object.pose.bones[a.name].matrix=mrarm
elif a.leftarm == True:
skl=skeleton.SkeletonPositions[JointId.ElbowLeft]
skl2=bpy.context.object.pose.bones[a.name].matrix
mlarm=calMatrix(skl,skl2)
bpy.context.object.pose.bones[a.name].matrix=mlarm
elif a.rightforearm == True:
skl=skeleton.SkeletonPositions[JointId.WristRight]
skl2=bpy.context.object.pose.bones[a.name].matrix
mrfarm=calMatrix(skl,skl2)
bpy.context.object.pose.bones[a.name].matrix=mrfarm
elif a.leftforearm == True:
skl=skeleton.SkeletonPositions[JointId.WristLeft]
skl2=bpy.context.object.pose.bones[a.name].matrix
mlfarm=calMatrix(skl,skl2)
bpy.context.object.pose.bones[a.name].matrix=mlfarm
elif a.lefthand == True:
skl=skeleton.SkeletonPositions[JointId.HandLeft]
skl2=bpy.context.object.pose.bones[a.name].matrix
mlhand=calMatrix(skl,skl2)
bpy.context.object.pose.bones[a.name].matrix=mlhand
elif a.righthand == True:
skl=skeleton.SkeletonPositions[JointId.HandRight]
skl2=bpy.context.object.pose.bones[a.name].matrix
mrhand=calMatrix(skl,skl2)
bpy.context.object.pose.bones[a.name].matrix=mrhand
elif a.lefthip == True:
skl=skeleton.SkeletonPositions[JointId.HipLeft]
skl2=bpy.context.object.pose.bones[a.name].matrix
mlhip=calMatrix(skl,skl2)
bpy.context.object.pose.bones[a.name].matrix=mlhip
elif a.righthip == True:
skl=skeleton.SkeletonPositions[JointId.HipRight]
skl2=bpy.context.object.pose.bones[a.name].matrix
mrhip=calMatrix(skl,skl2)
bpy.context.object.pose.bones[a.name].matrix=mrhip
elif a.rightthigh == True:
skl=skeleton.SkeletonPositions[JointId.KneeRight]
skl2=bpy.context.object.pose.bones[a.name].matrix
mrthgh=calMatrix(skl,skl2)
bpy.context.object.pose.bones[a.name].matrix=mrthgh
elif a.leftthigh == True:
skl=skeleton.SkeletonPositions[JointId.KneeLeft]
skl2=bpy.context.object.pose.bones[a.name].matrix
mlthgh=calMatrix(skl,skl2)
bpy.context.object.pose.bones[a.name].matrix=mlthgh
elif a.rightleg == True:
skl=skeleton.SkeletonPositions[JointId.FootRight]
skl2=bpy.context.object.pose.bones[a.name].matrix
mrleg=calMatrix(skl,skl2)
bpy.context.object.pose.bones[a.name].matrix=mrleg
elif a.leftleg == True:
skl=skeleton.SkeletonPositions[JointId.FootLeft]
skl2=bpy.context.object.pose.bones[a.name].matrix
mlleg=calMatrix(skl,skl2)
bpy.context.object.pose.bones[a.name].matrix=mlleg
bpy.context.object.pose.bones[a.name].keyframe_insert('rotation_euler', frame=count, index=0)
bpy.context.object.pose.bones[a.name].keyframe_insert('rotation_euler', frame=count, index=1)
bpy.context.object.pose.bones[a.name].keyframe_insert('rotation_euler', frame=count, index=2)
def calMatrix(A,B):
angles=mathutils.Vector((0.0,0.0,0.0))
temp=mathutils.Vector((0.0,0.0,0.0))
alfa=math.atan2(-A.y,A.z)
beta=math.atan2(-A.z,A.x)
gama=math.atan2(A.y,A.x)
angles.x=alfa
angles.y=beta
angles.z=gama
loc, rot, scl=B.decompose()
temp.x=A.x
temp.y=A.y
temp.z=A.z
x= mathutils.Matrix.Rotation(angles.x, 4, 'X')
y= mathutils.Matrix.Rotation(angles.y, 4, 'Y')
z= mathutils.Matrix.Rotation(angles.z, 4, 'Z')
xyz=x*y*z
trans=mathutils.Matrix.Translation(temp)
s=mathutils.Matrix([[scl.x,0,0,0],[0,scl.y,0,0],[0,0,scl.z,0],[0,0,0,1]])
newmat1=trans*xyz*s
global_matrix = mathutils.Matrix.Rotation(3.14159265, 4, 'X')
newmat=global_matrix*newmat1
return newmat