diff options
Diffstat (limited to 'io_scene_gltf2/blender/imp/gltf2_blender_light.py')
-rw-r--r-- | io_scene_gltf2/blender/imp/gltf2_blender_light.py | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_light.py b/io_scene_gltf2/blender/imp/gltf2_blender_light.py index fb060598..034d41ab 100644 --- a/io_scene_gltf2/blender/imp/gltf2_blender_light.py +++ b/io_scene_gltf2/blender/imp/gltf2_blender_light.py @@ -6,6 +6,7 @@ from math import pi from ..com.gltf2_blender_extras import set_extras from io_scene_gltf2.io.imp.gltf2_io_user_extensions import import_user_extensions +from ..com.gltf2_blender_conversion import PBR_WATTS_TO_LUMENS class BlenderLight(): @@ -21,7 +22,7 @@ class BlenderLight(): import_user_extensions('gather_import_light_before_hook', gltf, vnode, pylight) if pylight['type'] == "directional": - light = BlenderLight.create_directional(gltf, light_id) + light = BlenderLight.create_directional(gltf, light_id) # ...Why not pass the pylight? elif pylight['type'] == "point": light = BlenderLight.create_point(gltf, light_id) elif pylight['type'] == "spot": @@ -30,9 +31,6 @@ class BlenderLight(): if 'color' in pylight.keys(): light.color = pylight['color'] - if 'intensity' in pylight.keys(): - light.energy = pylight['intensity'] - # TODO range set_extras(light, pylight.get('extras')) @@ -44,12 +42,34 @@ class BlenderLight(): pylight = gltf.data.extensions['KHR_lights_punctual']['lights'][light_id] if 'name' not in pylight.keys(): - pylight['name'] = "Sun" + pylight['name'] = "Sun" # Uh... Is it okay to mutate the import data? sun = bpy.data.lights.new(name=pylight['name'], type="SUN") + + if 'intensity' in pylight.keys(): + if gltf.import_settings['convert_lighting_mode'] == 'SPEC': + sun.energy = pylight['intensity'] / PBR_WATTS_TO_LUMENS + elif gltf.import_settings['convert_lighting_mode'] == 'COMPAT': + sun.energy = pylight['intensity'] + elif gltf.import_settings['convert_lighting_mode'] == 'RAW': + sun.energy = pylight['intensity'] + else: + raise ValueError(gltf.import_settings['convert_lighting_mode']) + return sun @staticmethod + def _calc_energy_pointlike(gltf, pylight): + if gltf.import_settings['convert_lighting_mode'] == 'SPEC': + return pylight['intensity'] / PBR_WATTS_TO_LUMENS * 4 * pi + elif gltf.import_settings['convert_lighting_mode'] == 'COMPAT': + return pylight['intensity'] * 4 * pi + elif gltf.import_settings['convert_lighting_mode'] == 'RAW': + return pylight['intensity'] + else: + raise ValueError(gltf.import_settings['convert_lighting_mode']) + + @staticmethod def create_point(gltf, light_id): pylight = gltf.data.extensions['KHR_lights_punctual']['lights'][light_id] @@ -57,6 +77,10 @@ class BlenderLight(): pylight['name'] = "Point" point = bpy.data.lights.new(name=pylight['name'], type="POINT") + + if 'intensity' in pylight.keys(): + point.energy = BlenderLight._calc_energy_pointlike(gltf, pylight) + return point @staticmethod @@ -79,4 +103,7 @@ class BlenderLight(): else: spot.spot_blend = 1.0 + if 'intensity' in pylight.keys(): + spot.energy = BlenderLight._calc_energy_pointlike(gltf, pylight) + return spot |