mapbox / mapbox-maps-ios

Interactive, thoroughly customizable maps for iOS powered by vector tiles and Metal
https://www.mapbox.com/mapbox-mobile-sdk
Other
462 stars 149 forks source link

Add option to render metal view continuously #514

Open Cal-um opened 3 years ago

Cal-um commented 3 years ago

New Feature

Add option to render metal view continuously in the MapView class. The MTLView needs to be configured with metalView.isPaused = false metalView.enableSetNeedsDisplay = false as per the docs https://developer.apple.com/documentation/metalkit/mtkview

Timed updates: The view redraws its contents based on an internal timer. In this case, which is the default behavior, both isPaused and enableSetNeedsDisplay are set to false. Use this mode for games and other animated content that’s regularly updated. Currently these are set to true.

Why

For metal SceneKit integration this is required to let the nodes animate. I need this is my current use case.

vincentborcard commented 3 years ago

I modified metalView.isPaused = false metalView.enableSetNeedsDisplay = false in MapView.swift and it allows to continuously render metal view. Thx Cal-um. I also would like to change that through an option.

In my case, to continuously update the position of a 3D node on a path retrieved from a lineString (turf). I modified the SceneKitExample.swift to do that.

But modifying metalView.isPaused = false metalView.enableSetNeedsDisplay = false produce some strange elevation with the Hillshade. Any idea why it happens?

Screenshot 2021-08-22 at 19 20 07
macdrevx commented 2 years ago

https://github.com/mapbox/mapbox-maps-ios/pull/964 exposed a new API that allows client code to request that the map redraw. You may be able to use that to solve some of the same problems that would be addressed by continual metal view rendering.

Cal-um commented 2 years ago

@macdrevx Is this API intended to be used for animations? Would it be used called continuously with a display link when needing to animate a node?

macdrevx commented 2 years ago

Yes, you'd need to invoke it any time something happens in your model that requires a new drawing pass.