DP_QC_GETTAGINFO_BONEPROPERTIES
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 17 Feb 2009 09:26:40 +0000 (09:26 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 17 Feb 2009 09:26:40 +0000 (09:26 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8716 d7cf8633-e32d-0410-b094-e92efae38249

clvm_cmds.c
model_alias.c
model_shared.h
progsvm.h
prvm_edict.c
svvm_cmds.c

index fd0af20..813437c 100644 (file)
@@ -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)
        {
index ca40d93..3f6efa5 100644 (file)
@@ -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;
index 794e3e8..aca3501 100644 (file)
@@ -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);
index c4ace92..1f459d4 100644 (file)
--- 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;
 
index 0199f24..72b9c3e 100644 (file)
@@ -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");
index 42173ca..107c42b 100644 (file)
@@ -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)
        {