diff --git a/crates/bevy_gltf_blueprints/src/lib.rs b/crates/bevy_gltf_blueprints/src/lib.rs index 2bfd298..b7a0bf2 100644 --- a/crates/bevy_gltf_blueprints/src/lib.rs +++ b/crates/bevy_gltf_blueprints/src/lib.rs @@ -157,6 +157,7 @@ impl Plugin for BlueprintsPlugin { .add_systems( Update, ( + test_thingy, ( prepare_blueprints, check_for_loaded, diff --git a/crates/bevy_gltf_blueprints/src/spawn_from_blueprints.rs b/crates/bevy_gltf_blueprints/src/spawn_from_blueprints.rs index 5165962..5c54bb8 100644 --- a/crates/bevy_gltf_blueprints/src/spawn_from_blueprints.rs +++ b/crates/bevy_gltf_blueprints/src/spawn_from_blueprints.rs @@ -51,6 +51,35 @@ pub struct AddToGameWorld; /// helper component, just to transfer child data pub(crate) struct OriginalChildren(pub Vec); + + +pub(crate) fn test_thingy( + spawn_placeholders: Query< + ( + Entity, + &BlueprintPath, + ), + (Added, Without, Without), +>, +mut commands: Commands, +asset_server: Res, + + +) { + for (entity, blueprint_path) in spawn_placeholders.iter() { + println!("added blueprint_path {:?}", blueprint_path); + commands.entity(entity).insert( + SceneBundle { + scene: asset_server.load(format!("{}#Scene0", &blueprint_path.0)), // "levels/World.glb#Scene0"), + ..default() + }, + ); + // let model_handle: Handle = asset_server.load(model_path.clone()); + + } + +} + /// spawning prepare function, /// * also takes into account the already exisiting "override" components, ie "override components" > components from blueprint pub(crate) fn prepare_blueprints( diff --git a/tools/blenvy/TODO.md b/tools/blenvy/TODO.md index 405bf07..750d9f3 100644 --- a/tools/blenvy/TODO.md +++ b/tools/blenvy/TODO.md @@ -115,5 +115,7 @@ General issues: - [ ] remove 'export_marked_assets' it should be a default setting - [x] disable/ hide asset editing ui for external assets +- [ ] inject_export_path_into_internal_blueprints should be called on every asset/blueprint scan !! Not just on export +- [ ] fix level asets UI clear && pytest -svv --blender-template ../../testing/bevy_example/art/testing_library.blend --blender-executable /home/ckaos/tools/blender/blender-4.1.0-linux-x64/blender tests/test_bevy_integration_prepare.py && pytest -svv --blender-executable /home/ckaos/tools/blender/blender-4.1.0-linux-x64/blender tests/test_bevy_integration.py \ No newline at end of file diff --git a/tools/blenvy/add_ons/auto_export/blueprints/export_blueprints.py b/tools/blenvy/add_ons/auto_export/blueprints/export_blueprints.py index b2ae030..9cb1d4e 100644 --- a/tools/blenvy/add_ons/auto_export/blueprints/export_blueprints.py +++ b/tools/blenvy/add_ons/auto_export/blueprints/export_blueprints.py @@ -4,6 +4,12 @@ from ..constants import TEMPSCENE_PREFIX from ..common.generate_temporary_scene_and_export import generate_temporary_scene_and_export, copy_hollowed_collection_into, clear_hollow_scene from ..common.export_gltf import generate_gltf_export_settings +def assets_to_fake_ron(list_like): + result = [] + for item in list_like: + result.append(f"(name: \"{item['name']}\", path: \"{item['path']}\")") + return result#.join(", ") + def export_blueprints(blueprints, settings, blueprints_data): blueprints_path_full = getattr(settings, "blueprints_path_full") gltf_export_settings = generate_gltf_export_settings(settings) @@ -15,7 +21,7 @@ def export_blueprints(blueprints, settings, blueprints_data): for blueprint in blueprints: print("exporting collection", blueprint.name) - gltf_output_path = os.path.join(blueprints_path_full, blueprint.name) + gltf_output_path = os.path.join(blueprints_path_full, blueprint.name) # TODO: reuse the export_path custom property ? gltf_export_settings = { **gltf_export_settings, 'use_active_scene': True, 'use_active_collection': True, 'use_active_collection_with_nested':True} # if we are using the material library option, do not export materials, use placeholder instead @@ -23,10 +29,23 @@ def export_blueprints(blueprints, settings, blueprints_data): gltf_export_settings['export_materials'] = 'PLACEHOLDER' collection = bpy.data.collections[blueprint.name] + + print("BLUEPRINT", blueprint.name) + + for asset in collection.user_assets: + print(" user asset", asset.name, asset.path) + + all_assets = [] + auto_assets = [] + collection["local_assets"] = assets_to_fake_ron([{"name": asset.name, "path": asset.path} for asset in collection.user_assets] + auto_assets) + collection["AllAssets"] = assets_to_fake_ron([{"name": asset.name, "path": asset.path} for asset in collection.user_assets]) #all_assets + [{"name": asset.name, "path": asset.path} for asset in collection.user_assets] + auto_assets) + + # do the actual export generate_temporary_scene_and_export( settings, temp_scene_name=TEMPSCENE_PREFIX+collection.name, + additional_data = collection, gltf_export_settings=gltf_export_settings, gltf_output_path=gltf_output_path, tempScene_filler= lambda temp_collection: copy_hollowed_collection_into(collection, temp_collection, blueprints_data=blueprints_data, settings=settings), diff --git a/tools/blenvy/add_ons/auto_export/common/duplicate_object.py b/tools/blenvy/add_ons/auto_export/common/duplicate_object.py index 4107b10..ec07b87 100644 --- a/tools/blenvy/add_ons/auto_export/common/duplicate_object.py +++ b/tools/blenvy/add_ons/auto_export/common/duplicate_object.py @@ -96,6 +96,8 @@ def duplicate_object(object, parent, combine_mode, destination_collection, bluep original_collection = object.instance_collection original_name = object.name blueprint_name = original_collection.name + # FIXME: blueprint path is WRONG ! + print("BLUEPRINT PATH", original_collection.get('export_path', None)) blueprint_path = original_collection['export_path'] if 'export_path' in original_collection else f'./{blueprint_name}' # TODO: the default requires the currently used extension !! diff --git a/tools/blenvy/add_ons/auto_export/common/generate_temporary_scene_and_export.py b/tools/blenvy/add_ons/auto_export/common/generate_temporary_scene_and_export.py index 2f5e6ee..e4dc647 100644 --- a/tools/blenvy/add_ons/auto_export/common/generate_temporary_scene_and_export.py +++ b/tools/blenvy/add_ons/auto_export/common/generate_temporary_scene_and_export.py @@ -27,12 +27,16 @@ def generate_temporary_scene_and_export(settings, gltf_export_settings, gltf_out temp_scene["local_assets"] = additional_data[entry] # this is for bevy 0.14 temp_root_collection["local_assets"] = additional_data[entry] # for previous bevy versions, remove when migration done bla = "[(name: \"test_asset\", path: \"audio/fake.mp3\")]" - add_scene_property(temp_scene, 'assets_components', {"LocalAssets": f"LocalAssets({additional_data[entry]})".replace("'", '')}) + local_assets = additional_data.get(entry, []) + local_assets = [entry for entry in local_assets] + add_scene_property(temp_scene, 'assets_components', {"LocalAssets": f"LocalAssets({local_assets})".replace("'", '')}) if entry == entry == "AllAssets": temp_scene["AllAssets"] = additional_data[entry] temp_root_collection["AllAssets"] = additional_data[entry] # for previous bevy versions, remove when migration done - add_scene_property(temp_scene, 'assets_components', {"AllAssets": f"AllAssets({additional_data[entry]})".replace("'", '')}) + all_assets = additional_data.get(entry, []) + all_assets = [entry for entry in all_assets] + add_scene_property(temp_scene, 'assets_components', {"AllAssets": f"AllAssets({all_assets})".replace("'", '')}) # save active scene original_scene = bpy.context.window.scene diff --git a/tools/blenvy/add_ons/auto_export/levels/export_main_scenes.py b/tools/blenvy/add_ons/auto_export/levels/export_main_scenes.py index 0c634ae..c807536 100644 --- a/tools/blenvy/add_ons/auto_export/levels/export_main_scenes.py +++ b/tools/blenvy/add_ons/auto_export/levels/export_main_scenes.py @@ -72,6 +72,7 @@ def export_main_scene(scene, settings, blueprints_data): scene["local_assets"] = assets_to_fake_ron([{"name": asset.name, "path": asset.path} for asset in scene.user_assets] + auto_assets) scene["AllAssets"] = assets_to_fake_ron(all_assets + [{"name": asset.name, "path": asset.path} for asset in scene.user_assets] + auto_assets) + if export_separate_dynamic_and_static_objects: #print("SPLIT STATIC AND DYNAMIC") # first export static objects diff --git a/tools/blenvy/blueprints/blueprint_helpers.py b/tools/blenvy/blueprints/blueprint_helpers.py index 5074640..b1f5f76 100644 --- a/tools/blenvy/blueprints/blueprint_helpers.py +++ b/tools/blenvy/blueprints/blueprint_helpers.py @@ -23,6 +23,8 @@ def check_if_blueprint_on_disk(scene_name, folder_path, extension): def inject_export_path_into_internal_blueprints(internal_blueprints, blueprints_path, gltf_extension): for blueprint in internal_blueprints: blueprint_exported_path = os.path.join(blueprints_path, f"{blueprint.name}{gltf_extension}") + print("injecting blueprint path", blueprint_exported_path, "for", blueprint.name) + blueprint.collection["export_path"] = blueprint_exported_path def inject_blueprints_list_into_main_scene(scene, blueprints_data, settings): diff --git a/tools/blenvy/tests/test_bevy_integration.py b/tools/blenvy/tests/test_bevy_integration.py index 3a11543..fd0dc94 100644 --- a/tools/blenvy/tests/test_bevy_integration.py +++ b/tools/blenvy/tests/test_bevy_integration.py @@ -120,6 +120,12 @@ def test_export_complex(setup_data): user_asset.name = "yoho_audio" user_asset.path = "audio/fake.mp3" + # we have to cheat, since we cannot rely on the data injected when saving the library file + bpy.data.collections["External_blueprint"]["export_path"] = "blueprints/External_blueprint.glb" + bpy.data.collections["External_blueprint2"]["export_path"] = "blueprints/External_blueprint2.glb" + bpy.data.collections["External_blueprint3"]["export_path"] = "blueprints/External_blueprint3.glb" + + prepare_and_export() # blueprint1 => has an instance, got changed, should export