LibOverride: Extend unittest to cover more advanced/complex cases.
These tests now have basic coverage of: * Linking data and creating liboverride hierarchy from it. * Linking that liboverride again. * Creating liboverride of liboverride. * Modifying data hierarchy in the library, and testing (recursive) resync of it. * ID name collision handling (between modified linked data and existing overrides).
This commit is contained in:
parent
f32f775e5b
commit
93728fee53
@ -183,120 +183,638 @@ class TestLibraryTemplate(TestHelper, unittest.TestCase):
|
||||
assert operation.operation == 'NOOP'
|
||||
|
||||
|
||||
class TestLibraryOverridesResync(TestHelper, unittest.TestCase):
|
||||
class TestLibraryOverridesComplex(TestHelper, unittest.TestCase):
|
||||
# Test resync, recursive resync, overrides of overrides, ID names collision handling, and multiple overrides.
|
||||
|
||||
DATA_NAME_CONTAINER = "LibCollection"
|
||||
DATA_NAME_RIGGED = "LibRigged"
|
||||
DATA_NAME_RIG = "LibRig"
|
||||
DATA_NAME_CONTROLLER_1 = "LibController1"
|
||||
DATA_NAME_CONTROLLER_2 = "LibController2"
|
||||
DATA_NAME_SAMENAME_CONTAINER = "LibCube"
|
||||
DATA_NAME_SAMENAME_0 = "LibCube"
|
||||
DATA_NAME_SAMENAME_1 = "LibCube.001"
|
||||
DATA_NAME_SAMENAME_2 = "LibCube.002"
|
||||
DATA_NAME_SAMENAME_3 = "LibCube.003"
|
||||
|
||||
def __init__(self, args):
|
||||
self.args = args
|
||||
|
||||
output_dir = pathlib.Path(self.args.output_dir)
|
||||
self.ensure_path(str(output_dir))
|
||||
self.output_path = output_dir / "blendlib_overrides.blend"
|
||||
self.lib_output_path = output_dir / "blendlib_overrides_lib.blend"
|
||||
self.test_output_path = output_dir / "blendlib_overrides_test.blend"
|
||||
self.test_output_path_recursive = output_dir / "blendlib_overrides_test_recursive.blend"
|
||||
|
||||
def reset(self):
|
||||
bpy.ops.wm.read_homefile(use_empty=True, use_factory_startup=True)
|
||||
|
||||
collection_container = bpy.data.collections.new(TestLibraryOverridesResync.DATA_NAME_CONTAINER)
|
||||
def init_lib_data(self, custom_cb=None):
|
||||
self.reset()
|
||||
|
||||
collection_container = bpy.data.collections.new(self.__class__.DATA_NAME_CONTAINER)
|
||||
bpy.context.collection.children.link(collection_container)
|
||||
|
||||
mesh = bpy.data.meshes.new(TestLibraryOverridesResync.DATA_NAME_RIGGED)
|
||||
obj_child = bpy.data.objects.new(TestLibraryOverridesResync.DATA_NAME_RIGGED, object_data=mesh)
|
||||
mesh = bpy.data.meshes.new(self.__class__.DATA_NAME_RIGGED)
|
||||
obj_child = bpy.data.objects.new(self.__class__.DATA_NAME_RIGGED, object_data=mesh)
|
||||
collection_container.objects.link(obj_child)
|
||||
armature = bpy.data.armatures.new(TestLibraryOverridesResync.DATA_NAME_RIG)
|
||||
obj_armature = bpy.data.objects.new(TestLibraryOverridesResync.DATA_NAME_RIG, object_data=armature)
|
||||
armature = bpy.data.armatures.new(self.__class__.DATA_NAME_RIG)
|
||||
obj_armature = bpy.data.objects.new(self.__class__.DATA_NAME_RIG, object_data=armature)
|
||||
obj_child.parent = obj_armature
|
||||
collection_container.objects.link(obj_armature)
|
||||
|
||||
obj_child_modifier = obj_child.modifiers.new("", 'ARMATURE')
|
||||
obj_child_modifier.object = obj_armature
|
||||
|
||||
obj_ctrl1 = bpy.data.objects.new(TestLibraryOverridesResync.DATA_NAME_CONTROLLER_1, object_data=None)
|
||||
obj_ctrl1 = bpy.data.objects.new(self.__class__.DATA_NAME_CONTROLLER_1, object_data=None)
|
||||
collection_container.objects.link(obj_ctrl1)
|
||||
|
||||
obj_armature_constraint = obj_armature.constraints.new('COPY_LOCATION')
|
||||
obj_armature_constraint.target = obj_ctrl1
|
||||
|
||||
collection_sub = bpy.data.collections.new(TestLibraryOverridesResync.DATA_NAME_CONTROLLER_2)
|
||||
collection_sub = bpy.data.collections.new(self.__class__.DATA_NAME_CONTROLLER_2)
|
||||
collection_container.children.link(collection_sub)
|
||||
obj_ctrl2 = bpy.data.objects.new(TestLibraryOverridesResync.DATA_NAME_CONTROLLER_2, object_data=None)
|
||||
obj_ctrl2 = bpy.data.objects.new(self.__class__.DATA_NAME_CONTROLLER_2, object_data=None)
|
||||
collection_sub.objects.link(obj_ctrl2)
|
||||
|
||||
bpy.ops.wm.save_as_mainfile(filepath=str(self.output_path), check_existing=False, compress=False)
|
||||
collection_sub = bpy.data.collections.new(self.__class__.DATA_NAME_SAMENAME_CONTAINER)
|
||||
collection_container.children.link(collection_sub)
|
||||
# 'Samename' objects are purposedly not added to the collection here.
|
||||
|
||||
def test_link_and_override_resync(self):
|
||||
bpy.ops.wm.read_homefile(use_empty=True, use_factory_startup=True)
|
||||
bpy.data.orphans_purge()
|
||||
if custom_cb is not None:
|
||||
custom_cb(self)
|
||||
|
||||
link_dir = self.output_path / "Collection"
|
||||
bpy.ops.wm.link(
|
||||
directory=str(link_dir),
|
||||
filename=TestLibraryOverridesResync.DATA_NAME_CONTAINER,
|
||||
instance_collections=False,
|
||||
bpy.ops.wm.save_as_mainfile(
|
||||
filepath=str(self.lib_output_path),
|
||||
check_existing=False,
|
||||
compress=False,
|
||||
relative_remap=False,
|
||||
)
|
||||
|
||||
linked_collection_container = bpy.data.collections[TestLibraryOverridesResync.DATA_NAME_CONTAINER]
|
||||
def edit_lib_data(self, custom_cb):
|
||||
bpy.ops.wm.open_mainfile(filepath=str(self.lib_output_path))
|
||||
custom_cb(self)
|
||||
bpy.ops.wm.save_as_mainfile(
|
||||
filepath=str(self.lib_output_path),
|
||||
check_existing=False,
|
||||
compress=False,
|
||||
relative_remap=False,
|
||||
)
|
||||
|
||||
def link_lib_data(self, num_collections, num_objects, num_meshes, num_armatures):
|
||||
link_dir = self.lib_output_path / "Collection"
|
||||
bpy.ops.wm.link(
|
||||
directory=str(link_dir),
|
||||
filename=self.__class__.DATA_NAME_CONTAINER,
|
||||
instance_collections=False,
|
||||
relative_path=False,
|
||||
)
|
||||
|
||||
linked_collection_container = bpy.data.collections[self.__class__.DATA_NAME_CONTAINER]
|
||||
|
||||
assert linked_collection_container.library is not None
|
||||
assert linked_collection_container.override_library is None
|
||||
assert len(bpy.data.collections) == 2
|
||||
assert len(bpy.data.collections) == num_collections
|
||||
assert all(id_.library is not None for id_ in bpy.data.collections)
|
||||
assert len(bpy.data.objects) == 4
|
||||
assert len(bpy.data.objects) == num_objects
|
||||
assert all(id_.library is not None for id_ in bpy.data.objects)
|
||||
assert len(bpy.data.meshes) == 1
|
||||
assert len(bpy.data.meshes) == num_meshes
|
||||
assert all(id_.library is not None for id_ in bpy.data.meshes)
|
||||
assert len(bpy.data.armatures) == 1
|
||||
assert len(bpy.data.armatures) == num_armatures
|
||||
assert all(id_.library is not None for id_ in bpy.data.armatures)
|
||||
|
||||
return linked_collection_container
|
||||
|
||||
def link_liboverride_data(self, num_collections, num_objects, num_meshes, num_armatures):
|
||||
link_dir = self.test_output_path / "Collection"
|
||||
bpy.ops.wm.link(
|
||||
directory=str(link_dir),
|
||||
filename=self.__class__.DATA_NAME_CONTAINER,
|
||||
instance_collections=False,
|
||||
relative_path=False,
|
||||
)
|
||||
|
||||
linked_collection_container = bpy.data.collections[self.__class__.DATA_NAME_CONTAINER, str(self.test_output_path)]
|
||||
assert linked_collection_container.library is not None
|
||||
assert linked_collection_container.override_library is not None
|
||||
assert len(bpy.data.collections) == num_collections
|
||||
assert all(id_.library is not None for id_ in bpy.data.collections)
|
||||
assert len(bpy.data.objects) == num_objects
|
||||
assert all(id_.library is not None for id_ in bpy.data.objects)
|
||||
assert len(bpy.data.meshes) == num_meshes
|
||||
assert all(id_.library is not None for id_ in bpy.data.meshes)
|
||||
assert len(bpy.data.armatures) == num_armatures
|
||||
assert all(id_.library is not None for id_ in bpy.data.armatures)
|
||||
|
||||
self.liboverride_hierarchy_validate(linked_collection_container)
|
||||
|
||||
return linked_collection_container
|
||||
|
||||
@staticmethod
|
||||
def liboverride_hierarchy_validate(root_collection):
|
||||
def liboverride_systemoverrideonly_hierarchy_validate(id_, id_root):
|
||||
if not id_.override_library:
|
||||
return
|
||||
assert id_.override_library.hierarchy_root == id_root
|
||||
for op in id_.override_library.properties:
|
||||
for opop in op.operations:
|
||||
assert 'IDPOINTER_MATCH_REFERENCE' in opop.flag
|
||||
|
||||
for coll_ in root_collection.children_recursive:
|
||||
liboverride_systemoverrideonly_hierarchy_validate(coll_, root_collection)
|
||||
for ob_ in root_collection.all_objects:
|
||||
liboverride_systemoverrideonly_hierarchy_validate(ob_, root_collection)
|
||||
|
||||
def test_link_and_override_resync(self):
|
||||
self.init_lib_data()
|
||||
self.reset()
|
||||
|
||||
# NOTE: All counts below are in the form `local_ids + linked_ids`.
|
||||
linked_collection_container = self.link_lib_data(
|
||||
num_collections=0 + 3,
|
||||
num_objects=0 + 4,
|
||||
num_meshes=0 + 1,
|
||||
num_armatures=0 + 1)
|
||||
|
||||
override_collection_container = linked_collection_container.override_hierarchy_create(
|
||||
bpy.context.scene,
|
||||
bpy.context.view_layer,
|
||||
)
|
||||
assert override_collection_container.library is None
|
||||
assert override_collection_container.override_library is not None
|
||||
# Objects and collections are duplicated as overrides, but meshes and armatures remain only linked data.
|
||||
assert len(bpy.data.collections) == 4
|
||||
# Objects and collections are duplicated as overrides (except for empty collection),
|
||||
# but meshes and armatures remain only linked data.
|
||||
assert len(bpy.data.collections) == 2 + 3
|
||||
assert all((id_.library is None and id_.override_library is not None) for id_ in bpy.data.collections[:2])
|
||||
assert len(bpy.data.objects) == 8
|
||||
assert len(bpy.data.objects) == 4 + 4
|
||||
assert all((id_.library is None and id_.override_library is not None) for id_ in bpy.data.objects[:4])
|
||||
assert len(bpy.data.meshes) == 1
|
||||
assert len(bpy.data.armatures) == 1
|
||||
assert len(bpy.data.meshes) == 0 + 1
|
||||
assert len(bpy.data.armatures) == 0 + 1
|
||||
|
||||
bpy.ops.wm.save_as_mainfile(filepath=str(self.test_output_path), check_existing=False, compress=False)
|
||||
self.liboverride_hierarchy_validate(override_collection_container)
|
||||
|
||||
bpy.ops.wm.save_as_mainfile(
|
||||
filepath=str(self.test_output_path),
|
||||
check_existing=False,
|
||||
compress=False,
|
||||
relative_remap=False,
|
||||
)
|
||||
|
||||
# Create linked liboverrides file (for recursive resync).
|
||||
self.reset()
|
||||
|
||||
self.link_liboverride_data(
|
||||
num_collections=0 + 5,
|
||||
num_objects=0 + 8,
|
||||
num_meshes=0 + 1,
|
||||
num_armatures=0 + 1)
|
||||
|
||||
bpy.ops.wm.save_as_mainfile(
|
||||
filepath=str(self.test_output_path_recursive),
|
||||
check_existing=False,
|
||||
compress=False,
|
||||
relative_remap=False,
|
||||
)
|
||||
|
||||
# Re-open the lib file, and change its ID relationships.
|
||||
bpy.ops.wm.open_mainfile(filepath=str(self.output_path))
|
||||
bpy.ops.wm.open_mainfile(filepath=str(self.lib_output_path))
|
||||
|
||||
obj_armature = bpy.data.objects[TestLibraryOverridesResync.DATA_NAME_RIG]
|
||||
obj_armature = bpy.data.objects[self.__class__.DATA_NAME_RIG]
|
||||
obj_armature_constraint = obj_armature.constraints[0]
|
||||
obj_ctrl2 = bpy.data.objects[TestLibraryOverridesResync.DATA_NAME_CONTROLLER_2]
|
||||
obj_ctrl2 = bpy.data.objects[self.__class__.DATA_NAME_CONTROLLER_2]
|
||||
obj_armature_constraint.target = obj_ctrl2
|
||||
|
||||
bpy.ops.wm.save_as_mainfile(filepath=str(self.output_path), check_existing=False, compress=False)
|
||||
bpy.ops.wm.save_as_mainfile(filepath=str(self.lib_output_path), check_existing=False, compress=False)
|
||||
|
||||
# Re-open the main file, and check that automatic resync did its work correctly, remapping the target of the
|
||||
# armature constraint to controller 2, without creating unexpected garbage IDs along the line.
|
||||
bpy.ops.wm.open_mainfile(filepath=str(self.test_output_path))
|
||||
|
||||
override_collection_container = bpy.data.collections[TestLibraryOverridesResync.DATA_NAME_CONTAINER]
|
||||
override_collection_container = bpy.data.collections[self.__class__.DATA_NAME_CONTAINER]
|
||||
assert override_collection_container.library is None
|
||||
assert override_collection_container.override_library is not None
|
||||
# Objects and collections are duplicated as overrides, but meshes and armatures remain only linked data.
|
||||
assert len(bpy.data.collections) == 4
|
||||
assert len(bpy.data.collections) == 2 + 3
|
||||
assert all((id_.library is None and id_.override_library is not None) for id_ in bpy.data.collections[:2])
|
||||
assert len(bpy.data.objects) == 8
|
||||
assert len(bpy.data.objects) == 4 + 4
|
||||
assert all((id_.library is None and id_.override_library is not None) for id_ in bpy.data.objects[:4])
|
||||
assert len(bpy.data.meshes) == 1
|
||||
assert len(bpy.data.armatures) == 1
|
||||
assert len(bpy.data.meshes) == 0 + 1
|
||||
assert len(bpy.data.armatures) == 0 + 1
|
||||
|
||||
obj_armature = bpy.data.objects[TestLibraryOverridesResync.DATA_NAME_RIG]
|
||||
obj_ctrl2 = bpy.data.objects[TestLibraryOverridesResync.DATA_NAME_CONTROLLER_2]
|
||||
obj_armature = bpy.data.objects[self.__class__.DATA_NAME_RIG]
|
||||
obj_ctrl2 = bpy.data.objects[self.__class__.DATA_NAME_CONTROLLER_2]
|
||||
assert obj_armature.library is None and obj_armature.override_library is not None
|
||||
assert obj_ctrl2.library is None and obj_ctrl2.override_library is not None
|
||||
assert obj_armature.constraints[0].target == obj_ctrl2
|
||||
|
||||
self.liboverride_hierarchy_validate(override_collection_container)
|
||||
|
||||
# Re-open the 'recursive resync' file, and check that automatic recursive resync did its work correctly,
|
||||
# remapping the target of the linked liboverride armature constraint to controller 2, without creating
|
||||
# unexpected garbage IDs along the line.
|
||||
bpy.ops.wm.open_mainfile(filepath=str(self.test_output_path_recursive))
|
||||
|
||||
override_collection_container = bpy.data.collections[self.__class__.DATA_NAME_CONTAINER, str(self.test_output_path)]
|
||||
assert override_collection_container.library is not None
|
||||
assert override_collection_container.override_library is not None
|
||||
test_output_path_lib = override_collection_container.library
|
||||
assert len(bpy.data.collections) == 0 + 5
|
||||
assert all((id_.override_library is not None) for id_ in bpy.data.collections if id_.library == test_output_path_lib)
|
||||
assert len(bpy.data.objects) == 0 + 8
|
||||
assert all((id_.override_library is not None) for id_ in bpy.data.objects if id_.library == test_output_path_lib)
|
||||
assert len(bpy.data.meshes) == 0 + 1
|
||||
assert len(bpy.data.armatures) == 0 + 1
|
||||
|
||||
obj_armature = bpy.data.objects[self.__class__.DATA_NAME_RIG, str(self.test_output_path)]
|
||||
obj_ctrl2 = bpy.data.objects[self.__class__.DATA_NAME_CONTROLLER_2, str(self.test_output_path)]
|
||||
assert obj_armature.override_library is not None
|
||||
assert obj_ctrl2.override_library is not None
|
||||
assert obj_armature.constraints[0].target == obj_ctrl2
|
||||
|
||||
self.liboverride_hierarchy_validate(override_collection_container)
|
||||
|
||||
def test_link_and_override_multiple(self):
|
||||
self.init_lib_data()
|
||||
self.reset()
|
||||
|
||||
# NOTE: All counts below are in the form `local_ids + linked_ids`.
|
||||
linked_collection_container = self.link_lib_data(
|
||||
num_collections=0 + 3,
|
||||
num_objects=0 + 4,
|
||||
num_meshes=0 + 1,
|
||||
num_armatures=0 + 1)
|
||||
|
||||
override_collection_containers = [linked_collection_container.override_hierarchy_create(
|
||||
bpy.context.scene,
|
||||
bpy.context.view_layer,
|
||||
) for i in range(3)]
|
||||
for override_container in override_collection_containers:
|
||||
assert override_container.library is None
|
||||
assert override_container.override_library is not None
|
||||
self.liboverride_hierarchy_validate(override_container)
|
||||
|
||||
# Objects and collections are duplicated as overrides (except for empty collection),
|
||||
# but meshes and armatures remain only linked data.
|
||||
assert len(bpy.data.collections) == 3 * 2 + 3
|
||||
assert all((id_.library is None and id_.override_library is not None) for id_ in bpy.data.collections[:3 * 2])
|
||||
assert len(bpy.data.objects) == 3 * 4 + 4
|
||||
assert all((id_.library is None and id_.override_library is not None) for id_ in bpy.data.objects[:3 * 4])
|
||||
assert len(bpy.data.meshes) == 0 + 1
|
||||
assert len(bpy.data.armatures) == 0 + 1
|
||||
|
||||
bpy.ops.wm.save_as_mainfile(
|
||||
filepath=str(self.test_output_path),
|
||||
check_existing=False,
|
||||
compress=False,
|
||||
relative_remap=False,
|
||||
)
|
||||
|
||||
# Create linked liboverrides file (for recursive resync).
|
||||
self.reset()
|
||||
|
||||
self.link_liboverride_data(
|
||||
num_collections=0 + 5,
|
||||
num_objects=0 + 8,
|
||||
num_meshes=0 + 1,
|
||||
num_armatures=0 + 1)
|
||||
|
||||
bpy.ops.wm.save_as_mainfile(
|
||||
filepath=str(self.test_output_path_recursive),
|
||||
check_existing=False,
|
||||
compress=False,
|
||||
relative_remap=False,
|
||||
)
|
||||
|
||||
# Change the lib's ID relationships.
|
||||
def edit_lib_cb(self):
|
||||
obj_armature = bpy.data.objects[self.__class__.DATA_NAME_RIG]
|
||||
obj_armature_constraint = obj_armature.constraints[0]
|
||||
obj_ctrl2 = bpy.data.objects[self.__class__.DATA_NAME_CONTROLLER_2]
|
||||
obj_armature_constraint.target = obj_ctrl2
|
||||
self.edit_lib_data(edit_lib_cb)
|
||||
|
||||
# Re-open the main file, and check that automatic resync did its work correctly, remapping the target of the
|
||||
# armature constraint to controller 2, without creating unexpected garbage IDs along the line.
|
||||
bpy.ops.wm.open_mainfile(filepath=str(self.test_output_path))
|
||||
|
||||
override_collection_container = bpy.data.collections[self.__class__.DATA_NAME_CONTAINER]
|
||||
assert override_collection_container.library is None
|
||||
assert override_collection_container.override_library is not None
|
||||
# Objects and collections are duplicated as overrides, but meshes and armatures remain only linked data.
|
||||
assert len(bpy.data.collections) == 3 * 2 + 3
|
||||
assert all((id_.library is None and id_.override_library is not None) for id_ in bpy.data.collections[:3 * 2])
|
||||
assert len(bpy.data.objects) == 3 * 4 + 4
|
||||
assert all((id_.library is None and id_.override_library is not None) for id_ in bpy.data.objects[:3 * 4])
|
||||
assert len(bpy.data.meshes) == 0 + 1
|
||||
assert len(bpy.data.armatures) == 0 + 1
|
||||
|
||||
obj_armature = bpy.data.objects[self.__class__.DATA_NAME_RIG]
|
||||
obj_ctrl2 = bpy.data.objects[self.__class__.DATA_NAME_CONTROLLER_2]
|
||||
assert obj_armature.library is None and obj_armature.override_library is not None
|
||||
assert obj_ctrl2.library is None and obj_ctrl2.override_library is not None
|
||||
assert obj_armature.constraints[0].target == obj_ctrl2
|
||||
|
||||
override_collection_containers = [
|
||||
bpy.data.collections[self.__class__.DATA_NAME_CONTAINER],
|
||||
bpy.data.collections[self.__class__.DATA_NAME_CONTAINER + ".001"],
|
||||
bpy.data.collections[self.__class__.DATA_NAME_CONTAINER + ".002"],
|
||||
]
|
||||
for override_container in override_collection_containers:
|
||||
assert override_container.library is None
|
||||
assert override_container.override_library is not None
|
||||
self.liboverride_hierarchy_validate(override_container)
|
||||
|
||||
# Re-open the 'recursive resync' file, and check that automatic recursive resync did its work correctly,
|
||||
# remapping the target of the linked liboverride armature constraint to controller 2, without creating
|
||||
# unexpected garbage IDs along the line.
|
||||
bpy.ops.wm.open_mainfile(filepath=str(self.test_output_path_recursive))
|
||||
|
||||
linked_collection_container = bpy.data.collections[self.__class__.DATA_NAME_CONTAINER, str(self.test_output_path)]
|
||||
assert linked_collection_container.library is not None
|
||||
assert linked_collection_container.override_library is not None
|
||||
test_output_path_lib = linked_collection_container.library
|
||||
# Objects and collections are duplicated as overrides, but meshes and armatures remain only linked data.
|
||||
assert len(bpy.data.collections) == 0 + 5
|
||||
assert all((id_.override_library is not None) for id_ in bpy.data.collections if id_.library == test_output_path_lib)
|
||||
assert len(bpy.data.objects) == 0 + 8
|
||||
assert all((id_.override_library is not None) for id_ in bpy.data.objects if id_.library == test_output_path_lib)
|
||||
assert len(bpy.data.meshes) == 0 + 1
|
||||
assert len(bpy.data.armatures) == 0 + 1
|
||||
|
||||
obj_armature = bpy.data.objects[self.__class__.DATA_NAME_RIG, str(self.test_output_path)]
|
||||
obj_ctrl2 = bpy.data.objects[self.__class__.DATA_NAME_CONTROLLER_2, str(self.test_output_path)]
|
||||
assert obj_armature.override_library is not None
|
||||
assert obj_ctrl2.override_library is not None
|
||||
assert obj_armature.constraints[0].target == obj_ctrl2
|
||||
|
||||
self.liboverride_hierarchy_validate(linked_collection_container)
|
||||
|
||||
def test_link_and_override_of_override(self):
|
||||
self.init_lib_data()
|
||||
self.reset()
|
||||
|
||||
# NOTE: All counts below are in the form `local_ids + linked_ids`.
|
||||
linked_collection_container = self.link_lib_data(
|
||||
num_collections=0 + 3,
|
||||
num_objects=0 + 4,
|
||||
num_meshes=0 + 1,
|
||||
num_armatures=0 + 1)
|
||||
|
||||
override_collection_container = linked_collection_container.override_hierarchy_create(
|
||||
bpy.context.scene,
|
||||
bpy.context.view_layer,
|
||||
)
|
||||
assert override_collection_container.library is None
|
||||
assert override_collection_container.override_library is not None
|
||||
|
||||
# Objects and collections are duplicated as overrides (except for empty collection),
|
||||
# but meshes and armatures remain only linked data.
|
||||
assert len(bpy.data.collections) == 2 + 3
|
||||
assert all((id_.library is None and id_.override_library is not None) for id_ in bpy.data.collections[:2])
|
||||
assert len(bpy.data.objects) == 4 + 4
|
||||
assert all((id_.library is None and id_.override_library is not None) for id_ in bpy.data.objects[:4])
|
||||
assert len(bpy.data.meshes) == 0 + 1
|
||||
assert len(bpy.data.armatures) == 0 + 1
|
||||
|
||||
self.liboverride_hierarchy_validate(override_collection_container)
|
||||
|
||||
bpy.ops.wm.save_as_mainfile(
|
||||
filepath=str(self.test_output_path),
|
||||
check_existing=False,
|
||||
compress=False,
|
||||
relative_remap=False,
|
||||
)
|
||||
|
||||
# Create liboverrides of liboverrides file.
|
||||
self.reset()
|
||||
|
||||
linked_collection_container = self.link_liboverride_data(
|
||||
num_collections=0 + 5,
|
||||
num_objects=0 + 8,
|
||||
num_meshes=0 + 1,
|
||||
num_armatures=0 + 1)
|
||||
|
||||
override_collection_container = linked_collection_container.override_hierarchy_create(
|
||||
bpy.context.scene,
|
||||
bpy.context.view_layer,
|
||||
)
|
||||
assert override_collection_container.library is None
|
||||
assert override_collection_container.override_library is not None
|
||||
|
||||
# Objects and collections are duplicated as overrides (except for empty collection),
|
||||
# but meshes and armatures remain only linked data.
|
||||
assert len(bpy.data.collections) == 2 + 5
|
||||
assert all((id_.library is None and id_.override_library is not None) for id_ in bpy.data.collections[:2])
|
||||
assert len(bpy.data.objects) == 4 + 8
|
||||
assert all((id_.library is None and id_.override_library is not None) for id_ in bpy.data.objects[:4])
|
||||
assert len(bpy.data.meshes) == 0 + 1
|
||||
assert len(bpy.data.armatures) == 0 + 1
|
||||
|
||||
self.liboverride_hierarchy_validate(override_collection_container)
|
||||
|
||||
bpy.ops.wm.save_as_mainfile(
|
||||
filepath=str(self.test_output_path_recursive),
|
||||
check_existing=False,
|
||||
compress=False,
|
||||
relative_remap=False,
|
||||
)
|
||||
|
||||
# Re-open the lib file, and change its ID relationships.
|
||||
bpy.ops.wm.open_mainfile(filepath=str(self.lib_output_path))
|
||||
|
||||
obj_armature = bpy.data.objects[self.__class__.DATA_NAME_RIG]
|
||||
obj_armature_constraint = obj_armature.constraints[0]
|
||||
obj_ctrl2 = bpy.data.objects[self.__class__.DATA_NAME_CONTROLLER_2]
|
||||
obj_armature_constraint.target = obj_ctrl2
|
||||
|
||||
bpy.ops.wm.save_as_mainfile(filepath=str(self.lib_output_path), check_existing=False, compress=False)
|
||||
|
||||
# Re-open the main file, and check that automatic resync did its work correctly, remapping the target of the
|
||||
# armature constraint to controller 2, without creating unexpected garbage IDs along the line.
|
||||
bpy.ops.wm.open_mainfile(filepath=str(self.test_output_path))
|
||||
|
||||
override_collection_container = bpy.data.collections[self.__class__.DATA_NAME_CONTAINER]
|
||||
assert override_collection_container.library is None
|
||||
assert override_collection_container.override_library is not None
|
||||
# Objects and collections are duplicated as overrides, but meshes and armatures remain only linked data.
|
||||
assert len(bpy.data.collections) == 2 + 3
|
||||
assert all((id_.library is None and id_.override_library is not None) for id_ in bpy.data.collections[:2])
|
||||
assert len(bpy.data.objects) == 4 + 4
|
||||
assert all((id_.library is None and id_.override_library is not None) for id_ in bpy.data.objects[:4])
|
||||
assert len(bpy.data.meshes) == 0 + 1
|
||||
assert len(bpy.data.armatures) == 0 + 1
|
||||
|
||||
obj_armature = bpy.data.objects[self.__class__.DATA_NAME_RIG]
|
||||
obj_ctrl2 = bpy.data.objects[self.__class__.DATA_NAME_CONTROLLER_2]
|
||||
assert obj_armature.library is None and obj_armature.override_library is not None
|
||||
assert obj_ctrl2.library is None and obj_ctrl2.override_library is not None
|
||||
assert obj_armature.constraints[0].target == obj_ctrl2
|
||||
|
||||
self.liboverride_hierarchy_validate(override_collection_container)
|
||||
|
||||
# Re-open the 'recursive resync' file, and check that automatic recursive resync did its work correctly,
|
||||
# remapping the target of the linked liboverride armature constraint to controller 2, without creating
|
||||
# unexpected garbage IDs along the line.
|
||||
bpy.ops.wm.open_mainfile(filepath=str(self.test_output_path_recursive))
|
||||
|
||||
override_collection_container = bpy.data.collections[self.__class__.DATA_NAME_CONTAINER]
|
||||
assert override_collection_container.library is None
|
||||
assert override_collection_container.override_library is not None
|
||||
# Objects and collections are duplicated as overrides, but meshes and armatures remain only linked data.
|
||||
assert len(bpy.data.collections) == 2 + 5
|
||||
assert all((id_.library is None and id_.override_library is not None) for id_ in bpy.data.collections[:2])
|
||||
assert len(bpy.data.objects) == 4 + 8
|
||||
assert all((id_.library is None and id_.override_library is not None) for id_ in bpy.data.objects[:4])
|
||||
assert len(bpy.data.meshes) == 0 + 1
|
||||
assert len(bpy.data.armatures) == 0 + 1
|
||||
|
||||
obj_armature = bpy.data.objects[self.__class__.DATA_NAME_RIG]
|
||||
obj_ctrl2 = bpy.data.objects[self.__class__.DATA_NAME_CONTROLLER_2]
|
||||
assert obj_armature.override_library is not None
|
||||
assert obj_ctrl2.override_library is not None
|
||||
assert obj_armature.constraints[0].target == obj_ctrl2
|
||||
|
||||
self.liboverride_hierarchy_validate(override_collection_container)
|
||||
|
||||
def test_link_and_override_idnames_conflict(self):
|
||||
def init_lib_cb(self):
|
||||
# Add some 'samename' objects to the library.
|
||||
collection_sub = bpy.data.collections[self.__class__.DATA_NAME_SAMENAME_CONTAINER]
|
||||
obj_samename_0 = bpy.data.objects.new(self.__class__.DATA_NAME_SAMENAME_0, object_data=None)
|
||||
collection_sub.objects.link(obj_samename_0)
|
||||
obj_samename_3 = bpy.data.objects.new(self.__class__.DATA_NAME_SAMENAME_3, object_data=None)
|
||||
collection_sub.objects.link(obj_samename_3)
|
||||
self.init_lib_data(init_lib_cb)
|
||||
self.reset()
|
||||
|
||||
# NOTE: All counts below are in the form `local_ids + linked_ids`.
|
||||
linked_collection_container = self.link_lib_data(
|
||||
num_collections=0 + 3,
|
||||
num_objects=0 + 6,
|
||||
num_meshes=0 + 1,
|
||||
num_armatures=0 + 1)
|
||||
|
||||
override_collection_containers = [linked_collection_container.override_hierarchy_create(
|
||||
bpy.context.scene,
|
||||
bpy.context.view_layer,
|
||||
) for i in range(3)]
|
||||
for override_container in override_collection_containers:
|
||||
assert override_container.library is None
|
||||
assert override_container.override_library is not None
|
||||
self.liboverride_hierarchy_validate(override_container)
|
||||
|
||||
# Objects and collections are duplicated as overrides (except for empty collection),
|
||||
# but meshes and armatures remain only linked data.
|
||||
assert len(bpy.data.collections) == 3 * 3 + 3
|
||||
assert all((id_.library is None and id_.override_library is not None) for id_ in bpy.data.collections[:3 * 3])
|
||||
assert len(bpy.data.objects) == 3 * 6 + 6
|
||||
assert all((id_.library is None and id_.override_library is not None) for id_ in bpy.data.objects[:3 * 6])
|
||||
assert len(bpy.data.meshes) == 0 + 1
|
||||
assert len(bpy.data.armatures) == 0 + 1
|
||||
|
||||
bpy.data.objects[self.__class__.DATA_NAME_SAMENAME_0].override_library.reference.name == self.__class__.DATA_NAME_SAMENAME_0
|
||||
bpy.data.objects[self.__class__.DATA_NAME_SAMENAME_3].override_library.reference.name == self.__class__.DATA_NAME_SAMENAME_3
|
||||
# These names will be used by the second created liboverride, due to how naming is currently handled when original name is already used.
|
||||
bpy.data.objects[self.__class__.DATA_NAME_SAMENAME_1].override_library.reference.name == self.__class__.DATA_NAME_SAMENAME_0
|
||||
bpy.data.objects[self.__class__.DATA_NAME_SAMENAME_2].override_library.reference.name == self.__class__.DATA_NAME_SAMENAME_3
|
||||
|
||||
bpy.ops.wm.save_as_mainfile(
|
||||
filepath=str(self.test_output_path),
|
||||
check_existing=False,
|
||||
compress=False,
|
||||
relative_remap=False,
|
||||
)
|
||||
|
||||
# Create liboverrides of liboverrides file.
|
||||
self.reset()
|
||||
|
||||
linked_collection_container = self.link_liboverride_data(
|
||||
num_collections=0 + 6,
|
||||
num_objects=0 + 12,
|
||||
num_meshes=0 + 1,
|
||||
num_armatures=0 + 1)
|
||||
|
||||
override_collection_container = linked_collection_container.override_hierarchy_create(
|
||||
bpy.context.scene,
|
||||
bpy.context.view_layer,
|
||||
)
|
||||
assert override_collection_container.library is None
|
||||
assert override_collection_container.override_library is not None
|
||||
|
||||
# Objects and collections are duplicated as overrides (except for empty collection),
|
||||
# but meshes and armatures remain only linked data.
|
||||
assert len(bpy.data.collections) == 3 + 6
|
||||
assert all((id_.library is None and id_.override_library is not None) for id_ in bpy.data.collections[:3])
|
||||
assert len(bpy.data.objects) == 6 + 12
|
||||
assert all((id_.library is None and id_.override_library is not None) for id_ in bpy.data.objects[:6])
|
||||
assert len(bpy.data.meshes) == 0 + 1
|
||||
assert len(bpy.data.armatures) == 0 + 1
|
||||
|
||||
self.liboverride_hierarchy_validate(override_collection_container)
|
||||
|
||||
bpy.ops.wm.save_as_mainfile(
|
||||
filepath=str(self.test_output_path_recursive),
|
||||
check_existing=False,
|
||||
compress=False,
|
||||
relative_remap=False,
|
||||
)
|
||||
|
||||
# Modify the names of 'samename' objects in the library to generate ID name collisions.
|
||||
def edit_lib_cb(self):
|
||||
obj_samename_0 = bpy.data.objects[self.__class__.DATA_NAME_SAMENAME_0]
|
||||
obj_samename_3 = bpy.data.objects[self.__class__.DATA_NAME_SAMENAME_3]
|
||||
obj_samename_0.name = self.__class__.DATA_NAME_SAMENAME_2
|
||||
obj_samename_3.name = self.__class__.DATA_NAME_SAMENAME_1
|
||||
self.edit_lib_data(edit_lib_cb)
|
||||
|
||||
# Re-open the main file, and check that automatic resync did its work correctly, remapping the target of the
|
||||
# armature constraint to controller 2, without creating unexpected garbage IDs along the line.
|
||||
bpy.ops.wm.open_mainfile(filepath=str(self.test_output_path))
|
||||
|
||||
override_collection_container = bpy.data.collections[self.__class__.DATA_NAME_CONTAINER]
|
||||
assert override_collection_container.library is None
|
||||
assert override_collection_container.override_library is not None
|
||||
# Objects and collections are duplicated as overrides, but meshes and armatures remain only linked data.
|
||||
assert len(bpy.data.collections) == 3 * 3 + 3
|
||||
assert all((id_.library is None and id_.override_library is not None) for id_ in bpy.data.collections[:3 * 3])
|
||||
# Note that the 'missing' renamed objects from the library are still here as empty placeholders,
|
||||
# hence the 8 linked ones instead of 6.
|
||||
assert len(bpy.data.objects) == 3 * 6 + 8
|
||||
assert all((id_.library is None and id_.override_library is not None) for id_ in bpy.data.objects[:3 * 6])
|
||||
assert len(bpy.data.meshes) == 0 + 1
|
||||
assert len(bpy.data.armatures) == 0 + 1
|
||||
|
||||
override_collection_containers = [
|
||||
bpy.data.collections[self.__class__.DATA_NAME_CONTAINER],
|
||||
bpy.data.collections[self.__class__.DATA_NAME_CONTAINER + ".001"],
|
||||
bpy.data.collections[self.__class__.DATA_NAME_CONTAINER + ".002"],
|
||||
]
|
||||
for override_container in override_collection_containers:
|
||||
assert override_container.library is None
|
||||
assert override_container.override_library is not None
|
||||
self.liboverride_hierarchy_validate(override_container)
|
||||
|
||||
# Re-open the 'recursive resync' file, and check that automatic recursive resync did its work correctly,
|
||||
# remapping the target of the linked liboverride armature constraint to controller 2, without creating
|
||||
# unexpected garbage IDs along the line.
|
||||
bpy.ops.wm.open_mainfile(filepath=str(self.test_output_path_recursive))
|
||||
|
||||
linked_collection_container = bpy.data.collections[self.__class__.DATA_NAME_CONTAINER, str(self.test_output_path)]
|
||||
assert linked_collection_container.library is not None
|
||||
assert linked_collection_container.override_library is not None
|
||||
|
||||
test_output_path_lib = linked_collection_container.library
|
||||
# Objects and collections are duplicated as overrides, but meshes and armatures remain only linked data.
|
||||
assert len(bpy.data.collections) == 3 + 6
|
||||
assert all((id_.override_library is not None) for id_ in bpy.data.collections if id_.library == test_output_path_lib)
|
||||
# Note that the 'missing' renamed objects from the library are still here as empty placeholders,
|
||||
# hence the 8 + 6 linked ones instead of 6 + 6.
|
||||
assert len(bpy.data.objects) == 6 + 14
|
||||
assert all((id_.override_library is not None) for id_ in bpy.data.objects if id_.library == test_output_path_lib)
|
||||
assert len(bpy.data.meshes) == 0 + 1
|
||||
assert len(bpy.data.armatures) == 0 + 1
|
||||
|
||||
self.liboverride_hierarchy_validate(linked_collection_container)
|
||||
|
||||
|
||||
class TestLibraryOverridesFromProxies(TestHelper, unittest.TestCase):
|
||||
# Very basic test, could be improved/extended.
|
||||
@ -327,7 +845,7 @@ class TestLibraryOverridesFromProxies(TestHelper, unittest.TestCase):
|
||||
TESTS = (
|
||||
TestLibraryOverrides,
|
||||
TestLibraryTemplate,
|
||||
TestLibraryOverridesResync,
|
||||
TestLibraryOverridesComplex,
|
||||
TestLibraryOverridesFromProxies,
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user