mapbox / mapbox/mapbox-maps-ios

Model animation shows jerky movement

Open
#2,200 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

auto-triaged bug :beetle:
Dominant language
Swift
Stars
601
Forks
196
PR merge metrics
No merged PRs in 30d

Description

## Environment

- Xcode version: 15.3
- iOS version: 17.4
- Devices affected:
- Maps SDK Version: 11.4.0

## Observed behavior and steps to reproduce

When animating the position of a 3D model in Mapbox iOS, the model exhibits jerky movements during translation. The jerky movement is especially noticeable when the model is translating from one position to another. I have tried adjusting the modelTranslationTransition and modelRotationTransition, but the issue persists.

**Code for adding model**

```
let plane = Bundle.main.url(
forResource: "A320",
withExtension: "glb")!.absoluteString
var source = GeoJSONSource(id: "source-id")
source.maxzoom = 4
try? mapProxy?.map!.addStyleModel(modelId: "model-id-plane", modelUri: plane)
var planeFeature = Feature(geometry: Point(CLLocationCoordinate2D(latitude: 42.97330, longitude: -75.085930)))
planeFeature.properties = ["model-id-key": .string("model-id-plane")]
source.data = .featureCollection(FeatureCollection(features: [planeFeature]))
try? mapProxy?.map!.addSource(source)
var layer = ModelLayer(id: "model-layer-id", source: "source-id")
layer.modelId = .expression(Exp(.get) { "model-id-key" })
layer.modelType = .constant(.common3d)
layer.modelScale = .constant([1, 1, 1])
layer.modelTranslation = .constant([0, 0, 9753.60])
layer.modelRotation = .constant([0, 0, 186])
layer.maxZoom = 23
layer.minZoom = 5
layer.modelRotationTransition = StyleTransition(duration: 0.1, delay: 0.1)
layer.modelTranslationTransition = StyleTransition(duration: 0, delay: 0)
layer.modelCutoffFadeRange = .constant(0.0)
try? mapProxy?.map!.addLayer(layer)
```

**Code for setting camera:**

```
let freeCam = self.mapProxy?.map?.freeCameraOptions
freeCam?.altitude = 10253.6
freeCam?.location = CLLocationCoordinate2D(latitude: 42.97330, longitude: -75.085930)
freeCam?.setPitchBearingForPitch(0, bearing: 276)
mapProxy?.map?.freeCameraOptions = freeCam!
```

**Code for updating model location:**

```
func updateModelPositionByTraslation(lat: Double, lng: Double, alt: Double, head: Double) {
try? mapProxy?.map?.updateLayer(withId: MapViewLabels.layerId, type: ModelLayer.self) { layer in
// Update layer properties
layer.modelTranslation = .constant([0, 0, alt])
layer.modelRotation = .constant([0, 0, 186])
}

let point = Point(CLLocationCoordinate2D(latitude: lat, longitude: lng))
var pointFeature = Feature(geometry: point)
pointFeature.properties = [MapViewLabels.modelKey: .string(MapViewLabels.modelID)]
self.mapProxy?.map?.updateGeoJSONSource(withId: MapViewLabels.sourceID, geoJSON: .feature(pointFeature))

}
```

## Expected behavior

The model should move smoothly without noticeable jerks.

## Additional links and references

https://github.com/mapbox/mapbox-maps-ios/assets/82497041/ce16304e-ab74-4161-9895-7ede8e8d049e

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No repository file or test is identified. Start by reproducing the issue with the ModelLayer setup, updateLayer, updateGeoJSONSource, and freeCameraOptions calls shown here, then trace model translation and rotation transitions. Done means the 3D model moves between positions without visible jerking.

Written by the indexing model from the issue text.

Assessment

Tech stack
ios, swift
Domain
computer-graphics, mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.