multi-user/helpers.py

632 lines
20 KiB
Python
Raw Normal View History

2019-05-02 17:58:37 +02:00
import logging
import sys
2019-04-19 15:46:54 +02:00
from uuid import uuid4
2019-05-03 16:20:40 +02:00
import json
2019-05-02 17:58:37 +02:00
import bpy
import mathutils
from . import draw
2019-05-02 17:58:37 +02:00
from .libs import dump_anything
2019-04-10 17:01:21 +02:00
# TODO: replace hardcoded values...
2019-05-27 17:33:52 +02:00
BPY_TYPES = {'Texture': 'textures','Material': 'materials', 'GreasePencil': 'grease_pencils', 'Curve': 'curves', 'Collection': 'collections', 'Mesh': 'meshes', 'Object': 'objects',
'Scene': 'scenes', 'Light': 'lights', 'SunLight': 'lights', 'SpotLight': 'lights', 'AreaLight': 'lights', 'PointLight': 'lights', 'Camera': 'cameras', 'Action': 'actions', 'Armature': 'armatures', 'Grease Pencil': 'grease_pencils'}
2019-04-11 14:39:31 +02:00
2019-04-19 15:46:54 +02:00
logger = logging.getLogger(__name__)
2019-05-14 10:38:13 +02:00
logging.basicConfig(level=logging.INFO)
2019-04-17 15:48:20 +02:00
# UTILITY FUNCTIONS
def revers(d):
l = []
for i in d:
l.append(i)
2019-05-08 17:06:52 +02:00
return l[::-1]
2019-05-02 17:58:37 +02:00
2019-05-08 17:06:52 +02:00
2019-04-11 14:39:31 +02:00
def refresh_window():
import bpy
2019-04-11 14:39:31 +02:00
bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
2019-04-10 18:01:55 +02:00
2019-05-08 17:06:52 +02:00
def get_armature_edition_context(armature):
2019-05-08 17:06:52 +02:00
2019-05-03 16:20:40 +02:00
override = {}
# Set correct area
2019-05-08 17:06:52 +02:00
for area in bpy.data.window_managers[0].windows[0].screen.areas:
if area.type == 'VIEW_3D':
2019-05-03 16:20:40 +02:00
override = bpy.context.copy()
override['area'] = area
break
# Set correct armature settings
2019-05-08 17:06:52 +02:00
override['window'] = bpy.data.window_managers[0].windows[0]
2019-05-03 16:20:40 +02:00
override['screen'] = bpy.data.window_managers[0].windows[0].screen
override['mode'] = 'EDIT_ARMATURE'
override['active_object'] = armature
override['selected_objects'] = [armature]
for o in bpy.data.objects:
if o.data == armature:
2019-05-03 16:20:40 +02:00
override['edit_object'] = o
2019-05-08 17:06:52 +02:00
break
return override
2019-04-18 15:05:48 +02:00
2019-05-08 17:06:52 +02:00
2019-04-17 16:15:21 +02:00
def get_selected_objects(scene):
2019-04-17 15:48:20 +02:00
selected_objects = []
2019-04-17 16:15:21 +02:00
for obj in scene.objects:
2019-04-17 15:48:20 +02:00
if obj.select_get():
selected_objects.append(obj.name)
2019-04-10 18:01:55 +02:00
2019-04-17 15:48:20 +02:00
return selected_objects
2019-04-18 15:05:48 +02:00
2019-05-02 17:58:37 +02:00
2019-05-14 10:38:13 +02:00
# LOAD HELPERS
2019-04-10 18:01:55 +02:00
def load(key, value):
target = resolve_bpy_path(key)
2019-04-11 14:39:31 +02:00
target_type = key.split('/')[0]
2019-04-10 18:01:55 +02:00
logger.debug("load {}".format(key))
2019-04-30 17:18:41 +02:00
if value == "None":
2019-05-02 17:58:37 +02:00
return
2019-04-10 18:01:55 +02:00
if target_type == 'Object':
load_object(target=target, data=value,
create=True)
elif target_type == 'Mesh':
load_mesh(target=target, data=value,
2019-04-18 15:05:48 +02:00
create=True)
2019-04-10 18:01:55 +02:00
elif target_type == 'Collection':
load_collection(target=target, data=value,
create=True)
elif target_type == 'Material':
load_material(target=target, data=value,
2019-04-18 15:05:48 +02:00
create=True)
2019-05-23 16:49:32 +02:00
elif target_type == 'GreasePencil':
2019-04-10 18:01:55 +02:00
load_gpencil(target=target, data=value,
2019-04-18 15:05:48 +02:00
create=True)
2019-04-10 18:01:55 +02:00
elif target_type == 'Scene':
load_scene(target=target, data=value,
2019-04-18 15:05:48 +02:00
create=True)
2019-04-10 18:01:55 +02:00
elif 'Light' in target_type:
load_light(target=target, data=value,
2019-04-18 15:05:48 +02:00
create=True)
2019-04-11 14:39:31 +02:00
elif target_type == 'Camera':
2019-04-10 18:01:55 +02:00
load_default(target=target, data=value,
2019-04-18 15:05:48 +02:00
create=True, type=target_type)
elif target_type == 'Armature':
load_armature(target=target, data=value,
2019-05-08 17:06:52 +02:00
create=True)
elif target_type == 'Curve':
load_curve(target=target, data=value,
create=True)
elif target_type == 'Client':
2019-04-18 15:05:48 +02:00
load_client(key.split('/')[1], value)
2019-04-11 14:39:31 +02:00
2019-04-10 18:01:55 +02:00
def resolve_bpy_path(path):
"""
Get bpy property value from path
"""
item = None
2019-04-10 17:01:21 +02:00
2019-04-10 18:01:55 +02:00
try:
path = path.split('/')
item = getattr(bpy.data, BPY_TYPES[path[0]])[path[1]]
2019-04-10 17:01:21 +02:00
2019-04-10 18:01:55 +02:00
except:
pass
2019-04-10 17:01:21 +02:00
2019-04-10 18:01:55 +02:00
return item
2019-04-10 17:01:21 +02:00
2019-04-17 15:48:20 +02:00
2019-04-18 15:05:48 +02:00
def load_client(client=None, data=None):
2019-04-17 16:15:21 +02:00
C = bpy.context
D = bpy.data
net_settings = C.window_manager.session
if client and data:
if net_settings.enable_draw:
draw.renderer.draw_client(data)
draw.renderer.draw_client_selected_objects(data)
2019-04-18 15:05:48 +02:00
def load_armature(target=None, data=None, create=False):
2019-05-03 16:20:40 +02:00
file = "cache_{}.json".format(data['name'])
context = bpy.context
2019-05-03 16:20:40 +02:00
if not target:
2019-05-08 17:06:52 +02:00
target = bpy.data.armatures.new(data['name'])
2019-05-03 16:20:40 +02:00
dump_anything.load(target, data)
2019-05-03 16:20:40 +02:00
with open(file, 'w') as fp:
json.dump(data, fp)
2019-05-08 17:06:52 +02:00
fp.close()
2019-05-03 16:20:40 +02:00
target.id = data['id']
else:
# Construct a correct execution context
2019-05-03 16:20:40 +02:00
file = "cache_{}.json".format(target.name)
with open(file, 'r') as fp:
data = json.load(fp)
2019-05-03 16:20:40 +02:00
if data:
ob = None
for o in bpy.data.objects:
if o.data == target:
ob = o
if ob:
bpy.context.view_layer.objects.active = ob
bpy.ops.object.mode_set(mode='EDIT', toggle=False)
for eb in data['edit_bones']:
if eb in target.edit_bones.keys():
# Update the bone
pass
else:
# Add new edit bone and load it
target_new_b = target.edit_bones.new[eb]
dump_anything.load(target_new_b, data['bones'][eb])
logger.debug(eb)
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
fp.close()
import os
os.remove(file)
2019-04-17 15:48:20 +02:00
2019-04-10 17:01:21 +02:00
def load_mesh(target=None, data=None, create=False):
import bmesh
2019-04-19 15:46:54 +02:00
if not target or not target.is_editmode:
# LOAD GEOMETRY
2019-04-19 15:46:54 +02:00
mesh_buffer = bmesh.new()
2019-04-10 17:01:21 +02:00
2019-04-19 15:46:54 +02:00
for i in data["vertices"]:
mesh_buffer.verts.new(data["vertices"][i]["co"])
2019-04-10 17:01:21 +02:00
2019-04-19 15:46:54 +02:00
mesh_buffer.verts.ensure_lookup_table()
2019-04-10 17:01:21 +02:00
2019-04-19 15:46:54 +02:00
for i in data["edges"]:
verts = mesh_buffer.verts
v1 = data["edges"][i]["vertices"][0]
v2 = data["edges"][i]["vertices"][1]
mesh_buffer.edges.new([verts[v1], verts[v2]])
2019-04-10 17:01:21 +02:00
2019-04-19 15:46:54 +02:00
for p in data["polygons"]:
verts = []
for v in data["polygons"][p]["vertices"]:
verts.append(mesh_buffer.verts[v])
2019-04-10 17:01:21 +02:00
2019-04-19 15:46:54 +02:00
if len(verts) > 0:
f = mesh_buffer.faces.new(verts)
2019-05-08 17:06:52 +02:00
f.material_index = data["polygons"][p]['material_index']
2019-04-10 17:01:21 +02:00
2019-04-19 15:46:54 +02:00
if target is None and create:
target = bpy.data.meshes.new(data["name"])
2019-04-10 17:01:21 +02:00
2019-04-19 15:46:54 +02:00
mesh_buffer.to_mesh(target)
2019-05-08 17:06:52 +02:00
# LOAD METADATA
2019-04-19 15:46:54 +02:00
dump_anything.load(target, data)
material_to_load = []
material_to_load = revers(data["materials"])
target.materials.clear()
# SLots
i = 0
2019-05-06 15:58:28 +02:00
for m in data["material_list"]:
target.materials.append(bpy.data.materials[m])
target.id = data['id']
2019-04-19 15:46:54 +02:00
else:
2019-04-29 16:39:11 +02:00
logger.debug("Mesh can't be loaded")
2019-04-10 17:01:21 +02:00
def load_object(target=None, data=None, create=False):
try:
if target is None and create:
pointer = None
2019-05-27 17:33:52 +02:00
2019-04-10 17:01:21 +02:00
# 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"]]
2019-04-10 17:01:21 +02:00
elif data["data"] in bpy.data.grease_pencils.keys():
pointer = bpy.data.grease_pencils[data["data"]]
2019-05-08 17:06:52 +02:00
elif data["data"] in bpy.data.curves.keys():
pointer = bpy.data.curves[data["data"]]
2019-04-10 17:01:21 +02:00
target = bpy.data.objects.new(data["name"], pointer)
2019-04-11 18:07:59 +02:00
# Load other meshes metadata
2019-05-10 10:17:52 +02:00
# dump_anything.load(target, data)
2019-04-18 15:05:48 +02:00
2019-04-10 17:01:21 +02:00
target.matrix_world = mathutils.Matrix(data["matrix_world"])
target.id = data['id']
2019-05-02 17:58:37 +02:00
client = bpy.context.window_manager.session.username
if target.id == client or target.id == "Common":
target.hide_select = False
else:
target.hide_select = True
2019-05-03 16:20:40 +02:00
except Exception as e:
2019-05-08 17:06:52 +02:00
logger.error("Object {} loading error: {} ".format(data["name"], e))
def load_curve(target=None, data=None, create=False):
try:
if target is None and create:
target = bpy.data.curves.new(data["name"], 'CURVE')
dump_anything.load(target, data)
target.splines.clear()
# load splines
for spline in data['splines']:
# Update existing..
# if spline in target.splines.keys():
new_spline = target.splines.new(data['splines'][spline]['type'])
dump_anything.load(new_spline, data['splines'][spline])
2019-05-13 11:49:46 +02:00
# Load curve geometry data
2019-05-08 17:06:52 +02:00
for bezier_point_index in data['splines'][spline]["bezier_points"]:
new_spline.bezier_points.add(1)
2019-05-13 11:49:46 +02:00
dump_anything.load(
new_spline.bezier_points[bezier_point_index], data['splines'][spline]["bezier_points"][bezier_point_index])
2019-05-08 17:06:52 +02:00
for point_index in data['splines'][spline]["points"]:
new_spline.points.add(1)
2019-05-13 11:49:46 +02:00
dump_anything.load(
new_spline.points[point_index], data['splines'][spline]["points"][point_index])
2019-05-08 18:18:09 +02:00
target.id = data['id']
2019-05-08 17:06:52 +02:00
except Exception as e:
logger.error("curve loading error: {}".format(e))
2019-04-10 17:01:21 +02:00
def load_collection(target=None, data=None, create=False):
try:
if target is None and create:
target = bpy.data.collections.new(data["name"])
# Load other meshes metadata
# dump_anything.load(target, data)
2019-04-26 16:14:48 +02:00
# link objects
2019-04-10 17:01:21 +02:00
for object in data["objects"]:
2019-05-10 16:22:14 +02:00
if object not in target.objects.keys():
target.objects.link(bpy.data.objects[object])
2019-04-10 17:01:21 +02:00
for object in target.objects.keys():
if object not in data["objects"]:
target.objects.unlink(bpy.data.objects[object])
2019-05-02 17:58:37 +02:00
2019-04-26 16:14:48 +02:00
# Link childrens
for collection in data["children"]:
if collection not in target.children.keys():
2019-05-27 17:33:52 +02:00
if bpy.data.collections.find(collection) == -1:
target.children.link(
bpy.data.collections[collection])
else:
logger.debug(target.name)
2019-05-27 17:33:52 +02:00
for collection in target.children.keys():
if collection not in data["children"]:
target.collection.children.unlink(
2019-04-26 16:14:48 +02:00
bpy.data.collections[collection])
2019-05-27 17:33:52 +02:00
2019-05-02 17:58:37 +02:00
target.id = data['id']
2019-05-10 15:31:23 +02:00
client = bpy.context.window_manager.session.username
2019-05-10 15:31:23 +02:00
if target.id == client or target.id == "Common":
2019-05-10 15:31:23 +02:00
target.hide_select = False
else:
target.hide_select = True
2019-05-10 16:22:14 +02:00
2019-04-26 16:14:48 +02:00
except Exception as e:
logger.error("Collection loading error: {}".format(e))
2019-04-10 17:01:21 +02:00
def load_scene(target=None, data=None, create=False):
try:
if target is None and create:
target = bpy.data.scenes.new(data["name"])
# Load other meshes metadata
dump_anything.load(target, data)
# Load master collection
for object in data["collection"]["objects"]:
if object not in target.collection.objects.keys():
target.collection.objects.link(bpy.data.objects[object])
for object in target.collection.objects.keys():
2019-04-18 15:05:48 +02:00
if object not in data["collection"]["objects"]:
2019-04-10 17:01:21 +02:00
target.collection.objects.unlink(bpy.data.objects[object])
2019-04-10 17:01:21 +02:00
# load collections
# TODO: Recursive link
logger.debug("check for scene childs")
2019-04-10 17:01:21 +02:00
for collection in data["collection"]["children"]:
2019-05-10 15:12:52 +02:00
logger.debug(collection)
2019-04-10 17:01:21 +02:00
if collection not in target.collection.children.keys():
target.collection.children.link(
bpy.data.collections[collection])
2019-04-18 15:05:48 +02:00
logger.debug("check for scene child to remove")
2019-05-10 15:12:52 +02:00
for collection in target.collection.children.keys():
if collection not in data["collection"]["children"]:
target.collection.children.unlink(
bpy.data.collections[collection])
target.id = data['id']
2019-04-10 17:01:21 +02:00
# Load annotation
2019-05-10 13:05:47 +02:00
# if data["grease_pencil"]:
# target.grease_pencil = bpy.data.grease_pencils[data["grease_pencil"]["name"]]
# else:
# target.grease_pencil = None
2019-05-10 13:01:24 +02:00
2019-05-10 15:12:52 +02:00
except Exception as e:
logger.error("Scene loading error: {}".format(e))
2019-04-10 17:01:21 +02:00
def load_material(target=None, data=None, create=False):
try:
if target is None:
2019-04-10 17:01:21 +02:00
target = bpy.data.materials.new(data["name"])
2019-05-10 17:00:47 +02:00
if data['is_grease_pencil']:
if not target.is_grease_pencil:
bpy.data.materials.create_gpencil_data(target)
2019-05-13 11:49:46 +02:00
dump_anything.load(target.grease_pencil, data['grease_pencil'])
2019-04-10 17:01:21 +02:00
# Load other meshes metadata
dump_anything.load(target, data)
# load nodes
if data["use_nodes"]:
for node in data["node_tree"]["nodes"]:
# fix None node tree error
if target.node_tree is None:
target.use_nodes = True
2019-04-10 17:01:21 +02:00
index = target.node_tree.nodes.find(node)
2019-04-10 17:01:21 +02:00
if index is -1:
node_type = data["node_tree"]["nodes"][node]["bl_idname"]
2019-04-10 17:01:21 +02:00
target.node_tree.nodes.new(type=node_type)
2019-04-10 17:01:21 +02:00
dump_anything.load(
target.node_tree.nodes[index], data["node_tree"]["nodes"][node])
2019-04-10 17:01:21 +02:00
for input in data["node_tree"]["nodes"][node]["inputs"]:
2019-04-10 17:01:21 +02:00
try:
target.node_tree.nodes[index].inputs[input].default_value = data[
"node_tree"]["nodes"][node]["inputs"][input]["default_value"]
except:
pass
2019-04-10 17:01:21 +02:00
# Load nodes links
target.node_tree.links.clear()
for link in data["node_tree"]["links"]:
current_link = data["node_tree"]["links"][link]
input_socket = target.node_tree.nodes[current_link['to_node']
2019-05-13 11:49:46 +02:00
['name']].inputs[current_link['to_socket']['name']]
output_socket = target.node_tree.nodes[current_link['from_node']
2019-05-13 11:49:46 +02:00
['name']].outputs[current_link['from_socket']['name']]
2019-04-10 17:01:21 +02:00
target.node_tree.links.new(input_socket, output_socket)
2019-04-10 17:01:21 +02:00
target.id = data['id']
except Exception as e:
logger.error("Material loading error: {}".format(e))
2019-04-10 17:01:21 +02:00
2019-04-18 15:05:48 +02:00
def load_gpencil_layer(target=None, data=None, create=False):
2019-04-10 17:01:21 +02:00
2019-04-18 15:05:48 +02:00
dump_anything.load(target, data)
2019-04-10 17:01:21 +02:00
for frame in data["frames"]:
2019-04-18 15:05:48 +02:00
try:
2019-04-10 17:01:21 +02:00
tframe = target.frames[frame]
except:
tframe = target.frames.new(frame)
dump_anything.load(tframe, data["frames"][frame])
for stroke in data["frames"][frame]["strokes"]:
try:
tstroke = tframe.strokes[stroke]
except:
tstroke = tframe.strokes.new()
2019-04-18 15:05:48 +02:00
dump_anything.load(
tstroke, data["frames"][frame]["strokes"][stroke])
2019-04-10 17:01:21 +02:00
for point in data["frames"][frame]["strokes"][stroke]["points"]:
p = data["frames"][frame]["strokes"][stroke]["points"][point]
tstroke.points.add(1)
tpoint = tstroke.points[len(tstroke.points)-1]
2019-04-18 15:05:48 +02:00
dump_anything.load(tpoint, p)
2019-05-08 18:18:09 +02:00
2019-04-10 17:01:21 +02:00
def load_gpencil(target=None, data=None, create=False):
try:
if target is None and create:
target = bpy.data.grease_pencils.new(data["name"])
for layer in target.layers:
target.layers.remove(layer)
2019-05-08 18:18:09 +02:00
2019-04-10 17:01:21 +02:00
if "layers" in data.keys():
for layer in data["layers"]:
if layer not in target.layers.keys():
gp_layer = target.layers.new(data["layers"][layer]["info"])
else:
gp_layer = target.layers[layer]
2019-04-18 15:05:48 +02:00
load_gpencil_layer(
target=gp_layer, data=data["layers"][layer], create=create)
2019-04-10 17:01:21 +02:00
dump_anything.load(target, data)
target.materials.clear()
if "materials" in data.keys():
for mat in data['materials']:
target.materials.append(bpy.data.materials[mat])
target.id = data['id']
2019-04-10 17:01:21 +02:00
except:
logger.error("default loading error")
2019-04-10 17:01:21 +02:00
def load_light(target=None, data=None, create=False, type=None):
try:
if target is None and create:
target = bpy.data.lights.new(data["name"], data["type"])
2019-04-10 17:01:21 +02:00
dump_anything.load(target, data)
target.id = data['id']
2019-05-08 17:06:52 +02:00
except Exception as e:
logger.error("light loading error: {}".format(e))
2019-04-10 17:01:21 +02:00
def load_default(target=None, data=None, create=False, type=None):
try:
if target is None and create:
target = getattr(bpy.data, BPY_TYPES[type]).new(data["name"])
2019-04-10 17:01:21 +02:00
dump_anything.load(target, data)
target.id = data['id']
except Exception as e:
logger.error("default loading error {}".format(e))
2019-04-10 18:01:55 +02:00
# DUMP HELPERS
def dump(key):
target = resolve_bpy_path(key)
2019-04-11 14:39:31 +02:00
target_type = key.split('/')[0]
2019-04-10 18:01:55 +02:00
data = None
if target_type == 'Material':
2019-05-10 17:00:47 +02:00
data = dump_datablock(target, 2)
dump_datablock_attibute(target, ['node_tree'], 7, data)
2019-05-23 16:49:32 +02:00
elif target_type == 'GreasePencil':
2019-05-10 13:01:24 +02:00
data = dump_datablock(target, 2)
dump_datablock_attibute(
2019-05-13 11:49:46 +02:00
target, ['layers'], 9, data)
2019-04-10 18:01:55 +02:00
elif target_type == 'Camera':
data = dump_datablock(target, 1)
2019-05-13 11:49:46 +02:00
elif 'Light' in target_type:
2019-04-10 18:01:55 +02:00
data = dump_datablock(target, 1)
elif target_type == 'Mesh':
data = dump_datablock(target, 2)
dump_datablock_attibute(
2019-05-08 17:06:52 +02:00
target, ['name', 'polygons', 'edges', 'vertices', 'id'], 6, data)
2019-05-08 17:06:52 +02:00
# Fix material index
2019-05-06 15:58:28 +02:00
m_list = []
for m in target.materials:
m_list.append(m.name)
2019-05-08 17:06:52 +02:00
2019-05-06 15:58:28 +02:00
data['material_list'] = m_list
2019-05-08 17:06:52 +02:00
elif target_type == 'Curve':
data = dump_datablock(target, 1)
dump_datablock_attibute(
target, ['splines'], 5, data)
# for index, spline in enumerate(target.splines):
# data["splines"][index] = dump_datablock_attibute(target.splines[index],"Curve/{}".format(index), ["bezier_points", "material_index", "points", "order_u", "order_v", "point_count_u", "point_count_v",
# "radius_interpolation", "resolution_v", "use_bezier_u", "use_bezier_v", "use_cyclic_u", "use_cyclic_v", "use_endpoint_u", "use_endpoint_v"], 3)
2019-04-10 18:01:55 +02:00
elif target_type == 'Object':
data = dump_datablock(target, 1)
elif target_type == 'Collection':
data = dump_datablock(target, 4)
elif target_type == 'Scene':
2019-05-02 17:58:37 +02:00
data = dump_datablock_attibute(
2019-05-10 16:24:34 +02:00
target, ['name', 'collection', 'id', 'camera', 'grease_pencil'], 2)
dump_datablock_attibute(
target, ['collection'], 4, data)
2019-05-13 11:49:46 +02:00
# elif target_type == 'Armature':
# data = dump_datablock(target, 4)
2019-04-10 18:01:55 +02:00
return data
2019-05-14 11:00:38 +02:00
2019-04-10 18:01:55 +02:00
def dump_datablock(datablock, depth):
if datablock:
dumper = dump_anything.Dumper()
dumper.type_subset = dumper.match_subset_all
dumper.depth = depth
datablock_type = datablock.bl_rna.name
key = "{}/{}".format(datablock_type, datablock.name)
data = dumper.dump(datablock)
return data
2019-05-14 11:00:38 +02:00
2019-05-08 17:06:52 +02:00
def dump_datablock_attibute(datablock=None, attributes=[], depth=1, dickt=None):
2019-04-10 18:01:55 +02:00
if datablock:
dumper = dump_anything.Dumper()
dumper.type_subset = dumper.match_subset_all
dumper.depth = depth
2019-05-13 11:49:46 +02:00
datablock_type = datablock.bl_rna.name
2019-04-10 18:01:55 +02:00
key = "{}/{}".format(datablock_type, datablock.name)
data = {}
2019-05-08 17:06:52 +02:00
if dickt:
data = dickt
2019-04-10 18:01:55 +02:00
for attr in attributes:
try:
data[attr] = dumper.dump(getattr(datablock, attr))
except:
pass
return data
2019-04-17 16:15:21 +02:00
2019-04-17 15:48:20 +02:00
def init_client(key=None):
client_dict = {}
2019-04-18 15:05:48 +02:00
2019-04-17 15:48:20 +02:00
C = bpy.context
Net = C.window_manager.session
2019-04-19 15:46:54 +02:00
client_dict['uuid'] = str(uuid4())
2019-04-18 15:05:48 +02:00
client_dict['location'] = [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]]
client_dict['color'] = [Net.client_color.r,
Net.client_color.g, Net.client_color.b, 1]
2019-04-17 15:48:20 +02:00
client_dict['active_objects'] = get_selected_objects(C.view_layer)
2019-04-18 15:05:48 +02:00
return client_dict