mapbox-unity-sdk icon indicating copy to clipboard operation
mapbox-unity-sdk copied to clipboard

Spawning objects for ARTabletop

Open dpruitt90 opened this issue 8 years ago • 8 comments

Unity version: Unity 2018.2.14f1 Mapbox Version: 1.4.5

Attempting to spawn objects onto a TableTop map (using ARTableTopKit).

Changed the Map to the following LAtLon: 36.0966, -112.0985 (which is working for spawning objects on a standard map.

However, when I use the same spawning technique, the objects fall straight through the map. I would assume that the

abstractMap.GeoToWorldPosition(tankLatLon, true)

Would spawn the object at the specified LatLon and set the Y position to the appropriate level for the map, however this is not working. The LatLon for the objects are correct, but the objects fall straight through the map. However, if I change the scale of the objects (so that they are huge relative to the map) they do not fall through the map. If I adjust the zoom level (on the device by gesture) the objects then fall through the map. So my questions are:

  1. Is there a different method for spawning objects using an AR Tabletop Map? I am using the following:

Vector2d objLatLon = new Vector2d(Double.Parse(newObject.Lat), Double.Parse(newObject.Lon)); var instance = Instantiate(_markerPrefab, parentAnchor);

instance.transform.localPosition = abstractMap.GeoToWorldPosition(objLatLon, true); instance.transform.localScale = new Vector3(.2f, .2f, .2f);

  1. What is the recommended method for ensuring that the object scale changes relative to the zoom level? When I zoom in or out the objects remain the same size (as I am troubleshooting the spawn issue and making the objects large).

My overall process is:

In Awake: abstractMap.MapVisualizer.OnMapVisualizerStateChanged += OnMapReady; if (abstractMap == null) { Debug.LogWarning("Could not find AbstractMap..."); enabled = false; return; }

private void OnMapReady(ModuleState moduleState) {

    if (moduleState == ModuleState.Finished)
    {
        abstractMap.MapVisualizer.OnMapVisualizerStateChanged -= OnMapReady;

        enabled = true;
        Debug.Log("Call Coroutine");
        StartCoroutine(GetExternalData());
    }
}

GetExternalData() { //Call Web Service to get the objects to spawn (with appropriate LatLon) (working correctly) For each object to be spawned:

Vector2d objLatLon = new Vector2d(Double.Parse(newObject.Lat), Double.Parse(newObject.Lon)); var instance = Instantiate(_markerPrefab, parentAnchor);

instance.transform.localPosition = abstractMap.GeoToWorldPosition(objLatLon, true); instance.transform.localScale = new Vector3(.2f, .2f, .2f); }

The objects spawn above the map and fall through the map.....

Thanks in advance.

dpruitt90 avatar Oct 30 '18 22:10 dpruitt90

@dpruitt90 Have you taken a look at the ZoomableMap example? It has an implementation of the SpawnOnMap script for placing objects as well as scaling with zoom.

jordy-isaac avatar Oct 31 '18 19:10 jordy-isaac

Yes. In fact, I am spawning objects on maps in another app just fine. Utilizing the same approach (and virtually the same code - the changes should not affect the spawning) does not work when using the ARTableTop starter project and a terrain map, as noted in the post.

Don Pruitt Executive Vice President nFocus Solutions (o) 602.954.9557 (m) 602.524.6077 www.nfocus.comhttp://www.nfocus.com/

Facebookhttp://www.facebook.com/nfocussolutions | Twitterhttp://www.twitter.com/nfocussolutions | YouTubehttp://www.youtube.com/nfocussolutions

NOTICE - The information contained in this email, and in any accompanying documents, may constitute confidential and/or legally privileged information. The information is intended only for use by the designated recipient. If you are not the intended recipient (or responsible for the delivery of the message to the intended recipient), you are hereby notified that any dissemination, distribution, copying, or other use of, or taking of any action in reliance on this email is strictly prohibited. If you have received this email communication in error, please notify the sender immediately and delete the message from your system.


From: Jordy W. [email protected] Sent: Wednesday, October 31, 2018 12:56:29 PM To: mapbox/mapbox-unity-sdk Cc: Don Pruitt; Mention Subject: Re: [mapbox/mapbox-unity-sdk] Spawning objects for ARTabletop (#1121)

@dpruitt90https://github.com/dpruitt90 Have you taken a look at the ZoomableMap examplehttps://www.mapbox.com/unity-sdk/maps/examples/zoomable-map/? It has an implementation of the SpawnOnMap script for placing objects as well as scaling with zoom.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/mapbox/mapbox-unity-sdk/issues/1121#issuecomment-434824427, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AGnORx6L0dwSHdfmHWJxHgzq-65amhDDks5uqgBtgaJpZM4YDAZE.

dpruitt90 avatar Oct 31 '18 20:10 dpruitt90

@dpruitt90 Just thinking out loud here. ARTableTop map uses a clipping shader to render the map on the detected surface. The colliders might not be scaled properly and that might be causing the objects to fall off.

abhishektrip avatar Oct 31 '18 21:10 abhishektrip

That makes sense as it would be one of the only things that is different between the two. Do you have an idea of how I might adjust to this? Add a new collider to the Abstract map?

Don


From: Abhishek Tripathi [email protected] Sent: Wednesday, October 31, 2018 2:11:38 PM To: mapbox/mapbox-unity-sdk Cc: Don Pruitt; Mention Subject: Re: [mapbox/mapbox-unity-sdk] Spawning objects for ARTabletop (#1121)

@dpruitt90https://github.com/dpruitt90 Just thinking out loud here. ARTableTop map uses a clipping shader to render the map on the detected surface. The colliders might not be scaled properly and that might be causing the objects to fall off.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/mapbox/mapbox-unity-sdk/issues/1121#issuecomment-434849269, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AGnOR5_xkNKJJRt1obNtLXBXt3nb2XnVks5uqhIKgaJpZM4YDAZE.

dpruitt90 avatar Oct 31 '18 21:10 dpruitt90

@dpruitt90 I quickly tried it ( using v2.0.0) and this is what worked for me

  1. Under terrain section -> check the Add Collider checkbox ( will add a mesh collider to terrain tiles)
  2. On the prefab I am spawning ( using SpawnOnMap script) I added a RigidBody and a Box Collider .

With this setup, prefab spawns on the correct place and stay on top of the terrain.

abhishektrip avatar Oct 31 '18 21:10 abhishektrip

Thanks, but I already had the Add Collider box checked for the map and have a RigidBody and MEsh Collider (for a tank - the mesh colliders are on the hull and turret). I also have the TileMap and TileMap Collider 2D on the Map (from the ARTableTop Kit).

Any other ideas?

Don


From: Abhishek Tripathi [email protected] Sent: Wednesday, October 31, 2018 2:33:49 PM To: mapbox/mapbox-unity-sdk Cc: Don Pruitt; Mention Subject: Re: [mapbox/mapbox-unity-sdk] Spawning objects for ARTabletop (#1121)

@dpruitt90https://github.com/dpruitt90 I quickly tried it ( using v2.0.0) and this is what worked for me

  1. Under terrain section -> check the Add Collider checkbox ( will add a mesh collider to terrain tiles)
  2. On the prefab I am spawning ( using SpawnOnMap script) I added a RigidBody and a Box Collider .

With this setup, prefab spawns on the correct place and stay on top of the terrain.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/mapbox/mapbox-unity-sdk/issues/1121#issuecomment-434855717, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AGnOR6jBh-VukkUlO7yHIv7czDrYT6MFks5uqhc9gaJpZM4YDAZE.

dpruitt90 avatar Oct 31 '18 22:10 dpruitt90

Could you try to narrow down on what is causing objects to fall off the terrain? At this point I would say this is not a bug on our end. Some component in the setup is causing the collision to probably fail.

The scaling issue assumed to be the cause doesn't look like the problem after testing.

abhishektrip avatar Oct 31 '18 22:10 abhishektrip

Closing this for now. Please reopen if anything changes.

jordy-isaac avatar Nov 07 '18 17:11 jordy-isaac