Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

patch.c File Reference

#include "qbsp.h"

Include dependency graph for patch.c:

Include dependency graph

Go to the source code of this file.

Functions

mapDrawSurface_tDrawSurfaceForMesh (mesh_t *m)
void GrowGroup_r (int patchNum, int patchCount, const byte *bordering, byte *group)
void ParsePatch (void)
void PatchMapDrawSurfs (entity_t *e)
void PrintCtrl (vec3_t ctrl[9])


Function Documentation

mapDrawSurface_t* DrawSurfaceForMesh mesh_t m  ) 
 

Definition at line 41 of file patch.c.

References AllocDrawSurf(), CopyMesh(), drawsurf_s::fogNum, FreeMesh(), mesh_t::height, i, j, drawsurf_s::lightmapNum, m, MakeMeshNormals(), malloc(), drawsurf_s::mapBrush, mapDrawSurface_t, memcpy(), drawsurf_s::numVerts, drawsurf_s::patch, drawsurf_s::patchHeight, drawsurf_s::patchWidth, PutMeshOnCurve(), drawsurf_s::side, VectorCopy, mesh_t::verts, drawsurf_s::verts, and mesh_t::width.

Referenced by ChopPatchByBrush(), and PatchMapDrawSurfs().

00041                                                      {
00042     mapDrawSurface_t    *ds;
00043     int             i, j;
00044     mesh_t          *copy;
00045 
00046     // to make valid normals for patches with degenerate edges,
00047     // we need to make a copy of the mesh and put the aproximating
00048     // points onto the curve
00049     copy = CopyMesh( m );
00050     PutMeshOnCurve( *copy );
00051     MakeMeshNormals( *copy );
00052     for ( j = 0 ; j < m->width ; j++ ) {
00053         for ( i = 0 ; i < m->height ; i++ ) {
00054             VectorCopy( copy->verts[i*m->width+j].normal, m->verts[i*m->width+j].normal );
00055         }
00056     }
00057     FreeMesh( copy );
00058 
00059     ds = AllocDrawSurf();
00060     ds->mapBrush = NULL;
00061     ds->side = NULL;
00062 
00063     ds->patch = qtrue;
00064     ds->patchWidth = m->width;
00065     ds->patchHeight = m->height;
00066     ds->numVerts = ds->patchWidth * ds->patchHeight;
00067     ds->verts = malloc( ds->numVerts * sizeof( *ds->verts ) );
00068     memcpy( ds->verts, m->verts, ds->numVerts * sizeof( *ds->verts ) );
00069 
00070     ds->lightmapNum = -1;
00071     ds->fogNum = -1;
00072 
00073     return ds;
00074 }

Here is the call graph for this function:

void GrowGroup_r int  patchNum,
int  patchCount,
const byte bordering,
byte group
 

Definition at line 158 of file patch.c.

References byte, and i.

Referenced by PatchMapDrawSurfs().

00158                                                                                      {
00159     int     i;
00160     const byte *row;
00161 
00162     if ( group[patchNum] ) {
00163         return;
00164     }
00165     group[patchNum] = 1;
00166     row = bordering + patchNum * patchCount;
00167     for ( i = 0 ; i < patchCount ; i++ ) {
00168         if ( row[i] ) {
00169             GrowGroup_r( i, patchCount, bordering, group );
00170         }
00171     }
00172 }

void ParsePatch void   ) 
 

Definition at line 83 of file patch.c.

References BPRIMIT_OLDBRUSHES, epair_t, Error(), g_bBrushPrimit, GetToken(), mesh_t::height, i, j, m, malloc(), mapent, mapIndexedShaders, MatchToken(), MAX_PATCH_SIZE, memset(), numMapIndexedShaders, Parse1DMatrix(), ParseEpair(), parseMesh_t, entity_t::patches, pm, qtrue, ShaderInfoForShader(), sprintf(), strcmp(), strcpy(), texture, UnGetToken(), vec_t, mesh_t::verts, and mesh_t::width.

Referenced by ParseMapEntity().

00083                         {
00084     vec_t       info[5];
00085     int         i, j;
00086     parseMesh_t *pm;
00087     char        texture[MAX_QPATH];
00088     char        shader[MAX_QPATH];
00089     mesh_t      m;
00090     drawVert_t  *verts;
00091   epair_t *ep;
00092 
00093     MatchToken( "{" );
00094 
00095     // get texture
00096     GetToken (qtrue);
00097     strcpy( texture, token );
00098 
00099     // save the shader name for retexturing
00100     if ( numMapIndexedShaders == MAX_MAP_BRUSHSIDES ) {
00101         Error( "MAX_MAP_BRUSHSIDES" );
00102     }
00103     strcpy( mapIndexedShaders[numMapIndexedShaders], texture );
00104     numMapIndexedShaders++;
00105 
00106 
00107     Parse1DMatrix( 5, info );
00108     m.width = info[0];
00109     m.height = info[1];
00110     m.verts = verts = malloc( m.width * m.height * sizeof( m.verts[0] ) );
00111 
00112     if ( m.width < 0 || m.width > MAX_PATCH_SIZE
00113         || m.height < 0 || m.height > MAX_PATCH_SIZE ) {
00114         Error("ParsePatch: bad size");
00115     }
00116 
00117     MatchToken( "(" );
00118     for ( j = 0 ; j < m.width ; j++ ) {
00119         MatchToken( "(" );
00120         for ( i = 0 ; i < m.height ; i++ ) {
00121             Parse1DMatrix( 5, verts[i*m.width+j].xyz );
00122         }
00123         MatchToken( ")" );
00124     }
00125     MatchToken( ")" );
00126 
00127   // if brush primitives format, we may have some epairs to ignore here
00128   GetToken(qtrue);
00129   if (g_bBrushPrimit!=BPRIMIT_OLDBRUSHES && strcmp(token,"}"))
00130   {
00131     // NOTE: we leak that!
00132     ep = ParseEpair();
00133   }
00134   else
00135     UnGetToken();
00136 
00137     MatchToken( "}" );
00138     MatchToken( "}" );
00139 
00140     if ( noCurveBrushes ) {
00141         return;
00142     }
00143 
00144     // find default flags and values
00145     pm = malloc( sizeof( *pm ) );
00146     memset( pm, 0, sizeof( *pm ) );
00147 
00148     sprintf( shader, "textures/%s", texture );
00149     pm->shaderInfo = ShaderInfoForShader( shader ); 
00150     pm->mesh = m;
00151 
00152     // link to the entity
00153     pm->next = mapent->patches;
00154     mapent->patches = pm;
00155 }

Here is the call graph for this function:

void PatchMapDrawSurfs entity_t e  ) 
 

Definition at line 184 of file patch.c.

References AddPointToBounds(), byte, check(), ClearBounds(), DrawSurfaceForMesh(), e, fabs(), parseMesh_s::grouped, GrowGroup_r(), mesh_t::height, i, j, k, l, drawsurf_s::lightmapVecs, malloc(), mapDrawSurface_t, memset(), parseMesh_s::mesh, parseMesh_t, entity_t::patches, pm, qboolean, qprintf(), drawsurf_s::shaderInfo, parseMesh_s::shaderInfo, v1, v2, vec3_t, VectorCopy, mesh_t::verts, mesh_t::width, and drawVert_t::xyz.

Referenced by ProcessSubModel(), and ProcessWorldModel().

00184                                       {
00185     parseMesh_t         *pm;
00186     parseMesh_t         *check, *scan;
00187     mapDrawSurface_t    *ds;
00188     int                 patchCount, groupCount;
00189     int                 i, j, k, l, c1, c2;
00190     drawVert_t          *v1, *v2;
00191     vec3_t              bounds[2];
00192     byte                *bordering;
00193     parseMesh_t         *meshes[MAX_MAP_DRAW_SURFS];
00194     qboolean            grouped[MAX_MAP_DRAW_SURFS];
00195     byte                group[MAX_MAP_DRAW_SURFS];
00196 
00197     qprintf( "----- PatchMapDrawSurfs -----\n" );
00198 
00199     patchCount = 0;
00200     for ( pm = e->patches ; pm ; pm = pm->next  ) {
00201         meshes[patchCount] = pm;
00202         patchCount++;
00203     }
00204 
00205     if ( !patchCount ) {
00206         return;
00207     }
00208     bordering = malloc( patchCount * patchCount );
00209     memset( bordering, 0, patchCount * patchCount );
00210 
00211     // build the bordering matrix
00212     for ( k = 0 ; k < patchCount ; k++ ) {
00213         bordering[k*patchCount+k] = 1;
00214 
00215         for ( l = k+1 ; l < patchCount ; l++ ) {
00216             check = meshes[k];
00217             scan = meshes[l];
00218             c1 = scan->mesh.width * scan->mesh.height;
00219             v1 = scan->mesh.verts;
00220 
00221             for ( i = 0 ; i < c1 ; i++, v1++ ) {
00222                 c2 = check->mesh.width * check->mesh.height;
00223                 v2 = check->mesh.verts;
00224                 for ( j = 0 ; j < c2 ; j++, v2++ ) {
00225                     if ( fabs( v1->xyz[0] - v2->xyz[0] ) < 1.0
00226                         && fabs( v1->xyz[1] - v2->xyz[1] ) < 1.0
00227                         && fabs( v1->xyz[2] - v2->xyz[2] ) < 1.0 ) {
00228                         break;
00229                     }
00230                 }
00231                 if ( j != c2 ) {
00232                     break;
00233                 }
00234             }
00235             if ( i != c1 ) {
00236                 // we have a connection
00237                 bordering[k*patchCount+l] =
00238                 bordering[l*patchCount+k] = 1;
00239             } else {
00240                 // no connection
00241                 bordering[k*patchCount+l] =
00242                 bordering[l*patchCount+k] = 0;
00243             }
00244 
00245         }
00246     }
00247 
00248     // build groups
00249     memset( grouped, 0, sizeof(grouped) );
00250     groupCount = 0;
00251     for ( i = 0 ; i < patchCount ; i++ ) {
00252         if ( !grouped[i] ) {
00253             groupCount++;
00254         }
00255 
00256         // recursively find all patches that belong in the same group
00257         memset( group, 0, patchCount );
00258         GrowGroup_r( i, patchCount, bordering, group );
00259 
00260         // bound them
00261         ClearBounds( bounds[0], bounds[1] );
00262         for ( j = 0 ; j < patchCount ; j++ ) {
00263             if ( group[j] ) {
00264                 grouped[j] = qtrue;
00265                 scan = meshes[j];
00266                 c1 = scan->mesh.width * scan->mesh.height;
00267                 v1 = scan->mesh.verts;
00268                 for ( k = 0 ; k < c1 ; k++, v1++ ) {
00269                     AddPointToBounds( v1->xyz, bounds[0], bounds[1] );
00270                 }
00271             }
00272         }
00273 
00274         // create drawsurf
00275         scan = meshes[i];
00276         scan->grouped = qtrue;
00277         ds = DrawSurfaceForMesh( &scan->mesh );
00278         ds->shaderInfo = scan->shaderInfo;
00279         VectorCopy( bounds[0], ds->lightmapVecs[0] );
00280         VectorCopy( bounds[1], ds->lightmapVecs[1] );
00281     }
00282 
00283     qprintf( "%5i patches\n", patchCount );
00284     qprintf( "%5i patch LOD groups\n", groupCount );
00285 }

Here is the call graph for this function:

void PrintCtrl vec3_t  ctrl[9]  ) 
 

Definition at line 25 of file patch.c.

References _printf(), i, and j.

00025                                  {
00026     int     i, j;
00027 
00028     for ( i = 0 ; i < 3 ; i++ ) {
00029         for ( j = 0 ; j < 3 ; j++ ) {
00030             _printf("(%5.2f %5.2f %5.2f) ", ctrl[i*3+j][0], ctrl[i*3+j][1], ctrl[i*3+j][2] );
00031         }
00032         _printf("\n");
00033     }
00034 }

Here is the call graph for this function:


Generated on Thu Aug 25 16:59:53 2005 for Quake III Arena by  doxygen 1.3.9.1