JunkBox_Win_Lib 1.5.3
Loading...
Searching...
No Matches
CNiVMDTool Class Reference

#include <NiVMDTool.h>

Inheritance diagram for CNiVMDTool:
Collaboration diagram for CNiVMDTool:

Public Member Functions

 CNiVMDTool (void)
 
virtual ~CNiVMDTool (void)
 
void free_data (void)
 
void clear_data (void)
 
virtual unsigned int getFramesNumber (void)
 
virtual NiFrameDatagetFramesData (void)
 
virtual NiJointDatagetJointsData (int frmnum, int fps)
 
virtual BOOL readFile (FILE *fp)
 
- Public Member Functions inherited from CBaseFrameTool
 CBaseFrameTool (void)
 
virtual ~CBaseFrameTool (void)
 
virtual int getJointsNumber (void)
 
virtual int getPlayBackTime (void)
 
virtual int getPlayBackFPS (void)
 
virtual BOOL writeFile (FILE *fp)
 

Private Member Functions

VMDFileHeader readFileHeader (FILE *fp)
 
VMDJointData readJointData (FILE *fp)
 
VMDJointDatareadJointsData (FILE *fp, unsigned int &frmnum)
 
NiFrameDataconvert2FrameData (VMDJointData *motion_data, unsigned int datnum, unsigned int &frmnum)
 
void calcJointRotation (void)
 
void calcJointIK (int fnum)
 
void calcLegIK_CCD (Vector< double > *vect, Vector< double > ik, Quaternion< double > *quat, int rpmax)
 

Private Attributes

Quaternion< double > A2TPose
 
double rate_frame
 
VMDFileHeader vmd_header
 
VMDJointDatavmd_frames
 
unsigned int vmd_datnum
 
NiFrameDatadmy_frames
 
unsigned int dmy_frmnum
 

Additional Inherited Members

- Protected Member Functions inherited from CBaseFrameTool
void init_data (void)
 
void free_data (void)
 
void clear_data (void)
 
void clearJointsData (int jnum)
 
void clearVectorData (int jnum)
 
- Protected Attributes inherited from CBaseFrameTool
unsigned int frames_num
 
int joints_num
 
int start_time
 
int stop_time
 
int exec_time
 
NiFrameDataframesData
 
NiJointDatajointsData
 
Vector< double > * posVect
 
Quaternion< double > * rotQuat
 

Detailed Description

Definition at line 110 of file NiVMDTool.h.

Constructor & Destructor Documentation

◆ CNiVMDTool()

CNiVMDTool ( void )

Definition at line 154 of file NiVMDTool.cpp.

155{
156 memset(&vmd_header, 0, sizeof(VMDFileHeader));
157
158 vmd_frames = NULL;
159 vmd_datnum = 0;
160 dmy_frames = NULL;
161 dmy_frmnum = 0;
163
165 A2TPose.setRotation(37.0/180.0*PI, 1.0, 0.0, 0.0, 1.0);
166
167 posVect = (Vector<double>*)malloc(sizeof(Vector<double>)*VMD_JOINT_NUM);
168 rotQuat = (Quaternion<double>*)malloc(sizeof(Quaternion<double>)*VMD_JOINT_NUM);
169}
#define VMD_JOINT_NUM
Definition NiVMDTool.h:11
#define VMD_FARME_RATE
Definition NiVMDTool.h:14
Vector< double > * posVect
Quaternion< double > * rotQuat
Quaternion< double > A2TPose
Definition NiVMDTool.h:129
unsigned int vmd_datnum
Definition NiVMDTool.h:135
NiFrameData * dmy_frames
Definition NiVMDTool.h:138
VMDFileHeader vmd_header
Definition NiVMDTool.h:133
unsigned int dmy_frmnum
Definition NiVMDTool.h:139
VMDJointData * vmd_frames
Definition NiVMDTool.h:134

References CNiVMDTool::A2TPose, CNiVMDTool::dmy_frames, CNiVMDTool::dmy_frmnum, CBaseFrameTool::joints_num, CBaseFrameTool::posVect, CNiVMDTool::rate_frame, CBaseFrameTool::rotQuat, CNiVMDTool::vmd_datnum, VMD_FARME_RATE, CNiVMDTool::vmd_frames, CNiVMDTool::vmd_header, and VMD_JOINT_NUM.

◆ ~CNiVMDTool()

~CNiVMDTool ( void )
virtual

Definition at line 173 of file NiVMDTool.cpp.

174{
175 DEBUG_INFO("DESTRUCTOR: CNiVMDTool\n");
176
177 free_data();
178}
void free_data(void)

References CNiVMDTool::free_data().

Here is the call graph for this function:

Member Function Documentation

◆ calcJointIK()

void calcJointIK ( int fnum)
private

Definition at line 562 of file NiVMDTool.cpp.

563{
564 // 軸
565 Vector<double> vect_Y(0.0, 1.0, 0.0, 1.0);
566 Vector<double> vect_Z(0.0, 0.0,-1.0, 1.0);
567 Vector<double> cnt_vect_Y = VectorRotation(vect_Y, rotQuat[VMD_CENTER]);
568 Vector<double> cnt_vect_Z = VectorRotation(vect_Z, rotQuat[VMD_CENTER]);
569
570 // 足の方向
571 Vector<double> l_leg_vect = VectorRotation(cnt_vect_Z, rotQuat[VMD_L_HIP]);
572 Vector<double> r_leg_vect = VectorRotation(cnt_vect_Z, rotQuat[VMD_R_HIP]);
573
574 // エフェクタ: センターからの初期相対位置
575 Vector<double> l_ank_vect = vect_Y*0.10 + vect_Z*0.83;
576 Vector<double> r_ank_vect = -vect_Y*0.10 + vect_Z*0.83;
577
578 // エフェクタ: 移動後のセンターからの相対位置
579 Vector<double> l_end_vect = cnt_vect_Y*0.10 + l_leg_vect*0.83;
580 Vector<double> r_end_vect = -cnt_vect_Y*0.10 + r_leg_vect*0.83;
581
582 // 到達目標
583 Vector<double> l_ik_vect = l_ank_vect + posVect[VMD_L_ANKLE_IK] - posVect[VMD_CENTER] - l_end_vect;
584 Vector<double> r_ik_vect = r_ank_vect + posVect[VMD_R_ANKLE_IK] - posVect[VMD_CENTER] - r_end_vect;
585
586 // 到達目標(ローカル座標系)
587 l_ik_vect = VectorRotation(l_ik_vect, ~rotQuat[VMD_CENTER]);
588 r_ik_vect = VectorRotation(r_ik_vect, ~rotQuat[VMD_CENTER]);
589
590 //
591 Vector<double> l_vect[3], r_vect[3];
592 Quaternion<double> l_quat[3], r_quat[3];
593
594 // 膝,腰の相対位置
595 l_vect[0].set(0.0, 0.0, 0.0);
596 r_vect[0].set(0.0, 0.0, 0.0);
597
598 l_vect[1] = -l_leg_vect*0.58;
599 r_vect[1] = -r_leg_vect*0.58;
600 l_vect[2] = -l_leg_vect*1.18;
601 r_vect[2] = -r_leg_vect*1.18;
602
603 // ローカル座標系
604 l_vect[1] = VectorRotation(l_vect[1], ~rotQuat[VMD_CENTER]);
605 r_vect[1] = VectorRotation(r_vect[1], ~rotQuat[VMD_CENTER]);
606 l_vect[2] = VectorRotation(l_vect[2], ~rotQuat[VMD_CENTER]);
607 r_vect[2] = VectorRotation(r_vect[2], ~rotQuat[VMD_CENTER]);
608
610 calcLegIK_CCD(l_vect, l_ik_vect, l_quat, 50);
611 calcLegIK_CCD(r_vect, r_ik_vect, r_quat, 50);
613
614 // HIP
615 if (rotQuat[VMD_L_HIP].c>0.0) rotQuat[VMD_L_HIP] = l_quat[2]*rotQuat[VMD_L_HIP];
616 else rotQuat[VMD_L_HIP] = l_quat[2];
617 if (rotQuat[VMD_R_HIP].c>0.0) rotQuat[VMD_R_HIP] = r_quat[2]*rotQuat[VMD_R_HIP];
618 else rotQuat[VMD_R_HIP] = r_quat[2];
619
622 framesData[fnum].jdat[VMD_L_HIP].index = fnum;
623 framesData[fnum].jdat[VMD_R_HIP].index = fnum;
624
625 // KNEE
626 rotQuat[VMD_L_KNEE] = l_quat[1];
627 rotQuat[VMD_R_KNEE] = r_quat[1];
628 //
629 double dot = vect_Y*rotQuat[VMD_L_KNEE].getVector();
630 if (dot>=0.0) {
632 framesData[fnum].jdat[VMD_L_KNEE].index = fnum;
633 }
634 else {
635 framesData[fnum].jdat[VMD_L_KNEE].joint = -1;
636 framesData[fnum].jdat[VMD_L_KNEE].index = -1;
637 }
638
639 dot = vect_Y*rotQuat[VMD_R_KNEE].getVector();
640 if (dot>=0.0) {
642 framesData[fnum].jdat[VMD_R_KNEE].index = fnum;
643 }
644 else {
645 framesData[fnum].jdat[VMD_R_KNEE].joint = -1;
646 framesData[fnum].jdat[VMD_R_KNEE].index = -1;
647 }
648
649 return;
650}
#define VMD_L_KNEE
Definition NiVMDTool.h:50
#define VMD_R_HIP
Definition NiVMDTool.h:56
#define VMD_L_HIP
Definition NiVMDTool.h:49
#define VMD_R_ANKLE_IK
Definition NiVMDTool.h:58
#define VMD_R_KNEE
Definition NiVMDTool.h:57
#define VMD_L_ANKLE_IK
Definition NiVMDTool.h:51
#define VMD_CENTER
Definition NiVMDTool.h:19
NiFrameData * framesData
void calcLegIK_CCD(Vector< double > *vect, Vector< double > ik, Quaternion< double > *quat, int rpmax)
NiJointData * jdat

References CNiVMDTool::calcLegIK_CCD(), CBaseFrameTool::framesData, NiJointData::index, NiFrameData::jdat, NiJointData::joint, CBaseFrameTool::posVect, CBaseFrameTool::rotQuat, VMD_CENTER, VMD_L_ANKLE_IK, VMD_L_HIP, VMD_L_KNEE, VMD_R_ANKLE_IK, VMD_R_HIP, and VMD_R_KNEE.

Referenced by CNiVMDTool::calcJointRotation().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ calcJointRotation()

void calcJointRotation ( void )
private

void CNiVMDTool::calcJointRotation(void)

全ジョイントのクオータニオンを計算し直す.

Definition at line 472 of file NiVMDTool.cpp.

473{
474 if (framesData==NULL || frames_num<=0) return;
475
476 if (posVect==NULL) posVect = (Vector<double>*)malloc(sizeof(Vector<double>)*VMD_JOINT_NUM);
477 if (rotQuat==NULL) rotQuat = (Quaternion<double>*)malloc(sizeof(Quaternion<double>)*VMD_JOINT_NUM);
478 if (posVect==NULL || rotQuat==NULL) return;
480
481 NiJointData prevJoint[VMD_JOINT_NUM]; // joints_num = VMD_JOINT_NUM
482 for (int j=0; j<VMD_JOINT_NUM; j++) {
483 prevJoint[j].joint = -1;
484 prevJoint[j].index = -1;
485 prevJoint[j].vect.init(-1.0);
486 prevJoint[j].quat.init(-1.0);
487 }
488
489 // 関節の変換
490 for (unsigned int i=0; i<frames_num; i++) {
491 //
492 NiJointData* jdata = framesData[i].jdat;
493
494 jdata[VMD_CENTER].vect.c = 1.0;
495 jdata[VMD_CENTER].quat.c = 1.0;
496
497 for (int j=0; j<framesData[i].jnum; j++) {
498 //
499 if (jdata[j].joint>=0) {
500 posVect[j] = jdata[j].vect;
501 rotQuat[j] = jdata[j].quat;
502 if (posVect[j].c<0.0) posVect[j] = prevJoint[j].vect;
503 if (rotQuat[j].c<0.0) rotQuat[j] = prevJoint[j].quat;
504 }
505 //
506 else {
507 posVect[j] = prevJoint[j].vect;
508 rotQuat[j] = prevJoint[j].quat;
509 }
510 }
511
513 calcJointIK(i); // IK
515
516 //
517 for (int j=0; j<framesData[i].jnum; j++) {
518 if (jdata[j].joint>=0) {
519 prevJoint[j] = jdata[j];
520 }
521 }
522
523 //
528
531
535 rotQuat[VMD_L_ARM] = rotQuat[VMD_L_ARM]*~A2TPose;
536
540
541 // 足首の回転は省略
542 rotQuat[VMD_L_ANKLE_IK].set(1.0, 0.0, 0.0, 0.0, 1.0);
543 rotQuat[VMD_R_ANKLE_IK].set(1.0, 0.0, 0.0, 0.0, 1.0);
544
545 //rotQuat[VMD_CENTER] = rotQuat[VMD_CENTER]*~rotQuat[VMD_PARENT];
546 //posVect[VMD_CENTER] = posVect[VMD_CENTER] + posVect[VMD_PARENT];
547
548 //
549 for (int j=0; j<framesData[i].jnum; j++) {
550 jdata[j].joint = prevJoint[j].joint;
551 jdata[j].index = prevJoint[j].index;
552 jdata[j].vect = posVect[j];
553 jdata[j].quat = rotQuat[j];
554 }
555 }
556
557 return;
558}
#define VMD_L_WRIST
Definition NiVMDTool.h:38
#define VMD_L_ARM
Definition NiVMDTool.h:34
#define VMD_L_ELBOW
Definition NiVMDTool.h:36
#define VMD_R_EYE
Definition NiVMDTool.h:29
#define VMD_L_EYE
Definition NiVMDTool.h:28
#define VMD_L_ARM_TW
Definition NiVMDTool.h:35
#define VMD_L_WRIST_TW
Definition NiVMDTool.h:37
#define VMD_R_ELBOW
Definition NiVMDTool.h:44
#define VMD_R_WRIST_TW
Definition NiVMDTool.h:45
#define VMD_R_WRIST
Definition NiVMDTool.h:46
#define VMD_R_ARM_TW
Definition NiVMDTool.h:43
#define VMD_EYES
Definition NiVMDTool.h:27
#define VMD_R_ARM
Definition NiVMDTool.h:42
void clearVectorData(int jnum)
unsigned int frames_num
void calcJointIK(int fnum)
Quaternion< double > quat
Vector< double > vect

References CNiVMDTool::A2TPose, CNiVMDTool::calcJointIK(), CBaseFrameTool::clearVectorData(), CBaseFrameTool::frames_num, CBaseFrameTool::framesData, NiJointData::index, NiFrameData::jdat, NiFrameData::jnum, NiJointData::joint, CBaseFrameTool::posVect, NiJointData::quat, CBaseFrameTool::rotQuat, NiJointData::vect, VMD_CENTER, VMD_EYES, VMD_JOINT_NUM, VMD_L_ANKLE_IK, VMD_L_ARM, VMD_L_ARM_TW, VMD_L_ELBOW, VMD_L_EYE, VMD_L_WRIST, VMD_L_WRIST_TW, VMD_R_ANKLE_IK, VMD_R_ARM, VMD_R_ARM_TW, VMD_R_ELBOW, VMD_R_EYE, VMD_R_WRIST, and VMD_R_WRIST_TW.

Referenced by CNiVMDTool::getFramesData().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ calcLegIK_CCD()

void calcLegIK_CCD ( Vector< double > * vect,
Vector< double > ik_vect,
Quaternion< double > * quat,
int rpmax )
private

HIP(2) -> KNEE(1) -> ANKLE(0) の IK をCCDで解く.

Definition at line 657 of file NiVMDTool.cpp.

658{
659 Vector<double> vect_Y(0.0, 1.0, 0.0, 1.0);
660 Vector<double> effect, target;
661 Quaternion<double> rot;
662
663 for (int j=0; j<3; j++) quat[j].init();
664
665 for (int i=0; i<rpmax; i++) {
666 //
667 int cnt = 0;
668 for (int j=1; j<3; j++) {
669 //
670 if (i==0 && j==1) {
671 rot.setRotation((double)PI_DIV2, vect_Y); // 最初にひざを曲げる
672 }
673 else {
674 effect = vect[0] - vect[j];
675 target = ik_vect - vect[j];
676 rot = V2VQuaternion(effect, target);
677 }
678
679 //
680 if (rot.c>0.0) {
681 rot.normalize();
682 if (rot.s<1.00-Zero_Eps) {
683 //if (rot.s<1.00) {
684 quat[j] = quat[j]*rot;
685 for (int k=0; k<j; k++) {
686 vect[k] = VectorRotation(vect[k]-vect[j], rot) + vect[j];
687 }
688 }
689 else cnt++;
690 }
691 else cnt++;
692 }
693 if (cnt==2) break;
694 }
695
696 return;
697}

Referenced by CNiVMDTool::calcJointIK().

Here is the caller graph for this function:

◆ clear_data()

void clear_data ( void )

Definition at line 197 of file NiVMDTool.cpp.

References CBaseFrameTool::free_data().

Referenced by CNiFileTool::clearFrameData(), CNiVMDTool::free_data(), CNiVMDTool::getFramesData(), and CNiVMDTool::readFile().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ convert2FrameData()

NiFrameData * convert2FrameData ( VMDJointData * motion_data,
unsigned int datanum,
unsigned int & framenum )
private

NiFrameData* CNiVMDTool::convert2FrameData(VMDJointData* motion_data, unsigned int datanum, unsigned int& framenum)

VMDの全フレームデータを共通ジョイントのフレームデータに変換する.

Parameters
[in]datanumデータの総数
[out]framenum一意的なフレームの数
Returns
(ダミー)フレームデータへのポインタ

Definition at line 388 of file NiVMDTool.cpp.

389{
390 framenum = 0;
391 if (motion_data==NULL || datanum<=0) return NULL;
392
393 // VMDのデータをフレーム番号でソート
394 VMDJointData swap_motion;
395 unsigned int k = datanum - 1;
396 while (k>0) {
397 unsigned int j = 0;
398 for (unsigned int i=0; i<k; i++) {
399 if (motion_data[i].frm_num>motion_data[i+1].frm_num) {
400 swap_motion = motion_data[i];
401 motion_data[i] = motion_data[i+1];
402 motion_data[i+1] = swap_motion;
403 j = i;
404 }
405 }
406 k = j;
407 }
408
409 // 一意的なフレーム数を数える
410 unsigned int uniq_frame = 1;
411
412 unsigned int frm_num = motion_data[0].frm_num;
413 for (unsigned int i=1; i<datanum; i++) {
414 if (frm_num!=motion_data[i].frm_num) {
415 uniq_frame++;
416 frm_num = motion_data[i].frm_num;
417 }
418 }
419
420 NiFrameData* ni_joints = makeFramesData((int)uniq_frame, joints_num, NULL);
421 if (ni_joints==NULL) return NULL;
422 framenum = uniq_frame;
423
424 // Joints
425 unsigned int datacnt = 0;
426 for (unsigned int i=0; i<uniq_frame; i++) {
427 frm_num = motion_data[datacnt].frm_num;
428 ni_joints[i].frmn = frm_num;
429 ni_joints[i].msec = (int)(frm_num*33.3333333333333); // msec
430 //
431 while (frm_num==motion_data[datacnt].frm_num) {
432 int joint = VMDJointNum(motion_data[datacnt].name);
433 if (joint>=0) {
434 NiJointData* jdat = &(ni_joints[i].jdat[joint]);
435 jdat->joint = joint;
436 jdat->index = i;
437 jdat->vect.x = -motion_data[datacnt].posz*(double)VMD_GRID_UNIT;
438 jdat->vect.y = motion_data[datacnt].posx*(double)VMD_GRID_UNIT;
439 jdat->vect.z = motion_data[datacnt].posy*(double)VMD_GRID_UNIT;
440 jdat->quat.x = motion_data[datacnt].qutz;
441 jdat->quat.y = -motion_data[datacnt].qutx;
442 jdat->quat.z = -motion_data[datacnt].quty;
443 jdat->quat.s = motion_data[datacnt].qutw;
444 if (jdat->quat.s<0.0) jdat->quat = - jdat->quat;
445 jdat->quat.normalize();
446
447 //
448 if (jdat->vect.x!=0.0 || jdat->vect.y!=0.0 || jdat->vect.z!=0.0) {
449 jdat->vect.c = 1.0;
450 }
451 if (jdat->quat.x!=0.0 || jdat->quat.y!=0.0 || jdat->quat.z!=0.0 || jdat->quat.s!=0.0) {
452 jdat->quat.c = 1.0;
453 }
454 }
455
456 datacnt++;
457 if (datacnt==datanum) break;
458 }
459 }
460
461 //
462 return ni_joints;
463}
#define VMD_GRID_UNIT
Definition NiVMDTool.h:12
NiFrameData * makeFramesData(int frame, int joint_num, int *frame_num)
int VMDJointNum(char *name)
Definition NiVMDTool.cpp:64
double qutz
Definition NiVMDTool.h:89
unsigned long frm_num
Definition NiVMDTool.h:83
double posx
Definition NiVMDTool.h:84
double posz
Definition NiVMDTool.h:86
double posy
Definition NiVMDTool.h:85
double quty
Definition NiVMDTool.h:88
double qutx
Definition NiVMDTool.h:87
double qutw
Definition NiVMDTool.h:90

References VMDJointData::frm_num, NiFrameData::frmn, NiJointData::index, NiFrameData::jdat, NiJointData::joint, CBaseFrameTool::joints_num, jbxwl::makeFramesData(), NiFrameData::msec, VMDJointData::posx, VMDJointData::posy, VMDJointData::posz, NiJointData::quat, VMDJointData::qutw, VMDJointData::qutx, VMDJointData::quty, VMDJointData::qutz, NiJointData::vect, VMD_GRID_UNIT, and jbxwl::VMDJointNum().

Referenced by CNiVMDTool::getFramesData().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ free_data()

void free_data ( void )

Definition at line 182 of file NiVMDTool.cpp.

183{
185 if (vmd_frames!=NULL) ::free(vmd_frames);
186
187 vmd_frames = NULL;
188 vmd_datnum = 0;
189 dmy_frames = NULL;
190 dmy_frmnum = 0;
191
192 clear_data();
193}
void clear_data(void)
void freeFramesData(NiFrameData *frmdata, int frm_num)

References CNiVMDTool::clear_data(), CNiVMDTool::dmy_frames, CNiVMDTool::dmy_frmnum, jbxwl::freeFramesData(), CNiVMDTool::vmd_datnum, and CNiVMDTool::vmd_frames.

Referenced by CNiVMDTool::~CNiVMDTool().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getFramesData()

NiFrameData * getFramesData ( void )
virtual

NiFrameData* CNiVMDTool::getJointsFrame(void)

ジョイントの各フレームデータを計算し,静的なデータとして返す. ただし,VMDでは全フレームのデータがないので,ここではダミーデータを返し,実際のデータは getFrameData()で得る.

See also
convert2FrameData()
calcJointRotation()

Reimplemented from CBaseFrameTool.

Definition at line 330 of file NiVMDTool.cpp.

331{
333
335 if (framesData!=NULL) clear_data();
337 if (framesData==NULL) return NULL;
338
341
342 // ジョイント番号の書き換え
343 for (unsigned int i=0; i<frames_num; i++) {
344 //
345 for (int j=0; j<framesData[i].jnum; j++) {
346 int n = VMD2NiJointNum(framesData[i].jdat[j].joint);
347 framesData[i].jdat[j].joint = n;
348 }
349 }
350
351
354 if (dmy_frames==NULL) {
356 return framesData;
357 }
358
359 for (unsigned int i=0; i<dmy_frmnum; i++) {
361 dmy_frames[i].msec = (int)(i*(100.0/(rate_frame*3.0)));
362 }
363 if (rate_frame!=1.0) {
364 for (unsigned int i=0; i<frames_num; i++) {
365 framesData[i].frmn = (int)(framesData[i].frmn*rate_frame);
366 framesData[i].msec = (int)(framesData[i].msec/rate_frame);
367 }
368 }
369
373
374 return dmy_frames;
375}
NiFrameData * convert2FrameData(VMDJointData *motion_data, unsigned int datnum, unsigned int &frmnum)
void calcJointRotation(void)
int VMD2NiJointNum(int joint)

References CNiVMDTool::calcJointRotation(), CNiVMDTool::clear_data(), CNiVMDTool::convert2FrameData(), CNiVMDTool::dmy_frames, CNiVMDTool::dmy_frmnum, CBaseFrameTool::exec_time, CBaseFrameTool::frames_num, CBaseFrameTool::framesData, NiFrameData::frmn, NiFrameData::jdat, NiFrameData::jnum, NiJointData::joint, CBaseFrameTool::joints_num, jbxwl::makeFramesData(), NiFrameData::msec, CNiVMDTool::rate_frame, CBaseFrameTool::start_time, CBaseFrameTool::stop_time, jbxwl::VMD2NiJointNum(), CNiVMDTool::vmd_datnum, CNiVMDTool::vmd_frames, and VMD_JOINT_NUM.

Referenced by CNiFileTool::readVMDFile().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getFramesNumber()

virtual unsigned int getFramesNumber ( void )
inlinevirtual

Reimplemented from CBaseFrameTool.

Definition at line 121 of file NiVMDTool.h.

121{ return dmy_frmnum;}

References CNiVMDTool::dmy_frmnum.

Referenced by CNiFileTool::readVMDFile().

Here is the caller graph for this function:

◆ getJointsData()

NiJointData * getJointsData ( int frmnum,
int fps )
virtual

NiJointData* CNiVMDTool::getJointsData(int frmnum, int fps)

動的にジョイントデータを計算する場合に使用する.
getJointsFrame で返したデータが NULLの場合,代わりにこの関数が呼ばれる.

フレーム frmnum時の 全ジョイントのデータを得る.戻り値は配列.
frmnumのデータが存在しない場合は,補間する.

Parameters
frmnumフレーム数
fpsFPS.

Reimplemented from CBaseFrameTool.

Definition at line 713 of file NiVMDTool.cpp.

714{
716
717 frmnum = (int)((double)frmnum*VMD_FARME_RATE/(double)fps);
718
719 //
720 for (int j=0; j<joints_num; j++) {
721 //
722 int n = framesData[0].jdat[j].joint;
723 if (n>=0) {
724 unsigned int st_index = 0;
725 unsigned int en_index = 0;
726
727 while (en_index<frames_num && framesData[en_index].frmn<frmnum) en_index++;
728 if (en_index==frames_num) break;
729
730 if (en_index==0 || (framesData[en_index].frmn==frmnum && en_index==framesData[en_index].jdat[j].index)) {
731 jointsData[j].vect = framesData[en_index].jdat[j].vect;
732 jointsData[j].quat = framesData[en_index].jdat[j].quat;
733 }
734 else {
735 st_index = framesData[en_index-1].jdat[j].index;
736 while (en_index<frames_num && en_index!=framesData[en_index].jdat[j].index) en_index++;
737
738 if (en_index==frames_num) {
739 jointsData[j].vect = framesData[st_index].jdat[j].vect;
740 jointsData[j].quat = framesData[st_index].jdat[j].quat;
741 }
742 else {
743 NiJointData st_joint = framesData[st_index].jdat[j];
744 NiJointData en_joint = framesData[en_index].jdat[j];
745 double tparam = ((double)(frmnum - framesData[st_index].frmn))/(framesData[en_index].frmn - framesData[st_index].frmn);
746 jointsData[j].vect = BSplineInterp4 (st_joint.vect, en_joint.vect, tparam);
747 jointsData[j].quat = SlerpQuaternion(st_joint.quat, en_joint.quat, tparam);
748 }
749 }
750
751 jointsData[j].joint = n;
752 jointsData[j].index = frmnum;
753 jointsData[j].vect.c = 1.0;
754 jointsData[j].quat.c = 1.0;
755 }
756 }
757
758 return jointsData;
759}
NiJointData * jointsData
void clearJointsData(int jnum)

References CBaseFrameTool::clearJointsData(), CBaseFrameTool::frames_num, CBaseFrameTool::framesData, NiJointData::index, NiFrameData::jdat, NiJointData::joint, CBaseFrameTool::joints_num, CBaseFrameTool::jointsData, NiJointData::quat, NiJointData::vect, and VMD_FARME_RATE.

Here is the call graph for this function:

◆ readFile()

BOOL readFile ( FILE * fp)
virtual

BOOL CNiVMDTool::readFile(FILE* fp)

VMDファイルを読み込む

Reimplemented from CBaseFrameTool.

Definition at line 213 of file NiVMDTool.cpp.

214{
215 if (fp==NULL) return FALSE;
216
217 clear_data();
218
219 vmd_datnum = 0;
220 vmd_header = readFileHeader(fp); // ヘッダ部
221 if (vmd_header.data_num==0) return FALSE;
222
223 vmd_frames = readJointsData(fp, vmd_header.data_num); // 全フレームのデータ
224 if (vmd_frames==NULL) return FALSE;
226
227 //
229 if (jointsData!=NULL) ::free(jointsData);
230 jointsData = (NiJointData*)malloc(sizeof(NiJointData)*joints_num);
231 if (jointsData==NULL) {
232 clear_data();
233 return FALSE;
234 }
236
237 if (posVect==NULL) posVect = (Vector<double>*)malloc(sizeof(Vector<double>)*VMD_JOINT_NUM);
238 if (rotQuat==NULL) rotQuat = (Quaternion<double>*)malloc(sizeof(Quaternion<double>)*VMD_JOINT_NUM);
239 if (posVect==NULL || rotQuat==NULL) {
240 clear_data();
241 return FALSE;
242 }
244
245 return TRUE;
246}
VMDFileHeader readFileHeader(FILE *fp)
VMDJointData * readJointsData(FILE *fp, unsigned int &frmnum)
unsigned int data_num
Definition NiVMDTool.h:74

References CNiVMDTool::clear_data(), CBaseFrameTool::clearJointsData(), CBaseFrameTool::clearVectorData(), VMDFileHeader::data_num, CBaseFrameTool::joints_num, CBaseFrameTool::jointsData, CBaseFrameTool::posVect, CNiVMDTool::readFileHeader(), CNiVMDTool::readJointsData(), CBaseFrameTool::rotQuat, CNiVMDTool::vmd_datnum, CNiVMDTool::vmd_frames, CNiVMDTool::vmd_header, and VMD_JOINT_NUM.

Referenced by CNiFileTool::readVMDFile().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ readFileHeader()

VMDFileHeader readFileHeader ( FILE * fp)
private

VMDFileHeader CNiVMDTool::readFileHeader(FILE* fp)

VMDファイルのヘッダ部を読み込む

Definition at line 255 of file NiVMDTool.cpp.

256{
257 VMDFileHeader fhd;
258
259 fread(fhd.header, 30, 1, fp);
260 fread(fhd.name, 20, 1, fp);
261 fread(&fhd.data_num, 4, 1, fp);
262
263 if (strcmp(VMD_FILE_HD_ID2, fhd.header)) {
264 fhd.data_num = 0;
265 }
266
267 return fhd;
268}
#define VMD_FILE_HD_ID2
Definition NiVMDTool.h:9
char name[20]
Definition NiVMDTool.h:73
char header[30]
Definition NiVMDTool.h:72

References VMDFileHeader::data_num, VMDFileHeader::header, VMDFileHeader::name, and VMD_FILE_HD_ID2.

Referenced by CNiVMDTool::readFile().

Here is the caller graph for this function:

◆ readJointData()

VMDJointData readJointData ( FILE * fp)
private

VMDJointData CNiVMDTool::readJointData(FILE* fp)

VMDファイルから 1フレーム(ジョイント)の VMDJointDataを読み込む.
sizeof(VMDJointData)==15 + (4+4x7+64)

Definition at line 278 of file NiVMDTool.cpp.

279{
280 VMDJointData frame;
281
282 fread(frame.name, 15, 1, fp);
283 fread(&frame.frm_num, 96, 1, fp); // 4 + 4x7 + 64
284
285 return frame;
286}
char name[15]
Definition NiVMDTool.h:82

References VMDJointData::frm_num, and VMDJointData::name.

Referenced by CNiVMDTool::readJointsData().

Here is the caller graph for this function:

◆ readJointsData()

VMDJointData * readJointsData ( FILE * fp,
unsigned int & frmnum )
private

VMDJointData* CNiVMDTool::readJointsData(FILE* fp, unsigned int& frmnum)

全フレーム&ジョイントの VMDJointDataを読み込む.
ジョイント間でフレームの同期は取られていない.

Definition at line 296 of file NiVMDTool.cpp.

297{
298 VMDJointData* motion_data = (VMDJointData*)malloc(frmnum*sizeof(VMDJointData));
299 if (motion_data==NULL) return NULL;
300 memset(motion_data, 0, frmnum*sizeof(VMDJointData));
301
302 //
303 unsigned int num = 0;
304 while(num<frmnum) {
305 motion_data[num] = readJointData(fp);
306 if (feof(fp)) break;
307 num++;
308 }
309
310 frmnum = num;
311 if (frmnum==0) {
312 ::free(motion_data);
313 motion_data = NULL;
314 }
315
316 return motion_data;
317}
VMDJointData readJointData(FILE *fp)

References CNiVMDTool::readJointData().

Referenced by CNiVMDTool::readFile().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ A2TPose

Quaternion<double> A2TPose
private

Definition at line 129 of file NiVMDTool.h.

Referenced by CNiVMDTool::calcJointRotation(), and CNiVMDTool::CNiVMDTool().

◆ dmy_frames

NiFrameData* dmy_frames
private

◆ dmy_frmnum

unsigned int dmy_frmnum
private

◆ rate_frame

double rate_frame
private

Definition at line 130 of file NiVMDTool.h.

Referenced by CNiVMDTool::CNiVMDTool(), and CNiVMDTool::getFramesData().

◆ vmd_datnum

unsigned int vmd_datnum
private

◆ vmd_frames

◆ vmd_header

VMDFileHeader vmd_header
private

Definition at line 133 of file NiVMDTool.h.

Referenced by CNiVMDTool::CNiVMDTool(), and CNiVMDTool::readFile().


The documentation for this class was generated from the following files: