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

[F3D] Fix RDP world defaults #377

Merged
merged 10 commits into from
Aug 5, 2024
15 changes: 15 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
)

from .fast64_internal.sm64 import sm64_register, sm64_unregister
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
from .fast64_internal.sm64.sm64_objects import SM64_ObjectProperties

from .fast64_internal.oot import OOT_Properties, oot_register, oot_unregister
from .fast64_internal.oot.oot_constants import oot_world_defaults
from .fast64_internal.oot.props_panel_main import OOT_ObjectProperties
from .fast64_internal.utility_anim import utility_anim_register, utility_anim_unregister, ArmatureApplyWithMeshOperator

Expand Down Expand Up @@ -208,6 +210,8 @@ class Fast64Settings_Properties(bpy.types.PropertyGroup):
)
internal_fixed_4_2: bpy.props.BoolProperty(default=False)

internal_game_update_ver: bpy.props.IntProperty(default=0)


class Fast64_Properties(bpy.types.PropertyGroup):
"""
Expand Down Expand Up @@ -324,6 +328,9 @@ def upgrade_changed_props():
SM64_ObjectProperties.upgrade_changed_props()
OOT_ObjectProperties.upgrade_changed_props()
for scene in bpy.data.scenes:
if scene.fast64.settings.internal_game_update_ver != 1:
gameEditorUpdate(scene, bpy.context)
scene.fast64.settings.internal_game_update_ver = 1
if scene.get("decomp_compatible", False):
scene.gameEditorMode = "Homebrew"
del scene["decomp_compatible"]
Expand Down Expand Up @@ -359,12 +366,20 @@ def after_load(_a, _b):


def gameEditorUpdate(self, context):
world_defaults = None
if self.gameEditorMode == "SM64":
self.f3d_type = "F3D"
world_defaults = sm64_world_defaults
elif self.gameEditorMode == "OOT":
self.f3d_type = "F3DEX2/LX2"
world_defaults = oot_world_defaults
elif self.gameEditorMode == "MK64":
self.f3d_type = "F3DEX/LX"
elif self.gameEditorMode == "Homebrew":
self.f3d_type = "F3D"
world_defaults = {} # This will set some pretty bad defaults, but trust the user
if self.world is not None:
self.world.rdp_defaults.from_dict(world_defaults)


# called on add-on enabling
Expand Down
60 changes: 39 additions & 21 deletions fast64_internal/f3d/f3d_material.py
Original file line number Diff line number Diff line change
Expand Up @@ -3127,13 +3127,13 @@ def key(self):
class RDPSettings(PropertyGroup):
g_zbuffer: bpy.props.BoolProperty(
name="Z Buffer",
default=True,
default=False,
update=update_node_values_with_preset,
description="Enables calculation of Z value for primitives. Disable if not reading or writing Z-Buffer in the blender",
)
g_shade: bpy.props.BoolProperty(
name="Shading",
default=True,
default=False,
update=update_node_values_with_preset,
description="Computes shade coordinates for primitives. Disable if not using lighting, vertex colors or fog",
)
Expand Down Expand Up @@ -3165,7 +3165,7 @@ class RDPSettings(PropertyGroup):
# v1/2 difference
g_cull_back: bpy.props.BoolProperty(
name="Cull Back",
default=True,
default=False,
update=update_node_values_with_preset,
description="Disables drawing of back faces",
)
Expand Down Expand Up @@ -3207,7 +3207,7 @@ class RDPSettings(PropertyGroup):
)
g_lighting: bpy.props.BoolProperty(
name="Lighting",
default=True,
default=False,
update=update_node_values_with_preset,
description="Enables calculating shade color using lights. Turn off for vertex colors as shade color",
)
Expand All @@ -3231,13 +3231,13 @@ class RDPSettings(PropertyGroup):
)
g_shade_smooth: bpy.props.BoolProperty(
name="Smooth Shading",
default=True,
default=False,
update=update_node_values_with_preset,
description="Shades primitive smoothly using interpolation between shade values for each vertex (Gouraud shading)",
)
g_clipping: bpy.props.BoolProperty(
name="Clipping",
default=False,
default=True,
update=update_node_values_with_preset,
description="F3DEX1/LX only, exact function unknown",
)
Expand All @@ -3247,7 +3247,7 @@ class RDPSettings(PropertyGroup):
g_mdsft_alpha_dither: bpy.props.EnumProperty(
name="Alpha Dither",
items=enumAlphaDither,
default="G_AD_NOISE",
default="G_AD_DISABLE",
update=update_node_values_with_preset,
description="Applies your choice dithering type to output framebuffer alpha. Dithering is used to convert high precision source colors into lower precision framebuffer values",
)
Expand All @@ -3269,14 +3269,14 @@ class RDPSettings(PropertyGroup):
g_mdsft_textconv: bpy.props.EnumProperty(
name="Texture Convert",
items=enumTextConv,
default="G_TC_FILT",
default="G_TC_CONV",
update=update_node_values_with_preset,
description="Sets the function of the texture convert unit, to do texture filtering, YUV to RGB conversion, or both",
)
g_mdsft_text_filt: bpy.props.EnumProperty(
name="Texture Filter",
items=enumTextFilt,
default="G_TF_BILERP",
default="G_TF_POINT",
update=update_node_values_without_preset,
description="Applies your choice of filtering to texels",
)
Expand Down Expand Up @@ -3310,7 +3310,7 @@ class RDPSettings(PropertyGroup):
g_mdsft_textpersp: bpy.props.EnumProperty(
name="Texture Perspective Correction",
items=enumTextPersp,
default="G_TP_PERSP",
default="G_TP_NONE",
update=update_node_values_with_preset,
description="Turns on/off texture perspective correction",
)
Expand All @@ -3332,7 +3332,7 @@ class RDPSettings(PropertyGroup):
g_mdsft_pipeline: bpy.props.EnumProperty(
name="Pipeline Span Buffer Coherency",
items=enumPipelineMode,
default="G_PM_1PRIMITIVE",
default="G_PM_NPRIMITIVE",
update=update_node_values_with_preset,
description="Changes primitive rasterization timing by adding syncs after tri draws. Vanilla SM64 has synchronization issues which could cause a crash if not using 1 prim. For any modern SM64 hacking project or other game N-prim should always be used",
)
Expand Down Expand Up @@ -3518,7 +3518,7 @@ def attributes_from_dict(self, data: dict, info: dict):
]

geo_mode_f3dex_attributes = [
("clipping", "g_clipping", False),
("clipping", "g_clipping", True),
]

geo_mode_f3dex3_attributes = [
Expand Down Expand Up @@ -3546,7 +3546,7 @@ def geo_mode_from_dict(self, data: dict):
self.attributes_from_dict(data, self.geo_mode_attributes)

other_mode_h_attributes = [
("alphaDither", "g_mdsft_alpha_dither", "G_AD_PATTERN"),
("alphaDither", "g_mdsft_alpha_dither", "G_AD_DISABLE"),
("colorDither", "g_mdsft_rgb_dither", "G_CD_MAGICSQ"),
("chromaKey", "g_mdsft_combkey", "G_CK_NONE"),
("textureConvert", "g_mdsft_textconv", "G_TC_CONV"),
Expand Down Expand Up @@ -3671,6 +3671,31 @@ def key(self):
return str(self.to_dict().items())


def draw_rdp_world_defaults(layout: UILayout, scene: Scene):
world = scene.world
if world is None:
layout.box().label(text="No World Selected In Scene", icon="WORLD")
return
rdp_defaults = world.rdp_defaults
col = layout.column()
col.box().label(text="RDP Default Settings", icon="WORLD")
multilineLabel(
col,
text="If a material setting is the same as the default setting\n"
"it won't be set, otherwise a revert will be added.",
)
if scene.gameEditorMode == "Homebrew":
multilineLabel(
col.box(),
text="Homebrew mode defaults to ucode defaults,\nmake sure to set your own.",
icon="INFO",
)
ui_geo_mode(rdp_defaults, world, col, True)
ui_upper_mode(rdp_defaults, world, col, True)
ui_lower_mode(rdp_defaults, world, col, True)
ui_other(rdp_defaults, world, col, True)


class DefaultRDPSettingsPanel(Panel):
bl_label = "RDP Default Settings"
bl_idname = "WORLD_PT_RDP_Default_Inspector"
Expand All @@ -3680,14 +3705,7 @@ class DefaultRDPSettingsPanel(Panel):
bl_options = {"HIDE_HEADER"}

def draw(self, context):
world = context.scene.world
layout = self.layout
layout.box().label(text="RDP Default Settings")
layout.label(text="If a material setting is a same as a default setting, then it won't be set.")
ui_geo_mode(world.rdp_defaults, world, layout, True)
ui_upper_mode(world.rdp_defaults, world, layout, True)
ui_lower_mode(world.rdp_defaults, world, layout, True)
ui_other(world.rdp_defaults, world, layout, True)
draw_rdp_world_defaults(self.layout, context.scene)


class CelLevelProperty(PropertyGroup):
Expand Down
17 changes: 17 additions & 0 deletions fast64_internal/oot/oot_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,3 +602,20 @@
("SDC_GANONS_TOWER_COLLAPSE_INTERIOR", "Ganon's Tower (Collapsing) (Ganon Sonogo)", "Ganon Sonogo"),
("SDC_INSIDE_GANONS_CASTLE_COLLAPSE", "Inside Ganon's Castle (Collapsing) (Ganontika Sonogo)", "Ganontika Sonogo"),
]

oot_world_defaults = {
"geometryMode": {
"zBuffer": True,
"shade": True,
"cullBack": True,
"lighting": True,
"shadeSmooth": True,
},
"otherModeH": {
"alphaDither": "G_AD_NOISE",
"textureFilter": "G_TF_BILERP",
"perspectiveCorrection": "G_TP_PERSP",
"textureConvert": "G_TC_FILT",
"cycleType": "G_CYC_2CYCLE",
},
}
11 changes: 2 additions & 9 deletions fast64_internal/repo_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from .utility import filepath_checks, prop_split, filepath_ui_warnings, draw_and_check_tab
from .operators import OperatorBase
from .f3d.f3d_material import ui_geo_mode, ui_upper_mode, ui_lower_mode, ui_other
from .f3d.f3d_material import draw_rdp_world_defaults
from .sm64.settings.repo_settings import load_sm64_repo_settings, save_sm64_repo_settings

from typing import TYPE_CHECKING
Expand Down Expand Up @@ -126,14 +126,7 @@ def draw_repo_settings(layout: UILayout, context: Context):
col.prop(fast64_settings, "prefer_rgba_over_ci")
col.separator()

world = scene.world
rdp_defaults = world.rdp_defaults
col.box().label(text="RDP Default Settings", icon="WORLD")
col.label(text="If a material setting is a same as a default setting, then it won't be set.")
ui_geo_mode(rdp_defaults, world, col, True)
ui_upper_mode(rdp_defaults, world, col, True)
ui_lower_mode(rdp_defaults, world, col, True)
ui_other(rdp_defaults, world, col, True)
draw_rdp_world_defaults(col, scene)


classes = (SaveRepoSettings, LoadRepoSettings)
Expand Down
16 changes: 16 additions & 0 deletions fast64_internal/sm64/sm64_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2351,3 +2351,19 @@ def __init__(self, geoAddr, level, switchDict):
(5737600, "207 - Forwards spinning flip"),
(5740584, "208 - Triple jump fly"),
]

sm64_world_defaults = {
"geometryMode": {
"zBuffer": True,
"shade": True,
"cullBack": True,
"lighting": True,
"shadeSmooth": True,
},
Lilaa3 marked this conversation as resolved.
Show resolved Hide resolved
"otherModeH": {
"textureFilter": "G_TF_BILERP",
"perspectiveCorrection": "G_TP_PERSP",
"textureConvert": "G_TC_FILT",
"pipelineMode": "G_PM_1PRIMITIVE",
},
}
Loading