feature: 基本完成绑定

This commit is contained in:
jackfiled 2023-03-30 21:18:20 +08:00
parent f812a1b831
commit 2a0047a04b
2 changed files with 24 additions and 7 deletions

View File

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using Models; using Models;
using UnityEngine; using UnityEngine;
@ -31,7 +32,8 @@ private void Update()
{ {
if (_isReceived) if (_isReceived)
{ {
_animator.GetBoneTransform(HumanBodyBones.Hips).rotation = _rotationNodes[HumanBodyBones.Hips].Rotation; _animator.GetBoneTransform(HumanBodyBones.Hips).rotation =
_rotationNodes[HumanBodyBones.Hips].Rotation;
/*var rotation = _rotationNodes[HumanBodyBones.Hips].CalculateRotate /*var rotation = _rotationNodes[HumanBodyBones.Hips].CalculateRotate
* Quaternion.Inverse(_rotationNodes[HumanBodyBones.RightUpperArm].CalculateRotate); * Quaternion.Inverse(_rotationNodes[HumanBodyBones.RightUpperArm].CalculateRotate);
@ -52,16 +54,34 @@ private void Update()
} }
_animator.GetBoneTransform(HumanBodyBones.LeftUpperArm).rotation = _bonds[9].Rotation; _animator.GetBoneTransform(HumanBodyBones.LeftUpperArm).rotation = _bonds[9].Rotation;
_animator.GetBoneTransform(HumanBodyBones.LeftUpperArm).Rotate(0, -180, 0,
Space.Self);
_animator.GetBoneTransform(HumanBodyBones.LeftLowerArm).rotation = _bonds[10].Rotation; _animator.GetBoneTransform(HumanBodyBones.LeftLowerArm).rotation = _bonds[10].Rotation;
_animator.GetBoneTransform(HumanBodyBones.LeftLowerArm).Rotate(0, -180, 0,
Space.Self);
_animator.GetBoneTransform(HumanBodyBones.RightUpperArm).rotation = _bonds[15].Rotation; _animator.GetBoneTransform(HumanBodyBones.RightUpperArm).rotation = _bonds[15].Rotation;
_animator.GetBoneTransform(HumanBodyBones.RightUpperArm).Rotate(0, -180, 0,
Space.Self);
_animator.GetBoneTransform(HumanBodyBones.RightLowerArm).rotation = _bonds[16].Rotation; _animator.GetBoneTransform(HumanBodyBones.RightLowerArm).rotation = _bonds[16].Rotation;
_animator.GetBoneTransform(HumanBodyBones.RightLowerArm).Rotate(0, -180, 0,
Space.Self);
_animator.GetBoneTransform(HumanBodyBones.LeftUpperLeg).rotation = _bonds[22].Rotation; _animator.GetBoneTransform(HumanBodyBones.LeftUpperLeg).rotation = _bonds[22].Rotation;
_animator.GetBoneTransform(HumanBodyBones.LeftUpperLeg).Rotate(0, -180, 0,
Space.Self);
_animator.GetBoneTransform(HumanBodyBones.LeftLowerLeg).rotation = _bonds[23].Rotation; _animator.GetBoneTransform(HumanBodyBones.LeftLowerLeg).rotation = _bonds[23].Rotation;
_animator.GetBoneTransform(HumanBodyBones.LeftLowerLeg).Rotate(0, -180, 0,
Space.Self);
_animator.GetBoneTransform(HumanBodyBones.RightUpperLeg).rotation = _bonds[28].Rotation; _animator.GetBoneTransform(HumanBodyBones.RightUpperLeg).rotation = _bonds[28].Rotation;
_animator.GetBoneTransform(HumanBodyBones.RightUpperLeg).Rotate(0, -180, 0,
Space.Self);
_animator.GetBoneTransform(HumanBodyBones.RightLowerLeg).rotation = _bonds[29].Rotation; _animator.GetBoneTransform(HumanBodyBones.RightLowerLeg).rotation = _bonds[29].Rotation;
_animator.GetBoneTransform(HumanBodyBones.RightLowerLeg).Rotate(0, -180, 0,
Space.Self);
_isReceived = false; _isReceived = false;
} }
@ -94,11 +114,6 @@ private void OnReceive(List<PoseLandmark> landmarks)
oldRotation.Rotation, oldRotation.Rotation,
Quaternion.LookRotation(front)); Quaternion.LookRotation(front));
_rotationNodes[HumanBodyBones.RightUpperArm] = new RotationNode(
_rotationNodes[HumanBodyBones.RightUpperArm],
landmarks[PoseLandmarkType.RightShoulder],
landmarks[PoseLandmarkType.RightElbow]);
_landmarks = landmarks; _landmarks = landmarks;
_isReceived = true; _isReceived = true;
} }

View File

@ -1,4 +1,5 @@
using UnityEngine; using UnityEngine;
using Utils;
namespace Models namespace Models
{ {
@ -12,6 +13,7 @@ public class Bond
private readonly GameObject _bond; private readonly GameObject _bond;
public Quaternion Rotation => _bond.transform.rotation; public Quaternion Rotation => _bond.transform.rotation;
public Vector3 Vector => End.transform.position - Start.transform.position;
public Bond(GameObject start,GameObject end,float scale) public Bond(GameObject start,GameObject end,float scale)
{ {