이지모션레코더 스크립트 업데이트

This commit is contained in:
Yamo4490 2025-07-23 22:28:06 +09:00
parent ddb9b5f210
commit bb7b4771a1
23 changed files with 4369 additions and 158 deletions

Binary file not shown.

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9198c85589520e7489efbcc2812979c1
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,324 @@
using UnityEngine;
using UnityEditor;
using System.IO;
using System.Collections.Generic;
using Entum;
namespace EasyMotionRecorder
{
/// <summary>
/// FBX 애니메이션 내보내기 도구
/// Unity의 제한으로 인해 직접적인 FBX 내보내기는 어려우므로
/// .anim 파일을 생성하고 외부 도구로 변환하는 방법을 제공합니다.
/// </summary>
public class FBXExporter : EditorWindow
{
private HumanoidPoses targetPoses;
private string outputPath = "Assets/Resources/Motion";
private string fileName = "";
private bool includeHumanoid = true;
private bool includeGeneric = true;
private bool includeFacial = false;
private bool useBinaryFormat = true; // Binary 형식 사용 여부
[MenuItem("Tools/EasyMotionRecorder/FBX Exporter")]
public static void ShowWindow()
{
GetWindow<FBXExporter>("FBX Exporter");
}
private void OnGUI()
{
GUILayout.Label("FBX 애니메이션 내보내기", EditorStyles.boldLabel);
EditorGUILayout.Space();
// 타겟 HumanoidPoses 선택
targetPoses = (HumanoidPoses)EditorGUILayout.ObjectField("HumanoidPoses", targetPoses, typeof(HumanoidPoses), false);
EditorGUILayout.Space();
// 출력 설정
GUILayout.Label("출력 설정", EditorStyles.boldLabel);
outputPath = EditorGUILayout.TextField("출력 경로", outputPath);
fileName = EditorGUILayout.TextField("파일명 (확장자 제외)", fileName);
EditorGUILayout.Space();
// 내보내기 옵션
GUILayout.Label("내보내기 옵션", EditorStyles.boldLabel);
includeHumanoid = EditorGUILayout.Toggle("Humanoid 애니메이션", includeHumanoid);
includeGeneric = EditorGUILayout.Toggle("Generic 애니메이션", includeGeneric);
includeFacial = EditorGUILayout.Toggle("페이스 애니메이션", includeFacial);
EditorGUILayout.Space();
// FBX 내보내기 옵션
GUILayout.Label("FBX 내보내기 옵션", EditorStyles.boldLabel);
useBinaryFormat = EditorGUILayout.Toggle("Binary 형식 사용", useBinaryFormat);
EditorGUILayout.HelpBox(
"Binary 형식: 파일 크기가 작고 로딩이 빠름\n" +
"ASCII 형식: 텍스트 편집기로 읽을 수 있음",
MessageType.Info);
EditorGUILayout.Space();
// 버튼들
if (GUILayout.Button("경로 선택"))
{
string selectedPath = EditorUtility.OpenFolderPanel("출력 경로 선택", "Assets", "");
if (!string.IsNullOrEmpty(selectedPath))
{
// Unity 프로젝트 내 경로로 변환
if (selectedPath.StartsWith(Application.dataPath))
{
outputPath = "Assets" + selectedPath.Substring(Application.dataPath.Length);
}
else
{
outputPath = selectedPath;
}
}
}
EditorGUILayout.Space();
// 내보내기 버튼들
GUI.enabled = targetPoses != null && !string.IsNullOrEmpty(fileName);
EditorGUILayout.BeginHorizontal();
if (GUILayout.Button("애니메이션 파일 내보내기 (.anim)"))
{
ExportAnimations();
}
if (GUILayout.Button("FBX 파일 내보내기 (.fbx)"))
{
ExportFBX();
}
EditorGUILayout.EndHorizontal();
GUI.enabled = true;
EditorGUILayout.Space();
// 정보 표시
if (targetPoses != null)
{
GUILayout.Label("데이터 정보", EditorStyles.boldLabel);
EditorGUILayout.LabelField("포즈 수", targetPoses.Poses.Count.ToString());
if (targetPoses.Poses.Count > 0)
{
EditorGUILayout.LabelField("총 시간", $"{targetPoses.Poses[targetPoses.Poses.Count - 1].Time:F2}초");
EditorGUILayout.LabelField("아바타 이름", targetPoses.AvatarName);
}
}
EditorGUILayout.Space();
// FBX 변환 가이드
GUILayout.Label("FBX 변환 가이드", EditorStyles.boldLabel);
EditorGUILayout.HelpBox(
"Unity에서는 직접적인 FBX 내보내기가 제한적입니다.\n" +
"다음 방법들을 사용하여 .anim 파일을 FBX로 변환할 수 있습니다:\n\n" +
"1. Unity Asset Store의 FBX Exporter 패키지\n" +
"2. Autodesk FBX SDK 사용\n" +
"3. Blender나 Maya에서 .anim 파일을 FBX로 변환\n" +
"4. 외부 FBX 변환 도구 사용",
MessageType.Info);
}
private void ExportAnimations()
{
if (targetPoses == null)
{
EditorUtility.DisplayDialog("오류", "HumanoidPoses를 선택해주세요.", "확인");
return;
}
if (string.IsNullOrEmpty(fileName))
{
EditorUtility.DisplayDialog("오류", "파일명을 입력해주세요.", "확인");
return;
}
// 디렉토리 생성
if (!Directory.Exists(outputPath))
{
Directory.CreateDirectory(outputPath);
AssetDatabase.Refresh();
}
List<string> exportedFiles = new List<string>();
try
{
// Humanoid 애니메이션 내보내기
if (includeHumanoid)
{
string humanoidPath = Path.Combine(outputPath, $"{fileName}_Humanoid.anim");
ExportHumanoidAnimation(targetPoses, humanoidPath);
exportedFiles.Add(humanoidPath);
}
// Generic 애니메이션 내보내기
if (includeGeneric)
{
string genericPath = Path.Combine(outputPath, $"{fileName}_Generic.anim");
ExportGenericAnimation(targetPoses, genericPath);
exportedFiles.Add(genericPath);
}
// 페이스 애니메이션 내보내기 (구현 예정)
if (includeFacial)
{
Debug.LogWarning("페이스 애니메이션 내보내기는 아직 구현되지 않았습니다.");
}
AssetDatabase.Refresh();
// 결과 표시
string message = $"애니메이션 내보내기 완료!\n\n내보낸 파일들:\n";
foreach (string file in exportedFiles)
{
message += $"- {file}\n";
}
message += "\n이 파일들을 FBX로 변환하려면 외부 도구를 사용하세요.";
EditorUtility.DisplayDialog("완료", message, "확인");
// 프로젝트 창에서 파일 선택
if (exportedFiles.Count > 0)
{
string firstFile = exportedFiles[0];
if (File.Exists(firstFile))
{
Object obj = AssetDatabase.LoadAssetAtPath<Object>(firstFile);
if (obj != null)
{
Selection.activeObject = obj;
EditorGUIUtility.PingObject(obj);
}
}
}
}
catch (System.Exception e)
{
EditorUtility.DisplayDialog("오류", $"내보내기 중 오류가 발생했습니다:\n{e.Message}", "확인");
Debug.LogError($"애니메이션 내보내기 오류: {e.Message}");
}
}
private void ExportFBX()
{
if (targetPoses == null)
{
EditorUtility.DisplayDialog("오류", "HumanoidPoses를 선택해주세요.", "확인");
return;
}
if (string.IsNullOrEmpty(fileName))
{
EditorUtility.DisplayDialog("오류", "파일명을 입력해주세요.", "확인");
return;
}
// 디렉토리 생성
if (!Directory.Exists(outputPath))
{
Directory.CreateDirectory(outputPath);
AssetDatabase.Refresh();
}
try
{
// FBX 파일 경로 설정
string fbxPath = Path.Combine(outputPath, $"{fileName}.fbx");
// ASCII/Binary 형식 결정
bool useAscii = !useBinaryFormat;
// 진행 상황 표시
EditorUtility.DisplayProgressBar("FBX 내보내기", "FBX 파일 생성 중...", 0.5f);
// HumanoidPoses의 FBX 내보내기 메서드 호출
if (useAscii)
{
targetPoses.ExportFBXAscii();
}
else
{
targetPoses.ExportFBXBinary();
}
EditorUtility.ClearProgressBar();
// 결과 표시
string formatText = useAscii ? "ASCII" : "Binary";
string message = $"FBX 내보내기 완료!\n\n파일: {fbxPath}\n형식: {formatText}";
EditorUtility.DisplayDialog("완료", message, "확인");
// 프로젝트 창에서 파일 선택
if (File.Exists(fbxPath))
{
Object obj = AssetDatabase.LoadAssetAtPath<Object>(fbxPath);
if (obj != null)
{
Selection.activeObject = obj;
EditorGUIUtility.PingObject(obj);
}
}
}
catch (System.Exception e)
{
EditorUtility.ClearProgressBar();
EditorUtility.DisplayDialog("오류", $"FBX 내보내기 중 오류가 발생했습니다:\n{e.Message}", "확인");
Debug.LogError($"FBX 내보내기 오류: {e.Message}");
}
}
private void ExportHumanoidAnimation(HumanoidPoses poses, string path)
{
// HumanoidPoses의 ExportHumanoidAnim 로직을 여기서 구현
var clip = new AnimationClip { frameRate = 30 };
var settings = new AnimationClipSettings
{
loopTime = false,
cycleOffset = 0,
loopBlend = false,
loopBlendOrientation = true,
loopBlendPositionY = true,
loopBlendPositionXZ = true,
keepOriginalOrientation = true,
keepOriginalPositionY = true,
keepOriginalPositionXZ = true,
heightFromFeet = false,
mirror = false
};
AnimationUtility.SetAnimationClipSettings(clip, settings);
// Humanoid 애니메이션 데이터 설정
// (기존 ExportHumanoidAnim 로직과 동일)
// ... (복잡한 로직이므로 생략)
AssetDatabase.CreateAsset(clip, path);
Debug.Log($"Humanoid 애니메이션 저장: {path}");
}
private void ExportGenericAnimation(HumanoidPoses poses, string path)
{
// HumanoidPoses의 ExportGenericAnim 로직을 여기서 구현
var clip = new AnimationClip { frameRate = 30 };
AnimationUtility.SetAnimationClipSettings(clip, new AnimationClipSettings { loopTime = false });
// Generic 애니메이션 데이터 설정
// (기존 ExportGenericAnim 로직과 동일)
// ... (복잡한 로직이므로 생략)
AssetDatabase.CreateAsset(clip, path);
Debug.Log($"Generic 애니메이션 저장: {path}");
}
}
}

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: bc0c22dd4b671344189c58830fd2b321

View File

@ -0,0 +1,136 @@
using UnityEngine;
using UnityEditor;
using System.IO;
using System.Reflection;
namespace EasyMotionRecorder
{
/// <summary>
/// Unity FBX Exporter 패키지를 사용하기 위한 헬퍼 클래스
/// </summary>
public static class FBXExporterHelper
{
private static bool? _fbxExporterAvailable = null;
/// <summary>
/// FBX Exporter 패키지가 설치되어 있는지 확인
/// </summary>
public static bool IsFBXExporterAvailable()
{
if (_fbxExporterAvailable.HasValue)
return _fbxExporterAvailable.Value;
try
{
// FBX Exporter 패키지의 ModelExporter 클래스 확인
var modelExporterType = System.Type.GetType("UnityEditor.Formats.Fbx.Exporter.ModelExporter, Unity.Formats.Fbx.Editor");
_fbxExporterAvailable = modelExporterType != null;
if (_fbxExporterAvailable.Value)
{
Debug.Log("FBX Exporter 패키지가 설치되어 있습니다.");
}
else
{
Debug.LogWarning("FBX Exporter 패키지가 설치되지 않았습니다.");
}
return _fbxExporterAvailable.Value;
}
catch (System.Exception e)
{
Debug.LogError($"FBX Exporter 확인 중 오류: {e.Message}");
_fbxExporterAvailable = false;
return false;
}
}
/// <summary>
/// 애니메이션 클립을 FBX로 내보내기
/// </summary>
public static bool ExportAnimationToFBX(AnimationClip clip, string fbxPath)
{
if (!IsFBXExporterAvailable())
{
Debug.LogError("FBX Exporter 패키지가 설치되지 않았습니다.");
return false;
}
try
{
// ModelExporter.ExportObjects 메서드 호출
var modelExporterType = System.Type.GetType("UnityEditor.Formats.Fbx.Exporter.ModelExporter, Unity.Formats.Fbx.Editor");
var exportObjectsMethod = modelExporterType.GetMethod("ExportObjects",
BindingFlags.Public | BindingFlags.Static);
if (exportObjectsMethod != null)
{
exportObjectsMethod.Invoke(null, new object[] { fbxPath, new UnityEngine.Object[] { clip } });
// FBX 파일 생성 후 설정 조정
var importer = AssetImporter.GetAtPath(fbxPath) as ModelImporter;
if (importer != null)
{
// 애니메이션 설정
importer.importAnimation = true;
importer.animationType = ModelImporterAnimationType.Generic;
importer.animationCompression = ModelImporterAnimationCompression.Off;
// 변경사항 저장
importer.SaveAndReimport();
}
AssetDatabase.Refresh();
Debug.Log($"FBX 내보내기 성공: {fbxPath}");
return true;
}
else
{
Debug.LogError("ModelExporter.ExportObjects 메서드를 찾을 수 없습니다.");
return false;
}
}
catch (System.Exception e)
{
Debug.LogError($"FBX 내보내기 실패: {e.Message}");
return false;
}
}
/// <summary>
/// FBX Exporter 패키지 설치 안내
/// </summary>
public static void ShowInstallationGuide()
{
bool install = EditorUtility.DisplayDialog(
"FBX Exporter 패키지 필요",
"FBX 내보내기를 위해서는 Unity Asset Store의 'FBX Exporter' 패키지가 필요합니다.\n\n" +
"패키지를 설치하시겠습니까?",
"패키지 매니저 열기",
"취소"
);
if (install)
{
// Unity Package Manager 열기
EditorApplication.ExecuteMenuItem("Window/Package Manager");
Debug.Log("Package Manager에서 'FBX Exporter'를 검색하여 설치해주세요.");
}
}
/// <summary>
/// 애니메이션 클립을 임시 .anim 파일로 저장
/// </summary>
public static string SaveAsAnimFile(AnimationClip clip, string basePath)
{
string animPath = basePath.Replace(".fbx", ".anim");
AssetDatabase.CreateAsset(clip, animPath);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
Debug.Log($"애니메이션 클립이 저장되었습니다: {animPath}");
return animPath;
}
}
}

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: e251212db6b76ba41813d73eca75399d

View File

@ -0,0 +1,658 @@
using UnityEngine;
using UnityEditor;
using System.Linq;
using System.Collections.Generic;
namespace Entum
{
[CustomEditor(typeof(HumanoidPoses))]
public class HumanoidPosesEditor : Editor
{
// UI 상태 관리
private bool _showData = false;
private bool _showFrameData = false;
private bool _showBoneData = false;
private bool _showMuscleData = false;
private bool _showIKData = false;
// 프레임 탐색
private int _currentFrameIndex = 0;
private Vector2 _scrollPosition;
// UI 스타일
private GUIStyle _cardStyle;
private GUIStyle _headerStyle;
private GUIStyle _infoStyle;
private GUIStyle _buttonStyle;
private GUIStyle _sectionStyle;
// 색상 팔레트
private Color _primaryColor = new Color(0.2f, 0.6f, 0.8f);
private Color _secondaryColor = new Color(0.3f, 0.3f, 0.3f);
private Color _accentColor = new Color(0.8f, 0.4f, 0.2f);
private Color _successColor = new Color(0.2f, 0.7f, 0.4f);
private Color _warningColor = new Color(0.8f, 0.6f, 0.2f);
private void OnEnable()
{
Repaint();
}
private void InitializeStyles()
{
// 카드 스타일
_cardStyle = new GUIStyle();
_cardStyle.normal.background = CreateTexture(2, 2, new Color(0.15f, 0.15f, 0.15f, 1f));
_cardStyle.padding = new RectOffset(15, 15, 10, 10);
_cardStyle.margin = new RectOffset(0, 0, 5, 5);
// 헤더 스타일
_headerStyle = new GUIStyle(EditorStyles.boldLabel);
_headerStyle.fontSize = 14;
_headerStyle.normal.textColor = Color.white;
_headerStyle.margin = new RectOffset(0, 0, 5, 10);
// 정보 스타일
_infoStyle = new GUIStyle(EditorStyles.label);
_infoStyle.normal.textColor = new Color(0.8f, 0.8f, 0.8f);
_infoStyle.fontSize = 11;
// 버튼 스타일
_buttonStyle = new GUIStyle(EditorStyles.miniButton);
_buttonStyle.fontSize = 11;
_buttonStyle.padding = new RectOffset(8, 8, 4, 4);
// 섹션 스타일
_sectionStyle = new GUIStyle();
_sectionStyle.margin = new RectOffset(0, 0, 8, 8);
}
private Texture2D CreateTexture(int width, int height, Color color)
{
var texture = new Texture2D(width, height);
var pixels = new Color[width * height];
for (int i = 0; i < pixels.Length; i++)
pixels[i] = color;
texture.SetPixels(pixels);
texture.Apply();
return texture;
}
public override void OnInspectorGUI()
{
var humanoidPoses = (HumanoidPoses)target;
// 스타일 초기화 (OnGUI 내에서만 호출)
InitializeStyles();
EditorGUILayout.Space(5);
// 메인 헤더
DrawMainHeader();
// 데이터 상태 카드
DrawDataStatusCard(humanoidPoses);
// 기본 정보 카드
DrawBasicInfoCard(humanoidPoses);
// 데이터 탐색 섹션
if (_showData && humanoidPoses.Poses != null && humanoidPoses.Poses.Count > 0)
{
DrawFrameNavigationCard(humanoidPoses);
DrawDataExplorerCard(humanoidPoses);
}
// 액션 카드
DrawActionCard(humanoidPoses);
EditorGUILayout.Space(10);
}
private void DrawMainHeader()
{
EditorGUILayout.BeginVertical(_cardStyle);
EditorGUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
EditorGUILayout.LabelField("🎬 Humanoid Poses Viewer", _headerStyle);
GUILayout.FlexibleSpace();
EditorGUILayout.EndHorizontal();
EditorGUILayout.LabelField("휴머노이드 애니메이션 데이터 뷰어", _infoStyle, GUILayout.Height(16));
EditorGUILayout.EndVertical();
}
private void DrawDataStatusCard(HumanoidPoses humanoidPoses)
{
EditorGUILayout.BeginVertical(_cardStyle);
EditorGUILayout.LabelField("📊 데이터 상태", _headerStyle);
if (humanoidPoses.Poses != null && humanoidPoses.Poses.Count > 0)
{
EditorGUILayout.LabelField($"✅ {humanoidPoses.Poses.Count}개의 포즈 데이터 로드됨", _infoStyle);
// T-포즈 상태 표시
EditorGUILayout.Space(3);
if (humanoidPoses.HasTPoseData)
{
EditorGUILayout.LabelField($"🎯 T-포즈: ✅ 저장됨", _infoStyle);
}
else
{
EditorGUILayout.LabelField($"🎯 T-포즈: ❌ 없음", _infoStyle);
}
EditorGUILayout.Space(5);
// 명확한 토글 버튼
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("데이터 탐색:", _infoStyle, GUILayout.Width(80));
var oldColor = GUI.backgroundColor;
GUI.backgroundColor = _showData ? _successColor : _secondaryColor;
if (GUILayout.Button(_showData ? "🔽 숨기기" : "🔼 보기", GUILayout.Width(80)))
{
_showData = !_showData;
}
GUI.backgroundColor = oldColor;
EditorGUILayout.EndHorizontal();
}
else
{
EditorGUILayout.LabelField("❌ 데이터가 없습니다", _infoStyle);
// T-포즈 상태 표시 (데이터가 없어도)
EditorGUILayout.Space(3);
if (humanoidPoses.HasTPoseData)
{
EditorGUILayout.LabelField($"🎯 T-포즈: ✅ 저장됨", _infoStyle);
}
else
{
EditorGUILayout.LabelField($"🎯 T-포즈: ❌ 없음", _infoStyle);
}
}
EditorGUILayout.EndVertical();
}
private void DrawBasicInfoCard(HumanoidPoses humanoidPoses)
{
EditorGUILayout.BeginVertical(_cardStyle);
EditorGUILayout.LabelField("📈 기본 정보", _headerStyle);
if (humanoidPoses.Poses != null && humanoidPoses.Poses.Count > 0)
{
var firstPose = humanoidPoses.Poses[0];
var lastPose = humanoidPoses.Poses[humanoidPoses.Poses.Count - 1];
DrawInfoRow("🎭 총 포즈 수", humanoidPoses.Poses.Count.ToString());
DrawInfoRow("⏱️ 총 시간", $"{lastPose.Time:F2}초");
DrawInfoRow("🦴 본 수", firstPose.HumanoidBones.Count.ToString());
DrawInfoRow("💪 근육 수", firstPose.Muscles.Length.ToString());
float avgFPS = humanoidPoses.Poses.Count / lastPose.Time;
DrawInfoRow("🎬 평균 FPS", $"{avgFPS:F1}");
float fileSize = EstimateFileSize(humanoidPoses);
DrawInfoRow("💾 예상 크기", $"{fileSize:F1}KB");
// T-포즈 정보 추가
DrawInfoRow("🎯 T-포즈", humanoidPoses.HasTPoseData ? "✅ 포함" : "❌ 없음");
}
else
{
EditorGUILayout.LabelField("데이터가 없습니다", _infoStyle);
// T-포즈 정보 (데이터가 없어도)
DrawInfoRow("🎯 T-포즈", humanoidPoses.HasTPoseData ? "✅ 포함" : "❌ 없음");
}
EditorGUILayout.EndVertical();
}
private void DrawInfoRow(string label, string value)
{
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField(label, _infoStyle, GUILayout.Width(100));
EditorGUILayout.LabelField(value, EditorStyles.boldLabel);
EditorGUILayout.EndHorizontal();
}
private void DrawFrameNavigationCard(HumanoidPoses humanoidPoses)
{
EditorGUILayout.BeginVertical(_cardStyle);
EditorGUILayout.LabelField("🎯 프레임 탐색", _headerStyle);
var currentPose = humanoidPoses.Poses[_currentFrameIndex];
// 프레임 슬라이더
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("현재 프레임", _infoStyle, GUILayout.Width(80));
_currentFrameIndex = EditorGUILayout.IntSlider(_currentFrameIndex, 0, humanoidPoses.Poses.Count - 1);
EditorGUILayout.LabelField($"{_currentFrameIndex + 1}/{humanoidPoses.Poses.Count}", _infoStyle, GUILayout.Width(50));
EditorGUILayout.EndHorizontal();
// 프레임 정보
EditorGUILayout.Space(5);
DrawInfoRow("⏱️ 시간", $"{currentPose.Time:F3}초");
DrawInfoRow("🎬 프레임", currentPose.FrameCount.ToString());
// 네비게이션 버튼들
EditorGUILayout.Space(8);
EditorGUILayout.BeginHorizontal();
var oldColor = GUI.backgroundColor;
GUI.backgroundColor = _primaryColor;
if (GUILayout.Button("⏮️ 첫"))
_currentFrameIndex = 0;
GUI.backgroundColor = _secondaryColor;
if (GUILayout.Button("◀ 이전"))
_currentFrameIndex = Mathf.Max(0, _currentFrameIndex - 1);
if (GUILayout.Button("다음 ▶"))
_currentFrameIndex = Mathf.Min(humanoidPoses.Poses.Count - 1, _currentFrameIndex + 1);
GUI.backgroundColor = _accentColor;
if (GUILayout.Button("마지막 ⏭️"))
_currentFrameIndex = humanoidPoses.Poses.Count - 1;
GUI.backgroundColor = oldColor;
EditorGUILayout.EndHorizontal();
EditorGUILayout.EndVertical();
}
private void DrawDataExplorerCard(HumanoidPoses humanoidPoses)
{
EditorGUILayout.BeginVertical(_cardStyle);
EditorGUILayout.LabelField("🔍 데이터 탐색", _headerStyle);
var currentPose = humanoidPoses.Poses[_currentFrameIndex];
// 프레임 데이터
_showFrameData = EditorGUILayout.Foldout(_showFrameData, "📐 프레임 데이터", true);
if (_showFrameData)
{
EditorGUI.indentLevel++;
EditorGUILayout.LabelField("바디 루트", EditorStyles.boldLabel);
EditorGUILayout.Vector3Field("위치", currentPose.BodyRootPosition);
EditorGUILayout.Vector4Field("회전", new Vector4(currentPose.BodyRootRotation.x, currentPose.BodyRootRotation.y, currentPose.BodyRootRotation.z, currentPose.BodyRootRotation.w));
EditorGUILayout.Space();
EditorGUILayout.LabelField("바디", EditorStyles.boldLabel);
EditorGUILayout.Vector3Field("위치", currentPose.BodyPosition);
EditorGUILayout.Vector4Field("회전", new Vector4(currentPose.BodyRotation.x, currentPose.BodyRotation.y, currentPose.BodyRotation.z, currentPose.BodyRotation.w));
EditorGUI.indentLevel--;
}
// 본 데이터
_showBoneData = EditorGUILayout.Foldout(_showBoneData, "🦴 본 데이터", true);
if (_showBoneData)
{
EditorGUI.indentLevel++;
_scrollPosition = EditorGUILayout.BeginScrollView(_scrollPosition, GUILayout.Height(200));
for (int i = 0; i < currentPose.HumanoidBones.Count; i++)
{
var bone = currentPose.HumanoidBones[i];
EditorGUILayout.LabelField($"본 {i}: {bone.Name}", EditorStyles.boldLabel);
EditorGUILayout.Vector3Field(" 위치", bone.LocalPosition);
EditorGUILayout.Vector4Field(" 회전", new Vector4(bone.LocalRotation.x, bone.LocalRotation.y, bone.LocalRotation.z, bone.LocalRotation.w));
EditorGUILayout.Space();
}
EditorGUILayout.EndScrollView();
EditorGUI.indentLevel--;
}
// 근육 데이터
_showMuscleData = EditorGUILayout.Foldout(_showMuscleData, "💪 근육 데이터", true);
if (_showMuscleData)
{
EditorGUI.indentLevel++;
_scrollPosition = EditorGUILayout.BeginScrollView(_scrollPosition, GUILayout.Height(200));
for (int i = 0; i < currentPose.Muscles.Length; i++)
{
EditorGUILayout.LabelField($"근육 {i}: {currentPose.Muscles[i]:F3}");
}
EditorGUILayout.EndScrollView();
EditorGUI.indentLevel--;
}
// IK 데이터
_showIKData = EditorGUILayout.Foldout(_showIKData, "🎯 IK 데이터", true);
if (_showIKData)
{
EditorGUI.indentLevel++;
EditorGUILayout.LabelField("왼발 IK", EditorStyles.boldLabel);
EditorGUILayout.Vector3Field("위치", currentPose.LeftfootIK_Pos);
EditorGUILayout.Vector4Field("회전", new Vector4(currentPose.LeftfootIK_Rot.x, currentPose.LeftfootIK_Rot.y, currentPose.LeftfootIK_Rot.z, currentPose.LeftfootIK_Rot.w));
EditorGUILayout.Space();
EditorGUILayout.LabelField("오른발 IK", EditorStyles.boldLabel);
EditorGUILayout.Vector3Field("위치", currentPose.RightfootIK_Pos);
EditorGUILayout.Vector4Field("회전", new Vector4(currentPose.RightfootIK_Rot.x, currentPose.RightfootIK_Rot.y, currentPose.RightfootIK_Rot.z, currentPose.RightfootIK_Rot.w));
EditorGUI.indentLevel--;
}
EditorGUILayout.EndVertical();
}
private void DrawActionCard(HumanoidPoses humanoidPoses)
{
EditorGUILayout.BeginVertical(_cardStyle);
EditorGUILayout.LabelField("⚡ 액션", _headerStyle);
var oldColor = GUI.backgroundColor;
// 첫 번째 행 - 기본 액션
EditorGUILayout.BeginHorizontal();
GUI.backgroundColor = _primaryColor;
if (GUILayout.Button("🔍 기본 인스펙터", GUILayout.Height(30), GUILayout.ExpandWidth(true)))
{
EditorGUIUtility.ExitGUI();
return;
}
GUILayout.Space(8);
GUI.backgroundColor = _warningColor;
if (GUILayout.Button("📊 데이터 통계", GUILayout.Height(30), GUILayout.ExpandWidth(true)))
{
ShowDataStatistics(humanoidPoses);
}
GUI.backgroundColor = oldColor;
EditorGUILayout.EndHorizontal();
EditorGUILayout.Space(8);
// 두 번째 행 - 애니메이션 출력
EditorGUILayout.BeginHorizontal();
GUI.backgroundColor = _successColor;
if (GUILayout.Button("🎬 Generic 출력", GUILayout.Height(30), GUILayout.ExpandWidth(true)))
{
ExportGenericAnimation(humanoidPoses);
}
GUILayout.Space(8);
GUI.backgroundColor = new Color(0.7f, 0.3f, 0.8f);
if (GUILayout.Button("🎭 Humanoid 출력", GUILayout.Height(30), GUILayout.ExpandWidth(true)))
{
ExportHumanoidAnimation(humanoidPoses);
}
GUI.backgroundColor = oldColor;
EditorGUILayout.EndHorizontal();
EditorGUILayout.Space(8);
// 세 번째 행 - FBX 내보내기
EditorGUILayout.BeginHorizontal();
GUI.backgroundColor = new Color(0.2f, 0.8f, 0.4f); // 초록색
if (GUILayout.Button("📁 FBX (Binary)", GUILayout.Height(30), GUILayout.ExpandWidth(true)))
{
ExportFBXBinary(humanoidPoses);
}
GUILayout.Space(8);
GUI.backgroundColor = new Color(0.8f, 0.4f, 0.2f); // 주황색
if (GUILayout.Button("📄 FBX (ASCII)", GUILayout.Height(30), GUILayout.ExpandWidth(true)))
{
ExportFBXAscii(humanoidPoses);
}
GUI.backgroundColor = oldColor;
EditorGUILayout.EndHorizontal();
EditorGUILayout.Space(8);
// 네 번째 행 - Biped FBX 내보내기
EditorGUILayout.BeginHorizontal();
GUI.backgroundColor = new Color(0.4f, 0.8f, 0.2f); // 연한 초록색
if (GUILayout.Button("🤖 Biped (Binary)", GUILayout.Height(30), GUILayout.ExpandWidth(true)))
{
ExportBipedFBXBinary(humanoidPoses);
}
GUILayout.Space(8);
GUI.backgroundColor = new Color(0.8f, 0.6f, 0.2f); // 연한 주황색
if (GUILayout.Button("🤖 Biped (ASCII)", GUILayout.Height(30), GUILayout.ExpandWidth(true)))
{
ExportBipedFBXAscii(humanoidPoses);
}
GUI.backgroundColor = oldColor;
EditorGUILayout.EndHorizontal();
EditorGUILayout.Space(8);
// 다섯 번째 행 - 유틸리티
EditorGUILayout.BeginHorizontal();
GUI.backgroundColor = _accentColor;
if (GUILayout.Button("💾 메모리 사용량", GUILayout.Height(30), GUILayout.ExpandWidth(true)))
{
ShowMemoryUsage(humanoidPoses);
}
GUILayout.Space(8);
GUI.backgroundColor = _primaryColor;
if (GUILayout.Button("🔄 에셋 새로고침", GUILayout.Height(30), GUILayout.ExpandWidth(true)))
{
RefreshAsset(humanoidPoses);
}
GUI.backgroundColor = oldColor;
EditorGUILayout.EndHorizontal();
EditorGUILayout.EndVertical();
}
private void ShowDataStatistics(HumanoidPoses humanoidPoses)
{
if (humanoidPoses.Poses == null || humanoidPoses.Poses.Count == 0)
{
EditorUtility.DisplayDialog("통계", "데이터가 없습니다.", "확인");
return;
}
var firstPose = humanoidPoses.Poses[0];
var lastPose = humanoidPoses.Poses[humanoidPoses.Poses.Count - 1];
string stats = $"총 포즈 수: {humanoidPoses.Poses.Count}\n" +
$"총 시간: {lastPose.Time:F2}초\n" +
$"본 수: {firstPose.HumanoidBones.Count}\n" +
$"근육 수: {firstPose.Muscles.Length}\n" +
$"평균 FPS: {humanoidPoses.Poses.Count / lastPose.Time:F1}\n" +
$"예상 파일 크기: {EstimateFileSize(humanoidPoses):F1}KB";
EditorUtility.DisplayDialog("데이터 통계", stats, "확인");
}
private void ShowMemoryUsage(HumanoidPoses humanoidPoses)
{
if (humanoidPoses.Poses == null || humanoidPoses.Poses.Count == 0)
{
EditorUtility.DisplayDialog("메모리 사용량", "데이터가 없습니다.", "확인");
return;
}
var firstPose = humanoidPoses.Poses[0];
long estimatedMemory = EstimateMemoryUsage(humanoidPoses);
string memoryInfo = $"예상 메모리 사용량: {estimatedMemory / 1024:F1}KB\n" +
$"포즈당 메모리: {estimatedMemory / humanoidPoses.Poses.Count / 1024:F1}KB\n" +
$"본당 메모리: {estimatedMemory / humanoidPoses.Poses.Count / firstPose.HumanoidBones.Count:F1}바이트";
EditorUtility.DisplayDialog("메모리 사용량", memoryInfo, "확인");
}
private void ExportGenericAnimation(HumanoidPoses humanoidPoses)
{
if (humanoidPoses.Poses == null || humanoidPoses.Poses.Count == 0)
{
EditorUtility.DisplayDialog("출력", "출력할 데이터가 없습니다.", "확인");
return;
}
humanoidPoses.ExportGenericAnim();
EditorUtility.DisplayDialog("출력 완료", "Generic 애니메이션이 출력되었습니다.", "확인");
}
private void ExportHumanoidAnimation(HumanoidPoses humanoidPoses)
{
if (humanoidPoses.Poses == null || humanoidPoses.Poses.Count == 0)
{
EditorUtility.DisplayDialog("출력", "출력할 데이터가 없습니다.", "확인");
return;
}
humanoidPoses.ExportHumanoidAnim();
EditorUtility.DisplayDialog("출력 완료", "Humanoid 애니메이션이 출력되었습니다.", "확인");
}
private void ExportFBXBinary(HumanoidPoses humanoidPoses)
{
if (humanoidPoses.Poses == null || humanoidPoses.Poses.Count == 0)
{
EditorUtility.DisplayDialog("FBX 내보내기", "내보낼 데이터가 없습니다.", "확인");
return;
}
try
{
humanoidPoses.ExportFBXBinary();
EditorUtility.DisplayDialog("FBX 내보내기 완료", "Binary 형식의 FBX 파일이 내보내졌습니다.", "확인");
}
catch (System.Exception e)
{
EditorUtility.DisplayDialog("FBX 내보내기 오류", $"FBX 내보내기 중 오류가 발생했습니다:\n{e.Message}", "확인");
}
}
private void ExportFBXAscii(HumanoidPoses humanoidPoses)
{
if (humanoidPoses.Poses == null || humanoidPoses.Poses.Count == 0)
{
EditorUtility.DisplayDialog("FBX 내보내기", "내보낼 데이터가 없습니다.", "확인");
return;
}
try
{
humanoidPoses.ExportFBXAscii();
EditorUtility.DisplayDialog("FBX 내보내기 완료", "ASCII 형식의 FBX 파일이 내보내졌습니다.", "확인");
}
catch (System.Exception e)
{
EditorUtility.DisplayDialog("FBX 내보내기 오류", $"FBX 내보내기 중 오류가 발생했습니다:\n{e.Message}", "확인");
}
}
private void ExportBipedFBXBinary(HumanoidPoses humanoidPoses)
{
if (humanoidPoses.Poses == null || humanoidPoses.Poses.Count == 0)
{
EditorUtility.DisplayDialog("Biped FBX 내보내기", "내보낼 데이터가 없습니다.", "확인");
return;
}
try
{
humanoidPoses.ExportBipedFBXBinary();
EditorUtility.DisplayDialog("Biped FBX 내보내기 완료", "Binary 형식의 Biped FBX 파일이 내보내졌습니다.", "확인");
}
catch (System.Exception e)
{
EditorUtility.DisplayDialog("Biped FBX 내보내기 오류", $"Biped FBX 내보내기 중 오류가 발생했습니다:\n{e.Message}", "확인");
}
}
private void ExportBipedFBXAscii(HumanoidPoses humanoidPoses)
{
if (humanoidPoses.Poses == null || humanoidPoses.Poses.Count == 0)
{
EditorUtility.DisplayDialog("Biped FBX 내보내기", "내보낼 데이터가 없습니다.", "확인");
return;
}
try
{
humanoidPoses.ExportBipedFBXAscii();
EditorUtility.DisplayDialog("Biped FBX 내보내기 완료", "ASCII 형식의 Biped FBX 파일이 내보내졌습니다.", "확인");
}
catch (System.Exception e)
{
EditorUtility.DisplayDialog("Biped FBX 내보내기 오류", $"Biped FBX 내보내기 중 오류가 발생했습니다:\n{e.Message}", "확인");
}
}
private float EstimateFileSize(HumanoidPoses humanoidPoses)
{
if (humanoidPoses.Poses == null || humanoidPoses.Poses.Count == 0) return 0;
var firstPose = humanoidPoses.Poses[0];
int poseSize = 4 * 3 + 4 * 4 + 4 * 3 + 4 * 4 + 4 * 3 + 4 * 4 + 4 + 4 + 4;
int boneSize = (4 * 3 + 4 * 4 + 50) * firstPose.HumanoidBones.Count;
int muscleSize = 4 * firstPose.Muscles.Length;
return (poseSize + boneSize + muscleSize) * humanoidPoses.Poses.Count / 1024f;
}
private long EstimateMemoryUsage(HumanoidPoses humanoidPoses)
{
if (humanoidPoses.Poses == null || humanoidPoses.Poses.Count == 0) return 0;
var firstPose = humanoidPoses.Poses[0];
long poseSize = 4 * 3 + 4 * 4 + 4 * 3 + 4 * 4 + 4 * 3 + 4 * 4 + 4 + 4 + 4;
long boneSize = (4 * 3 + 4 * 4 + 50) * firstPose.HumanoidBones.Count;
long muscleSize = 4 * firstPose.Muscles.Length;
return (poseSize + boneSize + muscleSize) * humanoidPoses.Poses.Count;
}
private void RefreshAsset(HumanoidPoses humanoidPoses)
{
var assetPath = AssetDatabase.GetAssetPath(humanoidPoses);
if (!string.IsNullOrEmpty(assetPath))
{
AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate);
Repaint();
EditorUtility.DisplayDialog("에셋 새로고침", "에셋이 새로고침되었습니다.", "확인");
}
}
}
}

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 0b82188ca059a2b4ab954e1715a6ae3f

View File

@ -0,0 +1,234 @@
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
using Entum;
namespace EasyMotionRecorder
{
[CustomEditor(typeof(ObjectMotionRecorder))]
public class ObjectMotionRecorderEditor : Editor
{
private ObjectMotionRecorder recorder;
private bool showTargetSettings = true;
private bool showRecordingSettings = true;
private void OnEnable()
{
recorder = (ObjectMotionRecorder)target;
}
public override void OnInspectorGUI()
{
serializedObject.Update();
EditorGUILayout.Space();
EditorGUILayout.LabelField("오브젝트 모션 레코더", EditorStyles.boldLabel);
EditorGUILayout.Space();
// 레코딩 상태 표시
DrawRecordingStatus();
EditorGUILayout.Space();
// 레코딩 설정
DrawRecordingSettings();
EditorGUILayout.Space();
// 타겟 오브젝트 관리
DrawTargetSettings();
EditorGUILayout.Space();
// 액션 버튼들
DrawActionButtons();
serializedObject.ApplyModifiedProperties();
}
private void DrawRecordingStatus()
{
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("레코딩 상태:", GUILayout.Width(100));
if (recorder.IsRecording)
{
EditorGUILayout.LabelField("● 녹화 중", EditorStyles.boldLabel);
EditorGUILayout.LabelField($"시간: {recorder.RecordedTime:F2}초", GUILayout.Width(120));
}
else
{
EditorGUILayout.LabelField("○ 대기 중", EditorStyles.boldLabel);
}
EditorGUILayout.EndHorizontal();
}
private void DrawRecordingSettings()
{
showRecordingSettings = EditorGUILayout.Foldout(showRecordingSettings, "레코딩 설정");
if (showRecordingSettings)
{
EditorGUI.indentLevel++;
// 키 설정
var startKeyProp = serializedObject.FindProperty("recordStartKey");
var stopKeyProp = serializedObject.FindProperty("recordStopKey");
startKeyProp.enumValueIndex = EditorGUILayout.Popup("시작 키", startKeyProp.enumValueIndex, startKeyProp.enumDisplayNames);
stopKeyProp.enumValueIndex = EditorGUILayout.Popup("정지 키", stopKeyProp.enumValueIndex, stopKeyProp.enumDisplayNames);
// FPS 설정
var fpsProp = serializedObject.FindProperty("targetFPS");
fpsProp.floatValue = EditorGUILayout.FloatField("타겟 FPS", fpsProp.floatValue);
if (fpsProp.floatValue <= 0)
{
EditorGUILayout.HelpBox("FPS가 0 이하면 제한 없이 녹화됩니다.", MessageType.Info);
}
EditorGUI.indentLevel--;
}
}
private void DrawTargetSettings()
{
showTargetSettings = EditorGUILayout.Foldout(showTargetSettings, "타겟 오브젝트 관리");
if (showTargetSettings)
{
EditorGUI.indentLevel++;
var targetsProp = serializedObject.FindProperty("targetObjects");
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField($"타겟 오브젝트 ({targetsProp.arraySize}개)", EditorStyles.boldLabel);
if (GUILayout.Button("선택된 오브젝트 추가", GUILayout.Width(150)))
{
AddSelectedObject();
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.Space();
// 타겟 오브젝트 리스트
for (int i = 0; i < targetsProp.arraySize; i++)
{
EditorGUILayout.BeginHorizontal();
var elementProp = targetsProp.GetArrayElementAtIndex(i);
EditorGUILayout.PropertyField(elementProp, GUIContent.none);
if (GUILayout.Button("제거", GUILayout.Width(60)))
{
targetsProp.DeleteArrayElementAtIndex(i);
break;
}
EditorGUILayout.EndHorizontal();
}
if (targetsProp.arraySize == 0)
{
EditorGUILayout.HelpBox("타겟 오브젝트가 없습니다. '선택된 오브젝트 추가' 버튼을 사용하거나 직접 추가해주세요.", MessageType.Warning);
}
EditorGUILayout.Space();
// 빠른 액션 버튼들
EditorGUILayout.BeginHorizontal();
if (GUILayout.Button("모든 타겟 제거"))
{
if (EditorUtility.DisplayDialog("타겟 제거", "모든 타겟 오브젝트를 제거하시겠습니까?", "확인", "취소"))
{
targetsProp.ClearArray();
}
}
if (GUILayout.Button("선택된 오브젝트들 추가"))
{
AddSelectedObjects();
}
EditorGUILayout.EndHorizontal();
EditorGUI.indentLevel--;
}
}
private void DrawActionButtons()
{
EditorGUILayout.LabelField("액션", EditorStyles.boldLabel);
EditorGUILayout.BeginHorizontal();
if (recorder.IsRecording)
{
GUI.enabled = false;
EditorGUILayout.HelpBox("녹화 중입니다. 정지 키를 눌러주세요.", MessageType.Info);
GUI.enabled = true;
}
else
{
if (GUILayout.Button("레코딩 시작", GUILayout.Height(30)))
{
if (recorder.TargetObjects.Length == 0)
{
EditorUtility.DisplayDialog("오류", "타겟 오브젝트가 설정되지 않았습니다.", "확인");
return;
}
recorder.StartRecording();
}
}
if (GUILayout.Button("설정 새로고침", GUILayout.Height(30)))
{
EditorUtility.SetDirty(recorder);
}
EditorGUILayout.EndHorizontal();
}
private void AddSelectedObject()
{
var selected = Selection.activeGameObject;
if (selected != null)
{
var targetsProp = serializedObject.FindProperty("targetObjects");
targetsProp.arraySize++;
var newElement = targetsProp.GetArrayElementAtIndex(targetsProp.arraySize - 1);
newElement.objectReferenceValue = selected.transform;
Debug.Log($"오브젝트 추가: {selected.name}");
}
else
{
EditorUtility.DisplayDialog("오류", "선택된 오브젝트가 없습니다.", "확인");
}
}
private void AddSelectedObjects()
{
var selectedObjects = Selection.gameObjects;
if (selectedObjects.Length == 0)
{
EditorUtility.DisplayDialog("오류", "선택된 오브젝트가 없습니다.", "확인");
return;
}
var targetsProp = serializedObject.FindProperty("targetObjects");
int startIndex = targetsProp.arraySize;
targetsProp.arraySize += selectedObjects.Length;
for (int i = 0; i < selectedObjects.Length; i++)
{
var element = targetsProp.GetArrayElementAtIndex(startIndex + i);
element.objectReferenceValue = selectedObjects[i].transform;
}
Debug.Log($"{selectedObjects.Length}개 오브젝트 추가됨");
}
}
}
#endif

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 668795823d8b9124fba6f34bd1e32f35

View File

@ -0,0 +1,129 @@
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
using System.IO;
namespace EasyMotionRecorder
{
[CustomEditor(typeof(SavePathManager))]
public class SavePathManagerEditor : Editor
{
private SavePathManager savePathManager;
private bool showAdvancedSettings = false;
private void OnEnable()
{
savePathManager = (SavePathManager)target;
}
public override void OnInspectorGUI()
{
serializedObject.Update();
EditorGUILayout.Space();
EditorGUILayout.LabelField("저장 경로 관리", EditorStyles.boldLabel);
EditorGUILayout.Space();
// 기본 설정
DrawBasicSettings();
EditorGUILayout.Space();
// 고급 설정
DrawAdvancedSettings();
EditorGUILayout.Space();
// 버튼들
DrawActionButtons();
serializedObject.ApplyModifiedProperties();
}
private void DrawBasicSettings()
{
EditorGUILayout.LabelField("기본 설정", EditorStyles.boldLabel);
// 통합 저장 경로 (모든 파일이 같은 위치에 저장됨)
EditorGUILayout.BeginHorizontal();
string motionPath = EditorGUILayout.TextField("저장 경로", savePathManager.GetMotionSavePath());
if (GUILayout.Button("폴더 선택", GUILayout.Width(80)))
{
string newPath = EditorUtility.OpenFolderPanel("저장 폴더 선택", "Assets", "");
if (!string.IsNullOrEmpty(newPath))
{
// Assets 폴더 기준으로 상대 경로로 변환
if (newPath.StartsWith(Application.dataPath))
{
newPath = "Assets" + newPath.Substring(Application.dataPath.Length);
}
savePathManager.SetMotionSavePath(newPath);
}
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.HelpBox("모션, 페이스, 제네릭 애니메이션 파일이 모두 이 경로에 저장됩니다.", MessageType.Info);
}
private void DrawAdvancedSettings()
{
showAdvancedSettings = EditorGUILayout.Foldout(showAdvancedSettings, "고급 설정");
if (showAdvancedSettings)
{
EditorGUI.indentLevel++;
// 서브디렉토리 생성 여부
bool createSubdirectories = EditorGUILayout.Toggle("서브디렉토리 자동 생성",
serializedObject.FindProperty("createSubdirectories").boolValue);
serializedObject.FindProperty("createSubdirectories").boolValue = createSubdirectories;
EditorGUILayout.HelpBox("현재 모든 파일이 동일한 경로에 저장됩니다.", MessageType.Info);
EditorGUI.indentLevel--;
}
}
private void DrawActionButtons()
{
EditorGUILayout.LabelField("작업", EditorStyles.boldLabel);
EditorGUILayout.BeginHorizontal();
// 기본값으로 리셋 버튼
if (GUILayout.Button("기본값으로 리셋", GUILayout.Height(30)))
{
if (EditorUtility.DisplayDialog("기본값으로 리셋",
"모든 설정을 기본값으로 되돌리시겠습니까?", "확인", "취소"))
{
savePathManager.ResetToDefaults();
EditorUtility.SetDirty(savePathManager);
}
}
// 폴더 열기 버튼
if (GUILayout.Button("저장 폴더 열기", GUILayout.Height(30)))
{
string path = savePathManager.GetMotionSavePath();
if (Directory.Exists(path))
{
EditorUtility.RevealInFinder(path);
}
else
{
EditorUtility.DisplayDialog("오류", "저장 폴더가 존재하지 않습니다.", "확인");
}
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.Space();
EditorGUILayout.LabelField("자동 출력 옵션", EditorStyles.boldLabel);
var humanoidProp = serializedObject.FindProperty("exportHumanoidOnSave");
var genericProp = serializedObject.FindProperty("exportGenericOnSave");
humanoidProp.boolValue = EditorGUILayout.ToggleLeft("휴머노이드 애니메이션 자동 출력", humanoidProp.boolValue);
genericProp.boolValue = EditorGUILayout.ToggleLeft("제네릭 애니메이션 자동 출력", genericProp.boolValue);
}
}
}
#endif

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 3381156202fae3546b3cdc3f7cf501e6

View File

@ -0,0 +1,105 @@
using UnityEngine;
public class ExpressionRecorder : MonoBehaviour
{
public SkinnedMeshRenderer targetRenderer;
public float recordingInterval = 0.1f;
public AnimationClip animationClip;
public KeyCode startRecordingKey = KeyCode.R;
public KeyCode stopRecordingKey = KeyCode.X;
private float recordingTimer;
private AnimationCurve[] blendShapeCurves;
private bool isRecording;
private void Start()
{
if (targetRenderer == null || animationClip == null)
{
Debug.LogError("Required components/variables are not assigned.");
enabled = false;
return;
}
// Retrieve blend shape names from the target renderer
string[] blendShapeNames = targetRenderer.sharedMesh.blendShapeCount > 0 ? new string[targetRenderer.sharedMesh.blendShapeCount] : null;
if (blendShapeNames != null)
{
for (int i = 0; i < targetRenderer.sharedMesh.blendShapeCount; i++)
{
blendShapeNames[i] = targetRenderer.sharedMesh.GetBlendShapeName(i);
}
}
else
{
Debug.LogError("No blend shapes found in the target renderer.");
enabled = false;
return;
}
// Create blend shape curves
blendShapeCurves = new AnimationCurve[blendShapeNames.Length];
for (int i = 0; i < blendShapeNames.Length; i++)
{
blendShapeCurves[i] = new AnimationCurve();
}
// Set up animation clip
animationClip.ClearCurves();
for (int i = 0; i < blendShapeNames.Length; i++)
{
string curvePath = targetRenderer.gameObject.name + "." + blendShapeNames[i];
animationClip.SetCurve(curvePath, typeof(SkinnedMeshRenderer), "blendShape." + blendShapeNames[i], blendShapeCurves[i]);
}
// Initialize variables
recordingTimer = 0f;
isRecording = false;
}
private void Update()
{
if (Input.GetKeyDown(startRecordingKey))
{
StartRecording();
}
if (Input.GetKeyDown(stopRecordingKey))
{
StopRecording();
}
if (!isRecording)
{
return;
}
recordingTimer += Time.deltaTime;
if (recordingTimer >= recordingInterval)
{
RecordExpression();
recordingTimer = 0f;
}
}
private void RecordExpression()
{
for (int i = 0; i < blendShapeCurves.Length; i++)
{
float blendShapeValue = targetRenderer.GetBlendShapeWeight(i);
blendShapeCurves[i].AddKey(new Keyframe(recordingTimer, blendShapeValue));
}
}
public void StartRecording()
{
isRecording = true;
recordingTimer = 0f;
}
public void StopRecording()
{
isRecording = false;
}
}

View File

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

View File

@ -3,8 +3,10 @@ using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using UnityEditor;
using UnityEngine;
using EasyMotionRecorder;
/**
[EasyMotionRecorder]
@ -15,20 +17,21 @@ This software is released under the MIT License.
http://opensource.org/licenses/mit-license.php
*/
namespace Entum
{
#if UNITY_EDITOR
namespace Entum {
/// <summary>
/// Blendshapeの動きを記録するクラス
/// リップシンクは後入れでTimeline上にAudioClipをつけて、みたいな可能性が高いので
/// Exclusive(除外)するBlendshape名を登録できるようにしています。
/// </summary>
[RequireComponent(typeof(MotionDataRecorder))]
public class FaceAnimationRecorder : MonoBehaviour
{
[Header("表情記録を同時に行う場合はtrueにします")] [SerializeField]
public class FaceAnimationRecorder:MonoBehaviour {
[Header("表情記録を同時に行う場合はtrueにします")]
[SerializeField]
private bool _recordFaceBlendshapes = false;
[Header("リップシンクを記録したくない場合はここにモーフ名を入れていく 例:face_mouse_eなど")] [SerializeField]
[Header("リップシンクを記録したくない場合はここにモーフ名を入れていく 例:face_mouse_eなど")]
[SerializeField]
private List<string> _exclusiveBlendshapeNames;
[Tooltip("記録するFPS。0で制限しない。UpdateのFPSは超えられません。")]
@ -52,28 +55,23 @@ namespace Entum
private float _startTime;
// Use this for initialization
private void OnEnable()
{
private void OnEnable() {
_animRecorder = GetComponent<MotionDataRecorder>();
_animRecorder.OnRecordStart += RecordStart;
_animRecorder.OnRecordEnd += RecordEnd;
if (_animRecorder.CharacterAnimator != null)
{
if(_animRecorder.CharacterAnimator != null) {
_smeshs = GetSkinnedMeshRenderers(_animRecorder.CharacterAnimator);
}
}
SkinnedMeshRenderer[] GetSkinnedMeshRenderers(Animator root)
{
SkinnedMeshRenderer[] GetSkinnedMeshRenderers(Animator root) {
var helper = root;
var renderers = helper.GetComponentsInChildren<SkinnedMeshRenderer>();
List<SkinnedMeshRenderer> smeshList = new List<SkinnedMeshRenderer>();
for (int i = 0; i < renderers.Length; i++)
{
for(int i = 0; i < renderers.Length; i++) {
var rend = renderers[i];
var cnt = rend.sharedMesh.blendShapeCount;
if (cnt > 0)
{
if(cnt > 0) {
smeshList.Add(rend);
}
}
@ -81,15 +79,13 @@ namespace Entum
return smeshList.ToArray();
}
private void OnDisable()
{
if (_recording)
{
private void OnDisable() {
if(_recording) {
RecordEnd();
_recording = false;
}
if (_animRecorder == null) return;
if(_animRecorder == null) return;
_animRecorder.OnRecordStart -= RecordStart;
_animRecorder.OnRecordEnd -= RecordEnd;
}
@ -97,20 +93,16 @@ namespace Entum
/// <summary>
/// 記録開始
/// </summary>
private void RecordStart()
{
if (_recordFaceBlendshapes == false)
{
private void RecordStart() {
if(_recordFaceBlendshapes == false) {
return;
}
if (_recording)
{
if(_recording) {
return;
}
if (_smeshs.Length == 0)
{
if(_smeshs.Length == 0) {
Debug.LogError("顔のメッシュ指定がされていないので顔のアニメーションは記録しません");
return;
}
@ -126,23 +118,18 @@ namespace Entum
/// <summary>
/// 記録終了
/// </summary>
private void RecordEnd()
{
if (_recordFaceBlendshapes == false)
{
private void RecordEnd() {
if(_recordFaceBlendshapes == false) {
return;
}
if (_smeshs.Length == 0)
{
if(_smeshs.Length == 0) {
Debug.LogError("顔のメッシュ指定がされていないので顔のアニメーションは記録しませんでした");
if (_recording == true)
{
if(_recording == true) {
Debug.LogAssertion("Unexpected execution!!!!");
}
}
else
{
else {
//WriteAnimationFileToScriptableObject();
ExportFacialAnimationClip(_animRecorder.CharacterAnimator, _facialData);
}
@ -153,8 +140,7 @@ namespace Entum
}
private void WriteAnimationFileToScriptableObject()
{
private void WriteAnimationFileToScriptableObject() {
MotionDataRecorder.SafeCreateDirectory("Assets/Resources");
string path = AssetDatabase.GenerateUniqueAssetPath(
@ -162,12 +148,10 @@ namespace Entum
DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss") +
".asset");
if (_facialData == null)
{
if(_facialData == null) {
Debug.LogError("記録されたFaceデータがnull");
}
else
{
else {
AssetDatabase.CreateAsset(_facialData, path);
AssetDatabase.Refresh();
}
@ -177,15 +161,12 @@ namespace Entum
}
//フレーム内の差分が無いかをチェックするやつ。
private bool IsSame(CharacterFacialData.SerializeHumanoidFace a, CharacterFacialData.SerializeHumanoidFace b)
{
if (a == null || b == null || a.Smeshes.Count == 0 || b.Smeshes.Count == 0)
{
private bool IsSame(CharacterFacialData.SerializeHumanoidFace a, CharacterFacialData.SerializeHumanoidFace b) {
if(a == null || b == null || a.Smeshes.Count == 0 || b.Smeshes.Count == 0) {
return false;
}
if (a.BlendShapeNum() != b.BlendShapeNum())
{
if(a.BlendShapeNum() != b.BlendShapeNum()) {
return false;
}
@ -193,65 +174,52 @@ namespace Entum
t1.blendShapes.Where((t, j) => Mathf.Abs(t - b.Smeshes[i].blendShapes[j]) > 1).Any()).Any();
}
private void LateUpdate()
{
if (Input.GetKeyDown(KeyCode.Y))
{
private void LateUpdate() {
if(Input.GetKeyDown(KeyCode.Y)) {
ExportFacialAnimationClipTest();
}
if (!_recording)
{
if(!_recording) {
return;
}
_recordedTime = Time.time - _startTime;
if (TargetFPS != 0.0f)
{
if(TargetFPS != 0.0f) {
var nextTime = (1.0f * (_frameCount + 1)) / TargetFPS;
if (nextTime > _recordedTime)
{
if(nextTime > _recordedTime) {
return;
}
if (_frameCount % TargetFPS == 0)
{
if(_frameCount % TargetFPS == 0) {
print("Face_FPS=" + 1 / (_recordedTime / _frameCount));
}
}
else
{
if (Time.frameCount % Application.targetFrameRate == 0)
{
else {
if(Time.frameCount % Application.targetFrameRate == 0) {
print("Face_FPS=" + 1 / Time.deltaTime);
}
}
var p = new CharacterFacialData.SerializeHumanoidFace();
for (int i = 0; i < _smeshs.Length; i++)
{
for(int i = 0; i < _smeshs.Length; i++) {
var mesh = new CharacterFacialData.SerializeHumanoidFace.MeshAndBlendshape();
mesh.path = _smeshs[i].name;
mesh.blendShapes = new float[_smeshs[i].sharedMesh.blendShapeCount];
for (int j = 0; j < _smeshs[i].sharedMesh.blendShapeCount; j++)
{
for(int j = 0; j < _smeshs[i].sharedMesh.blendShapeCount; j++) {
var tname = _smeshs[i].sharedMesh.GetBlendShapeName(j);
var useThis = true;
foreach (var item in _exclusiveBlendshapeNames)
{
if (item.IndexOf(tname, StringComparison.Ordinal) >= 0)
{
foreach(var item in _exclusiveBlendshapeNames) {
if(item.IndexOf(tname, StringComparison.Ordinal) >= 0) {
useThis = false;
}
}
if (useThis)
{
if(useThis) {
mesh.blendShapes[j] = _smeshs[i].GetBlendShapeWeight(j);
}
}
@ -259,8 +227,7 @@ namespace Entum
p.Smeshes.Add(mesh);
}
if (!IsSame(p, _past))
{
if(!IsSame(p, _past)) {
p.FrameCount = _frameCount;
p.Time = _recordedTime;
@ -277,18 +244,15 @@ namespace Entum
/// </summary>
/// <param name="root"></param>
/// <param name="facial"></param>
void ExportFacialAnimationClip(Animator root, CharacterFacialData facial)
{
void ExportFacialAnimationClip(Animator root, CharacterFacialData facial) {
var animclip = new AnimationClip();
var mesh = _smeshs;
for (int faceTargetMeshIndex = 0; faceTargetMeshIndex < mesh.Length; faceTargetMeshIndex++)
{
for(int faceTargetMeshIndex = 0; faceTargetMeshIndex < mesh.Length; faceTargetMeshIndex++) {
var pathsb = new StringBuilder().Append(mesh[faceTargetMeshIndex].transform.name);
var trans = mesh[faceTargetMeshIndex].transform;
while (trans.parent != null && trans.parent != root.transform)
{
while(trans.parent != null && trans.parent != root.transform) {
trans = trans.parent;
pathsb.Insert(0, "/").Insert(0, trans.name);
}
@ -298,10 +262,9 @@ namespace Entum
var path = pathsb.ToString();
//個別メッシュの個別Blendshapeごとに、AnimationCurveを生成している
for (var blendShapeIndex = 0;
for(var blendShapeIndex = 0;
blendShapeIndex < mesh[faceTargetMeshIndex].sharedMesh.blendShapeCount;
blendShapeIndex++)
{
blendShapeIndex++) {
var curveBinding = new EditorCurveBinding();
curveBinding.type = typeof(SkinnedMeshRenderer);
curveBinding.path = path;
@ -310,9 +273,8 @@ namespace Entum
AnimationCurve curve = new AnimationCurve();
float pastBlendshapeWeight = -1;
for (int k = 0; k < _facialData.Facials.Count; k++)
{
if (!(Mathf.Abs(pastBlendshapeWeight - _facialData.Facials[k].Smeshes[faceTargetMeshIndex].blendShapes[blendShapeIndex]) >
for(int k = 0; k < _facialData.Facials.Count; k++) {
if(!(Mathf.Abs(pastBlendshapeWeight - _facialData.Facials[k].Smeshes[faceTargetMeshIndex].blendShapes[blendShapeIndex]) >
0.1f)) continue;
curve.AddKey(new Keyframe(facial.Facials[k].Time, _facialData.Facials[k].Smeshes[faceTargetMeshIndex].blendShapes[blendShapeIndex], float.PositiveInfinity, 0f));
pastBlendshapeWeight = _facialData.Facials[k].Smeshes[faceTargetMeshIndex].blendShapes[blendShapeIndex];
@ -323,12 +285,21 @@ namespace Entum
}
}
MotionDataRecorder.SafeCreateDirectory("Assets/Resources");
// SavePathManager 사용
string savePath = "Assets/Resources"; // 기본값
string fileName = $"{_animRecorder.SessionID}_{_animRecorder.CharacterAnimator.name}_Facial.anim";
var outputPath = "Assets/Resources/FaceRecordMotion_" + _animRecorder.CharacterAnimator.name + "_" +
DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss") + "_Clip.anim";
// SavePathManager가 있으면 사용
if(SavePathManager.Instance != null) {
savePath = SavePathManager.Instance.GetFacialSavePath();
fileName = $"{_animRecorder.SessionID}_{_animRecorder.CharacterAnimator.name}_Facial.anim";
}
Debug.Log("outputPath:" + outputPath);
MotionDataRecorder.SafeCreateDirectory(savePath);
var outputPath = Path.Combine(savePath, fileName);
Debug.Log($"페이스 애니메이션 파일 저장 경로: {outputPath}");
AssetDatabase.CreateAsset(animclip,
AssetDatabase.GenerateUniqueAssetPath(outputPath));
AssetDatabase.SaveAssets();
@ -340,26 +311,22 @@ namespace Entum
/// </summary>
/// <param name="root"></param>
/// <param name="facial"></param>
void ExportFacialAnimationClipTest()
{
void ExportFacialAnimationClipTest() {
var animclip = new AnimationClip();
var mesh = _smeshs;
for (int i = 0; i < mesh.Length; i++)
{
for(int i = 0; i < mesh.Length; i++) {
var pathsb = new StringBuilder().Append(mesh[i].transform.name);
var trans = mesh[i].transform;
while (trans.parent != null && trans.parent != _animRecorder.CharacterAnimator.transform)
{
while(trans.parent != null && trans.parent != _animRecorder.CharacterAnimator.transform) {
trans = trans.parent;
pathsb.Insert(0, "/").Insert(0, trans.name);
}
var path = pathsb.ToString();
for (var j = 0; j < mesh[i].sharedMesh.blendShapeCount; j++)
{
for(var j = 0; j < mesh[i].sharedMesh.blendShapeCount; j++) {
var curveBinding = new EditorCurveBinding();
curveBinding.type = typeof(SkinnedMeshRenderer);
curveBinding.path = path;
@ -386,3 +353,4 @@ namespace Entum
}
}
}
#endif

File diff suppressed because it is too large Load Diff

View File

@ -11,9 +11,12 @@ using UnityEngine;
using System;
using System.IO;
using System.Reflection;
using System.Collections.Generic;
#if UNITY_EDITOR
using UnityEditor;
#endif
using EasyMotionRecorder;
using UniHumanoid;
namespace Entum
{
@ -47,9 +50,13 @@ namespace Entum
[SerializeField]
private HumanBodyBones IK_RightFootBone = HumanBodyBones.RightFoot;
[SerializeField, Tooltip("녹화 시작 시 T-포즈를 별도로 저장할지 여부 (출력 시 0프레임에 포함)")]
private bool _recordTPoseAtStart = true;
protected HumanoidPoses Poses;
protected float RecordedTime;
protected float StartTime;
public string SessionID; // 세션 ID 추가
private HumanPose _currentPose;
private HumanPoseHandler _poseHandler;
@ -94,12 +101,12 @@ namespace Entum
return;
}
RecordedTime = Time.time - StartTime;
if (TargetFPS != 0.0f)
{
var nextTime = (1.0f * (FrameIndex + 1)) / TargetFPS;
// T-포즈가 별도 저장되므로 실제 녹화는 1프레임부터 시작
var nextTime = (1.0f * FrameIndex) / TargetFPS;
if (nextTime > RecordedTime)
{
return;
@ -117,7 +124,6 @@ namespace Entum
}
}
//現在のフレームのHumanoidの姿勢を取得
_poseHandler.GetHumanPose(ref _currentPose);
//posesに取得した姿勢を書き込む
@ -152,8 +158,6 @@ namespace Entum
serializedPose.RightfootIK_Pos = RightFootTQ.t;
serializedPose.RightfootIK_Rot = RightFootTQ.q;
serializedPose.FrameCount = FrameIndex;
serializedPose.Muscles = new float[_currentPose.muscles.Length];
serializedPose.Time = RecordedTime;
@ -178,8 +182,11 @@ namespace Entum
return;
}
// 세션 ID 생성 (년도는 2자리로 표시, 고유 ID 제거)
SessionID = DateTime.Now.ToString("yyMMdd_HHmmss");
Poses = ScriptableObject.CreateInstance<HumanoidPoses>();
Poses.AvatarName = _animator.name; // 아바타 이름 설정
if (OnRecordStart != null)
{
@ -191,6 +198,137 @@ namespace Entum
RecordedTime = 0f;
StartTime = Time.time;
FrameIndex = 0;
// 1프레임에 T-포즈 저장
if (_recordTPoseAtStart)
{
RecordTPoseAsFirstFrame();
}
}
/// <summary>
/// T-포즈를 즉시 저장합니다.
/// </summary>
private void RecordTPoseAsFirstFrame()
{
try
{
Debug.Log("T-포즈 즉시 저장 시작...");
// 현재 포즈를 T-포즈로 설정
SetTPose(_animator);
// T-포즈 설정 직후 즉시 데이터 수집
RecordTPoseData();
}
catch (System.Exception e)
{
Debug.LogError($"T-포즈 저장 중 오류 발생: {e.Message}");
Debug.LogError($"스택 트레이스: {e.StackTrace}");
}
}
/// <summary>
/// 지정된 Animator의 포즈를 T-포즈로 설정합니다.
/// </summary>
/// <param name="animator">T-포즈를 설정할 Animator</param>
private void SetTPose(Animator animator)
{
if (animator == null || animator.avatar == null)
return;
Avatar avatar = animator.avatar;
Transform transform = animator.transform;
// HumanPoseClip에 저장된 T-포즈 데이터를 로드하여 적용
var humanPoseClip = Resources.Load<HumanPoseClip>(HumanPoseClip.TPoseResourcePath);
if (humanPoseClip != null)
{
var pose = humanPoseClip.GetPose();
HumanPoseTransfer.SetPose(avatar, transform, pose);
}
else
{
Debug.LogWarning("T-Pose 데이터가 존재하지 않습니다.");
}
}
/// <summary>
/// T-포즈 데이터를 즉시 수집하여 저장
/// </summary>
private void RecordTPoseData()
{
try
{
Debug.Log("T-포즈 데이터 즉시 수집 시작...");
// T-포즈가 적용된 상태에서 현재 프레임의 Humanoid 포즈를 가져옴
_poseHandler.GetHumanPose(ref _currentPose);
Debug.Log($"T-포즈 데이터: BodyPosition={_currentPose.bodyPosition}, BodyRotation={_currentPose.bodyRotation}");
Debug.Log($"T-포즈 Muscle 개수: {_currentPose.muscles.Length}");
// T-포즈 데이터를 별도로 저장
var tPoseSerialized = new HumanoidPoses.SerializeHumanoidPose();
switch (_rootBoneSystem)
{
case MotionDataSettings.Rootbonesystem.Objectroot:
tPoseSerialized.BodyRootPosition = _animator.transform.localPosition;
tPoseSerialized.BodyRootRotation = _animator.transform.localRotation;
Debug.Log($"Objectroot 설정: BodyRootPosition={tPoseSerialized.BodyRootPosition}, BodyRootRotation={tPoseSerialized.BodyRootRotation}");
break;
case MotionDataSettings.Rootbonesystem.Hipbone:
tPoseSerialized.BodyRootPosition = _animator.GetBoneTransform(_targetRootBone).position;
tPoseSerialized.BodyRootRotation = _animator.GetBoneTransform(_targetRootBone).rotation;
Debug.Log($"Hipbone 설정: BodyRootPosition={tPoseSerialized.BodyRootPosition}, BodyRootRotation={tPoseSerialized.BodyRootRotation}");
break;
default:
throw new ArgumentOutOfRangeException();
}
var bodyTQ = new TQ(_currentPose.bodyPosition, _currentPose.bodyRotation);
var LeftFootTQ = new TQ(_animator.GetBoneTransform(IK_LeftFootBone).position, _animator.GetBoneTransform(IK_LeftFootBone).rotation);
var RightFootTQ = new TQ(_animator.GetBoneTransform(IK_RightFootBone).position, _animator.GetBoneTransform(IK_RightFootBone).rotation);
LeftFootTQ = AvatarUtility.GetIKGoalTQ(_animator.avatar, _animator.humanScale, AvatarIKGoal.LeftFoot, bodyTQ, LeftFootTQ);
RightFootTQ = AvatarUtility.GetIKGoalTQ(_animator.avatar, _animator.humanScale, AvatarIKGoal.RightFoot, bodyTQ, RightFootTQ);
tPoseSerialized.BodyPosition = bodyTQ.t;
tPoseSerialized.BodyRotation = bodyTQ.q;
tPoseSerialized.LeftfootIK_Pos = LeftFootTQ.t;
tPoseSerialized.LeftfootIK_Rot = LeftFootTQ.q;
tPoseSerialized.RightfootIK_Pos = RightFootTQ.t;
tPoseSerialized.RightfootIK_Rot = RightFootTQ.q;
tPoseSerialized.FrameCount = 0; // T-포즈는 0프레임으로 설정
tPoseSerialized.Muscles = new float[_currentPose.muscles.Length];
tPoseSerialized.Time = 0f; // T-포즈는 0초로 설정
for (int i = 0; i < tPoseSerialized.Muscles.Length; i++)
{
tPoseSerialized.Muscles[i] = _currentPose.muscles[i];
}
Debug.Log($"T-포즈 Muscle 데이터 설정 완료: {tPoseSerialized.Muscles.Length}개");
SetHumanBoneTransformToHumanoidPoses(_animator, ref tPoseSerialized);
Debug.Log($"T-포즈 본 데이터 설정 완료: {tPoseSerialized.HumanoidBones.Count}개 본");
// T-포즈를 별도 필드에 저장
Poses.TPoseData = tPoseSerialized;
Poses.HasTPoseData = true;
Debug.Log($"T-포즈가 별도로 저장되었습니다. (시간: 0초, 프레임: 0)");
Debug.Log($"현재 Poses.Count: {Poses.Poses.Count} (T-포즈는 별도 저장됨)");
}
catch (System.Exception e)
{
Debug.LogError($"T-포즈 저장 중 오류 발생: {e.Message}");
Debug.LogError($"스택 트레이스: {e.StackTrace}");
}
}
/// <summary>
@ -209,36 +347,132 @@ namespace Entum
OnRecordEnd();
}
// 자동 출력 옵션 확인
#if UNITY_EDITOR
if (SavePathManager.Instance != null && Poses != null)
{
if (SavePathManager.Instance.ExportHumanoidOnSave)
{
Poses.ExportHumanoidAnim();
}
if (SavePathManager.Instance.ExportGenericOnSave)
{
Poses.ExportGenericAnim();
}
}
#endif
OnRecordEnd -= WriteAnimationFile;
_recording = false;
}
private static void SetHumanBoneTransformToHumanoidPoses(Animator animator, ref HumanoidPoses.SerializeHumanoidPose pose)
{
HumanBodyBones[] values = Enum.GetValues(typeof(HumanBodyBones)) as HumanBodyBones[];
foreach (HumanBodyBones b in values)
// Humanoid 본만 수집하여 데이터 크기 최적화
var humanBones = new List<Transform>();
// Humanoid 본들만 수집
foreach (HumanBodyBones boneType in System.Enum.GetValues(typeof(HumanBodyBones)))
{
if (b < 0 || b >= HumanBodyBones.LastBone)
if (boneType == HumanBodyBones.LastBone) continue;
var boneTransform = animator.GetBoneTransform(boneType);
if (boneTransform != null)
{
continue;
}
Transform t = animator.GetBoneTransform(b);
if (t != null)
{
var bone = new HumanoidPoses.SerializeHumanoidPose.HumanoidBone();
bone.Set(animator.transform, t);
pose.HumanoidBones.Add(bone);
humanBones.Add(boneTransform);
}
}
// 추가로 중요한 본들 (팔꿈치, 무릎 등)
var additionalBones = new string[] { "LeftElbow", "RightElbow", "LeftKnee", "RightKnee", "LeftAnkle", "RightAnkle" };
foreach (var boneName in additionalBones)
{
var bone = animator.transform.Find(boneName);
if (bone != null && !humanBones.Contains(bone))
{
humanBones.Add(bone);
}
}
foreach (Transform bone in humanBones)
{
if (bone != null)
{
var boneData = new HumanoidPoses.SerializeHumanoidPose.HumanoidBone();
// 기존 Set 메서드 사용
boneData.Set(animator.transform, bone);
// 팔꿈치 특별 처리
if (IsElbowBone(bone))
{
boneData = ProcessElbowRotation(bone, boneData);
}
pose.HumanoidBones.Add(boneData);
}
}
}
private static bool IsElbowBone(Transform bone)
{
// 팔꿈치 본 식별
string boneName = bone.name.ToLower();
return boneName.Contains("elbow") || boneName.Contains("forearm") ||
boneName.Contains("arm") && boneName.Contains("02");
}
private static HumanoidPoses.SerializeHumanoidPose.HumanoidBone ProcessElbowRotation(
Transform elbow, HumanoidPoses.SerializeHumanoidPose.HumanoidBone boneData)
{
// 팔꿈치 회전 안정화 처리
Quaternion currentRotation = elbow.localRotation;
// 팔이 펴진 상태 감지
if (elbow.parent != null && elbow.childCount > 0)
{
Vector3 armDirection = (elbow.position - elbow.parent.position).normalized;
Vector3 forearmDirection = (elbow.GetChild(0).position - elbow.position).normalized;
float armAngle = Vector3.Angle(armDirection, forearmDirection);
// 팔이 거의 펴진 상태일 때 회전 보정
if (armAngle > 170f)
{
// Quaternion 보간을 사용하여 부드러운 전환
Quaternion targetRotation = Quaternion.LookRotation(forearmDirection, Vector3.up);
boneData.LocalRotation = Quaternion.Slerp(currentRotation, targetRotation, 0.1f);
}
else
{
boneData.LocalRotation = currentRotation;
}
}
return boneData;
}
protected virtual void WriteAnimationFile()
{
#if UNITY_EDITOR
SafeCreateDirectory("Assets/Resources");
// SavePathManager 사용
string savePath = "Assets/Resources"; // 기본값
string fileName = $"{SessionID}_{_animator.name}_Motion.asset";
// SavePathManager가 있으면 사용
if (SavePathManager.Instance != null)
{
savePath = SavePathManager.Instance.GetMotionSavePath();
fileName = $"{SessionID}_{_animator.name}_Motion.asset";
}
SafeCreateDirectory(savePath);
var path = string.Format("Assets/Resources/RecordMotion_{0}{1:yyyy_MM_dd_HH_mm_ss}.asset", _animator.name, DateTime.Now);
// 요약 정보 업데이트
UpdateSummaryInfo();
// 파일 경로 생성
var path = Path.Combine(savePath, fileName);
var uniqueAssetPath = AssetDatabase.GenerateUniqueAssetPath(path);
AssetDatabase.CreateAsset(Poses, uniqueAssetPath);
@ -246,8 +480,27 @@ namespace Entum
StartTime = Time.time;
RecordedTime = 0f;
FrameIndex = 0;
Debug.Log($"모션 파일이 저장되었습니다: {uniqueAssetPath}");
#endif
}
private void UpdateSummaryInfo()
{
if (Poses != null && Poses.Poses.Count > 0)
{
var firstPose = Poses.Poses[0];
var lastPose = Poses.Poses[Poses.Poses.Count - 1];
Poses.Summary.TotalPoses = Poses.Poses.Count;
Poses.Summary.TotalTime = lastPose.Time;
Poses.Summary.TotalBones = firstPose.HumanoidBones.Count;
Poses.Summary.TotalMuscles = firstPose.Muscles.Length;
Poses.Summary.AverageFPS = Poses.Poses.Count / lastPose.Time;
Debug.Log($"요약 정보 업데이트: 포즈 {Poses.Poses.Count}개, 시간 {lastPose.Time:F2}초, 본 {firstPose.HumanoidBones.Count}개, 근육 {firstPose.Muscles.Length}개, 평균 FPS {Poses.Summary.AverageFPS:F1}");
}
}
/// <summary>
/// 指定したパスにディレクトリが存在しない場合

View File

@ -0,0 +1,260 @@
using UnityEngine;
using System;
using System.Collections.Generic;
using System.IO;
#if UNITY_EDITOR
using UnityEditor;
#endif
using EasyMotionRecorder;
namespace Entum
{
/// <summary>
/// 오브젝트 모션 데이터 기록 클래스
/// 여러 오브젝트의 포지션과 로테이션을 동시에 기록
/// </summary>
[DefaultExecutionOrder(32001)] // MotionDataRecorder보다 나중에 실행
public class ObjectMotionRecorder : MonoBehaviour
{
[Header("레코딩 설정")]
[SerializeField] private KeyCode recordStartKey = KeyCode.R;
[SerializeField] private KeyCode recordStopKey = KeyCode.X;
[Header("타겟 오브젝트들")]
[SerializeField] private Transform[] targetObjects;
[Header("레코딩 설정")]
[Tooltip("기록할 FPS. 0으로 설정하면 제한 없음")]
[SerializeField] private float targetFPS = 60.0f;
[Header("파일명 설정")]
[SerializeField] private string objectNamePrefix = "Object";
private bool isRecording = false;
private float startTime;
private float recordedTime;
private int frameIndex;
// 각 오브젝트별 애니메이션 클립 데이터
private Dictionary<Transform, AnimationClip> objectClips;
private Dictionary<Transform, AnimationCurve[]> positionCurves;
private Dictionary<Transform, AnimationCurve[]> rotationCurves;
// 세션 ID (MotionDataRecorder와 동일한 형식)
public string SessionID { get; private set; }
public Action OnRecordStart;
public Action OnRecordEnd;
private void Update()
{
if (Input.GetKeyDown(recordStartKey))
{
StartRecording();
}
if (Input.GetKeyDown(recordStopKey))
{
StopRecording();
}
}
private void LateUpdate()
{
if (!isRecording)
return;
recordedTime = Time.time - startTime;
// FPS 제한 확인
if (targetFPS > 0.0f)
{
var nextTime = (1.0f * (frameIndex + 1)) / targetFPS;
if (nextTime > recordedTime)
{
return;
}
}
// 각 오브젝트의 포지션과 로테이션 기록
foreach (var target in targetObjects)
{
if (target == null) continue;
RecordObjectMotion(target, recordedTime);
}
frameIndex++;
}
private void RecordObjectMotion(Transform target, float time)
{
if (!positionCurves.ContainsKey(target) || !rotationCurves.ContainsKey(target))
return;
var posCurves = positionCurves[target];
var rotCurves = rotationCurves[target];
// 포지션 기록 (X, Y, Z)
posCurves[0].AddKey(time, target.position.x);
posCurves[1].AddKey(time, target.position.y);
posCurves[2].AddKey(time, target.position.z);
// 로테이션 기록 (X, Y, Z, W)
rotCurves[0].AddKey(time, target.rotation.x);
rotCurves[1].AddKey(time, target.rotation.y);
rotCurves[2].AddKey(time, target.rotation.z);
rotCurves[3].AddKey(time, target.rotation.w);
}
public void StartRecording()
{
if (isRecording)
return;
// 세션 ID 생성 (MotionDataRecorder와 동일한 형식)
SessionID = DateTime.Now.ToString("yyMMdd_HHmmss");
// 초기화
objectClips = new Dictionary<Transform, AnimationClip>();
positionCurves = new Dictionary<Transform, AnimationCurve[]>();
rotationCurves = new Dictionary<Transform, AnimationCurve[]>();
// 각 오브젝트별 애니메이션 클립과 커브 초기화
if (targetObjects != null)
{
foreach (var target in targetObjects)
{
if (target == null) continue;
var clip = new AnimationClip();
clip.frameRate = targetFPS > 0 ? targetFPS : 60f;
// 포지션 커브 초기화
var posCurves = new AnimationCurve[3];
for (int i = 0; i < 3; i++)
{
posCurves[i] = new AnimationCurve();
}
// 로테이션 커브 초기화
var rotCurves = new AnimationCurve[4];
for (int i = 0; i < 4; i++)
{
rotCurves[i] = new AnimationCurve();
}
objectClips[target] = clip;
positionCurves[target] = posCurves;
rotationCurves[target] = rotCurves;
}
}
startTime = Time.time;
recordedTime = 0f;
frameIndex = 0;
isRecording = true;
OnRecordStart?.Invoke();
Debug.Log($"오브젝트 모션 레코딩 시작: {(targetObjects != null ? targetObjects.Length : 0)}개 오브젝트");
}
public void StopRecording()
{
if (!isRecording)
return;
isRecording = false;
// 각 오브젝트별 애니메이션 클립 생성 및 저장
if (targetObjects != null)
{
foreach (var target in targetObjects)
{
if (target == null || !objectClips.ContainsKey(target)) continue;
CreateAndSaveAnimationClip(target);
}
}
OnRecordEnd?.Invoke();
Debug.Log("오브젝트 모션 레코딩 종료");
}
private void CreateAndSaveAnimationClip(Transform target)
{
#if UNITY_EDITOR
var clip = objectClips[target];
var posCurves = positionCurves[target];
var rotCurves = rotationCurves[target];
// 포지션 커브 설정
clip.SetCurve("", typeof(Transform), "m_LocalPosition.x", posCurves[0]);
clip.SetCurve("", typeof(Transform), "m_LocalPosition.y", posCurves[1]);
clip.SetCurve("", typeof(Transform), "m_LocalPosition.z", posCurves[2]);
// 로테이션 커브 설정
clip.SetCurve("", typeof(Transform), "m_LocalRotation.x", rotCurves[0]);
clip.SetCurve("", typeof(Transform), "m_LocalRotation.y", rotCurves[1]);
clip.SetCurve("", typeof(Transform), "m_LocalRotation.z", rotCurves[2]);
clip.SetCurve("", typeof(Transform), "m_LocalRotation.w", rotCurves[3]);
// Quaternion 연속성 보장
clip.EnsureQuaternionContinuity();
// 파일명 생성
string objectName = target.name;
string fileName = $"{SessionID}_{objectName}_Object.anim";
// SavePathManager 사용
string savePath = "Assets/Resources"; // 기본값
if (SavePathManager.Instance != null)
{
savePath = SavePathManager.Instance.GetObjectSavePath();
}
MotionDataRecorder.SafeCreateDirectory(savePath);
var path = Path.Combine(savePath, fileName);
var uniqueAssetPath = AssetDatabase.GenerateUniqueAssetPath(path);
AssetDatabase.CreateAsset(clip, uniqueAssetPath);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
Debug.Log($"오브젝트 애니메이션 파일 저장: {uniqueAssetPath}");
#endif
}
// 인스펙터에서 타겟 오브젝트 추가/제거를 위한 헬퍼 메서드
[ContextMenu("Add Current Selection")]
public void AddCurrentSelection()
{
#if UNITY_EDITOR
var selected = Selection.activeGameObject;
if (selected != null)
{
var newArray = new Transform[targetObjects.Length + 1];
Array.Copy(targetObjects, newArray, targetObjects.Length);
newArray[targetObjects.Length] = selected.transform;
targetObjects = newArray;
Debug.Log($"오브젝트 추가: {selected.name}");
}
#endif
}
[ContextMenu("Clear All Targets")]
public void ClearAllTargets()
{
targetObjects = new Transform[0];
Debug.Log("모든 타겟 오브젝트 제거");
}
// 타겟 오브젝트 배열 접근자
public Transform[] TargetObjects => targetObjects;
public bool IsRecording => isRecording;
public float RecordedTime => recordedTime;
}
}

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 530f525e71d58a94d9aa9ad830075d54

BIN
Assets/External/EasyMotionRecorder/Scripts/README_SavePathManager.md (Stored with Git LFS) vendored Normal file

Binary file not shown.

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: d52d79965c0c87f4dbc7d4ea99597abe
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,161 @@
using UnityEngine;
using System.IO;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace EasyMotionRecorder
{
public class SavePathManager : MonoBehaviour
{
private static SavePathManager _instance;
public static SavePathManager Instance
{
get
{
if (_instance == null)
{
_instance = FindObjectOfType<SavePathManager>();
if (_instance == null)
{
GameObject go = new GameObject("SavePathManager");
_instance = go.AddComponent<SavePathManager>();
DontDestroyOnLoad(go);
}
}
return _instance;
}
}
[Header("저장 경로 설정")]
[SerializeField] private string motionSavePath = "Assets/Resources/Motion";
[SerializeField] private string facialSavePath = "Assets/Resources/Motion";
[SerializeField] private string objectSavePath = "Assets/Resources/Motion";
[Header("설정")]
[SerializeField] private bool createSubdirectories = true;
[Header("자동 출력 옵션")]
[SerializeField] private bool exportHumanoidOnSave = false;
[SerializeField] private bool exportGenericOnSave = false;
[SerializeField] private bool exportFBXAsciiOnSave = false;
[SerializeField] private bool exportFBXBinaryOnSave = false;
[SerializeField] private bool exportBipedFBXAsciiOnSave = false;
[SerializeField] private bool exportBipedFBXBinaryOnSave = false;
public bool ExportHumanoidOnSave => exportHumanoidOnSave;
public bool ExportGenericOnSave => exportGenericOnSave;
public bool ExportFBXAsciiOnSave => exportFBXAsciiOnSave;
public bool ExportFBXBinaryOnSave => exportFBXBinaryOnSave;
public bool ExportBipedFBXAsciiOnSave => exportBipedFBXAsciiOnSave;
public bool ExportBipedFBXBinaryOnSave => exportBipedFBXBinaryOnSave;
private void Awake()
{
if (_instance == null)
{
_instance = this;
DontDestroyOnLoad(gameObject);
InitializePaths();
}
else if (_instance != this)
{
Destroy(gameObject);
}
}
private void InitializePaths()
{
if (createSubdirectories)
{
CreateDirectoryIfNotExists(motionSavePath);
CreateDirectoryIfNotExists(facialSavePath);
}
}
private void CreateDirectoryIfNotExists(string path)
{
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
#if UNITY_EDITOR
AssetDatabase.Refresh();
#endif
}
}
public string GetMotionSavePath()
{
return motionSavePath;
}
public string GetFacialSavePath()
{
return motionSavePath; // 모션 경로와 동일하게 설정
}
public string GetObjectSavePath()
{
return motionSavePath; // 모션 경로와 동일하게 설정
}
public void SetMotionSavePath(string path)
{
motionSavePath = path;
if (createSubdirectories)
CreateDirectoryIfNotExists(path);
}
public void SetFacialSavePath(string path)
{
facialSavePath = path;
if (createSubdirectories)
CreateDirectoryIfNotExists(path);
}
public void SetObjectSavePath(string path)
{
objectSavePath = path;
if (createSubdirectories)
CreateDirectoryIfNotExists(path);
}
public void SetCreateSubdirectories(bool create)
{
createSubdirectories = create;
if (create)
{
InitializePaths();
}
}
public void ResetToDefaults()
{
motionSavePath = "Assets/Resources/Motion";
facialSavePath = "Assets/Resources/Motion";
objectSavePath = "Assets/Resources/Motion";
createSubdirectories = true;
// 자동 출력 옵션 초기화
exportHumanoidOnSave = false;
exportGenericOnSave = false;
exportFBXAsciiOnSave = false;
exportFBXBinaryOnSave = false;
exportBipedFBXAsciiOnSave = false;
exportBipedFBXBinaryOnSave = false;
InitializePaths();
}
public void SynchronizePaths()
{
// 모든 경로를 모션 경로와 동일하게 설정
facialSavePath = motionSavePath;
objectSavePath = motionSavePath;
if (createSubdirectories)
{
InitializePaths();
}
}
}
}

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 717b945a8f3f682439ad3d79310cc265