Exemple #1
0
        void ReceiveRemoteScreenUVTex(MessageEventArgs mea)
        {
#if UNITY_EDITOR
            if (UnityEditor.EditorApplication.isPaused)
            {
                return;
            }
#endif
            if (!bTexturesInitialized)
            {
                return;
            }
            remoteScreenUVTex.LoadRawTextureData(CompressionHelper.ByteArrayDecompress(mea.data));
            remoteScreenUVTex.Apply();
            var arVideo = UnityARVideo.Instance;
            if (arVideo)
            {
                arVideo.SetUVTexure(remoteScreenUVTex);
            }
        }
Exemple #2
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
        }