Skip to content

Commit

Permalink
clean up imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Lilaa3 committed Sep 20, 2024
1 parent d555147 commit 5a38d48
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
15 changes: 8 additions & 7 deletions fast64_internal/f3d/glTF/f3d_gltf.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import copy
from dataclasses import dataclass
from math import ceil, floor
import copy
import bpy
from bpy.types import NodeTree, Object, Mesh, Material, Context, Panel, PropertyGroup, UILayout
from bpy.props import BoolProperty
import numpy as np

from io_scene_gltf2.io.com import gltf2_io # pylint: disable=import-error
from io_scene_gltf2.blender.imp.gltf2_blender_image import BlenderImage # pylint: disable=import-error
from io_scene_gltf2.io.com.gltf2_io_constants import TextureFilter, TextureWrap # pylint: disable=import-error

from bpy.types import NodeTree, Mesh, Material, Context, Panel, PropertyGroup, UILayout
from bpy.props import BoolProperty

from ...utility import (
json_to_prop_group,
multilineLabel,
Expand Down Expand Up @@ -46,10 +51,6 @@
from ..f3d_writer import cel_shading_checks, check_face_materials, getColorLayer
from ..f3d_texture_writer import UVtoSTLarge

from io_scene_gltf2.io.com import gltf2_io # pylint: disable=import-error
from io_scene_gltf2.blender.imp.gltf2_blender_image import BlenderImage # pylint: disable=import-error
from io_scene_gltf2.io.com.gltf2_io_constants import TextureFilter, TextureWrap # pylint: disable=import-error

MATERIAL_EXTENSION_NAME = "FAST64_materials_n64"
F3D_MATERIAL_EXTENSION_NAME = "FAST64_materials_f3d"
EX1_MATERIAL_EXTENSION_NAME = "FAST64_materials_f3dlx"
Expand Down
49 changes: 24 additions & 25 deletions fast64_internal/gltf_utility.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
from pprint import pprint
import functools
from typing import Callable
import functools

import addon_utils
import bpy
from bpy.types import Image


def find_glTF2_addon():
for mod in addon_utils.modules():
for mod in addon_utils.modules(): # pylint: disable=not-an-iterable
if mod.__name__ == "io_scene_gltf2":
return mod
else:
raise ValueError("glTF2 addon not found")
raise ValueError("glTF2 addon not found")


GLTF2_ADDDON = find_glTF2_addon()
GLTF2_ADDON_VERSION = GLTF2_ADDDON.bl_info.get("version", (-1, -1, -1))

if GLTF2_ADDON_VERSION >= (3, 6, 0):
if GLTF2_ADDON_VERSION:
from io_scene_gltf2.blender.exp.material.gltf2_blender_gather_image import (
from io_scene_gltf2.blender.exp.material.gltf2_blender_gather_image import ( # pylint: disable=import-error
__is_blender_image_a_webp,
) # pylint: disable=import-error
)
from io_scene_gltf2.blender.exp.material.gltf2_blender_gather_image import ( # pylint: disable=import-error
__gather_name,
__make_image,
__gather_uri,
__gather_buffer_view,
__is_blender_image_a_jpeg,
)
from io_scene_gltf2.blender.exp.material.extensions.gltf2_blender_image import (
from io_scene_gltf2.blender.exp.material.extensions.gltf2_blender_image import ( # pylint: disable=import-error
ExportImage,
) # pylint: disable=import-error
)
else:
from io_scene_gltf2.blender.exp.gltf2_blender_gather_image import ( # pylint: disable=import-error
__gather_name,
Expand Down Expand Up @@ -134,38 +133,38 @@ def is_import_context(context):
return context.space_data.active_operator.bl_idname == "IMPORT_SCENE_OT_gltf"


def prefix_function(function: Callable, prefunction: Callable):
function = getattr(function, "fast64_og_func", function)
def prefix_function(original: Callable, prefix: Callable):
original = getattr(original, "fast64_og_func", original)

@functools.wraps(function)
@functools.wraps(original)
def run(*args, **kwargs):
prefunction(*args, **kwargs)
return function(*args, **kwargs)
prefix(*args, **kwargs)
return original(*args, **kwargs)

setattr(run, "fast64_og_func", function)
setattr(run, "fast64_og_func", original)
return run


def suffix_function(function: Callable, suffix_function: Callable):
def suffix_function(original: Callable, suffix: Callable):
"""Passes in result as the first arg"""
function = getattr(function, "fast64_og_func", function)
original = getattr(original, "fast64_og_func", original)

@functools.wraps(function)
@functools.wraps(original)
def run(*args, **kwargs):
results = function(*args, **kwargs)
return suffix_function(results, *args, **kwargs)
results = original(*args, **kwargs)
return suffix(results, *args, **kwargs)

setattr(run, "fast64_og_func", function)
setattr(run, "fast64_og_func", original)
return run


def swap_function(function: Callable, new_function: Callable):
def swap_function(original: Callable, new: Callable):
"""Passes in the original function as the first arg"""
function = getattr(function, "fast64_og_func", function)
original = getattr(original, "fast64_og_func", original)

@functools.wraps(function)
@functools.wraps(original)
def run(*args, **kwargs):
return new_function(function, *args, **kwargs)
return new(original, *args, **kwargs)

setattr(run, "fast64_og_func", function)
setattr(run, "fast64_og_func", original)
return run

0 comments on commit 5a38d48

Please sign in to comment.