Пример #1
0
        // Update is called once per frame
        void Update()
        {
            FrameObj frame = frameSource.GetNewFrame();
            float    now   = Time.time;

            if (lastSample + fpsSampleInterval < now)
            {
                FPS        = fpsCounter / fpsSampleInterval;
                fpsCounter = 0;
                lastSample = now;
            }

            if (frame != null)
            {
                fpsCounter++;
                lastFrame = now;

                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.localPosition = frame.cameraPos;
                transform.localRotation = frame.cameraRot;
                //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);
                }

                Texture2D newBidxTex = frame.bidxTex;
                if (newBidxTex != null)
                {
                    Destroy(m_material.GetTexture("_BidxTex"));
                    m_material.SetTexture("_BidxTex", newBidxTex);
                }
            }

            if (fadeColorIfInactive)
            {
                if ((now - lastFrame) >= fadeAfter)
                {
                    float deltaFade = (now - lastFrame) - fadeAfter;
                    colorFade = Mathf.Max(0.0f, 1.0f - (deltaFade / fadeDuration));
                }
                else if (colorFade < 1.0f)
                {
                    colorFade += Time.deltaTime / fadeDuration;
                }

                m_material.SetFloat("_Fade", colorFade);
            }
            else
            {
                m_material.SetFloat("_Fade", 1.0f);
            }
        }
Пример #2
0
        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();
                }

                if (preObj.BodyIndexJPEG_colors != null)
                {
                    newFrame.bidxTex            = new Texture2D((int)preObj.colSize.x, (int)preObj.colSize.y); //TextureFormat.Alpha8
                    newFrame.bidxTex.wrapMode   = TextureWrapMode.Clamp;
                    newFrame.bidxTex.filterMode = FilterMode.Point;
                    newFrame.bidxTex.LoadImage(preObj.BodyIndexJPEG_colors);
                    newFrame.bidxTex.Apply();
                }

                newFrame.cameraPos = preObj.cameraPos;
                newFrame.cameraRot = preObj.cameraRot;

                newFrame.timeStamp = preObj.timeStamp;
                preObj.Release();
                return(newFrame);
            }
            else
            {
                return(null);
            }
        }