chore(auto_export): further exploration & experimenting

* now trying to copy the animation to the "empty" placeholder using animation linking operator
 * now in gltf viewer we can see the two animations/actions, but still nothing in Bevy
This commit is contained in:
kaosat.dev 2024-03-18 22:26:06 +01:00
parent 98eef2c755
commit 1c51d10da7
3 changed files with 21 additions and 6 deletions

View File

@ -28,9 +28,9 @@ def remove_unwanted_custom_properties(object):
def duplicate_object(object): def duplicate_object(object):
obj_copy = object.copy() obj_copy = object.copy()
# FIXME: orphan data comes from this one # FIXME: orphan data comes from this one
"""if object.data: if object.data:
data = object.data.copy() data = object.data.copy()
obj_copy.data = data""" obj_copy.data = data
if object.animation_data and object.animation_data.action: if object.animation_data and object.animation_data.action:
if obj_copy.animation_data == None: if obj_copy.animation_data == None:
obj_copy.animation_data_create() obj_copy.animation_data_create()
@ -39,14 +39,28 @@ def duplicate_object(object):
# TODO: rename actions # TODO: rename actions
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.action: if source.animation_data and source.animation_data.action:
print("source", source.animation_data.action.name)
print("copying animation data for", source.name, target.animation_data) print("copying animation data for", source.name, target.animation_data)
if target.animation_data == None: if target.animation_data == None:
target.animation_data_create() target.animation_data_create()
target.animation_data.action = source.animation_data.action.copy() target.animation_data.action = source.animation_data.action.copy()
# alternative method, using the build in link animation operator
with bpy.context.temp_override(active_object=source, selected_editable_objects=[target]):
bpy.ops.object.make_links_data(type='ANIMATION')
"""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]
for prop in properties:
print("copying stuff", prop)
setattr(target.animation_data, prop, getattr(source.animation_data, prop))"""
#also removes unwanted custom_properties for all objects in hiearchy #also removes unwanted custom_properties for all objects in hiearchy
def duplicate_object_recursive(object, parent, collection): def duplicate_object_recursive(object, parent, collection):
@ -97,7 +111,7 @@ def copy_hollowed_collection_into(source_collection, destination_collection, par
get_sub_collections([object.instance_collection], root_node, children_per_collection) get_sub_collections([object.instance_collection], root_node, children_per_collection)
empty_obj["BlueprintsList"] = f"({json.dumps(dict(children_per_collection))})" empty_obj["BlueprintsList"] = f"({json.dumps(dict(children_per_collection))})"
#empty_obj["Assets"] = {"Animations": [], "Materials": [], "Models":[], "Textures":[], "Audio":[], "Other":[]} #empty_obj["Assets"] = {"Animations": [], "Materials": [], "Models":[], "Textures":[], "Audio":[], "Other":[]}
copy_animation_data(object, empty_obj)
# we copy custom properties over from our original object to our empty # we copy custom properties over from our original object to our empty
for component_name, component_value in object.items(): for component_name, component_value in object.items():

View File

@ -56,7 +56,8 @@ def test_export_complex(setup_data):
# we use the global settings for that # we use the global settings for that
export_props = { export_props = {
"main_scene_names" : ['World'], "main_scene_names" : ['World'],
"library_scene_names": ['Library'] "library_scene_names": ['Library'],
#"export_format":'GLTF_SEPARATE'
} }
stored_settings = bpy.data.texts[".gltf_auto_export_settings"] if ".gltf_auto_export_settings" in bpy.data.texts else bpy.data.texts.new(".gltf_auto_export_settings") stored_settings = bpy.data.texts[".gltf_auto_export_settings"] if ".gltf_auto_export_settings" in bpy.data.texts else bpy.data.texts.new(".gltf_auto_export_settings")
stored_settings.clear() stored_settings.clear()