npz 파일 로드

Assets/StreamingAssets/01_05_poses.npz 파일 넣고 아래 코드로 로드

csharp

byte[] bytes = File.ReadAllBytes(path); var stream = new MemoryStream(bytes); var npz = new NpzDictionary(stream, false);

File.ReadAllBytes로 파일을 바이트 배열로 읽고 → MemoryStream으로 감싸서 → NpzDictionary에 넘기는 방식. 두 번째 인자 false는 jagged array 미사용 옵션.


poses / trans 키 접근

NpzDictionary의 키 이름에 .npy가 붙어있으므로 아래처럼 접근

csharp

NDArray poses = npz["poses.npy"]; NDArray trans = npz["trans.npy"];

"poses"로 접근하면 KeyNotFoundException 발생하므로 반드시 .npy 붙여야 함. 데이터 타입은 float이 아닌 double로 저장되어 있음.


첫 프레임 joint 값 콘솔 출력

csharp

double[] frame0 = poses[0].ToArray<double>(); for (int i = 0; i < 10; i++) { int joint = i / 3; int axis = i % 3; Debug.Log($"joint[{joint}] axis[{axis}] = {frame0[i]:F4}"); }

poses[0]으로 첫 프레임 슬라이싱 → ToArray<double>()로 변환 → 3개씩 묶어서 관절번호/축(X=0, Y=1, Z=2)으로 나눠 출력. float으로 받으면 ArrayTypeMismatchException 발생하므로 반드시 double 사용.

코드

using UnityEngine;
using System.IO;
using NumSharp;

public class AMASSLoader : MonoBehaviour
{
    void Start()
    {
        string path = Path.Combine(Application.streamingAssetsPath, "01_05_poses.npz");

        if (!File.Exists(path))
        {
            Debug.LogError("파일을 찾을 수 없습니다: " + path);
            return;
        }

        byte[] bytes = File.ReadAllBytes(path);
        var stream = new MemoryStream(bytes);
        var npz = new NpzDictionary(stream, false);

        foreach (var key in npz.Keys)
        {
            Debug.Log("key: " + key);
        }

        NDArray poses = npz["poses.npy"];
        Debug.Log("poses shape: " + poses.shape);

        NDArray trans = npz["trans.npy"];
        Debug.Log("trans shape: " + trans.shape);

        double[] frame0 = poses[0].ToArray<double>();
        for (int i = 0; i < 10; i++)
        {
            int joint = i / 3;
            int axis = i % 3;
            Debug.Log($"joint[{joint}] axis[{axis}] = {frame0[i]:F4}");
        }
    }
}