Skip to content

Commit

Permalink
Ui and refactor f3d.__init.py__
Browse files Browse the repository at this point in the history
To reduce main __init.py__ bloat
  • Loading branch information
Lilaa3 committed Oct 7, 2024
1 parent 7cdb920 commit ea9dc68
Show file tree
Hide file tree
Showing 8 changed files with 212 additions and 234 deletions.
96 changes: 6 additions & 90 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from . import addon_updater_ops

from .fast64_internal.utility import prop_split, multilineLabel, draw_and_check_tab
from .fast64_internal.utility import prop_split

from .fast64_internal.repo_settings import (
draw_repo_settings,
Expand All @@ -26,26 +26,9 @@

from .fast64_internal.mk64 import MK64_Properties, mk64_register, mk64_unregister

from .fast64_internal.f3d.f3d_material import (
F3D_MAT_CUR_VERSION,
mat_register,
mat_unregister,
check_or_ask_color_management,
)
from .fast64_internal.f3d.f3d_render_engine import render_engine_register, render_engine_unregister
from .fast64_internal.f3d.f3d_writer import f3d_writer_register, f3d_writer_unregister
from .fast64_internal.f3d.f3d_parser import f3d_parser_register, f3d_parser_unregister
from .fast64_internal.f3d.flipbook import flipbook_register, flipbook_unregister
from .fast64_internal.f3d.op_largetexture import op_largetexture_register, op_largetexture_unregister, ui_oplargetexture

from .fast64_internal.f3d_material_converter import (
MatUpdateConvert,
upgrade_f3d_version_all_meshes,
bsdf_conv_register,
bsdf_conv_unregister,
bsdf_conv_panel_regsiter,
bsdf_conv_panel_unregsiter,
)
from .fast64_internal.f3d import f3d_register, f3d_unregister
from .fast64_internal.f3d.f3d_material import F3D_MAT_CUR_VERSION, check_or_ask_color_management
from .fast64_internal.f3d_material_converter import upgrade_f3d_version_all_meshes

from .fast64_internal.render_settings import (
Fast64RenderSettings_Properties,
Expand Down Expand Up @@ -73,36 +56,6 @@
)


class F3D_GlobalSettingsPanel(bpy.types.Panel):
bl_idname = "F3D_PT_global_settings"
bl_label = "F3D Global Settings"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "Fast64"

@classmethod
def poll(cls, context):
return True

# called every frame
def draw(self, context):
col = self.layout.column()
col.scale_y = 1.1 # extra padding
prop_split(col, context.scene, "f3d_type", "F3D Microcode")
col.prop(context.scene, "saveTextures")
col.prop(context.scene, "f3d_simple", text="Simple Material UI")
col.prop(context.scene, "exportInlineF3D", text="Bleed and Inline Material Exports")
if context.scene.exportInlineF3D:
multilineLabel(
col.box(),
"While inlining, all meshes will be restored to world default values.\n You can configure these values in the world properties tab.",
icon="INFO",
)
col.prop(context.scene, "ignoreTextureRestrictions")
if context.scene.ignoreTextureRestrictions:
col.box().label(text="Width/height must be < 1024. Must be png format.")


class Fast64_GlobalSettingsPanel(bpy.types.Panel):
bl_idname = "FAST64_PT_global_settings"
bl_label = "Fast64 Global Settings"
Expand Down Expand Up @@ -135,26 +88,6 @@ def draw(self, context):
col.prop(fast64_settings, "prefer_rgba_over_ci")


class Fast64_GlobalToolsPanel(bpy.types.Panel):
bl_idname = "FAST64_PT_global_tools"
bl_label = "Fast64 Tools"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "Fast64"

@classmethod
def poll(cls, context):
return True

# called every frame
def draw(self, context):
col = self.layout.column()
col.operator(ArmatureApplyWithMeshOperator.bl_idname)
# col.operator(CreateMetarig.bl_idname)
ui_oplargetexture(col, context)
addon_updater_ops.update_notice_box_ui(self, context)


def repo_path_update(self, context):
load_repo_settings(context.scene, abspath(self.repo_settings_path), True)

Expand Down Expand Up @@ -316,9 +249,7 @@ def draw(self, context):
Fast64_Properties,
Fast64_BoneProperties,
Fast64_ObjectProperties,
F3D_GlobalSettingsPanel,
Fast64_GlobalSettingsPanel,
Fast64_GlobalToolsPanel,
UpgradeF3DMaterialsDialog,
)

Expand Down Expand Up @@ -418,9 +349,7 @@ def register():
addon_updater_ops.register(bl_info)

utility_anim_register()
mat_register()
render_engine_register()
bsdf_conv_register()
f3d_register(True)
sm64_register(True)
oot_register(True)
mk64_register(True)
Expand All @@ -430,12 +359,6 @@ def register():
for cls in classes:
register_class(cls)

bsdf_conv_panel_regsiter()
f3d_writer_register()
flipbook_register()
f3d_parser_register()
op_largetexture_register()

# ROM

bpy.types.Scene.ignoreTextureRestrictions = bpy.props.BoolProperty(name="Ignore Texture Restrictions")
Expand Down Expand Up @@ -464,17 +387,10 @@ def register():
# called on add-on disabling
def unregister():
utility_anim_unregister()
op_largetexture_unregister()
flipbook_unregister()
f3d_writer_unregister()
f3d_parser_unregister()
f3d_unregister(True)
sm64_unregister(True)
oot_unregister(True)
mk64_unregister(True)
mat_unregister()
bsdf_conv_unregister()
bsdf_conv_panel_unregsiter()
render_engine_unregister()

del bpy.types.Scene.fullTraceback
del bpy.types.Scene.ignoreTextureRestrictions
Expand Down
1 change: 0 additions & 1 deletion fast64_internal/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from .f3d_material_converter import *
from .f3d import *
from .sm64 import *
from .oot import * # is this really needed?
from .panels import *
135 changes: 131 additions & 4 deletions fast64_internal/f3d/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,131 @@
from .f3d_parser import *
from .f3d_material import *
from .f3d_render_engine import *
from .f3d_gbi import *
import bpy
from bpy.utils import register_class, unregister_class

from ... import addon_updater_ops
from ..utility_anim import ArmatureApplyWithMeshOperator
from ..utility import prop_split, multilineLabel

from .f3d_material import mat_register, mat_unregister
from .f3d_render_engine import render_engine_register, render_engine_unregister
from .f3d_writer import f3d_writer_register, f3d_writer_unregister
from .f3d_parser import f3d_parser_register, f3d_parser_unregister
from .flipbook import flipbook_register, flipbook_unregister
from .op_largetexture import op_largetexture_register, op_largetexture_unregister, ui_oplargetexture
from .bsdf_converter import bsdf_converter_register, bsdf_converter_unregister, bsdf_converter_panel_draw


class F3D_GlobalSettingsPanel(bpy.types.Panel):
bl_idname = "F3D_PT_global_settings"
bl_label = "F3D Global Settings"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "Fast64"

@classmethod
def poll(cls, context):
return True

# called every frame
def draw(self, context):
col = self.layout.column()
col.scale_y = 1.1 # extra padding
prop_split(col, context.scene, "f3d_type", "F3D Microcode")
col.prop(context.scene, "saveTextures")
col.prop(context.scene, "f3d_simple", text="Simple Material UI")
col.prop(context.scene, "exportInlineF3D", text="Bleed and Inline Material Exports")
if context.scene.exportInlineF3D:
multilineLabel(
col.box(),
"While inlining, all meshes will be restored to world default values.\n You can configure these values in the world properties tab.",
icon="INFO",
)
col.prop(context.scene, "ignoreTextureRestrictions")
if context.scene.ignoreTextureRestrictions:
col.box().label(text="Width/height must be < 1024. Must be png format.")


class Fast64_GlobalToolsPanel(bpy.types.Panel):
bl_idname = "FAST64_PT_global_tools"
bl_label = "Fast64 Tools"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "Fast64"

@classmethod
def poll(cls, context):
return True

# called every frame
def draw(self, context):
# TODO: figure out why a circular import is happening, this is bad
from ..f3d_material_converter import (
mat_updater_draw,
)

col = self.layout.column()
col.operator(ArmatureApplyWithMeshOperator.bl_idname)
# col.operator(CreateMetarig.bl_idname)
ui_oplargetexture(col, context)
col.separator()

box = col.box().column()
box.label(text="Material Updater")
mat_updater_draw(box, context)
col.separator()

box = col.box().column()
box.label(text="BSDF Converter")
bsdf_converter_panel_draw(box, context)
col.separator()

addon_updater_ops.update_notice_box_ui(self, context)


classes = tuple()
panel_classes = (F3D_GlobalSettingsPanel, Fast64_GlobalToolsPanel)


def f3d_panel_register():
for cls in panel_classes:
register_class(cls)


def f3d_panel_unregister():
for cls in reversed(panel_classes):
unregister_class(cls)


def f3d_register(register_panels: bool):
from ..f3d_material_converter import mat_updater_register

for cls in classes:
register_class(cls)
mat_register()
render_engine_register()
mat_updater_register()
f3d_writer_register()
flipbook_register()
f3d_parser_register()
op_largetexture_register()
bsdf_converter_register()

if register_panels:
f3d_panel_register()


def f3d_unregister(unregister_panels):
from ..f3d_material_converter import mat_updater_unregister

for cls in reversed(classes):
unregister_class(cls)
bsdf_converter_unregister()
op_largetexture_unregister()
f3d_parser_unregister()
flipbook_unregister()
f3d_writer_unregister()
mat_updater_unregister()
render_engine_unregister()
mat_unregister()

if unregister_panels:
f3d_panel_unregister()
10 changes: 10 additions & 0 deletions fast64_internal/f3d/bsdf_converter/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from .operators import bsdf_converter_ops_register, bsdf_converter_ops_unregister
from .ui import bsdf_converter_panel_draw


def bsdf_converter_register():
bsdf_converter_ops_register()


def bsdf_converter_unregister():
bsdf_converter_ops_unregister()
11 changes: 11 additions & 0 deletions fast64_internal/f3d/bsdf_converter/classes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import dataclasses


@dataclasses.dataclass
class SimpleN64Texture:
name: str


@dataclasses.dataclass
class SimpleN64Material:
name: str
30 changes: 30 additions & 0 deletions fast64_internal/f3d/bsdf_converter/operators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from bpy.utils import register_class, unregister_class

from ...operators import OperatorBase


class F3D_ConvertF3DToBSDF(OperatorBase):
bl_idname = "scene.f3d_convert_to_bsdf"
bl_label = "Convert F3D to BSDF"
bl_options = {"REGISTER", "UNDO", "PRESET"}
icon = "MATERIAL"


class F3D_ConvertBSDFToF3D(OperatorBase):
bl_idname = "scene.bsdf_convert_to_f3d"
bl_label = "Convert BSDF to F3D"
bl_options = {"REGISTER", "UNDO", "PRESET"}
icon = "NODE_MATERIAL"


classes = (F3D_ConvertF3DToBSDF, F3D_ConvertBSDFToF3D)


def bsdf_converter_ops_register():
for cls in classes:
register_class(cls)


def bsdf_converter_ops_unregister():
for cls in reversed(classes):
unregister_class(cls)
11 changes: 11 additions & 0 deletions fast64_internal/f3d/bsdf_converter/ui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""Usually this would be panel.py but there is no actual panel since we only draw in the tools panel."""

from bpy.types import UILayout, Context

from .operators import F3D_ConvertF3DToBSDF, F3D_ConvertBSDFToF3D


def bsdf_converter_panel_draw(layout: UILayout, _context: Context):
col = layout.column()
F3D_ConvertF3DToBSDF.draw_props(col)
F3D_ConvertBSDFToF3D.draw_props(col)
Loading

0 comments on commit ea9dc68

Please sign in to comment.