-
-
Save eobet/e3246afe67bad4cee348deb5538991b5 to your computer and use it in GitHub Desktop.
Creates a duplicate of the scene containing only instances
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
def full_linked_copy_scene(): | |
scene_copy = bpy.data.scenes.new(bpy.context.scene.name + ' - Full Linked Copy') | |
# https://blender.stackexchange.com/a/167889/38603 | |
collections_in_scene = [ | |
c for c in bpy.data.collections | |
if bpy.context.scene.user_of_id(c) | |
] | |
# duplicate all collections | |
for c in collections_in_scene: | |
collection_copy = bpy.data.collections.new(c.name + ' - Copy') | |
scene_copy.collection.children.link(collection_copy) | |
# make instances of all objects in the collection | |
for o in c.objects: | |
if o.parent == None: | |
instance_recursive(o, collection_copy) | |
return None | |
def instance_recursive(original_object, target_collection): | |
instance = original_object.copy() | |
instance.name = original_object.name + ' - Instance' | |
target_collection.objects.link(instance) | |
# not sure why I have to set this... | |
instance.hide_viewport = False | |
if len(original_object.children) > 0: | |
for c in original_object.children: | |
i = instance_recursive(c, target_collection) | |
i.parent = instance | |
return instance | |
# ensure that every instance can have their own materials | |
for o in bpy.data.objects: | |
if o.type == 'MESH': | |
for s in o.material_slots: | |
# need to back up the material first, because Blender UX is as always awful | |
m = s.material | |
s.link = 'OBJECT' | |
s.material = m | |
full_linked_copy_scene() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment