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 ){
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 );
133 main argument processing function for bsp conversion
136 int ConvertBSPMain( int argc, char **argv ){
138 int ( *convertFunc )( char * );
141 qboolean map_allowed, force_bsp, force_map;
145 convertFunc = ConvertBSPToASE;
147 map_allowed = qfalse;
153 Sys_Printf( "Usage: q3map -convert [-format <ase|obj|map_bp|map>] [-shadersasbitmap|-lightmapsastexcoord|-deluxemapsastexcoord] [-readbsp|-readmap [-meta|-patchmeta]] [-v] <mapname>\n" );
157 /* process arguments */
158 for ( i = 1; i < ( argc - 1 ); i++ )
160 /* -format map|ase|... */
161 if ( !strcmp( argv[ i ], "-format" ) ) {
163 if ( !Q_stricmp( argv[ i ], "ase" ) ) {
164 convertFunc = ConvertBSPToASE;
165 map_allowed = qfalse;
167 else if ( !Q_stricmp( argv[ i ], "obj" ) ) {
168 convertFunc = ConvertBSPToOBJ;
169 map_allowed = qfalse;
171 else if ( !Q_stricmp( argv[ i ], "map_bp" ) ) {
172 convertFunc = ConvertBSPToMap_BP;
175 else if ( !Q_stricmp( argv[ i ], "map" ) ) {
176 convertFunc = ConvertBSPToMap;
181 convertGame = GetGame( argv[ i ] );
182 map_allowed = qfalse;
183 if ( convertGame == NULL ) {
184 Sys_Printf( "Unknown conversion format \"%s\". Defaulting to ASE.\n", argv[ i ] );
188 else if ( !strcmp( argv[ i ], "-ne" ) ) {
189 normalEpsilon = atof( argv[ i + 1 ] );
191 Sys_Printf( "Normal epsilon set to %f\n", normalEpsilon );
193 else if ( !strcmp( argv[ i ], "-de" ) ) {
194 distanceEpsilon = atof( argv[ i + 1 ] );
196 Sys_Printf( "Distance epsilon set to %f\n", distanceEpsilon );
198 else if ( !strcmp( argv[ i ], "-shaderasbitmap" ) || !strcmp( argv[ i ], "-shadersasbitmap" ) ) {
199 shadersAsBitmap = qtrue;
201 else if ( !strcmp( argv[ i ], "-lightmapastexcoord" ) || !strcmp( argv[ i ], "-lightmapsastexcoord" ) ) {
202 lightmapsAsTexcoord = qtrue;
204 else if ( !strcmp( argv[ i ], "-deluxemapastexcoord" ) || !strcmp( argv[ i ], "-deluxemapsastexcoord" ) ) {
205 lightmapsAsTexcoord = qtrue;
208 else if ( !strcmp( argv[ i ], "-readbsp" ) ) {
211 else if ( !strcmp( argv[ i ], "-readmap" ) ) {
214 else if ( !strcmp( argv[ i ], "-meta" ) ) {
217 else if ( !strcmp( argv[ i ], "-patchmeta" ) ) {
225 /* clean up map name */
226 strcpy( source, ExpandArg( argv[i] ) );
227 ExtractFileExtension( source, ext );
229 if ( !map_allowed && !force_map ) {
233 if ( force_map || ( !force_bsp && !Q_stricmp( ext, "map" ) && map_allowed ) ) {
234 if ( !map_allowed ) {
235 Sys_Printf( "WARNING: the requested conversion should not be done from .map files. Compile a .bsp first.\n" );
237 StripExtension( source );
238 DefaultExtension( source, ".map" );
239 Sys_Printf( "Loading %s\n", source );
240 LoadMapFile( source, qfalse, convertGame == NULL );
241 PseudoCompileBSP( convertGame != NULL );
245 StripExtension( source );
246 DefaultExtension( source, ".bsp" );
247 Sys_Printf( "Loading %s\n", source );
248 LoadBSPFile( source );
252 /* bsp format convert? */
253 if ( convertGame != NULL ) {
254 /* set global game */
258 StripExtension( source );
259 DefaultExtension( source, "_c.bsp" );
260 Sys_Printf( "Writing %s\n", source );
261 WriteBSPFile( source );
263 /* return to sender */
268 return convertFunc( source );