/// <summary>
        /// Gets the state of localization against the global Earth map.
        /// </summary>
        /// <param name="cameraManager">The ARCameraManager instance.</param>
        /// <returns>The Earth localization state against the global Earth map.</returns>
        public static EarthLocalizationState GetEarthLocalizationState(
            this ARCameraManager cameraManager)
        {
            EarthLocalizationState state = EarthLocalizationState.NotLocalized;
            var cameraParams             = new XRCameraParams
            {
                zNear             = cameraManager.GetComponent <Camera>().nearClipPlane,
                zFar              = cameraManager.GetComponent <Camera>().farClipPlane,
                screenWidth       = Screen.width,
                screenHeight      = Screen.height,
                screenOrientation = Screen.orientation
            };

            if (!cameraManager.subsystem.TryGetLatestFrame(cameraParams, out XRCameraFrame frame))
            {
                Debug.LogWarning("Unable to determine the current EarthLocalizationState, " +
                                 "the current XRCameraFrame is not available, try again later.");
                return(state);
            }

            if (frame.timestampNs == 0 || frame.FrameHandle() == IntPtr.Zero)
            {
                Debug.LogWarning("Unable to determine the current EarthLocalizationState, " +
                                 "the current frame is not ready, try again later.");
                return(state);
            }

            return(FrameApi.GetEarthLocalizationState(
                       ARCoreExtensions._instance.currentARCoreSessionHandle, frame.FrameHandle()));
        }
Пример #2
0
        private static bool TryGetLastFrameFromExtensions(out XRCameraFrame frame)
        {
            ARCoreExtensions extensions    = ARCoreExtensions._instance;
            ARCameraManager  cameraManager = extensions.CameraManager;
            var cameraParams = new XRCameraParams
            {
                zNear             = cameraManager.GetComponent <Camera>().nearClipPlane,
                zFar              = cameraManager.GetComponent <Camera>().farClipPlane,
                screenWidth       = Screen.width,
                screenHeight      = Screen.height,
                screenOrientation = Screen.orientation
            };

            if (!cameraManager.subsystem.TryGetLatestFrame(
                    cameraParams, out frame))
            {
                Debug.LogWarning(
                    "The current XRCameraFrame is not available, try again later.");
                return(false);
            }

            if (frame.timestampNs == 0 || frame.FrameHandle() == IntPtr.Zero)
            {
                Debug.LogWarning(
                    "The current XRCameraFrame is not ready, try again later.");
                return(false);
            }

            return(true);
        }
Пример #3
0
        /// <summary>
        /// Gets the set of data recorded to the given track available during playback on this
        /// frame.
        /// Note, currently playback continues internally while the session is paused. Therefore, on
        /// pause/resume, track data discovered internally will be discarded to prevent stale track
        /// data from flowing through when the session resumed.
        /// Note, if the app's frame rate is higher than ARCore's frame rate, subsequent
        /// <c><cref="XRCameraFrame"/></c> objects may reference the same underlying ARCore Frame,
        /// which would mean the list of <c><see cref="TrackData"/></c> returned could be the same.
        /// One can differentiate by examining <c><see cref="TrackData.FrameTimestamp"/></c>.
        /// </summary>
        /// <param name="trackId">The ID of the track being queried.</param>
        /// <returns>Returns a list of <see cref="TrackData"/>. Will be empty if none are available.
        /// </returns>
        public List <TrackData> GetUpdatedTrackData(Guid trackId)
        {
            if (ARCoreExtensions._instance.currentARCoreSessionHandle == IntPtr.Zero &&
                ARCoreExtensions._instance.Session.subsystem != null &&
                ARCoreExtensions._instance.Session.subsystem.nativePtr != null)
            {
                Debug.LogWarning("Failed to fetch track data. The Session is not yet available. " +
                                 "Try again later.");
                return(new List <TrackData>());
            }

            ARCameraManager cameraManager = ARCoreExtensions._instance.CameraManager;

            var cameraParams = new XRCameraParams
            {
                zNear             = cameraManager.GetComponent <Camera>().nearClipPlane,
                zFar              = cameraManager.GetComponent <Camera>().farClipPlane,
                screenWidth       = Screen.width,
                screenHeight      = Screen.height,
                screenOrientation = Screen.orientation
            };

            if (!cameraManager.subsystem.TryGetLatestFrame(cameraParams, out XRCameraFrame frame))
            {
                Debug.LogWarning("Failed to fetch track data. The current XRCameraFrame is not " +
                                 "available. Try again later.");
                return(new List <TrackData>());
            }

            if (frame.timestampNs == 0 || frame.nativePtr == IntPtr.Zero)
            {
                Debug.LogWarning("Failed to fetch track data. The current XRCameraFrame is not " +
                                 "ready. Try again later.");
                return(new List <TrackData>());
            }

            return(FrameApi.GetUpdatedTrackData(
                       ARCoreExtensions._instance.currentARCoreSessionHandle, frame.FrameHandle(),
                       trackId));
        }
Пример #4
0
    public Vector3 GetScreenPosition(GameObject finger)
    {
        //HERE. Which "transform" should I get? The UICancas finger?
        //The go this script is attached to?
        RectTransform rectTransform = (RectTransform)finger.transform;
        Vector4       worldLocation = rectTransform.localToWorldMatrix * new  Vector4(rectTransform.anchoredPosition3D.x,
                                                                                      rectTransform.anchoredPosition3D.y,
                                                                                      rectTransform.anchoredPosition3D.z,
                                                                                      1);

        //is it different using a arcamera?
        return(arCameraManager.GetComponent <Camera>().WorldToScreenPoint(new Vector3(worldLocation.x, worldLocation.y, worldLocation.z)));
    }
Пример #5
0
 protected virtual void Awake()
 {
     if (arManager == null)
     {
         arManager = GetComponent <ARCameraManager>();
     }
     if (arBackground == null)
     {
         arBackground = FindObjectOfType <ARCameraBackground>();
     }
     if (cameraFinal == null)
     {
         if (arManager != null)
         {
             cameraFinal = arManager.GetComponent <Camera>();
         }
     }
 }
 void Start()
 {
     targetCamera = this.gameObject.GetComponent <Camera>();
     arCamera     = arCameraManager.GetComponent <Camera>();
 }