Skip to content

Commit

Permalink
cleanup - format
Browse files Browse the repository at this point in the history
  • Loading branch information
julienduroure committed Jan 13, 2025
1 parent 42ac3fe commit 99ceafa
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 32 deletions.
10 changes: 6 additions & 4 deletions addons/io_scene_gltf2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -816,9 +816,9 @@ class ExportGLTF2_Base(ConvertGLTF2_Base):
export_merge_animation: EnumProperty(
name='Merge Animation',
items=(('NLA_TRACK', 'NLA Track Names', 'Merge by NLA Track Names'),
('ACTION', 'Actions', 'Merge by Actions'),
('NONE', 'No Merge', 'Do not merge animations'),
),
('ACTION', 'Actions', 'Merge by Actions'),
('NONE', 'No Merge', 'Do not merge animations'),
),
description='Merge animations',
default='ACTION'
)
Expand Down Expand Up @@ -1503,7 +1503,7 @@ def export_panel_data_material(layout, operator):
col.active = operator.export_image_format != "WEBP" and not operator.export_materials in ['PLACEHOLDER', 'NONE']
col.prop(operator, "export_image_add_webp")
col = body.column()
col.active = operator.export_image_format != "WEBP" and not operator.export_materials in ['PLACEHOLDER', 'NONE']
col.active = operator.export_image_format != "WEBP" and not operator.export_materials in ['PLACEHOLDER', 'NONE']
col.prop(operator, "export_image_webp_fallback")

header, sub_body = body.panel("GLTF_export_data_material_unused", default_closed=True)
Expand Down Expand Up @@ -1642,6 +1642,7 @@ def export_panel_animation_notes(layout, operator):
body.label(text="- sampling is active")
body.label(text="- baking all objects is active")


def export_panel_animation_bake_and_merge(layout, operator):
header, body = layout.panel("GLTF_export_animation_bake_and_merge", default_closed=False)
header.label(text="Bake & Merge")
Expand Down Expand Up @@ -2015,6 +2016,7 @@ def import_bone_panel(layout, operator):
body.prop(operator, 'disable_bone_shape')
body.prop(operator, 'bone_shape_scale_factor')


def import_ux_panel(layout, operator):
header, body = layout.panel("GLTF_import_ux", default_closed=False)
header.label(text="Pipeline")
Expand Down
30 changes: 15 additions & 15 deletions addons/io_scene_gltf2/blender/exp/animation/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
from .anim_utils import reset_bone_matrix, reset_sk_data, link_samplers, add_slide_data, merge_tracks_perform, bake_animation, get_channelbag_for_slot



class ActionsData:
data_type = "ACTION"

Expand Down Expand Up @@ -75,6 +74,7 @@ def values(self):
def __len__(self):
return len(self.actions)


class ActionData:
def __init__(self, action):
self.action = action
Expand All @@ -89,7 +89,7 @@ def add_slot(self, slot, id_root, track):
self.slots.append(new_slot)

def sort(self):
#Implement sorting, to be sure to get:
# Implement sorting, to be sure to get:
# TRS first, and then SK
sort_items = {'OBJECT': 1, 'KEY': 2}
self.slots.sort(key=lambda x: sort_items.get(x.id_root))
Expand All @@ -104,6 +104,7 @@ def __init__(self, slot, id_root, track):
self.id_root = id_root
self.track = track


def gather_actions_animations(export_settings):

prepare_actions_range(export_settings)
Expand Down Expand Up @@ -154,6 +155,8 @@ def gather_actions_animations(export_settings):
# For example, cache will get frame 1/4/7/10 if step is 3, with an action starting at frame 1
# If all backing is enabled, and scene start at 0, we will get frame 0/3/6/9 => Cache will fail
# Set the reference frame from the first action retrieve, and align all actions to this frame


def _align_frame_start(reference_frame_start, frame, export_settings):

if reference_frame_start is None:
Expand Down Expand Up @@ -366,7 +369,6 @@ def gather_action_animations(obj_uuid: int,
# We can return early if no actions
return animations, tracks


# Keep current situation and prepare export
current_action = None
current_action_slot = None
Expand Down Expand Up @@ -592,7 +594,7 @@ def gather_action_animations(obj_uuid: int,
obj_uuid, prop, blender_action.name, slot.slot.handle, True, get_gltf_interpolation("LINEAR"), export_settings)
elif type_ == "SK":
channel = gather_sampled_sk_channel(obj_uuid, blender_action.name, slot.slot.handle, export_settings)
elif type_ == "EXTRA": #TODOSLOT slot-3
elif type_ == "EXTRA": # TODOSLOT slot-3
channel = None
else:
export_settings['log'].error("Type unknown. Should not happen")
Expand Down Expand Up @@ -655,11 +657,10 @@ def gather_action_animations(obj_uuid: int,
channels=all_channels,
name=blender_action.name,
extras=__gather_extras(blender_action, export_settings),
samplers=[], # This will be generated later, in link_samplers
samplers=[], # This will be generated later, in link_samplers
extensions=None
)


link_samplers(animation, export_settings)
animations.append(animation)

Expand All @@ -676,9 +677,9 @@ def gather_action_animations(obj_uuid: int,
tracks[blender_action.name] = []
tracks[blender_action.name].append(offset + len(animations) - 1)
elif export_settings['gltf_merge_animation'] == "NONE":
pass # Nothing to store, we are not going to merge animations
pass # Nothing to store, we are not going to merge animations
else:
pass # This should not happen (or the developer added a new option, and forget to take it into account here)
pass # This should not happen (or the developer added a new option, and forget to take it into account here)


# Restoring current situation
Expand All @@ -693,7 +694,7 @@ def gather_action_animations(obj_uuid: int,
if blender_object.animation_data.action is not None:
blender_object.animation_data.action_slot = None
blender_object.animation_data.action = None
elif blender_object.animation_data.action.name != current_action.name: #TODO action name is not unique (library)
elif blender_object.animation_data.action.name != current_action.name: # TODO action name is not unique (library)
# Restore action that was active at start of exporting
reset_bone_matrix(blender_object, export_settings)
blender_object.animation_data.action = current_action
Expand Down Expand Up @@ -742,12 +743,12 @@ def gather_action_animations(obj_uuid: int,

return animations, tracks


@cached
def __get_blender_actions(obj_uuid: str,
export_settings
) -> ActionsData:


actions = ActionsData()

blender_object = export_settings['vtree'].nodes[obj_uuid].blender_object
Expand All @@ -768,7 +769,7 @@ def __get_blender_actions(obj_uuid: str,
else:
# Store Action info
new_action = ActionData(blender_object.animation_data.action)
new_action.add_slot(blender_object.animation_data.action_slot, blender_object.animation_data.action_slot.id_root, None) # Active action => No track
new_action.add_slot(blender_object.animation_data.action_slot, blender_object.animation_data.action_slot.id_root, None) # Active action => No track
actions.add_action(new_action)

# Collect associated strips from NLA tracks.
Expand Down Expand Up @@ -852,14 +853,13 @@ def __get_blender_actions(obj_uuid: str,

# Check the action is not in list of actions to ignore
if hasattr(bpy.data.scenes[0], "gltf_action_filter") and id(act) in [id(item.action)
for item in bpy.data.scenes[0].gltf_action_filter if item.keep is False]:
for item in bpy.data.scenes[0].gltf_action_filter if item.keep is False]:
continue # We ignore this action

new_action = ActionData(act)
new_action.add_slot(slot, slot.id_root, None)
actions.add_action(new_action)


export_user_extensions('gather_actions_hook', export_settings, blender_object, actions)

# Duplicate actions/slot are already managed when inserting data
Expand Down Expand Up @@ -901,7 +901,7 @@ def __get_blender_actions_broadcast(obj_uuid, export_settings):
for blender_action in bpy.data.actions:
if hasattr(bpy.data.scenes[0], "gltf_action_filter") and id(blender_action) in [
id(item.action) for item in bpy.data.scenes[0].gltf_action_filter if item.keep is False]:
continue # We ignore this action
continue # We ignore this action

new_action = ActionData(blender_action)

Expand Down Expand Up @@ -929,7 +929,7 @@ def __get_blender_actions_broadcast(obj_uuid, export_settings):
new_action.add_slot(slot, slot.id_root, None)

else:
pass # TODOSLOT slot-3
pass # TODOSLOT slot-3

if new_action.has_slots():
blender_actions.add_action(new_action)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ def gather_animation_fcurves(

return channels, to_be_sampled, extra_samplers


def __gather_channels_fcurves(
obj_uuid: str,
blender_action: bpy.types.Action,
slot_handle: int,
export_settings):
return gather_animation_fcurves_channels(obj_uuid, blender_action, slot_handle, export_settings)

Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ def all_equal(lst):

return False


def __get_channelbag_for_slot_handle(action, slot_handle):
for layer in action.layers:
for strip in layer.strips:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,3 @@ def gather_action_object_sampled(object_uuid: str,
def __gather_channels(object_uuid: str, blender_action_name: str, slot_handle: int,
export_settings) -> typing.List[gltf2_io.AnimationChannel]:
return gather_object_sampled_channels(object_uuid, blender_action_name, slot_handle, export_settings)

Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def gather_action_sk_sampled(object_uuid: str,

return channels


def __gather_channels(object_uuid: str, blender_action_name: str, slot_handle: int,
export_settings) -> typing.List[gltf2_io.AnimationChannel]:
return gather_sk_sampled_channels(object_uuid, blender_action_name, slot_handle, export_settings)

8 changes: 3 additions & 5 deletions addons/io_scene_gltf2/blender/exp/animation/tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def values(self):
for tr in self.tracks:
yield tr


class TrackData:
def __init__(self, tracks, track_name, on_type):
self.tracks = tracks
Expand Down Expand Up @@ -254,9 +255,9 @@ def gather_track_animations(obj_uuid: int,
tracks[blender_action.name] = []
tracks[blender_action.name].append(offset + len(animations) - 1) # Store index of animation in animations
elif export_settings['gltf_merge_animation'] == "NONE":
pass # Nothing to store, we are not going to merge animations
pass # Nothing to store, we are not going to merge animations
else:
pass # This should not happen (or the developer added a new option, and forget to take it into account here)
pass # This should not happen (or the developer added a new option, and forget to take it into account here)

# Restoring muting
if track_data.on_type == "OBJECT":
Expand Down Expand Up @@ -372,7 +373,6 @@ def __get_nla_tracks_obj(obj_uuid: str, export_settings):

tracks_data.add(track_data)


# Start a new stack
current_exported_tracks.append(stored_track)

Expand Down Expand Up @@ -776,8 +776,6 @@ def __get_nla_tracks_material(blender_type_data, blender_id, export_settings):

tracks_data.add(track_data)



return tracks_data


Expand Down
1 change: 1 addition & 0 deletions addons/io_scene_gltf2/blender/exp/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def _is_driver_baking(val):

return True


def datacache(func):

def reset_all_cache():
Expand Down
1 change: 0 additions & 1 deletion addons/io_scene_gltf2/blender/imp/animation_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,3 @@ def do_channel(gltf, anim_idx, node_idx, channel):

import_user_extensions('gather_import_animation_channel_after_hook',
gltf, animation, vnode, path, channel, action)

1 change: 0 additions & 1 deletion addons/io_scene_gltf2/blender/imp/animation_pointer.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def do_channel(gltf, anim_idx, channel, asset, asset_idx, asset_type, name=None,
else:
id_root = asset_type


action, slot = BlenderPointerAnim.get_or_create_action_and_slot(
gltf, anim_idx, asset, asset_idx, id_root, name_=name)

Expand Down
13 changes: 10 additions & 3 deletions addons/io_scene_gltf2/blender/imp/animation_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
from .vnode import VNode

# Here data can be object, object.data, material, material.node_tree, camera, light


def simulate_stash(data, track_name, action, action_slot, start_frame=None):
# Simulate stash :
# * add a track
Expand All @@ -35,6 +37,7 @@ def simulate_stash(data, track_name, action, action_slot, start_frame=None):
new_track.lock = True
new_track.mute = True


def restore_animation_on_object(data, anim_name):
""" here, data can be an object, shapekeys, camera or light data """
if not getattr(data, 'animation_data', None):
Expand Down Expand Up @@ -91,6 +94,7 @@ def make_fcurve(action, slot, co, data_path, index=0, group_name='', interpolati

return fcurve


def get_channelbag_for_slot(action, slot):
# This is on purpose limited to the first layer and strip. To support more
# than 1 layer, a rewrite of this operator is needed which ideally would
Expand All @@ -103,6 +107,8 @@ def get_channelbag_for_slot(action, slot):

# This is use for TRS & weights animations
# For pointers, see the same function in animation_pointer.py


def get_or_create_action_and_slot(gltf, vnode_idx, anim_idx, path):
animation = gltf.data.animations[anim_idx]
vnode = gltf.vnodes[vnode_idx]
Expand Down Expand Up @@ -144,7 +150,7 @@ def get_or_create_action_and_slot(gltf, vnode_idx, anim_idx, path):
# It helps to automatically assign the right slot, and it will get range correctly without setting it by hand
gltf.needs_stash.append((obj.data.shape_keys, action, slot))
else:
pass # This should not happen, as we only support TRS and weights animations here
pass # This should not happen, as we only support TRS and weights animations here
# animation pointer is managed in another place

action.layers[0].strips[0].channelbags.new(slot)
Expand All @@ -165,7 +171,7 @@ def get_or_create_action_and_slot(gltf, vnode_idx, anim_idx, path):
# It helps to automatically assign the right slot, and it will get range correctly without setting it by hand
gltf.needs_stash.append((obj.data.shape_keys, action, slot))
else:
pass # This should not happen, as we only support TRS and weights animations here
pass # This should not happen, as we only support TRS and weights animations here
# animation pointer is managed in another place

action.layers[0].strips[0].channelbags.new(slot)
Expand All @@ -177,11 +183,12 @@ def get_or_create_action_and_slot(gltf, vnode_idx, anim_idx, path):
# We now have action and slot, we can return the right slot
return action, slot


def __get_id_from_path(path):
if path in ["translation", "rotation", "scale"]:
return "OBJECT"
elif path == "weights":
return "KEY"
else:
pass # This should not happen, as we only support TRS and weights animations here
pass # This should not happen, as we only support TRS and weights animations here
# animation pointer is managed in another place
1 change: 1 addition & 0 deletions addons/io_scene_gltf2/blender/imp/animation_weight.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from ...io.imp.gltf2_io_binary import BinaryData
from .animation_utils import make_fcurve, get_or_create_action_and_slot


class BlenderWeightAnim():
"""Blender ShapeKey Animation."""
def __new__(cls, *args, **kwargs):
Expand Down
1 change: 1 addition & 0 deletions addons/io_scene_gltf2/io/com/draco.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def dll_path() -> Path:
if library_name is None:
print('WARNING', 'Unsupported platform {}, Draco mesh compression is unavailable'.format(sys.platform))


def dll_exists(quiet=False) -> bool:
"""
Checks whether the DLL path exists.
Expand Down

0 comments on commit 99ceafa

Please sign in to comment.