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;
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" );
}
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" );
}
fprintf( f, "\t*MATERIAL_COUNT\t%d\r\n", lightmapCount );
for( i = 0; i < lightmapCount; i++ )
ConvertLightmap( f, base, i );
+ numLightmapsASE = lightmapCount;
}
else
{
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 )
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
{
{
/* 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 );
}
break;
fclose(tmp);
}
- for( i = 0; i < lightmapCount; i++ )
- ConvertLightmapToMTL( fmtl, base, i );
+ lastLightmap = lightmapCount - 1;
}
else
{
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 );