1 /* -------------------------------------------------------------------------------
3 Copyright (C) 1999-2007 id Software, Inc. and contributors.
4 For a list of contributors, see the accompanying CONTRIBUTORS file.
6 This file is part of GtkRadiant.
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.
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.
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
22 ----------------------------------------------------------------------------------
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."
27 ------------------------------------------------------------------------------- */
41 /* -------------------------------------------------------------------------------
45 ------------------------------------------------------------------------------- */
48 ProcessAdvertisements()
49 copies advertisement info into the BSP structures
52 static void ProcessAdvertisements( void ) {
54 const char* className;
58 bspDrawSurface_t* adSurface;
60 Sys_FPrintf( SYS_VRB, "--- ProcessAdvertisements ---\n" );
62 for ( i = 0; i < numEntities; i++ ) {
64 /* is an advertisement? */
65 className = ValueForKey( &entities[ i ], "classname" );
67 if ( !Q_stricmp( "advertisement", className ) ) {
69 modelKey = ValueForKey( &entities[ i ], "model" );
71 if ( strlen( modelKey ) > MAX_QPATH - 1 ) {
72 Error( "Model Key for entity exceeds ad struct string length." );
75 if ( numBSPAds < MAX_MAP_ADVERTISEMENTS ) {
76 bspAds[numBSPAds].cellId = IntForKey( &entities[ i ], "cellId" );
77 strncpy( bspAds[numBSPAds].model, modelKey, sizeof( bspAds[numBSPAds].model ) );
80 modelNum = atoi( modelKey );
81 adModel = &bspModels[modelNum];
83 if ( adModel->numBSPSurfaces != 1 ) {
84 Error( "Ad cell id %d has more than one surface.", bspAds[numBSPAds].cellId );
87 adSurface = &bspDrawSurfaces[adModel->firstBSPSurface];
89 // store the normal for use at run time.. all ad verts are assumed to
90 // have identical normals (because they should be a simple rectangle)
91 // so just use the first vert's normal
92 VectorCopy( bspDrawVerts[adSurface->firstVert].normal, bspAds[numBSPAds].normal );
94 // store the ad quad for quick use at run time
95 if ( adSurface->surfaceType == MST_PATCH ) {
96 int v0 = adSurface->firstVert + adSurface->patchHeight - 1;
97 int v1 = adSurface->firstVert + adSurface->numVerts - 1;
98 int v2 = adSurface->firstVert + adSurface->numVerts - adSurface->patchWidth;
99 int v3 = adSurface->firstVert;
100 VectorCopy( bspDrawVerts[v0].xyz, bspAds[numBSPAds].rect[0] );
101 VectorCopy( bspDrawVerts[v1].xyz, bspAds[numBSPAds].rect[1] );
102 VectorCopy( bspDrawVerts[v2].xyz, bspAds[numBSPAds].rect[2] );
103 VectorCopy( bspDrawVerts[v3].xyz, bspAds[numBSPAds].rect[3] );
106 Error( "Ad cell %d has an unsupported Ad Surface type.", bspAds[numBSPAds].cellId );
112 Error( "Maximum number of map advertisements exceeded." );
118 Sys_FPrintf( SYS_VRB, "%9d in-game advertisements\n", numBSPAds );
122 SetCloneModelNumbers() - ydnar
123 sets the model numbers for brush entities
126 static void SetCloneModelNumbers( void ){
129 char modelValue[ 10 ];
130 const char *value, *value2, *value3;
133 /* start with 1 (worldspawn is model 0) */
135 for ( i = 1; i < numEntities; i++ )
137 /* only entities with brushes or patches get a model number */
138 if ( entities[ i ].brushes == NULL && entities[ i ].patches == NULL ) {
142 /* is this a clone? */
143 value = ValueForKey( &entities[ i ], "_ins" );
144 if ( value[ 0 ] == '\0' ) {
145 value = ValueForKey( &entities[ i ], "_instance" );
147 if ( value[ 0 ] == '\0' ) {
148 value = ValueForKey( &entities[ i ], "_clone" );
150 if ( value[ 0 ] != '\0' ) {
154 /* add the model key */
155 sprintf( modelValue, "*%d", models );
156 SetKeyValue( &entities[ i ], "model", modelValue );
158 /* increment model count */
163 for ( i = 1; i < numEntities; i++ )
165 /* only entities with brushes or patches get a model number */
166 if ( entities[ i ].brushes == NULL && entities[ i ].patches == NULL ) {
170 /* is this a clone? */
171 value = ValueForKey( &entities[ i ], "_ins" );
172 if ( value[ 0 ] == '\0' ) {
173 value = ValueForKey( &entities[ i ], "_instance" );
175 if ( value[ 0 ] == '\0' ) {
176 value = ValueForKey( &entities[ i ], "_clone" );
178 if ( value[ 0 ] == '\0' ) {
182 /* find an entity with matching clone name */
183 for ( j = 0; j < numEntities; j++ )
185 /* is this a clone parent? */
186 value2 = ValueForKey( &entities[ j ], "_clonename" );
187 if ( value2[ 0 ] == '\0' ) {
192 if ( strcmp( value, value2 ) == 0 ) {
193 /* get the model num */
194 value3 = ValueForKey( &entities[ j ], "model" );
195 if ( value3[ 0 ] == '\0' ) {
196 Sys_FPrintf( SYS_WRN, "WARNING: Cloned entity %s referenced entity without model\n", value2 );
199 models = atoi( &value2[ 1 ] );
201 /* add the model key */
202 sprintf( modelValue, "*%d", models );
203 SetKeyValue( &entities[ i ], "model", modelValue );
205 /* nuke the brushes/patches for this entity (fixme: leak!) */
206 entities[ i ].brushes = NULL;
207 entities[ i ].patches = NULL;
216 FixBrushSides() - ydnar
217 matches brushsides back to their appropriate drawsurface and shader
220 static void FixBrushSides( entity_t *e ){
222 mapDrawSurface_t *ds;
224 bspBrushSide_t *side;
228 Sys_FPrintf( SYS_VRB, "--- FixBrushSides ---\n" );
230 /* walk list of drawsurfaces */
231 for ( i = e->firstDrawSurf; i < numMapDrawSurfs; i++ )
233 /* get surface and try to early out */
234 ds = &mapDrawSurfs[ i ];
235 if ( ds->outputNum < 0 ) {
239 /* walk sideref list */
240 for ( sideRef = ds->sideRef; sideRef != NULL; sideRef = sideRef->next )
242 /* get bsp brush side */
243 if ( sideRef->side == NULL || sideRef->side->outputNum < 0 ) {
246 side = &bspBrushSides[ sideRef->side->outputNum ];
248 /* set drawsurface */
249 side->surfaceNum = ds->outputNum;
250 //% Sys_FPrintf( SYS_VRB, "DS: %7d Side: %7d ", ds->outputNum, sideRef->side->outputNum );
253 if ( strcmp( bspShaders[ side->shaderNum ].shader, ds->shaderInfo->shader ) ) {
254 //% Sys_FPrintf( SYS_VRB, "Remapping %s to %s\n", bspShaders[ side->shaderNum ].shader, ds->shaderInfo->shader );
255 side->shaderNum = EmitShader( ds->shaderInfo->shader, &ds->shaderInfo->contentFlags, &ds->shaderInfo->surfaceFlags );
265 creates a full bsp + surfaces for the worldspawn entity
268 void ProcessWorldModel( const char *portalFilePath, const char *lineFilePath ){
273 qboolean ignoreLeaks, leaked;
274 xmlNodePtr polyline, leaknode;
275 char level[ 2 ], shader[ 1024 ];
279 /* sets integer blockSize from worldspawn "_blocksize" key if it exists */
280 value = ValueForKey( &entities[ 0 ], "_blocksize" );
281 if ( value[ 0 ] == '\0' ) {
282 value = ValueForKey( &entities[ 0 ], "blocksize" );
284 if ( value[ 0 ] == '\0' ) {
285 value = ValueForKey( &entities[ 0 ], "chopsize" ); /* sof2 */
287 if ( value[ 0 ] != '\0' ) {
289 s = sscanf( value, "%d %d %d", &blockSize[ 0 ], &blockSize[ 1 ], &blockSize[ 2 ] );
291 /* handle legacy case */
293 blockSize[ 1 ] = blockSize[ 0 ];
294 blockSize[ 2 ] = blockSize[ 0 ];
297 Sys_Printf( "block size = { %d %d %d }\n", blockSize[ 0 ], blockSize[ 1 ], blockSize[ 2 ] );
299 /* sof2: ignore leaks? */
300 value = ValueForKey( &entities[ 0 ], "_ignoreleaks" ); /* ydnar */
301 if ( value[ 0 ] == '\0' ) {
302 value = ValueForKey( &entities[ 0 ], "ignoreleaks" );
304 if ( value[ 0 ] == '1' ) {
308 ignoreLeaks = qfalse;
311 /* begin worldspawn model */
314 e->firstDrawSurf = 0;
317 ClearMetaTriangles();
319 /* check for patches with adjacent edges that need to lod together */
320 PatchMapDrawSurfs( e );
323 AddTriangleModels( e );
326 /* build an initial bsp tree using all of the sides of all of the structural brushes */
327 faces = MakeStructuralBSPFaceList( entities[ 0 ].brushes );
328 tree = FaceBSP( faces );
329 MakeTreePortals( tree );
330 FilterStructuralBrushesIntoTree( e, tree );
332 /* see if the bsp is completely enclosed */
333 leakStatus = FloodEntities( tree );
335 if ( leakStatus == FLOODENTITIES_LEAKED ) {
336 leakStatus = FLOODENTITIES_GOOD;
340 if ( leakStatus == FLOODENTITIES_GOOD ) {
347 Sys_FPrintf( SYS_NOXML, "**********************\n" );
348 Sys_FPrintf( SYS_NOXML, "******* leaked *******\n" );
349 Sys_FPrintf( SYS_NOXML, "**********************\n" );
350 polyline = LeakFile( tree, lineFilePath );
351 leaknode = xmlNewNode( NULL, (xmlChar*)"message" );
352 xmlNodeAddContent( leaknode, (xmlChar*)"MAP LEAKED\n" );
353 xmlAddChild( leaknode, polyline );
354 level[0] = (int) '0' + SYS_ERR;
356 xmlSetProp( leaknode, (xmlChar*)"level", (xmlChar*) &level );
357 xml_SendNode( leaknode );
359 Sys_Printf( "--- MAP LEAKED, ABORTING LEAKTEST ---\n" );
364 if ( leakStatus != FLOODENTITIES_EMPTY ) { /* if no entities exist, this would accidentally the whole map, and that IS bad */
365 /* rebuild a better bsp tree using only the sides that are visible from the inside */
366 FillOutside( tree->headnode );
368 /* chop the sides to the convex hull of their visible fragments, giving us the smallest polygons */
369 ClipSidesIntoTree( e, tree );
371 /* build a visible face tree (same thing as the initial bsp tree but after reducing the faces) */
372 faces = MakeVisibleBSPFaceList( entities[ 0 ].brushes );
374 tree = FaceBSP( faces );
375 MakeTreePortals( tree );
376 FilterStructuralBrushesIntoTree( e, tree );
378 /* ydnar: flood again for skybox */
379 if ( skyboxPresent ) {
380 FloodEntities( tree );
384 /* save out information for visibility processing */
385 NumberClusters( tree );
387 WritePortalFile( tree, portalFilePath );
390 /* flood from entities */
393 /* create drawsurfs for triangle models */
395 AddTriangleModels( e );
398 /* create drawsurfs for surface models */
399 AddEntitySurfaceModels( e );
401 /* generate bsp brushes from map brushes */
402 EmitBrushes( e->brushes, &e->firstBrush, &e->numBrushes );
404 /* add references to the detail brushes */
405 FilterDetailBrushesIntoTree( e, tree );
407 /* drawsurfs that cross fog boundaries will need to be split along the fog boundary */
409 FogDrawSurfaces( e );
412 /* subdivide each drawsurf as required by shader tesselation */
413 if ( !nosubdivide ) {
414 SubdivideFaceSurfaces( e, tree );
417 /* add in any vertexes required to fix t-junctions */
422 /* ydnar: classify the surfaces */
423 ClassifyEntitySurfaces( e );
425 /* ydnar: project decals */
426 MakeEntityDecals( e );
428 /* ydnar: meta surfaces */
429 MakeEntityMetaTriangles( e );
430 SmoothMetaTriangles();
432 MergeMetaTriangles();
434 /* ydnar: debug portals */
435 if ( debugPortals ) {
436 MakeDebugPortalSurfs( tree );
439 /* ydnar: fog hull */
440 value = ValueForKey( &entities[ 0 ], "_foghull" );
441 if ( value[ 0 ] != '\0' ) {
442 sprintf( shader, "textures/%s", value );
443 MakeFogHullSurfs( e, tree, shader );
446 /* ydnar: bug 645: do flares for lights */
447 for ( i = 0; i < numEntities && emitFlares; i++ )
449 entity_t *light, *target;
450 const char *value, *flareShader;
451 vec3_t origin, targetOrigin, normal, color;
456 light = &entities[ i ];
457 value = ValueForKey( light, "classname" );
458 if ( !strcmp( value, "light" ) ) {
459 /* get flare shader */
460 flareShader = ValueForKey( light, "_flareshader" );
461 value = ValueForKey( light, "_flare" );
462 if ( flareShader[ 0 ] != '\0' || value[ 0 ] != '\0' ) {
464 GetVectorForKey( light, "origin", origin );
465 GetVectorForKey( light, "_color", color );
466 lightStyle = IntForKey( light, "_style" );
467 if ( lightStyle == 0 ) {
468 lightStyle = IntForKey( light, "style" );
471 /* handle directional spotlights */
472 value = ValueForKey( light, "target" );
473 if ( value[ 0 ] != '\0' ) {
474 /* get target light */
475 target = FindTargetEntity( value );
476 if ( target != NULL ) {
477 GetVectorForKey( target, "origin", targetOrigin );
478 VectorSubtract( targetOrigin, origin, normal );
479 VectorNormalize( normal, normal );
483 //% VectorClear( normal );
484 VectorSet( normal, 0, 0, -1 );
488 color[0] = Image_LinearFloatFromsRGBFloat( color[0] );
489 color[1] = Image_LinearFloatFromsRGBFloat( color[1] );
490 color[2] = Image_LinearFloatFromsRGBFloat( color[2] );
493 /* create the flare surface (note shader defaults automatically) */
494 DrawSurfaceForFlare( mapEntityNum, origin, normal, color, flareShader, lightStyle );
499 /* add references to the final drawsurfs in the apropriate clusters */
500 FilterDrawsurfsIntoTree( e, tree );
502 /* match drawsurfaces back to original brushsides (sof2) */
506 EndModel( e, tree->headnode );
514 creates bsp + surfaces for other brush models
517 void ProcessSubModel( void ){
524 /* start a brush model */
526 e = &entities[ mapEntityNum ];
527 e->firstDrawSurf = numMapDrawSurfs;
530 ClearMetaTriangles();
532 /* check for patches with adjacent edges that need to lod together */
533 PatchMapDrawSurfs( e );
535 /* allocate a tree */
537 node->planenum = PLANENUM_LEAF;
539 tree->headnode = node;
541 /* add the sides to the tree */
542 ClipSidesIntoTree( e, tree );
544 /* ydnar: create drawsurfs for triangle models */
545 AddTriangleModels( e );
547 /* create drawsurfs for surface models */
548 AddEntitySurfaceModels( e );
550 /* generate bsp brushes from map brushes */
551 EmitBrushes( e->brushes, &e->firstBrush, &e->numBrushes );
553 /* just put all the brushes in headnode */
554 for ( b = e->brushes; b; b = b->next )
557 bc->next = node->brushlist;
558 node->brushlist = bc;
561 /* subdivide each drawsurf as required by shader tesselation */
562 if ( !nosubdivide ) {
563 SubdivideFaceSurfaces( e, tree );
566 /* add in any vertexes required to fix t-junctions */
571 /* ydnar: classify the surfaces and project lightmaps */
572 ClassifyEntitySurfaces( e );
574 /* ydnar: project decals */
575 MakeEntityDecals( e );
577 /* ydnar: meta surfaces */
578 MakeEntityMetaTriangles( e );
579 SmoothMetaTriangles();
581 MergeMetaTriangles();
583 /* add references to the final drawsurfs in the apropriate clusters */
584 FilterDrawsurfsIntoTree( e, tree );
586 /* match drawsurfaces back to original brushsides (sof2) */
598 process world + other models into the bsp
601 void ProcessModels( const char *portalFilePath, const char *lineFilePath ){
606 /* preserve -v setting */
607 oldVerbose = verbose;
609 /* start a new bsp */
612 /* create map fogs */
615 /* walk entity list */
616 for ( mapEntityNum = 0; mapEntityNum < numEntities; mapEntityNum++ )
619 entity = &entities[ mapEntityNum ];
620 if ( entity->brushes == NULL && entity->patches == NULL ) {
624 /* process the model */
625 Sys_FPrintf( SYS_VRB, "############### model %i ###############\n", numBSPModels );
626 if ( mapEntityNum == 0 ) {
627 ProcessWorldModel(portalFilePath, lineFilePath);
633 /* potentially turn off the deluge of text */
634 verbose = verboseEntities;
637 /* restore -v setting */
638 verbose = oldVerbose;
640 Sys_FPrintf( SYS_VRB, "%9i bspModels in total\n", numBSPModels );
645 /* vortex: emit meta stats */
653 this is probably broken unless teamed with a radiant version that preserves entity order
656 void OnlyEnts( const char *BSPFilePath ){
657 char save_cmdline[1024], save_version[1024], save_gridsize[1024];
661 Sys_Printf( "--- OnlyEnts ---\n" );
663 LoadBSPFile( BSPFilePath );
666 p = ValueForKey( &entities[0], "_q3map2_cmdline" );
667 strncpy( save_cmdline, p, sizeof( save_cmdline ) );
668 save_cmdline[sizeof( save_cmdline ) - 1] = 0;
669 p = ValueForKey( &entities[0], "_q3map2_version" );
670 strncpy( save_version, p, sizeof( save_version ) );
671 save_version[sizeof( save_version ) - 1] = 0;
672 p = ValueForKey( &entities[0], "gridsize" );
673 strncpy( save_gridsize, p, sizeof( save_gridsize ) );
674 save_gridsize[sizeof( save_gridsize ) - 1] = 0;
679 LoadMapFile( name, qfalse, qfalse );
683 if ( *save_cmdline ) {
684 SetKeyValue( &entities[0], "_q3map2_cmdline", save_cmdline );
686 if ( *save_version ) {
687 SetKeyValue( &entities[0], "_q3map2_version", save_version );
689 if ( *save_gridsize ) {
690 SetKeyValue( &entities[0], "gridsize", save_gridsize );
693 numBSPEntities = numEntities;
696 WriteBSPFile( BSPFilePath );
703 handles creation of a bsp from a map file
706 int BSPMain( int argc, char **argv ){
708 char path[ 1024 ], tempSource[ 1024 ];
709 qboolean onlyents = qfalse;
710 char BSPFilePath [ 1024 ];
711 char lineFilePath [ 1024 ];
712 char portalFilePath [ 1024 ];
713 char surfaceFilePath [ 1024 ];
716 portalFilePath[0] = 0;
717 surfaceFilePath[0] = 0;
721 Sys_Printf( "--- BSP ---\n" );
724 SetDrawSurfacesBuffer();
725 mapDrawSurfs = safe_malloc( sizeof( mapDrawSurface_t ) * MAX_MAP_DRAW_SURFS );
726 memset( mapDrawSurfs, 0, sizeof( mapDrawSurface_t ) * MAX_MAP_DRAW_SURFS );
729 tempSource[ 0 ] = '\0';
730 globalCelShader[0] = 0;
732 /* set standard game flags */
733 maxSurfaceVerts = game->maxSurfaceVerts;
734 maxSurfaceIndexes = game->maxSurfaceIndexes;
735 emitFlares = game->emitFlares;
736 texturesRGB = game->texturesRGB;
737 colorsRGB = game->colorsRGB;
739 /* process arguments */
740 for ( i = 1; i < ( argc - 1 ); i++ )
742 if ( !strcmp( argv[ i ], "-onlyents" ) ) {
743 Sys_Printf( "Running entity-only compile\n" );
746 else if ( !strcmp( argv[ i ], "-tempname" ) ) {
747 strcpy( tempSource, argv[ ++i ] );
749 else if ( !strcmp( argv[ i ], "-tmpout" ) ) {
750 strcpy( outbase, "/tmp" );
752 else if ( !strcmp( argv[ i ], "-nowater" ) ) {
753 Sys_Printf( "Disabling water\n" );
756 else if ( !strcmp( argv[ i ], "-keeplights" ) ) {
758 Sys_Printf( "Leaving light entities on map after compile\n" );
760 else if ( !strcmp( argv[ i ], "-nodetail" ) ) {
761 Sys_Printf( "Ignoring detail brushes\n" ) ;
764 else if ( !strcmp( argv[ i ], "-fulldetail" ) ) {
765 Sys_Printf( "Turning detail brushes into structural brushes\n" );
768 else if ( !strcmp( argv[ i ], "-nofog" ) ) {
769 Sys_Printf( "Fog volumes disabled\n" );
772 else if ( !strcmp( argv[ i ], "-nosubdivide" ) ) {
773 Sys_Printf( "Disabling brush face subdivision\n" );
776 else if ( !strcmp( argv[ i ], "-leaktest" ) ) {
777 Sys_Printf( "Leaktest enabled\n" );
780 else if ( !strcmp( argv[ i ], "-verboseentities" ) ) {
781 Sys_Printf( "Verbose entities enabled\n" );
782 verboseEntities = qtrue;
784 else if ( !strcmp( argv[ i ], "-nocurves" ) ) {
785 Sys_Printf( "Ignoring curved surfaces (patches)\n" );
786 noCurveBrushes = qtrue;
788 else if ( !strcmp( argv[ i ], "-notjunc" ) ) {
789 Sys_Printf( "T-junction fixing disabled\n" );
792 else if ( !strcmp( argv[ i ], "-fakemap" ) ) {
793 Sys_Printf( "Generating fakemap.map\n" );
796 else if ( !strcmp( argv[ i ], "-samplesize" ) ) {
797 sampleSize = atoi( argv[ i + 1 ] );
798 if ( sampleSize < 1 ) {
802 Sys_Printf( "Lightmap sample size set to %dx%d units\n", sampleSize, sampleSize );
804 else if ( !strcmp( argv[ i ], "-minsamplesize" ) ) {
805 minSampleSize = atoi( argv[ i + 1 ] );
806 if ( minSampleSize < 1 ) {
810 Sys_Printf( "Minimum lightmap sample size set to %dx%d units\n", minSampleSize, minSampleSize );
812 else if ( !strcmp( argv[ i ], "-custinfoparms" ) ) {
813 Sys_Printf( "Custom info parms enabled\n" );
814 useCustomInfoParms = qtrue;
818 else if ( !strcmp( argv[ i ], "-rename" ) ) {
819 Sys_Printf( "Appending _bsp suffix to misc_model shaders (SOF2)\n" );
820 renameModelShaders = qtrue;
824 else if ( !strcmp( argv[ i ], "-ne" ) ) {
825 normalEpsilon = atof( argv[ i + 1 ] );
827 Sys_Printf( "Normal epsilon set to %f\n", normalEpsilon );
829 else if ( !strcmp( argv[ i ], "-de" ) ) {
830 distanceEpsilon = atof( argv[ i + 1 ] );
832 Sys_Printf( "Distance epsilon set to %f\n", distanceEpsilon );
834 else if ( !strcmp( argv[ i ], "-mv" ) ) {
835 maxLMSurfaceVerts = atoi( argv[ i + 1 ] );
836 if ( maxLMSurfaceVerts < 3 ) {
837 maxLMSurfaceVerts = 3;
839 if ( maxLMSurfaceVerts > maxSurfaceVerts ) {
840 maxSurfaceVerts = maxLMSurfaceVerts;
843 Sys_Printf( "Maximum lightmapped surface vertex count set to %d\n", maxLMSurfaceVerts );
845 else if ( !strcmp( argv[ i ], "-mi" ) ) {
846 maxSurfaceIndexes = atoi( argv[ i + 1 ] );
847 if ( maxSurfaceIndexes < 3 ) {
848 maxSurfaceIndexes = 3;
851 Sys_Printf( "Maximum per-surface index count set to %d\n", maxSurfaceIndexes );
853 else if ( !strcmp( argv[ i ], "-np" ) ) {
854 npDegrees = atof( argv[ i + 1 ] );
855 if ( npDegrees < 0.0f ) {
858 else if ( npDegrees > 0.0f ) {
859 Sys_Printf( "Forcing nonplanar surfaces with a breaking angle of %f degrees\n", npDegrees );
863 else if ( !strcmp( argv[ i ], "-snap" ) ) {
864 bevelSnap = atoi( argv[ i + 1 ] );
865 if ( bevelSnap < 0 ) {
869 if ( bevelSnap > 0 ) {
870 Sys_Printf( "Snapping brush bevel planes to %d units\n", bevelSnap );
873 else if ( !strcmp( argv[ i ], "-texrange" ) ) {
874 texRange = atoi( argv[ i + 1 ] );
875 if ( texRange < 0 ) {
879 Sys_Printf( "Limiting per-surface texture range to %d texels\n", texRange );
881 else if ( !strcmp( argv[ i ], "-nohint" ) ) {
882 Sys_Printf( "Hint brushes disabled\n" );
885 else if ( !strcmp( argv[ i ], "-flat" ) ) {
886 Sys_Printf( "Flatshading enabled\n" );
889 else if ( !strcmp( argv[ i ], "-celshader" ) ) {
892 sprintf( globalCelShader, "textures/%s", argv[ i ] );
895 *globalCelShader = 0;
897 Sys_Printf( "Global cel shader set to \"%s\"\n", globalCelShader );
899 else if ( !strcmp( argv[ i ], "-meta" ) ) {
900 Sys_Printf( "Creating meta surfaces from brush faces\n" );
903 else if ( !strcmp( argv[ i ], "-metaadequatescore" ) ) {
904 metaAdequateScore = atoi( argv[ i + 1 ] );
905 if ( metaAdequateScore < 0 ) {
906 metaAdequateScore = -1;
909 if ( metaAdequateScore >= 0 ) {
910 Sys_Printf( "Setting ADEQUATE meta score to %d (see surface_meta.c)\n", metaAdequateScore );
913 else if ( !strcmp( argv[ i ], "-metagoodscore" ) ) {
914 metaGoodScore = atoi( argv[ i + 1 ] );
915 if ( metaGoodScore < 0 ) {
919 if ( metaGoodScore >= 0 ) {
920 Sys_Printf( "Setting GOOD meta score to %d (see surface_meta.c)\n", metaGoodScore );
923 else if ( !strcmp( argv[ i ], "-metamaxbboxdistance" ) ) {
924 metaMaxBBoxDistance = atof( argv[ i + 1 ] );
925 if ( metaMaxBBoxDistance < 0 ) {
926 metaMaxBBoxDistance = -1;
929 if ( metaMaxBBoxDistance >= 0 ) {
930 Sys_Printf( "Setting meta maximum bounding box distance to %f\n", metaMaxBBoxDistance );
933 else if ( !strcmp( argv[ i ], "-patchmeta" ) ) {
934 Sys_Printf( "Creating meta surfaces from patches\n" );
937 else if ( !strcmp( argv[ i ], "-flares" ) ) {
938 Sys_Printf( "Flare surfaces enabled\n" );
941 else if ( !strcmp( argv[ i ], "-noflares" ) ) {
942 Sys_Printf( "Flare surfaces disabled\n" );
945 else if ( !strcmp( argv[ i ], "-skyfix" ) ) {
946 Sys_Printf( "GL_CLAMP sky fix/hack/workaround enabled\n" );
949 else if ( !strcmp( argv[ i ], "-debugsurfaces" ) ) {
950 Sys_Printf( "emitting debug surfaces\n" );
951 debugSurfaces = qtrue;
953 else if ( !strcmp( argv[ i ], "-debuginset" ) ) {
954 Sys_Printf( "Debug surface triangle insetting enabled\n" );
957 else if ( !strcmp( argv[ i ], "-debugportals" ) ) {
958 Sys_Printf( "Debug portal surfaces enabled\n" );
959 debugPortals = qtrue;
961 else if ( !strcmp( argv[ i ], "-debugclip" ) ) {
962 Sys_Printf( "Debug model clip enabled\n" );
965 else if ( !strcmp( argv[ i ], "-clipdepth" ) ) {
966 clipDepthGlobal = atof( argv[ i + 1 ] );
968 Sys_Printf( "Model autoclip thickness set to %.3f\n", clipDepthGlobal );
970 else if ( !strcmp( argv[ i ], "-sRGBtex" ) ) {
972 Sys_Printf( "Textures are in sRGB\n" );
974 else if ( !strcmp( argv[ i ], "-nosRGBtex" ) ) {
975 texturesRGB = qfalse;
976 Sys_Printf( "Textures are linear\n" );
978 else if ( !strcmp( argv[ i ], "-sRGBcolor" ) ) {
980 Sys_Printf( "Colors are in sRGB\n" );
982 else if ( !strcmp( argv[ i ], "-nosRGBcolor" ) ) {
984 Sys_Printf( "Colors are linear\n" );
986 else if ( !strcmp( argv[ i ], "-nosRGB" ) ) {
987 texturesRGB = qfalse;
988 Sys_Printf( "Textures are linear\n" );
990 Sys_Printf( "Colors are linear\n" );
992 else if ( !strcmp( argv[ i ], "-altsplit" ) ) {
993 Sys_Printf( "Alternate BSP splitting (by 27) enabled\n" );
994 bspAlternateSplitWeights = qtrue;
996 else if ( !strcmp( argv[ i ], "-deep" ) ) {
997 Sys_Printf( "Deep BSP tree generation enabled\n" );
1000 else if ( !strcmp( argv[ i ], "-maxarea" ) ) {
1001 Sys_Printf( "Max Area face surface generation enabled\n" );
1002 maxAreaFaceSurface = qtrue;
1004 else if ( !strcmp( argv[ i ], "-bspfile" ) )
1006 strcpy( BSPFilePath, argv[i + 1] );
1008 Sys_Printf( "Use %s as bsp file\n", BSPFilePath );
1010 else if ( !strcmp( argv[ i ], "-linfile" ) )
1012 strcpy( lineFilePath, argv[i + 1] );
1014 Sys_Printf( "Use %s as line file\n", lineFilePath );
1016 else if ( !strcmp( argv[ i ], "-prtfile" ) )
1018 strcpy( portalFilePath, argv[i + 1] );
1020 Sys_Printf( "Use %s as portal file\n", portalFilePath );
1022 else if ( !strcmp( argv[ i ], "-srffile" ) )
1024 strcpy( surfaceFilePath, argv[i + 1] );
1026 Sys_Printf( "Use %s as surface file\n", surfaceFilePath );
1028 else if ( !strcmp( argv[ i ], "-bsp" ) ) {
1029 Sys_Printf( "-bsp argument unnecessary\n" );
1031 else if ( !strcmp( argv[ i ], "-noob" ) ) {
1032 Sys_Printf( "No oBs!\n" );
1037 Sys_Printf( "WARNING: Unknown option \"%s\"\n", argv[ i ] );
1041 /* fixme: print more useful usage here */
1042 if ( i != ( argc - 1 ) ) {
1043 Error( "usage: q3map [options] mapfile" );
1046 /* copy source name */
1047 strcpy( source, ExpandArg( argv[ i ] ) );
1048 StripExtension( source );
1050 /* ydnar: set default sample size */
1051 SetDefaultSampleSize( sampleSize );
1053 if (!BSPFilePath[0]) {
1054 sprintf( BSPFilePath, "%s.bsp", source );
1056 if (!lineFilePath[0]) {
1057 sprintf( lineFilePath, "%s.lin", source );
1059 if (!portalFilePath[0]) {
1060 sprintf( portalFilePath, "%s.prt", source );
1062 if (!surfaceFilePath[0]) {
1063 sprintf( surfaceFilePath, "%s.srf", source );
1066 /* delete portal, line and surface files */
1067 remove( portalFilePath );
1068 remove( lineFilePath );
1069 //% remove( surfaceFilePath ) /* ydnar */
1071 /* expand mapname */
1072 strcpy( name, ExpandArg( argv[ i ] ) );
1073 if ( strcmp( name + strlen( name ) - 4, ".reg" ) ) {
1074 /* if we are doing a full map, delete the last saved region map */
1075 sprintf( path, "%s.reg", source );
1077 DefaultExtension( name, ".map" ); /* might be .reg */
1080 /* if onlyents, just grab the entites and resave */
1082 OnlyEnts( BSPFilePath );
1089 /* load original file from temp spot in case it was renamed by the editor on the way in */
1090 if ( strlen( tempSource ) > 0 ) {
1091 LoadMapFile( tempSource, qfalse, qfalse );
1094 LoadMapFile( name, qfalse, qfalse );
1097 /* div0: inject command line parameters */
1098 InjectCommandLine( argv, 1, argc - 1 );
1100 /* ydnar: decal setup */
1103 /* ydnar: cloned brush model entities */
1104 SetCloneModelNumbers();
1106 /* process world and submodels */
1107 ProcessModels( portalFilePath, lineFilePath );
1109 /* set light styles from targetted light entities */
1112 /* process in game advertisements */
1113 ProcessAdvertisements();
1115 /* finish and write bsp */
1116 EndBSPFile( qtrue, BSPFilePath, surfaceFilePath );
1118 /* remove temp map source file if appropriate */
1119 if ( strlen( tempSource ) > 0 ) {
1120 remove( tempSource );
1123 /* return to sender */