fix: collection loading renaming

This commit is contained in:
Swann Martinez
2019-05-10 15:12:52 +02:00
parent 707ac984fe
commit 4192b88e6f
4 changed files with 66 additions and 23 deletions

View File

@ -174,7 +174,13 @@ class RCFClient(object):
return value return value
def exist(self,key):
"""
Fast key exist check
"""
pass
def list(self): def list(self):
dump_list = [] dump_list = []
for k,v in self.store.items(): for k,v in self.store.items():

View File

@ -362,11 +362,20 @@ def load_scene(target=None, data=None, create=False):
target.collection.objects.unlink(bpy.data.objects[object]) target.collection.objects.unlink(bpy.data.objects[object])
# load collections # load collections
# TODO: Recursive link # TODO: Recursive link
logger.info("check for new collections")
for collection in data["collection"]["children"]: for collection in data["collection"]["children"]:
logger.debug(collection)
if collection not in target.collection.children.keys(): if collection not in target.collection.children.keys():
target.collection.children.link( target.collection.children.link(
bpy.data.collections[collection]) bpy.data.collections[collection])
logger.info("check for collection to remove")
for collection in target.collection.children.keys():
if collection not in data["collection"]["children"]:
target.collection.children.unlink(
bpy.data.collections[collection])
target.id = data['id'] target.id = data['id']
# Load annotation # Load annotation
# if data["grease_pencil"]: # if data["grease_pencil"]:
@ -374,8 +383,8 @@ def load_scene(target=None, data=None, create=False):
# else: # else:
# target.grease_pencil = None # target.grease_pencil = None
except: except Exception as e:
logger.error("Scene loading error") logger.error("Scene loading error: {}".format(e))
def load_material(target=None, data=None, create=False): def load_material(target=None, data=None, create=False):

View File

@ -126,7 +126,6 @@ def update_selected_object(context):
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])
def init_datablocks(): def init_datablocks():
global client_instance global client_instance
@ -199,7 +198,7 @@ class session_join(bpy.types.Operator):
net_settings = context.scene.session_settings net_settings = context.scene.session_settings
# Scene setup # Scene setup
if net_settings.session_mode == "CONNECT" and net_settings.clear_scene: if net_settings.clear_scene:
clean_scene() clean_scene()
# Session setup # Session setup
@ -513,12 +512,12 @@ def ordered(updates):
return uplist return uplist
def exist(update): def is_replicated(update):
global client_keys global client_keys
dickt = dict(client_keys)
key = "{}/{}".format(update.id.bl_rna.name, update.id.name) key = "{}/{}".format(update.id.bl_rna.name, update.id.name)
if key in client_keys: if key in dickt:
return True return True
else: else:
return False return False
@ -531,7 +530,7 @@ def get_datablock(update,context):
datablock_ref = None datablock_ref = None
if item_id == 'Master Collection': if item_id == 'Master Collection':
Adatablock_ref= bpy.context.scene datablock_ref= bpy.context.scene
elif item_type in helpers.CORRESPONDANCE.keys(): elif item_type in helpers.CORRESPONDANCE.keys():
datablock_ref = getattr(bpy.data, helpers.CORRESPONDANCE[update.id.__class__.__name__])[update.id.name] datablock_ref = getattr(bpy.data, helpers.CORRESPONDANCE[update.id.__class__.__name__])[update.id.name]
else: else:
@ -541,30 +540,53 @@ def get_datablock(update,context):
return datablock_ref return datablock_ref
def toogle_dirty(context, update):
data_ref = get_datablock(update,context)
if data_ref:
logger.info(update.id.bl_rna.__class__.__name__)
data_ref.is_dirty= True
def depsgraph_update(scene): def depsgraph_update(scene):
global client_instance global client_instance
global client_keys global client_keys
global client_state global client_state
ctx = bpy.context
if client_state == 3: if client_state == 3:
print(bpy.context.mode)
if bpy.context.mode in ['OBJECT','PAINT_GPENCIL']:
updates = bpy.context.depsgraph.updates if ctx.mode in ['OBJECT','PAINT_GPENCIL']:
username = bpy.context.scene.session_settings.username updates = ctx.depsgraph.updates
update_selected_object(bpy.context) username = ctx.scene.session_settings.username
update_selected_object(ctx)
selected_objects = helpers.get_selected_objects(scene) selected_objects = helpers.get_selected_objects(scene)
for update in reversed(updates): for update in reversed(updates):
if update.id.id == username or update.id.id == 'Common' or update.id.id == 'None': if is_replicated(update):
# TODO: handle errors if update.id.id == username or update.id.id == 'Common':
data_ref = get_datablock(update,context) toogle_dirty(ctx, update)
else:
#get parent authority
parent_id = ctx.collection.id if ctx.collection.id != 'None' else ctx.scene.id
if parent_id == username or parent_id == 'Common':
item = get_datablock(update,ctx)
item.id = bpy.context.scene.session_settings.username
key = "{}/{}".format(item.__class__.__name__, item.name)
client_instance.set(key)
else:
break
# if update.id.id == username or update.id.id == 'Common' or update.id.id == 'None':
# # TODO: handle errors
# data_ref = get_datablock(update,context)
if data_ref: # if data_ref:
logger.info(update.id.bl_rna.__class__.__name__) # logger.info(update.id.bl_rna.__class__.__name__)
data_ref.is_dirty= True # data_ref.is_dirty= True
# elif update.id.id != username: # elif update.id.id != username:
# history.put("undo") # history.put("undo")

12
ui.py
View File

@ -44,10 +44,18 @@ class SessionSettingsPanel(bpy.types.Panel):
row = box.row() row = box.row()
row.label(text="draw overlay:") row.label(text="draw overlay:")
row.prop(net_settings, "enable_draw", text="") row.prop(net_settings, "enable_draw", text="")
row = box.row()
row.label(text="clear blend:")
row.prop(net_settings, "clear_scene", text="")
row = box.row()
row = box.row() row = box.row()
row.prop(scene.session_settings, "session_mode", expand=True) row.prop(scene.session_settings, "session_mode", expand=True)
row = box.row() row = box.row()
if scene.session_settings.session_mode == 'HOST': if scene.session_settings.session_mode == 'HOST':
box = row.box() box = row.box()
@ -66,9 +74,7 @@ class SessionSettingsPanel(bpy.types.Panel):
row = box.row() row = box.row()
row.label(text="load data:") row.label(text="load data:")
row.prop(net_settings, "load_data", text="") row.prop(net_settings, "load_data", text="")
row = box.row()
row.label(text="clear scene:")
row.prop(net_settings, "clear_scene", text="")
row = layout.row() row = layout.row()
row.operator("session.join", text="CONNECT") row.operator("session.join", text="CONNECT")