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); } } }
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 && frame.UserSpaceData != null) { greenScreenFilter.UpdateFilter(frame); if (greenScreenFilter.Result != null) { greenScreenViewTexture = ValidateTexture(greenScreenViewTexture, frame.DepthWidth, frame.DepthHeight, greenScreenViewRawImage); if (greenScreenViewTexture != null) { greenScreenViewTexture.LoadRawTextureData(greenScreenFilter.Result); greenScreenViewTexture.Apply(false); } } } Body body = frame.GetClosestBody(); if (body != null) { screemViewStickman.UpdateStickman(adapter, frame, body, greenScreenViewTransform, Visualization.Depth); } } }
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, imageViewRawImage); if (imageViewTexture != null) { imageViewTexture.LoadRawTextureData(frame.ImageData); imageViewTexture.Apply(false); } } Body body = frame.GetClosestBody(); if (body != null) { screenViewStickman.UpdateStickman(adapter, frame, body, imageViewTransform, Visualization.Image); screenViewStickface.UpdateStickface(adapter, frame, body.Face, imageViewTransform, Visualization.Image); pointCloudStickface.UpdateStickface(body.Face); } } }
void Update() { if (adapter == null) { return; } Frame frame = adapter.UpdateFrame(); if (frame != null) { Body body = frame.GetClosestBody(); if (body != null) { UpdateStickman(frame, body, imageViewTransform); } } }
void Update() { if (adapter == null) { return; } Frame frame = adapter.UpdateFrame(); if (frame != null) { Body body = frame.GetClosestBody(); if (body != null) { characterModel.DoAvateering(body); //CorrectZCoordinate(); } } }
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(); } }
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); } } Body body = frame.GetClosestBody(); if (body != null) { screenViewStickman.UpdateStickman(adapter, frame, body, imageViewTransform, Visualization.Image); UpdateArc( screenViewStickman.jointPoints[5].position, screenViewStickman.jointPoints[6].position, screenViewStickman.jointPoints[7].position, body.Joints[JointType.ShoulderLeft].WorldPosition, body.Joints[JointType.ElbowLeft].WorldPosition, body.Joints[JointType.WristLeft].WorldPosition, leftElbowParent, leftElbowArc, leftElbowAngleText); UpdateArc( screenViewStickman.jointPoints[9].position, screenViewStickman.jointPoints[10].position, screenViewStickman.jointPoints[11].position, body.Joints[JointType.ShoulderRight].WorldPosition, body.Joints[JointType.ElbowRight].WorldPosition, body.Joints[JointType.WristRight].WorldPosition, rightElbowParent, rightElbowArc, rightElbowAngleText); UpdateArc( screenViewStickman.jointPoints[13].position, screenViewStickman.jointPoints[14].position, screenViewStickman.jointPoints[15].position, body.Joints[JointType.HipLeft].WorldPosition, body.Joints[JointType.KneeLeft].WorldPosition, body.Joints[JointType.AnkleLeft].WorldPosition, leftKneeParent, leftKneeArc, leftKneeAngleText); UpdateArc( screenViewStickman.jointPoints[17].position, screenViewStickman.jointPoints[18].position, screenViewStickman.jointPoints[19].position, body.Joints[JointType.HipRight].WorldPosition, body.Joints[JointType.KneeRight].WorldPosition, body.Joints[JointType.AnkleRight].WorldPosition, rightKneeParent, rightKneeArc, rightKneeAngleText); } } }
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); } } }
protected void Update() { #if UNITY_EDITOR || UNITY_STANDALONE if (adapter == null) { return; } if (adapter.SensorType != sensorType) { adapter.SensorType = sensorType; } Frame frame = adapter.UpdateFrame(); var leftAngle = 0.0f; var rightAngle = 0.0f; if (frame != null) { Body body = frame.GetClosestBody(); if (body != null) { Angles angles = new Angles(); leftAngle = CalcAngle( body.Joints[JointType.SpineShoulder].WorldPosition, body.Joints[JointType.ShoulderLeft].WorldPosition, body.Joints[JointType.ElbowLeft].WorldPosition); //Debug.Log(indexer + " Calculating Left Angle: " + leftAngle.RoundToInt()); rightAngle = CalcAngle( body.Joints[JointType.SpineShoulder].WorldPosition, body.Joints[JointType.ShoulderRight].WorldPosition, body.Joints[JointType.ElbowRight].WorldPosition); //Debug.Log(indexer + " Calculating Right Angle: " + rightAngle.RoundToInt()); angles.LeftAngle = leftAngle.ToString(); angles.RightAngle = rightAngle.ToString(); angles.TimeStamp = Utilities.GetTimeStamp(); _anglesList.Add(angles); if (_anglesList.Count > 1000) { CSVMananger.AppendAnglesToReport(_anglesList); _anglesList.Clear(); Debug.Log("CSVManager Called!"); } //Debug.Log("Left angle:" + leftAngle); //Debug.Log("Right angle:" + rightAngle); if (leftAngle.RoundToInt() < lowarmAngleThreshold && rightAngle.RoundToInt() < lowarmAngleThreshold) { _hansUp = false; //Debug.Log(indexer + " Both hands angle is below " + lowarmAngleThreshold + " so _hansUp is " + _hansUp); } else { //Debug.Log(indexer + " One hand angle is more than " + lowarmAngleThreshold + " so _hansUp is " + _hansUp); } if (!_hansUp) { //Debug.Log(indexer + " User can now go right or left"); // Use key input in editor or standalone if (Input.GetKeyDown(KeyCode.LeftArrow) || leftAngle.RoundToInt() > hightArmAngleThreshold) { ChangeLane(-1); _hansUp = true; //Debug.Log(indexer + " <color=red>User moved left</color> so _handsUp is " + _hansUp); } else if (Input.GetKeyDown(KeyCode.RightArrow) || rightAngle.RoundToInt() > hightArmAngleThreshold) { ChangeLane(1); _hansUp = true; //Debug.Log(indexer + " <color=red>User moved right</color> so _handsUp is " + _hansUp); } else if (Input.GetKeyDown(KeyCode.UpArrow)) { Jump(); } else if (Input.GetKeyDown(KeyCode.DownArrow)) { if (!m_Sliding) { Slide(); } } } else { //Debug.Log(indexer + " User can not move"); } indexer++; //Debug.Log(indexer + " <color=yellow>Indexer changed</color>"); } } #else // Use touch input on mobile if (Input.touchCount == 1) { if (m_IsSwiping) { Vector2 diff = Input.GetTouch(0).position - m_StartingTouch; // Put difference in Screen ratio, but using only width, so the ratio is the same on both // axes (otherwise we would have to swipe more vertically...) diff = new Vector2(diff.x / Screen.width, diff.y / Screen.width); if (diff.magnitude > 0.01f) //we set the swip distance to trigger movement to 1% of the screen width { if (Mathf.Abs(diff.y) > Mathf.Abs(diff.x)) { if (diff.y < 0) { Slide(); } else { Jump(); } } else { if (diff.x < 0) { ChangeLane(-1); } else { ChangeLane(1); } } m_IsSwiping = false; } } // Input check is AFTER the swip test, that way if TouchPhase.Ended happen a single frame after the Began Phase // a swipe can still be registered (otherwise, m_IsSwiping will be set to false and the test wouldn't happen for that began-Ended pair) if (Input.GetTouch(0).phase == TouchPhase.Began) { m_StartingTouch = Input.GetTouch(0).position; m_IsSwiping = true; } else if (Input.GetTouch(0).phase == TouchPhase.Ended) { m_IsSwiping = false; } } #endif Vector3 verticalTargetPosition = m_TargetPosition; if (m_Sliding) { // Slide time isn't constant but the slide length is (even if slightly modified by speed, to slide slightly further when faster). // This is for gameplay reason, we don't want the character to drasticly slide farther when at max speed. float correctSlideLength = slideLength * (1.0f + trackManager.speedRatio); float ratio = (trackManager.worldDistance - m_SlideStart) / correctSlideLength; if (ratio >= 1.0f) { // We slid to (or past) the required length, go back to running StopSliding(); } } if (m_Jumping) { if (trackManager.isMoving) { // Same as with the sliding, we want a fixed jump LENGTH not fixed jump TIME. Also, just as with sliding, // we slightly modify length with speed to make it more playable. float correctJumpLength = jumpLength * (1.0f + trackManager.speedRatio); float ratio = (trackManager.worldDistance - m_JumpStart) / correctJumpLength; if (ratio >= 1.0f) { m_Jumping = false; character.animator.SetBool(s_JumpingHash, false); } else { verticalTargetPosition.y = Mathf.Sin(ratio * Mathf.PI) * jumpHeight; } } else if (!AudioListener.pause)//use AudioListener.pause as it is an easily accessible singleton & it is set when the app is in pause too { verticalTargetPosition.y = Mathf.MoveTowards(verticalTargetPosition.y, 0, k_GroundingSpeed * Time.deltaTime); if (Mathf.Approximately(verticalTargetPosition.y, 0f)) { character.animator.SetBool(s_JumpingHash, false); m_Jumping = false; } } } characterCollider.transform.localPosition = Vector3.MoveTowards(characterCollider.transform.localPosition, verticalTargetPosition, laneChangeSpeed * Time.deltaTime); // Put blob shadow under the character. RaycastHit hit; if (Physics.Raycast(characterCollider.transform.position + Vector3.up, Vector3.down, out hit, k_ShadowRaycastDistance, m_ObstacleLayer)) { blobShadow.transform.position = hit.point + Vector3.up * k_ShadowGroundOffset; } else { Vector3 shadowPosition = characterCollider.transform.position; shadowPosition.y = k_ShadowGroundOffset; blobShadow.transform.position = shadowPosition; } }
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 && frame.UserSpaceData != null) { greenScreenFilter.UpdateFilter(frame); if (greenScreenFilter.Result != null) { greenScreenViewTexture = ValidateTexture(greenScreenViewTexture, frame.DepthWidth, frame.DepthHeight, greenScreenViewRawImage); if (greenScreenViewTexture != null) { greenScreenViewTexture.LoadRawTextureData(greenScreenFilter.Result); greenScreenViewTexture.Apply(false); } } } Body body = frame.GetClosestBody(); if (body != null) { screenViewStickman.UpdateStickman(adapter, frame, body, greenScreenViewTransform, Visualization.Depth); uiPlaneScale = greenScreenViewTransform.localScale; uiPlaneScale.Set( uiPlaneScale.X * ((RectTransform)greenScreenViewTransform).root.localScale.x * ((RectTransform)greenScreenViewTransform).rect.size.x, uiPlaneScale.Y * ((RectTransform)greenScreenViewTransform).root.localScale.y * ((RectTransform)greenScreenViewTransform).rect.size.y, 1); float spineLengthWorld; float spineLengthScreen; MeasureBoneLength(body, JointType.SpineShoulder, JointType.SpineBase, boneLengths[0], 2, 4, out spineLengthWorld, out spineLengthScreen); float armLeftLengthWorld; float armLeftLengthScreen; MeasureBoneLength(body, JointType.ShoulderLeft, JointType.ElbowLeft, boneLengths[1], 5, 6, out armLeftLengthWorld, out armLeftLengthScreen); float forearmLeftLengthWorld; float forearmLeftLengthScreen; MeasureBoneLength(body, JointType.ElbowLeft, JointType.WristLeft, boneLengths[2], 6, 7, out forearmLeftLengthWorld, out forearmLeftLengthScreen); float armRightLengthWorld; float armRightLengthScreen; MeasureBoneLength(body, JointType.ShoulderRight, JointType.ElbowRight, boneLengths[3], 8, 9, out armRightLengthWorld, out armRightLengthScreen); float forearmRightLengthWorld; float forearmRightLengthScreen; MeasureBoneLength(body, JointType.ElbowRight, JointType.WristRight, boneLengths[4], 9, 10, out forearmRightLengthWorld, out forearmRightLengthScreen); float thighLeftLengthWorld; float thighLeftLengthScreen; MeasureBoneLength(body, JointType.HipLeft, JointType.KneeLeft, boneLengths[5], 11, 12, out thighLeftLengthWorld, out thighLeftLengthScreen); float calfLeftLengthWorld; float calfLeftLengthScreen; MeasureBoneLength(body, JointType.KneeLeft, JointType.AnkleLeft, boneLengths[6], 12, 13, out calfLeftLengthWorld, out calfLeftLengthScreen); float thighRightLengthWorld; float thighRightLengthScreen; MeasureBoneLength(body, JointType.HipRight, JointType.KneeRight, boneLengths[7], 14, 15, out thighRightLengthWorld, out thighRightLengthScreen); float calfRightLengthWorld; float calfRightLengthScreen; MeasureBoneLength(body, JointType.KneeRight, JointType.AnkleRight, boneLengths[8], 15, 16, out calfRightLengthWorld, out calfRightLengthScreen); MeasureBoneWidth(frame, body, JointType.SpineShoulder, JointType.SpineBase, boneWidthTexts[0], boneLines[0], spineLengthWorld, spineLengthScreen); MeasureBoneWidth(frame, body, JointType.ShoulderLeft, JointType.ElbowLeft, boneWidthTexts[1], boneLines[1], armLeftLengthWorld, armLeftLengthScreen); MeasureBoneWidth(frame, body, JointType.ElbowLeft, JointType.WristLeft, boneWidthTexts[2], boneLines[2], forearmLeftLengthWorld, forearmLeftLengthScreen); MeasureBoneWidth(frame, body, JointType.ShoulderRight, JointType.ElbowRight, boneWidthTexts[3], boneLines[3], armRightLengthWorld, armRightLengthScreen); MeasureBoneWidth(frame, body, JointType.ElbowRight, JointType.WristRight, boneWidthTexts[4], boneLines[4], forearmRightLengthWorld, forearmRightLengthScreen); MeasureBoneWidth(frame, body, JointType.HipLeft, JointType.KneeLeft, boneWidthTexts[5], boneLines[5], thighLeftLengthWorld, thighLeftLengthScreen); MeasureBoneWidth(frame, body, JointType.KneeLeft, JointType.AnkleLeft, boneWidthTexts[6], boneLines[6], calfLeftLengthWorld, calfLeftLengthScreen); MeasureBoneWidth(frame, body, JointType.HipRight, JointType.KneeRight, boneWidthTexts[7], boneLines[7], thighRightLengthWorld, thighRightLengthScreen); MeasureBoneWidth(frame, body, JointType.KneeRight, JointType.AnkleRight, boneWidthTexts[8], boneLines[8], calfRightLengthWorld, calfRightLengthScreen); } } }