From: divverent Date: Tue, 17 Feb 2009 09:26:40 +0000 (+0000) Subject: DP_QC_GETTAGINFO_BONEPROPERTIES X-Git-Tag: xonotic-v0.1.0preview~1878 X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=commitdiff_plain;h=cf128c9b9699145be0cb515a5e91e0b95b45b42f DP_QC_GETTAGINFO_BONEPROPERTIES git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8716 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/clvm_cmds.c b/clvm_cmds.c index fd0af207..813437c1 100644 --- a/clvm_cmds.c +++ b/clvm_cmds.c @@ -2165,6 +2165,35 @@ void VM_CL_setattachment (void) ///////////////////////////////////////// // DP_MD3_TAGINFO extension coded by VorteX +int CL_GetExtendedTagInfo (prvm_edict_t *e, int tagindex, int *parentindex, const char **tagname, matrix4x4_t *tag_localmatrix) +{ + int r; + dp_model_t *model; + int frame; + + *tagname = NULL; + *parentindex = 0; + Matrix4x4_CreateIdentity(tag_localmatrix); + + if (tagindex >= 0 + && (model = CL_GetModelFromEdict(e)) + && model->animscenes) + { + frame = (int)e->fields.client->frame; + if (frame < 0 || frame >= model->numframes) + frame = 0; + + r = Mod_Alias_GetExtendedTagInfoForIndex(model, (int)e->fields.client->skin, model->animscenes[frame].firstframe, tagindex - 1, parentindex, tagname, tag_localmatrix); + + if(!r) // success? + *parentindex += 1; + + return r; + } + + return 1; +} + int CL_GetTagIndex (prvm_edict_t *e, const char *tagname) { dp_model_t *model = CL_GetModelFromEdict(e); @@ -2272,7 +2301,12 @@ void VM_CL_gettaginfo (void) prvm_edict_t *e; int tagindex; matrix4x4_t tag_matrix; + matrix4x4_t tag_localmatrix; + int parentindex; + const char *tagname; int returncode; + prvm_eval_t *val; + vec3_t fo, ri, up, trans; VM_SAFEPARMCOUNT(2, VM_CL_gettaginfo); @@ -2280,6 +2314,21 @@ void VM_CL_gettaginfo (void) tagindex = (int)PRVM_G_FLOAT(OFS_PARM1); returncode = CL_GetTagMatrix(&tag_matrix, e, tagindex); Matrix4x4_ToVectors(&tag_matrix, prog->globals.client->v_forward, prog->globals.client->v_right, prog->globals.client->v_up, PRVM_G_VECTOR(OFS_RETURN)); + CL_GetExtendedTagInfo(e, tagindex, &parentindex, &tagname, &tag_localmatrix); + Matrix4x4_ToVectors(&tag_localmatrix, fo, ri, up, trans); + + if((val = PRVM_GLOBALFIELDVALUE(prog->globaloffsets.gettaginfo_parent))) + val->_float = parentindex; + if((val = PRVM_GLOBALFIELDVALUE(prog->globaloffsets.gettaginfo_name))) + val->string = tagname ? PRVM_SetTempString(tagname) : 0; + if((val = PRVM_GLOBALFIELDVALUE(prog->globaloffsets.gettaginfo_offset))) + VectorCopy(trans, val->vector); + if((val = PRVM_GLOBALFIELDVALUE(prog->globaloffsets.gettaginfo_forward))) + VectorCopy(fo, val->vector); + if((val = PRVM_GLOBALFIELDVALUE(prog->globaloffsets.gettaginfo_right))) + VectorCopy(ri, val->vector); + if((val = PRVM_GLOBALFIELDVALUE(prog->globaloffsets.gettaginfo_up))) + VectorCopy(up, val->vector); switch(returncode) { diff --git a/model_alias.c b/model_alias.c index ca40d93c..3f6efa5b 100644 --- a/model_alias.c +++ b/model_alias.c @@ -443,6 +443,41 @@ int Mod_Alias_GetTagMatrix(const dp_model_t *model, int poseframe, int tagindex, return 0; } +int Mod_Alias_GetExtendedTagInfoForIndex(const dp_model_t *model, unsigned int skin, int poseframe, int tagindex, int *parentindex, const char **tagname, matrix4x4_t *tag_localmatrix) +{ + const float *boneframe; + + if(skin >= (unsigned int)model->numskins) + skin = 0; + + if (model->num_bones) + { + if(tagindex >= model->num_bones || tagindex < 0) + return 1; + if (poseframe >= model->num_poses) + return 2; + + boneframe = model->data_poses + poseframe * model->num_bones * 12; + *parentindex = model->data_bones[tagindex].parent; + *tagname = model->data_bones[tagindex].name; + Matrix4x4_FromArray12FloatD3D(tag_localmatrix, boneframe + tagindex * 12); + return 0; + } + + if (model->num_tags) + { + if(tagindex >= model->num_tags || tagindex < 0) + return 1; + if (poseframe >= model->num_tagframes) + return 2; + *tagname = model->data_tags[tagindex].name; + Matrix4x4_FromArray12FloatGL(tag_localmatrix, model->data_tags[poseframe * model->num_tags + tagindex].matrixgl); + return 0; + } + + return 2; +} + int Mod_Alias_GetTagIndexForName(const dp_model_t *model, unsigned int skin, const char *tagname) { int i; diff --git a/model_shared.h b/model_shared.h index 794e3e83..aca35010 100644 --- a/model_shared.h +++ b/model_shared.h @@ -988,6 +988,7 @@ struct frameblend_s; void Mod_AliasInit(void); int Mod_Alias_GetTagMatrix(const dp_model_t *model, int poseframe, int tagindex, matrix4x4_t *outmatrix); int Mod_Alias_GetTagIndexForName(const dp_model_t *model, unsigned int skin, const char *tagname); +int Mod_Alias_GetExtendedTagInfoForIndex(const dp_model_t *model, unsigned int skin, int poseframe, int tagindex, int *parentindex, const char **tagname, matrix4x4_t *tag_localmatrix); // sprite models void Mod_SpriteInit(void); diff --git a/progsvm.h b/progsvm.h index c4ace926..1f459d43 100644 --- a/progsvm.h +++ b/progsvm.h @@ -261,6 +261,12 @@ typedef struct prvm_prog_globaloffsets_s int servertime; // csqc int serverprevtime; // csqc int serverdeltatime; // csqc + int gettaginfo_name; // ssqc / csqc + int gettaginfo_parent; // ssqc / csqc + int gettaginfo_offset; // ssqc / csqc + int gettaginfo_forward; // ssqc / csqc + int gettaginfo_right; // ssqc / csqc + int gettaginfo_up; // ssqc / csqc } prvm_prog_globaloffsets_t; diff --git a/prvm_edict.c b/prvm_edict.c index 0199f24e..72b9c3e2 100644 --- a/prvm_edict.c +++ b/prvm_edict.c @@ -1557,6 +1557,12 @@ void PRVM_FindOffsets(void) prog->globaloffsets.servertime = PRVM_ED_FindGlobalOffset("servertime"); prog->globaloffsets.serverprevtime = PRVM_ED_FindGlobalOffset("serverprevtime"); prog->globaloffsets.serverdeltatime = PRVM_ED_FindGlobalOffset("serverdeltatime"); + prog->globaloffsets.gettaginfo_name = PRVM_ED_FindGlobalOffset("gettaginfo_name"); + prog->globaloffsets.gettaginfo_parent = PRVM_ED_FindGlobalOffset("gettaginfo_parent"); + prog->globaloffsets.gettaginfo_offset = PRVM_ED_FindGlobalOffset("gettaginfo_offset"); + prog->globaloffsets.gettaginfo_forward = PRVM_ED_FindGlobalOffset("gettaginfo_forward"); + prog->globaloffsets.gettaginfo_right = PRVM_ED_FindGlobalOffset("gettaginfo_right"); + prog->globaloffsets.gettaginfo_up = PRVM_ED_FindGlobalOffset("gettaginfo_up"); // menu qc only uses some functions, nothing else prog->funcoffsets.m_draw = PRVM_ED_FindFunctionOffset("m_draw"); diff --git a/svvm_cmds.c b/svvm_cmds.c index 42173caf..107c42b1 100644 --- a/svvm_cmds.c +++ b/svvm_cmds.c @@ -78,6 +78,7 @@ char *vm_sv_extensions = "DP_QC_GETSURFACE " "DP_QC_GETSURFACEPOINTATTRIBUTE " "DP_QC_GETTAGINFO " +"DP_QC_GETTAGINFO_BONEPROPERTIES " "DP_QC_MINMAXBOUND " "DP_QC_MULTIPLETEMPSTRINGS " "DP_QC_NUM_FOR_EDICT " @@ -2493,7 +2494,38 @@ int SV_GetTagIndex (prvm_edict_t *e, const char *tagname) model = sv.models[i]; return Mod_Alias_GetTagIndexForName(model, (int)e->fields.server->skin, tagname); -}; +} + +int SV_GetExtendedTagInfo (prvm_edict_t *e, int tagindex, int *parentindex, const char **tagname, matrix4x4_t *tag_localmatrix) +{ + int r; + dp_model_t *model; + int frame; + int modelindex; + + *tagname = NULL; + *parentindex = 0; + Matrix4x4_CreateIdentity(tag_localmatrix); + + if (tagindex >= 0 + && (modelindex = (int)e->fields.server->modelindex) >= 1 && modelindex < MAX_MODELS + && (model = sv.models[(int)e->fields.server->modelindex]) + && model->animscenes) + { + frame = (int)e->fields.server->frame; + if (frame < 0 || frame >= model->numframes) + frame = 0; + + r = Mod_Alias_GetExtendedTagInfoForIndex(model, (int)e->fields.server->skin, model->animscenes[frame].firstframe, tagindex - 1, parentindex, tagname, tag_localmatrix); + + if(!r) // success? + *parentindex += 1; + + return r; + } + + return 1; +} void SV_GetEntityMatrix (prvm_edict_t *ent, matrix4x4_t *out, qboolean viewmatrix) { @@ -2662,7 +2694,12 @@ static void VM_SV_gettaginfo (void) prvm_edict_t *e; int tagindex; matrix4x4_t tag_matrix; + matrix4x4_t tag_localmatrix; + int parentindex; + const char *tagname; int returncode; + prvm_eval_t *val; + vec3_t fo, ri, up, trans; VM_SAFEPARMCOUNT(2, VM_SV_gettaginfo); @@ -2671,6 +2708,21 @@ static void VM_SV_gettaginfo (void) returncode = SV_GetTagMatrix(&tag_matrix, e, tagindex); Matrix4x4_ToVectors(&tag_matrix, prog->globals.server->v_forward, prog->globals.server->v_right, prog->globals.server->v_up, PRVM_G_VECTOR(OFS_RETURN)); + SV_GetExtendedTagInfo(e, tagindex, &parentindex, &tagname, &tag_localmatrix); + Matrix4x4_ToVectors(&tag_localmatrix, fo, ri, up, trans); + + if((val = PRVM_GLOBALFIELDVALUE(prog->globaloffsets.gettaginfo_parent))) + val->_float = parentindex; + if((val = PRVM_GLOBALFIELDVALUE(prog->globaloffsets.gettaginfo_name))) + val->string = tagname ? PRVM_SetTempString(tagname) : 0; + if((val = PRVM_GLOBALFIELDVALUE(prog->globaloffsets.gettaginfo_offset))) + VectorCopy(trans, val->vector); + if((val = PRVM_GLOBALFIELDVALUE(prog->globaloffsets.gettaginfo_forward))) + VectorCopy(fo, val->vector); + if((val = PRVM_GLOBALFIELDVALUE(prog->globaloffsets.gettaginfo_right))) + VectorCopy(ri, val->vector); + if((val = PRVM_GLOBALFIELDVALUE(prog->globaloffsets.gettaginfo_up))) + VectorCopy(up, val->vector); switch(returncode) {