feat: dependency resolve
feat: bl_datablock as a base class for all bl_implementation it allow to store uuid as a soft reference during datablock init process
This commit is contained in:
@ -41,7 +41,7 @@ def client_list_callback(scene, context):
|
||||
if cli:
|
||||
client_keys = cli.list(filter=BlUser)
|
||||
for k in client_keys:
|
||||
name = cli.get(k).buffer["name"]
|
||||
name = cli.get(uuid=k).buffer["name"]
|
||||
|
||||
name_desc = name
|
||||
if name == username:
|
||||
|
@ -2,14 +2,15 @@ import bpy
|
||||
import mathutils
|
||||
|
||||
from .. import utils
|
||||
from ..libs.replication.data import ReplicatedDatablock
|
||||
from .bl_datablock import BlDatablock
|
||||
|
||||
class BlCamera(ReplicatedDatablock):
|
||||
class BlCamera(BlDatablock):
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.icon = 'CAMERA_DATA'
|
||||
|
||||
super().__init__( *args, **kwargs)
|
||||
|
||||
|
||||
def load(self, data, target):
|
||||
utils.dump_anything.load(target, data)
|
||||
|
||||
|
@ -2,10 +2,10 @@ import bpy
|
||||
import mathutils
|
||||
|
||||
from .. import utils
|
||||
from ..libs.replication.data import ReplicatedDatablock
|
||||
from .bl_datablock import BlDatablock
|
||||
|
||||
|
||||
class BlCollection(ReplicatedDatablock):
|
||||
class BlCollection(BlDatablock):
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.icon = 'FILE_FOLDER'
|
||||
|
||||
@ -53,6 +53,16 @@ class BlCollection(ReplicatedDatablock):
|
||||
return (len(self.pointer.objects) != len(self.buffer['objects']) or
|
||||
len(self.pointer.children) != len(self.buffer['children']))
|
||||
|
||||
def resolve_dependencies(self):
|
||||
deps = []
|
||||
|
||||
for child in self.pointer.children:
|
||||
deps.append(child)
|
||||
for object in self.pointer.objects:
|
||||
deps.append(object)
|
||||
|
||||
return deps
|
||||
|
||||
bl_id = "collections"
|
||||
bl_class = bpy.types.Collection
|
||||
bl_rep_class = BlCollection
|
||||
|
@ -2,9 +2,9 @@ import bpy
|
||||
import mathutils
|
||||
|
||||
from .. import utils
|
||||
from ..libs.replication.data import ReplicatedDatablock
|
||||
from .bl_datablock import BlDatablock
|
||||
|
||||
class BlCurve(ReplicatedDatablock):
|
||||
class BlCurve(BlDatablock):
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.icon = 'CURVE_DATA'
|
||||
|
||||
@ -49,6 +49,7 @@ class BlCurve(ReplicatedDatablock):
|
||||
|
||||
def diff(self):
|
||||
return False
|
||||
|
||||
bl_id = "curves"
|
||||
bl_class = bpy.types.Curve
|
||||
bl_rep_class = BlCurve
|
||||
|
12
bl_types/bl_datablock.py
Normal file
12
bl_types/bl_datablock.py
Normal file
@ -0,0 +1,12 @@
|
||||
import bpy
|
||||
import mathutils
|
||||
|
||||
from .. import utils
|
||||
from ..libs.replication.data import ReplicatedDatablock
|
||||
|
||||
class BlDatablock(ReplicatedDatablock):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__( *args, **kwargs)
|
||||
|
||||
if self.pointer and hasattr(self.pointer,'uuid'):
|
||||
self.pointer.uuid = self.uuid
|
@ -2,7 +2,7 @@ import bpy
|
||||
import mathutils
|
||||
|
||||
from .. import utils
|
||||
from ..libs.replication.data import ReplicatedDatablock
|
||||
from .bl_datablock import BlDatablock
|
||||
|
||||
def load_gpencil_layer(target=None, data=None, create=False):
|
||||
|
||||
@ -30,7 +30,7 @@ def load_gpencil_layer(target=None, data=None, create=False):
|
||||
|
||||
utils.dump_anything.load(tpoint, p)
|
||||
|
||||
class BlGpencil(ReplicatedDatablock):
|
||||
class BlGpencil(BlDatablock):
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.icon = 'GREASEPENCIL'
|
||||
|
||||
|
@ -3,7 +3,7 @@ import mathutils
|
||||
import os
|
||||
|
||||
from .. import utils, environment
|
||||
from ..libs.replication.data import ReplicatedDatablock
|
||||
from .bl_datablock import BlDatablock
|
||||
|
||||
def dump_image(image):
|
||||
pixels = None
|
||||
@ -23,7 +23,7 @@ def dump_image(image):
|
||||
print("Image format not supported ")
|
||||
return pixels
|
||||
|
||||
class BlImage(ReplicatedDatablock):
|
||||
class BlImage(BlDatablock):
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.icon = 'IMAGE_DATA'
|
||||
|
||||
|
@ -2,9 +2,9 @@ import bpy
|
||||
import mathutils
|
||||
|
||||
from .. import utils
|
||||
from ..libs.replication.data import ReplicatedDatablock
|
||||
from .bl_datablock import BlDatablock
|
||||
|
||||
class BlLight(ReplicatedDatablock):
|
||||
class BlLight(BlDatablock):
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.icon = 'LIGHT_DATA'
|
||||
|
||||
@ -28,6 +28,7 @@ class BlLight(ReplicatedDatablock):
|
||||
|
||||
def diff(self):
|
||||
return False
|
||||
|
||||
bl_id = "lights"
|
||||
bl_class = bpy.types.Light
|
||||
bl_rep_class = BlLight
|
||||
|
@ -2,9 +2,9 @@ import bpy
|
||||
import mathutils
|
||||
|
||||
from .. import utils
|
||||
from ..libs.replication.data import ReplicatedDatablock
|
||||
from .bl_datablock import BlDatablock
|
||||
|
||||
class BlMaterial(ReplicatedDatablock):
|
||||
class BlMaterial(BlDatablock):
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.icon = 'MATERIAL_DATA'
|
||||
|
||||
|
@ -3,7 +3,7 @@ import bmesh
|
||||
import mathutils
|
||||
|
||||
from .. import utils
|
||||
from ..libs.replication.data import ReplicatedDatablock
|
||||
from .bl_datablock import BlDatablock
|
||||
|
||||
def dump_mesh(mesh, data={}):
|
||||
import bmesh
|
||||
@ -70,7 +70,7 @@ def dump_mesh(mesh, data={}):
|
||||
mesh_data["uv_layers"] = uv_layers
|
||||
return mesh_data
|
||||
|
||||
class BlMesh(ReplicatedDatablock):
|
||||
class BlMesh(BlDatablock):
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.icon = 'MESH_DATA'
|
||||
|
||||
@ -166,6 +166,14 @@ class BlMesh(ReplicatedDatablock):
|
||||
def diff(self):
|
||||
return len(self.pointer.vertices) != len(self.buffer['verts'])
|
||||
|
||||
def resolve_dependencies(self):
|
||||
deps = []
|
||||
|
||||
for material in self.pointer.materials:
|
||||
deps.append(material)
|
||||
|
||||
return deps
|
||||
|
||||
bl_id = "meshes"
|
||||
bl_class = bpy.types.Mesh
|
||||
bl_rep_class = BlMesh
|
||||
|
@ -2,9 +2,9 @@ import bpy
|
||||
import mathutils
|
||||
|
||||
from .. import utils
|
||||
from ..libs.replication.data import ReplicatedDatablock
|
||||
from .bl_datablock import BlDatablock
|
||||
|
||||
class BlObject(ReplicatedDatablock):
|
||||
class BlObject(BlDatablock):
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.icon = 'OBJECT_DATA'
|
||||
|
||||
@ -69,6 +69,12 @@ class BlObject(ReplicatedDatablock):
|
||||
def diff(self):
|
||||
return self.dump(pointer=self.pointer)['matrix_world'] != self.buffer['matrix_world']
|
||||
|
||||
def resolve_dependencies(self):
|
||||
deps = []
|
||||
|
||||
deps.append(self.pointer.data)
|
||||
|
||||
return deps
|
||||
bl_id = "objects"
|
||||
bl_class = bpy.types.Object
|
||||
bl_rep_class = BlObject
|
||||
|
@ -2,9 +2,9 @@ import bpy
|
||||
import mathutils
|
||||
|
||||
from .. import utils
|
||||
from ..libs.replication.data import ReplicatedDatablock
|
||||
from .bl_datablock import BlDatablock
|
||||
|
||||
class BlScene(ReplicatedDatablock):
|
||||
class BlScene(BlDatablock):
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.icon = 'SCENE_DATA'
|
||||
|
||||
@ -59,6 +59,16 @@ class BlScene(ReplicatedDatablock):
|
||||
return (len(self.pointer.collection.objects) != len(self.buffer['collection']['objects']) or
|
||||
len(self.pointer.collection.children) != len(self.buffer['collection']['children']))
|
||||
|
||||
def resolve_dependencies(self):
|
||||
deps = []
|
||||
|
||||
for child in self.pointer.collection.children:
|
||||
deps.append(child)
|
||||
for object in self.pointer.objects:
|
||||
deps.append(object)
|
||||
|
||||
return deps
|
||||
|
||||
bl_id = "scenes"
|
||||
bl_class = bpy.types.Scene
|
||||
bl_rep_class = BlScene
|
||||
|
@ -3,13 +3,13 @@ import mathutils
|
||||
|
||||
from .. import utils
|
||||
from .. import presence
|
||||
from ..libs.replication.data import ReplicatedDatablock
|
||||
from .bl_datablock import BlDatablock
|
||||
from ..libs.replication.constants import UP
|
||||
from ..libs.debug import draw_point
|
||||
|
||||
|
||||
|
||||
class BlUser(ReplicatedDatablock):
|
||||
class BlUser(BlDatablock):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__( *args, **kwargs)
|
||||
|
||||
|
@ -58,13 +58,15 @@ class ApplyTimer(Timer):
|
||||
nodes = operators.client.list(filter=self._type)
|
||||
|
||||
for node in nodes:
|
||||
node_ref = operators.client.get(node)
|
||||
node_ref = operators.client.get(uuid=node)
|
||||
|
||||
if node_ref.state == FETCHED:
|
||||
operators.client.apply(uuid=node)
|
||||
|
||||
return self._timeout
|
||||
|
||||
# class CheckNewTimer(Timer):
|
||||
|
||||
|
||||
class Draw(Delayable):
|
||||
def __init__(self):
|
||||
@ -93,7 +95,7 @@ class ClientUpdate(Draw):
|
||||
|
||||
def execute(self):
|
||||
if hasattr(operators, "client") and self._client_uuid:
|
||||
client = operators.client.get(self._client_uuid)
|
||||
client = operators.client.get(uuid=self._client_uuid)
|
||||
|
||||
if client:
|
||||
client.pointer.update_location()
|
||||
|
Submodule libs/replication updated: 74f02af8be...200821a512
31
operators.py
31
operators.py
@ -29,30 +29,8 @@ ui_context = None
|
||||
|
||||
def add_datablock(datablock):
|
||||
global client
|
||||
child = []
|
||||
|
||||
if hasattr(datablock, "data"):
|
||||
child.append(add_datablock(datablock.data))
|
||||
if hasattr(datablock, "materials"):
|
||||
for mat in datablock.materials:
|
||||
child.append(add_datablock(mat))
|
||||
if hasattr(datablock, "collection") \
|
||||
and hasattr(datablock.collection, "children"):
|
||||
for coll in datablock.collection.children:
|
||||
child.append(add_datablock(coll))
|
||||
if hasattr(datablock, "children"):
|
||||
for coll in datablock.children:
|
||||
child.append(add_datablock(coll))
|
||||
if hasattr(datablock, "objects"):
|
||||
for obj in datablock.objects:
|
||||
child.append(add_datablock(obj))
|
||||
if hasattr(datablock, 'uuid') \
|
||||
and datablock.uuid \
|
||||
and client.exist(datablock.uuid):
|
||||
return datablock.uuid
|
||||
else:
|
||||
new_uuid = client.add(datablock, dependencies=child)
|
||||
datablock.uuid = new_uuid
|
||||
new_uuid = client.add(datablock)
|
||||
return new_uuid
|
||||
|
||||
|
||||
@ -63,7 +41,10 @@ def init_supported_datablocks(supported_types_id):
|
||||
for type_id in supported_types_id:
|
||||
if hasattr(bpy.data, type_id):
|
||||
for item in getattr(bpy.data, type_id):
|
||||
add_datablock(item)
|
||||
if client.exist(uuid=item.uuid):
|
||||
continue
|
||||
else:
|
||||
client.add(item)
|
||||
|
||||
|
||||
# OPERATORS
|
||||
@ -247,7 +228,7 @@ class SessionSnapUserOperator(bpy.types.Operator):
|
||||
area, region, rv3d = presence.view3d_find()
|
||||
global client
|
||||
|
||||
target_client = client.get(self.target_client)
|
||||
target_client = client.get(uuid=self.target_client)
|
||||
if target_client:
|
||||
rv3d.view_location = target_client.buffer['location'][0]
|
||||
rv3d.view_distance = 30.0
|
||||
|
16
ui.py
16
ui.py
@ -4,12 +4,12 @@ from .libs.replication.constants import FETCHED, ERROR
|
||||
from .bl_types.bl_user import BlUser
|
||||
|
||||
|
||||
PROP_STATES = ['KEYTYPE_BREAKDOWN_VEC',
|
||||
'KEYTYPE_BREAKDOWN_VEC',
|
||||
'KEYTYPE_KEYFRAME_VEC',
|
||||
'KEYTYPE_KEYFRAME_VEC',
|
||||
'KEYTYPE_JITTER_VEC',
|
||||
'KEYTYPE_KEYFRAME_VEC']
|
||||
PROP_STATES = ['KEYTYPE_EXTREME_VEC', # ADDED
|
||||
'KEYTYPE_BREAKDOWN_VEC', # COMMITED
|
||||
'KEYTYPE_KEYFRAME_VEC', # PUSHED
|
||||
'KEYTYPE_KEYFRAME_VEC', # FETCHED
|
||||
'KEYTYPE_JITTER_VEC', # UP
|
||||
'KEYTYPE_KEYFRAME_VEC'] # CHANGED
|
||||
|
||||
|
||||
class SESSION_PT_settings(bpy.types.Panel):
|
||||
@ -163,7 +163,7 @@ class SESSION_PT_user(bpy.types.Panel):
|
||||
for key in client_keys:
|
||||
area_msg = col.row(align=True)
|
||||
item_box = area_msg.box()
|
||||
client = operators.client.get(key).buffer
|
||||
client = operators.client.get(uuid=key).buffer
|
||||
|
||||
info = ""
|
||||
|
||||
@ -193,7 +193,7 @@ class SESSION_PT_user(bpy.types.Panel):
|
||||
|
||||
def draw_property(context, parent, property_uuid, level=0):
|
||||
settings = context.window_manager.session
|
||||
item = operators.client.get(property_uuid)
|
||||
item = operators.client.get(uuid=property_uuid)
|
||||
|
||||
if item.str_type == 'BlUser' or item.state == ERROR:
|
||||
return
|
||||
|
Reference in New Issue
Block a user