diff --git a/crates/bevy_gltf_blueprints/src/animation.rs b/crates/bevy_gltf_blueprints/src/animation.rs index 4a18ec4..d3c40a3 100644 --- a/crates/bevy_gltf_blueprints/src/animation.rs +++ b/crates/bevy_gltf_blueprints/src/animation.rs @@ -14,3 +14,9 @@ pub struct Animations { /// this is for convenience, because currently , Bevy's gltf parsing inserts `AnimationPlayers` "one level down" /// ie armature/root for animated models, which means more complex queries to trigger animations that we want to avoid pub struct AnimationPlayerLink(pub Entity); + +#[derive(Component, Reflect, Default, Debug)] +#[reflect(Component)] +pub struct Animated{ + pub animations: Vec +} \ No newline at end of file diff --git a/crates/bevy_gltf_blueprints/src/lib.rs b/crates/bevy_gltf_blueprints/src/lib.rs index 78642cd..13f2d36 100644 --- a/crates/bevy_gltf_blueprints/src/lib.rs +++ b/crates/bevy_gltf_blueprints/src/lib.rs @@ -120,6 +120,7 @@ impl Plugin for BlueprintsPlugin { .register_type::() .register_type::() .register_type::() + .register_type::() .register_type::() .register_type::>() .register_type::>>() diff --git a/testing/bevy_example/Cargo.toml b/testing/bevy_example/Cargo.toml index 3dbc4ca..04043fb 100644 --- a/testing/bevy_example/Cargo.toml +++ b/testing/bevy_example/Cargo.toml @@ -14,3 +14,4 @@ bevy_rapier3d = { version = "0.25.0", features = ["serde-serialize", "debug-rend bevy_asset_loader = { version = "0.20", features = ["standard_dynamic_assets"] } bevy_editor_pls = { version = "0.8" } rand = "0.8.5" +json-writer ="0.3" \ No newline at end of file diff --git a/testing/bevy_example/assets/registry.json b/testing/bevy_example/assets/registry.json index 33887c3..7c84d1c 100644 --- a/testing/bevy_example/assets/registry.json +++ b/testing/bevy_example/assets/registry.json @@ -3516,6 +3516,25 @@ "type": "object", "typeInfo": "Struct" }, + "bevy_gltf_blueprints::animation::Animated": { + "additionalProperties": false, + "isComponent": true, + "isResource": false, + "properties": { + "animations": { + "type": { + "$ref": "#/$defs/alloc::vec::Vec" + } + } + }, + "required": [ + "animations" + ], + "short_name": "Animated", + "title": "bevy_gltf_blueprints::animation::Animated", + "type": "object", + "typeInfo": "Struct" + }, "bevy_gltf_blueprints::animation::Animations": { "additionalProperties": false, "isComponent": true, diff --git a/testing/bevy_example/assets/testing.blend b/testing/bevy_example/assets/testing.blend index 5af50a4..b3e02c1 100644 Binary files a/testing/bevy_example/assets/testing.blend and b/testing/bevy_example/assets/testing.blend differ diff --git a/testing/bevy_example/src/game/mod.rs b/testing/bevy_example/src/game/mod.rs index 973140b..a38b573 100644 --- a/testing/bevy_example/src/game/mod.rs +++ b/testing/bevy_example/src/game/mod.rs @@ -1,24 +1,30 @@ pub mod in_game; use std::{ - fs::{self}, - time::Duration, + collections::HashMap, fs, time::Duration }; -use bevy_gltf_blueprints::{AnimationPlayerLink, BlueprintName, BlueprintsList}; +use bevy_gltf_blueprints::{AnimationPlayerLink, Animations, BlueprintName, BlueprintsList}; pub use in_game::*; use bevy::{ - prelude::*, render::view::screenshot::ScreenshotManager, time::common_conditions::on_timer, - window::PrimaryWindow, + ecs::query, prelude::*, render::view::screenshot::ScreenshotManager, time::common_conditions::on_timer, window::PrimaryWindow }; use bevy_gltf_worlflow_examples_common_rapier::{AppState, GameState}; use crate::{TupleTestF32, UnitTest}; +use json_writer::to_json_string; fn start_game(mut next_app_state: ResMut>) { next_app_state.set(AppState::AppLoading); } + +#[derive(Debug)] +struct Node { + value: String, + children: Vec, +} + // if the export from Blender worked correctly, we should have animations (simplified here by using AnimationPlayerLink) // if the export from Blender worked correctly, we should have an Entity called "Cylinder" that has two components: UnitTest, TupleTestF32 // if the export from Blender worked correctly, we should have an Entity called "Blueprint4_nested" that has a child called "Blueprint3" that has a "BlueprintName" component with value Blueprint3 @@ -34,19 +40,10 @@ fn validate_export( empties_candidates: Query<(Entity, &Name, &GlobalTransform)>, blueprints_list: Query<(Entity, &BlueprintsList)>, + root: Query<(Entity, &Name, &Children), (Without, With)> ) { let animations_found = !animation_player_links.is_empty(); - let mut cylinder_found = false; - if let Ok(nested_cylinder) = exported_cylinder.get_single() { - let parent_name = names - .get(parents.get(nested_cylinder.0).unwrap().get()) - .unwrap(); - cylinder_found = parent_name.to_string() == *"Cube.001" - && nested_cylinder.1.to_string() == *"Cylinder" - && nested_cylinder.3 .0 == 75.1; - } - let mut nested_blueprint_found = false; for (entity, name, blueprint_name) in blueprints.iter() { if name.to_string() == *"Blueprint4_nested" && blueprint_name.0 == *"Blueprint4_nested" { @@ -71,14 +68,46 @@ fn validate_export( break; } } - + // check if there are blueprints_list components let blueprints_list_found = !blueprints_list.is_empty(); + // there should be no entity named xxx____bak as it means an error in the Blender side export process + let mut exported_names_correct = true; + for name in names.iter() { + if name.to_string().ends_with("___bak") { + exported_names_correct = false; + break; + } + } + + // generate parent/child tree + if !root.is_empty() { + let root = root.single(); + let mut tree: HashMap> = HashMap::new(); + // println!("root {}", root.1); + + for child in children.iter_descendants(root.0) { + let child_name:String = names.get(child).map_or(String::from("no_name"), |e| e.to_string() ); //|e| e.to_string(), || "no_name".to_string()); + //println!(" child {}", child_name); + let parent = parents.get(child).unwrap(); + let parent_name:String = names.get(parent.get()).map_or(String::from("no_name"), |e| e.to_string() ); //|e| e.to_string(), || "no_name".to_string()); + tree.entry(parent_name).or_default().push(child_name.clone()); + } + + let hierarchy = to_json_string(&tree); + fs::write( + "bevy_hierarchy.json", + hierarchy + ) + .expect("unable to write hierarchy file") + } + + fs::write( "bevy_diagnostics.json", format!( - "{{ \"animations\": {}, \"cylinder_found\": {} , \"nested_blueprint_found\": {}, \"empty_found\": {}, \"blueprints_list_found\": {} }}", - animations_found, cylinder_found, nested_blueprint_found, empty_found, blueprints_list_found + "{{ \"animations\": {}, \"nested_blueprint_found\": {}, \"empty_found\": {}, \"blueprints_list_found\": {}, \"exported_names_correct\": {} }}", + animations_found, nested_blueprint_found, empty_found, blueprints_list_found, exported_names_correct ), ) .expect("Unable to write file"); @@ -97,6 +126,35 @@ fn exit_game(mut app_exit_events: ResMut>) { app_exit_events.send(bevy::app::AppExit); } +/* +#[derive(Resource)] +struct Animations(Vec>); +*/ + +fn animations( + foo:Query<(Entity, &Name, &AnimationPlayer),(Added)>, + asset_server: Res, + mut commands: Commands, +) { + for bla in foo.iter() { + let mut counter = 0; + counter +=1; + println!("found some animations {} {}", counter, bla.1); + + if bla.1.to_string() == "Collection".to_string(){ + /*commands.insert_resource(Animations(vec![ + asset_server.load("models/World.glb#Animation0"), + asset_server.load("models/World.glb#Animation1"), + ]));*/ + /*commands.entity(bla.0).insert(Animations { + named_animations: + })*/ + } + + + } +} + pub struct GamePlugin; impl Plugin for GamePlugin { fn build(&self, app: &mut App) { @@ -104,6 +162,7 @@ impl Plugin for GamePlugin { .add_systems(Update, validate_export) .add_systems(OnEnter(AppState::MenuRunning), start_game) .add_systems(OnEnter(AppState::AppRunning), setup_game) + .add_systems(Update, animations) .add_systems(Update, generate_screenshot.run_if(on_timer(Duration::from_secs_f32(0.2)))) // TODO: run once .add_systems( Update, diff --git a/tools/gltf_auto_export/auto_export/get_standard_exporter_settings.py b/tools/gltf_auto_export/auto_export/get_standard_exporter_settings.py new file mode 100644 index 0000000..8756e7d --- /dev/null +++ b/tools/gltf_auto_export/auto_export/get_standard_exporter_settings.py @@ -0,0 +1,6 @@ +import bpy + +def get_standard_exporter_settings(): + for scene in bpy.data.scenes: + if 'glTF2ExportSettings' in scene: + print("standard exporter settings", scene['glTF2ExportSettings']) \ No newline at end of file diff --git a/tools/gltf_auto_export/helpers/helpers_scenes.py b/tools/gltf_auto_export/helpers/helpers_scenes.py index 55009c9..ded9753 100644 --- a/tools/gltf_auto_export/helpers/helpers_scenes.py +++ b/tools/gltf_auto_export/helpers/helpers_scenes.py @@ -20,87 +20,133 @@ def remove_unwanted_custom_properties(object): for component_name in object.keys(): if not is_component_valid(object, component_name): to_remove.append(component_name) - for cp in custom_properties_to_filter_out + to_remove: if cp in object: del object[cp] -def duplicate_object(object): - obj_copy = object.copy() - if object.data: +# 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): + """if source.data: + data = source.data.copy() + target.data = data""" + if source.animation_data and source.animation_data: + #print("copying animation data from", source.name, "to", target.name) + print("I have animation data") + ad = source.animation_data + """if ad.action: + print(source.name,'uses',ad.action.name)""" + + animations = [] + 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: + target.animation_data_create() + 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') + # we add an "animated" flag component + target['Animated'] = f'(animations: {animations})'.replace("'", '"') #'(animations: [])' # + """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))""" + +def duplicate_object(object, parent, combine_mode, destination_collection, library_collections, legacy_mode, nester=""): + copy = None + if object.instance_type == 'COLLECTION' and (combine_mode == 'Split' or (combine_mode == 'EmbedExternal' and (object.instance_collection.name in library_collections)) ): + #print("creating empty for", object.name, object.instance_collection.name, library_collections, combine_mode) + collection_name = object.instance_collection.name + original_name = object.name + + object.name = original_name + "____bak" + empty_obj = make_empty(original_name, object.location, object.rotation_euler, object.scale, destination_collection) + """we inject the collection/blueprint name, as a component called 'BlueprintName', but we only do this in the empty, not the original object""" + empty_obj['BlueprintName'] = '"'+collection_name+'"' if legacy_mode else '("'+collection_name+'")' + empty_obj['SpawnHere'] = '()' + + # we also inject a list of all sub blueprints, so that the bevy side can preload them + if not legacy_mode: + root_node = CollectionNode() + root_node.name = "root" + 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["Assets"] = {"Animations": [], "Materials": [], "Models":[], "Textures":[], "Audio":[], "Other":[]} + + # we copy custom properties over from our original object to our empty + for component_name, component_value in object.items(): + if component_name not in custom_properties_to_filter_out and is_component_valid(object, component_name): #copy only valid properties + empty_obj[component_name] = component_value + copy = empty_obj + else: + # for objects which are NOT collection instances + # we create a copy of our object and its children, to leave the original one as it is + original_name = object.name + object.name = original_name + "____bak" + copy = object.copy() + copy.name = original_name + # FIXME: orphan data comes from this one, not even sure if this copying is needed at all + """if object.data: data = object.data.copy() - obj_copy.data = data - if object.animation_data and object.animation_data.action: - obj_copy.animation_data.action = object.animation_data.action.copy() - return obj_copy + obj_copy.data = data""" -#also removes unwanted custom_properties for all objects in hiearchy -def duplicate_object_recursive(object, parent, collection): - original_name = object.name - object.name = original_name + "____bak" - copy = duplicate_object(object) - copy.name = original_name - collection.objects.link(copy) + destination_collection.objects.link(copy) - remove_unwanted_custom_properties(copy) + """if object.parent == None: + if parent_empty is not None: + copy.parent = parent_empty + """ - if parent: + print(nester, "copy", copy) + # do this both for empty replacements & normal copies + if parent is not None: copy.parent = parent + remove_unwanted_custom_properties(copy) + copy_animation_data(object, copy) for child in object.children: - duplicate_object_recursive(child, copy, collection) - return copy - + duplicate_object(child, copy, combine_mode, destination_collection, library_collections, legacy_mode, nester+" ") # copies the contents of a collection into another one while replacing library instances with empties def copy_hollowed_collection_into(source_collection, destination_collection, parent_empty=None, filter=None, library_collections=[], addon_prefs={}): collection_instances_combine_mode = getattr(addon_prefs, "collection_instances_combine_mode") legacy_mode = getattr(addon_prefs, "export_legacy_mode") collection_instances_combine_mode= collection_instances_combine_mode + for object in source_collection.objects: + if object.name.endswith("____bak"): # some objects could already have been handled, ignore them + continue if filter is not None and filter(object) is False: continue #check if a specific collection instance does not have an ovveride for combine_mode combine_mode = object['_combine'] if '_combine' in object else collection_instances_combine_mode - - if object.instance_type == 'COLLECTION' and (combine_mode == 'Split' or (combine_mode == 'EmbedExternal' and (object.instance_collection.name in library_collections)) ): - #print("creating empty for", object.name, object.instance_collection.name, library_collections, combine_mode) - collection_name = object.instance_collection.name - original_name = object.name - - object.name = original_name + "____bak" - empty_obj = make_empty(original_name, object.location, object.rotation_euler, object.scale, destination_collection) - """we inject the collection/blueprint name, as a component called 'BlueprintName', but we only do this in the empty, not the original object""" - empty_obj['BlueprintName'] = '"'+collection_name+'"' if legacy_mode else '("'+collection_name+'")' - empty_obj['SpawnHere'] = '()' - - # we also inject a list of all sub blueprints, so that the bevy side can preload them - if not legacy_mode: - root_node = CollectionNode() - root_node.name = "root" - children_per_collection = {} - print("collection stuff", original_name) - get_sub_collections([object.instance_collection], root_node, children_per_collection) - empty_obj["BlueprintsList"] = f"({json.dumps(dict(children_per_collection))})" - #empty_obj["Assets"] = {"Animations": [], "Materials": [], "Models":[], "Textures":[], "Audio":[], "Other":[]} - - - # we copy custom properties over from our original object to our empty - for component_name, component_value in object.items(): - if component_name not in custom_properties_to_filter_out and is_component_valid(object, component_name): #copy only valid properties - empty_obj[component_name] = component_value - 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 - - # for every sub-collection of the source, copy its content into a new sub-collection of the destination + parent = parent_empty + duplicate_object(object, parent, combine_mode, destination_collection, library_collections, legacy_mode) + + # for every child-collection of the source, copy its content into a new sub-collection of the destination for collection in source_collection.children: original_name = collection.name collection.name = original_name + "____bak" @@ -108,7 +154,6 @@ def copy_hollowed_collection_into(source_collection, destination_collection, par if parent_empty is not None: collection_placeholder.parent = parent_empty - copy_hollowed_collection_into( source_collection = collection, destination_collection = destination_collection, @@ -117,6 +162,8 @@ def copy_hollowed_collection_into(source_collection, destination_collection, par library_collections = library_collections, addon_prefs=addon_prefs ) + + return {} @@ -138,14 +185,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): diff --git a/tools/gltf_auto_export/tests/expected_bevy_hierarchy.json b/tools/gltf_auto_export/tests/expected_bevy_hierarchy.json new file mode 100644 index 0000000..8a1165b --- /dev/null +++ b/tools/gltf_auto_export/tests/expected_bevy_hierarchy.json @@ -0,0 +1 @@ +{"b_Tail02_013":["b_Tail03_014"],"Blueprint4_nested.001":["Blueprint3"],"Collection 2 1":["Empty_in_sub_collection"],"b_Root_00":["b_Hip_01"],"b_LeftForeArm_010":["b_LeftHand_011"],"b_Spine01_02":["b_Spine02_03"],"Blueprint7_hierarchy.001":["Blueprint4_nested.001","Cube.001"],"b_RightLeg01_019":["b_RightLeg02_020"],"b_LeftUpperArm_09":["b_LeftForeArm_010"],"no_name":["Parent_Object","lighting_components_World","assets_list_World_components","Collection","Collection 2"],"Blueprint3":["Blueprint3_mesh","Blueprint3_mesh"],"world":["no_name"],"Parent_Object":["Cube.003","Blueprint1","Cylinder.001"],"Light":["Light","DirectionalLight Gizmo"],"Blueprint1.001":["Blueprint1_mesh"],"Blueprint7_hierarchy":["Cube.001"],"Spot":["Spot"],"b_Hip_01":["b_Spine01_02","b_Tail01_012","b_LeftLeg01_015","b_RightLeg01_019"],"Cylinder":["Cylinder.001","Cylinder.001"],"Collection 2":["Collection 2 1","Empty_in_collection","Spot"],"b_RightForeArm_07":["b_RightHand_08"],"Blueprint3_mesh":["Cylinder","Cylinder"],"Blueprint4_nested":["Blueprint3"],"Fox_mesh":["fox1"],"b_LeftLeg01_015":["b_LeftLeg02_016"],"b_Neck_04":["b_Head_05"],"b_RightFoot01_021":["b_RightFoot02_022"],"Blueprint1_mesh":["Cube.001","Cube.001"],"b_Tail01_012":["b_Tail02_013"],"Fox":["Fox_mesh","_rootJoint"],"Collection":["Blueprint1.001","Blueprint4_nested","Blueprint6_animated","Blueprint7_hierarchy","Camera","Cube","Empty","Light","Plane"],"Cube":["Cube"],"_rootJoint":["b_Root_00"],"b_RightLeg02_020":["b_RightFoot01_021"],"b_RightUpperArm_06":["b_RightForeArm_07"],"Plane":["Plane"],"Camera":["Camera Gizmo"],"Blueprint6_animated":["Fox"],"b_Spine02_03":["b_Neck_04","b_RightUpperArm_06","b_LeftUpperArm_09"],"b_LeftLeg02_016":["b_LeftFoot01_017"],"b_LeftFoot01_017":["b_LeftFoot02_018"],"Cube.001":["Cube.002","Cylinder","Cube.002","Cylinder"],"Cylinder.001":["Cylinder.002","Blueprint7_hierarchy.001","Empty_as_child"],"Blueprint1":["Blueprint1_mesh"]} \ No newline at end of file diff --git a/tools/gltf_auto_export/tests/test_basic.py b/tools/gltf_auto_export/tests/test_basic.py index 7d01954..8d3c1e5 100644 --- a/tools/gltf_auto_export/tests/test_basic.py +++ b/tools/gltf_auto_export/tests/test_basic.py @@ -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 diff --git a/tools/gltf_auto_export/tests/test_bevy_integration.py b/tools/gltf_auto_export/tests/test_bevy_integration.py index e45114c..b64f237 100644 --- a/tools/gltf_auto_export/tests/test_bevy_integration.py +++ b/tools/gltf_auto_export/tests/test_bevy_integration.py @@ -5,6 +5,7 @@ import json import pytest import shutil +import filecmp from PIL import Image from pixelmatch.contrib.PIL import pixelmatch @@ -56,7 +57,8 @@ def test_export_complex(setup_data): # we use the global settings for that export_props = { "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.clear() @@ -107,9 +109,15 @@ def test_export_complex(setup_data): diagnostics = json.load(diagnostics_file) print("diagnostics", diagnostics) assert diagnostics["animations"] == True - assert diagnostics["cylinder_found"] == True assert diagnostics["empty_found"] == True assert diagnostics["blueprints_list_found"] == True + assert diagnostics["exported_names_correct"] == True + + with open(os.path.join(root_path, "bevy_hierarchy.json")) as hierarchy_file: + with open(os.path.join(os.path.dirname(__file__), "expected_bevy_hierarchy.json")) as expexted_hierarchy_file: + hierarchy = json.load(hierarchy_file) + expected = json.load(expexted_hierarchy_file) + assert sorted(hierarchy.items()) == sorted(expected.items()) # last but not least, do a visual compare screenshot_expected_path = os.path.join(root_path, "expected_screenshot.png")