feat(rcf): added mesh creation
This commit is contained in:
@ -23,7 +23,7 @@ context = None
|
|||||||
COLOR_TABLE = [(1, 0, 0, 1), (0, 1, 0, 1), (0, 0, 1, 1),
|
COLOR_TABLE = [(1, 0, 0, 1), (0, 1, 0, 1), (0, 0, 1, 1),
|
||||||
(0, 0.5, 1, 1), (0.5, 0, 1, 1)]
|
(0, 0.5, 1, 1), (0.5, 0, 1, 1)]
|
||||||
SUPPORTED_DATABLOCKS = ['collections', 'meshes', 'objects', 'materials', 'textures', 'lights', 'cameras', 'actions', 'armatures']
|
SUPPORTED_DATABLOCKS = ['collections', 'meshes', 'objects', 'materials', 'textures', 'lights', 'cameras', 'actions', 'armatures']
|
||||||
|
SUPPORTED_TYPES = ['Mesh','Object', 'Material', 'Texture', 'Light', 'Camera', 'Action', 'Armature']
|
||||||
# UTILITY FUNCTIONS
|
# UTILITY FUNCTIONS
|
||||||
|
|
||||||
def clean_scene(elements=SUPPORTED_DATABLOCKS):
|
def clean_scene(elements=SUPPORTED_DATABLOCKS):
|
||||||
@ -122,7 +122,7 @@ def resolve_bpy_path(path):
|
|||||||
try:
|
try:
|
||||||
item = getattr(bpy.data, path[0])[path[1]]
|
item = getattr(bpy.data, path[0])[path[1]]
|
||||||
|
|
||||||
except AttributeError:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return item
|
return item
|
||||||
@ -141,7 +141,7 @@ def init_scene():
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def load_mesh(target, data):
|
def load_mesh(target=None, data=None, create=False):
|
||||||
import bmesh
|
import bmesh
|
||||||
|
|
||||||
# TODO: handle error
|
# TODO: handle error
|
||||||
@ -166,34 +166,35 @@ def load_mesh(target, data):
|
|||||||
if len(verts) > 0:
|
if len(verts) > 0:
|
||||||
mesh_buffer.faces.new(verts)
|
mesh_buffer.faces.new(verts)
|
||||||
|
|
||||||
if not target:
|
if target is None and create:
|
||||||
target = bpy.data.meshes.new(data["name"])
|
target = bpy.data.meshes.new(data["name"])
|
||||||
|
|
||||||
mesh_buffer.to_mesh(target)
|
mesh_buffer.to_mesh(target)
|
||||||
|
|
||||||
def load_object(target,data):
|
# Load other meshes metadata
|
||||||
pass
|
dump_anything.load(target, data)
|
||||||
|
|
||||||
|
def load_object(target=None, data=None, create=False):
|
||||||
|
bpy.data.objects.new()
|
||||||
|
|
||||||
def update_scene(msg):
|
def update_scene(msg):
|
||||||
global client
|
global client
|
||||||
|
|
||||||
if msg.id != client.id:
|
if msg.id != client.id:
|
||||||
# try:
|
net_vars = bpy.context.scene.session_settings
|
||||||
value = None
|
|
||||||
if bpy.context.scene.session_settings.active_object:
|
if net_vars.active_object:
|
||||||
if bpy.context.scene.session_settings.active_object.name in msg.key:
|
if net_vars.active_object.name in msg.key:
|
||||||
raise ValueError()
|
raise ValueError()
|
||||||
|
|
||||||
if msg.mtype in SUPPORTED_DATABLOCKS:
|
if msg.mtype in SUPPORTED_TYPES:
|
||||||
item = resolve_bpy_path(msg.key)
|
target = resolve_bpy_path(msg.key)
|
||||||
|
|
||||||
if item is None:
|
if msg.mtype == 'Object':
|
||||||
pass
|
pass
|
||||||
loader = dump_anything.Loader()
|
|
||||||
loader.load(item, msg.body)
|
|
||||||
|
|
||||||
if msg.mtype == 'Mesh':
|
if msg.mtype == 'Mesh':
|
||||||
load_mesh(item, msg.body)
|
load_mesh(target=target, data=msg.body,create=net_vars.load_data)
|
||||||
|
|
||||||
|
|
||||||
recv_callbacks = [update_scene]
|
recv_callbacks = [update_scene]
|
||||||
|
50
net_ui.py
50
net_ui.py
@ -1,6 +1,6 @@
|
|||||||
import bpy
|
import bpy
|
||||||
from . import net_components
|
|
||||||
from . import net_operators
|
from . import net_components, net_operators
|
||||||
|
|
||||||
|
|
||||||
class SessionSettingsPanel(bpy.types.Panel):
|
class SessionSettingsPanel(bpy.types.Panel):
|
||||||
@ -11,21 +11,12 @@ class SessionSettingsPanel(bpy.types.Panel):
|
|||||||
bl_region_type = 'WINDOW'
|
bl_region_type = 'WINDOW'
|
||||||
bl_context = "scene"
|
bl_context = "scene"
|
||||||
|
|
||||||
def draw_header(self, context):
|
|
||||||
pass
|
|
||||||
# net_settings = context.scene.session_settings
|
|
||||||
|
|
||||||
# if net_settings.is_running:
|
|
||||||
# self.layout.label(text="",icon='HIDE_OFF')
|
|
||||||
# else:
|
|
||||||
# self.layout.label(text="",icon='HIDE_ON')
|
|
||||||
|
|
||||||
def draw(self, context):
|
def draw(self, context):
|
||||||
layout = self.layout
|
layout = self.layout
|
||||||
|
|
||||||
net_settings = context.scene.session_settings
|
net_settings = context.scene.session_settings
|
||||||
scene = context.scene
|
scene = context.scene
|
||||||
# Create a simple row.
|
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
if net_operators.client is None:
|
if net_operators.client is None:
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
@ -34,22 +25,22 @@ class SessionSettingsPanel(bpy.types.Panel):
|
|||||||
row = layout.row()
|
row = layout.row()
|
||||||
row.prop(scene.session_settings, "session_mode", expand=True)
|
row.prop(scene.session_settings, "session_mode", expand=True)
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
|
|
||||||
if scene.session_settings.session_mode == 'HOST':
|
if scene.session_settings.session_mode == 'HOST':
|
||||||
row.operator("session.create",text="HOST")
|
row.operator("session.create", text="HOST")
|
||||||
else:
|
else:
|
||||||
box = row.box()
|
box = row.box()
|
||||||
box.prop(net_settings,"ip",text="server ip")
|
box.prop(net_settings, "ip", text="server ip")
|
||||||
box = box.row()
|
box = box.row()
|
||||||
box.label(text="load data:")
|
box.label(text="load data:")
|
||||||
box.prop(net_settings,"load_data",text="")
|
box.prop(net_settings, "load_data", text="")
|
||||||
|
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
row.operator("session.join",text="CONNECT")
|
row.operator("session.join", text="CONNECT")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
if net_operators.client.status is net_components.RCFStatus.CONNECTED:
|
if net_operators.client.status is net_components.RCFStatus.CONNECTED:
|
||||||
row.label(text="Net frequency:")
|
row.label(text="Net frequency:")
|
||||||
row.prop(net_settings, "update_frequency", text="")
|
row.prop(net_settings, "update_frequency", text="")
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
@ -58,9 +49,8 @@ class SessionSettingsPanel(bpy.types.Panel):
|
|||||||
row.label(text="connecting...")
|
row.label(text="connecting...")
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
row.operator("session.stop", icon='QUIT', text="CANCEL")
|
row.operator("session.stop", icon='QUIT', text="CANCEL")
|
||||||
|
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class SessionUsersPanel(bpy.types.Panel):
|
class SessionUsersPanel(bpy.types.Panel):
|
||||||
@ -74,7 +64,7 @@ class SessionUsersPanel(bpy.types.Panel):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def poll(cls, context):
|
def poll(cls, context):
|
||||||
if net_operators.client:
|
if net_operators.client:
|
||||||
return net_operators.client.status == net_components.RCFStatus.CONNECTED
|
return net_operators.client.status == net_components.RCFStatus.CONNECTED
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def draw(self, context):
|
def draw(self, context):
|
||||||
@ -106,7 +96,6 @@ class SessionUsersPanel(bpy.types.Panel):
|
|||||||
row.label(text="Empty")
|
row.label(text="Empty")
|
||||||
|
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class SessionPropertiesPanel(bpy.types.Panel):
|
class SessionPropertiesPanel(bpy.types.Panel):
|
||||||
@ -120,7 +109,7 @@ class SessionPropertiesPanel(bpy.types.Panel):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def poll(cls, context):
|
def poll(cls, context):
|
||||||
if net_operators.client:
|
if net_operators.client:
|
||||||
return net_operators.client.status == net_components.RCFStatus.CONNECTED
|
return net_operators.client.status == net_components.RCFStatus.CONNECTED
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def draw(self, context):
|
def draw(self, context):
|
||||||
@ -134,10 +123,11 @@ class SessionPropertiesPanel(bpy.types.Panel):
|
|||||||
if net_operators.client:
|
if net_operators.client:
|
||||||
row = layout.row(align=True)
|
row = layout.row(align=True)
|
||||||
row.prop(net_settings, "buffer", text="")
|
row.prop(net_settings, "buffer", text="")
|
||||||
row.prop(net_settings,"add_property_depth",text="")
|
row.prop(net_settings, "add_property_depth", text="")
|
||||||
row.operator("session.add_prop", text="",
|
add = row.operator("session.add_prop", text="",
|
||||||
icon="ADD").property_path = net_settings.buffer
|
icon="ADD")
|
||||||
|
add.property_path = net_settings.buffer
|
||||||
|
add.depth = net_settings.add_property_depth
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
# Property area
|
# Property area
|
||||||
area_msg = row.box()
|
area_msg = row.box()
|
||||||
|
Reference in New Issue
Block a user