mirror of
https://github.com/kaosat-dev/Blender_bevy_components_workflow.git
synced 2024-11-24 12:50:53 +00:00
fix(tools/gltf_auto_export) : fix export of collections in the main scenes (#39)
* Recursively traverses the main scene collections to create the hollow scene, so that objects in sub-collections are properly exported * fixes #36
This commit is contained in:
parent
79f29776c2
commit
111f0d0226
@ -286,7 +286,6 @@ def generate_hollow_scene(scene, library_collections):
|
|||||||
root_collection = scene.collection
|
root_collection = scene.collection
|
||||||
temp_scene = bpy.data.scenes.new(name="temp_scene")
|
temp_scene = bpy.data.scenes.new(name="temp_scene")
|
||||||
copy_root_collection = temp_scene.collection
|
copy_root_collection = temp_scene.collection
|
||||||
scene_objects = [o for o in root_collection.objects]
|
|
||||||
|
|
||||||
# we set our active scene to be this one : this is needed otherwise the stand-in empties get generated in the wrong scene
|
# we set our active scene to be this one : this is needed otherwise the stand-in empties get generated in the wrong scene
|
||||||
bpy.context.window.scene = temp_scene
|
bpy.context.window.scene = temp_scene
|
||||||
@ -299,28 +298,40 @@ def generate_hollow_scene(scene, library_collections):
|
|||||||
|
|
||||||
#original_names = {}
|
#original_names = {}
|
||||||
original_names = []
|
original_names = []
|
||||||
for object in scene_objects:
|
|
||||||
if object.instance_type == 'COLLECTION' and (object.instance_collection.name in library_collections):
|
|
||||||
collection_name = object.instance_collection.name
|
|
||||||
|
|
||||||
#original_names[object.name] = object.name# + "____bak"
|
# copies the contents of a collection into another one while replacing library instances with empties
|
||||||
#print("custom properties", object, object.keys(), object.items())
|
def copy_hollowed_collection_into(source_collection, destination_collection):
|
||||||
#for k, e in object.items():
|
for object in source_collection.objects:
|
||||||
# print("custom properties ", k, e)
|
if object.instance_type == 'COLLECTION' and (object.instance_collection.name in library_collections):
|
||||||
print("object location", object.location)
|
collection_name = object.instance_collection.name
|
||||||
original_name = object.name
|
|
||||||
original_names.append(original_name)
|
|
||||||
|
|
||||||
object.name = original_name + "____bak"
|
#original_names[object.name] = object.name# + "____bak"
|
||||||
empty_obj = make_empty3(original_name, object.location, object.rotation_euler, object.scale, copy_root_collection)
|
#print("custom properties", object, object.keys(), object.items())
|
||||||
"""we inject the collection/blueprint name, as a component called 'BlueprintName', but we only do this in the empty, not the original object"""
|
#for k, e in object.items():
|
||||||
empty_obj['BlueprintName'] = '"'+collection_name+'"'
|
# print("custom properties ", k, e)
|
||||||
empty_obj['SpawnHere'] = ''
|
print("object location", object.location)
|
||||||
|
original_name = object.name
|
||||||
|
original_names.append(original_name)
|
||||||
|
|
||||||
|
object.name = original_name + "____bak"
|
||||||
|
empty_obj = make_empty3(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+'"'
|
||||||
|
empty_obj['SpawnHere'] = ''
|
||||||
|
|
||||||
|
for k, v in object.items():
|
||||||
|
empty_obj[k] = v
|
||||||
|
else:
|
||||||
|
destination_collection.objects.link(object)
|
||||||
|
|
||||||
|
# for every sub-collection of the source, copy its content into a new sub-collection of the destination
|
||||||
|
for collection in source_collection.children:
|
||||||
|
copy_collection = bpy.data.collections.new(collection.name + "____collection_export")
|
||||||
|
copy_hollowed_collection_into(collection, copy_collection)
|
||||||
|
destination_collection.children.link(copy_collection)
|
||||||
|
|
||||||
|
copy_hollowed_collection_into(root_collection, copy_root_collection)
|
||||||
|
|
||||||
for k, v in object.items():
|
|
||||||
empty_obj[k] = v
|
|
||||||
else:
|
|
||||||
copy_root_collection.objects.link(object)
|
|
||||||
|
|
||||||
# bpy.data.scenes.remove(temp_scene)
|
# bpy.data.scenes.remove(temp_scene)
|
||||||
# objs = bpy.data.objects
|
# objs = bpy.data.objects
|
||||||
@ -331,12 +342,16 @@ def generate_hollow_scene(scene, library_collections):
|
|||||||
def clear_hollow_scene(temp_scene, original_scene, original_names):
|
def clear_hollow_scene(temp_scene, original_scene, original_names):
|
||||||
# reset original names
|
# reset original names
|
||||||
root_collection = original_scene.collection
|
root_collection = original_scene.collection
|
||||||
scene_objects = [o for o in root_collection.objects]
|
|
||||||
|
|
||||||
for object in scene_objects:
|
def restore_original_names(collection):
|
||||||
if object.instance_type == 'COLLECTION':
|
for object in collection.objects:
|
||||||
if object.name.endswith("____bak"):
|
if object.instance_type == 'COLLECTION':
|
||||||
object.name = object.name.replace("____bak", "")
|
if object.name.endswith("____bak"):
|
||||||
|
object.name = object.name.replace("____bak", "")
|
||||||
|
for child_collection in collection.children:
|
||||||
|
restore_original_names(child_collection)
|
||||||
|
|
||||||
|
restore_original_names(root_collection)
|
||||||
|
|
||||||
# remove empties (only needed when we go via ops ????)
|
# remove empties (only needed when we go via ops ????)
|
||||||
root_collection = temp_scene.collection
|
root_collection = temp_scene.collection
|
||||||
|
Loading…
Reference in New Issue
Block a user