public FrameObj GetNewFrame() { APreFrameObj preObj = frameQueue.Poll(); if (preObj != null) { FrameObj newFrame = new FrameObj(); newFrame.posTex = new Texture2D((int)preObj.posSize.x, (int)preObj.posSize.y, TextureFormat.RGBAFloat, false); newFrame.posTex.wrapMode = TextureWrapMode.Repeat; newFrame.posTex.filterMode = FilterMode.Point; newFrame.posTex.SetPixels(preObj.positions); newFrame.posTex.Apply(); if (preObj.colors != null) { newFrame.colTex = new Texture2D((int)preObj.colSize.x, (int)preObj.colSize.y, TextureFormat.RGBAFloat, false); newFrame.colTex.wrapMode = TextureWrapMode.Repeat; newFrame.colTex.filterMode = FilterMode.Point; newFrame.colTex.SetPixels(preObj.colors); newFrame.colTex.Apply(); } else if (preObj.DXT1_colors != null) { newFrame.colTex = new Texture2D((int)preObj.colSize.x, (int)preObj.colSize.y, TextureFormat.DXT1, false); newFrame.colTex.wrapMode = TextureWrapMode.Clamp; newFrame.colTex.filterMode = FilterMode.Point; newFrame.colTex.LoadRawTextureData(preObj.DXT1_colors); newFrame.colTex.Apply(); } else if (preObj.JPEG_colors != null) { newFrame.colTex = new Texture2D((int)preObj.colSize.x, (int)preObj.colSize.y); newFrame.colTex.wrapMode = TextureWrapMode.Clamp; newFrame.colTex.filterMode = FilterMode.Point; newFrame.colTex.LoadImage(preObj.JPEG_colors); newFrame.colTex.Apply(); } newFrame.cameraPos = preObj.cameraPos; newFrame.cameraRot = preObj.cameraRot; newFrame.timeStamp = preObj.timeStamp; preObj.Release(); return(newFrame); } else { return(null); } }
// Update is called once per frame void Update() { FrameObj frame = frameSource.GetNewFrame(); if (lastSample + fpsSampleInterval < Time.time) { FPS = fpsCounter / fpsSampleInterval; fpsCounter = 0; lastSample = Time.time; } if (frame != null) { fpsCounter++; Vector2 _resolution = new Vector2(frame.posTex.width, frame.posTex.height); if (!resolution.Equals(_resolution)) { resolution = _resolution; m_maxPoints = (int)(_resolution.x * _resolution.y); CreateMesh(); } transform.position = frame.cameraPos; transform.rotation = frame.cameraRot; Texture2D newColTex = frame.colTex; if (newColTex != null) { Destroy(m_material.GetTexture("_ColorTex")); m_material.SetTexture("_ColorTex", newColTex); } Texture2D newPosTex = frame.posTex; if (newPosTex != null) { Destroy(m_material.GetTexture("_PositionTex")); m_material.SetTexture("_PositionTex", newPosTex); } } }