feat: added construct method to each implementation
This commit is contained in:
parent
38c5e9352d
commit
fa081d3cbe
@ -11,11 +11,10 @@ class BlCamera(ReplicatedDatablock):
|
||||
super().__init__( *args, **kwargs)
|
||||
|
||||
def load(self, data, target):
|
||||
if target is None:
|
||||
target = bpy.data.cameras.new(data["name"])
|
||||
|
||||
utils.dump_anything.load(target, data)
|
||||
|
||||
def construct(self, data):
|
||||
return bpy.data.cameras.new(data["name"])
|
||||
|
||||
def dump(self, pointer=None):
|
||||
assert(pointer)
|
||||
|
@ -10,12 +10,11 @@ class BlCollection(ReplicatedDatablock):
|
||||
self.icon = 'FILE_FOLDER'
|
||||
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def construct(self,data):
|
||||
return bpy.data.collections.new(data["name"])
|
||||
|
||||
def load(self, data, target):
|
||||
|
||||
if target is None:
|
||||
target = bpy.data.collections.new(data["name"])
|
||||
|
||||
# Load other meshes metadata
|
||||
# dump_anything.load(target, data)
|
||||
|
||||
|
@ -9,11 +9,11 @@ class BlCurve(ReplicatedDatablock):
|
||||
self.icon = 'CURVE_DATA'
|
||||
|
||||
super().__init__( *args, **kwargs)
|
||||
|
||||
def load(self, data, target):
|
||||
if target is None:
|
||||
target = bpy.data.curves.new(data["name"], 'CURVE')
|
||||
|
||||
def construct(self, data):
|
||||
return bpy.data.curves.new(data["name"], 'CURVE')
|
||||
|
||||
def load(self, data, target):
|
||||
utils.dump_anything.load(target, data)
|
||||
|
||||
target.splines.clear()
|
||||
|
@ -35,11 +35,11 @@ class BlGpencil(ReplicatedDatablock):
|
||||
self.icon = 'GREASEPENCIL'
|
||||
|
||||
super().__init__( *args, **kwargs)
|
||||
|
||||
|
||||
def construct(self,data):
|
||||
return bpy.data.grease_pencils.new(data["name"])
|
||||
|
||||
def load(self, data, target):
|
||||
if target is None:
|
||||
target = bpy.data.grease_pencils.new(data["name"])
|
||||
|
||||
for layer in target.layers:
|
||||
target.layers.remove(layer)
|
||||
|
||||
|
@ -10,16 +10,16 @@ class BlImage(ReplicatedDatablock):
|
||||
self.icon = 'IMAGE_DATA'
|
||||
|
||||
super().__init__( *args, **kwargs)
|
||||
|
||||
def load(self, data, target):
|
||||
if not target:
|
||||
image = bpy.data.images.new(
|
||||
|
||||
def construct(self, data):
|
||||
return bpy.data.images.new(
|
||||
name=data['name'],
|
||||
width=data['size'][0],
|
||||
height=data['size'][1]
|
||||
)
|
||||
else:
|
||||
image = target
|
||||
|
||||
def load(self, data, target):
|
||||
image = target
|
||||
|
||||
img_name = "{}.png".format(image.name)
|
||||
|
||||
|
@ -9,11 +9,11 @@ class BlLight(ReplicatedDatablock):
|
||||
self.icon = 'LIGHT_DATA'
|
||||
|
||||
super().__init__( *args, **kwargs)
|
||||
|
||||
|
||||
def construct(self, data):
|
||||
return bpy.data.lights.new(data["name"], data["type"])
|
||||
|
||||
def load(self, data, target):
|
||||
if target is None:
|
||||
target = bpy.data.lights.new(data["name"], data["type"])
|
||||
|
||||
utils.dump_anything.load(target, data)
|
||||
|
||||
|
||||
|
@ -10,10 +10,10 @@ class BlMaterial(ReplicatedDatablock):
|
||||
|
||||
super().__init__( *args, **kwargs)
|
||||
|
||||
def load(self, data, target):
|
||||
if target is None:
|
||||
target = bpy.data.materials.new(data["name"])
|
||||
def construct(self, data):
|
||||
return bpy.data.materials.new(data["name"])
|
||||
|
||||
def load(self, data, target):
|
||||
if data['is_grease_pencil']:
|
||||
if not target.is_grease_pencil:
|
||||
bpy.data.materials.create_gpencil_data(target)
|
||||
@ -66,7 +66,6 @@ class BlMaterial(ReplicatedDatablock):
|
||||
|
||||
target.node_tree.links.new(input_socket, output_socket)
|
||||
|
||||
|
||||
def dump(self, pointer=None):
|
||||
assert(pointer)
|
||||
data = utils.dump_datablock(pointer, 2)
|
||||
|
@ -75,7 +75,10 @@ class BlMesh(ReplicatedDatablock):
|
||||
self.icon = 'MESH_DATA'
|
||||
|
||||
super().__init__( *args, **kwargs)
|
||||
|
||||
|
||||
def construct(self, data):
|
||||
return bpy.data.meshes.new(data["name"])
|
||||
|
||||
def load(self, data, target):
|
||||
if not target or not target.is_editmode:
|
||||
# 1 - LOAD GEOMETRY
|
||||
@ -109,9 +112,7 @@ class BlMesh(ReplicatedDatablock):
|
||||
loop_uv = loop[uv_layer]
|
||||
loop_uv.uv = data["faces"][p]["uv"][i]
|
||||
|
||||
if target is None:
|
||||
target = bpy.data.meshes.new(data["name"])
|
||||
|
||||
|
||||
mesh_buffer.to_mesh(target)
|
||||
|
||||
# mesh_buffer.from_mesh(target)
|
||||
|
@ -9,29 +9,29 @@ class BlObject(ReplicatedDatablock):
|
||||
self.icon = 'OBJECT_DATA'
|
||||
|
||||
super().__init__( *args, **kwargs)
|
||||
|
||||
|
||||
def construct(self, data):
|
||||
pointer = None
|
||||
|
||||
# Object specific constructor...
|
||||
if data["data"] in bpy.data.meshes.keys():
|
||||
pointer = bpy.data.meshes[data["data"]]
|
||||
elif data["data"] in bpy.data.lights.keys():
|
||||
pointer = bpy.data.lights[data["data"]]
|
||||
elif data["data"] in bpy.data.cameras.keys():
|
||||
pointer = bpy.data.cameras[data["data"]]
|
||||
elif data["data"] in bpy.data.curves.keys():
|
||||
pointer = bpy.data.curves[data["data"]]
|
||||
elif data["data"] in bpy.data.armatures.keys():
|
||||
pointer = bpy.data.armatures[data["data"]]
|
||||
elif data["data"] in bpy.data.grease_pencils.keys():
|
||||
pointer = bpy.data.grease_pencils[data["data"]]
|
||||
elif data["data"] in bpy.data.curves.keys():
|
||||
pointer = bpy.data.curves[data["data"]]
|
||||
|
||||
return bpy.data.objects.new(data["name"], pointer)
|
||||
|
||||
def load(self, data, target):
|
||||
if target is None:
|
||||
pointer = None
|
||||
|
||||
# Object specific constructor...
|
||||
if data["data"] in bpy.data.meshes.keys():
|
||||
pointer = bpy.data.meshes[data["data"]]
|
||||
elif data["data"] in bpy.data.lights.keys():
|
||||
pointer = bpy.data.lights[data["data"]]
|
||||
elif data["data"] in bpy.data.cameras.keys():
|
||||
pointer = bpy.data.cameras[data["data"]]
|
||||
elif data["data"] in bpy.data.curves.keys():
|
||||
pointer = bpy.data.curves[data["data"]]
|
||||
elif data["data"] in bpy.data.armatures.keys():
|
||||
pointer = bpy.data.armatures[data["data"]]
|
||||
elif data["data"] in bpy.data.grease_pencils.keys():
|
||||
pointer = bpy.data.grease_pencils[data["data"]]
|
||||
elif data["data"] in bpy.data.curves.keys():
|
||||
pointer = bpy.data.curves[data["data"]]
|
||||
|
||||
target = bpy.data.objects.new(data["name"], pointer)
|
||||
|
||||
# Load other meshes metadata
|
||||
# dump_anything.load(target, data)
|
||||
|
||||
@ -67,7 +67,7 @@ class BlObject(ReplicatedDatablock):
|
||||
self.pointer = bpy.data.objects.get(object_name)
|
||||
|
||||
def diff(self):
|
||||
return self.pointer.location != self.buffer['location']
|
||||
return self.dump(pointer=self.pointer)['location'] != self.buffer['location']
|
||||
|
||||
bl_id = "objects"
|
||||
bl_class = bpy.types.Object
|
||||
|
@ -9,11 +9,12 @@ class BlScene(ReplicatedDatablock):
|
||||
self.icon = 'SCENE_DATA'
|
||||
|
||||
super().__init__( *args, **kwargs)
|
||||
|
||||
def load(self, data, target):
|
||||
if target is None:
|
||||
target = bpy.data.scenes.new(data["name"])
|
||||
|
||||
def construct(self, data):
|
||||
return bpy.data.scenes.new(data["name"])
|
||||
|
||||
def load(self, data, target):
|
||||
target = self.pointer
|
||||
# Load other meshes metadata
|
||||
utils.dump_anything.load(target, data)
|
||||
|
||||
|
@ -15,10 +15,10 @@ class BlUser(ReplicatedDatablock):
|
||||
if self.buffer:
|
||||
self.load(self.buffer, self.pointer)
|
||||
|
||||
def load(self, data, target):
|
||||
if target is None:
|
||||
target = User()
|
||||
|
||||
def construct(self, name):
|
||||
return User()
|
||||
|
||||
def load(self, data, target):
|
||||
target.name = data['name']
|
||||
|
||||
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 6cf163da862aa54cf22257bd2cb46b9953afb349
|
||||
Subproject commit 673844e476235e4944549d0708c144f3afc630b3
|
@ -149,7 +149,7 @@ class SessionStartOperator(bpy.types.Operator):
|
||||
supported_bl_types.append(_type.bl_id)
|
||||
|
||||
if _type.bl_id == 'objects':#For testing
|
||||
bpy_factory.register_type(_type.bl_class, _type.bl_rep_class, timer=2,automatic=False)
|
||||
bpy_factory.register_type(_type.bl_class, _type.bl_rep_class, timer=2,automatic=True)
|
||||
else:
|
||||
bpy_factory.register_type(_type.bl_class, _type.bl_rep_class)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user