69 lines
2.0 KiB
C#
69 lines
2.0 KiB
C#
using UnityEngine;
|
|
using System.Collections.Generic;
|
|
|
|
public class OptitrackRawDataReceiver : MonoBehaviour
|
|
{
|
|
[Header("OptiTrack 설정")]
|
|
public OptitrackStreamingClient StreamingClient;
|
|
public string SkeletonAssetName = "Skeleton1";
|
|
|
|
private OptitrackSkeletonDefinition m_skeletonDef;
|
|
private Dictionary<int, OptitrackPose> m_lastBonePoses = new Dictionary<int, OptitrackPose>();
|
|
|
|
void Start()
|
|
{
|
|
if (StreamingClient == null)
|
|
{
|
|
StreamingClient = FindFirstObjectByType<OptitrackStreamingClient>();
|
|
if (StreamingClient == null)
|
|
{
|
|
Debug.LogError("OptiTrack Streaming Client를 찾을 수 없습니다.");
|
|
return;
|
|
}
|
|
}
|
|
|
|
// 스켈레톤 등록
|
|
StreamingClient.RegisterSkeleton(this, SkeletonAssetName);
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (StreamingClient == null) return;
|
|
|
|
// 스켈레톤 정의 가져오기
|
|
if (m_skeletonDef == null)
|
|
{
|
|
m_skeletonDef = StreamingClient.GetSkeletonDefinitionByName(SkeletonAssetName);
|
|
if (m_skeletonDef == null) return;
|
|
}
|
|
|
|
// 최신 스켈레톤 상태 가져오기
|
|
OptitrackSkeletonState skelState = StreamingClient.GetLatestSkeletonState(m_skeletonDef.Id);
|
|
if (skelState == null) return;
|
|
|
|
// 각 본의 원본 데이터 저장
|
|
foreach (var bone in m_skeletonDef.Bones)
|
|
{
|
|
if (skelState.LocalBonePoses.TryGetValue(bone.Id, out OptitrackPose bonePose))
|
|
{
|
|
m_lastBonePoses[bone.Id] = bonePose;
|
|
}
|
|
}
|
|
}
|
|
|
|
// 외부에서 원본 데이터 접근을 위한 메서드
|
|
public Dictionary<int, OptitrackPose> GetRawBonePoses()
|
|
{
|
|
return m_lastBonePoses;
|
|
}
|
|
|
|
// 특정 본의 원본 데이터 가져오기
|
|
public OptitrackPose GetRawBonePose(int boneId)
|
|
{
|
|
if (m_lastBonePoses.TryGetValue(boneId, out OptitrackPose pose))
|
|
{
|
|
return pose;
|
|
}
|
|
return null;
|
|
}
|
|
} |