Fix: glTF exporter: Fix exporting Vertex Color for Unlit Materials
This commit is contained in:
@@ -5,7 +5,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": (4, 5, 22),
|
||||
"version": (4, 5, 23),
|
||||
'blender': (4, 4, 0),
|
||||
'location': 'File > Import-Export',
|
||||
'description': 'Import-Export as glTF 2.0',
|
||||
|
||||
@@ -30,7 +30,6 @@ from .search_node_tree import \
|
||||
get_node_socket, \
|
||||
get_material_nodes, \
|
||||
NodeSocket, \
|
||||
get_vertex_color_info, \
|
||||
gather_alpha_info
|
||||
|
||||
|
||||
@@ -480,7 +479,7 @@ def __export_unlit(blender_material, export_settings):
|
||||
else:
|
||||
alpha_info = gather_alpha_info(None)
|
||||
|
||||
vc_info = get_vertex_color_info(info.get('rgb_socket'), info.get('alpha_socket'), export_settings)
|
||||
base_color_factor, vc_info = gltf2_unlit.gather_base_color_factor(info, export_settings)
|
||||
|
||||
material = gltf2_io.Material(
|
||||
alpha_cutoff=__gather_alpha_cutoff(alpha_info, export_settings),
|
||||
@@ -495,7 +494,7 @@ def __export_unlit(blender_material, export_settings):
|
||||
occlusion_texture=None,
|
||||
|
||||
pbr_metallic_roughness=gltf2_io.MaterialPBRMetallicRoughness(
|
||||
base_color_factor=gltf2_unlit.gather_base_color_factor(info, export_settings),
|
||||
base_color_factor=base_color_factor,
|
||||
base_color_texture=base_color_texture,
|
||||
metallic_factor=0.0,
|
||||
roughness_factor=0.9,
|
||||
|
||||
@@ -7,7 +7,6 @@ import bpy
|
||||
from ....io.com import gltf2_io
|
||||
from ....io.exp.user_extensions import export_user_extensions
|
||||
from ..cache import cached
|
||||
from .search_node_tree import get_vertex_color_info
|
||||
from .texture_info import gather_texture_info
|
||||
from .search_node_tree import \
|
||||
get_socket_from_gltf_material_node, \
|
||||
|
||||
@@ -968,56 +968,6 @@ def check_if_is_linked_to_active_output(shader_socket, group_path):
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def get_vertex_color_info(color_socket, alpha_socket, export_settings):
|
||||
|
||||
attribute_color = None
|
||||
attribute_alpha = None
|
||||
attribute_color_type = None
|
||||
attribute_alpha_type = None
|
||||
alpha_mode = "OPAQUE"
|
||||
|
||||
# Retrieve Attribute used as vertex color for Color
|
||||
if color_socket is not None and color_socket.socket is not None:
|
||||
node = previous_node(color_socket)
|
||||
if node.node is not None:
|
||||
if node.node.type == 'MIX' and node.node.data_type == "RGBA" and node.node.blend_type == 'MULTIPLY':
|
||||
use_vc, attribute_color, use_active = get_attribute_name(
|
||||
NodeSocket(node.node.inputs[6], node.group_path), export_settings)
|
||||
if use_vc is False:
|
||||
use_vc, attribute_color, use_active = get_attribute_name(
|
||||
NodeSocket(node.node.inputs[7], node.group_path), export_settings)
|
||||
if use_vc is True and use_active is True:
|
||||
attribute_color_type = "active"
|
||||
elif use_vc is True and use_active is None and attribute_color is not None:
|
||||
attribute_color_type = "name"
|
||||
elif node.node.type in ["ATTRIBUTE", "VERTEX_COLOR"]:
|
||||
use_vc, attribute_color, use_active = get_attribute_name(
|
||||
NodeSocket(node.node.outputs[0], node.group_path), export_settings)
|
||||
if use_vc is True and use_active is True:
|
||||
attribute_color_type = "active"
|
||||
elif use_vc is True and use_active is None and attribute_color is not None:
|
||||
attribute_color_type = "name"
|
||||
|
||||
if alpha_socket is not None and alpha_socket.socket is not None:
|
||||
alpha_info = gather_alpha_info(alpha_socket.to_node_nav())
|
||||
|
||||
if alpha_info['alphaColorAttrib'] == '':
|
||||
attribute_alpha = None
|
||||
attribute_alpha_type = 'active'
|
||||
elif alpha_info['alphaColorAttrib'] is not None:
|
||||
attribute_alpha = alpha_info['alphaColorAttrib']
|
||||
attribute_alpha_type = 'name'
|
||||
alpha_mode = alpha_info['alphaMode']
|
||||
|
||||
return {
|
||||
"color": attribute_color,
|
||||
"alpha": attribute_alpha,
|
||||
"color_type": attribute_color_type,
|
||||
"alpha_type": attribute_alpha_type,
|
||||
'alpha_mode': alpha_mode}
|
||||
|
||||
|
||||
def get_attribute_name(socket, export_settings):
|
||||
node = previous_node(socket)
|
||||
if node.node is not None and node.node.type == "ATTRIBUTE" \
|
||||
|
||||
@@ -9,7 +9,8 @@ from .search_node_tree import \
|
||||
previous_socket, \
|
||||
previous_node, \
|
||||
get_factor_from_socket, \
|
||||
gather_alpha_info
|
||||
gather_alpha_info, \
|
||||
gather_color_info
|
||||
|
||||
|
||||
def detect_shadeless_material(blender_material_node_tree, use_nodes, export_settings):
|
||||
@@ -124,13 +125,22 @@ def __detect_lightpath_trick(socket):
|
||||
def gather_base_color_factor(info, export_settings):
|
||||
rgb, alpha = None, None
|
||||
path, path_alpha = None, None
|
||||
vc_info = {"color": None, "alpha": None, "color_type": None, "alpha_type": None, "alpha_mode": "OPAQUE"}
|
||||
|
||||
|
||||
if 'rgb_socket' in info:
|
||||
rgb, path = get_factor_from_socket(info['rgb_socket'], kind='RGB')
|
||||
rgb_vc_info = gather_color_info(info['rgb_socket'].to_node_nav())
|
||||
vc_info['color'] = rgb_vc_info['colorAttrib']
|
||||
vc_info['color_type'] = rgb_vc_info['colorAttribType']
|
||||
rgb = rgb_vc_info['colorFactor']
|
||||
path = rgb_vc_info['colorPath']
|
||||
if 'alpha_socket' in info:
|
||||
alpha_info = gather_alpha_info(info['alpha_socket'].to_node_nav())
|
||||
alpha = alpha_info['alphaFactor']
|
||||
path_alpha = alpha_info['alphaPath']
|
||||
vc_info['alpha'] = alpha_info['alphaColorAttrib']
|
||||
vc_info['alpha_type'] = alpha_info['alphaColorAttribType']
|
||||
vc_info['alpha_mode'] = alpha_info['alphaMode']
|
||||
|
||||
# Storing path for KHR_animation_pointer
|
||||
if path is not None:
|
||||
@@ -147,8 +157,8 @@ def gather_base_color_factor(info, export_settings):
|
||||
|
||||
rgba = [*rgb, alpha]
|
||||
if rgba == [1, 1, 1, 1]:
|
||||
return None
|
||||
return rgba
|
||||
return None, vc_info
|
||||
return rgba, vc_info
|
||||
|
||||
|
||||
def gather_base_color_texture(info, export_settings):
|
||||
|
||||
Reference in New Issue
Block a user