Пример #1
0
        public void OnPreRender()
        {
            ARTextureHandles handles = m_Session.GetARVideoTextureHandles();

            if (handles.IsNull())
            {
                return;
            }

            if (!bTexturesInitialized)
            {
                return;
            }

            currentFrameIndex = (currentFrameIndex + 1) % 2;

            Resolution currentResolution = Screen.currentResolution;


            m_Session.SetCapturePixelData(true, PinByteArray(ref m_pinnedYArray, YByteArrayForFrame(currentFrameIndex)), PinByteArray(ref m_pinnedUVArray, UVByteArrayForFrame(currentFrameIndex)));

            connectToEditor.SendToEditor(ConnectionMessageIds.screenCaptureYMsgId,
                                         CompressionHelper.ByteArrayCompress(YByteArrayForFrame(1 - currentFrameIndex)));
            connectToEditor.SendToEditor(ConnectionMessageIds.screenCaptureUVMsgId,
                                         CompressionHelper.ByteArrayCompress(UVByteArrayForFrame(1 - currentFrameIndex)));
        }
Пример #2
0
        public void OnPreRender()
        {
#if UNITY_IOS || UNITY_EDITOR
            ARTextureHandles handles = m_Session.GetARVideoTextureHandles();
            if (handles.textureY == System.IntPtr.Zero || handles.textureCbCr == System.IntPtr.Zero)
            {
                return;
            }

            if (!bTexturesInitialized)
            {
                return;
            }

            currentFrameIndex = (currentFrameIndex + 1) % 2;

            Resolution currentResolution = Screen.currentResolution;


            m_Session.SetCapturePixelData(true, PinByteArray(ref m_pinnedYArray, YByteArrayForFrame(currentFrameIndex)), PinByteArray(ref m_pinnedUVArray, UVByteArrayForFrame(currentFrameIndex)));

            connectToEditor.SendToEditor(ConnectionMessageIds.screenCaptureYMsgId, YByteArrayForFrame(1 - currentFrameIndex));
            connectToEditor.SendToEditor(ConnectionMessageIds.screenCaptureUVMsgId, UVByteArrayForFrame(1 - currentFrameIndex));
#endif
        }
Пример #3
0
        public void OnPreRender()
        {
            ARTextureHandles handles = m_Session.GetARVideoTextureHandles();

            if (handles.textureY == System.IntPtr.Zero || handles.textureCbCr == System.IntPtr.Zero)
            {
                return;
            }
            if (!bTexturesInitialized)
            {
                return;
            }
            currentFrameIndex = (currentFrameIndex + 1) % 2;
            Resolution currentResolution = Screen.currentResolution;

            m_Session.SetCapturePixelData(true, PinByteArray(ref m_pinnedYArray, YByteArrayForFrame(currentFrameIndex)), PinByteArray(ref m_pinnedUVArray, UVByteArrayForFrame(currentFrameIndex)));

            tex = toTexture2D(rTexture);
            //tex.Compress (true);
            m_textureBytes = tex.GetRawTextureData();
            connectToEditor.SendToEditor(ConnectionMessageIds.screenCaptureRenTextureMsgId, m_textureBytes);
            //ucl.SendByte (m_textureBytes);
            //connectToEditor.SendToEditor (ConnectionMessageIds.screenCaptureYMsgId, YByteArrayForFrame(1-currentFrameIndex));
            //connectToEditor.SendToEditor (ConnectionMessageIds.screenCaptureUVMsgId, UVByteArrayForFrame(1-currentFrameIndex));
        }
Пример #4
0
        public void OnPreRender()
        {
            ARTextureHandles handles = m_Session.GetARVideoTextureHandles();

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

            if (!bCommandBufferInitialized)
            {
                InitializeCommandBuffer();
            }

            Resolution currentResolution = Screen.currentResolution;

            // Texture Y
            _videoTextureY = Texture2D.CreateExternalTexture(currentResolution.width, currentResolution.height,
                                                             TextureFormat.R8, false, false, (System.IntPtr)handles.textureY);
            _videoTextureY.filterMode = FilterMode.Bilinear;
            _videoTextureY.wrapMode   = TextureWrapMode.Repeat;
            _videoTextureY.UpdateExternalTexture(handles.textureY);

            // Texture CbCr
            _videoTextureCbCr = Texture2D.CreateExternalTexture(currentResolution.width, currentResolution.height,
                                                                TextureFormat.RG16, false, false, (System.IntPtr)handles.textureCbCr);
            _videoTextureCbCr.filterMode = FilterMode.Bilinear;
            _videoTextureCbCr.wrapMode   = TextureWrapMode.Repeat;
            _videoTextureCbCr.UpdateExternalTexture(handles.textureCbCr);

            m_ClearMaterial.SetTexture("_textureY", _videoTextureY);
            m_ClearMaterial.SetTexture("_textureCbCr", _videoTextureCbCr);
            int isPortrait = 0;

            float rotation = 0;

            if (Screen.orientation == ScreenOrientation.Portrait)
            {
                rotation   = -90;
                isPortrait = 1;
            }
            else if (Screen.orientation == ScreenOrientation.PortraitUpsideDown)
            {
                rotation   = 90;
                isPortrait = 1;
            }
            else if (Screen.orientation == ScreenOrientation.LandscapeRight)
            {
                rotation = -180;
            }
            Matrix4x4 m = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0.0f, 0.0f, rotation), Vector3.one);

            m_ClearMaterial.SetMatrix("_TextureRotation", m);
            m_ClearMaterial.SetFloat("_texCoordScale", m_Session.GetARYUVTexCoordScale());
            m_ClearMaterial.SetInt("_isPortrait", isPortrait);
        }
Пример #5
0
        public void OnPreRender()
        {
            ARTextureHandles aRVideoTextureHandles = m_Session.GetARVideoTextureHandles();

            if (!(aRVideoTextureHandles.textureY == IntPtr.Zero) && !(aRVideoTextureHandles.textureCbCr == IntPtr.Zero) && bTexturesInitialized)
            {
                currentFrameIndex = (currentFrameIndex + 1) % 2;
                Resolution currentResolution = Screen.currentResolution;
                m_Session.SetCapturePixelData(enable: true, PinByteArray(ref m_pinnedYArray, YByteArrayForFrame(currentFrameIndex)), PinByteArray(ref m_pinnedUVArray, UVByteArrayForFrame(currentFrameIndex)));
                connectToEditor.SendToEditor(ConnectionMessageIds.screenCaptureYMsgId, YByteArrayForFrame(1 - currentFrameIndex));
                connectToEditor.SendToEditor(ConnectionMessageIds.screenCaptureUVMsgId, UVByteArrayForFrame(1 - currentFrameIndex));
            }
        }
Пример #6
0
        public void OnPreRender()
        {
            ARTextureHandles handles = m_Session.GetARVideoTextureHandles();

            if (handles.IsNull())
            {
                return;
            }

            if (!bTexturesInitialized)
            {
                return;
            }

            currentFrameIndex = (currentFrameIndex + 1) % 2;

            Resolution currentResolution = Screen.currentResolution;


            m_Session.SetCapturePixelData(true, PinByteArray(ref m_pinnedYArray, YByteArrayForFrame(currentFrameIndex)), PinByteArray(ref m_pinnedUVArray, UVByteArrayForFrame(currentFrameIndex)));

            connectToEditor.SendToEditor(ConnectionMessageIds.screenCaptureYMsgId,
                                         CompressionHelper.ByteArrayCompress(YByteArrayForFrame(1 - currentFrameIndex)));
            connectToEditor.SendToEditor(ConnectionMessageIds.screenCaptureUVMsgId,
                                         CompressionHelper.ByteArrayCompress(UVByteArrayForFrame(1 - currentFrameIndex)));

#if ARKIT_REMOTE_LANDMARK
            // landmark
            Assembly  ARFace             = AppDomain.CurrentDomain.GetAssemblies().Single(a => a.GetName().Name == "ARFace");
            Type      LandmarkManager    = ARFace.GetType("ARFace.Landmarks.LandmarkManager");
            FieldInfo ActiveLandmarkType =
                LandmarkManager.GetField("ActiveLandmarkType", BindingFlags.Static | BindingFlags.Public);
            MethodInfo GetLandmark =
                LandmarkManager.GetMethod("GetLandmark", BindingFlags.Static | BindingFlags.Public);
            System.Diagnostics.Debug.Assert(GetLandmark != null, nameof(GetLandmark) + " != null");

            var material = GetComponent <UnityARVideo>().m_ClearMaterial;
            var matrix   = GetComponent <UnityARVideo>().displayTransform;
            var textureY = material.GetTexture("_textureY");
            if (!textureY)
            {
                Debug.Log("textureY == null");
                return;
            }
            var           p    = matrix.MultiplyPoint(new Vector2(textureY.width, textureY.height));
            var           size = new Vector2Int((int)Mathf.Abs(p.x), (int)Mathf.Abs(p.y));
            RenderTexture rt   = RenderTexture.GetTemporary(size.x, size.y, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB);
            Graphics.Blit(null, rt, material);

            var landmarkType = ActiveLandmarkType.GetValue(null);
            GetLandmark.Invoke(null, new[]
            {
                rt,
                landmarkType,
                (Action <Dictionary <string, Vector2> >)(landmarks =>
                {
                    RenderTexture.ReleaseTemporary(rt);
                    if (landmarks == null)
                    {
                        Debug.Log("no landmark.");
                        return;
                    }
                    var data = landmarks.ToDictionary(
                        pair => pair.Key,
                        pair => (serializableVector2)pair.Value);
                    connectToEditor.SendToEditor(ConnectionMessageIds.screenCaptureLandmarksId, data);
                }),
                null
            });
#endif
        }