multi-user/multi_user/__init__.py

167 lines
4.5 KiB
Python
Raw Normal View History

2019-02-07 17:41:18 +01:00
bl_info = {
"name": "Multi-User",
2019-10-22 16:37:23 +02:00
"author": "Swann Martinez",
"version": (0, 0, 2),
"description": "Enable real-time collaborative workflow inside blender",
"blender": (2, 80, 0),
"location": "3D View > Sidebar > Multi-User tab",
"warning": "Unstable addon, use it at your own risks",
"category": "Collaboration",
"wiki_url": "https://multi-user.readthedocs.io/en/develop/index.html",
"tracker_url": "https://gitlab.com/slumber/multi-user/issues",
"support": "COMMUNITY"
2019-02-07 17:41:18 +01:00
}
2019-03-14 16:44:18 +01:00
2019-07-01 18:04:35 +02:00
import logging
2019-08-23 12:28:57 +02:00
import os
import random
import sys
2019-08-23 12:28:57 +02:00
import bpy
2019-08-22 10:58:54 +02:00
from bpy.app.handlers import persistent
from . import environment, utils, presence, preferences
2019-09-24 14:42:59 +02:00
from .libs.replication.replication.constants import RP_COMMON
2019-08-23 12:28:57 +02:00
# TODO: remove dependency as soon as replication will be installed as a module
DEPENDENCIES = {
2019-08-26 23:14:30 +02:00
("zmq","zmq"),
("msgpack","msgpack"),
("yaml","pyyaml"),
("jsondiff","jsondiff")
}
2019-07-02 16:43:30 +02:00
2019-07-01 18:04:35 +02:00
logger = logging.getLogger(__name__)
logger.setLevel(logging.WARNING)
def client_list_callback(scene, context):
2019-08-14 15:57:07 +02:00
from . import operators
2019-05-22 17:17:09 +02:00
2019-09-24 14:42:59 +02:00
items = [(RP_COMMON, RP_COMMON, "")]
username = utils.get_preferences().username
2019-08-14 15:57:07 +02:00
cli = operators.client
if cli:
2020-01-22 14:33:34 +01:00
client_ids = cli.online_users.keys()
for id in client_ids:
name_desc = id
if id == username:
name_desc += " (self)"
2020-01-22 14:33:34 +01:00
items.append((id, name_desc, ""))
return items
class SessionUser(bpy.types.PropertyGroup):
"""Session User
Blender user information property
"""
username: bpy.props.StringProperty(name="username")
current_frame: bpy.props.IntProperty(name="current_frame")
class SessionProps(bpy.types.PropertyGroup):
2019-09-24 13:26:51 +02:00
is_admin: bpy.props.BoolProperty(
name="is_admin",
default=False
)
2019-05-15 18:37:14 +02:00
session_mode: bpy.props.EnumProperty(
name='session_mode',
description='session mode',
items={
('HOST', 'hosting', 'host a session'),
('CONNECT', 'connexion', 'connect to a session')},
default='HOST')
2019-05-15 18:37:14 +02:00
clients: bpy.props.EnumProperty(
name="clients",
description="client enum",
items=client_list_callback)
2019-07-01 18:04:35 +02:00
enable_presence: bpy.props.BoolProperty(
2019-09-19 13:02:39 +02:00
name="Presence overlay",
description='Enable overlay drawing module',
2019-09-24 14:42:59 +02:00
default=True,
update=presence.update_presence
)
presence_show_selected: bpy.props.BoolProperty(
name="Show selected objects",
description='Enable selection overlay ',
default=True,
update=presence.update_overlay_settings
2019-09-24 18:37:36 +02:00
)
2019-09-24 14:42:59 +02:00
presence_show_user: bpy.props.BoolProperty(
name="Show users",
description='Enable user overlay ',
default=True,
update=presence.update_overlay_settings
2019-07-01 18:04:35 +02:00
)
presence_show_far_user: bpy.props.BoolProperty(
name="Show different scenes",
description="Show user on different scenes",
default=False,
update=presence.update_overlay_settings
)
2019-09-18 23:10:36 +02:00
filter_owned: bpy.props.BoolProperty(
name="filter_owned",
description='Show only owned datablocks',
default=True
)
user_snap_running: bpy.props.BoolProperty(
default=False
)
time_snap_running: bpy.props.BoolProperty(
default=False
)
2019-07-01 18:04:35 +02:00
2019-07-02 16:43:30 +02:00
classes = (
SessionUser,
2019-08-08 15:35:43 +02:00
SessionProps,
2019-07-02 16:43:30 +02:00
)
2020-02-03 19:04:08 +01:00
libs = os.path.dirname(os.path.abspath(__file__))+"\\libs\\replication\\replication"
2019-05-23 16:49:32 +02:00
def register():
2019-08-05 16:48:46 +02:00
if libs not in sys.path:
sys.path.append(libs)
2019-07-01 18:04:35 +02:00
environment.setup(DEPENDENCIES,bpy.app.binary_path_python)
2019-05-15 18:37:14 +02:00
from . import presence
2019-05-15 18:37:14 +02:00
from . import operators
from . import ui
from . import preferences
2019-05-15 18:37:14 +02:00
for cls in classes:
bpy.utils.register_class(cls)
bpy.types.WindowManager.session = bpy.props.PointerProperty(
type=SessionProps)
2019-08-08 18:12:13 +02:00
bpy.types.ID.uuid = bpy.props.StringProperty(default="")
bpy.types.WindowManager.online_users = bpy.props.CollectionProperty(
type=SessionUser
)
bpy.types.WindowManager.user_index = bpy.props.IntProperty()
2019-09-24 13:26:51 +02:00
preferences.register()
presence.register()
2019-04-10 17:01:21 +02:00
operators.register()
ui.register()
2019-02-07 17:41:18 +01:00
def unregister():
from . import presence
2019-05-15 18:37:14 +02:00
from . import operators
from . import ui
from . import preferences
presence.unregister()
2019-04-10 17:01:21 +02:00
ui.unregister()
operators.unregister()
preferences.unregister()
del bpy.types.WindowManager.session
2019-07-02 16:43:30 +02:00
for cls in reversed(classes):
bpy.utils.unregister_class(cls)