def _synch_childs(self, context, o, linked, childs):
"""
sub synch childs nodes of linked object
"""
# remove childs not found on source
l_childs = self.get_childs_panels(context, linked)
c_names = [c.data.name for c in childs]
for c in l_childs:
try:
id = c_names.index(c.data.name)
except:
self.remove_handle(context, c)
context.scene.objects.unlink(c)
bpy.data.objects.remove(c, do_unlink=True)
# children ordering may not be the same, so get the right l_childs order
l_childs = self.get_childs_panels(context, linked)
l_names = [c.data.name for c in l_childs]
order = []
for c in childs:
try:
id = l_names.index(c.data.name)
except:
id = -1
order.append(id)
# add missing childs and update other ones
for i, child in enumerate(childs):
if order[i] < 0:
p = bpy.data.objects.new("Panel", child.data)
context.scene.objects.link(p)
p.lock_location[0] = True
p.lock_location[1] = True
p.lock_location[2] = True
p.lock_rotation[1] = True
p.lock_scale[0] = True
p.lock_scale[1] = True
p.lock_scale[2] = True
p.parent = linked
p.matrix_world = linked.matrix_world.copy()
else:
p = l_childs[order[i]]
# update handle
handle = self.find_handle(child)
h = self.find_handle(p)
if handle is not None:
if h is None:
h = create_handle(context, p, handle.data)
MaterialUtils.add_handle_materials(h)
h.location = handle.location.copy()
elif h is not None:
context.scene.objects.unlink(h)
bpy.data.objects.remove(h, do_unlink=True)
p.location = child.location.copy()
评论列表
文章目录