Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Duroure <julien.duroure@gmail.com>2020-09-16 19:00:14 +0300
committerJulien Duroure <julien.duroure@gmail.com>2020-09-17 16:23:03 +0300
commitf3cf3a16e989eb2b407be466be8ecb2aa951275c (patch)
tree723d63bdb4df6152a20c81ca84b578ee5cdebece /io_scene_gltf2
parent59787f0f2f74fed8159554c105c6c01802070271 (diff)
glTF exporter: Manage emission strength in materials
Diffstat (limited to 'io_scene_gltf2')
-rwxr-xr-xio_scene_gltf2/__init__.py2
-rwxr-xr-xio_scene_gltf2/blender/exp/gltf2_blender_gather_materials.py33
-rwxr-xr-xio_scene_gltf2/blender/exp/gltf2_blender_get.py12
3 files changed, 35 insertions, 12 deletions
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