]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - tools/quake3/q3map2/writebsp.c
Merge branch 'NateEag-master-patch-12920' into 'master'
[xonotic/netradiant.git] / tools / quake3 / q3map2 / writebsp.c
1 /* -------------------------------------------------------------------------------
2
3    Copyright (C) 1999-2007 id Software, Inc. and contributors.
4    For a list of contributors, see the accompanying CONTRIBUTORS file.
5
6    This file is part of GtkRadiant.
7
8    GtkRadiant is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12
13    GtkRadiant is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with GtkRadiant; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21
22    ----------------------------------------------------------------------------------
23
24    This code has been altered significantly from its original form, to support
25    several games based on the Quake III Arena engine, in the form of "Q3Map2."
26
27    ------------------------------------------------------------------------------- */
28
29
30
31 /* marker */
32 #define WRITEBSP_C
33
34
35
36 /* dependencies */
37 #include "q3map2.h"
38
39
40
41 //prefixInfo-stats
42 typedef struct {
43         char    *name;
44         int             surfaceFlags;
45 } prefixInfo_t;
46
47 static prefixInfo_t prefixInfo[] = {
48         { "metal",      TEX_SURF_METAL},
49         { "wood",       TEX_SURF_WOOD},
50         { "cloth",      TEX_SURF_CLOTH},
51         { "dirt",       TEX_SURF_DIRT},
52         { "glass",      TEX_SURF_GLASS},
53         { "plant",      TEX_SURF_PLANT},
54         { "sand",       TEX_SURF_SAND},
55         { "snow",       TEX_SURF_SNOW},
56         { "stone",      TEX_SURF_STONE},
57         { "water",      TEX_SURF_WATER},
58         { "grass",      TEX_SURF_GRASS},
59 };
60
61 #define NUM_PREFIXINFO 11 /* very important */
62
63 //Added by Spoon to recognize surfaceparms by shadernames
64 int GetSurfaceParm(const char *tex){
65         char surf[MAX_QPATH], tex2[MAX_QPATH];
66         int     i, j = 0;
67
68         strcpy(tex2, tex);
69
70         /* find last dir */
71         for(i = 0; i < 64 && tex2[i] != '\0'; i++){
72                 if(tex2[i] == '\\' || tex2[i] == '/')
73                         j=i+1;
74         }
75
76         strcpy(surf, tex2+j);
77
78         for(i=0; i<10; i++){
79                 if(surf[i] == '_')
80                         break;
81         }
82         surf[i] = '\0';
83
84         /* Sys_Printf("%s\n", surf); */
85
86         for(i=0; i < NUM_PREFIXINFO; i++){
87                 if(!Q_stricmp(surf, prefixInfo[i].name)){
88                         return prefixInfo[i].surfaceFlags;
89                 }
90         }
91         return 0;
92 }
93
94
95
96 /*
97    EmitShader()
98    emits a bsp shader entry
99  */
100
101 int EmitShader( const char *shader, int *contentFlags, int *surfaceFlags ){
102         int i;
103         shaderInfo_t    *si;
104
105
106         /* handle special cases */
107         if ( shader == NULL ) {
108                 shader = "noshader";
109         }
110
111         /* try to find an existing shader */
112         for ( i = 0; i < numBSPShaders; i++ )
113         {
114                 /* if not Smokin'Guns like tex file */
115                 if ( !game->texFile )
116                 {
117                 /* ydnar: handle custom surface/content flags */
118                 if ( surfaceFlags != NULL && bspShaders[ i ].surfaceFlags != *surfaceFlags ) {
119                         continue;
120                 }
121                 if ( contentFlags != NULL && bspShaders[ i ].contentFlags != *contentFlags ) {
122                         continue;
123                 }
124                 }
125                 if ( !doingBSP ){
126                         si = ShaderInfoForShader( shader );
127                         if ( si->remapShader && si->remapShader[ 0 ] ) {
128                                 shader = si->remapShader;
129                         }
130                 }
131                 /* compare name */
132                 if ( !Q_stricmp( shader, bspShaders[ i ].shader ) ) {
133                         return i;
134                 }
135         }
136
137         /* get shaderinfo */
138         si = ShaderInfoForShader( shader );
139
140         /* emit a new shader */
141         AUTOEXPAND_BY_REALLOC0_BSP( Shaders, 1024 );
142
143         numBSPShaders++;
144         strcpy( bspShaders[ i ].shader, shader );
145         bspShaders[ i ].surfaceFlags = si->surfaceFlags;
146
147         if ( game->texFile )
148         {
149                 /* Smokin'Guns like tex file */
150                 bspShaders[ i ].surfaceFlags |= GetSurfaceParm(si->shader);
151         }
152
153         bspShaders[ i ].contentFlags = si->contentFlags;
154
155         /* if not Smokin'Guns like tex file */
156         if ( !game->texFile )
157         {
158         /* handle custom content/surface flags */
159         if ( surfaceFlags != NULL ) {
160                 bspShaders[ i ].surfaceFlags = *surfaceFlags;
161         }
162         if ( contentFlags != NULL ) {
163                 bspShaders[ i ].contentFlags = *contentFlags;
164         }
165         }
166
167         /* recursively emit any damage shaders */
168         if ( si->damageShader != NULL && si->damageShader[ 0 ] != '\0' ) {
169                 Sys_FPrintf( SYS_VRB, "Shader %s has damage shader %s\n", si->shader, si->damageShader );
170                 EmitShader( si->damageShader, NULL, NULL );
171         }
172
173         /* return it */
174         return i;
175 }
176
177
178
179 /*
180    EmitPlanes()
181    there is no oportunity to discard planes, because all of the original
182    brushes will be saved in the map
183  */
184
185 void EmitPlanes( void ){
186         int i;
187         bspPlane_t  *bp;
188         plane_t     *mp;
189
190
191         /* walk plane list */
192         mp = mapplanes;
193         for ( i = 0; i < nummapplanes; i++, mp++ )
194         {
195                 AUTOEXPAND_BY_REALLOC_BSP( Planes, 1024 );
196                 bp = &bspPlanes[ numBSPPlanes ];
197                 VectorCopy( mp->normal, bp->normal );
198                 bp->dist = mp->dist;
199                 numBSPPlanes++;
200         }
201
202         /* emit some statistics */
203         Sys_FPrintf( SYS_VRB, "%9d BSP planes\n", numBSPPlanes );
204 }
205
206
207
208 /*
209    EmitLeaf()
210    emits a leafnode to the bsp file
211  */
212
213 void EmitLeaf( node_t *node ){
214         bspLeaf_t       *leaf_p;
215         brush_t         *b;
216         drawSurfRef_t   *dsr;
217
218
219         /* check limits */
220         if ( numBSPLeafs >= MAX_MAP_LEAFS ) {
221                 Error( "MAX_MAP_LEAFS" );
222         }
223
224         leaf_p = &bspLeafs[numBSPLeafs];
225         numBSPLeafs++;
226
227         leaf_p->cluster = node->cluster;
228         leaf_p->area = node->area;
229
230         /* emit bounding box */
231         VectorCopy( node->mins, leaf_p->mins );
232         VectorCopy( node->maxs, leaf_p->maxs );
233
234         /* emit leaf brushes */
235         leaf_p->firstBSPLeafBrush = numBSPLeafBrushes;
236         for ( b = node->brushlist; b; b = b->next )
237         {
238                 /* something is corrupting brushes */
239                 if ( (size_t) b < 256 ) {
240                         Sys_FPrintf( SYS_WRN, "WARNING: Node brush list corrupted (0x%08X)\n", b );
241                         break;
242                 }
243                 //%     if( b->guard != 0xDEADBEEF )
244                 //%             Sys_Printf( "Brush %6d: 0x%08X Guard: 0x%08X Next: 0x%08X Original: 0x%08X Sides: %d\n", b->brushNum, b, b, b->next, b->original, b->numsides );
245
246                 AUTOEXPAND_BY_REALLOC_BSP( LeafBrushes, 1024 );
247                 bspLeafBrushes[ numBSPLeafBrushes ] = b->original->outputNum;
248                 numBSPLeafBrushes++;
249         }
250
251         leaf_p->numBSPLeafBrushes = numBSPLeafBrushes - leaf_p->firstBSPLeafBrush;
252
253         /* emit leaf surfaces */
254         if ( node->opaque ) {
255                 return;
256         }
257
258         /* add the drawSurfRef_t drawsurfs */
259         leaf_p->firstBSPLeafSurface = numBSPLeafSurfaces;
260         for ( dsr = node->drawSurfReferences; dsr; dsr = dsr->nextRef )
261         {
262                 AUTOEXPAND_BY_REALLOC_BSP( LeafSurfaces, 1024 );
263                 bspLeafSurfaces[ numBSPLeafSurfaces ] = dsr->outputNum;
264                 numBSPLeafSurfaces++;
265         }
266
267         leaf_p->numBSPLeafSurfaces = numBSPLeafSurfaces - leaf_p->firstBSPLeafSurface;
268 }
269
270
271 /*
272    EmitDrawNode_r()
273    recursively emit the bsp nodes
274  */
275
276 int EmitDrawNode_r( node_t *node ){
277         bspNode_t   *n;
278         int i, n0;
279
280
281         /* check for leafnode */
282         if ( node->planenum == PLANENUM_LEAF ) {
283                 EmitLeaf( node );
284                 return -numBSPLeafs;
285         }
286
287         /* emit a node */
288         AUTOEXPAND_BY_REALLOC_BSP( Nodes, 1024 );
289         n0 = numBSPNodes;
290         n = &bspNodes[ n0 ];
291         numBSPNodes++;
292
293         VectorCopy( node->mins, n->mins );
294         VectorCopy( node->maxs, n->maxs );
295
296         if ( node->planenum & 1 ) {
297                 Error( "WriteDrawNodes_r: odd planenum" );
298         }
299         n->planeNum = node->planenum;
300
301         //
302         // recursively output the other nodes
303         //
304         for ( i = 0 ; i < 2 ; i++ )
305         {
306                 if ( node->children[i]->planenum == PLANENUM_LEAF ) {
307                         n->children[i] = -( numBSPLeafs + 1 );
308                         EmitLeaf( node->children[i] );
309                 }
310                 else
311                 {
312                         n->children[i] = numBSPNodes;
313                         EmitDrawNode_r( node->children[i] );
314                         // n may have become invalid here, so...
315                         n = &bspNodes[ n0 ];
316                 }
317         }
318
319         return n - bspNodes;
320 }
321
322
323
324 /*
325    ============
326    SetModelNumbers
327    ============
328  */
329 void SetModelNumbers( void ){
330         int i;
331         int models;
332         char value[10];
333
334         models = 1;
335         for ( i = 1 ; i < numEntities ; i++ ) {
336                 if ( entities[i].brushes || entities[i].patches ) {
337                         sprintf( value, "*%i", models );
338                         models++;
339                         SetKeyValue( &entities[i], "model", value );
340                 }
341         }
342
343 }
344
345
346
347
348 /*
349    SetLightStyles()
350    sets style keys for entity lights
351  */
352
353 void SetLightStyles( void ){
354         int i, j, style, numStyles;
355         const char  *t;
356         entity_t    *e;
357         epair_t     *ep, *next;
358         char value[ 10 ];
359         char lightTargets[ MAX_SWITCHED_LIGHTS ][ 64 ];
360         int lightStyles[ MAX_SWITCHED_LIGHTS ];
361
362         /* -keeplights option: force lights to be kept and ignore what the map file says */
363         if ( keepLights ) {
364                 SetKeyValue( &entities[0], "_keepLights", "1" );
365         }
366
367         /* ydnar: determine if we keep lights in the bsp */
368         if ( KeyExists( &entities[ 0 ], "_keepLights" ) == qtrue ) {
369                 t = ValueForKey( &entities[ 0 ], "_keepLights" );
370                 keepLights = ( t[ 0 ] == '1' ) ? qtrue : qfalse;
371         }
372
373         /* any light that is controlled (has a targetname) must have a unique style number generated for it */
374         numStyles = 0;
375         for ( i = 1; i < numEntities; i++ )
376         {
377                 e = &entities[ i ];
378
379                 t = ValueForKey( e, "classname" );
380                 if ( Q_strncasecmp( t, "light", 5 ) ) {
381                         continue;
382                 }
383                 t = ValueForKey( e, "targetname" );
384                 if ( t[ 0 ] == '\0' ) {
385                         /* ydnar: strip the light from the BSP file */
386                         if ( keepLights == qfalse ) {
387                                 ep = e->epairs;
388                                 while ( ep != NULL )
389                                 {
390                                         next = ep->next;
391                                         free( ep->key );
392                                         free( ep->value );
393                                         free( ep );
394                                         ep = next;
395                                 }
396                                 e->epairs = NULL;
397                                 numStrippedLights++;
398                         }
399
400                         /* next light */
401                         continue;
402                 }
403
404                 /* get existing style */
405                 style = IntForKey( e, "style" );
406                 if ( style < LS_NORMAL || style > LS_NONE ) {
407                         Error( "Invalid lightstyle (%d) on entity %d", style, i );
408                 }
409
410                 /* find this targetname */
411                 for ( j = 0; j < numStyles; j++ )
412                         if ( lightStyles[ j ] == style && !strcmp( lightTargets[ j ], t ) ) {
413                                 break;
414                         }
415
416                 /* add a new style */
417                 if ( j >= numStyles ) {
418                         if ( numStyles == MAX_SWITCHED_LIGHTS ) {
419                                 Error( "MAX_SWITCHED_LIGHTS (%d) exceeded, reduce the number of lights with targetnames", MAX_SWITCHED_LIGHTS );
420                         }
421                         strcpy( lightTargets[ j ], t );
422                         lightStyles[ j ] = style;
423                         numStyles++;
424                 }
425
426                 /* set explicit style */
427                 sprintf( value, "%d", 32 + j );
428                 SetKeyValue( e, "style", value );
429
430                 /* set old style */
431                 if ( style != LS_NORMAL ) {
432                         sprintf( value, "%d", style );
433                         SetKeyValue( e, "switch_style", value );
434                 }
435         }
436
437         /* emit some statistics */
438         Sys_FPrintf( SYS_VRB, "%9d light entities stripped\n", numStrippedLights );
439 }
440
441
442
443 /*
444    BeginBSPFile()
445    starts a new bsp file
446  */
447
448 void BeginBSPFile( void ){
449         /* these values may actually be initialized if the file existed when loaded, so clear them explicitly */
450         numBSPModels = 0;
451         numBSPNodes = 0;
452         numBSPBrushSides = 0;
453         numBSPLeafSurfaces = 0;
454         numBSPLeafBrushes = 0;
455
456         /* leave leaf 0 as an error, because leafs are referenced as negative number nodes */
457         numBSPLeafs = 1;
458
459
460         /* ydnar: gs mods: set the first 6 drawindexes to 0 1 2 2 1 3 for triangles and quads */
461         numBSPDrawIndexes = 6;
462         AUTOEXPAND_BY_REALLOC_BSP( DrawIndexes, 1024 );
463         bspDrawIndexes[ 0 ] = 0;
464         bspDrawIndexes[ 1 ] = 1;
465         bspDrawIndexes[ 2 ] = 2;
466         bspDrawIndexes[ 3 ] = 0;
467         bspDrawIndexes[ 4 ] = 2;
468         bspDrawIndexes[ 5 ] = 3;
469 }
470
471
472
473 /*
474    RestoreSurfaceFlags()
475    read Smokin'Guns like tex file
476    added by spoon to get back the changed surfaceflags
477  */
478
479 void RestoreSurfaceFlags( char *filename ) {
480         int i;
481         FILE *texfile;
482         int surfaceFlags[ MAX_MAP_DRAW_SURFS ];
483         int numTexInfos;
484
485         /* first parse the tex file */
486         texfile = fopen( filename, "r" );
487
488         if ( texfile ) {
489                 fscanf( texfile, "TEXFILE\n%i\n", &numTexInfos );
490
491                 /* Sys_Printf( "%i\n", numTexInfos ); */
492
493                 for ( i = 0; i < numTexInfos; i++ ) {
494                         vec3_t color;
495
496                         fscanf( texfile, "%i %f %f %f\n", &surfaceFlags[ i ],
497                                 &color[ 0 ], &color[ 1 ], &color[ 2 ]);
498
499                         bspShaders[ i ].surfaceFlags = surfaceFlags[ i ];
500
501                         /* Sys_Printf( "%i\n", surfaceFlags[ i ] ); */
502                 }
503         } else {
504                 Sys_Printf("couldn't find %s not tex-file is now writed without surfaceFlags!\n", filename);
505         }
506 }
507
508
509
510 /*
511    WriteTexFile()
512    write Smokin'Guns like tex file
513    added by spoon
514  */
515
516 void WriteTexFile( char* filename ) {
517         FILE *texfile;
518         int i;
519
520         if ( !compile_map ) {
521                 RestoreSurfaceFlags( filename );
522         }
523
524         Sys_Printf( "Writing %s ...\n", filename );
525
526         texfile = fopen ( filename, "w" );
527
528         fprintf( texfile, "TEXFILE\n" );
529
530         fprintf( texfile, "%i\n", numBSPShaders );
531
532         for ( i = 0 ; i < numBSPShaders ; i++ ) {
533                 shaderInfo_t *se = ShaderInfoForShader( bspShaders[ i ].shader );
534
535                 fprintf( texfile, "\n%i %f %f %f", bspShaders[ i ].surfaceFlags,
536                         se->color[ 0 ], se->color[ 1 ], se->color[ 2 ] );
537
538                 bspShaders[ i ].surfaceFlags = i;
539         }
540
541         fclose( texfile );
542 }
543
544
545
546 /*
547    EndBSPFile()
548    finishes a new bsp and writes to disk
549  */
550
551 void EndBSPFile( qboolean do_write, const char *BSPFilePath, const char *surfaceFilePath ){
552
553         Sys_FPrintf( SYS_VRB, "--- EndBSPFile ---\n" );
554
555         EmitPlanes();
556
557         numBSPEntities = numEntities;
558         UnparseEntities();
559
560         if ( do_write ) {
561                 /* write the surface extra file */
562                 WriteSurfaceExtraFile( surfaceFilePath );
563
564                 if ( game->texFile )
565                 {
566                         char basename[ 1024 ];  
567                         char filename[ 1024 ];
568                         strncpy( basename, BSPFilePath, sizeof(basename) );
569                         StripExtension( basename );
570                         sprintf( filename, "%s.tex", basename );
571
572                         /* only create tex file if it is the first compile */
573                         WriteTexFile( filename );
574                 }
575
576                 /* write the bsp */
577                 Sys_Printf( "Writing %s\n", BSPFilePath );
578                 WriteBSPFile( BSPFilePath );
579         }
580 }
581
582
583
584 /*
585    EmitBrushes()
586    writes the brush list to the bsp
587  */
588
589 void EmitBrushes( brush_t *brushes, int *firstBrush, int *numBrushes ){
590         int j;
591         brush_t         *b;
592         bspBrush_t      *db;
593         bspBrushSide_t  *cp;
594
595
596         /* set initial brush */
597         if ( firstBrush != NULL ) {
598                 *firstBrush = numBSPBrushes;
599         }
600         if ( numBrushes != NULL ) {
601                 *numBrushes = 0;
602         }
603
604         /* walk list of brushes */
605         for ( b = brushes; b != NULL; b = b->next )
606         {
607                 /* check limits */
608                 AUTOEXPAND_BY_REALLOC_BSP( Brushes, 1024 );
609
610                 /* get bsp brush */
611                 b->outputNum = numBSPBrushes;
612                 db = &bspBrushes[ numBSPBrushes ];
613                 numBSPBrushes++;
614                 if ( numBrushes != NULL ) {
615                         ( *numBrushes )++;
616                 }
617
618                 db->shaderNum = EmitShader( b->contentShader->shader, &b->contentShader->contentFlags, &b->contentShader->surfaceFlags );
619                 db->firstSide = numBSPBrushSides;
620
621                 /* walk sides */
622                 db->numSides = 0;
623                 for ( j = 0; j < b->numsides; j++ )
624                 {
625                         /* set output number to bogus initially */
626                         b->sides[ j ].outputNum = -1;
627
628                         /* check count */
629                         AUTOEXPAND_BY_REALLOC_BSP( BrushSides, 1024 );
630
631                         /* emit side */
632                         b->sides[ j ].outputNum = numBSPBrushSides;
633                         cp = &bspBrushSides[ numBSPBrushSides ];
634                         db->numSides++;
635                         numBSPBrushSides++;
636                         cp->planeNum = b->sides[ j ].planenum;
637
638                         /* emit shader */
639                         if ( b->sides[ j ].shaderInfo ) {
640                                 cp->shaderNum = EmitShader( b->sides[ j ].shaderInfo->shader, &b->sides[ j ].shaderInfo->contentFlags, &b->sides[ j ].shaderInfo->surfaceFlags );
641                         }
642                         else{
643                                 cp->shaderNum = EmitShader( NULL, NULL, NULL );
644                         }
645                 }
646         }
647 }
648
649
650
651 /*
652    EmitFogs() - ydnar
653    turns map fogs into bsp fogs
654  */
655
656 void EmitFogs( void ){
657         int i, j;
658
659
660         /* setup */
661         numBSPFogs = numMapFogs;
662
663         /* walk list */
664         for ( i = 0; i < numMapFogs; i++ )
665         {
666                 /* set shader */
667                 strcpy( bspFogs[ i ].shader, mapFogs[ i ].si->shader );
668
669                 /* global fog doesn't have an associated brush */
670                 if ( mapFogs[ i ].brush == NULL ) {
671                         bspFogs[ i ].brushNum = -1;
672                         bspFogs[ i ].visibleSide = -1;
673                 }
674                 else
675                 {
676                         /* set brush */
677                         bspFogs[ i ].brushNum = mapFogs[ i ].brush->outputNum;
678
679                         /* try to use forced visible side */
680                         if ( mapFogs[ i ].visibleSide >= 0 ) {
681                                 bspFogs[ i ].visibleSide = mapFogs[ i ].visibleSide;
682                                 continue;
683                         }
684
685                         /* find visible side */
686                         for ( j = 0; j < 6; j++ )
687                         {
688                                 if ( mapFogs[ i ].brush->sides[ j ].visibleHull != NULL ) {
689                                         Sys_Printf( "Fog %d has visible side %d\n", i, j );
690                                         bspFogs[ i ].visibleSide = j;
691                                         break;
692                                 }
693                         }
694                 }
695         }
696 }
697
698
699
700 /*
701    BeginModel()
702    sets up a new brush model
703  */
704
705 void BeginModel( void ){
706         bspModel_t  *mod;
707         brush_t     *b;
708         entity_t    *e;
709         vec3_t mins, maxs;
710         vec3_t lgMins, lgMaxs;          /* ydnar: lightgrid mins/maxs */
711         parseMesh_t *p;
712         int i;
713
714
715         /* test limits */
716         AUTOEXPAND_BY_REALLOC_BSP( Models, 256 );
717
718         /* get model and entity */
719         mod = &bspModels[ numBSPModels ];
720         e = &entities[ mapEntityNum ];
721
722         /* ydnar: lightgrid mins/maxs */
723         ClearBounds( lgMins, lgMaxs );
724
725         /* bound the brushes */
726         ClearBounds( mins, maxs );
727         for ( b = e->brushes; b; b = b->next )
728         {
729                 /* ignore non-real brushes (origin, etc) */
730                 if ( b->numsides == 0 ) {
731                         continue;
732                 }
733                 AddPointToBounds( b->mins, mins, maxs );
734                 AddPointToBounds( b->maxs, mins, maxs );
735
736                 /* ydnar: lightgrid bounds */
737                 if ( b->compileFlags & C_LIGHTGRID ) {
738                         AddPointToBounds( b->mins, lgMins, lgMaxs );
739                         AddPointToBounds( b->maxs, lgMins, lgMaxs );
740                 }
741         }
742
743         /* bound patches */
744         for ( p = e->patches; p; p = p->next )
745         {
746                 for ( i = 0; i < ( p->mesh.width * p->mesh.height ); i++ )
747                         AddPointToBounds( p->mesh.verts[i].xyz, mins, maxs );
748         }
749
750         /* ydnar: lightgrid mins/maxs */
751         if ( lgMins[ 0 ] < 99999 ) {
752                 /* use lightgrid bounds */
753                 VectorCopy( lgMins, mod->mins );
754                 VectorCopy( lgMaxs, mod->maxs );
755         }
756         else
757         {
758                 /* use brush/patch bounds */
759                 VectorCopy( mins, mod->mins );
760                 VectorCopy( maxs, mod->maxs );
761         }
762
763         /* note size */
764         Sys_FPrintf( SYS_VRB, "BSP bounds: { %f %f %f } { %f %f %f }\n", mins[ 0 ], mins[ 1 ], mins[ 2 ], maxs[ 0 ], maxs[ 1 ], maxs[ 2 ] );
765         Sys_FPrintf( SYS_VRB, "Lightgrid bounds: { %f %f %f } { %f %f %f }\n", lgMins[ 0 ], lgMins[ 1 ], lgMins[ 2 ], lgMaxs[ 0 ], lgMaxs[ 1 ], lgMaxs[ 2 ] );
766
767         /* set firsts */
768         mod->firstBSPSurface = numBSPDrawSurfaces;
769         mod->firstBSPBrush = numBSPBrushes;
770 }
771
772
773
774
775 /*
776    EndModel()
777    finish a model's processing
778  */
779
780 void EndModel( entity_t *e, node_t *headnode ){
781         bspModel_t  *mod;
782
783
784         /* note it */
785         Sys_FPrintf( SYS_VRB, "--- EndModel ---\n" );
786
787         /* emit the bsp */
788         mod = &bspModels[ numBSPModels ];
789         EmitDrawNode_r( headnode );
790
791         /* set surfaces and brushes */
792         mod->numBSPSurfaces = numBSPDrawSurfaces - mod->firstBSPSurface;
793         mod->firstBSPBrush = e->firstBrush;
794         mod->numBSPBrushes = e->numBrushes;
795
796         /* increment model count */
797         numBSPModels++;
798 }