feat: basic diff implementation
This commit is contained in:
@ -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
|
||||
|
@ -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
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
41
delayable.py
41
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]))
|
||||
|
||||
|
14
operators.py
14
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"}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user