Skip to content
Snippets Groups Projects
Commit 4003baf0 authored by Julien Duroure's avatar Julien Duroure
Browse files

glTF exporter: Option to not export texture images

parent 3b088fc3
No related branches found
No related tags found
No related merge requests found
......@@ -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, 8, 16),
"version": (1, 8, 17),
'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'
)
......
......@@ -114,7 +114,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,
......
......@@ -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:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment