]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
enlarge q3bsp bounding box to include all geometry, this is necessary
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 19 Mar 2008 02:16:57 +0000 (02:16 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 19 Mar 2008 02:16:57 +0000 (02:16 +0000)
because q3map2 sometimes lies (to alter the lightgrid box)

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

model_brush.c

index ab1146c02195d955a6139c09d86cafdbb6a9f9e0..7b3efb2bc63a5982a8b0c1b625bf4a7c62a800a1 100644 (file)
@@ -5699,6 +5699,7 @@ void Mod_Q3BSP_Load(model_t *mod, void *buffer, void *bufferend)
        mod = loadmodel;
        for (i = 0;i < loadmodel->brush.numsubmodels;i++)
        {
+               qboolean boxready;
                if (i > 0)
                {
                        char name[10];
@@ -5738,6 +5739,33 @@ void Mod_Q3BSP_Load(model_t *mod, void *buffer, void *bufferend)
 
                VectorCopy(mod->brushq3.data_models[i].mins, mod->normalmins);
                VectorCopy(mod->brushq3.data_models[i].maxs, mod->normalmaxs);
+               // enlarge the bounding box to enclose all geometry of this model,
+               // because q3map2 sometimes lies (mostly to affect the lightgrid),
+               // which can in turn mess up the farclip (as well as culling when
+               // outside the level - an unimportant concern)
+               boxready = false;
+               for (j = 0;j < mod->nummodelsurfaces;j++)
+               {
+                       const msurface_t *surface = mod->data_surfaces + j + mod->firstmodelsurface;
+                       const float *v = mod->surfmesh.data_vertex3f + 3 * surface->num_firstvertex;
+                       int k;
+                       if (!surface->num_vertices)
+                               continue;
+                       if (!boxready)
+                       {
+                               VectorCopy(v, mod->normalmins);
+                               VectorCopy(v, mod->normalmaxs);
+                       }
+                       for (k = 0;k < surface->num_vertices;k++, v += 3)
+                       {
+                               mod->normalmins[0] = min(mod->normalmins[0], v[0]);
+                               mod->normalmins[1] = min(mod->normalmins[1], v[1]);
+                               mod->normalmins[2] = min(mod->normalmins[2], v[2]);
+                               mod->normalmaxs[0] = min(mod->normalmaxs[0], v[0]);
+                               mod->normalmaxs[1] = min(mod->normalmaxs[1], v[1]);
+                               mod->normalmaxs[2] = min(mod->normalmaxs[2], v[2]);
+                       }
+               }
                corner[0] = max(fabs(mod->normalmins[0]), fabs(mod->normalmaxs[0]));
                corner[1] = max(fabs(mod->normalmins[1]), fabs(mod->normalmaxs[1]));
                corner[2] = max(fabs(mod->normalmins[2]), fabs(mod->normalmaxs[2]));