Search Unity

Multi-AR Examples

Discussion in 'Assets and Asset Store' started by roumenf, Aug 7, 2018.

  1. roumenf

    roumenf

    Joined:
    Dec 12, 2012
    Posts:
    635
  2. IMAGINE360

    IMAGINE360

    Joined:
    Apr 15, 2016
    Posts:
    3
    Hello

    I'd like to know how i can stop the plane visualization once i have tracked the plane i want (i'am making an app on both Android and IOS) i don't want to see the plane at all when i'am done.
     
  3. roumenf

    roumenf

    Joined:
    Dec 12, 2012
    Posts:
    635
    Please open MultiARManager.cs in MultiAR/CoreScripts-folder and add the following method to it (I'll add it to the next release, too):

    Code (CSharp):
    1.  
    2.     public void UpdateOverlaySurfaces()
    3.     {
    4.         // get current material
    5.         Material surfaceMat = GetSurfaceMaterial();
    6.  
    7.         foreach (string sKey in arData.dictOverlaySurfaces.Keys)
    8.         {
    9.             OverlaySurfaceUpdater surface = arData.dictOverlaySurfaces[sKey];
    10.  
    11.             MeshRenderer meshRenderer = surface.gameObject.GetComponent<MeshRenderer>();
    12.             MeshCollider meshCollider = surface.gameObject.GetComponent<MeshCollider>();
    13.  
    14.             // surface renderer
    15.             if (surfaceMat != null)
    16.             {
    17.                 if (meshRenderer != null && !meshRenderer.enabled)
    18.                     meshRenderer.enabled = true;
    19.                
    20.                 surface.SetSurfaceMaterial(surfaceMat);
    21.             }
    22.             else
    23.             {
    24.                 if (meshRenderer != null && meshRenderer.enabled)
    25.                     meshRenderer.enabled = false;
    26.             }
    27.  
    28.             // surface collider
    29.             if (surfaceCollider)
    30.             {
    31.                 if (meshCollider != null && !meshCollider.enabled)
    32.                     meshCollider.enabled = true;
    33.  
    34.                 surface.SetSurfaceCollider(surfaceCollider, colliderMaterial);
    35.             }
    36.             else
    37.             {
    38.                 if (meshCollider != null && meshCollider.enabled)
    39.                     meshCollider.enabled = false;
    40.             }
    41.         }
    42.     }
    43.  
    Then from your script do something like this:
    "
    MultiARManager.Instance.useOverlaySurface = SurfaceRenderEnum.None; // or SurfaceRenderEnum.Occlusion
    MultiARManager.Instance.UpdateOverlaySurfaces();
    "
     
  4. Ruminya

    Ruminya

    Joined:
    Sep 29, 2015
    Posts:
    2
    Hello Roumenf,

    Can you make a demo or tutorial document about switching between two scenes, 1 normal and 1 AR. I can't find how to turn-off "AR mode" and "device camera" when out of AR-scene.

    Also, shall we have a way to check this device support AR or not without go to scene AR ?
    (i've test a not supported Android device, when open AR scene, it's said "need download ARCore from google play", of course that i can't download and it's crash when back to app).
     
  5. roumenf

    roumenf

    Joined:
    Dec 12, 2012
    Posts:
    635
    Hi, there are 'MultiARManager.Instance.PauseSession()' and 'MultiARManager.Instance.ResumeSession()' methods to pause & resume the AR-sessions, when you need to (i.e. turn off & back on the AR-mode). I think this was demonstrated with the pause-button in DemoScenes/AnchoringDemo/AnchorUnanchorDemo-scene.

    Regarding the check for AR-support when the app starts, I need to research a bit, whether such API is available for different platforms. But I suppose for AR-Core the first thing to do is to disable 'ARCore Required' in ARCore settings (menu Edit / Project Settings / ARCore).
     
  6. Ruminya

    Ruminya

    Joined:
    Sep 29, 2015
    Posts:
    2
    Tks for reply,

    With Ar-core, i found this post use CheckApkAvailability to check device support.
    It's work on my android phone (not test ios device yet).
     
    roumenf likes this.
  7. joescott

    joescott

    Joined:
    Oct 18, 2018
    Posts:
    5
    Wonderful package! I enjoy the examples a lot.

    Looking through the examples I think I found a typo… Please check the script "ObjectController" (Anchoring Demo) in line 278 ff:
    Code (CSharp):
    1.     public void Toggle3Selected(bool bOn)
    2.     {
    3.         if(model2)
    Shouldn't it be like this?

    Code (CSharp):
    1.     public void Toggle3Selected(bool bOn)
    2.     {
    3.         if(model3)

    Best Regards,
    Joe
     
    roumenf likes this.
  8. roumenf

    roumenf

    Joined:
    Dec 12, 2012
    Posts:
    635
    Yes, you are right. This is a result of the copy&paste coding :)
    Thank you for the feedback!
     
    joescott likes this.
  9. joescott

    joescott

    Joined:
    Oct 18, 2018
    Posts:
    5
    I've updated the package to v2.6. Trying to run the ImageAnchorDemo via Instant Preview Fails. The previous verision worked fine. Is this an ARCore 1.5 issue?


    EntryPointNotFoundException: ArPrestoAugmentedImageDatabase_create
    GoogleARCoreInternal.AugmentedImageDatabaseApi.CreateArPrestoAugmentedImageDatabase (System.Byte[] rawData) (at Assets/GoogleARCore/SDK/Scripts/Api/AugmentedImageDatabaseApi.cs:59)
    GoogleARCore.AugmentedImageDatabase.get_m_ArPrestoDatabaseHandle () (at Assets/GoogleARCore/SDK/Scripts/AugmentedImageDatabase.cs:104)
    GoogleARCoreInternal.ApiPrestoConfig..ctor (GoogleARCore.ARCoreSessionConfig config) (at Assets/GoogleARCore/SDK/Scripts/Api/ApiPrestoConfig.cs:73)
    GoogleARCoreInternal.ARCoreAndroidLifecycleManager._SetConfiguration (GoogleARCore.ARCoreSessionConfig config) (at Assets/GoogleARCore/SDK/Scripts/Managers/ARCoreAndroidLifecycleManager.cs:278)
    GoogleARCoreInternal.ARCoreAndroidLifecycleManager._OnEarlyUpdate () (at Assets/GoogleARCore/SDK/Scripts/Managers/ARCoreAndroidLifecycleManager.cs:176)
    GoogleARCoreInternal.ARPrestoCallbackManager._EarlyUpdateTrampoline () (at Assets/GoogleARCore/SDK/Scripts/Managers/ARPrestoCallbackManager.cs:151)
    (wrapper native-to-managed) GoogleARCoreInternal.ARPrestoCallbackManager:_EarlyUpdateTrampoline ()
    GoogleARCoreInternal.InstantPreviewManager+<UpdateLoop>c__Iterator1.MoveNext () (at Assets/GoogleARCore/SDK/InstantPreview/Scripts/InstantPreviewManager.cs:288)
    UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)
     
  10. roumenf

    roumenf

    Joined:
    Dec 12, 2012
    Posts:
    635
    Yes, I think this is a bug in the latest AR-Core Unity plugin :(
    If you get it from its own repository (https://github.com/google-ar/arcore-unity-sdk.git) and try its AugmentedImage-scene in the Editor, you will get the same message.
     
    joescott likes this.
  11. joescott

    joescott

    Joined:
    Oct 18, 2018
    Posts:
    5
    Me again... ;)

    I'm playing around a little with the ImageAnchorDemo scene. It only works on the first Image scanned. I'd like to change it where when I find the second image the coffee cups will be rendered on top of the second image. And when I then move back to the first Image the cups should appear at the first image again.

    Is there anything like in ARCore where I get an update?
    Session.GetTrackables<AugmentedImage>(m_TempAugmentedImages, TrackableQueryFilter.Updated);
     
    roumenf likes this.
  12. roumenf

    roumenf

    Joined:
    Dec 12, 2012
    Posts:
    635
    Yes, this is a good point. Currently, the CoffeeMachineController-script looks for the 1st found image anchor, and uses it all the time. This is done by calling GetFirstTrackedImageAnchorName()-method of MultiARManager. I suppose, it may be useful to have some convenience methods too, like GetNearestImageAnchorName() and GetVisibleImageAnchorName(), so you could have more options to choose from. Should I post the needed code here, or you can add it by yourself to MultiARManager.cs?
     
    Last edited: Nov 1, 2018
    joescott likes this.
  13. joescott

    joescott

    Joined:
    Oct 18, 2018
    Posts:
    5
    I need to think about this a little more. I suppose a GetVisibleImageAnchorNames() would also be useful to support multiple Image target tracking.
    I think I should be able to add it by myself but I don't want to mess with the original files to avoid problems when you update your package.
    I'll try to figure something out and will then get back to you.
    Cheers,
    Joe
     
    roumenf likes this.
  14. roumenf

    roumenf

    Joined:
    Dec 12, 2012
    Posts:
    635
    Don't worry. In the meanwhile I created and tested a bit these functions, so here is the code. Please add it to MultiARManager.cs in MultiAR/CoreScripts-folder. Then, feel free to experiment:

    Code (CSharp):
    1.  
    2.     public string GetNearestImageAnchorName()
    3.     {
    4.         if (arInterface != null)
    5.         {
    6.             Camera mainCamera = arInterface.GetMainCamera();
    7.             List<string> alAnchorNames = GetTrackedImageAnchorNames();
    8.  
    9.             if (mainCamera != null && alAnchorNames != null)
    10.             {
    11.                 Vector3 cameraPos = mainCamera.transform.position;
    12.  
    13.                 float minDistance = float.MaxValue;
    14.                 int foundAnchorIndex = -1;
    15.  
    16.                 for (int i = 0; i < alAnchorNames.Count; i++)
    17.                 {
    18.                     string anchorName = alAnchorNames[i];
    19.                     GameObject anchorObj = arInterface.GetTrackedImageAnchorByName(anchorName);
    20.  
    21.                     if(anchorObj != null)
    22.                     {
    23.                         Vector3 anchorPos = anchorObj.transform.position;
    24.                         float camToAnchorDist2 = (anchorPos - cameraPos).sqrMagnitude;
    25.  
    26.                         if(camToAnchorDist2 < minDistance)
    27.                         {
    28.                             minDistance = camToAnchorDist2;
    29.                             foundAnchorIndex = i;
    30.                         }
    31.                     }
    32.                 }
    33.  
    34.                 return (foundAnchorIndex >= 0 ? alAnchorNames[foundAnchorIndex] : string.Empty);
    35.             }
    36.         }
    37.  
    38.         return string.Empty;
    39.     }
    40.  
    41.  
    42.     public string GetVisibleImageAnchorName()
    43.     {
    44.         if (arInterface != null)
    45.         {
    46.             Camera mainCamera = arInterface.GetMainCamera();
    47.             List<string> alAnchorNames = GetTrackedImageAnchorNames();
    48.  
    49.             if (mainCamera != null && alAnchorNames != null)
    50.             {
    51.                 Rect screenRect = new Rect(0, 0, mainCamera.pixelWidth, mainCamera.pixelHeight);
    52.                 Vector2 cameraPos = new Vector2(mainCamera.pixelWidth / 2, mainCamera.pixelHeight / 2);
    53.  
    54.                 float minDistance = float.MaxValue;
    55.                 int foundAnchorIndex = -1;
    56.  
    57.                 for (int i = 0; i < alAnchorNames.Count; i++)
    58.                 {
    59.                     string anchorName = alAnchorNames[i];
    60.                     GameObject anchorObj = arInterface.GetTrackedImageAnchorByName(anchorName);
    61.  
    62.                     if (anchorObj != null)
    63.                     {
    64.                         Vector2 anchorPos = mainCamera.WorldToScreenPoint(anchorObj.transform.position);
    65.                         float camToAnchorDist2 = (anchorPos - cameraPos).sqrMagnitude;
    66.  
    67.                         if (camToAnchorDist2 < minDistance &&
    68.                             anchorPos.x >= screenRect.x && anchorPos.x < screenRect.width &&
    69.                             anchorPos.y >= screenRect.y && anchorPos.y < screenRect.height)
    70.                         {
    71.                             minDistance = camToAnchorDist2;
    72.                             foundAnchorIndex = i;
    73.                         }
    74.                     }
    75.                 }
    76.  
    77.                 return (foundAnchorIndex >= 0 ? alAnchorNames[foundAnchorIndex] : string.Empty);
    78.             }
    79.         }
    80.  
    81.         return string.Empty;
    82.     }
    83.  
    84.  
     
    joescott likes this.
  15. joescott

    joescott

    Joined:
    Oct 18, 2018
    Posts:
    5
    Thanks a lot for the Code! Works pretty well in my case.

    I've just seen the "What's new in 2.6.1". Thanks for mentioning me ;)

    Unfortunately I can think of a scenario where this solution isn't useful.
    Multiple images at the same position in the real world e.g. a product catalog. Any ideas?
     
  16. probitaille

    probitaille

    Joined:
    May 5, 2015
    Posts:
    34
    Hi! Thank you for this plugin. I'm interested in your project because you support multi-platform.

    Unfortunately, I just tested the ObjectControllerDemo and it's not working on my iPhone (iOS 12.1).

    Here some useful logs from XCode:

    Code (CSharp):
    1. ArKit is available.
    2. MultiArManager:Awake()
    3. Selected AR-Platform: ArKit
    4. Error: Could not create a cross platform ARCore session.
    This is the project out of the box. I also tested with ARCore disabled in the MultiArController. I got the same problem.

    Is there a setting that I missed?

    Thank you for your response.
     
  17. probitaille

    probitaille

    Joined:
    May 5, 2015
    Posts:
    34
  18. CarryMinaty

    CarryMinaty

    Joined:
    Jul 10, 2018
    Posts:
    2
    Hi,
    I am facing a problem. When I uncheck ModelLookingAtCamera on ObjectController script the vertical object not place with right rotation. I used "currentModel.rotation = Quaternion.LookRotation(Vector3.back);" for rotation. It works only one wall but when I use different wall the model rotation changed. I do not want to use camera facing.

    Any HELP PLEASE.
     
  19. jonalexfilms

    jonalexfilms

    Joined:
    Jan 4, 2017
    Posts:
    3
    Downloaded the latest version 2.6 and tried running on 2019.1 with no luck.

    Most errors are related to Networking (obsolete) and MessageBase (obsolete)

    I managed to get it running in 2018.3, but with a long list of errores.

    Is it possible to get the next version running with Unity's new ARFoundation, which targets both platforms simultaneously.
     
    Last edited: May 3, 2019
  20. roumenf

    roumenf

    Joined:
    Dec 12, 2012
    Posts:
    635
    Thank you for the bug report! Hm, I need to check it with 2019.1, which was released the same day I released the latest Multi-AR version, I think. But it should work with 2018.3, where the Unity's own networking system was not yet obsolete.

    Regarding AR-Foundation: It requires installing extra packages and supports mobile AR only. I want my package to run out of the box, without extra installs, and to target 3 platforms simultaneously. So, I don't plan to include support for AR-foundation in the near future.
     
    Last edited: May 3, 2019
  21. jonalexfilms

    jonalexfilms

    Joined:
    Jan 4, 2017
    Posts:
    3
    I take back the 2018.3, you are right, I was able to get it running after starting a clean project instead of downgrading the original one from 2019. Sorry for the alarm.

    As far as ARFoundation, makes sense.

    Question: Is it safe to assume that I need to make 2 different scenes, one for Android and one for iOS using your framework? If so, that's the biggest benefit I see to the ARFoundation structure... import a packages and get on to prepping one scene for all major mobile platforms.

    Regardless, I'm still testing your plugin out, there are so many things working really nice out of the box. AR Portals ready to go is a big deal. :)

    Thanks for the reply!
     
  22. roumenf

    roumenf

    Joined:
    Dec 12, 2012
    Posts:
    635
    To your question: No, you don't need to create two identical scenes for both platforms. That's the whole point. The MultiARManager-component should select the proper platform-interface for you. Or, you can set a 'Preferred platform', if for instance, you'd like to do some desktop tests.

    By the way, as far as I remember, the predecessor of AR-Foundation (called AR-Interface back then), was created right after I submitted this package to the Asset store for a first time.
     
  23. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    I wanted to get the AR objects to cast shadows on themselves and on the detected planes on Android phone (ObjectControllerDemo scene). These are the MultiARController settings. I have also enabled shadows in the quality settings, but I can't get these shadows to work. mar.png
    Could I be missing something? My Unity version is 2019.1.0f2, ar foundation is 1.1
     
  24. roumenf

    roumenf

    Joined:
    Dec 12, 2012
    Posts:
    635
    Hi, I just tested the SurfaceOcclusionDemo-scene with 'Use overlay surface' set to 'Occlusion with shadows', and it worked as expected on my Android phone - with shadows on the surfaces and on the AR objects. This means your settings are correct.

    But, as a matter of fact, I used Unity 2018.2.0f2 without any extra AR packages included. I'm not sure how you managed to run it on 2019.1.0, because of the recently removed by Unity Network-related classes and other newly introduced 2019.1 issues. Please mind, I have not updated the package yet, to run on the 2019.x versions of Unity.
     
    tomekkie2 likes this.
  25. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    Thanks for taking a look into this.
    Yes, I have checked that in 2018.2.2 and it works on galaxy s7 and probably other a>7 devices as well.
    Regarding 2019.1 and network related classes - I had to install the multiplayer hlapi package to get it working.
    I have also tried other packages/shaders and shadows were not working on any of them on 2019.1.
     
    roumenf likes this.
  26. Chris_1001

    Chris_1001

    Joined:
    Jan 16, 2018
    Posts:
    13
    Hi - great asset - One issue - on the:
    PortalDoorDemo - I always check "Portal Looking at Camera" but the spawned prefab never faces the camera,
    it always stays at one angle.
    (I am building to iOS)
    I would be really grateful if you have any ideas on how to fix this,
    thanks.
     
  27. roumenf

    roumenf

    Joined:
    Dec 12, 2012
    Posts:
    635
    Thank you!
    The fix was sent by e-mail. It will be added to the next update, as well.
     
  28. briwil78

    briwil78

    Joined:
    Jan 3, 2015
    Posts:
    4
    I'm currently trying this out on an iPhone XS, and everything is working great except the imageAnchor, it just won't recognize any of the coffee cups- is there anything I need to do other than open the demo scene and build?
    I also tried adding my own image, but again, its not recognizing, I'm using prints of the photos.
    Using Unity 2019.1.8f1
     
  29. briwil78

    briwil78

    Joined:
    Jan 3, 2015
    Posts:
    4
    Also just noticed that in ImageAnchorDemo, the MultiARController's 'Point Cloud Prefab' is set to 'None (Game Object)', whereas in every other one of the demos its connected to the PointCloudPrefab. Is this as its supposed to be? I tried connecting it but still not working.
     
  30. briwil78

    briwil78

    Joined:
    Jan 3, 2015
    Posts:
    4
    Ohhh... create database....oops, got it!
     
    roumenf likes this.
  31. roumenf

    roumenf

    Joined:
    Dec 12, 2012
    Posts:
    635
    :)