From fc0e5c3cccbcbd15154808f5c7842bb31a79023c Mon Sep 17 00:00:00 2001 From: Joshua Ashton Date: Sun, 22 Aug 2021 03:10:27 +0100 Subject: [PATCH] Handle Half-Life 1 styled point light info This adds support for the vector version of _light, where the first 3 values are the color and the alpha is the intensity. Signed-off-by: Joshua Ashton --- tools/vmap/light.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/tools/vmap/light.c b/tools/vmap/light.c index 43ac1a8..8cf86a8 100644 --- a/tools/vmap/light.c +++ b/tools/vmap/light.c @@ -542,10 +542,30 @@ void CreateEntityLights( void ){ Sys_FPrintf( SYS_WRN, "WARNING: Styled light found targeting %s\n **", target ); } + /* default to white color values */ + light->color[ 0 ] = + light->color[ 1 ] = + light->color[ 2 ] = 1.0f; + /* set light intensity */ - intensity = FloatForKey( e, "_light" ); - if ( intensity == 0.0f ) { - intensity = FloatForKey( e, "light" ); + _color = ValueForKey( e, "_light" ); + if ( _color && _color[0] ) { + /* Handle Half-Life styled _light values which + * contain color. Otherwise, fallback to _light + * being a single float for intensity + */ + if ( sscanf( _color, "%f %f %f %f", &light->color[ 0 ], &light->color[ 1 ], &light->color[ 2 ], &intensity ) == 4 ) { + light->color[ 0 ] /= 255; + light->color[ 1 ] /= 255; + light->color[ 2 ] /= 255; + intensity /= 4; + } + else { + intensity = FloatForKey( e, "_light" ); + if ( intensity == 0.0f ) { + intensity = FloatForKey( e, "light" ); + } + } } if ( intensity == 0.0f ) { intensity = 300.0f; @@ -629,11 +649,6 @@ void CreateEntityLights( void ){ /*if ( !( light->flags & LIGHT_UNNORMALIZED ) ) { ColorNormalize( light->color, light->color ); }*/ - } else { - /* default to white color values */ - light->color[ 0 ] = - light->color[ 1 ] = - light->color[ 2 ] = 1.0f; } }