using System.Collections.Generic; using UnityEngine; using Utils; namespace Models { /// /// 捕捉骨骼的动作转换 /// public struct PoseTransform { /// /// MediaPipe中动捕节点标识 /// public readonly PoseLandmarkType MediaPipeName; /// /// Unity中绑定骨骼名称 /// public readonly HumanBodyBones UnityName; /// /// 取平均的长度 /// public static int AverageLength = 3; /// /// 取平均之后的结果 /// public Vector3 ResultPosition => _transformHandler.GetResultPosition(); /// /// 节点的父节点列表 /// public readonly List Parent; /// /// 骨骼节点的初始角度 /// public Quaternion PreviousQuaternion; /// /// 骨骼节点的当前角度 /// public Quaternion CurrentQuaternion; private readonly IPoseTransformHandler _transformHandler; public PoseTransform( int type, IPoseTransformHandler handler ) { MediaPipeName = new PoseLandmarkType(type); UnityName = GetRelatedBone(MediaPipeName); Parent = new List(); PreviousQuaternion = new Quaternion(); CurrentQuaternion = new Quaternion(); _transformHandler = handler; } public static void UpdatePosition(ref PoseTransform pose, PoseLandmark landmark) { pose._transformHandler.ReceivePoseLandmark(landmark); } public static void CalculateRotation(ref PoseTransform poseTransform, PoseLandmark landmark) { } /// /// 获得同相关捕捉点关联的骨骼 /// /// 捕捉点的种类 /// 关联骨骼的种类 private static HumanBodyBones GetRelatedBone(PoseLandmarkType type) { switch (type.Value) { case PoseLandmarkType.LeftHip: return HumanBodyBones.LeftUpperLeg; case PoseLandmarkType.RightHip: return HumanBodyBones.RightUpperLeg; case PoseLandmarkType.LeftShoulder: return HumanBodyBones.LeftUpperArm; case PoseLandmarkType.RightShoulder: return HumanBodyBones.RightUpperArm; case PoseLandmarkType.Nose: return HumanBodyBones.Head; case PoseLandmarkType.LeftElbow: return HumanBodyBones.LeftLowerArm; case PoseLandmarkType.RightElbow: return HumanBodyBones.RightLowerArm; case PoseLandmarkType.LeftWrist: return HumanBodyBones.LeftHand; case PoseLandmarkType.RightWrist: return HumanBodyBones.RightHand; case PoseLandmarkType.LeftKnee: return HumanBodyBones.LeftLowerLeg; case PoseLandmarkType.RightKnee: return HumanBodyBones.RightLowerLeg; case PoseLandmarkType.LeftAnkle: return HumanBodyBones.LeftFoot; case PoseLandmarkType.RightAnkle: return HumanBodyBones.RightFoot; case PoseLandmarkType.LeftFootIndex: return HumanBodyBones.LeftToes; case PoseLandmarkType.RightFootIndex: return HumanBodyBones.RightToes; default: return HumanBodyBones.LastBone; } } } }