mapbox / mapbox-scenekit

Other
231 stars 51 forks source link

Line support - trail drawing [feature] #20

Closed natalia-osa closed 5 years ago

natalia-osa commented 6 years ago

Do you plan to support adding a path/line/trail to the map? Is there any timebox during which we can expect functionality to draw a line on the map? The source code contains following lines:

/**
 Adds an annotation to the map view.

 @note `MGLMultiPolyline`, `MGLMultiPolygon`, `MGLShapeCollection`, and
    `MGLPointCollection` objects cannot be added to the map view at this time.
    Any multipoint, multipolyline, multipolygon, shape or point collection
    object that is specified is silently ignored.

 @param annotation The annotation object to add to the receiver. This object
    must conform to the `MGLAnnotation` protocol. The map view retains the
    annotation object. */
- (void)addAnnotation:(id <MGLAnnotation>)annotation;

At MapBox blog article you write:

The team at Slopes, the iOS app for skiers and snowboarders, used our SceneKit SDK to pull detailed 3D trail guides into their app.

What indicates that either they wrote their custom support for it or it's already in the framework but I can't find it.

Due to it, I'm not sure if there is already support for trails (or at least lines) or we should wait / implement it ourselves / look for a different solution.

avi-c commented 6 years ago

Hi @natalia-osa,

We don't support 3D line drawing at the moment. You can use SceneKit ability to build an SCNShape from a UIBezierPath, but that will only create an extruded 2D shape. That might do some of what you want, depending on your use case.

Since SceneKit itself lacks a primitive for 3D lines, people have been implementing interim solutions using short SCNCylinder or SCNTube geometrys connected together. This isn't a great solution, but again, it might work well enough for some cases.

We do plan to add this ability to the SDK, but I don't have a timeframe for it right now. If you do choose to implement a solution, please consider submitting it a PR. I'm sure other users would be very appreciative!

natalia-osa commented 6 years ago

I already have some sort of the solution (dirty) fully working in your example project using DemoPlacementViewController. I was trying to use the same solution in DemoARViewController but I failed (WIP) - the trail is shown, but around 10m above placement of the map (so above my head). I'm not yet sure what causes it to work badly, maybe the zoom you apply there, maybe the height function is invalid for AR or maybe I'm using convertPosition with a wrong argument. I will most probably make a PR once my company decides to work on it (2-3 weeks I guess), atm we just did a proof of concept it's possible (and it is).

The solution I've done iterates by all of the points and creates a SCNCylinders. Besides the problem I wrote about above, I want to upgrade the function, which recalculates the points to work in such way, that the distances between the points will be passed as an argument to 3d route creation method. So if the route contains points with distances 1m, 1m, 5m, 2m between them, now it's a bigger possibility the middle of 5m cylinder will go into the mountain or float above the water/depression. With the upgraded method, the developer will set eg 1m and it will break 5m and 2m cylinders into 7 cylinders. Also obviously I need to refactor everything and add the tests before PR.

avi-c commented 6 years ago

@natalia-osa Would you be willing to chat directly about some of the use cases? We're working on some of the route features and it would help us to learn more about what people would like to accomplish.

natalia-osa commented 6 years ago

@avi-c Yes, I'll be happy to chat directly about the use cases. I have my own solution already working. Currently, I'm tidying code up and I will create a pull request here up to Friday. There are a few places where I'd like to improve it and surely will do so in upcoming time.

natalia-osa commented 5 years ago

Done in #48.