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

black format #277

Merged
merged 3 commits into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
black
  • Loading branch information
Dragorn421 committed Jan 6, 2024
commit d00a07c99ddb031219a01242d08af26d88f1a87c
6 changes: 5 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,11 @@ def draw(self, context):
col.prop(context.scene, "generateF3DNodeGraph", text="Generate F3D Node Graph For Materials")
col.prop(context.scene, "exportInlineF3D", text="Bleed and Inline Material Exports")
if context.scene.exportInlineF3D:
multilineLabel(col.box(), "While inlining, all meshes will be restored to world default values.\n You can configure these values in the world properties tab.", icon="INFO")
multilineLabel(
col.box(),
"While inlining, all meshes will be restored to world default values.\n You can configure these values in the world properties tab.",
icon="INFO",
)
col.prop(context.scene, "decomp_compatible", invert_checkbox=True, text="Homebrew Compatibility")
col.prop(context.scene, "ignoreTextureRestrictions")
if context.scene.ignoreTextureRestrictions:
Expand Down
46 changes: 28 additions & 18 deletions fast64_internal/f3d/f3d_bleed.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@


class BleedGraphics:

# bleed_state "enums"
bleed_start = 1
bleed_in_progress = 2
Expand Down Expand Up @@ -126,18 +125,25 @@ def bleed_fModel(self, fModel: FModel, fMeshes: dict[FMesh]):

# clear the gfx lists so they don't export
def clear_gfx_lists(self, fModel: FModel):
for (fMaterial, texDimensions) in fModel.materials.values():
for fMaterial, texDimensions in fModel.materials.values():
fMaterial.material.tag |= GfxListTag.NoExport
if fMaterial.revert:
fMaterial.revert.tag |= GfxListTag.NoExport
for fMesh in fModel.meshes.values():
for tri_list in fMesh.triangleGroups:
tri_list.triList.tag |= GfxListTag.NoExport

def bleed_fmesh(self, fMesh: FMesh, last_mat: FMaterial, cmd_list: GfxList, fmodel_materials, default_render_mode: list[str] = None):
def bleed_fmesh(
self,
fMesh: FMesh,
last_mat: FMaterial,
cmd_list: GfxList,
fmodel_materials,
default_render_mode: list[str] = None,
):
if bled_mat := self.bled_gfx_lists.get(cmd_list, None):
return bled_mat

bleed_state = self.bleed_start
cur_fmat = None
reset_cmd_dict = dict()
Expand Down Expand Up @@ -169,15 +175,15 @@ def bleed_fmesh(self, fMesh: FMesh, last_mat: FMaterial, cmd_list: GfxList, fmod
bleed_gfx_lists = BleedGfxLists()
# set bleed state for cmd reverts
bleed_state = self.bleed_in_progress

last_mat = cur_fmat
self.on_bleed_end(last_mat, cmd_list, fmesh_static_cmds, reset_cmd_dict, default_render_mode)
return last_mat

def build_tmem_dict(self, cmd_list: GfxList):
im_buffer = None
tmem_dict = dict()
tile_dict = {i:0 for i in range(8)} # an assumption that hopefully never needs correction
tile_dict = {i: 0 for i in range(8)} # an assumption that hopefully never needs correction
for cmd in cmd_list.commands:
if type(cmd) == DPSetTextureImage:
im_buffer = cmd
Expand All @@ -188,7 +194,7 @@ def build_tmem_dict(self, cmd_list: GfxList):
tmem_dict[tile_dict[cmd.tile]] = im_buffer
continue
return tmem_dict

def bleed_textures(self, cur_fmat: FMaterial, last_mat: FMaterial, bleed_state: int):
if last_mat:
# bleed cmds if matching tile has duplicate cmds
Expand Down Expand Up @@ -220,7 +226,7 @@ def bleed_textures(self, cur_fmat: FMaterial, last_mat: FMaterial, bleed_state:
# now eval as normal conditionals
for j, cmd in enumerate(cur_fmat.texture_DL.commands):
if not cmd:
continue # some cmds are None from previous step
continue # some cmds are None from previous step
if self.bleed_individual_cmd(commands_bled, cmd, bleed_state):
if cmd in last_mat.texture_DL.commands:
commands_bled.commands[j] = None
Expand Down Expand Up @@ -252,9 +258,7 @@ def bleed_mat(self, cur_fmat: FMaterial, last_mat: FMaterial, bleed_state: int):
commands_bled.commands.remove(SPEndDisplayList())
return commands_bled.commands

def bleed_tri_group(
self, tri_list: GfxList, cur_fmat: fMaterial, bleed_state: int
):
def bleed_tri_group(self, tri_list: GfxList, cur_fmat: fMaterial, bleed_state: int):
# remove SPEndDisplayList from triGroup
while SPEndDisplayList() in tri_list.commands:
tri_list.commands.remove(SPEndDisplayList())
Expand All @@ -281,7 +285,9 @@ def bleed_cmd_list(self, target_cmd_list: GfxList, bleed_state: int):
return commands_bled

# Put triGroup bleed gfx in the FMesh.draw object
def inline_triGroup(self, tri_list: GfxList, bleed_gfx_lists: BleedGfxLists, cmd_list: GfxList, reset_cmd_dict: dict[GbiMacro]):
def inline_triGroup(
self, tri_list: GfxList, bleed_gfx_lists: BleedGfxLists, cmd_list: GfxList, reset_cmd_dict: dict[GbiMacro]
):
# add material
cmd_list.commands.extend(bleed_gfx_lists.bled_mats)
# add textures
Expand Down Expand Up @@ -329,7 +335,12 @@ def on_tri_group_bleed_end(self, triGroup: FTriGroup, last_mat: FMaterial, bleed
return

def on_bleed_end(
self, last_mat: FMaterial, cmd_list: GfxList, fmesh_static_cmds: list[GbiMacro], reset_cmd_dict: dict[GbiMacro], default_render_mode: list[str] = None
self,
last_mat: FMaterial,
cmd_list: GfxList,
fmesh_static_cmds: list[GbiMacro],
reset_cmd_dict: dict[GbiMacro],
default_render_mode: list[str] = None,
):
# revert certain cmds for extra safety
reset_cmds = self.create_reset_cmds(reset_cmd_dict, default_render_mode)
Expand All @@ -338,14 +349,13 @@ def on_bleed_end(
reset_cmds.remove(DPPipeSync)
reset_cmds.insert(0, DPPipeSync)
cmd_list.commands.extend(reset_cmds)
cmd_list.commands.extend(fmesh_static_cmds) # this is troublesome
cmd_list.commands.extend(fmesh_static_cmds) # this is troublesome
cmd_list.commands.append(SPEndDisplayList())
self.bled_gfx_lists[cmd_list] = last_mat

def create_reset_cmds(self, reset_cmd_dict: dict[GbiMacro], default_render_mode: list[str]):
reset_cmds = []
for cmd_type, cmd_use in reset_cmd_dict.items():

if cmd_type == DPPipeSync:
reset_cmds.append(DPPipeSync())

Expand Down Expand Up @@ -493,7 +503,7 @@ def bleed_between_tris(self, cmd_list: GfxList, cmd: GbiMacro, bleed_state: int,
class BleedGfxLists:
bled_mats: GfxList = field(default_factory=list)
bled_tex: GfxList = field(default_factory=list)

@property
def reset_command_dict(self):
return {
Expand All @@ -514,7 +524,7 @@ def add_reset_cmd(self, cmd: GbiMacro, reset_cmd_dict: dict[GbiMacro]):
# separate other mode H and othermode L
if type(cmd) == SPSetOtherMode:
reset_cmd_dict[cmd.cmd] = cmd

if type(cmd) in reset_cmd_list:
reset_cmd_dict[type(cmd)] = cmd

Expand All @@ -533,4 +543,4 @@ def find_material_from_jump_cmd(
return bpy_material, fmaterial
elif fmaterial.material == dl_jump.displayList:
return bpy_material, fmaterial
return None, None
return None, None
30 changes: 25 additions & 5 deletions fast64_internal/f3d/f3d_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,18 +392,38 @@
]

enumCelThreshMode = [
("Lighter", "Lighter", "This cel level is drawn when the lighting level per-pixel is LIGHTER than (>=) the threshold"),
(
"Lighter",
"Lighter",
"This cel level is drawn when the lighting level per-pixel is LIGHTER than (>=) the threshold",
),
("Darker", "Darker", "This cel level is drawn when the lighting level per-pixel is DARKER than (<) the threshold"),
]

enumCelTintPipeline = [
("CC", "CC (tint in Prim Color)", "Cel shading puts tint color in Prim Color and tint level in Prim Alpha. Set up CC color to LERP between source color and tint color based on tint level, or multiply source color by tint color. Source may be Tex 0 or Env Color"),
("Blender", "Blender (tint in Fog Color)", "Cel shading puts tint color in Fog Color and tint level in Fog Alpha. Set up blender to LERP between CC output and tint color based on tint level. Then set CC to Tex 0 * shade color (vertex colors)"),
(
"CC",
"CC (tint in Prim Color)",
"Cel shading puts tint color in Prim Color and tint level in Prim Alpha. Set up CC color to LERP between source color and tint color based on tint level, or multiply source color by tint color. Source may be Tex 0 or Env Color",
),
(
"Blender",
"Blender (tint in Fog Color)",
"Cel shading puts tint color in Fog Color and tint level in Fog Alpha. Set up blender to LERP between CC output and tint color based on tint level. Then set CC to Tex 0 * shade color (vertex colors)",
),
]

enumCelCutoutSource = [
("TEXEL0", "Texture 0", "Cel shading material has binary alpha cutout from Texture 0 alpha. Does not work with I4 or I8 formats"),
("TEXEL1", "Texture 1", "Cel shading material has binary alpha cutout from Texture 1 alpha. Does not work with I4 or I8 formats"),
(
"TEXEL0",
"Texture 0",
"Cel shading material has binary alpha cutout from Texture 0 alpha. Does not work with I4 or I8 formats",
),
(
"TEXEL1",
"Texture 1",
"Cel shading material has binary alpha cutout from Texture 1 alpha. Does not work with I4 or I8 formats",
),
("ENVIRONMENT", "None / Env Alpha", "Make sure your material writes env color, and set env alpha to opaque (255)"),
]

Expand Down
22 changes: 8 additions & 14 deletions fast64_internal/f3d/f3d_gbi.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ class GfxListTag(enum.IntFlag):
MaterialRevert = 4
Draw = 4
NoExport = 16

@property
def Export(self):
return not self & GfxListTag.NoExport



class GfxTag(enum.Flag):
Expand Down Expand Up @@ -2938,7 +2937,7 @@ def set_addr(self, startAddress, f3d):

def save_binary(self, romfile, f3d, segments):
for celTriList in self.celTriLists:
celTriList.save_binary(romfile, f3d, segments);
celTriList.save_binary(romfile, f3d, segments)
self.triList.save_binary(romfile, f3d, segments)
self.vertexList.save_binary(romfile)

Expand Down Expand Up @@ -3779,9 +3778,7 @@ class SPAmbOcclusionAmbDir(GbiMacro):
def to_binary(self, f3d, segments):
if not f3d.F3DEX_GBI_3:
raise PluginError("SPAmbOcclusionAmbDir requires F3DEX3 microcode")
return gsMoveWd(
f3d.G_MW_FX, f3d.G_MWO_AO_AMBIENT, (_SHIFTL(self.amb, 16, 16) | _SHIFTL(self.dir, 0, 16)), f3d
)
return gsMoveWd(f3d.G_MW_FX, f3d.G_MWO_AO_AMBIENT, (_SHIFTL(self.amb, 16, 16) | _SHIFTL(self.dir, 0, 16)), f3d)


@dataclass(unsafe_hash=True)
Expand All @@ -3808,8 +3805,9 @@ class SPAmbOcclusion(GbiMacro):
def to_binary(self, f3d, segments):
if not f3d.F3DEX_GBI_3:
raise PluginError("SPAmbOcclusion requires F3DEX3 microcode")
return SPAmbOcclusionAmbDir(self.amb, self.dir).to_binary(f3d, segments) + \
SPAmbOcclusionPoint(self.point).to_binary(f3d, segments)
return SPAmbOcclusionAmbDir(self.amb, self.dir).to_binary(f3d, segments) + SPAmbOcclusionPoint(
self.point
).to_binary(f3d, segments)


@dataclass(unsafe_hash=True)
Expand All @@ -3820,9 +3818,7 @@ class SPFresnelScale(GbiMacro):
def to_binary(self, f3d, segments):
if not f3d.F3DEX_GBI_3:
raise PluginError("SPFresnelScale requires F3DEX3 microcode")
return gsMoveHalfwd(
f3d.G_MW_FX, f3d.G_MWO_FRESNEL_SCALE, self.scale, f3d
)
return gsMoveHalfwd(f3d.G_MW_FX, f3d.G_MWO_FRESNEL_SCALE, self.scale, f3d)


@dataclass(unsafe_hash=True)
Expand All @@ -3833,9 +3829,7 @@ class SPFresnelOffset(GbiMacro):
def to_binary(self, f3d, segments):
if not f3d.F3DEX_GBI_3:
raise PluginError("SPFresnelOffset requires F3DEX3 microcode")
return gsMoveHalfwd(
f3d.G_MW_FX, f3d.G_MWO_FRESNEL_OFFSET, self.offset, f3d
)
return gsMoveHalfwd(f3d.G_MW_FX, f3d.G_MWO_FRESNEL_OFFSET, self.offset, f3d)


@dataclass(unsafe_hash=True)
Expand Down
36 changes: 18 additions & 18 deletions fast64_internal/f3d/f3d_generate_presets.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import os

basePath = 'presets/f3d'
data = ''
basePath = "presets/f3d"
data = ""
presetList = "material_presets = {\n"

for subdir in os.listdir(basePath):
subPath = os.path.join(basePath, subdir)
if subdir != '__pycache__' and subdir != 'user' and os.path.isdir(subPath):
presetList += '\t"' + subdir + '" : {\n'
for filename in os.listdir(subPath):
presetPath = os.path.join(subPath, filename)
if os.path.isfile(presetPath):
print(presetPath)
presetFile = open(presetPath, 'r')
presetData = presetFile.read()
presetFile.close()
subPath = os.path.join(basePath, subdir)
if subdir != "__pycache__" and subdir != "user" and os.path.isdir(subPath):
presetList += '\t"' + subdir + '" : {\n'
for filename in os.listdir(subPath):
presetPath = os.path.join(subPath, filename)
if os.path.isfile(presetPath):
print(presetPath)
presetFile = open(presetPath, "r")
presetData = presetFile.read()
presetFile.close()

data += filename[:-3] + " = '''\n" + presetData + "'''\n\n"
presetList += '\t\t"' + filename[:-3] + '" : ' + filename[:-3] + ',\n'
presetList += '\t},\n'
data += filename[:-3] + " = '''\n" + presetData + "'''\n\n"
presetList += '\t\t"' + filename[:-3] + '" : ' + filename[:-3] + ",\n"
presetList += "\t},\n"

presetList += '}\n'
presetList += "}\n"

data += presetList

outFile = open('f3d_material_presets.py', 'w')
outFile = open("f3d_material_presets.py", "w")
outFile.write(data)
outFile.close()
outFile.close()
Loading