I followed the documentation for displaying a 3D Puck but it is not showing.
Already tried with another .gltf, .glb or even a .usdz but still no luck.
The puck does show if I change the .puckType
to a .puck2D()
.
Fatal Error does not get called so MapBox is getting the model successfully, and the file does not have any errors.
Also tried changing the modelScale but no luck. As well as modelOpacity or orientation.
class MapViewController: UIViewController {
var mapView: MapView!
private var cancelables = Set<AnyCancelable>()
override func viewDidLoad() {
super.viewDidLoad()
let options = MapInitOptions()
mapView = MapView(frame: view.bounds, mapInitOptions: options)
mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
view.addSubview(mapView)
mapView.mapboxMap.onStyleLoaded.observeNext { _ in
self.configureMapView()
}.store(in: &cancelables)
setupGestureRecognizers()
}
private func configureMapView() {
// Fetch the asset
guard let uri = Bundle.main.url(forResource: "truck", withExtension: "gltf") else {
fatalError("Failed to locate glb model in asset catalog")
}
// Instantiate the model
let myModel = Model(uri: uri, orientation: [0, 0, 180])
let configuration = Puck3DConfiguration(
model: myModel,
modelScale: .constant([10, 10, 10])
)
mapView.location.options.puckType = .puck3D(configuration)
mapView.location.options.puckBearing = .course
mapView.location.options.puckBearingEnabled = true
mapView.location.onLocationChange.observeNext { [weak mapView] newLocation in
guard let location = newLocation.last, let mapView else { return }
mapView.camera.ease(
to: CameraOptions(
center: location.coordinate,
zoom: 15,
bearing: 0,
pitch: 55),
duration: 1,
curve: .linear,
completion: nil
)
}.store(in: &cancelables)
}
}