* auto_export now injecting the list of available animations into the "Animated" component
  for any object with animations
 * modified bevy side struct to match
This commit is contained in:
kaosat.dev 2024-03-21 15:25:50 +01:00
parent a001ee21f6
commit 4f50c4f6d2
4 changed files with 42 additions and 12 deletions

View File

@ -17,4 +17,6 @@ pub struct AnimationPlayerLink(pub Entity);
#[derive(Component, Reflect, Default, Debug)] #[derive(Component, Reflect, Default, Debug)]
#[reflect(Component)] #[reflect(Component)]
pub struct Animated; pub struct Animated{
pub animations: Vec<String>
}

View File

@ -3520,8 +3520,16 @@
"additionalProperties": false, "additionalProperties": false,
"isComponent": true, "isComponent": true,
"isResource": false, "isResource": false,
"properties": {}, "properties": {
"required": [], "animations": {
"type": {
"$ref": "#/$defs/alloc::vec::Vec<alloc::string::String>"
}
}
},
"required": [
"animations"
],
"short_name": "Animated", "short_name": "Animated",
"title": "bevy_gltf_blueprints::animation::Animated", "title": "bevy_gltf_blueprints::animation::Animated",
"type": "object", "type": "object",

View File

@ -25,19 +25,40 @@ def remove_unwanted_custom_properties(object):
del object[cp] del object[cp]
# TODO: rename actions ? # TODO: rename actions ?
# reference https://github.com/KhronosGroup/glTF-Blender-IO/blob/main/addons/io_scene_gltf2/blender/exp/animation/gltf2_blender_gather_action.py#L481
def copy_animation_data(source, target): def copy_animation_data(source, target):
"""if source.data: """if source.data:
data = source.data.copy() data = source.data.copy()
target.data = data""" target.data = data"""
if source.animation_data and source.animation_data: if source.animation_data and source.animation_data:
#print("copying animation data from", source.name, "to", target.name) #print("copying animation data from", source.name, "to", target.name)
"""print("I have animation data") print("I have animation data")
ad = source.animation_data ad = source.animation_data
if ad.action: """if ad.action:
print(source.name,'uses',ad.action.name) print(source.name,'uses',ad.action.name)"""
for t in ad.nla_tracks:
for s in t.strips: animations = []
print(source.name,'uses',s.action.name)""" blender_actions = []
blender_tracks = {}
# TODO: this might need to be modified/ adapted to match the standard gltf exporter settings
for track in ad.nla_tracks:
#print("track", track.name, track.active)
non_muted_strips = [strip for strip in track.strips if strip.action is not None and strip.mute is False]
for strip in non_muted_strips: #t.strips:
print(" ", source.name,'uses',strip.action.name, "active", strip.active, "action", strip.action)
blender_actions.append(strip.action)
blender_tracks[strip.action.name] = track.name
# Remove duplicate actions.
blender_actions = list(set(blender_actions))
# sort animations alphabetically (case insensitive) so they have a defined order and match Blender's Action list
blender_actions.sort(key = lambda a: a.name.lower())
for action in blender_actions:
animations.append(blender_tracks[action.name])
print("animations", animations)
"""if target.animation_data == None: """if target.animation_data == None:
target.animation_data_create() target.animation_data_create()
@ -46,7 +67,7 @@ def copy_animation_data(source, target):
with bpy.context.temp_override(active_object=source, selected_editable_objects=[target]): with bpy.context.temp_override(active_object=source, selected_editable_objects=[target]):
bpy.ops.object.make_links_data(type='ANIMATION') bpy.ops.object.make_links_data(type='ANIMATION')
# we add an "animated" flag component # we add an "animated" flag component
target['Animated'] = '()' target['Animated'] = f'(animations: {animations})'.replace("'", '"') #'(animations: [])' #
"""print("copying animation data for", source.name, target.animation_data) """print("copying animation data for", source.name, target.animation_data)
properties = [p.identifier for p in source.animation_data.bl_rna.properties if not p.is_readonly] properties = [p.identifier for p in source.animation_data.bl_rna.properties if not p.is_readonly]
for prop in properties: for prop in properties:
@ -97,8 +118,7 @@ def duplicate_object(object, parent, combine_mode, destination_collection, libra
"""if object.parent == None: """if object.parent == None:
if parent_empty is not None: if parent_empty is not None:
copy.parent = parent_empty copy.parent = parent_empty
if object.animation_data: """
copy['Animated'] = '()'"""
print(nester, "copy", copy) print(nester, "copy", copy)
# do this both for empty replacements & normal copies # do this both for empty replacements & normal copies