]> git.rm.cloudns.org Git - xonotic/netradiant.git/commitdiff
improved lightmap handling
authorRudolf Polzer <divverent@alientrap.org>
Thu, 23 Dec 2010 11:52:10 +0000 (12:52 +0100)
committerRudolf Polzer <divverent@alientrap.org>
Thu, 23 Dec 2010 11:52:10 +0000 (12:52 +0100)
tools/quake3/q3map2/convert_ase.c
tools/quake3/q3map2/convert_obj.c

index a0597957e062a24611b78503dd09735c2911a9a0..304b1b7c0c804dba93714d01c176d774b90a6684 100644 (file)
@@ -43,6 +43,7 @@ ConvertSurface()
 converts a bsp drawsurface to an ase chunk
 */
 
+int numLightmapsASE = 0;
 static void ConvertSurface( FILE *f, bspModel_t *model, int modelNum, bspDrawSurface_t *ds, int surfaceNum, vec3_t origin )
 {
        int                             i, v, face, a, b, c;
@@ -162,7 +163,15 @@ 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", lightmapsAsTexcoord ? ds->lightmapNum : ds->shaderNum );
+       if(lightmapsAsTexcoord)
+       {
+               if(ds->lightmapNum >= 0 && ds->lightmapNum < numLightmapsASE)
+                       fprintf( f, "\t*MATERIAL_REF\t%d\r\n", ds->lightmapNum );
+               else
+                       Sys_Printf( "WARNING: lightmap %d out of range, not exporting\n", ds->lightmapNum );
+       }
+       else
+               fprintf( f, "\t*MATERIAL_REF\t%d\r\n", ds->shaderNum );
        fprintf( f, "}\r\n" );
 }
 
@@ -293,15 +302,18 @@ static void ConvertLightmap( FILE *f, const char *base, int lightmapNum )
        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" );
+       if(lightmapNum >= 0)
+       {
+               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" );
 }
@@ -377,6 +389,7 @@ int ConvertBSPToASE( char *bspName )
                fprintf( f, "\t*MATERIAL_COUNT\t%d\r\n", lightmapCount );
                for( i = 0; i < lightmapCount; i++ )
                        ConvertLightmap( f, base, i );
+               numLightmapsASE = lightmapCount;
        }
        else
        {
index f680cf97f41b65d2f0a1f01fd5bc8c45e362b81c..f02da25a73d2fe84cf6a7a62be4e81b7b9d2371f 100644 (file)
@@ -43,6 +43,10 @@ ConvertSurface()
 converts a bsp drawsurface to an obj chunk
 */
 
+int firstLightmap = 0;
+int lastLightmap = -1;
+static void ConvertLightmapToMTL( FILE *f, const char *base, int lightmapNum );
+
 int objVertexCount = 0;
 int objLastShaderNum = -1;
 static void ConvertSurfaceToOBJ( FILE *f, bspModel_t *model, int modelNum, bspDrawSurface_t *ds, int surfaceNum, vec3_t origin )
@@ -73,6 +77,16 @@ static void ConvertSurfaceToOBJ( FILE *f, bspModel_t *model, int modelNum, bspDr
                        fprintf(f, "usemtl lm_%04d\r\n", ds->lightmapNum[0]);
                        objLastShaderNum = ds->lightmapNum[0];
                }
+               if(ds->lightmapNum[0] < firstLightmap)
+               {
+                       Sys_Printf( "WARNING: lightmap %d out of range (exporting anyway)\n", ds->lightmapNum[0] );
+                       firstLightmap = ds->lightmapNum[0];
+               }
+               if(ds->lightmapNum[0] > lastLightmap)
+               {
+                       Sys_Printf( "WARNING: lightmap %d out of range (exporting anyway)\n", ds->lightmapNum[0] );
+                       lastLightmap = ds->lightmapNum[0];
+               }
        }
        else
        {
@@ -179,7 +193,8 @@ 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 );
+       if(lightmapNum >= 0)
+               fprintf( f, "map_Kd %s\\lm_%04d.tga\r\n", base, lightmapNum );
 }
 
 
@@ -248,8 +263,7 @@ int ConvertBSPToOBJ( char *bspName )
                                break;
                        fclose(tmp);
                }
-               for( i = 0; i < lightmapCount; i++ )
-                       ConvertLightmapToMTL( fmtl, base, i );
+               lastLightmap = lightmapCount - 1;
        }
        else
        {
@@ -287,6 +301,12 @@ int ConvertBSPToOBJ( char *bspName )
                ConvertModelToOBJ( f, model, modelNum, origin );
        }
        
+       if(lightmapsAsTexcoord)
+       {
+               for( i = firstLightmap; i <= lastLightmap; i++ )
+                       ConvertLightmapToMTL( fmtl, base, i );
+       }
+
        /* close the file and return */
        fclose( f );
        fclose( fmtl );