From: Rudolf Polzer Date: Thu, 23 Dec 2010 11:52:10 +0000 (+0100) Subject: improved lightmap handling X-Git-Tag: xonotic-v0.5.0~94 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=fa46a28662a6b496f6a25d916d69e93e79fbdc28;p=xonotic%2Fnetradiant.git improved lightmap handling --- diff --git a/tools/quake3/q3map2/convert_ase.c b/tools/quake3/q3map2/convert_ase.c index a0597957..304b1b7c 100644 --- a/tools/quake3/q3map2/convert_ase.c +++ b/tools/quake3/q3map2/convert_ase.c @@ -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 { diff --git a/tools/quake3/q3map2/convert_obj.c b/tools/quake3/q3map2/convert_obj.c index f680cf97..f02da25a 100644 --- a/tools/quake3/q3map2/convert_obj.c +++ b/tools/quake3/q3map2/convert_obj.c @@ -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 );