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 ------------------------------------------------------------------------------- */
38 a stripped down ProcessModels
40 void PseudoCompileBSP( qboolean need_tree, const char *BSPFilePath, const char *surfaceFilePath ){
51 SetDrawSurfacesBuffer();
52 mapDrawSurfs = safe_malloc( sizeof( mapDrawSurface_t ) * MAX_MAP_DRAW_SURFS );
53 memset( mapDrawSurfs, 0, sizeof( mapDrawSurface_t ) * MAX_MAP_DRAW_SURFS );
58 for ( mapEntityNum = 0; mapEntityNum < numEntities; mapEntityNum++ )
61 entity = &entities[ mapEntityNum ];
62 if ( entity->brushes == NULL && entity->patches == NULL ) {
66 if ( mapEntityNum != 0 ) {
67 sprintf( modelValue, "*%d", models++ );
68 SetKeyValue( entity, "model", modelValue );
71 /* process the model */
72 Sys_FPrintf( SYS_VRB, "############### model %i ###############\n", numBSPModels );
75 entity->firstDrawSurf = numMapDrawSurfs;
78 PatchMapDrawSurfs( entity );
80 if ( mapEntityNum == 0 && need_tree ) {
81 faces = MakeStructuralBSPFaceList( entities[0].brushes );
82 tree = FaceBSP( faces );
83 node = tree->headnode;
88 node->planenum = PLANENUM_LEAF;
90 tree->headnode = node;
93 /* a minimized ClipSidesIntoTree */
94 for ( brush = entity->brushes; brush; brush = brush->next )
96 /* walk the brush sides */
97 for ( i = 0; i < brush->numsides; i++ )
100 side = &brush->sides[ i ];
101 if ( side->winding == NULL ) {
105 if ( side->shaderInfo == NULL ) {
108 /* save this winding as a visible surface */
109 DrawSurfaceForSide( entity, brush, side, side->winding );
114 ClassifyEntitySurfaces( entity );
115 MakeEntityDecals( entity );
116 MakeEntityMetaTriangles( entity );
117 SmoothMetaTriangles();
118 MergeMetaTriangles();
120 FilterDrawsurfsIntoTree( entity, tree );
122 FilterStructuralBrushesIntoTree( entity, tree );
123 FilterDetailBrushesIntoTree( entity, tree );
125 EmitBrushes( entity->brushes, &entity->firstBrush, &entity->numBrushes );
126 EndModel( entity, node );
128 EndBSPFile( qfalse, BSPFilePath, surfaceFilePath );
133 main argument processing function for bsp conversion
136 int ConvertBSPMain( int argc, char **argv ){
138 int ( *convertFunc )( char * );
141 char BSPFilePath [ 1024 ];
142 char surfaceFilePath [ 1024 ];
143 qboolean map_allowed, force_bsp, force_map;
147 convertFunc = ConvertBSPToASE;
149 map_allowed = qfalse;
155 Sys_Printf( "Usage: q3map -convert [-format <ase|obj|map_bp|map>] [-shadersasbitmap|-lightmapsastexcoord|-deluxemapsastexcoord] [-readbsp|-readmap [-meta|-patchmeta]] [-v] <mapname>\n" );
159 /* process arguments */
160 for ( i = 1; i < ( argc - 1 ); i++ )
162 /* -format map|ase|... */
163 if ( !strcmp( argv[ i ], "-format" ) ) {
165 if ( !Q_stricmp( argv[ i ], "ase" ) ) {
166 convertFunc = ConvertBSPToASE;
167 map_allowed = qfalse;
169 else if ( !Q_stricmp( argv[ i ], "obj" ) ) {
170 convertFunc = ConvertBSPToOBJ;
171 map_allowed = qfalse;
173 else if ( !Q_stricmp( argv[ i ], "map_bp" ) ) {
174 convertFunc = ConvertBSPToMap_BP;
177 else if ( !Q_stricmp( argv[ i ], "map" ) ) {
178 convertFunc = ConvertBSPToMap;
183 convertGame = GetGame( argv[ i ] );
184 map_allowed = qfalse;
185 if ( convertGame == NULL ) {
186 Sys_Printf( "Unknown conversion format \"%s\". Defaulting to ASE.\n", argv[ i ] );
190 else if ( !strcmp( argv[ i ], "-ne" ) ) {
191 normalEpsilon = atof( argv[ i + 1 ] );
193 Sys_Printf( "Normal epsilon set to %f\n", normalEpsilon );
195 else if ( !strcmp( argv[ i ], "-de" ) ) {
196 distanceEpsilon = atof( argv[ i + 1 ] );
198 Sys_Printf( "Distance epsilon set to %f\n", distanceEpsilon );
200 else if ( !strcmp( argv[ i ], "-shaderasbitmap" ) || !strcmp( argv[ i ], "-shadersasbitmap" ) ) {
201 shadersAsBitmap = qtrue;
203 else if ( !strcmp( argv[ i ], "-lightmapastexcoord" ) || !strcmp( argv[ i ], "-lightmapsastexcoord" ) ) {
204 lightmapsAsTexcoord = qtrue;
206 else if ( !strcmp( argv[ i ], "-deluxemapastexcoord" ) || !strcmp( argv[ i ], "-deluxemapsastexcoord" ) ) {
207 lightmapsAsTexcoord = qtrue;
210 else if ( !strcmp( argv[ i ], "-readbsp" ) ) {
213 else if ( !strcmp( argv[ i ], "-readmap" ) ) {
216 else if ( !strcmp( argv[ i ], "-meta" ) ) {
219 else if ( !strcmp( argv[ i ], "-patchmeta" ) ) {
227 /* clean up map name */
228 strcpy( source, ExpandArg( argv[i] ) );
229 ExtractFileExtension( source, ext );
231 if ( !map_allowed && !force_map ) {
235 if ( force_map || ( !force_bsp && !Q_stricmp( ext, "map" ) && map_allowed ) ) {
236 if ( !map_allowed ) {
237 Sys_FPrintf( SYS_WRN, "WARNING: the requested conversion should not be done from .map files. Compile a .bsp first.\n" );
239 StripExtension( source );
240 DefaultExtension( source, ".map" );
241 Sys_Printf( "Loading %s\n", source );
242 LoadMapFile( source, qfalse, convertGame == NULL );
243 sprintf( BSPFilePath, "%s.bsp", source );
244 sprintf( surfaceFilePath, "%s.srf", source );
245 PseudoCompileBSP( convertGame != NULL, BSPFilePath, surfaceFilePath );
249 StripExtension( source );
250 DefaultExtension( source, ".bsp" );
251 Sys_Printf( "Loading %s\n", source );
252 LoadBSPFile( source );
256 /* bsp format convert? */
257 if ( convertGame != NULL ) {
258 /* set global game */
262 StripExtension( source );
263 DefaultExtension( source, "_c.bsp" );
264 Sys_Printf( "Writing %s\n", source );
265 WriteBSPFile( source );
267 /* return to sender */
272 return convertFunc( source );