From 00f9946c9f1d27fd313ed31e95e3ed9aed898291 Mon Sep 17 00:00:00 2001 From: Lila Date: Wed, 18 Sep 2024 16:12:37 +0100 Subject: [PATCH] F3D_MAT_CUR_VERSION --- fast64_internal/f3d/glTF/f3d_gltf.py | 14 ++++++++++++++ gltf_extension.py | 14 +------------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/fast64_internal/f3d/glTF/f3d_gltf.py b/fast64_internal/f3d/glTF/f3d_gltf.py index 3a7cb2376..c309291f8 100644 --- a/fast64_internal/f3d/glTF/f3d_gltf.py +++ b/fast64_internal/f3d/glTF/f3d_gltf.py @@ -12,6 +12,7 @@ get_gltf_settings, is_import_context, prefix_function, + GLTF2_ADDON_VERSION, ) from ..f3d_gbi import F3D, get_F3D_GBI from ..f3d_material import ( @@ -28,6 +29,7 @@ F3DMaterialProperty, RDPSettings, TextureProperty, + F3D_MAT_CUR_VERSION, ) from ..f3d_material_helpers import node_tree_copy from ..f3d_writer import cel_shading_checks, check_face_materials, getColorLayer @@ -882,6 +884,18 @@ def draw(self, context: Context): get_gltf_settings(context).f3d.draw_props(self.layout, is_import_context(context)) +def set_use_nodes_in_f3d_materials(use: bool): + """ + HACK: For 4.1 and 4.2 we need to disable all F3D nodes, + otherwise an infinite recursion occurs in texture gathering + this is also called in gather_gltf_extensions_hook (glTF2_post_export_callback can fail) + """ + if GLTF2_ADDON_VERSION >= (4, 1, 0): + for mat in bpy.data.materials: + if mat.is_f3d and mat.mat_ver == F3D_MAT_CUR_VERSION: + mat.use_nodes = use + + def gather_mesh_hook(blender_mesh: Mesh, *args): """HACK: Runs right before the actual gather_mesh func in the addon, we need to join col and alpha""" print("F3D glTF: Applying alpha") diff --git a/gltf_extension.py b/gltf_extension.py index 95d5101a2..a14196e3b 100644 --- a/gltf_extension.py +++ b/gltf_extension.py @@ -5,7 +5,7 @@ from .fast64_internal.utility import multilineLabel, prop_group_to_json, json_to_prop_group from .fast64_internal.gltf_utility import GLTF2_ADDON_VERSION, get_gltf_settings -from .fast64_internal.f3d.glTF.f3d_gltf import F3DGlTFSettings, F3DGlTFPanel, F3DExtensions +from .fast64_internal.f3d.glTF.f3d_gltf import F3DGlTFSettings, F3DGlTFPanel, F3DExtensions, set_use_nodes_in_f3d_materials # Original implementation from github.com/Mr-Wiseguy/gltf64-blender @@ -17,18 +17,6 @@ # Doesn´t use world defaults, as those should be left to the repo to handle. -def set_use_nodes_in_f3d_materials(use: bool): - """ - HACK: For 4.1 and 4.2 we need to disable all F3D nodes, - otherwise an infinite recursion occurs in texture gathering - this is also called in gather_gltf_extensions_hook (glTF2_post_export_callback can fail) - """ - if GLTF2_ADDON_VERSION >= (4, 1, 0): - for mat in bpy.data.materials: - if mat.is_f3d and mat.mat_ver == 5: - mat.use_nodes = use - - def glTF2_pre_export_callback(_gltf): set_use_nodes_in_f3d_materials(False)