JunkBox_Win_Lib 1.5.3
Loading...
Searching...
No Matches
NiBVHTool.cpp
Go to the documentation of this file.
1
2#include "NiBVHTool.h"
3
4using namespace jbxl;
5using namespace jbxwl;
6
7
9// CNiBVHTool Class
10
12{
13 DEBUG_INFO("DESTRUCTOR: CNiBVHTool\n");
14
15 free_data();
16}
17
18
19
21{
22 bvh_tool = new CBVHTool();
23
25}
26
27
28
30{
31 //
32 if (bvh_tool!=NULL) delete(bvh_tool);
33 bvh_tool = NULL;
34
35 if (bvh_name_list!=NULL) {
36 del_tList(&bvh_name_list);
37 bvh_name_list = NULL;
38 }
39
40 clear_data();
41}
42
43
44
46{
47 if (bvh_tool!=NULL) bvh_tool->free_data();
48
50}
51
52
53
54
56//
57
59{
60 if (fp==NULL || bvh_tool==NULL) return FALSE;
61
62 clear_data();
63
64 bvh_tool->readBVH(fp);
65 if (bvh_tool->state!=0) return FALSE;
66
67 //
68 joints_num = bvh_tool->joint_num;
69 if (jointsData!=NULL) ::free(jointsData);
70 jointsData = (NiJointData*)malloc(sizeof(NiJointData)*joints_num);
71 if (jointsData==NULL) {
72 clear_data();
73 return FALSE;
74 }
76
77 frames_num = bvh_tool->frame_num;
79 if (framesData==NULL) {
80 clear_data();
81 return FALSE;
82 }
83
84 //
86
87 //
88 for (unsigned int i=0; i<frames_num; i++) {
89 framesData[i].frmn = (int)i; // フレーム番号
90 framesData[i].msec = (int)(bvh_tool->frame_time*i*1000); // フレーム時間 ms
91 framesData[i].jnum = joints_num; // Joint の数
92
93 posVect = bvh_tool->getPosData(i);
94 rotQuat = bvh_tool->getQuaternion(i);
95
96 NiJointData* jdata = framesData[i].jdat;
97 for (int j=0; j<bvh_tool->joint_num; j++) {
98 jdata[j].joint = BVHJoint2NiJointNum(namelist, bvh_tool->joint_name[j]);
99 jdata[j].index = i;
100 jdata[j].vect.x = posVect[j].z;
101 jdata[j].vect.y = posVect[j].x;
102 jdata[j].vect.z = posVect[j].y;
103 jdata[j].vect.c = 1.0;
104 jdata[j].quat = rotQuat[j];
105 jdata[j].quat.c = 1.0;
106 }
107
108 //
109 free(posVect);
110 free(rotQuat);
111 posVect = NULL;
112 rotQuat = NULL;
113 }
114
115 /*
116 tList* pp = namelist;
117 while(pp!=NULL) {
118 DEBUG_INFO("%d => %s\n", pp->ldat.id, pp->ldat.key.buf);
119 pp = pp->next;
120 }*/
121
122 //
126
127 del_tList(&namelist);
128
129 return TRUE;
130}
131
132
133
135{
136 BOOL ret = FALSE;
137
138 if (bvh_tool!=NULL) {
139 ret = bvh_tool->printBVH(fp);
140 }
141
142 return ret;
143}
144
145
146
148{
149 if (bvh_tool->framepsec<=0) {
150 if (bvh_tool->frame_time!=0.0) bvh_tool->framepsec = (int)(1.0/bvh_tool->frame_time);
151 else bvh_tool->framepsec = 30;
152 }
153
154 return bvh_tool->framepsec;
155}
156
157
158
160{
161 if (frmnum<0) return NULL;
162
163 if (fps<=0) fps = 30;
164 int msec = (int)(1000./fps*frmnum);
165 if (msec>exec_time) return NULL;
166
167 unsigned int f;
168 double t = 0.0;
169
170 for (f=1; f<frames_num; f++) {
171 if (framesData[f].msec >= msec + start_time) {
172 t = (float)(msec - framesData[f-1].msec)/(float)(framesData[f].msec - framesData[f-1].msec);
173 break;
174 }
175 }
176 if (f>=frames_num) return NULL;
177
178 //
180
181 NiJointData* jdat1 = framesData[f-1].jdat;
182 NiJointData* jdat2 = framesData[f].jdat;
183
184 for (int j=0; j<joints_num; j++) {
185 jointsData[j].joint = jdat1[j].joint;
186 jointsData[j].index = frmnum;
187 jointsData[j].vect = BSplineInterp4 (jdat1[j].vect, jdat2[j].vect, t);
188 jointsData[j].quat = SlerpQuaternion(jdat1[j].quat, jdat2[j].quat, t);
189 }
190
191 return jointsData;
192}
193
#define BVH_ADD_JOINTNAME_TXT
Definition NiBVHName.h:10
NiJointData * jointsData
void clearJointsData(int jnum)
Vector< double > * posVect
unsigned int frames_num
NiFrameData * framesData
Quaternion< double > * rotQuat
CBVHTool * bvh_tool
Definition NiBVHTool.h:45
void init(void)
Definition NiBVHTool.cpp:20
virtual ~CNiBVHTool(void)
Definition NiBVHTool.cpp:11
virtual BOOL readFile(FILE *fp)
Definition NiBVHTool.cpp:58
virtual NiJointData * getJointsData(int frmnum, int fps)
tList * bvh_name_list
Definition NiBVHTool.h:46
void clear_data(void)
Definition NiBVHTool.cpp:45
void free_data(void)
Definition NiBVHTool.cpp:29
virtual int getPlayBackFPS(void)
virtual BOOL writeFile(FILE *fp)
NiFrameData * makeFramesData(int frame, int joint_num, int *frame_num)
int BVHJoint2NiJointNum(tList *lt, Buffer joint_name)
tList * setBVHJointName(void)
Definition NiBVHName.cpp:11
tList * addBVHJointName(char *fname, tList *lt)
NiJointData * jdat
Quaternion< double > quat
Vector< double > vect