Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into glTF_experimental
Browse files Browse the repository at this point in the history
  • Loading branch information
Lilaa3 committed Sep 18, 2024
2 parents e3cdfc8 + ddd6969 commit c140eae
Show file tree
Hide file tree
Showing 29 changed files with 545 additions and 1,818 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 @@ -49,6 +49,7 @@

from .fast64_internal.render_settings import (
Fast64RenderSettings_Properties,
ManualUpdatePreviewOperator,
resync_scene_props,
on_update_render_settings,
)
Expand All @@ -65,7 +66,7 @@
# 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 @@ -322,6 +323,7 @@ def draw(self, context):
classes = (
Fast64Settings_Properties,
Fast64RenderSettings_Properties,
ManualUpdatePreviewOperator,
Fast64_Properties,
Fast64_BoneProperties,
Fast64_ObjectProperties,
Expand All @@ -339,9 +341,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 @@ -374,23 +377,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
17 changes: 11 additions & 6 deletions fast64_internal/f3d/f3d_bleed.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,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 @@ -480,9 +479,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
22 changes: 19 additions & 3 deletions fast64_internal/f3d/f3d_material.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@
from .f3d_gbi import get_F3D_GBI, enumTexScroll, isUcodeF3DEX1, default_draw_layers
from .f3d_material_presets import *
from ..utility import *
from ..render_settings import Fast64RenderSettings_Properties, update_scene_props_from_render_settings
from ..render_settings import (
Fast64RenderSettings_Properties,
update_scene_props_from_render_settings,
ManualUpdatePreviewOperator,
)
from .f3d_material_helpers import F3DMaterial_UpdateLock, node_tree_copy
from bpy.app.handlers import persistent
from typing import Generator, Optional, Tuple, Any, Dict, Union
Expand Down Expand Up @@ -1488,7 +1492,7 @@ def update_node_values(self, context, update_preset):

def update_all_node_values(material, context):
update_node_values_without_preset(material, context)
update_tex_values_and_formats(material, context)
update_tex_values_manual(material, context)
update_rendermode_preset(material, context)


Expand Down Expand Up @@ -2453,7 +2457,7 @@ def createOrUpdateSceneProperties():
sceneOutputs: NodeGroupOutput = new_group.nodes["Group Output"]
renderSettings: "Fast64RenderSettings_Properties" = bpy.context.scene.fast64.renderSettings

update_scene_props_from_render_settings(bpy.context, sceneOutputs, renderSettings)
update_scene_props_from_render_settings(sceneOutputs, renderSettings)


def createScenePropertiesForMaterial(material: Material):
Expand Down Expand Up @@ -5024,6 +5028,18 @@ def draw(self, context):
labelbox.label(text="Global Settings")
labelbox.ui_units_x = 6

# Only show the update preview UI if the render engine is EEVEE,
# as there's no point in updating the nodes otherwise.
if context.scene.render.engine in {
"BLENDER_EEVEE", # <4.2
"BLENDER_EEVEE_NEXT", # 4.2+
}:
updatePreviewRow = globalSettingsBox.row()
updatePreviewRow.prop(renderSettings, "enableAutoUpdatePreview")
if not renderSettings.enableAutoUpdatePreview:
updatePreviewRow.operator(ManualUpdatePreviewOperator.bl_idname)
globalSettingsBox.separator()

globalSettingsBox.prop(renderSettings, "enableFogPreview")
prop_split(globalSettingsBox, renderSettings, "fogPreviewColor", "Fog Color")
prop_split(globalSettingsBox, renderSettings, "fogPreviewPosition", "Fog Position")
Expand Down
25 changes: 11 additions & 14 deletions fast64_internal/f3d/f3d_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ def __init__(self, f3d: F3D, basePath: str, materialContext: bpy.types.Material)
self.materialContext.f3d_update_flag = True # Don't want visual updates while parsing
# If this is not disabled, then tex_scale will auto-update on manual node update.
self.materialContext.f3d_mat.scale_autoprop = False
self.draw_layer_prop: str | None = None
self.initContext()

# This is separate as we want to call __init__ in clearGeometry, but don't want same behaviour for child classes
Expand Down Expand Up @@ -1931,15 +1932,15 @@ def parseF3D(
transformMatrix: mathutils.Matrix,
limbName: str,
boneName: str,
drawLayerPropName: str,
drawLayer: str,
f3dContext: F3DContext,
callClearMaterial: bool,
):
f3dContext.matrixData[limbName] = transformMatrix
f3dContext.setCurrentTransform(limbName)
f3dContext.limbToBoneName[limbName] = boneName
setattr(f3dContext.mat().draw_layer, drawLayerPropName, drawLayer)
if f3dContext.draw_layer_prop is not None:
setattr(f3dContext.mat().draw_layer, f3dContext.draw_layer_prop, drawLayer)

# vertexGroup = getOrMakeVertexGroup(obj, boneName)
# groupIndex = vertexGroup.index
Expand Down Expand Up @@ -2275,21 +2276,17 @@ def importMeshC(
f3dContext: F3DContext,
callClearMaterial: bool = True,
) -> bpy.types.Object:
if bpy.context.scene.gameEditorMode == "OOT":
mesh = bpy.data.meshes.new(name + "_mesh")
obj = bpy.data.objects.new(name + "_mesh", mesh)
bpy.context.collection.objects.link(obj)
mesh = bpy.data.meshes.new(name + "_mesh")
obj = bpy.data.objects.new(name + "_mesh", mesh)
bpy.context.collection.objects.link(obj)

f3dContext.mat().draw_layer.oot = drawLayer
transformMatrix = mathutils.Matrix.Scale(1 / scale, 4)
transformMatrix = mathutils.Matrix.Scale(1 / scale, 4)

parseF3D(data, name, transformMatrix, name, name, "oot", drawLayer, f3dContext, True)
f3dContext.createMesh(obj, removeDoubles, importNormals, callClearMaterial)
parseF3D(data, name, transformMatrix, name, name, drawLayer, f3dContext, True)
f3dContext.createMesh(obj, removeDoubles, importNormals, callClearMaterial)

applyRotation([obj], math.radians(-90), "X")
return obj
else:
raise PluginError("ERROR: This function has not been implemented yet for this game.")
applyRotation([obj], math.radians(-90), "X")
return obj


class F3D_ImportDL(bpy.types.Operator):
Expand Down
4 changes: 2 additions & 2 deletions fast64_internal/mk64/mk64_model_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ def course_vertex_format_patterns():
return (
# decomp format
r"\{\s*"
r"\{+([^,\}]*),([^,\}]*),([^,\}]*)\}\s*,\s*"
r"\{[\{\s]*([^,\}]*),([^,\}]*),([^,\}]*)\}\s*,\s*"
r"\{([^,\}]*),([^,\}]*)\}\s*,\s*"
r"\{MACRO_COLOR_FLAG\(([^,\}]*),([^,\}]*),([^,\}]*),([^,\}])*\),([^,\}]*)\}\s*"
r"\{\s*MACRO_COLOR_FLAG\(([^,\}]*),([^,\}]*),([^,\}]*),([^,\}])*\),([^,\}]*)\}\s*"
r"\}"
)

Expand Down
10 changes: 5 additions & 5 deletions fast64_internal/oot/exporter/collision/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,14 @@ def getCollisionData(dataHolder: Optional[Object], transform: Matrix, useMacros:
surfaceType = SurfaceType(
colProp.cameraID,
colProp.exitID,
int(Utility.getPropValue(colProp, "floorProperty"), base=16),
Utility.getPropValue(colProp, "floorProperty"),
0, # unused?
int(Utility.getPropValue(colProp, "wallSetting"), base=16),
int(Utility.getPropValue(colProp, "floorSetting"), base=16),
Utility.getPropValue(colProp, "wallSetting"),
Utility.getPropValue(colProp, "floorSetting"),
colProp.decreaseHeight,
colProp.eponaBlock,
int(Utility.getPropValue(colProp, "sound"), base=16),
int(Utility.getPropValue(colProp, "terrain"), base=16),
Utility.getPropValue(colProp, "sound"),
Utility.getPropValue(colProp, "terrain"),
colProp.lightingSetting,
int(colProp.echo, base=16),
colProp.hookshotable,
Expand Down
10 changes: 5 additions & 5 deletions fast64_internal/oot/exporter/collision/surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ class SurfaceType:
# surface type 0
bgCamIndex: int
exitIndex: int
floorType: int
floorType: str
unk18: int # unused?
wallType: int
floorProperty: int
wallType: str
floorProperty: str
isSoft: bool
isHorseBlocked: bool

# surface type 1
material: int
floorEffect: int
material: str
floorEffect: str
lightSetting: int
echo: int
canHookshot: bool
Expand Down
2 changes: 1 addition & 1 deletion fast64_internal/oot/importer/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def parseScene(
importSubdir = os.path.dirname(getSceneDirFromLevelName(sceneName, True)) + "/"

sceneFolderPath = ootGetPath(
f"{importPath}/{bpy.context.scene.fast64.oot.get_extracted_path()}/",
importPath if settings.isCustomDest else f"{importPath}/{bpy.context.scene.fast64.oot.get_extracted_path()}/",
settings.isCustomDest,
importSubdir,
sceneName,
Expand Down
Loading

0 comments on commit c140eae

Please sign in to comment.