From f8a5329ea87f2b187cb5b8c114f40f7ddbe9c2a6 Mon Sep 17 00:00:00 2001 From: Robert Beckebans Date: Wed, 24 Apr 2024 15:46:03 +0200 Subject: [PATCH] Read Blender lights directly through the KHR_lights_punctual glTF extension --- base/devtools.cfg | 2 +- neo/idlib/MapFile_gltf.cpp | 29 ++++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/base/devtools.cfg b/base/devtools.cfg index 20dc3373..4826fe73 100644 --- a/base/devtools.cfg +++ b/base/devtools.cfg @@ -3,7 +3,7 @@ bind "I" "toggle r_showSurfaceInfo" bind "N" "noclip" bind "M" "spawn moveable_macbethchart" -bind "F1" "toggle editLights" +bind "F1" "editLights" bind "F2" "toggle r_showTris 1 2 0" bind "F3" "toggle r_forceAmbient 0.5 1.0 0" bind "F4" "toggle r_skipInteractions" diff --git a/neo/idlib/MapFile_gltf.cpp b/neo/idlib/MapFile_gltf.cpp index 554ca269..1a99a951 100644 --- a/neo/idlib/MapFile_gltf.cpp +++ b/neo/idlib/MapFile_gltf.cpp @@ -433,6 +433,8 @@ void ResolveLight( gltfData* data, idMapEntity* newEntity, gltfNode* node ) assert( light ); + newEntity->epairs.Set( "classname", "light" ); + //newEntity->epairs.SetMatrix( "rotation", mat3_default ); newEntity->epairs.SetVector( "_color", light->color ); @@ -450,8 +452,19 @@ void ResolveLight( gltfData* data, idMapEntity* newEntity, gltfNode* node ) case gltfExt_KHR_lights_punctual::Point: { - newEntity->epairs.SetVector( "light_radius", idVec3( light->range ) ); - newEntity->epairs.Set( "texture", "lights/defaultpointlight" ); + float radius = 300; + if( light->range != -1 ) + { + radius = light->range; + } + + newEntity->epairs.SetVector( "light_radius", idVec3( radius ) ); + + idStr texture; + if( !newEntity->epairs.GetString( "texture", "", texture ) ) + { + newEntity->epairs.Set( "texture", "lights/biground1" ); + } break; } @@ -471,7 +484,12 @@ void ResolveLight( gltfData* data, idMapEntity* newEntity, gltfNode* node ) newEntity->epairs.SetVector( "light_up", axis[2] * fov ); newEntity->epairs.SetVector( "light_start", axis[0] * 16 ); newEntity->epairs.SetVector( "light_end", axis[0] * ( light->range - 16 ) ); - newEntity->epairs.Set( "texture", "lights/spot01" ); + + idStr texture; + if( !newEntity->epairs.GetString( "texture", "", texture ) ) + { + newEntity->epairs.Set( "texture", "lights/spot01" ); + } break; } @@ -638,8 +656,9 @@ int idMapEntity::GetEntities( gltfData* data, EntityListRef entities, int sceneI idStr classnameStr = node->extras.strPairs.GetString( "classname" ); bool skipInline = !node->extras.strPairs.GetBool( "inline", true ); idDict epairs; - // skip everything that is not an entity - if( !classnameStr.IsEmpty() ) + + // skip everything that is not an entity except lights + if( !classnameStr.IsEmpty() || node->extensions.KHR_lights_punctual ) { idMapEntity* newEntity = new( TAG_IDLIB_GLTF ) idMapEntity(); entities.Append( newEntity );