fix: get datablock to mark it dirty
This commit is contained in:
14
client.py
14
client.py
@ -487,13 +487,19 @@ def serial_worker(product, feed):
|
||||
if command == 'STOP':
|
||||
break
|
||||
elif command == 'DUMP':
|
||||
try:
|
||||
value = helpers.dump(key)
|
||||
|
||||
if value:
|
||||
product.put((key,value))
|
||||
except Exception as e:
|
||||
logger.error("{}".format(e))
|
||||
elif command == 'LOAD':
|
||||
if value:
|
||||
try:
|
||||
helpers.load(key, value)
|
||||
except Exception as e:
|
||||
logger.error("{}".format(e))
|
||||
|
||||
logger.info("serial thread stopped")
|
||||
|
||||
@ -508,10 +514,10 @@ def watchdog_worker(feed,interval, stop_event):
|
||||
for item in getattr(bpy.data, helpers.CORRESPONDANCE[datatype]):
|
||||
key = "{}/{}".format(datatype, item.name)
|
||||
try:
|
||||
if item.id == 'None':
|
||||
item.id = bpy.context.scene.session_settings.username
|
||||
feed.put(('DUMP',key,None))
|
||||
elif item.is_dirty:
|
||||
# if item.id == 'None':
|
||||
# item.id = bpy.context.scene.session_settings.username
|
||||
# feed.put(('DUMP',key,None))
|
||||
if item.is_dirty:
|
||||
logger.info("{} needs update".format(item.name))
|
||||
feed.put(('DUMP',key,None))
|
||||
item.is_dirty = False
|
||||
|
13
helpers.py
13
helpers.py
@ -227,12 +227,14 @@ def load_mesh(target=None, data=None, create=False):
|
||||
material_to_load = []
|
||||
material_to_load = revers(data["materials"])
|
||||
|
||||
|
||||
target.materials.clear()
|
||||
# SLots
|
||||
i = 0
|
||||
while len(material_to_load) > len(target.materials):
|
||||
target.materials.append(bpy.data.materials[material_to_load[i]])
|
||||
i+=1
|
||||
|
||||
for m in data["material_list"]:
|
||||
target.materials.append(bpy.data.materials[m])
|
||||
|
||||
|
||||
|
||||
target.id = data['id']
|
||||
@ -481,6 +483,11 @@ def dump(key):
|
||||
data = dump_datablock(target, 2)
|
||||
dump_datablock_attibute(
|
||||
target, ['name', 'polygons', 'edges', 'vertices', 'id'], 6,data)
|
||||
m_list = []
|
||||
for m in target.materials:
|
||||
m_list.append(m.name)
|
||||
|
||||
data['material_list'] = m_list
|
||||
|
||||
elif target_type == 'Object':
|
||||
data = dump_datablock(target, 1)
|
||||
|
36
operators.py
36
operators.py
@ -30,12 +30,11 @@ update_list = {}
|
||||
|
||||
SUPPORTED_DATABLOCKS = ['collections','armatures', 'meshes', 'objects',
|
||||
'materials', 'textures', 'lights', 'cameras', 'actions', 'grease_pencils']
|
||||
|
||||
SUPPORTED_TYPES = [ 'Armature', 'Material',
|
||||
'Texture', 'Light', 'Camera', 'Mesh', 'Grease Pencil', 'Object', 'Action', 'Collection', 'Scene']
|
||||
|
||||
# UTILITY FUNCTIONS
|
||||
|
||||
|
||||
def client_list_callback(scene, context):
|
||||
global client_keys
|
||||
|
||||
@ -494,6 +493,24 @@ def exist(update):
|
||||
else:
|
||||
return False
|
||||
|
||||
def get_datablock(update,context):
|
||||
|
||||
item_type = update.id.__class__.__name__
|
||||
item_id = update.id.name
|
||||
|
||||
datablock_ref = None
|
||||
|
||||
if item_id == 'Master Collection':
|
||||
Adatablock_ref= bpy.context.scene
|
||||
elif item_type in helpers.CORRESPONDANCE.keys():
|
||||
datablock_ref = getattr(bpy.data, helpers.CORRESPONDANCE[update.id.__class__.__name__])[update.id.name]
|
||||
else:
|
||||
if item_id in bpy.data.lights.keys():
|
||||
datablock_ref = bpy.data.lights[item_id]
|
||||
|
||||
|
||||
return datablock_ref
|
||||
|
||||
|
||||
def depsgraph_update(scene):
|
||||
global client_instance
|
||||
@ -508,15 +525,14 @@ def depsgraph_update(scene):
|
||||
update_selected_object(bpy.context)
|
||||
|
||||
selected_objects = helpers.get_selected_objects(scene)
|
||||
# if len(selected_objects) > 0:
|
||||
# for updated_data in updates:
|
||||
# if updated_data.id.name in selected_objects:
|
||||
# if updated_data.is_updated_transform or updated_data.is_updated_geometry:
|
||||
# client_instance.set(
|
||||
# "{}/{}".format(updated_data.id.bl_rna.name, updated_data.id.name))
|
||||
|
||||
for update in reversed(updates):
|
||||
if update.id.id == username:
|
||||
getattr(bpy.data, helpers.CORRESPONDANCE[update.id.__class__.__name__])[update.id.name].is_dirty= True
|
||||
if update.id.id == username or update.id.id == 'None':
|
||||
# TODO: handle errors
|
||||
data_ref = get_datablock(update,context)
|
||||
|
||||
if data_ref:
|
||||
data_ref.is_dirty= True
|
||||
|
||||
|
||||
def register():
|
||||
|
Reference in New Issue
Block a user