Esempio n. 1
0
        public override bool TryGetCameraImage(ref Image image)
        {
            var handles = default(ARTextureHandles);

            //Preprocessor locked because 'GetARVideoTextureHandles' is not declared in all platforms
            #if !UNITY_EDITOR && UNITY_IOS
            handles = NativeInterface.GetARVideoTextureHandles();
            #endif

            if (!m_isTexturesInitialized || (handles.textureY == IntPtr.Zero || handles.textureCbCr == IntPtr.Zero))
            {
                return(false);
            }

            m_currentFrameIndex = (m_currentFrameIndex + 1) % 2;

            NativeInterface.SetCapturePixelData(true,
                                                HandleByteArray(ref m_YArrayHandle, YByteArrayForFrame(m_currentFrameIndex)),
                                                HandleByteArray(ref m_UVArrayHandle, UVByteArrayForFrame(m_currentFrameIndex))
                                                );

            image.y  = YByteArrayForFrame(1 - m_currentFrameIndex);
            image.uv = UVByteArrayForFrame(1 - m_currentFrameIndex);

            image.width  = m_cameraWidth;
            image.height = m_cameraHeight;

            return(true);
        }
Esempio n. 2
0
        public override void UpdateCamera(Camera _camera)
        {
            _camera.projectionMatrix = NativeInterface.GetCameraProjection();

            if (!m_isBackgroundRendering)
            {
                return;
            }

            var handles = default(ARTextureHandles);

            //Preprocessor locked because 'GetARVideoTextureHandles' is not declared in all platforms
            #if !UNITY_EDITOR && UNITY_IOS
            handles = NativeInterface.GetARVideoTextureHandles();
            #endif

            if (handles.textureY == IntPtr.Zero || handles.textureCbCr == IntPtr.Zero)
            {
                m_canRenderBackground = false;
                return;
            }

            m_canRenderBackground = true;
            IsRenderingBackground = m_isBackgroundRendering;

            Resolution currentResolution = Screen.currentResolution;

            //Texture Y
            if (m_videoTextureY == null)
            {
                m_videoTextureY = Texture2D.CreateExternalTexture(
                    currentResolution.width,
                    currentResolution.height,
                    TextureFormat.R8,
                    false,
                    false,
                    handles.textureY
                    );

                m_videoTextureY.filterMode = FilterMode.Bilinear;
                m_videoTextureY.wrapMode   = TextureWrapMode.Repeat;

                m_clearMaterial.SetTexture("_textureY", m_videoTextureY);
            }

            //Texture CbCr
            if (m_videoTextureCbCr == null)
            {
                m_videoTextureCbCr = Texture2D.CreateExternalTexture(
                    currentResolution.width,
                    currentResolution.height,
                    TextureFormat.RG16,
                    false,
                    false,
                    handles.textureCbCr
                    );

                m_videoTextureCbCr.filterMode = FilterMode.Bilinear;
                m_videoTextureCbCr.wrapMode   = TextureWrapMode.Repeat;

                m_clearMaterial.SetTexture("_textureCbCr", m_videoTextureCbCr);
            }

            m_videoTextureY.UpdateExternalTexture(handles.textureY);
            m_videoTextureCbCr.UpdateExternalTexture(handles.textureCbCr);

            m_clearMaterial.SetMatrix("_DisplayTransform", m_displayTransform);
        }