eliminated model->meshlist, replaced with an embedded model->surfmesh to cut down...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 29 Mar 2006 11:11:46 +0000 (11:11 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 29 Mar 2006 11:11:46 +0000 (11:11 +0000)
some minor optimizations of code to keep track of ent->model in a local variable rather than dereferencing ent every time

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

12 files changed:
cl_main.c
clvm_cmds.c
gl_rmain.c
gl_rsurf.c
model_alias.c
model_brush.c
model_shared.c
model_shared.h
portals.c
r_shadow.c
r_sprites.c
svvm_cmds.c

index 99a2c13..8c41941 100644 (file)
--- a/cl_main.c
+++ b/cl_main.c
@@ -405,44 +405,45 @@ static void CL_PrintEntities_f(void)
 //static const vec3_t nomodelmaxs = {16, 16, 16};
 void CL_BoundingBoxForEntity(entity_render_t *ent)
 {
-       if (ent->model)
+       model_t *model = ent->model;
+       if (model)
        {
                //if (ent->angles[0] || ent->angles[2])
                if (ent->matrix.m[2][0] != 0 || ent->matrix.m[2][1] != 0)
                {
                        // pitch or roll
-                       ent->mins[0] = ent->matrix.m[0][3] + ent->model->rotatedmins[0];
-                       ent->mins[1] = ent->matrix.m[1][3] + ent->model->rotatedmins[1];
-                       ent->mins[2] = ent->matrix.m[2][3] + ent->model->rotatedmins[2];
-                       ent->maxs[0] = ent->matrix.m[0][3] + ent->model->rotatedmaxs[0];
-                       ent->maxs[1] = ent->matrix.m[1][3] + ent->model->rotatedmaxs[1];
-                       ent->maxs[2] = ent->matrix.m[2][3] + ent->model->rotatedmaxs[2];
-                       //VectorAdd(ent->origin, ent->model->rotatedmins, ent->mins);
-                       //VectorAdd(ent->origin, ent->model->rotatedmaxs, ent->maxs);
+                       ent->mins[0] = ent->matrix.m[0][3] + model->rotatedmins[0];
+                       ent->mins[1] = ent->matrix.m[1][3] + model->rotatedmins[1];
+                       ent->mins[2] = ent->matrix.m[2][3] + model->rotatedmins[2];
+                       ent->maxs[0] = ent->matrix.m[0][3] + model->rotatedmaxs[0];
+                       ent->maxs[1] = ent->matrix.m[1][3] + model->rotatedmaxs[1];
+                       ent->maxs[2] = ent->matrix.m[2][3] + model->rotatedmaxs[2];
+                       //VectorAdd(ent->origin, model->rotatedmins, ent->mins);
+                       //VectorAdd(ent->origin, model->rotatedmaxs, ent->maxs);
                }
                //else if (ent->angles[1])
                else if (ent->matrix.m[0][1] != 0 || ent->matrix.m[1][0] != 0)
                {
                        // yaw
-                       ent->mins[0] = ent->matrix.m[0][3] + ent->model->yawmins[0];
-                       ent->mins[1] = ent->matrix.m[1][3] + ent->model->yawmins[1];
-                       ent->mins[2] = ent->matrix.m[2][3] + ent->model->yawmins[2];
-                       ent->maxs[0] = ent->matrix.m[0][3] + ent->model->yawmaxs[0];
-                       ent->maxs[1] = ent->matrix.m[1][3] + ent->model->yawmaxs[1];
-                       ent->maxs[2] = ent->matrix.m[2][3] + ent->model->yawmaxs[2];
-                       //VectorAdd(ent->origin, ent->model->yawmins, ent->mins);
-                       //VectorAdd(ent->origin, ent->model->yawmaxs, ent->maxs);
+                       ent->mins[0] = ent->matrix.m[0][3] + model->yawmins[0];
+                       ent->mins[1] = ent->matrix.m[1][3] + model->yawmins[1];
+                       ent->mins[2] = ent->matrix.m[2][3] + model->yawmins[2];
+                       ent->maxs[0] = ent->matrix.m[0][3] + model->yawmaxs[0];
+                       ent->maxs[1] = ent->matrix.m[1][3] + model->yawmaxs[1];
+                       ent->maxs[2] = ent->matrix.m[2][3] + model->yawmaxs[2];
+                       //VectorAdd(ent->origin, model->yawmins, ent->mins);
+                       //VectorAdd(ent->origin, model->yawmaxs, ent->maxs);
                }
                else
                {
-                       ent->mins[0] = ent->matrix.m[0][3] + ent->model->normalmins[0];
-                       ent->mins[1] = ent->matrix.m[1][3] + ent->model->normalmins[1];
-                       ent->mins[2] = ent->matrix.m[2][3] + ent->model->normalmins[2];
-                       ent->maxs[0] = ent->matrix.m[0][3] + ent->model->normalmaxs[0];
-                       ent->maxs[1] = ent->matrix.m[1][3] + ent->model->normalmaxs[1];
-                       ent->maxs[2] = ent->matrix.m[2][3] + ent->model->normalmaxs[2];
-                       //VectorAdd(ent->origin, ent->model->normalmins, ent->mins);
-                       //VectorAdd(ent->origin, ent->model->normalmaxs, ent->maxs);
+                       ent->mins[0] = ent->matrix.m[0][3] + model->normalmins[0];
+                       ent->mins[1] = ent->matrix.m[1][3] + model->normalmins[1];
+                       ent->mins[2] = ent->matrix.m[2][3] + model->normalmins[2];
+                       ent->maxs[0] = ent->matrix.m[0][3] + model->normalmaxs[0];
+                       ent->maxs[1] = ent->matrix.m[1][3] + model->normalmaxs[1];
+                       ent->maxs[2] = ent->matrix.m[2][3] + model->normalmaxs[2];
+                       //VectorAdd(ent->origin, model->normalmins, ent->mins);
+                       //VectorAdd(ent->origin, model->normalmaxs, ent->maxs);
                }
        }
        else
index 6c132ee..4b155e4 100644 (file)
@@ -1976,7 +1976,7 @@ void VM_CL_te_plasmaburn (void)
 //DP_QC_GETSURFACE
 
 void clippointtosurface(msurface_t *surface, vec3_t p, vec3_t out);
-static msurface_t *cl_getsurface(prvm_edict_t *ed, int surfacenum)
+static model_t *cl_getmodel(prvm_edict_t *ed)
 {
        int modelindex;
        model_t *model = NULL;
@@ -1996,8 +1996,11 @@ static msurface_t *cl_getsurface(prvm_edict_t *ed, int surfacenum)
                if(modelindex < MAX_MODELS)
                        model = cl.model_precache[modelindex];
        }
-       if(!model)
-               return NULL;
+       return model;
+}
+
+static msurface_t *cl_getsurface(model_t *model, int surfacenum)
+{
        if (surfacenum < 0 || surfacenum >= model->nummodelsurfaces)
                return NULL;
        return model->data_surfaces + surfacenum + model->firstmodelsurface;
@@ -2006,9 +2009,10 @@ static msurface_t *cl_getsurface(prvm_edict_t *ed, int surfacenum)
 // #434 float(entity e, float s) getsurfacenumpoints
 void VM_CL_getsurfacenumpoints(void)
 {
+       model_t *model = cl_getmodel(PRVM_G_EDICT(OFS_PARM0));
        msurface_t *surface;
        // return 0 if no such surface
-       if (!(surface = cl_getsurface(PRVM_G_EDICT(OFS_PARM0), PRVM_G_FLOAT(OFS_PARM1))))
+       if (!model || !(surface = cl_getsurface(model, PRVM_G_FLOAT(OFS_PARM1))))
        {
                PRVM_G_FLOAT(OFS_RETURN) = 0;
                return;
@@ -2022,35 +2026,35 @@ void VM_CL_getsurfacenumpoints(void)
 void VM_CL_getsurfacepoint(void)
 {
        prvm_edict_t *ed;
+       model_t *model;
        msurface_t *surface;
        int pointnum;
        VectorClear(PRVM_G_VECTOR(OFS_RETURN));
        ed = PRVM_G_EDICT(OFS_PARM0);
-       if (!ed || ed->priv.server->free)
-               return;
-       if (!(surface = cl_getsurface(ed, PRVM_G_FLOAT(OFS_PARM1))))
+       if (!(model = cl_getmodel(ed)) || !(surface = cl_getsurface(model, PRVM_G_FLOAT(OFS_PARM1))))
                return;
        // note: this (incorrectly) assumes it is a simple polygon
        pointnum = PRVM_G_FLOAT(OFS_PARM2);
        if (pointnum < 0 || pointnum >= surface->num_vertices)
                return;
        // FIXME: implement rotation/scaling
-       VectorAdd(&(surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex)[pointnum * 3], ed->fields.client->origin, PRVM_G_VECTOR(OFS_RETURN));
+       VectorAdd(&(model->surfmesh.data_vertex3f + 3 * surface->num_firstvertex)[pointnum * 3], ed->fields.client->origin, PRVM_G_VECTOR(OFS_RETURN));
 }
 
 // #436 vector(entity e, float s) getsurfacenormal
 void VM_CL_getsurfacenormal(void)
 {
+       model_t *model;
        msurface_t *surface;
        vec3_t normal;
        VectorClear(PRVM_G_VECTOR(OFS_RETURN));
-       if (!(surface = cl_getsurface(PRVM_G_EDICT(OFS_PARM0), PRVM_G_FLOAT(OFS_PARM1))))
+       if (!(model = cl_getmodel(PRVM_G_EDICT(OFS_PARM0))) || !(surface = cl_getsurface(model, PRVM_G_FLOAT(OFS_PARM1))))
                return;
        // FIXME: implement rotation/scaling
        // note: this (incorrectly) assumes it is a simple polygon
        // note: this only returns the first triangle, so it doesn't work very
        // well for curved surfaces or arbitrary meshes
-       TriangleNormal((surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex), (surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex) + 3, (surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex) + 6, normal);
+       TriangleNormal((model->surfmesh.data_vertex3f + 3 * surface->num_firstvertex), (model->surfmesh.data_vertex3f + 3 * surface->num_firstvertex) + 3, (model->surfmesh.data_vertex3f + 3 * surface->num_firstvertex) + 6, normal);
        VectorNormalize(normal);
        VectorCopy(normal, PRVM_G_VECTOR(OFS_RETURN));
 }
@@ -2058,9 +2062,10 @@ void VM_CL_getsurfacenormal(void)
 // #437 string(entity e, float s) getsurfacetexture
 void VM_CL_getsurfacetexture(void)
 {
+       model_t *model;
        msurface_t *surface;
        PRVM_G_INT(OFS_RETURN) = 0;
-       if (!(surface = cl_getsurface(PRVM_G_EDICT(OFS_PARM0), PRVM_G_FLOAT(OFS_PARM1))))
+       if (!(model = cl_getmodel(PRVM_G_EDICT(OFS_PARM0))) || !(surface = cl_getsurface(model, PRVM_G_FLOAT(OFS_PARM1))))
                return;
        PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(surface->texture->name);
 }
@@ -2068,7 +2073,7 @@ void VM_CL_getsurfacetexture(void)
 // #438 float(entity e, vector p) getsurfacenearpoint
 void VM_CL_getsurfacenearpoint(void)
 {
-       int surfacenum, best, modelindex;
+       int surfacenum, best;
        vec3_t clipped, p;
        vec_t dist, bestdist;
        prvm_edict_t *ed;
@@ -2077,28 +2082,11 @@ void VM_CL_getsurfacenearpoint(void)
        vec_t *point;
        PRVM_G_FLOAT(OFS_RETURN) = -1;
        ed = PRVM_G_EDICT(OFS_PARM0);
-       point = PRVM_G_VECTOR(OFS_PARM1);
-
-       if (!ed || ed->priv.server->free)
-               return;
-       modelindex = ed->fields.client->modelindex;
-       if(!modelindex)
-               return;
-       if(modelindex<0)
-       {
-               modelindex = -(modelindex+1);
-               if(modelindex < MAX_MODELS)
-                       model = cl.csqc_model_precache[modelindex];
-       }
-       else
-               if(modelindex < MAX_MODELS)
-                       model = cl.model_precache[modelindex];
-       if(!model)
-               return;
-       if (!model->num_surfaces)
+       if(!(model = cl_getmodel(ed)) || !model->num_surfaces)
                return;
 
        // FIXME: implement rotation/scaling
+       point = PRVM_G_VECTOR(OFS_PARM1);
        VectorSubtract(point, ed->fields.client->origin, p);
        best = -1;
        bestdist = 1000000000;
@@ -2131,13 +2119,12 @@ void VM_CL_getsurfacenearpoint(void)
 void VM_CL_getsurfaceclippedpoint(void)
 {
        prvm_edict_t *ed;
+       model_t *model;
        msurface_t *surface;
        vec3_t p, out;
        VectorClear(PRVM_G_VECTOR(OFS_RETURN));
        ed = PRVM_G_EDICT(OFS_PARM0);
-       if (!ed || ed->priv.server->free)
-               return;
-       if (!(surface = cl_getsurface(ed, PRVM_G_FLOAT(OFS_PARM1))))
+       if (!(model = cl_getmodel(ed)) || !(surface = cl_getsurface(model, PRVM_G_FLOAT(OFS_PARM1))))
                return;
        // FIXME: implement rotation/scaling
        VectorSubtract(PRVM_G_VECTOR(OFS_PARM2), ed->fields.client->origin, p);
index a98dade..1a566d4 100644 (file)
@@ -2581,18 +2581,19 @@ float *rsurface_lightmapcolor4f;
 
 void RSurf_SetVertexPointer(const entity_render_t *ent, const texture_t *texture, const msurface_t *surface, const vec3_t modelorg, qboolean generatenormals, qboolean generatetangents)
 {
-       if (rsurface_array_size < surface->groupmesh->num_vertices)
-               R_Mesh_ResizeArrays(surface->groupmesh->num_vertices);
-       if ((ent->frameblend[0].lerp != 1 || ent->frameblend[0].frame != 0) && (surface->groupmesh->data_morphvertex3f || surface->groupmesh->data_vertexboneweights))
+       model_t *model = ent->model;
+       if (rsurface_array_size < model->surfmesh.num_vertices)
+               R_Mesh_ResizeArrays(model->surfmesh.num_vertices);
+       if ((ent->frameblend[0].lerp != 1 || ent->frameblend[0].frame != 0) && (model->surfmesh.data_morphvertex3f || model->surfmesh.data_vertexboneweights))
        {
                rsurface_vertex3f = rsurface_array_vertex3f;
-               Mod_Alias_GetMesh_Vertex3f(ent->model, ent->frameblend, surface->groupmesh, rsurface_vertex3f);
+               Mod_Alias_GetMesh_Vertex3f(model, ent->frameblend, rsurface_vertex3f);
                if (generatetangents || (texture->textureflags & (Q3TEXTUREFLAG_AUTOSPRITE | Q3TEXTUREFLAG_AUTOSPRITE2)))
                {
                        rsurface_svector3f = rsurface_array_svector3f;
                        rsurface_tvector3f = rsurface_array_tvector3f;
                        rsurface_normal3f = rsurface_array_normal3f;
-                       Mod_BuildTextureVectorsAndNormals(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, rsurface_vertex3f, surface->groupmesh->data_texcoordtexture2f, surface->groupmesh->data_element3i + surface->num_firsttriangle * 3, rsurface_svector3f, rsurface_tvector3f, rsurface_normal3f, r_smoothnormals_areaweighting.integer);
+                       Mod_BuildTextureVectorsAndNormals(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, rsurface_vertex3f, model->surfmesh.data_texcoordtexture2f, model->surfmesh.data_element3i + surface->num_firsttriangle * 3, rsurface_svector3f, rsurface_tvector3f, rsurface_normal3f, r_smoothnormals_areaweighting.integer);
                }
                else
                {
@@ -2601,7 +2602,7 @@ void RSurf_SetVertexPointer(const entity_render_t *ent, const texture_t *texture
                        if (generatenormals)
                        {
                                rsurface_normal3f = rsurface_array_normal3f;
-                               Mod_BuildNormals(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, rsurface_vertex3f, surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle, rsurface_normal3f, r_smoothnormals_areaweighting.integer);
+                               Mod_BuildNormals(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, rsurface_vertex3f, model->surfmesh.data_element3i + 3 * surface->num_firsttriangle, rsurface_normal3f, r_smoothnormals_areaweighting.integer);
                        }
                        else
                                rsurface_normal3f = NULL;
@@ -2609,10 +2610,10 @@ void RSurf_SetVertexPointer(const entity_render_t *ent, const texture_t *texture
        }
        else
        {
-               rsurface_vertex3f = surface->groupmesh->data_vertex3f;
-               rsurface_svector3f = surface->groupmesh->data_svector3f;
-               rsurface_tvector3f = surface->groupmesh->data_tvector3f;
-               rsurface_normal3f = surface->groupmesh->data_normal3f;
+               rsurface_vertex3f = model->surfmesh.data_vertex3f;
+               rsurface_svector3f = model->surfmesh.data_svector3f;
+               rsurface_tvector3f = model->surfmesh.data_tvector3f;
+               rsurface_normal3f = model->surfmesh.data_normal3f;
        }
        if (texture->textureflags & (Q3TEXTUREFLAG_AUTOSPRITE | Q3TEXTUREFLAG_AUTOSPRITE2))
        {
@@ -2652,15 +2653,15 @@ void RSurf_SetVertexPointer(const entity_render_t *ent, const texture_t *texture
                rsurface_svector3f = rsurface_array_svector3f;
                rsurface_tvector3f = rsurface_array_tvector3f;
                rsurface_normal3f = rsurface_array_normal3f;
-               Mod_BuildTextureVectorsAndNormals(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, rsurface_vertex3f, surface->groupmesh->data_texcoordtexture2f, surface->groupmesh->data_element3i + surface->num_firsttriangle * 3, rsurface_svector3f, rsurface_tvector3f, rsurface_normal3f, r_smoothnormals_areaweighting.integer);
+               Mod_BuildTextureVectorsAndNormals(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, rsurface_vertex3f, model->surfmesh.data_texcoordtexture2f, model->surfmesh.data_element3i + surface->num_firsttriangle * 3, rsurface_svector3f, rsurface_tvector3f, rsurface_normal3f, r_smoothnormals_areaweighting.integer);
        }
        R_Mesh_VertexPointer(rsurface_vertex3f);
 }
 
-static void RSurf_Draw(const msurface_t *surface)
+static void RSurf_Draw(model_t *model, const msurface_t *surface)
 {
        GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
-       R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
+       R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (model->surfmesh.data_element3i + 3 * surface->num_firsttriangle));
        GL_LockArrays(0, 0);
 }
 
@@ -2669,6 +2670,7 @@ static void RSurf_DrawLightmap(const entity_render_t *ent, const texture_t *text
        int i;
        float f;
        float *v, *c, *c2;
+       model_t *model = ent->model;
        RSurf_SetVertexPointer(ent, texture, surface, modelorg, lightmode >= 2, false);
        if (lightmode >= 2)
        {
@@ -2721,7 +2723,7 @@ static void RSurf_DrawLightmap(const entity_render_t *ent, const texture_t *text
                        {
                                if (surface->lightmapinfo->samples)
                                {
-                                       const unsigned char *lm = surface->lightmapinfo->samples + (surface->groupmesh->data_lightmapoffsets + surface->num_firstvertex)[i];
+                                       const unsigned char *lm = surface->lightmapinfo->samples + (model->surfmesh.data_lightmapoffsets + surface->num_firstvertex)[i];
                                        float scale = r_refdef.lightstylevalue[surface->lightmapinfo->styles[0]] * (1.0f / 32768.0f);
                                        VectorScale(lm, scale, c);
                                        if (surface->lightmapinfo->styles[1] != 255)
@@ -2750,7 +2752,7 @@ static void RSurf_DrawLightmap(const entity_render_t *ent, const texture_t *text
                        rsurface_lightmapcolor4f = rsurface_array_color4f;
                }
                else
-                       rsurface_lightmapcolor4f = surface->groupmesh->data_lightmapcolor4f;
+                       rsurface_lightmapcolor4f = model->surfmesh.data_lightmapcolor4f;
        }
        else
                rsurface_lightmapcolor4f = NULL;
@@ -2793,7 +2795,7 @@ static void RSurf_DrawLightmap(const entity_render_t *ent, const texture_t *text
        }
        R_Mesh_ColorPointer(rsurface_lightmapcolor4f);
        GL_Color(r, g, b, a);
-       RSurf_Draw(surface);
+       RSurf_Draw(model, surface);
 }
 
 static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *texture, int texturenumsurfaces, const msurface_t **texturesurfacelist, const vec3_t modelorg)
@@ -2801,6 +2803,7 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
        int texturesurfaceindex;
        int lightmode;
        const msurface_t *surface;
+       model_t *model = ent->model;
        qboolean applycolor;
        qboolean applyfog;
        rmeshstate_t m;
@@ -2808,8 +2811,8 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                return;
        r_shadow_rtlight = NULL;
        renderstats.entities_surfaces += texturenumsurfaces;
-       // FIXME: identify models using a better check than ent->model->brush.shadowmesh
-       lightmode = ((ent->effects & EF_FULLBRIGHT) || ent->model->brush.shadowmesh) ? 0 : 2;
+       // FIXME: identify models using a better check than model->brush.shadowmesh
+       lightmode = ((ent->effects & EF_FULLBRIGHT) || model->brush.shadowmesh) ? 0 : 2;
        GL_DepthTest(!(texture->currentmaterialflags & MATERIALFLAG_NODEPTHTEST));
        if ((texture->textureflags & Q3TEXTUREFLAG_TWOSIDED) || (ent->flags & RENDER_NOCULLFACE))
                qglDisable(GL_CULL_FACE);
@@ -2830,7 +2833,7 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                        // LordHavoc: Quake3 never did sky masking (unlike software Quake
                        // and Quake2), so disable the sky masking in Quake3 maps as it
                        // causes problems with q3map2 sky tricks
-                       if (!ent->model->brush.ishlbsp && ent->model->type != mod_brushq3)
+                       if (!model->brush.ishlbsp && model->type != mod_brushq3)
                        {
                                GL_Color(fogcolor[0], fogcolor[1], fogcolor[2], 1);
                                memset(&m, 0, sizeof(m));
@@ -2852,7 +2855,7 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                                {
                                        surface = texturesurfacelist[texturesurfaceindex];
                                        RSurf_SetVertexPointer(ent, texture, surface, modelorg, false, false);
-                                       RSurf_Draw(surface);
+                                       RSurf_Draw(model, surface);
                                }
                                if (skyrendermasked)
                                        GL_ColorMask(r_refdef.colormask[0], r_refdef.colormask[1], r_refdef.colormask[2], 1);
@@ -2889,11 +2892,11 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                        {
                                surface = texturesurfacelist[texturesurfaceindex];
                                RSurf_SetVertexPointer(ent, texture, surface, modelorg, false, true);
-                               R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoordtexture2f);
+                               R_Mesh_TexCoordPointer(0, 2, model->surfmesh.data_texcoordtexture2f);
                                R_Mesh_TexCoordPointer(1, 3, rsurface_svector3f);
                                R_Mesh_TexCoordPointer(2, 3, rsurface_tvector3f);
                                R_Mesh_TexCoordPointer(3, 3, rsurface_normal3f);
-                               RSurf_Draw(surface);
+                               RSurf_Draw(model, surface);
                        }
                }
                else
@@ -2902,11 +2905,11 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                        {
                                surface = texturesurfacelist[texturesurfaceindex];
                                RSurf_SetVertexPointer(ent, texture, surface, modelorg, false, true);
-                               R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoordtexture2f);
+                               R_Mesh_TexCoordPointer(0, 2, model->surfmesh.data_texcoordtexture2f);
                                R_Mesh_TexCoordPointer(1, 3, rsurface_svector3f);
                                R_Mesh_TexCoordPointer(2, 3, rsurface_tvector3f);
                                R_Mesh_TexCoordPointer(3, 3, rsurface_normal3f);
-                               R_Mesh_TexCoordPointer(4, 2, surface->groupmesh->data_texcoordlightmap2f);
+                               R_Mesh_TexCoordPointer(4, 2, model->surfmesh.data_texcoordlightmap2f);
                                if (surface->lightmaptexture)
                                {
                                        R_Mesh_TexBind(7, R_GetTexture(surface->lightmaptexture));
@@ -2919,9 +2922,9 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                                        R_Mesh_TexBind(7, R_GetTexture(r_texture_white));
                                        if (r_glsl_permutation->loc_Texture_Deluxemap >= 0)
                                                R_Mesh_TexBind(8, R_GetTexture(r_texture_blanknormalmap));
-                                       R_Mesh_ColorPointer(surface->groupmesh->data_lightmapcolor4f);
+                                       R_Mesh_ColorPointer(model->surfmesh.data_lightmapcolor4f);
                                }
-                               RSurf_Draw(surface);
+                               RSurf_Draw(model, surface);
                        }
                }
                qglUseProgramObjectARB(0);
@@ -2969,8 +2972,8 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                                        for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                                        {
                                                surface = texturesurfacelist[texturesurfaceindex];
-                                               R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoordlightmap2f);
-                                               R_Mesh_TexCoordPointer(1, 2, surface->groupmesh->data_texcoordtexture2f);
+                                               R_Mesh_TexCoordPointer(0, 2, model->surfmesh.data_texcoordlightmap2f);
+                                               R_Mesh_TexCoordPointer(1, 2, model->surfmesh.data_texcoordtexture2f);
                                                R_Mesh_TexBind(0, R_GetTexture(r_texture_white));
                                                RSurf_DrawLightmap(ent, texture, surface, modelorg, layercolor[0], layercolor[1], layercolor[2], layercolor[3], 2, applycolor, applyfog);
                                        }
@@ -2980,8 +2983,8 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                                        for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                                        {
                                                surface = texturesurfacelist[texturesurfaceindex];
-                                               R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoordlightmap2f);
-                                               R_Mesh_TexCoordPointer(1, 2, surface->groupmesh->data_texcoordtexture2f);
+                                               R_Mesh_TexCoordPointer(0, 2, model->surfmesh.data_texcoordlightmap2f);
+                                               R_Mesh_TexCoordPointer(1, 2, model->surfmesh.data_texcoordtexture2f);
                                                if (surface->lightmaptexture)
                                                {
                                                        R_Mesh_TexBind(0, R_GetTexture(surface->lightmaptexture));
@@ -3007,7 +3010,7 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                                        for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                                        {
                                                surface = texturesurfacelist[texturesurfaceindex];
-                                               R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoordlightmap2f);
+                                               R_Mesh_TexCoordPointer(0, 2, model->surfmesh.data_texcoordlightmap2f);
                                                R_Mesh_TexBind(0, R_GetTexture(r_texture_white));
                                                RSurf_DrawLightmap(ent, texture, surface, modelorg, 1, 1, 1, 1, 2, false, false);
                                        }
@@ -3017,7 +3020,7 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                                        for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                                        {
                                                surface = texturesurfacelist[texturesurfaceindex];
-                                               R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoordlightmap2f);
+                                               R_Mesh_TexCoordPointer(0, 2, model->surfmesh.data_texcoordlightmap2f);
                                                if (surface->lightmaptexture)
                                                {
                                                        R_Mesh_TexBind(0, R_GetTexture(surface->lightmaptexture));
@@ -3040,7 +3043,7 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                                for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                                {
                                        surface = texturesurfacelist[texturesurfaceindex];
-                                       R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoordtexture2f);
+                                       R_Mesh_TexCoordPointer(0, 2, model->surfmesh.data_texcoordtexture2f);
                                        RSurf_DrawLightmap(ent, texture, surface, modelorg, layercolor[0], layercolor[1], layercolor[2], layercolor[3], 0, applycolor, applyfog);
                                }
                                break;
@@ -3056,7 +3059,7 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                                        for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                                        {
                                                surface = texturesurfacelist[texturesurfaceindex];
-                                               R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoordtexture2f);
+                                               R_Mesh_TexCoordPointer(0, 2, model->surfmesh.data_texcoordtexture2f);
                                                RSurf_DrawLightmap(ent, texture, surface, modelorg, layercolor[0], layercolor[1], layercolor[2], layercolor[3], 2, applycolor, applyfog);
                                        }
                                }
@@ -3065,7 +3068,7 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                                        for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                                        {
                                                surface = texturesurfacelist[texturesurfaceindex];
-                                               R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoordtexture2f);
+                                               R_Mesh_TexCoordPointer(0, 2, model->surfmesh.data_texcoordtexture2f);
                                                RSurf_DrawLightmap(ent, texture, surface, modelorg, layercolor[0], layercolor[1], layercolor[2], layercolor[3], 1, applycolor, applyfog);
                                        }
                                }
@@ -3080,7 +3083,7 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                                for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                                {
                                        surface = texturesurfacelist[texturesurfaceindex];
-                                       R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoordtexture2f);
+                                       R_Mesh_TexCoordPointer(0, 2, model->surfmesh.data_texcoordtexture2f);
                                        RSurf_DrawLightmap(ent, texture, surface, modelorg, layercolor[0], layercolor[1], layercolor[2], layercolor[3], 0, applycolor, applyfog);
                                }
                                break;
@@ -3099,7 +3102,7 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                                        surface = texturesurfacelist[texturesurfaceindex];
                                        RSurf_SetVertexPointer(ent, texture, surface, modelorg, false, false);
                                        if (layer->texture)
-                                               R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoordtexture2f);
+                                               R_Mesh_TexCoordPointer(0, 2, model->surfmesh.data_texcoordtexture2f);
                                        R_Mesh_ColorPointer(rsurface_array_color4f);
                                        for (i = 0, v = (rsurface_vertex3f + 3 * surface->num_firstvertex), c = (rsurface_array_color4f + 4 * surface->num_firstvertex);i < surface->num_vertices;i++, v += 3, c += 4)
                                        {
@@ -3109,7 +3112,7 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                                                c[2] = layercolor[2];
                                                c[3] = f * layercolor[3];
                                        }
-                                       RSurf_Draw(surface);
+                                       RSurf_Draw(model, surface);
                                }
                                break;
                        default:
@@ -3129,7 +3132,7 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                                        surface = texturesurfacelist[texturesurfaceindex];
                                        RSurf_SetVertexPointer(ent, texture, surface, modelorg, false, false);
                                        for (scale = 1;scale < layertexrgbscale;scale <<= 1)
-                                               RSurf_Draw(surface);
+                                               RSurf_Draw(model, surface);
                                }
                        }
                }
@@ -3235,7 +3238,7 @@ void R_DrawSurfaces(entity_render_t *ent, qboolean skysurfaces)
                                int k = (int)(((size_t)surface) / sizeof(msurface_t));
                                GL_Color((k & 15) * (1.0f / 16.0f), ((k >> 4) & 15) * (1.0f / 16.0f), ((k >> 8) & 15) * (1.0f / 16.0f), 0.2f);
                                RSurf_SetVertexPointer(ent, texture, surface, modelorg, false, false);
-                               RSurf_Draw(surface);
+                               RSurf_Draw(ent->model, surface);
                                renderstats.entities_triangles += surface->num_triangles;
                        }
                        renderstats.entities_surfaces++;
@@ -3359,7 +3362,7 @@ void R_DrawSurfaces(entity_render_t *ent, qboolean skysurfaces)
                                                GL_Color(r_showtris.value, r_showtris.value, r_showtris.value, 1);
                                        else
                                                GL_Color(0, r_showtris.value, 0, 1);
-                                       elements = (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle);
+                                       elements = (ent->model->surfmesh.data_element3i + 3 * surface->num_firsttriangle);
                                        qglBegin(GL_LINES);
                                        for (k = 0;k < surface->num_triangles;k++, elements += 3)
                                        {
index 731eda0..c85321f 100644 (file)
@@ -53,6 +53,7 @@ void R_BuildLightMap (const entity_render_t *ent, msurface_t *surface)
        int smax, tmax, i, size, size3, maps, l;
        int *bl, scale;
        unsigned char *lightmap, *out, *stain;
+       model_t *model = ent->model;
        static int intblocklights[MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE*3]; // LordHavoc: *3 for colored lighting
        static unsigned char templight[MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE*4];
 
@@ -67,7 +68,7 @@ void R_BuildLightMap (const entity_render_t *ent, msurface_t *surface)
 
 // set to full bright if no light data
        bl = intblocklights;
-       if (!ent->model->brushq1.lightdata)
+       if (!model->brushq1.lightdata)
        {
                for (i = 0;i < size3;i++)
                        bl[i] = 255*256;
@@ -91,7 +92,7 @@ void R_BuildLightMap (const entity_render_t *ent, msurface_t *surface)
        // scaling, and remaps the 0-65536 (2x overbright) to 0-256, it will
        // be doubled during rendering to achieve 2x overbright
        // (0 = 0.0, 128 = 1.0, 256 = 2.0)
-       if (ent->model->brushq1.lightmaprgba)
+       if (model->brushq1.lightmaprgba)
        {
                for (i = 0;i < size;i++)
                {
@@ -140,7 +141,7 @@ void R_BuildLightMap (const entity_render_t *ent, msurface_t *surface)
                bl = intblocklights;
                out = templight;
                // we simply renormalize the weighted normals to get a valid deluxemap
-               if (ent->model->brushq1.lightmaprgba)
+               if (model->brushq1.lightmaprgba)
                {
                        for (i = 0;i < size;i++, bl += 3)
                        {
@@ -715,7 +716,7 @@ void R_Q1BSP_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin,
        vec3_t modelorg;
        texture_t *texture;
        // check the box in modelspace, it was already checked in worldspace
-       if (!BoxesOverlap(ent->model->normalmins, ent->model->normalmaxs, lightmins, lightmaxs))
+       if (!BoxesOverlap(model->normalmins, model->normalmaxs, lightmins, lightmaxs))
                return;
        R_UpdateAllTextureInfo(ent);
        if (model->brush.shadowmesh)
@@ -735,20 +736,19 @@ void R_Q1BSP_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin,
        }
        else
        {
-               projectdistance = lightradius + ent->model->radius*2;
+               projectdistance = lightradius + model->radius*2;
                Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, modelorg);
                for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
                {
                        surface = model->data_surfaces + surfacelist[surfacelistindex];
-                       // FIXME: get current skin
-                       texture = surface->texture;//R_FetchAliasSkin(ent, surface->groupmesh);
+                       texture = surface->texture->currentframe;
                        if (texture->currentmaterialflags & (MATERIALFLAG_NODRAW | MATERIALFLAG_TRANSPARENT) || !surface->num_triangles)
                                continue;
                        RSurf_SetVertexPointer(ent, texture, surface, modelorg, false, false);
                        // identify lit faces within the bounding box
-                       R_Shadow_PrepareShadowMark(surface->groupmesh->num_triangles);
-                       R_Shadow_MarkVolumeFromBox(surface->num_firsttriangle, surface->num_triangles, rsurface_vertex3f, surface->groupmesh->data_element3i, relativelightorigin, lightmins, lightmaxs, surface->mins, surface->maxs);
-                       R_Shadow_VolumeFromList(surface->groupmesh->num_vertices, surface->groupmesh->num_triangles, rsurface_vertex3f, surface->groupmesh->data_element3i, surface->groupmesh->data_neighbor3i, relativelightorigin, projectdistance, numshadowmark, shadowmarklist);
+                       R_Shadow_PrepareShadowMark(model->surfmesh.num_triangles);
+                       R_Shadow_MarkVolumeFromBox(surface->num_firsttriangle, surface->num_triangles, rsurface_vertex3f, model->surfmesh.data_element3i, relativelightorigin, lightmins, lightmaxs, surface->mins, surface->maxs);
+                       R_Shadow_VolumeFromList(model->surfmesh.num_vertices, model->surfmesh.num_triangles, rsurface_vertex3f, model->surfmesh.data_element3i, model->surfmesh.data_neighbor3i, relativelightorigin, projectdistance, numshadowmark, shadowmarklist);
                }
        }
 }
@@ -770,6 +770,7 @@ static void R_Q1BSP_DrawLight_TransparentCallback(const entity_render_t *ent, in
 static void R_Q1BSP_DrawLight_TransparentBatch(const entity_render_t *ent, texture_t *texture, int batchnumsurfaces, msurface_t **batchsurfacelist)
 {
        int batchsurfaceindex;
+       model_t *model = ent->model;
        msurface_t *batchsurface;
        vec3_t tempcenter, center;
        for (batchsurfaceindex = 0;batchsurfaceindex < batchnumsurfaces;batchsurfaceindex++)
@@ -779,7 +780,7 @@ static void R_Q1BSP_DrawLight_TransparentBatch(const entity_render_t *ent, textu
                tempcenter[1] = (batchsurface->mins[1] + batchsurface->maxs[1]) * 0.5f;
                tempcenter[2] = (batchsurface->mins[2] + batchsurface->maxs[2]) * 0.5f;
                Matrix4x4_Transform(&ent->matrix, tempcenter, center);
-               R_MeshQueue_AddTransparent(texture->currentmaterialflags & MATERIALFLAG_NODEPTHTEST ? r_vieworigin : center, R_Q1BSP_DrawLight_TransparentCallback, ent, batchsurface - ent->model->data_surfaces, r_shadow_rtlight);
+               R_MeshQueue_AddTransparent(texture->currentmaterialflags & MATERIALFLAG_NODEPTHTEST ? r_vieworigin : center, R_Q1BSP_DrawLight_TransparentCallback, ent, batchsurface - model->data_surfaces, r_shadow_rtlight);
        }
 }
 
index 833fbe2..b5d2919 100644 (file)
@@ -39,9 +39,9 @@ void Mod_AliasInit (void)
        Cvar_RegisterVariable(&r_skeletal_debugtranslatez);
 }
 
-void Mod_Alias_GetMesh_Vertex3f(const model_t *model, const frameblend_t *frameblend, const surfmesh_t *mesh, float *out3f)
+void Mod_Alias_GetMesh_Vertex3f(const model_t *model, const frameblend_t *frameblend, float *out3f)
 {
-       if (mesh->num_vertexboneweights)
+       if (model->surfmesh.num_vertexboneweights)
        {
                int i, k, blends;
                surfmeshvertexboneweight_t *v;
@@ -70,9 +70,9 @@ void Mod_Alias_GetMesh_Vertex3f(const model_t *model, const frameblend_t *frameb
                                        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++)
+               memset(out3f, 0, model->surfmesh.num_vertices * sizeof(float[3]));
+               v = model->surfmesh.data_vertexboneweights;
+               for (i = 0;i < model->surfmesh.num_vertexboneweights;i++, v++)
                {
                        out = out3f + v->vertexindex * 3;
                        matrix = bonepose[v->boneindex];
@@ -88,10 +88,10 @@ void Mod_Alias_GetMesh_Vertex3f(const model_t *model, const frameblend_t *frameb
                float lerp1, lerp2, lerp3, lerp4;
                const float *vertsbase, *verts1, *verts2, *verts3, *verts4;
                // vertex morph
-               if (!mesh->data_morphvertex3f)
+               if (!model->surfmesh.data_morphvertex3f)
                        Host_Error("model %s has no skeletal or vertex morph animation data", model->name);
-               vertsbase = mesh->data_morphvertex3f;
-               vertcount = mesh->num_vertices;
+               vertsbase = model->surfmesh.data_morphvertex3f;
+               vertcount = model->surfmesh.num_vertices;
                verts1 = vertsbase + frameblend[0].frame * vertcount * 3;
                lerp1 = frameblend[0].lerp;
                if (frameblend[1].lerp)
@@ -187,15 +187,15 @@ int Mod_Alias_GetTagIndexForName(const model_t *model, unsigned int skin, const
        return 0;
 }
 
-static void Mod_Alias_Mesh_CompileFrameZero(surfmesh_t *mesh)
+static void Mod_Alias_Mesh_CompileFrameZero(void)
 {
        frameblend_t frameblend[4] = {{0, 1}, {0, 0}, {0, 0}, {0, 0}};
-       mesh->data_vertex3f = (float *)Mem_Alloc(loadmodel->mempool, mesh->num_vertices * sizeof(float[3][4]));
-       mesh->data_svector3f = mesh->data_vertex3f + mesh->num_vertices * 3;
-       mesh->data_tvector3f = mesh->data_vertex3f + mesh->num_vertices * 6;
-       mesh->data_normal3f = mesh->data_vertex3f + mesh->num_vertices * 9;
-       Mod_Alias_GetMesh_Vertex3f(loadmodel, frameblend, mesh, mesh->data_vertex3f);
-       Mod_BuildTextureVectorsAndNormals(0, mesh->num_vertices, mesh->num_triangles, mesh->data_vertex3f, mesh->data_texcoordtexture2f, mesh->data_element3i, mesh->data_svector3f, mesh->data_tvector3f, mesh->data_normal3f, true);
+       loadmodel->surfmesh.data_vertex3f = (float *)Mem_Alloc(loadmodel->mempool, loadmodel->surfmesh.num_vertices * sizeof(float[3][4]));
+       loadmodel->surfmesh.data_svector3f = loadmodel->surfmesh.data_vertex3f + loadmodel->surfmesh.num_vertices * 3;
+       loadmodel->surfmesh.data_tvector3f = loadmodel->surfmesh.data_vertex3f + loadmodel->surfmesh.num_vertices * 6;
+       loadmodel->surfmesh.data_normal3f = loadmodel->surfmesh.data_vertex3f + loadmodel->surfmesh.num_vertices * 9;
+       Mod_Alias_GetMesh_Vertex3f(loadmodel, frameblend, loadmodel->surfmesh.data_vertex3f);
+       Mod_BuildTextureVectorsAndNormals(0, loadmodel->surfmesh.num_vertices, loadmodel->surfmesh.num_triangles, loadmodel->surfmesh.data_vertex3f, loadmodel->surfmesh.data_texcoordtexture2f, loadmodel->surfmesh.data_element3i, loadmodel->surfmesh.data_svector3f, loadmodel->surfmesh.data_tvector3f, loadmodel->surfmesh.data_normal3f, true);
 }
 
 static void Mod_MDLMD2MD3_TraceBox(model_t *model, int frame, trace_t *trace, const vec3_t start, const vec3_t boxmins, const vec3_t boxmaxs, const vec3_t end, int hitsupercontentsmask)
@@ -204,7 +204,6 @@ static void Mod_MDLMD2MD3_TraceBox(model_t *model, int frame, trace_t *trace, co
        float segmentmins[3], segmentmaxs[3];
        frameblend_t frameblend[4];
        msurface_t *surface;
-       surfmesh_t *mesh;
        static int maxvertices = 0;
        static float *vertex3f = NULL;
        memset(trace, 0, sizeof(*trace));
@@ -214,6 +213,13 @@ static void Mod_MDLMD2MD3_TraceBox(model_t *model, int frame, trace_t *trace, co
        memset(frameblend, 0, sizeof(frameblend));
        frameblend[0].frame = frame;
        frameblend[0].lerp = 1;
+       if (maxvertices < model->surfmesh.num_vertices)
+       {
+               if (vertex3f)
+                       Z_Free(vertex3f);
+               maxvertices = (model->surfmesh.num_vertices + 255) & ~255;
+               vertex3f = Z_Malloc(maxvertices * sizeof(float[3]));
+       }
        if (VectorLength2(boxmins) + VectorLength2(boxmaxs) == 0)
        {
                // line trace
@@ -225,16 +231,8 @@ static void Mod_MDLMD2MD3_TraceBox(model_t *model, int frame, trace_t *trace, co
                segmentmaxs[2] = max(start[2], end[2]) + 1;
                for (i = 0, surface = model->data_surfaces;i < model->num_surfaces;i++, surface++)
                {
-                       mesh = surface->groupmesh;
-                       if (maxvertices < mesh->num_vertices)
-                       {
-                               if (vertex3f)
-                                       Z_Free(vertex3f);
-                               maxvertices = (mesh->num_vertices + 255) & ~255;
-                               vertex3f = Z_Malloc(maxvertices * sizeof(float[3]));
-                       }
-                       Mod_Alias_GetMesh_Vertex3f(model, frameblend, mesh, vertex3f);
-                       Collision_TraceLineTriangleMeshFloat(trace, start, end, mesh->num_triangles, mesh->data_element3i, vertex3f, SUPERCONTENTS_SOLID, 0, surface->texture, segmentmins, segmentmaxs);
+                       Mod_Alias_GetMesh_Vertex3f(model, frameblend, vertex3f);
+                       Collision_TraceLineTriangleMeshFloat(trace, start, end, model->surfmesh.num_triangles, model->surfmesh.data_element3i, vertex3f, SUPERCONTENTS_SOLID, 0, surface->texture, segmentmins, segmentmaxs);
                }
        }
        else
@@ -256,48 +254,42 @@ static void Mod_MDLMD2MD3_TraceBox(model_t *model, int frame, trace_t *trace, co
                thisbrush_end = Collision_BrushForBox(&identitymatrix, boxendmins, boxendmaxs, 0, 0, NULL);
                for (i = 0, surface = model->data_surfaces;i < model->num_surfaces;i++, surface++)
                {
-                       mesh = surface->groupmesh;
-                       if (maxvertices < mesh->num_vertices)
+                       if (maxvertices < model->surfmesh.num_vertices)
                        {
                                if (vertex3f)
                                        Z_Free(vertex3f);
-                               maxvertices = (mesh->num_vertices + 255) & ~255;
+                               maxvertices = (model->surfmesh.num_vertices + 255) & ~255;
                                vertex3f = Z_Malloc(maxvertices * sizeof(float[3]));
                        }
-                       Mod_Alias_GetMesh_Vertex3f(model, frameblend, mesh, vertex3f);
-                       Collision_TraceBrushTriangleMeshFloat(trace, thisbrush_start, thisbrush_end, mesh->num_triangles, mesh->data_element3i, vertex3f, SUPERCONTENTS_SOLID, 0, surface->texture, segmentmins, segmentmaxs);
+                       Mod_Alias_GetMesh_Vertex3f(model, frameblend, vertex3f);
+                       Collision_TraceBrushTriangleMeshFloat(trace, thisbrush_start, thisbrush_end, model->surfmesh.num_triangles, model->surfmesh.data_element3i, vertex3f, SUPERCONTENTS_SOLID, 0, surface->texture, segmentmins, segmentmaxs);
                }
        }
 }
 
 static void Mod_CalcAliasModelBBoxes (void)
 {
-       int vnum, meshnum;
+       int vnum;
        float dist, yawradius, radius;
-       surfmesh_t *mesh;
        float *v;
        VectorClear(loadmodel->normalmins);
        VectorClear(loadmodel->normalmaxs);
        yawradius = 0;
        radius = 0;
-       for (meshnum = 0;meshnum < loadmodel->nummeshes;meshnum++)
-       {
-               mesh = loadmodel->meshlist[meshnum];
-               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];
-                       if (loadmodel->normalmins[2] > v[2]) loadmodel->normalmins[2] = v[2];
-                       if (loadmodel->normalmaxs[0] < v[0]) loadmodel->normalmaxs[0] = v[0];
-                       if (loadmodel->normalmaxs[1] < v[1]) loadmodel->normalmaxs[1] = v[1];
-                       if (loadmodel->normalmaxs[2] < v[2]) loadmodel->normalmaxs[2] = v[2];
-                       dist = v[0] * v[0] + v[1] * v[1];
-                       if (yawradius < dist)
-                               yawradius = dist;
-                       dist += v[2] * v[2];
-                       if (radius < dist)
-                               radius = dist;
-               }
+       for (vnum = 0, v = loadmodel->surfmesh.data_morphvertex3f;vnum < loadmodel->surfmesh.num_vertices * loadmodel->surfmesh.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];
+               if (loadmodel->normalmins[2] > v[2]) loadmodel->normalmins[2] = v[2];
+               if (loadmodel->normalmaxs[0] < v[0]) loadmodel->normalmaxs[0] = v[0];
+               if (loadmodel->normalmaxs[1] < v[1]) loadmodel->normalmaxs[1] = v[1];
+               if (loadmodel->normalmaxs[2] < v[2]) loadmodel->normalmaxs[2] = v[2];
+               dist = v[0] * v[0] + v[1] * v[1];
+               if (yawradius < dist)
+                       yawradius = dist;
+               dist += v[2] * v[2];
+               if (radius < dist)
+                       radius = dist;
        }
        radius = sqrt(radius);
        yawradius = sqrt(yawradius);
@@ -386,7 +378,7 @@ static void Mod_MDL_LoadFrames (unsigned char* datapointer, int inverts, vec3_t
                {
                        pinframe = (daliasframe_t *)datapointer;
                        datapointer += sizeof(daliasframe_t);
-                       Mod_ConvertAliasVerts(inverts, scale, translate, (trivertx_t *)datapointer, loadmodel->meshlist[0]->data_morphvertex3f + pose * loadmodel->meshlist[0]->num_vertices * 3, vertremap);
+                       Mod_ConvertAliasVerts(inverts, scale, translate, (trivertx_t *)datapointer, loadmodel->surfmesh.data_morphvertex3f + pose * loadmodel->surfmesh.num_vertices * 3, vertremap);
                        datapointer += sizeof(trivertx_t) * inverts;
                        pose++;
                }
@@ -506,12 +498,9 @@ void Mod_IDP0_Load(model_t *mod, void *buffer, void *bufferend)
 
        loadmodel->num_surfaces = 1;
        loadmodel->nummodelsurfaces = loadmodel->num_surfaces;
-       loadmodel->nummeshes = 1;
-       data = (unsigned char *)Mem_Alloc(loadmodel->mempool, loadmodel->num_surfaces * sizeof(msurface_t) + loadmodel->num_surfaces * sizeof(int) + sizeof(surfmesh_t *) + sizeof(surfmesh_t));
+       data = (unsigned char *)Mem_Alloc(loadmodel->mempool, loadmodel->num_surfaces * sizeof(msurface_t) + loadmodel->num_surfaces * sizeof(int));
        loadmodel->data_surfaces = (msurface_t *)data;data += loadmodel->num_surfaces * sizeof(msurface_t);
        loadmodel->surfacelist = (int *)data;data += loadmodel->num_surfaces * sizeof(int);
-       loadmodel->meshlist = (surfmesh_t **)data;data += loadmodel->num_surfaces * sizeof(surfmesh_t *);
-       loadmodel->meshlist[0] = (surfmesh_t *)data;data += sizeof(surfmesh_t);
        loadmodel->surfacelist[0] = 0;
 
        loadmodel->numskins = LittleLong(pinmodel->numskins);
@@ -522,8 +511,8 @@ void Mod_IDP0_Load(model_t *mod, void *buffer, void *bufferend)
        BOUNDI(skinheight,0,65536);
        numverts = LittleLong(pinmodel->numverts);
        BOUNDI(numverts,0,65536);
-       loadmodel->meshlist[0]->num_triangles = LittleLong(pinmodel->numtris);
-       BOUNDI(loadmodel->meshlist[0]->num_triangles,0,65536);
+       loadmodel->surfmesh.num_triangles = LittleLong(pinmodel->numtris);
+       BOUNDI(loadmodel->surfmesh.num_triangles,0,65536);
        loadmodel->numframes = LittleLong(pinmodel->numframes);
        BOUNDI(loadmodel->numframes,0,65536);
        loadmodel->synctype = (synctype_t)LittleLong (pinmodel->synctype);
@@ -563,10 +552,10 @@ void Mod_IDP0_Load(model_t *mod, void *buffer, void *bufferend)
        datapointer += sizeof(stvert_t) * numverts;
 
        pintriangles = (dtriangle_t *)datapointer;
-       datapointer += sizeof(dtriangle_t) * loadmodel->meshlist[0]->num_triangles;
+       datapointer += sizeof(dtriangle_t) * loadmodel->surfmesh.num_triangles;
 
        startframes = datapointer;
-       loadmodel->meshlist[0]->num_morphframes = 0;
+       loadmodel->surfmesh.num_morphframes = 0;
        for (i = 0;i < loadmodel->numframes;i++)
        {
                pinframetype = (daliasframetype_t *)datapointer;
@@ -585,7 +574,7 @@ void Mod_IDP0_Load(model_t *mod, void *buffer, void *bufferend)
                {
                        datapointer += sizeof(daliasframe_t);
                        datapointer += sizeof(trivertx_t) * numverts;
-                       loadmodel->meshlist[0]->num_morphframes++;
+                       loadmodel->surfmesh.num_morphframes++;
                }
        }
 
@@ -607,60 +596,60 @@ void Mod_IDP0_Load(model_t *mod, void *buffer, void *bufferend)
        }
 
 // load triangle data
-       loadmodel->meshlist[0]->data_element3i = (int *)Mem_Alloc(loadmodel->mempool, sizeof(int[3]) * loadmodel->meshlist[0]->num_triangles);
+       loadmodel->surfmesh.data_element3i = (int *)Mem_Alloc(loadmodel->mempool, sizeof(int[3]) * loadmodel->surfmesh.num_triangles);
 
        // read the triangle elements
-       for (i = 0;i < loadmodel->meshlist[0]->num_triangles;i++)
+       for (i = 0;i < loadmodel->surfmesh.num_triangles;i++)
                for (j = 0;j < 3;j++)
-                       loadmodel->meshlist[0]->data_element3i[i*3+j] = LittleLong(pintriangles[i].vertindex[j]);
+                       loadmodel->surfmesh.data_element3i[i*3+j] = LittleLong(pintriangles[i].vertindex[j]);
        // validate (note numverts is used because this is the original data)
-       Mod_ValidateElements(loadmodel->meshlist[0]->data_element3i, loadmodel->meshlist[0]->num_triangles, 0, numverts, __FILE__, __LINE__);
+       Mod_ValidateElements(loadmodel->surfmesh.data_element3i, loadmodel->surfmesh.num_triangles, 0, numverts, __FILE__, __LINE__);
        // now butcher the elements according to vertonseam and tri->facesfront
        // and then compact the vertex set to remove duplicates
-       for (i = 0;i < loadmodel->meshlist[0]->num_triangles;i++)
+       for (i = 0;i < loadmodel->surfmesh.num_triangles;i++)
                if (!LittleLong(pintriangles[i].facesfront)) // backface
                        for (j = 0;j < 3;j++)
-                               if (vertonseam[loadmodel->meshlist[0]->data_element3i[i*3+j]])
-                                       loadmodel->meshlist[0]->data_element3i[i*3+j] += numverts;
+                               if (vertonseam[loadmodel->surfmesh.data_element3i[i*3+j]])
+                                       loadmodel->surfmesh.data_element3i[i*3+j] += numverts;
        // count the usage
        // (this uses vertremap to count usage to save some memory)
        for (i = 0;i < numverts*2;i++)
                vertremap[i] = 0;
-       for (i = 0;i < loadmodel->meshlist[0]->num_triangles*3;i++)
-               vertremap[loadmodel->meshlist[0]->data_element3i[i]]++;
+       for (i = 0;i < loadmodel->surfmesh.num_triangles*3;i++)
+               vertremap[loadmodel->surfmesh.data_element3i[i]]++;
        // build remapping table and compact array
-       loadmodel->meshlist[0]->num_vertices = 0;
+       loadmodel->surfmesh.num_vertices = 0;
        for (i = 0;i < numverts*2;i++)
        {
                if (vertremap[i])
                {
-                       vertremap[i] = loadmodel->meshlist[0]->num_vertices;
-                       vertst[loadmodel->meshlist[0]->num_vertices*2+0] = vertst[i*2+0];
-                       vertst[loadmodel->meshlist[0]->num_vertices*2+1] = vertst[i*2+1];
-                       loadmodel->meshlist[0]->num_vertices++;
+                       vertremap[i] = loadmodel->surfmesh.num_vertices;
+                       vertst[loadmodel->surfmesh.num_vertices*2+0] = vertst[i*2+0];
+                       vertst[loadmodel->surfmesh.num_vertices*2+1] = vertst[i*2+1];
+                       loadmodel->surfmesh.num_vertices++;
                }
                else
                        vertremap[i] = -1; // not used at all
        }
        // remap the elements to the new vertex set
-       for (i = 0;i < loadmodel->meshlist[0]->num_triangles * 3;i++)
-               loadmodel->meshlist[0]->data_element3i[i] = vertremap[loadmodel->meshlist[0]->data_element3i[i]];
+       for (i = 0;i < loadmodel->surfmesh.num_triangles * 3;i++)
+               loadmodel->surfmesh.data_element3i[i] = vertremap[loadmodel->surfmesh.data_element3i[i]];
        // store the texture coordinates
-       loadmodel->meshlist[0]->data_texcoordtexture2f = (float *)Mem_Alloc(loadmodel->mempool, sizeof(float[2]) * loadmodel->meshlist[0]->num_vertices);
-       for (i = 0;i < loadmodel->meshlist[0]->num_vertices;i++)
+       loadmodel->surfmesh.data_texcoordtexture2f = (float *)Mem_Alloc(loadmodel->mempool, sizeof(float[2]) * loadmodel->surfmesh.num_vertices);
+       for (i = 0;i < loadmodel->surfmesh.num_vertices;i++)
        {
-               loadmodel->meshlist[0]->data_texcoordtexture2f[i*2+0] = vertst[i*2+0];
-               loadmodel->meshlist[0]->data_texcoordtexture2f[i*2+1] = vertst[i*2+1];
+               loadmodel->surfmesh.data_texcoordtexture2f[i*2+0] = vertst[i*2+0];
+               loadmodel->surfmesh.data_texcoordtexture2f[i*2+1] = vertst[i*2+1];
        }
 
 // load the frames
        loadmodel->animscenes = (animscene_t *)Mem_Alloc(loadmodel->mempool, sizeof(animscene_t) * loadmodel->numframes);
-       loadmodel->meshlist[0]->data_morphvertex3f = (float *)Mem_Alloc(loadmodel->mempool, sizeof(float[3]) * loadmodel->meshlist[0]->num_morphframes * loadmodel->meshlist[0]->num_vertices);
-       loadmodel->meshlist[0]->data_neighbor3i = (int *)Mem_Alloc(loadmodel->mempool, loadmodel->meshlist[0]->num_triangles * sizeof(int[3]));
+       loadmodel->surfmesh.data_morphvertex3f = (float *)Mem_Alloc(loadmodel->mempool, sizeof(float[3]) * loadmodel->surfmesh.num_morphframes * loadmodel->surfmesh.num_vertices);
+       loadmodel->surfmesh.data_neighbor3i = (int *)Mem_Alloc(loadmodel->mempool, loadmodel->surfmesh.num_triangles * sizeof(int[3]));
        Mod_MDL_LoadFrames (startframes, numverts, scale, translate, vertremap);
-       Mod_BuildTriangleNeighbors(loadmodel->meshlist[0]->data_neighbor3i, loadmodel->meshlist[0]->data_element3i, loadmodel->meshlist[0]->num_triangles);
+       Mod_BuildTriangleNeighbors(loadmodel->surfmesh.data_neighbor3i, loadmodel->surfmesh.data_element3i, loadmodel->surfmesh.num_triangles);
        Mod_CalcAliasModelBBoxes();
-       Mod_Alias_Mesh_CompileFrameZero(loadmodel->meshlist[0]);
+       Mod_Alias_Mesh_CompileFrameZero();
 
        Mem_Free(vertst);
        Mem_Free(vertremap);
@@ -764,11 +753,10 @@ void Mod_IDP0_Load(model_t *mod, void *buffer, void *bufferend)
 
        surface = loadmodel->data_surfaces;
        surface->texture = loadmodel->data_textures;
-       surface->groupmesh = loadmodel->meshlist[0];
        surface->num_firsttriangle = 0;
-       surface->num_triangles = surface->groupmesh->num_triangles;
+       surface->num_triangles = loadmodel->surfmesh.num_triangles;
        surface->num_firstvertex = 0;
-       surface->num_vertices = surface->groupmesh->num_vertices;
+       surface->num_vertices = loadmodel->surfmesh.num_vertices;
 }
 
 static void Mod_MD2_ConvertVerts (vec3_t scale, vec3_t translate, trivertx_t *v, float *out3f, int numverts, int *vertremap)
@@ -845,20 +833,17 @@ void Mod_IDP2_Load(model_t *mod, void *buffer, void *bufferend)
 
        loadmodel->num_surfaces = 1;
        loadmodel->nummodelsurfaces = loadmodel->num_surfaces;
-       loadmodel->nummeshes = 1;
-       data = (unsigned char *)Mem_Alloc(loadmodel->mempool, loadmodel->num_surfaces * sizeof(msurface_t) + loadmodel->num_surfaces * sizeof(int) + sizeof(surfmesh_t *) + sizeof(surfmesh_t));
+       data = (unsigned char *)Mem_Alloc(loadmodel->mempool, loadmodel->num_surfaces * sizeof(msurface_t) + loadmodel->num_surfaces * sizeof(int));
        loadmodel->data_surfaces = (msurface_t *)data;data += loadmodel->num_surfaces * sizeof(msurface_t);
        loadmodel->surfacelist = (int *)data;data += loadmodel->num_surfaces * sizeof(int);
-       loadmodel->meshlist = (surfmesh_t **)data;data += loadmodel->num_surfaces * sizeof(surfmesh_t *);
-       loadmodel->meshlist[0] = (surfmesh_t *)data;data += sizeof(surfmesh_t);
        loadmodel->surfacelist[0] = 0;
 
        loadmodel->numskins = LittleLong(pinmodel->num_skins);
        numxyz = LittleLong(pinmodel->num_xyz);
        numst = LittleLong(pinmodel->num_st);
-       loadmodel->meshlist[0]->num_triangles = LittleLong(pinmodel->num_tris);
+       loadmodel->surfmesh.num_triangles = LittleLong(pinmodel->num_tris);
        loadmodel->numframes = LittleLong(pinmodel->num_frames);
-       loadmodel->meshlist[0]->num_morphframes = loadmodel->numframes;
+       loadmodel->surfmesh.num_morphframes = loadmodel->numframes;
        loadmodel->animscenes = (animscene_t *)Mem_Alloc(loadmodel->mempool, loadmodel->numframes * sizeof(animscene_t));
 
        loadmodel->flags = 0; // there are no MD2 flags
@@ -932,11 +917,11 @@ void Mod_IDP2_Load(model_t *mod, void *buffer, void *bufferend)
        }
 
        md2verthash = (struct md2verthash_s **)Mem_Alloc(tempmempool, 256 * sizeof(hash));
-       md2verthashdata = (struct md2verthash_s *)Mem_Alloc(tempmempool, loadmodel->meshlist[0]->num_triangles * 3 * sizeof(*hash));
+       md2verthashdata = (struct md2verthash_s *)Mem_Alloc(tempmempool, loadmodel->surfmesh.num_triangles * 3 * sizeof(*hash));
        // swap the triangle list
        num = 0;
-       loadmodel->meshlist[0]->data_element3i = (int *)Mem_Alloc(loadmodel->mempool, loadmodel->meshlist[0]->num_triangles * sizeof(int[3]));
-       for (i = 0;i < loadmodel->meshlist[0]->num_triangles;i++)
+       loadmodel->surfmesh.data_element3i = (int *)Mem_Alloc(loadmodel->mempool, loadmodel->surfmesh.num_triangles * sizeof(int[3]));
+       for (i = 0;i < loadmodel->surfmesh.num_triangles;i++)
        {
                for (j = 0;j < 3;j++)
                {
@@ -967,22 +952,22 @@ void Mod_IDP2_Load(model_t *mod, void *buffer, void *bufferend)
                                hash->next = md2verthash[hashindex];
                                md2verthash[hashindex] = hash;
                        }
-                       loadmodel->meshlist[0]->data_element3i[i*3+j] = (hash - md2verthashdata);
+                       loadmodel->surfmesh.data_element3i[i*3+j] = (hash - md2verthashdata);
                }
        }
 
        Mem_Free(stverts);
 
        numverts = num;
-       loadmodel->meshlist[0]->num_vertices = numverts;
+       loadmodel->surfmesh.num_vertices = numverts;
        vertremap = (int *)Mem_Alloc(loadmodel->mempool, num * sizeof(int));
-       loadmodel->meshlist[0]->data_texcoordtexture2f = (float *)Mem_Alloc(loadmodel->mempool, num * sizeof(float[2]));
+       loadmodel->surfmesh.data_texcoordtexture2f = (float *)Mem_Alloc(loadmodel->mempool, num * sizeof(float[2]));
        for (i = 0;i < num;i++)
        {
                hash = md2verthashdata + i;
                vertremap[i] = hash->xyz;
-               loadmodel->meshlist[0]->data_texcoordtexture2f[i*2+0] = hash->st[0];
-               loadmodel->meshlist[0]->data_texcoordtexture2f[i*2+1] = hash->st[1];
+               loadmodel->surfmesh.data_texcoordtexture2f[i*2+0] = hash->st[0];
+               loadmodel->surfmesh.data_texcoordtexture2f[i*2+1] = hash->st[1];
        }
 
        Mem_Free(md2verthash);
@@ -990,8 +975,8 @@ void Mod_IDP2_Load(model_t *mod, void *buffer, void *bufferend)
 
        // load the frames
        datapointer = (base + LittleLong(pinmodel->ofs_frames));
-       loadmodel->meshlist[0]->data_morphvertex3f = (float *)Mem_Alloc(loadmodel->mempool, numverts * loadmodel->meshlist[0]->num_morphframes * sizeof(float[3]));
-       for (i = 0;i < loadmodel->meshlist[0]->num_morphframes;i++)
+       loadmodel->surfmesh.data_morphvertex3f = (float *)Mem_Alloc(loadmodel->mempool, numverts * loadmodel->surfmesh.num_morphframes * sizeof(float[3]));
+       for (i = 0;i < loadmodel->surfmesh.num_morphframes;i++)
        {
                pinframe = (md2frame_t *)datapointer;
                datapointer += sizeof(md2frame_t);
@@ -1000,7 +985,7 @@ void Mod_IDP2_Load(model_t *mod, void *buffer, void *bufferend)
                        scale[j] = LittleFloat(pinframe->scale[j]);
                        translate[j] = LittleFloat(pinframe->translate[j]);
                }
-               Mod_MD2_ConvertVerts(scale, translate, (trivertx_t *)datapointer, loadmodel->meshlist[0]->data_morphvertex3f + i * numverts * 3, numverts, vertremap);
+               Mod_MD2_ConvertVerts(scale, translate, (trivertx_t *)datapointer, loadmodel->surfmesh.data_morphvertex3f + i * numverts * 3, numverts, vertremap);
                datapointer += numxyz * sizeof(trivertx_t);
 
                strcpy(loadmodel->animscenes[i].name, pinframe->name);
@@ -1012,18 +997,17 @@ void Mod_IDP2_Load(model_t *mod, void *buffer, void *bufferend)
 
        Mem_Free(vertremap);
 
-       loadmodel->meshlist[0]->data_neighbor3i = (int *)Mem_Alloc(loadmodel->mempool, loadmodel->meshlist[0]->num_triangles * sizeof(int[3]));
-       Mod_BuildTriangleNeighbors(loadmodel->meshlist[0]->data_neighbor3i, loadmodel->meshlist[0]->data_element3i, loadmodel->meshlist[0]->num_triangles);
+       loadmodel->surfmesh.data_neighbor3i = (int *)Mem_Alloc(loadmodel->mempool, loadmodel->surfmesh.num_triangles * sizeof(int[3]));
+       Mod_BuildTriangleNeighbors(loadmodel->surfmesh.data_neighbor3i, loadmodel->surfmesh.data_element3i, loadmodel->surfmesh.num_triangles);
        Mod_CalcAliasModelBBoxes();
-       Mod_Alias_Mesh_CompileFrameZero(loadmodel->meshlist[0]);
+       Mod_Alias_Mesh_CompileFrameZero();
 
        surface = loadmodel->data_surfaces;
-       surface->groupmesh = loadmodel->meshlist[0];
        surface->texture = loadmodel->data_textures;
        surface->num_firsttriangle = 0;
-       surface->num_triangles = surface->groupmesh->num_triangles;
+       surface->num_triangles = loadmodel->surfmesh.num_triangles;
        surface->num_firstvertex = 0;
-       surface->num_vertices = surface->groupmesh->num_vertices;
+       surface->num_vertices = loadmodel->surfmesh.num_vertices;
 }
 
 void Mod_IDP3_Load(model_t *mod, void *buffer, void *bufferend)
@@ -1117,20 +1101,17 @@ void Mod_IDP3_Load(model_t *mod, void *buffer, void *bufferend)
 
        loadmodel->nummodelsurfaces = loadmodel->num_surfaces;
        loadmodel->num_textures = loadmodel->num_surfaces;
-       loadmodel->nummeshes = 1;
-       data = (unsigned char *)Mem_Alloc(loadmodel->mempool, loadmodel->num_surfaces * sizeof(msurface_t) + loadmodel->num_surfaces * sizeof(int) + loadmodel->num_surfaces * loadmodel->numskins * sizeof(texture_t) + sizeof(surfmesh_t *) + sizeof(surfmesh_t) + meshtriangles * sizeof(int[6]) + meshvertices * sizeof(float[2]) + meshvertices * loadmodel->numframes * sizeof(float[3]));
+       data = (unsigned char *)Mem_Alloc(loadmodel->mempool, loadmodel->num_surfaces * sizeof(msurface_t) + loadmodel->num_surfaces * sizeof(int) + loadmodel->num_surfaces * loadmodel->numskins * sizeof(texture_t) + meshtriangles * sizeof(int[3]) + meshtriangles * sizeof(int[3]) + meshvertices * sizeof(float[2]) + meshvertices * loadmodel->numframes * sizeof(float[3]));
        loadmodel->data_surfaces = (msurface_t *)data;data += loadmodel->num_surfaces * sizeof(msurface_t);
        loadmodel->surfacelist = (int *)data;data += loadmodel->num_surfaces * sizeof(int);
        loadmodel->data_textures = (texture_t *)data;data += loadmodel->num_surfaces * loadmodel->numskins * sizeof(texture_t);
-       loadmodel->meshlist = (surfmesh_t **)data;data += sizeof(surfmesh_t *);
-       loadmodel->meshlist[0] = (surfmesh_t *)data;data += sizeof(surfmesh_t);
-       loadmodel->meshlist[0]->num_vertices = meshvertices;
-       loadmodel->meshlist[0]->num_triangles = meshtriangles;
-       loadmodel->meshlist[0]->num_morphframes = loadmodel->numframes; // TODO: remove?
-       loadmodel->meshlist[0]->data_element3i = (int *)data;data += meshtriangles * sizeof(int[3]);
-       loadmodel->meshlist[0]->data_neighbor3i = (int *)data;data += meshtriangles * sizeof(int[3]);
-       loadmodel->meshlist[0]->data_texcoordtexture2f = (float *)data;data += meshvertices * sizeof(float[2]);
-       loadmodel->meshlist[0]->data_morphvertex3f = (float *)data;data += meshvertices * loadmodel->numframes * sizeof(float[3]);
+       loadmodel->surfmesh.num_vertices = meshvertices;
+       loadmodel->surfmesh.num_triangles = meshtriangles;
+       loadmodel->surfmesh.num_morphframes = loadmodel->numframes; // TODO: remove?
+       loadmodel->surfmesh.data_element3i = (int *)data;data += meshtriangles * sizeof(int[3]);
+       loadmodel->surfmesh.data_neighbor3i = (int *)data;data += meshtriangles * sizeof(int[3]);
+       loadmodel->surfmesh.data_texcoordtexture2f = (float *)data;data += meshvertices * sizeof(float[2]);
+       loadmodel->surfmesh.data_morphvertex3f = (float *)data;data += meshvertices * loadmodel->numframes * sizeof(float[3]);
 
        meshvertices = 0;
        meshtriangles = 0;
@@ -1140,7 +1121,6 @@ void Mod_IDP3_Load(model_t *mod, void *buffer, void *bufferend)
                        Host_Error("Mod_IDP3_Load: invalid mesh identifier (not IDP3)");
                loadmodel->surfacelist[i] = i;
                surface = loadmodel->data_surfaces + i;
-               surface->groupmesh = loadmodel->meshlist[0];
                surface->texture = loadmodel->data_textures + i;
                surface->num_firsttriangle = meshtriangles;
                surface->num_triangles = LittleLong(pinmesh->num_triangles);
@@ -1150,17 +1130,17 @@ void Mod_IDP3_Load(model_t *mod, void *buffer, void *bufferend)
                meshtriangles += surface->num_triangles;
 
                for (j = 0;j < surface->num_triangles * 3;j++)
-                       surface->groupmesh->data_element3i[j + surface->num_firsttriangle * 3] = surface->num_firstvertex + LittleLong(((int *)((unsigned char *)pinmesh + LittleLong(pinmesh->lump_elements)))[j]);
+                       loadmodel->surfmesh.data_element3i[j + surface->num_firsttriangle * 3] = surface->num_firstvertex + LittleLong(((int *)((unsigned char *)pinmesh + LittleLong(pinmesh->lump_elements)))[j]);
                for (j = 0;j < surface->num_vertices;j++)
                {
-                       surface->groupmesh->data_texcoordtexture2f[(j + surface->num_firstvertex) * 2 + 0] = LittleFloat(((float *)((unsigned char *)pinmesh + LittleLong(pinmesh->lump_texcoords)))[j * 2 + 0]);
-                       surface->groupmesh->data_texcoordtexture2f[(j + surface->num_firstvertex) * 2 + 1] = LittleFloat(((float *)((unsigned char *)pinmesh + LittleLong(pinmesh->lump_texcoords)))[j * 2 + 1]);
+                       loadmodel->surfmesh.data_texcoordtexture2f[(j + surface->num_firstvertex) * 2 + 0] = LittleFloat(((float *)((unsigned char *)pinmesh + LittleLong(pinmesh->lump_texcoords)))[j * 2 + 0]);
+                       loadmodel->surfmesh.data_texcoordtexture2f[(j + surface->num_firstvertex) * 2 + 1] = LittleFloat(((float *)((unsigned char *)pinmesh + LittleLong(pinmesh->lump_texcoords)))[j * 2 + 1]);
                }
                for (j = 0;j < surface->num_vertices * loadmodel->numframes;j++)
                {
-                       surface->groupmesh->data_morphvertex3f[(j + surface->num_firstvertex) * 3 + 0] = LittleShort(((short *)((unsigned char *)pinmesh + LittleLong(pinmesh->lump_framevertices)))[j * 4 + 0]) * (1.0f / 64.0f);
-                       surface->groupmesh->data_morphvertex3f[(j + surface->num_firstvertex) * 3 + 1] = LittleShort(((short *)((unsigned char *)pinmesh + LittleLong(pinmesh->lump_framevertices)))[j * 4 + 1]) * (1.0f / 64.0f);
-                       surface->groupmesh->data_morphvertex3f[(j + surface->num_firstvertex) * 3 + 2] = LittleShort(((short *)((unsigned char *)pinmesh + LittleLong(pinmesh->lump_framevertices)))[j * 4 + 2]) * (1.0f / 64.0f);
+                       loadmodel->surfmesh.data_morphvertex3f[(j + surface->num_firstvertex) * 3 + 0] = LittleShort(((short *)((unsigned char *)pinmesh + LittleLong(pinmesh->lump_framevertices)))[j * 4 + 0]) * (1.0f / 64.0f);
+                       loadmodel->surfmesh.data_morphvertex3f[(j + surface->num_firstvertex) * 3 + 1] = LittleShort(((short *)((unsigned char *)pinmesh + LittleLong(pinmesh->lump_framevertices)))[j * 4 + 1]) * (1.0f / 64.0f);
+                       loadmodel->surfmesh.data_morphvertex3f[(j + surface->num_firstvertex) * 3 + 2] = LittleShort(((short *)((unsigned char *)pinmesh + LittleLong(pinmesh->lump_framevertices)))[j * 4 + 2]) * (1.0f / 64.0f);
                }
 
                if (LittleLong(pinmesh->num_shaders) >= 1)
@@ -1169,10 +1149,10 @@ void Mod_IDP3_Load(model_t *mod, void *buffer, void *bufferend)
                        for (j = 0;j < loadmodel->numskins;j++)
                                Mod_BuildAliasSkinFromSkinFrame(loadmodel->data_textures + i + j * loadmodel->num_surfaces, NULL);
 
-               Mod_ValidateElements(surface->groupmesh->data_element3i + surface->num_firsttriangle * 3, surface->num_triangles, surface->num_firstvertex, surface->num_vertices, __FILE__, __LINE__);
+               Mod_ValidateElements(loadmodel->surfmesh.data_element3i + surface->num_firsttriangle * 3, surface->num_triangles, surface->num_firstvertex, surface->num_vertices, __FILE__, __LINE__);
        }
-       Mod_BuildTriangleNeighbors(loadmodel->meshlist[0]->data_neighbor3i, loadmodel->meshlist[0]->data_element3i, loadmodel->meshlist[0]->num_triangles);
-       Mod_Alias_Mesh_CompileFrameZero(loadmodel->meshlist[0]);
+       Mod_BuildTriangleNeighbors(loadmodel->surfmesh.data_neighbor3i, loadmodel->surfmesh.data_element3i, loadmodel->surfmesh.num_triangles);
+       Mod_Alias_Mesh_CompileFrameZero();
        Mod_CalcAliasModelBBoxes();
        Mod_FreeSkinFiles(skinfiles);
 }
@@ -1345,20 +1325,17 @@ void Mod_ZYMOTICMODEL_Load(model_t *mod, void *buffer, void *bufferend)
 
        loadmodel->nummodelsurfaces = loadmodel->num_surfaces;
        loadmodel->num_textures = loadmodel->num_surfaces;
-       loadmodel->nummeshes = 1;
-       data = (unsigned char *)Mem_Alloc(loadmodel->mempool, loadmodel->num_surfaces * sizeof(msurface_t) + loadmodel->num_surfaces * sizeof(int) + loadmodel->num_surfaces * loadmodel->numskins * sizeof(texture_t) + sizeof(surfmesh_t *) + sizeof(surfmesh_t) + meshtriangles * sizeof(int[6]) + meshvertices * sizeof(float[2]) + numvertexboneweights * sizeof(surfmeshvertexboneweight_t) + loadmodel->num_poses * sizeof(float[3][4]));
+       data = (unsigned char *)Mem_Alloc(loadmodel->mempool, loadmodel->num_surfaces * sizeof(msurface_t) + loadmodel->num_surfaces * sizeof(int) + loadmodel->num_surfaces * loadmodel->numskins * sizeof(texture_t) + meshtriangles * sizeof(int[3]) + meshtriangles * sizeof(int[3]) + meshvertices * sizeof(float[2]) + numvertexboneweights * sizeof(surfmeshvertexboneweight_t) + loadmodel->num_poses * sizeof(float[3][4]));
        loadmodel->data_surfaces = (msurface_t *)data;data += loadmodel->num_surfaces * sizeof(msurface_t);
        loadmodel->surfacelist = (int *)data;data += loadmodel->num_surfaces * sizeof(int);
        loadmodel->data_textures = (texture_t *)data;data += loadmodel->num_surfaces * loadmodel->numskins * sizeof(texture_t);
-       loadmodel->meshlist = (surfmesh_t **)data;data += sizeof(surfmesh_t *);
-       loadmodel->meshlist[0] = (surfmesh_t *)data;data += sizeof(surfmesh_t);
-       loadmodel->meshlist[0]->num_vertices = meshvertices;
-       loadmodel->meshlist[0]->num_triangles = meshtriangles;
-       loadmodel->meshlist[0]->num_vertexboneweights = numvertexboneweights;
-       loadmodel->meshlist[0]->data_element3i = (int *)data;data += meshtriangles * sizeof(int[3]);
-       loadmodel->meshlist[0]->data_neighbor3i = (int *)data;data += meshtriangles * sizeof(int[3]);
-       loadmodel->meshlist[0]->data_texcoordtexture2f = (float *)data;data += meshvertices * sizeof(float[2]);
-       loadmodel->meshlist[0]->data_vertexboneweights = (surfmeshvertexboneweight_t *)data;data += numvertexboneweights * sizeof(surfmeshvertexboneweight_t);
+       loadmodel->surfmesh.num_vertices = meshvertices;
+       loadmodel->surfmesh.num_triangles = meshtriangles;
+       loadmodel->surfmesh.num_vertexboneweights = numvertexboneweights;
+       loadmodel->surfmesh.data_element3i = (int *)data;data += meshtriangles * sizeof(int[3]);
+       loadmodel->surfmesh.data_neighbor3i = (int *)data;data += meshtriangles * sizeof(int[3]);
+       loadmodel->surfmesh.data_texcoordtexture2f = (float *)data;data += meshvertices * sizeof(float[2]);
+       loadmodel->surfmesh.data_vertexboneweights = (surfmeshvertexboneweight_t *)data;data += numvertexboneweights * sizeof(surfmeshvertexboneweight_t);
        loadmodel->data_poses = (float *)data;data += loadmodel->num_poses * sizeof(float[3][4]);
 
        //zymlump_t lump_poses; // float pose[numposes][numbones][3][4]; // animation data
@@ -1376,17 +1353,17 @@ void Mod_ZYMOTICMODEL_Load(model_t *mod, void *buffer, void *bufferend)
                {
                        // this format really should have had a per vertexweight weight value...
                        float influence = 1.0f / vertbonecounts[j];
-                       loadmodel->meshlist[0]->data_vertexboneweights[l].vertexindex = j;
-                       loadmodel->meshlist[0]->data_vertexboneweights[l].boneindex = BigLong(vertdata[l].bonenum);
-                       loadmodel->meshlist[0]->data_vertexboneweights[l].origin[0] = BigFloat(vertdata[l].origin[0]) * influence;
-                       loadmodel->meshlist[0]->data_vertexboneweights[l].origin[1] = BigFloat(vertdata[l].origin[1]) * influence;
-                       loadmodel->meshlist[0]->data_vertexboneweights[l].origin[2] = BigFloat(vertdata[l].origin[2]) * influence;
-                       loadmodel->meshlist[0]->data_vertexboneweights[l].origin[3] = influence;
+                       loadmodel->surfmesh.data_vertexboneweights[l].vertexindex = j;
+                       loadmodel->surfmesh.data_vertexboneweights[l].boneindex = BigLong(vertdata[l].bonenum);
+                       loadmodel->surfmesh.data_vertexboneweights[l].origin[0] = BigFloat(vertdata[l].origin[0]) * influence;
+                       loadmodel->surfmesh.data_vertexboneweights[l].origin[1] = BigFloat(vertdata[l].origin[1]) * influence;
+                       loadmodel->surfmesh.data_vertexboneweights[l].origin[2] = BigFloat(vertdata[l].origin[2]) * influence;
+                       loadmodel->surfmesh.data_vertexboneweights[l].origin[3] = influence;
                }
        }
 
        //zymlump_t lump_texcoords; // float texcoords[numvertices][2];
-       outtexcoord2f = loadmodel->meshlist[0]->data_texcoordtexture2f;
+       outtexcoord2f = loadmodel->surfmesh.data_texcoordtexture2f;
        intexcoord2f = (float *) (pheader->lump_texcoords.start + pbase);
        for (i = 0;i < pheader->numverts;i++)
        {
@@ -1419,7 +1396,6 @@ void Mod_ZYMOTICMODEL_Load(model_t *mod, void *buffer, void *bufferend)
 
                loadmodel->surfacelist[i] = i;
                surface = loadmodel->data_surfaces + i;
-               surface->groupmesh = loadmodel->meshlist[0];
                surface->texture = loadmodel->data_textures + i;
                surface->num_firsttriangle = meshtriangles;
                surface->num_triangles = count;
@@ -1428,7 +1404,7 @@ void Mod_ZYMOTICMODEL_Load(model_t *mod, void *buffer, void *bufferend)
 
                // load the elements and find the used vertex range
                lastvertex = 0;
-               outelements = surface->groupmesh->data_element3i + surface->num_firsttriangle * 3;
+               outelements = loadmodel->surfmesh.data_element3i + surface->num_firsttriangle * 3;
                for (j = 0;j < surface->num_triangles;j++)
                {
                        outelements[2] = BigLong(renderlist[0]);
@@ -1460,10 +1436,10 @@ void Mod_ZYMOTICMODEL_Load(model_t *mod, void *buffer, void *bufferend)
                        for (j = 0;j < loadmodel->numskins;j++)
                                Mod_BuildAliasSkinFromSkinFrame(loadmodel->data_textures + i + j * loadmodel->num_surfaces, NULL);
 
-               Mod_ValidateElements(surface->groupmesh->data_element3i + surface->num_firsttriangle * 3, surface->num_triangles, surface->num_firstvertex, surface->num_vertices, __FILE__, __LINE__);
+               Mod_ValidateElements(loadmodel->surfmesh.data_element3i + surface->num_firsttriangle * 3, surface->num_triangles, surface->num_firstvertex, surface->num_vertices, __FILE__, __LINE__);
        }
-       Mod_BuildTriangleNeighbors(loadmodel->meshlist[0]->data_neighbor3i, loadmodel->meshlist[0]->data_element3i, loadmodel->meshlist[0]->num_triangles);
-       Mod_Alias_Mesh_CompileFrameZero(loadmodel->meshlist[0]);
+       Mod_BuildTriangleNeighbors(loadmodel->surfmesh.data_neighbor3i, loadmodel->surfmesh.data_element3i, loadmodel->surfmesh.num_triangles);
+       Mod_Alias_Mesh_CompileFrameZero();
        Mod_FreeSkinFiles(skinfiles);
        Mem_Free(vertbonecounts);
        Mem_Free(verts);
@@ -1573,21 +1549,18 @@ void Mod_DARKPLACESMODEL_Load(model_t *mod, void *buffer, void *bufferend)
        loadmodel->num_bones = pheader->num_bones;
        loadmodel->num_poses = loadmodel->num_bones * loadmodel->numframes;
        loadmodel->num_textures = loadmodel->nummodelsurfaces = loadmodel->num_surfaces = pheader->num_meshs;
-       loadmodel->nummeshes = 1;
        // do most allocations as one merged chunk
-       data = (unsigned char *)Mem_Alloc(loadmodel->mempool, loadmodel->num_surfaces * sizeof(msurface_t) + loadmodel->num_surfaces * sizeof(int) + loadmodel->num_surfaces * loadmodel->numskins * sizeof(texture_t) + sizeof(surfmesh_t *) + sizeof(surfmesh_t) + meshtriangles * sizeof(int[3]) + meshtriangles * sizeof(int[3]) + meshvertices * sizeof(float[2]) + numvertexboneweights * sizeof(surfmeshvertexboneweight_t) + loadmodel->num_poses * sizeof(float[3][4]) + loadmodel->numskins * sizeof(animscene_t) + loadmodel->num_bones * sizeof(aliasbone_t) + loadmodel->numframes * sizeof(animscene_t));
+       data = (unsigned char *)Mem_Alloc(loadmodel->mempool, loadmodel->num_surfaces * sizeof(msurface_t) + loadmodel->num_surfaces * sizeof(int) + loadmodel->num_surfaces * loadmodel->numskins * sizeof(texture_t) + meshtriangles * sizeof(int[3]) + meshtriangles * sizeof(int[3]) + meshvertices * sizeof(float[2]) + numvertexboneweights * sizeof(surfmeshvertexboneweight_t) + loadmodel->num_poses * sizeof(float[3][4]) + loadmodel->numskins * sizeof(animscene_t) + loadmodel->num_bones * sizeof(aliasbone_t) + loadmodel->numframes * sizeof(animscene_t));
        loadmodel->data_surfaces = (msurface_t *)data;data += loadmodel->num_surfaces * sizeof(msurface_t);
        loadmodel->surfacelist = (int *)data;data += loadmodel->num_surfaces * sizeof(int);
        loadmodel->data_textures = (texture_t *)data;data += loadmodel->num_surfaces * loadmodel->numskins * sizeof(texture_t);
-       loadmodel->meshlist = (surfmesh_t **)data;data += sizeof(surfmesh_t *);
-       loadmodel->meshlist[0] = (surfmesh_t *)data;data += sizeof(surfmesh_t);
-       loadmodel->meshlist[0]->num_vertices = meshvertices;
-       loadmodel->meshlist[0]->num_triangles = meshtriangles;
-       loadmodel->meshlist[0]->num_vertexboneweights = numvertexboneweights;
-       loadmodel->meshlist[0]->data_element3i = (int *)data;data += meshtriangles * sizeof(int[3]);
-       loadmodel->meshlist[0]->data_neighbor3i = (int *)data;data += meshtriangles * sizeof(int[3]);
-       loadmodel->meshlist[0]->data_texcoordtexture2f = (float *)data;data += meshvertices * sizeof(float[2]);
-       loadmodel->meshlist[0]->data_vertexboneweights = (surfmeshvertexboneweight_t *)data;data += numvertexboneweights * sizeof(surfmeshvertexboneweight_t);
+       loadmodel->surfmesh.num_vertices = meshvertices;
+       loadmodel->surfmesh.num_triangles = meshtriangles;
+       loadmodel->surfmesh.num_vertexboneweights = numvertexboneweights;
+       loadmodel->surfmesh.data_element3i = (int *)data;data += meshtriangles * sizeof(int[3]);
+       loadmodel->surfmesh.data_neighbor3i = (int *)data;data += meshtriangles * sizeof(int[3]);
+       loadmodel->surfmesh.data_texcoordtexture2f = (float *)data;data += meshvertices * sizeof(float[2]);
+       loadmodel->surfmesh.data_vertexboneweights = (surfmeshvertexboneweight_t *)data;data += numvertexboneweights * sizeof(surfmeshvertexboneweight_t);
        loadmodel->data_poses = (float *)data;data += loadmodel->num_poses * sizeof(float[3][4]);
        loadmodel->skinscenes = (animscene_t *)data;data += loadmodel->numskins * sizeof(animscene_t);
        loadmodel->data_bones = (aliasbone_t *)data;data += loadmodel->num_bones * sizeof(aliasbone_t);
@@ -1644,7 +1617,6 @@ void Mod_DARKPLACESMODEL_Load(model_t *mod, void *buffer, void *bufferend)
 
                loadmodel->surfacelist[i] = i;
                surface = loadmodel->data_surfaces + i;
-               surface->groupmesh = loadmodel->meshlist[0];
                surface->texture = loadmodel->data_textures + i;
                surface->num_firsttriangle = meshtriangles;
                surface->num_triangles = BigLong(dpmmesh->num_tris);
@@ -1654,7 +1626,7 @@ void Mod_DARKPLACESMODEL_Load(model_t *mod, void *buffer, void *bufferend)
                meshtriangles += surface->num_triangles;
 
                inelements = (int *) (pbase + BigLong(dpmmesh->ofs_indices));
-               outelements = surface->groupmesh->data_element3i + surface->num_firsttriangle * 3;
+               outelements = loadmodel->surfmesh.data_element3i + surface->num_firsttriangle * 3;
                for (j = 0;j < surface->num_triangles;j++)
                {
                        // swap element order to flip triangles, because Quake uses clockwise (rare) and dpm uses counterclockwise (standard)
@@ -1667,7 +1639,7 @@ void Mod_DARKPLACESMODEL_Load(model_t *mod, void *buffer, void *bufferend)
 
                intexcoord = (float *) (pbase + BigLong(dpmmesh->ofs_texcoords));
                for (j = 0;j < surface->num_vertices*2;j++)
-                       surface->groupmesh->data_texcoordtexture2f[j + surface->num_firstvertex * 2] = BigFloat(intexcoord[j]);
+                       loadmodel->surfmesh.data_texcoordtexture2f[j + surface->num_firstvertex * 2] = BigFloat(intexcoord[j]);
 
                data = (unsigned char *) (pbase + BigLong(dpmmesh->ofs_verts));
                for (j = 0;j < surface->num_vertices;j++)
@@ -1678,12 +1650,12 @@ void Mod_DARKPLACESMODEL_Load(model_t *mod, void *buffer, void *bufferend)
                        {
                                const dpmbonevert_t *vert = (dpmbonevert_t *) data;
                                // stuff not processed here: normal
-                               surface->groupmesh->data_vertexboneweights[numvertexboneweights].vertexindex = j;
-                               surface->groupmesh->data_vertexboneweights[numvertexboneweights].boneindex = BigLong(vert->bonenum);
-                               surface->groupmesh->data_vertexboneweights[numvertexboneweights].origin[0] = BigFloat(vert->origin[0]);
-                               surface->groupmesh->data_vertexboneweights[numvertexboneweights].origin[1] = BigFloat(vert->origin[1]);
-                               surface->groupmesh->data_vertexboneweights[numvertexboneweights].origin[2] = BigFloat(vert->origin[2]);
-                               surface->groupmesh->data_vertexboneweights[numvertexboneweights].origin[3] = BigFloat(vert->influence);
+                               loadmodel->surfmesh.data_vertexboneweights[numvertexboneweights].vertexindex = j;
+                               loadmodel->surfmesh.data_vertexboneweights[numvertexboneweights].boneindex = BigLong(vert->bonenum);
+                               loadmodel->surfmesh.data_vertexboneweights[numvertexboneweights].origin[0] = BigFloat(vert->origin[0]);
+                               loadmodel->surfmesh.data_vertexboneweights[numvertexboneweights].origin[1] = BigFloat(vert->origin[1]);
+                               loadmodel->surfmesh.data_vertexboneweights[numvertexboneweights].origin[2] = BigFloat(vert->origin[2]);
+                               loadmodel->surfmesh.data_vertexboneweights[numvertexboneweights].origin[3] = BigFloat(vert->influence);
                                numvertexboneweights++;
                                data += sizeof(dpmbonevert_t);
                        }
@@ -1696,10 +1668,10 @@ void Mod_DARKPLACESMODEL_Load(model_t *mod, void *buffer, void *bufferend)
                        for (j = 0;j < loadmodel->numskins;j++)
                                Mod_BuildAliasSkinFromSkinFrame(loadmodel->data_textures + i + j * loadmodel->num_surfaces, NULL);
 
-               Mod_ValidateElements(surface->groupmesh->data_element3i + surface->num_firsttriangle * 3, surface->num_triangles, surface->num_firstvertex, surface->num_vertices, __FILE__, __LINE__);
+               Mod_ValidateElements(loadmodel->surfmesh.data_element3i + surface->num_firsttriangle * 3, surface->num_triangles, surface->num_firstvertex, surface->num_vertices, __FILE__, __LINE__);
        }
-       Mod_BuildTriangleNeighbors(loadmodel->meshlist[0]->data_neighbor3i, loadmodel->meshlist[0]->data_element3i, loadmodel->meshlist[0]->num_triangles);
-       Mod_Alias_Mesh_CompileFrameZero(loadmodel->meshlist[0]);
+       Mod_BuildTriangleNeighbors(loadmodel->surfmesh.data_neighbor3i, loadmodel->surfmesh.data_element3i, loadmodel->surfmesh.num_triangles);
+       Mod_Alias_Mesh_CompileFrameZero();
        Mod_FreeSkinFiles(skinfiles);
 }
 
@@ -2111,21 +2083,18 @@ void Mod_PSKMODEL_Load(model_t *mod, void *buffer, void *bufferend)
        loadmodel->num_bones = numbones;
        loadmodel->num_poses = loadmodel->num_bones * loadmodel->numframes;
        loadmodel->num_textures = loadmodel->nummodelsurfaces = loadmodel->num_surfaces = nummatts;
-       loadmodel->nummeshes = 1;
        // do most allocations as one merged chunk
-       data = (unsigned char *)Mem_Alloc(loadmodel->mempool, loadmodel->num_surfaces * sizeof(msurface_t) + loadmodel->num_surfaces * sizeof(int) + loadmodel->num_surfaces * loadmodel->numskins * sizeof(texture_t) + sizeof(surfmesh_t *) + sizeof(surfmesh_t) + meshtriangles * sizeof(int[3]) + meshtriangles * sizeof(int[3]) + meshvertices * sizeof(float[2]) + numvertexboneweights * sizeof(surfmeshvertexboneweight_t) + loadmodel->num_poses * sizeof(float[3][4]) + loadmodel->numskins * sizeof(animscene_t) + loadmodel->num_bones * sizeof(aliasbone_t) + loadmodel->numframes * sizeof(animscene_t));
+       data = (unsigned char *)Mem_Alloc(loadmodel->mempool, loadmodel->num_surfaces * sizeof(msurface_t) + loadmodel->num_surfaces * sizeof(int) + loadmodel->num_surfaces * loadmodel->numskins * sizeof(texture_t) + meshtriangles * sizeof(int[3]) + meshtriangles * sizeof(int[3]) + meshvertices * sizeof(float[2]) + numvertexboneweights * sizeof(surfmeshvertexboneweight_t) + loadmodel->num_poses * sizeof(float[3][4]) + loadmodel->numskins * sizeof(animscene_t) + loadmodel->num_bones * sizeof(aliasbone_t) + loadmodel->numframes * sizeof(animscene_t));
        loadmodel->data_surfaces = (msurface_t *)data;data += loadmodel->num_surfaces * sizeof(msurface_t);
        loadmodel->surfacelist = (int *)data;data += loadmodel->num_surfaces * sizeof(int);
        loadmodel->data_textures = (texture_t *)data;data += loadmodel->num_surfaces * loadmodel->numskins * sizeof(texture_t);
-       loadmodel->meshlist = (surfmesh_t **)data;data += sizeof(surfmesh_t *);
-       loadmodel->meshlist[0] = (surfmesh_t *)data;data += sizeof(surfmesh_t);
-       loadmodel->meshlist[0]->num_vertices = meshvertices;
-       loadmodel->meshlist[0]->num_triangles = meshtriangles;
-       loadmodel->meshlist[0]->num_vertexboneweights = numvertexboneweights;
-       loadmodel->meshlist[0]->data_element3i = (int *)data;data += meshtriangles * sizeof(int[3]);
-       loadmodel->meshlist[0]->data_neighbor3i = (int *)data;data += meshtriangles * sizeof(int[3]);
-       loadmodel->meshlist[0]->data_texcoordtexture2f = (float *)data;data += meshvertices * sizeof(float[2]);
-       loadmodel->meshlist[0]->data_vertexboneweights = (surfmeshvertexboneweight_t *)data;data += numvertexboneweights * sizeof(surfmeshvertexboneweight_t);
+       loadmodel->surfmesh.num_vertices = meshvertices;
+       loadmodel->surfmesh.num_triangles = meshtriangles;
+       loadmodel->surfmesh.num_vertexboneweights = numvertexboneweights;
+       loadmodel->surfmesh.data_element3i = (int *)data;data += meshtriangles * sizeof(int[3]);
+       loadmodel->surfmesh.data_neighbor3i = (int *)data;data += meshtriangles * sizeof(int[3]);
+       loadmodel->surfmesh.data_texcoordtexture2f = (float *)data;data += meshvertices * sizeof(float[2]);
+       loadmodel->surfmesh.data_vertexboneweights = (surfmeshvertexboneweight_t *)data;data += numvertexboneweights * sizeof(surfmeshvertexboneweight_t);
        loadmodel->data_poses = (float *)data;data += loadmodel->num_poses * sizeof(float[3][4]);
        loadmodel->skinscenes = (animscene_t *)data;data += loadmodel->numskins * sizeof(animscene_t);
        loadmodel->data_bones = (aliasbone_t *)data;data += loadmodel->num_bones * sizeof(aliasbone_t);
@@ -2149,17 +2118,16 @@ void Mod_PSKMODEL_Load(model_t *mod, void *buffer, void *bufferend)
                        for (j = 0;j < loadmodel->numskins;j++)
                                Mod_BuildAliasSkinFromSkinFrame(loadmodel->data_textures + index + j * loadmodel->num_surfaces, NULL);
                loadmodel->surfacelist[index] = index;
-               loadmodel->data_surfaces[index].groupmesh = loadmodel->meshlist[0];
                loadmodel->data_surfaces[index].texture = loadmodel->data_textures + index;
                loadmodel->data_surfaces[index].num_firstvertex = 0;
-               loadmodel->data_surfaces[index].num_vertices = loadmodel->meshlist[0]->num_vertices;
+               loadmodel->data_surfaces[index].num_vertices = loadmodel->surfmesh.num_vertices;
        }
 
        // copy over the texcoords
        for (index = 0;index < numvtxw;index++)
        {
-               loadmodel->meshlist[0]->data_texcoordtexture2f[index*2+0] = vtxw[index].texcoord[0];
-               loadmodel->meshlist[0]->data_texcoordtexture2f[index*2+1] = vtxw[index].texcoord[1];
+               loadmodel->surfmesh.data_texcoordtexture2f[index*2+0] = vtxw[index].texcoord[0];
+               loadmodel->surfmesh.data_texcoordtexture2f[index*2+1] = vtxw[index].texcoord[1];
        }
 
        // loading the faces is complicated because we need to sort them into surfaces by mattindex
@@ -2174,9 +2142,9 @@ void Mod_PSKMODEL_Load(model_t *mod, void *buffer, void *bufferend)
        for (index = 0;index < numfaces;index++)
        {
                i = (loadmodel->data_surfaces[faces[index].mattindex].num_firsttriangle + loadmodel->data_surfaces[faces[index].mattindex].num_triangles++)*3;
-               loadmodel->meshlist[0]->data_element3i[i+0] = faces[index].vtxwindex[0];
-               loadmodel->meshlist[0]->data_element3i[i+1] = faces[index].vtxwindex[1];
-               loadmodel->meshlist[0]->data_element3i[i+2] = faces[index].vtxwindex[2];
+               loadmodel->surfmesh.data_element3i[i+0] = faces[index].vtxwindex[0];
+               loadmodel->surfmesh.data_element3i[i+1] = faces[index].vtxwindex[1];
+               loadmodel->surfmesh.data_element3i[i+2] = faces[index].vtxwindex[2];
        }
 
        // copy over the bones
@@ -2197,9 +2165,9 @@ void Mod_PSKMODEL_Load(model_t *mod, void *buffer, void *bufferend)
                        if (rawweights[j].pntsindex == vtxw[index].pntsindex)
                        {
                                matrix4x4_t matrix, inversematrix;
-                               loadmodel->meshlist[0]->data_vertexboneweights[numvertexboneweights].vertexindex = index;
-                               loadmodel->meshlist[0]->data_vertexboneweights[numvertexboneweights].boneindex = rawweights[j].boneindex;
-                               loadmodel->meshlist[0]->data_vertexboneweights[numvertexboneweights].weight = rawweights[j].weight;
+                               loadmodel->surfmesh.data_vertexboneweights[numvertexboneweights].vertexindex = index;
+                               loadmodel->surfmesh.data_vertexboneweights[numvertexboneweights].boneindex = rawweights[j].boneindex;
+                               loadmodel->surfmesh.data_vertexboneweights[numvertexboneweights].weight = rawweights[j].weight;
                                matrix = identitymatrix;
                                for (i = rawweights[j].boneindex;i >= 0;i = loadmodel->data_bones[i].parent)
                                {
@@ -2209,8 +2177,8 @@ void Mod_PSKMODEL_Load(model_t *mod, void *buffer, void *bufferend)
                                        Matrix4x4_Concat(&matrix, &tempmatrix, &childmatrix);
                                }
                                Matrix4x4_Invert_Simple(&inversematrix, &matrix);
-                               Matrix4x4_Transform(&inversematrix, pnts[rawweights[j].pntsindex].origin, loadmodel->meshlist[0]->data_vertexboneweights[numvertexboneweights].origin);
-                               VectorScale(loadmodel->meshlist[0]->data_vertexboneweights[numvertexboneweights].origin, loadmodel->meshlist[0]->data_vertexboneweights[numvertexboneweights].weight, loadmodel->meshlist[0]->data_vertexboneweights[numvertexboneweights].origin);
+                               Matrix4x4_Transform(&inversematrix, pnts[rawweights[j].pntsindex].origin, loadmodel->surfmesh.data_vertexboneweights[numvertexboneweights].origin);
+                               VectorScale(loadmodel->surfmesh.data_vertexboneweights[numvertexboneweights].origin, loadmodel->surfmesh.data_vertexboneweights[numvertexboneweights].weight, loadmodel->surfmesh.data_vertexboneweights[numvertexboneweights].origin);
                                numvertexboneweights++;
                        }
                }
@@ -2249,9 +2217,9 @@ void Mod_PSKMODEL_Load(model_t *mod, void *buffer, void *bufferend)
        }
 
        // compile extra data we want
-       Mod_ValidateElements(loadmodel->meshlist[0]->data_element3i, loadmodel->meshlist[0]->num_triangles, 0, loadmodel->meshlist[0]->num_vertices, __FILE__, __LINE__);
-       Mod_BuildTriangleNeighbors(loadmodel->meshlist[0]->data_neighbor3i, loadmodel->meshlist[0]->data_element3i, loadmodel->meshlist[0]->num_triangles);
-       Mod_Alias_Mesh_CompileFrameZero(loadmodel->meshlist[0]);
+       Mod_ValidateElements(loadmodel->surfmesh.data_element3i, loadmodel->surfmesh.num_triangles, 0, loadmodel->surfmesh.num_vertices, __FILE__, __LINE__);
+       Mod_BuildTriangleNeighbors(loadmodel->surfmesh.data_neighbor3i, loadmodel->surfmesh.data_element3i, loadmodel->surfmesh.num_triangles);
+       Mod_Alias_Mesh_CompileFrameZero();
        Mod_FreeSkinFiles(skinfiles);
 
        Mem_Free(animfilebuffer);
index bf3f000..bc788a3 100644 (file)
@@ -430,10 +430,10 @@ static void Mod_Q1BSP_FindNonSolidLocation_r_Leaf(findnonsolidlocationinfo_t *in
                {
                        for (k = 0;k < surface->num_triangles;k++)
                        {
-                               tri = (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle) + k * 3;
-                               VectorCopy((surface->groupmesh->data_vertex3f + tri[0] * 3), vert[0]);
-                               VectorCopy((surface->groupmesh->data_vertex3f + tri[1] * 3), vert[1]);
-                               VectorCopy((surface->groupmesh->data_vertex3f + tri[2] * 3), vert[2]);
+                               tri = (info->model->surfmesh.data_element3i + 3 * surface->num_firsttriangle) + k * 3;
+                               VectorCopy((info->model->surfmesh.data_vertex3f + tri[0] * 3), vert[0]);
+                               VectorCopy((info->model->surfmesh.data_vertex3f + tri[1] * 3), vert[1]);
+                               VectorCopy((info->model->surfmesh.data_vertex3f + tri[2] * 3), vert[2]);
                                VectorSubtract(vert[1], vert[0], edge[0]);
                                VectorSubtract(vert[2], vert[1], edge[1]);
                                CrossProduct(edge[1], edge[0], facenormal);
@@ -1970,7 +1970,7 @@ static void Mod_Q1BSP_GenerateWarpMesh(msurface_t *surface)
 
        subdivpolytriangles = 0;
        subdivpolyverts = 0;
-       SubdividePolygon(surface->num_vertices, (surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex));
+       SubdividePolygon(surface->num_vertices, (surface->mesh->data_vertex3f + 3 * surface->num_firstvertex));
        if (subdivpolytriangles < 1)
                Host_Error("Mod_Q1BSP_GenerateWarpMesh: no triangles?");
 
@@ -2053,9 +2053,7 @@ static void Mod_Q1BSP_LoadFaces(lump_t *l)
                totaltris += numedges - 2;
        }
 
-       loadmodel->nummeshes = 1;
-       loadmodel->meshlist = (surfmesh_t **)Mem_Alloc(loadmodel->mempool, sizeof(surfmesh_t *));
-       loadmodel->meshlist[0] = Mod_AllocSurfMesh(loadmodel->mempool, totalverts, totaltris, true, false, false);
+       Mod_AllocSurfMesh(loadmodel->mempool, totalverts, totaltris, true, false, false);
 
        lightmaptexture = NULL;
        deluxemaptexture = r_texture_blanknormalmap;
@@ -2088,7 +2086,6 @@ static void Mod_Q1BSP_LoadFaces(lump_t *l)
                //      surface->flags |= SURF_PLANEBACK;
                //surface->plane = loadmodel->brush.data_planes + planenum;
 
-               surface->groupmesh = loadmodel->meshlist[0];
                surface->num_firstvertex = totalverts;
                surface->num_vertices = numedges;
                surface->num_firsttriangle = totaltris;
@@ -2102,37 +2099,37 @@ static void Mod_Q1BSP_LoadFaces(lump_t *l)
                        int lindex = loadmodel->brushq1.surfedges[firstedge + i];
                        float s, t;
                        if (lindex > 0)
-                               VectorCopy(loadmodel->brushq1.vertexes[loadmodel->brushq1.edges[lindex].v[0]].position, (surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex) + i * 3);
+                               VectorCopy(loadmodel->brushq1.vertexes[loadmodel->brushq1.edges[lindex].v[0]].position, (loadmodel->surfmesh.data_vertex3f + 3 * surface->num_firstvertex) + i * 3);
                        else
-                               VectorCopy(loadmodel->brushq1.vertexes[loadmodel->brushq1.edges[-lindex].v[1]].position, (surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex) + i * 3);
-                       s = DotProduct(((surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex) + i * 3), surface->lightmapinfo->texinfo->vecs[0]) + surface->lightmapinfo->texinfo->vecs[0][3];
-                       t = DotProduct(((surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex) + i * 3), surface->lightmapinfo->texinfo->vecs[1]) + surface->lightmapinfo->texinfo->vecs[1][3];
-                       (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex)[i * 2 + 0] = s / surface->texture->width;
-                       (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex)[i * 2 + 1] = t / surface->texture->height;
-                       (surface->groupmesh->data_texcoordlightmap2f + 2 * surface->num_firstvertex)[i * 2 + 0] = 0;
-                       (surface->groupmesh->data_texcoordlightmap2f + 2 * surface->num_firstvertex)[i * 2 + 1] = 0;
-                       (surface->groupmesh->data_lightmapoffsets + surface->num_firstvertex)[i] = 0;
+                               VectorCopy(loadmodel->brushq1.vertexes[loadmodel->brushq1.edges[-lindex].v[1]].position, (loadmodel->surfmesh.data_vertex3f + 3 * surface->num_firstvertex) + i * 3);
+                       s = DotProduct(((loadmodel->surfmesh.data_vertex3f + 3 * surface->num_firstvertex) + i * 3), surface->lightmapinfo->texinfo->vecs[0]) + surface->lightmapinfo->texinfo->vecs[0][3];
+                       t = DotProduct(((loadmodel->surfmesh.data_vertex3f + 3 * surface->num_firstvertex) + i * 3), surface->lightmapinfo->texinfo->vecs[1]) + surface->lightmapinfo->texinfo->vecs[1][3];
+                       (loadmodel->surfmesh.data_texcoordtexture2f + 2 * surface->num_firstvertex)[i * 2 + 0] = s / surface->texture->width;
+                       (loadmodel->surfmesh.data_texcoordtexture2f + 2 * surface->num_firstvertex)[i * 2 + 1] = t / surface->texture->height;
+                       (loadmodel->surfmesh.data_texcoordlightmap2f + 2 * surface->num_firstvertex)[i * 2 + 0] = 0;
+                       (loadmodel->surfmesh.data_texcoordlightmap2f + 2 * surface->num_firstvertex)[i * 2 + 1] = 0;
+                       (loadmodel->surfmesh.data_lightmapoffsets + surface->num_firstvertex)[i] = 0;
                }
 
                for (i = 0;i < surface->num_triangles;i++)
                {
-                       (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle)[i * 3 + 0] = 0 + surface->num_firstvertex;
-                       (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle)[i * 3 + 1] = i + 1 + surface->num_firstvertex;
-                       (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle)[i * 3 + 2] = i + 2 + surface->num_firstvertex;
+                       (loadmodel->surfmesh.data_element3i + 3 * surface->num_firsttriangle)[i * 3 + 0] = 0 + surface->num_firstvertex;
+                       (loadmodel->surfmesh.data_element3i + 3 * surface->num_firsttriangle)[i * 3 + 1] = i + 1 + surface->num_firstvertex;
+                       (loadmodel->surfmesh.data_element3i + 3 * surface->num_firsttriangle)[i * 3 + 2] = i + 2 + surface->num_firstvertex;
                }
 
                // compile additional data about the surface geometry
-               Mod_BuildTextureVectorsAndNormals(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, surface->groupmesh->data_vertex3f, surface->groupmesh->data_texcoordtexture2f, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle), surface->groupmesh->data_svector3f, surface->groupmesh->data_tvector3f, surface->groupmesh->data_normal3f, true);
-               BoxFromPoints(surface->mins, surface->maxs, surface->num_vertices, (surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex));
+               Mod_BuildTextureVectorsAndNormals(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, loadmodel->surfmesh.data_vertex3f, loadmodel->surfmesh.data_texcoordtexture2f, (loadmodel->surfmesh.data_element3i + 3 * surface->num_firsttriangle), loadmodel->surfmesh.data_svector3f, loadmodel->surfmesh.data_tvector3f, loadmodel->surfmesh.data_normal3f, true);
+               BoxFromPoints(surface->mins, surface->maxs, surface->num_vertices, (loadmodel->surfmesh.data_vertex3f + 3 * surface->num_firstvertex));
 
                // generate surface extents information
-               texmins[0] = texmaxs[0] = DotProduct((surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex), surface->lightmapinfo->texinfo->vecs[0]) + surface->lightmapinfo->texinfo->vecs[0][3];
-               texmins[1] = texmaxs[1] = DotProduct((surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex), surface->lightmapinfo->texinfo->vecs[1]) + surface->lightmapinfo->texinfo->vecs[1][3];
+               texmins[0] = texmaxs[0] = DotProduct((loadmodel->surfmesh.data_vertex3f + 3 * surface->num_firstvertex), surface->lightmapinfo->texinfo->vecs[0]) + surface->lightmapinfo->texinfo->vecs[0][3];
+               texmins[1] = texmaxs[1] = DotProduct((loadmodel->surfmesh.data_vertex3f + 3 * surface->num_firstvertex), surface->lightmapinfo->texinfo->vecs[1]) + surface->lightmapinfo->texinfo->vecs[1][3];
                for (i = 1;i < surface->num_vertices;i++)
                {
                        for (j = 0;j < 2;j++)
                        {
-                               val = DotProduct((surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex) + i * 3, surface->lightmapinfo->texinfo->vecs[j]) + surface->lightmapinfo->texinfo->vecs[j][3];
+                               val = DotProduct((loadmodel->surfmesh.data_vertex3f + 3 * surface->num_firstvertex) + i * 3, surface->lightmapinfo->texinfo->vecs[j]) + surface->lightmapinfo->texinfo->vecs[j][3];
                                texmins[j] = min(texmins[j], val);
                                texmaxs[j] = max(texmaxs[j], val);
                        }
@@ -2213,14 +2210,14 @@ static void Mod_Q1BSP_LoadFaces(lump_t *l)
 
                        for (i = 0;i < surface->num_vertices;i++)
                        {
-                               u = ((DotProduct(((surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex) + i * 3), surface->lightmapinfo->texinfo->vecs[0]) + surface->lightmapinfo->texinfo->vecs[0][3]) + 8 - surface->lightmapinfo->texturemins[0]) * (1.0 / 16.0);
-                               v = ((DotProduct(((surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex) + i * 3), surface->lightmapinfo->texinfo->vecs[1]) + surface->lightmapinfo->texinfo->vecs[1][3]) + 8 - surface->lightmapinfo->texturemins[1]) * (1.0 / 16.0);
-                               (surface->groupmesh->data_texcoordlightmap2f + 2 * surface->num_firstvertex)[i * 2 + 0] = u * uscale + ubase;
-                               (surface->groupmesh->data_texcoordlightmap2f + 2 * surface->num_firstvertex)[i * 2 + 1] = v * vscale + vbase;
+                               u = ((DotProduct(((loadmodel->surfmesh.data_vertex3f + 3 * surface->num_firstvertex) + i * 3), surface->lightmapinfo->texinfo->vecs[0]) + surface->lightmapinfo->texinfo->vecs[0][3]) + 8 - surface->lightmapinfo->texturemins[0]) * (1.0 / 16.0);
+                               v = ((DotProduct(((loadmodel->surfmesh.data_vertex3f + 3 * surface->num_firstvertex) + i * 3), surface->lightmapinfo->texinfo->vecs[1]) + surface->lightmapinfo->texinfo->vecs[1][3]) + 8 - surface->lightmapinfo->texturemins[1]) * (1.0 / 16.0);
+                               (loadmodel->surfmesh.data_texcoordlightmap2f + 2 * surface->num_firstvertex)[i * 2 + 0] = u * uscale + ubase;
+                               (loadmodel->surfmesh.data_texcoordlightmap2f + 2 * surface->num_firstvertex)[i * 2 + 1] = v * vscale + vbase;
                                // LordHavoc: calc lightmap data offset for vertex lighting to use
                                iu = (int) u;
                                iv = (int) v;
-                               (surface->groupmesh->data_lightmapoffsets + surface->num_firstvertex)[i] = (bound(0, iv, tmax) * ssize + bound(0, iu, smax)) * 3;
+                               (loadmodel->surfmesh.data_lightmapoffsets + surface->num_firstvertex)[i] = (bound(0, iv, tmax) * ssize + bound(0, iu, smax)) * 3;
                        }
                }
        }
@@ -3281,7 +3278,7 @@ void Mod_Q1BSP_Load(model_t *mod, void *buffer, void *bufferend)
        }
        loadmodel->brush.shadowmesh = Mod_ShadowMesh_Begin(loadmodel->mempool, numshadowmeshtriangles * 3, numshadowmeshtriangles, NULL, NULL, NULL, false, false, true);
        for (j = 0, surface = loadmodel->data_surfaces;j < loadmodel->num_surfaces;j++, surface++)
-               Mod_ShadowMesh_AddMesh(loadmodel->mempool, loadmodel->brush.shadowmesh, NULL, NULL, NULL, surface->groupmesh->data_vertex3f, NULL, NULL, NULL, NULL, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
+               Mod_ShadowMesh_AddMesh(loadmodel->mempool, loadmodel->brush.shadowmesh, NULL, NULL, NULL, loadmodel->surfmesh.data_vertex3f, NULL, NULL, NULL, NULL, surface->num_triangles, (loadmodel->surfmesh.data_element3i + 3 * surface->num_firsttriangle));
        loadmodel->brush.shadowmesh = Mod_ShadowMesh_Finish(loadmodel->mempool, loadmodel->brush.shadowmesh, false, true);
        Mod_BuildTriangleNeighbors(loadmodel->brush.shadowmesh->neighbor3i, loadmodel->brush.shadowmesh->element3i, loadmodel->brush.shadowmesh->numtriangles);
 
@@ -3389,7 +3386,7 @@ void Mod_Q1BSP_Load(model_t *mod, void *buffer, void *bufferend)
                                if (surface->texture->basematerialflags & MATERIALFLAG_SKY)
                                        mod->DrawSky = R_Q1BSP_DrawSky;
                                // calculate bounding shapes
-                               for (k = 0, vec = (surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex);k < surface->num_vertices;k++, vec += 3)
+                               for (k = 0, vec = (loadmodel->surfmesh.data_vertex3f + 3 * surface->num_firstvertex);k < surface->num_vertices;k++, vec += 3)
                                {
                                        if (mod->normalmins[0] > vec[0]) mod->normalmins[0] = vec[0];
                                        if (mod->normalmins[1] > vec[1]) mod->normalmins[1] = vec[1];
@@ -4627,12 +4624,10 @@ static void Mod_Q3BSP_LoadFaces(lump_t *l)
        i = oldi;
        in = oldin;
        out = oldout;
-       loadmodel->nummeshes = 1;
-       loadmodel->meshlist = (surfmesh_t **)Mem_Alloc(loadmodel->mempool, sizeof(surfmesh_t *));
-       loadmodel->meshlist[0] = Mod_AllocSurfMesh(loadmodel->mempool, meshvertices, meshtriangles, false, true, false);
+       Mod_AllocSurfMesh(loadmodel->mempool, meshvertices, meshtriangles, false, true, false);
        meshvertices = 0;
        meshtriangles = 0;
-       for (;i < count && meshvertices + out->num_vertices <= loadmodel->meshlist[0]->num_vertices;i++, in++, out++)
+       for (;i < count && meshvertices + out->num_vertices <= loadmodel->surfmesh.num_vertices;i++, in++, out++)
        {
                if (out->num_vertices < 3 || out->num_triangles < 1)
                        continue;
@@ -4640,7 +4635,6 @@ static void Mod_Q3BSP_LoadFaces(lump_t *l)
                type = LittleLong(in->type);
                firstvertex = LittleLong(in->firstvertex);
                firstelement = LittleLong(in->firstelement);
-               out->groupmesh = loadmodel->meshlist[0];
                out->num_firstvertex = meshvertices;
                out->num_firsttriangle = meshtriangles;
                switch(type)
@@ -4650,20 +4644,20 @@ static void Mod_Q3BSP_LoadFaces(lump_t *l)
                        // no processing necessary
                        for (j = 0;j < out->num_vertices;j++)
                        {
-                               (out->groupmesh->data_vertex3f + 3 * out->num_firstvertex)[j * 3 + 0] = loadmodel->brushq3.data_vertex3f[(firstvertex + j) * 3 + 0];
-                               (out->groupmesh->data_vertex3f + 3 * out->num_firstvertex)[j * 3 + 1] = loadmodel->brushq3.data_vertex3f[(firstvertex + j) * 3 + 1];
-                               (out->groupmesh->data_vertex3f + 3 * out->num_firstvertex)[j * 3 + 2] = loadmodel->brushq3.data_vertex3f[(firstvertex + j) * 3 + 2];
-                               (out->groupmesh->data_texcoordtexture2f + 2 * out->num_firstvertex)[j * 2 + 0] = loadmodel->brushq3.data_texcoordtexture2f[(firstvertex + j) * 2 + 0];
-                               (out->groupmesh->data_texcoordtexture2f + 2 * out->num_firstvertex)[j * 2 + 1] = loadmodel->brushq3.data_texcoordtexture2f[(firstvertex + j) * 2 + 1];
-                               (out->groupmesh->data_texcoordlightmap2f + 2 * out->num_firstvertex)[j * 2 + 0] = loadmodel->brushq3.data_texcoordlightmap2f[(firstvertex + j) * 2 + 0];
-                               (out->groupmesh->data_texcoordlightmap2f + 2 * out->num_firstvertex)[j * 2 + 1] = loadmodel->brushq3.data_texcoordlightmap2f[(firstvertex + j) * 2 + 1];
-                               (out->groupmesh->data_lightmapcolor4f + 4 * out->num_firstvertex)[j * 4 + 0] = loadmodel->brushq3.data_color4f[(firstvertex + j) * 4 + 0];
-                               (out->groupmesh->data_lightmapcolor4f + 4 * out->num_firstvertex)[j * 4 + 1] = loadmodel->brushq3.data_color4f[(firstvertex + j) * 4 + 1];
-                               (out->groupmesh->data_lightmapcolor4f + 4 * out->num_firstvertex)[j * 4 + 2] = loadmodel->brushq3.data_color4f[(firstvertex + j) * 4 + 2];
-                               (out->groupmesh->data_lightmapcolor4f + 4 * out->num_firstvertex)[j * 4 + 3] = loadmodel->brushq3.data_color4f[(firstvertex + j) * 4 + 3];
+                               (loadmodel->surfmesh.data_vertex3f + 3 * out->num_firstvertex)[j * 3 + 0] = loadmodel->brushq3.data_vertex3f[(firstvertex + j) * 3 + 0];
+                               (loadmodel->surfmesh.data_vertex3f + 3 * out->num_firstvertex)[j * 3 + 1] = loadmodel->brushq3.data_vertex3f[(firstvertex + j) * 3 + 1];
+                               (loadmodel->surfmesh.data_vertex3f + 3 * out->num_firstvertex)[j * 3 + 2] = loadmodel->brushq3.data_vertex3f[(firstvertex + j) * 3 + 2];
+                               (loadmodel->surfmesh.data_texcoordtexture2f + 2 * out->num_firstvertex)[j * 2 + 0] = loadmodel->brushq3.data_texcoordtexture2f[(firstvertex + j) * 2 + 0];
+                               (loadmodel->surfmesh.data_texcoordtexture2f + 2 * out->num_firstvertex)[j * 2 + 1] = loadmodel->brushq3.data_texcoordtexture2f[(firstvertex + j) * 2 + 1];
+                               (loadmodel->surfmesh.data_texcoordlightmap2f + 2 * out->num_firstvertex)[j * 2 + 0] = loadmodel->brushq3.data_texcoordlightmap2f[(firstvertex + j) * 2 + 0];
+                               (loadmodel->surfmesh.data_texcoordlightmap2f + 2 * out->num_firstvertex)[j * 2 + 1] = loadmodel->brushq3.data_texcoordlightmap2f[(firstvertex + j) * 2 + 1];
+                               (loadmodel->surfmesh.data_lightmapcolor4f + 4 * out->num_firstvertex)[j * 4 + 0] = loadmodel->brushq3.data_color4f[(firstvertex + j) * 4 + 0];
+                               (loadmodel->surfmesh.data_lightmapcolor4f + 4 * out->num_firstvertex)[j * 4 + 1] = loadmodel->brushq3.data_color4f[(firstvertex + j) * 4 + 1];
+                               (loadmodel->surfmesh.data_lightmapcolor4f + 4 * out->num_firstvertex)[j * 4 + 2] = loadmodel->brushq3.data_color4f[(firstvertex + j) * 4 + 2];
+                               (loadmodel->surfmesh.data_lightmapcolor4f + 4 * out->num_firstvertex)[j * 4 + 3] = loadmodel->brushq3.data_color4f[(firstvertex + j) * 4 + 3];
                        }
                        for (j = 0;j < out->num_triangles*3;j++)
-                               (out->groupmesh->data_element3i + 3 * out->num_firsttriangle)[j] = loadmodel->brushq3.data_element3i[firstelement + j] + out->num_firstvertex;
+                               (loadmodel->surfmesh.data_element3i + 3 * out->num_firsttriangle)[j] = loadmodel->brushq3.data_element3i[firstelement + j] + out->num_firstvertex;
                        break;
                case Q3FACETYPE_PATCH:
                        patchsize[0] = LittleLong(in->specific.patch.patchsize[0]);
@@ -4696,12 +4690,12 @@ static void Mod_Q3BSP_LoadFaces(lump_t *l)
                        type = Q3FACETYPE_MESH;
                        // generate geometry
                        // (note: normals are skipped because they get recalculated)
-                       Q3PatchTesselateFloat(3, sizeof(float[3]), (out->groupmesh->data_vertex3f + 3 * out->num_firstvertex), patchsize[0], patchsize[1], sizeof(float[3]), originalvertex3f, xtess, ytess);
-                       Q3PatchTesselateFloat(2, sizeof(float[2]), (out->groupmesh->data_texcoordtexture2f + 2 * out->num_firstvertex), patchsize[0], patchsize[1], sizeof(float[2]), originaltexcoordtexture2f, xtess, ytess);
-                       Q3PatchTesselateFloat(2, sizeof(float[2]), (out->groupmesh->data_texcoordlightmap2f + 2 * out->num_firstvertex), patchsize[0], patchsize[1], sizeof(float[2]), originaltexcoordlightmap2f, xtess, ytess);
-                       Q3PatchTesselateFloat(4, sizeof(float[4]), (out->groupmesh->data_lightmapcolor4f + 4 * out->num_firstvertex), patchsize[0], patchsize[1], sizeof(float[4]), originalcolor4f, xtess, ytess);
-                       Q3PatchTriangleElements((out->groupmesh->data_element3i + 3 * out->num_firsttriangle), finalwidth, finalheight, out->num_firstvertex);
-                       out->num_triangles = Mod_RemoveDegenerateTriangles(out->num_triangles, (out->groupmesh->data_element3i + 3 * out->num_firsttriangle), (out->groupmesh->data_element3i + 3 * out->num_firsttriangle), out->groupmesh->data_vertex3f);
+                       Q3PatchTesselateFloat(3, sizeof(float[3]), (loadmodel->surfmesh.data_vertex3f + 3 * out->num_firstvertex), patchsize[0], patchsize[1], sizeof(float[3]), originalvertex3f, xtess, ytess);
+                       Q3PatchTesselateFloat(2, sizeof(float[2]), (loadmodel->surfmesh.data_texcoordtexture2f + 2 * out->num_firstvertex), patchsize[0], patchsize[1], sizeof(float[2]), originaltexcoordtexture2f, xtess, ytess);
+                       Q3PatchTesselateFloat(2, sizeof(float[2]), (loadmodel->surfmesh.data_texcoordlightmap2f + 2 * out->num_firstvertex), patchsize[0], patchsize[1], sizeof(float[2]), originaltexcoordlightmap2f, xtess, ytess);
+                       Q3PatchTesselateFloat(4, sizeof(float[4]), (loadmodel->surfmesh.data_lightmapcolor4f + 4 * out->num_firstvertex), patchsize[0], patchsize[1], sizeof(float[4]), originalcolor4f, xtess, ytess);
+                       Q3PatchTriangleElements((loadmodel->surfmesh.data_element3i + 3 * out->num_firsttriangle), finalwidth, finalheight, out->num_firstvertex);
+                       out->num_triangles = Mod_RemoveDegenerateTriangles(out->num_triangles, (loadmodel->surfmesh.data_element3i + 3 * out->num_firsttriangle), (loadmodel->surfmesh.data_element3i + 3 * out->num_firsttriangle), loadmodel->surfmesh.data_vertex3f);
                        if (developer.integer >= 100)
                        {
                                if (out->num_triangles < finaltriangles)
@@ -4739,7 +4733,7 @@ static void Mod_Q3BSP_LoadFaces(lump_t *l)
                        Q3PatchTesselateFloat(3, sizeof(float[3]), out->data_collisionvertex3f, patchsize[0], patchsize[1], sizeof(float[3]), originalvertex3f, xtess, ytess);
                        Q3PatchTriangleElements(out->data_collisionelement3i, finalwidth, finalheight, 0);
 
-                       //Mod_SnapVertices(3, out->num_vertices, (out->groupmesh->data_vertex3f + 3 * out->num_firstvertex), 0.25);
+                       //Mod_SnapVertices(3, out->num_vertices, (loadmodel->surfmesh.data_vertex3f + 3 * out->num_firstvertex), 0.25);
                        Mod_SnapVertices(3, out->num_collisionvertices, out->data_collisionvertex3f, 1);
 
                        oldnumtriangles = out->num_triangles;
@@ -4754,29 +4748,29 @@ static void Mod_Q3BSP_LoadFaces(lump_t *l)
                meshvertices += out->num_vertices;
                meshtriangles += out->num_triangles;
                for (j = 0, invalidelements = 0;j < out->num_triangles * 3;j++)
-                       if ((out->groupmesh->data_element3i + 3 * out->num_firsttriangle)[j] < out->num_firstvertex || (out->groupmesh->data_element3i + 3 * out->num_firsttriangle)[j] >= out->num_firstvertex + out->num_vertices)
+                       if ((loadmodel->surfmesh.data_element3i + 3 * out->num_firsttriangle)[j] < out->num_firstvertex || (loadmodel->surfmesh.data_element3i + 3 * out->num_firsttriangle)[j] >= out->num_firstvertex + out->num_vertices)
                                invalidelements++;
                if (invalidelements)
                {
                        Con_Printf("Mod_Q3BSP_LoadFaces: Warning: face #%i has %i invalid elements, type = %i, texture->name = \"%s\", texture->surfaceflags = %i, firstvertex = %i, numvertices = %i, firstelement = %i, numelements = %i, elements list:\n", i, invalidelements, type, out->texture->name, out->texture->surfaceflags, firstvertex, out->num_vertices, firstelement, out->num_triangles * 3);
                        for (j = 0;j < out->num_triangles * 3;j++)
                        {
-                               Con_Printf(" %i", (out->groupmesh->data_element3i + 3 * out->num_firsttriangle)[j] - out->num_firstvertex);
-                               if ((out->groupmesh->data_element3i + 3 * out->num_firsttriangle)[j] < out->num_firstvertex || (out->groupmesh->data_element3i + 3 * out->num_firsttriangle)[j] >= out->num_firstvertex + out->num_vertices)
-                                       (out->groupmesh->data_element3i + 3 * out->num_firsttriangle)[j] = out->num_firstvertex;
+                               Con_Printf(" %i", (loadmodel->surfmesh.data_element3i + 3 * out->num_firsttriangle)[j] - out->num_firstvertex);
+                               if ((loadmodel->surfmesh.data_element3i + 3 * out->num_firsttriangle)[j] < out->num_firstvertex || (loadmodel->surfmesh.data_element3i + 3 * out->num_firsttriangle)[j] >= out->num_firstvertex + out->num_vertices)
+                                       (loadmodel->surfmesh.data_element3i + 3 * out->num_firsttriangle)[j] = out->num_firstvertex;
                        }
                        Con_Print("\n");
                }
                // for per pixel lighting
-               Mod_BuildTextureVectorsAndNormals(out->num_firstvertex, out->num_vertices, out->num_triangles, out->groupmesh->data_vertex3f, out->groupmesh->data_texcoordtexture2f, (out->groupmesh->data_element3i + 3 * out->num_firsttriangle), out->groupmesh->data_svector3f, out->groupmesh->data_tvector3f, out->groupmesh->data_normal3f, true);
+               Mod_BuildTextureVectorsAndNormals(out->num_firstvertex, out->num_vertices, out->num_triangles, loadmodel->surfmesh.data_vertex3f, loadmodel->surfmesh.data_texcoordtexture2f, (loadmodel->surfmesh.data_element3i + 3 * out->num_firsttriangle), loadmodel->surfmesh.data_svector3f, loadmodel->surfmesh.data_tvector3f, loadmodel->surfmesh.data_normal3f, true);
                // calculate a bounding box
                VectorClear(out->mins);
                VectorClear(out->maxs);
                if (out->num_vertices)
                {
-                       VectorCopy((out->groupmesh->data_vertex3f + 3 * out->num_firstvertex), out->mins);
-                       VectorCopy((out->groupmesh->data_vertex3f + 3 * out->num_firstvertex), out->maxs);
-                       for (j = 1, v = (out->groupmesh->data_vertex3f + 3 * out->num_firstvertex) + 3;j < out->num_vertices;j++, v += 3)
+                       VectorCopy((loadmodel->surfmesh.data_vertex3f + 3 * out->num_firstvertex), out->mins);
+                       VectorCopy((loadmodel->surfmesh.data_vertex3f + 3 * out->num_firstvertex), out->maxs);
+                       for (j = 1, v = (loadmodel->surfmesh.data_vertex3f + 3 * out->num_firstvertex) + 3;j < out->num_vertices;j++, v += 3)
                        {
                                out->mins[0] = min(out->mins[0], v[0]);
                                out->maxs[0] = max(out->maxs[0], v[0]);
@@ -5545,8 +5539,8 @@ void Mod_Q3BSP_Load(model_t *mod, void *buffer, void *bufferend)
        }
        loadmodel->brush.shadowmesh = Mod_ShadowMesh_Begin(loadmodel->mempool, numshadowmeshtriangles * 3, numshadowmeshtriangles, NULL, NULL, NULL, false, false, true);
        for (j = 0, surface = loadmodel->data_surfaces;j < loadmodel->num_surfaces;j++, surface++)
-               if (surface->groupmesh)
-                       Mod_ShadowMesh_AddMesh(loadmodel->mempool, loadmodel->brush.shadowmesh, NULL, NULL, NULL, surface->groupmesh->data_vertex3f, NULL, NULL, NULL, NULL, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
+               if (surface->num_triangles > 0)
+                       Mod_ShadowMesh_AddMesh(loadmodel->mempool, loadmodel->brush.shadowmesh, NULL, NULL, NULL, loadmodel->surfmesh.data_vertex3f, NULL, NULL, NULL, NULL, surface->num_triangles, (loadmodel->surfmesh.data_element3i + 3 * surface->num_firsttriangle));
        loadmodel->brush.shadowmesh = Mod_ShadowMesh_Finish(loadmodel->mempool, loadmodel->brush.shadowmesh, false, true);
        Mod_BuildTriangleNeighbors(loadmodel->brush.shadowmesh->neighbor3i, loadmodel->brush.shadowmesh->element3i, loadmodel->brush.shadowmesh->numtriangles);
 
index ae555e8..841346b 100644 (file)
@@ -707,34 +707,31 @@ void Mod_BuildTextureVectorsAndNormals(int firstvertex, int numvertices, int num
                        VectorNormalize(v);
 }
 
-surfmesh_t *Mod_AllocSurfMesh(mempool_t *mempool, int numvertices, int numtriangles, qboolean lightmapoffsets, qboolean vertexcolors, qboolean neighbors)
+void Mod_AllocSurfMesh(mempool_t *mempool, int numvertices, int numtriangles, qboolean lightmapoffsets, qboolean vertexcolors, qboolean neighbors)
 {
-       surfmesh_t *mesh;
        unsigned char *data;
-       mesh = (surfmesh_t *)Mem_Alloc(mempool, sizeof(surfmesh_t) + numvertices * (3 + 3 + 3 + 3 + 2 + 2 + (vertexcolors ? 4 : 0)) * sizeof(float) + numvertices * (lightmapoffsets ? 1 : 0) * sizeof(int) + numtriangles * (3 + (neighbors ? 3 : 0)) * sizeof(int));
-       mesh->num_vertices = numvertices;
-       mesh->num_triangles = numtriangles;
-       data = (unsigned char *)(mesh + 1);
-       if (mesh->num_vertices)
+       data = (unsigned char *)Mem_Alloc(mempool, numvertices * (3 + 3 + 3 + 3 + 2 + 2 + (vertexcolors ? 4 : 0)) * sizeof(float) + numvertices * (lightmapoffsets ? 1 : 0) * sizeof(int) + numtriangles * (3 + (neighbors ? 3 : 0)) * sizeof(int));
+       loadmodel->surfmesh.num_vertices = numvertices;
+       loadmodel->surfmesh.num_triangles = numtriangles;
+       if (loadmodel->surfmesh.num_vertices)
        {
-               mesh->data_vertex3f = (float *)data, data += sizeof(float[3]) * mesh->num_vertices;
-               mesh->data_svector3f = (float *)data, data += sizeof(float[3]) * mesh->num_vertices;
-               mesh->data_tvector3f = (float *)data, data += sizeof(float[3]) * mesh->num_vertices;
-               mesh->data_normal3f = (float *)data, data += sizeof(float[3]) * mesh->num_vertices;
-               mesh->data_texcoordtexture2f = (float *)data, data += sizeof(float[2]) * mesh->num_vertices;
-               mesh->data_texcoordlightmap2f = (float *)data, data += sizeof(float[2]) * mesh->num_vertices;
+               loadmodel->surfmesh.data_vertex3f = (float *)data, data += sizeof(float[3]) * loadmodel->surfmesh.num_vertices;
+               loadmodel->surfmesh.data_svector3f = (float *)data, data += sizeof(float[3]) * loadmodel->surfmesh.num_vertices;
+               loadmodel->surfmesh.data_tvector3f = (float *)data, data += sizeof(float[3]) * loadmodel->surfmesh.num_vertices;
+               loadmodel->surfmesh.data_normal3f = (float *)data, data += sizeof(float[3]) * loadmodel->surfmesh.num_vertices;
+               loadmodel->surfmesh.data_texcoordtexture2f = (float *)data, data += sizeof(float[2]) * loadmodel->surfmesh.num_vertices;
+               loadmodel->surfmesh.data_texcoordlightmap2f = (float *)data, data += sizeof(float[2]) * loadmodel->surfmesh.num_vertices;
                if (vertexcolors)
-                       mesh->data_lightmapcolor4f = (float *)data, data += sizeof(float[4]) * mesh->num_vertices;
+                       loadmodel->surfmesh.data_lightmapcolor4f = (float *)data, data += sizeof(float[4]) * loadmodel->surfmesh.num_vertices;
                if (lightmapoffsets)
-                       mesh->data_lightmapoffsets = (int *)data, data += sizeof(int) * mesh->num_vertices;
+                       loadmodel->surfmesh.data_lightmapoffsets = (int *)data, data += sizeof(int) * loadmodel->surfmesh.num_vertices;
        }
-       if (mesh->num_triangles)
+       if (loadmodel->surfmesh.num_triangles)
        {
-               mesh->data_element3i = (int *)data, data += sizeof(int[3]) * mesh->num_triangles;
+               loadmodel->surfmesh.data_element3i = (int *)data, data += sizeof(int[3]) * loadmodel->surfmesh.num_triangles;
                if (neighbors)
-                       mesh->data_neighbor3i = (int *)data, data += sizeof(int[3]) * mesh->num_triangles;
+                       loadmodel->surfmesh.data_neighbor3i = (int *)data, data += sizeof(int[3]) * loadmodel->surfmesh.num_triangles;
        }
-       return mesh;
 }
 
 shadowmesh_t *Mod_ShadowMesh_Alloc(mempool_t *mempool, int maxverts, int maxtriangles, rtexture_t *map_diffuse, rtexture_t *map_specular, rtexture_t *map_normal, int light, int neighbors, int expandable)
index 811b4d3..e1fc004 100644 (file)
@@ -269,12 +269,11 @@ typedef struct msurface_s
        // the lighting direction texture fragment to use on the rendering mesh
        rtexture_t *deluxemaptexture;
 
-       // this surface is part of this mesh
-       surfmesh_t *groupmesh;
-       int num_triangles; // number of triangles in the mesh
-       int num_firsttriangle; // first triangle in the mesh (index into groupmesh)
-       int num_vertices; // number of vertices in the mesh
-       int num_firstvertex; // first vertex in the mesh (index into groupmesh)
+       // surfaces own ranges of vertices and triangles in the model->surfmesh
+       int num_triangles; // number of triangles
+       int num_firsttriangle; // first triangle
+       int num_vertices; // number of vertices
+       int num_firstvertex; // first vertex
 
        // shadow volume building information
        int num_firstshadowmeshtriangle; // index into model->brush.shadowmesh
@@ -559,11 +558,8 @@ typedef struct model_s
        msurface_t              *data_surfaces;
        // optional lightmapinfo data for surface lightmap updates
        msurface_lightmapinfo_t *data_surfaces_lightmapinfo;
-       // surface meshes are merged to a smaller set of meshes to allow reduced
-       // vertex array switching, the meshes are limited to 65536 vertices each
-       // to play nice with Geforce1 hardware
-       int                             nummeshes;
-       surfmesh_t              **meshlist;
+       // all surfaces belong to this mesh
+       surfmesh_t              surfmesh;
        // draw the model's sky polygons (only used by brush models)
        void(*DrawSky)(struct entity_render_s *ent);
        // draw the model using lightmap/dlight shading
@@ -622,7 +618,7 @@ void Mod_ValidateElements(int *elements, int numtriangles, int firstvertex, int
 void Mod_BuildNormals(int firstvertex, int numvertices, int numtriangles, const float *vertex3f, const int *elements, float *normal3f, qboolean areaweighting);
 void Mod_BuildTextureVectorsAndNormals(int firstvertex, int numvertices, int numtriangles, const float *vertex, const float *texcoord, const int *elements, float *svectors, float *tvectors, float *normals, qboolean areaweighting);
 
-surfmesh_t *Mod_AllocSurfMesh(mempool_t *mempool, int numvertices, int numtriangles, qboolean lightmapoffsets, qboolean vertexcolors, qboolean neighbors);
+void Mod_AllocSurfMesh(mempool_t *mempool, int numvertices, int numtriangles, qboolean lightmapoffsets, qboolean vertexcolors, qboolean neighbors);
 
 shadowmesh_t *Mod_ShadowMesh_Alloc(mempool_t *mempool, int maxverts, int maxtriangles, rtexture_t *map_diffuse, rtexture_t *map_specular, rtexture_t *map_normal, int light, int neighbors, int expandable);
 shadowmesh_t *Mod_ShadowMesh_ReAlloc(mempool_t *mempool, shadowmesh_t *oldmesh, int light, int neighbors);
@@ -679,7 +675,7 @@ void R_Q1BSP_DrawLight(struct entity_render_s *ent, int numsurfaces, const int *
 // alias models
 struct frameblend_s;
 void Mod_AliasInit(void);
-void Mod_Alias_GetMesh_Vertex3f(const model_t *model, const struct frameblend_s *frameblend, const struct surfmesh_s *mesh, float *out3f);
+void Mod_Alias_GetMesh_Vertex3f(const model_t *model, const struct frameblend_s *frameblend, float *out3f);
 int Mod_Alias_GetTagMatrix(const model_t *model, int poseframe, int tagindex, matrix4x4_t *outmatrix);
 int Mod_Alias_GetTagIndexForName(const model_t *model, unsigned int skin, const char *tagname);
 
index eb192b7..759fa4d 100644 (file)
--- a/portals.c
+++ b/portals.c
@@ -325,8 +325,8 @@ static void Portal_RecursiveFlow (portalrecursioninfo_t *info, mleaf_t *leaf, in
                                                const int *elements;
                                                const float *vertex3f;
                                                float v[9], trimins[3], trimaxs[3];
-                                               vertex3f = surface->groupmesh->data_vertex3f;
-                                               elements = (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle);
+                                               vertex3f = info->model->surfmesh.data_vertex3f;
+                                               elements = (info->model->surfmesh.data_element3i + 3 * surface->num_firsttriangle);
                                                for (j = 0;j < surface->num_triangles;j++, elements += 3)
                                                {
                                                        VectorCopy(vertex3f + elements[0] * 3, v + 0);
index 9417854..4484a2e 100644 (file)
@@ -1242,6 +1242,7 @@ static void R_Shadow_RenderSurfacesLighting_VisibleLighting(const entity_render_
 {
        // used to display how many times a surface is lit for level design purposes
        int surfacelistindex;
+       model_t *model = ent->model;
        rmeshstate_t m;
        GL_Color(0.1, 0.025, 0, 1);
        memset(&m, 0, sizeof(m));
@@ -1251,7 +1252,7 @@ static void R_Shadow_RenderSurfacesLighting_VisibleLighting(const entity_render_
                const msurface_t *surface = surfacelist[surfacelistindex];
                RSurf_SetVertexPointer(ent, texture, surface, r_shadow_entityeyeorigin, false, false);
                GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
-               R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle);
+               R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, model->surfmesh.data_element3i + 3 * surface->num_firsttriangle);
                GL_LockArrays(0, 0);
        }
 }
@@ -1260,13 +1261,14 @@ static void R_Shadow_RenderSurfacesLighting_Light_GLSL(const entity_render_t *en
 {
        // ARB2 GLSL shader path (GFFX5200, Radeon 9500)
        int surfacelistindex;
+       model_t *model = ent->model;
        R_SetupSurfaceShader(ent, texture, r_shadow_entityeyeorigin, lightcolorbase, false);
        for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
        {
                const msurface_t *surface = surfacelist[surfacelistindex];
-               const int *elements = surface->groupmesh->data_element3i + surface->num_firsttriangle * 3;
+               const int *elements = model->surfmesh.data_element3i + surface->num_firsttriangle * 3;
                RSurf_SetVertexPointer(ent, texture, surface, r_shadow_entityeyeorigin, false, true);
-               R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoordtexture2f);
+               R_Mesh_TexCoordPointer(0, 2, model->surfmesh.data_texcoordtexture2f);
                R_Mesh_TexCoordPointer(1, 3, rsurface_svector3f);
                R_Mesh_TexCoordPointer(2, 3, rsurface_tvector3f);
                R_Mesh_TexCoordPointer(3, 3, rsurface_normal3f);
@@ -1279,9 +1281,10 @@ static void R_Shadow_RenderSurfacesLighting_Light_GLSL(const entity_render_t *en
 static void R_Shadow_RenderSurfacesLighting_Light_Dot3_AmbientPass(const entity_render_t *ent, const texture_t *texture, const msurface_t *surface, const vec3_t lightcolorbase, rtexture_t *basetexture, float colorscale)
 {
        int renders;
+       model_t *model = ent->model;
        float color2[3];
        rmeshstate_t m;
-       const int *elements = surface->groupmesh->data_element3i + surface->num_firsttriangle * 3;
+       const int *elements = model->surfmesh.data_element3i + surface->num_firsttriangle * 3;
        GL_Color(1,1,1,1);
        // colorscale accounts for how much we multiply the brightness
        // during combine.
@@ -1299,7 +1302,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_AmbientPass(const entity_
                m.pointer_texcoord3f[0] = rsurface_vertex3f;
                m.texmatrix[0] = r_shadow_entitytoattenuationxyz;
                m.tex[1] = R_GetTexture(basetexture);
-               m.pointer_texcoord[1] = surface->groupmesh->data_texcoordtexture2f;
+               m.pointer_texcoord[1] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[1] = texture->currenttexmatrix;
                m.texcubemap[2] = R_GetTexture(r_shadow_rtlight->currentcubemap);
                m.pointer_texcoord3f[2] = rsurface_vertex3f;
@@ -1315,7 +1318,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_AmbientPass(const entity_
                m.pointer_texcoord3f[0] = rsurface_vertex3f;
                m.texmatrix[0] = r_shadow_entitytoattenuationxyz;
                m.tex[1] = R_GetTexture(basetexture);
-               m.pointer_texcoord[1] = surface->groupmesh->data_texcoordtexture2f;
+               m.pointer_texcoord[1] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[1] = texture->currenttexmatrix;
                GL_BlendFunc(GL_ONE, GL_ONE);
        }
@@ -1331,7 +1334,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_AmbientPass(const entity_
                m.pointer_texcoord3f[1] = rsurface_vertex3f;
                m.texmatrix[1] = r_shadow_entitytoattenuationz;
                m.tex[2] = R_GetTexture(basetexture);
-               m.pointer_texcoord[2] = surface->groupmesh->data_texcoordtexture2f;
+               m.pointer_texcoord[2] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[2] = texture->currenttexmatrix;
                if (r_shadow_rtlight->currentcubemap != r_texture_whitecube)
                {
@@ -1353,7 +1356,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_AmbientPass(const entity_
                m.pointer_texcoord3f[1] = rsurface_vertex3f;
                m.texmatrix[1] = r_shadow_entitytoattenuationz;
                m.tex[2] = R_GetTexture(basetexture);
-               m.pointer_texcoord[2] = surface->groupmesh->data_texcoordtexture2f;
+               m.pointer_texcoord[2] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[2] = texture->currenttexmatrix;
                GL_BlendFunc(GL_ONE, GL_ONE);
        }
@@ -1378,7 +1381,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_AmbientPass(const entity_
                memset(&m, 0, sizeof(m));
                m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(basetexture);
-               m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f;
+               m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
                if (r_shadow_rtlight->currentcubemap != r_texture_whitecube)
                {
@@ -1404,9 +1407,10 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_AmbientPass(const entity_
 static void R_Shadow_RenderSurfacesLighting_Light_Dot3_DiffusePass(const entity_render_t *ent, const texture_t *texture, const msurface_t *surface, const vec3_t lightcolorbase, rtexture_t *basetexture, rtexture_t *normalmaptexture, float colorscale)
 {
        int renders;
+       model_t *model = ent->model;
        float color2[3];
        rmeshstate_t m;
-       const int *elements = surface->groupmesh->data_element3i + surface->num_firsttriangle * 3;
+       const int *elements = model->surfmesh.data_element3i + surface->num_firsttriangle * 3;
        GL_Color(1,1,1,1);
        // colorscale accounts for how much we multiply the brightness
        // during combine.
@@ -1422,7 +1426,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_DiffusePass(const entity_
                m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(normalmaptexture);
                m.texcombinergb[0] = GL_REPLACE;
-               m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f;
+               m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
                m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube);
                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
@@ -1441,7 +1445,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_DiffusePass(const entity_
                memset(&m, 0, sizeof(m));
                m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(basetexture);
-               m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f;
+               m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
                if (r_shadow_rtlight->currentcubemap != r_texture_whitecube)
                {
@@ -1470,7 +1474,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_DiffusePass(const entity_
                m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(normalmaptexture);
                m.texcombinergb[0] = GL_REPLACE;
-               m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f;
+               m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
                m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube);
                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
@@ -1485,7 +1489,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_DiffusePass(const entity_
                memset(&m, 0, sizeof(m));
                m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(basetexture);
-               m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f;
+               m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
                if (r_shadow_rtlight->currentcubemap != r_texture_whitecube)
                {
@@ -1502,7 +1506,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_DiffusePass(const entity_
                m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(normalmaptexture);
                m.texcombinergb[0] = GL_REPLACE;
-               m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f;
+               m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
                m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube);
                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
@@ -1518,7 +1522,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_DiffusePass(const entity_
                memset(&m, 0, sizeof(m));
                m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(basetexture);
-               m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f;
+               m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
                m.tex3d[1] = R_GetTexture(r_shadow_attenuation3dtexture);
                m.pointer_texcoord3f[1] = rsurface_vertex3f;
@@ -1532,7 +1536,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_DiffusePass(const entity_
                m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(normalmaptexture);
                m.texcombinergb[0] = GL_REPLACE;
-               m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f;
+               m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
                m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube);
                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
@@ -1554,7 +1558,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_DiffusePass(const entity_
                memset(&m, 0, sizeof(m));
                m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(basetexture);
-               m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f;
+               m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
                if (r_shadow_rtlight->currentcubemap != r_texture_whitecube)
                {
@@ -1586,7 +1590,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_DiffusePass(const entity_
                m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(normalmaptexture);
                m.texcombinergb[0] = GL_REPLACE;
-               m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f;
+               m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
                m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube);
                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
@@ -1601,7 +1605,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_DiffusePass(const entity_
                memset(&m, 0, sizeof(m));
                m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(basetexture);
-               m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f;
+               m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
                if (r_shadow_rtlight->currentcubemap != r_texture_whitecube)
                {
@@ -1627,9 +1631,10 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_DiffusePass(const entity_
 static void R_Shadow_RenderSurfacesLighting_Light_Dot3_SpecularPass(const entity_render_t *ent, const texture_t *texture, const msurface_t *surface, const vec3_t lightcolorbase, rtexture_t *glosstexture, rtexture_t *normalmaptexture, float colorscale)
 {
        int renders;
+       model_t *model = ent->model;
        float color2[3];
        rmeshstate_t m;
-       const int *elements = surface->groupmesh->data_element3i + surface->num_firsttriangle * 3;
+       const int *elements = model->surfmesh.data_element3i + surface->num_firsttriangle * 3;
        // FIXME: detect blendsquare!
        //if (!gl_support_blendsquare)
        //      return;
@@ -1640,7 +1645,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_SpecularPass(const entity
                memset(&m, 0, sizeof(m));
                m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(normalmaptexture);
-               m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f;
+               m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
                m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube);
                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
@@ -1682,7 +1687,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_SpecularPass(const entity
                memset(&m, 0, sizeof(m));
                m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(glosstexture);
-               m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f;
+               m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
                if (r_shadow_rtlight->currentcubemap != r_texture_whitecube)
                {
@@ -1698,7 +1703,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_SpecularPass(const entity
                memset(&m, 0, sizeof(m));
                m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(normalmaptexture);
-               m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f;
+               m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
                m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube);
                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
@@ -1729,7 +1734,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_SpecularPass(const entity
                memset(&m, 0, sizeof(m));
                m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(glosstexture);
-               m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f;
+               m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
                m.tex3d[1] = R_GetTexture(r_shadow_attenuation3dtexture);
                m.pointer_texcoord3f[1] = rsurface_vertex3f;
@@ -1742,7 +1747,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_SpecularPass(const entity
                memset(&m, 0, sizeof(m));
                m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(normalmaptexture);
-               m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f;
+               m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
                m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube);
                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
@@ -1787,7 +1792,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_SpecularPass(const entity
                memset(&m, 0, sizeof(m));
                m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(glosstexture);
-               m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f;
+               m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
                if (r_shadow_rtlight->currentcubemap != r_texture_whitecube)
                {
@@ -1845,10 +1850,10 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3(const entity_render_t *en
        }
 }
 
-void R_Shadow_RenderSurfacesLighting_Light_Vertex_Pass(const msurface_t *surface, vec3_t diffusecolor2, vec3_t ambientcolor2)
+void R_Shadow_RenderSurfacesLighting_Light_Vertex_Pass(const model_t *model, const msurface_t *surface, vec3_t diffusecolor2, vec3_t ambientcolor2)
 {
        int renders;
-       const int *elements = surface->groupmesh->data_element3i + surface->num_firsttriangle * 3;
+       const int *elements = model->surfmesh.data_element3i + surface->num_firsttriangle * 3;
        R_Shadow_RenderSurfacesLighting_Light_Vertex_Shading(surface, diffusecolor2, ambientcolor2);
        for (renders = 0;renders < 64 && (ambientcolor2[0] > renders || ambientcolor2[1] > renders || ambientcolor2[2] > renders || diffusecolor2[0] > renders || diffusecolor2[1] > renders || diffusecolor2[2] > renders);renders++)
        {
@@ -1918,6 +1923,7 @@ goodpass:
 static void R_Shadow_RenderSurfacesLighting_Light_Vertex(const entity_render_t *ent, const texture_t *texture, int numsurfaces, msurface_t **surfacelist, const vec3_t lightcolorbase, const vec3_t lightcolorpants, const vec3_t lightcolorshirt, rtexture_t *basetexture, rtexture_t *pantstexture, rtexture_t *shirttexture, rtexture_t *normalmaptexture, rtexture_t *glosstexture, float specularscale, qboolean dopants, qboolean doshirt)
 {
        int surfacelistindex;
+       model_t *model = ent->model;
        float ambientcolorbase[3], diffusecolorbase[3];
        float ambientcolorpants[3], diffusecolorpants[3];
        float ambientcolorshirt[3], diffusecolorshirt[3];
@@ -1950,7 +1956,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Vertex(const entity_render_t *
                const msurface_t *surface = surfacelist[surfacelistindex];
                RSurf_SetVertexPointer(ent, texture, surface, r_shadow_entityeyeorigin, true, false);
                // OpenGL 1.1 path (anything)
-               R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoordtexture2f);
+               R_Mesh_TexCoordPointer(0, 2, model->surfmesh.data_texcoordtexture2f);
                R_Mesh_TexMatrix(0, &texture->currenttexmatrix);
                if (r_textureunits.integer >= 2)
                {
@@ -1963,16 +1969,16 @@ static void R_Shadow_RenderSurfacesLighting_Light_Vertex(const entity_render_t *
                        }
                }
                R_Mesh_TexBind(0, R_GetTexture(basetexture));
-               R_Shadow_RenderSurfacesLighting_Light_Vertex_Pass(surface, diffusecolorbase, ambientcolorbase);
+               R_Shadow_RenderSurfacesLighting_Light_Vertex_Pass(model, surface, diffusecolorbase, ambientcolorbase);
                if (dopants)
                {
                        R_Mesh_TexBind(0, R_GetTexture(pantstexture));
-                       R_Shadow_RenderSurfacesLighting_Light_Vertex_Pass(surface, diffusecolorpants, ambientcolorpants);
+                       R_Shadow_RenderSurfacesLighting_Light_Vertex_Pass(model, surface, diffusecolorpants, ambientcolorpants);
                }
                if (doshirt)
                {
                        R_Mesh_TexBind(0, R_GetTexture(shirttexture));
-                       R_Shadow_RenderSurfacesLighting_Light_Vertex_Pass(surface, diffusecolorshirt, ambientcolorshirt);
+                       R_Shadow_RenderSurfacesLighting_Light_Vertex_Pass(model, surface, diffusecolorshirt, ambientcolorshirt);
                }
        }
 }
@@ -2195,6 +2201,7 @@ void R_Shadow_UncompileWorldLights(void)
 
 void R_Shadow_DrawEntityShadow(entity_render_t *ent, int numsurfaces, int *surfacelist)
 {
+       model_t *model = ent->model;
        vec3_t relativeshadoworigin, relativeshadowmins, relativeshadowmaxs;
        vec_t relativeshadowradius;
        if (ent == r_refdef.worldentity)
@@ -2225,7 +2232,7 @@ void R_Shadow_DrawEntityShadow(entity_render_t *ent, int numsurfaces, int *surfa
                else if (numsurfaces)
                {
                        R_Mesh_Matrix(&ent->matrix);
-                       ent->model->DrawShadowVolume(ent, r_shadow_rtlight->shadoworigin, r_shadow_rtlight->radius, numsurfaces, surfacelist, r_shadow_rtlight->cullmins, r_shadow_rtlight->cullmaxs);
+                       model->DrawShadowVolume(ent, r_shadow_rtlight->shadoworigin, r_shadow_rtlight->radius, numsurfaces, surfacelist, r_shadow_rtlight->cullmins, r_shadow_rtlight->cullmaxs);
                }
        }
        else
@@ -2239,7 +2246,7 @@ void R_Shadow_DrawEntityShadow(entity_render_t *ent, int numsurfaces, int *surfa
                relativeshadowmaxs[1] = relativeshadoworigin[1] + relativeshadowradius;
                relativeshadowmaxs[2] = relativeshadoworigin[2] + relativeshadowradius;
                R_Mesh_Matrix(&ent->matrix);
-               ent->model->DrawShadowVolume(ent, relativeshadoworigin, relativeshadowradius, ent->model->nummodelsurfaces, ent->model->surfacelist, relativeshadowmins, relativeshadowmaxs);
+               model->DrawShadowVolume(ent, relativeshadoworigin, relativeshadowradius, model->nummodelsurfaces, model->surfacelist, relativeshadowmins, relativeshadowmaxs);
        }
 }
 
@@ -2256,13 +2263,14 @@ void R_Shadow_SetupEntityLight(const entity_render_t *ent)
 
 void R_Shadow_DrawEntityLight(entity_render_t *ent, int numsurfaces, int *surfacelist)
 {
-       if (!ent->model->DrawLight)
+       model_t *model = ent->model;
+       if (!model->DrawLight)
                return;
        R_Shadow_SetupEntityLight(ent);
        if (ent == r_refdef.worldentity)
-               ent->model->DrawLight(ent, numsurfaces, surfacelist);
+               model->DrawLight(ent, numsurfaces, surfacelist);
        else
-               ent->model->DrawLight(ent, ent->model->nummodelsurfaces, ent->model->surfacelist);
+               model->DrawLight(ent, model->nummodelsurfaces, model->surfacelist);
 }
 
 void R_DrawRTLight(rtlight_t *rtlight, qboolean visible)
@@ -2369,16 +2377,17 @@ void R_DrawRTLight(rtlight_t *rtlight, qboolean visible)
        {
                for (i = 0;i < r_refdef.numentities;i++)
                {
+                       model_t *model;
                        entity_render_t *ent = r_refdef.entities[i];
                        if (BoxesOverlap(ent->mins, ent->maxs, rtlight->cullmins, rtlight->cullmaxs)
-                        && ent->model
+                        && (model = ent->model)
                         && !(ent->flags & RENDER_TRANSPARENT)
                         && (r_refdef.worldmodel == NULL || r_refdef.worldmodel->brush.BoxTouchingLeafPVS == NULL || r_refdef.worldmodel->brush.BoxTouchingLeafPVS(r_refdef.worldmodel, leafpvs, ent->mins, ent->maxs)))
                        {
                                // about the VectorDistance2 - light emitting entities should not cast their own shadow
-                               if ((ent->flags & RENDER_SHADOW) && ent->model->DrawShadowVolume && VectorDistance2(ent->origin, rtlight->shadoworigin) > 0.1)
+                               if ((ent->flags & RENDER_SHADOW) && model->DrawShadowVolume && VectorDistance2(ent->origin, rtlight->shadoworigin) > 0.1)
                                        shadowentities[numshadowentities++] = ent;
-                               if (ent->visframe == r_framecount && (ent->flags & RENDER_LIGHT) && ent->model->DrawLight)
+                               if (ent->visframe == r_framecount && (ent->flags & RENDER_LIGHT) && model->DrawLight)
                                        lightentities[numlightentities++] = ent;
                        }
                }
index af4bbfd..0c1b922 100644 (file)
@@ -5,6 +5,7 @@
 void R_Model_Sprite_Draw_TransparentCallback(const entity_render_t *ent, int surfacenumber, const rtlight_t *rtlight)
 {
        int i;
+       model_t *model = ent->model;
        vec3_t left, up, org, color, diffusecolor, diffusenormal;
        mspriteframe_t *frame;
        float scale;
@@ -13,7 +14,7 @@ void R_Model_Sprite_Draw_TransparentCallback(const entity_render_t *ent, int sur
        org[0] = ent->matrix.m[0][3] - r_viewforward[0];
        org[1] = ent->matrix.m[1][3] - r_viewforward[1];
        org[2] = ent->matrix.m[2][3] - r_viewforward[2];
-       switch(ent->model->sprite.sprnum_type)
+       switch(model->sprite.sprnum_type)
        {
        case SPR_VP_PARALLEL_UPRIGHT:
                // flames and such
@@ -38,7 +39,7 @@ void R_Model_Sprite_Draw_TransparentCallback(const entity_render_t *ent, int sur
                up[2] = ent->scale;
                break;
        default:
-               Con_Printf("R_SpriteSetup: unknown sprite type %i\n", ent->model->sprite.sprnum_type);
+               Con_Printf("R_SpriteSetup: unknown sprite type %i\n", model->sprite.sprnum_type);
                // fall through to normal sprite
        case SPR_VP_PARALLEL:
                // normal sprite
@@ -91,7 +92,7 @@ void R_Model_Sprite_Draw_TransparentCallback(const entity_render_t *ent, int sur
        {
                if (ent->frameblend[i].lerp >= 0.01f)
                {
-                       frame = ent->model->sprite.sprdata_frames + ent->frameblend[i].frame;
+                       frame = model->sprite.sprdata_frames + ent->frameblend[i].frame;
                        // FIXME: negate left and right in loader
                        R_DrawSprite(GL_SRC_ALPHA, (ent->effects & EF_ADDITIVE) ? GL_ONE : GL_ONE_MINUS_SRC_ALPHA, frame->skin.base, frame->skin.fog, (ent->effects & EF_NODEPTHTEST), org, left, up, frame->left, frame->right, frame->down, frame->up, color[0], color[1], color[2], ent->alpha * ent->frameblend[i].lerp);
                }
index c5db79b..de42971 100644 (file)
@@ -2029,20 +2029,20 @@ void PF_te_flamejet (void)
        MSG_WriteByte(&sv.datagram, PRVM_G_FLOAT(OFS_PARM2));
 }
 
-void clippointtosurface(msurface_t *surface, vec3_t p, vec3_t out)
+void clippointtosurface(model_t *model, msurface_t *surface, vec3_t p, vec3_t out)
 {
        int i, j, k;
        float *v[3], facenormal[3], edgenormal[3], sidenormal[3], temp[3], offsetdist, dist, bestdist;
        const int *e;
        bestdist = 1000000000;
        VectorCopy(p, out);
-       for (i = 0, e = (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle);i < surface->num_triangles;i++, e += 3)
+       for (i = 0, e = (model->surfmesh.data_element3i + 3 * surface->num_firsttriangle);i < surface->num_triangles;i++, e += 3)
        {
                // clip original point to each triangle of the surface and find the
                // triangle that is closest
-               v[0] = surface->groupmesh->data_vertex3f + e[0] * 3;
-               v[1] = surface->groupmesh->data_vertex3f + e[1] * 3;
-               v[2] = surface->groupmesh->data_vertex3f + e[2] * 3;
+               v[0] = model->surfmesh.data_vertex3f + e[0] * 3;
+               v[1] = model->surfmesh.data_vertex3f + e[1] * 3;
+               v[2] = model->surfmesh.data_vertex3f + e[2] * 3;
                TriangleNormal(v[0], v[1], v[2], facenormal);
                VectorNormalize(facenormal);
                offsetdist = DotProduct(v[0], facenormal) - DotProduct(p, facenormal);
@@ -2065,16 +2065,19 @@ void clippointtosurface(msurface_t *surface, vec3_t p, vec3_t out)
        }
 }
 
-static msurface_t *getsurface(prvm_edict_t *ed, int surfacenum)
+static model_t *getmodel(prvm_edict_t *ed)
 {
        int modelindex;
-       model_t *model;
        if (!ed || ed->priv.server->free)
                return NULL;
        modelindex = ed->fields.server->modelindex;
        if (modelindex < 1 || modelindex >= MAX_MODELS)
                return NULL;
-       model = sv.models[modelindex];
+       return sv.models[modelindex];
+}
+
+static msurface_t *getsurface(model_t *model, int surfacenum)
+{
        if (surfacenum < 0 || surfacenum >= model->nummodelsurfaces)
                return NULL;
        return model->data_surfaces + surfacenum + model->firstmodelsurface;
@@ -2084,9 +2087,10 @@ static msurface_t *getsurface(prvm_edict_t *ed, int surfacenum)
 //PF_getsurfacenumpoints, // #434 float(entity e, float s) getsurfacenumpoints = #434;
 void PF_getsurfacenumpoints(void)
 {
+       model_t *model;
        msurface_t *surface;
        // return 0 if no such surface
-       if (!(surface = getsurface(PRVM_G_EDICT(OFS_PARM0), PRVM_G_FLOAT(OFS_PARM1))))
+       if (!(model = getmodel(PRVM_G_EDICT(OFS_PARM0))) || !(surface = getsurface(model, PRVM_G_FLOAT(OFS_PARM1))))
        {
                PRVM_G_FLOAT(OFS_RETURN) = 0;
                return;
@@ -2099,50 +2103,51 @@ void PF_getsurfacenumpoints(void)
 void PF_getsurfacepoint(void)
 {
        prvm_edict_t *ed;
+       model_t *model;
        msurface_t *surface;
        int pointnum;
        VectorClear(PRVM_G_VECTOR(OFS_RETURN));
        ed = PRVM_G_EDICT(OFS_PARM0);
-       if (!ed || ed->priv.server->free)
-               return;
-       if (!(surface = getsurface(ed, PRVM_G_FLOAT(OFS_PARM1))))
+       if (!(model = getmodel(ed)) || !(surface = getsurface(model, PRVM_G_FLOAT(OFS_PARM1))))
                return;
        // note: this (incorrectly) assumes it is a simple polygon
        pointnum = PRVM_G_FLOAT(OFS_PARM2);
        if (pointnum < 0 || pointnum >= surface->num_vertices)
                return;
        // FIXME: implement rotation/scaling
-       VectorAdd(&(surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex)[pointnum * 3], ed->fields.server->origin, PRVM_G_VECTOR(OFS_RETURN));
+       VectorAdd(&(model->surfmesh.data_vertex3f + 3 * surface->num_firstvertex)[pointnum * 3], ed->fields.server->origin, PRVM_G_VECTOR(OFS_RETURN));
 }
 //PF_getsurfacenormal,    // #436 vector(entity e, float s) getsurfacenormal = #436;
 void PF_getsurfacenormal(void)
 {
+       model_t *model;
        msurface_t *surface;
        vec3_t normal;
        VectorClear(PRVM_G_VECTOR(OFS_RETURN));
-       if (!(surface = getsurface(PRVM_G_EDICT(OFS_PARM0), PRVM_G_FLOAT(OFS_PARM1))))
+       if (!(model = getmodel(PRVM_G_EDICT(OFS_PARM0))) || !(surface = getsurface(model, PRVM_G_FLOAT(OFS_PARM1))))
                return;
        // FIXME: implement rotation/scaling
        // note: this (incorrectly) assumes it is a simple polygon
        // note: this only returns the first triangle, so it doesn't work very
        // well for curved surfaces or arbitrary meshes
-       TriangleNormal((surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex), (surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex) + 3, (surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex) + 6, normal);
+       TriangleNormal((model->surfmesh.data_vertex3f + 3 * surface->num_firstvertex), (model->surfmesh.data_vertex3f + 3 * surface->num_firstvertex) + 3, (model->surfmesh.data_vertex3f + 3 * surface->num_firstvertex) + 6, normal);
        VectorNormalize(normal);
        VectorCopy(normal, PRVM_G_VECTOR(OFS_RETURN));
 }
 //PF_getsurfacetexture,   // #437 string(entity e, float s) getsurfacetexture = #437;
 void PF_getsurfacetexture(void)
 {
+       model_t *model;
        msurface_t *surface;
        PRVM_G_INT(OFS_RETURN) = 0;
-       if (!(surface = getsurface(PRVM_G_EDICT(OFS_PARM0), PRVM_G_FLOAT(OFS_PARM1))))
+       if (!(model = getmodel(PRVM_G_EDICT(OFS_PARM0))) || !(surface = getsurface(model, PRVM_G_FLOAT(OFS_PARM1))))
                return;
        PRVM_G_INT(OFS_RETURN) = PRVM_SetEngineString(surface->texture->name);
 }
 //PF_getsurfacenearpoint, // #438 float(entity e, vector p) getsurfacenearpoint = #438;
 void PF_getsurfacenearpoint(void)
 {
-       int surfacenum, best, modelindex;
+       int surfacenum, best;
        vec3_t clipped, p;
        vec_t dist, bestdist;
        prvm_edict_t *ed;
@@ -2155,11 +2160,8 @@ void PF_getsurfacenearpoint(void)
 
        if (!ed || ed->priv.server->free)
                return;
-       modelindex = ed->fields.server->modelindex;
-       if (modelindex < 1 || modelindex >= MAX_MODELS)
-               return;
-       model = sv.models[modelindex];
-       if (!model->num_surfaces)
+       model = getmodel(ed);
+       if (!model || !model->num_surfaces)
                return;
 
        // FIXME: implement rotation/scaling
@@ -2177,7 +2179,7 @@ void PF_getsurfacenearpoint(void)
                if (dist < bestdist)
                {
                        // it is, check the nearest point on the actual geometry
-                       clippointtosurface(surface, p, clipped);
+                       clippointtosurface(model, surface, p, clipped);
                        VectorSubtract(clipped, p, clipped);
                        dist += VectorLength2(clipped);
                        if (dist < bestdist)
@@ -2194,17 +2196,16 @@ void PF_getsurfacenearpoint(void)
 void PF_getsurfaceclippedpoint(void)
 {
        prvm_edict_t *ed;
+       model_t *model;
        msurface_t *surface;
        vec3_t p, out;
        VectorClear(PRVM_G_VECTOR(OFS_RETURN));
        ed = PRVM_G_EDICT(OFS_PARM0);
-       if (!ed || ed->priv.server->free)
-               return;
-       if (!(surface = getsurface(ed, PRVM_G_FLOAT(OFS_PARM1))))
+       if (!(model = getmodel(ed)) || !(surface = getsurface(model, PRVM_G_FLOAT(OFS_PARM1))))
                return;
        // FIXME: implement rotation/scaling
        VectorSubtract(PRVM_G_VECTOR(OFS_PARM2), ed->fields.server->origin, p);
-       clippointtosurface(surface, p, out);
+       clippointtosurface(model, surface, p, out);
        // FIXME: implement rotation/scaling
        VectorAdd(out, ed->fields.server->origin, PRVM_G_VECTOR(OFS_RETURN));
 }