Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SM64] Custom draw layers #426

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
repo_settings_operators_unregister,
)

from .fast64_internal.sm64 import sm64_register, sm64_unregister
from .fast64_internal.sm64 import sm64_register, sm64_unregister, SM64_WorldProperties
from .fast64_internal.sm64.sm64_constants import sm64_world_defaults
from .fast64_internal.sm64.settings.properties import SM64_Properties
from .fast64_internal.sm64.sm64_geolayout_bone import SM64_BoneProperties
Expand Down Expand Up @@ -245,6 +245,19 @@ class Fast64_ObjectProperties(bpy.types.PropertyGroup):
oot: bpy.props.PointerProperty(type=OOT_ObjectProperties, name="OOT Object Properties")


class Fast64_WorldProperties(bpy.types.PropertyGroup):
"""
Properties in world.fast64 (bpy.types.World)
All new world properties should be children of this property group.
"""

sm64: bpy.props.PointerProperty(type=SM64_WorldProperties, name="SM64 World Properties")

@staticmethod
def upgrade_changed_props():
SM64_WorldProperties.upgrade_changed_props()


class UpgradeF3DMaterialsDialog(bpy.types.Operator):
bl_idname = "dialog.upgrade_f3d_materials"
bl_label = "Upgrade F3D Materials"
Expand Down Expand Up @@ -314,6 +327,7 @@ def draw(self, context):
Fast64_Properties,
Fast64_BoneProperties,
Fast64_ObjectProperties,
Fast64_WorldProperties,
F3D_GlobalSettingsPanel,
Fast64_GlobalSettingsPanel,
Fast64_GlobalToolsPanel,
Expand All @@ -323,6 +337,7 @@ def draw(self, context):

def upgrade_changed_props():
"""Set scene properties after a scene loads, used for migrating old properties"""
Fast64_WorldProperties.upgrade_changed_props()
SM64_Properties.upgrade_changed_props()
MK64_Properties.upgrade_changed_props()
SM64_ObjectProperties.upgrade_changed_props()
Expand Down Expand Up @@ -443,6 +458,7 @@ def register():
bpy.types.Scene.fast64 = bpy.props.PointerProperty(type=Fast64_Properties, name="Fast64 Properties")
bpy.types.Bone.fast64 = bpy.props.PointerProperty(type=Fast64_BoneProperties, name="Fast64 Bone Properties")
bpy.types.Object.fast64 = bpy.props.PointerProperty(type=Fast64_ObjectProperties, name="Fast64 Object Properties")
bpy.types.World.fast64 = bpy.props.PointerProperty(type=Fast64_WorldProperties, name="Fast64 World Properties")

bpy.app.handlers.load_post.append(after_load)

Expand Down Expand Up @@ -472,6 +488,7 @@ def unregister():
del bpy.types.Scene.fast64
del bpy.types.Bone.fast64
del bpy.types.Object.fast64
del bpy.types.World.fast64

repo_settings_operators_unregister()

Expand Down
64 changes: 22 additions & 42 deletions fast64_internal/f3d/f3d_material.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,39 +80,25 @@
}


sm64EnumDrawLayers = [
("0", "Background (0x00)", "Background"),
("1", "Opaque (0x01)", "Opaque"),
("2", "Opaque Decal (0x02)", "Opaque Decal"),
("3", "Opaque Intersecting (0x03)", "Opaque Intersecting"),
("4", "Cutout (0x04)", "Cutout"),
("5", "Transparent (0x05)", "Transparent"),
("6", "Transparent Decal (0x06)", "Transparent Decal"),
("7", "Transparent Intersecting (0x07)", "Transparent Intersecting"),
]
def get_sm64_draw_layers(self, context):
return create_or_get_world(context.scene).fast64.sm64.draw_layers.to_enum()


ootEnumDrawLayers = [
("Opaque", "Opaque", "Opaque"),
("Transparent", "Transparent", "Transparent"),
("Overlay", "Overlay", "Overlay"),
]


drawLayerSM64toOOT = {
"0": "Opaque",
"1": "Opaque",
"2": "Opaque",
"3": "Opaque",
"4": "Opaque",
"5": "Transparent",
"6": "Transparent",
"7": "Transparent",
}

drawLayerOOTtoSM64 = {
"Opaque": "1",
"Transparent": "5",
"Overlay": "1",
drawLayerSM64Alpha = {
"0": "OPA",
"1": "OPA",
"2": "OPA",
"3": "OPA",
"4": "CLIP",
"5": "XLU",
"6": "XLU",
"7": "XLU",
}

enumF3DMenu = [
Expand Down Expand Up @@ -154,30 +140,25 @@ def update_draw_layer(self, context):
if not material:
return

drawLayer = material.f3d_mat.draw_layer
if context.scene.gameEditorMode == "SM64":
drawLayer.oot = drawLayerSM64toOOT[drawLayer.sm64]
elif context.scene.gameEditorMode == "OOT":
if material.f3d_mat.draw_layer.oot == "Opaque":
if int(material.f3d_mat.draw_layer.sm64) > 4:
material.f3d_mat.draw_layer.sm64 = "1"
elif material.f3d_mat.draw_layer.oot == "Transparent":
if int(material.f3d_mat.draw_layer.sm64) < 5:
material.f3d_mat.draw_layer.sm64 = "5"
material.f3d_mat.presetName = "Custom"
update_blend_method(material, context)
update_fog_nodes(material, context)
set_output_node_groups(material)

drawLayer = material.f3d_mat.draw_layer
output_method = get_output_method(material)
if context.scene.gameEditorMode == "SM64":
drawLayer.oot = {"OPA": "Opaque", "XLU": "Transparent"}.get(output_method, "Opaque")
elif context.scene.gameEditorMode == "OOT":
drawLayer.sm64 = {"OPA": "1", "XLU": "5"}.get(output_method, "1") # expects vanilla draw layers


def get_world_layer_defaults(scene, game_mode: str, layer: str):
world = scene.world
if world is None:
return default_draw_layers.get(game_mode, {}).get(layer, ("", ""))
if game_mode == "SM64":
return (
getattr(world, f"draw_layer_{layer}_cycle_1", ""),
getattr(world, f"draw_layer_{layer}_cycle_2", ""),
)
return world.fast64.sm64.draw_layers.layers_by_prop[layer].preset
elif game_mode == "OOT":
return (
getattr(world.ootDefaultRenderModes, f"{layer.lower()}Cycle1", ""),
Expand Down Expand Up @@ -329,7 +310,7 @@ def update_blend_method(material: Material, context):


class DrawLayerProperty(PropertyGroup):
sm64: bpy.props.EnumProperty(items=sm64EnumDrawLayers, default="1", update=update_draw_layer)
sm64: bpy.props.EnumProperty(items=get_sm64_draw_layers, update=update_draw_layer)
oot: bpy.props.EnumProperty(items=ootEnumDrawLayers, default="Opaque", update=update_draw_layer)

def key(self):
Expand Down Expand Up @@ -4860,7 +4841,6 @@ def mat_register():
World.menu_upper = bpy.props.BoolProperty()
World.menu_lower = bpy.props.BoolProperty()
World.menu_other = bpy.props.BoolProperty()
World.menu_layers = bpy.props.BoolProperty()

Material.is_f3d = bpy.props.BoolProperty()
Material.mat_ver = bpy.props.IntProperty(default=1)
Expand Down
6 changes: 4 additions & 2 deletions fast64_internal/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ class OperatorBase(Operator):
icon = "NONE"

@classmethod
def draw_props(cls, layout: UILayout, icon="", text: Optional[str] = None, **op_values):
def draw_props(cls, layout: UILayout, icon="", text: Optional[str] = None, enabled=True, **op_values):
"""Op args are passed to the operator via setattr()"""
icon = icon if icon else cls.icon
op = layout.operator(cls.bl_idname, icon=icon, text=text)
col = layout.column()
col.enabled = enabled
op = col.operator(cls.bl_idname, icon=icon, text=text)
for key, value in op_values.items():
setattr(op, key, value)
return op
Expand Down
2 changes: 1 addition & 1 deletion fast64_internal/repo_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
if TYPE_CHECKING:
from .f3d.f3d_material import RDPSettings

CUR_VERSION = 1.0
CUR_VERSION = 1.1


class SaveRepoSettings(OperatorBase):
Expand Down
20 changes: 20 additions & 0 deletions fast64_internal/sm64/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
from bpy.utils import register_class, unregister_class
from bpy.types import PropertyGroup
from bpy.props import PointerProperty

from .settings import (
settings_props_register,
settings_props_unregister,
Expand Down Expand Up @@ -81,6 +85,7 @@
sm64_dl_writer_panel_unregister,
sm64_dl_writer_register,
sm64_dl_writer_unregister,
SM64_DrawLayersProperties,
)

from .sm64_anim import (
Expand All @@ -91,6 +96,17 @@
)


class SM64_WorldProperties(PropertyGroup):
draw_layers: PointerProperty(type=SM64_DrawLayersProperties)

@staticmethod
def upgrade_changed_props():
SM64_DrawLayersProperties.upgrade_changed_props()


classes = (SM64_WorldProperties,)


def sm64_panel_register():
settings_panels_register()
tools_panels_register()
Expand Down Expand Up @@ -136,6 +152,8 @@ def sm64_register(register_panels: bool):
sm64_dl_parser_register()
sm64_anim_register()
settings_props_register()
for cls in classes:
register_class(cls)

if register_panels:
sm64_panel_register()
Expand All @@ -156,6 +174,8 @@ def sm64_unregister(unregister_panels: bool):
sm64_dl_parser_unregister()
sm64_anim_unregister()
settings_props_unregister()
for cls in classes:
unregister_class(cls)

if unregister_panels:
sm64_panel_unregister()
17 changes: 2 additions & 15 deletions fast64_internal/sm64/settings/repo_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,7 @@
def save_sm64_repo_settings(scene: Scene):
world = scene.world
data: dict[str, Any] = {}
draw_layers: dict[str, Any] = {}
data["draw_layers"] = draw_layers

for layer in range(8):
draw_layers[layer] = {
"cycle_1": getattr(world, f"draw_layer_{layer}_cycle_1"),
"cycle_2": getattr(world, f"draw_layer_{layer}_cycle_2"),
}
data["draw_layers"] = world.fast64.sm64.draw_layers.to_dict()

sm64_props = scene.fast64.sm64
data["refresh_version"] = sm64_props.refresh_version
Expand All @@ -29,13 +22,7 @@ def save_sm64_repo_settings(scene: Scene):
def load_sm64_repo_settings(scene: Scene, data: dict[str, Any]):
world = scene.world

draw_layers = data.get("draw_layers", {})
for layer in range(8):
draw_layer = draw_layers.get(str(layer), {})
if "cycle_1" in draw_layer:
setattr(world, f"draw_layer_{layer}_cycle_1", draw_layer["cycle_1"])
if "cycle_2" in draw_layer:
setattr(world, f"draw_layer_{layer}_cycle_2", draw_layer["cycle_2"])
world.fast64.sm64.draw_layers.from_dict(data.get("draw_layers", {}))

sm64_props = scene.fast64.sm64
sm64_props.refresh_version = data.get("refresh_version", sm64_props.refresh_version)
Expand Down
Loading
Loading