Merge branch 'blender-v3.1-release'

This commit is contained in:
Julien Duroure 2022-02-12 14:07:32 +01:00
commit 2fab028347
5 changed files with 29 additions and 5 deletions

View File

@ -4,7 +4,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": (3, 2, 4),
"version": (3, 2, 5),
'blender': (3, 1, 0),
'location': 'File > Import-Export',
'description': 'Import-Export as glTF 2.0',
@ -149,10 +149,12 @@ class ExportGLTF2_Base:
('JPEG', 'JPEG Format (.jpg)',
'Save images as JPEGs. (Images that need alpha are saved as PNGs though.) '
'Be aware of a possible loss in quality'),
('NONE', 'None',
'Don\'t export images.'),
),
description=(
'Output format for images. PNG is lossless and generally preferred, but JPEG might be preferable for web '
'applications due to the smaller file size'
'applications due to the smaller file size. Alternatively they can be omitted if they are not needed'
),
default='AUTO'
)

View File

@ -103,7 +103,10 @@ 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):
factor = gltf2_blender_get.get_factor_from_socket(emissive_socket, kind='RGB')
if export_settings['gltf_image_format'] != "NONE":
factor = gltf2_blender_get.get_factor_from_socket(emissive_socket, kind='RGB')
else:
factor = gltf2_blender_get.get_const_from_default_value_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,

View File

@ -42,7 +42,10 @@ def __gather_base_color_factor(blender_material, export_settings):
alpha_socket = gltf2_blender_get.get_socket(blender_material, "Alpha")
if isinstance(alpha_socket, bpy.types.NodeSocket):
alpha = gltf2_blender_get.get_factor_from_socket(alpha_socket, kind='VALUE')
if export_settings['gltf_image_format'] != "NONE":
alpha = gltf2_blender_get.get_factor_from_socket(alpha_socket, kind='VALUE')
else:
alpha = gltf2_blender_get.get_const_from_default_value_socket(alpha_socket, kind='VALUE')
base_color_socket = gltf2_blender_get.get_socket(blender_material, "Base Color")
if base_color_socket is None:
@ -50,7 +53,10 @@ def __gather_base_color_factor(blender_material, export_settings):
if base_color_socket is None:
base_color_socket = gltf2_blender_get.get_socket_old(blender_material, "BaseColorFactor")
if isinstance(base_color_socket, bpy.types.NodeSocket):
rgb = gltf2_blender_get.get_factor_from_socket(base_color_socket, kind='RGB')
if export_settings['gltf_image_format'] != "NONE":
rgb = gltf2_blender_get.get_factor_from_socket(base_color_socket, kind='RGB')
else:
rgb = gltf2_blender_get.get_const_from_default_value_socket(base_color_socket, kind='RGB')
if rgb is None: rgb = [1.0, 1.0, 1.0]
if alpha is None: alpha = 1.0

View File

@ -24,6 +24,7 @@ def gather_texture(
:param export_settings: configuration of the export
:return: a glTF 2.0 texture with sampler and source embedded (will be converted to references by the exporter)
"""
if not __filter_texture(blender_shader_sockets, export_settings):
return None
@ -45,6 +46,9 @@ def gather_texture(
def __filter_texture(blender_shader_sockets, export_settings):
# User doesn't want to export textures
if export_settings['gltf_image_format'] == "NONE":
return None
return True

View File

@ -239,6 +239,15 @@ def get_factor_from_socket(socket, kind):
return None
def get_const_from_default_value_socket(socket, kind):
if kind == 'RGB':
if socket.type != 'RGBA': return None
return list(socket.default_value)[:3]
if kind == 'VALUE':
if socket.type != 'VALUE': return None
return socket.default_value
return None
def get_const_from_socket(socket, kind):
if not socket.is_linked: