public System.Collections.IEnumerator OnPhotoModeStartedReady(Action callback) { while (!this.m_CaptureContext.GetFrameProvider().IsFrameReady()) { NRDebugger.LogFormat("Wait for the frame ready!"); yield return(new WaitForEndOfFrame()); } callback?.Invoke(); }
private void Update() { while (m_Requests.Count > 0) { var req = m_Requests.Peek(); var task = m_Tasks.Peek(); if (req.hasError) { NRDebugger.Log("GPU readback error detected"); m_Requests.Dequeue(); CommitResult(null, task); m_Tasks.Dequeue(); } else if (req.done) { var buffer = req.GetData <Color32>(); if (tempTexture != null && tempTexture.width != Width && tempTexture.height != Height) { GameObject.Destroy(tempTexture); tempTexture = null; } if (tempTexture == null) { tempTexture = new Texture2D(Width, Height, TextureFormat.RGB24, false); } tempTexture.SetPixels32(buffer.ToArray()); tempTexture.Apply(); if (task.OnReceive != null) { Texture2D resulttex; if (tempTexture.width != task.Width || tempTexture.height != task.Height) { NRDebugger.LogFormat("[BlendCamera] need to scale the texture which origin width:{0} and out put width:{1}", Width, task.Width); resulttex = ImageEncoder.ScaleTexture(tempTexture, task.Width, task.Height); CommitResult(resulttex, task); //Destroy the scale temp texture. GameObject.Destroy(resulttex); } else { CommitResult(tempTexture, task); } } m_Requests.Dequeue(); m_Tasks.Dequeue(); } else { break; } } }
private IEnumerator Initialize() { bool result; EyeProjectMatrixData matrix_data = NRFrame.GetEyeProjectMatrix(out result, m_TargetCamera.nearClipPlane, m_TargetCamera.farClipPlane); while (!result) { Debug.Log("Waitting to initialize camera param."); yield return(new WaitForEndOfFrame()); matrix_data = NRFrame.GetEyeProjectMatrix(out result, m_TargetCamera.nearClipPlane, m_TargetCamera.farClipPlane); } var eyeposFromHead = NRFrame.EyePosFromHead; switch (EyeType) { case NativeEye.LEFT: m_TargetCamera.projectionMatrix = matrix_data.LEyeMatrix; NRDebugger.Log("[Matrix] RGB Camera Project Matrix :" + m_TargetCamera.projectionMatrix.ToString()); transform.localPosition = eyeposFromHead.LEyePose.position; transform.localRotation = eyeposFromHead.LEyePose.rotation; NRDebugger.LogFormat("RGB Camera pos:{0} rotation:{1}", transform.localPosition.ToString(), transform.localRotation.ToString()); break; case NativeEye.RIGHT: m_TargetCamera.projectionMatrix = matrix_data.REyeMatrix; NRDebugger.Log("[Matrix] RGB Camera Project Matrix :" + m_TargetCamera.projectionMatrix.ToString()); transform.localPosition = eyeposFromHead.REyePose.position; transform.localRotation = eyeposFromHead.REyePose.rotation; NRDebugger.LogFormat("RGB Camera pos:{0} rotation:{1}", transform.localPosition.ToString(), transform.localRotation.ToString()); break; case NativeEye.RGB: m_TargetCamera.projectionMatrix = matrix_data.RGBEyeMatrix; NRDebugger.Log("[Matrix] RGB Camera Project Matrix :" + m_TargetCamera.projectionMatrix.ToString()); transform.localPosition = eyeposFromHead.RGBEyePos.position; transform.localRotation = eyeposFromHead.RGBEyePos.rotation; NRDebugger.LogFormat("RGB Camera pos:{0} rotation:{1}", transform.localPosition.ToString(), transform.localRotation.ToString()); break; default: break; } }
private void Update() { while (m_Requests.Count > 0) { var req = m_Requests.Peek(); var task = m_Tasks.Peek(); if (req.hasError) { Debug.Log("GPU readback error detected"); m_Requests.Dequeue(); CommitResult(null, task); m_Tasks.Dequeue(); } else if (req.done) { var buffer = req.GetData <Color32>(); if (m_EncodeTempTex != null && m_EncodeTempTex.width != m_CameraParameters.cameraResolutionWidth && m_EncodeTempTex.height != m_CameraParameters.cameraResolutionHeight) { GameObject.Destroy(m_EncodeTempTex); m_EncodeTempTex = null; } if (m_EncodeTempTex == null) { m_EncodeTempTex = new Texture2D( m_CameraParameters.cameraResolutionWidth, m_CameraParameters.cameraResolutionHeight, TextureFormat.RGB24, false ); } m_EncodeTempTex.SetPixels32(buffer.ToArray()); m_EncodeTempTex.Apply(); if (task.OnReceive != null) { if (m_EncodeTempTex.width != task.Width || m_EncodeTempTex.height != task.Height) { Texture2D scaledtexture; NRDebugger.LogFormat("[BlendCamera] need to scale the texture which origin width:{0} and out put width:{1}", m_EncodeTempTex.width, task.Width); scaledtexture = ImageEncoder.ScaleTexture(m_EncodeTempTex, task.Width, task.Height); CommitResult(scaledtexture, task); //Destroy the scale temp texture. GameObject.Destroy(scaledtexture); } else { CommitResult(m_EncodeTempTex, task); } } m_Requests.Dequeue(); m_Tasks.Dequeue(); } else { break; } } }