feat(auto_export): experimenting with injecting list/tree of sub blueprints to main scenes/levels

This commit is contained in:
kaosat.dev 2024-03-08 23:21:48 +01:00
parent 1353e14802
commit e53098db72
4 changed files with 61 additions and 9 deletions

View File

@ -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
from ..helpers.helpers_scenes import clear_hollow_scene, copy_hollowed_collection_into, inject_blueprints_list_into_main_scene
# export all main scenes
@ -29,6 +29,8 @@ def export_main_scene(scene, folder_path, addon_prefs, library_collections):
}
if export_blueprints :
inject_blueprints_list_into_main_scene(scene)
if export_separate_dynamic_and_static_objects:
#print("SPLIT STATIC AND DYNAMIC")
# first export static objects

View File

@ -36,16 +36,23 @@ def get_marked_collections(scene, addon_prefs):
return (collection_names, marked_collections)
# gets all collections within collections that might also be relevant
def get_sub_collections(collections, parent, children_per_collection):
def get_sub_collections(collections, parent=None, children_per_collection=None):
if parent == None:
parent = CollectionNode()
if children_per_collection == None:
children_per_collection = {}
collection_names = set()
used_collections = []
for root_collection in collections:
node = Node(name=root_collection.name, parent=parent)
print("collections", collections)
node = CollectionNode(name=root_collection.name, parent=parent)
parent.children.append(node)
#print("root collection", root_collection.name)
for collection in traverse_tree(root_collection): # TODO: filter out COLLECTIONS that have the flatten flag (unlike the flatten flag on colleciton instances themselves)
print("sub", collection)
node_name = collection.name
children_per_collection[node_name] = []
#print(" scanning", collection.name)
@ -53,12 +60,17 @@ def get_sub_collections(collections, parent, children_per_collection):
#print("FLATTEN", object.name, 'Flatten' in object)
if object.instance_type == 'COLLECTION' : # and not 'Flatten' in object:
collection_name = object.instance_collection.name
print("sub obj", collection_name)
# FIXME: not sure:
children_per_collection[node_name].append(collection_name)
(sub_names, sub_collections) = get_sub_collections([object.instance_collection], node, children_per_collection)
print("gna", sub_names, sub_collections)
if len(list(sub_names)) > 0:
print("toto")
children_per_collection[node_name] += (list(sub_names))
#print(" found sub collection in use", object.name, object.instance_collection)
if not collection_name in collection_names:
collection_names.add(collection_name)
used_collections.append(object.instance_collection)
@ -77,7 +89,7 @@ def flatten_collection_tree(node, children_per_collection):
children_per_collection[node.name] = list(set( children_per_collection[node.name]))
class Node :
class CollectionNode :
def __init__(self, name="", parent=None):
self.name = name
self.children = []
@ -93,7 +105,7 @@ def get_exportable_collections(main_scenes, library_scenes, addon_prefs):
all_collections = []
all_collection_names = []
root_node = Node()
root_node = CollectionNode()
root_node.name = "root"
children_per_collection = {}

View File

@ -1,5 +1,6 @@
import json
import bpy
from .helpers_collections import (set_active_collection)
from .helpers_collections import (CollectionNode, get_sub_collections, get_used_collections, set_active_collection)
from .object_makers import (make_empty)
@ -149,3 +150,40 @@ def get_scenes(addon_prefs):
return [level_scene_names, level_scenes, library_scene_names, library_scenes]
def inject_blueprints_list_into_main_scene(scene):
print("injecting assets data")
root_collection = scene.collection
assets_list = None
for object in scene.objects:
if object.name == "assets_list"+scene.name:
assets_list = object
break
if assets_list is None:
assets_list = make_empty('assets_list_'+scene.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)
(collection_names, collections) = get_used_collections(scene)
root_node = CollectionNode()
root_node.name = "root"
children_per_collection = {}
#print("collection_names", collection_names, "collections", collections)
(bla, bli ) = get_sub_collections(collections, root_node, children_per_collection)
#print("sfdsfsdf", bla, bli, "root", root_node, "children_per_collection", children_per_collection)
# with sub collections
# (collection_names, collections) = get_sub_collections(all_collections, root_node, children_per_collection)
#
# what about marked assets ?
#assets_list["blueprints_direct"] = list(collection_names)
assets_list["BlueprintsList"] = f"({json.dumps(dict(children_per_collection))})"
#'({"a":[]})'
#'([])'
#
#
print("assets list", assets_list["BlueprintsList"], children_per_collection)

View File

@ -20,7 +20,7 @@ def setup_data(request):
#other_materials_path = os.path.join("../../testing", "other_materials")
print("\nPerforming teardown...")
if os.path.exists(models_path):
'''if os.path.exists(models_path):
shutil.rmtree(models_path)
"""if os.path.exists(materials_path):
@ -34,7 +34,7 @@ def setup_data(request):
screenshot_observed_path = os.path.join(root_path, "screenshot.png")
if os.path.exists(screenshot_observed_path):
os.remove(screenshot_observed_path)
os.remove(screenshot_observed_path)'''
request.addfinalizer(finalizer)