refact: 删除了冗余的代码

This commit is contained in:
jackfiled 2023-02-28 12:55:21 +08:00
parent abf97571e7
commit 2f9e21fe66
4 changed files with 3 additions and 104 deletions

View File

@ -7,16 +7,11 @@ public class ModelBehaviour : MonoBehaviour
private Animator _animator;
private readonly UdpListener _listener = new UdpListener();
private static readonly List<PosTransformator> _posLandmarks = new List<PosTransformator>();
private static readonly List<PoseTransform> PoseTransforms = new List<PoseTransform>();
private void Start()
{
_animator = GetComponent<Animator>(); // 获取动画控件
TransformatorInit(); //匹配初始化
InitPoseTransformList();
_listener.AddHandler(LogLandmarks);
@ -37,8 +32,6 @@ private void Update()
_animator.GetBoneTransform(landmark.UnityName).rotation = landmark.CurrentQuaternion;
}
}
@ -51,6 +44,7 @@ private void OnDisable()
private static void LogLandmarks(List<PoseLandmark> landmarks)
{
Debug.Log("Here");
foreach (var landmark in landmarks)
{
Debug.Log(landmark.ToString());
@ -64,34 +58,7 @@ private static void RigPoint(List<PoseLandmark> landmarks)
foreach (var landmark in landmarks)
{
var temp = PoseTransforms[(int)landmark.Type];
temp.CalculateCurrentQuaternion(landmark);
PoseTransforms[(int)landmark.Type] = temp;
//PoseTransforms[(int)landmark.Type].CalculateCurrentQuaternion(landmark);
// var temp = _posLandmarks.Find(t=>t.mediaPipeName == landmark.Type.ToString());
// var sum = new Vector3(0,0,0);
//var mediatemp = new Vector3(landmark.X, landmark.Y, landmark.Z);
//temp.mediaPipePos = new Vector3(landmark.X, landmark.Y, landmark.Z);
//temp.mediaPipePos.x = landmark.X;
//temp.mediaPipePos.y = landmark.Y;
//temp.mediaPipePos.z = landmark.Z;
//foreach (var parents in temp.parent)
//{
// if (parents != null)
// {
// sum += parents.mediaPipePos;
// }
//}
//var currentPos = sum / temp.parent.Count();
//temp.currentQ = Quaternion.Euler(temp.mediaPipePos - currentPos);
//Debug.Log("Here!!");
}
}

View File

@ -1,28 +0,0 @@
/*
using System.Collections.Generic;
using UnityEngine;
namespace Models
{
public class PosTransformator
{
public string mediaPipeName;
//动捕手机端关节点标识
public HumanBodyBones unityName;
//unity内部avatar系统关节点标识
public Vector3 mediaPipePos = new Vector3(0,0,0);
//动捕手机端位置数据
public List<PosTransformator> parent = new List<PosTransformator>();
//该骨骼节点的父关节点列表(因为传上来的数据没有脖子和骨盆节点)
public Quaternion prevQ;
//该骨骼节点的初始角度
public Quaternion currentQ;
//该骨骼节点的当前角度
}
}
*/

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: dfbef38b30e17e44b831e51debbd5087
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -87,38 +87,9 @@ public static void UpdatePosition(ref PoseTransform pose, PoseLandmark landmark)
}
}
public static void CalculateRotation(PoseTransform poseTransform)
public static void CalculateRotation(ref PoseTransform poseTransform, PoseLandmark landmark)
{
//var temp = _posLandmarks.Find(t=>t.mediaPipeName == landmark.Type.ToString());
var sum = new Vector3(0,0,0);
if (landmark.Visibility > 0.6)
{
var temp = new Vector4(landmark.X, landmark.Y, landmark.Z, 1);
MediaPipePos = new Vector3(-temp.x, -temp.y, -temp.z);
}
if (UnityName != HumanBodyBones.LastBone)
{
Debug.Log(UnityName+".MediaPipePos:"+MediaPipePos);
}
foreach (var parents in Parent)
{
sum += parents.MediaPipePos;
//Debug.Log("parents:"+parents.UnityName+".MediaPipePos:"+parents.MediaPipePos);
}
//Debug.Log("sum:"+sum);
var currentPos = sum / Parent.Count;
CurrentQuaternion = Quaternion.LookRotation(MediaPipePos - currentPos);
}
/// <summary>