From a892c5af159d1c886d3263bdc85bbf806aafec2b Mon Sep 17 00:00:00 2001 From: Carlos Barreto Date: Sat, 1 May 2021 18:53:40 -0300 Subject: [PATCH] adding the files for the alpha branch realtime mocap development --- __init__.py | 17 +- load_mocap.py | 4379 ++++++++++++++++++++++++++-------------- mediapipe_py_server.py | 97 + test_panel.py | 193 +- 4 files changed, 3060 insertions(+), 1626 deletions(-) create mode 100644 mediapipe_py_server.py diff --git a/__init__.py b/__init__.py index b0b1586..0499b1e 100644 --- a/__init__.py +++ b/__init__.py @@ -11,18 +11,16 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -# beta 0.61 -# - option to choose person to import from vibe mocap -# - apply new skeleton to easymocap -# - impórt SMPL result from easymocap (need file from https://smpl.is.tue.mpg.de/downloads "SMPL for Maya" PS.: need to register to download the file) +# Alpha 0.1 +# - Realtime with mediapipe bl_info = { - "name" : "MOCAP Pose Estimation Data Import", + "name" : "MOCAP Pose Estimation Data Import ALPHA", "author" : "Carlos Barreto", "description" : "", "blender" : (2, 90, 0), - "version" : (0, 0, 61), + "version" : (0, 0, 1), "location" : "View3D", "warning" : "", "category" : "Generic" @@ -39,11 +37,12 @@ ) from . load_mocap import Import_Data_easymocap, OT_TestOpenFilebrowser,Import_Data_frankmocap,Import_Data_vibe,Mediapipe_Pose_estimation, \ - Install_Mediapipe,Install_Joblib,Convert_axis,Reset_location,Reset_rotation,Foot_high,Compensate_Rotation,Smooth_Bone, Reload_sk_easymocap, Import_SMPL_easymocap,Path_SMPL_FBX_File -from . test_panel import Test_PT_Panel, MySettings, Install_PT_Panel, Modify_PT_Panel,Debug_PT_Panel + Install_Mediapipe,Install_Joblib,Convert_axis,Reset_location,Reset_rotation,Foot_high,Compensate_Rotation,Smooth_Bone,Mediapipe_Pose_estimation_RT, Mediapipe_Pose_Prepare_Skeleton_RT, Reload_sk_Mediapipe +from . test_panel import Test_PT_Panel, MySettings, Install_PT_Panel, Modify_PT_Panel, Debug_PT_Panel classes = (Import_Data_easymocap, Test_PT_Panel, OT_TestOpenFilebrowser,Import_Data_frankmocap,Import_Data_vibe,Mediapipe_Pose_estimation, - Install_Mediapipe,Install_Joblib,MySettings,Modify_PT_Panel,Install_PT_Panel,Convert_axis,Reset_location,Reset_rotation,Foot_high,Compensate_Rotation,Smooth_Bone,Debug_PT_Panel, Reload_sk_easymocap, Import_SMPL_easymocap, Path_SMPL_FBX_File) + Install_Mediapipe,Install_Joblib,MySettings,Modify_PT_Panel,Install_PT_Panel,Convert_axis,Reset_location,Reset_rotation,Foot_high,Compensate_Rotation,Smooth_Bone,Mediapipe_Pose_estimation_RT,Mediapipe_Pose_Prepare_Skeleton_RT, + Reload_sk_Mediapipe, Debug_PT_Panel) # register, unregister = bpy.utils.register_classes_factory(classes) def register(): diff --git a/load_mocap.py b/load_mocap.py index 9cc59af..f5e1ddc 100644 --- a/load_mocap.py +++ b/load_mocap.py @@ -27,12 +27,12 @@ def execute(self, context): return {'FINISHED'} -class Import_SMPL_easymocap(Operator, ImportHelper): - bl_idname = "mocap.import_smpl_easymocap" - bl_label = "Import data" - bl_description = "Import SMPL EasyMOCAP" +class Import_Data_easymocap(Operator, ImportHelper): + bl_idname = "mocap.import_easymocap" + bl_label = "Import data" + bl_description = "Import EasyMOCAP" filename_ext = ".json" @@ -48,182 +48,82 @@ class Import_SMPL_easymocap(Operator, ImportHelper): def execute(self,context): + + + #======================== + #EASYMOCAP + #===================== + import os import json import bpy from bpy import context import math + # bpy.ops.test.open_filebrowser('INVOKE_DEFAULT')#abrir janela de navegador - multiplier = context.scene.sk_value_prop.sk_value - raw_bool = context.scene.sk_value_prop.sk_raw_bool - debug_bool = context.scene.sk_value_prop.sk_debug_bool - # reload_skeleton_bool = context.scene.sk_value_prop.sk_reload_skeleton_bool - limit_rotation_bool = context.scene.sk_value_prop.sk_constraint_limit_rotation_bool + object = [] + for ob in bpy.context.scene.objects: + object.append(ob) - #======================== - #EASYMOCAP - #===================== + if len(object) >0 : + if bpy.context.mode != 'OBJECT': + bpy.ops.object.editmode_toggle() - import sys - import bpy - from os.path import join - import math - import numpy as np - from mathutils import Matrix, Vector, Quaternion, Euler - import json + #path = r'D:\MOCAP\EasyMocap-master\Teste_20210321_1_out\keypoints3d' + path = os.path.dirname(self.filepath) + list_dir = os.listdir(path) + s_list = sorted(list_dir) - part_match = {'root': 'root', 'bone_00': 'Pelvis', 'bone_01': 'L_Hip', 'bone_02': 'R_Hip', - 'bone_03': 'Spine1', 'bone_04': 'L_Knee', 'bone_05': 'R_Knee', 'bone_06': 'Spine2', - 'bone_07': 'L_Ankle', 'bone_08': 'R_Ankle', 'bone_09': 'Spine3', 'bone_10': 'L_Foot', - 'bone_11': 'R_Foot', 'bone_12': 'Neck', 'bone_13': 'L_Collar', 'bone_14': 'R_Collar', - 'bone_15': 'Head', 'bone_16': 'L_Shoulder', 'bone_17': 'R_Shoulder', 'bone_18': 'L_Elbow', - 'bone_19': 'R_Elbow', 'bone_20': 'L_Wrist', 'bone_21': 'R_Wrist', 'bone_22': 'L_Hand', 'bone_23': 'R_Hand'} - - def deg2rad(angle): - return -np.pi * (angle + 90) / 180. - - def setState0(): - for ob in bpy.data.objects.values(): - ob.select = False - bpy.context.scene.objects.active = None - - def Rodrigues(rotvec): - theta = np.linalg.norm(rotvec) - r = (rotvec/theta).reshape(3, 1) if theta > 0. else rotvec - cost = np.cos(theta) - mat = np.asarray([[0, -r[2], r[1]], - [r[2], 0, -r[0]], - [-r[1], r[0], 0]]) - return(cost*np.eye(3) + (1-cost)*r.dot(r.T) + np.sin(theta)*mat) - - def rodrigues2bshapes(pose): - rod_rots = np.asarray(pose).reshape(24, 3) - mat_rots = [Rodrigues(rod_rot) for rod_rot in rod_rots] - bshapes = np.concatenate([(mat_rot - np.eye(3)).ravel() - for mat_rot in mat_rots[1:]]) - return(mat_rots, bshapes) - - # apply trans pose and shape to character - def apply_trans_pose_shape(trans, pose, shape, ob, arm_ob, obname, scene, cam_ob, frame=None): - # transform pose into rotation matrices (for pose) and pose blendshapes - mrots, bsh = rodrigues2bshapes(pose) - - # set the location of the first bone to the translation parameter - arm_ob.pose.bones[obname+'_Pelvis'].location = trans - arm_ob.pose.bones[obname+'_root'].location = trans - arm_ob.pose.bones[obname +'_root'].keyframe_insert('location', frame=frame) - # set the pose of each bone to the quaternion specified by pose - for ibone, mrot in enumerate(mrots): - bone = arm_ob.pose.bones[obname+'_'+part_match['bone_%02d' % ibone]] - bone.rotation_quaternion = Matrix(mrot).to_quaternion() - if frame is not None: - bone.keyframe_insert('rotation_quaternion', frame=frame) - bone.keyframe_insert('location', frame=frame) - - # apply pose blendshapes - for ibshape, bshape in enumerate(bsh): - ob.data.shape_keys.key_blocks['Pose%03d' % ibshape].value = bshape - if frame is not None: - ob.data.shape_keys.key_blocks['Pose%03d' % ibshape].keyframe_insert( - 'value', index=-1, frame=frame) - - # apply shape blendshapes - for ibshape, shape_elem in enumerate(shape): - ob.data.shape_keys.key_blocks['Shape%03d' % ibshape].value = shape_elem - if frame is not None: - ob.data.shape_keys.key_blocks['Shape%03d' % ibshape].keyframe_insert( - 'value', index=-1, frame=frame) - import os - import json + data = [] + for i in s_list: + with open(path+ os.sep +i,'r') as f: + data.append(json.load(f)) + #json.load(f) + + len(data) + + #----------------- + x=0 + y=1 + z=2 + + #armature = 'Armature' + + #===================== + #trecho usado para rotacionar ao redor do cursor + def get_override(area_type, region_type): + for area in bpy.context.screen.areas: + if area.type == area_type: + for region in area.regions: + if region.type == region_type: + override = {'area': area, 'region': region} + return override + #error message if the area or region wasn't found + raise RuntimeError("Wasn't able to find", region_type," in area ", area_type, + "\n Make sure it's open while executing script.") - def read_json(path): - with open(path) as f: - data = json.load(f) - return data - - def read_smpl(outname): - assert os.path.exists(outname), outname - datas = read_json(outname) - outputs = [] - for data in datas: - for key in ['Rh', 'Th', 'poses', 'shapes']: - data[key] = np.array(data[key]) - outputs.append(data) - return outputs - - def merge_params(param_list, share_shape=True): - output = {} - for key in ['poses', 'shapes', 'Rh', 'Th', 'expression']: - if key in param_list[0].keys(): - output[key] = np.vstack([v[key] for v in param_list]) - if share_shape: - output['shapes'] = output['shapes'].mean(axis=0, keepdims=True) - return output - - def load_motions(path): - from glob import glob - filenames = sorted(glob(join(path, '*.json'))) - print(filenames) - motions = {} - # for filename in filenames[300:900]: - for filename in filenames: - infos = read_smpl(filename) - for data in infos: - pid = data['id'] - if pid not in motions.keys(): - motions[pid] = [] - motions[pid].append(data) - keys = list(motions.keys()) - # BUG: not strictly equal: (Rh, Th, poses) != (Th, (Rh, poses)) - for pid in motions.keys(): - motions[pid] = merge_params(motions[pid]) - motions[pid]['poses'][:, :3] = motions[pid]['Rh'] - return motions - - def load_smpl_params(datapath): - motions = load_motions(datapath) - return motions - - def init_scene(scene, params, gender='male', angle=0): - # load fbx model - # path_fbx=r'D:\MOCAP\EasyMocap_v2\data\smplx\SMPL_maya' - path_fbx = context.scene.sk_value_prop.sk_smpl_path - bpy.ops.import_scene.fbx(filepath=join(path_fbx, 'basicModel_%s_lbs_10_207_0_v1.0.2.fbx' % 'm'), axis_forward='-Y', axis_up='-Z', global_scale=100) - print('success load') - obname = '%s_avg' % 'm' - ob = bpy.data.objects[obname] - ob.data.use_auto_smooth = False # autosmooth creates artifacts - bpy.ops.object.select_all(action='DESELECT') - bpy.ops.object.select_all(action='DESELECT') - cam_ob = '' - ob.data.shape_keys.animation_data_clear() - arm_ob = bpy.data.objects['Armature'] - arm_ob.animation_data_clear() - - return(ob, obname, arm_ob, cam_ob) - params = [] - #path_smpl = r'D:\MOCAP\EasyMocap_v2\1_output\20210423_3\smpl' - # path_smpl = r'D:\MOCAP\EasyMocap_v2\1_output\20210424_1\smpl' - path_smpl = self.filepath - scene = bpy.data.scenes['Scene'] + #=================================== + #creating bones + #==================================== - ob, obname, arm_ob, cam_ob = init_scene(scene, params, 'm') - #setState0() - #ob.select = True - #bpy.context.scene.objects.active = ob - obj = bpy.context.window.scene.objects[0] - bpy.context.view_layer.objects.active = ob + # obs = [] + # for ob in bpy.context.scene.objects: + # # if ob.type == 'ARMATURE': + # obs.append(ob) + # if len(obs)>0: + # if obs[len(obs)-1].mode != 'OBJECT': + # bpy.ops.object.editmode_toggle() #try to change to object mode + # if obs[len(obs)-1].mode != 'OBJECT': + # bpy.ops.object.editmode_toggle() #try again to change to object mode - # unblocking both the pose and the blendshape limits - for k in ob.data.shape_keys.key_blocks.keys(): - bpy.data.shape_keys["Key"].key_blocks[k].slider_min = -10 - bpy.data.shape_keys["Key"].key_blocks[k].slider_max = 10 + bpy.ops.object.armature_add(enter_editmode=True, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1)) #cria armature e primeiro bone + #bpy.ops.object.editmode_toggle() + #bpy.data.armatures['Armature'].edit_bones.active = bpy.context.object.data.edit_bones['Bone'] - #scene.objects.active = arm_ob obs = [] for ob in bpy.context.scene.objects: @@ -231,308 +131,394 @@ def init_scene(scene, params, gender='male', angle=0): obs.append(ob) #obs - armature = obs[len(obs)-1].name + bpy.ops.armature.select_all(action='DESELECT') + #bpy.context.object.data.edit_bones['Bone'].select_tail=True + obs[len(obs)-1].data.edit_bones['Bone'].select_tail=True + #bpy.ops.armature.extrude_move()#Neck + bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.1, 0.1, 0.1), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), "mirror":True, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False, "use_automerge_and_split":False}) + #bpy.ops.armature.extrude_move()#Head_L + bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.1, 0.1, 0.1), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), "mirror":True, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False, "use_automerge_and_split":False}) - #bpy.data.objects[armature].select_set(True) - obs[len(obs)-1].select_set(True) - view_layer = bpy.context.view_layer - #Armature_obj = bpy.context.scene.objects[armature] - Armature_obj = obs[len(obs)-1] - #view_layer.objects.active = Armature_obj - view_layer.objects.active = arm_ob - - - - motions = load_smpl_params(path_smpl) - for pid, data in motions.items(): - # animation - arm_ob.animation_data_clear() - # cam_ob.animation_data_clear() - # load smpl params: - nFrames = data['poses'].shape[0] - for frame in range(nFrames): - print(frame) - scene.frame_set(frame) - # apply - trans = data['Th'][frame] - shape = data['shapes'][0] - pose = data['poses'][frame] - apply_trans_pose_shape(Vector(trans), pose, shape, ob, - arm_ob, obname, scene, cam_ob, frame) - # scene.update() - bpy.context.view_layer.update() - # bpy.ops.export_anim.bvh(filepath=join(params['out'], '{}.bvh'.format(pid)), frame_start=0, frame_end=nFrames-1) - return{'FINISHED'} + bpy.ops.armature.select_all(action='DESELECT') + bpy.context.object.data.edit_bones['Bone.001'].select_tail=True + #bpy.ops.armature.extrude_move()#Head_R + bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.1, 0.1, 0.1), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), "mirror":True, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False, "use_automerge_and_split":False}) -class Import_Data_easymocap(Operator, ImportHelper): - bl_idname = "mocap.import_easymocap" - bl_label = "Import data" - bl_description = "Import EasyMOCAP" + bpy.ops.armature.bone_primitive_add()#Forearm_L + #bpy.ops.armature.extrude_move()#Arm_L + bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.1, 0.1, 0.1), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), "mirror":True, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False, "use_automerge_and_split":False}) + bpy.ops.armature.bone_primitive_add()#Forearm_R + #bpy.ops.armature.extrude_move()#Arm_R + bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.1, 0.1, 0.1), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), "mirror":True, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False, "use_automerge_and_split":False}) + bpy.ops.armature.bone_primitive_add()#Thigh_L + #bpy.ops.armature.extrude_move()#Leg_L + #bpy.ops.armature.extrude_move()#Foot_L + bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.1, 0.1, 0.1), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), "mirror":True, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False, "use_automerge_and_split":False}) + bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.1, 0.1, 0.1), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), "mirror":True, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False, "use_automerge_and_split":False}) - filename_ext = ".json" + bpy.ops.armature.bone_primitive_add()#Thigh_R + #bpy.ops.armature.extrude_move()#Leg_R + #bpy.ops.armature.extrude_move()#Foot_R + bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.1, 0.1, 0.1), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), "mirror":True, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False, "use_automerge_and_split":False}) + bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.1, 0.1, 0.1), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), "mirror":True, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False, "use_automerge_and_split":False}) - filter_glob: StringProperty( - default="*.json", - options={'HIDDEN'}, - maxlen=255, # Max internal buffer length, longer would be clamped. - ) + #bpy.ops.object.editmode_toggle() + #bpy.data.objects['Armature'].data.edit_bones['Arm_L'].name = 'Teste' + #bpy.context.object.data.edit_bones["Bone"].name = 'Spline' + #bpy.context.object.data.edit_bones["Bone.001"].name = 'Neck' + #bpy.context.object.data.edit_bones["Bone.002"].name = 'Head_L' + #bpy.context.object.data.edit_bones["Bone.003"].name = 'Head_R' + #bpy.context.object.data.edit_bones["Bone.004"].name = 'Forearm_L' + #bpy.context.object.data.edit_bones["Bone.005"].name = 'Arm_L' + #bpy.context.object.data.edit_bones["Bone.006"].name = 'Forearm_R' + #bpy.context.object.data.edit_bones["Bone.007"].name = 'Arm_R' + #bpy.context.object.data.edit_bones["Bone.008"].name = 'Thigh_L' + #bpy.context.object.data.edit_bones["Bone.009"].name = 'Leg_L' + #bpy.context.object.data.edit_bones["Bone.010"].name = 'Foot_L' + #bpy.context.object.data.edit_bones["Bone.011"].name = 'Thigh_R' + #bpy.context.object.data.edit_bones["Bone.012"].name = 'Leg_R' + #bpy.context.object.data.edit_bones["Bone.013"].name = 'Foot_R' - def execute(self,context): - import os - import json - import bpy - from bpy import context - import math + obs[len(obs)-1].data.edit_bones["Bone"].name = 'Spline' + obs[len(obs)-1].data.edit_bones["Bone.001"].name = 'Neck' + obs[len(obs)-1].data.edit_bones["Bone.002"].name = 'Head_L' + obs[len(obs)-1].data.edit_bones["Bone.003"].name = 'Head_R' + obs[len(obs)-1].data.edit_bones["Bone.004"].name = 'Forearm_L' + obs[len(obs)-1].data.edit_bones["Bone.005"].name = 'Arm_L' + obs[len(obs)-1].data.edit_bones["Bone.006"].name = 'Forearm_R' + obs[len(obs)-1].data.edit_bones["Bone.007"].name = 'Arm_R' + obs[len(obs)-1].data.edit_bones["Bone.008"].name = 'Thigh_L' + obs[len(obs)-1].data.edit_bones["Bone.009"].name = 'Leg_L' + obs[len(obs)-1].data.edit_bones["Bone.010"].name = 'Foot_L' + obs[len(obs)-1].data.edit_bones["Bone.011"].name = 'Thigh_R' + obs[len(obs)-1].data.edit_bones["Bone.012"].name = 'Leg_R' + obs[len(obs)-1].data.edit_bones["Bone.013"].name = 'Foot_R' - multiplier = context.scene.sk_value_prop.sk_value - raw_bool = context.scene.sk_value_prop.sk_raw_bool - debug_bool = context.scene.sk_value_prop.sk_debug_bool - # reload_skeleton_bool = context.scene.sk_value_prop.sk_reload_skeleton_bool - limit_rotation_bool = context.scene.sk_value_prop.sk_constraint_limit_rotation_bool + bpy.ops.object.editmode_toggle() - #======================== - #EASYMOCAP - #===================== - #path = r'D:\MOCAP\EasyMocap-master\Teste_20210321_1_out\keypoints3d' - - path = os.path.dirname(self.filepath) - list_dir = os.listdir(path) - s_list = sorted(list_dir) - data = [] - for i in s_list: - with open(path+ os.sep +i,'r') as f: - data.append(json.load(f)) - #json.load(f) - - x=0 - y=1 - z=2 - name_points = 'Point' - - skeleton_import.create_dots(name_points,25) - for item in range(len(data)): - print("frame: ",item) - for limb in range(len(data[item][0]['keypoints3d'])): - # print("limb: ",limb) - bpy.data.objects["Point."+str(1000+limb)[1:]].location[x]=data[item][0]['keypoints3d'][limb][x] - bpy.data.objects["Point."+str(1000+limb)[1:]].location[y]=data[item][0]['keypoints3d'][limb][y] - bpy.data.objects["Point."+str(1000+limb)[1:]].location[z]=data[item][0]['keypoints3d'][limb][z] - #Salva Frame - bpy.data.objects["Point."+str(1000+limb)[1:]].keyframe_insert(data_path="location", frame=item) - #=========== - # selectign Scene Collection - scene_collection = bpy.context.view_layer.layer_collection - bpy.context.view_layer.active_layer_collection = scene_collection - bones = [['Bone','Root'], - ['Bone.001','Spine'], - ['Bone.002','Neck'], - ['Bone.003','Face'], - ['Bone.004','Arm_L'], - ['Bone.005','Forearm_L'], - ['Bone.006','Arm_R'], - ['Bone.007','Forearm_R'], - ['Bone.008','Thigh_L'], - ['Bone.009','Leg_L'], - ['Bone.010','Foot_L'], - ['Bone.011','Thigh_R'], - ['Bone.012','Leg_R'], - ['Bone.013','Foot_R'] - ] - - skeleton_import.create_bones(bones) - unit = skeleton_import.size_ref_bone('Point.001','Point.008','Point.008') - unit = unit*multiplier - spine_multi = context.scene.sk_value_prop.sk_spine_mulitplier - neck_multi = context.scene.sk_value_prop.sk_neck_mulitplier - head_multi = context.scene.sk_value_prop.sk_head_mulitplier - forearm_multi = context.scene.sk_value_prop.sk_forearm_mulitplier - arm_multi = context.scene.sk_value_prop.sk_arm_mulitplier - tigh_multi = context.scene.sk_value_prop.sk_tigh_mulitplier - leg_multi = context.scene.sk_value_prop.sk_leg_mulitplier - foot_multi = context.scene.sk_value_prop.sk_foot_mulitplier - root_sz =unit/10 - spine_sz =unit*3.5*spine_multi - neck_sz =unit*neck_multi - face_sz =unit*head_multi - thigh_sz =unit*3*tigh_multi - leg_sz =unit*2.5*leg_multi - foot_sz =unit*foot_multi #inclinado 45 graud pra frente - arm_sz =unit*1.5*arm_multi - forearm_sz =unit*1.5*forearm_multi - skeleton_import.size_of_bones(unit, root_sz, spine_sz, neck_sz, face_sz, thigh_sz, leg_sz, foot_sz, arm_sz, forearm_sz) + #remove Collection + if bpy.data.collections.find("Points") >= 0: + collection = bpy.data.collections.get('Points') + # + for obj in collection.objects: + bpy.data.objects.remove(obj, do_unlink=True) + bpy.data.collections.remove(collection) - constraints = [ - ['Root', 'COPY_LOCATION', 'Point.008'], - ['Root', 'DAMPED_TRACK', 'Point.001'], - ['Root', 'DAMPED_TRACK', 'Point.012', 'TRACK_X', 0.5], - ['Root', 'DAMPED_TRACK', 'Point.009', 'TRACK_NEGATIVE_X', 0.5], - ['Spine', 'DAMPED_TRACK', 'Point.001'], - ['Spine', 'LIMIT_ROTATION', 'LOCAL'], - ['Spine', 'LIMIT_ROTATION', 'X', True, -0.349066, 0.349066], - ['Spine', 'LIMIT_ROTATION', 'Y', True, -0.698132, 0.698132], - ['Spine', 'LIMIT_ROTATION', 'Z', True, -0.174533, 0.174533], - ['Neck', 'DAMPED_TRACK', 'Point.018'], - ['Neck', 'LIMIT_ROTATION', 'LOCAL'], - ['Neck', 'LIMIT_ROTATION', 'X', True, -0.174533, 1.0472], - ['Neck', 'LIMIT_ROTATION', 'Y', True, -0.523599, 0.523599], - ['Neck', 'LIMIT_ROTATION', 'Z', True, -0.349066, 0.349066], - ['Face', 'DAMPED_TRACK', 'Point.000'], - ['Face', 'LIMIT_ROTATION', 'LOCAL'], - ['Face', 'LIMIT_ROTATION', 'X', True, -0.174533, 0.872665], - ['Face', 'LIMIT_ROTATION', 'Y', True, 0, 0], - ['Face', 'LIMIT_ROTATION', 'Z', True, -0.523599, 0.523599], - ['Arm_L', 'DAMPED_TRACK', 'Point.006'], - ['Forearm_L', 'DAMPED_TRACK', 'Point.007'], - ['Forearm_L', 'LIMIT_ROTATION', 'LOCAL'], - ['Forearm_L', 'LIMIT_ROTATION', 'X', True, 0, 0], - ['Forearm_L', 'LIMIT_ROTATION', 'Y', True, 0, 0], - ['Forearm_L', 'LIMIT_ROTATION', 'Z', True, -2.53073, -0.191986], - ['Arm_R', 'DAMPED_TRACK', 'Point.002'], - ['Forearm_R', 'DAMPED_TRACK', 'Point.003'], - ['Forearm_R', 'LIMIT_ROTATION', 'LOCAL'], - ['Forearm_R', 'LIMIT_ROTATION', 'X', False ], - ['Forearm_R', 'LIMIT_ROTATION', 'Y', False ], - ['Forearm_R', 'LIMIT_ROTATION', 'Z', True, 0.191986, 2.53073], - ['Thigh_L', 'DAMPED_TRACK', 'Point.013'], - ['Thigh_L', 'LIMIT_ROTATION', 'LOCAL'], - ['Thigh_L', 'LIMIT_ROTATION', 'X', True, -1.76278, 1.3439], - ['Thigh_L', 'LIMIT_ROTATION', 'Y', True, 0, 0], - ['Thigh_L', 'LIMIT_ROTATION', 'Z', True, -0.785398, 0.174533], - ['Leg_L', 'DAMPED_TRACK', 'Point.014'], - ['Leg_L', 'LIMIT_ROTATION', 'LOCAL'], - ['Leg_L', 'LIMIT_ROTATION', 'X', True, 0.0698132, 2.0944], - ['Leg_L', 'LIMIT_ROTATION', 'Y', True, 0, 0], - ['Leg_L', 'LIMIT_ROTATION', 'Z', True, 0, 0], - ['Foot_L', 'DAMPED_TRACK', 'Point.019'], - ['Foot_L', 'LIMIT_ROTATION', 'LOCAL'], - ['Foot_L', 'LIMIT_ROTATION', 'X', True, -0.523599, 0.523599], - ['Foot_L', 'LIMIT_ROTATION', 'Y', True, 0, 0], - ['Foot_L', 'LIMIT_ROTATION', 'Z', True, 0, 0], - ['Thigh_R', 'DAMPED_TRACK', 'Point.010'], - ['Thigh_R', 'LIMIT_ROTATION', 'LOCAL'], - ['Thigh_R', 'LIMIT_ROTATION', 'X', True, -1.76278, 1.3439], - ['Thigh_R', 'LIMIT_ROTATION', 'Y', True, 0, 0], - ['Thigh_R', 'LIMIT_ROTATION', 'Z', True, -0.174533, 0.785398], - ['Leg_R', 'DAMPED_TRACK', 'Point.011'], - ['Leg_R', 'LIMIT_ROTATION', 'LOCAL'], - ['Leg_R', 'LIMIT_ROTATION', 'X', True, 0.0698132, 2.0944], - ['Leg_R', 'LIMIT_ROTATION', 'Y', True, 0, 0], - ['Leg_R', 'LIMIT_ROTATION', 'Z', True, 0, 0], - ['Foot_R', 'DAMPED_TRACK', 'Point.022'], - ['Foot_R', 'LIMIT_ROTATION', 'LOCAL'], - ['Foot_R', 'LIMIT_ROTATION', 'X', True, -0.523599, 0.523599], - ['Foot_R', 'LIMIT_ROTATION', 'Y', True, 0, 0], - ['Foot_R', 'LIMIT_ROTATION', 'Z', True, 0, 0] - ] - - # add_constraints(constraints) - skeleton_import.add_constraints_track_X(constraints, limit_rotation_bool) - print(len(data)) - bpy.context.scene.frame_end = len(data) - if debug_bool == False: - bpy.ops.nla.bake(frame_start=1, frame_end=len(data), visual_keying=True, clear_constraints=True, clear_parents=True, bake_types={'POSE'}) - bpy.ops.object.mode_set(mode='OBJECT') - skeleton_import.remove_dots(name_points) - sk_value_prop = context.scene.sk_value_prop - if raw_bool == True: - print('raw_bool True - ',raw_bool) - x_original, y_original, z_original = helper_functions.get_rotations() - sk_value_prop.sk_root_rot_x = math.degrees(x_original) - sk_value_prop.sk_root_rot_y = math.degrees(y_original) - sk_value_prop.sk_root_rot_z = math.degrees(z_original) - #in this case both original and actual is the same, because there was no alteration on the angle - x_actual_deg = math.degrees(x_original) - y_actual_deg = math.degrees(y_original) - z_actual_deg = math.degrees(z_original) + #cria os pontos nuima collection chamada Points + #===================================================== + collection = bpy.data.collections.new("Points") + bpy.context.scene.collection.children.link(collection) - sk_value_prop.sk_root_actual_rot_x = x_actual_deg - sk_value_prop.sk_root_actual_rot_y = y_actual_deg - sk_value_prop.sk_root_actual_rot_z = z_actual_deg + layer_collection = bpy.context.view_layer.layer_collection.children[collection.name] + bpy.context.view_layer.active_layer_collection = layer_collection + + for point in range(25): + bpy.ops.mesh.primitive_plane_add(enter_editmode=True, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1)) + bpy.ops.mesh.merge(type='CENTER') + bpy.ops.object.editmode_toggle() + context.active_object.name = 'Point.'+str(1000+point)[1:] + #===================================================== + + + + + + #colocar cursor no tempo + #bpy.context.scene.cursor.location = (0.0, 0.0, 0.0) + #bpy.context.scene.tool_settings.transform_pivot_point = 'CURSOR' + + + + + ## Deselect all objects + #bpy.ops.object.select_all(action='DESELECT') + + #for o in bpy.data.objects: + # # Check for given object names + # if o.name in ("Point.000","Point.001","Point.002","Point.003","Point.004","Point.005","Point.006","Point.007","Point.008","Point.009" ,"Point.010" ,"Point.011","Point.012","Point.013","Point.014","Point.015","Point.016","Point.017","Point.018","Point.019","Point.020" ,"Point.021","Point.022","Point.023","Point.024"): + # o.select_set(True) + + for item in range(len(data)): + print("frame: ",item) + for limb in range(len(data[item][0]['keypoints3d'])): + # print("limb: ",limb) + bpy.data.objects["Point."+str(1000+limb)[1:]].location[x]=data[item][0]['keypoints3d'][limb][x] + bpy.data.objects["Point."+str(1000+limb)[1:]].location[y]=data[item][0]['keypoints3d'][limb][y] + bpy.data.objects["Point."+str(1000+limb)[1:]].location[z]=data[item][0]['keypoints3d'][limb][z] + # + + # #we need to override the context of our operator + # override = get_override( 'VIEW_3D', 'WINDOW' ) + # #rotate about the X-axis by 45 degrees + # bpy.ops.transform.rotate(override, value=6.283/2, orient_axis="Y") + # + #Salva Frame + bpy.data.objects["Point."+str(1000+limb)[1:]].keyframe_insert(data_path="location", frame=item) + + + + + + + #========================================================================================================== + + def distance(point1, point2) -> float: + #Calculate distance between two points in 3D. + # return math.sqrt((point2[0] - point1[0]) ** 2 + (point2[1] - point1[1]) ** 2 + (point2[2] - point1[2]) ** 2) + return math.sqrt((point2.location[0] - point1.location[0]) ** 2 + (point2.location[1] - point1.location[1]) ** 2 + (point2.location[2] - point1.location[2]) ** 2) + + + def size_bone(point_name1, point_name2, bone): + p1 = bpy.data.objects[point_name1] + p2 = bpy.data.objects[point_name2] + #edit bones + if bpy.context.active_object.mode == 'EDIT': + bpy.context.object.data.edit_bones[bone].length= distance(p1,p2) else: - print('raw_bool False - ',raw_bool) - x_deg, y_deg, z_deg = helper_functions.anim_to_origin() - #take the information of the rotation to the panel - print('result x: ',x_deg) - print('result y: ',y_deg) - print('result z: ',z_deg) - sk_value_prop.sk_root_rot_x = x_deg - sk_value_prop.sk_root_rot_y = y_deg - sk_value_prop.sk_root_rot_z = z_deg + bpy.ops.object.editmode_toggle() + bpy.context.object.data.edit_bones[bone].length= distance(p1,p2) + bpy.ops.object.editmode_toggle() + #selecting and making the armature Active + #selecionando armature - return{'FINISHED'} + obs = [] + for ob in bpy.context.scene.objects: + if ob.type == 'ARMATURE': + obs.append(ob) + #obs -class Reload_sk_easymocap(Operator): + armature = obs[len(obs)-1].name - bl_idname = "mocap.import_easymocap_reload" - bl_label = "Reload Skeleton Easymocap" - bl_description = "Reload SK EasyMOCAP" + #bpy.data.objects[armature].select_set(True) + obs[len(obs)-1].select_set(True) + view_layer = bpy.context.view_layer + #Armature_obj = bpy.context.scene.objects[armature] + Armature_obj = obs[len(obs)-1] + view_layer.objects.active = Armature_obj + + + + size_bone("Point.008", "Point.001", "Spline") + size_bone("Point.001", "Point.000", "Neck") + size_bone("Point.000", "Point.016", "Head_L") + size_bone("Point.000", "Point.015", "Head_R") + + size_bone("Point.005", "Point.006", "Forearm_L") + size_bone("Point.006", "Point.007", "Arm_L") + + size_bone("Point.002", "Point.003", "Forearm_R") + size_bone("Point.003", "Point.004", "Arm_R") + + size_bone("Point.012", "Point.013", "Thigh_L") + size_bone("Point.013", "Point.014", "Leg_L") + size_bone("Point.014", "Point.019", "Foot_L") + + size_bone("Point.009", "Point.010", "Thigh_R") + size_bone("Point.010", "Point.011", "Leg_R") + size_bone("Point.011", "Point.022", "Foot_R") + + #comecando configuração seguir movimentos pontos + #colocando em pose mode + bpy.ops.object.mode_set(mode='POSE') + + #bpy.data.objects[armature].pose.bones["Spine"] + #bpy.data.objects[armature].pose.bones["Spine"].bone + + actual_bone = 'Spline' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + + bpy.ops.pose.constraint_add(type='COPY_LOCATION') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.008"] + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[1].target = bpy.data.objects["Point.001"] + #===== + actual_bone = 'Neck' + bpy.context.object.data.bones.active = bpy.data.objects[armature].pose.bones[actual_bone].bone + bpy.context.object.pose.bones[actual_bone].bone.select = True + + #bpy.ops.pose.constraint_add(type='COPY_LOCATION') + #bpy.context.object.pose.bones[actual_bone].constraints["Copy Location"].target = bpy.data.objects["Point.001"] + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.000"] + #===== + actual_bone = 'Head_L' + bpy.context.object.data.bones.active = bpy.data.objects[armature].pose.bones[actual_bone].bone + bpy.context.object.pose.bones[actual_bone].bone.select = True + + #bpy.ops.pose.constraint_add(type='COPY_LOCATION') + #bpy.context.object.pose.bones[actual_bone].constraints["Copy Location"].target = bpy.data.objects["Point.000"] + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.016"] + #===== + actual_bone = 'Head_R' + bpy.context.object.data.bones.active = bpy.data.objects[armature].pose.bones[actual_bone].bone + bpy.context.object.pose.bones[actual_bone].bone.select = True + + #bpy.ops.pose.constraint_add(type='COPY_LOCATION') + #bpy.context.object.pose.bones[actual_bone].constraints["Copy Location"].target = bpy.data.objects["Point.000"] + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.015"] + #===== + + + actual_bone = 'Forearm_L' + bpy.context.object.data.bones.active = bpy.data.objects[armature].pose.bones[actual_bone].bone + bpy.context.object.pose.bones[actual_bone].bone.select = True + + bpy.ops.pose.constraint_add(type='COPY_LOCATION') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.005"] + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[1].target = bpy.data.objects["Point.006"] + #===== + actual_bone = 'Arm_L' + bpy.context.object.data.bones.active = bpy.data.objects[armature].pose.bones[actual_bone].bone + bpy.context.object.pose.bones[actual_bone].bone.select = True + + #bpy.ops.pose.constraint_add(type='COPY_LOCATION') + #bpy.context.object.pose.bones[actual_bone].constraints["Copy Location"].target = bpy.data.objects["Point.006"] + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.007"] + #===== + + + actual_bone = 'Forearm_R' + bpy.context.object.data.bones.active = bpy.data.objects[armature].pose.bones[actual_bone].bone + bpy.context.object.pose.bones[actual_bone].bone.select = True + + bpy.ops.pose.constraint_add(type='COPY_LOCATION') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.002"] + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[1].target = bpy.data.objects["Point.003"] + #===== + actual_bone = 'Arm_R' + bpy.context.object.data.bones.active = bpy.data.objects[armature].pose.bones[actual_bone].bone + bpy.context.object.pose.bones[actual_bone].bone.select = True + + #bpy.ops.pose.constraint_add(type='COPY_LOCATION') + #bpy.context.object.pose.bones[actual_bone].constraints["Copy Location"].target = bpy.data.objects["Point.003"] + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.004"] + #===== + + + + + actual_bone = 'Thigh_L' + bpy.context.object.data.bones.active = bpy.data.objects[armature].pose.bones[actual_bone].bone + bpy.context.object.pose.bones[actual_bone].bone.select = True + + bpy.ops.pose.constraint_add(type='COPY_LOCATION') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.012"] + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[1].target = bpy.data.objects["Point.013"] + #===== + actual_bone = 'Leg_L' + bpy.context.object.data.bones.active = bpy.data.objects[armature].pose.bones[actual_bone].bone + bpy.context.object.pose.bones[actual_bone].bone.select = True + + #bpy.ops.pose.constraint_add(type='COPY_LOCATION') + #bpy.context.object.pose.bones[actual_bone].constraints["Copy Location"].target = bpy.data.objects["Point.013"] + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.014"] + #===== + actual_bone = 'Foot_L' + bpy.context.object.data.bones.active = bpy.data.objects[armature].pose.bones[actual_bone].bone + bpy.context.object.pose.bones[actual_bone].bone.select = True + + #bpy.ops.pose.constraint_add(type='COPY_LOCATION') + #bpy.context.object.pose.bones[actual_bone].constraints["Copy Location"].target = bpy.data.objects["Point.014"] + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.019"] + #===== + + + + + actual_bone = 'Thigh_R' + bpy.context.object.data.bones.active = bpy.data.objects[armature].pose.bones[actual_bone].bone + bpy.context.object.pose.bones[actual_bone].bone.select = True + + bpy.ops.pose.constraint_add(type='COPY_LOCATION') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.009"] + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[1].target = bpy.data.objects["Point.010"] + #===== + actual_bone = 'Leg_R' + bpy.context.object.data.bones.active = bpy.data.objects[armature].pose.bones[actual_bone].bone + bpy.context.object.pose.bones[actual_bone].bone.select = True + + #bpy.ops.pose.constraint_add(type='COPY_LOCATION') + #bpy.context.object.pose.bones[actual_bone].constraints["Copy Location"].target = bpy.data.objects["Point.010"] + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.011"] + #===== + actual_bone = 'Foot_R' + bpy.context.object.data.bones.active = bpy.data.objects[armature].pose.bones[actual_bone].bone + bpy.context.object.pose.bones[actual_bone].bone.select = True + + #bpy.ops.pose.constraint_add(type='COPY_LOCATION') + #bpy.context.object.pose.bones[actual_bone].constraints["Copy Location"].target = bpy.data.objects["Point.011"] + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.022"] + #===== + + #bpy.data.objects['Armature'].pose.bones.items() + #[('Bone', bpy.data.objects['Armature'].pose.bones["Bone"]), ('Thigh_L', bpy.data.objects['Armature'].pose.bones["Thigh_L"]), ('Leg_L', bpy.data.objects['Armature'].pose.bones["Leg_L"]), ('Foot_L', bpy.data.objects['Armature'].pose.bones["Foot_L"]), ('Spine', bpy.data.objects['Armature'].pose.bones["Spine"]), ('Neck', bpy.data.objects['Armature'].pose.bones["Neck"]), ('Head_L', bpy.data.objects['Armature'].pose.bones["Head_L"]), ('Head_R', bpy.data.objects['Armature'].pose.bones["Head_R"]), ('Forearm_L', bpy.data.objects['Armature'].pose.bones["Forearm_L"]), ('Arm_L', bpy.data.objects['Armature'].pose.bones["Arm_L"]), ('Thigh_R', bpy.data.objects['Armature'].pose.bones["Thigh_R"]), ('Leg_R', bpy.data.objects['Armature'].pose.bones["Leg_R"]), ('Foot_R', bpy.data.objects['Armature'].pose.bones["Foot_R"]), ('Forearm_R', bpy.data.objects['Armature'].pose.bones["Forearm_R"]), ('Arm_R', bpy.data.objects['Armature'].pose.bones["Arm_R"])] - def execute(self,context): + print(len(data)) + bpy.context.scene.frame_end = len(data) + bpy.ops.nla.bake(frame_start=1, frame_end=len(data), visual_keying=True, clear_constraints=True, clear_parents=True, bake_types={'POSE'}) bpy.ops.object.mode_set(mode='OBJECT') - multiplier = context.scene.sk_value_prop.sk_value - - unit = skeleton_import.size_ref_bone('Point.001','Point.008','Point.008') - unit = unit*multiplier - spine_multi = context.scene.sk_value_prop.sk_spine_mulitplier - neck_multi = context.scene.sk_value_prop.sk_neck_mulitplier - head_multi = context.scene.sk_value_prop.sk_head_mulitplier - forearm_multi = context.scene.sk_value_prop.sk_forearm_mulitplier - arm_multi = context.scene.sk_value_prop.sk_arm_mulitplier - tigh_multi = context.scene.sk_value_prop.sk_tigh_mulitplier - leg_multi = context.scene.sk_value_prop.sk_leg_mulitplier - foot_multi = context.scene.sk_value_prop.sk_foot_mulitplier - root_sz =unit/10 - spine_sz =unit*3.5*spine_multi - neck_sz =unit*neck_multi - face_sz =unit*head_multi - thigh_sz =unit*3*tigh_multi - leg_sz =unit*2.5*leg_multi - foot_sz =unit*foot_multi #inclinado 45 graud pra frente - arm_sz =unit*1.5*arm_multi - forearm_sz =unit*1.5*forearm_multi + #apagar collection points criada + collection = bpy.data.collections.get('Points') + # + for obj in collection.objects: + bpy.data.objects.remove(obj, do_unlink=True) + bpy.data.collections.remove(collection) - skeleton_import.size_of_bones(unit, root_sz, spine_sz, neck_sz, face_sz, thigh_sz, leg_sz, foot_sz, arm_sz, forearm_sz) return{'FINISHED'} + class Import_Data_frankmocap(Operator, ImportHelper): bl_idname = "mocap.import_frankmocap" bl_label = "Import data from Frankmocap" @@ -547,6 +533,9 @@ class Import_Data_frankmocap(Operator, ImportHelper): maxlen=255, # Max internal buffer length, longer would be clamped. ) + + + def execute(self,context): #""" @@ -571,11 +560,12 @@ def middle_point(p1,p2,p_middle): bpy.context.view_layer.objects.active = bpy.data.objects[p2] obs = bpy.context.selected_objects n = len(obs) - # print('n: ',n) + # print('n: ',n) assert(n) #scene.cursor.location = sum([o.matrix_world.translation for o in obs], Vector()) / n bpy.data.objects[p_middle].location = sum([o.matrix_world.translation for o in obs], Vector()) / n + def create_dots(name, amount): #remove Collection if bpy.data.collections.find(name) >= 0: @@ -588,10 +578,10 @@ def create_dots(name, amount): #===================================================== collection = bpy.data.collections.new(name) bpy.context.scene.collection.children.link(collection) - # + # layer_collection = bpy.context.view_layer.layer_collection.children[collection.name] bpy.context.view_layer.active_layer_collection = layer_collection - # + # for point in range(amount): bpy.ops.mesh.primitive_plane_add(enter_editmode=True, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1)) bpy.ops.mesh.merge(type='CENTER') @@ -599,11 +589,16 @@ def create_dots(name, amount): bpy.context.active_object.name = name+'.'+str(1000+point)[1:] #===================================================== + #============================== + #codes to size the bones + #============================== + def distance(point1, point2) -> float: #Calculate distance between two points in 3D. - # return math.sqrt((point2[0] - point1[0]) ** 2 + (point2[1] - point1[1]) ** 2 + (point2[2] - point1[2]) ** 2) + # return math.sqrt((point2[0] - point1[0]) ** 2 + (point2[1] - point1[1]) ** 2 + (point2[2] - point1[2]) ** 2) return math.sqrt((point2.location[0] - point1.location[0]) ** 2 + (point2.location[1] - point1.location[1]) ** 2 + (point2.location[2] - point1.location[2]) ** 2) + def size_bone(point_name1, point_name2, bone): p1 = bpy.data.objects[point_name1] p2 = bpy.data.objects[point_name2] @@ -615,330 +610,155 @@ def size_bone(point_name1, point_name2, bone): bpy.context.object.data.edit_bones[bone].length= distance(p1,p2) bpy.ops.object.editmode_toggle() - def create_bones(bones_list): - #=================================== - #creating bones - #==================================== - - bpy.ops.object.armature_add(enter_editmode=True, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1)) #cria armature e primeiro bone - #bpy.ops.object.editmode_toggle() - #bpy.data.armatures['Armature'].edit_bones.active = bpy.context.object.data.edit_bones['Bone'] - obs = [] - for ob in bpy.context.scene.objects: - if ob.type == 'ARMATURE': - obs.append(ob) - #obs - + create_dots('Point',49) - bpy.ops.armature.select_all(action='DESELECT') - obs[len(obs)-1].data.edit_bones['Bone'].select_tail=True + # pkl_path=r'C:\MOCAP\frankmocap\mocap_output\mocap\temp' + pkl_path = os.path.dirname(self.filepath) + list_dir = os.listdir(pkl_path) + s_list = sorted(list_dir) - - bpy.ops.armature.bone_primitive_add()#Spine - #Neck - bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1)}) - #Face - bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1)}) + len(s_list) + x=0 + y=1 + z=2 + multi=100 + #armature = 'Armature' - bpy.ops.armature.bone_primitive_add()#Arm_L - #Forearm_L - bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1)}) - - bpy.ops.armature.bone_primitive_add()#Arm_R - #Forearm_R - bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1)}) - - bpy.ops.armature.bone_primitive_add()#Thigh_L - #Leg_L - #Foot_L - bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1)}) - bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1)}) - - bpy.ops.armature.bone_primitive_add()#Thigh_R - #Leg_R - #Foot_R - bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1)}) - bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1)}) - - for i in range(len(bones_list)): - obs[len(obs)-1].data.edit_bones[bones_list[i][0]].name = bones_list[i][1] + #exemplo + file = open(pkl_path+ os.sep +s_list[0],'rb') - #Hierarquia - bpy.context.object.data.edit_bones["Spine"].parent = bpy.context.object.data.edit_bones["Root"] - bpy.context.object.data.edit_bones["Arm_L"].parent = bpy.context.object.data.edit_bones["Spine"] - bpy.context.object.data.edit_bones["Arm_R"].parent = bpy.context.object.data.edit_bones["Spine"] - bpy.context.object.data.edit_bones["Thigh_L"].parent = bpy.context.object.data.edit_bones["Root"] - bpy.context.object.data.edit_bones["Thigh_R"].parent = bpy.context.object.data.edit_bones["Root"] + pic = pickle.load(file) + file.close() - bpy.ops.object.editmode_toggle() + nppic = np.load(pkl_path+ os.sep +s_list[0], allow_pickle=True) - def distance(point1, point2) -> float: - #Calculate distance between two points in 3D. - #return math.sqrt((point2[0] - point1[0]) ** 2 + (point2[1] - point1[1]) ** 2 + (point2[2] - point1[2]) ** 2) - return math.sqrt((point2.location[0] - point1.location[0]) ** 2 + (point2.location[1] - point1.location[1]) ** 2 + (point2.location[2] - point1.location[2]) ** 2) + for item in range(len(s_list)-1): + nppic = np.load(pkl_path+ os.sep +s_list[item], allow_pickle=True) + # nppic['pred_output_list'][0]['pred_body_joints_img'] #todos os limbs + print("frame: ",item) + for limb in range(len(nppic['pred_output_list'][0]['pred_body_joints_img'])): + # print("limb: ",limb) + bpy.data.objects["Point."+str(1000+limb)[1:]].location[z]=nppic['pred_output_list'][0]['pred_body_joints_img'][limb][x]/multi + bpy.data.objects["Point."+str(1000+limb)[1:]].location[y]=nppic['pred_output_list'][0]['pred_body_joints_img'][limb][y]/multi + bpy.data.objects["Point."+str(1000+limb)[1:]].location[x]=nppic['pred_output_list'][0]['pred_body_joints_img'][limb][z]/multi + bpy.data.objects["Point."+str(1000+limb)[1:]].keyframe_insert(data_path="location", frame=item) - def size_bone(point_name1, point_name2, bone): - p1 = bpy.data.objects[point_name1] - p2 = bpy.data.objects[point_name2] - #edit bones - if bpy.context.active_object.mode == 'EDIT': - bpy.context.object.data.edit_bones[bone].length= distance(p1,p2) - else: - bpy.ops.object.editmode_toggle() - bpy.context.object.data.edit_bones[bone].length= distance(p1,p2) - bpy.ops.object.editmode_toggle() - def size_ref_bone(p1,p2,p_final): - from mathutils import Vector - import bpy + len(nppic['pred_output_list'][0]['pred_body_joints_img']) - ## size of the reference bone (spine) - bpy.ops.object.select_all(action='DESELECT') - bpy.data.objects[p1].select_set(True) - bpy.data.objects[p2].select_set(True) - # bpy.context.view_layer.objects.active = bpy.data.objects['Point.034'] - bpy.context.view_layer.objects.active = bpy.data.objects[p2] - obs = bpy.context.selected_objects - n = len(obs) - # print('n: ',n) - assert(n) - #scene.cursor.location = sum([o.matrix_world.translation for o in obs], Vector()) / n - #bpy.data.objects[p_middle].location = sum([o.matrix_world.translation for o in obs], Vector()) / n - - x_subtract = abs(obs[0].matrix_world.translation.x - obs[1].matrix_world.translation.x) - y_subtract = abs(obs[0].matrix_world.translation.y - obs[1].matrix_world.translation.y) - z_subtract = abs(obs[0].matrix_world.translation.z - obs[1].matrix_world.translation.z) - - max(x_subtract, y_subtract, z_subtract) #maior das medidas - unit_def = max(x_subtract, y_subtract, z_subtract)/3 - #end of size of reference bone Spine - return unit_def - - def size_of_bones(root_size, spine_size, neck_size, face_size, thigh_size, leg_size, foot_size, arm_size, forearm_size): - #========================================== - #selecting and making the armature Active - #selecionando armature - #========================================== - bpy.ops.object.select_all(action='DESELECT') - #bpy.ops.armature.select_all(action='DESELECT') - obs = [] - for ob in bpy.context.scene.objects: - if ob.type == 'ARMATURE': - obs.append(ob) - #obs - armature = obs[len(obs)-1].name + import bpy - #bpy.data.objects[armature].select_set(True) - obs[len(obs)-1].select_set(True) - view_layer = bpy.context.view_layer - #Armature_obj = bpy.context.scene.objects[armature] - Armature_obj = obs[len(obs)-1] - view_layer.objects.active = Armature_obj - #converting to euler rotation - order = 'XYZ' - context = bpy.context - rig_object = context.active_object - for pb in rig_object.pose.bones: - pb.rotation_mode = order + #=========== + # selectign Scene Collection + scene_collection = bpy.context.view_layer.layer_collection + bpy.context.view_layer.active_layer_collection = scene_collection - bpy.ops.object.editmode_toggle() + #=================================== + #creating bones + #==================================== - #changing location - #resetting - bpy.context.object.data.edit_bones["Spine"].head.xy=0 - bpy.context.object.data.edit_bones["Neck"].head.xy=0 - bpy.context.object.data.edit_bones["Face"].head.xy=0 - - bpy.context.object.data.edit_bones["Arm_L"].head.xy=0 - bpy.context.object.data.edit_bones["Forearm_L"].head.xy=0 - - bpy.context.object.data.edit_bones["Arm_R"].head.xy=0 - bpy.context.object.data.edit_bones["Forearm_R"].head.xy=0 - - bpy.context.object.data.edit_bones["Thigh_L"].head.xy=0 - bpy.context.object.data.edit_bones["Leg_L"].head.xy=0 - bpy.context.object.data.edit_bones["Foot_L"].head.xy=0 - - bpy.context.object.data.edit_bones["Thigh_R"].head.xy=0 - bpy.context.object.data.edit_bones["Leg_R"].head.xy=0 - bpy.context.object.data.edit_bones["Foot_R"].head.xy=0 - #tail - bpy.context.object.data.edit_bones["Face"].tail.xy=0 - bpy.context.object.data.edit_bones["Neck"].tail.xy=0 - bpy.context.object.data.edit_bones["Forearm_L"].tail.xy=0 - bpy.context.object.data.edit_bones["Forearm_R"].tail.xy=0 - bpy.context.object.data.edit_bones["Foot_L"].tail.xy=0 - bpy.context.object.data.edit_bones["Foot_R"].tail.xy=0 - - - - - bpy.context.object.data.edit_bones["Root"].length = root_size - - bpy.context.object.data.edit_bones["Spine"].head.z = unit/2 - bpy.context.object.data.edit_bones["Spine"].tail.z = spine_size - - bpy.context.object.data.edit_bones["Neck"].tail.z = spine_size + neck_size - bpy.context.object.data.edit_bones["Neck"].tail.y = neck_size/3 - bpy.context.object.data.edit_bones["Face"].tail.z = spine_size + neck_size - bpy.context.object.data.edit_bones["Face"].tail.y = face_size*-1 - - bpy.context.object.data.edit_bones["Arm_L"].head.z= spine_size - bpy.context.object.data.edit_bones["Arm_L"].head.x= unit*3/4 - bpy.context.object.data.edit_bones["Forearm_L"].head.z= spine_size - bpy.context.object.data.edit_bones["Forearm_L"].head.x= unit + arm_size - bpy.context.object.data.edit_bones["Forearm_L"].tail.z= spine_size - bpy.context.object.data.edit_bones["Forearm_L"].tail.x= unit + arm_size + forearm_size - - bpy.context.object.data.edit_bones["Arm_R"].head.z= spine_size - bpy.context.object.data.edit_bones["Arm_R"].head.x= (unit*3/4)*-1 - bpy.context.object.data.edit_bones["Forearm_R"].head.z= spine_size - bpy.context.object.data.edit_bones["Forearm_R"].head.x= (unit + arm_size) *-1 - bpy.context.object.data.edit_bones["Forearm_R"].tail.z= spine_size - bpy.context.object.data.edit_bones["Forearm_R"].tail.x= (unit + arm_size + forearm_size) *-1 - - bpy.context.object.data.edit_bones["Thigh_L"].head.x= unit*3/4 - bpy.context.object.data.edit_bones["Thigh_L"].head.z= (unit/5)*-1 - bpy.context.object.data.edit_bones["Leg_L"].head.x= unit*3/4 - bpy.context.object.data.edit_bones["Leg_L"].head.z= (unit/5 + thigh_size)*-1 - bpy.context.object.data.edit_bones["Foot_L"].head.x= unit*3/4 - bpy.context.object.data.edit_bones["Foot_L"].head.z= (unit/5 + thigh_size + leg_size)*-1 - bpy.context.object.data.edit_bones["Foot_L"].tail.x= unit*3/4 - bpy.context.object.data.edit_bones["Foot_L"].tail.z= (unit/5 + thigh_size + leg_size + foot_size/2)*-1 - bpy.context.object.data.edit_bones["Foot_L"].tail.y= foot_sz/2*-1 - - bpy.context.object.data.edit_bones["Thigh_R"].head.x= unit*3/4*-1 - bpy.context.object.data.edit_bones["Thigh_R"].head.z= (unit/5)*-1 - bpy.context.object.data.edit_bones["Leg_R"].head.x= unit*3/4*-1 - bpy.context.object.data.edit_bones["Leg_R"].head.z= (unit/5 + thigh_size)*-1 - bpy.context.object.data.edit_bones["Foot_R"].head.x= unit*3/4*-1 - bpy.context.object.data.edit_bones["Foot_R"].head.z= (unit/5 + thigh_size + leg_size)*-1 - bpy.context.object.data.edit_bones["Foot_R"].tail.x= unit*3/4*-1 - bpy.context.object.data.edit_bones["Foot_R"].tail.z= (unit/5 + thigh_size + leg_size + foot_size/2)*-1 - bpy.context.object.data.edit_bones["Foot_R"].tail.y= foot_size/2*-1 + bpy.ops.object.armature_add(enter_editmode=True, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1)) #cria armature e primeiro bone + #bpy.ops.object.editmode_toggle() + #bpy.data.armatures['Armature'].edit_bones.active = bpy.context.object.data.edit_bones['Bone'] - bpy.ops.object.editmode_toggle() - def add_constraints_track_X(constraints): - obs = [] - for ob in bpy.context.scene.objects: - if ob.type == 'ARMATURE': - obs.append(ob) - #obs - - bpy.ops.object.mode_set(mode='POSE') - - for i in range(len(constraints)): - print('processar: ',constraints[i]) - if constraints[i][1] == 'COPY_LOCATION' or constraints[i][1] == 'DAMPED_TRACK': - # print('in 1 j: ',j,' - name: ',constraints[i][0],' constraint: ',constraints[i][1]) - obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[constraints[i][0]].bone - obs[len(obs)-1].pose.bones[constraints[i][0]].bone.select = True - # - bpy.ops.pose.constraint_add(type=constraints[i][1]) - qtd_constraint = len(bpy.context.object.pose.bones[constraints[i][0]].constraints) - bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].target = bpy.data.objects[constraints[i][2]] - if constraints[i][1] == 'DAMPED_TRACK' and len(constraints[i])==4: - bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].track_axis = constraints[i][3] - # - if constraints[i][1] == 'LIMIT_ROTATION': - qtd_constraint = len(bpy.context.object.pose.bones[constraints[i][0]].constraints) - if constraints[i][2] == 'LOCAL': - bpy.ops.pose.constraint_add(type=constraints[i][1]) - qtd_constraint = len(bpy.context.object.pose.bones[constraints[i][0]].constraints) - bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].owner_space = constraints[i][2] - if constraints[i][2] == 'X': - if constraints[i][3] == True: - bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].use_limit_x = constraints[i][3] - bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].min_x = constraints[i][4] - bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].max_x = constraints[i][5] - if constraints[i][2] == 'Y': - if constraints[i][3] == True: - bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].use_limit_y = constraints[i][3] - bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].min_y = constraints[i][4] - bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].max_y = constraints[i][5] - if constraints[i][2] == 'Z': - if constraints[i][3] == True: - bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].use_limit_z = constraints[i][3] - bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].min_z = constraints[i][4] - bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].max_z = constraints[i][5] + obs = [] + for ob in bpy.context.scene.objects: + if ob.type == 'ARMATURE': + obs.append(ob) + #obs - create_dots('Point',49) - # pkl_path=r'C:\MOCAP\frankmocap\mocap_output\mocap\temp' - pkl_path = os.path.dirname(self.filepath) - list_dir = os.listdir(pkl_path) - s_list = sorted(list_dir) + bpy.ops.armature.select_all(action='DESELECT') + #bpy.context.object.data.edit_bones['Bone'].select_tail=True + obs[len(obs)-1].data.edit_bones['Bone'].select_tail=True - len(s_list) + bpy.ops.armature.bone_primitive_add()#Spine + #bpy.ops.armature.extrude_move()#Neck + bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), "mirror":True, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False, "use_automerge_and_split":False}) + ##bpy.ops.armature.extrude_move()#Face + bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), "mirror":True, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False, "use_automerge_and_split":False}) - x=0 - y=1 - z=2 - multi=100 - #armature = 'Armature' + bpy.ops.armature.bone_primitive_add()#Arm_L + #bpy.ops.armature.extrude_move()#Forearm_L + bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), "mirror":True, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False, "use_automerge_and_split":False}) - #exemplo - file = open(pkl_path+ os.sep +s_list[0],'rb') + bpy.ops.armature.bone_primitive_add()#Arm_R + #bpy.ops.armature.extrude_move()#Forearm_R + bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), "mirror":True, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False, "use_automerge_and_split":False}) - pic = pickle.load(file) - file.close() + bpy.ops.armature.bone_primitive_add()#Thigh_L + #bpy.ops.armature.extrude_move()#Leg_L + #bpy.ops.armature.extrude_move()#Foot_L + bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), "mirror":True, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False, "use_automerge_and_split":False}) + bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), "mirror":True, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False, "use_automerge_and_split":False}) - nppic = np.load(pkl_path+ os.sep +s_list[0], allow_pickle=True) + bpy.ops.armature.bone_primitive_add()#Thigh_R + #bpy.ops.armature.extrude_move()#Leg_R + #bpy.ops.armature.extrude_move()#Foot_R + bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), "mirror":True, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False, "use_automerge_and_split":False}) + bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), "mirror":True, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False, "use_automerge_and_split":False}) - for item in range(len(s_list)-1): - nppic = np.load(pkl_path+ os.sep +s_list[item], allow_pickle=True) - # nppic['pred_output_list'][0]['pred_body_joints_img'] #todos os limbs - print("frame: ",item) - for limb in range(len(nppic['pred_output_list'][0]['pred_body_joints_img'])): - # print("limb: ",limb) - bpy.data.objects["Point."+str(1000+limb)[1:]].location[z]=nppic['pred_output_list'][0]['pred_body_joints_img'][limb][x]/multi - bpy.data.objects["Point."+str(1000+limb)[1:]].location[y]=nppic['pred_output_list'][0]['pred_body_joints_img'][limb][y]/multi - bpy.data.objects["Point."+str(1000+limb)[1:]].location[x]=nppic['pred_output_list'][0]['pred_body_joints_img'][limb][z]/multi - bpy.data.objects["Point."+str(1000+limb)[1:]].keyframe_insert(data_path="location", frame=item) + obs[len(obs)-1].data.edit_bones["Bone"].name = 'Root' + obs[len(obs)-1].data.edit_bones["Bone.001"].name = 'Spine' + obs[len(obs)-1].data.edit_bones["Bone.002"].name = 'Neck' + obs[len(obs)-1].data.edit_bones["Bone.003"].name = 'Face' + obs[len(obs)-1].data.edit_bones["Bone.004"].name = 'Arm_L' + obs[len(obs)-1].data.edit_bones["Bone.005"].name = 'Forearm_L' + obs[len(obs)-1].data.edit_bones["Bone.006"].name = 'Arm_R' + obs[len(obs)-1].data.edit_bones["Bone.007"].name = 'Forearm_R' + obs[len(obs)-1].data.edit_bones["Bone.008"].name = 'Thigh_L' + obs[len(obs)-1].data.edit_bones["Bone.009"].name = 'Leg_L' + obs[len(obs)-1].data.edit_bones["Bone.010"].name = 'Foot_L' + obs[len(obs)-1].data.edit_bones["Bone.011"].name = 'Thigh_R' + obs[len(obs)-1].data.edit_bones["Bone.012"].name = 'Leg_R' + obs[len(obs)-1].data.edit_bones["Bone.013"].name = 'Foot_R' - len(nppic['pred_output_list'][0]['pred_body_joints_img']) + #Hierarquia + bpy.context.object.data.edit_bones["Spine"].parent = bpy.context.object.data.edit_bones["Root"] + bpy.context.object.data.edit_bones["Arm_L"].parent = bpy.context.object.data.edit_bones["Spine"] + bpy.context.object.data.edit_bones["Arm_R"].parent = bpy.context.object.data.edit_bones["Spine"] + bpy.context.object.data.edit_bones["Thigh_L"].parent = bpy.context.object.data.edit_bones["Root"] + bpy.context.object.data.edit_bones["Thigh_R"].parent = bpy.context.object.data.edit_bones["Root"] + + bpy.ops.object.editmode_toggle() + + from mathutils import Vector import bpy + bpy.ops.object.select_all(action='DESELECT') + bpy.data.objects['Point.001'].select_set(True) + bpy.data.objects['Point.008'].select_set(True) + bpy.context.view_layer.objects.active = bpy.data.objects['Point.034'] + obs = bpy.context.selected_objects + n = len(obs) + # print('n: ',n) + assert(n) + #scene.cursor.location = sum([o.matrix_world.translation for o in obs], Vector()) / n + #bpy.data.objects[p_middle].location = sum([o.matrix_world.translation for o in obs], Vector()) / n - #=========== - # selectign Scene Collection - scene_collection = bpy.context.view_layer.layer_collection - bpy.context.view_layer.active_layer_collection = scene_collection - bones = [['Bone','Root'], - ['Bone.001','Spine'], - ['Bone.002','Neck'], - ['Bone.003','Face'], - ['Bone.004','Arm_L'], - ['Bone.005','Forearm_L'], - ['Bone.006','Arm_R'], - ['Bone.007','Forearm_R'], - ['Bone.008','Thigh_L'], - ['Bone.009','Leg_L'], - ['Bone.010','Foot_L'], - ['Bone.011','Thigh_R'], - ['Bone.012','Leg_R'], - ['Bone.013','Foot_R'] - ] - - create_bones(bones) - - unit = size_ref_bone('Point.001','Point.008','Point.034') + + x_subtract = abs(obs[0].matrix_world.translation.x - obs[1].matrix_world.translation.x) + y_subtract = abs(obs[0].matrix_world.translation.y - obs[1].matrix_world.translation.y) + z_subtract = abs(obs[0].matrix_world.translation.z - obs[1].matrix_world.translation.z) + + max(x_subtract, y_subtract, z_subtract) #maior das medidas + unit = max(x_subtract, y_subtract, z_subtract)/3 unit = unit*multiplier root_sz =unit/10 @@ -951,72 +771,393 @@ def add_constraints_track_X(constraints): arm_sz =unit*1.5 forearm_sz =unit*1.5 - size_of_bones(root_sz, spine_sz, neck_sz, face_sz, thigh_sz, leg_sz, foot_sz, arm_sz, forearm_sz) - - constraints = [ - ['Root', 'COPY_LOCATION', 'Point.039'], - ['Root', 'DAMPED_TRACK', 'Point.037'], - ['Root', 'DAMPED_TRACK', 'Point.027','TRACK_X'], - ['Spine', 'DAMPED_TRACK', 'Point.037'], - ['Spine', 'LIMIT_ROTATION', 'LOCAL'], - ['Spine', 'LIMIT_ROTATION', 'X', True, -0.349066, 0.349066], - ['Spine', 'LIMIT_ROTATION', 'Y', True, -0.698132, 0.698132], - ['Spine', 'LIMIT_ROTATION', 'Z', True, -0.174533, 0.174533], - ['Neck', 'DAMPED_TRACK', 'Point.042'], - ['Neck', 'LIMIT_ROTATION', 'LOCAL'], - ['Neck', 'LIMIT_ROTATION', 'X', True, -0.174533, 1.0472], - ['Neck', 'LIMIT_ROTATION', 'Y', True, -0.523599, 0.523599], - ['Neck', 'LIMIT_ROTATION', 'Z', True, -0.349066, 0.349066], - ['Face', 'DAMPED_TRACK', 'Point.044'], - ['Face', 'LIMIT_ROTATION', 'LOCAL'], - ['Face', 'LIMIT_ROTATION', 'X', True, -0.174533, 0.872665], - ['Face', 'LIMIT_ROTATION', 'Y', True, 0, 0], - ['Face', 'LIMIT_ROTATION', 'Z', True, -0.523599, 0.523599], - ['Arm_L', 'DAMPED_TRACK', 'Point.032'], - ['Forearm_L', 'DAMPED_TRACK', 'Point.031'], - ['Forearm_L', 'LIMIT_ROTATION', 'LOCAL'], - ['Forearm_L', 'LIMIT_ROTATION', 'X', True, 0, 0], - ['Forearm_L', 'LIMIT_ROTATION', 'Y', True, 0, 0], - ['Forearm_L', 'LIMIT_ROTATION', 'Z', True, -2.53073, -0.191986], - ['Arm_R', 'DAMPED_TRACK', 'Point.035'], - ['Forearm_R', 'DAMPED_TRACK', 'Point.036'], - ['Forearm_R', 'LIMIT_ROTATION', 'LOCAL'], - ['Forearm_R', 'LIMIT_ROTATION', 'X', False ], - ['Forearm_R', 'LIMIT_ROTATION', 'Y', False ], - ['Forearm_R', 'LIMIT_ROTATION', 'Z', True, 0.191986, 2.53073], - ['Thigh_L', 'DAMPED_TRACK', 'Point.026'], - ['Thigh_L', 'LIMIT_ROTATION', 'LOCAL'], - ['Thigh_L', 'LIMIT_ROTATION', 'X', True, -1.76278, 1.3439], - ['Thigh_L', 'LIMIT_ROTATION', 'Y', True, 0, 0], - ['Thigh_L', 'LIMIT_ROTATION', 'Z', True, -0.785398, 0.174533], - ['Leg_L', 'DAMPED_TRACK', 'Point.025'], - ['Leg_L', 'LIMIT_ROTATION', 'LOCAL'], - ['Leg_L', 'LIMIT_ROTATION', 'X', True, 0.0698132, 2.0944], - ['Leg_L', 'LIMIT_ROTATION', 'Y', True, 0, 0], - ['Leg_L', 'LIMIT_ROTATION', 'Z', True, 0, 0], - ['Foot_L', 'DAMPED_TRACK', 'Point.022'], - ['Foot_L', 'LIMIT_ROTATION', 'LOCAL'], - ['Foot_L', 'LIMIT_ROTATION', 'X', True, -0.523599, 0.523599], - ['Foot_L', 'LIMIT_ROTATION', 'Y', True, 0, 0], - ['Foot_L', 'LIMIT_ROTATION', 'Z', True, 0, 0], - ['Thigh_R', 'DAMPED_TRACK', 'Point.029'], - ['Thigh_R', 'LIMIT_ROTATION', 'LOCAL'], - ['Thigh_R', 'LIMIT_ROTATION', 'X', True, -1.76278, 1.3439], - ['Thigh_R', 'LIMIT_ROTATION', 'Y', True, 0, 0], - ['Thigh_R', 'LIMIT_ROTATION', 'Z', True, -0.174533, 0.785398], - ['Leg_R', 'DAMPED_TRACK', 'Point.030'], - ['Leg_R', 'LIMIT_ROTATION', 'LOCAL'], - ['Leg_R', 'LIMIT_ROTATION', 'X', True, 0.0698132, 2.0944], - ['Leg_R', 'LIMIT_ROTATION', 'Y', True, 0, 0], - ['Leg_R', 'LIMIT_ROTATION', 'Z', True, 0, 0], - ['Foot_R', 'DAMPED_TRACK', 'Point.019'], - ['Foot_R', 'LIMIT_ROTATION', 'LOCAL'], - ['Foot_R', 'LIMIT_ROTATION', 'X', True, -0.523599, 0.523599], - ['Foot_R', 'LIMIT_ROTATION', 'Y', True, 0, 0], - ['Foot_R', 'LIMIT_ROTATION', 'Z', True, 0, 0] - ] - - add_constraints_track_X(constraints) + + + #if bpy.context.active_object.mode != 'EDIT': + # bpy.ops.object.editmode_toggle() + #========================================== + #selecting and making the armature Active + #selecionando armature + #========================================== + bpy.ops.object.select_all(action='DESELECT') + #bpy.ops.armature.select_all(action='DESELECT') + + obs = [] + for ob in bpy.context.scene.objects: + if ob.type == 'ARMATURE': + obs.append(ob) + #obs + + armature = obs[len(obs)-1].name + + #bpy.data.objects[armature].select_set(True) + obs[len(obs)-1].select_set(True) + view_layer = bpy.context.view_layer + #Armature_obj = bpy.context.scene.objects[armature] + Armature_obj = obs[len(obs)-1] + view_layer.objects.active = Armature_obj + + + #converting to euler rotation + order = 'XYZ' + context = bpy.context + rig_object = context.active_object + for pb in rig_object.pose.bones: + pb.rotation_mode = order + + + + bpy.ops.object.editmode_toggle() + + #changing location + #resetting + bpy.context.object.data.edit_bones["Spine"].head.xy=0 + bpy.context.object.data.edit_bones["Neck"].head.xy=0 + bpy.context.object.data.edit_bones["Face"].head.xy=0 + + bpy.context.object.data.edit_bones["Arm_L"].head.xy=0 + bpy.context.object.data.edit_bones["Forearm_L"].head.xy=0 + + bpy.context.object.data.edit_bones["Arm_R"].head.xy=0 + bpy.context.object.data.edit_bones["Forearm_R"].head.xy=0 + + bpy.context.object.data.edit_bones["Thigh_L"].head.xy=0 + bpy.context.object.data.edit_bones["Leg_L"].head.xy=0 + bpy.context.object.data.edit_bones["Foot_L"].head.xy=0 + + bpy.context.object.data.edit_bones["Thigh_R"].head.xy=0 + bpy.context.object.data.edit_bones["Leg_R"].head.xy=0 + bpy.context.object.data.edit_bones["Foot_R"].head.xy=0 + #tail + bpy.context.object.data.edit_bones["Face"].tail.xy=0 + bpy.context.object.data.edit_bones["Neck"].tail.xy=0 + bpy.context.object.data.edit_bones["Forearm_L"].tail.xy=0 + bpy.context.object.data.edit_bones["Forearm_R"].tail.xy=0 + bpy.context.object.data.edit_bones["Foot_L"].tail.xy=0 + bpy.context.object.data.edit_bones["Foot_R"].tail.xy=0 + + + + + bpy.context.object.data.edit_bones["Root"].length = root_sz + + bpy.context.object.data.edit_bones["Spine"].head.z = unit/2 + bpy.context.object.data.edit_bones["Spine"].tail.z = spine_sz + + bpy.context.object.data.edit_bones["Neck"].tail.z = spine_sz + neck_sz + bpy.context.object.data.edit_bones["Neck"].tail.y = neck_sz/3 + bpy.context.object.data.edit_bones["Face"].tail.z = spine_sz + neck_sz + bpy.context.object.data.edit_bones["Face"].tail.y = face_sz*-1 + + bpy.context.object.data.edit_bones["Arm_L"].head.z= spine_sz + bpy.context.object.data.edit_bones["Arm_L"].head.x= unit*3/4 + bpy.context.object.data.edit_bones["Forearm_L"].head.z= spine_sz + bpy.context.object.data.edit_bones["Forearm_L"].head.x= unit + arm_sz + bpy.context.object.data.edit_bones["Forearm_L"].tail.z= spine_sz + bpy.context.object.data.edit_bones["Forearm_L"].tail.x= unit + arm_sz + forearm_sz + + bpy.context.object.data.edit_bones["Arm_R"].head.z= spine_sz + bpy.context.object.data.edit_bones["Arm_R"].head.x= (unit*3/4)*-1 + bpy.context.object.data.edit_bones["Forearm_R"].head.z= spine_sz + bpy.context.object.data.edit_bones["Forearm_R"].head.x= (unit + arm_sz) *-1 + bpy.context.object.data.edit_bones["Forearm_R"].tail.z= spine_sz + bpy.context.object.data.edit_bones["Forearm_R"].tail.x= (unit + arm_sz + forearm_sz) *-1 + + bpy.context.object.data.edit_bones["Thigh_L"].head.x= unit*3/4 + bpy.context.object.data.edit_bones["Thigh_L"].head.z= (unit/5)*-1 + bpy.context.object.data.edit_bones["Leg_L"].head.x= unit*3/4 + bpy.context.object.data.edit_bones["Leg_L"].head.z= (unit/5 + thigh_sz)*-1 + bpy.context.object.data.edit_bones["Foot_L"].head.x= unit*3/4 + bpy.context.object.data.edit_bones["Foot_L"].head.z= (unit/5 + thigh_sz + leg_sz)*-1 + bpy.context.object.data.edit_bones["Foot_L"].tail.x= unit*3/4 + bpy.context.object.data.edit_bones["Foot_L"].tail.z= (unit/5 + thigh_sz + leg_sz + foot_sz/2)*-1 + bpy.context.object.data.edit_bones["Foot_L"].tail.y= foot_sz/2*-1 + + bpy.context.object.data.edit_bones["Thigh_R"].head.x= unit*3/4*-1 + bpy.context.object.data.edit_bones["Thigh_R"].head.z= (unit/5)*-1 + bpy.context.object.data.edit_bones["Leg_R"].head.x= unit*3/4*-1 + bpy.context.object.data.edit_bones["Leg_R"].head.z= (unit/5 + thigh_sz)*-1 + bpy.context.object.data.edit_bones["Foot_R"].head.x= unit*3/4*-1 + bpy.context.object.data.edit_bones["Foot_R"].head.z= (unit/5 + thigh_sz + leg_sz)*-1 + bpy.context.object.data.edit_bones["Foot_R"].tail.x= unit*3/4*-1 + bpy.context.object.data.edit_bones["Foot_R"].tail.z= (unit/5 + thigh_sz + leg_sz + foot_sz/2)*-1 + bpy.context.object.data.edit_bones["Foot_R"].tail.y= foot_sz/2*-1 + + bpy.ops.object.editmode_toggle() + + + + import bpy + + #comecando configuração seguir movimentos pontos + #colocando em pose mode + + + obs = [] + for ob in bpy.context.scene.objects: + if ob.type == 'ARMATURE': + obs.append(ob) + #obs + + bpy.ops.object.mode_set(mode='POSE') + + + actual_bone = 'Root' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='COPY_LOCATION') + #bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.008"] + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.039"] + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + #bpy.context.object.pose.bones[actual_bone].constraints[1].target = bpy.data.objects["Point.001"] + bpy.context.object.pose.bones[actual_bone].constraints[1].target = bpy.data.objects["Point.037"] + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + #bpy.context.object.pose.bones[actual_bone].constraints[1].target = bpy.data.objects["Point.001"] + bpy.context.object.pose.bones[actual_bone].constraints[2].target = bpy.data.objects["Point.027"] + bpy.context.object.pose.bones[actual_bone].constraints[2].track_axis = 'TRACK_X' + + + #==== + actual_bone = 'Spine' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + #bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.001"] + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.037"] + bpy.ops.pose.constraint_add(type='LIMIT_ROTATION') + bpy.context.object.pose.bones[actual_bone].constraints[1].owner_space = 'LOCAL' + #x + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_x = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_x = -0.349066 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_x = 0.349066 + #y + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_y = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_y = -0.698132 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_y = 0.698132 + #z + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_z = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_z = -0.174533 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_z = 0.174533 + + #===== + actual_bone = 'Neck' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + #bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.000"] + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.042"] + bpy.ops.pose.constraint_add(type='LIMIT_ROTATION') + bpy.context.object.pose.bones[actual_bone].constraints[1].owner_space = 'LOCAL' + #x + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_x = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_x = -0.174533 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_x = 1.0472 + #y + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_y = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_y = -0.523599 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_y = 0.523599 + #z + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_z = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_z = -0.349066 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_z = 0.349066 + #===== + actual_bone = 'Face' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.044"] + bpy.ops.pose.constraint_add(type='LIMIT_ROTATION') + bpy.context.object.pose.bones[actual_bone].constraints[1].owner_space = 'LOCAL' + #x + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_x = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_x = -0.174533 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_x = 0.872665 + #y + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_y = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_y = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_y = 0 + #z + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_z = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_z = -0.523599 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_z = 0.523599 + #===== + actual_bone = 'Arm_L' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + #bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.006"] + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.032"] + #===== + actual_bone = 'Forearm_L' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + #bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.007"] + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.031"] + bpy.ops.pose.constraint_add(type='LIMIT_ROTATION') + bpy.context.object.pose.bones[actual_bone].constraints[1].owner_space = 'LOCAL' + #x + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_x = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_x = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_x = 0 + #y + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_y = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_y = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_y = 0 + #z + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_z = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_z = -2.53073 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_z = -0.191986 + #===== + actual_bone = 'Arm_R' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + #bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.003"] + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.035"] + #===== + actual_bone = 'Forearm_R' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + #bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.004"] + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.036"] + bpy.ops.pose.constraint_add(type='LIMIT_ROTATION') + bpy.context.object.pose.bones[actual_bone].constraints[1].owner_space = 'LOCAL' + #x + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_x = False + #y + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_y = False + #z + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_z = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_z = 0.191986 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_z = 2.53073 + #===== + actual_bone = 'Thigh_L' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + #bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.013"] + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.026"] + bpy.ops.pose.constraint_add(type='LIMIT_ROTATION') + bpy.context.object.pose.bones[actual_bone].constraints[1].owner_space = 'LOCAL' + #x + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_x = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_x = -1.76278 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_x = 1.3439 + #y + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_y = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_y = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_y = 0 + #z + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_z = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_z = -0.785398 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_z = 0.174533 + #===== + actual_bone = 'Leg_L' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + #bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.014"] + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.025"] + bpy.ops.pose.constraint_add(type='LIMIT_ROTATION') + bpy.context.object.pose.bones[actual_bone].constraints[1].owner_space = 'LOCAL' + #x + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_x = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_x = 0.0698132 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_x = 2.0944 + #y + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_y = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_y = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_y = 0 + #z + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_z = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_z = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_z = 0 + #===== + actual_bone = 'Foot_L' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + #bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.019"] + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.022"] + bpy.ops.pose.constraint_add(type='LIMIT_ROTATION') + bpy.context.object.pose.bones[actual_bone].constraints[1].owner_space = 'LOCAL' + #x + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_x = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_x = -0.523599 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_x = 0.523599 + #y + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_y = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_y = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_y = 0 + #z + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_z = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_z = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_z = 0 + #===== + actual_bone = 'Thigh_R' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + #bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.010"] + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.029"] + bpy.ops.pose.constraint_add(type='LIMIT_ROTATION') + bpy.context.object.pose.bones[actual_bone].constraints[1].owner_space = 'LOCAL' + #x + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_x = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_x = -1.76278 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_x = 1.3439 + #y + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_y = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_y = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_y = 0 + #z + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_z = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_z = -0.174533 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_z = 0.785398 + + actual_bone = 'Leg_R' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + #bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.011"] + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.030"] + bpy.ops.pose.constraint_add(type='LIMIT_ROTATION') + bpy.context.object.pose.bones[actual_bone].constraints[1].owner_space = 'LOCAL' + #x + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_x = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_x = 0.0698132 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_x = 2.0944 + #y + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_y = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_y = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_y = 0 + #z + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_z = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_z = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_z = 0 + + actual_bone = 'Foot_R' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + #bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.022"] + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.019"] + bpy.ops.pose.constraint_add(type='LIMIT_ROTATION') + bpy.context.object.pose.bones[actual_bone].constraints[1].owner_space = 'LOCAL' + #x + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_x = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_x = -0.523599 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_x = 0.523599 + #y + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_y = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_y = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_y = 0 + #z + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_z = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_z = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_z = 0 print(len(s_list)) bpy.context.scene.frame_end = len(s_list) @@ -1063,8 +1204,10 @@ def add_constraints_track_X(constraints): sk_value_prop.sk_root_rot_z = z_deg - + #""" return{'FINISHED'} + #""" + class Import_Data_vibe(Operator, ImportHelper): bl_idname = "mocap.import_vibe" @@ -1101,7 +1244,6 @@ def execute(self,context): multiplier = context.scene.sk_value_prop.sk_value raw_bool = context.scene.sk_value_prop.sk_raw_bool - def middle_point(p1,p2,p_middle): bpy.ops.object.select_all(action='DESELECT') @@ -1110,11 +1252,12 @@ def middle_point(p1,p2,p_middle): bpy.context.view_layer.objects.active = bpy.data.objects[p2] obs = bpy.context.selected_objects n = len(obs) - # print('n: ',n) + # print('n: ',n) assert(n) #scene.cursor.location = sum([o.matrix_world.translation for o in obs], Vector()) / n bpy.data.objects[p_middle].location = sum([o.matrix_world.translation for o in obs], Vector()) / n + def create_dots(name, amount): #remove Collection if bpy.data.collections.find(name) >= 0: @@ -1127,10 +1270,10 @@ def create_dots(name, amount): #===================================================== collection = bpy.data.collections.new(name) bpy.context.scene.collection.children.link(collection) - # + # layer_collection = bpy.context.view_layer.layer_collection.children[collection.name] bpy.context.view_layer.active_layer_collection = layer_collection - # + # for point in range(amount): bpy.ops.mesh.primitive_plane_add(enter_editmode=True, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1)) bpy.ops.mesh.merge(type='CENTER') @@ -1144,9 +1287,10 @@ def create_dots(name, amount): def distance(point1, point2) -> float: #Calculate distance between two points in 3D. - # return math.sqrt((point2[0] - point1[0]) ** 2 + (point2[1] - point1[1]) ** 2 + (point2[2] - point1[2]) ** 2) + # return math.sqrt((point2[0] - point1[0]) ** 2 + (point2[1] - point1[1]) ** 2 + (point2[2] - point1[2]) ** 2) return math.sqrt((point2.location[0] - point1.location[0]) ** 2 + (point2.location[1] - point1.location[1]) ** 2 + (point2.location[2] - point1.location[2]) ** 2) + def size_bone(point_name1, point_name2, bone): p1 = bpy.data.objects[point_name1] p2 = bpy.data.objects[point_name2] @@ -1158,249 +1302,9 @@ def size_bone(point_name1, point_name2, bone): bpy.context.object.data.edit_bones[bone].length= distance(p1,p2) bpy.ops.object.editmode_toggle() - def create_bones_wo_face(bones_list): - #=================================== - #creating bones - #==================================== - - bpy.ops.object.armature_add(enter_editmode=True, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1)) #cria armature e primeiro bone - #bpy.ops.object.editmode_toggle() - #bpy.data.armatures['Armature'].edit_bones.active = bpy.context.object.data.edit_bones['Bone'] - - - obs = [] - for ob in bpy.context.scene.objects: - if ob.type == 'ARMATURE': - obs.append(ob) - #obs - - - bpy.ops.armature.select_all(action='DESELECT') - obs[len(obs)-1].data.edit_bones['Bone'].select_tail=True - - - - bpy.ops.armature.bone_primitive_add()#Spine - #Neck - bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1)}) - #Face - # bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1)}) - - - bpy.ops.armature.bone_primitive_add()#Arm_L - #Forearm_L - bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1)}) - - bpy.ops.armature.bone_primitive_add()#Arm_R - #Forearm_R - bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1)}) - - bpy.ops.armature.bone_primitive_add()#Thigh_L - #Leg_L - #Foot_L - bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1)}) - bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1)}) - - bpy.ops.armature.bone_primitive_add()#Thigh_R - #Leg_R - #Foot_R - bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1)}) - bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1)}) - - for i in range(len(bones_list)): - obs[len(obs)-1].data.edit_bones[bones_list[i][0]].name = bones_list[i][1] - - - #Hierarquia - bpy.context.object.data.edit_bones["Spine"].parent = bpy.context.object.data.edit_bones["Root"] - bpy.context.object.data.edit_bones["Arm_L"].parent = bpy.context.object.data.edit_bones["Spine"] - bpy.context.object.data.edit_bones["Arm_R"].parent = bpy.context.object.data.edit_bones["Spine"] - bpy.context.object.data.edit_bones["Thigh_L"].parent = bpy.context.object.data.edit_bones["Root"] - bpy.context.object.data.edit_bones["Thigh_R"].parent = bpy.context.object.data.edit_bones["Root"] - - bpy.ops.object.editmode_toggle() - - def size_ref_bone(p1,p2,p_final): - from mathutils import Vector - import bpy - ## size of the reference bone (spine) - bpy.ops.object.select_all(action='DESELECT') - bpy.data.objects[p1].select_set(True) - bpy.data.objects[p2].select_set(True) - # bpy.context.view_layer.objects.active = bpy.data.objects['Point.034'] - bpy.context.view_layer.objects.active = bpy.data.objects[p2] - obs = bpy.context.selected_objects - n = len(obs) - # print('n: ',n) - assert(n) - #scene.cursor.location = sum([o.matrix_world.translation for o in obs], Vector()) / n - #bpy.data.objects[p_middle].location = sum([o.matrix_world.translation for o in obs], Vector()) / n - - x_subtract = abs(obs[0].matrix_world.translation.x - obs[1].matrix_world.translation.x) - y_subtract = abs(obs[0].matrix_world.translation.y - obs[1].matrix_world.translation.y) - z_subtract = abs(obs[0].matrix_world.translation.z - obs[1].matrix_world.translation.z) - - max(x_subtract, y_subtract, z_subtract) #maior das medidas - unit_def = max(x_subtract, y_subtract, z_subtract)/3 - #end of size of reference bone Spine - return unit_def - - def size_of_bones(root_size, spine_size, neck_size, face_size, thigh_size, leg_size, foot_size, arm_size, forearm_size): - #========================================== - #selecting and making the armature Active - #selecionando armature - #========================================== - bpy.ops.object.select_all(action='DESELECT') - #bpy.ops.armature.select_all(action='DESELECT') - - obs = [] - for ob in bpy.context.scene.objects: - if ob.type == 'ARMATURE': - obs.append(ob) - #obs - - armature = obs[len(obs)-1].name - - #bpy.data.objects[armature].select_set(True) - obs[len(obs)-1].select_set(True) - view_layer = bpy.context.view_layer - #Armature_obj = bpy.context.scene.objects[armature] - Armature_obj = obs[len(obs)-1] - view_layer.objects.active = Armature_obj - - #converting to euler rotation - order = 'XYZ' - context = bpy.context - rig_object = context.active_object - for pb in rig_object.pose.bones: - pb.rotation_mode = order - - - bpy.ops.object.editmode_toggle() - #changing location - #resetting - bpy.context.object.data.edit_bones["Spine"].head.xy=0 - bpy.context.object.data.edit_bones["Neck"].head.xy=0 - #bpy.context.object.data.edit_bones["Face"].head.xy=0 - - bpy.context.object.data.edit_bones["Arm_L"].head.xy=0 - bpy.context.object.data.edit_bones["Forearm_L"].head.xy=0 - - bpy.context.object.data.edit_bones["Arm_R"].head.xy=0 - bpy.context.object.data.edit_bones["Forearm_R"].head.xy=0 - - bpy.context.object.data.edit_bones["Thigh_L"].head.xy=0 - bpy.context.object.data.edit_bones["Leg_L"].head.xy=0 - bpy.context.object.data.edit_bones["Foot_L"].head.xy=0 - - bpy.context.object.data.edit_bones["Thigh_R"].head.xy=0 - bpy.context.object.data.edit_bones["Leg_R"].head.xy=0 - bpy.context.object.data.edit_bones["Foot_R"].head.xy=0 - #tail - #bpy.context.object.data.edit_bones["Face"].tail.xy=0 - bpy.context.object.data.edit_bones["Neck"].tail.xy=0 - bpy.context.object.data.edit_bones["Forearm_L"].tail.xy=0 - bpy.context.object.data.edit_bones["Forearm_R"].tail.xy=0 - bpy.context.object.data.edit_bones["Foot_L"].tail.xy=0 - bpy.context.object.data.edit_bones["Foot_R"].tail.xy=0 - - - - - bpy.context.object.data.edit_bones["Root"].length = root_size - - bpy.context.object.data.edit_bones["Spine"].head.z = unit/2 - bpy.context.object.data.edit_bones["Spine"].tail.z = spine_size - - bpy.context.object.data.edit_bones["Neck"].tail.z = spine_size + neck_size - bpy.context.object.data.edit_bones["Neck"].tail.y = neck_size/3 - #bpy.context.object.data.edit_bones["Face"].tail.z = spine_size + neck_size - #bpy.context.object.data.edit_bones["Face"].tail.y = face_size*-1 - - bpy.context.object.data.edit_bones["Arm_L"].head.z= spine_size - bpy.context.object.data.edit_bones["Arm_L"].head.x= unit*3/4 - bpy.context.object.data.edit_bones["Forearm_L"].head.z= spine_size - bpy.context.object.data.edit_bones["Forearm_L"].head.x= unit + arm_size - bpy.context.object.data.edit_bones["Forearm_L"].tail.z= spine_size - bpy.context.object.data.edit_bones["Forearm_L"].tail.x= unit + arm_size + forearm_size - - bpy.context.object.data.edit_bones["Arm_R"].head.z= spine_size - bpy.context.object.data.edit_bones["Arm_R"].head.x= (unit*3/4)*-1 - bpy.context.object.data.edit_bones["Forearm_R"].head.z= spine_size - bpy.context.object.data.edit_bones["Forearm_R"].head.x= (unit + arm_size) *-1 - bpy.context.object.data.edit_bones["Forearm_R"].tail.z= spine_size - bpy.context.object.data.edit_bones["Forearm_R"].tail.x= (unit + arm_size + forearm_size) *-1 - - bpy.context.object.data.edit_bones["Thigh_L"].head.x= unit*3/4 - bpy.context.object.data.edit_bones["Thigh_L"].head.z= (unit/5)*-1 - bpy.context.object.data.edit_bones["Leg_L"].head.x= unit*3/4 - bpy.context.object.data.edit_bones["Leg_L"].head.z= (unit/5 + thigh_size)*-1 - bpy.context.object.data.edit_bones["Foot_L"].head.x= unit*3/4 - bpy.context.object.data.edit_bones["Foot_L"].head.z= (unit/5 + thigh_size + leg_size)*-1 - bpy.context.object.data.edit_bones["Foot_L"].tail.x= unit*3/4 - bpy.context.object.data.edit_bones["Foot_L"].tail.z= (unit/5 + thigh_size + leg_size + foot_size/2)*-1 - bpy.context.object.data.edit_bones["Foot_L"].tail.y= foot_sz/2*-1 - - bpy.context.object.data.edit_bones["Thigh_R"].head.x= unit*3/4*-1 - bpy.context.object.data.edit_bones["Thigh_R"].head.z= (unit/5)*-1 - bpy.context.object.data.edit_bones["Leg_R"].head.x= unit*3/4*-1 - bpy.context.object.data.edit_bones["Leg_R"].head.z= (unit/5 + thigh_size)*-1 - bpy.context.object.data.edit_bones["Foot_R"].head.x= unit*3/4*-1 - bpy.context.object.data.edit_bones["Foot_R"].head.z= (unit/5 + thigh_size + leg_size)*-1 - bpy.context.object.data.edit_bones["Foot_R"].tail.x= unit*3/4*-1 - bpy.context.object.data.edit_bones["Foot_R"].tail.z= (unit/5 + thigh_size + leg_size + foot_size/2)*-1 - bpy.context.object.data.edit_bones["Foot_R"].tail.y= foot_size/2*-1 - bpy.ops.object.editmode_toggle() - - def add_constraints(constraints): - obs = [] - for ob in bpy.context.scene.objects: - if ob.type == 'ARMATURE': - obs.append(ob) - #obs - - bpy.ops.object.mode_set(mode='POSE') - - for i in range(len(constraints)): - print('processar: ',constraints[i]) - if constraints[i][1] == 'COPY_LOCATION' or constraints[i][1] == 'DAMPED_TRACK': - # print('in 1 j: ',j,' - name: ',constraints[i][0],' constraint: ',constraints[i][1]) - obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[constraints[i][0]].bone - obs[len(obs)-1].pose.bones[constraints[i][0]].bone.select = True - # - bpy.ops.pose.constraint_add(type=constraints[i][1]) - qtd_constraint = len(bpy.context.object.pose.bones[constraints[i][0]].constraints) - bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].target = bpy.data.objects[constraints[i][2]] - # - if constraints[i][1] == 'LIMIT_ROTATION': - qtd_constraint = len(bpy.context.object.pose.bones[constraints[i][0]].constraints) - if constraints[i][2] == 'LOCAL': - bpy.ops.pose.constraint_add(type=constraints[i][1]) - qtd_constraint = len(bpy.context.object.pose.bones[constraints[i][0]].constraints) - bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].owner_space = constraints[i][2] - if constraints[i][2] == 'X': - if constraints[i][3] == True: - bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].use_limit_x = constraints[i][3] - bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].min_x = constraints[i][4] - bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].max_x = constraints[i][5] - if constraints[i][2] == 'Y': - if constraints[i][3] == True: - bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].use_limit_y = constraints[i][3] - bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].min_y = constraints[i][4] - bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].max_y = constraints[i][5] - if constraints[i][2] == 'Z': - if constraints[i][3] == True: - bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].use_limit_z = constraints[i][3] - bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].min_z = constraints[i][4] - bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].max_z = constraints[i][5] - - - - ############################# - ## Start of VIBE import data #path = r'D:\MOCAP\EasyMocap-master\demo_test\videos\1.mp4' #path = r'D:\Video_editing\running e brack dance para mocap.mp4' create_dots('Point',49) @@ -1415,8 +1319,8 @@ def add_constraints(constraints): y=1 z=2 - person_id = context.scene.sk_value_prop.vibe_person_id - # person_id=1 + + person_id=1 for item in range(len(pic[person_id]['pose'])): print("frame: ",item) @@ -1430,181 +1334,563 @@ def add_constraints(constraints): + import bpy + + #=========== # selectign Scene Collection scene_collection = bpy.context.view_layer.layer_collection bpy.context.view_layer.active_layer_collection = scene_collection - bones = [['Bone','Root'], - ['Bone.001','Spine'], - ['Bone.002','Neck'], - # ['Bone.003','Face'], - ['Bone.003','Arm_L'], - ['Bone.004','Forearm_L'], - ['Bone.005','Arm_R'], - ['Bone.006','Forearm_R'], - ['Bone.007','Thigh_L'], - ['Bone.008','Leg_L'], - ['Bone.009','Foot_L'], - ['Bone.010','Thigh_R'], - ['Bone.011','Leg_R'], - ['Bone.012','Foot_R'] - ] - - create_bones_wo_face(bones) - - unit = size_ref_bone('Point.001','Point.008','Point.034') - unit = unit*multiplier + #=================================== + #creating bones + #==================================== - root_sz =unit/10 - spine_sz =unit*3.5 - neck_sz =unit - face_sz =unit - thigh_sz =unit*3 - leg_sz =unit*2.5 - foot_sz =unit #inclinado 45 graud pra frente - arm_sz =unit*1.5 - forearm_sz =unit*1.5 + bpy.ops.object.armature_add(enter_editmode=True, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1)) #cria armature e primeiro bone + #bpy.ops.object.editmode_toggle() + #bpy.data.armatures['Armature'].edit_bones.active = bpy.context.object.data.edit_bones['Bone'] - size_of_bones(root_sz, spine_sz, neck_sz, face_sz, thigh_sz, leg_sz, foot_sz, arm_sz, forearm_sz) - - - constraints = [ - ['Root', 'COPY_LOCATION', 'Point.008'], - ['Root', 'DAMPED_TRACK', 'Point.001'], - ['Spine', 'DAMPED_TRACK', 'Point.001'], - ['Spine', 'LIMIT_ROTATION', 'LOCAL'], - ['Spine', 'LIMIT_ROTATION', 'X', True, -0.349066, 0.349066], - ['Spine', 'LIMIT_ROTATION', 'Y', True, -0.698132, 0.698132], - ['Spine', 'LIMIT_ROTATION', 'Z', True, -0.174533, 0.174533], - ['Neck', 'DAMPED_TRACK', 'Point.000'], - ['Neck', 'LIMIT_ROTATION', 'LOCAL'], - ['Neck', 'LIMIT_ROTATION', 'X', True, -0.174533, 1.0472], - ['Neck', 'LIMIT_ROTATION', 'Y', True, -0.523599, 0.523599], - ['Neck', 'LIMIT_ROTATION', 'Z', True, -0.349066, 0.349066], - # ['Face', 'DAMPED_TRACK', 'Point.000'], - # ['Face', 'LIMIT_ROTATION', 'LOCAL'], - # ['Face', 'LIMIT_ROTATION', 'X', True, -0.174533, 0.872665], - # ['Face', 'LIMIT_ROTATION', 'Y', True, 0, 0], - # ['Face', 'LIMIT_ROTATION', 'Z', True, -0.523599, 0.523599], - ['Arm_L', 'DAMPED_TRACK', 'Point.006'], - ['Forearm_L', 'DAMPED_TRACK', 'Point.007'], - ['Forearm_L', 'LIMIT_ROTATION', 'LOCAL'], - ['Forearm_L', 'LIMIT_ROTATION', 'X', True, 0, 0], - ['Forearm_L', 'LIMIT_ROTATION', 'Y', True, 0, 0], - ['Forearm_L', 'LIMIT_ROTATION', 'Z', True, -2.53073, -0.191986], - ['Arm_R', 'DAMPED_TRACK', 'Point.003'], - ['Forearm_R', 'DAMPED_TRACK', 'Point.007'], - ['Forearm_R', 'LIMIT_ROTATION', 'LOCAL'], - ['Forearm_R', 'LIMIT_ROTATION', 'X', False ], - ['Forearm_R', 'LIMIT_ROTATION', 'Y', False ], - ['Forearm_R', 'LIMIT_ROTATION', 'Z', True, 0.191986, 2.53073], - ['Thigh_L', 'DAMPED_TRACK', 'Point.013'], - ['Thigh_L', 'LIMIT_ROTATION', 'LOCAL'], - ['Thigh_L', 'LIMIT_ROTATION', 'X', True, -1.76278, 1.3439], - ['Thigh_L', 'LIMIT_ROTATION', 'Y', True, 0, 0], - ['Thigh_L', 'LIMIT_ROTATION', 'Z', True, -0.785398, 0.174533], - ['Leg_L', 'DAMPED_TRACK', 'Point.014'], - ['Leg_L', 'LIMIT_ROTATION', 'LOCAL'], - ['Leg_L', 'LIMIT_ROTATION', 'X', True, 0.0698132, 2.0944], - ['Leg_L', 'LIMIT_ROTATION', 'Y', True, 0, 0], - ['Leg_L', 'LIMIT_ROTATION', 'Z', True, 0, 0], - ['Foot_L', 'DAMPED_TRACK', 'Point.019'], - ['Foot_L', 'LIMIT_ROTATION', 'LOCAL'], - ['Foot_L', 'LIMIT_ROTATION', 'X', True, -0.523599, 0.523599], - ['Foot_L', 'LIMIT_ROTATION', 'Y', True, 0, 0], - ['Foot_L', 'LIMIT_ROTATION', 'Z', True, 0, 0], - ['Thigh_R', 'DAMPED_TRACK', 'Point.010'], - ['Thigh_R', 'LIMIT_ROTATION', 'LOCAL'], - ['Thigh_R', 'LIMIT_ROTATION', 'X', True, -1.76278, 1.3439], - ['Thigh_R', 'LIMIT_ROTATION', 'Y', True, 0, 0], - ['Thigh_R', 'LIMIT_ROTATION', 'Z', True, -0.174533, 0.785398], - ['Leg_R', 'DAMPED_TRACK', 'Point.011'], - ['Leg_R', 'LIMIT_ROTATION', 'LOCAL'], - ['Leg_R', 'LIMIT_ROTATION', 'X', True, 0.0698132, 2.0944], - ['Leg_R', 'LIMIT_ROTATION', 'Y', True, 0, 0], - ['Leg_R', 'LIMIT_ROTATION', 'Z', True, 0, 0], - ['Foot_R', 'DAMPED_TRACK', 'Point.019'], - ['Foot_R', 'LIMIT_ROTATION', 'LOCAL'], - ['Foot_R', 'LIMIT_ROTATION', 'X', True, -0.523599, 0.523599], - ['Foot_R', 'LIMIT_ROTATION', 'Y', True, 0, 0], - ['Foot_R', 'LIMIT_ROTATION', 'Z', True, 0, 0] - ] - - add_constraints(constraints) + obs = [] + for ob in bpy.context.scene.objects: + if ob.type == 'ARMATURE': + obs.append(ob) + #obs - - bpy.context.scene.frame_end = len(pic[person_id]['pose']) - bpy.ops.nla.bake(frame_start=1, frame_end=len(pic[person_id]['pose']), visual_keying=True, clear_constraints=True, clear_parents=True, bake_types={'POSE'}) - bpy.ops.object.mode_set(mode='OBJECT') + bpy.ops.armature.select_all(action='DESELECT') + #bpy.context.object.data.edit_bones['Bone'].select_tail=True + obs[len(obs)-1].data.edit_bones['Bone'].select_tail=True - #apagar collection points criada - collection = bpy.data.collections.get('Point') - # - for obj in collection.objects: - bpy.data.objects.remove(obj, do_unlink=True) - bpy.data.collections.remove(collection) + bpy.ops.armature.bone_primitive_add()#Spine + #bpy.ops.armature.extrude_move()#Neck + bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), "mirror":True, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False, "use_automerge_and_split":False}) + ##bpy.ops.armature.extrude_move()#Face + #bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), "mirror":True, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False, "use_automerge_and_split":False}) - sk_value_prop = context.scene.sk_value_prop - if raw_bool == True: - print('raw_bool True - ',raw_bool) - x_original, y_original, z_original = helper_functions.get_rotations() - sk_value_prop.sk_root_rot_x = math.degrees(x_original) - sk_value_prop.sk_root_rot_y = math.degrees(y_original) - sk_value_prop.sk_root_rot_z = math.degrees(z_original) + bpy.ops.armature.bone_primitive_add()#Arm_L + #bpy.ops.armature.extrude_move()#Forearm_L + bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), "mirror":True, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False, "use_automerge_and_split":False}) - #in this case both original and actual is the same, because there was no alteration on the angle - x_actual_deg = math.degrees(x_original) - y_actual_deg = math.degrees(y_original) - z_actual_deg = math.degrees(z_original) + bpy.ops.armature.bone_primitive_add()#Arm_R + #bpy.ops.armature.extrude_move()#Forearm_R + bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), "mirror":True, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False, "use_automerge_and_split":False}) - sk_value_prop.sk_root_actual_rot_x = x_actual_deg - sk_value_prop.sk_root_actual_rot_y = y_actual_deg - sk_value_prop.sk_root_actual_rot_z = z_actual_deg - else: - print('raw_bool False - ',raw_bool) - x_deg, y_deg, z_deg = helper_functions.anim_to_origin() - #take the information of the rotation to the panel - print('result x: ',x_deg) - print('result y: ',y_deg) - print('result z: ',z_deg) - sk_value_prop.sk_root_rot_x = x_deg - sk_value_prop.sk_root_rot_y = y_deg - sk_value_prop.sk_root_rot_z = z_deg + bpy.ops.armature.bone_primitive_add()#Thigh_L + #bpy.ops.armature.extrude_move()#Leg_L + #bpy.ops.armature.extrude_move()#Foot_L + bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), "mirror":True, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False, "use_automerge_and_split":False}) + bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), "mirror":True, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False, "use_automerge_and_split":False}) + bpy.ops.armature.bone_primitive_add()#Thigh_R + #bpy.ops.armature.extrude_move()#Leg_R + #bpy.ops.armature.extrude_move()#Foot_R + bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), "mirror":True, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False, "use_automerge_and_split":False}) + bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), "mirror":True, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False, "use_automerge_and_split":False}) - - - return{'FINISHED'} + obs[len(obs)-1].data.edit_bones["Bone"].name = 'Root' + obs[len(obs)-1].data.edit_bones["Bone.001"].name = 'Spine' + obs[len(obs)-1].data.edit_bones["Bone.002"].name = 'Neck' + #obs[len(obs)-1].data.edit_bones["Bone.003"].name = 'Face' + obs[len(obs)-1].data.edit_bones["Bone.003"].name = 'Arm_L' + obs[len(obs)-1].data.edit_bones["Bone.004"].name = 'Forearm_L' + obs[len(obs)-1].data.edit_bones["Bone.005"].name = 'Arm_R' + obs[len(obs)-1].data.edit_bones["Bone.006"].name = 'Forearm_R' + obs[len(obs)-1].data.edit_bones["Bone.007"].name = 'Thigh_L' + obs[len(obs)-1].data.edit_bones["Bone.008"].name = 'Leg_L' + obs[len(obs)-1].data.edit_bones["Bone.009"].name = 'Foot_L' + obs[len(obs)-1].data.edit_bones["Bone.010"].name = 'Thigh_R' + obs[len(obs)-1].data.edit_bones["Bone.011"].name = 'Leg_R' + obs[len(obs)-1].data.edit_bones["Bone.012"].name = 'Foot_R' -class Mediapipe_Pose_estimation(Operator, ImportHelper): - bl_idname = "mocap.mediapipe_pose" - bl_label = "Generate Pose using MediaPipe" - bl_description = "Generate Mocap data with MediaPipe" + #Hierarquia + bpy.context.object.data.edit_bones["Spine"].parent = bpy.context.object.data.edit_bones["Root"] + bpy.context.object.data.edit_bones["Arm_L"].parent = bpy.context.object.data.edit_bones["Spine"] + bpy.context.object.data.edit_bones["Arm_R"].parent = bpy.context.object.data.edit_bones["Spine"] + bpy.context.object.data.edit_bones["Thigh_L"].parent = bpy.context.object.data.edit_bones["Root"] + bpy.context.object.data.edit_bones["Thigh_R"].parent = bpy.context.object.data.edit_bones["Root"] + + bpy.ops.object.editmode_toggle() - filename_ext = ".mp4" - filter_glob: StringProperty( - default="*.mp4", - options={'HIDDEN'}, - maxlen=255, # Max internal buffer length, longer would be clamped. - ) - - def execute(self,context): - import cv2 - import mediapipe as mp - import bpy - import sys from mathutils import Vector - import math + import bpy + + bpy.ops.object.select_all(action='DESELECT') + bpy.data.objects['Point.001'].select_set(True) + bpy.data.objects['Point.008'].select_set(True) + bpy.context.view_layer.objects.active = bpy.data.objects['Point.034'] + obs = bpy.context.selected_objects + n = len(obs) + # print('n: ',n) + assert(n) + #scene.cursor.location = sum([o.matrix_world.translation for o in obs], Vector()) / n + #bpy.data.objects[p_middle].location = sum([o.matrix_world.translation for o in obs], Vector()) / n + + + + x_subtract = abs(obs[0].matrix_world.translation.x - obs[1].matrix_world.translation.x) + y_subtract = abs(obs[0].matrix_world.translation.y - obs[1].matrix_world.translation.y) + z_subtract = abs(obs[0].matrix_world.translation.z - obs[1].matrix_world.translation.z) + + max(x_subtract, y_subtract, z_subtract) #maior das medidas + unit = max(x_subtract, y_subtract, z_subtract)/3 + unit = unit*multiplier + + root_sz =unit/10 + spine_sz =unit*3.5 + neck_sz =unit + face_sz =unit + thigh_sz =unit*3 + leg_sz =unit*2.5 + foot_sz =unit #inclinado 45 graud pra frente + arm_sz =unit*1.5 + forearm_sz =unit*1.5 + + + + #if bpy.context.active_object.mode != 'EDIT': + # bpy.ops.object.editmode_toggle() + #========================================== + #selecting and making the armature Active + #selecionando armature + #========================================== + bpy.ops.object.select_all(action='DESELECT') + #bpy.ops.armature.select_all(action='DESELECT') + + obs = [] + for ob in bpy.context.scene.objects: + if ob.type == 'ARMATURE': + obs.append(ob) + #obs + + armature = obs[len(obs)-1].name + + #bpy.data.objects[armature].select_set(True) + obs[len(obs)-1].select_set(True) + view_layer = bpy.context.view_layer + #Armature_obj = bpy.context.scene.objects[armature] + Armature_obj = obs[len(obs)-1] + view_layer.objects.active = Armature_obj + + #converting to euler rotation + order = 'XYZ' + context = bpy.context + rig_object = context.active_object + for pb in rig_object.pose.bones: + pb.rotation_mode = order + + + bpy.ops.object.editmode_toggle() + + #changing location + #resetting + bpy.context.object.data.edit_bones["Spine"].head.xy=0 + bpy.context.object.data.edit_bones["Neck"].head.xy=0 + #bpy.context.object.data.edit_bones["Face"].head.xy=0 + + bpy.context.object.data.edit_bones["Arm_L"].head.xy=0 + bpy.context.object.data.edit_bones["Forearm_L"].head.xy=0 + + bpy.context.object.data.edit_bones["Arm_R"].head.xy=0 + bpy.context.object.data.edit_bones["Forearm_R"].head.xy=0 + + bpy.context.object.data.edit_bones["Thigh_L"].head.xy=0 + bpy.context.object.data.edit_bones["Leg_L"].head.xy=0 + bpy.context.object.data.edit_bones["Foot_L"].head.xy=0 + + bpy.context.object.data.edit_bones["Thigh_R"].head.xy=0 + bpy.context.object.data.edit_bones["Leg_R"].head.xy=0 + bpy.context.object.data.edit_bones["Foot_R"].head.xy=0 + #tail + #bpy.context.object.data.edit_bones["Face"].tail.xy=0 + bpy.context.object.data.edit_bones["Neck"].tail.xy=0 + bpy.context.object.data.edit_bones["Forearm_L"].tail.xy=0 + bpy.context.object.data.edit_bones["Forearm_R"].tail.xy=0 + bpy.context.object.data.edit_bones["Foot_L"].tail.xy=0 + bpy.context.object.data.edit_bones["Foot_R"].tail.xy=0 + + + + + bpy.context.object.data.edit_bones["Root"].length = root_sz + + bpy.context.object.data.edit_bones["Spine"].head.z = unit/2 + bpy.context.object.data.edit_bones["Spine"].tail.z = spine_sz + + bpy.context.object.data.edit_bones["Neck"].tail.z = spine_sz + neck_sz + bpy.context.object.data.edit_bones["Neck"].tail.y = neck_sz/3 + #bpy.context.object.data.edit_bones["Face"].tail.z = spine_sz + neck_sz + #bpy.context.object.data.edit_bones["Face"].tail.y = face_sz*-1 + + bpy.context.object.data.edit_bones["Arm_L"].head.z= spine_sz + bpy.context.object.data.edit_bones["Arm_L"].head.x= unit*3/4 + bpy.context.object.data.edit_bones["Forearm_L"].head.z= spine_sz + bpy.context.object.data.edit_bones["Forearm_L"].head.x= unit + arm_sz + bpy.context.object.data.edit_bones["Forearm_L"].tail.z= spine_sz + bpy.context.object.data.edit_bones["Forearm_L"].tail.x= unit + arm_sz + forearm_sz + + bpy.context.object.data.edit_bones["Arm_R"].head.z= spine_sz + bpy.context.object.data.edit_bones["Arm_R"].head.x= (unit*3/4)*-1 + bpy.context.object.data.edit_bones["Forearm_R"].head.z= spine_sz + bpy.context.object.data.edit_bones["Forearm_R"].head.x= (unit + arm_sz) *-1 + bpy.context.object.data.edit_bones["Forearm_R"].tail.z= spine_sz + bpy.context.object.data.edit_bones["Forearm_R"].tail.x= (unit + arm_sz + forearm_sz) *-1 + + bpy.context.object.data.edit_bones["Thigh_L"].head.x= unit*3/4 + bpy.context.object.data.edit_bones["Thigh_L"].head.z= (unit/5)*-1 + bpy.context.object.data.edit_bones["Leg_L"].head.x= unit*3/4 + bpy.context.object.data.edit_bones["Leg_L"].head.z= (unit/5 + thigh_sz)*-1 + bpy.context.object.data.edit_bones["Foot_L"].head.x= unit*3/4 + bpy.context.object.data.edit_bones["Foot_L"].head.z= (unit/5 + thigh_sz + leg_sz)*-1 + bpy.context.object.data.edit_bones["Foot_L"].tail.x= unit*3/4 + bpy.context.object.data.edit_bones["Foot_L"].tail.z= (unit/5 + thigh_sz + leg_sz + foot_sz/2)*-1 + bpy.context.object.data.edit_bones["Foot_L"].tail.y= foot_sz/2*-1 + + bpy.context.object.data.edit_bones["Thigh_R"].head.x= unit*3/4*-1 + bpy.context.object.data.edit_bones["Thigh_R"].head.z= (unit/5)*-1 + bpy.context.object.data.edit_bones["Leg_R"].head.x= unit*3/4*-1 + bpy.context.object.data.edit_bones["Leg_R"].head.z= (unit/5 + thigh_sz)*-1 + bpy.context.object.data.edit_bones["Foot_R"].head.x= unit*3/4*-1 + bpy.context.object.data.edit_bones["Foot_R"].head.z= (unit/5 + thigh_sz + leg_sz)*-1 + bpy.context.object.data.edit_bones["Foot_R"].tail.x= unit*3/4*-1 + bpy.context.object.data.edit_bones["Foot_R"].tail.z= (unit/5 + thigh_sz + leg_sz + foot_sz/2)*-1 + bpy.context.object.data.edit_bones["Foot_R"].tail.y= foot_sz/2*-1 + + bpy.ops.object.editmode_toggle() + + + + + import bpy + + #comecando configuração seguir movimentos pontos + #colocando em pose mode + + + obs = [] + for ob in bpy.context.scene.objects: + if ob.type == 'ARMATURE': + obs.append(ob) + #obs + + bpy.ops.object.mode_set(mode='POSE') + + + actual_bone = 'Root' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='COPY_LOCATION') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.008"] + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[1].target = bpy.data.objects["Point.001"] + + #==== + actual_bone = 'Spine' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.001"] + bpy.ops.pose.constraint_add(type='LIMIT_ROTATION') + bpy.context.object.pose.bones[actual_bone].constraints[1].owner_space = 'LOCAL' + #x + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_x = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_x = -0.349066 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_x = 0.349066 + #y + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_y = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_y = -0.698132 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_y = 0.698132 + #z + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_z = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_z = -0.174533 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_z = 0.174533 + + #===== + actual_bone = 'Neck' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.000"] + bpy.ops.pose.constraint_add(type='LIMIT_ROTATION') + bpy.context.object.pose.bones[actual_bone].constraints[1].owner_space = 'LOCAL' + #x + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_x = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_x = -0.174533 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_x = 1.0472 + #y + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_y = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_y = -0.523599 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_y = 0.523599 + #z + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_z = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_z = -0.349066 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_z = 0.349066 + #===== + #actual_bone = 'Face' + #obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + #obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + #bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + #bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.000"] + #bpy.ops.pose.constraint_add(type='LIMIT_ROTATION') + #bpy.context.object.pose.bones[actual_bone].constraints[1].owner_space = 'LOCAL' + ##x + #bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_x = True + #bpy.context.object.pose.bones[actual_bone].constraints[1].min_x = -0.174533 + #bpy.context.object.pose.bones[actual_bone].constraints[1].max_x = 0.872665 + ##y + #bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_y = True + #bpy.context.object.pose.bones[actual_bone].constraints[1].min_y = 0 + #bpy.context.object.pose.bones[actual_bone].constraints[1].max_y = 0 + ##z + #bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_z = True + #bpy.context.object.pose.bones[actual_bone].constraints[1].min_z = -0.523599 + #bpy.context.object.pose.bones[actual_bone].constraints[1].max_z = 0.523599 + #===== + actual_bone = 'Arm_L' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.006"] + #===== + actual_bone = 'Forearm_L' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.007"] + bpy.ops.pose.constraint_add(type='LIMIT_ROTATION') + bpy.context.object.pose.bones[actual_bone].constraints[1].owner_space = 'LOCAL' + #x + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_x = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_x = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_x = 0 + #y + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_y = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_y = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_y = 0 + #z + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_z = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_z = -2.53073 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_z = -0.191986 + #===== + actual_bone = 'Arm_R' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.003"] + #===== + actual_bone = 'Forearm_R' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.004"] + bpy.ops.pose.constraint_add(type='LIMIT_ROTATION') + bpy.context.object.pose.bones[actual_bone].constraints[1].owner_space = 'LOCAL' + #x + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_x = False + #y + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_y = False + #z + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_z = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_z = 0.191986 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_z = 2.53073 + #===== + actual_bone = 'Thigh_L' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.013"] + bpy.ops.pose.constraint_add(type='LIMIT_ROTATION') + bpy.context.object.pose.bones[actual_bone].constraints[1].owner_space = 'LOCAL' + #x + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_x = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_x = -1.76278 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_x = 1.3439 + #y + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_y = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_y = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_y = 0 + #z + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_z = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_z = -0.785398 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_z = 0.174533 + #===== + actual_bone = 'Leg_L' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.014"] + bpy.ops.pose.constraint_add(type='LIMIT_ROTATION') + bpy.context.object.pose.bones[actual_bone].constraints[1].owner_space = 'LOCAL' + #x + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_x = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_x = 0.0698132 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_x = 2.0944 + #y + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_y = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_y = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_y = 0 + #z + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_z = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_z = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_z = 0 + #===== + actual_bone = 'Foot_L' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.019"] + bpy.ops.pose.constraint_add(type='LIMIT_ROTATION') + bpy.context.object.pose.bones[actual_bone].constraints[1].owner_space = 'LOCAL' + #x + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_x = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_x = -0.523599 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_x = 0.523599 + #y + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_y = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_y = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_y = 0 + #z + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_z = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_z = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_z = 0 + #===== + actual_bone = 'Thigh_R' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.010"] + bpy.ops.pose.constraint_add(type='LIMIT_ROTATION') + bpy.context.object.pose.bones[actual_bone].constraints[1].owner_space = 'LOCAL' + #x + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_x = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_x = -1.76278 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_x = 1.3439 + #y + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_y = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_y = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_y = 0 + #z + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_z = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_z = -0.174533 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_z = 0.785398 + + actual_bone = 'Leg_R' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.011"] + bpy.ops.pose.constraint_add(type='LIMIT_ROTATION') + bpy.context.object.pose.bones[actual_bone].constraints[1].owner_space = 'LOCAL' + #x + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_x = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_x = 0.0698132 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_x = 2.0944 + #y + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_y = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_y = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_y = 0 + #z + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_z = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_z = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_z = 0 + + actual_bone = 'Foot_R' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.022"] + bpy.ops.pose.constraint_add(type='LIMIT_ROTATION') + bpy.context.object.pose.bones[actual_bone].constraints[1].owner_space = 'LOCAL' + #x + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_x = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_x = -0.523599 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_x = 0.523599 + #y + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_y = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_y = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_y = 0 + #z + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_z = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_z = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_z = 0 + + bpy.context.scene.frame_end = len(pic[person_id]['pose']) + + bpy.ops.nla.bake(frame_start=1, frame_end=len(pic[person_id]['pose']), visual_keying=True, clear_constraints=True, clear_parents=True, bake_types={'POSE'}) + bpy.ops.object.mode_set(mode='OBJECT') + + #apagar collection points criada + collection = bpy.data.collections.get('Point') + # + for obj in collection.objects: + bpy.data.objects.remove(obj, do_unlink=True) + bpy.data.collections.remove(collection) + + sk_value_prop = context.scene.sk_value_prop + if raw_bool == True: + print('raw_bool True - ',raw_bool) + + x_original, y_original, z_original = helper_functions.get_rotations() + sk_value_prop.sk_root_rot_x = math.degrees(x_original) + sk_value_prop.sk_root_rot_y = math.degrees(y_original) + sk_value_prop.sk_root_rot_z = math.degrees(z_original) + + #in this case both original and actual is the same, because there was no alteration on the angle + x_actual_deg = math.degrees(x_original) + y_actual_deg = math.degrees(y_original) + z_actual_deg = math.degrees(z_original) + + sk_value_prop.sk_root_actual_rot_x = x_actual_deg + sk_value_prop.sk_root_actual_rot_y = y_actual_deg + sk_value_prop.sk_root_actual_rot_z = z_actual_deg + else: + print('raw_bool False - ',raw_bool) + x_deg, y_deg, z_deg = helper_functions.anim_to_origin() + #take the information of the rotation to the panel + print('result x: ',x_deg) + print('result y: ',y_deg) + print('result z: ',z_deg) + sk_value_prop.sk_root_rot_x = x_deg + sk_value_prop.sk_root_rot_y = y_deg + sk_value_prop.sk_root_rot_z = z_deg + + + + + + return{'FINISHED'} + + +class Mediapipe_Pose_estimation(Operator, ImportHelper): + bl_idname = "mocap.mediapipe_pose" + bl_label = "Generate Pose using MediaPipe" + bl_description = "Generate Mocap data with MediaPipe" + + + filename_ext = ".mp4" + + filter_glob: StringProperty( + default="*.mp4", + options={'HIDDEN'}, + maxlen=255, # Max internal buffer length, longer would be clamped. + ) + + + def execute(self,context): + + import cv2 + import mediapipe as mp + import bpy + import sys + from mathutils import Vector + import math multiplier = context.scene.sk_value_prop.sk_value raw_bool = context.scene.sk_value_prop.sk_raw_bool @@ -1616,23 +1902,25 @@ def middle_point(p1,p2,p_middle): bpy.context.view_layer.objects.active = bpy.data.objects[p2] obs = bpy.context.selected_objects n = len(obs) - # print('n: ',n) + # print('n: ',n) assert(n) #scene.cursor.location = sum([o.matrix_world.translation for o in obs], Vector()) / n bpy.data.objects[p_middle].location = sum([o.matrix_world.translation for o in obs], Vector()) / n + + def get_landmarks(vid_name, frame_list): mp_drawing = mp.solutions.drawing_utils mp_holistic = mp.solutions.holistic - # + # # For static images: holistic = mp_holistic.Holistic(static_image_mode=True) for idx, image in enumerate(frame_list): - # image_height, image_width, _ = image.shape + # image_height, image_width, _ = image.shape # Convert the BGR image to RGB before processing. results = holistic.process(cv2.cvtColor(image, cv2.COLOR_BGR2RGB)) - # - # + # + # x=0 y=1 z=2 @@ -1658,7 +1946,7 @@ def get_landmarks(vid_name, frame_list): bpy.data.objects["Point."+str(1000+35)[1:]].keyframe_insert(data_path="location", frame=idx) bpy.data.objects["Point."+str(1000+i)[1:]].keyframe_insert(data_path="location", frame=idx) # - # print('frame: ',idx,' landmark_id: ',i,'x: ', x_pose, ' - y: ',y_pose,' - z: ',z_pose) + # print('frame: ',idx,' landmark_id: ',i,'x: ', x_pose, ' - y: ',y_pose,' - z: ',z_pose) except: print('Error Frame: ',idx) bpy.data.objects["Point."+str(1000+i)[1:]].location[x]=0 @@ -1668,6 +1956,7 @@ def get_landmarks(vid_name, frame_list): continue holistic.close() + def get_video_frames(file_url): vidcap = cv2.VideoCapture(file_url) success, image = vidcap.read() @@ -1676,7 +1965,7 @@ def get_video_frames(file_url): while success: frames.append(image) success, image = vidcap.read() - # + # return frames def create_dots(name, amount): @@ -1691,84 +1980,27 @@ def create_dots(name, amount): #===================================================== collection = bpy.data.collections.new(name) bpy.context.scene.collection.children.link(collection) - # + # layer_collection = bpy.context.view_layer.layer_collection.children[collection.name] bpy.context.view_layer.active_layer_collection = layer_collection - # + # for point in range(amount): bpy.ops.mesh.primitive_plane_add(enter_editmode=True, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1)) bpy.ops.mesh.merge(type='CENTER') bpy.ops.object.editmode_toggle() bpy.context.active_object.name = name+'.'+str(1000+point)[1:] #===================================================== - - def create_bones(bones_list): - #=================================== - #creating bones - #==================================== - - bpy.ops.object.armature_add(enter_editmode=True, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1)) #cria armature e primeiro bone - #bpy.ops.object.editmode_toggle() - #bpy.data.armatures['Armature'].edit_bones.active = bpy.context.object.data.edit_bones['Bone'] - - - obs = [] - for ob in bpy.context.scene.objects: - if ob.type == 'ARMATURE': - obs.append(ob) - #obs - - - bpy.ops.armature.select_all(action='DESELECT') - obs[len(obs)-1].data.edit_bones['Bone'].select_tail=True - - - bpy.ops.armature.bone_primitive_add()#Spine - #Neck - bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1)}) - #Face - bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1)}) - - - bpy.ops.armature.bone_primitive_add()#Arm_L - #Forearm_L - bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1)}) - - bpy.ops.armature.bone_primitive_add()#Arm_R - #Forearm_R - bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1)}) - - bpy.ops.armature.bone_primitive_add()#Thigh_L - #Leg_L - #Foot_L - bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1)}) - bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1)}) - - bpy.ops.armature.bone_primitive_add()#Thigh_R - #Leg_R - #Foot_R - bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1)}) - bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1)}) - - for i in range(len(bones_list)): - obs[len(obs)-1].data.edit_bones[bones_list[i][0]].name = bones_list[i][1] - - - #Hierarquia - bpy.context.object.data.edit_bones["Spine"].parent = bpy.context.object.data.edit_bones["Root"] - bpy.context.object.data.edit_bones["Arm_L"].parent = bpy.context.object.data.edit_bones["Spine"] - bpy.context.object.data.edit_bones["Arm_R"].parent = bpy.context.object.data.edit_bones["Spine"] - bpy.context.object.data.edit_bones["Thigh_L"].parent = bpy.context.object.data.edit_bones["Root"] - bpy.context.object.data.edit_bones["Thigh_R"].parent = bpy.context.object.data.edit_bones["Root"] - - bpy.ops.object.editmode_toggle() + #============================== + #codes to size the bones + #============================== def distance(point1, point2) -> float: #Calculate distance between two points in 3D. - #return math.sqrt((point2[0] - point1[0]) ** 2 + (point2[1] - point1[1]) ** 2 + (point2[2] - point1[2]) ** 2) + # return math.sqrt((point2[0] - point1[0]) ** 2 + (point2[1] - point1[1]) ** 2 + (point2[2] - point1[2]) ** 2) return math.sqrt((point2.location[0] - point1.location[0]) ** 2 + (point2.location[1] - point1.location[1]) ** 2 + (point2.location[2] - point1.location[2]) ** 2) + def size_bone(point_name1, point_name2, bone): p1 = bpy.data.objects[point_name1] p2 = bpy.data.objects[point_name2] @@ -1780,182 +2012,7 @@ def size_bone(point_name1, point_name2, bone): bpy.context.object.data.edit_bones[bone].length= distance(p1,p2) bpy.ops.object.editmode_toggle() - def size_ref_bone(p1,p2,p_final): - from mathutils import Vector - import bpy - - ## size of the reference bone (spine) - bpy.ops.object.select_all(action='DESELECT') - bpy.data.objects[p1].select_set(True) - bpy.data.objects[p2].select_set(True) - # bpy.context.view_layer.objects.active = bpy.data.objects['Point.034'] - bpy.context.view_layer.objects.active = bpy.data.objects[p2] - obs = bpy.context.selected_objects - n = len(obs) - # print('n: ',n) - assert(n) - #scene.cursor.location = sum([o.matrix_world.translation for o in obs], Vector()) / n - #bpy.data.objects[p_middle].location = sum([o.matrix_world.translation for o in obs], Vector()) / n - - x_subtract = abs(obs[0].matrix_world.translation.x - obs[1].matrix_world.translation.x) - y_subtract = abs(obs[0].matrix_world.translation.y - obs[1].matrix_world.translation.y) - z_subtract = abs(obs[0].matrix_world.translation.z - obs[1].matrix_world.translation.z) - - max(x_subtract, y_subtract, z_subtract) #maior das medidas - unit_def = max(x_subtract, y_subtract, z_subtract)/3 - #end of size of reference bone Spine - return unit_def - - def size_of_bones(root_size, spine_size, neck_size, face_size, thigh_size, leg_size, foot_size, arm_size, forearm_size): - #========================================== - #selecting and making the armature Active - #selecionando armature - #========================================== - bpy.ops.object.select_all(action='DESELECT') - #bpy.ops.armature.select_all(action='DESELECT') - - obs = [] - for ob in bpy.context.scene.objects: - if ob.type == 'ARMATURE': - obs.append(ob) - #obs - - armature = obs[len(obs)-1].name - - #bpy.data.objects[armature].select_set(True) - obs[len(obs)-1].select_set(True) - view_layer = bpy.context.view_layer - #Armature_obj = bpy.context.scene.objects[armature] - Armature_obj = obs[len(obs)-1] - view_layer.objects.active = Armature_obj - - #converting to euler rotation - order = 'XYZ' - context = bpy.context - rig_object = context.active_object - for pb in rig_object.pose.bones: - pb.rotation_mode = order - - - bpy.ops.object.editmode_toggle() - - #changing location - #resetting - bpy.context.object.data.edit_bones["Spine"].head.xy=0 - bpy.context.object.data.edit_bones["Neck"].head.xy=0 - bpy.context.object.data.edit_bones["Face"].head.xy=0 - - bpy.context.object.data.edit_bones["Arm_L"].head.xy=0 - bpy.context.object.data.edit_bones["Forearm_L"].head.xy=0 - - bpy.context.object.data.edit_bones["Arm_R"].head.xy=0 - bpy.context.object.data.edit_bones["Forearm_R"].head.xy=0 - - bpy.context.object.data.edit_bones["Thigh_L"].head.xy=0 - bpy.context.object.data.edit_bones["Leg_L"].head.xy=0 - bpy.context.object.data.edit_bones["Foot_L"].head.xy=0 - - bpy.context.object.data.edit_bones["Thigh_R"].head.xy=0 - bpy.context.object.data.edit_bones["Leg_R"].head.xy=0 - bpy.context.object.data.edit_bones["Foot_R"].head.xy=0 - #tail - bpy.context.object.data.edit_bones["Face"].tail.xy=0 - bpy.context.object.data.edit_bones["Neck"].tail.xy=0 - bpy.context.object.data.edit_bones["Forearm_L"].tail.xy=0 - bpy.context.object.data.edit_bones["Forearm_R"].tail.xy=0 - bpy.context.object.data.edit_bones["Foot_L"].tail.xy=0 - bpy.context.object.data.edit_bones["Foot_R"].tail.xy=0 - - - - - bpy.context.object.data.edit_bones["Root"].length = root_size - - bpy.context.object.data.edit_bones["Spine"].head.z = unit/2 - bpy.context.object.data.edit_bones["Spine"].tail.z = spine_size - - bpy.context.object.data.edit_bones["Neck"].tail.z = spine_size + neck_size - bpy.context.object.data.edit_bones["Neck"].tail.y = neck_size/3 - bpy.context.object.data.edit_bones["Face"].tail.z = spine_size + neck_size - bpy.context.object.data.edit_bones["Face"].tail.y = face_size*-1 - - bpy.context.object.data.edit_bones["Arm_L"].head.z= spine_size - bpy.context.object.data.edit_bones["Arm_L"].head.x= unit*3/4 - bpy.context.object.data.edit_bones["Forearm_L"].head.z= spine_size - bpy.context.object.data.edit_bones["Forearm_L"].head.x= unit + arm_size - bpy.context.object.data.edit_bones["Forearm_L"].tail.z= spine_size - bpy.context.object.data.edit_bones["Forearm_L"].tail.x= unit + arm_size + forearm_size - - bpy.context.object.data.edit_bones["Arm_R"].head.z= spine_size - bpy.context.object.data.edit_bones["Arm_R"].head.x= (unit*3/4)*-1 - bpy.context.object.data.edit_bones["Forearm_R"].head.z= spine_size - bpy.context.object.data.edit_bones["Forearm_R"].head.x= (unit + arm_size) *-1 - bpy.context.object.data.edit_bones["Forearm_R"].tail.z= spine_size - bpy.context.object.data.edit_bones["Forearm_R"].tail.x= (unit + arm_size + forearm_size) *-1 - - bpy.context.object.data.edit_bones["Thigh_L"].head.x= unit*3/4 - bpy.context.object.data.edit_bones["Thigh_L"].head.z= (unit/5)*-1 - bpy.context.object.data.edit_bones["Leg_L"].head.x= unit*3/4 - bpy.context.object.data.edit_bones["Leg_L"].head.z= (unit/5 + thigh_size)*-1 - bpy.context.object.data.edit_bones["Foot_L"].head.x= unit*3/4 - bpy.context.object.data.edit_bones["Foot_L"].head.z= (unit/5 + thigh_size + leg_size)*-1 - bpy.context.object.data.edit_bones["Foot_L"].tail.x= unit*3/4 - bpy.context.object.data.edit_bones["Foot_L"].tail.z= (unit/5 + thigh_size + leg_size + foot_size/2)*-1 - bpy.context.object.data.edit_bones["Foot_L"].tail.y= foot_sz/2*-1 - - bpy.context.object.data.edit_bones["Thigh_R"].head.x= unit*3/4*-1 - bpy.context.object.data.edit_bones["Thigh_R"].head.z= (unit/5)*-1 - bpy.context.object.data.edit_bones["Leg_R"].head.x= unit*3/4*-1 - bpy.context.object.data.edit_bones["Leg_R"].head.z= (unit/5 + thigh_size)*-1 - bpy.context.object.data.edit_bones["Foot_R"].head.x= unit*3/4*-1 - bpy.context.object.data.edit_bones["Foot_R"].head.z= (unit/5 + thigh_size + leg_size)*-1 - bpy.context.object.data.edit_bones["Foot_R"].tail.x= unit*3/4*-1 - bpy.context.object.data.edit_bones["Foot_R"].tail.z= (unit/5 + thigh_size + leg_size + foot_size/2)*-1 - bpy.context.object.data.edit_bones["Foot_R"].tail.y= foot_size/2*-1 - bpy.ops.object.editmode_toggle() - - def add_constraints(constraints): - obs = [] - for ob in bpy.context.scene.objects: - if ob.type == 'ARMATURE': - obs.append(ob) - #obs - - bpy.ops.object.mode_set(mode='POSE') - - for i in range(len(constraints)): - print('processar: ',constraints[i]) - if constraints[i][1] == 'COPY_LOCATION' or constraints[i][1] == 'DAMPED_TRACK': - # print('in 1 j: ',j,' - name: ',constraints[i][0],' constraint: ',constraints[i][1]) - obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[constraints[i][0]].bone - obs[len(obs)-1].pose.bones[constraints[i][0]].bone.select = True - # - bpy.ops.pose.constraint_add(type=constraints[i][1]) - qtd_constraint = len(bpy.context.object.pose.bones[constraints[i][0]].constraints) - bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].target = bpy.data.objects[constraints[i][2]] - # - if constraints[i][1] == 'LIMIT_ROTATION': - qtd_constraint = len(bpy.context.object.pose.bones[constraints[i][0]].constraints) - if constraints[i][2] == 'LOCAL': - bpy.ops.pose.constraint_add(type=constraints[i][1]) - qtd_constraint = len(bpy.context.object.pose.bones[constraints[i][0]].constraints) - bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].owner_space = constraints[i][2] - if constraints[i][2] == 'X': - if constraints[i][3] == True: - bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].use_limit_x = constraints[i][3] - bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].min_x = constraints[i][4] - bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].max_x = constraints[i][5] - if constraints[i][2] == 'Y': - if constraints[i][3] == True: - bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].use_limit_y = constraints[i][3] - bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].min_y = constraints[i][4] - bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].max_y = constraints[i][5] - if constraints[i][2] == 'Z': - if constraints[i][3] == True: - bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].use_limit_z = constraints[i][3] - bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].min_z = constraints[i][4] - bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].max_z = constraints[i][5] #path = r'D:\MOCAP\EasyMocap-master\demo_test\videos\1.mp4' @@ -1973,26 +2030,105 @@ def add_constraints(constraints): scene_collection = bpy.context.view_layer.layer_collection bpy.context.view_layer.active_layer_collection = scene_collection - bones = [['Bone','Root'], - ['Bone.001','Spine'], - ['Bone.002','Neck'], - ['Bone.003','Face'], - ['Bone.004','Arm_L'], - ['Bone.005','Forearm_L'], - ['Bone.006','Arm_R'], - ['Bone.007','Forearm_R'], - ['Bone.008','Thigh_L'], - ['Bone.009','Leg_L'], - ['Bone.010','Foot_L'], - ['Bone.011','Thigh_R'], - ['Bone.012','Leg_R'], - ['Bone.013','Foot_R'] - ] - - create_bones(bones) - - - unit = size_ref_bone('Point.001','Point.008','Point.034') + + #=================================== + #creating bones + #==================================== + + bpy.ops.object.armature_add(enter_editmode=True, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1)) #cria armature e primeiro bone + #bpy.ops.object.editmode_toggle() + #bpy.data.armatures['Armature'].edit_bones.active = bpy.context.object.data.edit_bones['Bone'] + + + obs = [] + for ob in bpy.context.scene.objects: + if ob.type == 'ARMATURE': + obs.append(ob) + #obs + + + bpy.ops.armature.select_all(action='DESELECT') + #bpy.context.object.data.edit_bones['Bone'].select_tail=True + obs[len(obs)-1].data.edit_bones['Bone'].select_tail=True + + bpy.ops.armature.bone_primitive_add()#Spine + #bpy.ops.armature.extrude_move()#Neck + bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), "mirror":True, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False, "use_automerge_and_split":False}) + #bpy.ops.armature.extrude_move()#Face + bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), "mirror":True, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False, "use_automerge_and_split":False}) + + + bpy.ops.armature.bone_primitive_add()#Arm_L + #bpy.ops.armature.extrude_move()#Forearm_L + bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), "mirror":True, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False, "use_automerge_and_split":False}) + + bpy.ops.armature.bone_primitive_add()#Arm_R + #bpy.ops.armature.extrude_move()#Forearm_R + bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), "mirror":True, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False, "use_automerge_and_split":False}) + + bpy.ops.armature.bone_primitive_add()#Thigh_L + #bpy.ops.armature.extrude_move()#Leg_L + #bpy.ops.armature.extrude_move()#Foot_L + bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), "mirror":True, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False, "use_automerge_and_split":False}) + bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), "mirror":True, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False, "use_automerge_and_split":False}) + + bpy.ops.armature.bone_primitive_add()#Thigh_R + #bpy.ops.armature.extrude_move()#Leg_R + #bpy.ops.armature.extrude_move()#Foot_R + bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), "mirror":True, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False, "use_automerge_and_split":False}) + bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), "mirror":True, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False, "use_automerge_and_split":False}) + + + obs[len(obs)-1].data.edit_bones["Bone"].name = 'Root' + obs[len(obs)-1].data.edit_bones["Bone.001"].name = 'Spine' + obs[len(obs)-1].data.edit_bones["Bone.002"].name = 'Neck' + obs[len(obs)-1].data.edit_bones["Bone.003"].name = 'Face' + obs[len(obs)-1].data.edit_bones["Bone.004"].name = 'Arm_L' + obs[len(obs)-1].data.edit_bones["Bone.005"].name = 'Forearm_L' + obs[len(obs)-1].data.edit_bones["Bone.006"].name = 'Arm_R' + obs[len(obs)-1].data.edit_bones["Bone.007"].name = 'Forearm_R' + obs[len(obs)-1].data.edit_bones["Bone.008"].name = 'Thigh_L' + obs[len(obs)-1].data.edit_bones["Bone.009"].name = 'Leg_L' + obs[len(obs)-1].data.edit_bones["Bone.010"].name = 'Foot_L' + obs[len(obs)-1].data.edit_bones["Bone.011"].name = 'Thigh_R' + obs[len(obs)-1].data.edit_bones["Bone.012"].name = 'Leg_R' + obs[len(obs)-1].data.edit_bones["Bone.013"].name = 'Foot_R' + + + #Hierarquia + bpy.context.object.data.edit_bones["Spine"].parent = bpy.context.object.data.edit_bones["Root"] + bpy.context.object.data.edit_bones["Arm_L"].parent = bpy.context.object.data.edit_bones["Spine"] + bpy.context.object.data.edit_bones["Arm_R"].parent = bpy.context.object.data.edit_bones["Spine"] + bpy.context.object.data.edit_bones["Thigh_L"].parent = bpy.context.object.data.edit_bones["Root"] + bpy.context.object.data.edit_bones["Thigh_R"].parent = bpy.context.object.data.edit_bones["Root"] + + bpy.ops.object.editmode_toggle() + + + + + from mathutils import Vector + import bpy + + bpy.ops.object.select_all(action='DESELECT') + bpy.data.objects['Point.034'].select_set(True) + bpy.data.objects['Point.035'].select_set(True) + bpy.context.view_layer.objects.active = bpy.data.objects['Point.034'] + obs = bpy.context.selected_objects + n = len(obs) + # print('n: ',n) + assert(n) + #scene.cursor.location = sum([o.matrix_world.translation for o in obs], Vector()) / n + #bpy.data.objects[p_middle].location = sum([o.matrix_world.translation for o in obs], Vector()) / n + + + + x_subtract = abs(obs[0].matrix_world.translation.x - obs[1].matrix_world.translation.x) + y_subtract = abs(obs[0].matrix_world.translation.y - obs[1].matrix_world.translation.y) + z_subtract = abs(obs[0].matrix_world.translation.z - obs[1].matrix_world.translation.z) + + max(x_subtract, y_subtract, z_subtract) #maior das medidas + unit = max(x_subtract, y_subtract, z_subtract)/3 unit = unit*multiplier root_sz =unit/10 @@ -2005,95 +2141,396 @@ def add_constraints(constraints): arm_sz =unit*1.5 forearm_sz =unit*1.5 - size_of_bones(root_sz, spine_sz, neck_sz, face_sz, thigh_sz, leg_sz, foot_sz, arm_sz, forearm_sz) - - constraints = [ - ['Root', 'COPY_LOCATION', 'Point.035'], - ['Root', 'DAMPED_TRACK', 'Point.011'], - ['Spine', 'DAMPED_TRACK', 'Point.011'], - ['Spine', 'DAMPED_TRACK', 'Point.011'], - ['Spine', 'LIMIT_ROTATION', 'LOCAL'], - ['Spine', 'LIMIT_ROTATION', 'X', True, -0.349066, 0.349066], - ['Spine', 'LIMIT_ROTATION', 'Y', True, -0.698132, 0.698132], - ['Spine', 'LIMIT_ROTATION', 'Z', True, -0.174533, 0.174533], - ['Neck', 'DAMPED_TRACK', 'Point.033'], - ['Neck', 'LIMIT_ROTATION', 'LOCAL'], - ['Neck', 'LIMIT_ROTATION', 'X', True, -0.174533, 1.0472], - ['Neck', 'LIMIT_ROTATION', 'Y', True, -0.523599, 0.523599], - ['Neck', 'LIMIT_ROTATION', 'Z', True, -0.349066, 0.349066], - ['Face', 'DAMPED_TRACK', 'Point.000'], - ['Face', 'LIMIT_ROTATION', 'LOCAL'], - ['Face', 'LIMIT_ROTATION', 'X', True, -0.174533, 0.872665], - ['Face', 'LIMIT_ROTATION', 'Y', True, 0, 0], - ['Face', 'LIMIT_ROTATION', 'Z', True, -0.523599, 0.523599], - ['Arm_L', 'DAMPED_TRACK', 'Point.013'], - ['Forearm_L', 'DAMPED_TRACK', 'Point.015'], - ['Forearm_L', 'LIMIT_ROTATION', 'LOCAL'], - ['Forearm_L', 'LIMIT_ROTATION', 'X', True, 0, 0], - ['Forearm_L', 'LIMIT_ROTATION', 'Y', True, 0, 0], - ['Forearm_L', 'LIMIT_ROTATION', 'Z', True, -2.53073, -0.191986], - ['Arm_R', 'DAMPED_TRACK', 'Point.014'], - ['Forearm_R', 'DAMPED_TRACK', 'Point.016'], - ['Forearm_R', 'LIMIT_ROTATION', 'LOCAL'], - ['Forearm_R', 'LIMIT_ROTATION', 'X', False ], - ['Forearm_R', 'LIMIT_ROTATION', 'Y', False ], - ['Forearm_R', 'LIMIT_ROTATION', 'Z', True, 0.191986, 2.53073], - ['Thigh_L', 'DAMPED_TRACK', 'Point.025'], - ['Thigh_L', 'LIMIT_ROTATION', 'LOCAL'], - ['Thigh_L', 'LIMIT_ROTATION', 'X', True, -1.76278, 1.3439], - ['Thigh_L', 'LIMIT_ROTATION', 'Y', True, 0, 0], - ['Thigh_L', 'LIMIT_ROTATION', 'Z', True, -0.785398, 0.174533], - ['Leg_L', 'DAMPED_TRACK', 'Point.027'], - ['Leg_L', 'LIMIT_ROTATION', 'LOCAL'], - ['Leg_L', 'LIMIT_ROTATION', 'X', True, 0.0698132, 2.0944], - ['Leg_L', 'LIMIT_ROTATION', 'Y', True, 0, 0], - ['Leg_L', 'LIMIT_ROTATION', 'Z', True, 0, 0], - ['Foot_L', 'DAMPED_TRACK', 'Point.031'], - ['Foot_L', 'LIMIT_ROTATION', 'LOCAL'], - ['Foot_L', 'LIMIT_ROTATION', 'X', True, -0.523599, 0.523599], - ['Foot_L', 'LIMIT_ROTATION', 'Y', True, 0, 0], - ['Foot_L', 'LIMIT_ROTATION', 'Z', True, 0, 0], - ['Thigh_R', 'DAMPED_TRACK', 'Point.026'], - ['Thigh_R', 'LIMIT_ROTATION', 'LOCAL'], - ['Thigh_R', 'LIMIT_ROTATION', 'X', True, -1.76278, 1.3439], - ['Thigh_R', 'LIMIT_ROTATION', 'Y', True, 0, 0], - ['Thigh_R', 'LIMIT_ROTATION', 'Z', True, -0.174533, 0.785398], - ['Leg_R', 'DAMPED_TRACK', 'Point.028'], - ['Leg_R', 'LIMIT_ROTATION', 'LOCAL'], - ['Leg_R', 'LIMIT_ROTATION', 'X', True, 0.0698132, 2.0944], - ['Leg_R', 'LIMIT_ROTATION', 'Y', True, 0, 0], - ['Leg_R', 'LIMIT_ROTATION', 'Z', True, 0, 0], - ['Foot_R', 'DAMPED_TRACK', 'Point.032'], - ['Foot_R', 'LIMIT_ROTATION', 'LOCAL'], - ['Foot_R', 'LIMIT_ROTATION', 'X', True, -0.523599, 0.523599], - ['Foot_R', 'LIMIT_ROTATION', 'Y', True, 0, 0], - ['Foot_R', 'LIMIT_ROTATION', 'Z', True, 0, 0] - ] - - add_constraints(constraints) - - frames = len(get_video_frames(path)) - bpy.context.scene.frame_end = frames - bpy.ops.nla.bake(frame_start=1, frame_end=frames, visual_keying=True, clear_constraints=True, clear_parents=True, bake_types={'POSE'}) - bpy.ops.object.mode_set(mode='OBJECT') + #if bpy.context.active_object.mode != 'EDIT': + # bpy.ops.object.editmode_toggle() + #========================================== + #selecting and making the armature Active + #selecionando armature + #========================================== + bpy.ops.object.select_all(action='DESELECT') + #bpy.ops.armature.select_all(action='DESELECT') + obs = [] + for ob in bpy.context.scene.objects: + if ob.type == 'ARMATURE': + obs.append(ob) + #obs + armature = obs[len(obs)-1].name - #apagar collection points criada - collection = bpy.data.collections.get('Point') - # - for obj in collection.objects: - bpy.data.objects.remove(obj, do_unlink=True) - bpy.data.collections.remove(collection) + #bpy.data.objects[armature].select_set(True) + obs[len(obs)-1].select_set(True) + view_layer = bpy.context.view_layer + #Armature_obj = bpy.context.scene.objects[armature] + Armature_obj = obs[len(obs)-1] + view_layer.objects.active = Armature_obj - sk_value_prop = context.scene.sk_value_prop - if raw_bool == True: - print('raw_bool True - ',raw_bool) - x_original, y_original, z_original = helper_functions.get_rotations() - sk_value_prop.sk_root_rot_x = math.degrees(x_original) + #converting to euler rotation + order = 'XYZ' + context = bpy.context + rig_object = context.active_object + for pb in rig_object.pose.bones: + pb.rotation_mode = order + + + + bpy.ops.object.editmode_toggle() + + #changing location + #resetting + bpy.context.object.data.edit_bones["Spine"].head.xy=0 + bpy.context.object.data.edit_bones["Neck"].head.xy=0 + bpy.context.object.data.edit_bones["Face"].head.xy=0 + + bpy.context.object.data.edit_bones["Arm_L"].head.xy=0 + bpy.context.object.data.edit_bones["Forearm_L"].head.xy=0 + + bpy.context.object.data.edit_bones["Arm_R"].head.xy=0 + bpy.context.object.data.edit_bones["Forearm_R"].head.xy=0 + + bpy.context.object.data.edit_bones["Thigh_L"].head.xy=0 + bpy.context.object.data.edit_bones["Leg_L"].head.xy=0 + bpy.context.object.data.edit_bones["Foot_L"].head.xy=0 + + bpy.context.object.data.edit_bones["Thigh_R"].head.xy=0 + bpy.context.object.data.edit_bones["Leg_R"].head.xy=0 + bpy.context.object.data.edit_bones["Foot_R"].head.xy=0 + #tail + bpy.context.object.data.edit_bones["Face"].tail.xy=0 + bpy.context.object.data.edit_bones["Forearm_L"].tail.xy=0 + bpy.context.object.data.edit_bones["Forearm_R"].tail.xy=0 + bpy.context.object.data.edit_bones["Foot_L"].tail.xy=0 + bpy.context.object.data.edit_bones["Foot_R"].tail.xy=0 + + + + + bpy.context.object.data.edit_bones["Root"].length = root_sz + + bpy.context.object.data.edit_bones["Spine"].head.z = unit/2 + bpy.context.object.data.edit_bones["Spine"].tail.z = spine_sz + + bpy.context.object.data.edit_bones["Neck"].tail.z = spine_sz + neck_sz + bpy.context.object.data.edit_bones["Neck"].tail.y = neck_sz/3 + bpy.context.object.data.edit_bones["Face"].tail.z = spine_sz + neck_sz + bpy.context.object.data.edit_bones["Face"].tail.y = face_sz*-1 + + bpy.context.object.data.edit_bones["Arm_L"].head.z= spine_sz + bpy.context.object.data.edit_bones["Arm_L"].head.x= unit/2 + bpy.context.object.data.edit_bones["Forearm_L"].head.z= spine_sz + bpy.context.object.data.edit_bones["Forearm_L"].head.x= unit + arm_sz + bpy.context.object.data.edit_bones["Forearm_L"].tail.z= spine_sz + bpy.context.object.data.edit_bones["Forearm_L"].tail.x= unit + arm_sz + forearm_sz + + bpy.context.object.data.edit_bones["Arm_R"].head.z= spine_sz + bpy.context.object.data.edit_bones["Arm_R"].head.x= (unit/2)*-1 + bpy.context.object.data.edit_bones["Forearm_R"].head.z= unit/2 + spine_sz + bpy.context.object.data.edit_bones["Forearm_R"].head.x= (unit + arm_sz) *-1 + bpy.context.object.data.edit_bones["Forearm_R"].tail.z= unit/2 + spine_sz + bpy.context.object.data.edit_bones["Forearm_R"].tail.x= (unit + arm_sz + forearm_sz) *-1 + + bpy.context.object.data.edit_bones["Thigh_L"].head.x= unit*3/4 + bpy.context.object.data.edit_bones["Thigh_L"].head.z= (unit/5)*-1 + bpy.context.object.data.edit_bones["Leg_L"].head.x= unit*3/4 + bpy.context.object.data.edit_bones["Leg_L"].head.z= (unit/5 + thigh_sz)*-1 + bpy.context.object.data.edit_bones["Foot_L"].head.x= unit*3/4 + bpy.context.object.data.edit_bones["Foot_L"].head.z= (unit/5 + thigh_sz + leg_sz)*-1 + bpy.context.object.data.edit_bones["Foot_L"].tail.x= unit*3/4 + bpy.context.object.data.edit_bones["Foot_L"].tail.z= (unit/5 + thigh_sz + leg_sz + foot_sz/2)*-1 + bpy.context.object.data.edit_bones["Foot_L"].tail.y= foot_sz/2*-1 + + bpy.context.object.data.edit_bones["Thigh_R"].head.x= unit*3/4*-1 + bpy.context.object.data.edit_bones["Thigh_R"].head.z= (unit/5)*-1 + bpy.context.object.data.edit_bones["Leg_R"].head.x= unit*3/4*-1 + bpy.context.object.data.edit_bones["Leg_R"].head.z= (unit/5 + thigh_sz)*-1 + bpy.context.object.data.edit_bones["Foot_R"].head.x= unit*3/4*-1 + bpy.context.object.data.edit_bones["Foot_R"].head.z= (unit/5 + thigh_sz + leg_sz)*-1 + bpy.context.object.data.edit_bones["Foot_R"].tail.x= unit*3/4*-1 + bpy.context.object.data.edit_bones["Foot_R"].tail.z= (unit/5 + thigh_sz + leg_sz + foot_sz/2)*-1 + bpy.context.object.data.edit_bones["Foot_R"].tail.y= foot_sz/2*-1 + + bpy.ops.object.editmode_toggle() + + import bpy + + #comecando configuração seguir movimentos pontos + #colocando em pose mode + + + obs = [] + for ob in bpy.context.scene.objects: + if ob.type == 'ARMATURE': + obs.append(ob) + #obs + + bpy.ops.object.mode_set(mode='POSE') + + + actual_bone = 'Root' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='COPY_LOCATION') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.035"] + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[1].target = bpy.data.objects["Point.011"] + + #==== + actual_bone = 'Spine' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.011"] + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[1].target = bpy.data.objects["Point.012"] + bpy.ops.pose.constraint_add(type='LIMIT_ROTATION') + bpy.context.object.pose.bones[actual_bone].constraints[2].owner_space = 'LOCAL' + #x + bpy.context.object.pose.bones[actual_bone].constraints[2].use_limit_x = True + bpy.context.object.pose.bones[actual_bone].constraints[2].min_x = -0.349066 + bpy.context.object.pose.bones[actual_bone].constraints[2].max_x = 0.349066 + #y + bpy.context.object.pose.bones[actual_bone].constraints[2].use_limit_y = True + bpy.context.object.pose.bones[actual_bone].constraints[2].min_y = -0.698132 + bpy.context.object.pose.bones[actual_bone].constraints[2].max_y = 0.698132 + #z + bpy.context.object.pose.bones[actual_bone].constraints[2].use_limit_z = True + bpy.context.object.pose.bones[actual_bone].constraints[2].min_z = -0.174533 + bpy.context.object.pose.bones[actual_bone].constraints[2].max_z = 0.174533 + + #===== + actual_bone = 'Neck' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.033"] + bpy.ops.pose.constraint_add(type='LIMIT_ROTATION') + bpy.context.object.pose.bones[actual_bone].constraints[1].owner_space = 'LOCAL' + #x + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_x = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_x = -0.174533 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_x = 1.0472 + #y + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_y = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_y = -0.523599 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_y = 0.523599 + #z + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_z = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_z = -0.349066 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_z = 0.349066 + #===== + actual_bone = 'Face' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.000"] + bpy.ops.pose.constraint_add(type='LIMIT_ROTATION') + bpy.context.object.pose.bones[actual_bone].constraints[1].owner_space = 'LOCAL' + #x + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_x = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_x = -0.174533 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_x = 0.872665 + #y + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_y = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_y = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_y = 0 + #z + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_z = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_z = -0.523599 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_z = 0.523599 + #===== + actual_bone = 'Arm_L' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.013"] + #===== + actual_bone = 'Forearm_L' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.015"] + bpy.ops.pose.constraint_add(type='LIMIT_ROTATION') + bpy.context.object.pose.bones[actual_bone].constraints[1].owner_space = 'LOCAL' + #x + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_x = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_x = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_x = 0 + #y + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_y = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_y = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_y = 0 + #z + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_z = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_z = -2.53073 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_z = -0.191986 + #===== + actual_bone = 'Arm_R' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.014"] + #===== + actual_bone = 'Forearm_R' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.016"] + bpy.ops.pose.constraint_add(type='LIMIT_ROTATION') + bpy.context.object.pose.bones[actual_bone].constraints[1].owner_space = 'LOCAL' + #x + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_x = False + #y + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_y = False + #z + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_z = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_z = 0.191986 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_z = 2.53073 + #===== + actual_bone = 'Thigh_L' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.025"] + bpy.ops.pose.constraint_add(type='LIMIT_ROTATION') + bpy.context.object.pose.bones[actual_bone].constraints[1].owner_space = 'LOCAL' + #x + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_x = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_x = -1.76278 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_x = 1.3439 + #y + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_y = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_y = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_y = 0 + #z + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_z = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_z = -0.785398 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_z = 0.174533 + #===== + actual_bone = 'Leg_L' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.027"] + bpy.ops.pose.constraint_add(type='LIMIT_ROTATION') + bpy.context.object.pose.bones[actual_bone].constraints[1].owner_space = 'LOCAL' + #x + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_x = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_x = 0.0698132 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_x = 2.0944 + #y + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_y = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_y = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_y = 0 + #z + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_z = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_z = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_z = 0 + #===== + actual_bone = 'Foot_L' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.031"] + bpy.ops.pose.constraint_add(type='LIMIT_ROTATION') + bpy.context.object.pose.bones[actual_bone].constraints[1].owner_space = 'LOCAL' + #x + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_x = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_x = -0.523599 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_x = 0.523599 + #y + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_y = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_y = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_y = 0 + #z + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_z = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_z = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_z = 0 + #===== + actual_bone = 'Thigh_R' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.026"] + bpy.ops.pose.constraint_add(type='LIMIT_ROTATION') + bpy.context.object.pose.bones[actual_bone].constraints[1].owner_space = 'LOCAL' + #x + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_x = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_x = -1.76278 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_x = 1.3439 + #y + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_y = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_y = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_y = 0 + #z + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_z = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_z = -0.174533 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_z = 0.785398 + + actual_bone = 'Leg_R' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.028"] + bpy.ops.pose.constraint_add(type='LIMIT_ROTATION') + bpy.context.object.pose.bones[actual_bone].constraints[1].owner_space = 'LOCAL' + #x + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_x = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_x = 0.0698132 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_x = 2.0944 + #y + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_y = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_y = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_y = 0 + #z + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_z = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_z = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_z = 0 + + actual_bone = 'Foot_R' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.032"] + bpy.ops.pose.constraint_add(type='LIMIT_ROTATION') + bpy.context.object.pose.bones[actual_bone].constraints[1].owner_space = 'LOCAL' + #x + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_x = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_x = -0.523599 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_x = 0.523599 + #y + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_y = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_y = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_y = 0 + #z + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_z = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_z = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_z = 0 + + frames = len(get_video_frames(path)) + + bpy.context.scene.frame_end = frames + + bpy.ops.nla.bake(frame_start=1, frame_end=frames, visual_keying=True, clear_constraints=True, clear_parents=True, bake_types={'POSE'}) + bpy.ops.object.mode_set(mode='OBJECT') + + + + #apagar collection points criada + collection = bpy.data.collections.get('Point') + # + for obj in collection.objects: + bpy.data.objects.remove(obj, do_unlink=True) + bpy.data.collections.remove(collection) + + sk_value_prop = context.scene.sk_value_prop + if raw_bool == True: + print('raw_bool True - ',raw_bool) + + x_original, y_original, z_original = helper_functions.get_rotations() + sk_value_prop.sk_root_rot_x = math.degrees(x_original) sk_value_prop.sk_root_rot_y = math.degrees(y_original) sk_value_prop.sk_root_rot_z = math.degrees(z_original) @@ -2120,6 +2557,7 @@ def add_constraints(constraints): return{'FINISHED'} + class Install_Mediapipe(bpy.types.Operator): bl_idname = "install.mediapipe_package" bl_label = "Install python Mediapipe Package" @@ -2143,6 +2581,7 @@ def execute(self,context): return{'FINISHED'} + class Install_Joblib(bpy.types.Operator): bl_idname = "install.joblib_package" bl_label = "Install python JobLib Package" @@ -2247,24 +2686,928 @@ def execute(sel,context): helper_functions.smooth_curves(o) return{'FINISHED'} -class Path_SMPL_FBX_File(Operator, ImportHelper): - bl_idname = "mocap.browse_smpl_file" - bl_label = "Get the smpl file path" - bl_description = "Get the smpl file path" - filename_ext = ".fbx" +# class ModalTimerOperator_Mediapipe(bpy.types.Operator): +# """Operator which runs its self from a timer""" +# bl_idname = "wm.modal_timer_operator" +# bl_label = "Modal Timer Operator" - filter_glob: StringProperty( - default="*.fbx", - options={'HIDDEN'}, - maxlen=255, # Max internal buffer length, longer would be clamped. - ) +# _timer = None + +# def middle_point(p1,p2,p_middle): +# bpy.ops.object.select_all(action='DESELECT') +# bpy.data.objects[p1].select_set(True) +# bpy.data.objects[p2].select_set(True) +# bpy.context.view_layer.objects.active = bpy.data.objects[p2] +# obs = bpy.context.selected_objects +# n = len(obs) +# # print('n: ',n) +# assert(n) +# #scene.cursor.location = sum([o.matrix_world.translation for o in obs], Vector()) / n +# bpy.data.objects[p_middle].location = sum([o.matrix_world.translation for o in obs], Vector()) / n + +# def modal(self, context, event): +# if event.type in {'RIGHTMOUSE', 'ESC'}: +# self.cancel(context) +# return {'CANCELLED'} + +# if event.type == 'TIMER': +# # change theme color, silly! +# # color = context.preferences.themes[0].view_3d.space.gradients.high_gradient +# # color.s = 1.0 +# # color.h += 0.01 + +# ############# +# #begin of connection code +# full_msg = b'' +# nem_msg = True +# while True: +# msg = s.recv(512) #1024 is the buffer +# if nem_msg: +# # print(f"new message length: {msg[:HEADERSIZE]}") +# msglen = int(msg[:HEADERSIZE]) +# nem_msg = False + +# full_msg += msg + +# if len(full_msg)-HEADERSIZE == msglen: + +# d = json.loads(full_msg[HEADERSIZE:].decode('utf-8')) + +# nem_msg = True +# full_msg = b'' +# break + +# # print('fim: ',d) +# if d != 'nada': +# # print('len d[0]: ', len(d[0])) +# print('bone: ',d[1][0],' x: ',d[1][1],' y: ',d[1][2],' z: ',d[1][3]) +# for i in range(len(d)): +# x_pose = d[i][1] +# y_pose = d[i][2] +# z_pose = d[i][3] +# bpy.data.objects["Point."+str(1000+i)[1:]].location[0]=x_pose +# bpy.data.objects["Point."+str(1000+i)[1:]].location[1]=y_pose +# bpy.data.objects["Point."+str(1000+i)[1:]].location[2]=z_pose +# if i == 10: +# # middle_point('Point.009','Point.010','Point.033') +# bpy.ops.object.select_all(action='DESELECT') +# bpy.data.objects['Point.009'].select_set(True) +# bpy.data.objects['Point.010'].select_set(True) +# bpy.context.view_layer.objects.active = bpy.data.objects['Point.010'] +# obs = bpy.context.selected_objects +# n = len(obs) +# assert(n) +# bpy.data.objects['Point.033'].location = sum([o.matrix_world.translation for o in obs], Vector()) / n +# # bpy.data.objects["Point."+str(1000+33)[1:]].keyframe_insert(data_path="location", frame=idx) +# if i == 12: +# # middle_point('Point.011','Point.012','Point.034') +# bpy.ops.object.select_all(action='DESELECT') +# bpy.data.objects['Point.011'].select_set(True) +# bpy.data.objects['Point.012'].select_set(True) +# bpy.context.view_layer.objects.active = bpy.data.objects['Point.012'] +# obs = bpy.context.selected_objects +# n = len(obs) +# assert(n) +# bpy.data.objects['Point.034'].location = sum([o.matrix_world.translation for o in obs], Vector()) / n +# # bpy.data.objects["Point."+str(1000+34)[1:]].keyframe_insert(data_path="location", frame=idx) +# if i == 24: +# # middle_point('Point.023','Point.024','Point.035') +# bpy.ops.object.select_all(action='DESELECT') +# bpy.data.objects['Point.023'].select_set(True) +# bpy.data.objects['Point.024'].select_set(True) +# bpy.context.view_layer.objects.active = bpy.data.objects['Point.024'] +# obs = bpy.context.selected_objects +# n = len(obs) +# assert(n) +# bpy.data.objects['Point.035'].location = sum([o.matrix_world.translation for o in obs], Vector()) / n +# bpy.data.objects["Point."+str(1000+35)[1:]].keyframe_insert(data_path="location", frame=idx) +# # bpy.data.objects["Point."+str(1000+i)[1:]].keyframe_insert(data_path="location", frame=idx) + + +# #end connection code + + +# return {'PASS_THROUGH'} + + # def execute(self, context): + # wm = context.window_manager + # self._timer = wm.event_timer_add(0.2, window=context.window) + # wm.modal_handler_add(self) + # print('MODAL!!!!!!!!!!!!!!!') + # return {'RUNNING_MODAL'} + + # def cancel(self, context): + # wm = context.window_manager + # wm.event_timer_remove(self._timer) + + + + + +######################################## +##### MediaPipe Realtime +######################################## + + +class Mediapipe_Pose_Prepare_Skeleton_RT(Operator): + bl_idname = "mocap.mediapipe_prepare_sk_rt" + bl_label = "Generate Pose using MediaPipe" + bl_description = "Generate Mocap data with MediaPipe" + + def execute(self,context): - # path = self.filepath - context.scene.sk_value_prop.sk_smpl_path = os.path.dirname(self.filepath) + import cv2 + # import mediapipe as mp + import bpy + import sys + from mathutils import Vector + import math + + multiplier = context.scene.sk_value_prop.sk_value + raw_bool = context.scene.sk_value_prop.sk_raw_bool + def middle_point(p1,p2,p_middle): + bpy.ops.object.select_all(action='DESELECT') + bpy.data.objects[p1].select_set(True) + bpy.data.objects[p2].select_set(True) + bpy.context.view_layer.objects.active = bpy.data.objects[p2] + obs = bpy.context.selected_objects + n = len(obs) + # print('n: ',n) + assert(n) + #scene.cursor.location = sum([o.matrix_world.translation for o in obs], Vector()) / n + bpy.data.objects[p_middle].location = sum([o.matrix_world.translation for o in obs], Vector()) / n + + def get_video_frames(file_url): + vidcap = cv2.VideoCapture(file_url) + success, image = vidcap.read() + # array of objects with class 'numpy.ndarray' + frames = [] + while success: + frames.append(image) + success, image = vidcap.read() + # + return frames + + def create_dots(name, amount): + #remove Collection + if bpy.data.collections.find(name) >= 0: + collection = bpy.data.collections.get(name) + # + for obj in collection.objects: + bpy.data.objects.remove(obj, do_unlink=True) + bpy.data.collections.remove(collection) + #cria os pontos nuima collection chamada Points + #===================================================== + collection = bpy.data.collections.new(name) + bpy.context.scene.collection.children.link(collection) + # + layer_collection = bpy.context.view_layer.layer_collection.children[collection.name] + bpy.context.view_layer.active_layer_collection = layer_collection + # + for point in range(amount): + bpy.ops.mesh.primitive_plane_add(enter_editmode=True, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1)) + bpy.ops.mesh.merge(type='CENTER') + bpy.ops.object.editmode_toggle() + bpy.context.active_object.name = name+'.'+str(1000+point)[1:] + #===================================================== + + #============================== + #codes to size the bones + #============================== + + def distance(point1, point2) -> float: + #Calculate distance between two points in 3D. + # return math.sqrt((point2[0] - point1[0]) ** 2 + (point2[1] - point1[1]) ** 2 + (point2[2] - point1[2]) ** 2) + return math.sqrt((point2.location[0] - point1.location[0]) ** 2 + (point2.location[1] - point1.location[1]) ** 2 + (point2.location[2] - point1.location[2]) ** 2) + + + def size_bone(point_name1, point_name2, bone): + p1 = bpy.data.objects[point_name1] + p2 = bpy.data.objects[point_name2] + #edit bones + if bpy.context.active_object.mode == 'EDIT': + bpy.context.object.data.edit_bones[bone].length= distance(p1,p2) + else: + bpy.ops.object.editmode_toggle() + bpy.context.object.data.edit_bones[bone].length= distance(p1,p2) + bpy.ops.object.editmode_toggle() + + + create_dots('Point',36) + + + + import bpy + + + #=========== + # selectign Scene Collection + scene_collection = bpy.context.view_layer.layer_collection + bpy.context.view_layer.active_layer_collection = scene_collection + + + #=================================== + #creating bones + #==================================== + + bpy.ops.object.armature_add(enter_editmode=True, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1)) #cria armature e primeiro bone + #bpy.ops.object.editmode_toggle() + #bpy.data.armatures['Armature'].edit_bones.active = bpy.context.object.data.edit_bones['Bone'] + + + obs = [] + for ob in bpy.context.scene.objects: + if ob.type == 'ARMATURE': + obs.append(ob) + #obs + + + bpy.ops.armature.select_all(action='DESELECT') + #bpy.context.object.data.edit_bones['Bone'].select_tail=True + obs[len(obs)-1].data.edit_bones['Bone'].select_tail=True + + bpy.ops.armature.bone_primitive_add()#Spine + #bpy.ops.armature.extrude_move()#Neck + bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), "mirror":True, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False, "use_automerge_and_split":False}) + #bpy.ops.armature.extrude_move()#Face + bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), "mirror":True, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False, "use_automerge_and_split":False}) + + + bpy.ops.armature.bone_primitive_add()#Arm_L + #bpy.ops.armature.extrude_move()#Forearm_L + bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), "mirror":True, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False, "use_automerge_and_split":False}) + + bpy.ops.armature.bone_primitive_add()#Arm_R + #bpy.ops.armature.extrude_move()#Forearm_R + bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), "mirror":True, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False, "use_automerge_and_split":False}) + + bpy.ops.armature.bone_primitive_add()#Thigh_L + #bpy.ops.armature.extrude_move()#Leg_L + #bpy.ops.armature.extrude_move()#Foot_L + bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), "mirror":True, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False, "use_automerge_and_split":False}) + bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), "mirror":True, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False, "use_automerge_and_split":False}) + + bpy.ops.armature.bone_primitive_add()#Thigh_R + #bpy.ops.armature.extrude_move()#Leg_R + #bpy.ops.armature.extrude_move()#Foot_R + bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), "mirror":True, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False, "use_automerge_and_split":False}) + bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1), "orient_type":'GLOBAL', "orient_matrix":((1, 0, 0), (0, 1, 0), (0, 0, 1)), "orient_matrix_type":'GLOBAL', "constraint_axis":(False, False, False), "mirror":True, "use_proportional_edit":False, "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "use_proportional_connected":False, "use_proportional_projected":False, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "cursor_transform":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False, "use_automerge_and_split":False}) + + + obs[len(obs)-1].data.edit_bones["Bone"].name = 'Root' + obs[len(obs)-1].data.edit_bones["Bone.001"].name = 'Spine' + obs[len(obs)-1].data.edit_bones["Bone.002"].name = 'Neck' + obs[len(obs)-1].data.edit_bones["Bone.003"].name = 'Face' + obs[len(obs)-1].data.edit_bones["Bone.004"].name = 'Arm_L' + obs[len(obs)-1].data.edit_bones["Bone.005"].name = 'Forearm_L' + obs[len(obs)-1].data.edit_bones["Bone.006"].name = 'Arm_R' + obs[len(obs)-1].data.edit_bones["Bone.007"].name = 'Forearm_R' + obs[len(obs)-1].data.edit_bones["Bone.008"].name = 'Thigh_L' + obs[len(obs)-1].data.edit_bones["Bone.009"].name = 'Leg_L' + obs[len(obs)-1].data.edit_bones["Bone.010"].name = 'Foot_L' + obs[len(obs)-1].data.edit_bones["Bone.011"].name = 'Thigh_R' + obs[len(obs)-1].data.edit_bones["Bone.012"].name = 'Leg_R' + obs[len(obs)-1].data.edit_bones["Bone.013"].name = 'Foot_R' + + + #Hierarquia + bpy.context.object.data.edit_bones["Spine"].parent = bpy.context.object.data.edit_bones["Root"] + bpy.context.object.data.edit_bones["Arm_L"].parent = bpy.context.object.data.edit_bones["Spine"] + bpy.context.object.data.edit_bones["Arm_R"].parent = bpy.context.object.data.edit_bones["Spine"] + bpy.context.object.data.edit_bones["Thigh_L"].parent = bpy.context.object.data.edit_bones["Root"] + bpy.context.object.data.edit_bones["Thigh_R"].parent = bpy.context.object.data.edit_bones["Root"] + + bpy.ops.object.editmode_toggle() + + + + + from mathutils import Vector + import bpy + + bpy.ops.object.select_all(action='DESELECT') + bpy.data.objects['Point.034'].select_set(True) + bpy.data.objects['Point.035'].select_set(True) + bpy.context.view_layer.objects.active = bpy.data.objects['Point.034'] + obs = bpy.context.selected_objects + n = len(obs) + # print('n: ',n) + assert(n) + #scene.cursor.location = sum([o.matrix_world.translation for o in obs], Vector()) / n + #bpy.data.objects[p_middle].location = sum([o.matrix_world.translation for o in obs], Vector()) / n + + + + x_subtract = abs(obs[0].matrix_world.translation.x - obs[1].matrix_world.translation.x) + y_subtract = abs(obs[0].matrix_world.translation.y - obs[1].matrix_world.translation.y) + z_subtract = abs(obs[0].matrix_world.translation.z - obs[1].matrix_world.translation.z) + + max(x_subtract, y_subtract, z_subtract) #maior das medidas + # unit = max(x_subtract, y_subtract, z_subtract)/3 + unit=1 + unit = unit*multiplier + + root_sz =unit/10 + spine_sz =unit*3.5 + neck_sz =unit + face_sz =unit + thigh_sz =unit*3 + leg_sz =unit*2.5 + foot_sz =unit #inclinado 45 graud pra frente + arm_sz =unit*1.5 + forearm_sz =unit*1.5 + + + + #if bpy.context.active_object.mode != 'EDIT': + # bpy.ops.object.editmode_toggle() + #========================================== + #selecting and making the armature Active + #selecionando armature + #========================================== + bpy.ops.object.select_all(action='DESELECT') + #bpy.ops.armature.select_all(action='DESELECT') + + obs = [] + for ob in bpy.context.scene.objects: + if ob.type == 'ARMATURE': + obs.append(ob) + #obs + + armature = obs[len(obs)-1].name + + #bpy.data.objects[armature].select_set(True) + obs[len(obs)-1].select_set(True) + view_layer = bpy.context.view_layer + #Armature_obj = bpy.context.scene.objects[armature] + Armature_obj = obs[len(obs)-1] + view_layer.objects.active = Armature_obj + + + #converting to euler rotation + order = 'XYZ' + context = bpy.context + rig_object = context.active_object + for pb in rig_object.pose.bones: + pb.rotation_mode = order + + + + bpy.ops.object.editmode_toggle() + + #changing location + #resetting + bpy.context.object.data.edit_bones["Spine"].head.xy=0 + bpy.context.object.data.edit_bones["Neck"].head.xy=0 + bpy.context.object.data.edit_bones["Face"].head.xy=0 + + bpy.context.object.data.edit_bones["Arm_L"].head.xy=0 + bpy.context.object.data.edit_bones["Forearm_L"].head.xy=0 + + bpy.context.object.data.edit_bones["Arm_R"].head.xy=0 + bpy.context.object.data.edit_bones["Forearm_R"].head.xy=0 + + bpy.context.object.data.edit_bones["Thigh_L"].head.xy=0 + bpy.context.object.data.edit_bones["Leg_L"].head.xy=0 + bpy.context.object.data.edit_bones["Foot_L"].head.xy=0 + + bpy.context.object.data.edit_bones["Thigh_R"].head.xy=0 + bpy.context.object.data.edit_bones["Leg_R"].head.xy=0 + bpy.context.object.data.edit_bones["Foot_R"].head.xy=0 + #tail + bpy.context.object.data.edit_bones["Face"].tail.xy=0 + bpy.context.object.data.edit_bones["Forearm_L"].tail.xy=0 + bpy.context.object.data.edit_bones["Forearm_R"].tail.xy=0 + bpy.context.object.data.edit_bones["Foot_L"].tail.xy=0 + bpy.context.object.data.edit_bones["Foot_R"].tail.xy=0 + + + + + bpy.context.object.data.edit_bones["Root"].length = root_sz + + bpy.context.object.data.edit_bones["Spine"].head.z = unit/2 + bpy.context.object.data.edit_bones["Spine"].tail.z = spine_sz + + bpy.context.object.data.edit_bones["Neck"].tail.z = spine_sz + neck_sz + bpy.context.object.data.edit_bones["Neck"].tail.y = neck_sz/3 + bpy.context.object.data.edit_bones["Face"].tail.z = spine_sz + neck_sz + bpy.context.object.data.edit_bones["Face"].tail.y = face_sz*-1 + + bpy.context.object.data.edit_bones["Arm_L"].head.z= spine_sz + bpy.context.object.data.edit_bones["Arm_L"].head.x= unit/2 + bpy.context.object.data.edit_bones["Forearm_L"].head.z= spine_sz + bpy.context.object.data.edit_bones["Forearm_L"].head.x= unit + arm_sz + bpy.context.object.data.edit_bones["Forearm_L"].tail.z= spine_sz + bpy.context.object.data.edit_bones["Forearm_L"].tail.x= unit + arm_sz + forearm_sz + + bpy.context.object.data.edit_bones["Arm_R"].head.z= spine_sz + bpy.context.object.data.edit_bones["Arm_R"].head.x= (unit/2)*-1 + bpy.context.object.data.edit_bones["Forearm_R"].head.z= unit/2 + spine_sz + bpy.context.object.data.edit_bones["Forearm_R"].head.x= (unit + arm_sz) *-1 + bpy.context.object.data.edit_bones["Forearm_R"].tail.z= unit/2 + spine_sz + bpy.context.object.data.edit_bones["Forearm_R"].tail.x= (unit + arm_sz + forearm_sz) *-1 + + bpy.context.object.data.edit_bones["Thigh_L"].head.x= unit*3/4 + bpy.context.object.data.edit_bones["Thigh_L"].head.z= (unit/5)*-1 + bpy.context.object.data.edit_bones["Leg_L"].head.x= unit*3/4 + bpy.context.object.data.edit_bones["Leg_L"].head.z= (unit/5 + thigh_sz)*-1 + bpy.context.object.data.edit_bones["Foot_L"].head.x= unit*3/4 + bpy.context.object.data.edit_bones["Foot_L"].head.z= (unit/5 + thigh_sz + leg_sz)*-1 + bpy.context.object.data.edit_bones["Foot_L"].tail.x= unit*3/4 + bpy.context.object.data.edit_bones["Foot_L"].tail.z= (unit/5 + thigh_sz + leg_sz + foot_sz/2)*-1 + bpy.context.object.data.edit_bones["Foot_L"].tail.y= foot_sz/2*-1 + + bpy.context.object.data.edit_bones["Thigh_R"].head.x= unit*3/4*-1 + bpy.context.object.data.edit_bones["Thigh_R"].head.z= (unit/5)*-1 + bpy.context.object.data.edit_bones["Leg_R"].head.x= unit*3/4*-1 + bpy.context.object.data.edit_bones["Leg_R"].head.z= (unit/5 + thigh_sz)*-1 + bpy.context.object.data.edit_bones["Foot_R"].head.x= unit*3/4*-1 + bpy.context.object.data.edit_bones["Foot_R"].head.z= (unit/5 + thigh_sz + leg_sz)*-1 + bpy.context.object.data.edit_bones["Foot_R"].tail.x= unit*3/4*-1 + bpy.context.object.data.edit_bones["Foot_R"].tail.z= (unit/5 + thigh_sz + leg_sz + foot_sz/2)*-1 + bpy.context.object.data.edit_bones["Foot_R"].tail.y= foot_sz/2*-1 + + bpy.ops.object.editmode_toggle() + + import bpy + + #comecando configuração seguir movimentos pontos + #colocando em pose mode + + + obs = [] + for ob in bpy.context.scene.objects: + if ob.type == 'ARMATURE': + obs.append(ob) + #obs + + bpy.ops.object.mode_set(mode='POSE') + + + actual_bone = 'Root' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='COPY_LOCATION') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.035"] + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[1].target = bpy.data.objects["Point.011"] + + #==== + actual_bone = 'Spine' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.011"] + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[1].target = bpy.data.objects["Point.012"] + bpy.ops.pose.constraint_add(type='LIMIT_ROTATION') + bpy.context.object.pose.bones[actual_bone].constraints[2].owner_space = 'LOCAL' + #x + bpy.context.object.pose.bones[actual_bone].constraints[2].use_limit_x = True + bpy.context.object.pose.bones[actual_bone].constraints[2].min_x = -0.349066 + bpy.context.object.pose.bones[actual_bone].constraints[2].max_x = 0.349066 + #y + bpy.context.object.pose.bones[actual_bone].constraints[2].use_limit_y = True + bpy.context.object.pose.bones[actual_bone].constraints[2].min_y = -0.698132 + bpy.context.object.pose.bones[actual_bone].constraints[2].max_y = 0.698132 + #z + bpy.context.object.pose.bones[actual_bone].constraints[2].use_limit_z = True + bpy.context.object.pose.bones[actual_bone].constraints[2].min_z = -0.174533 + bpy.context.object.pose.bones[actual_bone].constraints[2].max_z = 0.174533 + + #===== + actual_bone = 'Neck' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.033"] + bpy.ops.pose.constraint_add(type='LIMIT_ROTATION') + bpy.context.object.pose.bones[actual_bone].constraints[1].owner_space = 'LOCAL' + #x + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_x = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_x = -0.174533 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_x = 1.0472 + #y + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_y = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_y = -0.523599 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_y = 0.523599 + #z + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_z = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_z = -0.349066 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_z = 0.349066 + #===== + actual_bone = 'Face' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.000"] + bpy.ops.pose.constraint_add(type='LIMIT_ROTATION') + bpy.context.object.pose.bones[actual_bone].constraints[1].owner_space = 'LOCAL' + #x + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_x = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_x = -0.174533 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_x = 0.872665 + #y + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_y = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_y = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_y = 0 + #z + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_z = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_z = -0.523599 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_z = 0.523599 + #===== + actual_bone = 'Arm_L' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.013"] + #===== + actual_bone = 'Forearm_L' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.015"] + bpy.ops.pose.constraint_add(type='LIMIT_ROTATION') + bpy.context.object.pose.bones[actual_bone].constraints[1].owner_space = 'LOCAL' + #x + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_x = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_x = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_x = 0 + #y + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_y = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_y = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_y = 0 + #z + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_z = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_z = -2.53073 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_z = -0.191986 + #===== + actual_bone = 'Arm_R' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.014"] + #===== + actual_bone = 'Forearm_R' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.016"] + bpy.ops.pose.constraint_add(type='LIMIT_ROTATION') + bpy.context.object.pose.bones[actual_bone].constraints[1].owner_space = 'LOCAL' + #x + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_x = False + #y + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_y = False + #z + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_z = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_z = 0.191986 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_z = 2.53073 + #===== + actual_bone = 'Thigh_L' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.025"] + bpy.ops.pose.constraint_add(type='LIMIT_ROTATION') + bpy.context.object.pose.bones[actual_bone].constraints[1].owner_space = 'LOCAL' + #x + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_x = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_x = -1.76278 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_x = 1.3439 + #y + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_y = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_y = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_y = 0 + #z + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_z = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_z = -0.785398 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_z = 0.174533 + #===== + actual_bone = 'Leg_L' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.027"] + bpy.ops.pose.constraint_add(type='LIMIT_ROTATION') + bpy.context.object.pose.bones[actual_bone].constraints[1].owner_space = 'LOCAL' + #x + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_x = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_x = 0.0698132 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_x = 2.0944 + #y + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_y = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_y = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_y = 0 + #z + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_z = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_z = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_z = 0 + #===== + actual_bone = 'Foot_L' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.031"] + bpy.ops.pose.constraint_add(type='LIMIT_ROTATION') + bpy.context.object.pose.bones[actual_bone].constraints[1].owner_space = 'LOCAL' + #x + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_x = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_x = -0.523599 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_x = 0.523599 + #y + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_y = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_y = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_y = 0 + #z + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_z = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_z = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_z = 0 + #===== + actual_bone = 'Thigh_R' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.026"] + bpy.ops.pose.constraint_add(type='LIMIT_ROTATION') + bpy.context.object.pose.bones[actual_bone].constraints[1].owner_space = 'LOCAL' + #x + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_x = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_x = -1.76278 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_x = 1.3439 + #y + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_y = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_y = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_y = 0 + #z + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_z = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_z = -0.174533 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_z = 0.785398 + + actual_bone = 'Leg_R' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.028"] + bpy.ops.pose.constraint_add(type='LIMIT_ROTATION') + bpy.context.object.pose.bones[actual_bone].constraints[1].owner_space = 'LOCAL' + #x + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_x = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_x = 0.0698132 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_x = 2.0944 + #y + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_y = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_y = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_y = 0 + #z + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_z = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_z = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_z = 0 + + actual_bone = 'Foot_R' + obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[actual_bone].bone + obs[len(obs)-1].pose.bones[actual_bone].bone.select = True + bpy.ops.pose.constraint_add(type='DAMPED_TRACK') + bpy.context.object.pose.bones[actual_bone].constraints[0].target = bpy.data.objects["Point.032"] + bpy.ops.pose.constraint_add(type='LIMIT_ROTATION') + bpy.context.object.pose.bones[actual_bone].constraints[1].owner_space = 'LOCAL' + #x + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_x = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_x = -0.523599 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_x = 0.523599 + #y + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_y = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_y = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_y = 0 + #z + bpy.context.object.pose.bones[actual_bone].constraints[1].use_limit_z = True + bpy.context.object.pose.bones[actual_bone].constraints[1].min_z = 0 + bpy.context.object.pose.bones[actual_bone].constraints[1].max_z = 0 + + # frames = len(get_video_frames(path)) + + # bpy.context.scene.frame_end = frames + + # bpy.ops.nla.bake(frame_start=1, frame_end=frames, visual_keying=True, clear_constraints=True, clear_parents=True, bake_types={'POSE'}) + bpy.ops.object.mode_set(mode='OBJECT') + + + + #apagar collection points criada + # collection = bpy.data.collections.get('Point') + # # + # for obj in collection.objects: + # bpy.data.objects.remove(obj, do_unlink=True) + # bpy.data.collections.remove(collection) + + sk_value_prop = context.scene.sk_value_prop + + return{'FINISHED'} + + + + + +# class Mediapipe_Pose_estimation_RT(Operator, ImportHelper): +class Mediapipe_Pose_estimation_RT(Operator): + bl_idname = "mocap.mediapipe_pose_rt" + bl_label = "Generate Pose using MediaPipe RealTime" + bl_description = "Generate Mocap data with MediaPipe RealTime, you have to use separated script running outside Blender" + + + import bpy + import socket + import json + from datetime import datetime + from mathutils import Vector + import math + + + + + + ################################## + #### Starting modal to get media pipe realtime + ################################## + + _timer = None + _s = None + _frame = None + + + def modal(self, context, event): + socket_buffer = context.scene.sk_value_prop.sk_socket_buffer + record_bool = context.scene.sk_value_prop.sk_record_bool + # record_frame_start = context.scene.sk_value_prop.sk_record_frame_start + + + import socket + from mathutils import Vector + # s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + # s.connect((socket.gethostname(), 1234)) #gethostname is the local address, + + HEADERSIZE = 10 + + + if event.type in {'RIGHTMOUSE', 'ESC'}: + self.cancel(context) + return {'CANCELLED'} + + if event.type == 'TIMER': + ############# + #begin of connection code + full_msg = b'' + nem_msg = True + while True: + # msg = self._s.recv(1024) #1024 is the buffer + msg = self._s.recv(socket_buffer) + if nem_msg: + # self._frame = self._frame + 1 + print(f"new message length: {msg[:HEADERSIZE]}") + msglen = int(msg[:HEADERSIZE]) + nem_msg = False + + full_msg += msg + + if len(full_msg)-HEADERSIZE >= msglen: + + d = json.loads(full_msg[HEADERSIZE:].decode('utf-8')) + + nem_msg = True + full_msg = b'' + break + + # print('fim: ',d) + if d != 'nada': + # print('len d[0]: ', len(d[0])) + print('Frame:',self._frame,'bone: ',d[1][0],' x: ',d[1][1],' y: ',d[1][2],' z: ',d[1][3]) + for i in range(len(d)): + x_pose = d[i][1] + y_pose = d[i][2] + z_pose = d[i][3] + bpy.data.objects["Point."+str(1000+i)[1:]].location[0]=x_pose + bpy.data.objects["Point."+str(1000+i)[1:]].location[1]=y_pose + bpy.data.objects["Point."+str(1000+i)[1:]].location[2]=z_pose + if i == 10: + # middle_point('Point.009','Point.010','Point.033') + bpy.ops.object.select_all(action='DESELECT') + bpy.data.objects['Point.009'].select_set(True) + bpy.data.objects['Point.010'].select_set(True) + bpy.context.view_layer.objects.active = bpy.data.objects['Point.010'] + obs = bpy.context.selected_objects + n = len(obs) + assert(n) + bpy.data.objects['Point.033'].location = sum([o.matrix_world.translation for o in obs], Vector()) / n + if record_bool == True: + bpy.data.objects["Point."+str(1000+33)[1:]].keyframe_insert(data_path="location", frame=self._frame) + if i == 12: + # middle_point('Point.011','Point.012','Point.034') + bpy.ops.object.select_all(action='DESELECT') + bpy.data.objects['Point.011'].select_set(True) + bpy.data.objects['Point.012'].select_set(True) + bpy.context.view_layer.objects.active = bpy.data.objects['Point.012'] + obs = bpy.context.selected_objects + n = len(obs) + assert(n) + bpy.data.objects['Point.034'].location = sum([o.matrix_world.translation for o in obs], Vector()) / n + if record_bool == True: + bpy.data.objects["Point."+str(1000+34)[1:]].keyframe_insert(data_path="location", frame=self._frame) + if i == 24: + # middle_point('Point.023','Point.024','Point.035') + bpy.ops.object.select_all(action='DESELECT') + bpy.data.objects['Point.023'].select_set(True) + bpy.data.objects['Point.024'].select_set(True) + bpy.context.view_layer.objects.active = bpy.data.objects['Point.024'] + obs = bpy.context.selected_objects + n = len(obs) + assert(n) + bpy.data.objects['Point.035'].location = sum([o.matrix_world.translation for o in obs], Vector()) / n + if record_bool == True: + bpy.data.objects["Point."+str(1000+35)[1:]].keyframe_insert(data_path="location", frame=self._frame) + if record_bool == True: + bpy.data.objects["Point."+str(1000+i)[1:]].keyframe_insert(data_path="location", frame=self._frame) + self._frame = self._frame + 1 + + #end connection code + return {'PASS_THROUGH'} + + def execute(self, context): + import socket + import bpy + + refresh_rate = context.scene.sk_value_prop.sk_refresh_rate + self._frame = context.scene.sk_value_prop.sk_record_frame_start + + + self._s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self._s.connect((socket.gethostname(), 1234)) #gethostname is the local address, + + name_points = 'Point' + + #=========== + # selectign Scene Collection + + multiplier = 0.9 + + scene_collection = bpy.context.view_layer.layer_collection + bpy.context.view_layer.active_layer_collection = scene_collection + + wm = context.window_manager + # self._timer = wm.event_timer_add(0.1, window=context.window) + self._timer = wm.event_timer_add(refresh_rate, window=context.window) + + wm.modal_handler_add(self) + print('MODAL!!!!!!!!!!!!!!!') + return {'RUNNING_MODAL'} + + def cancel(self, context): + wm = context.window_manager + wm.event_timer_remove(self._timer) + + +class Reload_sk_Mediapipe(Operator): + + bl_idname = "mocap.import_mediapipe_reload" + bl_label = "Reload Skeleton Easymocap" + bl_description = "Reload SK EasyMOCAP" + + def execute(self,context): + + bpy.ops.object.mode_set(mode='OBJECT') + multiplier = context.scene.sk_value_prop.sk_value + + + + unit = skeleton_import.size_ref_bone('Point.001','Point.008','Point.008') + unit = unit*multiplier + + spine_multi = context.scene.sk_value_prop.sk_spine_mulitplier + neck_multi = context.scene.sk_value_prop.sk_neck_mulitplier + head_multi = context.scene.sk_value_prop.sk_head_mulitplier + + forearm_multi = context.scene.sk_value_prop.sk_forearm_mulitplier + arm_multi = context.scene.sk_value_prop.sk_arm_mulitplier + + tigh_multi = context.scene.sk_value_prop.sk_tigh_mulitplier + leg_multi = context.scene.sk_value_prop.sk_leg_mulitplier + foot_multi = context.scene.sk_value_prop.sk_foot_mulitplier + + root_sz =unit/10 + spine_sz =unit*3.5*spine_multi + neck_sz =unit*neck_multi + face_sz =unit*head_multi + thigh_sz =unit*3*tigh_multi + leg_sz =unit*2.5*leg_multi + foot_sz =unit*foot_multi #inclinado 45 graud pra frente + arm_sz =unit*1.5*arm_multi + forearm_sz =unit*1.5*forearm_multi + + skeleton_import.size_of_bones(unit, root_sz, spine_sz, neck_sz, face_sz, thigh_sz, leg_sz, foot_sz, arm_sz, forearm_sz) return{'FINISHED'} \ No newline at end of file diff --git a/mediapipe_py_server.py b/mediapipe_py_server.py new file mode 100644 index 0000000..a53f972 --- /dev/null +++ b/mediapipe_py_server.py @@ -0,0 +1,97 @@ +import cv2 +import mediapipe as mp +mp_drawing = mp.solutions.drawing_utils +mp_holistic = mp.solutions.holistic + +#Creating the connection to send the data +import socket +import pickle +import json + +HEADERSIZE = 10 +s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #ipv4 and TCP +s.bind((socket.gethostname(), 1234)) +s.listen(5) + +clientsocket, address = s.accept() +print(f"Connection from {address} has ben estabilished!") + +# For webcam input: +cap = cv2.VideoCapture(0) +with mp_holistic.Holistic( + min_detection_confidence=0.5, + min_tracking_confidence=0.5) as holistic: + while cap.isOpened(): + success, image = cap.read() + if not success: + print("Ignoring empty camera frame.") + # If loading a video, use 'break' instead of 'continue'. + continue + + # Flip the image horizontally for a later selfie-view display, and convert + # the BGR image to RGB. + image = cv2.cvtColor(cv2.flip(image, 1), cv2.COLOR_BGR2RGB) + # To improve performance, optionally mark the image as not writeable to + # pass by reference. + image.flags.writeable = False + results = holistic.process(image) + + # Draw landmark annotation on the image. + image.flags.writeable = True + image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR) + mp_drawing.draw_landmarks( + image, results.face_landmarks, mp_holistic.FACE_CONNECTIONS) + mp_drawing.draw_landmarks( + image, results.left_hand_landmarks, mp_holistic.HAND_CONNECTIONS) + mp_drawing.draw_landmarks( + image, results.right_hand_landmarks, mp_holistic.HAND_CONNECTIONS) + mp_drawing.draw_landmarks( + image, results.pose_landmarks, mp_holistic.POSE_CONNECTIONS) + cv2.imshow('MediaPipe Holistic', image) + + + + #preparing and sending the data + + + # clientsocket, address = s.accept() + # print(f"Connection from {address} has ben estabilished!") + # print(results.pose_landmarks) + # d = results.pose_landmarks + # msg = pickle.dumps(d) + pose='' + + try: + pose=results.pose_landmarks.landmark + except: + pose='' + + #creating serialized variable to convert to json + if isinstance(pose,str): + msg = json.dumps('nada') + else: + pose_serialize=[] + for i in range(len(pose)): + x=pose[i].x + y=pose[i].y + z=pose[i].z + pose_serialize.append([i,x,y,z]) + + msg = json.dumps(pose_serialize) + + + + + # print(msg) + print('len: ',len(msg)) + print('len encode: ',len(msg.encode('utf-8'))) + # while True: + msg = bytes(f'{len(msg):<{HEADERSIZE}}', "utf-8") + msg.encode('utf-8') + clientsocket.send(msg) + # #finish sending data + + # clientsocket.sendall(msg.encode('utf-8')) + + if cv2.waitKey(5) & 0xFF == 27: + break +cap.release() \ No newline at end of file diff --git a/test_panel.py b/test_panel.py index 62bbd5a..edb5b65 100644 --- a/test_panel.py +++ b/test_panel.py @@ -2,9 +2,9 @@ class Test_PT_Panel(bpy.types.Panel): - bl_idname = "MOCAP_IMPORT_PT_Panel" - bl_label = "MOCAP PE Import Data" - bl_category = "MOCAP" + bl_idname = "MOCAP_IMPORT_PT_Panel_ALPHA" + bl_label = "MOCAP PE Import Data ALPHA" + bl_category = "MOCAP_ALPHA" bl_space_type = "VIEW_3D" bl_region_type = "UI" @@ -15,78 +15,75 @@ def draw(self, context): sk_value_prop = context.scene.sk_value_prop # percent_render_var = sk_value_prop.sk_value - row = layout.row() - row.prop(sk_value_prop, "sk_raw_bool", text="Raw Import") - row = layout.row() - row.prop(sk_value_prop, "sk_constraint_limit_rotation_bool", text="Constraint Limit Rotation") - - row = layout.row() - row.prop(sk_value_prop, "sk_debug_bool", text="Debug") - + # row = layout.row() + # row.prop(sk_value_prop, "sk_raw_bool", text="Raw Import") + # row = layout.row() + # row.operator('mocap.import_easymocap', text="Import EasyMOCAP") row = layout.row() - row.operator('mocap.import_easymocap', text="Import EasyMOCAP") - row.operator('mocap.import_easymocap_reload', text="Reload Skeleton") - row = layout.row() - row.label(text='----------') - row = layout.row() - row.operator('mocap.import_smpl_easymocap', text="Import SMPL EasyMOCAP") - row = layout.row() - row.prop(sk_value_prop, "sk_smpl_path") + row.prop(sk_value_prop, "sk_record_bool", text="Record Realtime") row = layout.row() - row.operator('mocap.browse_smpl_file', text="Browse SMPL FBX File") + row.prop(sk_value_prop, "sk_record_frame_start", text="Frame to start Recording") + row = layout.row() - row.label(text='----------') - + row.operator('mocap.mediapipe_prepare_sk_rt', text="Prepare MP Skeleton for RT") layout.row().separator() + + layout.prop(sk_value_prop, "sk_value", text="SK Mult") - row = layout.row() - row.operator('mocap.import_frankmocap', text="SK Import FrankMocap") - + layout.operator('mocap.import_mediapipe_reload', text="Reload MP Skeleton for RT") + # row = layout.row() + # row.operator('mocap.import_frankmocap', text="SK Import FrankMocap") + # row = layout.row() + # row.operator('mocap.import_vibe', text="SK Import VIBE") + + # row = layout.row() + # row.operator('mocap.mediapipe_pose', text="SK Generate Mocap (MediaPipe)") + # layout.row().separator() layout.row().separator() + row = layout.row() - row.operator('mocap.import_vibe', text="SK Import VIBE") - row = layout.row() - row.prop(sk_value_prop, "vibe_person_id", text="Vibe Person ID") + row.operator('mocap.mediapipe_pose_rt', text="MediaPipe Real Time") layout.row().separator() - row = layout.row() - row.operator('mocap.mediapipe_pose', text="SK Generate Mocap (MediaPipe)") - layout.row().separator() + row.prop(sk_value_prop, "sk_socket_buffer", text="Buffer") + row = layout.row() + row.prop(sk_value_prop, "sk_refresh_rate", text="Refresh Rate") + # Create two columns, by using a split layout. - split = layout.split() + # split = layout.split() - # First column - col = split.column() - # col.label(text="Column One:") - # layout.label(text='Original angles') - # layout.label(text='x: '+ '%.2f' %sk_value_prop.sk_root_rot_x) - # layout.label(text='y: '+ '%.2f' %sk_value_prop.sk_root_rot_y) - # layout.label(text='z: '+ '%.2f' %sk_value_prop.sk_root_rot_z) + # # First column + # col = split.column() + # # col.label(text="Column One:") + # # layout.label(text='Original angles') + # # layout.label(text='x: '+ '%.2f' %sk_value_prop.sk_root_rot_x) + # # layout.label(text='y: '+ '%.2f' %sk_value_prop.sk_root_rot_y) + # # layout.label(text='z: '+ '%.2f' %sk_value_prop.sk_root_rot_z) - col.label(text='Original angles') - col.label(text='x: '+ '%.2f' %sk_value_prop.sk_root_rot_x) - col.label(text='y: '+ '%.2f' %sk_value_prop.sk_root_rot_y) - col.label(text='z: '+ '%.2f' %sk_value_prop.sk_root_rot_z) + # col.label(text='Original angles') + # col.label(text='x: '+ '%.2f' %sk_value_prop.sk_root_rot_x) + # col.label(text='y: '+ '%.2f' %sk_value_prop.sk_root_rot_y) + # col.label(text='z: '+ '%.2f' %sk_value_prop.sk_root_rot_z) - # Second column, aligned - col = split.column(align=True) - col.label(text="Actual Angle:") - col.label(text='x: '+ '%.2f' %sk_value_prop.sk_root_actual_rot_x) - col.label(text='y: '+ '%.2f' %sk_value_prop.sk_root_actual_rot_y) - col.label(text='z: '+ '%.2f' %sk_value_prop.sk_root_actual_rot_z) + # # Second column, aligned + # col = split.column(align=True) + # col.label(text="Actual Angle:") + # col.label(text='x: '+ '%.2f' %sk_value_prop.sk_root_actual_rot_x) + # col.label(text='y: '+ '%.2f' %sk_value_prop.sk_root_actual_rot_y) + # col.label(text='z: '+ '%.2f' %sk_value_prop.sk_root_actual_rot_z) class Modify_PT_Panel(bpy.types.Panel): - bl_idname = "MODIFY_PT_Panel" - bl_label = "Modify Data" - bl_category = "MOCAP" + bl_idname = "MODIFY_PT_Panel_ALPHA" + bl_label = "Modify Data ALPHA" + bl_category = "MOCAP_ALPHA" bl_space_type = "VIEW_3D" bl_region_type = "UI" @@ -99,51 +96,51 @@ def draw(self, context): layout.label(text=" Convert axis") row = layout.row() - row.prop(sk_value_prop, "sk_from_axis", text="From") - row.prop(sk_value_prop, "sk_to_axis", text="To") - row = layout.row() - row.operator('mocap.convert_axis', text='Convert') - row = layout.row() - row.label(text='----------') - row = layout.row() - row.operator('mocap.reset_location', text='Reset loc') - row.operator('mocap.reset_rotation', text='Reset rot') - row.operator('mocap.foot_high', text='Foot') + # row.prop(sk_value_prop, "sk_from_axis", text="From") + # row.prop(sk_value_prop, "sk_to_axis", text="To") + # row = layout.row() + # row.operator('mocap.convert_axis', text='Convert') + # row = layout.row() + # row.label(text='----------') + # row = layout.row() + # row.operator('mocap.reset_location', text='Reset loc') + # row.operator('mocap.reset_rotation', text='Reset rot') + # row.operator('mocap.foot_high', text='Foot') # row = layout.row() # row.operator('mocap.smooth_bones', text='Smooth Curves') - row = layout.row() - row.label(text='----------') - row = layout.row() - row.label(text='Compensate Rotation') - row = layout.row() - row.prop(sk_value_prop, "sk_rot_compens_x", text="x") - row.prop(sk_value_prop, "sk_rot_compens_y", text="y") - row.prop(sk_value_prop, "sk_rot_compens_z", text="z") - row = layout.row() - row.operator('mocap.compensate_rotation', text='Rotate') + # row = layout.row() + # row.label(text='----------') + # row = layout.row() + # row.label(text='Compensate Rotation') + # row = layout.row() + # row.prop(sk_value_prop, "sk_rot_compens_x", text="x") + # row.prop(sk_value_prop, "sk_rot_compens_y", text="y") + # row.prop(sk_value_prop, "sk_rot_compens_z", text="z") + # row = layout.row() + # row.operator('mocap.compensate_rotation', text='Rotate') class Install_PT_Panel(bpy.types.Panel): - bl_idname = "INSTALL_PT_Panel" - bl_label = "Install PyPacks" - bl_category = "MOCAP" + bl_idname = "INSTALL_PT_Panel_ALPHA" + bl_label = "Install PyPacks ALPHA" + bl_category = "MOCAP_ALPHA" bl_space_type = "VIEW_3D" bl_region_type = "UI" def draw(self, context): layout = self.layout - + row = layout.row() row.operator('install.mediapipe_package', text="Install python Mediapipe Package") row = layout.row() row.operator('install.joblib_package', text="Install Joblib (Vibe requirement)") class Debug_PT_Panel(bpy.types.Panel): - bl_idname = "Debug_PT_Panel" + bl_idname = "Debug_PT_Panel_ALPHA" bl_label = "Debug Panel" - bl_category = "MOCAP" + bl_category = "MOCAP_ALPHA" bl_space_type = "VIEW_3D" bl_region_type = "UI" @@ -184,7 +181,7 @@ def draw(self, context): BoolProperty, IntProperty, FloatProperty, -# FloatVectorProperty, + # FloatVectorProperty, EnumProperty, # PointerProperty, ) @@ -203,7 +200,7 @@ class MySettings(PropertyGroup): sk_rot_compens_z: IntProperty(name="Rotation_compensate_z", description="Value to compensate Roation Z", default=0) sk_rot_original: StringProperty(name="rotation", description="rotation") - + sk_root_rot_x: FloatProperty(name="original rotation x", description="original rotation of root bone x") sk_root_rot_y: FloatProperty(name="original rotation y", description="original rotation of root bone y") sk_root_rot_z: FloatProperty(name="original rotation z", description="original rotation of root bone z") @@ -213,25 +210,6 @@ class MySettings(PropertyGroup): sk_root_actual_rot_z: FloatProperty(name="Actual rotation z", description="Actual rotation of root bone z") sk_raw_bool: BoolProperty(name='raw_bool', default=False) - sk_debug_bool: BoolProperty(name='debug_bool', default=False) - # sk_reload_skeleton_bool: BoolProperty(name='Reload_skeleton_bool', default=False) - sk_constraint_limit_rotation_bool: BoolProperty(name='Limit_rotation_bool', default=True) - - vibe_person_id: IntProperty(name="Vibe Person ID", description="Person to import pose estimation", default=1) - ############ - sk_spine_mulitplier: FloatProperty(name="Spine size multiplier", description="Ajust the Spine size", default=1) - sk_neck_mulitplier: FloatProperty(name="Neck size multiplier", description="Ajust the Neck size", default=1) - sk_head_mulitplier: FloatProperty(name="Head size multiplier", description="Ajust the Head size", default=1) - - sk_forearm_mulitplier: FloatProperty(name="Forearm size multiplier", description="Ajust the Forearm size", default=1) - sk_arm_mulitplier: FloatProperty(name="Arm size multiplier", description="Ajust the Arm size", default=1) - - sk_tigh_mulitplier: FloatProperty(name="Thigh size multiplier", description="Ajust the Thigh size", default=1) - sk_leg_mulitplier: FloatProperty(name="Leg size multiplier", description="Ajust the Leg size", default=1) - sk_foot_mulitplier: FloatProperty(name="Foot size multiplier", description="Ajust the Foot size", default=1) - - sk_smpl_path: StringProperty(name="Path to SMPL FBX file", description="Path to SMPL FBX file") - sk_from_axis: EnumProperty( name= "From Axis", description="From specific axis of animation", @@ -251,3 +229,20 @@ class MySettings(PropertyGroup): default = 'to_z' ) + sk_spine_mulitplier: FloatProperty(name="Spine size multiplier", description="Ajust the Spine size", default=1) + sk_neck_mulitplier: FloatProperty(name="Neck size multiplier", description="Ajust the Neck size", default=1) + sk_head_mulitplier: FloatProperty(name="Head size multiplier", description="Ajust the Head size", default=1) + + sk_forearm_mulitplier: FloatProperty(name="Forearm size multiplier", description="Ajust the Forearm size", default=1) + sk_arm_mulitplier: FloatProperty(name="Arm size multiplier", description="Ajust the Arm size", default=1) + + sk_tigh_mulitplier: FloatProperty(name="Thigh size multiplier", description="Ajust the Thigh size", default=1) + sk_leg_mulitplier: FloatProperty(name="Leg size multiplier", description="Ajust the Leg size", default=1) + sk_foot_mulitplier: FloatProperty(name="Foot size multiplier", description="Ajust the Foot size", default=1) + + + sk_socket_buffer: IntProperty(name="Socket buffer", description="Socket buffer value", default=1024) + sk_refresh_rate: FloatProperty(name="Refresh_rate", description="Value of refresh rate", default=0.1) + + sk_record_bool: BoolProperty(name='record_bool', default=False) + sk_record_frame_start: IntProperty(name='Frame to start recording',description="Frame to start recording", default=1)