ARKit support for iOS via Unity-ARKit-Plugin

Those devices will not work.
The devices that use A9 or A10 chips are:

  • iPhone 6s and 6s Plus
  • iPhone 7 and 7 Plus
  • iPhone SE
  • iPad Pro (9.7, 10.5 or 12.9)
  • iPad (2017)

Hi everyone,

Maybe someone can help me with this problem: I need to get the image that the ARCamera is showing in order to broadcast it.

So I tried to get the ARVideoTextureHandles from the ARSession interface, after that I use the UpdateExternalTexture method from Texture2D class for copying it, encoding it to PNG and converting it to base64 so I can send it through a network connection.

When I receive that base64 string in the server and decode it, the image is full of gray pixels.

Can someone help me sending the camera image through the network?

Thanks in advance

So your just trying to broadcast the devices camera feed, not the AR experience? This line from the tutorial.txt file might help you understand why you are seeing those pixels:

ā€œ7. On the main camera for the scene, add the UnityARVideo MonoBehaviour component, and set the clear material in the inspector to point to the YUVMaterial in the project. You can look in the source at what this does: every frame, it takes the two textures that make up the video that ARKit wants to display from the camera, and uses the YUVMaterial shader to combine them into the background that is rendered by the camera. (see UnityARVideo,cs)ā€

I think someone has asked this question before on this thread, if you do a little search a suggestion was posted.

Does anyone know if I can ā€œtransportā€ the Camera/user to a different part of a scene? Or similarly, maybe swap to a different camera?

Playing with the ARCameraManager components hasn’t yielded any results.

Can anyone confirm that the position of the Unity camera will always be tied to the ARKit’s camera?

Unity camera that is specified in ARCameraManager will always have its transform updated by the input pose provided by ARKit. If you want to move to another area of the scene, you can instead move the rest of the scene in the opposite direction in relation to the camera as has been described in previous posts. You can use other cameras that are not affected by the transform sent by ARKit, but then basically you will not be using ARKit to ā€œsteerā€ the camera.

Thank you for confirming my suspicions, and I appreciate the feedback. I was hoping I would not have to move the entire scene.

To clarify, if I update the camera in ARCameraManager with SetCamera midway through a play, will it be controlled by the input pose from ARKit? Maybe also reinitialize the tracking session?

Hi all,

We have added support for three features that were missing.
1.) Add/Remove Anchors
2.) Callbacks for ARKit Session Interruption status
3.) A callback for ARKit tracking changed events.

There is a new example scene named AddRemoveAnchorScene, that uses a new component named UnityARUserAnchorComponent. This component adds/removes anchors to ARKit based on the life cycle of the object. This is one way to use the add/remove anchor API, but don’t feel limited by our implementation. If you want to implement your own version, there are methods on UnityARSessionNativeInterface named AddUserAnchor, AddUserAnchorFromGameObject, and RemoveUserAnchor.

ARKit provides callbacks for when a session is interrupted (app going to background/phone call/etc.), and when the interruption has ended. You can now subscribe to these events through the plugin. The events exist on the UnityARSessionNativeInterface and are named ARSessionInterruptedEvent and ARSessioninterruptionEndedEvent.

ARKit also provides a callback for when the tracking state changes. You can now subscribe to the ARSessionTrackingChangedEvent on UnityARSessionNativeInterface.

The asset store package will take a couple of days to update, but you can get it from the bitbucket repository immediately here.
As always, please let us know if you have any feedback. We will be watching the forums.

Cheers,
Chris

edit: Mentioning people that requested these
@lusas @rockstarsaad @roooo

I built and loaded UnityParticlePainter with no problem but I’m only getting blue screen and the Color Picker? Is there something I’m doing wrong?

Thanks for the great work guys! Just voicing as well that Vuforia support would be really appreciated! :slight_smile: We’re a team building a big installation with multiple users walking around in a VR environment. We’ve been doing lots of other kinds of tracking, but the flexibility and ease of implementation of ARkit is really a plus. The only downside is that we’re afraid of users getting sidetracked. Of course we’ll give them extra physical space for the expected drifting (this is art :wink: It’s not meant to be perfect), but having different areas where a marker could get the scene back on track would just be so useful!

I’ve done a little test of my own in ARkit, by calibrating 3 predefined locations and setting the scene at their average while rotating the scene towards the green location I could get a room mesh to fit quite well (see result around 53sec):

The green mesh is scanned using a Hololens and was just for reference. I’m sorry it probably looks pretty confusing, but it helped getting an idea of tracking quality. You can especially see drifitng along the staircase and upstairs when looking at the pillar. And later when I go downstairs again the 3 locations are slightly misplaced.
On the plus side I learned that a Hololens scan is 1:1 with the ARkit world.

I actually find this challenge super fun :slight_smile: Someone mentioned Beakons as well. I’ve also been considering simply having some dedicated Vive tracking areas and then just using the ARkit as a transportation tracking between the Vive areas. So every time the user gets close to the Vive border the ARkit would take over, while at the same time also do a slight adjustment of the world so it aligns again… of course this is not really easy to scale and implement :eyes:

hi there, i have the same problem previously and here is how i solve it and my guess.

I have two copy of xcode in my mac (8.1 and 9 beta 3), i manually open the Simulator under
ā€œ/Applications/Xcode-beta.app/Contents/Developer/Applications/ā€
close it and restart xcode, and everything works.

i guess it is because xcode 9 beta somehow referring to the old xcode 8 path for the simulator thing.

hope it helps.

Hi, I have the Far and Near script already attached, but its still clipping at a very close range. Any ideas?

I was trying to build AR Application with Unity-ARKit-Plugin but it failed to compile because Unity uses some Metal classes, but in Simulator mode, only OpenGL is supported.

Errors in ARSessionNative.mm:

CVMetalTextureCacheRef _textureCache; unknown type name and so on

I don’t have a solution, but I have experienced the same issue. I’ve confirmed that I have the code from this commit, but I still find that the far clipping plane is set to 30. I didn’t dig any deeper.

Hi @mmortall ,
As of right now, only Metal is supported for the ARKit plugin.
Cheers,
Chris

Hi @theiajsanchez ,
It sounds like you may be sending only one of the textures over the network which is a luminance map. Which would be grayscale. One option would be to render it to a render texture, then read the pixels back as RGB, encode as PNG and then send it over the network. The other option is that you could send both textures over the Y and UV, then combine them on the other side of the connection in a shader like we do in the plugin. Let me know if this helps
Cheers,
Chris

Hey @Staus ,
When you say ā€œVuforia support would be really appreciated!ā€ Do you mean the features that Vuforia has, or the actual Vuforia sdk? Could you expand on that a bit?
Cheers,
Chris

Did you actually change the far clipping plane value on the camera to be larger? The script reads the value you have set on the camera.

Hi all, getting some two different crashes in xCode on two different iOS devices:

Dev set up:

  • Unity 2017.1.0f3
  • xCode 9.0 beta 3 (9M174d)
  • OSX High Sierra

Phones / Crash Info:
- iPhone 6s - iOS11 (15A5278f)
xCode Crash on run ā€œdyld: Symbol not found: OBJC_CLASS$_MTLToolsArgumentEncoder
Referenced from: /Developer/Library/PrivateFrameworks/MTLToolsDeviceSupport.framework/libMTLInterpose.dylib
Expected in: /System/Library/PrivateFrameworks/MetalTools.framework/MetalTools
in /Developer/Library/PrivateFrameworks/MTLToolsDeviceSupport.framework/libMTLInterpose.dylibā€

However this app does run on device by itself

- iPhone 6s - iOS11 (15A5318g)
xCode Crash on run " Uncaught exception: UnrecognizedARTrackingStateReason: Unrecognized ARTrackingStateReason: 1"

When app is run on device alone, it crashes as soon as camera turns on

Thoughts?
Thanks!
J

Hi @christophergoy thanks for answering! Can you give us some help with the steps you mentioned? Actually I don’t know how to render the texture into a render texture, neither read the pixels back as RGB.

This is what we tried (without success):
Code

public class  SuperControlador : MonoBehaviour 
{
        private WebSocketController ws;

        private Texture2D tex;

        // Use this for initialization
        void Start ()
        {
            Application.runInBackground = true;

            ws = WebSocketController.GetInstance();

            tex = new Texture2D(100, 100);
        }

        void Update()
        {
            RenderTexture rt = new RenderTexture(100, 100, 24, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default);
            rt.antiAliasing = 1;
            rt.filterMode = FilterMode.Bilinear;
            rt.useMipMap = false;
            rt.wrapMode = TextureWrapMode.Clamp;

            if (rt.Create())
            {
                Shader.SetGlobalTexture(Shader.PropertyToID("_textureY"), rt);

                RenderTexture.active = rt;
                tex.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0);
                tex.Apply();

                ws.SendMessage(Convert.ToBase64String(tex.EncodeToPNG()), "stream");
            }
       }
}

Thanks in advance

Hi @TJUnityBuilder ,
The second crash is due to your plugin being out of date. If you update to the latest (either bitbucket or asset store) you should not get the UnrecognizedARTrackingStateReason assert anymore.

For the first crash, is the iOS 11 build older or newer?
Cheers,
Chris