Beispiel #1
0
        static void Register()
        {
            if (!Api.platformAndroid || !Api.loaderPresent)
            {
                return;
            }

            var cameraSubsystemCinfo = new XRCameraSubsystemCinfo
            {
                id                               = k_SubsystemId,
                providerType                     = typeof(ARCoreCameraSubsystem.ARCoreProvider),
                subsystemTypeOverride            = typeof(ARCoreCameraSubsystem),
                supportsAverageBrightness        = true,
                supportsAverageColorTemperature  = false,
                supportsColorCorrection          = true,
                supportsDisplayMatrix            = true,
                supportsProjectionMatrix         = true,
                supportsTimestamp                = true,
                supportsCameraConfigurations     = true,
                supportsCameraImage              = true,
                supportsAverageIntensityInLumens = false,
                supportsFocusModes               = true,
                supportsFaceTrackingAmbientIntensityLightEstimation = true,
                supportsFaceTrackingHDRLightEstimation = false,
                supportsWorldTrackingAmbientIntensityLightEstimation = true,
                supportsWorldTrackingHDRLightEstimation = true,
                supportsCameraGrain = false,
            };

            if (!XRCameraSubsystem.Register(cameraSubsystemCinfo))
            {
                Debug.LogError($"Failed to register the {k_SubsystemId} subsystem.");
            }
        }
Beispiel #2
0
        /// <summary>
        /// Attempt to get the latest camera image. This provides directly access to the raw
        /// pixel data, as well as utilities to convert to RGB and Grayscale formats.
        /// The <see cref="CameraImage"/> must be disposed to avoid resource leaks.
        /// </summary>
        /// <param name="cameraSubsystem">The <c>XRCameraSubsystem</c> being extended.</param>
        /// <param name="cameraImage"></param>
        /// <returns></returns>
        public static bool TryGetLatestImage(
            this XRCameraSubsystem cameraSubsystem,
            out CameraImage cameraImage)
        {
            if (cameraSubsystem == null)
            {
                throw new ArgumentNullException("cameraSubsystem");
            }

            int               nativeHandle;
            Vector2Int        dimensions;
            int               planeCount;
            double            timestamp;
            CameraImageFormat format;

            if (s_AsyncCameraImageApi.TryAcquireLatestImage(out nativeHandle, out dimensions, out planeCount, out timestamp, out format))
            {
                cameraImage = new CameraImage(s_AsyncCameraImageApi, nativeHandle, dimensions, planeCount, timestamp, format);
                return(true);
            }
            else
            {
                cameraImage = default(CameraImage);
                return(false);
            }
        }
        static void Register()
        {
            const string id = "ARKit-Camera-Remote";

#if UNITY_EDITOR
            XRCameraSubsystemCinfo cameraSubsystemCinfo = new XRCameraSubsystemCinfo
            {
                id = id,
                implementationType              = typeof(ARKitCameraRemoteSubsystem),
                supportsAverageBrightness       = false,
                supportsAverageColorTemperature = true,
                supportsColorCorrection         = false,
                supportsDisplayMatrix           = true,
                supportsProjectionMatrix        = true,
                supportsTimestamp                = true,
                supportsCameraConfigurations     = true,
                supportsCameraImage              = true,
                supportsAverageIntensityInLumens = true
            };

            if (!XRCameraSubsystem.Register(cameraSubsystemCinfo))
            {
                Debug.LogErrorFormat("Cannot register the {0} subsystem", id);
            }
            else
            {
                Debug.LogFormat("Registered the {0} subsystem", id);
            }
#endif // UNITY_EDITOR
        }
        static void Register()
        {
            if (!Api.AtLeast11_0())
            {
                return;
            }

            XRCameraSubsystemCinfo cameraSubsystemCinfo = new XRCameraSubsystemCinfo
            {
                id = k_SubsystemId,
                implementationType              = typeof(ARKitCameraSubsystem),
                supportsAverageBrightness       = false,
                supportsAverageColorTemperature = true,
                supportsColorCorrection         = false,
                supportsDisplayMatrix           = true,
                supportsProjectionMatrix        = true,
                supportsTimestamp                = true,
                supportsCameraConfigurations     = true,
                supportsCameraImage              = true,
                supportsAverageIntensityInLumens = true,
                supportsFocusModes               = true,
                supportsFaceTrackingAmbientIntensityLightEstimation = true,
                supportsFaceTrackingHDRLightEstimation = true,
                supportsWorldTrackingAmbientIntensityLightEstimation = true,
                supportsWorldTrackingHDRLightEstimation = false,
            };

            if (!XRCameraSubsystem.Register(cameraSubsystemCinfo))
            {
                Debug.LogErrorFormat("Cannot register the {0} subsystem", k_SubsystemId);
            }
        }
        static void Register()
        {
#if UNITY_IOS && !UNITY_EDITOR
            XRCameraSubsystemCinfo cameraSubsystemCinfo = new XRCameraSubsystemCinfo
            {
                id = k_SubsystemId,
                implementationType              = typeof(ARKitCameraSubsystem),
                supportsAverageBrightness       = false,
                supportsAverageColorTemperature = true,
                supportsColorCorrection         = false,
                supportsDisplayMatrix           = true,
                supportsProjectionMatrix        = true,
                supportsTimestamp                = true,
                supportsCameraConfigurations     = true,
                supportsCameraImage              = true,
                supportsAverageIntensityInLumens = true,
                supportsFocusModes               = true,
            };

            if (!XRCameraSubsystem.Register(cameraSubsystemCinfo))
            {
                Debug.LogErrorFormat("Cannot register the {0} subsystem", k_SubsystemId);
            }
#endif // UNITY_IOS && !UNITY_EDITOR
        }
Beispiel #6
0
    private void Start()
    {
        xrCameraSubsystem = arCameraManager.subsystem;
        string token = AccessToken.getAccessToken();

        Debug.Log("token:" + token);
        tokenJson = JsonUtility.FromJson <TokenJson>(token);
    }
Beispiel #7
0
        /// <summary>
        /// Attempts to retrieve color correction data for the extended <c>XRCameraSubsystem</c>.
        /// The color correction data represents the scaling factors used for color correction.
        /// The RGB scale factors are used to match the color of the light
        /// in the scene. The alpha channel value is platform-specific.
        /// </summary>
        /// <param name="cameraSubsystem">The <c>XRCameraSubsystem</c> being extended.</param>
        /// <param name="color">The <c>Color</c> representing the color correction value.</param>
        /// <returns><c>True</c> if the data is available, otherwise <c>False</c>.</returns>
        public static bool TryGetColorCorrection(this XRCameraSubsystem cameraSubsystem, out Color color)
        {
            if (cameraSubsystem == null)
            {
                throw new ArgumentNullException("cameraSubsystem");
            }

            return(s_TryGetColorCorrectionDelegate(cameraSubsystem, out color));
        }
        /// <summary>
        /// Attempt to get the hardware camera's intrinsics. Intrinsics describe physical
        /// characteristics of a camera, which may be necessary to perform
        /// computer vision algorithms or other processing.
        /// </summary>
        /// <param name="cameraSubsystem">The <c>XRCameraSubsystem</c> being extended.</param>
        /// <param name="cameraIntrinsics">If this method returns <c>true</c>, this parameter will be
        /// populated with intrinsics describing the physical camera.</param>
        /// <returns><c>true</c> if successful, otherwise <c>false</c>.</returns>
        public static bool TryGetIntrinsics(this XRCameraSubsystem cameraSubsystem, out CameraIntrinsics cameraIntrinsics)
        {
            if (cameraSubsystem == null)
            {
                throw new ArgumentNullException("cameraSubsystem");
            }

            return(s_TryGetIntrinsicsDelegate(cameraSubsystem, out cameraIntrinsics));
        }
Beispiel #9
0
        /// <summary>
        /// Retrieve a native <c>IntPtr</c> associated with the <c>XRCameraSubsystem</c>.
        /// </summary>
        /// <param name="cameraSubsystem">The <c>XRCameraSubsystem</c> being extended.</param>
        /// <returns>An <c>IntPtr</c> associated with <paramref name="cameraSubsystem"/>.</returns>
        public static IntPtr GetNativePtr(this XRCameraSubsystem cameraSubsystem)
        {
            if (cameraSubsystem == null)
            {
                throw new ArgumentNullException("cameraSubsystem");
            }

            return(s_GetNativePtrDelegate(cameraSubsystem));
        }
Beispiel #10
0
        /// <summary>
        /// Allows you to determine whether camera permission has been granted.
        /// </summary>
        /// <param name="cameraSubsystem">The <c>XRCameraSubsystem</c> being extended.</param>
        /// <returns>True if camera permission has been granted for this app, false otherwise.</returns>
        public static bool IsPermissionGranted(this XRCameraSubsystem cameraSubsystem)
        {
            if (cameraSubsystem == null)
            {
                throw new ArgumentNullException("cameraSubsystem");
            }

            return(s_IsPermissionGrantedDelegate(cameraSubsystem));
        }
 public void RegisterTestDescriptor()
 {
     XRCameraSubsystem.Register(new XRCameraSubsystemCinfo
     {
         id                    = "Test-Camera",
         providerType          = typeof(XRCameraSubsystemImpl.ProviderImpl),
         subsystemTypeOverride = typeof(XRCameraSubsystemImpl)
     });
 }
        /// <summary>
        /// Attempt to set the <see cref="CameraFocusMode"/>.
        /// </summary>
        /// <param name="cameraSubsystem">The <c>XRCameraSubsystem</c> being extended.</param>
        /// <param name="mode">The <see cref="CameraFocusMode"/> to use.</param>
        /// <returns><c>true</c> if the focus mode was successfully set; <c>false</c> otherwise.</returns>
        public static bool TrySetFocusMode(this XRCameraSubsystem cameraSubsystem, CameraFocusMode mode)
        {
            if (cameraSubsystem == null)
            {
                throw new ArgumentNullException("cameraSubsystem");
            }

            return(s_TrySetFocusModeDelegate(cameraSubsystem, mode));
        }
Beispiel #13
0
        void OnDestroy()
        {
            if (subsystem != null)
            {
                subsystem.Destroy();
            }

            subsystem = null;
        }
        /// <summary>
        /// Get the current <see cref="CameraConfiguration"/>. If camera configurations
        /// are not supported, or if the session is not active, this method may throw
        /// <c>InvalidOperationException</c>.
        ///
        /// Camera configurations are unsupported if
        /// <see cref="Configurations()"/> returns a collection with <see cref="CameraConfigurationCollection.count"/> of zero.
        /// </summary>
        /// <param name="cameraSubsystem">The <c>XRCameraSubsystem</c> being extended.</param>
        /// <returns>The currently active <see cref="CameraConfiguration"/>.</returns>
        public static CameraConfiguration GetCurrentConfiguration(
            this XRCameraSubsystem cameraSubsystem)
        {
            if (cameraSubsystem == null)
            {
                throw new ArgumentNullException("cameraSubsystem");
            }

            return(s_CameraConfigApi.currentConfiguration);
        }
        /// <summary>
        /// Enumerate the <see cref="CameraConfiguration"/>s supported by the device.
        /// </summary>
        /// <example>
        /// You can use <see cref="Configurations(XRCameraSubsystem)"/> in a <c>foreach</c> statement:
        /// <code>
        /// foreach (var config in cameraSubsystem.Configurations())
        ///     Debug.Log(config);
        /// </code>
        /// </example>
        /// <param name="cameraSubsystem">The <c>XRCameraSubsystem</c> being extended.</param>
        /// <returns>A <see cref="CameraConfigurationCollection"/>, which allows you to
        /// enumerate the supported configurations.</returns>
        public static CameraConfigurationCollection Configurations(
            this XRCameraSubsystem cameraSubsystem)
        {
            if (cameraSubsystem == null)
            {
                throw new ArgumentNullException("cameraSubsystem");
            }

            return(new CameraConfigurationCollection(s_CameraConfigApi));
        }
Beispiel #16
0
        static bool TryGetColorCorrection(XRCameraSubsystem cameraSubsystem, out Color color)
        {
            if (CameraApi.colorCorrection.HasValue)
            {
                color = CameraApi.colorCorrection.Value;
                return(true);
            }

            color = default(Color);
            return(false);
        }
        /// <summary>
        /// Set a <see cref="CameraConfiguration"/> to be the active one. Throws if the
        /// camera configuration is not supported by the device.
        /// You can enumerate the available configurations with
        /// <seealso cref="Configurations(XRCameraSubsystem)"/>.
        ///
        /// The camera image configuration affects the resolution of the <see cref="CameraImage"/>
        /// provided by <see cref="TryGetLatestImage(XRCameraSubsystem, out CameraImage)"/>.
        /// It may also affect the camera framerate. See <see cref="CameraConfiguration.framerate"/>.
        ///
        /// Setting this value may cause the device to relocalize, similar to stopping and restarting
        /// the session.
        ///
        /// All <see cref="CameraImage"/>s should be disposed and all asynchronous conversion operations
        /// completed prior to setting the configuration or the this method may throw
        /// <c>InvalidOperationException</c>, depending on the platform.
        /// </summary>
        /// <param name="cameraSubsystem">The <c>XRCameraSubsystem</c> being extended.</param>
        /// <param name="configuration">A configuration to use. This is typically one of the
        /// configurations returned by <see cref="GetConfiguration(XRCameraSubsystem, int)"/>.</param>
        public static void SetCurrentConfiguration(
            this XRCameraSubsystem cameraSubsystem,
            CameraConfiguration configuration)
        {
            if (cameraSubsystem == null)
            {
                throw new ArgumentNullException("cameraSubsystem");
            }

            s_CameraConfigApi.currentConfiguration = configuration;
        }
        static void Register()
        {
            XRCameraSubsystem.Register(new XRCameraSubsystemCinfo
            {
                id = "MARS-Camera",
#if ARSUBSYSTEMS_4_OR_NEWER && UNITY_2020_2_OR_NEWER
                providerType          = typeof(CameraSubsystem.MARSXRProvider),
                subsystemTypeOverride = typeof(CameraSubsystem),
#else
                implementationType = typeof(CameraSubsystem),
#endif
            });
        }
Beispiel #19
0
        void OnEnable()
        {
            if (subsystem == null)
            {
                subsystem = CreateSubsystem();
            }

            if (subsystem != null)
            {
                subsystem.focusMode           = m_FocusMode;
                subsystem.lightEstimationMode = m_LightEstimationMode;
                subsystem.Start();
            }
        }
        public void RunningStateTests()
        {
            XRCameraSubsystem subsystem = CreateTestCameraSubsystem();

            // Initial state is not running
            Assert.That(subsystem.running == false);

            // After start subsystem is running
            subsystem.Start();
            Assert.That(subsystem.running == true);

            // After start subsystem is running
            subsystem.Stop();
            Assert.That(subsystem.running == false);
        }
Beispiel #21
0
        static bool TryGetColorCorrection(XRCameraSubsystem cameraSubsystem, out Color color)
        {
            float r, g, b, a;

            if (Api.UnityARCore_tryGetColorCorrection(out r, out g, out b, out a))
            {
                color = new Color(r, g, b, a);
                return(true);
            }
            else
            {
                color = default(Color);
                return(false);
            }
        }
Beispiel #22
0
        /// <summary>
        /// For internal use. Sets the active subsystem whose extension methods should be used.
        /// </summary>
        /// <param name="cameraSubsystem">The <c>XRCameraSubsystem</c> being extended.</param>
        public static void ActivateExtensions(this XRCameraSubsystem cameraSubsystem)
        {
            if (cameraSubsystem == null)

            {
                SetDefaultDelegates();
            }
            else
            {
                var id = cameraSubsystem.SubsystemDescriptor.id;
                s_IsPermissionGrantedDelegate   = RegistrationHelper.GetValueOrDefault(s_IsPermissionGrantedDelegates, id, DefaultIsPermissionGranted);
                s_TryGetColorCorrectionDelegate = RegistrationHelper.GetValueOrDefault(s_TryGetColorCorrectionDelegates, id, DefaultTryGetColorCorrection);
                s_GetNativePtrDelegate          = RegistrationHelper.GetValueOrDefault(s_GetNativePtrDelegates, id, DefaultGetNativePtr);
                s_AsyncCameraImageApi           = RegistrationHelper.GetValueOrDefault(s_CameraImageApis, id, s_DefaultAsyncCameraImageApi);
            }
        }
Beispiel #23
0
        static void Register()
        {
            XRCameraSubsystemCinfo cameraSubsystemCinfo = new XRCameraSubsystemCinfo();

            cameraSubsystemCinfo.id = k_SubsystemId;
            cameraSubsystemCinfo.implementationType              = typeof(ARKitCameraSubsystem);
            cameraSubsystemCinfo.supportsAverageBrightness       = true;
            cameraSubsystemCinfo.supportsAverageColorTemperature = true;
            cameraSubsystemCinfo.supportsDisplayMatrix           = true;
            cameraSubsystemCinfo.supportsProjectionMatrix        = true;
            cameraSubsystemCinfo.supportsTimestamp = true;

            if (!XRCameraSubsystem.Register(cameraSubsystemCinfo))
            {
                Debug.LogErrorFormat("Cannot register the {0} subsystem", k_SubsystemId);
            }
        }
        /// <summary>
        /// Allows you to determine whether camera permission has been granted.
        /// </summary>
        /// <param name="cameraSubsystem">The <c>XRCameraSubsystem</c> being extended.</param>
        /// <returns>True if camera permission has been granted for this app, false otherwise.</returns>
        public static bool IsPermissionGranted(this XRCameraSubsystem cameraSubsystem)
        {
            if (cameraSubsystem == null)
            {
                throw new ArgumentNullException("cameraSubsystem");
            }

            Func <XRCameraSubsystem, bool> handler;

            if (s_IsPermissionGrantedDelegates.TryGetValue(cameraSubsystem.SubsystemDescriptor.id, out handler))
            {
                return(handler(cameraSubsystem));
            }
            else
            {
                return(true);
            }
        }
        static void Register()
        {
            XRCameraSubsystemCinfo cameraSubsystemCinfo = new XRCameraSubsystemCinfo
            {
                id = k_SubsystemId,
                implementationType              = typeof(ARCoreCameraSubsystem),
                supportsAverageBrightness       = true,
                supportsAverageColorTemperature = false,
                supportsColorCorrection         = true,
                supportsDisplayMatrix           = true,
                supportsProjectionMatrix        = true,
                supportsTimestamp = true
            };

            if (!XRCameraSubsystem.Register(cameraSubsystemCinfo))
            {
                Debug.LogErrorFormat("Cannot register the {0} subsystem", k_SubsystemId);
            }
        }
        /// <summary>
        /// Attempts to retrieve color correction data for the extended <c>XRCameraSubsystem</c>.
        /// The color correction data represents the scaling factors used for color correction.
        /// The RGB scale factors are used to match the color of the light
        /// in the scene. The alpha channel value is platform-specific.
        /// </summary>
        /// <param name="cameraSubsystem">The <c>XRCameraSubsystem</c> being extended.</param>
        /// <param name="color">The <c>Color</c> representing the color correction value.</param>
        /// <returns><c>True</c> if the data is available, otherwise <c>False</c>.</returns>
        public static bool TryGetColorCorrection(this XRCameraSubsystem cameraSubsystem, out Color color)
        {
            if (cameraSubsystem == null)
            {
                throw new ArgumentNullException("cameraSubsystem");
            }

            TryGetColorCorrectionDelegate handler;

            if (s_TryGetColorCorrectionDelegates.TryGetValue(cameraSubsystem.SubsystemDescriptor.id, out handler))
            {
                return(handler(cameraSubsystem, out color));
            }
            else
            {
                color = default(Color);
                return(false);
            }
        }
        private void Initialize()
        {
            if (this.isInitialized)
            {
                return;
            }

            if (!UnityXRMockActivator.Active)
            {
                if (originalDescriptor == null)
                {
                    originalDescriptor = GetSubsystemDescriptor();
                }

                this.wrappedSubsystem = originalDescriptor?.Create();
            }

            this.isInitialized = true;
        }
Beispiel #28
0
        static void Register()
        {
#if UNITY_EDITOR
            XRCameraSubsystemCinfo cameraSubsystemCinfo = new XRCameraSubsystemCinfo
            {
                id = ID,
#if UNITY_2020_2_OR_NEWER
                providerType          = typeof(MockCameraSubsystem.MockProvider),
                subsystemTypeOverride = typeof(MockCameraSubsystem),
#else
                implementationType = typeof(MockCameraSubsystem),
#endif

                supportsAverageBrightness       = false,
                supportsAverageColorTemperature = true,
                supportsColorCorrection         = false,
                supportsDisplayMatrix           = true,
                supportsProjectionMatrix        = true,
                supportsTimestamp                = true,
                supportsCameraConfigurations     = true,
                supportsCameraImage              = true,
                supportsAverageIntensityInLumens = true,
                supportsFocusModes               = true,
                supportsFaceTrackingAmbientIntensityLightEstimation = true,
                supportsFaceTrackingHDRLightEstimation = true,
                supportsWorldTrackingAmbientIntensityLightEstimation = true,
                supportsWorldTrackingHDRLightEstimation = false,
            };

            if (!XRCameraSubsystem.Register(cameraSubsystemCinfo))
            {
                Debug.LogErrorFormat("Cannot register the {0} subsystem", ID);
            }
            else
            {
                Debug.LogFormat("Registered the {0} subsystem", ID);
            }
#endif // UNITY_EDITOR
        }
Beispiel #29
0
 static IntPtr DefaultGetNativePtr(XRCameraSubsystem cameraSubsystem)
 {
     return(IntPtr.Zero);
 }
Beispiel #30
0
 static bool DefaultTryGetColorCorrection(XRCameraSubsystem cameraSubsystem, out Color color)
 {
     color = default(Color);
     return(false);
 }