Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
28 changes: 28 additions & 0 deletions fast64_internal/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -2138,3 +2138,31 @@ def get_new_empty_object(
):
"""Creates and returns a new empty object"""
return get_new_object(name, None, do_select, location, rotation_euler, scale, parent)


class ExportUtils:
def __init__(self):
# get areas that are currently in local view mode
self.areas = []
for area in bpy.context.screen.areas:
if area.type == "VIEW_3D" and area.spaces.active.local_view is not None:
self.areas.append(area)

def __enter__(self):
# disable local views if enabled
for area in self.areas:
with bpy.context.temp_override(area=area):
bpy.ops.view3d.localview()

return self

def __exit__(self, exc_type, exc_value, traceback):
# restore local views
for area in self.areas:
with bpy.context.temp_override(area=area):
bpy.ops.view3d.localview()

if exc_value:
print("\nExecution type:", exc_type)
print("\nExecution value:", exc_value)
print("\nTraceback:", traceback)
17 changes: 9 additions & 8 deletions fast64_internal/z64/animated_mats/operators.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from bpy.utils import register_class, unregister_class
from bpy.types import Operator

from ...utility import raisePluginError
from ...utility import ExportUtils, raisePluginError


class Z64_ExportAnimatedMaterials(Operator):
Expand All @@ -12,13 +12,14 @@ class Z64_ExportAnimatedMaterials(Operator):
def execute(self, context):
from ..exporter.scene.animated_mats import SceneAnimatedMaterial

try:
SceneAnimatedMaterial.export()
self.report({"INFO"}, "Success!")
return {"FINISHED"}
except Exception as e:
raisePluginError(self, e)
return {"CANCELLED"}
with ExportUtils() as export_utils:
try:
SceneAnimatedMaterial.export()
self.report({"INFO"}, "Success!")
return {"FINISHED"}
except Exception as e:
raisePluginError(self, e)
return {"CANCELLED"}


class Z64_ImportAnimatedMaterials(Operator):
Expand Down
43 changes: 22 additions & 21 deletions fast64_internal/z64/animation/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from bpy.props import StringProperty, BoolProperty
from bpy.utils import register_class, unregister_class
from bpy.ops import object
from ...utility import PluginError, toAlnum, writeCData, raisePluginError
from ...utility import PluginError, ExportUtils, toAlnum, writeCData, raisePluginError
from .properties import OOTAnimExportSettingsProperty, OOTAnimImportSettingsProperty
from ..exporter.animation import ootExportLinkAnimation, ootExportNonLinkAnimation
from .importer import ootImportLinkAnimationC, ootImportNonLinkAnimationC
Expand Down Expand Up @@ -123,26 +123,27 @@ class OOT_ExportAnim(Operator):
# Called on demand (i.e. button press, menu item)
# Can also be called from operator search menu (Spacebar)
def execute(self, context):
try:
if len(context.selected_objects) == 0 or not isinstance(context.selected_objects[0].data, Armature):
raise PluginError("Armature not selected.")
if len(context.selected_objects) > 1:
raise PluginError("Multiple objects selected, make sure to select only one.")
armatureObj = context.selected_objects[0]
if context.mode != "OBJECT":
object.mode_set(mode="OBJECT")
except Exception as e:
raisePluginError(self, e)
return {"CANCELLED"}

try:
settings = context.scene.fast64.oot.animExportSettings
exportAnimationC(armatureObj, settings)
self.report({"INFO"}, "Success!")

except Exception as e:
raisePluginError(self, e)
return {"CANCELLED"} # must return a set
with ExportUtils() as export_utils:
try:
if len(context.selected_objects) == 0 or not isinstance(context.selected_objects[0].data, Armature):
raise PluginError("Armature not selected.")
if len(context.selected_objects) > 1:
raise PluginError("Multiple objects selected, make sure to select only one.")
armatureObj = context.selected_objects[0]
if context.mode != "OBJECT":
object.mode_set(mode="OBJECT")
except Exception as e:
raisePluginError(self, e)
return {"CANCELLED"}

try:
settings = context.scene.fast64.oot.animExportSettings
exportAnimationC(armatureObj, settings)
self.report({"INFO"}, "Success!")

except Exception as e:
raisePluginError(self, e)
return {"CANCELLED"} # must return a set

return {"FINISHED"} # must return a set

Expand Down
41 changes: 21 additions & 20 deletions fast64_internal/z64/collision/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from bpy.ops import object
from mathutils import Matrix

from ...utility import PluginError, raisePluginError
from ...utility import PluginError, ExportUtils, raisePluginError
from ..utility import getOOTScale
from ..exporter.collision import CollisionHeader
from .properties import OOTCollisionExportSettings
Expand All @@ -16,27 +16,28 @@ class OOT_ExportCollision(Operator):
bl_options = {"REGISTER", "UNDO", "PRESET"}

def execute(self, context):
obj = None
if context.mode != "OBJECT":
object.mode_set(mode="OBJECT")
if len(context.selected_objects) == 0:
raise PluginError("No object selected.")
obj = context.active_object
if obj.type != "MESH":
raise PluginError("No mesh object selected.")

try:
transform = Matrix.Scale(getOOTScale(obj.ootActorScale), 4)
settings: OOTCollisionExportSettings = context.scene.fast64.oot.collisionExportSettings
CollisionHeader.export(obj, transform, settings)

self.report({"INFO"}, "Success!")
return {"FINISHED"}
except Exception as e:
with ExportUtils() as export_utils:
obj = None
if context.mode != "OBJECT":
object.mode_set(mode="OBJECT")
raisePluginError(self, e)
return {"CANCELLED"} # must return a set
if len(context.selected_objects) == 0:
raise PluginError("No object selected.")
obj = context.active_object
if obj.type != "MESH":
raise PluginError("No mesh object selected.")

try:
transform = Matrix.Scale(getOOTScale(obj.ootActorScale), 4)
settings: OOTCollisionExportSettings = context.scene.fast64.oot.collisionExportSettings
CollisionHeader.export(obj, transform, settings)

self.report({"INFO"}, "Success!")
return {"FINISHED"}
except Exception as e:
if context.mode != "OBJECT":
object.mode_set(mode="OBJECT")
raisePluginError(self, e)
return {"CANCELLED"} # must return a set


oot_col_classes = (OOT_ExportCollision,)
Expand Down
92 changes: 47 additions & 45 deletions fast64_internal/z64/cutscene/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from bpy.props import StringProperty, EnumProperty, IntProperty
from bpy.types import Scene, Operator, Object
from bpy.utils import register_class, unregister_class
from ...utility import PluginError, raisePluginError
from ...utility import PluginError, ExportUtils, raisePluginError
from ...game_data import game_data
from ..collection_utility import getCollection
from .constants import ootEnumCSTextboxType
Expand Down Expand Up @@ -73,28 +73,29 @@ class OOT_ExportCutscene(Operator):
bl_options = {"REGISTER", "UNDO", "PRESET"}

def execute(self, context):
try:
if context.mode != "OBJECT":
object.mode_set(mode="OBJECT")
with ExportUtils() as export_utils:
try:
if context.mode != "OBJECT":
object.mode_set(mode="OBJECT")

if context.scene.fast64.oot.export_cutscene_obj is not None:
cs_obj = context.scene.fast64.oot.export_cutscene_obj
else:
cs_obj = context.view_layer.objects.active
if context.scene.fast64.oot.export_cutscene_obj is not None:
cs_obj = context.scene.fast64.oot.export_cutscene_obj
else:
cs_obj = context.view_layer.objects.active

if cs_obj is None or cs_obj.type != "EMPTY" or cs_obj.ootEmptyType != "Cutscene":
raise PluginError("You must select a cutscene object")
if cs_obj is None or cs_obj.type != "EMPTY" or cs_obj.ootEmptyType != "Cutscene":
raise PluginError("You must select a cutscene object")

if cs_obj.parent is not None:
raise PluginError("Cutscene object must not be parented to anything")
if cs_obj.parent is not None:
raise PluginError("Cutscene object must not be parented to anything")

Cutscene.export(cs_obj)
Cutscene.export(cs_obj)

self.report({"INFO"}, "Successfully exported cutscene")
return {"FINISHED"}
except Exception as e:
raisePluginError(self, e)
return {"CANCELLED"}
self.report({"INFO"}, "Successfully exported cutscene")
return {"FINISHED"}
except Exception as e:
raisePluginError(self, e)
return {"CANCELLED"}


class OOT_ExportAllCutscenes(Operator):
Expand All @@ -103,33 +104,34 @@ class OOT_ExportAllCutscenes(Operator):
bl_options = {"REGISTER", "UNDO", "PRESET"}

def execute(self, context):
try:
if context.mode != "OBJECT":
object.mode_set(mode="OBJECT")

cs_obj_list: list[Object] = []

for obj in context.view_layer.objects:
if obj.type == "EMPTY" and obj.ootEmptyType == "Cutscene":
if obj.parent is not None:
print(f"Parent: {obj.parent.name}, Object: {obj.name}")
raise PluginError("Cutscene object must not be parented to anything")

cs_obj_list.append(obj)

for count, cs_obj in enumerate(cs_obj_list, 1):
# skip the includes if this isn't the first cutscene
# skip the #endif directive if this isn't the last cutscene
Cutscene.export(cs_obj, count > 1, count < len(cs_obj_list))

if count == 0:
raise PluginError("Could not find any cutscenes to export")

self.report({"INFO"}, "Successfully exported " + str(count) + " cutscenes")
return {"FINISHED"}
except Exception as e:
raisePluginError(self, e)
return {"CANCELLED"}
with ExportUtils() as export_utils:
try:
if context.mode != "OBJECT":
object.mode_set(mode="OBJECT")

cs_obj_list: list[Object] = []

for obj in context.view_layer.objects:
if obj.type == "EMPTY" and obj.ootEmptyType == "Cutscene":
if obj.parent is not None:
print(f"Parent: {obj.parent.name}, Object: {obj.name}")
raise PluginError("Cutscene object must not be parented to anything")

cs_obj_list.append(obj)

for count, cs_obj in enumerate(cs_obj_list, 1):
# skip the includes if this isn't the first cutscene
# skip the #endif directive if this isn't the last cutscene
Cutscene.export(cs_obj, count > 1, count < len(cs_obj_list))

if count == 0:
raise PluginError("Could not find any cutscenes to export")

self.report({"INFO"}, "Successfully exported " + str(count) + " cutscenes")
return {"FINISHED"}
except Exception as e:
raisePluginError(self, e)
return {"CANCELLED"}


class OOT_SearchCSDestinationEnumOperator(Operator):
Expand Down
69 changes: 35 additions & 34 deletions fast64_internal/z64/f3d/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from mathutils import Matrix
from typing import Optional

from ...utility import CData, PluginError, raisePluginError, writeCData, toAlnum
from ...utility import CData, PluginError, ExportUtils, raisePluginError, writeCData, toAlnum
from ...f3d.f3d_parser import importMeshC, getImportData
from ...f3d.f3d_gbi import DLFormat, TextureExportSettings, ScrollMethod, get_F3D_GBI
from ...f3d.f3d_writer import TriangleConverterInfo, removeDL, saveStaticModel, getInfoDict
Expand Down Expand Up @@ -188,41 +188,42 @@ class OOT_ExportDL(Operator):
# Called on demand (i.e. button press, menu item)
# Can also be called from operator search menu (Spacebar)
def execute(self, context):
obj = None
if context.mode != "OBJECT":
object.mode_set(mode="OBJECT")
if len(context.selected_objects) == 0:
raise PluginError("Mesh not selected.")
obj = context.active_object
if obj.type != "MESH":
raise PluginError("Mesh not selected.")

finalTransform = Matrix.Scale(getOOTScale(obj.ootActorScale), 4)

try:
# exportPath, levelName = getPathAndLevel(context.scene.geoCustomExport,
# context.scene.geoExportPath, context.scene.geoLevelName,
# context.scene.geoLevelOption)

saveTextures = context.scene.saveTextures
exportSettings = context.scene.fast64.oot.DLExportSettings

ootConvertMeshToC(
obj,
finalTransform,
DLFormat.Static,
saveTextures,
exportSettings,
)

self.report({"INFO"}, "Success!")
return {"FINISHED"}

except Exception as e:
with ExportUtils() as export_utils:
obj = None
if context.mode != "OBJECT":
object.mode_set(mode="OBJECT")
raisePluginError(self, e)
return {"CANCELLED"} # must return a set
if len(context.selected_objects) == 0:
raise PluginError("Mesh not selected.")
obj = context.active_object
if obj.type != "MESH":
raise PluginError("Mesh not selected.")

finalTransform = Matrix.Scale(getOOTScale(obj.ootActorScale), 4)

try:
# exportPath, levelName = getPathAndLevel(context.scene.geoCustomExport,
# context.scene.geoExportPath, context.scene.geoLevelName,
# context.scene.geoLevelOption)

saveTextures = context.scene.saveTextures
exportSettings = context.scene.fast64.oot.DLExportSettings

ootConvertMeshToC(
obj,
finalTransform,
DLFormat.Static,
saveTextures,
exportSettings,
)

self.report({"INFO"}, "Success!")
return {"FINISHED"}

except Exception as e:
if context.mode != "OBJECT":
object.mode_set(mode="OBJECT")
raisePluginError(self, e)
return {"CANCELLED"} # must return a set


oot_dl_writer_classes = (
Expand Down
Loading