Skip to content
Draft
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
59 changes: 59 additions & 0 deletions fast64_internal/gltf_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
add_3_2_hooks,
get_version,
)
from .sm64.gltf_extension import SM64Extensions

# Original implementation from github.com/Mr-Wiseguy/gltf64-blender

Expand Down Expand Up @@ -87,6 +88,8 @@ def __init__(self):
self.sub_extensions = []
if self.settings.f3d.use:
self.sub_extensions.append(F3DExtensions(self))
if bpy.context.scene.gameEditorMode == "SM64":
self.sub_extensions.append(SM64Extensions(self))


class glTF2ExportUserExtension(GlTF2Extension):
Expand All @@ -101,6 +104,28 @@ def gather_node_hook(self, gltf2_node, blender_object, export_settings):
export_settings,
)

def animation_action_object_sampled(
self, gltf2_animation, blender_object, blender_action, cache_key, export_settings
):
self.call_hooks(
"gather_any_animation_hook",
'Animation "{args[1].name}"',
gltf2_animation,
blender_action,
blender_object,
export_settings,
)

def gather_animation_hook(self, gltf2_animation, blender_action, blender_object, export_settings):
self.call_hooks(
"gather_any_animation_hook",
'Animation "{args[1].name}"',
gltf2_animation,
blender_action,
blender_object,
export_settings,
)

def gather_mesh_hook(self, gltf2_mesh, blender_mesh, blender_object, vertex_groups, modifiers, *last_args):
materials, export_settings = last_args[-2:] # 3.2
self.call_hooks(
Expand All @@ -124,6 +149,24 @@ def gather_material_hook(self, gltf2_material, blender_material, export_settings
export_settings,
)

def gather_joint_hook(self, gltf2_node, blender_bone, export_settings):
self.call_hooks(
"gather_joint_hook",
'Joint "{args[1].name}"',
gltf2_node,
blender_bone,
export_settings,
)

def gather_scene_hook(self, gltf2_scene, blender_scene, export_settings):
self.call_hooks(
"gather_scene_hook",
'Scene "{args[1].name}"',
gltf2_scene,
blender_scene,
export_settings,
)

def gather_gltf_extensions_hook(self, _gltf, _export_settings):
modify_f3d_nodes_for_export(True)

Expand Down Expand Up @@ -160,6 +203,20 @@ def gather_import_mesh_after_hook(self, gltf_mesh, blender_mesh, gltf):
gltf,
)

def gather_import_animation_channel_after_hook(
self, gltf_animation, gltf_node, path, channel, blender_action, gltf
):
self.call_hooks(
"gather_import_animation_channel_after_hook",
'Animation Channel "{args[4].name}"',
gltf_animation,
gltf_node,
path,
channel,
blender_action,
gltf,
)


class Fast64GlTFSettings(PropertyGroup):
verbose: BoolProperty(
Expand All @@ -168,6 +225,7 @@ class Fast64GlTFSettings(PropertyGroup):
)
f3d: PointerProperty(type=F3DGlTFSettings)
game: BoolProperty(default=True, name="Export current game mode")
include_hints: BoolProperty(default=True, name="Include hints")

def to_dict(self):
return prop_group_to_json(self)
Expand All @@ -187,6 +245,7 @@ def draw_props(self, scene, layout: UILayout):
col.separator()

col.prop(self, "verbose")
col.prop(self, "include_hints")

game_mode = scene.gameEditorMode
if game_mode == "Homebrew":
Expand Down
23 changes: 15 additions & 8 deletions fast64_internal/gltf_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ def get_gltf_image_from_blender_image(blender_image_name: str, export_settings:
class GlTF2SubExtension:
required: bool = False

@property
def hints(self):
return self.extension.settings.include_hints

def post_init(self):
pass

Expand All @@ -136,25 +140,28 @@ def print_verbose(self, content):
pprint(content)

def append_extension(self, gltf_prop, name: str, data: dict | None = None, required=False, skip_if_empty=True):
if skip_if_empty and not data and data is not None: # If none, assume it shouldn´t skip
if skip_if_empty and (data is None or not any(data)):
return
self.print_verbose(f"Appending {name} extension")
if data:
self.print_verbose(data)
if gltf_prop.extensions is None:
gltf_prop.extensions = {}
gltf_prop.extensions[name] = self.extension.Extension(
self.print_verbose(data)
extension = self.extension.Extension(
name=name,
extension=data if data else {},
required=required if required else self.required,
)
return gltf_prop.extensions[name]
if isinstance(gltf_prop, dict):
gltf_prop.setdefault("extensions", {})[name] = extension
else:
if gltf_prop.extensions is None:
gltf_prop.extensions = {}
gltf_prop.extensions[name] = extension
return extension

def get_extension(self, gltf_prop, name: str):
if gltf_prop.extensions is None:
return None
data = gltf_prop.extensions.get(name, None)
if data and any(data):
if data is not None and any(data):
self.print_verbose(data)
return data

Expand Down
4 changes: 2 additions & 2 deletions fast64_internal/panels.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ def poll(cls, context):
return False
elif cls.import_panel and not sm64_props.show_importing_menus:
return False
elif cls.decomp_only and sm64_props.export_type != "C":
elif cls.decomp_only and sm64_props.legacy_export_type != "C":
return False
elif cls.binary_only and sm64_props.export_type == "C":
elif cls.binary_only and sm64_props.legacy_export_type == "C":
return False
scene_goal = sm64_props.goal
return scene_goal == "All" or sm64_props.goal == cls.goal or cls.goal == "All"
Expand Down
12 changes: 12 additions & 0 deletions fast64_internal/sm64/animation/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,18 @@ def evaluate(cls, value: str | int):
else: # the value was not evaluated
return value

def to_dict(self):
return {name: bool(self & flag) for name, flag in SM64_AnimFlags.props_to_flags().items()}

@classmethod
def from_dict(cls, data: dict):
flags = cls(0)
props = cls.props_to_flags()
for prop, value in data.items():
if value and prop in props:
flags |= props[prop]
return flags


@dataclasses.dataclass
class SM64_AnimHeader:
Expand Down
12 changes: 6 additions & 6 deletions fast64_internal/sm64/animation/constants.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import struct
import re

from ...utility import intToHex
from ...utility import intToHex, toAlnum
from ..sm64_constants import ACTOR_PRESET_INFO, ActorPresetInfo

HEADER_STRUCT = struct.Struct(">h h h h h h I I I")
Expand All @@ -10,7 +10,7 @@
TABLE_ELEMENT_PATTERN = re.compile( # strict but only in the sense that it requires valid c code
r"""
(?:\[\s*(?P<enum>\w+)\s*\]\s*=\s*)? # Don´t capture brackets or equal, works with nums
(?:(?:&\s*(?P<element>\w+))|(?P<null>NULL)) # Capture element or null, element requires &
(?:(?:&\s*(?P<element>\w+))|(?P<null>NULL|0)) # Capture element or null, element requires &
(?:\s*,|) # allow no comma, techinically not correct but no other method works
""",
re.DOTALL | re.VERBOSE | re.MULTILINE,
Expand Down Expand Up @@ -73,16 +73,16 @@
]


enum_animated_behaviours = [("Custom", "Custom Behavior", "Custom"), ("", "Presets", "")]
enum_anim_tables = [("Custom", "Custom", "Custom"), ("", "Presets", "")]
enum_animated_behaviours = [("CUSTOM", "Custom Behavior", "Custom"), ("", "Presets", "")]
enum_anim_tables = [("CUSTOM", "Custom", "Custom"), ("", "Presets", "")]
for actor_name, preset_info in ACTOR_PRESET_INFO.items():
if not preset_info.animation:
continue
behaviours = ActorPresetInfo.get_member_as_dict(actor_name, preset_info.animation.behaviours)
enum_animated_behaviours.extend(
[(intToHex(address), name, intToHex(address)) for name, address in behaviours.items()]
[(toAlnum(name.upper()), name, intToHex(address)) for name, address in behaviours.items()]
)
tables = ActorPresetInfo.get_member_as_dict(actor_name, preset_info.animation.address)
enum_anim_tables.extend(
[(name, name, f"{intToHex(address)}, {preset_info.level}") for name, address in tables.items()]
[(toAlnum(name.upper()), name, f"{intToHex(address)}, {preset_info.level}") for name, address in tables.items()]
)
Loading