Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into write-differing-in-…
Browse files Browse the repository at this point in the history
…bleed
  • Loading branch information
Lilaa3 committed Oct 31, 2024
2 parents 7c9209d + ac5ff61 commit d1152d7
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 20 deletions.
2 changes: 1 addition & 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, prop_group_to_json, set_prop_if_in_data
from .fast64_internal.utility import prop_split, multilineLabel, set_prop_if_in_data

from .fast64_internal.repo_settings import (
draw_repo_settings,
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
12 changes: 6 additions & 6 deletions fast64_internal/f3d_material_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,16 @@ def convertAllBSDFtoF3D(objs, renameUV):
def convertBSDFtoF3D(obj, index, material, materialDict):
if not material.use_nodes:
newMaterial = createF3DMat(obj, preset="Shaded Solid", index=index)
f3dMat = newMaterial.f3d_mat if newMaterial.mat_ver > 3 else newMaterial
f3dMat.default_light_color = material.diffuse_color
with bpy.context.temp_override(material=newMaterial):
newMaterial.f3d_mat.default_light_color = material.diffuse_color
updateMatWithName(newMaterial, material, materialDict)

elif "Principled BSDF" in material.node_tree.nodes:
tex0Node = material.node_tree.nodes["Principled BSDF"].inputs["Base Color"]
if len(tex0Node.links) == 0:
newMaterial = createF3DMat(obj, preset=getDefaultMaterialPreset("Shaded Solid"), index=index)
f3dMat = newMaterial.f3d_mat if newMaterial.mat_ver > 3 else newMaterial
f3dMat.default_light_color = tex0Node.default_value
with bpy.context.temp_override(material=newMaterial):
newMaterial.f3d_mat.default_light_color = tex0Node.default_value
updateMatWithName(newMaterial, material, materialDict)
else:
if isinstance(tex0Node.links[0].from_node, bpy.types.ShaderNodeTexImage):
Expand All @@ -213,8 +213,8 @@ def convertBSDFtoF3D(obj, index, material, materialDict):
else:
presetName = getDefaultMaterialPreset("Shaded Texture")
newMaterial = createF3DMat(obj, preset=presetName, index=index)
f3dMat = newMaterial.f3d_mat if newMaterial.mat_ver > 3 else newMaterial
f3dMat.tex0.tex = tex0Node.links[0].from_node.image
with bpy.context.temp_override(material=newMaterial):
newMaterial.f3d_mat.tex0.tex = tex0Node.links[0].from_node.image
updateMatWithName(newMaterial, material, materialDict)
else:
print("Principled BSDF material does not have an Image Node attached to its Base Color.")
Expand Down
3 changes: 2 additions & 1 deletion fast64_internal/sm64/settings/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -117,6 +117,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 Down
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
3 changes: 3 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

0 comments on commit d1152d7

Please sign in to comment.