glTF: Merge master
This commit is contained in:
parent
0508df3751
commit
38956097e3
|
@ -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": (3, 2, 2),
|
||||
"version": (3, 2, 5),
|
||||
'blender': (3, 1, 0),
|
||||
'location': 'File > Import-Export',
|
||||
'description': 'Import-Export as glTF 2.0',
|
||||
|
@ -160,10 +160,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'
|
||||
)
|
||||
|
|
|
@ -120,7 +120,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,
|
||||
|
@ -279,7 +282,9 @@ def __gather_clearcoat_extension(blender_material, export_settings):
|
|||
clearcoat_extension['clearcoatFactor'] = clearcoat_socket.default_value
|
||||
clearcoat_enabled = clearcoat_extension['clearcoatFactor'] > 0
|
||||
elif __has_image_node_from_socket(clearcoat_socket):
|
||||
clearcoat_extension['clearcoatFactor'] = 1
|
||||
fac = gltf2_blender_get.get_factor_from_socket(clearcoat_socket, kind='VALUE')
|
||||
# default value in glTF is 0.0, but if there is a texture without factor, use 1
|
||||
clearcoat_extension['clearcoatFactor'] = fac if fac != None else 1.0
|
||||
has_clearcoat_texture = True
|
||||
clearcoat_enabled = True
|
||||
|
||||
|
@ -289,7 +294,9 @@ def __gather_clearcoat_extension(blender_material, export_settings):
|
|||
if isinstance(clearcoat_roughness_socket, bpy.types.NodeSocket) and not clearcoat_roughness_socket.is_linked:
|
||||
clearcoat_extension['clearcoatRoughnessFactor'] = clearcoat_roughness_socket.default_value
|
||||
elif __has_image_node_from_socket(clearcoat_roughness_socket):
|
||||
clearcoat_extension['clearcoatRoughnessFactor'] = 1
|
||||
fac = gltf2_blender_get.get_factor_from_socket(clearcoat_roughness_socket, kind='VALUE')
|
||||
# default value in glTF is 0.0, but if there is a texture without factor, use 1
|
||||
clearcoat_extension['clearcoatRoughnessFactor'] = fac if fac != None else 1.0
|
||||
has_clearcoat_roughness_texture = True
|
||||
|
||||
# Pack clearcoat (R) and clearcoatRoughness (G) channels.
|
||||
|
|
|
@ -53,7 +53,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:
|
||||
|
@ -61,7 +64,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
|
||||
|
|
|
@ -35,6 +35,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
|
||||
|
||||
|
@ -56,6 +57,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
|
||||
|
||||
|
||||
|
|
|
@ -250,6 +250,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:
|
||||
|
|
|
@ -245,8 +245,10 @@ def _make_temp_image_copy(guard: TmpImageGuard, src_image: bpy.types.Image):
|
|||
tmp_image = guard.image
|
||||
|
||||
tmp_image.update()
|
||||
# See #1564 and T95616
|
||||
tmp_image.scale(*src_image.size)
|
||||
|
||||
if src_image.is_dirty:
|
||||
if src_image.is_dirty: # Warning, img size change doesn't make it dirty, see T95616
|
||||
# Unsaved changes aren't copied by .copy(), so do them ourselves
|
||||
tmp_buf = np.empty(src_image.size[0] * src_image.size[1] * 4, np.float32)
|
||||
src_image.pixels.foreach_get(tmp_buf)
|
||||
|
|
Loading…
Reference in New Issue