Beispiel #1
0
    def drop_squishy(self) -> List[dict]:

        self.squishy = self.SOFT_RECORD
        self.squishy_id = self._get_next_object_id()
        self.squishy_position = {'x': 0., 'y': 1.0, 'z': 0.}
        rotation = {k:0 for k in ['x','y','z']}

        self.squishy_color = [0.0,0.8,1.0]
        self.squishy_scale = get_random_xyz_transform(self.middle_scale_range)
        self.squishy_mass = 2.0

        commands = self.add_soft_object(
            record = self.squishy,
            position = self.squishy_position,
            rotation = rotation,
            scale=self.squishy_scale,
            o_id = self.squishy_id)

        # set mass
        commands.append({"$type": "set_flex_object_mass",
                         "mass": self.squishy_mass,
                         "id": self.squishy_id})

        commands.append(
            {"$type": "set_color",
             "color": {"r": self.squishy_color[0], "g": self.squishy_color[1], "b": self.squishy_color[2], "a": 1.},
             "id": self.squishy_id})

        self._add_name_scale_color(
            self.squishy, {'color': self.squishy_color, 'scale': self.squishy_scale, 'id': self.squishy_id})
        self.masses = np.append(self.masses, self.squishy_mass)

        return commands
 def get_rotation(self, rot_range):
     if rot_range is None:
         return {"x": 0,
                 "y": random.uniform(0, 360),
                 "z": 0}
     else:
         return get_random_xyz_transform(rot_range)
Beispiel #3
0
    def _build_intermediate_structure(self) -> List[dict]:

        ramp_pos = TDWUtils.VECTOR3_ZERO
        ramp_rot = TDWUtils.VECTOR3_ZERO

        self.middle = random.choice(self._middle_types)
        self.middle_id = self._get_next_object_id()
        self.middle_scale = get_random_xyz_transform(self.middle_scale_range)
        rgb = self.middle_color or self.random_color(exclude=self.target_color)

        ramp_data = {
            'name': self.middle.name,
            'id': self.middle_id,
            'scale': self.middle_scale,
            'color': rgb
        }

        commands = self.add_ramp(record=self.middle,
                                 position=ramp_pos,
                                 rotation=ramp_rot,
                                 scale=self.middle_scale,
                                 o_id=self.middle_id,
                                 color=rgb,
                                 material=self.middle_material,
                                 mass=500,
                                 static_friction=self.middle_friction,
                                 dynamic_friction=self.middle_friction,
                                 bounciness=0,
                                 add_data=False)

        # append data
        self.middle_objects.append((self.middle, ramp_data))
        commands.extend(super()._build_intermediate_structure())

        return commands
Beispiel #4
0
    def _place_container(self) -> List[dict]:
        '''
        TODO
        '''
        commands = []

        ## choose a relation type
        self.relation = random.choice(self._relation_types)

        ## create the container
        record, data = self.random_primitive(self._container_types,
                                             scale=1.0,
                                             color=None,
                                             add_data=False)
        self.container = record
        self.container_id = data["id"]

        ## scale the container so it's in the required size range
        self.container_scale = self.rescale_record_to_size(
            record, self.container_scale_range, randomize=True)
        _, cheight, _ = self.get_record_dimensions(self.container)
        self.container_height = cheight * self.container_scale["y"]

        ## jitter the xz position of the container
        self.container_position = get_random_xyz_transform(
            self.container_position_range)

        ## rotate the container in the xz plane
        self.container_rotation = self.get_y_rotation([0, 360])

        ## if relationship is not contain, [possibly] flip
        print("RELATION", self.relation.name)
        if self.relation == Relation.support:
            self._flip_container()
        elif self.relation == Relation.contain:
            self.container_flipped = False
        else:
            if random.choice([0, 1]):
                self._flip_container()

        ## place the container
        add_container_cmds = self.add_primitive(
            record=self.container,
            position=self.container_position,
            rotation=self.container_rotation,
            scale=self.container_scale,
            material=self.container_material,
            color=data["color"],
            mass=5.0,
            scale_mass=True,
            o_id=self.container_id,
            add_data=True,
            make_kinematic=True,
            apply_texture=(True if self.container_material else False))
        commands.extend(add_container_cmds)

        return commands
Beispiel #5
0
    def _build_intermediate_structure(self) -> List[dict]:

        ramp_pos = TDWUtils.VECTOR3_ZERO
        ramp_rot = TDWUtils.VECTOR3_ZERO

        self.middle = random.choice(self._middle_types)
        self.middle_type = self.middle.name
        self.middle_id = self._get_next_object_id()
        self.middle_scale = get_random_xyz_transform(self.middle_scale_range)

        commands = self.add_ramp(record=self.middle,
                                 position=ramp_pos,
                                 rotation=ramp_rot,
                                 scale=self.middle_scale,
                                 o_id=self.middle_id,
                                 add_data=True)

        # give the ramp a texture and color
        commands.extend(
            self.get_object_material_commands(
                self.middle, self.middle_id,
                self.get_material_name(self.middle_material)))
        rgb = self.middle_color or self.random_color(exclude=self.target_color)
        commands.append({
            "$type": "set_color",
            "color": {
                "r": rgb[0],
                "g": rgb[1],
                "b": rgb[2],
                "a": 1.
            },
            "id": self.middle_id
        })
        self.colors = np.concatenate(
            [self.colors, np.array(rgb).reshape((1, 3))], axis=0)

        camera_y_aim = self.ramp_base_height
        self.camera_aim = arr_to_xyz([0., camera_y_aim, 0.])

        return commands
Beispiel #6
0
    def _get_block_scale(self, offset) -> dict:
        print("scale range", self.middle_scale_range)
        scale = get_random_xyz_transform(self.middle_scale_range)
        scale = {k: v + offset for k, v in scale.items()}

        return scale
Beispiel #7
0
    def _build_intermediate_structure(self) -> List[dict]:

        commands = []

        print("THIS IS A PIT!")
        print(self.num_middle_objects)

        # get the scale of the total pit object
        scale = get_random_xyz_transform(self.middle_scale_range)
        self.pit_mass = random.uniform(*get_range(self.middle_mass_range))

        # get color and texture
        self.pit_color = self.middle_color or self.random_color(
            exclude=self.target_color)
        self.pit_material = self.middle_material

        # how wide are the pits?
        self.pit_widths = [
            random.uniform(0.0, self.spacing_jitter) * scale['x']
            for _ in range(self.num_middle_objects - 1)
        ]

        # make M cubes and scale in x accordingly
        x_remaining = scale['x'] - self.pit_widths[0]
        x_filled = 0.0

        print("PIT WIDTHS", self.pit_widths)

        for m in range(self.num_middle_objects):
            print("x_filled, remaining", x_filled, x_remaining)

            m_rec = random.choice(self._middle_types)

            x_scale = random.uniform(0.0, x_remaining)

            x_len, _, _ = self.get_record_dimensions(m_rec)
            x_len *= x_scale
            x_pos = self.ramp_end_x + x_filled + (0.5 * x_len)
            z_pos = random.uniform(-self.lateral_jitter, self.lateral_jitter)

            print(m)
            print("ramp_end", self.ramp_end_x)
            print("x_len", x_len)
            print("x_scale", x_scale)
            print("x_pos", x_pos)
            print("z_pos", z_pos)

            m_scale = arr_to_xyz([x_scale, scale['y'], scale['z']])

            commands.extend(
                self.add_primitive(record=m_rec,
                                   position=arr_to_xyz([x_pos, 0., z_pos]),
                                   rotation=TDWUtils.VECTOR3_ZERO,
                                   scale=m_scale,
                                   color=self.pit_color,
                                   exclude_color=self.target_color,
                                   material=self.pit_material,
                                   mass=self.pit_mass,
                                   dynamic_friction=self.middle_friction,
                                   static_friction=self.middle_friction,
                                   scale_mass=True,
                                   make_kinematic=True,
                                   add_data=True,
                                   obj_list=self.middle_objects))

            if m < len(self.pit_widths):
                x_filled += self.pit_widths[m] + x_len
                x_remaining -= (self.pit_widths[m] + x_len)

        commands.extend(Gravity._build_intermediate_structure(self))

        print("INTERMEDIATE")
        print(commands)

        return commands