[Bf-extensions-cvs] [f3cf3a16] master: glTF exporter: Manage emission strength in materials
Julien Duroure
noreply at git.blender.org
Thu Sep 17 15:23:14 CEST 2020
Commit: f3cf3a16e989eb2b407be466be8ecb2aa951275c
Author: Julien Duroure
Date: Wed Sep 16 18:00:14 2020 +0200
Branches: master
https://developer.blender.org/rBAf3cf3a16e989eb2b407be466be8ecb2aa951275c
glTF exporter: Manage emission strength in materials
===================================================================
M io_scene_gltf2/__init__.py
M io_scene_gltf2/blender/exp/gltf2_blender_gather_materials.py
M io_scene_gltf2/blender/exp/gltf2_blender_get.py
===================================================================
diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py
index 765cce00..22afc4c5 100755
--- a/io_scene_gltf2/__init__.py
+++ b/io_scene_gltf2/__init__.py
@@ -15,7 +15,7 @@
bl_info = {
'name': 'glTF 2.0 format',
'author': 'Julien Duroure, Scurest, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin Schmithüsen, Jim Eckerlein, and many external contributors',
- "version": (1, 4, 24),
+ "version": (1, 4, 25),
'blender': (2, 90, 0),
'location': 'File > Import-Export',
'description': 'Import-Export as glTF 2.0',
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_materials.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_materials.py
index 0e764621..8dc5896f 100755
--- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_materials.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_materials.py
@@ -109,13 +109,36 @@ def __gather_emissive_factor(blender_material, export_settings):
if emissive_socket is None:
emissive_socket = gltf2_blender_get.get_socket_old(blender_material, "EmissiveFactor")
if isinstance(emissive_socket, bpy.types.NodeSocket):
- fac = gltf2_blender_get.get_factor_from_socket(emissive_socket, kind='RGB')
- if fac is None and emissive_socket.is_linked:
+ factor = gltf2_blender_get.get_factor_from_socket(emissive_socket, kind='RGB')
+
+ if factor is None and emissive_socket.is_linked:
# In glTF, the default emissiveFactor is all zeros, so if an emission texture is connected,
# we have to manually set it to all ones.
- fac = [1.0, 1.0, 1.0]
- if fac == [0, 0, 0]: fac = None
- return fac
+ factor = [1.0, 1.0, 1.0]
+
+ if factor is None: factor = [0.0, 0.0, 0.0]
+
+ # Handle Emission Strength
+ strength_socket = None
+ if emissive_socket.node.type == 'EMISSION':
+ strength_socket = emissive_socket.node.inputs['Strength']
+ elif 'Emission Strength' in emissive_socket.node.inputs:
+ strength_socket = emissive_socket.node.inputs['Emission Strength']
+ strength = (
+ gltf2_blender_get.get_const_from_socket(strength_socket, kind='VALUE')
+ if strength_socket is not None
+ else None
+ )
+ if strength is not None:
+ factor = [f * strength for f in factor]
+
+ # Clamp to range [0,1]
+ factor = [min(1.0, f) for f in factor]
+
+ if factor == [0, 0, 0]: factor = None
+
+ return factor
+
return None
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_get.py b/io_scene_gltf2/blender/exp/gltf2_blender_get.py
index 71eb4a2c..6a5152a6 100755
--- a/io_scene_gltf2/blender/exp/gltf2_blender_get.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_get.py
@@ -227,7 +227,7 @@ def get_factor_from_socket(socket, kind):
from a MULTIPLY node just before the socket.
kind is either 'RGB' or 'VALUE'.
"""
- fac = __get_const_from_socket(socket, kind)
+ fac = get_const_from_socket(socket, kind)
if fac is not None:
return fac
@@ -237,19 +237,19 @@ def get_factor_from_socket(socket, kind):
if kind == 'RGB':
if node.type == 'MIX_RGB' and node.blend_type == 'MULTIPLY':
# TODO: handle factor in inputs[0]?
- x1 = __get_const_from_socket(node.inputs[1], kind)
- x2 = __get_const_from_socket(node.inputs[2], kind)
+ x1 = get_const_from_socket(node.inputs[1], kind)
+ x2 = get_const_from_socket(node.inputs[2], kind)
if kind == 'VALUE':
if node.type == 'MATH' and node.operation == 'MULTIPLY':
- x1 = __get_const_from_socket(node.inputs[0], kind)
- x2 = __get_const_from_socket(node.inputs[1], kind)
+ x1 = get_const_from_socket(node.inputs[0], kind)
+ x2 = get_const_from_socket(node.inputs[1], kind)
if x1 is not None and x2 is None: return x1
if x2 is not None and x1 is None: return x2
return None
-def __get_const_from_socket(socket, kind):
+def get_const_from_socket(socket, kind):
if not socket.is_linked:
if kind == 'RGB':
if socket.type != 'RGBA': return None
More information about the Bf-extensions-cvs
mailing list