00001 #pragma once 00002 00003 #include "common++.h" 00004 #include "tools++.h" 00005 00006 #include "NiJointsTool.h" 00007 00008 00009 #define VMD_FILE_HD_ID2 "Vocaloid Motion Data 0002" 00010 00011 #define VMD_JOINT_NUM 39 00012 #define VMD_GRID_UNIT 0.08 // m/grid 00013 00014 #define VMD_FARME_RATE 30 // FPS 00015 00016 00017 // 00018 #define VMD_PARENT 0 00019 #define VMD_CENTER 1 00020 #define VMD_LOWER 2 00021 #define VMD_UPPER 3 00022 #define VMD_UPPER2 4 00023 #define VMD_NECK 5 00024 #define VMD_HEAD 6 00025 #define VMD_SKULL 7 00026 00027 #define VMD_EYES 8 00028 #define VMD_L_EYE 9 00029 #define VMD_R_EYE 10 00030 #define VMD_L_BUST 11 00031 #define VMD_R_BUST 12 00032 00033 #define VMD_L_SHLDR 13 00034 #define VMD_L_ARM 14 00035 #define VMD_L_ARM_TW 15 00036 #define VMD_L_ELBOW 16 00037 #define VMD_L_WRIST_TW 17 00038 #define VMD_L_WRIST 18 00039 #define VMD_L_HAND 19 00040 00041 #define VMD_R_SHLDR 20 00042 #define VMD_R_ARM 21 00043 #define VMD_R_ARM_TW 22 00044 #define VMD_R_ELBOW 23 00045 #define VMD_R_WRIST_TW 24 00046 #define VMD_R_WRIST 25 00047 #define VMD_R_HAND 26 00048 00049 #define VMD_L_HIP 27 00050 #define VMD_L_KNEE 28 00051 #define VMD_L_ANKLE_IK 29 00052 #define VMD_L_ANKLE 30 00053 #define VMD_L_TOE 31 00054 #define VMD_L_TOE_IK 32 00055 00056 #define VMD_R_HIP 33 00057 #define VMD_R_KNEE 34 00058 #define VMD_R_ANKLE_IK 35 00059 #define VMD_R_ANKLE 36 00060 #define VMD_R_TOE 37 00061 #define VMD_R_TOE_IK 38 00062 00063 00064 00065 namespace jbxwl { 00066 00067 using namespace jbxl; 00068 00069 00070 typedef struct _vmd_file_header 00071 { 00072 char header[30]; 00073 char name[20]; 00074 unsigned int data_num; 00075 // 00076 } VMDFileHeader; 00077 00078 00079 // 00080 typedef struct _vmd_joint_data 00081 { 00082 char name[15]; 00083 unsigned long frm_num; 00084 double posx; 00085 double posy; 00086 double posz; 00087 double qutx; 00088 double quty; 00089 double qutz; 00090 double qutw; 00091 char param[64]; // 補間係数 00092 // 00093 } VMDJointData; 00094 00095 00096 00097 /* 00098 // 未対応 00099 typedef struct _vmd_face_frame 00100 { 00101 char name[15]; 00102 unsigned long num; 00103 double value; 00104 // 00105 } VMDFaceFrame; 00106 */ 00107 00108 00109 00110 class CNiVMDTool : public CBaseFrameTool 00111 { 00112 public: 00113 CNiVMDTool(void); 00114 virtual ~CNiVMDTool(void); 00115 00116 public: 00117 void free_data(void); 00118 void clear_data(void); 00119 00120 public: 00121 virtual unsigned int getFramesNumber(void) { return dmy_frmnum;} 00122 virtual NiFrameData * getFramesData(void); // フレームの情報と全フレームへのポインタ 00123 virtual NiJointData* getJointsData(int frmnum, int fps); // 動的にフレームデータ(補間)を計算. 00124 00125 virtual BOOL readFile(FILE* fp); 00126 00127 // 00128 private: 00129 Quaternion<double> A2TPose; 00130 double rate_frame; 00131 00132 // 00133 VMDFileHeader vmd_header; 00134 VMDJointData* vmd_frames; 00135 unsigned int vmd_datnum; 00136 00137 // 00138 NiFrameData* dmy_frames; 00139 unsigned int dmy_frmnum; 00140 00141 private: 00142 VMDFileHeader readFileHeader(FILE* fp); 00143 VMDJointData readJointData (FILE* fp); 00144 VMDJointData* readJointsData(FILE* fp, unsigned int& frmnum); 00145 00146 NiFrameData* convert2FrameData(VMDJointData* motion_data, unsigned int datnum, unsigned int& frmnum); 00147 void calcJointRotation(void); 00148 void calcJointIK(int fnum); 00149 00150 void calcLegIK_CCD(Vector<double>* vect, Vector<double> ik, Quaternion<double>* quat, int rpmax); 00151 }; 00152 00153 00154 00155 00157 // 00158 00159 std::string VMDJointName(int n); 00160 int VMDJointNum(char* name); 00161 00162 int VMD2NiJointNum(int joint); 00163 00164 00165 } 00166 00167