def randomize_object(self): handle = self.cube.get_handle() sim.simRemoveObject(handle) sizes = [max(random() * 0.1, 0.02), 0.05] objects = list() position = [0, 0, 0] mass = 0.1 # Create cube with random size s = sizes[0] objects.append( Shape.create(type=PrimitiveShape.CUBOID, size=[s, s, s], position=position, mass=mass, color=[random() for _ in range(3)])) index = sample(range(len(position) - 1), 1)[0] sign = sample([1, -1], 1)[0] position[index] += sum(sizes) * 0.5 * sign s = sizes[-1] # Create cube with fix size objects.append( Shape.create(type=PrimitiveShape.CUBOID, size=[s, s, s], position=position, mass=mass, color=[random() for _ in range(3)])) handles = [o.get_handle() for o in objects] handle = sim.simGroupShapes(handles) self.cube = Shape(handle) self.graspable_objects = [ self.cube, ]
def remove(self) -> None: """Removes this object/model from the scene. :raises: ObjectAlreadyRemoved if the object is no longer on the scene. """ try: if self.is_model(): sim.simRemoveModel(self._handle) else: sim.simRemoveObject(self._handle) except RuntimeError as e: raise ObjectAlreadyRemovedError( 'The object/model was already deleted.') from e