@ -40,44 +40,23 @@ void export_lightmap(const world_t* world, const face_t* face, const FaceBound&
if ( face - > lightmap < 0 )
if ( face - > lightmap < 0 )
return ;
return ;
const unsigned char * lightmap = & world - > lightmap [ face - > lightmap ] ;
const plane_t * plane = & world - > planes [ face - > plane_id ] ;
Vec3 minBounds = ( bounds . lightmapBounds . min / 16 ) . floor ( ) ;
Vec3 maxBounds = ( bounds . lightmapBounds . max / 16 ) . ceil ( ) ;
int width , height ;
switch ( plane - > type )
{
case 0 :
case 3 :
// Towards X
width = ( int ) ( ceil ( bounds . worldBounds . max . y / 16 ) - floor ( bounds . worldBounds . min . y / 16 ) ) ;
height = ( int ) ( ceil ( bounds . worldBounds . max . z / 16 ) - floor ( bounds . worldBounds . min . z / 16 ) ) ;
break ;
case 1 :
case 4 :
// Towards Y
width = ( int ) ( ceil ( bounds . worldBounds . max . x / 16 ) - floor ( bounds . worldBounds . min . x / 16 ) ) ;
height = ( int ) ( ceil ( bounds . worldBounds . max . z / 16 ) - floor ( bounds . worldBounds . min . z / 16 ) ) ;
break ;
case 2 :
case 5 :
// Towards Z
width = ( int ) ( ceil ( bounds . worldBounds . max . x / 16 ) - floor ( bounds . worldBounds . min . x / 16 ) ) ;
height = ( int ) ( ceil ( bounds . worldBounds . max . y / 16 ) - floor ( bounds . worldBounds . min . y / 16 ) ) ;
break ;
default :
printf ( " Error: unknown plane type %d \n " , plane - > type ) ;
return ;
}
int width = ( ( int ) maxBounds . x - ( int ) minBounds . x ) * 16 ; // extents[0]
int height = ( ( int ) maxBounds . y - ( int ) minBounds . y ) * 16 ; // extents[1]
width + = 1 ;
width = ( width > > 4 ) + 1 ;
height = ( height > > 4 ) + 1 ;
char path [ _MAX_PATH ] ;
char path [ _MAX_PATH ] ;
sprintf_s ( path , _MAX_PATH , " lightmap_face%d_e%d_PT%d_ %dx%d.raw " , faceIdx , face - > ledge_num , plane - > type , width , height ) ;
sprintf_s ( path , _MAX_PATH , " lightmap_face%d_e%d_%dx%d.raw " , faceIdx , face - > ledge_num , width , height ) ;
FILE * flm ;
FILE * flm ;
fopen_s ( & flm , path , " wb " ) ;
fopen_s ( & flm , path , " wb " ) ;
if ( ! flm )
if ( ! flm )
return ;
return ;
const unsigned char * lightmap = & world - > lightmap [ face - > lightmap ] ;
for ( int y = 0 ; y < height ; + + y )
for ( int y = 0 ; y < height ; + + y )
{
{
fwrite ( & lightmap [ y * width ] , sizeof ( unsigned char ) , width , flm ) ;
fwrite ( & lightmap [ y * width ] , sizeof ( unsigned char ) , width , flm ) ;