Skip to content
Snippets Groups Projects
Commit 7a327ffb authored by Romain Guesdon's avatar Romain Guesdon
Browse files

Fix human switch

parent c75f2718
No related branches found
No related tags found
No related merge requests found
......@@ -73,11 +73,11 @@ cars = []
for src_path, name in {
r"car_models\suv_car\car.blend": 'SUV',
# r"car_models\red_car\red.blend": 'Red',
# r"car_models\pickup_car\pickup.blend": 'PickUp',
# r"car_models\family_car\family_car.blend": 'Family',
# r"car_models\coupe_car\coupe_car.blend": 'Coupe',
# r"car_models\truck\truck_open.blend": 'Truck',
r"car_models\red_car\red.blend": 'Red',
r"car_models\pickup_car\pickup.blend": 'PickUp',
r"car_models\family_car\family_car.blend": 'Family',
r"car_models\coupe_car\coupe_car.blend": 'Coupe',
r"car_models\truck\truck_open.blend": 'Truck',
}.items():
with D.libraries.load(abs_path(src_path)) as (data_from, data_to):
......@@ -152,7 +152,7 @@ light_params = {
},
'night': {
'energy_bounds': (5, 15),
'back_color_bounds': (0.05, 0.15),
'back_color_bounds': (0.1, 0.15),
'sun_color': (1, 0.5, 0.2)
}
......@@ -194,7 +194,7 @@ if not CONTINUE or not os.path.isfile(info_path):
frame_rate = 25
nb_scene = 1
nb_pose = 10
nb_pose = 30
human_loader.max_len = min(human_loader.max_len, nb_scene)
ratio_conf_man = int(nb_scene / len(human_loader.human_paths))
if CONTINUE:
......@@ -302,7 +302,8 @@ for sc in range(nb_scene):
bpy.ops.object.mode_set(mode='OBJECT')
# set output path so render won't get overwritten
C.scene.render.filepath = os.path.join(fp_img, f"{file_root_name}_{po}" + f'_drive' if use_targets else '')
C.scene.render.filepath = os.path.join(fp_img,
f"{file_root_name}_{po}" + (f'_drive' if use_targets else ''))
bpy.ops.render.render(write_still=True) # render still
annotations_2D = []
......
......@@ -234,11 +234,11 @@ def set_shrinkwraps(model, car=None):
class HumanLoader:
def __init__(self, dir_path, max_len=10):
self.human_paths = glob.glob(os.path.join(dir_path, '*.fbx'))
# random.shuffle(self.human_paths)
random.shuffle(self.human_paths)
self.paths = {}
self.humans = {}
self.max_len = max_len
self.start_idx = 0
self.start_loaded = 0
self.current_idx = -1
self.collection = D.collections.new("Humans")
......@@ -250,16 +250,16 @@ class HumanLoader:
def load_next(self):
if self.max_len >= len(self.human_paths):
# If asked too much
self.start_idx = 0
self.start_loaded = 0
if len(self.paths) == len(self.human_paths):
# If everything already loaded
return
else:
next_idx = len(self.human_paths)
end_loaded = len(self.human_paths)
else:
next_idx = self.start_idx + self.max_len
end_loaded = self.start_loaded + self.max_len
human_paths = (self.human_paths * 2)[self.start_idx:next_idx]
human_paths = (self.human_paths * 2)[self.start_loaded:end_loaded]
human_paths = list({k: None for k in human_paths})
already_loaded = [hp for hp in human_paths if hp in self.paths.values()]
......@@ -277,12 +277,11 @@ class HumanLoader:
self.humans[human_path] = Human(model)
self.picker = utils.Randomizer(list(self.humans.values()))
self.start_idx = next_idx % len(self.human_paths)
self.start_loaded = end_loaded % len(self.human_paths)
def next(self, *args, **kwargs):
self.current_idx += 1
if not self.current_idx % self.max_len:
self.start_idx = self.current_idx
self.load_next()
self.current_idx = 0
return self.picker.get(self.current_idx, *args, **kwargs)
......@@ -301,7 +300,8 @@ class HumanLoader:
def clear_humans(exceptions=[]):
collection = D.collections["Humans"]
exceptions = exceptions + [obj.children_recursive for obj in exceptions]
exceptions = exceptions + [ch for obj in exceptions for ch in obj.children_recursive]
for obj in collection.objects:
if obj in exceptions:
continue
......
......@@ -95,9 +95,8 @@ def hand_pose(pose, side, grasp=None):
hand_ratio = random.uniform(0.5, 0.8)
elif grasp is False:
hand_ratio = random.uniform(0.05, 0.15)
print(grasp)
print(hand_ratio)
else:
hand_ratio = 0
for finger in ['thumb', 'index', 'middle', 'ring', 'pinky']:
angles = r([40, 40, 40]) if finger == 'thumb' else r([70, 90, 40])
......@@ -157,7 +156,7 @@ def random_pose_ik(subject, auto_ik=False, targets=None):
else:
pose.bones['spine_03'].rotation_euler = get_angles([[5, 20], 15, None])
pose.bones['neck_01'].rotation_euler = get_angles(bounds_vals['neck_01'])
pose.bones['neck_01'].rotation_euler = get_angles([[5, 25], 0, 10])
pose.use_auto_ik = auto_ik
......@@ -215,7 +214,6 @@ def random_pose_ik(subject, auto_ik=False, targets=None):
pose.bones[f'hand_{s}_IK'].rotation_euler = Vector((0, 0, 0))
pose.bones[f'hand_{s}_IK'].rotation_euler = (
((matrix_world @ pose.bones[f'hand_{s}_IK'].matrix).inverted() @ target.matrix_world).to_euler())
print("_close" in target.name)
hand_pose(pose, side=s, grasp="_close" in target.name)
target = target.location
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment