From 63bd4cc6bae869cbcd1ef49d27687184c9168fb0 Mon Sep 17 00:00:00 2001 From: havoc Date: Thu, 25 Feb 2010 16:16:46 +0000 Subject: [PATCH] added dpmeshcollisions keyword in shader parsing, this causes all rendering triangles of the affected surfaces to be added to the BIH system, so that q3map2's misc_model collision flag can be turned off, greatly reducing bsp size and memory usage, as well as possibly improving collisions (no need to reconstruct points from planes) git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10006 d7cf8633-e32d-0410-b094-e92efae38249 --- model_brush.c | 46 ++++++++++++++++++++++++++-------------------- model_brush.h | 2 ++ model_shared.c | 5 +++++ model_shared.h | 3 +++ 4 files changed, 36 insertions(+), 20 deletions(-) diff --git a/model_brush.c b/model_brush.c index e1603ac0..e6203723 100644 --- a/model_brush.c +++ b/model_brush.c @@ -6637,7 +6637,12 @@ void Mod_MakeCollisionBIH(dp_model_t *model, qboolean userendersurfaces) if (brush->colbrushf) bihnumleafs++; for (j = 0, surface = model->data_surfaces + model->firstmodelsurface;j < nummodelsurfaces;j++, surface++) - bihnumleafs += surface->num_collisiontriangles; + { + if (surface->texture->basematerialflags & MATERIALFLAG_MESHCOLLISIONS) + bihnumleafs += surface->num_triangles; + else + bihnumleafs += surface->num_collisiontriangles; + } } if (!bihnumleafs) @@ -6648,29 +6653,30 @@ void Mod_MakeCollisionBIH(dp_model_t *model, qboolean userendersurfaces) // now populate the BIH leaf nodes bihleafindex = 0; - if (userendersurfaces) + + // add render surfaces + renderelement3i = model->surfmesh.data_element3i; + rendervertex3f = model->surfmesh.data_vertex3f; + for (j = 0, surface = model->data_surfaces + model->firstmodelsurface;j < nummodelsurfaces;j++, surface++) { - // add render surfaces - renderelement3i = model->surfmesh.data_element3i; - rendervertex3f = model->surfmesh.data_vertex3f; - for (j = 0, surface = model->data_surfaces + model->firstmodelsurface;j < nummodelsurfaces;j++, surface++) + for (triangleindex = 0, e = renderelement3i + 3*surface->num_firsttriangle;triangleindex < surface->num_triangles;triangleindex++, e += 3) { - for (triangleindex = 0, e = renderelement3i + 3*surface->num_firsttriangle;triangleindex < surface->num_triangles;triangleindex++, e += 3) - { - bihleafs[bihleafindex].type = BIH_RENDERTRIANGLE; - bihleafs[bihleafindex].textureindex = surface->texture - model->data_textures; - bihleafs[bihleafindex].itemindex = triangleindex+surface->num_firsttriangle; - bihleafs[bihleafindex].mins[0] = min(rendervertex3f[3*e[0]+0], min(rendervertex3f[3*e[1]+0], rendervertex3f[3*e[2]+0])) - 1; - bihleafs[bihleafindex].mins[1] = min(rendervertex3f[3*e[0]+1], min(rendervertex3f[3*e[1]+1], rendervertex3f[3*e[2]+1])) - 1; - bihleafs[bihleafindex].mins[2] = min(rendervertex3f[3*e[0]+2], min(rendervertex3f[3*e[1]+2], rendervertex3f[3*e[2]+2])) - 1; - bihleafs[bihleafindex].maxs[0] = max(rendervertex3f[3*e[0]+0], max(rendervertex3f[3*e[1]+0], rendervertex3f[3*e[2]+0])) + 1; - bihleafs[bihleafindex].maxs[1] = max(rendervertex3f[3*e[0]+1], max(rendervertex3f[3*e[1]+1], rendervertex3f[3*e[2]+1])) + 1; - bihleafs[bihleafindex].maxs[2] = max(rendervertex3f[3*e[0]+2], max(rendervertex3f[3*e[1]+2], rendervertex3f[3*e[2]+2])) + 1; - bihleafindex++; - } + if (!userendersurfaces && !(surface->texture->basematerialflags & MATERIALFLAG_MESHCOLLISIONS)) + continue; + bihleafs[bihleafindex].type = BIH_RENDERTRIANGLE; + bihleafs[bihleafindex].textureindex = surface->texture - model->data_textures; + bihleafs[bihleafindex].itemindex = triangleindex+surface->num_firsttriangle; + bihleafs[bihleafindex].mins[0] = min(rendervertex3f[3*e[0]+0], min(rendervertex3f[3*e[1]+0], rendervertex3f[3*e[2]+0])) - 1; + bihleafs[bihleafindex].mins[1] = min(rendervertex3f[3*e[0]+1], min(rendervertex3f[3*e[1]+1], rendervertex3f[3*e[2]+1])) - 1; + bihleafs[bihleafindex].mins[2] = min(rendervertex3f[3*e[0]+2], min(rendervertex3f[3*e[1]+2], rendervertex3f[3*e[2]+2])) - 1; + bihleafs[bihleafindex].maxs[0] = max(rendervertex3f[3*e[0]+0], max(rendervertex3f[3*e[1]+0], rendervertex3f[3*e[2]+0])) + 1; + bihleafs[bihleafindex].maxs[1] = max(rendervertex3f[3*e[0]+1], max(rendervertex3f[3*e[1]+1], rendervertex3f[3*e[2]+1])) + 1; + bihleafs[bihleafindex].maxs[2] = max(rendervertex3f[3*e[0]+2], max(rendervertex3f[3*e[1]+2], rendervertex3f[3*e[2]+2])) + 1; + bihleafindex++; } } - else + + if (!userendersurfaces) { // add collision brushes for (brushindex = 0, brush = model->brush.data_brushes + brushindex+model->firstmodelbrush;brushindex < nummodelbrushes;brushindex++, brush++) diff --git a/model_brush.h b/model_brush.h index 0463d74d..34519383 100644 --- a/model_brush.h +++ b/model_brush.h @@ -62,6 +62,8 @@ mplane_t; //#define SURF_PLANEBACK 2 +// indicates that all triangles of the surface should be added to the BIH collision system +#define MATERIALFLAG_MESHCOLLISIONS 1 // use alpha blend on this material #define MATERIALFLAG_ALPHA 2 // use additive blend on this material diff --git a/model_shared.c b/model_shared.c index 4bf93638..3d2b877c 100644 --- a/model_shared.c +++ b/model_shared.c @@ -1946,6 +1946,8 @@ void Mod_LoadQ3Shaders(void) shader.dpnoshadow = true; else if (!strcasecmp(parameter[0], "dpreflectcube")) strlcpy(shader.dpreflectcube, parameter[1], sizeof(shader.dpreflectcube)); + else if (!strcasecmp(parameter[0], "dpmeshcollisions")) + shader.dpmeshcollisions = true; else if (!strcasecmp(parameter[0], "sky") && numparameters >= 2) { // some q3 skies don't have the sky parm set @@ -2312,6 +2314,9 @@ nothing GL_ZERO GL_ONE if (shader->surfaceparms & Q3SURFACEPARM_BOTCLIP ) texture->supercontents |= SUPERCONTENTS_BOTCLIP | SUPERCONTENTS_MONSTERCLIP; // if (shader->surfaceparms & Q3SURFACEPARM_LIGHTGRID ) texture->supercontents |= SUPERCONTENTS_LIGHTGRID ; // if (shader->surfaceparms & Q3SURFACEPARM_ANTIPORTAL ) texture->supercontents |= SUPERCONTENTS_ANTIPORTAL ; + + if (shader->dpmeshcollisions) + texture->basematerialflags |= MATERIALFLAG_MESHCOLLISIONS; } else if (!strcmp(texture->name, "noshader") || !texture->name[0]) { diff --git a/model_shared.h b/model_shared.h index 61e833c4..40dc7e31 100644 --- a/model_shared.h +++ b/model_shared.h @@ -401,6 +401,9 @@ typedef struct q3shaderinfo_s qboolean dpshadow; qboolean dpnoshadow; + // add collisions to all triangles of the surface + qboolean dpmeshcollisions; + // fake reflection char dpreflectcube[Q3PATHLENGTH]; -- 2.39.2