From a75b54d2c1a0ac59f8308fb2d0d78f8e14f9a7d3 Mon Sep 17 00:00:00 2001 From: Mitchell Stokes Date: Mon, 9 Sep 2019 21:12:26 -0700 Subject: [PATCH] KHR_lights_punctual: Add work-around for bad intensity values from Khronos Blender exporter See https://github.com/KhronosGroup/glTF-Blender-IO/issues/564 --- gltf/converter.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/gltf/converter.py b/gltf/converter.py index 60a8a0c..405ec89 100644 --- a/gltf/converter.py +++ b/gltf/converter.py @@ -133,7 +133,10 @@ def update(self, gltf_data, writing_bam=False): if 'extensions' in gltf_data and 'KHR_lights_punctual' in gltf_data['extensions']: lights = gltf_data['extensions']['KHR_lights_punctual'].get('lights', []) for lightid, gltf_light in enumerate(lights): - self.load_light(lightid, gltf_light, punctual=True) + asset = gltf_data.get('asset', {}) + generator = asset.get('generator', '') + blender_hack = generator.startswith('Khronos glTF Blender I/O') + self.load_light(lightid, gltf_light, punctual=True, blender_hack=blender_hack) for texid, gltf_tex in enumerate(gltf_data.get('textures', [])): self.load_texture(texid, gltf_tex, gltf_data) @@ -1028,7 +1031,7 @@ def load_camera(self, camid, gltf_camera): self.cameras[camid] = node - def load_light(self, lightid, gltf_light, punctual=False): + def load_light(self, lightid, gltf_light, punctual=False, blender_hack=False): node = self.lights.get(lightid, None) lightname = gltf_light.get('name', 'light'+str(lightid)) @@ -1054,7 +1057,11 @@ def load_light(self, lightid, gltf_light, punctual=False): if hasattr(node, 'attenuation'): node.attenuation = LVector3(1, 0, 1) - if 'intensity' in gltf_light: + if blender_hack: + # Blender exports with radiometric values so don't convert + # (see https://github.com/KhronosGroup/glTF-Blender-IO/issues/564) + energy = gltf_light.get('intensity') + elif 'intensity' in gltf_light: # convert photometric light value to radiometric and multiply it # against color kv_const = 638