diff --git a/bl_types/bl_camera.py b/bl_types/bl_camera.py index 775ee62..0eb0cba 100644 --- a/bl_types/bl_camera.py +++ b/bl_types/bl_camera.py @@ -28,4 +28,5 @@ class BlCamera(ReplicatedDatablock): bl_id = "cameras" bl_class = bpy.types.Camera bl_rep_class = BlCamera - +bl_delay_refresh = 1 +bl_delay_apply = 1 diff --git a/bl_types/bl_collection.py b/bl_types/bl_collection.py index 3edc2f5..8395232 100644 --- a/bl_types/bl_collection.py +++ b/bl_types/bl_collection.py @@ -48,7 +48,13 @@ class BlCollection(ReplicatedDatablock): def resolve(self): assert(self.buffer) self.pointer = bpy.data.collections.get(self.buffer['name']) + + def diff(self): + return (len(self.pointer.objects) != self.buffer['objects'] or + len(self.pointer.collection.children) != self.buffer['collection']['children']) bl_id = "collections" bl_class = bpy.types.Collection bl_rep_class = BlCollection +bl_delay_refresh = 1 +bl_delay_apply = 1 \ No newline at end of file diff --git a/bl_types/bl_curve.py b/bl_types/bl_curve.py index 4febd0f..26919e6 100644 --- a/bl_types/bl_curve.py +++ b/bl_types/bl_curve.py @@ -50,4 +50,5 @@ class BlCurve(ReplicatedDatablock): bl_id = "curves" bl_class = bpy.types.Curve bl_rep_class = BlCurve - +bl_delay_refresh = 1 +bl_delay_apply = 1 diff --git a/bl_types/bl_gpencil.py b/bl_types/bl_gpencil.py index f8127df..2d79275 100644 --- a/bl_types/bl_gpencil.py +++ b/bl_types/bl_gpencil.py @@ -75,4 +75,5 @@ class BlGpencil(ReplicatedDatablock): bl_id = "grease_pencils" bl_class = bpy.types.GreasePencil bl_rep_class = BlGpencil - +bl_delay_refresh = 5 +bl_delay_apply = 5 diff --git a/bl_types/bl_image.py b/bl_types/bl_image.py index 12823ef..5bf6958 100644 --- a/bl_types/bl_image.py +++ b/bl_types/bl_image.py @@ -69,4 +69,5 @@ class BlImage(ReplicatedDatablock): bl_id = "images" bl_class = bpy.types.Image bl_rep_class = BlImage - +bl_delay_refresh = 0 +bl_delay_apply = 0 diff --git a/bl_types/bl_light.py b/bl_types/bl_light.py index f13a290..5005945 100644 --- a/bl_types/bl_light.py +++ b/bl_types/bl_light.py @@ -29,4 +29,5 @@ class BlLight(ReplicatedDatablock): bl_id = "lights" bl_class = bpy.types.Light bl_rep_class = BlLight - +bl_delay_refresh = 1 +bl_delay_apply = 1 diff --git a/bl_types/bl_material.py b/bl_types/bl_material.py index 35b7f89..b95a812 100644 --- a/bl_types/bl_material.py +++ b/bl_types/bl_material.py @@ -80,7 +80,10 @@ class BlMaterial(ReplicatedDatablock): assert(self.buffer) self.pointer = bpy.data.materials.get(self.buffer['name']) + def diff(self): + return len(self.pointer.node_tree.links) != len(self.buffer['node_tree']['links']) bl_id = "materials" bl_class = bpy.types.Material bl_rep_class = BlMaterial - +bl_delay_refresh = 1 +bl_delay_apply = 1 diff --git a/bl_types/bl_mesh.py b/bl_types/bl_mesh.py index 039c8b2..30a129c 100644 --- a/bl_types/bl_mesh.py +++ b/bl_types/bl_mesh.py @@ -163,7 +163,11 @@ class BlMesh(ReplicatedDatablock): assert(self.buffer) self.pointer = bpy.data.meshes.get(self.buffer['name']) + def diff(self): + return len(self.pointer.vertices) != self.buffer['verts'] + bl_id = "meshes" bl_class = bpy.types.Mesh bl_rep_class = BlMesh - +bl_delay_refresh = 10 +bl_delay_apply = 10 diff --git a/bl_types/bl_object.py b/bl_types/bl_object.py index 2c1e596..1b52411 100644 --- a/bl_types/bl_object.py +++ b/bl_types/bl_object.py @@ -72,4 +72,5 @@ class BlObject(ReplicatedDatablock): bl_id = "objects" bl_class = bpy.types.Object bl_rep_class = BlObject - +bl_delay_refresh = 1 +bl_delay_apply = 1 diff --git a/bl_types/bl_scene.py b/bl_types/bl_scene.py index 8dc6f8b..fe6ecda 100644 --- a/bl_types/bl_scene.py +++ b/bl_types/bl_scene.py @@ -54,8 +54,13 @@ class BlScene(ReplicatedDatablock): scene_name = self.buffer['name'] self.pointer = bpy.data.scenes.get(scene_name) + + def diff(self): + return (len(self.pointer.collection.objects) != self.buffer['collection']['objects'] or + len(self.pointer.collection.children) != self.buffer['collection']['children']) bl_id = "scenes" bl_class = bpy.types.Scene bl_rep_class = BlScene - +bl_delay_refresh = 1 +bl_delay_apply = 1 diff --git a/bl_types/bl_user.py b/bl_types/bl_user.py index b748436..fd9aaa1 100644 --- a/bl_types/bl_user.py +++ b/bl_types/bl_user.py @@ -54,4 +54,5 @@ class BlUser(ReplicatedDatablock): bl_id = "users" bl_class = presence.User bl_rep_class = BlUser - +bl_delay_refresh = 1 +bl_delay_apply = 1 diff --git a/delayable.py b/delayable.py index eade3a2..eaee3c8 100644 --- a/delayable.py +++ b/delayable.py @@ -5,6 +5,8 @@ from . import operators, utils from .bl_types.bl_user import BlUser class Delayable(): + """Delayable task interface + """ def register(self): raise NotImplementedError @@ -88,42 +90,3 @@ class ClientUpdate(Draw): if client: client.pointer.update_location() - -class DrawClients(Draw): - def __init__(self): - super().__init__() - self._camera_lines = [] - - def execute(self): - if operators.client: - users = operators.client.list(filter=BlUser) - try: - self.clear_camera() - except: - pass - - for u in users: - cli = operators.client.get(u) - if cli: - loc = cli.buffer['location'] - self.draw_camera(loc) - - def clear_camera(self): - for line in self._camera_lines: - line.clear() - - self._camera_lines.clear() - - def draw_camera(self, loc): - self._camera_lines.append(debug.draw_line(a=loc[0],b=loc[2])) - self._camera_lines.append(debug.draw_line(a=loc[1],b=loc[2])) - self._camera_lines.append(debug.draw_line(a=loc[3],b=loc[1])) - self._camera_lines.append(debug.draw_line(a=loc[3],b=loc[0])) - - self._camera_lines.append(debug.draw_line(a=loc[0],b=loc[6])) - self._camera_lines.append(debug.draw_line(a=loc[1],b=loc[6])) - self._camera_lines.append(debug.draw_line(a=loc[2],b=loc[6])) - self._camera_lines.append(debug.draw_line(a=loc[3],b=loc[6])) - - self._camera_lines.append(debug.draw_line(a=loc[4],b=loc[5])) - diff --git a/operators.py b/operators.py index 2a097f3..9b5e6b0 100644 --- a/operators.py +++ b/operators.py @@ -93,12 +93,11 @@ class SessionStartOperator(bpy.types.Operator): _type = getattr(bl_types, type) supported_bl_types.append(_type.bl_id) - if _type.bl_id == 'users':#For testing - bpy_factory.register_type(_type.bl_class, _type.bl_rep_class, timer=0.1,automatic=True) - delayables.append(delayable.ApplyTimer(timout=0.1,target_type=_type.bl_rep_class)) - else: - bpy_factory.register_type(_type.bl_class, _type.bl_rep_class) - + bpy_factory.register_type(_type.bl_class, _type.bl_rep_class, timer=_type.bl_delay_refresh,automatic=True) + + if _type.bl_delay_apply > 0: + delayables.append(delayable.ApplyTimer(timout=_type.bl_delay_apply,target_type=_type.bl_rep_class)) + client = Client(factory=bpy_factory) if self.host: @@ -126,8 +125,8 @@ class SessionStartOperator(bpy.types.Operator): ) settings.user_uuid = client.add(usr) - # delayables.append(delayable.DrawClients()) delayables.append(delayable.ClientUpdate(client_uuid=settings.user_uuid)) + # Push all added values client.push() @@ -137,6 +136,7 @@ class SessionStartOperator(bpy.types.Operator): for d in delayables: d.register() + return {"FINISHED"}