35#include <libFreeWRL.h>
37#include "../vrml_parser/Structs.h"
38#include "../vrml_parser/CRoutes.h"
39#include "../main/headers.h"
40#include "../opengl/Material.h"
41#include "../opengl/OpenGL_Utils.h"
43#include "../scenegraph/RenderFuncs.h"
45#include "Component_Shape.h"
46#include "../opengl/Frustum.h"
47#include "LinearAlgebra.h"
48#include "../ui/common.h"
347 Stack *humanoid_stack;
348 Stack* humanoid_skinCoord_stack;
352void *Component_HAnim_constructor(){
357void Component_HAnim_init(
struct tComponent_HAnim *t){
360 t->prv = Component_HAnim_constructor();
362 ppComponent_HAnim p = (ppComponent_HAnim)t->prv;
364 p->humanoid_skinCoord_stack = newStack(
void*);
365 stack_push(
void*, p->humanoid_skinCoord_stack, NULL);
366 p->joint_center = newStack(
struct SFVec3f);
367 p->bones = newStack(
bone);
370void Component_HAnim_clear(
struct tComponent_HAnim *t){
374 ppComponent_HAnim p = (ppComponent_HAnim)t->prv;
376 deleteStack(
void*, p->humanoid_skinCoord_stack);
377 deleteStack(
float*, p->joint_center);
378 deleteStack(
bone, p->bones);
383void push_humanoid_skinCoord(
void* coord) {
384 ppComponent_HAnim p = (ppComponent_HAnim)gglobal()->Component_HAnim.prv;
385 stack_push(
void*, p->humanoid_skinCoord_stack, coord);
387void* peek_humanoid_skinCoord() {
388 ppComponent_HAnim p = (ppComponent_HAnim)gglobal()->Component_HAnim.prv;
389 return stack_top(
void*, p->humanoid_skinCoord_stack);
391void pop_humanoid_skinCoord() {
392 ppComponent_HAnim p = (ppComponent_HAnim)gglobal()->Component_HAnim.prv;
393 stack_pop(
void*, p->humanoid_skinCoord_stack);
399 ppComponent_HAnim p = (ppComponent_HAnim)gglobal()->Component_HAnim.prv;
403 ppComponent_HAnim p = (ppComponent_HAnim)gglobal()->Component_HAnim.prv;
407 ppComponent_HAnim p = (ppComponent_HAnim)gglobal()->Component_HAnim.prv;
410void push_joint_center(
float *center) {
412 ppComponent_HAnim p = (ppComponent_HAnim)gglobal()->Component_HAnim.prv;
413 double modelview[16], rootmat[16], a[3], r[3];
415 FW_GL_GETDOUBLEV(GL_MODELVIEW_MATRIX, modelview);
416 matmultiplyAFFINE(rootmat, modelview, p->HHMatrix);
417 float2double(a, center, 3);
418 transformAFFINEd(r, a, rootmat);
419 double2float(rcenter.c, r,3);
420 stack_push(
struct SFVec3f, p->joint_center, rcenter);
422void pop_joint_center() {
423 ppComponent_HAnim p = (ppComponent_HAnim)gglobal()->Component_HAnim.prv;
424 stack_pop(
struct SFVec3f, p->joint_center);
426float* peek_joint_center() {
427 ppComponent_HAnim p = (ppComponent_HAnim)gglobal()->Component_HAnim.prv;
428 struct SFVec3f* cc = stack_top_ptr(
struct SFVec3f, p->joint_center);
431int joint_center_count() {
432 ppComponent_HAnim p = (ppComponent_HAnim)gglobal()->Component_HAnim.prv;
433 return p->joint_center->n;
435void push_bone(
float *head,
float* tail) {
437 ppComponent_HAnim p = (ppComponent_HAnim)gglobal()->Component_HAnim.prv;
439 veccopy3f(b.head, head);
440 veccopy3f(b.tail, tail);
441 stack_push(
bone, p->bones, b);
444 ppComponent_HAnim p = (ppComponent_HAnim)gglobal()->Component_HAnim.prv;
445 clearStack(p->bones);
447bone* peek_bone(
int index) {
448 ppComponent_HAnim p = (ppComponent_HAnim)gglobal()->Component_HAnim.prv;
449 return vector_get_ptr(
bone, p->bones,index);
452 ppComponent_HAnim p = (ppComponent_HAnim)gglobal()->Component_HAnim.prv;
453 return vectorSize(p->bones);
458void update_jointMatrixFromMotion(
struct X3D_Node* HM,
char *jname,
double *jmatrix);
466 node->__do_center = verify_translate ((GLfloat *)node->center.c);
467 node->__do_trans = verify_translate ((GLfloat *)node->translation.c);
468 node->__do_scale = verify_scale ((GLfloat *)node->scale.c);
469 node->__do_rotation = verify_rotate ((GLfloat *)node->rotation.c);
470 node->__do_scaleO = verify_rotate ((GLfloat *)node->scaleOrientation.c);
472 node->__do_anything = (node->__do_center ||
475 node->__do_rotation ||
485 hr->joint_changed = TRUE;
491void update_displacerWeightFromMotion(
struct X3D_Node* HMnode,
char* jname,
float* weight);
507 if(!renderstate()->render_vp) {
508 push_transform_local_identity();
511 if (node->__do_anything) {
515 FW_GL_LOAD_IDENTITY();
518 if (node->__do_trans)
519 FW_GL_TRANSLATE_F(node->translation.c[0],node->translation.c[1],node->translation.c[2]);
522 if (node->__do_center)
523 FW_GL_TRANSLATE_F(node->center.c[0],node->center.c[1],node->center.c[2]);
528 double modelviewMatrix[16];
529 for (
int i = 0; i < HH->motions.n; i++) {
532 if(HM->transitionWeight > 0.0){
534 FW_GL_GETDOUBLEV(GL_MODELVIEW_MATRIX, modelviewMatrix);
538 update_jointMatrixFromMotion(X3D_NODE(HM),node->name->strptr,modelviewMatrix);
540 FW_GL_SETDOUBLEV(GL_MODELVIEW_MATRIX, modelviewMatrix);
543 for (
int j = 0; j < node->displacers.n; j++) {
545 char* name = dp->name->strptr;
546 update_displacerWeightFromMotion(X3D_NODE(HM), name, &dp->weight);
554 if (node->__do_rotation) {
555 FW_GL_ROTATE_RADIANS(node->rotation.c[3], node->rotation.c[0],node->rotation.c[1],node->rotation.c[2]);
559 if (node->__do_scaleO) {
560 FW_GL_ROTATE_RADIANS(node->scaleOrientation.c[3], node->scaleOrientation.c[0], node->scaleOrientation.c[1],node->scaleOrientation.c[2]);
565 if (node->__do_scale)
566 FW_GL_SCALE_F(node->scale.c[0],node->scale.c[1],node->scale.c[2]);
569 if (node->__do_scaleO)
570 FW_GL_ROTATE_RADIANS(-node->scaleOrientation.c[3], node->scaleOrientation.c[0], node->scaleOrientation.c[1],node->scaleOrientation.c[2]);
573 if (node->__do_center)
574 FW_GL_TRANSLATE_F(-node->center.c[0],-node->center.c[1],-node->center.c[2]);
579 FW_GL_GETDOUBLEV(GL_MODELVIEW_MATRIX,mat);
581 FW_GL_TRANSFORM_D(mat);
582 reset_transform_local(mat);
598 if(!renderstate()->render_vp) {
599 pop_transform_local();
600 if (node->__do_anything) {
605 if((node->_renderFlags & VF_Viewpoint) == VF_Viewpoint) {
606 FW_GL_TRANSLATE_F(((node->center).c[0]),((node->center).c[1]),((node->center).c[2])
608 FW_GL_ROTATE_RADIANS(((node->scaleOrientation).c[3]),((node->scaleOrientation).c[0]),((node->scaleOrientation).c[1]),((node->scaleOrientation).c[2])
610 FW_GL_SCALE_F((
float)1.0/(((node->scale).c[0])),(
float)1.0/(((node->scale).c[1])),(
float)1.0/(((node->scale).c[2]))
612 FW_GL_ROTATE_RADIANS(-(((node->scaleOrientation).c[3])),((node->scaleOrientation).c[0]),((node->scaleOrientation).c[1]),((node->scaleOrientation).c[2])
614 FW_GL_ROTATE_RADIANS(-(((node->rotation).c[3])),((node->rotation).c[0]),((node->rotation).c[1]),((node->rotation).c[2])
616 FW_GL_TRANSLATE_F(-(((node->center).c[0])),-(((node->center).c[1])),-(((node->center).c[2]))
618 FW_GL_TRANSLATE_F(-(((node->translation).c[0])),-(((node->translation).c[1])),-(((node->translation).c[2]))
630 node->__do_center = verify_translate ((GLfloat *)node->center.c);
631 node->__do_trans = verify_translate ((GLfloat *)node->translation.c);
632 node->__do_scale = verify_scale ((GLfloat *)node->scale.c);
633 node->__do_rotation = verify_rotate ((GLfloat *)node->rotation.c);
634 node->__do_scaleO = verify_rotate ((GLfloat *)node->scaleOrientation.c);
636 node->__do_anything = (node->__do_center ||
639 node->__do_rotation ||
662 if(!renderstate()->render_vp) {
664 push_transform_local_identity();
666 if (node->__do_anything) {
670 FW_GL_LOAD_IDENTITY();
673 if (node->__do_trans)
674 FW_GL_TRANSLATE_F(node->translation.c[0],node->translation.c[1],node->translation.c[2]);
677 if (node->__do_center)
678 FW_GL_TRANSLATE_F(node->center.c[0],node->center.c[1],node->center.c[2]);
681 if (node->__do_rotation) {
682 FW_GL_ROTATE_RADIANS(node->rotation.c[3], node->rotation.c[0],node->rotation.c[1],node->rotation.c[2]);
686 if (node->__do_scaleO) {
687 FW_GL_ROTATE_RADIANS(node->scaleOrientation.c[3], node->scaleOrientation.c[0], node->scaleOrientation.c[1],node->scaleOrientation.c[2]);
692 if (node->__do_scale)
693 FW_GL_SCALE_F(node->scale.c[0],node->scale.c[1],node->scale.c[2]);
696 if (node->__do_scaleO)
697 FW_GL_ROTATE_RADIANS(-node->scaleOrientation.c[3], node->scaleOrientation.c[0], node->scaleOrientation.c[1],node->scaleOrientation.c[2]);
700 if (node->__do_center)
701 FW_GL_TRANSLATE_F(-node->center.c[0],-node->center.c[1],-node->center.c[2]);
705 FW_GL_GETDOUBLEV(GL_MODELVIEW_MATRIX,mat);
707 FW_GL_TRANSFORM_D(mat);
708 reset_transform_local(mat);
724 if(!renderstate()->render_vp) {
725 pop_transform_local();
726 if (node->__do_anything) {
731 if((node->_renderFlags & VF_Viewpoint) == VF_Viewpoint) {
732 FW_GL_TRANSLATE_F(((node->center).c[0]),((node->center).c[1]),((node->center).c[2])
734 FW_GL_ROTATE_RADIANS(((node->scaleOrientation).c[3]),((node->scaleOrientation).c[0]),((node->scaleOrientation).c[1]),((node->scaleOrientation).c[2])
736 FW_GL_SCALE_F((
float)1.0/(((node->scale).c[0])),(
float)1.0/(((node->scale).c[1])),(
float)1.0/(((node->scale).c[2]))
738 FW_GL_ROTATE_RADIANS(-(((node->scaleOrientation).c[3])),((node->scaleOrientation).c[0]),((node->scaleOrientation).c[1]),((node->scaleOrientation).c[2])
740 FW_GL_ROTATE_RADIANS(-(((node->rotation).c[3])),((node->rotation).c[0]),((node->rotation).c[1]),((node->rotation).c[2])
742 FW_GL_TRANSLATE_F(-(((node->center).c[0])),-(((node->center).c[1])),-(((node->center).c[2]))
744 FW_GL_TRANSLATE_F(-(((node->translation).c[0])),-(((node->translation).c[1])),-(((node->translation).c[2]))
756 VERTEXTRANSFORMMETHOD_CPU = 1,
757 VERTEXTRANSFORMMETHOD_GPU = 2,
759static int vertex_transform_method = VERTEXTRANSFORMMETHOD_GPU;
760int vertexTransformMethod() {
761 return vertex_transform_method;
763void fwl_set_skinning(
char tf) {
764 if (tf ==
'F' || tf ==
'f')
765 vertex_transform_method = VERTEXTRANSFORMMETHOD_CPU;
767 vertex_transform_method = VERTEXTRANSFORMMETHOD_GPU;
778void line_draw(
float* p,
float* q,
int depthtest,
float linewidth);
780void render_rig_bones() {
784 if (fwl_getDrawRig()) {
785 glDisable(GL_DEPTH_TEST);
787 for (
int i = 0; i < bone_count(); i++) {
788 bone* b = peek_bone(i);
789 line_draw(b->head, b->tail, TRUE, 1.5);
792 glEnable(GL_DEPTH_TEST);
796void save_rig_bone(
struct X3D_HAnimJoint* joint,
double* jointmat) {
798 if (joint_center_count()) {
801 float2double(a, joint->center.c, 3);
802 transformAFFINEd(r, a, jointmat);
803 double2float(rcenter, r, 3);
805 push_bone(peek_joint_center(), rcenter);
809 int i,j, jointTransformIndex;
810 double modelviewMatrix[16];
817 ppComponent_HAnim p = (ppComponent_HAnim)gglobal()->Component_HAnim.prv;
820 HH = peek_humanoid();
823 if (hr->make_joint_list) {
825 HH->joints.p = realloc(HH->joints.p, HH->joints.n *
sizeof(
void*));
826 HH->joints.p[HH->joints.n - 1] = X3D_NODE(node);
829 FW_GL_GETDOUBLEV(GL_MODELVIEW_MATRIX, modelviewMatrix);
830 matmultiplyAFFINE(jointMatrix.mat,modelviewMatrix,p->HHMatrix);
831 if (1) save_rig_bone(node, jointMatrix.mat);
835 if(0)
if(HH->motions.n){
836 for(
int i=0;i<HH->motions.n;i++){
837 if(HH->motionsEnabled.p[i]){
839 update_jointMatrixFromMotion(HH->motions.p[i],node->name->strptr,jointMatrix.mat);
848 float fmat4[16], fmat3[9],fmat3i[9];
849 matdouble2float4(fmat4,jointMatrix.mat);
850 mat423f(fmat3,fmat4);
851 matinverse3f(fmat3i,fmat3);
852 mattranspose3f(jointMatrix.normat,fmat3i);
859 stack_push(
JMATRIX,hr->JT,jointMatrix);
864 jointTransformIndex = vectorSize(hr->JT);
872 for (i = 0; i < node->skinCoordIndex.n; i++) {
873 int idx = node->skinCoordIndex.p[i];
874 float wt = node->skinCoordWeight.n ? node->skinCoordWeight.p[min(i, node->skinCoordWeight.n - 1)] : 1.0f;
875 for (j = 0; j < 4; j++) {
876 if (PVI[idx * 4 + j] == 0) {
877 PVI[idx * 4 + j] = jointTransformIndex;
878 PVW[idx * 4 + j] = wt;
887 if (HH->skinCoord && node->displacers.n) {
888 if (vertexTransformMethod() == VERTEXTRANSFORMMETHOD_CPU) {
893 psc = (
float*)nc->point.p;
895 for (i = 0; i < node->displacers.n; i++) {
897 float* point, weight, wdisp[3];
901 pdp = (
float*)dp->displacements.p;
904 ni = dp->coordIndex.n;
905 ci = dp->coordIndex.p;
906 for (j = 0; j < ni; j++) {
908 point = &psc[index * 3];
909 vecscale3f(wdisp, &pdp[j * 3], weight);
910 vecadd3f(point, point, wdisp);
917 HH->skinCoord->_change++;
918 parents = HH->skinCoord->_parentVector;
919 for (k = 0; k < vectorSize(parents); k++) {
926 else if (vertexTransformMethod() == VERTEXTRANSFORMMETHOD_GPU) {
944 if (!hr->dindex_done) {
945 if (!hr->dindex_lookup) {
950 hr->dindex_lookup = newStack(
ivec2);
954 ivec2 cindin = { -1,0 };
956 stack_push(
ivec2, hr->dindex_lookup, cindin);
958 for (i = 0; i < node->displacers.n; i++) {
959 int index, * dindex, j;
960 float* point, weight, wdisp[3];
965 int ni = dp->coordIndex.n;
966 int* ci = dp->coordIndex.p;
967 if (!dp->_dindex) dp->_dindex = malloc(
sizeof(
int) * ni);
968 dindex = (
int*)dp->_dindex;
971 for (j = 0; j < ni; j++) {
973 for (
int k = 0; k < hr->ND; k++) {
974 ivec2 cindin = vector_get(
ivec2, hr->dindex_lookup, k);
975 if (cindin.X == ci[j]) {
983 index = cindin.Y = hr->ND; hr->ND++;
985 stack_push(
ivec2, hr->dindex_lookup, cindin);
990 int nc = X3D_COORDINATE(HH->skinCoord)->point.n;
991 hr->dindex = malloc(
sizeof(
int) * nc );
992 memset(hr->dindex, 0,
sizeof(
int)* nc);
994 hr->dindex[ci[j]] = index;
1000 hr->joint_displacer_count += node->displacers.n;
1008 for (i = 0; i < node->displacers.n; i++) {
1009 int index, *dindex, j;
1010 float* point, weight, wdisp[3];
1012 weight = dp->weight;
1013 if (weight > 0.0f) {
1015 float* pdp = (
float*)dp->displacements.p;
1017 int ni = dp->coordIndex.n;
1018 int* ci = dp->coordIndex.p;
1019 dindex = dp->_dindex;
1020 for (j = 0; j < ni; j++) {
1022 float* displace = &hr->displace[index * 4];
1023 vecscale3f(wdisp, &pdp[j * 3], weight);
1024 vecadd3f(displace, displace, wdisp);
1034int vecsametol3f(
float *a,
float *b,
float tol){
1037 if(fabsf(a[i] - b[i]) > tol) isame = FALSE;
1046 if (!node->_intern) {
1052 static int oncegpu = 0;
1054 char* smeth =
"GPU";
1055 if (vertexTransformMethod() == VERTEXTRANSFORMMETHOD_CPU)
1057 printf(
"Skinning Method: %s\n", smeth);
1060 push_humanoid(node);
1061 if (node->motions.n) {
1062 if (node->motions.n > node->motionsEnabled.n) {
1064 int* moe = MALLOC(
int*, node->motions.n *
sizeof(
int));
1065 memset(moe, 0, node->motions.n *
sizeof(
int));
1066 memcpy(moe, node->motionsEnabled.p, node->motionsEnabled.n *
sizeof(
int));
1068 for (
int i = node->motionsEnabled.n; i < node->motions.n; i++) {
1072 FREE_IF_NZ(node->motionsEnabled.p);
1073 node->motionsEnabled.p = moe;
1074 node->motionsEnabled.n = node->motions.n;
1077 if (node->motions.n > node->_lastMotionsEnabled.n) {
1078 node->_lastMotionsEnabled.p = MALLOC(
int*, node->motions.n *
sizeof(
int));
1079 node->_lastMotionsEnabled.n = node->motions.n;
1080 for (
int i = 0; i < node->_lastMotionsEnabled.n; i++)
1081 node->_lastMotionsEnabled.p[i] = 0;
1083 for (
int i = 0; i < node->motions.n; i++) {
1084 check_compile(node->motions.p[i]);
1088 int nsc = 0, nsn = 0;
1089 float* psc = NULL, * psn = NULL;
1090 if (node->skinCoord && node->skinCoord->_nodeType == NODE_Coordinate) {
1094 static int ionce = 0;
1096 printf(
"number of skin coord points %d", nsc);
1102 if (vertexTransformMethod() == VERTEXTRANSFORMMETHOD_CPU) {
1103 psc = (
float*)nc->point.p;
1104 node->_origCoords = realloc(node->_origCoords, nsc * 3 *
sizeof(
float));
1105 memcpy(node->_origCoords, psc, nsc * 3 *
sizeof(
float));
1108 float myfind[9] = { -0.030000f, -0.070000f, 1.777000f, -0.070000f, 1.777000f, 0.130000f, 1.777000f, 0.130000f, 0.070000f };
1110 for (i = 0; i < nsc; i++) {
1111 for (j = 0; j < 3; j++)
1112 if (vecsametol3f(&psc[i * 3], &myfind[j * 3], .001f)) {
1113 printf(
"%d %f %f %f\n", i, myfind[j * 3 + 0], myfind[j * 3 + 1], myfind[j * 3 + 2]);
1121 if (node->skinNormal && node->skinNormal->_nodeType == NODE_Normal) {
1125 if (vertexTransformMethod() == VERTEXTRANSFORMMETHOD_CPU) {
1126 psn = (
float*)nn->vector.p;
1127 node->_origNorms = realloc(node->_origNorms, nsn * 3 *
sizeof(
float));
1128 memcpy(node->_origNorms, psn, nsn * 3 *
sizeof(
float));
1131 if (!node->skeleton.n && node->joints.n) {
1133 for (
int i = 0; i < node->joints.n; i++) {
1135 char* name = joint->name->strptr;
1136 if (name && !strcmp(name,
"humanoid_root") || !strcmp(name,
"root") || !strcmp(name,
"humanoidroot")){
1138 node->skeleton.p = malloc(
sizeof(
void*));
1139 node->skeleton.n = 1;
1140 node->skeleton.p[0] = X3D_NODE(joint);
1148 if (hr->NV == 0 || hr->NV != nsc) {
1149 hr->PVI = realloc(hr->PVI, nsc * 4 *
sizeof(
int));
1150 hr->PVW = realloc(hr->PVW, nsc * 4 *
sizeof(
float));
1155 if (hr->JT == NULL) {
1164void rwhat_printf(
int rwhat);
1171 ppComponent_HAnim p = (ppComponent_HAnim)gglobal()->Component_HAnim.prv;
1172 COMPILE_IF_REQUIRED;
1187 nc = node->joints.n + node->segments.n + node->viewpoints.n + node->sites.n +
1188 node->skeleton.n + node->skin.n;
1190 RETURN_FROM_CHILD_IF_NOT_FOR_ME;
1193 push_humanoid(node);
1195 if(renderstate()->render_vp){
1197 normalChildren(node->viewpoints);
1201 if(node->motions.n){
1203 for(
int i=0;i<node->motions.n;i++){
1205 int keep = node->motionsEnabled.p[i];
1206 HM->transitionWeight = 1.0f;
1207 if (HM->transitionStart == 0.0) HM->transitionStart = TickTime() - node->transitionTime;
1208 if (node->transitionTime > 0.0) {
1209 if (node->motionsEnabled.p[i] != node->_lastMotionsEnabled.p[i]) {
1210 HM->transitionStart = TickTime();
1212 double dtime = TickTime() - HM->transitionStart;
1213 float weight = dtime / node->transitionTime;
1215 weight = min(1.0f, weight);
1216 if (node->motionsEnabled.p[i])
1217 HM->transitionWeight = weight;
1218 else HM->transitionWeight = 1.0f - weight;
1219 if (HM->transitionWeight > 0.0f) keep = TRUE;
1220 node->_lastMotionsEnabled.p[i] = node->motionsEnabled.p[i];
1225 render_node(X3D_NODE(node->motions.p[i]));
1237 if(0) normalChildren(node->segments);
1243 if(0) normalChildren(node->joints);
1251 if(0) normalChildren(node->sites);
1253 prep_sibAffectors((
struct X3D_Node*)node,&node->__sibAffectors);
1255 prep_BBox((
struct BBoxFields*)&node->bboxCenter);
1262 memset(hr->PVI,0,4*hr->NV*
sizeof(
int));
1263 memset(hr->PVW,0,4*hr->NV*
sizeof(
float));
1270 double modelviewMatrix[16];
1271 FW_GL_GETDOUBLEV(GL_MODELVIEW_MATRIX, modelviewMatrix);
1272 matinverseAFFINE(p->HHMatrix,modelviewMatrix);
1275 if(vertexTransformMethod() == VERTEXTRANSFORMMETHOD_CPU) {
1279 int nsc = 0, nsn = 0;
1280 float *psc = NULL, *psn = NULL;
1281 if(node->skinCoord && node->skinCoord->_nodeType == NODE_Coordinate){
1285 psc = (
float*)nc->point.p;
1286 memcpy(psc,node->_origCoords,3*nsc*
sizeof(
float));
1289 psn = (
float *)nn->vector.p;
1290 memcpy(psn,node->_origNorms,3*nsn*
sizeof(
float));
1294 else if (vertexTransformMethod() == VERTEXTRANSFORMMETHOD_GPU) {
1299 hr->displace = malloc(hr->ND * 4 *
sizeof(
float));
1300 hr->dindex_done = TRUE;
1301 memset(hr->displace, 0, hr->ND * 4 *
sizeof(
float));
1307 float zerocenter[3];
1309 if (node->skeleton.n && !node->joints.n) {
1311 hr->make_joint_list = TRUE;
1314 if(1) normalChildren(node->skeleton);
1315 if (hr->make_joint_list) {
1316 printf(
"joint names [");
1317 for (
int j = 0; j < node->joints.n; j++) {
1319 printf(
"%s ", jnode->name->strptr);
1322 hr->make_joint_list = FALSE;
1326 int renderpass = (renderstate()->render_geom || renderstate()->render_other) && !renderstate()->render_sensitive;
1330 if (vertexTransformMethod() == VERTEXTRANSFORMMETHOD_CPU) {
1335 float* psc = NULL, * psn = NULL;
1336 if (node->skinCoord && node->skinCoord->_nodeType == NODE_Coordinate) {
1341 psc = (
float*)nc->point.p[0].c;
1345 psn = (
float*)nn->vector.p;
1349 for (i = 0; i < nsc; i++) {
1351 float* point, * norm;
1352 float newpoint[3], newnorm[3];
1356 point = &psc[i * 3];
1358 if (nn) norm = &psn[i * 3];
1362 memset(newpoint, 0, 3 *
sizeof(
float));
1363 memset(newnorm, 0, 3 *
sizeof(
float));
1365 for (j = 0; j < 4; j++) {
1366 int jointTransformIndex = PVI[i * 4 + j];
1367 float wt = PVW[i * 4 + j];
1368 if (jointTransformIndex > 0) {
1369 float tpoint[3], tnorm[3];
1371 jointMatrix = vector_get(
JMATRIX, hr->JT, jointTransformIndex - 1);
1372 transformf(tpoint, point, jointMatrix.mat);
1373 vecscale3f(tpoint, tpoint, wt);
1374 vecadd3f(newpoint, newpoint, tpoint);
1376 transform3x3f(tnorm, norm, jointMatrix.normat);
1377 vecnormalize3f(tnorm, tnorm);
1378 vecscale3f(tnorm, tnorm, wt);
1379 vecadd3f(newnorm, newnorm, tnorm);
1384 if (totalWeight > 0.0f) {
1385 vecscale3f(newpoint, newpoint, 1.0f / totalWeight);
1386 veccopy3f(point, newpoint);
1388 vecscale3f(newnorm, newnorm, 1.0f / totalWeight);
1389 vecnormalize3f(norm, newnorm);
1395 float* osc = node->_origCoords;
1396 for (i = 0; i < nsc; i++) {
1398 for (j = 0; j < 3; j++) printf(
"%f ", psc[i * 3 + j]);
1400 for (j = 0; j < 3; j++) printf(
"%f ", osc[i * 3 + j]);
1412 node->skinCoord->_change++;
1413 parents = node->skinCoord->_parentVector;
1414 for (k = 0; k < vectorSize(parents); k++) {
1424 else if (vertexTransformMethod() == VERTEXTRANSFORMMETHOD_GPU) {
1425 if (renderstate()->render_blend || renderstate()->render_geom) {
1427 if (node->skinCoord && node->skinCoord->_nodeType == NODE_Coordinate) {
1428 push_humanoid_skinCoord(node->skinCoord);
1433 if ((hr->joint_changed == TRUE) && hr->PVset) {
1434 hr->joint_changed = FALSE;
1438 static int pvwonce = 1;
1440 for (
int kk = 0; kk < hr->NV; kk++)
1443 for (
int jj = 0; jj < 4; jj++) {
1444 printf(
"%f ", hr->PVW[kk * 4 + jj]);
1450 if (hr->bo_PVW == 0) {
1451 PRINT_GL_ERROR_IF_ANY(
"Hanim SSBO 0");
1452 glGenBuffers(1, &hr->bo_PVW);
1454 glBindBuffer(GL_SHADER_STORAGE_BUFFER, hr->bo_PVW);
1455 PRINT_GL_ERROR_IF_ANY(
"Hanim SSBO 1");
1456 glBufferData(GL_SHADER_STORAGE_BUFFER, hr->NV *
sizeof(
float) * 4, hr->PVW, GL_STATIC_DRAW);
1457 PRINT_GL_ERROR_IF_ANY(
"Hanim SSBO 2");
1459 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 10, hr->bo_PVW);
1460 PRINT_GL_ERROR_IF_ANY(
"Hanim SSBO 3");
1462 glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
1463 PRINT_GL_ERROR_IF_ANY(
"Hanim SSBO 4");
1467 static int pvionce = 1;
1469 for (
int kk = 0; kk < hr->NV; kk++)
1472 for (
int jj = 0; jj < 4; jj++) {
1473 printf(
"%d ", hr->PVI[kk * 4 + jj]);
1479 if (hr->bo_PVI == 0)
1480 glGenBuffers(1, &hr->bo_PVI);
1481 glBindBuffer(GL_SHADER_STORAGE_BUFFER, hr->bo_PVI);
1482 PRINT_GL_ERROR_IF_ANY(
"Hanim SSBO 5");
1483 glBufferData(GL_SHADER_STORAGE_BUFFER, hr->NV *
sizeof(
int) * 4, hr->PVI, GL_STATIC_DRAW);
1484 PRINT_GL_ERROR_IF_ANY(
"Hanim SSBO 6");
1485 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 11, hr->bo_PVI);
1486 PRINT_GL_ERROR_IF_ANY(
"Hanim SSBO 7");
1487 glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
1488 PRINT_GL_ERROR_IF_ANY(
"Hanim SSBO 8");
1492 static int dionce = 0;
1494 for (
int kk = 0; kk < hr->NV; kk++)
1496 if (hr->dindex[kk]) {
1497 printf(
"[%d %d]\n", kk, hr->dindex[kk]);
1503 if (hr->bo_dindex == 0)
1504 glGenBuffers(1, &hr->bo_dindex);
1505 glBindBuffer(GL_SHADER_STORAGE_BUFFER, hr->bo_dindex);
1506 PRINT_GL_ERROR_IF_ANY(
"Hanim SSBO 9");
1507 glBufferData(GL_SHADER_STORAGE_BUFFER, hr->NV *
sizeof(
int), hr->dindex, GL_STATIC_DRAW);
1508 PRINT_GL_ERROR_IF_ANY(
"Hanim SSBO 10");
1509 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 14, hr->bo_dindex);
1510 PRINT_GL_ERROR_IF_ANY(
"Hanim SSBO 11");
1511 glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
1512 PRINT_GL_ERROR_IF_ANY(
"Hanim SSBO 12");
1516 if (hr->ND && hr->displace) {
1519 if (!hr->bo_displace) {
1520 PRINT_GL_ERROR_IF_ANY(
"Hanim ND_SSBO 0");
1521 glGenBuffers(1, &hr->bo_displace);
1522 glBindBuffer(GL_SHADER_STORAGE_BUFFER, hr->bo_displace);
1523 PRINT_GL_ERROR_IF_ANY(
"Hanim ND_SSBO 13");
1524 glBufferData(GL_SHADER_STORAGE_BUFFER, hr->ND * 4 *
sizeof(
float), NULL, GL_DYNAMIC_DRAW);
1525 PRINT_GL_ERROR_IF_ANY(
"Hanim ND_SSBO 14");
1526 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 15, hr->bo_displace);
1527 PRINT_GL_ERROR_IF_ANY(
"Hanim ND_SSBO 15");
1530 glBindBuffer(GL_SHADER_STORAGE_BUFFER, hr->bo_displace);
1531 PRINT_GL_ERROR_IF_ANY(
"Hanim ND_SSBO 16");
1532 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 15, hr->bo_displace);
1533 PRINT_GL_ERROR_IF_ANY(
"Hanim ND_SSBO 17");
1535 static int donce = 1;
1537 printf(
"\nND %d\n", hr->ND);
1539 for (
int kk = 0; kk < hr->ND; kk++)
1541 float* v4 = &hr->displace[kk * 4];
1542 if (v4[0] == v4[1] == v4[2] == 0.0f) nz++;
1543 printf(
"[%d %f %f %f]\n", kk, v4[0], v4[1], v4[2]);
1546 printf(
"nz=%d ", nz - 1);
1549 rwhat_printf(renderstate()->rwhat);
1555 void* bdata = glMapBuffer(GL_SHADER_STORAGE_BUFFER, GL_WRITE_ONLY);
1556 PRINT_GL_ERROR_IF_ANY(
"Hanim ND_SSBO 18");
1557 memcpy(bdata, hr->displace, hr->ND * 4 *
sizeof(
float));
1558 glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
1559 PRINT_GL_ERROR_IF_ANY(
"Hanim ND_SSBO 18");
1560 glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
1564 if (vectorSize(hr->JT)) {
1570 int normatsize = 12;
1571 int nmat = vectorSize(hr->JT);
1572 if (hr->jt32 == NULL)
1573 hr->jt32 = malloc(nmat * 16 *
sizeof(
float));
1574 if (hr->jn32 == NULL) {
1575 hr->jn32 = malloc(nmat * normatsize *
sizeof(
float));
1576 memset(hr->jn32, 0, nmat * normatsize *
sizeof(
float));
1578 for (
int i = 0; i < nmat; i++) {
1580 double2float(&hr->jt32[i * 16], jm->mat, 16);
1584 for (
int k = 0; k < 3; k++)
1585 veccopy3f(&hr->jn32[i * normatsize + k * 4], &jm->normat[k * 3]);
1586 if (normatsize == 16) hr->jn32[i * normatsize + 15] = 1.0f;
1591 static int mat_once = 0;
1592 if (0 && mat_once == 30) {
1594 for (
int kk = 0; kk < nmat; kk++) {
1596 for (
int jj = 0; jj < 4; jj++) {
1597 for (
int ii = 0; ii < 4; ii++)
1598 printf(
"%f ", hr->jt32[(kk * nrow + jj) * 4 + ii]);
1606 PRINT_GL_ERROR_IF_ANY(
"Hanim JT_SSBO 0");
1607 glGenBuffers(1, &hr->bo_JT);
1608 glBindBuffer(GL_SHADER_STORAGE_BUFFER, hr->bo_JT);
1609 PRINT_GL_ERROR_IF_ANY(
"Hanim JT_SSBO 1");
1610 glBufferData(GL_SHADER_STORAGE_BUFFER, nmat * 16 *
sizeof(
float), NULL, GL_DYNAMIC_DRAW);
1611 PRINT_GL_ERROR_IF_ANY(
"Hanim JT_SSBO 2");
1612 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 12, hr->bo_JT);
1613 PRINT_GL_ERROR_IF_ANY(
"Hanim JT_SSBO 3");
1616 glBindBuffer(GL_SHADER_STORAGE_BUFFER, hr->bo_JT);
1617 PRINT_GL_ERROR_IF_ANY(
"Hanim JT_SSBO 4");
1618 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 12, hr->bo_JT);
1619 PRINT_GL_ERROR_IF_ANY(
"Hanim JT_SSBO 5");
1621 void* bdata = glMapBuffer(GL_SHADER_STORAGE_BUFFER, GL_WRITE_ONLY);
1622 PRINT_GL_ERROR_IF_ANY(
"Hanim JT_SSBO 6");
1623 memcpy(bdata, hr->jt32, nmat * 16 *
sizeof(
float));
1624 glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
1625 PRINT_GL_ERROR_IF_ANY(
"Hanim JT_SSBO 7");
1626 glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
1630 static int normat_once = 0;
1631 if (0 && normat_once == 30) {
1632 int nrow = normatsize == 12 ? 3 : 4;
1633 for (
int kk = 0; kk < nmat; kk++) {
1635 for (
int jj = 0; jj < 4; jj++) {
1636 for (
int ii = 0; ii < 4; ii++)
1637 printf(
"%f ", hr->jn32[(kk * nrow + jj) * 4 + ii]);
1644 PRINT_GL_ERROR_IF_ANY(
"Hanim JN_SSBO 0");
1645 glGenBuffers(1, &hr->bo_JN);
1646 glBindBuffer(GL_SHADER_STORAGE_BUFFER, hr->bo_JN);
1647 PRINT_GL_ERROR_IF_ANY(
"Hanim JN_SSBO 1");
1648 glBufferData(GL_SHADER_STORAGE_BUFFER, nmat * normatsize *
sizeof(
float), NULL, GL_DYNAMIC_DRAW);
1649 PRINT_GL_ERROR_IF_ANY(
"Hanim JN_SSBO 2");
1650 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 13, hr->bo_JN);
1651 PRINT_GL_ERROR_IF_ANY(
"Hanim JN_SSBO 3");
1654 glBindBuffer(GL_SHADER_STORAGE_BUFFER, hr->bo_JN);
1655 PRINT_GL_ERROR_IF_ANY(
"Hanim JN_SSBO 4");
1656 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 13, hr->bo_JN);
1657 PRINT_GL_ERROR_IF_ANY(
"Hanim JN_SSBO 5");
1659 void* bdata = glMapBuffer(GL_SHADER_STORAGE_BUFFER, GL_WRITE_ONLY);
1660 PRINT_GL_ERROR_IF_ANY(
"Hanim JN_SSBO 6");
1661 memcpy(bdata, hr->jn32, nmat * normatsize *
sizeof(
float));
1662 glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
1663 PRINT_GL_ERROR_IF_ANY(
"Hanim JN_SSBO 7");
1664 glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
1673 if(hr->render_count > 2) normalChildren(node->skin);
1674 if(0)
for (
int j = 0; j < node->skin.n; j++) {
1675 printf(
"skin[%d] extent: ", j);
1676 for (
int i = 0; i < 6; i++) printf(
"%4.3f ", node->skin.p[j]->_extent[i]);
1680 if (vertexTransformMethod() == VERTEXTRANSFORMMETHOD_GPU) {
1682 if (renderstate()->render_blend || renderstate()->render_geom) {
1684 if (node->skinCoord && node->skinCoord->_nodeType == NODE_Coordinate) {
1687 pop_humanoid_skinCoord();
1691 else if (vertexTransformMethod() == VERTEXTRANSFORMMETHOD_CPU) {
1698 psc = (
float*)nc->point.p;
1699 memcpy(psc, node->_origCoords, 3 * nsc *
sizeof(
float));
1702 psn = (
float*)nn->vector.p;
1703 memcpy(psn, node->_origNorms, 3 * nsn *
sizeof(
float));
1714 fin_sibAffectors((
struct X3D_Node*)node,&node->__sibAffectors);
1723void sendSkinningInfo() {
1727 PRINT_GL_ERROR_IF_ANY(
"Hanim SENd 0");
1732 glBindBuffer(GL_SHADER_STORAGE_BUFFER, hr->bo_JT);
1733 PRINT_GL_ERROR_IF_ANY(
"Hanim JT_SSBO SENd 3");
1734 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 12, hr->bo_JT);
1735 PRINT_GL_ERROR_IF_ANY(
"Hanim JT_SSBO SENd 4");
1737 glBindBuffer(GL_SHADER_STORAGE_BUFFER, hr->bo_JN);
1738 PRINT_GL_ERROR_IF_ANY(
"Hanim JN_SSBO SENd 5");
1739 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 13, hr->bo_JN);
1740 PRINT_GL_ERROR_IF_ANY(
"Hanim JN_SSBO SENd 6");
1746 glBindBuffer(GL_SHADER_STORAGE_BUFFER, hr->bo_PVW);
1747 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 10, hr->bo_PVW);
1750 glBindBuffer(GL_SHADER_STORAGE_BUFFER, hr->bo_PVI);
1751 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 11, hr->bo_PVI);
1754 if (hr->bo_dindex) {
1755 glBindBuffer(GL_SHADER_STORAGE_BUFFER, hr->bo_dindex);
1756 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 14, hr->bo_dindex);
1757 if (hr->bo_displace) {
1758 glBindBuffer(GL_SHADER_STORAGE_BUFFER, hr->bo_displace);
1759 PRINT_GL_ERROR_IF_ANY(
"Hanim ND_SSBO SENd 3");
1760 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 15, hr->bo_displace);
1761 PRINT_GL_ERROR_IF_ANY(
"Hanim ND_SSBO SENd 4");
1769void clearSkinningInfo() {
1774 PRINT_GL_ERROR_IF_ANY(
"Hanim CLEAR 0");
1775 glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
1776 PRINT_GL_ERROR_IF_ANY(
"Hanim SSBO CLEAR 1");
1794 prep_sibAffectors((
struct X3D_Node*)node,&node->__sibAffectors);
1795 prep_BBox((
struct BBoxFields*)&node->bboxCenter);
1797 push_joint_center(node->center.c);
1799 normalChildren(node->children);
1803 fin_sibAffectors((
struct X3D_Node*)node,&node->__sibAffectors);
1805float *vecmix3f(
float *out3,
float* a3,
float *b3,
float fraction){
1808 out3[i] = (1.0f - fraction)*a3[i] + fraction*b3[i];
1828 if(node->coord && node->displacers.n){
1834 psc = (
float*)nc->point.p;
1836 if(!node->_origCoords)
1837 node->_origCoords = malloc(3*nsc*
sizeof(
float));
1838 memcpy(node->_origCoords,psc,3*nsc*
sizeof(
float));
1839 for(i=0;i<node->displacers.n;i++){
1841 float *point, weight, wdisp[3];
1844 weight = dp->weight;
1846 pdp = (
float*)dp->displacements.p;
1849 ni = dp->coordIndex.n;
1850 ci = dp->coordIndex.p;
1853 point = &psc[index*3];
1854 vecscale3f(wdisp,&pdp[j*3],weight);
1855 vecadd3f(point,point,wdisp);
1862 node->coord->_change++;
1863 parents = node->coord->_parentVector;
1864 for(k=0;k<vectorSize(parents);k++){
1873 float myfind[9] = {-0.029100f, 1.603000f, 0.042740f, -0.045570f, 1.601000f, 0.036520f, -0.018560f, 1.600000f, 0.043490f };
1874 int j,found = FALSE;
1878 if(vecsametol3f(&psc[i*3],&myfind[j*3],.0001f)){
1879 printf(
"%d %f %f %f\n",i,myfind[j*3 + 0],myfind[j*3 +1],myfind[j*3 +2]);
1887 prep_sibAffectors((
struct X3D_Node*)node,&node->__sibAffectors);
1888 prep_BBox((
struct BBoxFields*)&node->bboxCenter);
1890 normalChildren(node->children);
1893 fin_sibAffectors((
struct X3D_Node*)node,&node->__sibAffectors);
1895 if(node->coord && node->displacers.n){
1899 psc = (
float*)nc->point.p;
1901 memcpy(psc,node->_origCoords,3*nsc*
sizeof(
float));
1914 prep_sibAffectors((
struct X3D_Node*)node,&node->__sibAffectors);
1915 prep_BBox((
struct BBoxFields*)&node->bboxCenter);
1918 normalChildren(node->children);
1921 fin_sibAffectors((
struct X3D_Node*)node,&node->__sibAffectors);
1926int char_is_separator(
char c,
char *separators){
1928 char *s = separators;
1931 is_sep = TRUE;
break;
1938static int next_token(
char const ** inp,
char *separators,
char const ** end )
1940 char const * pos = NULL;
1941 if(!(inp && end && *inp))
1943 assert( inp && end && *inp );
1944 if( *inp == *end )
return 0;
1951 for( ; *pos && ( char_is_separator(*pos,separators)); ++pos) { }
1953 for( ; *pos && ( !char_is_separator(*pos,separators)); ++pos) { }
1955 return (pos > *inp) ? 1 : 0;
1957Stack* parse_joint_names(
struct X3D_Node* node,
char *joint_names){
1958 char *sep =
" \n\r\t,";
1959 Stack* jnames = newStack(
char*);
1965 for(
int i=0;; ++i, beg=end, end=NULL )
1967 rc = next_token( &beg, sep, &end );
1969 assert( beg != end );
1970 assert( end > beg );
1972 len = (
unsigned int)(end - beg);
1973 char *name = malloc(len+1);
1974 register_node_gc(node,name);
1977 memcpy(name, beg, len );
1979 stack_push(
char*,jnames,name);
1993static struct chan_name {
1997{CHAN_RX,
"Xrotation"},
1998{CHAN_RY,
"Yrotation"},
1999{CHAN_RZ,
"Zrotation"},
2000{CHAN_TX,
"Xposition"},
2001{CHAN_TY,
"Yposition"},
2002{CHAN_TZ,
"Zposition"},
2005static int chan_lookup(
char *cname){
2007 struct chan_name *cn;
2011 cn = &chan_names[i];
2012 if(!strcmp(cn->cname,cname)){
2017 }
while(cn->cname != NULL);
2029char *channame_lookup(
int ichan){
2031 struct chan_name *cn;
2033 char * cname = NULL;
2035 cn = &chan_names[i];
2036 if(cn->iname == ichan){
2041 }
while(cn->iname != CHAN_NONE);
2044char *next_buffer_token(
char **beg,
char* sep,
char **end){
2045 static char buffer[128];
2048 rc = next_token( beg, sep, end );
2050 assert( *beg != *end );
2051 assert( *end > *beg );
2053 len = (
unsigned int)(*end - *beg);
2055 memcpy(buffer, *beg, len );
2060int parse_channels(
char *channelstring,
int nentries,
struct joint_frame_motion * chan){
2061 char *sep =
" \n\r\t,";
2063 int len, rc, count, totalcount;
2064 char *beg, *end, *token;
2066 beg = channelstring;
2068 for(
int i=0;i<nentries; ++i, beg=end, end=NULL )
2070 token = next_buffer_token( &beg, sep, &end );
2071 len = strlen(token);
2073 sscanf(token,
"%d",&count);
2074 totalcount += count;
2075 chan[i].nchan = count;
2076 for(
int j=0;j<count;j++){
2078 token = next_buffer_token( &beg, sep, &end );
2079 int ichan = chan_lookup(token);
2080 chan[i].ichan[j] = ichan;
2091float *parse_float_values(
int n,
char *str){
2092 char *beg, *end, *token;
2094 char *sep =
" \n\r\t,";
2095 float *fv = malloc(n*
sizeof(
float));
2098 for(
int i=0;i<n; ++i, beg=end, end=NULL )
2100 token = next_buffer_token( &beg, sep, &end );
2101 len = (
unsigned int)(*end - *beg);
2103 sscanf(token,
"%f",&fv[i]);
2123#define RADIANS_PER_DEGREE (double)0.0174532925199432957692
2124#define DEGREES_PER_RADIAN (double)57.2957795130823208768
2127 if (node->frameCount == 0) {
2129 struct Vector* jnames = parse_joint_names(X3D_NODE(node), node->joints->strptr);
2131 for (
int i = 0; i < jnames->n; i++)
2132 printf(
"%d %s\n", i, vector_get(
char*, jnames, i));
2133 int njoints = jnames->n;
2137 int channelcount = parse_channels(node->channels->strptr, njoints, chan);
2141 for (
int i = 0; i < njoints; i++) {
2142 chan[i].jname = vector_get(
char*, jnames, i);
2143 printf(
"joint %d nchan %d ", i, chan[i].nchan);
2144 for (
int j = 0; j < chan[i].nchan; j++) {
2145 printf(
"%s ", channame_lookup(chan[i].ichan[j]));
2151 float* fvalues = node->values.p;
2153 node->frameCount = node->values.n / channelcount;
2155 node->frameCount = 0;
2156 MARK_EVENT(X3D_NODE(node), offsetof(
struct X3D_HAnimMotion, frameCount));
2159 for (
int iframe = 0; iframe < node->frameCount; iframe++) {
2160 float* fv = &fvalues[iframe * channelcount];
2162 for (
int j = 0; j < njoints; j++) {
2164 for (
int k = 0; k < chan[j].nchan; k++) {
2165 if (chan[j].ichan[k] < 4)
2166 fv[kchan] *= RADIANS_PER_DEGREE;
2178 node->_njoints = njoints;
2179 node->_channelcount = channelcount;
2180 node->_fvalues = fvalues;
2181 node->_channels = chan;
2182 node->_framevalues = fvalues;
2184 if (node->endFrame == 0) node->endFrame = node->frameCount - 1;
2185 MARK_EVENT(X3D_NODE(node), offsetof(
struct X3D_HAnimMotion, frameCount));
2186 printf(
"frameCount %d startFrame %d endFrame %d channels %d\n",
2187 node->frameCount, node->startFrame, node->endFrame, node->_channelcount);
2195 float *fvalues = (
float*)node->_fvalues;
2196 int channelcount = (int)node->_channelcount;
2197 float *frame_values;
2198 int isActive = FALSE;
2200 int increment = node->frameIncrement;
2201 if(increment == 0)
return;
2202 index = node->frameIndex;
2203 int fcount = node->frameCount;
2204 index = max(0,min(index,fcount-1));
2208 isActive = node->enabled && ((node->loop && increment != 0) || (increment > 0 && index < fcount -1) || (increment < 0 && index > 0) );
2209 if(node->enabled && !node->_lastenabled){
2211 node->_lastenabled = node->enabled;
2212 }
else if(!node->enabled && node->_lastenabled){
2214 node->_lastenabled = node->enabled;
2217 node->_startTime = TickTime();
2222 index = index + increment;
2224 }
else if(node->previous){
2225 index = index - increment;
2226 node->previous = FALSE;
2227 }
else if(node->enabled){
2228 double dtime = TickTime() - node->_startTime;
2229 index = node->frameIncrement * (int)( dtime / node->frameDuration);
2231 int startingloop = 0;
2233 int lindex = index % fcount;
2234 startingloop = lindex != index;
2237 index = max(0,min(index,fcount-1));
2238 if(starting && index == fcount -1 && increment > 0) index = 0;
2239 if(starting && index == 0 && increment < 0) index = fcount -1;
2240 if(starting || startingloop ){
2241 node->cycleTime = TickTime();
2242 MARK_EVENT (X3D_NODE(node), offsetof(
struct X3D_HAnimMotion, cycleTime));
2245 node->elapsedTime = TickTime();
2246 MARK_EVENT (X3D_NODE(node), offsetof(
struct X3D_HAnimMotion, elapsedTime));
2248 int last_index = node->frameIndex;
2249 node->frameIndex = index;
2250 if (last_index != index)
2251 MARK_EVENT(X3D_NODE(node), offsetof(
struct X3D_HAnimMotion, frameIndex));
2252 frame_values = &fvalues[node->frameIndex * channelcount];
2253 node->_framevalues = frame_values;
2256 LOADER_INITIAL_STATE=0,
2257 LOADER_REQUEST_RESOURCE,
2258 LOADER_FETCHING_RESOURCE,
2268 if(node->_nodeType == NODE_HAnimMotion){
2272 int njoints = (int)HM->_njoints;
2274 float *frame_values = (
float*)HM->_framevalues;
2276 for(
int i=0;i<njoints;i++){
2277 if(!strcmp(chan[i].jname,jname)){
2280 jm->values = &frame_values[kchan];
2283 kchan += chan[i].nchan;
2286 }
else if(node->_nodeType == NODE_HAnimMotionPlay){
2289 if(HD->__loadstatus != LOADER_LOADED)
return jm;
2290 if(HM->enabled && HD){
2292 int njoints = (int)HD->_njoints;
2294 float *frame_values = (
float*)HM->_framevalues;
2295 if (!frame_values)
return NULL;
2297 char* kname = jname;
2298 if (HM->mapping.n) {
2303 for (
int k = 0; k < HM->mapping.n; k += 2) {
2304 char* sname = HM->mapping.p[k]->strptr;
2305 char* dname = HM->mapping.p[k + 1]->strptr;
2306 if (!strcmp(jname, sname)) {
2312 for(
int i=0;i<njoints;i++){
2313 if(!strcmp(chan[i].jname,kname)){
2317 jm->values = &frame_values[kchan];
2325 kchan += chan[i].nchan;
2332void update_displacerWeightFromMotion(
struct X3D_Node* HMnode,
char* jname,
float *weight) {
2333 if (HMnode && (HMnode->_nodeType == NODE_HAnimMotion || HMnode->_nodeType == NODE_HAnimMotionPlay)) {
2337 else if (HMnode && (HMnode->_nodeType == NODE_HAnimMotionInterpolator)) {
2339 struct Vector* jointnames = HMO->_jointnames;
2341 if (jointnames && vectorSize(jointnames)) {
2342 int n = vectorSize(jointnames);
2343 for (
int i = 0; i < n; i++) {
2344 char* hmoname = vector_get(
char*, jointnames, i);
2346 if (!strcmp(jname, hmoname) && strcmp(jname,
"IGNORE")) {
2348 if (i < HMO->children.n) {
2349 struct X3D_Node* inode = HMO->children.p[i];
2350 if (inode->_nodeType == NODE_ScalarInterpolator) {
2353 float wt = onode->value_changed;
2363void update_jointMatrixFromMotion(
struct X3D_Node* HMnode,
char* jname,
double* jmatrix0) {
2365 if (HM && (HM->_nodeType == NODE_HAnimMotion || HM->_nodeType == NODE_HAnimMotionPlay)) {
2366 float weight = HM->transitionWeight;
2369 debug = debug2 = FALSE;
2372 double mat1[16],jmatrix[16],xyz[3];
2373 if(debug) printf(
"in update_jointMatrix\n");
2374 if(debug) printmatrix(jmatrix0);
2375 matidentity4d(jmatrix);
2377 if (igl) glPushMatrix();
2378 if (igl) glLoadIdentity();
2380 printf(
"%s ",jname);
2382 for(
int ii=0;ii<jm->nchan;ii++){
2384 float value = jm->values[i] * weight;
2386 printf(
"%d %4.2f ",jm->ichan[i],value);
2390 matidentity4d(mat1);
2391 switch(jm->ichan[i]){
2393 matrixFromAxisAngle4d(mat1, -(
double)value, 1.0, 0.0,0.0);
2394 if (igl) glRotatef(value*DEGREES_PER_RADIAN, 1, 0, 0);
2395 if (debug2) printf(
"xr %f ", value*DEGREES_PER_RADIAN);
2396 if(ir) matmultiplyAFFINE(jmatrix,jmatrix, mat1);
2397 else matmultiplyAFFINE(jmatrix, mat1, jmatrix);
2399 printf(
"case 1 mat1\n");
2401 printf(
"case 1 jmatrix\n");
2402 printmatrix(jmatrix);
2406 matrixFromAxisAngle4d(mat1, -(
double)value, 0.0, 1.0, 0.0);
2407 if (igl) glRotatef(value * DEGREES_PER_RADIAN, 0, 1, 0);
2408 if (debug2) printf(
"yr %f ", value * DEGREES_PER_RADIAN);
2409 if (ir) matmultiplyAFFINE(jmatrix, jmatrix, mat1);
2410 else matmultiplyAFFINE(jmatrix, mat1, jmatrix);
2412 printf(
"case 2 mat1\n");
2414 printf(
"case 2 jmatrix\n");
2415 printmatrix(jmatrix);
2419 matrixFromAxisAngle4d(mat1, -(
double)value, 0.0, 0.0, 1.0);
2420 if (igl) glRotatef(value * DEGREES_PER_RADIAN, 0, 0, 1);
2421 if (debug2) printf(
"zr %f ", value * DEGREES_PER_RADIAN);
2422 if (ir) matmultiplyAFFINE(jmatrix, jmatrix, mat1);
2423 else matmultiplyAFFINE(jmatrix, mat1, jmatrix);
2425 printf(
"case 3 mat1\n");
2427 printf(
"case 3 jmatrix\n");
2428 printmatrix(jmatrix);
2432 mattranslate4d(mat1,vecsetd(xyz,(
double)value,0.0,0.0));
2433 if (igl) glTranslatef(value,0,0);
2434 if (ir) matmultiplyAFFINE(jmatrix, jmatrix, mat1);
2435 else matmultiplyAFFINE(jmatrix, mat1, jmatrix);
2437 printf(
"case 4 mat1\n");
2439 printf(
"case 4 jmatrix\n");
2440 printmatrix(jmatrix);
2444 mattranslate4d(mat1,vecsetd(xyz,0.0,(
double)value,0.0));
2445 if (igl) glTranslatef(0, value, 0);
2446 if (ir) matmultiplyAFFINE(jmatrix, jmatrix, mat1);
2447 else matmultiplyAFFINE(jmatrix, mat1, jmatrix);
2449 printf(
"case 5 mat1\n");
2451 printf(
"case 5 jmatrix\n");
2452 printmatrix(jmatrix);
2456 mattranslate4d(mat1,vecsetd(xyz,0.0,0.0,(
double)value));
2457 if (igl) glTranslatef(0, 0, value);
2458 if (ir) matmultiplyAFFINE(jmatrix, jmatrix, mat1);
2459 else matmultiplyAFFINE(jmatrix, mat1, jmatrix);
2461 printf(
"case 6 mat1\n");
2463 printf(
"case 6 jmatrix\n");
2464 printmatrix(jmatrix);
2468 if(debug) printf(
"OUCH DEFAULT\n");
2472 if (debug2)printf(
"\n");
2473 if(0)
if (jm->level == 1) {
2474 double toYup[] = {1,0,0,0, 0,0,-1,0, 0,1,0,0, 0,0,0,1};
2475 matmultiplyAFFINE(jmatrix, toYup, jmatrix);
2477 if(debug)
if (!strcmp(jm->jname,
"l_shoulder")) {
2479 glGetDoublev(GL_MODELVIEW_MATRIX, tmatrix);
2483 printf(
"opengl matrix multiply\n");
2484 printf(
"%lf %lf %lf %lf\n %lf %lf %lf %lf\n %lf %lf %lf %lf\n %lf %lf %lf %lf\n",
2485 tmatrix[0], tmatrix[1], tmatrix[2], tmatrix[3],
2486 tmatrix[4], tmatrix[5], tmatrix[6], tmatrix[7],
2487 tmatrix[8], tmatrix[9], tmatrix[10], tmatrix[11],
2488 tmatrix[12], tmatrix[13], tmatrix[14], tmatrix[15]);
2491 printf(
"fw matrix multiply\n");
2492 printf(
"%lf %lf %lf %lf\n %lf %lf %lf %lf\n %lf %lf %lf %lf\n %lf %lf %lf %lf\n",
2493 jmatrix[0], jmatrix[1], jmatrix[2], jmatrix[3],
2494 jmatrix[4], jmatrix[5], jmatrix[6], jmatrix[7],
2495 jmatrix[8], jmatrix[9], jmatrix[10], jmatrix[11],
2496 jmatrix[12], jmatrix[13], jmatrix[14], jmatrix[15]);
2498 if (igl) memcpy(jmatrix, tmatrix, 16 *
sizeof(
double));
2499 printf(
"fw matrix multiply\n");
2500 printf(
"%lf %lf %lf %lf\n %lf %lf %lf %lf\n %lf %lf %lf %lf\n %lf %lf %lf %lf\n",
2501 jmatrix[0], jmatrix[1], jmatrix[2], jmatrix[3],
2502 jmatrix[4], jmatrix[5], jmatrix[6], jmatrix[7],
2503 jmatrix[8], jmatrix[9], jmatrix[10], jmatrix[11],
2504 jmatrix[12], jmatrix[13], jmatrix[14], jmatrix[15]);
2509 matmultiplyAFFINE(jmatrix0,jmatrix,jmatrix0);
2510 if (igl) glPopMatrix();
2515 else if (HM && (HM->_nodeType == NODE_HAnimMotionInterpolator)) {
2518 struct Vector* jointnames = HMO->_jointnames;
2519 float weight = HMO->transitionWeight;
2521 if(jointnames && vectorSize(jointnames)){
2523 int n = vectorSize(jointnames);
2525 for (
int i = 0; i < n; i++) {
2526 char* hmoname = vector_get(
char*, jointnames, i);
2528 if (!strcmp(jname, hmoname) && strcmp(jname,
"IGNORE")) {
2530 if (i < HMO->children.n) {
2531 matidentity4d(mat1);
2533 struct X3D_Node* inode = HMO->children.p[i];
2534 if (inode->_nodeType == NODE_OrientationInterpolator) {
2537 struct SFRotation* sfr = &onode->value_changed;
2538 matrixFromAxisAngle4d(mat1, -sfr->c[3]*weight,sfr->c[0],sfr->c[1], sfr->c[2]);
2539 matmultiplyAFFINE(jmatrix0, mat1, jmatrix0);
2541 else if (inode->_nodeType == NODE_PositionInterpolator) {
2543 struct SFVec3f* sft = &pnode->value_changed;
2546 vecscale3f(wvec, sft->c, weight);
2547 float2double(dvec, wvec, 3);
2549 matidentity4d(mat1);
2550 mattranslate4d(mat1, dvec);
2551 matmultiplyAFFINE(jmatrix0, mat1, jmatrix0);
2571void bvh_set_mapping(
char** mapping,
int n);
2572void read_bvh_blob(
char *blob,
int ignorePosition,
int yUp,
int teePose,
2573 int flipZ,
float armAngle,
float legAngle,
float scale,
2575 float *bvh_frame_time,
int *bvh_frame_count);
2578 float bvh_frame_time;
2579 int bvh_frame_count;
2582 float *fvalues = NULL;
2585 if (node->mapping.n) {
2586 char** mapp = malloc(2 *
sizeof(
char*) * node->mapping.n);
2587 for (
int i = 0; i < node->mapping.n; i++)
2588 mapp[i] = node->mapping.p[i]->strptr;
2589 bvh_set_mapping(mapp, node->mapping.n / 2);
2592 bvh_set_mapping(NULL, 0);
2594 read_bvh_blob(blob, node->ignorePosition, node->yUp, node->teePose,
2595 node->flipZ, node->armAngle, node->legAngle, node->scale,
2596 &chan, &njoint, &channel_count, &fvalues, &bvh_frame_time,&bvh_frame_count);
2597 map_mocap_to_hanim_loa(chan,njoint,node->loa);
2598 node->frameCount = bvh_frame_count;
2600 node->frameDuration = bvh_frame_time;
2601 node->_njoints = njoint;
2602 node->_channels = chan;
2603 node->_channelcount = channel_count;
2604 node->_fvalues = fvalues;
2606void process_mocap(resource_item_t *res){
2609 of = res->openned_files;
2615 char *blob = of->fileData;
2616 int len = of->fileDataSize;
2620 printf(
"process mocap\n");
2621 read_bvh_blob_to_node(node,blob,len);
2622 res->complete = TRUE;
2623 res->status = ress_parsed;
2629 struct Vector *jnames = parse_joint_names(X3D_NODE(node),node->joints->strptr);
2631 for(
int i=0;i<jnames->n;i++)
2632 printf(
"%d %s\n",i,vector_get(
char*,jnames,i));
2633 int njoints = jnames->n;
2637 int channelcount = parse_channels(node->channels->strptr,njoints,chan);
2641 for(
int i=0;i<njoints;i++){
2642 chan[i].jname = vector_get(
char*,jnames,i);
2643 printf(
"joint %d nchan %d ",i, chan[i].nchan);
2644 for(
int j=0;j<chan[i].nchan;j++){
2645 printf(
"%s ",channame_lookup(chan[i].ichan[j]));
2651 float* fvalues = node->values.p;
2653 node->frameCount = node->values.n / channelcount;
2655 node->frameCount = 0;
2659 for(
int iframe=0;iframe<node->frameCount;iframe++){
2660 float *fv = &fvalues[iframe * channelcount];
2662 for(
int j=0;j<njoints;j++){
2664 for(
int k=0;k<chan[j].nchan;k++){
2665 if(chan[j].ichan[k] < 4)
2666 fv[kchan] *= RADIANS_PER_DEGREE;
2678 node->_njoints = njoints;
2679 node->_channelcount = channelcount;
2680 node->_fvalues = fvalues;
2681 node->_channels = chan;
2682 node->__loadstatus = LOADER_LOADED;
2700 resource_item_t *res;
2702 switch (node->__loadstatus) {
2703 case LOADER_INITIAL_STATE:
2705 if (node->url.n == 0) {
2706 node->__loadstatus = LOADER_STABLE;
2708 res = resource_create_multi(&(node->url));
2709 res->media_type = resm_mocap;
2710 node->__loadstatus = LOADER_REQUEST_RESOURCE;
2711 node->__loadResource = res;
2715 case LOADER_REQUEST_RESOURCE:
2716 res = node->__loadResource;
2717 resource_identify(node->_parentResource, res);
2720 res->actions = resa_download | resa_load;
2721 resitem_enqueue(ml_new(res));
2723 node->__loadstatus = LOADER_FETCHING_RESOURCE;
2726 case LOADER_FETCHING_RESOURCE:
2727 res = node->__loadResource;
2732 if (res->status == ress_loaded) {
2736 res->whereToPlaceData = X3D_NODE(node);
2738 res->actions = resa_process;
2739 node->__loadstatus = LOADER_PROCESSING;
2740 res->complete = FALSE;
2743 resitem_enqueue(ml_new(res));
2747 node->__loadstatus = LOADER_LOADED;
2748 res->complete = TRUE;
2751 }
else if ((res->status == ress_failed) || (res->status == ress_invalid)) {
2753 printf (
"resource failed to load\n");
2754 node->__loadstatus = LOADER_STABLE;
2759 case LOADER_PROCESSING:
2760 res = node->__loadResource;
2765 if (res->status == ress_parsed) {
2766 node->__loadstatus = LOADER_LOADED;
2768 node->__loadstatus = LOADER_STABLE;
2776 case LOADER_COMPILED:
2779 if(node->__loadstatus == LOADER_STABLE || node->__loadstatus == LOADER_LOADED)
2787 int is_file = node->url.n;
2790 resource_item_t *res;
2792 switch (node->__loadstatus) {
2793 case LOADER_INITIAL_STATE:
2795 if (node->url.n == 0) {
2796 node->__loadstatus = LOADER_STABLE;
2798 res = resource_create_multi(&(node->url));
2799 res->media_type = resm_mocap;
2800 node->__loadstatus = LOADER_REQUEST_RESOURCE;
2801 node->__loadResource = res;
2805 case LOADER_REQUEST_RESOURCE:
2806 res = node->__loadResource;
2807 resource_identify(node->_parentResource, res);
2810 res->actions = resa_download | resa_load;
2811 resitem_enqueue(ml_new(res));
2813 node->__loadstatus = LOADER_FETCHING_RESOURCE;
2816 case LOADER_FETCHING_RESOURCE:
2817 res = node->__loadResource;
2822 if (res->status == ress_loaded) {
2826 res->whereToPlaceData = X3D_NODE(node);
2828 res->actions = resa_process;
2829 node->__loadstatus = LOADER_PROCESSING;
2830 res->complete = FALSE;
2833 resitem_enqueue(ml_new(res));
2837 node->__loadstatus = LOADER_LOADED;
2838 res->complete = TRUE;
2841 }
else if ((res->status == ress_failed) || (res->status == ress_invalid)) {
2843 printf (
"resource failed to load\n");
2844 node->__loadstatus = LOADER_STABLE;
2849 case LOADER_PROCESSING:
2850 res = node->__loadResource;
2855 if (res->status == ress_parsed) {
2856 node->__loadstatus = LOADER_LOADED;
2858 node->__loadstatus = LOADER_STABLE;
2866 case LOADER_COMPILED:
2869 if(node->__loadstatus == LOADER_STABLE || node->__loadstatus == LOADER_LOADED)
2875 struct Vector *jnames = parse_joint_names(X3D_NODE(node),node->joints->strptr);
2877 for(
int i=0;i<jnames->n;i++)
2878 printf(
"%d %s\n",i,vector_get(
char*,jnames,i));
2879 int njoints = jnames->n;
2883 int channelcount = parse_channels(node->channels->strptr,njoints,chan);
2887 for(
int i=0;i<njoints;i++){
2888 chan[i].jname = vector_get(
char*,jnames,i);
2889 printf(
"joint %d nchan %d ",i, chan[i].nchan);
2890 for(
int j=0;j<chan[i].nchan;j++){
2891 printf(
"%s ",channame_lookup(chan[i].ichan[j]));
2897 float* fvalues = node->values.p;
2899 node->frameCount = node->values.n / channelcount;
2901 node->frameCount = 0;
2905 for(
int iframe=0;iframe<node->frameCount;iframe++){
2906 float *fv = &fvalues[iframe * channelcount];
2908 for(
int j=0;j<njoints;j++){
2910 for(
int k=0;k<chan[j].nchan;k++){
2911 if(chan[j].ichan[k] < 4)
2912 fv[kchan] *= RADIANS_PER_DEGREE;
2924 node->_njoints = njoints;
2925 node->_channelcount = channelcount;
2926 node->_fvalues = fvalues;
2927 node->_channels = chan;
2928 node->__loadstatus = LOADER_LOADED;
2942 if(node->data->_nodeType == NODE_HAnimMotionData || node->data->_nodeType == NODE_HAnimMotionDataFile || node->data->_nodeType == NODE_HAnimMotionClip){
2943 render_node(X3D_NODE(node->data));
2944 int fileclip = node->data->_nodeType == NODE_HAnimMotionClip && ((
struct X3D_HAnimMotionClip*)(node->data))->url.n > 0;
2945 if(node->data->_nodeType == NODE_HAnimMotionDataFile || fileclip){
2949 if (motiondatafile->__loadstatus != LOADER_LOADED)
return;
2962 if (data && data->_nodeType == NODE_HAnimMotionData || data->_nodeType == NODE_HAnimMotionDataFile || data->_nodeType == NODE_HAnimMotionClip) {
2963 render_node(X3D_NODE(data));
2964 if (data->__loadstatus != LOADER_LOADED)
return;
2965 int fileclip = data->_nodeType == NODE_HAnimMotionClip && ((
struct X3D_HAnimMotionClip*)(data))->url.n > 0;
2966 if (data->_nodeType == NODE_HAnimMotionDataFile || fileclip) {
2968 play->startFrame = motiondatafile->ignoreFirstFrame ? 1 : 0;
2969 play->endFrame = motiondatafile->frameCount - 1;
2974 play->startFrame = 0;
2975 play->endFrame = data->frameCount - 1;
2984 if(motiondata && motiondata->_nodeType == NODE_HAnimMotionData || motiondata->_nodeType == NODE_HAnimMotionDataFile || motiondata->_nodeType == NODE_HAnimMotionClip ){
2985 render_node(X3D_NODE(motiondata));
2986 if(motiondata->__loadstatus != LOADER_LOADED)
return;
2988 updateMotionPlayFromData(node, motiondata);
2990 float *fvalues = (
float*)motiondata->_fvalues;
2991 int channelcount = (int)motiondata->_channelcount;
2992 float *frame_values;
2993 int isActive = FALSE;
2995 int increment = node->frameIncrement;
2997 index = node->frameIndex;
2998 int fcount = node->endFrame - node->startFrame + 1;
2999 index = max(0,min(index,node->endFrame));
3003 isActive = node->enabled && ((node->loop && increment != 0) || (increment > 0 && index < node->endFrame) || (increment < 0 && index > 0) );
3004 if(node->enabled && !node->_lastenabled){
3006 node->_lastenabled = node->enabled;
3007 }
else if(!node->enabled && node->_lastenabled){
3009 node->_lastenabled = node->enabled;
3012 node->_startTime = TickTime();
3019 }
else if(node->previous){
3021 node->previous = FALSE;
3022 }
else if(node->enabled && increment){
3023 double dtime = TickTime() - node->_startTime;
3024 index = node->frameIncrement * (int)( dtime / motiondata->frameDuration);
3026 int startingloop = 0;
3028 int lindex = ((index - node->startFrame) % fcount) + node->startFrame;
3029 startingloop = lindex != index;
3032 index = max(0,min(index,node->endFrame));
3033 if (increment) index = max(index, node->startFrame);
3034 if(starting && index == node->endFrame && increment > 0) index = node->startFrame;
3035 if(starting && index <= node->startFrame && increment < 0) index = node->endFrame;
3036 if(starting || startingloop ){
3037 node->cycleTime = TickTime();
3038 MARK_EVENT (X3D_NODE(node), offsetof(
struct X3D_HAnimMotion, cycleTime));
3041 node->elapsedTime = TickTime();
3042 MARK_EVENT (X3D_NODE(node), offsetof(
struct X3D_HAnimMotion, elapsedTime));
3044 int last_index = node->frameIndex;
3045 node->frameIndex = index;
3046 if(last_index != index)
3048 frame_values = &fvalues[node->frameIndex * channelcount];
3049 node->_framevalues = frame_values;
3054 if (node->compute) {
3059 unsigned int permutation;
3060 int HHindex, HMindex, np;
3062 HHn = node->humanoids.n;
3063 HMn = node->motions.n;
3065 FREE_IF_NZ(node->permutations.p);
3066 node->permutations.p = malloc((HHn*HMn+2) *
sizeof(
int));
3067 for (
int i = 0; i < HHn; i++) {
3068 for (
int j = 1; j < HMn; j++) {
3069 node->permutations.p[np] = i * 1000 + j;
3073 node->permutations.n = np;
3082 int permutation = node->permutations.p[node->index];
3083 int HHindex = permutation / 1000;
3084 int HMindex = permutation - (HHindex*1000);
3086 if (HH->motions.n == 0) {
3088 HH->motions.p = malloc(2 *
sizeof(
void*));
3091 if (node->_play.n == 0) {
3093 node->_play.p = malloc(2 *
sizeof(
void*));
3094 HMP0 = createNewX3DNode(NODE_HAnimMotionPlay);
3095 HMP1 = createNewX3DNode(NODE_HAnimMotionPlay);
3096 node->_play.p[0] = X3D_NODE(HMP0);
3097 node->_play.p[1] = X3D_NODE(HMP1);
3101 HMP0->enabled = TRUE;
3102 HMP1->enabled = TRUE;
3105 HMP0->frameIncrement = 1;
3106 HMP1->frameIncrement = 1;
3107 HMP0->frameIndex = 1;
3108 HMP1->frameIndex = 1;
3110 if (HM->_nodeType == NODE_HAnimMotionData || HM->_nodeType == NODE_HAnimMotionDataFile) {
3113 HMP->data = X3D_NODE(HM);
3116 HH->motions.p[1] = X3D_NODE(HM);
3119 if (HMS->_nodeType == NODE_HAnimMotionData || HMS->_nodeType == NODE_HAnimMotionDataFile) {
3121 HMP->data = X3D_NODE(HMS);
3124 HH->motions.p[0] = X3D_NODE(HMS);
3125 node->humanoid = X3D_NODE(HH);
3131 struct Vector* jnames = parse_joint_names(X3D_NODE(node), node->joints->strptr);
3132 node->_jointnames = jnames;
3143void delete_HanimRep(
void* _hanimrep) {
3148 deleteStack(
struct JMATRIX*, hanimrep->JT);
3150 FREE_IF_NZ(hanimrep->PVI);
3151 FREE_IF_NZ(hanimrep->PVW);
3152 if (hanimrep->bo_JT) glInvalidateBufferData(hanimrep->bo_JT);
3153 FREE_IF_NZ(_hanimrep);