KINECT MOTION CAPTURE
In this project, I used the Kinect sensor along with Kinect SDk and Blender python to capture body motion data and retarget it to humanoid characters then smoothing the output.
import bpy import mathutils def add_objects(models): for x in range(25): bpy.ops.object.select_all(action='DESELECT') bpy.ops.mesh.primitive_ico_sphere_add(radius=1, enter_editmode=False, align='WORLD', location=(0, 0, 0), scale=(0.05, 0.05, 0.05)) models.append(bpy.context.selected_objects[0]) bpy.ops.object.select_all(action='DESELECT') def RotateBone(boneName,models,indx0,indx1,frameNo): if bpy.context.object.mode != 'POSE': print( "Bone not selected" ) return armature = bpy.context.active_object for bone in armature.data.bones: bone.select = False armature.data.bones[boneName].select = True armature.data.bones.active = armature.data.bones[boneName] v1 = models[indx0].location v2 = models[indx1].location v = v2 - v1 v.normalize() vGoal = v + bpy.context.active_pose_bone.head bpy.ops.object.posemode_toggle() bpy.ops.object.empty_add(type='PLAIN_AXES', location= vGoal) target_axis = bpy.context.active_object bpy.ops.object.select_all(action='DESELECT') armature.select_set(True) bpy.context.view_layer.objects.active = armature bpy.ops.object.posemode_toggle() bpy.ops.pose.constraint_add(type='DAMPED_TRACK') bpy.context.object.pose.bones[boneName].constraints["Damped Track"].target = target_axis #bpy.ops.object.delete(use_global=False) #bpy.ops.nla.bake(frame_start=frameNo, frame_end=frameNo, visual_keying=True, clear_constraints=True, bake_types={'POSE'}) bpy.ops.pose.visual_transform_apply() bpy.ops.pose.constraints_clear() bpy.context.object.pose.bones[boneName].keyframe_insert(data_path='rotation_quaternion',frame=frameNo) bpy.ops.object.posemode_toggle() bpy.ops.object.select_all(action='DESELECT') target_axis.select_set(True) bpy.ops.object.delete(use_global=False) bpy.context.view_layer.objects.active = armature bpy.ops.object.posemode_toggle() #Contains the data of the joints models = [] add_objects(models) f = open("filename.txt", "r") bpy.context.scene.frame_current = 0 currFrame = 0 while (line := f.readline().rstrip()): #print(line) if(line[0] == "#"): if(currFrame > 0): if bpy.context.object.mode != 'POSE': bpy.ops.object.select_all(action='DESELECT') bpy.data.objects['Skin Armature.001'].select_set(True) bpy.context.view_layer.objects.active = bpy.data.objects['Skin Armature.001'] #bpy.context.scene.objects.active = bpy.data.objects['Skin Armature.001'] bpy.ops.object.posemode_toggle() RotateBone("Bone.05.R",models,8,9,currFrame) RotateBone("Bone.05.L",models,4,5,currFrame) RotateBone("Bone.36.R",models,9,10,currFrame) RotateBone("Bone.36.L",models,5,6,currFrame) #RotateBone("Bone.14.R",models,16,17,currFrame) #RotateBone("Bone.01.R",models,17,18,currFrame) #RotateBone("Bone.14.L",models,12,13,currFrame) #RotateBone("Bone.01.L",models,13,14,currFrame) RotateBone("Bone.10",models,2,3,currFrame) bpy.ops.object.posemode_toggle() bpy.context.scene.frame_current = bpy.context.scene.frame_current + 1 currFrame = bpy.context.scene.frame_current print("currFrame:" + str(currFrame)) elif(line[0] == "D"): pass else: jointAndNumbers = line.split(" ") joint = int(jointAndNumbers[0]) numbers = jointAndNumbers[1].split(",") bpy.ops.object.select_all(action='DESELECT') models[joint].select_set(True) models[joint].location = mathutils.Vector((-float(numbers[0]), float(numbers[2]), float(numbers[1]))) bpy.ops.anim.keyframe_insert_menu(type='Location') f.close()