]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
added dpmeshcollisions keyword in shader parsing, this causes all
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 25 Feb 2010 16:16:46 +0000 (16:16 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 25 Feb 2010 16:16:46 +0000 (16:16 +0000)
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
model_brush.h
model_shared.c
model_shared.h

index e1603ac0110a96ddbbfcf464c62108c7300e79e6..e62037231e962cd64e690c435958dbf261e30480 100644 (file)
@@ -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++)
index 0463d74d1eedc3a8fe65f79ff5143f250b77dda5..34519383dc72af8b09cc3cef85f580bf3ff4386f 100644 (file)
@@ -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
index 4bf93638781099e800855d8c5ffcc7e66420e59b..3d2b877c5b405c2635d5065afca1e9c624713dd2 100644 (file)
@@ -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])
        {
index 61e833c496c1d7a0c8e24e90a05e34d2f6925e23..40dc7e31c85e2aa00690bc44f4d97f6ac9445bb4 100644 (file)
@@ -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];