Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into ac
Browse files Browse the repository at this point in the history
  • Loading branch information
Lilaa3 committed Sep 15, 2024
2 parents d6c02b4 + ddd6969 commit be3900d
Show file tree
Hide file tree
Showing 50 changed files with 986 additions and 456 deletions.
Binary file removed LowPolySkinnedMario.blend
Binary file not shown.
Binary file removed LowPolySkinnedMario_V5.blend
Binary file not shown.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ Make sure to save often, as this plugin is prone to crashing when creating mater

<https://developer.blender.org/T70574>

### Example models can be found [here](https://github.com/Fast-64/fast64-models)

![alt-text](/images/mat_inspector.png)

### Credits
Thanks to anonymous_moose, Cheezepin, Rovert, and especially InTheBeef for testing.
Thanks to InTheBeef for LowPolySkinnedMario.

### Discord Server
We have a Discord server for support as well as development [here](https://discord.gg/ny7PDcN2x8).
Expand Down
44 changes: 29 additions & 15 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,15 @@

from .fast64_internal.render_settings import (
Fast64RenderSettings_Properties,
ManualUpdatePreviewOperator,
resync_scene_props,
on_update_render_settings,
)

# info about add on
bl_info = {
"name": "Fast64",
"version": (2, 2, 0),
"version": (2, 3, 0),
"author": "kurethedead",
"location": "3DView",
"description": "Plugin for exporting F3D display lists and other game data related to Nintendo 64 games.",
Expand Down Expand Up @@ -318,6 +319,7 @@ def draw(self, context):
classes = (
Fast64Settings_Properties,
Fast64RenderSettings_Properties,
ManualUpdatePreviewOperator,
Fast64_Properties,
Fast64_BoneProperties,
Fast64_ObjectProperties,
Expand All @@ -335,9 +337,10 @@ 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
settings: Fast64Settings_Properties = scene.fast64.settings
if settings.internal_game_update_ver != 1:
set_game_defaults(scene, False)
settings.internal_game_update_ver = 1
if scene.get("decomp_compatible", False):
scene.gameEditorMode = "Homebrew"
del scene["decomp_compatible"]
Expand Down Expand Up @@ -370,23 +373,34 @@ def after_load(_a, _b):
upgrade_changed_props()
upgrade_scene_props_node()
resync_scene_props()
try:
if settings.repo_settings_path:
load_repo_settings(bpy.context.scene, abspath(settings.repo_settings_path), True)
except Exception as exc:
print(exc)


def gameEditorUpdate(self, context):
def set_game_defaults(scene: bpy.types.Scene, set_ucode=True):
world_defaults = None
if self.gameEditorMode == "SM64":
self.f3d_type = "F3D"
if scene.gameEditorMode == "SM64":
f3d_type = "F3D"
world_defaults = sm64_world_defaults
elif self.gameEditorMode == "OOT":
self.f3d_type = "F3DEX2/LX2"
elif scene.gameEditorMode == "OOT":
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"
elif scene.gameEditorMode == "MK64":
f3d_type = "F3DEX/LX"
elif scene.gameEditorMode == "Homebrew":
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)
if set_ucode:
scene.f3d_type = f3d_type
if scene.world is not None:
scene.world.rdp_defaults.from_dict(world_defaults)


def gameEditorUpdate(scene: bpy.types.Scene, _context):
set_game_defaults(scene)


# called on add-on enabling
Expand Down
22 changes: 14 additions & 8 deletions fast64_internal/f3d/f3d_bleed.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from dataclasses import dataclass, field

from ..utility import create_or_get_world
from .f3d_gbi import (
GfxTag,
GfxListTag,
Expand Down Expand Up @@ -81,7 +82,7 @@ def __init__(self):
self.build_default_othermodes()

def build_default_geo(self):
defaults = bpy.context.scene.world.rdp_defaults
defaults = create_or_get_world(bpy.context.scene).rdp_defaults

setGeo = SPSetGeometryMode([])
clearGeo = SPClearGeometryMode([])
Expand Down Expand Up @@ -114,7 +115,7 @@ def place_in_flaglist(flag: bool, enum: str, set_list: SPSetGeometryMode, clear_
self.default_clear_geo = clearGeo

def build_default_othermodes(self):
defaults = bpy.context.scene.world.rdp_defaults
defaults = create_or_get_world(bpy.context.scene).rdp_defaults

othermode_H = SPSetOtherMode("G_SETOTHERMODE_H", 4, 20 - self.f3d.F3D_OLD_GBI, [])
# if the render mode is set, it will be consider non-default a priori
Expand Down Expand Up @@ -251,9 +252,8 @@ def bleed_textures(self, cur_fmat: FMaterial, last_mat: FMaterial, bleed_state:
for j, cmd in enumerate(cur_fmat.texture_DL.commands):
if not cmd:
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
if self.bleed_individual_cmd(commands_bled, cmd, bleed_state, last_mat.texture_DL.commands) is True:
commands_bled.commands[j] = None
# remove Nones from list
while None in commands_bled.commands:
commands_bled.commands.remove(None)
Expand Down Expand Up @@ -505,9 +505,15 @@ def bleed_SPSetOtherMode(self, cmd_list: GfxList, cmd: GbiMacro, bleed_state: in
else:
return cmd == self.default_othermode_L

# bleed if there are no tags to scroll and cmd was in last list
def bleed_DPSetTileSize(self, cmd_list: GfxList, cmd: GbiMacro, bleed_state: int, last_cmd_list: GfxList = None):
return cmd.tags != GfxTag.TileScroll0 and cmd.tags != GfxTag.TileScroll1 and cmd in last_cmd_list
# Don´t bleed if the cmd is used for scrolling or if the last cmd's tags are not the same (those are not hashed)
def bleed_DPSetTileSize(self, _cmd_list: GfxList, cmd: GbiMacro, _bleed_state: int, last_cmd_list: GfxList = None):
if cmd.tags == GfxTag.TileScroll0 or cmd.tags == GfxTag.TileScroll1:
return False
if cmd in last_cmd_list:
last_size_cmd = last_cmd_list[last_cmd_list.index(cmd)]
if last_size_cmd.tags == cmd.tags:
return True
return False

# At most, only one sync is needed after drawing tris. The f3d writer should
# already have placed the appropriate sync type required. If a second sync is
Expand Down
76 changes: 49 additions & 27 deletions fast64_internal/f3d/f3d_gbi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import annotations

from typing import Sequence, Union, Tuple
from dataclasses import dataclass, fields
from dataclasses import dataclass, fields, field
import bpy, os, enum, copy
from ..utility import *

Expand Down Expand Up @@ -74,15 +74,26 @@ class GfxMatWriteMethod(enum.Enum):
"F3DEX3": (56, 56),
}

drawLayerRenderMode = {
0: ("G_RM_ZB_OPA_SURF", "G_RM_NOOP2"),
1: ("G_RM_AA_ZB_OPA_SURF", "G_RM_NOOP2"),
2: ("G_RM_AA_ZB_OPA_DECAL", "G_RM_NOOP2"),
3: ("G_RM_AA_ZB_OPA_INTER", "G_RM_NOOP2"),
4: ("G_RM_AA_ZB_TEX_EDGE", "G_RM_NOOP2"),
5: ("G_RM_AA_ZB_XLU_SURF", "G_RM_NOOP2"),
6: ("G_RM_AA_ZB_XLU_DECAL", "G_RM_NOOP2"),
7: ("G_RM_AA_ZB_XLU_INTER", "G_RM_NOOP2"),
sm64_default_draw_layers = {
"0": ("G_RM_ZB_OPA_SURF", "G_RM_NOOP2"),
"1": ("G_RM_AA_ZB_OPA_SURF", "G_RM_NOOP2"),
"2": ("G_RM_AA_ZB_OPA_DECAL", "G_RM_NOOP2"),
"3": ("G_RM_AA_ZB_OPA_INTER", "G_RM_NOOP2"),
"4": ("G_RM_AA_ZB_TEX_EDGE", "G_RM_NOOP2"),
"5": ("G_RM_AA_ZB_XLU_SURF", "G_RM_NOOP2"),
"6": ("G_RM_AA_ZB_XLU_DECAL", "G_RM_NOOP2"),
"7": ("G_RM_AA_ZB_XLU_INTER", "G_RM_NOOP2"),
}

oot_default_draw_layers = {
"Opaque": ("G_RM_AA_ZB_OPA_SURF", "G_RM_AA_ZB_OPA_SURF2"),
"Transparent": ("G_RM_AA_ZB_XLU_SURF", "G_RM_AA_ZB_XLU_SURF2"),
"Overlay": ("G_RM_AA_ZB_OPA_SURF", "G_RM_AA_ZB_OPA_SURF2"),
}

default_draw_layers = {
"SM64": sm64_default_draw_layers,
"OOT": oot_default_draw_layers,
}

CCMUXDict = {
Expand Down Expand Up @@ -3292,18 +3303,18 @@ def spc(x):


# A palette is just a RGBA16 texture with width = 1.
@dataclass
class FImage:
def __init__(self, name, fmt, bitSize, width, height, filename):
self.name = name
self.fmt = fmt
self.bitSize = bitSize
self.width = width
self.height = height
self.startAddress = 0
self.data = bytearray(0)
self.filename = filename
self.converted = False
self.isLargeTexture = False
name: str
fmt: str
bitSize: str
width: int
height: int
filename: str
data: bytearray = field(init=False, compare=False, default_factory=bytearray)
startAddress: int = field(init=False, compare=False, default=0)
isLargeTexture: bool = field(init=False, compare=False, default=False)
converted: bool = field(init=False, compare=False, default=False)

def size(self):
return len(self.data)
Expand Down Expand Up @@ -3999,6 +4010,9 @@ def to_binary(self, f3d, segments):
self.point
).to_binary(f3d, segments)

def size(self, f3d):
return GFX_SIZE * 2


@dataclass(unsafe_hash=True)
class SPFresnelScale(GbiMacro):
Expand Down Expand Up @@ -4212,6 +4226,9 @@ def to_c(self, static=True):
header = "gsSPLightColor(" if static else "gSPLightColor(glistp++, "
return header + f"{self.n}, 0x" + format(self.color_to_int(), "08X") + ")"

def size(self, _f3d):
return GFX_SIZE * 2


@dataclass(unsafe_hash=True)
class SPSetLights(GbiMacro):
Expand Down Expand Up @@ -4398,7 +4415,7 @@ class SPPerspNormalize(GbiMacro):

def to_binary(self, f3d, segments):
if f3d.F3DEX_GBI_3:
return gsMoveHalfwd(f3d.G_MW_FX, G_MWO_PERSPNORM, (self.s), f3d)
return gsMoveHalfwd(f3d.G_MW_FX, f3d.G_MWO_PERSPNORM, (self.s), f3d)
else:
return gsMoveWd(f3d.G_MW_PERSPNORM, 0, (self.s), f3d)

Expand Down Expand Up @@ -4502,9 +4519,9 @@ class SPSetOtherMode(GbiMacro):
def to_binary(self, f3d, segments):
data = 0
for flag in self.flagList:
data |= getattr(f3d, flag) if hasattr(f3d, str(flag)) else flag
cmd = getattr(f3d, self.cmd) if hasattr(f3d, str(self.cmd)) else self.cmd
sft = getattr(f3d, self.sft) if hasattr(f3d, str(self.sft)) else self.sft
data |= getattr(f3d, str(flag), flag)
cmd = getattr(f3d, str(self.cmd), self.cmd)
sft = getattr(f3d, str(self.sft), self.sft)
return gsSPSetOtherMode(cmd, sft, self.length, data, f3d)


Expand Down Expand Up @@ -5062,7 +5079,12 @@ class DPSetOtherMode(GbiMacro):
mode1: list

def to_binary(self, f3d, segments):
words = _SHIFTL(f3d.G_RDPSETOTHERMODE, 24, 8) | _SHIFTL(self.mode0, 0, 24), self.mode1
mode0 = mode1 = 0
for mode in self.mode0:
mode0 |= getattr(f3d, str(mode), mode)
for mode in self.mode1:
mode1 |= getattr(f3d, str(mode), mode)
words = _SHIFTL(f3d.G_RDPSETOTHERMODE, 24, 8) | _SHIFTL(mode0, 0, 24), mode1
return words[0].to_bytes(4, "big") + words[1].to_bytes(4, "big")


Expand All @@ -5085,7 +5107,7 @@ def to_binary(self, f3d, segments):
return gsDPLoadTileGeneric(f3d.G_SETTILESIZE, self.tile, self.uls, self.ult, self.lrs, self.lrt)

def is_LOADTILE(self, f3d):
return self.t == f3d.G_TX_LOADTILE
return self.tile == f3d.G_TX_LOADTILE


@dataclass(unsafe_hash=True)
Expand Down
Loading

0 comments on commit be3900d

Please sign in to comment.