]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake3/q3map2/main.c
new args -meta and -patchmeta to -convert with .map file argument
[xonotic/netradiant.git] / tools / quake3 / q3map2 / main.c
index 97c2759d14098ef48d673e43f5364422aca5aa28..2deb142989b4c6c76becbe0fce027f6be8449ed2 100644 (file)
@@ -1199,12 +1199,12 @@ int ScaleBSPMain( int argc, char **argv )
                return 0;
        }
        
-       texscale = false;
+       texscale = qfalse;
        for(i = 1; i < argc-2; ++i)
        {
                if(!strcmp(argv[i], "-tex"))
                {
-                       texscale = true;
+                       texscale = qtrue;
                }
                else if(!strcmp(argv[i], "-spawn_ref"))
                {
@@ -1430,6 +1430,101 @@ int ScaleBSPMain( int argc, char **argv )
 }
 
 
+/*
+PseudoCompileBSP()
+a stripped down ProcessModels
+*/
+void PseudoCompileBSP(qboolean need_tree)
+{
+       int models;
+       char modelValue[10];
+       entity_t *entity;
+       face_t *faces;
+       tree_t *tree;
+       node_t *node;
+       brush_t *brush;
+       side_t *side;
+       int i;
+
+        SetDrawSurfacesBuffer();
+       mapDrawSurfs = safe_malloc( sizeof( mapDrawSurface_t ) * MAX_MAP_DRAW_SURFS );
+       memset( mapDrawSurfs, 0, sizeof( mapDrawSurface_t ) * MAX_MAP_DRAW_SURFS );
+       numMapDrawSurfs = 0;
+
+       BeginBSPFile();
+       models = 1;
+       for( mapEntityNum = 0; mapEntityNum < numEntities; mapEntityNum++ )
+       {
+               /* get entity */
+               entity = &entities[ mapEntityNum ];
+               if( entity->brushes == NULL && entity->patches == NULL )
+                       continue;
+
+               if(mapEntityNum != 0)
+               {
+                       sprintf( modelValue, "*%d", models++);
+                       SetKeyValue(entity, "model", modelValue);
+               }
+               
+               /* process the model */
+               Sys_FPrintf( SYS_VRB, "############### model %i ###############\n", numBSPModels );
+               BeginModel();
+
+               entity->firstDrawSurf = numMapDrawSurfs;
+
+               ClearMetaTriangles();
+               PatchMapDrawSurfs(entity);
+
+               if(mapEntityNum == 0 && need_tree)
+               {
+                       faces = MakeStructuralBSPFaceList(entities[0].brushes);
+                       tree = FaceBSP(faces);
+                       node = tree->headnode;
+               }
+               else
+               {
+                       node = AllocNode();
+                       node->planenum = PLANENUM_LEAF;
+                       tree = AllocTree();
+                       tree->headnode = node;
+               }
+
+               /* a minimized ClipSidesIntoTree */
+               for( brush = entity->brushes; brush; brush = brush->next )
+               {
+                       /* walk the brush sides */
+                       for( i = 0; i < brush->numsides; i++ )
+                       {
+                               /* get side */
+                               side = &brush->sides[ i ];
+                               if( side->winding == NULL )
+                                       continue;
+                               /* shader? */
+                               if( side->shaderInfo == NULL )
+                                       continue;
+                               /* save this winding as a visible surface */
+                               DrawSurfaceForSide(entity, brush, side, side->winding);
+                       }
+               }
+
+               if(meta)
+               {
+                       ClassifyEntitySurfaces(entity);
+                       MakeEntityDecals(entity);
+                       MakeEntityMetaTriangles(entity);
+                       SmoothMetaTriangles();
+                       MergeMetaTriangles();
+               }
+               FilterDrawsurfsIntoTree(entity, tree);
+
+               FilterStructuralBrushesIntoTree(entity, tree);
+               FilterDetailBrushesIntoTree(entity, tree);
+
+               EmitBrushes(entity->brushes, &entity->firstBrush, &entity->numBrushes );
+               EndModel(entity, node);
+       }
+       EndBSPFile(qfalse);
+}
 
 /*
 ConvertBSPMain()
@@ -1441,11 +1536,15 @@ int ConvertBSPMain( int argc, char **argv )
        int             i;
        int             (*convertFunc)( char * );
        game_t  *convertGame;
+       char            ext[1024];
+       qboolean        map_allowed, force_bsp;
        
        
        /* set default */
        convertFunc = ConvertBSPToASE;
        convertGame = NULL;
+       map_allowed = qtrue;
+       force_bsp = qfalse;
        
        /* arg checking */
        if( argc < 1 )
@@ -1462,12 +1561,24 @@ int ConvertBSPMain( int argc, char **argv )
                {
                        i++;
                        if( !Q_stricmp( argv[ i ], "ase" ) )
+                       {
                                convertFunc = ConvertBSPToASE;
+                               map_allowed = qfalse;
+                       }
+                       else if( !Q_stricmp( argv[ i ], "map_bp" ) )
+                       {
+                               convertFunc = ConvertBSPToMap_BP;
+                               map_allowed = qtrue;
+                       }
                        else if( !Q_stricmp( argv[ i ], "map" ) )
+                       {
                                convertFunc = ConvertBSPToMap;
+                               map_allowed = qtrue;
+                       }
                        else
                        {
                                convertGame = GetGame( argv[ i ] );
+                               map_allowed = qfalse;
                                if( convertGame == NULL )
                                        Sys_Printf( "Unknown conversion format \"%s\". Defaulting to ASE.\n", argv[ i ] );
                        }
@@ -1486,24 +1597,40 @@ int ConvertBSPMain( int argc, char **argv )
                }
                else if( !strcmp( argv[ i ],  "-shadersasbitmap" ) )
                        shadersAsBitmap = qtrue;
+               else if( !strcmp( argv[ i ],  "-forcereadbsp" ) )
+                       force_bsp = qtrue;
+               else if( !strcmp( argv[ i ],  "-meta" ) )
+                       meta = qtrue;
+               else if( !strcmp( argv[ i ],  "-patchmeta" ) )
+               {
+                       meta = qtrue;
+                       patchMeta = qtrue;
+               }
        }
-       
-       /* clean up map name */
-       strcpy( source, ExpandArg( argv[ i ] ) );
-       StripExtension( source );
-       DefaultExtension( source, ".bsp" );
-       
+
        LoadShaderInfo();
        
-       Sys_Printf( "Loading %s\n", source );
-       
-       /* ydnar: load surface file */
-       //%     LoadSurfaceExtraFile( source );
-       
-       LoadBSPFile( source );
-       
-       /* parse bsp entities */
-       ParseEntities();
+       /* clean up map name */
+       strcpy(source, ExpandArg(argv[i]));
+       ExtractFileExtension(source, ext);
+       if(!Q_stricmp(ext, "map") && !force_bsp)
+       {
+               if(!map_allowed)
+                       Sys_Printf("WARNING: the requested conversion should not be done from .map files. Compile a .bsp first.\n");
+               StripExtension(source);
+               DefaultExtension(source, ".map");
+               Sys_Printf("Loading %s\n", source);
+               LoadMapFile(source, qfalse, convertGame == NULL);
+               PseudoCompileBSP(convertGame != NULL);
+       }
+       else
+       {
+               StripExtension(source);
+               DefaultExtension(source, ".bsp");
+               Sys_Printf("Loading %s\n", source);
+               LoadBSPFile(source);
+               ParseEntities();
+       }
        
        /* bsp format convert? */
        if( convertGame != NULL )