glTF: deprecation of use_nodes
use_nodes is now deprecated in Blender 5.0 - Remove check checks - Remove all nodes before creating the node tree is no more needed : these nodes are no more created at material creation
This commit is contained in:
@@ -7,7 +7,7 @@ bl_info = {
|
||||
# This is now displayed as the maintainer, so show the foundation.
|
||||
# "author": "Julien Duroure, Scurest, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin Schmithüsen, Jim Eckerlein", # Original Authors
|
||||
'author': "Blender Foundation, Khronos Group",
|
||||
"version": (5, 0, 19),
|
||||
"version": (5, 0, 20),
|
||||
'blender': (4, 4, 0),
|
||||
'location': 'File > Import-Export',
|
||||
'description': 'Import-Export as glTF 2.0',
|
||||
|
||||
@@ -28,7 +28,6 @@ class NODE_OT_GLTF_SETTINGS(bpy.types.Operator):
|
||||
space is not None
|
||||
and space.type == "NODE_EDITOR"
|
||||
and context.object and context.object.active_material
|
||||
and context.object.active_material.use_nodes is True
|
||||
and bpy.context.preferences.addons['io_scene_gltf2'].preferences.settings_node_ui is True
|
||||
)
|
||||
|
||||
|
||||
@@ -18,12 +18,11 @@ def export_anisotropy(blender_material, export_settings):
|
||||
uvmap_infos = {}
|
||||
udim_infos = {}
|
||||
|
||||
anisotropy_socket = get_socket(blender_material.node_tree, blender_material.use_nodes, 'Anisotropic')
|
||||
anisotropy_socket = get_socket(blender_material.node_tree, 'Anisotropic')
|
||||
anisotropic_rotation_socket = get_socket(
|
||||
blender_material.node_tree,
|
||||
blender_material.use_nodes,
|
||||
'Anisotropic Rotation')
|
||||
anisotropy_tangent_socket = get_socket(blender_material.node_tree, blender_material.use_nodes, 'Tangent')
|
||||
anisotropy_tangent_socket = get_socket(blender_material.node_tree, 'Tangent')
|
||||
|
||||
if anisotropy_socket.socket is None or anisotropic_rotation_socket.socket is None or anisotropy_tangent_socket.socket is None:
|
||||
return None, {}, {}
|
||||
@@ -153,12 +152,11 @@ def export_anisotropy(blender_material, export_settings):
|
||||
def export_anisotropy_from_grayscale_textures(blender_material, export_settings):
|
||||
# There will be a texture, with a complex calculation (no direct channel mapping)
|
||||
|
||||
anisotropy_socket = get_socket(blender_material.node_tree, blender_material.use_nodes, 'Anisotropic')
|
||||
anisotropy_socket = get_socket(blender_material.node_tree, 'Anisotropic')
|
||||
anisotropic_rotation_socket = get_socket(
|
||||
blender_material.node_tree,
|
||||
blender_material.use_nodes,
|
||||
'Anisotropic Rotation')
|
||||
anisotropy_tangent_socket = get_socket(blender_material.node_tree, blender_material.use_nodes, 'Tangent')
|
||||
anisotropy_tangent_socket = get_socket(blender_material.node_tree, 'Tangent')
|
||||
|
||||
sockets = (anisotropy_socket, anisotropic_rotation_socket, anisotropy_tangent_socket)
|
||||
|
||||
|
||||
@@ -17,9 +17,9 @@ def export_clearcoat(blender_material, export_settings):
|
||||
clearcoat_extension = {}
|
||||
clearcoat_roughness_slots = ()
|
||||
|
||||
clearcoat_socket = get_socket(blender_material.node_tree, blender_material.use_nodes, 'Coat Weight')
|
||||
clearcoat_roughness_socket = get_socket(blender_material.node_tree, blender_material.use_nodes, 'Coat Roughness')
|
||||
clearcoat_normal_socket = get_socket(blender_material.node_tree, blender_material.use_nodes, 'Coat Normal')
|
||||
clearcoat_socket = get_socket(blender_material.node_tree, 'Coat Weight')
|
||||
clearcoat_roughness_socket = get_socket(blender_material.node_tree, 'Coat Roughness')
|
||||
clearcoat_normal_socket = get_socket(blender_material.node_tree, 'Coat Normal')
|
||||
|
||||
if clearcoat_socket.socket is not None and isinstance(
|
||||
clearcoat_socket.socket,
|
||||
|
||||
@@ -15,10 +15,10 @@ from ..search_node_tree import \
|
||||
|
||||
|
||||
def export_emission_factor(blender_material, export_settings):
|
||||
emissive_socket = get_socket(blender_material.node_tree, blender_material.use_nodes, "Emissive")
|
||||
emissive_socket = get_socket(blender_material.node_tree, "Emissive")
|
||||
if emissive_socket.socket is None:
|
||||
emissive_socket = get_socket_from_gltf_material_node(
|
||||
blender_material.node_tree, blender_material.use_nodes, "EmissiveFactor")
|
||||
blender_material.node_tree, "EmissiveFactor")
|
||||
if emissive_socket is not None and isinstance(emissive_socket.socket, bpy.types.NodeSocket):
|
||||
if export_settings['gltf_image_format'] != "NONE":
|
||||
factor, path = get_factor_from_socket(emissive_socket, kind='RGB')
|
||||
@@ -80,10 +80,10 @@ def export_emission_factor(blender_material, export_settings):
|
||||
|
||||
|
||||
def export_emission_texture(blender_material, export_settings):
|
||||
emissive = get_socket(blender_material.node_tree, blender_material.use_nodes, "Emissive")
|
||||
emissive = get_socket(blender_material.node_tree, "Emissive")
|
||||
if emissive.socket is None:
|
||||
emissive = get_socket_from_gltf_material_node(
|
||||
blender_material.node_tree, blender_material.use_nodes, "Emissive")
|
||||
blender_material.node_tree, "Emissive")
|
||||
emissive_texture, uvmap_info, udim_info, _ = gltf2_blender_gather_texture_info.gather_texture_info(
|
||||
emissive, (emissive,), export_settings)
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ from ..search_node_tree import get_socket
|
||||
|
||||
|
||||
def export_ior(blender_material, extensions, export_settings):
|
||||
ior_socket = get_socket(blender_material.node_tree, blender_material.use_nodes, 'IOR')
|
||||
ior_socket = get_socket(blender_material.node_tree, 'IOR')
|
||||
|
||||
if not ior_socket.socket:
|
||||
return None
|
||||
|
||||
@@ -14,9 +14,9 @@ from ..search_node_tree import \
|
||||
def export_sheen(blender_material, export_settings):
|
||||
sheen_extension = {}
|
||||
|
||||
sheenTint_socket = get_socket(blender_material.node_tree, blender_material.use_nodes, "Sheen Tint")
|
||||
sheenRoughness_socket = get_socket(blender_material.node_tree, blender_material.use_nodes, "Sheen Roughness")
|
||||
sheen_socket = get_socket(blender_material.node_tree, blender_material.use_nodes, "Sheen Weight")
|
||||
sheenTint_socket = get_socket(blender_material.node_tree, "Sheen Tint")
|
||||
sheenRoughness_socket = get_socket(blender_material.node_tree, "Sheen Roughness")
|
||||
sheen_socket = get_socket(blender_material.node_tree, "Sheen Weight")
|
||||
|
||||
if sheenTint_socket.socket is None or sheenRoughness_socket.socket is None or sheen_socket.socket is None:
|
||||
return None, {}, {}
|
||||
|
||||
@@ -14,8 +14,8 @@ from ..search_node_tree import \
|
||||
def export_specular(blender_material, export_settings):
|
||||
specular_extension = {}
|
||||
|
||||
specular_socket = get_socket(blender_material.node_tree, blender_material.use_nodes, 'Specular IOR Level')
|
||||
speculartint_socket = get_socket(blender_material.node_tree, blender_material.use_nodes, 'Specular Tint')
|
||||
specular_socket = get_socket(blender_material.node_tree, 'Specular IOR Level')
|
||||
speculartint_socket = get_socket(blender_material.node_tree, 'Specular Tint')
|
||||
|
||||
if specular_socket.socket is None or speculartint_socket.socket is None:
|
||||
return None, {}, {}
|
||||
|
||||
@@ -17,7 +17,7 @@ def export_transmission(blender_material, export_settings):
|
||||
transmission_extension = {}
|
||||
transmission_slots = ()
|
||||
|
||||
transmission_socket = get_socket(blender_material.node_tree, blender_material.use_nodes, 'Transmission Weight')
|
||||
transmission_socket = get_socket(blender_material.node_tree, 'Transmission Weight')
|
||||
|
||||
if transmission_socket.socket is not None and isinstance(
|
||||
transmission_socket.socket,
|
||||
|
||||
@@ -25,13 +25,13 @@ def export_volume(blender_material, export_settings):
|
||||
uvmap_info = {}
|
||||
|
||||
thickness_socket = get_socket_from_gltf_material_node(
|
||||
blender_material.node_tree, blender_material.use_nodes, 'Thickness')
|
||||
blender_material.node_tree, 'Thickness')
|
||||
if thickness_socket.socket is None:
|
||||
# If no thickness (here because there is no glTF Material Output node), no volume extension export
|
||||
return None, {}, {}
|
||||
|
||||
density_socket = get_socket(blender_material.node_tree, blender_material.use_nodes, 'Density', volume=True)
|
||||
attenuation_color_socket = get_socket(blender_material.node_tree, blender_material.use_nodes, 'Color', volume=True)
|
||||
density_socket = get_socket(blender_material.node_tree, 'Density', volume=True)
|
||||
attenuation_color_socket = get_socket(blender_material.node_tree, 'Color', volume=True)
|
||||
# Even if density or attenuation are not set, we export volume extension
|
||||
|
||||
if attenuation_color_socket.socket is not None and isinstance(
|
||||
|
||||
@@ -92,7 +92,7 @@ def gather_material(blender_material, export_settings):
|
||||
emission_strength = max(emissive_factor)
|
||||
emissive_factor = [f / emission_strength for f in emissive_factor]
|
||||
|
||||
alpha_socket = get_socket(blender_material.node_tree, blender_material.use_nodes, "Alpha")
|
||||
alpha_socket = get_socket(blender_material.node_tree, "Alpha")
|
||||
if isinstance(alpha_socket.socket, bpy.types.NodeSocket):
|
||||
alpha_info = gather_alpha_info(alpha_socket.to_node_nav())
|
||||
else:
|
||||
@@ -117,7 +117,7 @@ def gather_material(blender_material, export_settings):
|
||||
|
||||
# Get all textures nodes that are not used in the material
|
||||
if export_settings['gltf_unused_textures'] is True:
|
||||
if blender_material.node_tree and blender_material.use_nodes:
|
||||
if blender_material.node_tree:
|
||||
nodes = get_material_nodes(
|
||||
blender_material.node_tree, [
|
||||
blender_material.node_tree], bpy.types.ShaderNodeTexImage)
|
||||
@@ -305,7 +305,7 @@ def __gather_extensions(blender_material, emissive_factor, export_settings):
|
||||
|
||||
|
||||
def __gather_normal_texture(blender_material, export_settings):
|
||||
normal = get_socket(blender_material.node_tree, blender_material.use_nodes, "Normal")
|
||||
normal = get_socket(blender_material.node_tree, "Normal")
|
||||
normal_texture, uvmap_info, udim_info, _ = gltf2_blender_gather_texture_info.gather_material_normal_texture_info_class(
|
||||
normal, (normal,), export_settings)
|
||||
|
||||
@@ -339,15 +339,15 @@ def __gather_orm_texture(blender_material, export_settings):
|
||||
# Check for the presence of Occlusion, Roughness, Metallic sharing a single image.
|
||||
# If not fully shared, return None, so the images will be cached and processed separately.
|
||||
|
||||
occlusion = get_socket(blender_material.node_tree, blender_material.use_nodes, "Occlusion")
|
||||
occlusion = get_socket(blender_material.node_tree, "Occlusion")
|
||||
if occlusion.socket is None or not has_image_node_from_socket(occlusion, export_settings):
|
||||
occlusion = get_socket_from_gltf_material_node(
|
||||
blender_material.node_tree, blender_material.use_nodes, "Occlusion")
|
||||
blender_material.node_tree, "Occlusion")
|
||||
if occlusion.socket is None or not has_image_node_from_socket(occlusion, export_settings):
|
||||
return None
|
||||
|
||||
metallic_socket = get_socket(blender_material.node_tree, blender_material.use_nodes, "Metallic")
|
||||
roughness_socket = get_socket(blender_material.node_tree, blender_material.use_nodes, "Roughness")
|
||||
metallic_socket = get_socket(blender_material.node_tree, "Metallic")
|
||||
roughness_socket = get_socket(blender_material.node_tree, "Roughness")
|
||||
|
||||
hasMetal = metallic_socket.socket is not None and has_image_node_from_socket(metallic_socket, export_settings)
|
||||
hasRough = roughness_socket.socket is not None and has_image_node_from_socket(roughness_socket, export_settings)
|
||||
@@ -356,7 +356,7 @@ def __gather_orm_texture(blender_material, export_settings):
|
||||
# Using directlty the Blender socket object
|
||||
if not hasMetal and not hasRough:
|
||||
metallic_roughness = get_socket_from_gltf_material_node(
|
||||
blender_material.node_tree, blender_material.use_nodes, "MetallicRoughness")
|
||||
blender_material.node_tree, "MetallicRoughness")
|
||||
if metallic_roughness.socket is None or not has_image_node_from_socket(metallic_roughness, export_settings):
|
||||
return None
|
||||
result = (occlusion, metallic_roughness)
|
||||
@@ -404,10 +404,10 @@ def __gather_orm_texture(blender_material, export_settings):
|
||||
|
||||
|
||||
def __gather_occlusion_texture(blender_material, orm_texture, export_settings):
|
||||
occlusion = get_socket(blender_material.node_tree, blender_material.use_nodes, "Occlusion")
|
||||
occlusion = get_socket(blender_material.node_tree, "Occlusion")
|
||||
if occlusion.socket is None:
|
||||
occlusion = get_socket_from_gltf_material_node(
|
||||
blender_material.node_tree, blender_material.use_nodes, "Occlusion")
|
||||
blender_material.node_tree, "Occlusion")
|
||||
if occlusion.socket is None:
|
||||
return None, {}, {}
|
||||
occlusion_texture, uvmap_info, udim_info, _ = gltf2_blender_gather_texture_info.gather_material_occlusion_texture_info_class(
|
||||
@@ -449,7 +449,6 @@ def __export_unlit(blender_material, export_settings):
|
||||
|
||||
info = gltf2_unlit.detect_shadeless_material(
|
||||
blender_material.node_tree,
|
||||
blender_material.use_nodes,
|
||||
export_settings)
|
||||
if info is None:
|
||||
return None, {}, {"color": None, "alpha": None, "color_type": None, "alpha_type": None, "alpha_mode": "OPAQUE"}, {}
|
||||
|
||||
@@ -61,16 +61,13 @@ def __filter_pbr_material(blender_material, export_settings):
|
||||
|
||||
|
||||
def __gather_base_color_factor(blender_material, export_settings):
|
||||
if not blender_material.use_nodes:
|
||||
return [*blender_material.diffuse_color[:3],
|
||||
1.0], {"color": None, "alpha": None, "color_type": None, "alpha_type": None, "alpha_mode": "OPAQUE"}
|
||||
|
||||
rgb, alpha = None, None
|
||||
vc_info = {"color": None, "alpha": None, "color_type": None, "alpha_type": None, "alpha_mode": "OPAQUE"}
|
||||
|
||||
path_alpha = None
|
||||
path = None
|
||||
alpha_socket = get_socket(blender_material.node_tree, blender_material.use_nodes, "Alpha")
|
||||
alpha_socket = get_socket(blender_material.node_tree, "Alpha")
|
||||
if alpha_socket.socket is not None and isinstance(alpha_socket.socket, bpy.types.NodeSocket):
|
||||
alpha_info = gather_alpha_info(alpha_socket.to_node_nav())
|
||||
vc_info['alpha'] = alpha_info['alphaColorAttrib']
|
||||
@@ -79,12 +76,12 @@ def __gather_base_color_factor(blender_material, export_settings):
|
||||
alpha = alpha_info['alphaFactor']
|
||||
path_alpha = alpha_info['alphaPath']
|
||||
|
||||
base_color_socket = get_socket(blender_material.node_tree, blender_material.use_nodes, "Base Color")
|
||||
base_color_socket = get_socket(blender_material.node_tree, "Base Color")
|
||||
if base_color_socket.socket is None:
|
||||
base_color_socket = get_socket(blender_material.node_tree, blender_material.use_nodes, "BaseColor")
|
||||
base_color_socket = get_socket(blender_material.node_tree, "BaseColor")
|
||||
if base_color_socket.socket is None:
|
||||
base_color_socket = get_socket_from_gltf_material_node(
|
||||
blender_material.node_tree, blender_material.use_nodes, "BaseColorFactor")
|
||||
blender_material.node_tree, "BaseColorFactor")
|
||||
if base_color_socket.socket is not None and isinstance(base_color_socket.socket, bpy.types.NodeSocket):
|
||||
if export_settings['gltf_image_format'] != "NONE":
|
||||
rgb_vc_info = gather_color_info(base_color_socket.to_node_nav())
|
||||
@@ -127,14 +124,14 @@ def __gather_base_color_factor(blender_material, export_settings):
|
||||
|
||||
|
||||
def __gather_base_color_texture(blender_material, export_settings):
|
||||
base_color_socket = get_socket(blender_material.node_tree, blender_material.use_nodes, "Base Color")
|
||||
base_color_socket = get_socket(blender_material.node_tree, "Base Color")
|
||||
if base_color_socket.socket is None:
|
||||
base_color_socket = get_socket(blender_material.node_tree, blender_material.use_nodes, "BaseColor")
|
||||
base_color_socket = get_socket(blender_material.node_tree, "BaseColor")
|
||||
if base_color_socket.socket is None:
|
||||
base_color_socket = get_socket_from_gltf_material_node(
|
||||
blender_material.node_tree, blender_material.use_nodes, "BaseColor")
|
||||
blender_material.node_tree, "BaseColor")
|
||||
|
||||
alpha_socket = get_socket(blender_material.node_tree, blender_material.use_nodes, "Alpha")
|
||||
alpha_socket = get_socket(blender_material.node_tree, "Alpha")
|
||||
|
||||
# keep sockets that have some texture : color and/or alpha
|
||||
inputs = tuple(
|
||||
@@ -172,13 +169,11 @@ def __gather_extras(blender_material, export_settings):
|
||||
|
||||
|
||||
def __gather_metallic_factor(blender_material, export_settings):
|
||||
if not blender_material.use_nodes:
|
||||
return blender_material.metallic
|
||||
|
||||
metallic_socket = get_socket(blender_material.node_tree, blender_material.use_nodes, "Metallic")
|
||||
metallic_socket = get_socket(blender_material.node_tree, "Metallic")
|
||||
if metallic_socket.socket is None:
|
||||
metallic_socket = get_socket_from_gltf_material_node(
|
||||
blender_material.node_tree, blender_material.use_nodes, "MetallicFactor")
|
||||
blender_material.node_tree, "MetallicFactor")
|
||||
if metallic_socket.socket is not None and isinstance(metallic_socket.socket, bpy.types.NodeSocket):
|
||||
fac, path = get_factor_from_socket(metallic_socket, kind='VALUE')
|
||||
|
||||
@@ -195,8 +190,8 @@ def __gather_metallic_factor(blender_material, export_settings):
|
||||
|
||||
|
||||
def __gather_metallic_roughness_texture(blender_material, orm_texture, export_settings):
|
||||
metallic_socket = get_socket(blender_material.node_tree, blender_material.use_nodes, "Metallic")
|
||||
roughness_socket = get_socket(blender_material.node_tree, blender_material.use_nodes, "Roughness")
|
||||
metallic_socket = get_socket(blender_material.node_tree, "Metallic")
|
||||
roughness_socket = get_socket(blender_material.node_tree, "Roughness")
|
||||
|
||||
hasMetal = metallic_socket.socket is not None and has_image_node_from_socket(metallic_socket, export_settings)
|
||||
hasRough = roughness_socket.socket is not None and has_image_node_from_socket(roughness_socket, export_settings)
|
||||
@@ -205,7 +200,7 @@ def __gather_metallic_roughness_texture(blender_material, orm_texture, export_se
|
||||
# Using directlty the Blender socket object
|
||||
if not hasMetal and not hasRough:
|
||||
metallic_roughness = get_socket_from_gltf_material_node(
|
||||
blender_material.node_tree, blender_material.use_nodes, "MetallicRoughness")
|
||||
blender_material.node_tree, "MetallicRoughness")
|
||||
if metallic_roughness.socket is None or not has_image_node_from_socket(metallic_roughness, export_settings):
|
||||
return None, {}, {}, None
|
||||
else:
|
||||
@@ -231,13 +226,11 @@ def __gather_metallic_roughness_texture(blender_material, orm_texture, export_se
|
||||
|
||||
|
||||
def __gather_roughness_factor(blender_material, export_settings):
|
||||
if not blender_material.use_nodes:
|
||||
return blender_material.roughness
|
||||
|
||||
roughness_socket = get_socket(blender_material.node_tree, blender_material.use_nodes, "Roughness")
|
||||
roughness_socket = get_socket(blender_material.node_tree, "Roughness")
|
||||
if roughness_socket is None:
|
||||
roughness_socket = get_socket_from_gltf_material_node(
|
||||
blender_material.node_tree, blender_material.use_nodes, "RoughnessFactor")
|
||||
blender_material.node_tree, "RoughnessFactor")
|
||||
if roughness_socket.socket is not None and isinstance(roughness_socket.socket, bpy.types.NodeSocket):
|
||||
fac, path = get_factor_from_socket(roughness_socket, kind='VALUE')
|
||||
|
||||
|
||||
@@ -179,7 +179,7 @@ def get_material_nodes(node_tree: bpy.types.NodeTree, group_path, type):
|
||||
return nodes
|
||||
|
||||
|
||||
def get_socket_from_gltf_material_node(blender_material_nodetree, use_nodes: bool, name: str):
|
||||
def get_socket_from_gltf_material_node(blender_material_nodetree, name: str):
|
||||
"""
|
||||
For a given material input name, retrieve the corresponding node tree socket in the special glTF node group.
|
||||
|
||||
@@ -188,7 +188,7 @@ def get_socket_from_gltf_material_node(blender_material_nodetree, use_nodes: boo
|
||||
:return: a blender NodeSocket
|
||||
"""
|
||||
gltf_node_group_names = [get_gltf_node_name().lower(), get_gltf_node_old_name().lower()]
|
||||
if blender_material_nodetree and use_nodes:
|
||||
if blender_material_nodetree:
|
||||
nodes = get_material_nodes(blender_material_nodetree, [blender_material_nodetree], bpy.types.ShaderNodeGroup)
|
||||
# Some weird node groups with missing datablock can have no node_tree, so checking n.node_tree (See #1797)
|
||||
nodes = [n for n in nodes if n[0].node_tree is not None and any(
|
||||
@@ -758,7 +758,7 @@ def get_node_socket(blender_material_node_tree, type, name):
|
||||
return NodeSocket(None, None)
|
||||
|
||||
|
||||
def get_socket(blender_material_nodetree, use_nodes: bool, name: str, volume=False):
|
||||
def get_socket(blender_material_nodetree, name: str, volume=False):
|
||||
"""
|
||||
For a given material input name, retrieve the corresponding node tree socket.
|
||||
|
||||
@@ -766,7 +766,7 @@ def get_socket(blender_material_nodetree, use_nodes: bool, name: str, volume=Fal
|
||||
:param name: the name of the socket
|
||||
:return: a blender NodeSocket
|
||||
"""
|
||||
if blender_material_nodetree and use_nodes:
|
||||
if blender_material_nodetree:
|
||||
# i = [input for input in blender_material.node_tree.inputs]
|
||||
# o = [output for output in blender_material.node_tree.outputs]
|
||||
if name == "Emissive":
|
||||
|
||||
@@ -188,7 +188,7 @@ def __gather_sampler(blender_shader_sockets, export_settings):
|
||||
if len(first_valid_shader_node.group_path) > 0:
|
||||
# Retrieving the blender material using this shader tree
|
||||
for mat in bpy.data.materials:
|
||||
if mat.use_nodes is True and id(mat.node_tree) == id(first_valid_shader_node.group_path[0].original):
|
||||
if id(mat.node_tree) == id(first_valid_shader_node.group_path[0].original):
|
||||
group_path_str += mat.name # TODO if linked, we can have multiple materials with same name...
|
||||
break
|
||||
if len(first_valid_shader_node.group_path) > 1:
|
||||
|
||||
@@ -13,16 +13,14 @@ from .search_node_tree import \
|
||||
gather_color_info
|
||||
|
||||
|
||||
def detect_shadeless_material(blender_material_node_tree, use_nodes, export_settings):
|
||||
def detect_shadeless_material(blender_material_node_tree, export_settings):
|
||||
"""Detect if this material is "shadeless" ie. should be exported
|
||||
with KHR_materials_unlit. Returns None if not. Otherwise, returns
|
||||
a dict with info from parsing the node tree.
|
||||
"""
|
||||
if not use_nodes:
|
||||
return None
|
||||
|
||||
# Old Background node detection (unlikely to happen)
|
||||
bg_socket = get_socket(blender_material_node_tree, use_nodes, "Background")
|
||||
bg_socket = get_socket(blender_material_node_tree, "Background")
|
||||
if bg_socket.socket is not None:
|
||||
return {'rgb_socket': bg_socket}
|
||||
|
||||
|
||||
@@ -202,7 +202,7 @@ class BlenderPointerAnim():
|
||||
pointer_tab[3] in ["emissiveFactor", "alphaCutoff"]:
|
||||
|
||||
if pointer_tab[3] == "emissiveFactor":
|
||||
emissive_socket = get_socket(asset.blender_nodetree, True, "Emissive")
|
||||
emissive_socket = get_socket(asset.blender_nodetree, "Emissive")
|
||||
if emissive_socket.socket.is_linked:
|
||||
# We need to find the correct node value to animate (An Emissive Factor node)
|
||||
mix_node = emissive_socket.socket.links[0].from_node
|
||||
@@ -224,7 +224,7 @@ class BlenderPointerAnim():
|
||||
pointer_tab[3] == "normalTexture" and \
|
||||
pointer_tab[4] == "scale":
|
||||
|
||||
normal_socket = get_socket(asset.blender_nodetree, True, "Normal")
|
||||
normal_socket = get_socket(asset.blender_nodetree, "Normal")
|
||||
if normal_socket.socket.is_linked:
|
||||
normal_node = normal_socket.socket.links[0].from_node
|
||||
if normal_node.type == "NORMAL_MAP":
|
||||
@@ -236,9 +236,9 @@ class BlenderPointerAnim():
|
||||
pointer_tab[3] == "occlusionTexture" and \
|
||||
pointer_tab[4] == "strength":
|
||||
|
||||
occlusion_socket = get_socket(asset.blender_nodetree, True, "Occlusion")
|
||||
occlusion_socket = get_socket(asset.blender_nodetree, "Occlusion")
|
||||
if occlusion_socket.socket is None:
|
||||
occlusion_socket = get_socket_from_gltf_material_node(asset.blender_mat.node_tree, True, "Occlusion")
|
||||
occlusion_socket = get_socket_from_gltf_material_node(asset.blender_mat.node_tree, "Occlusion")
|
||||
if occlusion_socket.socket.is_linked:
|
||||
mix_node = occlusion_socket.socket.links[0].from_node
|
||||
if mix_node.type == "MIX":
|
||||
@@ -261,7 +261,7 @@ class BlenderPointerAnim():
|
||||
# This can be regular PBR, or unlit
|
||||
if is_unlit is False:
|
||||
|
||||
base_color_socket = get_socket(asset.blender_nodetree, True, "Base Color")
|
||||
base_color_socket = get_socket(asset.blender_nodetree, "Base Color")
|
||||
if base_color_socket.socket.is_linked:
|
||||
# We need to find the correct node value to animate (An Mix Factor node)
|
||||
mix_node = base_color_socket.links[0].from_node
|
||||
@@ -276,7 +276,7 @@ class BlenderPointerAnim():
|
||||
num_components = 3 # Do not use alpha here, will be managed later
|
||||
|
||||
else:
|
||||
unlit_info = detect_shadeless_material(asset.blender_nodetree, True, {})
|
||||
unlit_info = detect_shadeless_material(asset.blender_nodetree, {})
|
||||
if 'rgb_socket' in unlit_info:
|
||||
socket = unlit_info['rgb_socket']
|
||||
blender_path = socket.socket.path_from_id() + ".default_value"
|
||||
@@ -286,7 +286,7 @@ class BlenderPointerAnim():
|
||||
socket = NodeSocket(None, None)
|
||||
|
||||
if pointer_tab[4] == "roughnessFactor":
|
||||
roughness_socket = get_socket(asset.blender_nodetree, True, "Roughness")
|
||||
roughness_socket = get_socket(asset.blender_nodetree, "Roughness")
|
||||
if roughness_socket.socket.is_linked:
|
||||
# We need to find the correct node value to animate (An Mix Factor node)
|
||||
mix_node = roughness_socket.links[0].from_node
|
||||
@@ -302,7 +302,7 @@ class BlenderPointerAnim():
|
||||
num_components = 1
|
||||
|
||||
if pointer_tab[4] == "metallicFactor":
|
||||
metallic_socket = get_socket(asset.blender_nodetree, True, "Metallic")
|
||||
metallic_socket = get_socket(asset.blender_nodetree, "Metallic")
|
||||
if metallic_socket.socket.is_linked:
|
||||
# We need to find the correct node value to animate (An Mix Factor node)
|
||||
mix_node = metallic_socket.links[0].from_node
|
||||
@@ -326,41 +326,41 @@ class BlenderPointerAnim():
|
||||
if pointer_tab[-4] == "baseColorTexture":
|
||||
# This can be regular PBR, or unlit
|
||||
if is_unlit is False:
|
||||
socket = get_socket(asset['blender_nodetree'], True, "Base Color")
|
||||
socket = get_socket(asset['blender_nodetree'], "Base Color")
|
||||
else:
|
||||
unlit_info = detect_shadeless_material(asset['blender_nodetree'], True, {})
|
||||
unlit_info = detect_shadeless_material(asset['blender_nodetree'], {})
|
||||
if 'rgb_socket' in unlit_info:
|
||||
socket = unlit_info['rgb_socket']
|
||||
else:
|
||||
socket = NodeSocket(None, None)
|
||||
elif pointer_tab[-4] == "emissiveTexture":
|
||||
socket = get_socket(asset.blender_nodetree, True, "Emission Color")
|
||||
socket = get_socket(asset.blender_nodetree, "Emission Color")
|
||||
elif pointer_tab[-4] == "normalTexture":
|
||||
socket = get_socket(asset.blender_nodetree, True, "Normal")
|
||||
socket = get_socket(asset.blender_nodetree, "Normal")
|
||||
elif pointer_tab[-4] == "occlusionTexture":
|
||||
socket = get_socket(asset.blender_nodetree, True, "Occlusion")
|
||||
socket = get_socket(asset.blender_nodetree, "Occlusion")
|
||||
if socket is None:
|
||||
socket = get_socket_from_gltf_material_node(asset.blender_nodetree, True, "Occlusion")
|
||||
socket = get_socket_from_gltf_material_node(asset.blender_nodetree, "Occlusion")
|
||||
elif pointer_tab[-4] == "metallicRoughnessTexture":
|
||||
socket = get_socket(asset.blender_nodetree, True, "Roughness")
|
||||
socket = get_socket(asset.blender_nodetree, "Roughness")
|
||||
elif pointer_tab[-4] == "specularTexture":
|
||||
socket = get_socket(asset['blender_nodetree'], True, "Specular IOR Level")
|
||||
socket = get_socket(asset['blender_nodetree'], "Specular IOR Level")
|
||||
elif pointer_tab[-4] == "specularColorTexture":
|
||||
socket = get_socket(asset['blender_nodetree'], True, "Specular Tint")
|
||||
socket = get_socket(asset['blender_nodetree'], "Specular Tint")
|
||||
elif pointer_tab[-4] == "sheenColorTexture":
|
||||
socket = get_socket(asset['blender_nodetree'], True, "Sheen Tint")
|
||||
socket = get_socket(asset['blender_nodetree'], "Sheen Tint")
|
||||
elif pointer_tab[-4] == "sheenRoughnessTexture":
|
||||
socket = get_socket(asset['blender_nodetree'], True, "Sheen Roughness")
|
||||
socket = get_socket(asset['blender_nodetree'], "Sheen Roughness")
|
||||
elif pointer_tab[-4] == "clearcoatTexture":
|
||||
socket = get_socket(asset['blender_nodetree'], True, "Coat Weight")
|
||||
socket = get_socket(asset['blender_nodetree'], "Coat Weight")
|
||||
elif pointer_tab[-4] == "clearcoatRoughnessTexture":
|
||||
socket = get_socket(asset['blender_nodetree'], True, "Coat Roughness")
|
||||
socket = get_socket(asset['blender_nodetree'], "Coat Roughness")
|
||||
elif pointer_tab[-4] == "clearcoatNormalTexture":
|
||||
socket = get_socket(asset['blender_nodetree'], True, "Coat Normal")
|
||||
socket = get_socket(asset['blender_nodetree'], "Coat Normal")
|
||||
elif pointer_tab[-4] == "thicknessTexture":
|
||||
socket = get_socket_from_gltf_material_node(asset['blender_nodetree'], True, "Thickness")
|
||||
socket = get_socket_from_gltf_material_node(asset['blender_nodetree'], "Thickness")
|
||||
elif pointer_tab[-4] == "transmissionTexture":
|
||||
socket = get_socket(asset['blender_nodetree'], True, "Transmission Weight")
|
||||
socket = get_socket(asset['blender_nodetree'], "Transmission Weight")
|
||||
else:
|
||||
print("Some Texture are not managed for KHR_animation_pointer / KHR_texture_transform")
|
||||
|
||||
@@ -429,7 +429,7 @@ class BlenderPointerAnim():
|
||||
pointer_tab[4] == "KHR_materials_emissive_strength" and \
|
||||
pointer_tab[5] == "emissiveStrength":
|
||||
|
||||
socket = get_socket(asset['blender_nodetree'], True, "Emission Strength")
|
||||
socket = get_socket(asset['blender_nodetree'], "Emission Strength")
|
||||
blender_path = socket.socket.path_from_id() + ".default_value"
|
||||
group_name = 'Material'
|
||||
num_components = 1
|
||||
@@ -440,7 +440,7 @@ class BlenderPointerAnim():
|
||||
pointer_tab[5] in ["thicknessFactor", "attenuationDistance", "attenuationColor"]:
|
||||
|
||||
if pointer_tab[5] == "thicknessFactor":
|
||||
thicknesss_socket = get_socket_from_gltf_material_node(asset['blender_nodetree'], True, 'Thickness')
|
||||
thicknesss_socket = get_socket_from_gltf_material_node(asset['blender_nodetree'], 'Thickness')
|
||||
if thicknesss_socket.socket.is_linked:
|
||||
mix_node = thicknesss_socket.socket.links[0].from_node
|
||||
if mix_node.type == "MATH":
|
||||
@@ -455,7 +455,7 @@ class BlenderPointerAnim():
|
||||
num_components = 1
|
||||
|
||||
if pointer_tab[5] == "attenuationDistance":
|
||||
density_socket = get_socket(asset['blender_nodetree'], True, 'Density', volume=True)
|
||||
density_socket = get_socket(asset['blender_nodetree'], 'Density', volume=True)
|
||||
blender_path = density_socket.socket.path_from_id() + ".default_value"
|
||||
group_name = 'Material'
|
||||
num_components = 1
|
||||
@@ -465,7 +465,7 @@ class BlenderPointerAnim():
|
||||
values[idx] = [1.0 / old_values[idx][0]]
|
||||
|
||||
if pointer_tab[5] == "attenuationColor":
|
||||
attenuation_color_socket = get_socket(asset['blender_nodetree'], True, 'Color', volume=True)
|
||||
attenuation_color_socket = get_socket(asset['blender_nodetree'], 'Color', volume=True)
|
||||
blender_path = attenuation_color_socket.socket.path_from_id() + ".default_value"
|
||||
group_name = 'Material'
|
||||
num_components = 3
|
||||
@@ -475,7 +475,7 @@ class BlenderPointerAnim():
|
||||
pointer_tab[4] == "KHR_materials_ior" and \
|
||||
pointer_tab[5] == "ior":
|
||||
|
||||
ior_socket = get_socket(asset['blender_nodetree'], True, 'IOR')
|
||||
ior_socket = get_socket(asset['blender_nodetree'], 'IOR')
|
||||
blender_path = ior_socket.socket.path_from_id() + ".default_value"
|
||||
group_name = 'Material'
|
||||
num_components = 1
|
||||
@@ -485,7 +485,7 @@ class BlenderPointerAnim():
|
||||
pointer_tab[4] == "KHR_materials_transmission" and \
|
||||
pointer_tab[5] == "transmissionFactor":
|
||||
|
||||
transmission_socket = get_socket(asset['blender_nodetree'], True, 'Transmission Weight')
|
||||
transmission_socket = get_socket(asset['blender_nodetree'], 'Transmission Weight')
|
||||
if transmission_socket.socket.is_linked:
|
||||
mix_node = transmission_socket.links[0].from_node
|
||||
if mix_node.type == "MATH":
|
||||
@@ -505,7 +505,7 @@ class BlenderPointerAnim():
|
||||
pointer_tab[5] == "clearcoatNormalTexture" and \
|
||||
pointer_tab[6] == "scale":
|
||||
result = from_socket(
|
||||
get_socket(asset['blender_nodetree'], True, 'Coat Normal'),
|
||||
get_socket(asset['blender_nodetree'], 'Coat Normal'),
|
||||
FilterByType(bpy.types.ShaderNodeNormalMap))
|
||||
if result:
|
||||
blender_path = result[0].shader_node.inputs['Strength'].path_from_id() + ".default_value"
|
||||
@@ -516,7 +516,7 @@ class BlenderPointerAnim():
|
||||
pointer_tab[3] == "extensions" and \
|
||||
pointer_tab[4] == "KHR_materials_clearcoat" and \
|
||||
pointer_tab[5] == "clearcoatFactor":
|
||||
clearcoat_socket = get_socket(asset['blender_nodetree'], True, 'Coat Weight')
|
||||
clearcoat_socket = get_socket(asset['blender_nodetree'], 'Coat Weight')
|
||||
if clearcoat_socket.socket.is_linked:
|
||||
mix_node = clearcoat_socket.socket.links[0].from_node
|
||||
if mix_node.type == "MATH":
|
||||
@@ -534,7 +534,7 @@ class BlenderPointerAnim():
|
||||
pointer_tab[3] == "extensions" and \
|
||||
pointer_tab[4] == "KHR_materials_clearcoat" and \
|
||||
pointer_tab[5] == "clearcoatRoughnessFactor":
|
||||
clearcoat_roughness_socket = get_socket(asset['blender_nodetree'], True, 'Coat Roughness')
|
||||
clearcoat_roughness_socket = get_socket(asset['blender_nodetree'], 'Coat Roughness')
|
||||
if clearcoat_roughness_socket.socket.is_linked:
|
||||
mix_node = clearcoat_roughness_socket.socket.links[0].from_node
|
||||
if mix_node.type == "MATH":
|
||||
@@ -552,7 +552,7 @@ class BlenderPointerAnim():
|
||||
pointer_tab[3] == "extensions" and \
|
||||
pointer_tab[4] == "KHR_materials_sheen" and \
|
||||
pointer_tab[5] == "sheenColorFactor":
|
||||
sheen_color_socket = get_socket(asset['blender_nodetree'], True, 'Sheen Tint')
|
||||
sheen_color_socket = get_socket(asset['blender_nodetree'], 'Sheen Tint')
|
||||
if sheen_color_socket.socket.is_linked:
|
||||
mix_node = sheen_color_socket.socket.links[0].from_node
|
||||
if mix_node.type == "MIX":
|
||||
@@ -570,7 +570,7 @@ class BlenderPointerAnim():
|
||||
pointer_tab[3] == "extensions" and \
|
||||
pointer_tab[4] == "KHR_materials_sheen" and \
|
||||
pointer_tab[5] == "sheenRoughnessFactor":
|
||||
sheen_roughness_socket = get_socket(asset['blender_nodetree'], True, 'Sheen Roughness')
|
||||
sheen_roughness_socket = get_socket(asset['blender_nodetree'], 'Sheen Roughness')
|
||||
if sheen_roughness_socket.socket.is_linked:
|
||||
mix_node = sheen_roughness_socket.socket.links[0].from_node
|
||||
if mix_node.type == "MATH":
|
||||
@@ -588,7 +588,7 @@ class BlenderPointerAnim():
|
||||
pointer_tab[3] == "extensions" and \
|
||||
pointer_tab[4] == "KHR_materials_specular" and \
|
||||
pointer_tab[5] == "specularFactor":
|
||||
specular_socket = get_socket(asset['blender_nodetree'], True, 'Specular IOR Level')
|
||||
specular_socket = get_socket(asset['blender_nodetree'], 'Specular IOR Level')
|
||||
if specular_socket.socket.is_linked:
|
||||
mix_node = specular_socket.socket.links[0].from_node
|
||||
if mix_node.type == "MATH":
|
||||
@@ -610,7 +610,7 @@ class BlenderPointerAnim():
|
||||
pointer_tab[3] == "extensions" and \
|
||||
pointer_tab[4] == "KHR_materials_specular" and \
|
||||
pointer_tab[5] == "specularColorFactor":
|
||||
specular_color_socket = get_socket(asset['blender_nodetree'], True, 'Specular Tint')
|
||||
specular_color_socket = get_socket(asset['blender_nodetree'], 'Specular Tint')
|
||||
if specular_color_socket.socket.is_linked:
|
||||
mix_node = specular_color_socket.socket.links[0].from_node
|
||||
if mix_node.type == "MIX":
|
||||
@@ -628,7 +628,7 @@ class BlenderPointerAnim():
|
||||
pointer_tab[3] == "extensions" and \
|
||||
pointer_tab[4] == "KHR_materials_anisotropy" and \
|
||||
pointer_tab[5] == "anisotropyStrength":
|
||||
anisotropy_socket = get_socket(asset['blender_nodetree'], True, 'Anisotropic')
|
||||
anisotropy_socket = get_socket(asset['blender_nodetree'], 'Anisotropic')
|
||||
if anisotropy_socket.socket.is_linked:
|
||||
mix_node = anisotropy_socket.socket.links[0].from_node
|
||||
if mix_node.type == "MATH":
|
||||
@@ -646,7 +646,7 @@ class BlenderPointerAnim():
|
||||
pointer_tab[3] == "extensions" and \
|
||||
pointer_tab[4] == "KHR_materials_anisotropy" and \
|
||||
pointer_tab[5] == "anisotropyRotation":
|
||||
anisotropy_rotation_socket = get_socket(asset['blender_nodetree'], True, 'Anisotropic Rotation')
|
||||
anisotropy_rotation_socket = get_socket(asset['blender_nodetree'], 'Anisotropic Rotation')
|
||||
if anisotropy_rotation_socket.socket.is_linked:
|
||||
mix_node = anisotropy_rotation_socket.socket.links[0].from_node
|
||||
if mix_node.type == "MATH":
|
||||
@@ -687,9 +687,9 @@ class BlenderPointerAnim():
|
||||
pointer_tab[4] == "baseColorFactor":
|
||||
|
||||
if is_unlit is False:
|
||||
alpha_socket = get_socket(asset.blender_nodetree, True, "Alpha")
|
||||
alpha_socket = get_socket(asset.blender_nodetree, "Alpha")
|
||||
else:
|
||||
unlit_info = detect_shadeless_material(asset.blender_nodetree, True, {})
|
||||
unlit_info = detect_shadeless_material(asset.blender_nodetree, {})
|
||||
if 'alpha_socket' in unlit_info:
|
||||
alpha_socket = unlit_info['alpha_socket']
|
||||
if alpha_socket.socket.is_linked:
|
||||
|
||||
@@ -23,8 +23,7 @@ class BlenderMaterial():
|
||||
if material_idx is None:
|
||||
# If no material is specified, we create a default one
|
||||
mat = bpy.data.materials.new(name="DefaultMaterial")
|
||||
mat.use_nodes = True
|
||||
mat.node_tree.nodes.clear()
|
||||
# Since Blender 5.0, no need to remove default nodes, as they are not created by default
|
||||
output_node = mat.node_tree.nodes.new(type='ShaderNodeOutputMaterial')
|
||||
output_node.location = (0, 0)
|
||||
shader_node = mat.node_tree.nodes.new(type='ShaderNodeBsdfPrincipled')
|
||||
@@ -54,9 +53,7 @@ class BlenderMaterial():
|
||||
BlenderMaterial.set_eevee_surface_render_method(pymaterial, mat)
|
||||
BlenderMaterial.set_viewport_color(pymaterial, mat, vertex_color)
|
||||
|
||||
mat.use_nodes = True
|
||||
while mat.node_tree.nodes: # clear all nodes
|
||||
mat.node_tree.nodes.remove(mat.node_tree.nodes[0])
|
||||
# Since Blender 5.0, no need to remove default nodes, as they are not created by default
|
||||
|
||||
mh = MaterialHelper(gltf, pymaterial, mat, vertex_color)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user