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); }
public void OnPreRender() { ARTextureHandles handles = UnityARSessionNativeInterface.GetARSessionNativeInterface().GetARVideoTextureHandles(); if (handles.IsNull()) { return; } if (!bCommandBufferInitialized) { InitializeCommandBuffer(); } if (!videoParams.HasValue) { return; } Vector2Int size = new Vector2Int(videoParams.Value.yWidth, videoParams.Value.yHeight); // Texture Y if (_videoTextureY != null && new Vector2Int(_videoTextureY.width, _videoTextureY.height) != size) { Destroy(_videoTextureY); } if (_videoTextureY == null) { _videoTextureY = Texture2D.CreateExternalTexture(size.x, size.y, TextureFormat.R8, false, false, (System.IntPtr)handles.TextureY); _videoTextureY.filterMode = FilterMode.Bilinear; _videoTextureY.wrapMode = TextureWrapMode.Repeat; m_ClearMaterial.SetTexture("_textureY", _videoTextureY); } // Texture CbCr if (_videoTextureCbCr != null && new Vector2Int(_videoTextureCbCr.width, _videoTextureCbCr.height) != size) { Destroy(_videoTextureCbCr); } if (_videoTextureCbCr == null) { _videoTextureCbCr = Texture2D.CreateExternalTexture(size.x, size.y, TextureFormat.RG16, false, false, (System.IntPtr)handles.TextureCbCr); _videoTextureCbCr.filterMode = FilterMode.Bilinear; _videoTextureCbCr.wrapMode = TextureWrapMode.Repeat; m_ClearMaterial.SetTexture("_textureCbCr", _videoTextureCbCr); } _videoTextureY.UpdateExternalTexture(handles.TextureY); _videoTextureCbCr.UpdateExternalTexture(handles.TextureCbCr); m_ClearMaterial.SetMatrix("_DisplayTransform", displayTransform); }
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)); } }
public void OnPreRender() { if (shouldRender) { ARTextureHandles handles = UnityARSessionNativeInterface.GetARSessionNativeInterface().GetARVideoTextureHandles(); if (handles.textureY == System.IntPtr.Zero || handles.textureCbCr == System.IntPtr.Zero) { return; } if (!bCommandBufferInitialized) { InitializeCommandBuffer(); } Resolution currentResolution = Screen.currentResolution; // Texture Y if (_videoTextureY == null) { _videoTextureY = Texture2D.CreateExternalTexture(currentResolution.width, currentResolution.height, TextureFormat.R8, false, false, (System.IntPtr)handles.textureY); _videoTextureY.filterMode = FilterMode.Bilinear; _videoTextureY.wrapMode = TextureWrapMode.Repeat; m_ClearMaterial.SetTexture("_textureY", _videoTextureY); } // Texture CbCr if (_videoTextureCbCr == null) { _videoTextureCbCr = Texture2D.CreateExternalTexture(currentResolution.width, currentResolution.height, TextureFormat.RG16, false, false, (System.IntPtr)handles.textureCbCr); _videoTextureCbCr.filterMode = FilterMode.Bilinear; _videoTextureCbCr.wrapMode = TextureWrapMode.Repeat; m_ClearMaterial.SetTexture("_textureCbCr", _videoTextureCbCr); } _videoTextureY.UpdateExternalTexture(handles.textureY); _videoTextureCbCr.UpdateExternalTexture(handles.textureCbCr); m_ClearMaterial.SetMatrix("_DisplayTransform", _displayTransform); } }
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))); connectToEditor.SendToEditor(ConnectionMessageIds.screenCaptureYMsgId, ByteConverter.ConvertByteCompress(YByteArrayForFrame(1 - currentFrameIndex))); connectToEditor.SendToEditor(ConnectionMessageIds.screenCaptureUVMsgId, ByteConverter.ConvertByteCompress(UVByteArrayForFrame(1 - currentFrameIndex))); }
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 }