Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into f3d-to-bdsf
Browse files Browse the repository at this point in the history
  • Loading branch information
Lilaa3 committed Oct 26, 2024
2 parents b71ef57 + ac5ff61 commit 4aefc5b
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 66 deletions.
15 changes: 14 additions & 1 deletion __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, multilineLabel, set_prop_if_in_data

from .fast64_internal.repo_settings import (
draw_repo_settings,
Expand Down Expand Up @@ -224,6 +224,19 @@ class Fast64Settings_Properties(bpy.types.PropertyGroup):

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

def to_repo_settings(self):
data = {}
data["autoLoad"] = self.auto_repo_load_settings
data["autoPickTextureFormat"] = self.auto_pick_texture_format
if self.auto_pick_texture_format:
data["preferRGBAOverCI"] = self.prefer_rgba_over_ci
return data

def from_repo_settings(self, data: dict):
set_prop_if_in_data(self, "auto_repo_load_settings", data, "autoLoad")
set_prop_if_in_data(self, "auto_pick_texture_format", data, "autoPickTextureFormat")
set_prop_if_in_data(self, "prefer_rgba_over_ci", data, "preferRGBAOverCI")


class Fast64_Properties(bpy.types.PropertyGroup):
"""
Expand Down
25 changes: 19 additions & 6 deletions fast64_internal/f3d/f3d_texture_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,14 +763,25 @@ def writeAll(

# Assign TMEM addresses
sameTextures = (
self.ti0.useTex
and self.ti1.useTex
(self.ti0.useTex and self.ti1.useTex)
and self.ti0.isTexRef == self.ti1.isTexRef
and self.ti0.tmemSize == self.ti1.tmemSize
and self.ti0.texFormat == self.ti1.texFormat
and (
(not self.ti0.isTexRef and not self.ti1.isTexRef and self.ti0.texProp.tex == self.ti1.texProp.tex)
or (
( # not a reference
not self.ti0.isTexRef and self.ti0.texProp.tex == self.ti1.texProp.tex # same image
)
or ( # reference
self.ti0.isTexRef
and self.ti1.isTexRef
and self.ti0.texProp.tex_reference == self.ti1.texProp.tex_reference
and self.ti0.texProp.tex_reference_size == self.ti1.texProp.tex_reference_size
and ( # ci format reference
not self.isCI
or (
self.ti0.texProp.pal_reference == self.ti1.texProp.pal_reference
and self.ti0.texProp.pal_reference_size == self.ti1.texProp.pal_reference_size
)
)
)
)
)
Expand All @@ -779,7 +790,9 @@ def writeAll(
self.ti1.texAddr = None # must be set whenever tex 1 used (and loaded or tiled)
tmemOccupied = self.texDimensions = None # must be set on all codepaths
if sameTextures:
assert self.ti0.tmemSize == self.ti1.tmemSize
assert (
self.ti0.tmemSize == self.ti1.tmemSize
), f"Unreachable code path in material {material.name}, same textures (same image or reference) somehow not the same size"
tmemOccupied = self.ti0.tmemSize
self.ti1.doTexLoad = False
self.ti1.texAddr = 0
Expand Down
19 changes: 7 additions & 12 deletions fast64_internal/repo_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from bpy.props import StringProperty
from bpy.path import abspath

from .utility import filepath_checks, prop_split, filepath_ui_warnings, draw_and_check_tab
from .utility import filepath_checks, prop_split, filepath_ui_warnings, draw_and_check_tab, set_prop_if_in_data
from .operators import OperatorBase
from .f3d.f3d_material import draw_rdp_world_defaults
from .sm64.settings.repo_settings import load_sm64_repo_settings, save_sm64_repo_settings
Expand Down Expand Up @@ -71,13 +71,10 @@ def load_repo_settings(scene: Scene, path: os.PathLike, skip_if_no_auto_load=Fal
)

fast64_settings = scene.fast64.settings
fast64_settings.auto_repo_load_settings = data.get("autoLoad", fast64_settings.auto_repo_load_settings)
fast64_settings.auto_pick_texture_format = data.get(
"autoPickTextureFormat", fast64_settings.auto_pick_texture_format
)
fast64_settings.prefer_rgba_over_ci = data.get("preferRGBAOverCI", fast64_settings.prefer_rgba_over_ci)
scene.f3d_type = data.get("microcode", scene.f3d_type)
scene.saveTextures = data.get("saveTextures", scene.saveTextures)
fast64_settings.from_repo_settings(data)
set_prop_if_in_data(scene, "f3d_type", data, "microcode")
set_prop_if_in_data(scene, "saveTextures", data, "saveTextures")

rdp_defaults: RDPSettings = scene.world.rdp_defaults
rdp_defaults.from_dict(data.get("rdpDefaults", {}))

Expand All @@ -90,12 +87,10 @@ def save_repo_settings(scene: Scene, path: os.PathLike):
data = {}

data["version"] = CUR_VERSION
data["autoLoad"] = fast64_settings.auto_repo_load_settings
data.update(fast64_settings.to_repo_settings())
data["microcode"] = scene.f3d_type
data["saveTextures"] = scene.saveTextures
data["autoPickTextureFormat"] = fast64_settings.auto_pick_texture_format
if fast64_settings.auto_pick_texture_format:
data["preferRGBAOverCI"] = fast64_settings.prefer_rgba_over_ci

rdp_defaults: RDPSettings = scene.world.rdp_defaults
data["rdpDefaults"] = rdp_defaults.to_dict()

Expand Down
11 changes: 6 additions & 5 deletions fast64_internal/sm64/settings/panels.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
from bpy.types import Context

from ...panels import SM64_Panel

from .repo_settings import draw_repo_settings
from ...utility import draw_and_check_tab


class SM64_GeneralSettingsPanel(SM64_Panel):
Expand All @@ -18,10 +17,12 @@ def draw(self, context: Context):
if sm64_props.export_type == "C":
# If the repo settings tab is open, we pass show_repo_settings as False
# because we want to draw those specfic properties in the repo settings box
draw_repo_settings(scene, col.box())
col.separator()
box = col.box().column()
if draw_and_check_tab(box, sm64_props, "sm64_repo_settings_tab", icon="PROPERTIES"):
sm64_props.draw_repo_settings(box)
col.separator()

sm64_props.draw_props(col, not sm64_props.sm64_repo_settings_tab)
sm64_props.draw_props(col, not sm64_props.sm64_repo_settings_tab or sm64_props.binary_export)
else:
sm64_props.draw_props(col, True)

Expand Down
39 changes: 29 additions & 10 deletions fast64_internal/sm64/settings/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from bpy.utils import register_class, unregister_class

from ...render_settings import on_update_render_settings
from ...utility import directory_path_checks, directory_ui_warnings, prop_split, upgrade_old_prop
from ...utility import directory_path_checks, directory_ui_warnings, prop_split, set_prop_if_in_data, upgrade_old_prop
from ..sm64_constants import defaultExtendSegment4
from ..sm64_objects import SM64_CombinedObjectProperties
from ..sm64_utility import export_rom_ui_warnings, import_rom_ui_warnings
Expand All @@ -32,7 +32,7 @@ class SM64_Properties(PropertyGroup):
"""Global SM64 Scene Properties found under scene.fast64.sm64"""

version: IntProperty(name="SM64_Properties Version", default=0)
cur_version = 3 # version after property migration
cur_version = 4 # version after property migration

# UI Selection
show_importing_menus: BoolProperty(name="Show Importing Menus", default=False)
Expand Down Expand Up @@ -107,6 +107,7 @@ def upgrade_changed_props():
"custom_level_name": {"levelName", "geoLevelName", "colLevelName", "animLevelName"},
"non_decomp_level": {"levelCustomExport"},
"export_header_type": {"geoExportHeaderType", "colExportHeaderType", "animExportHeaderType"},
"custom_include_directory": {"geoTexDir"},
}
for scene in bpy.data.scenes:
sm64_props: SM64_Properties = scene.fast64.sm64
Expand All @@ -133,6 +134,29 @@ def upgrade_changed_props():
upgrade_old_prop(combined_props, new, scene, old)
sm64_props.version = SM64_Properties.cur_version

def to_repo_settings(self):
data = {}
data["refresh_version"] = self.refresh_version
data["compression_format"] = self.compression_format
data["force_extended_ram"] = self.force_extended_ram
data["matstack_fix"] = self.matstack_fix
return data

def from_repo_settings(self, data: dict):
set_prop_if_in_data(self, "refresh_version", data, "refresh_version")
set_prop_if_in_data(self, "compression_format", data, "compression_format")
set_prop_if_in_data(self, "force_extended_ram", data, "force_extended_ram")
set_prop_if_in_data(self, "matstack_fix", data, "matstack_fix")

def draw_repo_settings(self, layout: UILayout):
col = layout.column()
if not self.binary_export:
col.prop(self, "disable_scroll")
prop_split(col, self, "compression_format", "Compression Format")
prop_split(col, self, "refresh_version", "Refresh (Function Map)")
col.prop(self, "force_extended_ram")
col.prop(self, "matstack_fix")

def draw_props(self, layout: UILayout, show_repo_settings: bool = True):
col = layout.column()

Expand All @@ -152,14 +176,9 @@ def draw_props(self, layout: UILayout, show_repo_settings: bool = True):
directory_ui_warnings(col, abspath(self.decomp_path))
col.separator()

if not self.binary_export:
col.prop(self, "disable_scroll")
if show_repo_settings:
prop_split(col, self, "compression_format", "Compression Format")
prop_split(col, self, "refresh_version", "Refresh (Function Map)")
col.prop(self, "force_extended_ram")
col.prop(self, "matstack_fix")
col.separator()
if show_repo_settings:
self.draw_repo_settings(col)
col.separator()

col.prop(self, "show_importing_menus")
if self.show_importing_menus:
Expand Down
31 changes: 5 additions & 26 deletions fast64_internal/sm64/settings/repo_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from bpy.types import Scene, UILayout

from ...utility import draw_and_check_tab, prop_split
from ...utility import draw_and_check_tab, prop_split, set_prop_if_in_data


def save_sm64_repo_settings(scene: Scene):
Expand All @@ -18,11 +18,7 @@ def save_sm64_repo_settings(scene: Scene):
}

sm64_props = scene.fast64.sm64
data["refresh_version"] = sm64_props.refresh_version
data["compression_format"] = sm64_props.compression_format
data["force_extended_ram"] = sm64_props.force_extended_ram
data["matstack_fix"] = sm64_props.matstack_fix

data.update(sm64_props.to_repo_settings())
return data


Expand All @@ -33,26 +29,9 @@ def load_sm64_repo_settings(scene: Scene, data: dict[str, Any]):
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"])
set_prop_if_in_data(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"])

sm64_props = scene.fast64.sm64
sm64_props.refresh_version = data.get("refresh_version", sm64_props.refresh_version)
sm64_props.compression_format = data.get("compression_format", sm64_props.compression_format)
sm64_props.force_extended_ram = data.get("force_extended_ram", sm64_props.force_extended_ram)
sm64_props.matstack_fix = data.get("matstack_fix", sm64_props.matstack_fix)
set_prop_if_in_data(world, f"draw_layer_{layer}_cycle_2", draw_layer, "cycle_2")


def draw_repo_settings(scene: Scene, layout: UILayout):
col = layout.column()
sm64_props = scene.fast64.sm64
if not draw_and_check_tab(col, sm64_props, "sm64_repo_settings_tab", icon="PROPERTIES"):
return

prop_split(col, sm64_props, "compression_format", "Compression Format")
prop_split(col, sm64_props, "refresh_version", "Refresh (Function Map)")
col.prop(sm64_props, "force_extended_ram")
col.prop(sm64_props, "matstack_fix")

col.label(text="See Fast64 repo settings for general settings", icon="INFO")
sm64_props.from_repo_settings(data)
6 changes: 2 additions & 4 deletions fast64_internal/sm64/sm64_geolayout_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2858,7 +2858,7 @@ def execute(self, context):
obj,
final_transform,
export_path,
bpy.context.scene.geoTexDir,
props.custom_include_directory,
save_textures,
save_textures and bpy.context.scene.geoSeparateTextureDef,
None,
Expand Down Expand Up @@ -3058,7 +3058,7 @@ def execute(self, context):
obj,
final_transform,
export_path,
bpy.context.scene.geoTexDir,
props.custom_include_directory,
save_textures,
save_textures and bpy.context.scene.geoSeparateTextureDef,
None,
Expand Down Expand Up @@ -3252,7 +3252,6 @@ def sm64_geo_writer_register():
bpy.types.Scene.textDumpGeoPath = bpy.props.StringProperty(name="Text Dump Path", subtype="FILE_PATH")
bpy.types.Scene.geoUseBank0 = bpy.props.BoolProperty(name="Use Bank 0")
bpy.types.Scene.geoRAMAddr = bpy.props.StringProperty(name="RAM Address", default="80000000")
bpy.types.Scene.geoTexDir = bpy.props.StringProperty(name="Include Path", default="actors/mario/")
bpy.types.Scene.geoSeparateTextureDef = bpy.props.BoolProperty(name="Save texture.inc.c separately")
bpy.types.Scene.geoInsertableBinaryPath = bpy.props.StringProperty(name="Filepath", subtype="FILE_PATH")
bpy.types.Scene.geoIsSegPtr = bpy.props.BoolProperty(name="Is Segmented Address")
Expand Down Expand Up @@ -3282,7 +3281,6 @@ def sm64_geo_writer_unregister():
del bpy.types.Scene.textDumpGeoPath
del bpy.types.Scene.geoUseBank0
del bpy.types.Scene.geoRAMAddr
del bpy.types.Scene.geoTexDir
del bpy.types.Scene.geoSeparateTextureDef
del bpy.types.Scene.geoInsertableBinaryPath
del bpy.types.Scene.geoIsSegPtr
Expand Down
20 changes: 18 additions & 2 deletions fast64_internal/sm64/sm64_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -1941,6 +1941,7 @@ def update_or_inherit(new_cmd, index, arg_val, bhv_arg):
group_name: bpy.props.EnumProperty(name="Group Name", default="group0", items=groups_obj_export)
# custom export path, no headers written
custom_export_path: bpy.props.StringProperty(name="Custom Path", subtype="FILE_PATH")
custom_include_directory: bpy.props.StringProperty(name="Include directory", subtype="FILE_PATH")

# common export opts
custom_group_name: bpy.props.StringProperty(name="custom") # for custom group
Expand Down Expand Up @@ -2156,6 +2157,10 @@ def draw_export_options(self, layout):
col.prop(self, "export_bhv")
self.draw_obj_name(layout)

@property
def actor_names(self) -> list:
return list(dict.fromkeys(filter(None, [self.obj_name_col, self.obj_name_gfx])).keys())

def draw_level_path(self, layout):
if not directory_ui_warnings(layout, bpy.path.abspath(self.base_level_path)):
return
Expand Down Expand Up @@ -2218,7 +2223,7 @@ def draw_props(self, layout):
self.draw_level_path(box.box())
col.separator()
# object exports
box = col.box()
box = col.box().column()
if not self.export_col and not self.export_bhv and not self.export_gfx:
col = box.column()
col.operator("object.sm64_export_combined_object", text="Export Object")
Expand All @@ -2237,8 +2242,9 @@ def draw_props(self, layout):
# pathing for gfx/col exports
prop_split(box, self, "export_header_type", "Export Type")

if self.export_header_type == "Custom":
if self.export_header_type == "Custom" and bpy.context.scene.saveTextures:
prop_split(box, self, "custom_export_path", "Custom Path")
prop_split(box, self, "custom_include_directory", "Texture Include Directory")

elif self.export_header_type == "Actor":
prop_split(box, self, "group_name", "Group")
Expand Down Expand Up @@ -2277,6 +2283,16 @@ def draw_props(self, layout):
elif self.export_header_type == "Actor":
if not self.draw_actor_path(info_box):
return
elif self.export_header_type == "Custom" and bpy.context.scene.saveTextures:
if self.custom_include_directory:
info_box.label(text=f'Include directory "{self.custom_include_directory}"')
else:
actor_names = self.actor_names
joined = ",".join(self.actor_names)
if len(actor_names) > 1:
joined = "{" f"{joined}" "}"
directory = f"{Path(bpy.path.abspath(self.custom_export_path)).name}/{joined}"
info_box.label(text=f'Empty include directory, defaults to "{directory}"')

if self.obj_name_gfx and self.export_gfx:
self.draw_gfx_names(info_box)
Expand Down
13 changes: 13 additions & 0 deletions fast64_internal/utility.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from pathlib import Path
import bpy, random, string, os, math, traceback, re, os, mathutils, ast, operator
from math import pi, ceil, degrees, radians, copysign
from mathutils import *
Expand Down Expand Up @@ -708,6 +709,8 @@ def getExportDir(customExport, dirPath, headerType, levelName, texDir, dirName):
elif headerType == "Level":
dirPath = os.path.join(dirPath, "levels/" + levelName)
texDir = "levels/" + levelName
elif not texDir:
texDir = (Path(dirPath).name / Path(dirName)).as_posix()

return dirPath, texDir

Expand Down Expand Up @@ -1896,3 +1899,13 @@ def create_or_get_world(scene: Scene) -> World:
WORLD_WARNING_COUNT = 0
print(f'No world in this file, creating world named "Fast64".')
return bpy.data.worlds.new("Fast64")


def set_if_different(owner: object, prop: str, value):
if getattr(owner, prop) != value:
setattr(owner, prop, value)


def set_prop_if_in_data(owner: object, prop_name: str, data: dict, data_name: str):
if data_name in data:
set_if_different(owner, prop_name, data[data_name])

0 comments on commit 4aefc5b

Please sign in to comment.