fix(rcf): collection children loading

This commit is contained in:
Swann Martinez
2019-04-26 16:14:48 +02:00
parent 710af6e1dd
commit e449365c0a
2 changed files with 32 additions and 23 deletions

View File

@ -172,7 +172,7 @@ def load_collection(target=None, data=None, create=False):
# Load other meshes metadata # Load other meshes metadata
# dump_anything.load(target, data) # dump_anything.load(target, data)
# load objects into collection # link objects
for object in data["objects"]: for object in data["objects"]:
target.objects.link(bpy.data.objects[object]) target.objects.link(bpy.data.objects[object])
@ -180,9 +180,15 @@ def load_collection(target=None, data=None, create=False):
if object not in data["objects"]: if object not in data["objects"]:
target.objects.unlink(bpy.data.objects[object]) target.objects.unlink(bpy.data.objects[object])
# Link childrens
for collection in data["children"]:
if collection not in target.children.keys():
target.children.link(
bpy.data.collections[collection])
target.id = data['id'] target.id = data['id']
except: except Exception as e:
print("Collection loading error") print("Collection loading error: {}".format(e))
def load_scene(target=None, data=None, create=False): def load_scene(target=None, data=None, create=False):

View File

@ -40,14 +40,15 @@ def client_list_callback(scene, context):
global client_keys global client_keys
items = [] items = []
if client_keys:
for k in client_keys: for k in client_keys:
if 'Client' in k[0]: if 'Client' in k[0]:
name = k[1] name = k[1]
items.append((name, name, "")) items.append((name, name, ""))
return items return items
def clean_scene(elements=SUPPORTED_DATABLOCKS): def clean_scene(elements=SUPPORTED_DATABLOCKS):
for datablock in elements: for datablock in elements:
datablock_ref = getattr(bpy.data, datablock) datablock_ref = getattr(bpy.data, datablock)
@ -104,14 +105,14 @@ def update_selected_object(context):
if len(selected_objects) > 0: if len(selected_objects) > 0:
for obj in context.selected_objects: for obj in selected_objects:
if obj.name not in client_data[0][1]['active_objects']: if obj not in client_data[0][1]['active_objects']:
client_data[0][1]['active_objects'] = selected_objects client_data[0][1]['active_objects'] = selected_objects
client_instance.set(client_key,client_data[0][1]) client_instance.set(client_key,client_data[0][1])
break break
elif client_data[0][1]['active_objects']: elif client_data and client_data[0][1]['active_objects']:
client_data[0][1]['active_objects'] = [] client_data[0][1]['active_objects'] = []
client_instance.set(client_key,client_data[0][1]) client_instance.set(client_key,client_data[0][1])
@ -144,6 +145,7 @@ def update_selected_object(context):
# return False # return False
def update_rights(): def update_rights():
C = bpy.context C = bpy.context
@ -156,6 +158,7 @@ def update_rights():
else: else:
D.objects[obj.name].hide_select = True D.objects[obj.name].hide_select = True
def init_datablocks(): def init_datablocks():
global client_instance global client_instance
@ -527,7 +530,7 @@ def ordered(updates):
for item in updates.items(): for item in updates.items():
if item[1].id.bl_rna.name in SUPPORTED_TYPES: if item[1].id.bl_rna.name in SUPPORTED_TYPES:
uplist.append((SUPPORTED_TYPES.index( uplist.append((SUPPORTED_TYPES.index(
item[1].id.bl_rna.name), item[1].id.bl_rna.name, item[1].id.name)) item[1].id.bl_rna.name), item[1].id.bl_rna.name, item[1].id.name,item[1].id ))
uplist.sort(key=itemgetter(0)) uplist.sort(key=itemgetter(0))
return uplist return uplist
@ -553,7 +556,7 @@ def depsgraph_update(scene):
username = bpy.context.scene.session_settings.username username = bpy.context.scene.session_settings.username
update_selected_object(bpy.context) update_selected_object(bpy.context)
selected_objects = helpers.get_selected_objects(scene) # selected_objects = helpers.get_selected_objects(scene)
@ -579,21 +582,21 @@ def depsgraph_update(scene):
# data = client_instance.get(key) # data = client_instance.get(key)
# if data: # if data:
# # Queue update # if update[3].id == username:
# client_instance.set(key) # # Queue update
# client_instance.set(key)
# else: # else:
# # Instance new object ? # # Instance new object ?
# print("new") # print("new")
# client_instance.add(key) # client_instance.add(key)
if hasattr(bpy.context, 'selected_objects'): selected_objects = helpers.get_selected_objects(scene)
selected_objects = helpers.get_selected_objects(scene) if len(selected_objects) > 0:
if len(selected_objects) > 0: for updated_data in updates:
for updated_data in updates: if updated_data.id.name in selected_objects:
if updated_data.id.name in selected_objects: if updated_data.is_updated_transform or updated_data.is_updated_geometry:
if updated_data.is_updated_transform or updated_data.is_updated_geometry: client_instance.set(
client_instance.set( "{}/{}".format(updated_data.id.bl_rna.name, updated_data.id.name))
"{}/{}".format(updated_data.id.bl_rna.name, updated_data.id.name))
def register(): def register():