/// <summary> /// Gets latest frame from the frame stream. /// Frames update only if stream has been started. /// May be called from main thread only. /// </summary> /// <returns>Latest Distorted color stream frame.</returns> public VarjoDistortedColorFrame GetFrame() { lock (mutex) { var frame = new VarjoDistortedColorFrame(); frame.timestamp = data.timestamp; frame.metadata = new VarjoCameraMetadata(data); frame.leftTexture = leftBuffer.GetTexture2D(); frame.rightTexture = rightBuffer.GetTexture2D(); return(frame); } }
private void UpdateCubemap() { Texture2D texture = buffer.GetTexture2D(); if (texture == null) { cubemap = null; return; } int resolution = texture.width; if (!cubemap || cubemap.width != resolution) { UnityEngine.Object.Destroy(cubemap); cubemap = new Cubemap(resolution, TextureFormat.RGBAHalf, false); } for (int faceIdx = 0; faceIdx < 6; ++faceIdx) { Graphics.CopyTexture( src: texture, srcElement: 0, srcMip: 0, srcX: 0, srcY: faceIdx * resolution, srcWidth: resolution, srcHeight: resolution, dst: cubemap, dstElement: faceIdx, dstMip: 0, dstX: 0, dstY: 0 ); } }
/// <summary> /// Gets latest frame from the frame stream. /// Frames update only if stream has been started. /// May be called from main thread only. /// </summary> /// <returns>Latest Distorted color stream frame.</returns> public VarjoDistortedColorFrame GetFrame() { lock (mutex) { var frame = new VarjoDistortedColorFrame(); frame.timestamp = data.timestamp; frame.ev = data.ev; frame.exposureTime = data.exposureTime; frame.whiteBalanceTemperature = data.whiteBalanceTemperature; frame.wbNormalizationData = new VarjoWBNormalizationData(); if (data.wbNormalizationData.wbGains != null) { frame.wbNormalizationData.wbGains = new Color( (float)data.wbNormalizationData.wbGains[0], (float)data.wbNormalizationData.wbGains[1], (float)data.wbNormalizationData.wbGains[2] ); } if (data.wbNormalizationData.invCCM != null) { frame.wbNormalizationData.invCCM = new Matrix4x4( new Vector4( (float)data.wbNormalizationData.invCCM[0], (float)data.wbNormalizationData.invCCM[1], (float)data.wbNormalizationData.invCCM[2], 0.0f), new Vector4( (float)data.wbNormalizationData.invCCM[3], (float)data.wbNormalizationData.invCCM[4], (float)data.wbNormalizationData.invCCM[5], 0.0f), new Vector4( (float)data.wbNormalizationData.invCCM[6], (float)data.wbNormalizationData.invCCM[7], (float)data.wbNormalizationData.invCCM[8], 0.0f), new Vector4(0.0f, 0.0f, 0.0f, 1.0f) ); } if (data.wbNormalizationData.ccm != null) { frame.wbNormalizationData.ccm = new Matrix4x4( new Vector4( (float)data.wbNormalizationData.ccm[0], (float)data.wbNormalizationData.ccm[1], (float)data.wbNormalizationData.ccm[2], 0.0f), new Vector4( (float)data.wbNormalizationData.ccm[3], (float)data.wbNormalizationData.ccm[4], (float)data.wbNormalizationData.ccm[5], 0.0f), new Vector4( (float)data.wbNormalizationData.ccm[6], (float)data.wbNormalizationData.ccm[7], (float)data.wbNormalizationData.ccm[8], 0.0f), new Vector4(0.0f, 0.0f, 0.0f, 1.0f) ); } frame.cameraCalibrationConstant = data.cameraCalibrationConstant; frame.leftTexture = leftBuffer.GetTexture2D(); frame.rightTexture = rightBuffer.GetTexture2D(); return(frame); } }