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 22 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
58 changes: 27 additions & 31 deletions fast64_internal/sm64/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from ..panels import SM64_Panel, sm64GoalTypeEnum, sm64GoalImport
from ..render_settings import on_update_render_settings
from .sm64_level_parser import parseLevelAtPointer
from .sm64_constants import level_enums, level_pointers, defaultExtendSegment4
from .sm64_constants import level_enums, level_pointers, defaultExtendSegment4, enumLevelNames

from ..utility import (
prop_split,
Expand All @@ -15,6 +15,7 @@
encodeSegmentedAddr,
raisePluginError,
enumExportType,
enumExportHeaderType,
enumCompressionFormat,
)

Expand All @@ -40,6 +41,7 @@
)

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

from .sm64_level_writer import (
sm64_level_panel_register,
sm64_level_panel_unregister,
sm64_level_register,
sm64_level_unregister,
)
Expand Down Expand Up @@ -95,7 +95,6 @@
sm64_anim_unregister,
)


enumRefreshVer = [
("Refresh 3", "Refresh 3", "Refresh 3"),
("Refresh 4", "Refresh 4", "Refresh 4"),
Expand Down Expand Up @@ -215,37 +214,36 @@ class SM64_Properties(PropertyGroup):
"""Global SM64 Scene Properties found under scene.fast64.sm64"""

version: IntProperty(name="SM64_Properties Version", default=0)
cur_version = 1 # version after property migration
cur_version = 2 # version after property migration

# UI Selection
showImportingMenus: BoolProperty(name="Show Importing Menus", default=False)
exportType: EnumProperty(items=enumExportType, name="Export Type", default="C")
goal: EnumProperty(items=sm64GoalTypeEnum, name="Export Goal", default="All")

# TODO: Utilize these across all exports
# C exporting
# useCustomExportLocation = BoolProperty(name = 'Use Custom Export Path')
# customExportPath: StringProperty(name = 'Custom Export Path', subtype = 'FILE_PATH')
# exportLocation: EnumProperty(items = enumExportHeaderType, name = 'Export Location', default = 'Actor')
# useSelectedObjectName = BoolProperty(name = 'Use Name From Selected Object', default=False)
# exportName: StringProperty(name='Name', default='mario')
# exportGeolayoutName: StringProperty(name='Name', default='mario_geo')

# Actor exports
# exportGroup: StringProperty(name='Group', default='group0')

# Level exports
# exportLevelName: StringProperty(name = 'Level', default = 'bob')
# exportLevelOption: EnumProperty(items = enumLevelNames, name = 'Level', default = 'bob')

# Insertable Binary
# exportInsertableBinaryPath: StringProperty(name = 'Filepath', subtype = 'FILE_PATH')
combined_export: bpy.props.PointerProperty(type=SM64_CombinedObjectProperties)

@staticmethod
def upgrade_changed_props():
if bpy.context.scene.fast64.sm64.version != SM64_Properties.cur_version:
bpy.context.scene.fast64.sm64.exportType = get_legacy_export_type()
bpy.context.scene.fast64.sm64.version = SM64_Properties.cur_version
# props upgrade for combined export panel
combined_props = bpy.context.scene.fast64.sm64.combined_export
old_scene_props_to_new = {
"geoLevelName": "custom_export_name",
"geoExportPath": "custom_export_path",
"geoName": "object_name",
}
jesusyoshi54 marked this conversation as resolved.
Show resolved Hide resolved
for old, new in old_scene_props_to_new.items():
setattr(combined_props, new, bpy.context.scene.get(old, getattr(combined_props, new)))
export_type = bpy.context.scene.get("geoExportHeaderType", None)
if export_type is not None:
combined_props.export_header_type = enumExportHeaderType[export_type][0]

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


sm64_classes = (
Expand All @@ -270,7 +268,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 @@ -287,17 +284,13 @@ 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()
sm64_anim_panel_unregister()


def sm64_register(registerPanels):
for cls in sm64_classes:
register_class(cls)

sm64_col_register() # register first, so panel goes above mat panel
sm64_bone_register()
sm64_cam_register()
Expand All @@ -310,6 +303,9 @@ def sm64_register(registerPanels):
sm64_dl_parser_register()
sm64_anim_register()

for cls in sm64_classes:
register_class(cls)

if registerPanels:
sm64_panel_register()

Expand Down Expand Up @@ -339,9 +335,6 @@ def sm64_register(registerPanels):


def sm64_unregister(unregisterPanels):
for cls in reversed(sm64_classes):
unregister_class(cls)

sm64_col_unregister() # register first, so panel goes above mat panel
sm64_bone_unregister()
sm64_cam_unregister()
Expand All @@ -354,6 +347,9 @@ def sm64_unregister(unregisterPanels):
sm64_dl_parser_unregister()
sm64_anim_unregister()

for cls in reversed(sm64_classes):
unregister_class(cls)

if unregisterPanels:
sm64_panel_unregister()

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 @@ -383,6 +383,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 @@ -494,63 +496,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 = bpy.context.scene.blenderToSM64Scale
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 = bpy.context.scene.blenderToSM64Scale
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.exportType == "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.group_name,
level_name,
)
self.report({"INFO"}, "Success!")
elif context.scene.fast64.sm64.exportType == "Insertable Binary":
exportCollisionInsertableBinary(
obj,
finalTransform,
final_transform,
bpy.path.abspath(context.scene.colInsertableBinaryPath),
False,
context.scene.colIncludeChildren,
Expand All @@ -572,7 +568,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 @@ -628,41 +624,17 @@ class SM64_ExportCollisionPanel(SM64_Panel):
bl_label = "SM64 Collision Exporter"
goal = "Export Object/Actor/Anim"

@classmethod
def poll(cls, context):
return context.scene.fast64.sm64.exportType != "C"

# 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.exportType == "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.exportType == "Insertable Binary":
if context.scene.fast64.sm64.exportType == "Insertable Binary":
col.prop(context.scene, "colInsertableBinaryPath")
else:
prop_split(col, context.scene, "colStartAddr", "Start Address")
Expand Down Expand Up @@ -696,7 +668,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 @@ -706,15 +677,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 @@ -737,20 +699,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