def _init_object(c: Controller, name: str, pos: Dict[str, float], rot: Dict[str, float]) -> List[dict]: """ :param c: The controller. :param name: The name of the model. :param pos: The initial position of the model. :param rot: The initial rotation of the model. :return: A list of commands to instantiate an object from ObjectInfo values. """ o_id = c.get_unique_id() Scene.OBJECT_IDS.update({o_id: name}) info = Scene._OBJECT_INFO[name] return [c.get_add_object(name, object_id=o_id, position=pos, rotation=rot, library=info.library), {"$type": "set_mass", "id": o_id, "mass": info.mass}, {"$type": "set_physic_material", "id": o_id, "bounciness": info.bounciness, "static_friction": 0.1, "dynamic_friction": 0.8}]
def _initialize_scene(self, c: Controller) -> List[dict]: commands = super()._initialize_scene(c) model_name = self._get_model_name() o_id = c.get_unique_id() Scene.OBJECT_IDS.update({o_id: model_name}) commands.extend([c.get_add_object(model_name, object_id=o_id, library=self._get_library()), {"$type": "set_mass", "id": o_id, "mass": 1000}, {"$type": "set_physic_material", "id": o_id, "bounciness": Scene._OBJECT_INFO[model_name].bounciness, "static_friction": 0.1, "dynamic_friction": 0.8}]) return commands
def _initialize_scene(self, c: Controller) -> List[dict]: c.model_librarian = ModelLibrarian("models_full.json") commands = super()._initialize_scene(c) # Add a table, chair, and boxes. commands.extend(self._init_object(c, "b05_table_new", pos={"x": 0, "y": 0, "z": 4.33}, rot=TDWUtils.VECTOR3_ZERO)) commands.extend(self._init_object(c, "chair_willisau_riale", pos={"x": 0, "y": 0, "z": 3.7}, rot=TDWUtils.VECTOR3_ZERO)) commands.extend(self._init_object(c, "iron_box", pos={"x": 0.13, "y": 0.65, "z": 4.83}, rot=TDWUtils.VECTOR3_ZERO)) commands.extend(self._init_object(c, "iron_box", pos={"x": -0.285, "y": 1.342, "z": 4.79}, rot={"x": 90, "y": 0, "z": 0})) # Add a shelf with a custom scale. shelf_id = c.get_unique_id() shelf_name = "metal_lab_shelf" Scene.OBJECT_IDS.update({shelf_id: shelf_name}) commands.extend([c.get_add_object(shelf_name, object_id=shelf_id, rotation={"x": 0, "y": -90, "z": 0}, position={"x": 0, "y": 0, "z": 4.93}), {"$type": "set_mass", "id": shelf_id, "mass": 400}, {"$type": "set_physic_material", "id": shelf_id, "bounciness": Scene._OBJECT_INFO[shelf_name].bounciness, "static_friction": 0.1, "dynamic_friction": 0.8}, {"$type": "scale_object", "id": shelf_id, "scale_factor": {"x": 1, "y": 1.5, "z": 1.8}}]) return commands
from sticky_mitten_avatar.util import get_data """ Get default audio data for each sub-object of a composite object. """ if __name__ == "__main__": from argparse import ArgumentParser parser = ArgumentParser() parser.add_argument("--model", default="puzzle_box_composite") args = parser.parse_args() c = Controller() c.start() resp = c.communicate([ TDWUtils.create_empty_room(12, 12), c.get_add_object(model_name=args.model, object_id=0), { "$type": "send_composite_objects" }, { "$type": "send_segmentation_colors" } ]) c.communicate({"$type": "terminate"}) # Get the name of each object. colors = get_data(resp=resp, d_type=SegmentationColors) names = dict() for i in range(colors.get_num()): names[colors.get_object_id(i)] = colors.get_object_name(i) # Parse the composite object data. co = get_data(resp=resp, d_type=CompositeObjects)
# 1. Load the scene. # 2. Create an empty room (using a wrapper function) # 3. Add the table. # 4. Request Bounds data. resp = c.communicate([{ "$type": "load_scene", "scene_name": "ProcGenScene" }, TDWUtils.create_empty_room(12, 12), c.get_add_object(model_name=table_record.name, object_id=table_id, position={ "x": 0, "y": 0, "z": 0 }, rotation={ "x": 0, "y": 0, "z": 0 }), { "$type": "send_bounds", "ids": [table_id], "frequency": "once" }]) # Get the top of the table. top_y = 0 for r in resp[:-1]: r_id = OutputData.get_data_type_id(r) # Find the bounds data.
from tdw.controller import Controller from tdw.tdw_utils import TDWUtils from tdw.collisions import Collisions """ Receive collision output data and read it as a `Collisions` object. """ if __name__ == "__main__": c = Controller(launch_build=False) c.start() resp = c.communicate([ TDWUtils.create_empty_room(12, 12), c.get_add_object(model_name="rh10", position={ "x": 0, "y": 1, "z": 0 }, object_id=0), c.get_add_object(model_name="rh10", position={ "x": 0, "y": 2, "z": 0 }, object_id=1), { "$type": "send_collisions", "enter": True, "stay": True, "exit": True, "collision_types": ["obj", "env"]
txt = Path("../sticky_mitten_avatar/object_data/target_objects.csv" ).read_text(encoding="utf-8") c = Controller(launch_build=False) c.start() commands = [TDWUtils.create_empty_room(12, 12)] y = 0 o_id = 0 for line in txt.split("\n")[1:]: line_split = line.split(",") model = line_split[0] scale = float(line_split[1]) commands.extend([ c.get_add_object(model_name=model, object_id=o_id, position={ "x": 0, "y": y, "z": 0 }), { "$type": "scale_object", "scale_factor": { "x": scale, "y": scale, "z": scale }, "id": o_id } ]) o_id += 1 y += scale / 2 c.communicate(commands)
"x": 0, "y": 0, "z": 0 }, "id": o_id }, { "$type": "rotate_object_to", "rotation": { "w": 1, "x": 0, "y": 0, "z": 0 }, "id": o_id }] c = Controller() c.start() c.communicate([ TDWUtils.create_empty_room(12, 12), c.get_add_object("rh10", object_id=o_id) ]) num_trials = 5000 t0 = time() for i in range(num_trials): c.communicate(cmds) fps = (num_trials / (time() - t0)) print(f"FPS: {round(fps)}") c.communicate({"$type": "terminate"})