]> git.rm.cloudns.org Git - xonotic/netradiant.git/commitdiff
option -lightmapsastexcoord to extract lightmap UV
authorRudolf Polzer <divverent@alientrap.org>
Thu, 23 Dec 2010 09:02:13 +0000 (10:02 +0100)
committerRudolf Polzer <divverent@alientrap.org>
Thu, 23 Dec 2010 09:10:54 +0000 (10:10 +0100)
tools/quake3/q3map2/convert_ase.c
tools/quake3/q3map2/convert_obj.c
tools/quake3/q3map2/main.c
tools/quake3/q3map2/q3map2.h

index 59cc3d9cc41aa7291ab07a6e814160d9bd0b938f..ca070630005bc433f4e654a0dd0c1ca3fd62b20f 100644 (file)
@@ -162,7 +162,7 @@ static void ConvertSurface( FILE *f, bspModel_t *model, int modelNum, bspDrawSur
        fprintf( f, "\t*PROP_MOTIONBLUR\t0\r\n" );
        fprintf( f, "\t*PROP_CASTSHADOW\t1\r\n" );
        fprintf( f, "\t*PROP_RECVSHADOW\t1\r\n" );
-       fprintf( f, "\t*MATERIAL_REF\t%d\r\n", ds->shaderNum );
+       fprintf( f, "\t*MATERIAL_REF\t%d\r\n", lightmapsAsTexcoord ? ds->lightmapNum : ds->shaderNum );
        fprintf( f, "}\r\n" );
 }
 
@@ -280,6 +280,31 @@ static void ConvertShader( FILE *f, bspShader_t *shader, int shaderNum )
        
        fprintf( f, "\t}\r\n" );
 }
+static void ConvertLightmap( FILE *f, const char *base, int lightmapNum )
+{
+       shaderInfo_t    *si;
+       char                    *c, filename[ 1024 ];
+       
+       /* print shader info */
+       fprintf( f, "\t*MATERIAL\t%d\t{\r\n", lightmapNum );
+       fprintf( f, "\t\t*MATERIAL_NAME\t\"lm_%04d\"\r\n", lightmapNum );
+       fprintf( f, "\t\t*MATERIAL_CLASS\t\"Standard\"\r\n" );
+       fprintf( f, "\t\t*MATERIAL_DIFFUSE\t1\t1\t1\r\n");
+       fprintf( f, "\t\t*MATERIAL_SHADING Phong\r\n" );
+       
+       /* print map info */
+       fprintf( f, "\t\t*MAP_DIFFUSE\t{\r\n" );
+       fprintf( f, "\t\t\t*MAP_NAME\t\"lm_%04d\"\r\n", lightmapNum );
+       fprintf( f, "\t\t\t*MAP_CLASS\t\"Bitmap\"\r\n");
+       fprintf( f, "\t\t\t*MAP_SUBNO\t1\r\n" );
+       fprintf( f, "\t\t\t*MAP_AMOUNT\t1.0\r\n" );
+       fprintf( f, "\t\t\t*MAP_TYPE\tScreen\r\n" );
+       fprintf( f, "\t\t\t*BITMAP\t\"%s\\lm_%04d.tga\"\r\n", base, lightmapNum );
+       fprintf( f, "\t\t\t*BITMAP_FILTER\tPyramidal\r\n" );
+       fprintf( f, "\t\t}\r\n" );
+       
+       fprintf( f, "\t}\r\n" );
+}
 
 
 
@@ -332,11 +357,34 @@ int ConvertBSPToASE( char *bspName )
        
        /* print materials */
        fprintf( f, "*MATERIAL_LIST\t{\r\n" );
-       fprintf( f, "\t*MATERIAL_COUNT\t%d\r\n", numBSPShaders );
-       for( i = 0; i < numBSPShaders; i++ )
+       if(lightmapsAsTexcoord)
        {
-               shader = &bspShaders[ i ];
-               ConvertShader( f, shader, i );
+               int lightmapCount;
+               for( lightmapCount = 0; lightmapCount < numBSPLightmaps; lightmapCount++ )
+                       ;
+               for( ; ; lightmapCount++ )
+               {
+                       char buf[1024];
+                       FILE *tmp;
+                       snprintf(buf, sizeof(buf), "%s/lm_%04d.tga", base, lightmapCount);
+                       buf[sizeof(buf) - 1] = 0;
+                       tmp = fopen(buf, "rb");
+                       if(!tmp)
+                               break;
+                       fclose(tmp);
+               }
+               fprintf( f, "\t*MATERIAL_COUNT\t%d\r\n", lightmapCount );
+               for( i = 0; i < lightmapCount; i++ )
+                       ConvertLightmap( f, base, i );
+       }
+       else
+       {
+               fprintf( f, "\t*MATERIAL_COUNT\t%d\r\n", numBSPShaders );
+               for( i = 0; i < numBSPShaders; i++ )
+               {
+                       shader = &bspShaders[ i ];
+                       ConvertShader( f, shader, i );
+               }
        }
        fprintf( f, "}\r\n" );
        
index e370f7d57402b358b84447ee71676b8fc9bb34bc..dd11537effd30fc960cf8a9691cf6c8ad157b479 100644 (file)
@@ -49,9 +49,6 @@ static void ConvertSurfaceToOBJ( FILE *f, bspModel_t *model, int modelNum, bspDr
 {
        int                             i, v, face, a, b, c;
        bspDrawVert_t   *dv;
-       vec3_t                  normal;
-       char                    name[ 1024 ];
-       int startVert = objVertexCount;
        
        /* ignore patches for now */
        if( ds->surfaceType != MST_PLANAR && ds->surfaceType != MST_TRIANGLE_SOUP )
@@ -69,10 +66,21 @@ static void ConvertSurfaceToOBJ( FILE *f, bspModel_t *model, int modelNum, bspDr
        }
 
        /* export shader */
-       if(objLastShaderNum != ds->shaderNum)
+       if(lightmapsAsTexcoord)
        {
-               fprintf(f, "usemtl %s\r\n", bspShaders[ds->shaderNum].shader);
-               objLastShaderNum = ds->shaderNum;
+               if(objLastShaderNum != ds->lightmapNum[0])
+               {
+                       fprintf(f, "usemtl lm_%04d\r\n", ds->lightmapNum[0]);
+                       objLastShaderNum = ds->lightmapNum[0];
+               }
+       }
+       else
+       {
+               if(objLastShaderNum != ds->shaderNum)
+               {
+                       fprintf(f, "usemtl %s\r\n", bspShaders[ds->shaderNum].shader);
+                       objLastShaderNum = ds->shaderNum;
+               }
        }
        
        /* export vertex */
@@ -83,8 +91,10 @@ static void ConvertSurfaceToOBJ( FILE *f, bspModel_t *model, int modelNum, bspDr
                fprintf(f, "# vertex %d\r\n", i + objVertexCount + 1);
                fprintf(f, "v %f %f %f\r\n", dv->xyz[ 0 ], dv->xyz[ 1 ], dv->xyz[ 2 ]);
                fprintf(f, "vn %f %f %f\r\n", dv->normal[ 0 ], dv->normal[ 1 ], dv->normal[ 2 ]);
-               fprintf(f, "vt %f %f\r\n", dv->st[ 0 ], dv->st[ 1 ]);
-               fprintf(f, "# vt %f %f\r\n", dv->lightmap[0][0], dv->lightmap[0][1]);
+               if(lightmapsAsTexcoord)
+                       fprintf(f, "vt %f %f\r\n", dv->lightmap[0][0], 1.0 - dv->lightmap[0][1]);
+               else
+                       fprintf(f, "vt %f %f\r\n", dv->st[ 0 ], 1.0 - dv->st[ 1 ]);
        }
 
        /* export faces */
@@ -162,7 +172,14 @@ static void ConvertShaderToMTL( FILE *f, bspShader_t *shader, int shaderNum )
        if(shadersAsBitmap)
                fprintf( f, "map_Kd %s\r\n", shader->shader );
        else
-               fprintf( f, "map_Kd %s\r\n", filename );
+               fprintf( f, "map_Kd ..\\%s\r\n", filename );
+}
+
+static void ConvertLightmapToMTL( FILE *f, const char *base, int lightmapNum )
+{
+       /* print shader info */
+       fprintf( f, "newmtl lm_%04d\r\n", lightmapNum );
+       fprintf( f, "map_Kd %s\\lm_%04d.tga\r\n", base, lightmapNum );
 }
 
 
@@ -181,7 +198,7 @@ int ConvertBSPToOBJ( char *bspName )
        entity_t                *e;
        vec3_t                  origin;
        const char              *key;
-       char                    name[ 1024 ], base[ 1024 ];
+       char                    name[ 1024 ], base[ 1024 ], mtlname[ 1024 ];
        
        
        /* note it */
@@ -214,10 +231,32 @@ int ConvertBSPToOBJ( char *bspName )
        fprintf( f, "mtllib %s\r\n", mtlname );
 
        fprintf( fmtl, "# Generated by Q3Map2 (ydnar) -convert -format obj\r\n" );
-       for( i = 0; i < numBSPShaders; i++ )
+       if(lightmapsAsTexcoord)
        {
-               shader = &bspShaders[ i ];
-               ConvertShaderToMTL( fmtl, shader, i );
+               int lightmapCount;
+               for( lightmapCount = 0; lightmapCount < numBSPLightmaps; lightmapCount++ )
+                       ;
+               for( ; ; lightmapCount++ )
+               {
+                       char buf[1024];
+                       FILE *tmp;
+                       snprintf(buf, sizeof(buf), "%s/lm_%04d.tga", base, lightmapCount);
+                       buf[sizeof(buf) - 1] = 0;
+                       tmp = fopen(buf, "rb");
+                       if(!tmp)
+                               break;
+                       fclose(tmp);
+               }
+               for( i = 0; i < lightmapCount; i++ )
+                       ConvertLightmapToMTL( fmtl, base, i );
+       }
+       else
+       {
+               for( i = 0; i < numBSPShaders; i++ )
+               {
+                       shader = &bspShaders[ i ];
+                       ConvertShaderToMTL( fmtl, shader, i );
+               }
        }
        
        /* walk entity list */
index aa3bcff2765de821c3da756b68c1b1c7ac5c4622..325235fa57a0e66cdf8c432a970a1a35b2fabd67 100644 (file)
@@ -1602,6 +1602,8 @@ int ConvertBSPMain( int argc, char **argv )
                }
                else if( !strcmp( argv[ i ],  "-shadersasbitmap" ) )
                        shadersAsBitmap = qtrue;
+               else if( !strcmp( argv[ i ],  "-lightmapsastexcoord" ) )
+                       lightmapsAsTexcoord = qtrue;
                else if( !strcmp( argv[ i ],  "-forcereadbsp" ) )
                        force_bsp = qtrue;
                else if( !strcmp( argv[ i ],  "-meta" ) )
index 4c421203bc9b6cd880bed16bcbdc1f8f9c0d6be6..f01d353edbfb12986d31a66417a48500be91f456 100644 (file)
@@ -2275,6 +2275,7 @@ Q_EXTERN float                            linearScale Q_ASSIGN( 1.0f / 8000.0f );
 
 // for .ase conversion
 Q_EXTERN qboolean                      shadersAsBitmap Q_ASSIGN( qfalse );
+Q_EXTERN qboolean                      lightmapsAsTexcoord Q_ASSIGN( qfalse );
 
 Q_EXTERN light_t                       *lights;
 Q_EXTERN int                           numPointLights;