diff --git a/base.blend b/base.blend index 4505bfe11ded5ec9aee7c8e504b0416814fc9dc9..1e3da18215a760e4e6828771d8a03f56f4ea9fd7 100644 Binary files a/base.blend and b/base.blend differ diff --git a/global_script.py b/global_script.py index 62edad87533ce6a16ed29ac7d23622a24d256b3e..ebed668b617a09f8d5c395685c889cbcc3d23546 100644 --- a/global_script.py +++ b/global_script.py @@ -111,6 +111,7 @@ def main(): camera_object = D.objects.new('Camera', camera_data) C.scene.collection.objects.link(camera_object) + camera_object.rotation_mode = 'XYZ' # camera_object.location = [-.97, -0.24, 0.68] camera_object.location = [-.97, -0.1, 0.68] @@ -207,6 +208,7 @@ def main(): nb_pose = 1 human_loader.max_len = min(human_loader.max_len, nb_scene) ratio_conf_man = int(nb_scene / len(human_loader.human_paths)) + C.scene.frame_end = int(frame_rate * (nb_pose - 0.5)) if CONTINUE: try: @@ -223,7 +225,6 @@ def main(): car = car_picker() car_targets = {side: [ch for ch in car.children if f'Target_{side.upper()}' in ch.name] for side in 'lr'} nb_targets = len(car_targets['l']) * len(car_targets['r']) - print(nb_targets) # Random personne if ratio_conf_man < 1: if not sc % 10: @@ -289,12 +290,13 @@ def main(): json.dump(previous_cameras, f_cam, indent=4) man.animation_data_clear() - # Exemple: 150k / 200 / 2 = 1500 poses with open(os.path.join(fp_ann_2D, f'annotations_{file_root_name}.csv'), 'w') as annot_file_2D, \ open(os.path.join(fp_ann_3D, f'annotations_{file_root_name}.csv'), 'w') as annot_file_3D: bone_lbls = list(man.pose.bones.keys()) - bone_lbls = [lbl for bone in bone_lbls for lbl in [bone + k for k in ['_head', '_tail']]] + bone_lbls = [ + lbl for bone in bone_lbls for lbl in [bone + k for k in ['_head', '_tail']] if '_IK' not in lbl + ] face_lbls = ['nose', 'eye_l', 'eye_r', 'ear_l', 'ear_r'] # full_lbls = [lbl for lbl in bone_lbls if lbl not in face_lbls] + face_lbls full_lbls = bone_lbls + face_lbls @@ -313,10 +315,8 @@ def main(): if nb_pose < nb_targets or not use_targets: id_targets = None else: - print(po, nb_pose - po - 1) id_targets = {'l': (nb_pose - po - 1) % len(car_targets['l']), 'r': (nb_pose - po - 1) // len(car_targets['l'])} - print(id_targets) random_pose.random_pose_ik(man, targets=car_targets if use_targets else None, id_targets=id_targets) bpy.ops.object.mode_set(mode='OBJECT') @@ -370,7 +370,6 @@ def main(): if sc * nb_pose % 4000 == 3999: time.sleep(150) - C.scene.frame_end = int(frame_rate * (nb_pose - 0.5)) utils.select_only(man) bpy.ops.object.mode_set(mode='POSE') diff --git a/scripts/camera_proj.py b/scripts/camera_proj.py index 3f7b7a604e139dfd62804be6ac9ab101b7934cc8..8e8192457cd2bd1a8da5e6f0f0693f394c76b1ee 100644 --- a/scripts/camera_proj.py +++ b/scripts/camera_proj.py @@ -113,6 +113,7 @@ def get_3x4_RT_matrix_from_blender(cam): def get_3x4_P_matrix_from_blender(cam): + bpy.context.view_layer.update() K = get_calibration_matrix_K_from_blender(cam.data) RT = get_3x4_RT_matrix_from_blender(cam) return K @ RT, K, RT diff --git a/scripts/human.py b/scripts/human.py index 2bff41347aefa0d99f28d9f7a243c9a4bd15e3e8..a369438c21146e43f9982d52e8eb76eed452c224 100644 --- a/scripts/human.py +++ b/scripts/human.py @@ -218,7 +218,7 @@ def get_face(model): face_3D = {} for marker in ['nose', 'eye_l', 'eye_r', 'ear_l', 'ear_r']: if 'eye' in marker: - marker_loc = model.pose.bones[marker].head * 0.75 + model.pose.bones[marker].tail * 0.25 + marker_loc = model.pose.bones[marker].head * 0.65 + model.pose.bones[marker].tail * 0.35 else: marker_loc = model.pose.bones[marker].tail face_3D[marker] = matrix_world @ marker_loc diff --git a/scripts/random_pose.py b/scripts/random_pose.py index 384a48570ab6654bfff5ccc511cb6f45fed6c06a..8d85aa0a43ac4cb068046b40034a6316a0ec288a 100644 --- a/scripts/random_pose.py +++ b/scripts/random_pose.py @@ -58,25 +58,19 @@ def get_angles(angs): return Vector(r(new_angs)) -def reset_subject_old(subject): - bpy.ops.object.mode_set(mode='OBJECT') - subject.scale = (0.01, 0.01, 0.01) - subject.location = [-0.15, 0.5, 0.08] - subject.rotation_euler = r([-18, 0, 0]) - - bpy.ops.object.mode_set(mode='POSE') - for bone in subject.pose.bones: - bone.location = (0, 0, 0) - bone.rotation_euler = (0, 0, 0) - - def reset_subject(subject): bpy.ops.object.mode_set(mode='POSE') + subject.location = [0, 0, 0] + subject.rotation_euler = [0, 0, 0] + for bone in subject.pose.bones: bone.rotation_mode = 'XYZ' if bone.name in ["Root", "pelvis"]: continue - bone.location = (0, 0, 0) + if '_IK' in bone.name: + bone.location = (0, 1.2, 0.25) + else: + bone.location = (0, 0, 0) bone.rotation_euler = (0, 0, 0) bpy.ops.object.mode_set(mode='OBJECT') @@ -88,11 +82,10 @@ def reset_subject(subject): # subject.location = [0, -0.16, -0.5 * 1.66] # subject.location = [0, -0.16, -0.5 * height] # subject.rotation_euler = r([65, 0, 0]) - subject.scale = [1.] * 3 - height = subject.dimensions.z - print(height) - subject.location = [0, -0.05, -0.5 * height + 0.03] - subject.rotation_euler = r([-15, 0, 0]) + subject.scale = [0.9] * 3 + sit_height = utils.get_head_pose('pelvis', subject).z * 0.88 + subject.location = [0, -0.04, - sit_height] + subject.rotation_euler = r([-16, 0, 0]) def hand_pose(pose, side, grasp=None): diff --git a/scripts/utils.py b/scripts/utils.py index 24521248de1383c1abe1b24dc492902c171f7733..78a90ab7007a4a7c8b53e410618b4acc944bf298 100644 --- a/scripts/utils.py +++ b/scripts/utils.py @@ -94,7 +94,7 @@ def select_only_edit_bone(armature, bone=None): armature.edit_bones.active = bone -def get_bone_pose(bone, struct, side): +def _get_bone_pose(bone, struct, side): if isinstance(struct, str): struct = get_object(struct) @@ -111,11 +111,11 @@ def get_bone_pose(bone, struct, side): def get_head_pose(bone, struct='Subject'): - return get_bone_pose(bone, struct, side='head') + return _get_bone_pose(bone, struct, side='head') def get_tail_pose(bone, struct='Subject'): - return get_bone_pose(bone, struct, side='tail') + return _get_bone_pose(bone, struct, side='tail') # Other utils