BeamNGpy icon indicating copy to clipboard operation
BeamNGpy copied to clipboard

How to hide vehicles before shooting?

Open yuyuyu223 opened this issue 10 months ago • 3 comments

I want to hide the specified car when shooting with the camera. I bound the camera to the ego car and removed the remaining cars before shooting with the camera. However, the following error message will appear. How can I implement this function? Does beamng have a visible interface?

I used traffic flow and captured all participating vehicles:

beamng.traffic.spawn(max_amount=10)
time.sleep(10)
traffic_cars = beamng.get_current_vehicles()
traffic_cars.pop("ego")
for k, car in traffic_cars.items():
    car.connect(beamng)
    car.ai.set_mode('span')
    car.ai.set_speed(5.0, mode='limit')

I retrieve vehicle information through the following code, and then delete the vehicle:

def get_car_all_info(scenario, vehicle: Vehicle):
    if vehicle.vid not in scenario.transient_vehicles.keys():
        scenario.transient_vehicles[vehicle.vid] = vehicle
        # scenario.vehicles[vehicle.vid] = vehicle
    scenario.update()
    state = vehicle.state.copy()
    bbox = get_car_bbox(vehicle)
    state.update(bbox)
    return state

def get_car_bbox(vehicle: Vehicle):
    """
    Calculate the bounding box of a given vehicle.

    Parameters:
        vehicle (object): The vehicle object for which to calculate the bounding box.

    Returns:
        dict: A dictionary containing the bounding box coordinates.
    """
    bbox = vehicle.get_bbox()
    return bbox
for car in traffic_cars.values():
        state = get_car_all_info(scenario, car)
        car_states.append(state)
        beamng.vehicles.despawn(car)

Then I capture images:

  for camera in camera_ls:
      image, extra, c2w = camera_capture(camera, ego)
      image_ls.append(image)

But I received the following error message: image

BeamNG 0.31.3 BeamNGpy 1.28

yuyuyu223 avatar Apr 07 '24 15:04 yuyuyu223