mirror of
https://github.com/kaosat-dev/Blender_bevy_components_workflow.git
synced 2024-12-23 08:04:10 +00:00
feat(auto_export):
* added tests for orphan data * changed handling of animation data slightly * trying to figure out source of various issues
This commit is contained in:
parent
9f21df035b
commit
c6468f2b0b
@ -27,13 +27,27 @@ def remove_unwanted_custom_properties(object):
|
||||
|
||||
def duplicate_object(object):
|
||||
obj_copy = object.copy()
|
||||
if object.data:
|
||||
# FIXME: orphan data comes from this one
|
||||
"""if object.data:
|
||||
data = object.data.copy()
|
||||
obj_copy.data = data
|
||||
obj_copy.data = data"""
|
||||
if object.animation_data and object.animation_data.action:
|
||||
if obj_copy.animation_data == None:
|
||||
obj_copy.animation_data_create()
|
||||
obj_copy.animation_data.action = object.animation_data.action.copy()
|
||||
return obj_copy
|
||||
|
||||
# TODO: rename actions
|
||||
def copy_animation_data(source, target):
|
||||
if source.data:
|
||||
data = source.data.copy()
|
||||
target.data = data
|
||||
if source.animation_data and source.animation_data.action:
|
||||
print("copying animation data for", source.name, target.animation_data)
|
||||
if target.animation_data == None:
|
||||
target.animation_data_create()
|
||||
target.animation_data.action = source.animation_data.action.copy()
|
||||
|
||||
#also removes unwanted custom_properties for all objects in hiearchy
|
||||
def duplicate_object_recursive(object, parent, collection):
|
||||
original_name = object.name
|
||||
@ -92,11 +106,9 @@ def copy_hollowed_collection_into(source_collection, destination_collection, par
|
||||
if parent_empty is not None:
|
||||
empty_obj.parent = parent_empty
|
||||
else:
|
||||
|
||||
# we create a copy of our object and its children, to leave the original one as it is
|
||||
if object.parent == None:
|
||||
copy = duplicate_object_recursive(object, None, destination_collection)
|
||||
|
||||
if parent_empty is not None:
|
||||
copy.parent = parent_empty
|
||||
|
||||
@ -138,14 +150,14 @@ def clear_hollow_scene(temp_scene, original_root_collection):
|
||||
# reset original names
|
||||
restore_original_names(original_root_collection)
|
||||
|
||||
# remove empties (only needed when we go via ops ????)
|
||||
# remove any data we created
|
||||
temp_root_collection = temp_scene.collection
|
||||
temp_scene_objects = [o for o in temp_root_collection.objects]
|
||||
temp_scene_objects = [o for o in temp_root_collection.all_objects]
|
||||
for object in temp_scene_objects:
|
||||
print("removing", object.name)
|
||||
bpy.data.objects.remove(object, do_unlink=True)
|
||||
# remove the temporary scene
|
||||
bpy.data.scenes.remove(temp_scene)
|
||||
|
||||
bpy.data.scenes.remove(temp_scene, do_unlink=True)
|
||||
|
||||
# convenience utility to get lists of scenes
|
||||
def get_scenes(addon_prefs):
|
||||
|
@ -19,7 +19,6 @@ def setup_data(request):
|
||||
|
||||
def finalizer():
|
||||
print("\nPerforming teardown...")
|
||||
get_orphan_data()
|
||||
|
||||
if os.path.exists(models_path):
|
||||
shutil.rmtree(models_path)
|
||||
@ -38,7 +37,10 @@ def setup_data(request):
|
||||
|
||||
def get_orphan_data():
|
||||
orphan_meshes = [m.name for m in bpy.data.meshes if m.users == 0]
|
||||
# print("orphan meshes before", orphan_meshes)
|
||||
orphan_objects = [m.name for m in bpy.data.objects if m.users == 0]
|
||||
|
||||
#print("orphan meshes before", orphan_meshes)
|
||||
return orphan_meshes + orphan_objects
|
||||
|
||||
def test_export_do_not_export_blueprints(setup_data):
|
||||
auto_export_operator = bpy.ops.export_scenes.auto_gltf
|
||||
@ -61,6 +63,9 @@ def test_export_do_not_export_blueprints(setup_data):
|
||||
)
|
||||
assert os.path.exists(os.path.join(setup_data["models_path"], "World.glb")) == True
|
||||
assert os.path.exists(os.path.join(setup_data["models_path"], "library", "Blueprint1.glb")) == False
|
||||
orphan_data = get_orphan_data()
|
||||
assert len(orphan_data) == 0
|
||||
|
||||
|
||||
def test_export_custom_blueprints_path(setup_data):
|
||||
auto_export_operator = bpy.ops.export_scenes.auto_gltf
|
||||
@ -83,6 +88,7 @@ def test_export_custom_blueprints_path(setup_data):
|
||||
)
|
||||
assert os.path.exists(os.path.join(setup_data["models_path"], "World.glb")) == True
|
||||
assert os.path.exists(os.path.join(setup_data["models_path"], "another_library_path", "Blueprint1.glb")) == True
|
||||
assert len(get_orphan_data()) == 0
|
||||
|
||||
def test_export_materials_library(setup_data):
|
||||
auto_export_operator = bpy.ops.export_scenes.auto_gltf
|
||||
@ -107,7 +113,7 @@ def test_export_materials_library(setup_data):
|
||||
|
||||
assert os.path.exists(os.path.join(setup_data["models_path"], "library", "Blueprint1.glb")) == True
|
||||
assert os.path.exists(os.path.join(setup_data["materials_path"], "testing_materials_library.glb")) == True
|
||||
|
||||
assert len(get_orphan_data()) == 0
|
||||
|
||||
def test_export_materials_library_custom_path(setup_data):
|
||||
auto_export_operator = bpy.ops.export_scenes.auto_gltf
|
||||
@ -134,6 +140,7 @@ def test_export_materials_library_custom_path(setup_data):
|
||||
assert os.path.exists(os.path.join(setup_data["models_path"], "library", "Blueprint1.glb")) == True
|
||||
assert os.path.exists(os.path.join(setup_data["materials_path"], "testing_materials_library.glb")) == False
|
||||
assert os.path.exists(os.path.join(setup_data["other_materials_path"], "testing_materials_library.glb")) == True
|
||||
assert len(get_orphan_data()) == 0
|
||||
|
||||
def test_export_collection_instances_combine_mode(setup_data): # TODO: change & check this
|
||||
auto_export_operator = bpy.ops.export_scenes.auto_gltf
|
||||
@ -160,6 +167,7 @@ def test_export_collection_instances_combine_mode(setup_data): # TODO: change &
|
||||
|
||||
assert os.path.exists(os.path.join(setup_data["models_path"], "World.glb")) == True
|
||||
assert os.path.exists(os.path.join(setup_data["models_path"], "World_dynamic.glb")) == False
|
||||
assert len(get_orphan_data()) == 0
|
||||
|
||||
|
||||
def test_export_do_not_export_marked_assets(setup_data):
|
||||
@ -188,6 +196,7 @@ def test_export_do_not_export_marked_assets(setup_data):
|
||||
assert os.path.exists(os.path.join(setup_data["models_path"], "library", "Blueprint3.glb")) == True
|
||||
assert os.path.exists(os.path.join(setup_data["models_path"], "library", "Blueprint4_nested.glb")) == True
|
||||
assert os.path.exists(os.path.join(setup_data["models_path"], "library", "Blueprint5.glb")) == False
|
||||
assert len(get_orphan_data()) == 0
|
||||
|
||||
|
||||
def test_export_separate_dynamic_and_static_objects(setup_data):
|
||||
@ -216,6 +225,7 @@ def test_export_separate_dynamic_and_static_objects(setup_data):
|
||||
|
||||
assert os.path.exists(os.path.join(setup_data["models_path"], "World.glb")) == True
|
||||
assert os.path.exists(os.path.join(setup_data["models_path"], "World_dynamic.glb")) == True
|
||||
assert len(get_orphan_data()) == 0
|
||||
|
||||
|
||||
def test_export_should_not_generate_orphan_data(setup_data):
|
||||
@ -239,4 +249,5 @@ def test_export_should_not_generate_orphan_data(setup_data):
|
||||
)
|
||||
assert os.path.exists(os.path.join(setup_data["models_path"], "World.glb")) == True
|
||||
assert os.path.exists(os.path.join(setup_data["models_path"], "library", "Blueprint1.glb")) == False
|
||||
assert len(get_orphan_data()) == 0
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user