Skip to content

Free Motion Capture for Everyone πŸ’€βœ¨

TypeScript

fix dum git slop

Jon4afb26740fcc
diff --git a/freemocap/freemocap_blender_megascript.py b/freemocap/freemocap_blender_megascript.py
index 31df9ee3..bed22c29 100644
--- a/freemocap/freemocap_blender_megascript.py
+++ b/freemocap/freemocap_blender_megascript.py
@@ -272,7 +272,6 @@ try:
-<<<<<<< Updated upstream
print('hip_center - midway between left and right hips')
left_hip_index = 23
right_hip_index = 24
@@ -283,8 +282,7 @@ try:
this_empty.scale = [empty_size]*3
this_empty.parent = freemocap_origin_axes
mediapipe_tracked_point_names.append(this_empty.name)
-=======
-rig_constraint_dict_of_dicts = {
+ rig_constraint_dict_of_dicts = {
"spine": {
'COPY_LOCATION': 'hip_center',
'STRETCH_TO': 'chest_center',
@@ -482,674 +480,47 @@ rig_constraint_dict_of_dicts = {
},
}
-#loop through dictionary applying constraints
-try:
- bpy.ops.object.mode_set(mode='POSE')
-except:
- pass
->>>>>>> Stashed changes
-
- for frame_num in range(end_frame):
- this_empty.location = [hips_xyz[frame_num,0],
- hips_xyz[frame_num,1],
- hips_xyz[frame_num,2]]
- this_empty.keyframe_insert(data_path='location',frame=frame_num)
-
-
- print('chest_center - mean of R/L shoulders and R/L hips')
- chest_xyz = (neck_xyz + hips_xyz)/2
- bpy.ops.object.empty_add(type='PLAIN_AXES')
- this_empty = bpy.context.active_object
- this_empty.name = 'chest_center'
- this_empty.scale = [empty_size]*3
- this_empty.parent = freemocap_origin_axes
- mediapipe_tracked_point_names.append(this_empty.name)
-
- for frame_num in range(end_frame):
- this_empty.location = [chest_xyz[frame_num,0],
- chest_xyz[frame_num,1],
- chest_xyz[frame_num,2]]
- this_empty.keyframe_insert(data_path='location',frame=frame_num)
-
- print('Done loading empties :D')
-
-
- ######################################################################
- ## Fit Rigify metarig armatures to empties
-
- bpy.context.scene.frame_set(good_clean_frame_number)
-
- #each bone name has to match one in the Blender Rigify Human Metarig, or it will be ignored
- metarig_bone_empty_pairs_dict_of_dicts = {
- "nose.001": {
- 'head': 'head_center',
- 'tail': 'nose',
- },
- "nose.L.001": {
- 'head': 'nose',
- 'tail': 'left_eye_inner',
- },
- "eye.L": {
- 'head': 'left_eye_inner',
- 'tail': 'left_eye',
- },
- "lid.B.L": {
- 'head': 'left_eye',
- 'tail': 'left_eye_outer',
- },
- "ear.L": {
- 'head': 'left_eye_outer',
- 'tail': 'left_ear',
- },
- "nose.R.001": {
- 'head': 'nose',
- 'tail': 'right_eye_inner',
- },
- "eye.R": {
- 'head': 'right_eye_inner',
- 'tail': 'right_eye',
- },
- "lid.B.R": {
- 'head': 'right_eye',
- 'tail': 'right_eye_outer',
- },
- "ear.R": {
- 'head': 'right_eye_outer',
- 'tail': 'right_ear',
- },
- "lip.T.R": {
- 'head': 'nose',
- 'tail': 'mouth_right',
- },
- "lip.B.R": {
- 'head': 'mouth_right',
- 'tail': 'mouth_left',
- },
- "lip.T.L": {
- 'head': 'nose',
- 'tail': 'mouth_left',
- },
- "hand.L": {
- 'head': 'left_wrist',
- 'tail': 'left_index',
- },
- "forearm.L": {
- 'head': 'left_elbow',
- 'tail': 'left_wrist',
- },
- "upper_arm.L": {
- 'head': 'left_shoulder',
- 'tail': 'left_elbow',
- },
- "shoulder.L": {
- 'head': 'neck_center',
- 'tail': 'left_shoulder',
- },
- "hand.R": {
- 'head': 'right_wrist',
- 'tail': 'right_index',
- },
- "forearm.R": {
- 'head': 'right_elbow',
- 'tail': 'right_wrist',
- },
- "upper_arm.R": {
- 'head': 'right_shoulder',
- 'tail': 'right_elbow',
- },
- "shoulder.R": {
- 'head': 'neck_center',
- 'tail': 'right_shoulder',
- },
- "thigh.L": {
- 'head': 'left_hip',
- 'tail': 'left_knee',
- },
- "shin.L": {
- 'head': 'left_knee',
- 'tail': 'left_ankle',
- },
- "heel.02.L": {
- 'head': 'left_heel',
- 'tail': 'left_ankle',
- },
- "foot.L": {
- 'head': 'left_ankle',
- 'tail': 'left_foot_index',
- },
- "toe.L": {
- 'head': 'left_foot_index',
- 'tail': 'left_heel',
- },
- "thigh.R": {
- 'head': 'right_hip',
- 'tail': 'right_knee',
- },
- "shin.R": {
- 'head': 'right_knee',
- 'tail': 'right_ankle',
- },
- "heel.02.R": {
- 'head': 'right_heel',
- 'tail': 'right_ankle',
- },
- "foot.R": {
- 'head': 'right_ankle',
- 'tail': 'right_foot_index',
- },
- "toe.R": {
- 'head': 'right_foot_index',
- 'tail': 'right_heel',
- },
- "pelvis.L": {
- 'head': 'hip_center',
- 'tail': 'left_hip',
- },
- "pelvis.R": {
- 'head': 'hip_center',
- 'tail': 'right_hip',
- },
- "spine": {
- 'head': 'hip_center',
- 'tail': 'chest_center',
- },
- "spine.001": {
- 'head': 'chest_center',
- 'tail': 'neck_center',
- },
- "spine.002": {
- 'head': 'neck_center',
- 'tail': 'head_center',
- },
- "spine.003": {
- 'head': 'head_center',
- 'tail': 'nose',
- },
- "palm.01.R": {
- 'head': 'right_wrist',
- 'tail': 'right_hand_index_finger_mcp',
- },
- "palm.02.R": {
- 'head': 'right_wrist',
- 'tail': 'right_hand_middle_finger_mcp',
- },
- "palm.03.R": {
- 'head': 'right_wrist',
- 'tail': 'right_hand_ring_finger_mcp',
- },
- "palm.04.R": {
- 'head': 'right_wrist',
- 'tail': 'right_hand_pinky_finger_mcp',
- },
-
- "thumb.01.R": {
- 'head': 'right_wrist',
- 'tail': 'right_hand_thumb_mcp',
- },
- "thumb.02.R": {
- 'head': 'right_hand_thumb_mcp',
- 'tail': 'right_hand_thumb_ip',
- },
- "thumb.03.R": {
- 'head': 'right_hand_thumb_ip',
- 'tail': 'right_hand_thumb_tip',
- },
-
- "f_index.01.R": {
- 'head': 'right_hand_index_finger_mcp',
- 'tail': 'right_hand_index_finger_pip',
- },
- "f_index.02.R": {
- 'head': 'right_hand_index_finger_pip',
- 'tail': 'right_hand_index_finger_dip',
- },
- "f_index.03.R": {
- 'head': 'right_hand_index_finger_dip',
- 'tail': 'right_hand_index_finger_tip',
- },
-
- "f_middle.01.R": {
- 'head': 'right_hand_middle_finger_mcp',
- 'tail': 'right_hand_middle_finger_pip',
- },
- "f_middle.02.R": {
- 'head': 'right_hand_middle_finger_pip',
- 'tail': 'right_hand_middle_finger_dip',
- },
- "f_middle.03.R": {
- 'head': 'right_hand_middle_finger_dip',
- 'tail': 'right_hand_middle_finger_tip',
- },
-
- "f_ring.01.R": {
- 'head': 'right_hand_ring_finger_mcp',
- 'tail': 'right_hand_ring_finger_pip',
- },
- "f_ring.02.R": {
- 'head': 'right_hand_ring_finger_pip',
- 'tail': 'right_hand_ring_finger_dip',
- },
- "f_ring.03.R": {
- 'head': 'right_hand_ring_finger_dip',
- 'tail': 'right_hand_ring_finger_tip',
- },
-
- "f_pinky.01.R": {
- 'head': 'right_hand_pinky_finger_mcp',
- 'tail': 'right_hand_pinky_finger_pip',
- },
- "f_pinky.02.R": {
- 'head': 'right_hand_pinky_finger_pip',
- 'tail': 'right_hand_pinky_finger_dip',
- },
- "f_pinky.03.R": {
- 'head': 'right_hand_pinky_finger_dip',
- 'tail': 'right_hand_pinky_finger_tip',
- },
- "thumb.01.L": {
- 'head': 'left_wrist',
- 'tail': 'left_hand_thumb_mcp',
- },
- "thumb.02.L": {
- 'head': 'left_hand_thumb_mcp',
- 'tail': 'left_hand_thumb_ip',
- },
- "thumb.03.L": {
- 'head': 'left_hand_thumb_ip',
- 'tail': 'left_hand_thumb_tip',
- },
- "palm.01.L": {
- 'head': 'left_wrist',
- 'tail': 'left_hand_index_finger_mcp',
- },
- "palm.02.L": {
- 'head': 'left_wrist',
- 'tail': 'left_hand_middle_finger_mcp',
- },
- "palm.03.L": {
- 'head': 'left_wrist',
- 'tail': 'left_hand_ring_finger_mcp',
- },
- "palm.04.L": {
- 'head': 'left_wrist',
- 'tail': 'left_hand_pinky_finger_mcp',
- },
- "f_index.01.L": {
- 'head': 'left_hand_index_finger_mcp',
- 'tail': 'left_hand_index_finger_pip',
- },
- "f_index.02.L": {
- 'head': 'left_hand_index_finger_pip',
- 'tail': 'left_hand_index_finger_dip',
- },
- "f_index.03.L": {
- 'head': 'left_hand_index_finger_dip',
- 'tail': 'left_hand_index_finger_tip',
- },
-
- "f_middle.01.L": {
- 'head': 'left_hand_middle_finger_mcp',
- 'tail': 'left_hand_middle_finger_pip',
- },
- "f_middle.02.L": {
- 'head': 'left_hand_middle_finger_pip',
- 'tail': 'left_hand_middle_finger_dip',
- },
- "f_middle.03.L": {
- 'head': 'left_hand_middle_finger_dip',
- 'tail': 'left_hand_middle_finger_tip',
- },
- "f_ring.01.L": {
- 'head': 'left_hand_ring_finger_mcp',
- 'tail': 'left_hand_ring_finger_pip',
- },
- "f_ring.02.L": {
- 'head': 'left_hand_ring_finger_pip',
- 'tail': 'left_hand_ring_finger_dip',
- },
- "f_ring.03.L": {
- 'head': 'left_hand_ring_finger_dip',
- 'tail': 'left_hand_ring_finger_tip',
- },
- "f_pinky.01.L": {
- 'head': 'left_hand_pinky_finger_mcp',
- 'tail': 'left_hand_pinky_finger_pip',
- },
- "f_pinky.02.L": {
- 'head': 'left_hand_pinky_finger_pip',
- 'tail': 'left_hand_pinky_finger_dip',
- },
- "f_pinky.03.L": {
- 'head': 'left_hand_pinky_finger_dip',
- 'tail': 'left_hand_pinky_finger_tip',
- },
-
- }
-
-
- #%% create metarig
- bpy.ops.object.armature_human_metarig_add()
- this_metarig = bpy.context.active_object
-
- #%% loop through dictionary - set head and tail of each bone's to the relevant empty
- # bpy.ops.object.posemode_toggle()
+ #loop through dictionary applying constraints
try:
- bpy.ops.object.mode_set(mode='EDIT')
+ bpy.ops.object.mode_set(mode='POSE')
except:
pass
-
- for this_bone in list(this_metarig.data.bones):
- this_bone_name = this_bone.name
- print(f'--{this_bone_name}--')
- this_edit_bone= this_metarig.data.edit_bones[this_bone_name] # note this is using EDIT_bones, not regular bones b/c blender is a wild wacky place
-
- if this_bone_name in metarig_bone_empty_pairs_dict_of_dicts:
- this_bone_dict = metarig_bone_empty_pairs_dict_of_dicts[this_bone_name]
+ for frame_num in range(end_frame):
+ this_empty.location = [hips_xyz[frame_num,0],
+ hips_xyz[frame_num,1],
+ hips_xyz[frame_num,2]]
+ this_empty.keyframe_insert(data_path='location',frame=frame_num)
- this_head_empty_name = this_bone_dict['head']
- this_tail_empty_name = this_bone_dict['tail']
- print('setting (bone:head->tail){}:{}->{})'.format(this_bone_name, this_head_empty_name, this_tail_empty_name))
- if this_tail_empty_name is not None:
- print(f'setting bone: {this_bone_name}: head: {bpy.data.objects[this_head_empty_name].location}, tail: {bpy.data.objects[this_tail_empty_name].location}')
- this_edit_bone.head = bpy.data.objects[this_head_empty_name].location
- this_edit_bone.tail = bpy.data.objects[this_tail_empty_name].location
- else: #remove bones with no tail (and/or head) until we figure out a better plan
- print(f'removing bone: {this_bone_name}')
- this_metarig.data.edit_bones.remove(this_edit_bone)
- else:
- print(f'removing bone: {this_bone_name}')
- this_metarig.data.edit_bones.remove(this_edit_bone)
+ print('chest_center - mean of R/L shoulders and R/L hips')
+ chest_xyz = (neck_xyz + hips_xyz)/2
+ bpy.ops.object.empty_add(type='PLAIN_AXES')
+ this_empty = bpy.context.active_object
+ this_empty.name = 'chest_center'
+ this_empty.scale = [empty_size]*3
+ this_empty.parent = freemocap_origin_axes
+ mediapipe_tracked_point_names.append(this_empty.name)
- try:
- bpy.ops.object.mode_set(mode='OBJECT')
- except:
- pass
+ for frame_num in range(end_frame):
+ this_empty.location = [chest_xyz[frame_num,0],
+ chest_xyz[frame_num,1],
+ chest_xyz[frame_num,2]]
+ this_empty.keyframe_insert(data_path='location',frame=frame_num)
+ print('Done loading empties :D')
+ ######################################################################
+ ## Fit Rigify metarig armatures to empties
- #######################################################
- #### Damped track bones to empties
- bpy.ops.object.mode_set(mode='OBJECT')
- armature_name = 'metarig'
- this_armature = bpy.data.objects[armature_name]
+ bpy.context.scene.frame_set(good_clean_frame_number)
- rig_constraint_dict_of_dicts = {
+ #each bone name has to match one in the Blender Rigify Human Metarig, or it will be ignored
+ metarig_bone_empty_pairs_dict_of_dicts = {
"nose.001": {
- 'COPY_LOCATION': 'head_center',
- 'DAMPED_TRACK': 'nose',
- },
- "nose.L.001": {
- 'DAMPED_TRACK': 'left_eye_inner',
- },
- "eye.L": {
- 'DAMPED_TRACK': 'left_eye',
- },
- "lid.B.L": {
- 'DAMPED_TRACK': 'left_eye_outer',
- },
- "ear.L": {
- 'DAMPED_TRACK': 'left_ear',
- },
- "nose.R.001": {
- 'DAMPED_TRACK': 'right_eye_inner',
- },
- "eye.R": {
- 'DAMPED_TRACK': 'right_eye',
- },
- "lid.B.R": {
- 'DAMPED_TRACK': 'right_eye_outer',
- },
- "ear.R": {
- 'DAMPED_TRACK': 'right_ear',
- },
- "lip.T.R": {
- 'DAMPED_TRACK': 'mouth_right',
- },
- "lip.B.R": {
- 'DAMPED_TRACK': 'mouth_left',
- },
- "lip.T.L": {
- 'DAMPED_TRACK': 'nose',
- },
- "spine": {
- 'COPY_LOCATION': 'hip_center',
- 'DAMPED_TRACK': 'chest_center',
- },
- "spine.001": {
- 'DAMPED_TRACK': 'neck_center',
- },
- "spine.002": {
- 'DAMPED_TRACK': 'head_center',
- },
- "spine.003": {
- 'DAMPED_TRACK': 'nose',
- },
- "pelvis.L": {
- 'DAMPED_TRACK': 'left_hip',
- },
- "thigh.L": {
- 'COPY_LOCATION': 'left_hip',
- 'DAMPED_TRACK': 'left_knee',
- },
- "shin.L": {
- 'DAMPED_TRACK': 'left_ankle',
- },
- "foot.L": {
- 'DAMPED_TRACK': 'left_foot_index',
- },
- "heel.02.L": {
- 'DAMPED_TRACK': 'left_ankle',
- },
- "shoulder.L": {
- 'COPY_LOCATION': 'neck_center',
- 'DAMPED_TRACK': 'left_shoulder',
- },
- "upper_arm.L": {
- 'DAMPED_TRACK': 'left_elbow',
- },
- "forearm.L": {
- 'DAMPED_TRACK': 'left_wrist',
- },
- "hand.L": {
- 'DAMPED_TRACK': 'left_index',
- },
- "pelvis.R": {
- 'DAMPED_TRACK': 'right_hip',
- },
- "thigh.R": {
- 'COPY_LOCATION': 'right_hip',
- 'DAMPED_TRACK': 'right_knee',
- },
- "shin.R": {
- 'DAMPED_TRACK': 'right_ankle',
- },
- "foot.R": {
- 'DAMPED_TRACK': 'right_foot_index',
- },
- "heel.02.R": {
- 'DAMPED_TRACK': 'right_ankle',
- },
- "shoulder.R": {
- 'COPY_LOCATION': 'neck_center',
- 'DAMPED_TRACK': 'right_shoulder',
- },
- "upper_arm.R": {
- 'DAMPED_TRACK': 'right_elbow',
- },
- "forearm.R": {
- 'DAMPED_TRACK': 'right_wrist',
- },
- "hand.R": {
- 'DAMPED_TRACK': 'right_index',
- },
- "thumb.01.R": {
- 'COPY_LOCATION': 'right_wrist',
- 'DAMPED_TRACK': 'right_hand_thumb_mcp',
- },
- "thumb.02.R": {
- 'DAMPED_TRACK': 'right_hand_thumb_ip',
- },
- "thumb.02.R": {
- 'DAMPED_TRACK': 'right_hand_thumb_tip',
- },
- "palm.01.R": {
- 'COPY_LOCATION': 'right_wrist',
- 'DAMPED_TRACK': 'right_hand_index_finger_mcp',
- },
- "f_index.01.R": {
- 'DAMPED_TRACK': 'right_hand_index_finger_pip',
- },
- "f_index.02.R": {
- 'DAMPED_TRACK': 'right_hand_index_finger_dip',
- },
- "f_index.03.R": {
- 'DAMPED_TRACK': 'right_hand_index_finger_tip',
- },
- "palm.02.R": {
- 'COPY_LOCATION': 'right_wrist',
- 'DAMPED_TRACK': 'right_hand_middle_finger_mcp',
- },
- "f_middle.01.R": {
- 'DAMPED_TRACK': 'right_hand_middle_finger_pip',
- },
- "f_middle.02.R": {
- 'DAMPED_TRACK': 'right_hand_middle_finger_dip',
- },
- "f_middle.03.R": {
- 'DAMPED_TRACK': 'right_hand_middle_finger_tip',
- },
- "palm.03.R": {
- 'COPY_LOCATION': 'right_wrist',
- 'DAMPED_TRACK': 'right_hand_ring_finger_mcp',
- },
- "f_ring.01.R": {
- 'DAMPED_TRACK': 'right_hand_ring_finger_pip',
- },
- "f_ring.02.R": {
- 'DAMPED_TRACK': 'right_hand_ring_finger_dip',
- },
- "f_ring.03.R": {
- 'DAMPED_TRACK': 'right_hand_ring_finger_tip',
- },
- "palm.04.R": {
- 'COPY_LOCATION': 'right_wrist',
- 'DAMPED_TRACK': 'right_hand_pinky_finger_mcp',
- },
- "f_pinky.01.R": {
- 'DAMPED_TRACK': 'right_hand_pinky_finger_pip',
- },
- "f_pinky.02.R": {
- 'DAMPED_TRACK': 'right_hand_pinky_finger_dip',
- },
- "f_pinky.03.R": {
- 'DAMPED_TRACK': 'right_hand_pinky_finger_tip',
- },
- "thumb.01.L": {
- 'COPY_LOCATION': 'left_wrist',
- 'DAMPED_TRACK': 'left_hand_thumb_mcp',
- },
- "thumb.02.L": {
- 'DAMPED_TRACK': 'left_hand_thumb_ip',
- },
- "thumb.03.L": {
- 'DAMPED_TRACK': 'left_hand_thumb_tip',
- },
- "palm.01.L": {
- 'COPY_LOCATION': 'left_wrist',
- 'DAMPED_TRACK': 'left_hand_index_finger_mcp',
- },
- "f_index.01.L": {
- 'DAMPED_TRACK': 'left_hand_index_finger_pip',
- },
- "f_index.02.L": {
- 'DAMPED_TRACK': 'left_hand_index_finger_dip',
- },
- "f_index.03.L": {
- 'DAMPED_TRACK': 'left_hand_index_finger_tip',
- },
- "palm.02.L": {
- 'COPY_LOCATION': 'left_wrist',
- 'DAMPED_TRACK': 'left_hand_middle_finger_mcp',
- },
- "f_middle.01.L": {
- 'DAMPED_TRACK': 'left_hand_middle_finger_pip',
- },
- "f_middle.02.L": {
- 'DAMPED_TRACK': 'left_hand_middle_finger_dip',
- },
- "f_middle.03.L": {
- 'DAMPED_TRACK': 'left_hand_middle_finger_tip',
- },
- "palm.03.L": {
- 'COPY_LOCATION': 'left_wrist',
- 'DAMPED_TRACK': 'left_hand_ring_finger_mcp',
- },
- "f_ring.01.L": {
- 'DAMPED_TRACK': 'left_hand_ring_finger_pip',
- },
- "f_ring.02.L": {
- 'DAMPED_TRACK': 'left_hand_ring_finger_dip',
- },
- "f_ring.03.L": {
- 'DAMPED_TRACK': 'left_hand_ring_finger_tip',
- },
- "palm.04.L": {
- 'COPY_LOCATION': 'left_wrist',
- 'DAMPED_TRACK': 'left_hand_pinky_finger_mcp',
- },
- "f_pinky.01.L": {
- 'DAMPED_TRACK': 'left_hand_pinky_finger_pip',
- },
- "f_pinky.02.L": {
- 'DAMPED_TRACK': 'left_hand_pinky_finger_dip',
- },
- "f_pinky.03.L": {
- 'DAMPED_TRACK': 'left_hand_pinky_finger_tip',
- },
- }
-
- #loop through dictionary applying constraints
- try:
- bpy.ops.object.mode_set(mode='POSE')
- except:
- pass
-
- for this_bone_name, this_bone_dict in rig_constraint_dict_of_dicts.items():
- print(f'---Setting constraints for bone:{this_bone_name}---')
-
- for this_constraint_name, this_constraint_target_empty_name in this_bone_dict.items():
- print(f'constraint: {this_constraint_name} with target:{this_constraint_target_empty_name}')
- print('grab bone')
- this_bone= this_armature.pose.bones[this_bone_name]
- print('apply bone')
- this_constraint = this_bone.constraints.new(type=this_constraint_name)
- this_constraint.name = this_constraint_name
- this_constraint.target = bpy.data.objects[this_constraint_target_empty_name] #point constraint at relevant empty object
-
- ##############
- ## create extra bones
-
- extra_bone_empty_pairs_dict_of_dicts = {
- "hand.L": {
- 'head': 'left_wrist',
- 'tail': 'left_index',
- },
- "forearm.L": {
- 'head': 'left_elbow',
- 'tail': 'left_wrist',
- },
- }
-
- ###################################################################
- #### Create Stick Figure Mesh
-
- stick_figure_mesh_edge_pairs_dict_of_dicts = {
- "nose.001": {
- 'head': 'head_center',
- 'tail': 'nose',
+ 'head': 'head_center',
+ 'tail': 'nose',
},
"nose.L.001": {
'head': 'nose',
@@ -1195,6 +566,10 @@ except:
'head': 'nose',
'tail': 'mouth_left',
},
+ "hand.L": {
+ 'head': 'left_wrist',
+ 'tail': 'left_index',
+ },
"forearm.L": {
'head': 'left_elbow',
'tail': 'left_wrist',
@@ -1207,6 +582,10 @@ except:
'head': 'neck_center',
'tail': 'left_shoulder',
},
+ "hand.R": {
+ 'head': 'right_wrist',
+ 'tail': 'right_index',
+ },
"forearm.R": {
'head': 'right_elbow',
'tail': 'right_wrist',
@@ -1302,20 +681,17 @@ except:
"thumb.01.R": {
'head': 'right_wrist',
- 'tail': 'right_hand_thumb_cmc',
- },
- "thumb.02.R": {
- 'head': 'right_hand_thumb_cmc',
'tail': 'right_hand_thumb_mcp',
},
- "thumb.03.R": {
+ "thumb.02.R": {
'head': 'right_hand_thumb_mcp',
'tail': 'right_hand_thumb_ip',
},
- "thumb.04.R": {
+ "thumb.03.R": {
'head': 'right_hand_thumb_ip',
'tail': 'right_hand_thumb_tip',
},
+
"f_index.01.R": {
'head': 'right_hand_index_finger_mcp',
'tail': 'right_hand_index_finger_pip',
@@ -1328,6 +704,7 @@ except:
'head': 'right_hand_index_finger_dip',
'tail': 'right_hand_index_finger_tip',
},
+
"f_middle.01.R": {
'head': 'right_hand_middle_finger_mcp',
'tail': 'right_hand_middle_finger_pip',
@@ -1340,6 +717,7 @@ except:
'head': 'right_hand_middle_finger_dip',
'tail': 'right_hand_middle_finger_tip',
},
+
"f_ring.01.R": {
'head': 'right_hand_ring_finger_mcp',
'tail': 'right_hand_ring_finger_pip',
@@ -1367,17 +745,13 @@ except:
},
"thumb.01.L": {
'head': 'left_wrist',
- 'tail': 'left_hand_thumb_cmc',
- },
- "thumb.02.L": {
- 'head': 'left_hand_thumb_cmc',
'tail': 'left_hand_thumb_mcp',
},
- "thumb.03.L": {
+ "thumb.02.L": {
'head': 'left_hand_thumb_mcp',
'tail': 'left_hand_thumb_ip',
},
- "thumb.04.L": {
+ "thumb.03.L": {
'head': 'left_hand_thumb_ip',
'tail': 'left_hand_thumb_tip',
},
@@ -1409,6 +783,7 @@ except:
'head': 'left_hand_index_finger_dip',
'tail': 'left_hand_index_finger_tip',
},
+
"f_middle.01.L": {
'head': 'left_hand_middle_finger_mcp',
'tail': 'left_hand_middle_finger_pip',
@@ -1445,185 +820,807 @@ except:
'head': 'left_hand_pinky_finger_dip',
'tail': 'left_hand_pinky_finger_tip',
},
+
}
- mediapipe_virtual_markers_weights_dict = {
- 'head_center':{
- 'right_ear': .5,
- 'left_ear': .5
- },
- 'neck_center':{
- 'right_shoulder': .5,
- 'left_shoulder': .5
- },
- 'hip_center':{
- 'right_hip': .5,
- 'left_hip': .5
+
+ #%% create metarig
+ bpy.ops.object.armature_human_metarig_add()
+ this_metarig = bpy.context.active_object
+
+ #%% loop through dictionary - set head and tail of each bone's to the relevant empty
+ # bpy.ops.object.posemode_toggle()
+ try:
+ bpy.ops.object.mode_set(mode='EDIT')
+ except:
+ pass
+
+ for this_bone in list(this_metarig.data.bones):
+ this_bone_name = this_bone.name
+ print(f'--{this_bone_name}--')
+
+ this_edit_bone= this_metarig.data.edit_bones[this_bone_name] # note this is using EDIT_bones, not regular bones b/c blender is a wild wacky place
+
+ if this_bone_name in metarig_bone_empty_pairs_dict_of_dicts:
+ this_bone_dict = metarig_bone_empty_pairs_dict_of_dicts[this_bone_name]
+
+ this_head_empty_name = this_bone_dict['head']
+ this_tail_empty_name = this_bone_dict['tail']
+ print('setting (bone:head->tail){}:{}->{})'.format(this_bone_name, this_head_empty_name, this_tail_empty_name))
+
+ if this_tail_empty_name is not None:
+ print(f'setting bone: {this_bone_name}: head: {bpy.data.objects[this_head_empty_name].location}, tail: {bpy.data.objects[this_tail_empty_name].location}')
+ this_edit_bone.head = bpy.data.objects[this_head_empty_name].location
+ this_edit_bone.tail = bpy.data.objects[this_tail_empty_name].location
+ else: #remove bones with no tail (and/or head) until we figure out a better plan
+ print(f'removing bone: {this_bone_name}')
+ this_metarig.data.edit_bones.remove(this_edit_bone)
+ else:
+ print(f'removing bone: {this_bone_name}')
+ this_metarig.data.edit_bones.remove(this_edit_bone)
+
+ try:
+ bpy.ops.object.mode_set(mode='OBJECT')
+ except:
+ pass
+
+
+
+
+ #######################################################
+ #### Damped track bones to empties
+ bpy.ops.object.mode_set(mode='OBJECT')
+ armature_name = 'metarig'
+ this_armature = bpy.data.objects[armature_name]
+
+ rig_constraint_dict_of_dicts = {
+ "nose.001": {
+ 'COPY_LOCATION': 'head_center',
+ 'DAMPED_TRACK': 'nose',
+ },
+ "nose.L.001": {
+ 'DAMPED_TRACK': 'left_eye_inner',
+ },
+ "eye.L": {
+ 'DAMPED_TRACK': 'left_eye',
+ },
+ "lid.B.L": {
+ 'DAMPED_TRACK': 'left_eye_outer',
+ },
+ "ear.L": {
+ 'DAMPED_TRACK': 'left_ear',
+ },
+ "nose.R.001": {
+ 'DAMPED_TRACK': 'right_eye_inner',
+ },
+ "eye.R": {
+ 'DAMPED_TRACK': 'right_eye',
+ },
+ "lid.B.R": {
+ 'DAMPED_TRACK': 'right_eye_outer',
+ },
+ "ear.R": {
+ 'DAMPED_TRACK': 'right_ear',
+ },
+ "lip.T.R": {
+ 'DAMPED_TRACK': 'mouth_right',
+ },
+ "lip.B.R": {
+ 'DAMPED_TRACK': 'mouth_left',
+ },
+ "lip.T.L": {
+ 'DAMPED_TRACK': 'nose',
+ },
+ "spine": {
+ 'COPY_LOCATION': 'hip_center',
+ 'DAMPED_TRACK': 'chest_center',
+ },
+ "spine.001": {
+ 'DAMPED_TRACK': 'neck_center',
+ },
+ "spine.002": {
+ 'DAMPED_TRACK': 'head_center',
+ },
+ "spine.003": {
+ 'DAMPED_TRACK': 'nose',
+ },
+ "pelvis.L": {
+ 'DAMPED_TRACK': 'left_hip',
+ },
+ "thigh.L": {
+ 'COPY_LOCATION': 'left_hip',
+ 'DAMPED_TRACK': 'left_knee',
+ },
+ "shin.L": {
+ 'DAMPED_TRACK': 'left_ankle',
+ },
+ "foot.L": {
+ 'DAMPED_TRACK': 'left_foot_index',
+ },
+ "heel.02.L": {
+ 'DAMPED_TRACK': 'left_ankle',
+ },
+ "shoulder.L": {
+ 'COPY_LOCATION': 'neck_center',
+ 'DAMPED_TRACK': 'left_shoulder',
+ },
+ "upper_arm.L": {
+ 'DAMPED_TRACK': 'left_elbow',
+ },
+ "forearm.L": {
+ 'DAMPED_TRACK': 'left_wrist',
+ },
+ "hand.L": {
+ 'DAMPED_TRACK': 'left_index',
+ },
+ "pelvis.R": {
+ 'DAMPED_TRACK': 'right_hip',
+ },
+ "thigh.R": {
+ 'COPY_LOCATION': 'right_hip',
+ 'DAMPED_TRACK': 'right_knee',
+ },
+ "shin.R": {
+ 'DAMPED_TRACK': 'right_ankle',
+ },
+ "foot.R": {
+ 'DAMPED_TRACK': 'right_foot_index',
+ },
+ "heel.02.R": {
+ 'DAMPED_TRACK': 'right_ankle',
+ },
+ "shoulder.R": {
+ 'COPY_LOCATION': 'neck_center',
+ 'DAMPED_TRACK': 'right_shoulder',
+ },
+ "upper_arm.R": {
+ 'DAMPED_TRACK': 'right_elbow',
+ },
+ "forearm.R": {
+ 'DAMPED_TRACK': 'right_wrist',
+ },
+ "hand.R": {
+ 'DAMPED_TRACK': 'right_index',
+ },
+ "thumb.01.R": {
+ 'COPY_LOCATION': 'right_wrist',
+ 'DAMPED_TRACK': 'right_hand_thumb_mcp',
+ },
+ "thumb.02.R": {
+ 'DAMPED_TRACK': 'right_hand_thumb_ip',
+ },
+ "thumb.02.R": {
+ 'DAMPED_TRACK': 'right_hand_thumb_tip',
+ },
+ "palm.01.R": {
+ 'COPY_LOCATION': 'right_wrist',
+ 'DAMPED_TRACK': 'right_hand_index_finger_mcp',
+ },
+ "f_index.01.R": {
+ 'DAMPED_TRACK': 'right_hand_index_finger_pip',
+ },
+ "f_index.02.R": {
+ 'DAMPED_TRACK': 'right_hand_index_finger_dip',
+ },
+ "f_index.03.R": {
+ 'DAMPED_TRACK': 'right_hand_index_finger_tip',
+ },
+ "palm.02.R": {
+ 'COPY_LOCATION': 'right_wrist',
+ 'DAMPED_TRACK': 'right_hand_middle_finger_mcp',
+ },
+ "f_middle.01.R": {
+ 'DAMPED_TRACK': 'right_hand_middle_finger_pip',
+ },
+ "f_middle.02.R": {
+ 'DAMPED_TRACK': 'right_hand_middle_finger_dip',
+ },
+ "f_middle.03.R": {
+ 'DAMPED_TRACK': 'right_hand_middle_finger_tip',
+ },
+ "palm.03.R": {
+ 'COPY_LOCATION': 'right_wrist',
+ 'DAMPED_TRACK': 'right_hand_ring_finger_mcp',
+ },
+ "f_ring.01.R": {
+ 'DAMPED_TRACK': 'right_hand_ring_finger_pip',
+ },
+ "f_ring.02.R": {
+ 'DAMPED_TRACK': 'right_hand_ring_finger_dip',
+ },
+ "f_ring.03.R": {
+ 'DAMPED_TRACK': 'right_hand_ring_finger_tip',
+ },
+ "palm.04.R": {
+ 'COPY_LOCATION': 'right_wrist',
+ 'DAMPED_TRACK': 'right_hand_pinky_finger_mcp',
+ },
+ "f_pinky.01.R": {
+ 'DAMPED_TRACK': 'right_hand_pinky_finger_pip',
+ },
+ "f_pinky.02.R": {
+ 'DAMPED_TRACK': 'right_hand_pinky_finger_dip',
+ },
+ "f_pinky.03.R": {
+ 'DAMPED_TRACK': 'right_hand_pinky_finger_tip',
+ },
+ "thumb.01.L": {
+ 'COPY_LOCATION': 'left_wrist',
+ 'DAMPED_TRACK': 'left_hand_thumb_mcp',
+ },
+ "thumb.02.L": {
+ 'DAMPED_TRACK': 'left_hand_thumb_ip',
+ },
+ "thumb.03.L": {
+ 'DAMPED_TRACK': 'left_hand_thumb_tip',
+ },
+ "palm.01.L": {
+ 'COPY_LOCATION': 'left_wrist',
+ 'DAMPED_TRACK': 'left_hand_index_finger_mcp',
+ },
+ "f_index.01.L": {
+ 'DAMPED_TRACK': 'left_hand_index_finger_pip',
+ },
+ "f_index.02.L": {
+ 'DAMPED_TRACK': 'left_hand_index_finger_dip',
+ },
+ "f_index.03.L": {
+ 'DAMPED_TRACK': 'left_hand_index_finger_tip',
+ },
+ "palm.02.L": {
+ 'COPY_LOCATION': 'left_wrist',
+ 'DAMPED_TRACK': 'left_hand_middle_finger_mcp',
+ },
+ "f_middle.01.L": {
+ 'DAMPED_TRACK': 'left_hand_middle_finger_pip',
+ },
+ "f_middle.02.L": {
+ 'DAMPED_TRACK': 'left_hand_middle_finger_dip',
+ },
+ "f_middle.03.L": {
+ 'DAMPED_TRACK': 'left_hand_middle_finger_tip',
+ },
+ "palm.03.L": {
+ 'COPY_LOCATION': 'left_wrist',
+ 'DAMPED_TRACK': 'left_hand_ring_finger_mcp',
+ },
+ "f_ring.01.L": {
+ 'DAMPED_TRACK': 'left_hand_ring_finger_pip',
+ },
+ "f_ring.02.L": {
+ 'DAMPED_TRACK': 'left_hand_ring_finger_dip',
+ },
+ "f_ring.03.L": {
+ 'DAMPED_TRACK': 'left_hand_ring_finger_tip',
+ },
+ "palm.04.L": {
+ 'COPY_LOCATION': 'left_wrist',
+ 'DAMPED_TRACK': 'left_hand_pinky_finger_mcp',
+ },
+ "f_pinky.01.L": {
+ 'DAMPED_TRACK': 'left_hand_pinky_finger_pip',
+ },
+ "f_pinky.02.L": {
+ 'DAMPED_TRACK': 'left_hand_pinky_finger_dip',
+ },
+ "f_pinky.03.L": {
+ 'DAMPED_TRACK': 'left_hand_pinky_finger_tip',
+ },
+ }
+
+ #loop through dictionary applying constraints
+ try:
+ bpy.ops.object.mode_set(mode='POSE')
+ except:
+ pass
+
+ for this_bone_name, this_bone_dict in rig_constraint_dict_of_dicts.items():
+ print(f'---Setting constraints for bone:{this_bone_name}---')
+
+ for this_constraint_name, this_constraint_target_empty_name in this_bone_dict.items():
+ print(f'constraint: {this_constraint_name} with target:{this_constraint_target_empty_name}')
+ print('grab bone')
+ this_bone= this_armature.pose.bones[this_bone_name]
+ print('apply bone')
+ this_constraint = this_bone.constraints.new(type=this_constraint_name)
+ this_constraint.name = this_constraint_name
+ this_constraint.target = bpy.data.objects[this_constraint_target_empty_name] #point constraint at relevant empty object
+
+ ##############
+ ## create extra bones
+
+ extra_bone_empty_pairs_dict_of_dicts = {
+ "hand.L": {
+ 'head': 'left_wrist',
+ 'tail': 'left_index',
},
- 'chest_center':{
- 'right_shoulder': .25,
- 'left_shoulder': .25,
- 'right_hip': .25,
- 'left_hip': .25,
+ "forearm.L": {
+ 'head': 'left_elbow',
+ 'tail': 'left_wrist',
},
- }
+ }
- print('loading data as stick figure mesh \o/')
- #######################################################################
+ ###################################################################
+ #### Create Stick Figure Mesh
- #%% create virtual marker points (redundant from above, I think ? )
+ stick_figure_mesh_edge_pairs_dict_of_dicts = {
+ "nose.001": {
+ 'head': 'head_center',
+ 'tail': 'nose',
+ },
+ "nose.L.001": {
+ 'head': 'nose',
+ 'tail': 'left_eye_inner',
+ },
+ "eye.L": {
+ 'head': 'left_eye_inner',
+ 'tail': 'left_eye',
+ },
+ "lid.B.L": {
+ 'head': 'left_eye',
+ 'tail': 'left_eye_outer',
+ },
+ "ear.L": {
+ 'head': 'left_eye_outer',
+ 'tail': 'left_ear',
+ },
+ "nose.R.001": {
+ 'head': 'nose',
+ 'tail': 'right_eye_inner',
+ },
+ "eye.R": {
+ 'head': 'right_eye_inner',
+ 'tail': 'right_eye',
+ },
+ "lid.B.R": {
+ 'head': 'right_eye',
+ 'tail': 'right_eye_outer',
+ },
+ "ear.R": {
+ 'head': 'right_eye_outer',
+ 'tail': 'right_ear',
+ },
+ "lip.T.R": {
+ 'head': 'nose',
+ 'tail': 'mouth_right',
+ },
+ "lip.B.R": {
+ 'head': 'mouth_right',
+ 'tail': 'mouth_left',
+ },
+ "lip.T.L": {
+ 'head': 'nose',
+ 'tail': 'mouth_left',
+ },
+ "forearm.L": {
+ 'head': 'left_elbow',
+ 'tail': 'left_wrist',
+ },
+ "upper_arm.L": {
+ 'head': 'left_shoulder',
+ 'tail': 'left_elbow',
+ },
+ "shoulder.L": {
+ 'head': 'neck_center',
+ 'tail': 'left_shoulder',
+ },
+ "forearm.R": {
+ 'head': 'right_elbow',
+ 'tail': 'right_wrist',
+ },
+ "upper_arm.R": {
+ 'head': 'right_shoulder',
+ 'tail': 'right_elbow',
+ },
+ "shoulder.R": {
+ 'head': 'neck_center',
+ 'tail': 'right_shoulder',
+ },
+ "thigh.L": {
+ 'head': 'left_hip',
+ 'tail': 'left_knee',
+ },
+ "shin.L": {
+ 'head': 'left_knee',
+ 'tail': 'left_ankle',
+ },
+ "heel.02.L": {
+ 'head': 'left_heel',
+ 'tail': 'left_ankle',
+ },
+ "foot.L": {
+ 'head': 'left_ankle',
+ 'tail': 'left_foot_index',
+ },
+ "toe.L": {
+ 'head': 'left_foot_index',
+ 'tail': 'left_heel',
+ },
+ "thigh.R": {
+ 'head': 'right_hip',
+ 'tail': 'right_knee',
+ },
+ "shin.R": {
+ 'head': 'right_knee',
+ 'tail': 'right_ankle',
+ },
+ "heel.02.R": {
+ 'head': 'right_heel',
+ 'tail': 'right_ankle',
+ },
+ "foot.R": {
+ 'head': 'right_ankle',
+ 'tail': 'right_foot_index',
+ },
+ "toe.R": {
+ 'head': 'right_foot_index',
+ 'tail': 'right_heel',
+ },
+ "pelvis.L": {
+ 'head': 'hip_center',
+ 'tail': 'left_hip',
+ },
+ "pelvis.R": {
+ 'head': 'hip_center',
+ 'tail': 'right_hip',
+ },
+ "spine": {
+ 'head': 'hip_center',
+ 'tail': 'chest_center',
+ },
+ "spine.001": {
+ 'head': 'chest_center',
+ 'tail': 'neck_center',
+ },
+ "spine.002": {
+ 'head': 'neck_center',
+ 'tail': 'head_center',
+ },
+ "spine.003": {
+ 'head': 'head_center',
+ 'tail': 'nose',
+ },
+ "palm.01.R": {
+ 'head': 'right_wrist',
+ 'tail': 'right_hand_index_finger_mcp',
+ },
+ "palm.02.R": {
+ 'head': 'right_wrist',
+ 'tail': 'right_hand_middle_finger_mcp',
+ },
+ "palm.03.R": {
+ 'head': 'right_wrist',
+ 'tail': 'right_hand_ring_finger_mcp',
+ },
+ "palm.04.R": {
+ 'head': 'right_wrist',
+ 'tail': 'right_hand_pinky_finger_mcp',
+ },
+
+ "thumb.01.R": {
+ 'head': 'right_wrist',
+ 'tail': 'right_hand_thumb_cmc',
+ },
+ "thumb.02.R": {
+ 'head': 'right_hand_thumb_cmc',
+ 'tail': 'right_hand_thumb_mcp',
+ },
+ "thumb.03.R": {
+ 'head': 'right_hand_thumb_mcp',
+ 'tail': 'right_hand_thumb_ip',
+ },
+ "thumb.04.R": {
+ 'head': 'right_hand_thumb_ip',
+ 'tail': 'right_hand_thumb_tip',
+ },
+ "f_index.01.R": {
+ 'head': 'right_hand_index_finger_mcp',
+ 'tail': 'right_hand_index_finger_pip',
+ },
+ "f_index.02.R": {
+ 'head': 'right_hand_index_finger_pip',
+ 'tail': 'right_hand_index_finger_dip',
+ },
+ "f_index.03.R": {
+ 'head': 'right_hand_index_finger_dip',
+ 'tail': 'right_hand_index_finger_tip',
+ },
+ "f_middle.01.R": {
+ 'head': 'right_hand_middle_finger_mcp',
+ 'tail': 'right_hand_middle_finger_pip',
+ },
+ "f_middle.02.R": {
+ 'head': 'right_hand_middle_finger_pip',
+ 'tail': 'right_hand_middle_finger_dip',
+ },
+ "f_middle.03.R": {
+ 'head': 'right_hand_middle_finger_dip',
+ 'tail': 'right_hand_middle_finger_tip',
+ },
+ "f_ring.01.R": {
+ 'head': 'right_hand_ring_finger_mcp',
+ 'tail': 'right_hand_ring_finger_pip',
+ },
+ "f_ring.02.R": {
+ 'head': 'right_hand_ring_finger_pip',
+ 'tail': 'right_hand_ring_finger_dip',
+ },
+ "f_ring.03.R": {
+ 'head': 'right_hand_ring_finger_dip',
+ 'tail': 'right_hand_ring_finger_tip',
+ },
+
+ "f_pinky.01.R": {
+ 'head': 'right_hand_pinky_finger_mcp',
+ 'tail': 'right_hand_pinky_finger_pip',
+ },
+ "f_pinky.02.R": {
+ 'head': 'right_hand_pinky_finger_pip',
+ 'tail': 'right_hand_pinky_finger_dip',
+ },
+ "f_pinky.03.R": {
+ 'head': 'right_hand_pinky_finger_dip',
+ 'tail': 'right_hand_pinky_finger_tip',
+ },
+ "thumb.01.L": {
+ 'head': 'left_wrist',
+ 'tail': 'left_hand_thumb_cmc',
+ },
+ "thumb.02.L": {
+ 'head': 'left_hand_thumb_cmc',
+ 'tail': 'left_hand_thumb_mcp',
+ },
+ "thumb.03.L": {
+ 'head': 'left_hand_thumb_mcp',
+ 'tail': 'left_hand_thumb_ip',
+ },
+ "thumb.04.L": {
+ 'head': 'left_hand_thumb_ip',
+ 'tail': 'left_hand_thumb_tip',
+ },
+ "palm.01.L": {
+ 'head': 'left_wrist',
+ 'tail': 'left_hand_index_finger_mcp',
+ },
+ "palm.02.L": {
+ 'head': 'left_wrist',
+ 'tail': 'left_hand_middle_finger_mcp',
+ },
+ "palm.03.L": {
+ 'head': 'left_wrist',
+ 'tail': 'left_hand_ring_finger_mcp',
+ },
+ "palm.04.L": {
+ 'head': 'left_wrist',
+ 'tail': 'left_hand_pinky_finger_mcp',
+ },
+ "f_index.01.L": {
+ 'head': 'left_hand_index_finger_mcp',
+ 'tail': 'left_hand_index_finger_pip',
+ },
+ "f_index.02.L": {
+ 'head': 'left_hand_index_finger_pip',
+ 'tail': 'left_hand_index_finger_dip',
+ },
+ "f_index.03.L": {
+ 'head': 'left_hand_index_finger_dip',
+ 'tail': 'left_hand_index_finger_tip',
+ },
+ "f_middle.01.L": {
+ 'head': 'left_hand_middle_finger_mcp',
+ 'tail': 'left_hand_middle_finger_pip',
+ },
+ "f_middle.02.L": {
+ 'head': 'left_hand_middle_finger_pip',
+ 'tail': 'left_hand_middle_finger_dip',
+ },
+ "f_middle.03.L": {
+ 'head': 'left_hand_middle_finger_dip',
+ 'tail': 'left_hand_middle_finger_tip',
+ },
+ "f_ring.01.L": {
+ 'head': 'left_hand_ring_finger_mcp',
+ 'tail': 'left_hand_ring_finger_pip',
+ },
+ "f_ring.02.L": {
+ 'head': 'left_hand_ring_finger_pip',
+ 'tail': 'left_hand_ring_finger_dip',
+ },
+ "f_ring.03.L": {
+ 'head': 'left_hand_ring_finger_dip',
+ 'tail': 'left_hand_ring_finger_tip',
+ },
+ "f_pinky.01.L": {
+ 'head': 'left_hand_pinky_finger_mcp',
+ 'tail': 'left_hand_pinky_finger_pip',
+ },
+ "f_pinky.02.L": {
+ 'head': 'left_hand_pinky_finger_pip',
+ 'tail': 'left_hand_pinky_finger_dip',
+ },
+ "f_pinky.03.L": {
+ 'head': 'left_hand_pinky_finger_dip',
+ 'tail': 'left_hand_pinky_finger_tip',
+ },
+ }
+
+ mediapipe_virtual_markers_weights_dict = {
+ 'head_center':{
+ 'right_ear': .5,
+ 'left_ear': .5
+ },
+ 'neck_center':{
+ 'right_shoulder': .5,
+ 'left_shoulder': .5
+ },
+ 'hip_center':{
+ 'right_hip': .5,
+ 'left_hip': .5
+ },
+ 'chest_center':{
+ 'right_shoulder': .25,
+ 'left_shoulder': .25,
+ 'right_hip': .25,
+ 'left_hip': .25,
+ },
+ }
+ print('loading data as stick figure mesh \o/')
+ #######################################################################
+ #%% create virtual marker points (redundant from above, I think ? )
- current_frame = bpy.data.scenes[0].frame_current
- virtual_point_index_dict = {}
- for this_virtual_marker_dict in mediapipe_virtual_markers_weights_dict.items():
- this_virtual_marker_name = this_virtual_marker_dict[0]
- these_weighted_points = []
- for this_weighted_point_dict in this_virtual_marker_dict[1].items():
- this_point_name = this_weighted_point_dict[0]
- this_weight = this_weighted_point_dict[1]
- these_weighted_points.append(
- mediapipe_skel_fr_mar_dim[
- :,
- mediapipe_tracked_point_names.index(this_point_name),
- :
- ]*this_weight
- )
- this_virtual_point_fr_xyz = np.sum(these_weighted_points, axis=0)
- this_virtual_point_fr_mar_xyz = np.expand_dims(this_virtual_point_fr_xyz, axis=1)
- mediapipe_skel_fr_mar_dim = np.append(mediapipe_skel_fr_mar_dim,this_virtual_point_fr_mar_xyz, axis=1)
- virtual_point_index_dict[this_virtual_marker_name] = mediapipe_skel_fr_mar_dim.shape[1]-1
- print(f'Virtual marker: {this_virtual_marker_name} created at marker index {mediapipe_skel_fr_mar_dim.shape[1]-1}')
+ current_frame = bpy.data.scenes[0].frame_current
+ virtual_point_index_dict = {}
+ for this_virtual_marker_dict in mediapipe_virtual_markers_weights_dict.items():
+ this_virtual_marker_name = this_virtual_marker_dict[0]
+ these_weighted_points = []
+ for this_weighted_point_dict in this_virtual_marker_dict[1].items():
+ this_point_name = this_weighted_point_dict[0]
- #%% define edges
+ this_weight = this_weighted_point_dict[1]
+ these_weighted_points.append(
+ mediapipe_skel_fr_mar_dim[
+ :,
+ mediapipe_tracked_point_names.index(this_point_name),
+ :
+ ]*this_weight
+ )
+ this_virtual_point_fr_xyz = np.sum(these_weighted_points, axis=0)
+ this_virtual_point_fr_mar_xyz = np.expand_dims(this_virtual_point_fr_xyz, axis=1)
+ mediapipe_skel_fr_mar_dim = np.append(mediapipe_skel_fr_mar_dim,this_virtual_point_fr_mar_xyz, axis=1)
+ virtual_point_index_dict[this_virtual_marker_name] = mediapipe_skel_fr_mar_dim.shape[1]-1
+ print(f'Virtual marker: {this_virtual_marker_name} created at marker index {mediapipe_skel_fr_mar_dim.shape[1]-1}')
- edges = []
- #regular data
- for this_bone_dict in stick_figure_mesh_edge_pairs_dict_of_dicts.items():
- edge_name = this_bone_dict[0]
- head_name = this_bone_dict[1]['head']
- tail_name = this_bone_dict[1]['tail']
+ #%% define edges
- try:
+ edges = []
+ #regular data
+ for this_bone_dict in stick_figure_mesh_edge_pairs_dict_of_dicts.items():
+ edge_name = this_bone_dict[0]
+ head_name = this_bone_dict[1]['head']
+ tail_name = this_bone_dict[1]['tail']
- head_index = mediapipe_tracked_point_names.index(head_name)
- tail_index = mediapipe_tracked_point_names.index(tail_name)
- if 'center' in head_name: #virtual markers are acting weird so we're brute forcing it :-/ this will fail if there is a virtual marker without 'center' in the name....
- head_index = virtual_point_index_dict[head_name]
- if 'center' in tail_name:
- tail_index = virtual_point_index_dict[tail_name]
+ try:
- this_edge =(head_index, tail_index)
+ head_index = mediapipe_tracked_point_names.index(head_name)
+ tail_index = mediapipe_tracked_point_names.index(tail_name)
- edges.append(this_edge)
- print(f'edge created for bone: ({this_bone_dict[0]} : {head_name}-{tail_name}), indicies({this_edge[0]},{this_edge[1]})')
- except:
- print(f'edge FAILED for for bone:{this_bone_dict[0]} : {head_name}-{tail_name}')
- pass
+ if 'center' in head_name: #virtual markers are acting weird so we're brute forcing it :-/ this will fail if there is a virtual marker without 'center' in the name....
+ head_index = virtual_point_index_dict[head_name]
+ if 'center' in tail_name:
+ tail_index = virtual_point_index_dict[tail_name]
- print('edges created!')
+ this_edge =(head_index, tail_index)
+ edges.append(this_edge)
+ print(f'edge created for bone: ({this_bone_dict[0]} : {head_name}-{tail_name}), indicies({this_edge[0]},{this_edge[1]})')
+ except:
+ print(f'edge FAILED for for bone:{this_bone_dict[0]} : {head_name}-{tail_name}')
+ pass
- ##############################
- #%% Create mesh
- try:
+ print('edges created!')
+
+
+ ##############################
+ #%% Create mesh
+ try:
+ bpy.ops.object.mode_set(mode='OBJECT')
+ except:
+ pass
+
+ print('loading verticies')
+ vertices = mediapipe_skel_fr_mar_dim[current_frame,:,:] #don't plot face dottos until we know what to do with them
+ print('done loading verticies')
+ #edges defined above
+ faces = []
+ stick_figure_mesh = bpy.data.meshes.new('stick_figure_mesh')
+ print('a')
+ stick_figure_mesh.from_pydata(vertices, edges, faces)
+ print('b')
+ stick_figure_mesh.update()
+ print('c')
+ # make object from mesh
+ stick_figure_mesh_object = bpy.data.objects.new('stick_figure_mesh', stick_figure_mesh)
+ print('d')
+ # make collection
+ mesh_collection = bpy.data.collections.new('mesh_collection')
+ print('e')
+ bpy.context.scene.collection.children.link(mesh_collection)
+ print('f')
+ # add object to scene collection
+ mesh_collection.objects.link(stick_figure_mesh_object)
+ print('g')
+
+ bpy.context.view_layer.objects.active = bpy.data.objects['stick_figure_mesh']
+ print('h')
+
+ bpy.context.object.mode
+ try:
+ bpy.ops.object.editmode_toggle()
+ except:
+ pass
+ print('i')
+
+ #### skin that mesh!
+ print('skinning mesh \o/')
+ bpy.data.objects['stick_figure_mesh'].modifiers.new('stick_figure_mesh_skin', 'SKIN')
+ print('resizing mesh')
+ skin_radius = .025
+ bpy.ops.transform.skin_resize(value=(skin_radius, skin_radius, skin_radius))
+
+ ########
+ # # parent mesh to armature
+ print('parenting mesh to armarture with automatic weights...')
bpy.ops.object.mode_set(mode='OBJECT')
- except:
- pass
+ bpy.data.objects['stick_figure_mesh'].parent = this_metarig
+ bpy.context.view_layer.objects.active = this_metarig
+ bpy.context.active_object.select_set(True)
+ bpy.data.objects['stick_figure_mesh'].select_set(True)
+ bpy.ops.object.parent_set(type='ARMATURE_AUTO')
- print('loading verticies')
- vertices = mediapipe_skel_fr_mar_dim[current_frame,:,:] #don't plot face dottos until we know what to do with them
- print('done loading verticies')
- #edges defined above
- faces = []
- stick_figure_mesh = bpy.data.meshes.new('stick_figure_mesh')
- print('a')
- stick_figure_mesh.from_pydata(vertices, edges, faces)
- print('b')
- stick_figure_mesh.update()
- print('c')
- # make object from mesh
- stick_figure_mesh_object = bpy.data.objects.new('stick_figure_mesh', stick_figure_mesh)
- print('d')
- # make collection
- mesh_collection = bpy.data.collections.new('mesh_collection')
- print('e')
- bpy.context.scene.collection.children.link(mesh_collection)
- print('f')
- # add object to scene collection
- mesh_collection.objects.link(stick_figure_mesh_object)
- print('g')
-
- bpy.context.view_layer.objects.active = bpy.data.objects['stick_figure_mesh']
- print('h')
-
- bpy.context.object.mode
- try:
- bpy.ops.object.editmode_toggle()
- except:
- pass
- print('i')
-
- #### skin that mesh!
- print('skinning mesh \o/')
- bpy.data.objects['stick_figure_mesh'].modifiers.new('stick_figure_mesh_skin', 'SKIN')
- print('resizing mesh')
- skin_radius = .025
- bpy.ops.transform.skin_resize(value=(skin_radius, skin_radius, skin_radius))
-
- ########
- # # parent mesh to armature
- print('parenting mesh to armarture with automatic weights...')
- bpy.ops.object.mode_set(mode='OBJECT')
- bpy.data.objects['stick_figure_mesh'].parent = this_metarig
- bpy.context.view_layer.objects.active = this_metarig
- bpy.context.active_object.select_set(True)
- bpy.data.objects['stick_figure_mesh'].select_set(True)
- bpy.ops.object.parent_set(type='ARMATURE_AUTO')
-
-
- #####################
- ## Load nSynched Videos
- try:
- print('loading videos as planes...')
- annotated_videos_path = session_path / 'annotated_videos'
- if annotated_videos_path.is_dir():
- vidFolderPath = annotated_videos_path
- else:
- vidFolderPath = session_path / 'SyncedVideos'
+ #####################
+ ## Load nSynched Videos
+ try:
+ print('loading videos as planes...')
+ annotated_videos_path = session_path / 'annotated_videos'
- world_origin = bpy.data.objects['world_origin']
+ if annotated_videos_path.is_dir():
+ vidFolderPath = annotated_videos_path
+ else:
+ vidFolderPath = session_path / 'SyncedVideos'
- number_of_videos = len(list(vidFolderPath.glob('*.mp4')))
+ world_origin = bpy.data.objects['world_origin']
- vid_location_scale = 1
+ number_of_videos = len(list(vidFolderPath.glob('*.mp4')))
+ vid_location_scale = 1
- for vid_number, thisVidPath, in enumerate(vidFolderPath.glob('*.mp4')):
- print(thisVidPath)
- # use 'images as planes' add on to load in the video files as planes
- bpy.ops.import_image.to_plane(files=[{"name":thisVidPath.name}], directory=str(thisVidPath.parent), shader='EMISSION', )
- this_vid_as_plane = bpy.context.active_object
- this_vid_as_plane.name = 'vid_' + str(vid_number)
+ for vid_number, thisVidPath, in enumerate(vidFolderPath.glob('*.mp4')):
+ print(thisVidPath)
+ # use 'images as planes' add on to load in the video files as planes
+ bpy.ops.import_image.to_plane(files=[{"name":thisVidPath.name}], directory=str(thisVidPath.parent), shader='EMISSION', )
+ this_vid_as_plane = bpy.context.active_object
+ this_vid_as_plane.name = 'vid_' + str(vid_number)
- vid_x = (vid_number - number_of_videos/2) * vid_location_scale
- this_vid_as_plane.location = [vid_x, vid_location_scale, vid_location_scale]
- this_vid_as_plane.rotation_euler = [np.pi/2, 0, 0]
- this_vid_as_plane.scale = [vid_location_scale*1.5]*3
- this_vid_as_plane.parent = world_origin
- # create a light
- # bpy.ops.object.light_add(type='POINT', radius=1, align='WORLD')
- except:
- print('Failed to load videos to Blender scene - You might need to install the "images as planes" addon to this version of Blender')
+ vid_x = (vid_number - number_of_videos/2) * vid_location_scale
+
+ this_vid_as_plane.location = [vid_x, vid_location_scale, vid_location_scale]
+ this_vid_as_plane.rotation_euler = [np.pi/2, 0, 0]
+ this_vid_as_plane.scale = [vid_location_scale*1.5]*3
+ this_vid_as_plane.parent = world_origin
+ # create a light
+ # bpy.ops.object.light_add(type='POINT', radius=1, align='WORLD')
+ except:
+ print('Failed to load videos to Blender scene - You might need to install the "images as planes" addon to this version of Blender')
except Exception as e:
print(e)
print('Something broke in the Blender Megascript - Maybe it failed to find a good clean frame and then that borked something downstream?')