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