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

[SM64] Combined Export Panel & Behavior Script Exporting #284

Merged
merged 30 commits into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ab23182
added in combined export panel and operator with basic behavior scrip…
Dec 26, 2022
ad2ec88
added in some behavior presets, and code to write them
Dec 28, 2022
64344d1
Merge branch 'fast64_main' into combined_object_export
Jan 27, 2023
bc05826
combined export now writes level script value
Jan 28, 2023
dffd39f
updated UI and export options to allow export of active object, or al…
Jan 7, 2024
94f0366
moved level export to combined export panel. cleaned up data/naming a…
Jan 7, 2024
882ed10
final clean of code and verification of operability
Jan 8, 2024
131bfbf
cleaned up code
Jan 9, 2024
d63ed96
fixed bhv export bug for inherit from args and raised error for expor…
Jan 9, 2024
043c8c5
fixed persistent blocks causing double exports for sub scripts
Jan 9, 2024
b1ca3f0
Merge remote-tracking branch 'fast64/main' into combined_object_export
Jan 9, 2024
9ccca22
black formatting
Jan 9, 2024
980fdfd
fixed level writing errors, added extra safety checks, modified UI an…
Jan 10, 2024
1f4f686
black formatting
Lilaa3 Jan 10, 2024
e889d7b
added obj fields enum to behavior scripts, fixed object export not wo…
Jan 11, 2024
705bb79
added upgrade code
Jan 11, 2024
2d8af6d
Merge pull request #2 from Lilaa3/combined_object_export
Jan 11, 2024
a2e172c
added enum for obj lists, and added script export button
Jan 20, 2024
d3269b1
made upgrade props work
Jan 20, 2024
c4fdb82
black on debian
Jan 20, 2024
52c42b2
fixed upgrade props again
Jan 21, 2024
932cb2d
updated UI to be cleaner. Fixed object export naming with armatures. …
Feb 3, 2024
db7a219
merged, improved UI, standardized properties and exceptions
Jul 21, 2024
726327f
changed custom enums so they work, edited UI for panel
Jul 21, 2024
97ffe6a
fixed sm64 panel visibility options, some typos and formatting
Jul 26, 2024
84910c7
fixed merge conflicts, made prop migration work with string -> enum
Jul 26, 2024
fc566fe
inherit args assert
Jul 26, 2024
946c893
changed upgrade to be more compact
Jul 26, 2024
e4db8bc
lila jape
Jul 26, 2024
b38f078
added tab levels to behavior script loops
Jul 26, 2024
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
6 changes: 1 addition & 5 deletions fast64_internal/sm64/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
)

from .sm64_objects import (
SM64_CombinedObjectProperties,
sm64_obj_panel_register,
sm64_obj_panel_unregister,
sm64_obj_register,
Expand All @@ -57,8 +58,6 @@
)

from .sm64_level_writer import (
sm64_level_panel_register,
sm64_level_panel_unregister,
sm64_level_register,
sm64_level_unregister,
)
Expand Down Expand Up @@ -101,7 +100,6 @@ def sm64_panel_register():
sm64_obj_panel_register()
sm64_geo_parser_panel_register()
sm64_geo_writer_panel_register()
sm64_level_panel_register()
sm64_spline_panel_register()
sm64_dl_writer_panel_register()
sm64_dl_parser_panel_register()
Expand All @@ -117,7 +115,6 @@ def sm64_panel_unregister():
sm64_obj_panel_unregister()
sm64_geo_parser_panel_unregister()
sm64_geo_writer_panel_unregister()
sm64_level_panel_unregister()
sm64_spline_panel_unregister()
sm64_dl_writer_panel_unregister()
sm64_dl_parser_panel_unregister()
Expand All @@ -139,7 +136,6 @@ def sm64_register(register_panels: bool):
sm64_dl_parser_register()
sm64_anim_register()
settings_props_register()
jesusyoshi54 marked this conversation as resolved.
Show resolved Hide resolved

if register_panels:
sm64_panel_register()

Expand Down
26 changes: 25 additions & 1 deletion fast64_internal/sm64/settings/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from ...render_settings import on_update_render_settings
from ...utility import directory_path_checks, directory_ui_warnings, prop_split
from ..sm64_constants import defaultExtendSegment4
from ..sm64_objects import SM64_CombinedObjectProperties
from ..sm64_utility import export_rom_ui_warnings, import_rom_ui_warnings
from ..tools import SM64_AddrConvProperties

Expand Down Expand Up @@ -37,6 +38,7 @@ class SM64_Properties(PropertyGroup):
show_importing_menus: BoolProperty(name="Show Importing Menus", default=False)
export_type: EnumProperty(items=enum_export_type, name="Export Type", default="C")
goal: EnumProperty(items=enum_sm64_goal_type, name="Goal", default="All")
combined_export: bpy.props.PointerProperty(type=SM64_CombinedObjectProperties)

blender_to_sm64_scale: FloatProperty(
name="Blender To SM64 Scale",
Expand Down Expand Up @@ -115,9 +117,28 @@ def upgrade_version_1(self, scene: Scene):
export_type = self.get("exportType", None)
if export_type is not None:
self.export_type = enum_export_type[export_type][0]

self.version = 2

def upgrade_version_2(self, scene: Scene):
# props upgrade for combined export panel
combined_props = scene.fast64.sm64.combined_export
old_scene_props_to_new = {
"geoLevelName": "custom_export_name",
"geoExportPath": "custom_export_path",
"geoName": "object_name",
"geoGroupName": "group_name",
}
for old, new in old_scene_props_to_new.items():
setattr(combined_props, new, scene.get(old, getattr(combined_props, new)))
export_type = scene.get("geoExportHeaderType", None)
if export_type is not None:
combined_props.export_header_type = enumExportHeaderType[export_type][0]

level_name = scene.get("geoLevelOption", None)
if level_name is not None:
combined_props.level_name = enumLevelNames[level_name][0]
self.version = 3

jesusyoshi54 marked this conversation as resolved.
Show resolved Hide resolved
@staticmethod
def upgrade_changed_props():
for scene in bpy.data.scenes:
Expand All @@ -129,6 +150,9 @@ def upgrade_changed_props():
if sm64_props.version == 1:
sm64_props.upgrade_version_1(scene)
print("Upgraded global SM64 settings to version 2")
if sm64_props.version == 2:
sm64_props.upgrade_version_2(scene)
print("Upgraded global SM64 settings to version 3")
sm64_props.address_converter.upgrade_changed_props(scene)

def draw_props(self, layout: UILayout, show_repo_settings: bool = True):
Expand Down
2 changes: 1 addition & 1 deletion fast64_internal/sm64/sm64_anim.py
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ def draw(self, context):
prop_split(col, context.scene, "animGroupName", "Group Name")
elif context.scene.animExportHeaderType == "Level":
prop_split(col, context.scene, "animLevelOption", "Level")
if context.scene.animLevelOption == "custom":
if context.scene.animLevelOption == "Custom":
prop_split(col, context.scene, "animLevelName", "Level Name")

decompFolderMessage(col)
Expand Down
116 changes: 35 additions & 81 deletions fast64_internal/sm64/sm64_collision.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,8 @@ def exportCollisionCommon(obj, transformMatrix, includeSpecials, includeChildren
tempObj, allObjs = duplicateHierarchy(obj, None, True, areaIndex)
try:
addCollisionTriangles(tempObj, collisionDict, includeChildren, transformMatrix, areaIndex)
if not collisionDict:
raise PluginError("No collision data to export")
cleanupDuplicatedObjects(allObjs)
obj.select_set(True)
bpy.context.view_layer.objects.active = obj
Expand Down Expand Up @@ -474,63 +476,57 @@ class SM64_ExportCollision(bpy.types.Operator):
# set bl_ properties
bl_idname = "object.sm64_export_collision"
bl_label = "Export Collision"
bl_options = {"REGISTER", "UNDO", "PRESET"}
bl_options = {"REGISTER", "UNDO"}

export_obj: bpy.props.StringProperty()

def execute(self, context):
romfileOutput = None
tempROM = None
props = context.scene.fast64.sm64.combined_export
try:
obj = None
if context.mode != "OBJECT":
raise PluginError("Operator can only be used in object mode.")
if len(context.selected_objects) == 0:
raise PluginError("Object not selected.")
obj = context.active_object
# if type(obj.data) is not bpy.types.Mesh:
# raise PluginError("Mesh not selected.")

# T, R, S = obj.matrix_world.decompose()
# objTransform = R.to_matrix().to_4x4() @ \
# mathutils.Matrix.Diagonal(S).to_4x4()
# finalTransform = (blenderToSM64Rotation * \
# (bpy.context.scene.blenderToSM64Scale)).to_4x4()
# finalTransform = mathutils.Matrix.Identity(4)

scaleValue = context.scene.fast64.sm64.blender_to_sm64_scale
finalTransform = mathutils.Matrix.Diagonal(mathutils.Vector((scaleValue, scaleValue, scaleValue))).to_4x4()
obj = bpy.data.objects.get(self.export_obj, None) or context.active_object
self.export_obj = ""
scale_value = context.scene.fast64.sm64.blender_to_sm64_scale
final_transform = mathutils.Matrix.Diagonal(
mathutils.Vector((scale_value, scale_value, scale_value))
).to_4x4()
except Exception as e:
raisePluginError(self, e)
return {"CANCELLED"}

try:
applyRotation([obj], math.radians(90), "X")
if context.scene.fast64.sm64.export_type == "C":
exportPath, levelName = getPathAndLevel(
context.scene.colCustomExport,
context.scene.colExportPath,
context.scene.colLevelName,
context.scene.colLevelOption,
export_path, level_name = getPathAndLevel(
props.export_header_type == "Custom",
props.custom_export_path,
props.custom_export_name,
props.level_name,
)
if not context.scene.colCustomExport:
applyBasicTweaks(exportPath)
if not props.export_header_type == "Custom":
applyBasicTweaks(export_path)
exportCollisionC(
obj,
finalTransform,
exportPath,
final_transform,
export_path,
False,
context.scene.colIncludeChildren,
bpy.context.scene.colName,
context.scene.colCustomExport,
context.scene.colExportRooms,
context.scene.colExportHeaderType,
context.scene.colGroupName,
levelName,
props.include_children,
props.obj_name_col,
props.export_header_type == "Custom",
props.export_rooms,
props.export_header_type,
props.export_group_name,
level_name,
)
self.report({"INFO"}, "Success!")
elif context.scene.fast64.sm64.export_type == "Insertable Binary":
exportCollisionInsertableBinary(
obj,
finalTransform,
final_transform,
bpy.path.abspath(context.scene.colInsertableBinaryPath),
False,
context.scene.colIncludeChildren,
Expand All @@ -552,7 +548,7 @@ def execute(self, context):

addrRange = exportCollisionBinary(
obj,
finalTransform,
final_transform,
romfileOutput,
int(context.scene.colStartAddr, 16),
int(context.scene.colEndAddr, 16),
Expand Down Expand Up @@ -608,41 +604,17 @@ class SM64_ExportCollisionPanel(SM64_Panel):
bl_label = "SM64 Collision Exporter"
goal = "Object/Actor/Anim"

@classmethod
def poll(cls, context):
return context.scene.fast64.sm64.export_type != "C"
jesusyoshi54 marked this conversation as resolved.
Show resolved Hide resolved

# called every frame
def draw(self, context):
col = self.layout.column()
propsColE = col.operator(SM64_ExportCollision.bl_idname)

col.prop(context.scene, "colIncludeChildren")

if context.scene.fast64.sm64.export_type == "C":
col.prop(context.scene, "colExportRooms")
col.prop(context.scene, "colCustomExport")
if context.scene.colCustomExport:
col.prop(context.scene, "colExportPath")
prop_split(col, context.scene, "colName", "Name")
customExportWarning(col)
else:
prop_split(col, context.scene, "colExportHeaderType", "Export Type")
prop_split(col, context.scene, "colName", "Name")
if context.scene.colExportHeaderType == "Actor":
prop_split(col, context.scene, "colGroupName", "Group Name")
elif context.scene.colExportHeaderType == "Level":
prop_split(col, context.scene, "colLevelOption", "Level")
if context.scene.colLevelOption == "custom":
prop_split(col, context.scene, "colLevelName", "Level Name")

decompFolderMessage(col)
writeBox = makeWriteInfoBox(col)
writeBoxExportType(
writeBox,
context.scene.colExportHeaderType,
context.scene.colName,
context.scene.colLevelName,
context.scene.colLevelOption,
)

elif context.scene.fast64.sm64.export_type == "Insertable Binary":
if context.scene.fast64.sm64.export_type == "Insertable Binary":
col.prop(context.scene, "colInsertableBinaryPath")
else:
prop_split(col, context.scene, "colStartAddr", "Start Address")
Expand Down Expand Up @@ -676,7 +648,6 @@ def sm64_col_register():
register_class(cls)

# Collision
bpy.types.Scene.colExportPath = bpy.props.StringProperty(name="Directory", subtype="FILE_PATH")
bpy.types.Scene.colExportLevel = bpy.props.EnumProperty(
items=level_enums, name="Level Used By Collision", default="WF"
)
Expand All @@ -686,15 +657,6 @@ def sm64_col_register():
bpy.types.Scene.colEndAddr = bpy.props.StringProperty(name="Start Address", default="11FFF00")
bpy.types.Scene.colIncludeChildren = bpy.props.BoolProperty(name="Include child objects", default=True)
bpy.types.Scene.colInsertableBinaryPath = bpy.props.StringProperty(name="Filepath", subtype="FILE_PATH")
bpy.types.Scene.colExportRooms = bpy.props.BoolProperty(name="Export Rooms", default=False)
bpy.types.Scene.colName = bpy.props.StringProperty(name="Name", default="mario")
bpy.types.Scene.colCustomExport = bpy.props.BoolProperty(name="Custom Export Path")
bpy.types.Scene.colExportHeaderType = bpy.props.EnumProperty(
items=enumExportHeaderType, name="Header Export", default="Actor"
)
bpy.types.Scene.colGroupName = bpy.props.StringProperty(name="Group Name", default="group0")
bpy.types.Scene.colLevelName = bpy.props.StringProperty(name="Level", default="bob")
bpy.types.Scene.colLevelOption = bpy.props.EnumProperty(items=enumLevelNames, name="Level", default="bob")

bpy.types.Material.collision_type = bpy.props.EnumProperty(
name="Collision Type", items=enumCollisionType, default="SURFACE_DEFAULT"
Expand All @@ -717,20 +679,12 @@ def sm64_col_register():

def sm64_col_unregister():
# Collision
del bpy.types.Scene.colExportPath
del bpy.types.Scene.colExportLevel
del bpy.types.Scene.addr_0x2A
del bpy.types.Scene.set_addr_0x2A
del bpy.types.Scene.colStartAddr
del bpy.types.Scene.colEndAddr
del bpy.types.Scene.colInsertableBinaryPath
del bpy.types.Scene.colExportRooms
del bpy.types.Scene.colName
del bpy.types.Scene.colCustomExport
del bpy.types.Scene.colExportHeaderType
del bpy.types.Scene.colGroupName
del bpy.types.Scene.colLevelName
del bpy.types.Scene.colLevelOption

del bpy.types.Material.collision_type
del bpy.types.Material.collision_type_simple
Expand Down
Loading
Loading