Skip to content

Commit

Permalink
F3D_MAT_CUR_VERSION
Browse files Browse the repository at this point in the history
  • Loading branch information
Lilaa3 committed Sep 18, 2024
1 parent 8dd5b6b commit 00f9946
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
14 changes: 14 additions & 0 deletions fast64_internal/f3d/glTF/f3d_gltf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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
Expand Down Expand Up @@ -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")
Expand Down
14 changes: 1 addition & 13 deletions gltf_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)

Expand Down

0 comments on commit 00f9946

Please sign in to comment.