19 bvh = (BVHData*)malloc(
sizeof(BVHData));
20 if (bvh==NULL)
return NULL;
30 if (bvh==NULL || *bvh==NULL)
return;
42 if (bvh==NULL)
return;
44 memset(bvh, 0,
sizeof(BVHData));
53 if (bvh==NULL)
return;
55 if (bvh->hierarchy!=NULL) {
57 bvh->hierarchy = NULL;
59 if (bvh->motion!=NULL) {
63 if (bvh->offset!=NULL) {
92 if (fp==NULL)
return NULL;
97 pp = fgets(line,
LBUF, fp);
99 if (pack==NULL)
return NULL;
123 if (fp==NULL || key==NULL)
return NULL;
128 if (!
strcasecmp((
char*)list->ldat.key.buf, key))
return list;
142 if (pp==NULL)
return 0;
143 while(pp->esis!=NULL) pp = pp->esis;
159 if (pp==NULL)
return 0;
160 while(pp->esis!=NULL) pp = pp->esis;
182 if (pp==NULL)
return;
184 while(pp->esis!=NULL) pp = pp->esis;
188 **vect = *(
vector*)pp->ldat.ptr;
207 if (bvh==NULL || bvh->hierarchy==NULL)
return;
218 if (pp==NULL)
return;
220 while(pp->esis!=NULL) pp = pp->esis;
223 bvh->channels += pp->ldat.lv;
238 for (i=0; i<depth;i++) fprintf(fp,
" ");
255 FILE* fp = fopen(fn,
"r");
256 if (fp==NULL)
return NULL;
277 if (bvh->hierarchy==NULL || bvh->motion==NULL || bvh->state<0)
return JBXL_ARGS_ERROR;
279 FILE* fp = fopen(fn,
"w");
291 if (bvh==NULL || bvh->hierarchy==NULL || bvh->motion==NULL)
return JBXL_ARGS_ERROR;
309 if (fp==NULL || bvh==NULL || bvh->hierarchy==NULL)
return JBXL_ARGS_ERROR;
323 while(tree->esis!=NULL) tree = tree->esis;
337 if (ld.key.buf!=NULL) fprintf(fp,
" %s", ld.key.buf);
347 fprintf(fp,
" %f %f %f\n", vect->
x, vect->
y, vect->
z);
350 fprintf(fp,
" %f %f %f\n", 0.0, 0.0, 0.0);
354 if (ld.lv>0 && ld.val.buf!=NULL) {
357 for (i=0; i<ld.lv*2; i+=2) {
358 if (ld.val.buf[i]==
'P') {
359 if (ld.val.buf[i+1]==
'X') fprintf(fp,
" %s",
BVH_STR_PX);
360 else if (ld.val.buf[i+1]==
'Y') fprintf(fp,
" %s",
BVH_STR_PY);
361 else if (ld.val.buf[i+1]==
'Z') fprintf(fp,
" %s",
BVH_STR_PZ);
363 else if (ld.val.buf[i]==
'R') {
364 if (ld.val.buf[i+1]==
'X') fprintf(fp,
" %s",
BVH_STR_RX);
365 else if (ld.val.buf[i+1]==
'Y') fprintf(fp,
" %s",
BVH_STR_RY);
366 else if (ld.val.buf[i+1]==
'Z') fprintf(fp,
" %s",
BVH_STR_RZ);
374 if (tree->next!=NULL) {
391 if (fp==NULL || bvh==NULL || bvh->motion==NULL)
return JBXL_ARGS_ERROR;
399 for (j=0; j<bvh->frame_num; j++) {
400 int jpos = j*bvh->channels;
401 for (i=0; i<bvh->channels; i++) {
402 fprintf(fp,
"%f ", bvh->motion[jpos+i]);
423 if (fp==NULL)
return NULL;
427 if (list==NULL)
return bvh;
432 if (bvh==NULL)
return NULL;
436 if (bvh->hierarchy==NULL) {
446 bvh->offset = (
vector*)malloc(
sizeof(
vector)*bvh->joint_num);
447 if (bvh->offset!=NULL) {
448 memset(bvh->offset, 0,
sizeof(
vector)*bvh->joint_num);
449 vector* vect = bvh->offset;
455 if (list==NULL)
return bvh;
459 if (list==NULL || list->next==NULL)
return bvh;
460 bvh->frame_num = atoi((
char*)list->next->ldat.key.buf);
464 if (list==NULL || list->next==NULL || list->next->next==NULL)
return bvh;
466 bvh->frame_time = atof((
char*)list->next->next->ldat.key.buf);
467 if (bvh->frame_time!=0.0) bvh->framepsec = (int)(1./bvh->frame_time);
468 else bvh->framepsec = 30;
482 if (bvh==NULL || fp==NULL)
return;
483 if (bvh->channels<=0 || bvh->frame_num<=0)
return;
485 unsigned long int len = bvh->channels*bvh->frame_num*
sizeof(double);
486 bvh->motion = (
double*)malloc(len);
487 if (bvh->motion==NULL)
return;
488 memset(bvh->motion, 0, len);
494 while (!feof(fp) && list!=NULL) {
495 if (list->ldat.key.buf==NULL) {
500 int jptr = j*bvh->channels;
504 while (i<bvh->channels && lt!=NULL) {
505 bvh->motion[jptr+i] = atof((
char*)lt->ldat.key.buf);
531 char* cmp = (
char*)list->ldat.key.buf;
537 if (list->next==NULL) {
539 if (tree==NULL) tree = next;
543 if (tree==NULL) tree = next;
550 if (list->next==NULL) {
552 if (tree==NULL) tree = next;
556 if (tree==NULL) tree = next;
563 if (list->next==NULL) {
578 memset(vect, 0,
sizeof(
vector));
580 if (lt->next!=NULL) {
582 vect->
x = atof((
char*)lt->ldat.key.buf);
584 if (lt->next!=NULL) {
586 vect->
y = atof((
char*)lt->ldat.key.buf);
588 if (lt->next!=NULL) {
590 vect->
z = atof((
char*)lt->ldat.key.buf);
594 tree->ldat.ptr = (
void*)vect;
595 tree->ldat.sz =
sizeof(
vector);
606 if (lt->next!=NULL) {
608 num = atoi((
char*)lt->ldat.key.buf);
610 if (tree!=NULL) tree->ldat.lv = num;
616 for (i=0; i<num; i++) {
617 if (lt->next!=NULL) {
640 if (tree!=NULL) tree->ldat.val = channel;
645 else if (!strcmp(cmp,
"{")) {
656 else if (!strcmp(cmp,
"}")) {
Buffer make_Buffer(int sz)
Buffer型変数のバッファ部をつくり出す.
#define cat_s2Buffer(src, dst)
cat_b2Buffer()
#define JBXL_ARGS_ERROR
不正な引数(NULLなど)
#define JBXL_BVH_MOTION_ERROR
MOTIONデータの書き込み失敗
#define JBXL_FILE_OPEN_ERROR
ファイルオープン エラー
#define JBXL_BVH_HIERARCHY_ERROR
HIERARCHYデータの書き込み失敗
tList * del_tList(tList **pp)
指定したリストノード以降のリストを削除.
tList * awk_tList(char *str, char cc)
文字列を区切り文字で区切って,各項目をリストのキー部に入れて返す.
tTree * del_tTree(tTree **pp)
指定したノード以下のツリーを削除する.
tTree * add_tTree_node_bystr(tTree *pp, int id, int lv, const char *key, const char *val, void *ptr, int sz)
ノードを末っ子としてリストに追加.