Skip to content

Commit

Permalink
[SM64] Animations Rewrite/Rework
Browse files Browse the repository at this point in the history
  • Loading branch information
Lilaa3 committed Sep 30, 2024
1 parent ddd6969 commit 8dd4313
Show file tree
Hide file tree
Showing 32 changed files with 7,615 additions and 1,597 deletions.
14 changes: 12 additions & 2 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
repo_settings_operators_unregister,
)

from .fast64_internal.sm64 import sm64_register, sm64_unregister
from .fast64_internal.sm64 import sm64_register, sm64_unregister, SM64_ActionProperty
from .fast64_internal.sm64.sm64_constants import sm64_world_defaults
from .fast64_internal.sm64.settings.properties import SM64_Properties
from .fast64_internal.sm64.sm64_geolayout_bone import SM64_BoneProperties
Expand Down Expand Up @@ -227,6 +227,14 @@ class Fast64_Properties(bpy.types.PropertyGroup):
renderSettings: bpy.props.PointerProperty(type=Fast64RenderSettings_Properties, name="Fast64 Render Settings")


class Fast64_ActionProperties(bpy.types.PropertyGroup):
"""
Properties in Action.fast64.
"""

sm64: bpy.props.PointerProperty(type=SM64_ActionProperty, name="SM64 Properties")


class Fast64_BoneProperties(bpy.types.PropertyGroup):
"""
Properties in bone.fast64 (bpy.types.Bone)
Expand Down Expand Up @@ -314,6 +322,7 @@ def draw(self, context):
Fast64RenderSettings_Properties,
ManualUpdatePreviewOperator,
Fast64_Properties,
Fast64_ActionProperties,
Fast64_BoneProperties,
Fast64_ObjectProperties,
F3D_GlobalSettingsPanel,
Expand Down Expand Up @@ -457,7 +466,7 @@ def register():
bpy.types.Scene.fast64 = bpy.props.PointerProperty(type=Fast64_Properties, name="Fast64 Properties")
bpy.types.Bone.fast64 = bpy.props.PointerProperty(type=Fast64_BoneProperties, name="Fast64 Bone Properties")
bpy.types.Object.fast64 = bpy.props.PointerProperty(type=Fast64_ObjectProperties, name="Fast64 Object Properties")

bpy.types.Action.fast64 = bpy.props.PointerProperty(type=Fast64_ActionProperties, name="Fast64 Action Properties")
bpy.app.handlers.load_post.append(after_load)


Expand Down Expand Up @@ -486,6 +495,7 @@ def unregister():
del bpy.types.Scene.fast64
del bpy.types.Bone.fast64
del bpy.types.Object.fast64
del bpy.types.Action.fast64

repo_settings_operators_unregister()

Expand Down
12 changes: 6 additions & 6 deletions fast64_internal/f3d_material_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,16 @@ def convertAllBSDFtoF3D(objs, renameUV):
def convertBSDFtoF3D(obj, index, material, materialDict):
if not material.use_nodes:
newMaterial = createF3DMat(obj, preset="Shaded Solid", index=index)
f3dMat = newMaterial.f3d_mat if newMaterial.mat_ver > 3 else newMaterial
f3dMat.default_light_color = material.diffuse_color
with bpy.context.temp_override(material=newMaterial):
newMaterial.f3d_mat.default_light_color = material.diffuse_color
updateMatWithName(newMaterial, material, materialDict)

elif "Principled BSDF" in material.node_tree.nodes:
tex0Node = material.node_tree.nodes["Principled BSDF"].inputs["Base Color"]
if len(tex0Node.links) == 0:
newMaterial = createF3DMat(obj, preset=getDefaultMaterialPreset("Shaded Solid"), index=index)
f3dMat = newMaterial.f3d_mat if newMaterial.mat_ver > 3 else newMaterial
f3dMat.default_light_color = tex0Node.default_value
with bpy.context.temp_override(material=newMaterial):
newMaterial.f3d_mat.default_light_color = tex0Node.default_value
updateMatWithName(newMaterial, material, materialDict)
else:
if isinstance(tex0Node.links[0].from_node, bpy.types.ShaderNodeTexImage):
Expand All @@ -213,8 +213,8 @@ def convertBSDFtoF3D(obj, index, material, materialDict):
else:
presetName = getDefaultMaterialPreset("Shaded Texture")
newMaterial = createF3DMat(obj, preset=presetName, index=index)
f3dMat = newMaterial.f3d_mat if newMaterial.mat_ver > 3 else newMaterial
f3dMat.tex0.tex = tex0Node.links[0].from_node.image
with bpy.context.temp_override(material=newMaterial):
newMaterial.f3d_mat.tex0.tex = tex0Node.links[0].from_node.image
updateMatWithName(newMaterial, material, materialDict)
else:
print("Principled BSDF material does not have an Image Node attached to its Base Color.")
Expand Down
10 changes: 10 additions & 0 deletions fast64_internal/oot/oot_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,16 @@ def ootGetObjectHeaderPath(isCustomExport: bool, exportPath: str, folderName: st
return filepath


def ootGetObjectHeaderPath(isCustomExport: bool, exportPath: str, folderName: str) -> str:
if isCustomExport:
filepath = exportPath
else:
filepath = os.path.join(
ootGetPath(exportPath, isCustomExport, "assets/objects/", folderName, False, False), folderName + ".h"
)
return filepath


def ootGetPath(exportPath, isCustomExport, subPath, folderName, makeIfNotExists, useFolderForCustom):
if isCustomExport:
path = bpy.path.abspath(os.path.join(exportPath, (folderName if useFolderForCustom else "")))
Expand Down
64 changes: 59 additions & 5 deletions fast64_internal/operators.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
import bpy, mathutils, math
from bpy.types import Operator, Context, UILayout
from cProfile import Profile
from pstats import SortKey, Stats
from typing import Optional

import bpy, mathutils
from bpy.types import Operator, Context, UILayout, EnumProperty
from bpy.utils import register_class, unregister_class
from .utility import *
from .f3d.f3d_material import *

from .utility import (
cleanupTempMeshes,
get_mode_set_from_context_mode,
raisePluginError,
parentObject,
store_original_meshes,
store_original_mtx,
)
from .f3d.f3d_material import createF3DMat


def addMaterialByName(obj, matName, preset):
Expand All @@ -14,20 +26,29 @@ def addMaterialByName(obj, matName, preset):
material.name = matName


PROFILE_ENABLED = False


class OperatorBase(Operator):
"""Base class for operators, keeps track of context mode and sets it back after running
execute_operator() and catches exceptions for raisePluginError()"""

context_mode: str = ""
icon = "NONE"

@classmethod
def is_enabled(cls, context: Context, **op_values):
return True

@classmethod
def draw_props(cls, layout: UILayout, icon="", text: Optional[str] = None, **op_values):
"""Op args are passed to the operator via setattr()"""
icon = icon if icon else cls.icon
layout = layout.column()
op = layout.operator(cls.bl_idname, icon=icon, text=text)
for key, value in op_values.items():
setattr(op, key, value)
layout.enabled = cls.is_enabled(bpy.context, **op_values)
return op

def execute_operator(self, context: Context):
Expand All @@ -40,7 +61,12 @@ def execute(self, context: Context):
try:
if self.context_mode and self.context_mode != starting_mode_set:
bpy.ops.object.mode_set(mode=self.context_mode)
self.execute_operator(context)
if PROFILE_ENABLED:
with Profile() as profile:
self.execute_operator(context)
print(Stats(profile).strip_dirs().sort_stats(SortKey.CUMULATIVE).print_stats())
else:
self.execute_operator(context)
return {"FINISHED"}
except Exception as exc:
raisePluginError(self, exc)
Expand All @@ -53,6 +79,34 @@ def execute(self, context: Context):
bpy.ops.object.mode_set(mode=starting_mode_set)


class SearchEnumOperatorBase(OperatorBase):
bl_description = "Search Enum"
bl_label = "Search"
bl_property = None
bl_options = {"UNDO"}

@classmethod
def draw_props(cls, layout: UILayout, data, prop: str, name: str):
row = layout.row()
if name:
row.label(text=name)
row.prop(data, prop, text="")
row.operator(cls.bl_idname, icon="VIEWZOOM", text="")

def update_enum(self, context: Context):
raise NotImplementedError()

def execute_operator(self, context: Context):
assert self.bl_property
self.report({"INFO"}, f"Selected: {getattr(self, self.bl_property)}")
self.update_enum(context)
context.region.tag_redraw()

def invoke(self, context: Context, _):
context.window_manager.invoke_search_popup(self)
return {"RUNNING_MODAL"}


class AddWaterBox(OperatorBase):
bl_idname = "object.add_water_box"
bl_label = "Add Water Box"
Expand Down
33 changes: 24 additions & 9 deletions fast64_internal/sm64/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
from bpy.types import PropertyGroup
from bpy.props import PointerProperty
from bpy.utils import register_class, unregister_class

from .settings import (
settings_props_register,
settings_props_unregister,
Expand Down Expand Up @@ -83,14 +87,23 @@
sm64_dl_writer_unregister,
)

from .sm64_anim import (
sm64_anim_panel_register,
sm64_anim_panel_unregister,
sm64_anim_register,
sm64_anim_unregister,
from .animation import (
anim_panel_register,
anim_panel_unregister,
anim_register,
anim_unregister,
SM64_ActionAnimProperty,
)


class SM64_ActionProperty(PropertyGroup):
"""
Properties in Action.fast64.sm64.
"""

animation: PointerProperty(type=SM64_ActionAnimProperty, name="SM64 Properties")


def sm64_panel_register():
settings_panels_register()
tools_panels_register()
Expand All @@ -103,7 +116,7 @@ def sm64_panel_register():
sm64_spline_panel_register()
sm64_dl_writer_panel_register()
sm64_dl_parser_panel_register()
sm64_anim_panel_register()
anim_panel_register()


def sm64_panel_unregister():
Expand All @@ -118,12 +131,13 @@ def sm64_panel_unregister():
sm64_spline_panel_unregister()
sm64_dl_writer_panel_unregister()
sm64_dl_parser_panel_unregister()
sm64_anim_panel_unregister()
anim_panel_unregister()


def sm64_register(register_panels: bool):
tools_operators_register()
tools_props_register()
anim_register()
sm64_col_register()
sm64_bone_register()
sm64_cam_register()
Expand All @@ -134,8 +148,8 @@ def sm64_register(register_panels: bool):
sm64_spline_register()
sm64_dl_writer_register()
sm64_dl_parser_register()
sm64_anim_register()
settings_props_register()
register_class(SM64_ActionProperty)

if register_panels:
sm64_panel_register()
Expand All @@ -144,6 +158,7 @@ def sm64_register(register_panels: bool):
def sm64_unregister(unregister_panels: bool):
tools_operators_unregister()
tools_props_unregister()
anim_unregister()
sm64_col_unregister()
sm64_bone_unregister()
sm64_cam_unregister()
Expand All @@ -154,8 +169,8 @@ def sm64_unregister(unregister_panels: bool):
sm64_spline_unregister()
sm64_dl_writer_unregister()
sm64_dl_parser_unregister()
sm64_anim_unregister()
settings_props_unregister()
unregister_class(SM64_ActionProperty)

if unregister_panels:
sm64_panel_unregister()
15 changes: 15 additions & 0 deletions fast64_internal/sm64/animation/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from .operators import anim_ops_register, anim_ops_unregister
from .properties import anim_props_register, anim_props_unregister, SM64_ArmatureAnimProperties, SM64_ActionAnimProperty
from .panels import anim_panel_register, anim_panel_unregister
from .exporting import export_animation, export_animation_table
from .utility import get_anim_obj, is_obj_animatable


def anim_register():
anim_ops_register()
anim_props_register()


def anim_unregister():
anim_ops_unregister()
anim_props_unregister()
Loading

0 comments on commit 8dd4313

Please sign in to comment.