mirror of
https://github.com/kaosat-dev/Blender_bevy_components_workflow.git
synced 2024-11-26 21:37:01 +00:00
chore():
* made blueprints/asset list conditional on NOT legacy mode * cleaned up code * fleshed out testing some more
This commit is contained in:
parent
65c009c210
commit
079aed7627
@ -4,7 +4,7 @@ import bpy
|
||||
from ..helpers.generate_and_export import generate_and_export
|
||||
from .export_gltf import (generate_gltf_export_preferences, export_gltf)
|
||||
from ..modules.bevy_dynamic import is_object_dynamic, is_object_static
|
||||
from ..helpers.helpers_scenes import clear_hollow_scene, copy_hollowed_collection_into, inject_blueprints_list_into_main_scene
|
||||
from ..helpers.helpers_scenes import clear_hollow_scene, copy_hollowed_collection_into, inject_blueprints_list_into_main_scene, remove_blueprints_list_from_main_scene
|
||||
|
||||
|
||||
# export all main scenes
|
||||
@ -16,6 +16,7 @@ def export_main_scene(scene, folder_path, addon_prefs, library_collections):
|
||||
gltf_export_preferences = generate_gltf_export_preferences(addon_prefs)
|
||||
export_output_folder = getattr(addon_prefs,"export_output_folder")
|
||||
export_blueprints = getattr(addon_prefs,"export_blueprints")
|
||||
legacy_mode = getattr(addon_prefs, "export_legacy_mode")
|
||||
export_separate_dynamic_and_static_objects = getattr(addon_prefs, "export_separate_dynamic_and_static_objects")
|
||||
|
||||
gltf_output_path = os.path.join(folder_path, export_output_folder, scene.name)
|
||||
@ -29,7 +30,8 @@ def export_main_scene(scene, folder_path, addon_prefs, library_collections):
|
||||
}
|
||||
|
||||
if export_blueprints :
|
||||
inject_blueprints_list_into_main_scene(scene)
|
||||
if not legacy_mode:
|
||||
inject_blueprints_list_into_main_scene(scene)
|
||||
|
||||
if export_separate_dynamic_and_static_objects:
|
||||
#print("SPLIT STATIC AND DYNAMIC")
|
||||
@ -69,5 +71,8 @@ def export_main_scene(scene, folder_path, addon_prefs, library_collections):
|
||||
print(" exporting gltf to", gltf_output_path, ".gltf/glb")
|
||||
export_gltf(gltf_output_path, export_settings)
|
||||
|
||||
if not legacy_mode:
|
||||
remove_blueprints_list_from_main_scene(scene)
|
||||
|
||||
|
||||
|
||||
|
@ -73,13 +73,17 @@ def copy_hollowed_collection_into(source_collection, destination_collection, par
|
||||
"""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
|
||||
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":[]}
|
||||
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():
|
||||
@ -163,13 +167,14 @@ def inject_blueprints_list_into_main_scene(scene):
|
||||
print("injecting assets/blueprints data into scene")
|
||||
root_collection = scene.collection
|
||||
assets_list = None
|
||||
assets_list_name = f"assets_list_{scene.name}_components"
|
||||
for object in scene.objects:
|
||||
if object.name == "assets_list"+scene.name:
|
||||
if object.name == assets_list_name:
|
||||
assets_list = object
|
||||
break
|
||||
|
||||
if assets_list is None:
|
||||
assets_list = make_empty('assets_list_'+scene.name+"_components", [0,0,0], [0,0,0], [0,0,0], root_collection)
|
||||
assets_list = make_empty(assets_list_name, [0,0,0], [0,0,0], [0,0,0], root_collection)
|
||||
|
||||
# find all blueprints used in a scene
|
||||
# TODO: export a tree rather than a flat list ? because you could have potential clashing items in flat lists (amongst other issues)
|
||||
@ -179,7 +184,7 @@ def inject_blueprints_list_into_main_scene(scene):
|
||||
children_per_collection = {}
|
||||
|
||||
#print("collection_names", collection_names, "collections", collections)
|
||||
(bla, bli ) = get_sub_collections(collections, root_node, children_per_collection)
|
||||
get_sub_collections(collections, root_node, children_per_collection)
|
||||
# what about marked assets ?
|
||||
# what about audio assets ?
|
||||
# what about materials ?
|
||||
@ -188,4 +193,13 @@ def inject_blueprints_list_into_main_scene(scene):
|
||||
#assets_list["blueprints_direct"] = list(collection_names)
|
||||
assets_list["BlueprintsList"] = f"({json.dumps(dict(children_per_collection))})"
|
||||
#assets_list["Materials"]= '()'
|
||||
# print("assets list", assets_list["BlueprintsList"], children_per_collection)
|
||||
|
||||
def remove_blueprints_list_from_main_scene(scene):
|
||||
assets_list = None
|
||||
assets_list_name = f"assets_list_{scene.name}_components"
|
||||
|
||||
for object in scene.objects:
|
||||
if object.name == assets_list_name:
|
||||
assets_list = object
|
||||
if assets_list is not None:
|
||||
bpy.data.objects.remove(assets_list, do_unlink=True)
|
||||
|
@ -83,7 +83,6 @@ def test_export_complex(setup_data):
|
||||
# blueprint5 => has NO instance, not marked as asset, should NOT export
|
||||
|
||||
assert os.path.exists(os.path.join(models_path, "World.glb")) == True
|
||||
|
||||
assert os.path.exists(os.path.join(models_path, "library", "Blueprint1.glb")) == True
|
||||
assert os.path.exists(os.path.join(models_path, "library", "Blueprint2.glb")) == True
|
||||
assert os.path.exists(os.path.join(models_path, "library", "Blueprint3.glb")) == True
|
||||
@ -92,6 +91,11 @@ def test_export_complex(setup_data):
|
||||
assert os.path.exists(os.path.join(models_path, "library", "Blueprint6_animated.glb")) == True
|
||||
assert os.path.exists(os.path.join(models_path, "library", "Blueprint7_hierarchy.glb")) == True
|
||||
|
||||
# 'assets_list_'+scene.name+"_components" should have been removed after the export
|
||||
assets_list_object_name = "assets_list_"+"World"+"_components"
|
||||
assets_list_object_present = assets_list_object_name in bpy.data.objects
|
||||
assert assets_list_object_present == False
|
||||
|
||||
# now run bevy
|
||||
command = "cargo run --features bevy/dynamic_linking"
|
||||
FNULL = open(os.devnull, 'w') #use this if you want to suppress output to stdout from the subprocess
|
||||
@ -105,6 +109,7 @@ def test_export_complex(setup_data):
|
||||
assert diagnostics["animations"] == True
|
||||
assert diagnostics["cylinder_found"] == True
|
||||
assert diagnostics["empty_found"] == True
|
||||
assert diagnostics["blueprints_list_found"] == True
|
||||
|
||||
# last but not least, do a visual compare
|
||||
screenshot_expected_path = os.path.join(root_path, "expected_screenshot.png")
|
||||
|
Loading…
Reference in New Issue
Block a user