Skip to content
77 changes: 30 additions & 47 deletions fast64_internal/f3d/f3d_material.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,39 +92,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 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",
}


Expand Down Expand Up @@ -229,34 +215,32 @@ 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 in {"OOT", "MM"}:
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, ("", ""))
default = 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", ""),
)
layers = scene.fast64.sm64.draw_layers.layers_by_prop
if layer not in layers:
return default
return layers[layer].preset
elif game_mode == "OOT":
if scene.world is None:
return default
return (
getattr(world.ootDefaultRenderModes, f"{layer.lower()}Cycle1", ""),
getattr(world.ootDefaultRenderModes, f"{layer.lower()}Cycle2", ""),
getattr(scene.world.ootDefaultRenderModes, f"{layer.lower()}Cycle1", ""),
getattr(scene.world.ootDefaultRenderModes, f"{layer.lower()}Cycle2", ""),
)
else:
assert (
Expand Down Expand Up @@ -404,7 +388,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 @@ -4991,7 +4975,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
4 changes: 4 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
3 changes: 3 additions & 0 deletions fast64_internal/sm64/settings/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from ..sm64_objects import SM64_CombinedObjectProperties
from ..sm64_utility import export_rom_ui_warnings, import_rom_ui_warnings
from ..tools import SM64_AddrConvProperties
from ..sm64_f3d_writer import SM64_DrawLayersProperties

from .constants import (
enum_refresh_versions,
Expand Down Expand Up @@ -47,6 +48,7 @@ class SM64_Properties(PropertyGroup):
export_type: EnumProperty(items=enum_export_type, name="Export Type", default="C")
goal: EnumProperty(items=enum_sm64_goal_type, name="Goal", default="All")
combined_export: bpy.props.PointerProperty(type=SM64_CombinedObjectProperties)
draw_layers: bpy.props.PointerProperty(type=SM64_DrawLayersProperties)

blender_to_sm64_scale: FloatProperty(
name="Blender To SM64 Scale",
Expand Down Expand Up @@ -141,6 +143,7 @@ def upgrade_changed_props():
for scene in bpy.data.scenes:
sm64_props: SM64_Properties = scene.fast64.sm64
sm64_props.address_converter.upgrade_changed_props(scene)
sm64_props.draw_layers.upgrade_changed_props(scene)
if sm64_props.version == SM64_Properties.cur_version:
continue
upgrade_old_prop(
Expand Down
21 changes: 3 additions & 18 deletions fast64_internal/sm64/settings/repo_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,17 @@


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"] = scene.fast64.sm64.draw_layers.to_dict()

sm64_props = scene.fast64.sm64
data.update(sm64_props.to_repo_settings())
return data


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:
set_prop_if_in_data(world, f"draw_layer_{layer}_cycle_1", draw_layer, "cycle_1")
if "cycle_2" in draw_layer:
set_prop_if_in_data(world, f"draw_layer_{layer}_cycle_2", draw_layer, "cycle_2")
if "draw_layers" in data:
scene.fast64.sm64.draw_layers.from_dict(data["draw_layers"])

sm64_props = scene.fast64.sm64
sm64_props.from_repo_settings(data)
43 changes: 43 additions & 0 deletions fast64_internal/sm64/sm64_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3946,3 +3946,46 @@ def get_member_as_dict(name: str, member: DictOrVal[T]):
"pipelineMode": "G_PM_1PRIMITIVE",
},
}

DEFAULT_DRAW_LAYER_SETTINGS = {
"Background": {
"enum": "LAYER_FORCE",
"index": 0,
"preset": ["G_RM_ZB_OPA_SURF", "G_RM_ZB_OPA_SURF2"],
},
"Opaque": {
"enum": "LAYER_OPAQUE",
"index": 1,
"preset": ["G_RM_AA_ZB_OPA_SURF", "G_RM_AA_ZB_OPA_SURF2"],
},
"Opaque Decal": {
"enum": "LAYER_OPAQUE_DECAL",
"index": 2,
"preset": ["G_RM_AA_ZB_OPA_DECAL", "G_RM_AA_ZB_OPA_DECAL2"],
},
"Opaque Intersecting": {
"enum": "LAYER_OPAQUE_INTER",
"index": 3,
"preset": ["G_RM_AA_ZB_OPA_INTER", "G_RM_AA_ZB_OPA_INTER2"],
},
"Cutout": {
"enum": "LAYER_ALPHA",
"index": 4,
"preset": ["G_RM_AA_ZB_TEX_EDGE", "G_RM_AA_ZB_TEX_EDGE2"],
},
"Transparent": {
"enum": "LAYER_TRANSPARENT",
"index": 5,
"preset": ["G_RM_AA_ZB_XLU_SURF", "G_RM_AA_ZB_XLU_SURF2"],
},
"Transparent Decal": {
"enum": "LAYER_TRANSPARENT_DECAL",
"index": 6,
"preset": ["G_RM_AA_ZB_XLU_DECAL", "G_RM_AA_ZB_XLU_DECAL2"],
},
"Transparent Intersecting": {
"enum": "LAYER_TRANSPARENT_INTER",
"index": 7,
"preset": ["G_RM_AA_ZB_XLU_INTER", "G_RM_AA_ZB_XLU_INTER2"],
},
}
Loading