fix: annotations updates

Related to #215
This commit is contained in:
Swann 2021-07-06 16:06:14 +02:00
parent 297639e80f
commit e9ab633aac
No known key found for this signature in database
GPG Key ID: E1D3641A7C43AACB
4 changed files with 49 additions and 37 deletions

View File

@ -28,7 +28,7 @@ from replication.protocol import ReplicatedDatablock
from .bl_datablock import resolve_datablock_from_uuid from .bl_datablock import resolve_datablock_from_uuid
from .bl_action import dump_animation_data, load_animation_data, resolve_animation_dependencies from .bl_action import dump_animation_data, load_animation_data, resolve_animation_dependencies
from ..utils import get_preferences from ..utils import get_preferences
from ..timers import is_annotating
STROKE_POINT = [ STROKE_POINT = [
'co', 'co',
@ -323,7 +323,8 @@ class BlGpencil(ReplicatedDatablock):
return bpy.context.mode == 'OBJECT' \ return bpy.context.mode == 'OBJECT' \
or layer_changed(datablock, data) \ or layer_changed(datablock, data) \
or frame_changed(data) \ or frame_changed(data) \
or get_preferences().sync_flags.sync_during_editmode or get_preferences().sync_flags.sync_during_editmode \
or is_annotating(bpy.context)
_type = bpy.types.GreasePencil _type = bpy.types.GreasePencil
_class = BlGpencil _class = BlGpencil

View File

@ -403,8 +403,9 @@ class BlScene(ReplicatedDatablock):
datablock.world = bpy.data.worlds[data['world']] datablock.world = bpy.data.worlds[data['world']]
# Annotation # Annotation
if 'grease_pencil' in data.keys(): gpencil_uid = data.get('grease_pencil')
datablock.grease_pencil = bpy.data.grease_pencils[data['grease_pencil']] if gpencil_uid:
datablock.grease_pencil = resolve_datablock_from_uuid(gpencil_uid, bpy.data.grease_pencils)
if get_preferences().sync_flags.sync_render_settings: if get_preferences().sync_flags.sync_render_settings:
if 'eevee' in data.keys(): if 'eevee' in data.keys():
@ -470,7 +471,6 @@ class BlScene(ReplicatedDatablock):
'name', 'name',
'world', 'world',
'id', 'id',
'grease_pencil',
'frame_start', 'frame_start',
'frame_end', 'frame_end',
'frame_step', 'frame_step',
@ -530,6 +530,9 @@ class BlScene(ReplicatedDatablock):
if datablock.timeline_markers: if datablock.timeline_markers:
data['timeline_markers'] = [(m.name, m.frame, getattr(m.camera, 'uuid', None)) for m in datablock.timeline_markers] data['timeline_markers'] = [(m.name, m.frame, getattr(m.camera, 'uuid', None)) for m in datablock.timeline_markers]
if datablock.grease_pencil:
data['grease_pencil'] = datablock.grease_pencil.uuid
return data return data
@staticmethod @staticmethod

View File

@ -285,6 +285,7 @@ class SessionStartOperator(bpy.types.Operator):
deleyables.append(session_update) deleyables.append(session_update)
deleyables.append(session_user_sync) deleyables.append(session_user_sync)
deleyables.append(session_listen) deleyables.append(session_listen)
deleyables.append(timers.AnnotationUpdates())
return {"FINISHED"} return {"FINISHED"}

View File

@ -137,12 +137,50 @@ class ApplyTimer(Timer):
force=True) force=True)
class AnnotationUpdates(Timer):
def __init__(self, timeout=1):
self._annotating = False
self._settings = utils.get_preferences()
super().__init__(timeout)
def execute(self):
if session and session.state == STATE_ACTIVE:
ctx = bpy.context
annotation_gp = ctx.scene.grease_pencil
if annotation_gp and not annotation_gp.uuid:
ctx.scene.update_tag()
# if an annotation exist and is tracked
if annotation_gp and annotation_gp.uuid:
registered_gp = session.repository.graph.get(annotation_gp.uuid)
if is_annotating(bpy.context):
# try to get the right on it
if registered_gp.owner == RP_COMMON:
self._annotating = True
logging.debug(
"Getting the right on the annotation GP")
porcelain.lock(session.repository,
registered_gp.uuid,
ignore_warnings=True,
affect_dependencies=False)
if registered_gp.owner == self._settings.username:
porcelain.commit(session.repository, annotation_gp.uuid)
porcelain.push(session.repository, 'origin', annotation_gp.uuid)
elif self._annotating:
porcelain.unlock(session.repository,
registered_gp.uuid,
ignore_warnings=True,
affect_dependencies=False)
class DynamicRightSelectTimer(Timer): class DynamicRightSelectTimer(Timer):
def __init__(self, timeout=.1): def __init__(self, timeout=.1):
super().__init__(timeout) super().__init__(timeout)
self._last_selection = [] self._last_selection = []
self._user = None self._user = None
self._annotating = False
def execute(self): def execute(self):
settings = utils.get_preferences() settings = utils.get_preferences()
@ -153,37 +191,6 @@ class DynamicRightSelectTimer(Timer):
self._user = session.online_users.get(settings.username) self._user = session.online_users.get(settings.username)
if self._user: if self._user:
ctx = bpy.context
annotation_gp = ctx.scene.grease_pencil
if annotation_gp and not annotation_gp.uuid:
ctx.scene.update_tag()
# if an annotation exist and is tracked
if annotation_gp and annotation_gp.uuid:
registered_gp = session.repository.graph.get(annotation_gp.uuid)
if is_annotating(bpy.context):
# try to get the right on it
if registered_gp.owner == RP_COMMON:
self._annotating = True
logging.debug(
"Getting the right on the annotation GP")
porcelain.lock(session.repository,
registered_gp.uuid,
ignore_warnings=True,
affect_dependencies=False)
if registered_gp.owner == settings.username:
gp_node = session.repository.graph.get(annotation_gp.uuid)
porcelain.commit(session.repository, gp_node.uuid)
porcelain.push(session.repository, 'origin', gp_node.uuid)
elif self._annotating:
porcelain.unlock(session.repository,
registered_gp.uuid,
ignore_warnings=True,
affect_dependencies=False)
current_selection = utils.get_selected_objects( current_selection = utils.get_selected_objects(
bpy.context.scene, bpy.context.scene,
bpy.data.window_managers['WinMan'].windows[0].view_layer bpy.data.window_managers['WinMan'].windows[0].view_layer