Topic: Drawing "3D" line between 3D markers

Hi

I want to draw lines between a succession of OnlineMapsMarker3D which are the previous position of a plane.

OnlineMapsDrawingLine doesn't seems to be the right tool since i want 3D lines (altitude is important).

What is the best option ? Should i use LineRenderer ?

In that case, how to proceed to benefit of the map transformation ? I mean should my lineRenderer be a component of an OnlineMapsMarker3D? Will this be enough ?

I'm curious to know the best options to achieve this goal. I didn't find answers in the atlas of examples. I'm still a beginner with this awesome asset, any help will be appreciated ;D

Thanks
Thibault

Re: Drawing "3D" line between 3D markers

Hello.

Yes, I think for your case it is better to use LineRenderer.
Should LineRenderer be inside the marker or not, it depends on many things.
But in most cases it is better to have it outside the marker.
I made a small example.
At least it's something where you can begin.

using UnityEngine;

public class DrawLineRendererLine : MonoBehaviour
{
    public GameObject prefab;
    private LineRenderer lineRenderer;
    private OnlineMapsMarker3D marker1;
    private OnlineMapsMarker3D marker2;
    private OnlineMapsTileSetControl control;
    private OnlineMaps map;

    private void Start()
    {
        map = OnlineMaps.instance;
        control = OnlineMapsTileSetControl.instance;

        marker1 = control.AddMarker3D(Vector2.zero, prefab);
        marker2 = control.AddMarker3D(Vector2.one, prefab);

        GameObject go = new GameObject("Line");
        lineRenderer = go.AddComponent<LineRenderer>();
        lineRenderer.widthCurve = AnimationCurve.Constant(0, 1, 10);
        lineRenderer.positionCount = 2;

        UpdateLineRenderer();

        control.OnMeshUpdated += OnMeshUpdated;
    }

    private Vector3 GetWorldPositionWithAltitude(OnlineMapsMarker3D marker)
    {
        double lng, lat;
        marker.GetPosition(out lng, out lat);

        double tlx, tly, brx, bry;
        map.GetCorners(out tlx, out tly, out brx, out bry);

        Vector3 p;

        if (marker.altitude.HasValue)
        {
            p = OnlineMapsTileSetControl.instance.GetWorldPosition(lng, lat);
            float yScale = control.GetBestElevationYScale(tlx, tly, brx, bry);
            p.y = marker.altitude.Value * yScale;
            if (control.elevationBottomMode == OnlineMapsTileSetControl.ElevationBottomMode.minValue) p.y -= control.elevationMinValue * yScale;
            p.y *= control.elevationScale;
        }
        else p = OnlineMapsTileSetControl.instance.GetWorldPositionWithElevation(lng, lat, tlx, tly, brx, bry);

        return p;
    }

    private void OnMeshUpdated()
    {
        UpdateLineRenderer();
    }

    private void UpdateLineRenderer()
    {
        lineRenderer.SetPositions(new[]
        {
            GetWorldPositionWithAltitude(marker1),
            GetWorldPositionWithAltitude(marker2),
        });
    }
}
Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: Drawing "3D" line between 3D markers

Thanks for your response.

I tried on my own for a couple hours and i almost achieve it.

* i've got a lineRenderer component attached to my 3D marker
* each time i change the position of the marker, i add the new position to my lineRenderer.

But i'm struggling with a curious offset. My lineRenderer is drawn at a certain distance of where it should be.

I made a Gif to show this strange behaviour :

https://gph.is/2R1GjXp

Quality is not great, but you should see that the line are renderer like 50 meters from my marker.
On the bright side the LineRenderer positions follow the map movement now tongue

Initiating the LineRenderer :

LineRenderer LR = marker.instance.AddComponent<LineRenderer>();
LR.useWorldSpace = false;
LR.positionCount = 0;

Adding a position (each time i move my marker):

LineRenderer LR = droneMarker.instance.GetComponent<LineRenderer>();
LR.positionCount++;
LR.SetPosition(LR.positionCount - 1, droneMarker.transform.position);

What am i doing wrong ?
Is it a problem like: the transform is Vector3 with float, but the marker position was set with double, so i get an offset because of the precision lost ?

I will look at your example now. Am i supposed to attach it to the Map GameObject ?

Re: Drawing "3D" line between 3D markers

I manage to modify your example to fit my needs, and it's working smile

Thanks a lot, as i wasn't so close after all. Having the lineRenderer directly on my marker wasn't such a good idea and it's much more simple with your solution.

Thank you Alex, you have helped me a lot over the past 2 days. Hopefully i will progress & get more familiar with this asset to stop bothering you every day big_smile