예제 #1
0
        void ProcessLatestFrame()
        {
            if (!EnableProcessing)
            {
                return;
            }

            if (cloudSpatialAnchorSession == null)
            {
                throw new InvalidOperationException("Cloud spatial anchor session is not available.");
            }

            var nativeSession = GoogleARCoreInternal.ARCoreAndroidLifecycleManager.Instance.NativeSession;

            if (nativeSession.FrameHandle == IntPtr.Zero)
            {
                return;
            }

            long latestFrameTimeStamp = nativeSession.FrameApi.GetTimestamp();

            bool newFrameToProcess = latestFrameTimeStamp > lastFrameProcessedTimeStamp;

            if (newFrameToProcess)
            {
                cloudSpatialAnchorSession.ProcessFrame(nativeSession.FrameHandle);
                lastFrameProcessedTimeStamp = latestFrameTimeStamp;
            }
        }
예제 #2
0
        /// <summary>
        /// Sends the latest ARFoundation frame to Azure Spatial Anchors
        /// </summary>
        private void ProcessLatestFrame()
        {
            if (!isSessionStarted)
            {
                return;
            }

            var cameraParams = new XRCameraParams
            {
                zNear             = mainCamera.nearClipPlane,
                zFar              = mainCamera.farClipPlane,
                screenWidth       = Screen.width,
                screenHeight      = Screen.height,
                screenOrientation = Screen.orientation
            };

            XRCameraFrame xRCameraFrame;

            if (arCameraManager.subsystem.TryGetLatestFrame(cameraParams, out xRCameraFrame))
            {
                long latestFrameTimeStamp = xRCameraFrame.timestampNs;

                bool newFrameToProcess = latestFrameTimeStamp > lastFrameProcessedTimeStamp;

                if (newFrameToProcess)
                {
                    session.ProcessFrame(xRCameraFrame.nativePtr.GetPlatformPointer());
                    lastFrameProcessedTimeStamp = latestFrameTimeStamp;
                }
            }
        }
예제 #3
0
        // Android-Specific Internal Methods
        #if UNITY_ANDROID
        private void ProcessLatestFrame()
        {
            if (!isSessionStarted)
            {
                return;
            }

            var nativeSession = GoogleARCoreInternal.ARCoreAndroidLifecycleManager.Instance.NativeSession;

            if (nativeSession.FrameHandle == IntPtr.Zero)
            {
                return;
            }

            long latestFrameTimeStamp = nativeSession.FrameApi.GetTimestamp();

            bool newFrameToProcess = latestFrameTimeStamp > lastFrameProcessedTimeStamp;

            if (newFrameToProcess)
            {
                session.ProcessFrame(nativeSession.FrameHandle);
                lastFrameProcessedTimeStamp = latestFrameTimeStamp;
            }
        }
예제 #4
0
        public virtual void OnUpdateScene(double timeInSeconds)
        {
            // Note: Always a super-tricky thing in ARKit : must get rid of the managed reference to the Frame object ASAP.
            using (ARFrame frame = sceneView?.Session?.CurrentFrame)
            {
                if (frame == null)
                {
                    return;
                }

                if (cloudSession == null)
                {
                    return;
                }

                cloudSession.ProcessFrame(frame);

                if (currentlyPlacingAnchor && enoughDataForSaving && localAnchor != null)
                {
                    CreateCloudAnchor();
                }
            }
        }
예제 #5
0
    private async Task createSessionAsync()
    {
        if (cloudSession != null)
        {
            //session already created, need to exit
            return;
        }



        cloudSession = new CloudSpatialAnchorSession();
        cloudSession.Configuration.AccountId   = "87f0e62e-2379-4bc4-bd1e-38dc699e8d6b";
        cloudSession.Configuration.AccessToken = "kF/SejjecfM8CatFa74V94iAsgApvPiaT1mY//qgK44=";
        cloudSession.Session = aRSession.subsystem.nativePtr.GetPlatformPointer();


#if UNITY_ANDROID // Android Only
        // We should only run the Java initialization once
        if (!javaInitialized)
        {
            // Create a TaskCompletionSource that we can use to know when
            // the Java plugin has completed initialization on the Android
            // thread.
            TaskCompletionSource <bool> pluginInit = new TaskCompletionSource <bool>();

            // Make sure ARCore is running. This code must be executed
            // on a Java thread provided by Android.
            AndroidHelper.Instance.DispatchUiThread(unityActivity =>
            {
                // Create the plugin
                using (AndroidJavaClass cloudServices = new AndroidJavaClass("com.microsoft.CloudServices"))
                {
                    // Initialize the plugin
                    cloudServices.CallStatic("initialize", unityActivity);

                    // Update static variable to say that the plugin has been initialized
                    javaInitialized = true;

                    // Set the task completion source so the CreateSession method can
                    // continue back on the Unity thread.
                    pluginInit.SetResult(true);
                }
            });

            // Wait for the plugin to complete initialization on the
            // Java thread.
            await pluginInit.Task;
        }
#endif


#if UNITY_ANDROID || UNITY_IOS
        var cameraParams = new XRCameraParams
        {
            zNear             = Camera.main.nearClipPlane,
            zFar              = Camera.main.farClipPlane,
            screenWidth       = Screen.width,
            screenHeight      = Screen.height,
            screenOrientation = Screen.orientation
        };

        XRCameraFrame xRCameraFrame;
        if (aRCameraManager.subsystem.TryGetLatestFrame(cameraParams, out xRCameraFrame))
        {
            long latestFrameTimeStamp = xRCameraFrame.timestampNs;

            bool newFrameToProcess = latestFrameTimeStamp > lastFrameProcessedTimeStamp;

            if (newFrameToProcess)
            {
                cloudSession.ProcessFrame(xRCameraFrame.nativePtr.GetPlatformPointer());
                lastFrameProcessedTimeStamp = latestFrameTimeStamp;
            }
        }
#endif
    }
 public void Update(Google.AR.Core.Frame frame)
 {
     spatialAnchorsSession.ProcessFrame(frame);
 }