zym models are now loaded into the same structs as alias models in memory, this reduc...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 3 Sep 2004 14:14:44 +0000 (14:14 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 3 Sep 2004 14:14:44 +0000 (14:14 +0000)
zym models are now optimized when loading to eliminate duplicate vertex data (one of their more significant design flaws)
mdl/md2/md3 models no longer have stored svector/tvector/normal arrays, instead generating them on demand like skeletal models (this is slower but saves a *lot* of memory)
zym collisions are not implemented (yet)
zym bones are not reported as tags (yet)

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@4429 d7cf8633-e32d-0410-b094-e92efae38249

cl_main.c
gl_models.c
model_alias.c
model_alias.h
model_shared.c
model_shared.h
pr_cmds.c
prvm_cmds.c
render.h

index 75e5d57..547937a 100644 (file)
--- a/cl_main.c
+++ b/cl_main.c
@@ -535,6 +535,7 @@ void CL_LinkNetworkEntity(entity_t *e)
                        // make relative to the entity
                        matrix = &t->render.matrix;
                        // if a valid tagindex is used, make it relative to that tag instead
+                       // FIXME: use a model function to get tag info (need to handle skeletal)
                        if (e->state_current.tagentity && e->state_current.tagindex >= 1 && (model = t->render.model) && e->state_current.tagindex <= t->render.model->alias.aliasnum_tags)
                        {
                                // blend the matrices
index fac269f..14df524 100644 (file)
 
 #include "quakedef.h"
-#include "cl_collision.h"
 #include "r_shadow.h"
 
-typedef struct
-{
-       float m[3][4];
-} zymbonematrix;
-
-// LordHavoc: vertex arrays
-int aliasvertmax = 0;
-void *aliasvertarrays = NULL;
-float *aliasvertcolor4fbuf = NULL;
-float *aliasvertcolor4f = NULL; // this may point at aliasvertcolorbuf or at vertex arrays in the mesh backend
-float *aliasvert_vertex3f = NULL;
-float *aliasvert_svector3f = NULL;
-float *aliasvert_tvector3f = NULL;
-float *aliasvert_normal3f = NULL;
-
-float *aliasvertcolor2_4f = NULL;
-int *aliasvertusage;
-zymbonematrix *zymbonepose;
-
-mempool_t *gl_models_mempool;
-
-#define expandaliasvert(newmax) if ((newmax) > aliasvertmax) gl_models_allocarrays(newmax)
-
-void gl_models_allocarrays(int newmax)
-{
-       qbyte *data;
-       aliasvertmax = newmax;
-       if (aliasvertarrays != NULL)
-               Mem_Free(aliasvertarrays);
-       aliasvertarrays = Mem_Alloc(gl_models_mempool, aliasvertmax * (sizeof(float[4+4+3+3+3+3]) + sizeof(int[3])));
-       data = aliasvertarrays;
-       aliasvertcolor4f = aliasvertcolor4fbuf = (void *)data;data += aliasvertmax * sizeof(float[4]);
-       aliasvertcolor2_4f = (void *)data;data += aliasvertmax * sizeof(float[4]); // used temporarily for tinted coloring
-       aliasvert_vertex3f = (void *)data;data += aliasvertmax * sizeof(float[3]);
-       aliasvert_svector3f = (void *)data;data += aliasvertmax * sizeof(float[3]);
-       aliasvert_tvector3f = (void *)data;data += aliasvertmax * sizeof(float[3]);
-       aliasvert_normal3f = (void *)data;data += aliasvertmax * sizeof(float[3]);
-       aliasvertusage = (void *)data;data += aliasvertmax * sizeof(int[3]);
-}
-
-void gl_models_freearrays(void)
-{
-       aliasvertmax = 0;
-       if (aliasvertarrays != NULL)
-               Mem_Free(aliasvertarrays);
-       aliasvertarrays = NULL;
-       aliasvertcolor4f = aliasvertcolor4fbuf = NULL;
-       aliasvertcolor2_4f = NULL;
-       aliasvert_vertex3f = NULL;
-       aliasvert_svector3f = NULL;
-       aliasvert_tvector3f = NULL;
-       aliasvert_normal3f = NULL;
-       aliasvertusage = NULL;
-}
-
-void gl_models_start(void)
-{
-       // allocate vertex processing arrays
-       gl_models_mempool = Mem_AllocPool("GL_Models", 0, NULL);
-       zymbonepose = Mem_Alloc(gl_models_mempool, sizeof(zymbonematrix[256]));
-       gl_models_allocarrays(4096);
-}
-
-void gl_models_shutdown(void)
-{
-       gl_models_freearrays();
-       Mem_FreePool(&gl_models_mempool);
-}
-
-void gl_models_newmap(void)
-{
-}
-
 void GL_Models_Init(void)
 {
-       R_RegisterModule("GL_Models", gl_models_start, gl_models_shutdown, gl_models_newmap);
 }
 
-#define MODELARRAY_VERTEX 0
-#define MODELARRAY_SVECTOR 1
-#define MODELARRAY_TVECTOR 2
-#define MODELARRAY_NORMAL 3
-
-void R_Model_Alias_GetMesh_Array3f(const entity_render_t *ent, const aliasmesh_t *mesh, int whicharray, float *out3f)
+void R_Model_Alias_GetMesh_Vertex3f(const entity_render_t *ent, const aliasmesh_t *mesh, float *out3f)
 {
-       int i, vertcount;
-       float lerp1, lerp2, lerp3, lerp4;
-       const float *vertsbase, *verts1, *verts2, *verts3, *verts4;
-
-       switch(whicharray)
+       if (mesh->num_vertexboneweights)
        {
-       case MODELARRAY_VERTEX:vertsbase = mesh->data_aliasvertex3f;break;
-       case MODELARRAY_SVECTOR:vertsbase = mesh->data_aliassvector3f;break;
-       case MODELARRAY_TVECTOR:vertsbase = mesh->data_aliastvector3f;break;
-       case MODELARRAY_NORMAL:vertsbase = mesh->data_aliasnormal3f;break;
-       default:
-               Host_Error("R_Model_Alias_GetBlendedArray: unknown whicharray %i\n", whicharray);
-               return;
+               int i, k, blends;
+               aliasvertexboneweight_t *v;
+               float *out, *matrix, m[12], bonepose[256][12];
+               // vertex weighted skeletal
+               // interpolate matrices and concatenate them to their parents
+               for (i = 0;i < ent->model->alias.aliasnum_bones;i++)
+               {
+                       for (k = 0;k < 12;k++)
+                               m[k] = 0;
+                       for (blends = 0;blends < 4 && ent->frameblend[blends].lerp > 0;blends++)
+                       {
+                               matrix = ent->model->alias.aliasdata_poses + (ent->frameblend[blends].frame * ent->model->alias.aliasnum_bones + i) * 12;
+                               for (k = 0;k < 12;k++)
+                                       m[k] += matrix[k] * ent->frameblend[blends].lerp;
+                       }
+                       if (ent->model->alias.aliasdata_bones[i].parent >= 0)
+                               R_ConcatTransforms(bonepose[ent->model->alias.aliasdata_bones[i].parent], m, bonepose[i]);
+                       else
+                               for (k = 0;k < 12;k++)
+                                       bonepose[i][k] = m[k];
+               }
+               // blend the vertex bone weights
+               memset(out3f, 0, mesh->num_vertices * sizeof(float[3]));
+               v = mesh->data_vertexboneweights;
+               for (i = 0;i < mesh->num_vertexboneweights;i++, v++)
+               {
+                       out = out3f + v->vertexindex * 3;
+                       matrix = bonepose[v->boneindex];
+                       // FIXME: this can very easily be optimized with SSE or 3DNow
+                       out[0] += v->origin[0] * matrix[0] + v->origin[1] * matrix[1] + v->origin[2] * matrix[ 2] + v->origin[3] * matrix[ 3];
+                       out[1] += v->origin[0] * matrix[4] + v->origin[1] * matrix[5] + v->origin[2] * matrix[ 6] + v->origin[3] * matrix[ 7];
+                       out[2] += v->origin[0] * matrix[8] + v->origin[1] * matrix[9] + v->origin[2] * matrix[10] + v->origin[3] * matrix[11];
+               }                                                                                                              
        }
-
-       vertcount = mesh->num_vertices;
-       verts1 = vertsbase + ent->frameblend[0].frame * vertcount * 3;
-       lerp1 = ent->frameblend[0].lerp;
-       if (ent->frameblend[1].lerp)
+       else
        {
-               verts2 = vertsbase + ent->frameblend[1].frame * vertcount * 3;
-               lerp2 = ent->frameblend[1].lerp;
-               if (ent->frameblend[2].lerp)
+               int i, vertcount;
+               float lerp1, lerp2, lerp3, lerp4;
+               const float *vertsbase, *verts1, *verts2, *verts3, *verts4;
+               // vertex morph
+               vertsbase = mesh->data_morphvertex3f;
+               vertcount = mesh->num_vertices;
+               verts1 = vertsbase + ent->frameblend[0].frame * vertcount * 3;
+               lerp1 = ent->frameblend[0].lerp;
+               if (ent->frameblend[1].lerp)
                {
-                       verts3 = vertsbase + ent->frameblend[2].frame * vertcount * 3;
-                       lerp3 = ent->frameblend[2].lerp;
-                       if (ent->frameblend[3].lerp)
+                       verts2 = vertsbase + ent->frameblend[1].frame * vertcount * 3;
+                       lerp2 = ent->frameblend[1].lerp;
+                       if (ent->frameblend[2].lerp)
                        {
-                               verts4 = vertsbase + ent->frameblend[3].frame * vertcount * 3;
-                               lerp4 = ent->frameblend[3].lerp;
-                               for (i = 0;i < vertcount * 3;i++)
-                                       VectorMAMAMAM(lerp1, verts1 + i, lerp2, verts2 + i, lerp3, verts3 + i, lerp4, verts4 + i, out3f + i);
+                               verts3 = vertsbase + ent->frameblend[2].frame * vertcount * 3;
+                               lerp3 = ent->frameblend[2].lerp;
+                               if (ent->frameblend[3].lerp)
+                               {
+                                       verts4 = vertsbase + ent->frameblend[3].frame * vertcount * 3;
+                                       lerp4 = ent->frameblend[3].lerp;
+                                       for (i = 0;i < vertcount * 3;i++)
+                                               VectorMAMAMAM(lerp1, verts1 + i, lerp2, verts2 + i, lerp3, verts3 + i, lerp4, verts4 + i, out3f + i);
+                               }
+                               else
+                                       for (i = 0;i < vertcount * 3;i++)
+                                               VectorMAMAM(lerp1, verts1 + i, lerp2, verts2 + i, lerp3, verts3 + i, out3f + i);
                        }
                        else
                                for (i = 0;i < vertcount * 3;i++)
-                                       VectorMAMAM(lerp1, verts1 + i, lerp2, verts2 + i, lerp3, verts3 + i, out3f + i);
+                                       VectorMAM(lerp1, verts1 + i, lerp2, verts2 + i, out3f + i);
                }
                else
-                       for (i = 0;i < vertcount * 3;i++)
-                               VectorMAM(lerp1, verts1 + i, lerp2, verts2 + i, out3f + i);
+                       memcpy(out3f, verts1, vertcount * sizeof(float[3]));
        }
-       else
-               memcpy(out3f, verts1, vertcount * sizeof(float[3]));
 }
 
 aliaslayer_t r_aliasnoskinlayers[2] = {{ALIASLAYER_DIFFUSE, NULL, NULL}, {ALIASLAYER_FOG | ALIASLAYER_FORCEDRAW_IF_FIRSTPASS, NULL, NULL}};
@@ -160,7 +109,7 @@ aliasskin_t *R_FetchAliasSkin(const entity_render_t *ent, const aliasmesh_t *mes
 
 void R_DrawAliasModelCallback (const void *calldata1, int calldata2)
 {
-       int c, fullbright, layernum, firstpass;
+       int c, fullbright, layernum, firstpass, generatenormals = true;
        float tint[3], fog, ifog, colorscale, ambientcolor4f[4], diffusecolor[3], diffusenormal[3];
        vec3_t diff;
        qbyte *bcolor;
@@ -192,6 +141,7 @@ void R_DrawAliasModelCallback (const void *calldata1, int calldata2)
 
        firstpass = true;
        skin = R_FetchAliasSkin(ent, mesh);
+       R_Model_Alias_GetMesh_Vertex3f(ent, mesh, varray_vertex3f);
        for (layernum = 0, layer = skin->data_layers;layernum < skin->num_layers;layernum++, layer++)
        {
                if (!(layer->flags & ALIASLAYER_FORCEDRAW_IF_FIRSTPASS) || !firstpass)
@@ -220,7 +170,6 @@ void R_DrawAliasModelCallback (const void *calldata1, int calldata2)
                }
                GL_DepthTest(true);
                firstpass = false;
-               expandaliasvert(mesh->num_vertices);
                colorscale = 1.0f;
 
                memset(&m, 0, sizeof(m));
@@ -237,7 +186,6 @@ void R_DrawAliasModelCallback (const void *calldata1, int calldata2)
                m.pointer_vertex = varray_vertex3f;
 
                c_alias_polys += mesh->num_triangles;
-               R_Model_Alias_GetMesh_Array3f(ent, mesh, MODELARRAY_VERTEX, varray_vertex3f);
                if (layer->flags & ALIASLAYER_FOG)
                {
                        colorscale *= fog;
@@ -270,7 +218,11 @@ void R_DrawAliasModelCallback (const void *calldata1, int calldata2)
                                if (R_LightModel(ambientcolor4f, diffusecolor, diffusenormal, ent, tint[0] * colorscale, tint[1] * colorscale, tint[2] * colorscale, ent->alpha, false))
                                {
                                        m.pointer_color = varray_color4f;
-                                       R_Model_Alias_GetMesh_Array3f(ent, mesh, MODELARRAY_NORMAL, varray_normal3f);
+                                       if (generatenormals)
+                                       {
+                                               generatenormals = false;
+                                               Mod_BuildTextureVectorsAndNormals(mesh->num_vertices, mesh->num_triangles, varray_vertex3f, mesh->data_texcoord2f, mesh->data_element3i, NULL, NULL, varray_normal3f);
+                                       }
                                        R_LightModel_CalcVertexColors(ambientcolor4f, diffusecolor, diffusenormal, mesh->num_vertices, varray_vertex3f, varray_normal3f, varray_color4f);
                                }
                                else
@@ -319,7 +271,7 @@ void R_Model_Alias_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightor
                        skin = R_FetchAliasSkin(ent, mesh);
                        if (skin->flags & ALIASSKIN_TRANSPARENT)
                                continue;
-                       R_Model_Alias_GetMesh_Array3f(ent, mesh, MODELARRAY_VERTEX, varray_vertex3f);
+                       R_Model_Alias_GetMesh_Vertex3f(ent, mesh, varray_vertex3f);
                        R_Shadow_VolumeFromSphere(mesh->num_vertices, mesh->num_triangles, varray_vertex3f, mesh->data_element3i, mesh->data_neighbor3i, relativelightorigin, projectdistance, lightradius);
                }
        }
@@ -363,11 +315,8 @@ void R_Model_Alias_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, v
                skin = R_FetchAliasSkin(ent, mesh);
                if (skin->flags & ALIASSKIN_TRANSPARENT)
                        continue;
-               expandaliasvert(mesh->num_vertices);
-               R_Model_Alias_GetMesh_Array3f(ent, mesh, MODELARRAY_VERTEX, aliasvert_vertex3f);
-               R_Model_Alias_GetMesh_Array3f(ent, mesh, MODELARRAY_SVECTOR, aliasvert_svector3f);
-               R_Model_Alias_GetMesh_Array3f(ent, mesh, MODELARRAY_TVECTOR, aliasvert_tvector3f);
-               R_Model_Alias_GetMesh_Array3f(ent, mesh, MODELARRAY_NORMAL, aliasvert_normal3f);
+               R_Model_Alias_GetMesh_Vertex3f(ent, mesh, varray_vertex3f);
+               Mod_BuildTextureVectorsAndNormals(mesh->num_vertices, mesh->num_triangles, varray_vertex3f, mesh->data_texcoord2f, mesh->data_element3i, varray_svector3f, varray_tvector3f, varray_normal3f);
                for (layernum = 0, layer = skin->data_layers;layernum < skin->num_layers;layernum++, layer++)
                {
                        if (!(layer->flags & (ALIASLAYER_DIFFUSE | ALIASLAYER_SPECULAR))
@@ -380,7 +329,7 @@ void R_Model_Alias_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, v
                        if (layer->flags & ALIASLAYER_SPECULAR)
                        {
                                c_alias_polys += mesh->num_triangles;
-                               R_Shadow_RenderLighting(mesh->num_vertices, mesh->num_triangles, mesh->data_element3i, aliasvert_vertex3f, aliasvert_svector3f, aliasvert_tvector3f, aliasvert_normal3f, mesh->data_texcoord2f, relativelightorigin, relativeeyeorigin, lightcolor2, matrix_modeltolight, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz, layer->texture, layer->nmap, layer->texture, lightcubemap, LIGHTING_SPECULAR);
+                               R_Shadow_RenderLighting(mesh->num_vertices, mesh->num_triangles, mesh->data_element3i, varray_vertex3f, varray_svector3f, varray_tvector3f, varray_normal3f, mesh->data_texcoord2f, relativelightorigin, relativeeyeorigin, lightcolor2, matrix_modeltolight, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz, layer->texture, layer->nmap, layer->texture, lightcubemap, LIGHTING_SPECULAR);
                        }
                        else if (layer->flags & ALIASLAYER_DIFFUSE)
                        {
@@ -409,408 +358,9 @@ void R_Model_Alias_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, v
                                        lightcolor2[2] *= bcolor[2] * (1.0f / 255.0f);
                                }
                                c_alias_polys += mesh->num_triangles;
-                               R_Shadow_RenderLighting(mesh->num_vertices, mesh->num_triangles, mesh->data_element3i, aliasvert_vertex3f, aliasvert_svector3f, aliasvert_tvector3f, aliasvert_normal3f, mesh->data_texcoord2f, relativelightorigin, relativeeyeorigin, lightcolor2, matrix_modeltolight, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz, layer->texture, layer->nmap, layer->texture, lightcubemap, LIGHTING_DIFFUSE);
-                       }
-               }
-       }
-}
-
-int ZymoticLerpBones(int count, const zymbonematrix *bonebase, const frameblend_t *blend, const zymbone_t *bone)
-{
-       int i;
-       float lerp1, lerp2, lerp3, lerp4;
-       zymbonematrix *out, rootmatrix, m;
-       const zymbonematrix *bone1, *bone2, *bone3, *bone4;
-
-       rootmatrix.m[0][0] = 1;
-       rootmatrix.m[0][1] = 0;
-       rootmatrix.m[0][2] = 0;
-       rootmatrix.m[0][3] = 0;
-       rootmatrix.m[1][0] = 0;
-       rootmatrix.m[1][1] = 1;
-       rootmatrix.m[1][2] = 0;
-       rootmatrix.m[1][3] = 0;
-       rootmatrix.m[2][0] = 0;
-       rootmatrix.m[2][1] = 0;
-       rootmatrix.m[2][2] = 1;
-       rootmatrix.m[2][3] = 0;
-
-       bone1 = bonebase + blend[0].frame * count;
-       lerp1 = blend[0].lerp;
-       if (blend[1].lerp)
-       {
-               bone2 = bonebase + blend[1].frame * count;
-               lerp2 = blend[1].lerp;
-               if (blend[2].lerp)
-               {
-                       bone3 = bonebase + blend[2].frame * count;
-                       lerp3 = blend[2].lerp;
-                       if (blend[3].lerp)
-                       {
-                               // 4 poses
-                               bone4 = bonebase + blend[3].frame * count;
-                               lerp4 = blend[3].lerp;
-                               for (i = 0, out = zymbonepose;i < count;i++, out++)
-                               {
-                                       // interpolate matrices
-                                       m.m[0][0] = bone1->m[0][0] * lerp1 + bone2->m[0][0] * lerp2 + bone3->m[0][0] * lerp3 + bone4->m[0][0] * lerp4;
-                                       m.m[0][1] = bone1->m[0][1] * lerp1 + bone2->m[0][1] * lerp2 + bone3->m[0][1] * lerp3 + bone4->m[0][1] * lerp4;
-                                       m.m[0][2] = bone1->m[0][2] * lerp1 + bone2->m[0][2] * lerp2 + bone3->m[0][2] * lerp3 + bone4->m[0][2] * lerp4;
-                                       m.m[0][3] = bone1->m[0][3] * lerp1 + bone2->m[0][3] * lerp2 + bone3->m[0][3] * lerp3 + bone4->m[0][3] * lerp4;
-                                       m.m[1][0] = bone1->m[1][0] * lerp1 + bone2->m[1][0] * lerp2 + bone3->m[1][0] * lerp3 + bone4->m[1][0] * lerp4;
-                                       m.m[1][1] = bone1->m[1][1] * lerp1 + bone2->m[1][1] * lerp2 + bone3->m[1][1] * lerp3 + bone4->m[1][1] * lerp4;
-                                       m.m[1][2] = bone1->m[1][2] * lerp1 + bone2->m[1][2] * lerp2 + bone3->m[1][2] * lerp3 + bone4->m[1][2] * lerp4;
-                                       m.m[1][3] = bone1->m[1][3] * lerp1 + bone2->m[1][3] * lerp2 + bone3->m[1][3] * lerp3 + bone4->m[1][3] * lerp4;
-                                       m.m[2][0] = bone1->m[2][0] * lerp1 + bone2->m[2][0] * lerp2 + bone3->m[2][0] * lerp3 + bone4->m[2][0] * lerp4;
-                                       m.m[2][1] = bone1->m[2][1] * lerp1 + bone2->m[2][1] * lerp2 + bone3->m[2][1] * lerp3 + bone4->m[2][1] * lerp4;
-                                       m.m[2][2] = bone1->m[2][2] * lerp1 + bone2->m[2][2] * lerp2 + bone3->m[2][2] * lerp3 + bone4->m[2][2] * lerp4;
-                                       m.m[2][3] = bone1->m[2][3] * lerp1 + bone2->m[2][3] * lerp2 + bone3->m[2][3] * lerp3 + bone4->m[2][3] * lerp4;
-                                       if (bone->parent >= 0)
-                                               R_ConcatTransforms(&zymbonepose[bone->parent].m[0][0], &m.m[0][0], &out->m[0][0]);
-                                       else
-                                               R_ConcatTransforms(&rootmatrix.m[0][0], &m.m[0][0], &out->m[0][0]);
-                                       bone1++;
-                                       bone2++;
-                                       bone3++;
-                                       bone4++;
-                                       bone++;
-                               }
-                       }
-                       else
-                       {
-                               // 3 poses
-                               for (i = 0, out = zymbonepose;i < count;i++, out++)
-                               {
-                                       // interpolate matrices
-                                       m.m[0][0] = bone1->m[0][0] * lerp1 + bone2->m[0][0] * lerp2 + bone3->m[0][0] * lerp3;
-                                       m.m[0][1] = bone1->m[0][1] * lerp1 + bone2->m[0][1] * lerp2 + bone3->m[0][1] * lerp3;
-                                       m.m[0][2] = bone1->m[0][2] * lerp1 + bone2->m[0][2] * lerp2 + bone3->m[0][2] * lerp3;
-                                       m.m[0][3] = bone1->m[0][3] * lerp1 + bone2->m[0][3] * lerp2 + bone3->m[0][3] * lerp3;
-                                       m.m[1][0] = bone1->m[1][0] * lerp1 + bone2->m[1][0] * lerp2 + bone3->m[1][0] * lerp3;
-                                       m.m[1][1] = bone1->m[1][1] * lerp1 + bone2->m[1][1] * lerp2 + bone3->m[1][1] * lerp3;
-                                       m.m[1][2] = bone1->m[1][2] * lerp1 + bone2->m[1][2] * lerp2 + bone3->m[1][2] * lerp3;
-                                       m.m[1][3] = bone1->m[1][3] * lerp1 + bone2->m[1][3] * lerp2 + bone3->m[1][3] * lerp3;
-                                       m.m[2][0] = bone1->m[2][0] * lerp1 + bone2->m[2][0] * lerp2 + bone3->m[2][0] * lerp3;
-                                       m.m[2][1] = bone1->m[2][1] * lerp1 + bone2->m[2][1] * lerp2 + bone3->m[2][1] * lerp3;
-                                       m.m[2][2] = bone1->m[2][2] * lerp1 + bone2->m[2][2] * lerp2 + bone3->m[2][2] * lerp3;
-                                       m.m[2][3] = bone1->m[2][3] * lerp1 + bone2->m[2][3] * lerp2 + bone3->m[2][3] * lerp3;
-                                       if (bone->parent >= 0)
-                                               R_ConcatTransforms(&zymbonepose[bone->parent].m[0][0], &m.m[0][0], &out->m[0][0]);
-                                       else
-                                               R_ConcatTransforms(&rootmatrix.m[0][0], &m.m[0][0], &out->m[0][0]);
-                                       bone1++;
-                                       bone2++;
-                                       bone3++;
-                                       bone++;
-                               }
-                       }
-               }
-               else
-               {
-                       // 2 poses
-                       for (i = 0, out = zymbonepose;i < count;i++, out++)
-                       {
-                               // interpolate matrices
-                               m.m[0][0] = bone1->m[0][0] * lerp1 + bone2->m[0][0] * lerp2;
-                               m.m[0][1] = bone1->m[0][1] * lerp1 + bone2->m[0][1] * lerp2;
-                               m.m[0][2] = bone1->m[0][2] * lerp1 + bone2->m[0][2] * lerp2;
-                               m.m[0][3] = bone1->m[0][3] * lerp1 + bone2->m[0][3] * lerp2;
-                               m.m[1][0] = bone1->m[1][0] * lerp1 + bone2->m[1][0] * lerp2;
-                               m.m[1][1] = bone1->m[1][1] * lerp1 + bone2->m[1][1] * lerp2;
-                               m.m[1][2] = bone1->m[1][2] * lerp1 + bone2->m[1][2] * lerp2;
-                               m.m[1][3] = bone1->m[1][3] * lerp1 + bone2->m[1][3] * lerp2;
-                               m.m[2][0] = bone1->m[2][0] * lerp1 + bone2->m[2][0] * lerp2;
-                               m.m[2][1] = bone1->m[2][1] * lerp1 + bone2->m[2][1] * lerp2;
-                               m.m[2][2] = bone1->m[2][2] * lerp1 + bone2->m[2][2] * lerp2;
-                               m.m[2][3] = bone1->m[2][3] * lerp1 + bone2->m[2][3] * lerp2;
-                               if (bone->parent >= 0)
-                                       R_ConcatTransforms(&zymbonepose[bone->parent].m[0][0], &m.m[0][0], &out->m[0][0]);
-                               else
-                                       R_ConcatTransforms(&rootmatrix.m[0][0], &m.m[0][0], &out->m[0][0]);
-                               bone1++;
-                               bone2++;
-                               bone++;
-                       }
-               }
-       }
-       else
-       {
-               // 1 pose
-               if (lerp1 != 1)
-               {
-                       // lerp != 1.0
-                       for (i = 0, out = zymbonepose;i < count;i++, out++)
-                       {
-                               // interpolate matrices
-                               m.m[0][0] = bone1->m[0][0] * lerp1;
-                               m.m[0][1] = bone1->m[0][1] * lerp1;
-                               m.m[0][2] = bone1->m[0][2] * lerp1;
-                               m.m[0][3] = bone1->m[0][3] * lerp1;
-                               m.m[1][0] = bone1->m[1][0] * lerp1;
-                               m.m[1][1] = bone1->m[1][1] * lerp1;
-                               m.m[1][2] = bone1->m[1][2] * lerp1;
-                               m.m[1][3] = bone1->m[1][3] * lerp1;
-                               m.m[2][0] = bone1->m[2][0] * lerp1;
-                               m.m[2][1] = bone1->m[2][1] * lerp1;
-                               m.m[2][2] = bone1->m[2][2] * lerp1;
-                               m.m[2][3] = bone1->m[2][3] * lerp1;
-                               if (bone->parent >= 0)
-                                       R_ConcatTransforms(&zymbonepose[bone->parent].m[0][0], &m.m[0][0], &out->m[0][0]);
-                               else
-                                       R_ConcatTransforms(&rootmatrix.m[0][0], &m.m[0][0], &out->m[0][0]);
-                               bone1++;
-                               bone++;
-                       }
-               }
-               else
-               {
-                       // lerp == 1.0
-                       for (i = 0, out = zymbonepose;i < count;i++, out++)
-                       {
-                               if (bone->parent >= 0)
-                                       R_ConcatTransforms(&zymbonepose[bone->parent].m[0][0], &bone1->m[0][0], &out->m[0][0]);
-                               else
-                                       R_ConcatTransforms(&rootmatrix.m[0][0], &bone1->m[0][0], &out->m[0][0]);
-                               bone1++;
-                               bone++;
+                               R_Shadow_RenderLighting(mesh->num_vertices, mesh->num_triangles, mesh->data_element3i, varray_vertex3f, varray_svector3f, varray_tvector3f, varray_normal3f, mesh->data_texcoord2f, relativelightorigin, relativeeyeorigin, lightcolor2, matrix_modeltolight, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz, layer->texture, layer->nmap, layer->texture, lightcubemap, LIGHTING_DIFFUSE);
                        }
                }
        }
-       return true;
-}
-
-void ZymoticTransformVerts(int vertcount, float *vertex, int *bonecounts, zymvertex_t *vert)
-{
-       int c;
-       float *out = vertex;
-       zymbonematrix *matrix;
-       while(vertcount--)
-       {
-               c = *bonecounts++;
-               // FIXME: validate bonecounts at load time (must be >= 1)
-               // FIXME: need 4th component in origin, for how much of the translate to blend in
-               if (c == 1)
-               {
-                       matrix = &zymbonepose[vert->bonenum];
-                       out[0] = vert->origin[0] * matrix->m[0][0] + vert->origin[1] * matrix->m[0][1] + vert->origin[2] * matrix->m[0][2] + matrix->m[0][3];
-                       out[1] = vert->origin[0] * matrix->m[1][0] + vert->origin[1] * matrix->m[1][1] + vert->origin[2] * matrix->m[1][2] + matrix->m[1][3];
-                       out[2] = vert->origin[0] * matrix->m[2][0] + vert->origin[1] * matrix->m[2][1] + vert->origin[2] * matrix->m[2][2] + matrix->m[2][3];
-                       vert++;
-               }
-               else
-               {
-                       VectorClear(out);
-                       while(c--)
-                       {
-                               matrix = &zymbonepose[vert->bonenum];
-                               out[0] += vert->origin[0] * matrix->m[0][0] + vert->origin[1] * matrix->m[0][1] + vert->origin[2] * matrix->m[0][2] + matrix->m[0][3];
-                               out[1] += vert->origin[0] * matrix->m[1][0] + vert->origin[1] * matrix->m[1][1] + vert->origin[2] * matrix->m[1][2] + matrix->m[1][3];
-                               out[2] += vert->origin[0] * matrix->m[2][0] + vert->origin[1] * matrix->m[2][1] + vert->origin[2] * matrix->m[2][2] + matrix->m[2][3];
-                               vert++;
-                       }
-               }
-               out += 3;
-       }
-}
-
-void ZymoticCalcNormal3f(int vertcount, float *vertex3f, float *normal3f, int shadercount, int *renderlist)
-{
-       int a, b, c, d;
-       float *out, v1[3], v2[3], normal[3], s;
-       int *u;
-       // clear normals
-       memset(normal3f, 0, sizeof(float) * vertcount * 3);
-       memset(aliasvertusage, 0, sizeof(int) * vertcount);
-       // parse render list and accumulate surface normals
-       while(shadercount--)
-       {
-               d = *renderlist++;
-               while (d--)
-               {
-                       a = renderlist[0]*4;
-                       b = renderlist[1]*4;
-                       c = renderlist[2]*4;
-                       v1[0] = vertex3f[a+0] - vertex3f[b+0];
-                       v1[1] = vertex3f[a+1] - vertex3f[b+1];
-                       v1[2] = vertex3f[a+2] - vertex3f[b+2];
-                       v2[0] = vertex3f[c+0] - vertex3f[b+0];
-                       v2[1] = vertex3f[c+1] - vertex3f[b+1];
-                       v2[2] = vertex3f[c+2] - vertex3f[b+2];
-                       CrossProduct(v1, v2, normal);
-                       VectorNormalizeFast(normal);
-                       // add surface normal to vertices
-                       a = renderlist[0] * 3;
-                       normal3f[a+0] += normal[0];
-                       normal3f[a+1] += normal[1];
-                       normal3f[a+2] += normal[2];
-                       aliasvertusage[renderlist[0]]++;
-                       a = renderlist[1] * 3;
-                       normal3f[a+0] += normal[0];
-                       normal3f[a+1] += normal[1];
-                       normal3f[a+2] += normal[2];
-                       aliasvertusage[renderlist[1]]++;
-                       a = renderlist[2] * 3;
-                       normal3f[a+0] += normal[0];
-                       normal3f[a+1] += normal[1];
-                       normal3f[a+2] += normal[2];
-                       aliasvertusage[renderlist[2]]++;
-                       renderlist += 3;
-               }
-       }
-       // FIXME: precalc this
-       // average surface normals
-       out = normal3f;
-       u = aliasvertusage;
-       while(vertcount--)
-       {
-               if (*u > 1)
-               {
-                       s = ixtable[*u];
-                       out[0] *= s;
-                       out[1] *= s;
-                       out[2] *= s;
-               }
-               u++;
-               out += 3;
-       }
-}
-
-void R_DrawZymoticModelMeshCallback (const void *calldata1, int calldata2)
-{
-       float fog, ifog, colorscale, ambientcolor4f[4], diffusecolor[3], diffusenormal[3];
-       vec3_t diff;
-       int i, *renderlist, *elements;
-       rtexture_t *texture;
-       rmeshstate_t mstate;
-       const entity_render_t *ent = calldata1;
-       int shadernum = calldata2;
-       int numverts, numtriangles;
-
-       R_Mesh_Matrix(&ent->matrix);
-
-       // find the vertex index list and texture
-       renderlist = ent->model->alias.zymdata_renderlist;
-       for (i = 0;i < shadernum;i++)
-               renderlist += renderlist[0] * 3 + 1;
-       texture = ent->model->alias.zymdata_textures[shadernum];
-
-       numverts = ent->model->alias.zymnum_verts;
-       numtriangles = *renderlist++;
-       elements = renderlist;
-
-       expandaliasvert(numverts);
-
-       fog = 0;
-       if (fogenabled)
-       {
-               VectorSubtract(ent->origin, r_vieworigin, diff);
-               fog = DotProduct(diff,diff);
-               if (fog < 0.01f)
-                       fog = 0.01f;
-               fog = exp(fogdensity/fog);
-               if (fog > 1)
-                       fog = 1;
-               if (fog < 0.01f)
-                       fog = 0;
-               // fog method: darken, additive fog
-               // 1. render model as normal, scaled by inverse of fog alpha (darkens it)
-               // 2. render fog as additive
-       }
-       ifog = 1 - fog;
-
-       if (ent->effects & EF_ADDITIVE)
-       {
-               GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
-               GL_DepthMask(false);
-       }
-       else if (ent->alpha != 1.0 || R_TextureHasAlpha(texture))
-       {
-               GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-               GL_DepthMask(false);
-       }
-       else
-       {
-               GL_BlendFunc(GL_ONE, GL_ZERO);
-               GL_DepthMask(true);
-       }
-       GL_DepthTest(true);
-
-       memset(&mstate, 0, sizeof(mstate));
-       colorscale = 1.0f;
-       if (gl_combine.integer)
-       {
-               mstate.texrgbscale[0] = 4;
-               colorscale *= 0.25f;
-       }
-       mstate.tex[0] = R_GetTexture(texture);
-       mstate.pointer_texcoord[0] = ent->model->alias.zymdata_texcoords;
-       mstate.pointer_vertex = varray_vertex3f;
-
-       ZymoticLerpBones(ent->model->alias.zymnum_bones, (zymbonematrix *) ent->model->alias.zymdata_poses, ent->frameblend, ent->model->alias.zymdata_bones);
-
-       ZymoticTransformVerts(numverts, varray_vertex3f, ent->model->alias.zymdata_vertbonecounts, ent->model->alias.zymdata_verts);
-       ZymoticCalcNormal3f(numverts, varray_vertex3f, aliasvert_normal3f, ent->model->alias.zymnum_shaders, ent->model->alias.zymdata_renderlist);
-       if (R_LightModel(ambientcolor4f, diffusecolor, diffusenormal, ent, ifog * colorscale, ifog * colorscale, ifog * colorscale, ent->alpha, false))
-       {
-               mstate.pointer_color = varray_color4f;
-               R_LightModel_CalcVertexColors(ambientcolor4f, diffusecolor, diffusenormal, numverts, varray_vertex3f, aliasvert_normal3f, varray_color4f);
-       }
-       else
-               GL_Color(ambientcolor4f[0], ambientcolor4f[1], ambientcolor4f[2], ambientcolor4f[3]);
-       R_Mesh_State(&mstate);
-       GL_LockArrays(0, numverts);
-       R_Mesh_Draw(numverts, numtriangles, elements);
-       GL_LockArrays(0, 0);
-       c_alias_polys += numtriangles;
-
-       if (fog)
-       {
-               GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-               GL_DepthMask(false);
-               GL_DepthTest(true);
-
-               memset(&mstate, 0, sizeof(mstate));
-               // FIXME: need alpha mask for fogging...
-               //mstate.tex[0] = R_GetTexture(texture);
-               //mstate.pointer_texcoord = ent->model->alias.zymdata_texcoords;
-               mstate.pointer_vertex = varray_vertex3f;
-               R_Mesh_State(&mstate);
-
-               GL_Color(fogcolor[0], fogcolor[1], fogcolor[2], ent->alpha * fog);
-               ZymoticTransformVerts(numverts, varray_vertex3f, ent->model->alias.zymdata_vertbonecounts, ent->model->alias.zymdata_verts);
-               R_Mesh_State(&mstate);
-               GL_LockArrays(0, numverts);
-               R_Mesh_Draw(numverts, numtriangles, elements);
-               GL_LockArrays(0, 0);
-               c_alias_polys += numtriangles;
-       }
-}
-
-void R_Model_Zymotic_Draw(entity_render_t *ent)
-{
-       int i;
-
-       if (ent->alpha < (1.0f / 64.0f))
-               return; // basically completely transparent
-
-       c_models++;
-
-       for (i = 0;i < ent->model->alias.zymnum_shaders;i++)
-       {
-               if (ent->effects & EF_ADDITIVE || ent->alpha != 1.0 || R_TextureHasAlpha(ent->model->alias.zymdata_textures[i]))
-                       R_MeshQueue_AddTransparent(ent->origin, R_DrawZymoticModelMeshCallback, ent, i);
-               else
-                       R_DrawZymoticModelMeshCallback(ent, i);
-       }
-}
-
-void R_Model_Zymotic_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, float lightradius)
-{
-       // FIXME
-}
-
-void R_Model_Zymotic_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, vec3_t relativeeyeorigin, float lightradius, float *lightcolor, const matrix4x4_t *matrix_modeltolight, const matrix4x4_t *matrix_modeltoattenuationxyz, const matrix4x4_t *matrix_modeltoattenuationz, rtexture_t *lightcubemap)
-{
-       // FIXME
 }
 
index 8d7871f..7c0fd8a 100644 (file)
@@ -48,9 +48,12 @@ static void Mod_MDLMD2MD3_TraceBox(model_t *model, int frame, trace_t *trace, co
                for (i = 0;i < model->alias.aliasnum_meshes;i++)
                {
                        framenum = frame;
-                       if (framenum < 0 || framenum > model->alias.aliasdata_meshes[i].num_frames)
+                       if (framenum < 0 || framenum > model->alias.aliasdata_meshes[i].num_morphframes)
                                framenum = 0;
-                       Collision_TraceLineTriangleMeshFloat(trace, boxstartmins, boxendmins, model->alias.aliasdata_meshes[i].num_triangles, model->alias.aliasdata_meshes[i].data_element3i, model->alias.aliasdata_meshes[i].data_aliasvertex3f + framenum * model->alias.aliasdata_meshes[i].num_vertices * 3, SUPERCONTENTS_SOLID, segmentmins, segmentmaxs);
+                       if (model->alias.aliasdata_meshes[i].data_morphvertex3f)
+                               Collision_TraceLineTriangleMeshFloat(trace, boxstartmins, boxendmins, model->alias.aliasdata_meshes[i].num_triangles, model->alias.aliasdata_meshes[i].data_element3i, model->alias.aliasdata_meshes[i].data_morphvertex3f + framenum * model->alias.aliasdata_meshes[i].num_vertices * 3, SUPERCONTENTS_SOLID, segmentmins, segmentmaxs);
+                       //else
+                               // FIXME!!!  this needs to handle skeletal!
                }
        }
        else
@@ -63,9 +66,12 @@ static void Mod_MDLMD2MD3_TraceBox(model_t *model, int frame, trace_t *trace, co
                for (i = 0;i < model->alias.aliasnum_meshes;i++)
                {
                        framenum = frame;
-                       if (framenum < 0 || framenum > model->alias.aliasdata_meshes[i].num_frames)
+                       if (framenum < 0 || framenum > model->alias.aliasdata_meshes[i].num_morphframes)
                                framenum = 0;
-                       Collision_TraceBrushTriangleMeshFloat(trace, thisbrush_start, thisbrush_end, model->alias.aliasdata_meshes[i].num_triangles, model->alias.aliasdata_meshes[i].data_element3i, model->alias.aliasdata_meshes[i].data_aliasvertex3f + framenum * model->alias.aliasdata_meshes[i].num_vertices * 3, SUPERCONTENTS_SOLID, segmentmins, segmentmaxs);
+                       if (model->alias.aliasdata_meshes[i].data_morphvertex3f)
+                               Collision_TraceBrushTriangleMeshFloat(trace, thisbrush_start, thisbrush_end, model->alias.aliasdata_meshes[i].num_triangles, model->alias.aliasdata_meshes[i].data_element3i, model->alias.aliasdata_meshes[i].data_morphvertex3f + framenum * model->alias.aliasdata_meshes[i].num_vertices * 3, SUPERCONTENTS_SOLID, segmentmins, segmentmaxs);
+                       //else
+                               // FIXME!!!  this needs to handle skeletal!
                }
        }
 }
@@ -82,7 +88,7 @@ static void Mod_CalcAliasModelBBoxes (void)
        radius = 0;
        for (meshnum = 0, mesh = loadmodel->alias.aliasdata_meshes;meshnum < loadmodel->alias.aliasnum_meshes;meshnum++, mesh++)
        {
-               for (vnum = 0, v = mesh->data_aliasvertex3f;vnum < mesh->num_vertices * mesh->num_frames;vnum++, v += 3)
+               for (vnum = 0, v = mesh->data_morphvertex3f;vnum < mesh->num_vertices * mesh->num_morphframes;vnum++, v += 3)
                {
                        if (loadmodel->normalmins[0] > v[0]) loadmodel->normalmins[0] = v[0];
                        if (loadmodel->normalmins[1] > v[1]) loadmodel->normalmins[1] = v[1];
@@ -185,8 +191,7 @@ static void Mod_MDL_LoadFrames (qbyte* datapointer, int inverts, vec3_t scale, v
                {
                        pinframe = (daliasframe_t *)datapointer;
                        datapointer += sizeof(daliasframe_t);
-                       Mod_ConvertAliasVerts(inverts, scale, translate, (trivertx_t *)datapointer, loadmodel->alias.aliasdata_meshes->data_aliasvertex3f + pose * loadmodel->alias.aliasdata_meshes->num_vertices * 3, vertremap);
-                       Mod_BuildTextureVectorsAndNormals(loadmodel->alias.aliasdata_meshes->num_vertices, loadmodel->alias.aliasdata_meshes->num_triangles, loadmodel->alias.aliasdata_meshes->data_aliasvertex3f + pose * loadmodel->alias.aliasdata_meshes->num_vertices * 3, loadmodel->alias.aliasdata_meshes->data_texcoord2f, loadmodel->alias.aliasdata_meshes->data_element3i, loadmodel->alias.aliasdata_meshes->data_aliassvector3f + pose * loadmodel->alias.aliasdata_meshes->num_vertices * 3, loadmodel->alias.aliasdata_meshes->data_aliastvector3f + pose * loadmodel->alias.aliasdata_meshes->num_vertices * 3, loadmodel->alias.aliasdata_meshes->data_aliasnormal3f + pose * loadmodel->alias.aliasdata_meshes->num_vertices * 3);
+                       Mod_ConvertAliasVerts(inverts, scale, translate, (trivertx_t *)datapointer, loadmodel->alias.aliasdata_meshes->data_morphvertex3f + pose * loadmodel->alias.aliasdata_meshes->num_vertices * 3, vertremap);
                        datapointer += sizeof(trivertx_t) * inverts;
                        pose++;
                }
@@ -347,7 +352,6 @@ void Mod_IDP0_Load(model_t *mod, void *buffer)
                                 loadmodel->name, version, ALIAS_VERSION);
 
        loadmodel->type = mod_alias;
-       loadmodel->alias.aliastype = ALIASTYPE_ALIAS;
        loadmodel->DrawSky = NULL;
        loadmodel->Draw = R_Model_Alias_Draw;
        loadmodel->DrawShadowVolume = R_Model_Alias_DrawShadowVolume;
@@ -409,7 +413,7 @@ void Mod_IDP0_Load(model_t *mod, void *buffer)
        datapointer += sizeof(dtriangle_t) * loadmodel->alias.aliasdata_meshes->num_triangles;
 
        startframes = datapointer;
-       loadmodel->alias.aliasdata_meshes->num_frames = 0;
+       loadmodel->alias.aliasdata_meshes->num_morphframes = 0;
        for (i = 0;i < loadmodel->numframes;i++)
        {
                pinframetype = (daliasframetype_t *)datapointer;
@@ -428,7 +432,7 @@ void Mod_IDP0_Load(model_t *mod, void *buffer)
                {
                        datapointer += sizeof(daliasframe_t);
                        datapointer += sizeof(trivertx_t) * numverts;
-                       loadmodel->alias.aliasdata_meshes->num_frames++;
+                       loadmodel->alias.aliasdata_meshes->num_morphframes++;
                }
        }
 
@@ -498,12 +502,9 @@ void Mod_IDP0_Load(model_t *mod, void *buffer)
 
 // load the frames
        loadmodel->animscenes = Mem_Alloc(loadmodel->mempool, sizeof(animscene_t) * loadmodel->numframes);
-       loadmodel->alias.aliasdata_meshes->data_aliasvertex3f = Mem_Alloc(loadmodel->mempool, sizeof(float[4][3]) * loadmodel->alias.aliasdata_meshes->num_frames * loadmodel->alias.aliasdata_meshes->num_vertices);
-       loadmodel->alias.aliasdata_meshes->data_aliassvector3f = loadmodel->alias.aliasdata_meshes->data_aliasvertex3f + loadmodel->alias.aliasdata_meshes->num_frames * loadmodel->alias.aliasdata_meshes->num_vertices * 3 * 1;
-       loadmodel->alias.aliasdata_meshes->data_aliastvector3f = loadmodel->alias.aliasdata_meshes->data_aliasvertex3f + loadmodel->alias.aliasdata_meshes->num_frames * loadmodel->alias.aliasdata_meshes->num_vertices * 3 * 2;
-       loadmodel->alias.aliasdata_meshes->data_aliasnormal3f = loadmodel->alias.aliasdata_meshes->data_aliasvertex3f + loadmodel->alias.aliasdata_meshes->num_frames * loadmodel->alias.aliasdata_meshes->num_vertices * 3 * 3;
-       Mod_MDL_LoadFrames (startframes, numverts, scale, translate, vertremap);
+       loadmodel->alias.aliasdata_meshes->data_morphvertex3f = Mem_Alloc(loadmodel->mempool, sizeof(float[3]) * loadmodel->alias.aliasdata_meshes->num_morphframes * loadmodel->alias.aliasdata_meshes->num_vertices);
        loadmodel->alias.aliasdata_meshes->data_neighbor3i = Mem_Alloc(loadmodel->mempool, loadmodel->alias.aliasdata_meshes->num_triangles * sizeof(int[3]));
+       Mod_MDL_LoadFrames (startframes, numverts, scale, translate, vertremap);
        Mod_BuildTriangleNeighbors(loadmodel->alias.aliasdata_meshes->data_neighbor3i, loadmodel->alias.aliasdata_meshes->data_element3i, loadmodel->alias.aliasdata_meshes->num_triangles);
        Mod_CalcAliasModelBBoxes();
 
@@ -653,7 +654,6 @@ void Mod_IDP2_Load(model_t *mod, void *buffer)
                        loadmodel->name, version, MD2ALIAS_VERSION);
 
        loadmodel->type = mod_alias;
-       loadmodel->alias.aliastype = ALIASTYPE_ALIAS;
        loadmodel->DrawSky = NULL;
        loadmodel->Draw = R_Model_Alias_Draw;
        loadmodel->DrawShadowVolume = R_Model_Alias_DrawShadowVolume;
@@ -689,7 +689,7 @@ void Mod_IDP2_Load(model_t *mod, void *buffer)
        numst = LittleLong(pinmodel->num_st);
        loadmodel->alias.aliasdata_meshes->num_triangles = LittleLong(pinmodel->num_tris);
        loadmodel->numframes = LittleLong(pinmodel->num_frames);
-       loadmodel->alias.aliasdata_meshes->num_frames = loadmodel->numframes;
+       loadmodel->alias.aliasdata_meshes->num_morphframes = loadmodel->numframes;
        loadmodel->animscenes = Mem_Alloc(loadmodel->mempool, loadmodel->numframes * sizeof(animscene_t));
 
        loadmodel->flags = 0; // there are no MD2 flags
@@ -820,11 +820,8 @@ void Mod_IDP2_Load(model_t *mod, void *buffer)
 
        // load the frames
        datapointer = (base + LittleLong(pinmodel->ofs_frames));
-       loadmodel->alias.aliasdata_meshes->data_aliasvertex3f = Mem_Alloc(loadmodel->mempool, numverts * loadmodel->alias.aliasdata_meshes->num_frames * sizeof(float[4][3]));
-       loadmodel->alias.aliasdata_meshes->data_aliassvector3f = loadmodel->alias.aliasdata_meshes->data_aliasvertex3f + numverts * loadmodel->alias.aliasdata_meshes->num_frames * 3 * 1;
-       loadmodel->alias.aliasdata_meshes->data_aliastvector3f = loadmodel->alias.aliasdata_meshes->data_aliasvertex3f + numverts * loadmodel->alias.aliasdata_meshes->num_frames * 3 * 2;
-       loadmodel->alias.aliasdata_meshes->data_aliasnormal3f = loadmodel->alias.aliasdata_meshes->data_aliasvertex3f + numverts * loadmodel->alias.aliasdata_meshes->num_frames * 3 * 3;
-       for (i = 0;i < loadmodel->alias.aliasdata_meshes->num_frames;i++)
+       loadmodel->alias.aliasdata_meshes->data_morphvertex3f = Mem_Alloc(loadmodel->mempool, numverts * loadmodel->alias.aliasdata_meshes->num_morphframes * sizeof(float[3]));
+       for (i = 0;i < loadmodel->alias.aliasdata_meshes->num_morphframes;i++)
        {
                pinframe = (md2frame_t *)datapointer;
                datapointer += sizeof(md2frame_t);
@@ -833,8 +830,7 @@ void Mod_IDP2_Load(model_t *mod, void *buffer)
                        scale[j] = LittleFloat(pinframe->scale[j]);
                        translate[j] = LittleFloat(pinframe->translate[j]);
                }
-               Mod_MD2_ConvertVerts(scale, translate, (void *)datapointer, loadmodel->alias.aliasdata_meshes->data_aliasvertex3f + i * numverts * 3, numverts, vertremap);
-               Mod_BuildTextureVectorsAndNormals(loadmodel->alias.aliasdata_meshes->num_vertices, loadmodel->alias.aliasdata_meshes->num_triangles, loadmodel->alias.aliasdata_meshes->data_aliasvertex3f + i * loadmodel->alias.aliasdata_meshes->num_vertices * 3, loadmodel->alias.aliasdata_meshes->data_texcoord2f, loadmodel->alias.aliasdata_meshes->data_element3i, loadmodel->alias.aliasdata_meshes->data_aliassvector3f + i * loadmodel->alias.aliasdata_meshes->num_vertices * 3, loadmodel->alias.aliasdata_meshes->data_aliastvector3f + i * loadmodel->alias.aliasdata_meshes->num_vertices * 3, loadmodel->alias.aliasdata_meshes->data_aliasnormal3f + i * loadmodel->alias.aliasdata_meshes->num_vertices * 3);
+               Mod_MD2_ConvertVerts(scale, translate, (void *)datapointer, loadmodel->alias.aliasdata_meshes->data_morphvertex3f + i * numverts * 3, numverts, vertremap);
                datapointer += numxyz * sizeof(trivertx_t);
 
                strcpy(loadmodel->animscenes[i].name, pinframe->name);
@@ -875,7 +871,6 @@ void Mod_IDP3_Load(model_t *mod, void *buffer)
                loadmodel->numskins = 1;
 
        loadmodel->type = mod_alias;
-       loadmodel->alias.aliastype = ALIASTYPE_ALIAS;
        loadmodel->DrawSky = NULL;
        loadmodel->Draw = R_Model_Alias_Draw;
        loadmodel->DrawShadowVolume = R_Model_Alias_DrawShadowVolume;
@@ -934,17 +929,14 @@ void Mod_IDP3_Load(model_t *mod, void *buffer)
                        Host_Error("Mod_IDP3_Load: invalid mesh identifier (not IDP3)\n");
                mesh = loadmodel->alias.aliasdata_meshes + i;
                mesh->num_skins = loadmodel->numskins;
-               mesh->num_frames = LittleLong(pinmesh->num_frames);
+               mesh->num_morphframes = LittleLong(pinmesh->num_frames);
                mesh->num_vertices = LittleLong(pinmesh->num_vertices);
                mesh->num_triangles = LittleLong(pinmesh->num_triangles);
                mesh->data_skins = Mem_Alloc(loadmodel->mempool, mesh->num_skins * sizeof(aliasskin_t));
                mesh->data_element3i = Mem_Alloc(loadmodel->mempool, mesh->num_triangles * sizeof(int[3]));
                mesh->data_neighbor3i = Mem_Alloc(loadmodel->mempool, mesh->num_triangles * sizeof(int[3]));
                mesh->data_texcoord2f = Mem_Alloc(loadmodel->mempool, mesh->num_vertices * sizeof(float[2]));
-               mesh->data_aliasvertex3f = Mem_Alloc(loadmodel->mempool, mesh->num_vertices * mesh->num_frames * sizeof(float[4][3]));
-               mesh->data_aliassvector3f = mesh->data_aliasvertex3f + mesh->num_vertices * mesh->num_frames * 3 * 1;
-               mesh->data_aliastvector3f = mesh->data_aliasvertex3f + mesh->num_vertices * mesh->num_frames * 3 * 2;
-               mesh->data_aliasnormal3f = mesh->data_aliasvertex3f + mesh->num_vertices * mesh->num_frames * 3 * 3;
+               mesh->data_morphvertex3f = Mem_Alloc(loadmodel->mempool, mesh->num_vertices * mesh->num_morphframes * sizeof(float[3]));
                for (j = 0;j < mesh->num_triangles * 3;j++)
                        mesh->data_element3i[j] = LittleLong(((int *)((qbyte *)pinmesh + pinmesh->lump_elements))[j]);
                for (j = 0;j < mesh->num_vertices;j++)
@@ -952,14 +944,12 @@ void Mod_IDP3_Load(model_t *mod, void *buffer)
                        mesh->data_texcoord2f[j * 2 + 0] = LittleFloat(((float *)((qbyte *)pinmesh + pinmesh->lump_texcoords))[j * 2 + 0]);
                        mesh->data_texcoord2f[j * 2 + 1] = LittleFloat(((float *)((qbyte *)pinmesh + pinmesh->lump_texcoords))[j * 2 + 1]);
                }
-               for (j = 0;j < mesh->num_vertices * mesh->num_frames;j++)
+               for (j = 0;j < mesh->num_vertices * mesh->num_morphframes;j++)
                {
-                       mesh->data_aliasvertex3f[j * 3 + 0] = LittleShort(((short *)((qbyte *)pinmesh + pinmesh->lump_framevertices))[j * 4 + 0]) * (1.0f / 64.0f);
-                       mesh->data_aliasvertex3f[j * 3 + 1] = LittleShort(((short *)((qbyte *)pinmesh + pinmesh->lump_framevertices))[j * 4 + 1]) * (1.0f / 64.0f);
-                       mesh->data_aliasvertex3f[j * 3 + 2] = LittleShort(((short *)((qbyte *)pinmesh + pinmesh->lump_framevertices))[j * 4 + 2]) * (1.0f / 64.0f);
+                       mesh->data_morphvertex3f[j * 3 + 0] = LittleShort(((short *)((qbyte *)pinmesh + pinmesh->lump_framevertices))[j * 4 + 0]) * (1.0f / 64.0f);
+                       mesh->data_morphvertex3f[j * 3 + 1] = LittleShort(((short *)((qbyte *)pinmesh + pinmesh->lump_framevertices))[j * 4 + 1]) * (1.0f / 64.0f);
+                       mesh->data_morphvertex3f[j * 3 + 2] = LittleShort(((short *)((qbyte *)pinmesh + pinmesh->lump_framevertices))[j * 4 + 2]) * (1.0f / 64.0f);
                }
-               for (j = 0;j < mesh->num_frames;j++)
-                       Mod_BuildTextureVectorsAndNormals(mesh->num_vertices, mesh->num_triangles, mesh->data_aliasvertex3f + j * mesh->num_vertices * 3, mesh->data_texcoord2f, mesh->data_element3i, mesh->data_aliassvector3f + j * mesh->num_vertices * 3, mesh->data_aliastvector3f + j * mesh->num_vertices * 3, mesh->data_aliasnormal3f + j * mesh->num_vertices * 3);
 
                Mod_ValidateElements(mesh->data_element3i, mesh->num_triangles, mesh->num_vertices, __FILE__, __LINE__);
                Mod_BuildTriangleNeighbors(mesh->data_neighbor3i, mesh->data_element3i, mesh->num_triangles);
@@ -974,14 +964,18 @@ void Mod_IDP3_Load(model_t *mod, void *buffer)
        Mod_FreeSkinFiles(skinfiles);
 }
 
-extern void R_Model_Zymotic_DrawSky(entity_render_t *ent);
-extern void R_Model_Zymotic_Draw(entity_render_t *ent);
-extern void R_Model_Zymotic_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, float lightradius, int numsurfaces, const int *surfacelist);
-extern void R_Model_Zymotic_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, vec3_t relativeeyeorigin, float lightradius, float *lightcolor, const matrix4x4_t *matrix_modeltolight, const matrix4x4_t *matrix_modeltoattenuationxyz, const matrix4x4_t *matrix_modeltoattenuationz, rtexture_t *lightcubemap, int numsurfaces, const int *surfacelist);
 void Mod_ZYMOTICMODEL_Load(model_t *mod, void *buffer)
 {
        zymtype1header_t *pinmodel, *pheader;
        qbyte *pbase;
+       int i, j, k, l, numposes, *bonecount, *vertbonecounts, count, *renderlist, *renderlistend, *outelements, *remapvertices;
+       float modelradius, corner[2], *poses, *intexcoord2f, *outtexcoord2f;
+       zymvertex_t *verts, *vertdata;
+       zymscene_t *scene;
+       zymbone_t *bone;
+       char *shadername;
+       skinfile_t *skinfiles;
+       aliasmesh_t *mesh;
 
        pinmodel = (void *)buffer;
        pbase = buffer;
@@ -991,11 +985,13 @@ void Mod_ZYMOTICMODEL_Load(model_t *mod, void *buffer)
                Host_Error ("Mod_ZYMOTICMODEL_Load: only type 1 (skeletal pose) models are currently supported (name = %s)\n", loadmodel->name);
 
        loadmodel->type = mod_alias;
-       loadmodel->alias.aliastype = ALIASTYPE_ZYM;
        loadmodel->DrawSky = NULL;
-       loadmodel->Draw = R_Model_Zymotic_Draw;
-       loadmodel->DrawShadowVolume = NULL;//R_Model_Zymotic_DrawShadowVolume;
-       loadmodel->DrawLight = NULL;//R_Model_Zymotic_DrawLight;
+       loadmodel->Draw = R_Model_Alias_Draw;
+       loadmodel->DrawShadowVolume = R_Model_Alias_DrawShadowVolume;
+       loadmodel->DrawLight = R_Model_Alias_DrawLight;
+       //loadmodel->TraceBox = Mod_MDLMD2MD3_TraceBox; // FIXME: implement collisions
+       loadmodel->flags = 0; // there are no flags on zym models
+       loadmodel->synctype = ST_RAND;
 
        // byteswap header
        pheader = pinmodel;
@@ -1008,11 +1004,11 @@ void Mod_ZYMOTICMODEL_Load(model_t *mod, void *buffer)
        pheader->maxs[1] = BigFloat(pinmodel->maxs[1]);
        pheader->maxs[2] = BigFloat(pinmodel->maxs[2]);
        pheader->radius = BigFloat(pinmodel->radius);
-       pheader->numverts = loadmodel->alias.zymnum_verts = BigLong(pinmodel->numverts);
-       pheader->numtris = loadmodel->alias.zymnum_tris = BigLong(pinmodel->numtris);
-       pheader->numshaders = loadmodel->alias.zymnum_shaders = BigLong(pinmodel->numshaders);
-       pheader->numbones = loadmodel->alias.zymnum_bones = BigLong(pinmodel->numbones);
-       pheader->numscenes = loadmodel->alias.zymnum_scenes = BigLong(pinmodel->numscenes);
+       pheader->numverts = BigLong(pinmodel->numverts);
+       pheader->numtris = BigLong(pinmodel->numtris);
+       pheader->numshaders = BigLong(pinmodel->numshaders);
+       pheader->numbones = BigLong(pinmodel->numbones);
+       pheader->numscenes = BigLong(pinmodel->numscenes);
        pheader->lump_scenes.start = BigLong(pinmodel->lump_scenes.start);
        pheader->lump_scenes.length = BigLong(pinmodel->lump_scenes.length);
        pheader->lump_poses.start = BigLong(pinmodel->lump_poses.start);
@@ -1032,188 +1028,214 @@ void Mod_ZYMOTICMODEL_Load(model_t *mod, void *buffer)
        pheader->lump_trizone.start = BigLong(pinmodel->lump_trizone.start);
        pheader->lump_trizone.length = BigLong(pinmodel->lump_trizone.length);
 
-       loadmodel->flags = 0; // there are no flags
        loadmodel->numframes = pheader->numscenes;
-       loadmodel->synctype = ST_SYNC;
-       //loadmodel->num_triangles = pheader->num_triangles;
-       //loadmodel->num_vertices = 0;
+       loadmodel->alias.aliasnum_meshes = pheader->numshaders;
 
+       skinfiles = Mod_LoadSkinFiles();
+       if (loadmodel->numskins < 1)
+               loadmodel->numskins = 1;
+
+       // make skinscenes for the skins (no groups)
+       loadmodel->skinscenes = Mem_Alloc(loadmodel->mempool, sizeof(animscene_t) * loadmodel->numskins);
+       for (i = 0;i < loadmodel->numskins;i++)
        {
-               unsigned int i;
-               float modelradius, corner[2];
-               // model bbox
-               modelradius = pheader->radius;
-               for (i = 0;i < 3;i++)
-               {
-                       loadmodel->normalmins[i] = pheader->mins[i];
-                       loadmodel->normalmaxs[i] = pheader->maxs[i];
-                       loadmodel->rotatedmins[i] = -modelradius;
-                       loadmodel->rotatedmaxs[i] = modelradius;
-               }
-               corner[0] = max(fabs(loadmodel->normalmins[0]), fabs(loadmodel->normalmaxs[0]));
-               corner[1] = max(fabs(loadmodel->normalmins[1]), fabs(loadmodel->normalmaxs[1]));
-               loadmodel->yawmaxs[0] = loadmodel->yawmaxs[1] = sqrt(corner[0]*corner[0]+corner[1]*corner[1]);
-               if (loadmodel->yawmaxs[0] > modelradius)
-                       loadmodel->yawmaxs[0] = loadmodel->yawmaxs[1] = modelradius;
-               loadmodel->yawmins[0] = loadmodel->yawmins[1] = -loadmodel->yawmaxs[0];
-               loadmodel->yawmins[2] = loadmodel->normalmins[2];
-               loadmodel->yawmaxs[2] = loadmodel->normalmaxs[2];
-               loadmodel->radius = modelradius;
-               loadmodel->radius2 = modelradius * modelradius;
+               loadmodel->skinscenes[i].firstframe = i;
+               loadmodel->skinscenes[i].framecount = 1;
+               loadmodel->skinscenes[i].loop = true;
+               loadmodel->skinscenes[i].framerate = 10;
        }
 
+       // model bbox
+       modelradius = pheader->radius;
+       for (i = 0;i < 3;i++)
        {
-               // FIXME: add shaders, and make them switchable shader sets and...
-               loadmodel->skinscenes = Mem_Alloc(loadmodel->mempool, sizeof(animscene_t));
-               loadmodel->skinscenes[0].firstframe = 0;
-               loadmodel->skinscenes[0].framecount = 1;
-               loadmodel->skinscenes[0].loop = true;
-               loadmodel->skinscenes[0].framerate = 10;
-               loadmodel->numskins = 1;
+               loadmodel->normalmins[i] = pheader->mins[i];
+               loadmodel->normalmaxs[i] = pheader->maxs[i];
+               loadmodel->rotatedmins[i] = -modelradius;
+               loadmodel->rotatedmaxs[i] = modelradius;
        }
+       corner[0] = max(fabs(loadmodel->normalmins[0]), fabs(loadmodel->normalmaxs[0]));
+       corner[1] = max(fabs(loadmodel->normalmins[1]), fabs(loadmodel->normalmaxs[1]));
+       loadmodel->yawmaxs[0] = loadmodel->yawmaxs[1] = sqrt(corner[0]*corner[0]+corner[1]*corner[1]);
+       if (loadmodel->yawmaxs[0] > modelradius)
+               loadmodel->yawmaxs[0] = loadmodel->yawmaxs[1] = modelradius;
+       loadmodel->yawmins[0] = loadmodel->yawmins[1] = -loadmodel->yawmaxs[0];
+       loadmodel->yawmins[2] = loadmodel->normalmins[2];
+       loadmodel->yawmaxs[2] = loadmodel->normalmaxs[2];
+       loadmodel->radius = modelradius;
+       loadmodel->radius2 = modelradius * modelradius;
 
        // go through the lumps, swapping things
 
+       //zymlump_t lump_scenes; // zymscene_t scene[numscenes]; // name and other information for each scene (see zymscene struct)
+       loadmodel->animscenes = Mem_Alloc(loadmodel->mempool, sizeof(animscene_t) * loadmodel->numframes);
+       scene = (void *) (pheader->lump_scenes.start + pbase);
+       numposes = pheader->lump_poses.length / pheader->numbones / sizeof(float[3][4]);
+       for (i = 0;i < pheader->numscenes;i++)
        {
-               int i, numposes;
-               zymscene_t *scene;
-       //      zymlump_t lump_scenes; // zymscene_t scene[numscenes]; // name and other information for each scene (see zymscene struct)
-               loadmodel->animscenes = Mem_Alloc(loadmodel->mempool, sizeof(animscene_t) * loadmodel->numframes);
-               scene = (void *) (pheader->lump_scenes.start + pbase);
-               numposes = pheader->lump_poses.length / pheader->numbones / sizeof(float[3][4]);
-               for (i = 0;i < pheader->numscenes;i++)
-               {
-                       memcpy(loadmodel->animscenes[i].name, scene->name, 32);
-                       loadmodel->animscenes[i].firstframe = BigLong(scene->start);
-                       loadmodel->animscenes[i].framecount = BigLong(scene->length);
-                       loadmodel->animscenes[i].framerate = BigFloat(scene->framerate);
-                       loadmodel->animscenes[i].loop = (BigLong(scene->flags) & ZYMSCENEFLAG_NOLOOP) == 0;
-                       if ((unsigned int) loadmodel->animscenes[i].firstframe >= (unsigned int) numposes)
-                               Host_Error("%s scene->firstframe (%i) >= numposes (%i)\n", loadmodel->name, loadmodel->animscenes[i].firstframe, numposes);
-                       if ((unsigned int) loadmodel->animscenes[i].firstframe + (unsigned int) loadmodel->animscenes[i].framecount > (unsigned int) numposes)
-                               Host_Error("%s scene->firstframe (%i) + framecount (%i) >= numposes (%i)\n", loadmodel->name, loadmodel->animscenes[i].firstframe, loadmodel->animscenes[i].framecount, numposes);
-                       if (loadmodel->animscenes[i].framerate < 0)
-                               Host_Error("%s scene->framerate (%f) < 0\n", loadmodel->name, loadmodel->animscenes[i].framerate);
-                       scene++;
-               }
+               memcpy(loadmodel->animscenes[i].name, scene->name, 32);
+               loadmodel->animscenes[i].firstframe = BigLong(scene->start);
+               loadmodel->animscenes[i].framecount = BigLong(scene->length);
+               loadmodel->animscenes[i].framerate = BigFloat(scene->framerate);
+               loadmodel->animscenes[i].loop = (BigLong(scene->flags) & ZYMSCENEFLAG_NOLOOP) == 0;
+               if ((unsigned int) loadmodel->animscenes[i].firstframe >= (unsigned int) numposes)
+                       Host_Error("%s scene->firstframe (%i) >= numposes (%i)\n", loadmodel->name, loadmodel->animscenes[i].firstframe, numposes);
+               if ((unsigned int) loadmodel->animscenes[i].firstframe + (unsigned int) loadmodel->animscenes[i].framecount > (unsigned int) numposes)
+                       Host_Error("%s scene->firstframe (%i) + framecount (%i) >= numposes (%i)\n", loadmodel->name, loadmodel->animscenes[i].firstframe, loadmodel->animscenes[i].framecount, numposes);
+               if (loadmodel->animscenes[i].framerate < 0)
+                       Host_Error("%s scene->framerate (%f) < 0\n", loadmodel->name, loadmodel->animscenes[i].framerate);
+               scene++;
        }
 
+       //zymlump_t lump_poses; // float pose[numposes][numbones][3][4]; // animation data
+       loadmodel->alias.aliasnum_poses = pheader->lump_poses.length / sizeof(float[3][4]);
+       loadmodel->alias.aliasdata_poses = Mem_Alloc(loadmodel->mempool, pheader->lump_poses.length);
+       poses = (void *) (pheader->lump_poses.start + pbase);
+       for (i = 0;i < pheader->lump_poses.length / 4;i++)
+               loadmodel->alias.aliasdata_poses[i] = BigFloat(poses[i]);
+
+       //zymlump_t lump_bones; // zymbone_t bone[numbones];
+       loadmodel->alias.aliasnum_bones = pheader->numbones;
+       loadmodel->alias.aliasdata_bones = Mem_Alloc(loadmodel->mempool, pheader->numbones * sizeof(aliasbone_t));
+       bone = (void *) (pheader->lump_bones.start + pbase);
+       for (i = 0;i < pheader->numbones;i++)
        {
-               int i;
-               float *poses;
-       //      zymlump_t lump_poses; // float pose[numposes][numbones][3][4]; // animation data
-               loadmodel->alias.zymdata_poses = Mem_Alloc(loadmodel->mempool, pheader->lump_poses.length);
-               poses = (void *) (pheader->lump_poses.start + pbase);
-               for (i = 0;i < pheader->lump_poses.length / 4;i++)
-                       loadmodel->alias.zymdata_poses[i] = BigFloat(poses[i]);
+               memcpy(loadmodel->alias.aliasdata_bones[i].name, bone[i].name, sizeof(bone[i].name));
+               loadmodel->alias.aliasdata_bones[i].flags = BigLong(bone[i].flags);
+               loadmodel->alias.aliasdata_bones[i].parent = BigLong(bone[i].parent);
+               if (loadmodel->alias.aliasdata_bones[i].parent >= i)
+                       Host_Error("%s bone[%i].parent >= %i\n", loadmodel->name, i, i);
        }
 
+       //zymlump_t lump_vertbonecounts; // int vertbonecounts[numvertices]; // how many bones influence each vertex (separate mainly to make this compress better)
+       vertbonecounts = Mem_Alloc(loadmodel->mempool, pheader->numverts * sizeof(int));
+       bonecount = (void *) (pheader->lump_vertbonecounts.start + pbase);
+       for (i = 0;i < pheader->numverts;i++)
        {
-               int i;
-               zymbone_t *bone;
-       //      zymlump_t lump_bones; // zymbone_t bone[numbones];
-               loadmodel->alias.zymdata_bones = Mem_Alloc(loadmodel->mempool, pheader->numbones * sizeof(zymbone_t));
-               bone = (void *) (pheader->lump_bones.start + pbase);
-               for (i = 0;i < pheader->numbones;i++)
-               {
-                       memcpy(loadmodel->alias.zymdata_bones[i].name, bone[i].name, sizeof(bone[i].name));
-                       loadmodel->alias.zymdata_bones[i].flags = BigLong(bone[i].flags);
-                       loadmodel->alias.zymdata_bones[i].parent = BigLong(bone[i].parent);
-                       if (loadmodel->alias.zymdata_bones[i].parent >= i)
-                               Host_Error("%s bone[%i].parent >= %i\n", loadmodel->name, i, i);
-               }
+               vertbonecounts[i] = BigLong(bonecount[i]);
+               if (vertbonecounts[i] < 1)
+                       Host_Error("%s bonecount[%i] < 1\n", loadmodel->name, i);
        }
 
+       //zymlump_t lump_verts; // zymvertex_t vert[numvertices]; // see vertex struct
+       verts = Mem_Alloc(loadmodel->mempool, pheader->lump_verts.length);
+       vertdata = (void *) (pheader->lump_verts.start + pbase);
+       for (i = 0;i < pheader->lump_verts.length / (int) sizeof(zymvertex_t);i++)
        {
-               int i, *bonecount;
-       //      zymlump_t lump_vertbonecounts; // int vertbonecounts[numvertices]; // how many bones influence each vertex (separate mainly to make this compress better)
-               loadmodel->alias.zymdata_vertbonecounts = Mem_Alloc(loadmodel->mempool, pheader->numverts * sizeof(int));
-               bonecount = (void *) (pheader->lump_vertbonecounts.start + pbase);
-               for (i = 0;i < pheader->numverts;i++)
-               {
-                       loadmodel->alias.zymdata_vertbonecounts[i] = BigLong(bonecount[i]);
-                       if (loadmodel->alias.zymdata_vertbonecounts[i] < 1)
-                               Host_Error("%s bonecount[%i] < 1\n", loadmodel->name, i);
-               }
+               verts[i].bonenum = BigLong(vertdata[i].bonenum);
+               verts[i].origin[0] = BigFloat(vertdata[i].origin[0]);
+               verts[i].origin[1] = BigFloat(vertdata[i].origin[1]);
+               verts[i].origin[2] = BigFloat(vertdata[i].origin[2]);
        }
 
+       //zymlump_t lump_texcoords; // float texcoords[numvertices][2];
+       outtexcoord2f = Mem_Alloc(loadmodel->mempool, pheader->numverts * sizeof(float[2]));
+       intexcoord2f = (void *) (pheader->lump_texcoords.start + pbase);
+       for (i = 0;i < pheader->numverts;i++)
        {
-               int i;
-               zymvertex_t *vertdata;
-       //      zymlump_t lump_verts; // zymvertex_t vert[numvertices]; // see vertex struct
-               loadmodel->alias.zymdata_verts = Mem_Alloc(loadmodel->mempool, pheader->lump_verts.length);
-               vertdata = (void *) (pheader->lump_verts.start + pbase);
-               for (i = 0;i < pheader->lump_verts.length / (int) sizeof(zymvertex_t);i++)
-               {
-                       loadmodel->alias.zymdata_verts[i].bonenum = BigLong(vertdata[i].bonenum);
-                       loadmodel->alias.zymdata_verts[i].origin[0] = BigFloat(vertdata[i].origin[0]);
-                       loadmodel->alias.zymdata_verts[i].origin[1] = BigFloat(vertdata[i].origin[1]);
-                       loadmodel->alias.zymdata_verts[i].origin[2] = BigFloat(vertdata[i].origin[2]);
-               }
+               outtexcoord2f[i*2+0] = BigFloat(intexcoord2f[i*2+0]);
+               // flip T coordinate for OpenGL
+               outtexcoord2f[i*2+1] = 1 - BigFloat(intexcoord2f[i*2+1]);
        }
 
+       //zymlump_t lump_trizone; // byte trizone[numtris]; // see trizone explanation
+       //loadmodel->alias.zymdata_trizone = Mem_Alloc(loadmodel->mempool, pheader->numtris);
+       //memcpy(loadmodel->alias.zymdata_trizone, (void *) (pheader->lump_trizone.start + pbase), pheader->numtris);
+
+       loadmodel->alias.aliasdata_meshes = Mem_Alloc(loadmodel->mempool, loadmodel->alias.aliasnum_meshes * sizeof(aliasmesh_t));
+
+       //zymlump_t lump_shaders; // char shadername[numshaders][32]; // shaders used on this model
+       //zymlump_t lump_render; // int renderlist[rendersize]; // sorted by shader with run lengths (int count), shaders are sequentially used, each run can be used with glDrawElements (each triangle is 3 int indices)
+       // byteswap, validate, and swap winding order of tris
+       count = pheader->numshaders * sizeof(int) + pheader->numtris * sizeof(int[3]);
+       if (pheader->lump_render.length != count)
+               Host_Error("%s renderlist is wrong size (%i bytes, should be %i bytes)\n", loadmodel->name, pheader->lump_render.length, count);
+       renderlist = (void *) (pheader->lump_render.start + pbase);
+       renderlistend = (void *) ((qbyte *) renderlist + pheader->lump_render.length);
+       for (i = 0;i < loadmodel->alias.aliasnum_meshes;i++)
        {
-               int i;
-               float *intexcoord2f, *outtexcoord2f;
-       //      zymlump_t lump_texcoords; // float texcoords[numvertices][2];
-               loadmodel->alias.zymdata_texcoords = outtexcoord2f = Mem_Alloc(loadmodel->mempool, pheader->numverts * sizeof(float[2]));
-               intexcoord2f = (void *) (pheader->lump_texcoords.start + pbase);
-               for (i = 0;i < pheader->numverts;i++)
+               if (renderlist >= renderlistend)
+                       Host_Error("%s corrupt renderlist (wrong size)\n", loadmodel->name);
+               count = BigLong(*renderlist);renderlist++;
+               if (renderlist + count * 3 > renderlistend || (i == pheader->numshaders - 1 && renderlist + count * 3 != renderlistend))
+                       Host_Error("%s corrupt renderlist (wrong size)\n", loadmodel->name);
+               mesh = loadmodel->alias.aliasdata_meshes + i;
+               mesh->num_skins = loadmodel->numskins;
+               mesh->num_triangles = count;
+               mesh->data_skins = Mem_Alloc(loadmodel->mempool, mesh->num_skins * sizeof(aliasskin_t));
+               mesh->data_element3i = Mem_Alloc(loadmodel->mempool, mesh->num_triangles * sizeof(int[3]));
+               mesh->data_neighbor3i = Mem_Alloc(loadmodel->mempool, mesh->num_triangles * sizeof(int[3]));
+               outelements = mesh->data_element3i;
+               for (j = 0;j < mesh->num_triangles;j++)
                {
-                       outtexcoord2f[i*2+0] = BigFloat(intexcoord2f[i*2+0]);
-                       // flip T coordinate for OpenGL
-                       outtexcoord2f[i*2+1] = 1 - BigFloat(intexcoord2f[i*2+1]);
+                       outelements[2] = BigLong(renderlist[0]);
+                       outelements[1] = BigLong(renderlist[1]);
+                       outelements[0] = BigLong(renderlist[2]);
+                       if ((unsigned int)outelements[0] >= (unsigned int)pheader->numverts
+                        || (unsigned int)outelements[1] >= (unsigned int)pheader->numverts
+                        || (unsigned int)outelements[2] >= (unsigned int)pheader->numverts)
+                               Host_Error("%s corrupt renderlist (out of bounds index)\n", loadmodel->name);
+                       renderlist += 3;
+                       outelements += 3;
                }
-       }
-
-       {
-               int i, count, *renderlist, *renderlistend, *outrenderlist;
-       //      zymlump_t lump_render; // int renderlist[rendersize]; // sorted by shader with run lengths (int count), shaders are sequentially used, each run can be used with glDrawElements (each triangle is 3 int indices)
-               loadmodel->alias.zymdata_renderlist = Mem_Alloc(loadmodel->mempool, pheader->lump_render.length);
-               // byteswap, validate, and swap winding order of tris
-               count = pheader->numshaders * sizeof(int) + pheader->numtris * sizeof(int[3]);
-               if (pheader->lump_render.length != count)
-                       Host_Error("%s renderlist is wrong size (%i bytes, should be %i bytes)\n", loadmodel->name, pheader->lump_render.length, count);
-               outrenderlist = loadmodel->alias.zymdata_renderlist = Mem_Alloc(loadmodel->mempool, count);
-               renderlist = (void *) (pheader->lump_render.start + pbase);
-               renderlistend = (void *) ((qbyte *) renderlist + pheader->lump_render.length);
-               for (i = 0;i < pheader->numshaders;i++)
+               remapvertices = Mem_Alloc(loadmodel->mempool, pheader->numverts * sizeof(int));
+               mesh->num_vertices = Mod_BuildVertexRemapTableFromElements(mesh->num_triangles * 3, mesh->data_element3i, pheader->numverts, remapvertices);
+               for (j = 0;j < mesh->num_triangles * 3;j++)
+                       mesh->data_element3i[j] = remapvertices[mesh->data_element3i[j]];
+               Mod_BuildTriangleNeighbors(mesh->data_neighbor3i, mesh->data_element3i, mesh->num_triangles);
+               mesh->data_texcoord2f = Mem_Alloc(loadmodel->mempool, mesh->num_vertices * sizeof(float[2]));
+               for (j = 0;j < pheader->numverts;j++)
                {
-                       if (renderlist >= renderlistend)
-                               Host_Error("%s corrupt renderlist (wrong size)\n", loadmodel->name);
-                       count = BigLong(*renderlist);renderlist++;
-                       if (renderlist + count * 3 > renderlistend)
-                               Host_Error("%s corrupt renderlist (wrong size)\n", loadmodel->name);
-                       *outrenderlist++ = count;
-                       while (count--)
+                       if (remapvertices[j] >= 0)
                        {
-                               outrenderlist[2] = BigLong(renderlist[0]);
-                               outrenderlist[1] = BigLong(renderlist[1]);
-                               outrenderlist[0] = BigLong(renderlist[2]);
-                               if ((unsigned int)outrenderlist[0] >= (unsigned int)pheader->numverts
-                                || (unsigned int)outrenderlist[1] >= (unsigned int)pheader->numverts
-                                || (unsigned int)outrenderlist[2] >= (unsigned int)pheader->numverts)
-                                       Host_Error("%s corrupt renderlist (out of bounds index)\n", loadmodel->name);
-                               renderlist += 3;
-                               outrenderlist += 3;
+                               mesh->data_texcoord2f[remapvertices[j]*2+0] = outtexcoord2f[j*2+0];
+                               mesh->data_texcoord2f[remapvertices[j]*2+1] = outtexcoord2f[j*2+1];
+                       }
+               }
+               mesh->num_vertexboneweights = 0;
+               for (j = 0;j < mesh->num_vertices;j++)
+                       if (remapvertices[j] >= 0)
+                               mesh->num_vertexboneweights += vertbonecounts[remapvertices[j]];
+               mesh->data_vertexboneweights = Mem_Alloc(loadmodel->mempool, mesh->num_vertexboneweights * sizeof(aliasvertexboneweight_t));
+               mesh->num_vertexboneweights = 0;
+               // note this vertexboneweight ordering requires that the remapvertices array is sequential numbers (separated by -1 values for omitted vertices)
+               l = 0;
+               for (j = 0;j < mesh->num_vertices;j++)
+               {
+                       if (remapvertices[j] < 0)
+                       {
+                               l += vertbonecounts[j];
+                               continue;
+                       }
+                       for (k = 0;k < vertbonecounts[j];k++)
+                       {
+                               // this format really should have had a per vertexweight weight value...
+                               mesh->data_vertexboneweights[mesh->num_vertexboneweights].vertexindex = remapvertices[j];
+                               mesh->data_vertexboneweights[mesh->num_vertexboneweights].boneindex = verts[l].bonenum;
+                               mesh->data_vertexboneweights[mesh->num_vertexboneweights].origin[3] = 1.0f / vertbonecounts[j];
+                               mesh->data_vertexboneweights[mesh->num_vertexboneweights].origin[0] = verts[l].origin[0] * mesh->data_vertexboneweights[mesh->num_vertexboneweights].origin[3];
+                               mesh->data_vertexboneweights[mesh->num_vertexboneweights].origin[1] = verts[l].origin[1] * mesh->data_vertexboneweights[mesh->num_vertexboneweights].origin[3];
+                               mesh->data_vertexboneweights[mesh->num_vertexboneweights].origin[2] = verts[l].origin[2] * mesh->data_vertexboneweights[mesh->num_vertexboneweights].origin[3];
+                               mesh->num_vertexboneweights++;
+                               l++;
                        }
                }
-       }
 
-       {
-               int i;
-               char *shadername;
-       //      zymlump_t lump_shaders; // char shadername[numshaders][32]; // shaders used on this model
-               loadmodel->alias.zymdata_textures = Mem_Alloc(loadmodel->mempool, pheader->numshaders * sizeof(rtexture_t *));
-               shadername = (void *) (pheader->lump_shaders.start + pbase);
-               for (i = 0;i < pheader->numshaders;i++)
-                       loadmodel->alias.zymdata_textures[i] = loadtextureimage(loadmodel->texturepool, shadername + i * 32, 0, 0, true, TEXF_ALPHA | TEXF_PRECACHE | TEXF_PICMIP | (r_mipskins.integer ? TEXF_MIPMAP : 0));
-       }
+               Mod_ValidateElements(mesh->data_element3i, mesh->num_triangles, mesh->num_vertices, __FILE__, __LINE__);
+               Mod_BuildTriangleNeighbors(mesh->data_neighbor3i, mesh->data_element3i, mesh->num_triangles);
 
-       {
-       //      zymlump_t lump_trizone; // byte trizone[numtris]; // see trizone explanation
-               loadmodel->alias.zymdata_trizone = Mem_Alloc(loadmodel->mempool, pheader->numtris);
-               memcpy(loadmodel->alias.zymdata_trizone, (void *) (pheader->lump_trizone.start + pbase), pheader->numtris);
+               // since zym models do not have named sections, reuse their shader
+               // name as the section name
+               shadername = (char *) (pheader->lump_shaders.start + pbase) + i * 32;
+               if (shadername[0])
+                       Mod_BuildAliasSkinsFromSkinFiles(mesh->data_skins, skinfiles, shadername, shadername);
+               else
+                       for (j = 0;j < mesh->num_skins;j++)
+                               Mod_BuildAliasSkinFromSkinFrame(mesh->data_skins + j, NULL);
        }
+
+       Mem_Free(vertbonecounts);
+       Mem_Free(verts);
+       Mem_Free(outtexcoord2f);
 }
 
index ba62714..f8c81f7 100644 (file)
@@ -116,10 +116,6 @@ typedef struct
        int                     ofs_end;                // end of file
 } md2_t;
 
-// LordHavoc: mdl, md2 and md3 models are converted to the same internal format
-#define ALIASTYPE_ALIAS 1
-#define ALIASTYPE_ZYM 2
-
 extern void Mod_IDP0_Load(struct model_s *mod, void *buffer);
 extern void Mod_IDP2_Load(struct model_s *mod, void *buffer);
 extern void Mod_IDP3_Load(struct model_s *mod, void *buffer);
@@ -253,20 +249,37 @@ typedef struct aliasskin_s
 }
 aliasskin_t;
 
+typedef struct aliasvertexboneweight_s
+{
+       unsigned int vertexindex;
+       unsigned int boneindex;
+       float origin[3];
+       float weight;
+}
+aliasvertexboneweight_t;
+
 typedef struct aliasmesh_s
 {
+       // skins to choose from (indexed by entity skin)
        int num_skins;
-       int num_triangles;
-       int num_frames;
-       int num_vertices;
        aliasskin_t *data_skins;
+
+       // triangles comprising the mesh
+       int num_triangles;
        int *data_element3i;
        int *data_neighbor3i;
+
+       // skin texcoords do not change
+       int num_vertices;
        float *data_texcoord2f;
-       float *data_aliasvertex3f;
-       float *data_aliassvector3f;
-       float *data_aliastvector3f;
-       float *data_aliasnormal3f;
+
+       // morph blending, these are zero if model is skeletal
+       int num_morphframes;
+       float *data_morphvertex3f;
+
+       // skeletal blending, these are zero if model is morph
+       int num_vertexboneweights;
+       aliasvertexboneweight_t *data_vertexboneweights;
 }
 aliasmesh_t;
 
@@ -277,6 +290,13 @@ typedef struct aliastag_s
 }
 aliastag_t;
 
+typedef struct aliasbone_s
+{
+       char name[MD3NAME];
+       int flags;
+       int parent; // -1 for no parent
+}
+aliasbone_t;
 
 #endif
 
index 9081ccc..f2a0ccc 100644 (file)
@@ -489,6 +489,20 @@ static void Mod_Precache(void)
                Con_Print("usage: modelprecache <filename>\n");
 }
 
+int Mod_BuildVertexRemapTableFromElements(int numelements, const int *elements, int numvertices, int *remapvertices)
+{
+       int i, count;
+       qbyte *used;
+       used = Mem_Alloc(tempmempool, numvertices);
+       memset(used, 0, numvertices);
+       for (i = 0;i < numelements;i++)
+               used[elements[i]] = 1;
+       for (i = 0, count = 0;i < numvertices;i++)
+               remapvertices[i] = used[i] ? count++ : -1;
+       Mem_Free(used);
+       return count;
+}
+
 #if 1
 // fast way, using an edge hash
 #define TRIANGLEEDGEHASH 1024
index 45165a4..f7f9d49 100644 (file)
@@ -117,31 +117,22 @@ shadowmesh_t;
 
 typedef struct model_alias_s
 {
-       // LordHavoc: Q2/ZYM model support
-       int                             aliastype;
+       // mdl/md2/md3/zym model formats are treated the same after loading
 
-       // mdl/md2/md3 models are the same after loading
+       // the shader meshes comprising this model
        int                             aliasnum_meshes;
        aliasmesh_t             *aliasdata_meshes;
 
+       // for md3 models
        int                             aliasnum_tags;
        int                             aliasnum_tagframes;
        aliastag_t              *aliasdata_tags;
 
-       // for Zymotic models
-       int                             zymnum_verts;
-       int                             zymnum_tris;
-       int                             zymnum_shaders;
-       int                             zymnum_bones;
-       int                             zymnum_scenes;
-       float                   *zymdata_texcoords;
-       rtexture_t              **zymdata_textures;
-       qbyte                   *zymdata_trizone;
-       zymbone_t               *zymdata_bones;
-       unsigned int    *zymdata_vertbonecounts;
-       zymvertex_t             *zymdata_verts;
-       unsigned int    *zymdata_renderlist;
-       float                   *zymdata_poses;
+       // for skeletal models
+       int                             aliasnum_bones;
+       aliasbone_t             *aliasdata_bones;
+       int                             aliasnum_poses;
+       float                   *aliasdata_poses;
 }
 model_alias_t;
 
@@ -647,6 +638,7 @@ void Mod_LoadModels(void);
 extern model_t *loadmodel;
 extern char loadname[32];      // for hunk tags
 
+int Mod_BuildVertexRemapTableFromElements(int numelements, const int *elements, int numvertices, int *remapvertices);
 void Mod_BuildTriangleNeighbors(int *neighbors, const int *elements, int numtriangles);
 void Mod_ValidateElements(const int *elements, int numtriangles, int numverts, const char *filename, int fileline);
 void Mod_BuildTextureVectorsAndNormals(int numverts, int numtriangles, const float *vertex, const float *texcoord, const int *elements, float *svectors, float *tvectors, float *normals);
index 35f70c0..217bc7d 100644 (file)
--- a/pr_cmds.c
+++ b/pr_cmds.c
@@ -3115,6 +3115,7 @@ void PF_setattachment (void)
                                for (i = 0;i < model->data_overridetagnamesforskin[(unsigned int)tagentity->v->skin].num_overridetagnames;i++)
                                        if (!strcmp(tagname, model->data_overridetagnamesforskin[(unsigned int)tagentity->v->skin].data_overridetagnames[i].name))
                                                v->_float = i + 1;
+                       // FIXME: use a model function to get tag info (need to handle skeletal)
                        if (v->_float == 0 && model->alias.aliasnum_tags)
                                for (i = 0;i < model->alias.aliasnum_tags;i++)
                                        if (!strcmp(tagname, model->alias.aliasdata_tags[i].name))
index 6b8abd7..67cd6f9 100644 (file)
@@ -2117,6 +2117,7 @@ void PF_setattachment (void)
                                for (i = 0;i < model->data_overridetagnamesforskin[(unsigned int)tagentity->v->skin].num_overridetagnames;i++)
                                        if (!strcmp(tagname, model->data_overridetagnamesforskin[(unsigned int)tagentity->v->skin].data_overridetagnames[i].name))
                                                v->_float = i + 1;
+                       // FIXME: use a model function to get tag info (need to handle skeletal)
                        if (v->_float == 0 && model->alias.aliasnum_tags)
                                for (i = 0;i < model->alias.aliasnum_tags;i++)
                                        if (!strcmp(tagname, model->alias.aliasdata_tags[i].name))
index d1194f3..6a4fa82 100644 (file)
--- a/render.h
+++ b/render.h
@@ -59,11 +59,6 @@ extern char r_speeds_string[1024];
 // lighting stuff
 extern cvar_t r_ambient;
 
-// model rendering stuff
-extern float *aliasvert;
-extern float *aliasvertnorm;
-extern float *aliasvertcolor;
-
 // vis stuff
 extern cvar_t r_novis;