Beispiel #1
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            UnityEngine.SceneManagement.SceneManager.LoadScene(0);

            return;
        }

        if (adapter == null)
        {
            return;
        }

        if (adapter.SensorType != sensorType)
        {
            adapter.SensorType = sensorType;
        }

        Frame frame = adapter.UpdateFrame();

        if (frame != null)
        {
            if (frame.ImageData != null)
            {
                imageViewTexture = ValidateTexture(imageViewTexture, frame.ImageWidth, frame.ImageHeight, imageViewMaterial, imageViewTransform);

                if (imageViewTexture != null)
                {
                    imageViewTexture.LoadRawTextureData(frame.ImageData);
                    imageViewTexture.Apply(false);
                }
            }

            depthFilter.UpdateFilter(frame);
            if (depthFilter.Result != null)
            {
                depthViewTexture = ValidateTexture(depthViewTexture, frame.DepthWidth, frame.DepthHeight, depthViewMaterial, depthViewTransform);

                if (depthViewTexture != null)
                {
                    depthViewTexture.LoadRawTextureData(depthFilter.Result);
                    depthViewTexture.Apply(false);
                }
            }

            Body body = frame.GetClosestBody();

            if (body != null)
            {
                imageViewStickman.UpdateStickman(adapter, frame, body, imageViewTransform, Visualization.Image);
                depthViewStickman.UpdateStickman(adapter, frame, body, depthViewTransform, Visualization.Depth);

                model.DoAvateering(body);
            }
        }
    }
Beispiel #2
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            UnityEngine.SceneManagement.SceneManager.LoadScene(0);

            return;
        }

        if (adapter == null)
        {
            return;
        }

        if (adapter.SensorType != sensorType)
        {
            adapter.SensorType = sensorType;
        }

        Frame frame = VideoPlayer.IsPlaying ? VideoPlayer.Load() : adapter.UpdateFrame();

        if (VideoPlayer.IsPlaying && !VideoPlayer.IsSeeking)
        {
            seekSlider.slider.value = (VideoPlayer.Seek + 1) / (float)VideoPlayer.FrameCount;
        }

        if (frame != null)
        {
            if (frame.ImageData != null)
            {
                imageViewTexture = ValidateTexture(imageViewTexture, frame.ImageWidth, frame.ImageHeight, imageViewMaterial, imageViewTransform);

                if (imageViewTexture != null)
                {
                    if (isAndroid && VideoPlayer.IsPlaying)
                    {
                        imageViewTexture.LoadImage(frame.ImageData);
                    }
                    else
                    {
                        imageViewTexture.LoadRawTextureData(frame.ImageData);
                        imageViewTexture.Apply(false);
                    }
                }
            }

            depthFilter.UpdateFilter(frame);
            if (depthFilter.Result != null)
            {
                depthViewTexture = ValidateTexture(depthViewTexture, frame.DepthWidth, frame.DepthHeight, depthViewMaterial, depthViewTransform);

                if (depthViewTexture != null)
                {
                    depthViewTexture.LoadRawTextureData(depthFilter.Result);
                    depthViewTexture.Apply(false);
                }
            }

            Body body = frame.GetClosestBody();

            if (body != null)
            {
                imageViewStickman.UpdateStickman(adapter, frame, body, imageViewTransform, Visualization.Image);
                depthViewStickman.UpdateStickman(adapter, frame, body, depthViewTransform, Visualization.Depth);
                screenViewStickface.UpdateStickface(adapter, frame, body.Face, imageViewTransform, Visualization.Image);
                pointCloudStickface.UpdateStickface(body.Face);

                model.DoAvateering(body);
            }

            if (!VideoPlayer.IsPlaying)
            {
                VideoRecorder.Record(frame, recordingSettings);
            }
        }

        if (VideoRecorder.IsRecording)
        {
            bufferFrameCount = VideoRecorder.FrameCount;
        }

        if (bufferFrameCount > 0)
        {
            bufferVisuals.fillAmount = VideoRecorder.QueueLength / (float)bufferFrameCount;
            bufferQueueText.text     = VideoRecorder.QueueLength.ToString();
        }
    }
Beispiel #3
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            UnityEngine.SceneManagement.SceneManager.LoadScene(0);

            return;
        }

        if (adapter == null)
        {
            return;
        }

        if (adapter.SensorType != sensorType)
        {
            adapter.SensorType = sensorType;
        }

        Frame frame = adapter.UpdateFrame();

        if (frame != null)
        {
            if (frame.ImageData != null)
            {
                imageViewTexture = ValidateTexture(imageViewTexture, frame.ImageWidth, frame.ImageHeight, imageViewMaterial, imageViewTransform);

                if (imageViewTexture != null)
                {
                    imageViewTexture.LoadRawTextureData(frame.ImageData);
                    imageViewTexture.Apply(false);
                }
            }

            depthFilter.UpdateFilter(frame);
            if (depthFilter.Result != null)
            {
                depthViewTexture = ValidateTexture(depthViewTexture, frame.DepthWidth, frame.DepthHeight, depthViewMaterial, depthViewTransform);

                if (depthViewTexture != null)
                {
                    depthViewTexture.LoadRawTextureData(depthFilter.Result);
                    depthViewTexture.Apply(false);
                }
            }

            Body body = frame.GetClosestBody();

            if (body != null)
            {
                imageViewStickman.UpdateStickman(adapter, frame, body, imageViewTransform, Visualization.Image);
                depthViewStickman.UpdateStickman(adapter, frame, body, depthViewTransform, Visualization.Depth);

                if (!hadBody)
                {
                    hadBody = true;

                    model1.AvatarRoot.SetActive(true);
                    model2.AvatarRoot.SetActive(true);
                }

                model1.DoAvateering(body);

                model1.Bones[(int)JointType.SpineBase].Transform.position =
                    adapter.WorldToImageSpace(body.Joints[JointType.SpineBase].WorldPosition).
                    GetPositionOnPlane(frame.ImageWidth, frame.ImageHeight,
                                       imageViewTransform.position, imageViewTransform.rotation, imageViewTransform.localScale);

                model2.DoAvateering(body);
                model2.Bones[(int)JointType.SpineBase].Transform.position =
                    adapter.WorldToDepthSpace(body.Joints[JointType.SpineBase].WorldPosition).
                    GetPositionOnPlane(frame.DepthWidth, frame.DepthHeight,
                                       depthViewTransform.position, depthViewTransform.rotation, depthViewTransform.localScale);

                if (Vector3D.Angle(Vector3D.Up, body.Joints[JointType.Neck].WorldPosition - body.Joints[JointType.SpineBase].WorldPosition) < 10)
                {
                    bodyImageSize = (imageViewStickman.jointPoints[0].position - imageViewStickman.jointPoints[4].position).magnitude;
                    bodyDepthSize = (depthViewStickman.jointPoints[0].position - depthViewStickman.jointPoints[4].position).magnitude;

                    float scale = bodyImageSize / model1Size;
                    model1.AvatarRoot.transform.localScale = new Vector3(scale, scale, scale);

                    scale = bodyDepthSize / model2Size;
                    model2.AvatarRoot.transform.localScale = new Vector3(scale, scale, scale);
                }
            }
            else if (hadBody)
            {
                hadBody = false;

                model1.AvatarRoot.SetActive(false);
                model2.AvatarRoot.SetActive(false);
            }
        }
    }