commands.append({ "$type": "rotate_object_by", "angle": random.uniform(-15, 15), "id": toy_id, "axis": axis, "is_world": False }) # Apply a force. commands.append({ "$type": "apply_force_magnitude_to_object", "magnitude": random.uniform(20, 40), "id": toy_id }) return commands def get_per_frame_commands(self, resp: List[bytes], frame: int) -> List[dict]: return [] def is_done(self, resp: List[bytes], frame: int) -> bool: return frame >= 500 if __name__ == "__main__": args = get_args("bouncing") Bouncing().run(num=args.num, output_dir=args.dir, temp_path=args.temp, width=args.width, height=args.height)
:return: A list of commands to teleport the avatar and rotate the sensor container. """ return [{ "$type": "teleport_avatar_to", "position": a_pos }, { "$type": "look_at_position", "position": cam_aim }, { "$type": "set_focus_distance", "focus_distance": TDWUtils.get_distance(a_pos, cam_aim) }, { "$type": "rotate_sensor_container_by", "axis": "pitch", "angle": random.uniform(-3, 3) }, { "$type": "rotate_sensor_container_by", "axis": "yaw", "angle": random.uniform(-3, 3) }] if __name__ == "__main__": args = get_args("squishing") Squishing().run(num=args.num, output_dir=args.dir, temp_path=args.temp, width=args.width, height=args.height)
"id": self._occ_id}, {"$type": "set_object_collision_detection_mode", "mode": "continuous_speculative", "id": self._occ_id}, {"$type": "set_kinematic_state", "id": self._occ_id, "is_kinematic": True, "use_gravity": False}]) # Reset the avatar. occ_y = occ_record.bounds["top"]["y"] * s_occ commands.extend([{"$type": "teleport_avatar_to", "position": {"x": random.uniform(-0.05, 0.05), "y": random.uniform(occ_y * 0.3, occ_y * 0.8), "z": random.uniform(-1.5, -1.8)}}, {"$type": "look_at", "object_id": self._occ_id, "use_centroid": True}, {"$type": "rotate_sensor_container_by", "axis": "pitch", "angle": random.uniform(-5, 5)}, {"$type": "rotate_sensor_container_by", "axis": "yaw", "angle": random.uniform(-5, 5)}]) return commands if __name__ == "__main__": args = get_args("permanence") td = Permanence() td.run(num=args.num, output_dir=args.dir, temp_path=args.temp, width=args.width, height=args.height)
# Set a random color. # Scale the object. commands.extend([{ "$type": "set_color", "color": { "r": random.random(), "g": random.random(), "b": random.random(), "a": 1.0 }, "id": o_id }, { "$type": "scale_object", "id": o_id, "scale_factor": { "x": scale, "y": scale, "z": scale } }]) return commands if __name__ == "__main__": args = get_args("stability") Stability().run(num=args.num, output_dir=args.dir, temp_path=args.temp, width=args.width, height=args.height)
if np.abs(np.linalg.norm(p[:-1] - self._corner) ) <= self._corner_radius: # Calculate the force. pos = np.array(p[:-1]) force = ((pos - self._corner) / np.linalg.norm(pos - self._corner)) * self.\ _force_per_frame # Add the force and particle ID. forces.extend(force) forces.append(p_id) p_id += 1 # Encode and send the force. commands.extend([{ "$type": "apply_forces_to_flex_object_base64", "forces_and_ids_base64": TDWUtils.get_base64_flex_particle_forces( forces), "id": self.cloth_id }]) return commands if __name__ == "__main__": args = get_args("dragging") Dragging().run(num=args.num, output_dir=args.dir, temp_path=args.temp, width=args.width, height=args.height)
"y": 2.0, "z": -1.6 }, rotation=rotation, o_id=self.cloth_id, mass_scale=1, mesh_tesselation=1, tether_stiffness=uniform(0.5, 1.0), bend_stiffness=uniform(0.5, 1.0), stretch_stiffness=uniform(0.5, 1.0))) return trial_commands def get_per_frame_commands(self, resp: List[bytes], frame: int) -> List[dict]: return [{"$type": "focus_on_object", "object_id": self.cloth_id}] if __name__ == "__main__": args = get_args("draping") Draping().run(num=args.num, output_dir=args.dir, temp_path=args.temp, width=args.width, height=args.height, write_passes=args.write_passes.split(','), save_passes=args.save_passes.split(','), save_movies=args.save_movies, save_labels=args.save_labels, args_dict=vars(args))
"w": 1, "x": 0, "y": 0, "z": 0 }, "id": container_id }]) self._max_num_frames = len(self._shake_commands) + 500 return commands def get_per_frame_commands(self, resp: List[bytes], frame: int) -> List[dict]: # Send the next list of shake commands. if len(self._shake_commands) > 0: return self._shake_commands.pop(0) else: return [] def is_done(self, resp: List[bytes], frame: int) -> bool: return frame > self._max_num_frames if __name__ == "__main__": args = get_args("containment") Containment().run(num=args.num, output_dir=args.dir, temp_path=args.temp, width=args.width, height=args.height)
return [{ "$type": "focus_on_object", "object_id": self._ball_id, "use_centroid": True }] def get_field_of_view(self) -> float: return 68 def is_done(self, resp: List[bytes], frame: int) -> bool: for r in resp[:-1]: r_id = OutputData.get_data_type_id(r) # If the ball reaches or overshoots the destination, the trial is done. if r_id == "tran": t = Transforms(r) d0 = TDWUtils.get_distance( TDWUtils.array_to_vector3(t.get_position(0)), self._p0) d1 = TDWUtils.get_distance(self._p0, self._p1) return d0 > d1 * 1.5 return False if __name__ == "__main__": args = get_args("shadows") td = Shadows() td.run(num=args.num, output_dir=args.dir, temp_path=args.temp, width=args.width, height=args.height)
""" o_pos = TDWUtils.array_to_vector3( TDWUtils.get_random_point_in_circle(center=np.array([0, 0, 0]), radius=radius)) # Pick a position away from other objects. ok = False count = 0 while not ok and count < max_tries: count += 1 ok = True for o in object_positions: # If the object is too close to another object, try another position. if TDWUtils.get_distance(o.position, o_pos) <= o.radius: ok = False o_pos = TDWUtils.array_to_vector3( TDWUtils.get_random_point_in_circle(center=np.array( [0, 0, 0]), radius=radius)) return o_pos if __name__ == "__main__": args = get_args("toy_collisions") td = ToysDataset() td.run(num=args.num, output_dir=args.dir, temp_path=args.temp, width=args.width, height=args.height)
a_r = random.uniform(2.1, 3) d_theta = random.uniform(0.5, 3) a_y = random.uniform(0.4, 0.9) for theta in np.arange(0, 360, d_theta): self.per_frame_commands.append([{"$type": "teleport_avatar_to", "position": {"x": np.cos(np.radians(theta)) * a_r, "y": a_y, "z": np.sin(np.radians(theta)) * a_r}}, {"$type": "look_at", "object_id": big_id, "use_centroid": True}, {"$type": "focus_on_object", "object_id": big_id, "use_centroid": True}]) commands.extend(self.per_frame_commands.pop(0)) return commands def is_done(self, resp: List[bytes], frame: int) -> bool: return len(self.per_frame_commands) == 0 def get_per_frame_commands(self, resp: List[bytes], frame: int) -> List[dict]: return self.per_frame_commands.pop(0) if __name__ == "__main__": args = get_args("occlusion") Occlusion().run(num=args.num, output_dir=args.dir, temp_path=args.temp, width=args.width, height=args.height)
"x": -2.675, "y": 1.375, "z": 0 } }, { "$type": "look_at", "object_id": self.pool_id, "use_centroid": True }]) return trial_commands def get_per_frame_commands(self, frame: int, resp: List[bytes]) -> List[dict]: return [{"$type": "focus_on_object", "object_id": self.pool_id}] def get_field_of_view(self) -> float: return 35 def is_done(self, resp: List[bytes], frame: int) -> bool: return frame > 200 if __name__ == "__main__": args = get_args("submerging") Submerge().run(num=args.num, output_dir=args.dir, temp_path=args.temp, width=args.width, height=args.height)