/* ============== GrowNodeRegion_r ============== */ void GrowNodeRegion_r (node_t *node) { dface_t *r; face_t *f; int i; if (node->planenum == PLANENUM_LEAF) return; node->firstface = numfaces; for (f=node->faces ; f ; f=f->next) { // if (f->outputnumber != -1) // continue; // allready grown into an earlier region // emit a region if (numfaces == MAX_MAP_FACES) Error ("MAX_MAP_FACES"); f->outputnumber = numfaces; r = &dfaces[numfaces]; r->planenum = node->outputplanenum; r->side = f->planeside; r->texinfo = f->texturenum; for (i=0 ; i<MAXLIGHTMAPS ; i++) r->styles[i] = 255; r->lightofs = -1; // add the face and mergable neighbors to it #if 0 ClearRegionSize (); AddFaceToRegionSize (f); RecursiveGrowRegion (r, f); #endif r->firstedge = firstedge = numsurfedges; for (i=0 ; i<f->numpoints ; i++) { if (numsurfedges == MAX_MAP_SURFEDGES) Error ("numsurfedges == MAX_MAP_SURFEDGES"); dsurfedges[numsurfedges] = f->edges[i]; numsurfedges++; } r->numedges = numsurfedges - r->firstedge; numfaces++; } node->numfaces = numfaces - node->firstface; GrowNodeRegion_r (node->children[0]); GrowNodeRegion_r (node->children[1]); }
static void GrowNodeRegion_r (node_t * node) { dface_t r; face_t *f; int i; if (node->planenum == PLANENUM_LEAF) return; node->firstface = bsp->numfaces; for (f = node->faces; f; f = f->next) { if (f->texturenum < 0) continue; // if (f->outputnumber != -1) // continue; // allready grown into an earlier region // emit a region if (bsp->numfaces == MAX_MAP_FACES) Sys_Error ("MAX_MAP_FACES"); f->outputnumber = bsp->numfaces; r.planenum = node->outputplanenum; r.side = f->planeside; r.texinfo = f->texturenum; for (i = 0; i < MAXLIGHTMAPS; i++) r.styles[i] = 255; r.lightofs = -1; // add the face and mergable neighbors to it #if 0 ClearRegionSize (); AddFaceToRegionSize (f); RecursiveGrowRegion (r, f); #endif r.firstedge = firstedge = bsp->numsurfedges; for (i = 0; i < f->points->numpoints; i++) { BSP_AddSurfEdge (bsp, f->edges[i]); } r.numedges = bsp->numsurfedges - r.firstedge; BSP_AddFace (bsp, &r); } node->numfaces = bsp->numfaces - node->firstface; GrowNodeRegion_r (node->children[0]); GrowNodeRegion_r (node->children[1]); }
/* ============== CanJoinFaces ============== */ qboolean CanJoinFaces (face_t *f, face_t *f2) { vec3_t oldmins, oldmaxs; int i; if (f2->planenum != f->planenum || f2->planeside != f->planeside || f2->texturenum != f->texturenum) return false; if (f2->outputnumber != -1) return false; if (f2->contents[0] != f->contents[0]) { // does this ever happen? theyy shouldn't share. printf ("CanJoinFaces: edge with different contents"); return false; } // check size constraints if ( ! (texinfo[f->texturenum].flags & TEX_SPECIAL) ) { VectorCopy (region_mins, oldmins); VectorCopy (region_maxs, oldmaxs); AddFaceToRegionSize (f2); for (i=0 ; i<3 ; i++) { if (region_maxs[i] - region_mins[i] > 240) { VectorCopy (oldmins, region_mins); VectorCopy (oldmaxs, region_maxs); return false; } } } else { if (numsurfedges - firstedge + f2->numpoints > MAX_EDGES_IN_REGION) return false; // a huge water or sky polygon } // check edge count constraints return true; }