feat: reparent ground work

This commit is contained in:
Swann
2020-09-17 22:47:11 +02:00
parent 34ed5da6f0
commit ae71d7757e
22 changed files with 75 additions and 20 deletions

View File

@ -44,7 +44,7 @@ from . import environment, utils
DEPENDENCIES = { DEPENDENCIES = {
("replication", '0.0.21a6'), ("replication", '0.0.21a7'),
} }

View File

@ -134,6 +134,7 @@ class BlAction(BlDatablock):
bl_delay_refresh = 1 bl_delay_refresh = 1
bl_delay_apply = 1 bl_delay_apply = 1
bl_automatic_push = True bl_automatic_push = True
bl_check_common = False
bl_icon = 'ACTION_TWEAK' bl_icon = 'ACTION_TWEAK'
def _construct(self, data): def _construct(self, data):

View File

@ -31,6 +31,7 @@ class BlArmature(BlDatablock):
bl_delay_refresh = 1 bl_delay_refresh = 1
bl_delay_apply = 0 bl_delay_apply = 0
bl_automatic_push = True bl_automatic_push = True
bl_check_common = False
bl_icon = 'ARMATURE_DATA' bl_icon = 'ARMATURE_DATA'
def _construct(self, data): def _construct(self, data):

View File

@ -29,6 +29,7 @@ class BlCamera(BlDatablock):
bl_delay_refresh = 1 bl_delay_refresh = 1
bl_delay_apply = 1 bl_delay_apply = 1
bl_automatic_push = True bl_automatic_push = True
bl_check_common = False
bl_icon = 'CAMERA_DATA' bl_icon = 'CAMERA_DATA'
def _construct(self, data): def _construct(self, data):

View File

@ -79,6 +79,7 @@ class BlCollection(BlDatablock):
bl_delay_refresh = 1 bl_delay_refresh = 1
bl_delay_apply = 1 bl_delay_apply = 1
bl_automatic_push = True bl_automatic_push = True
bl_check_common = True
def _construct(self, data): def _construct(self, data):
if self.is_library: if self.is_library:

View File

@ -52,6 +52,7 @@ class BlCurve(BlDatablock):
bl_delay_refresh = 1 bl_delay_refresh = 1
bl_delay_apply = 1 bl_delay_apply = 1
bl_automatic_push = True bl_automatic_push = True
bl_check_common = False
bl_icon = 'CURVE_DATA' bl_icon = 'CURVE_DATA'
def _construct(self, data): def _construct(self, data):

View File

@ -18,6 +18,7 @@
import bpy import bpy
import mathutils import mathutils
import logging
from .. import utils from .. import utils
from .dump_anything import Loader, Dumper from .dump_anything import Loader, Dumper
@ -95,6 +96,7 @@ class BlDatablock(ReplicatedDatablock):
bl_delay_apply : refresh rate in sec for apply bl_delay_apply : refresh rate in sec for apply
bl_automatic_push : boolean bl_automatic_push : boolean
bl_icon : type icon (blender icon name) bl_icon : type icon (blender icon name)
bl_check_common: enable check even in common rights
""" """
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
@ -122,6 +124,8 @@ class BlDatablock(ReplicatedDatablock):
try: try:
datablock_ref = datablock_root[self.data['name']] datablock_ref = datablock_root[self.data['name']]
except Exception: except Exception:
name = self.data.get('name')
logging.debug(f"Constructing {name}")
datablock_ref = self._construct(data=self.data) datablock_ref = self._construct(data=self.data)
if datablock_ref: if datablock_ref:
@ -129,6 +133,15 @@ class BlDatablock(ReplicatedDatablock):
self.instance = datablock_ref self.instance = datablock_ref
def remove_instance(self):
"""
Remove instance from blender data
"""
assert(self.instance)
datablock_root = getattr(bpy.data, self.bl_id)
datablock_root.remove(self.instance)
def _dump(self, instance=None): def _dump(self, instance=None):
dumper = Dumper() dumper = Dumper()
data = {} data = {}
@ -189,6 +202,7 @@ class BlDatablock(ReplicatedDatablock):
if not self.is_library: if not self.is_library:
dependencies.extend(self._resolve_deps_implementation()) dependencies.extend(self._resolve_deps_implementation())
logging.debug(f"{self.instance.name} dependencies: {dependencies}")
return dependencies return dependencies
def _resolve_deps_implementation(self): def _resolve_deps_implementation(self):

View File

@ -218,6 +218,7 @@ class BlGpencil(BlDatablock):
bl_delay_refresh = 2 bl_delay_refresh = 2
bl_delay_apply = 1 bl_delay_apply = 1
bl_automatic_push = True bl_automatic_push = True
bl_check_common = False
bl_icon = 'GREASEPENCIL' bl_icon = 'GREASEPENCIL'
def _construct(self, data): def _construct(self, data):

View File

@ -54,6 +54,7 @@ class BlImage(BlDatablock):
bl_delay_refresh = 0 bl_delay_refresh = 0
bl_delay_apply = 1 bl_delay_apply = 1
bl_automatic_push = False bl_automatic_push = False
bl_check_common = False
bl_icon = 'IMAGE_DATA' bl_icon = 'IMAGE_DATA'
def _construct(self, data): def _construct(self, data):

View File

@ -32,6 +32,7 @@ class BlLattice(BlDatablock):
bl_delay_refresh = 1 bl_delay_refresh = 1
bl_delay_apply = 1 bl_delay_apply = 1
bl_automatic_push = True bl_automatic_push = True
bl_check_common = False
bl_icon = 'LATTICE_DATA' bl_icon = 'LATTICE_DATA'
def _construct(self, data): def _construct(self, data):

View File

@ -29,6 +29,7 @@ class BlLibrary(BlDatablock):
bl_delay_refresh = 1 bl_delay_refresh = 1
bl_delay_apply = 1 bl_delay_apply = 1
bl_automatic_push = True bl_automatic_push = True
bl_check_common = False
bl_icon = 'LIBRARY_DATA_DIRECT' bl_icon = 'LIBRARY_DATA_DIRECT'
def _construct(self, data): def _construct(self, data):

View File

@ -29,6 +29,7 @@ class BlLight(BlDatablock):
bl_delay_refresh = 1 bl_delay_refresh = 1
bl_delay_apply = 1 bl_delay_apply = 1
bl_automatic_push = True bl_automatic_push = True
bl_check_common = False
bl_icon = 'LIGHT_DATA' bl_icon = 'LIGHT_DATA'
def _construct(self, data): def _construct(self, data):

View File

@ -30,6 +30,7 @@ class BlLightprobe(BlDatablock):
bl_delay_refresh = 1 bl_delay_refresh = 1
bl_delay_apply = 1 bl_delay_apply = 1
bl_automatic_push = True bl_automatic_push = True
bl_check_common = False
bl_icon = 'LIGHTPROBE_GRID' bl_icon = 'LIGHTPROBE_GRID'
def _construct(self, data): def _construct(self, data):

View File

@ -163,6 +163,7 @@ class BlMaterial(BlDatablock):
bl_delay_refresh = 1 bl_delay_refresh = 1
bl_delay_apply = 1 bl_delay_apply = 1
bl_automatic_push = True bl_automatic_push = True
bl_check_common = False
bl_icon = 'MATERIAL_DATA' bl_icon = 'MATERIAL_DATA'
def _construct(self, data): def _construct(self, data):

View File

@ -52,6 +52,7 @@ class BlMesh(BlDatablock):
bl_delay_refresh = 2 bl_delay_refresh = 2
bl_delay_apply = 1 bl_delay_apply = 1
bl_automatic_push = True bl_automatic_push = True
bl_check_common = False
bl_icon = 'MESH_DATA' bl_icon = 'MESH_DATA'
def _construct(self, data): def _construct(self, data):

View File

@ -68,6 +68,7 @@ class BlMetaball(BlDatablock):
bl_delay_refresh = 1 bl_delay_refresh = 1
bl_delay_apply = 1 bl_delay_apply = 1
bl_automatic_push = True bl_automatic_push = True
bl_check_common = False
bl_icon = 'META_BALL' bl_icon = 'META_BALL'
def _construct(self, data): def _construct(self, data):

View File

@ -24,6 +24,7 @@ from replication.exception import ContextError
from .bl_datablock import BlDatablock from .bl_datablock import BlDatablock
from .dump_anything import Dumper, Loader from .dump_anything import Dumper, Loader
from replication.exception import ReparentException
def load_pose(target_bone, data): def load_pose(target_bone, data):
@ -45,6 +46,7 @@ class BlObject(BlDatablock):
bl_delay_refresh = 1 bl_delay_refresh = 1
bl_delay_apply = 1 bl_delay_apply = 1
bl_automatic_push = True bl_automatic_push = True
bl_check_common = False
bl_icon = 'OBJECT_DATA' bl_icon = 'OBJECT_DATA'
def _construct(self, data): def _construct(self, data):
@ -97,6 +99,9 @@ class BlObject(BlDatablock):
def _load_implementation(self, data, target): def _load_implementation(self, data, target):
loader = Loader() loader = Loader()
if target.type != data['type']:
raise ReparentException()
# vertex groups # vertex groups
if 'vertex_groups' in data: if 'vertex_groups' in data:
target.vertex_groups.clear() target.vertex_groups.clear()
@ -202,6 +207,7 @@ class BlObject(BlDatablock):
'lock_location', 'lock_location',
'lock_rotation', 'lock_rotation',
'lock_scale', 'lock_scale',
'type',
'rotation_quaternion' if instance.rotation_mode == 'QUATERNION' else 'rotation_euler', 'rotation_quaternion' if instance.rotation_mode == 'QUATERNION' else 'rotation_euler',
] ]

View File

@ -30,6 +30,7 @@ class BlScene(BlDatablock):
bl_delay_refresh = 1 bl_delay_refresh = 1
bl_delay_apply = 1 bl_delay_apply = 1
bl_automatic_push = True bl_automatic_push = True
bl_check_common = True
bl_icon = 'SCENE_DATA' bl_icon = 'SCENE_DATA'
def _construct(self, data): def _construct(self, data):

View File

@ -29,6 +29,7 @@ class BlSpeaker(BlDatablock):
bl_delay_refresh = 1 bl_delay_refresh = 1
bl_delay_apply = 1 bl_delay_apply = 1
bl_automatic_push = True bl_automatic_push = True
bl_check_common = False
bl_icon = 'SPEAKER' bl_icon = 'SPEAKER'
def _load_implementation(self, data, target): def _load_implementation(self, data, target):

View File

@ -30,6 +30,7 @@ class BlWorld(BlDatablock):
bl_delay_refresh = 1 bl_delay_refresh = 1
bl_delay_apply = 1 bl_delay_apply = 1
bl_automatic_push = True bl_automatic_push = True
bl_check_common = True
bl_icon = 'WORLD_DATA' bl_icon = 'WORLD_DATA'
def _construct(self, data): def _construct(self, data):

View File

@ -21,13 +21,15 @@ import bpy
from . import operators, presence, utils from . import operators, presence, utils
from replication.constants import (FETCHED, from replication.constants import (FETCHED,
UP,
RP_COMMON, RP_COMMON,
STATE_INITIAL, STATE_INITIAL,
STATE_QUITTING, STATE_QUITTING,
STATE_ACTIVE, STATE_ACTIVE,
STATE_SYNCING, STATE_SYNCING,
STATE_LOBBY, STATE_LOBBY,
STATE_SRV_SYNC) STATE_SRV_SYNC,
REPARENT)
class Delayable(): class Delayable():
@ -100,6 +102,16 @@ class ApplyTimer(Timer):
client.apply(node, force=True) client.apply(node, force=True)
except Exception as e: except Exception as e:
logging.error(f"Fail to apply {node_ref.uuid}: {e}") logging.error(f"Fail to apply {node_ref.uuid}: {e}")
elif node_ref.state == REPARENT:
# Reload the node
node_ref.remove_instance()
node_ref.resolve()
client.apply(node, force=True)
for parent in client._graph.find_parents(node):
logging.info(f"Applying parent {parent}")
client.apply(parent, force=True)
node_ref.state = UP
class DynamicRightSelectTimer(Timer): class DynamicRightSelectTimer(Timer):
def __init__(self, timout=.1): def __init__(self, timout=.1):
@ -253,14 +265,16 @@ class ClientUpdate(Timer):
if session and renderer: if session and renderer:
if session.state['STATE'] in [STATE_ACTIVE, STATE_LOBBY]: if session.state['STATE'] in [STATE_ACTIVE, STATE_LOBBY]:
local_user = operators.client.online_users.get(settings.username) local_user = operators.client.online_users.get(
settings.username)
if not local_user: if not local_user:
return return
else: else:
for username, user_data in operators.client.online_users.items(): for username, user_data in operators.client.online_users.items():
if username != settings.username: if username != settings.username:
cached_user_data = self.users_metadata.get(username) cached_user_data = self.users_metadata.get(
username)
new_user_data = operators.client.online_users[username]['metadata'] new_user_data = operators.client.online_users[username]['metadata']
if cached_user_data is None: if cached_user_data is None:
@ -298,9 +312,11 @@ class ClientUpdate(Timer):
session.update_user_metadata(local_user_metadata) session.update_user_metadata(local_user_metadata)
elif 'view_corners' in local_user_metadata and current_view_corners != local_user_metadata['view_corners']: elif 'view_corners' in local_user_metadata and current_view_corners != local_user_metadata['view_corners']:
local_user_metadata['view_corners'] = current_view_corners local_user_metadata['view_corners'] = current_view_corners
local_user_metadata['view_matrix'] = presence.get_view_matrix() local_user_metadata['view_matrix'] = presence.get_view_matrix(
)
session.update_user_metadata(local_user_metadata) session.update_user_metadata(local_user_metadata)
class SessionStatusUpdate(Timer): class SessionStatusUpdate(Timer):
def __init__(self, timout=1): def __init__(self, timout=1):
super().__init__(timout) super().__init__(timout)
@ -308,6 +324,7 @@ class SessionStatusUpdate(Timer):
def execute(self): def execute(self):
presence.refresh_sidebar_view() presence.refresh_sidebar_view()
class SessionUserSync(Timer): class SessionUserSync(Timer):
def __init__(self, timout=1): def __init__(self, timout=1):
super().__init__(timout) super().__init__(timout)

View File

@ -111,7 +111,8 @@ class SessionStartOperator(bpy.types.Operator):
type_module_class.bl_class, type_module_class.bl_class,
type_module_class, type_module_class,
timer=type_local_config.bl_delay_refresh*1000, timer=type_local_config.bl_delay_refresh*1000,
automatic=type_local_config.auto_push) automatic=type_local_config.auto_push,
check_common=type_module_class.bl_check_common)
if settings.update_method == 'DEFAULT': if settings.update_method == 'DEFAULT':
if type_local_config.bl_delay_apply > 0: if type_local_config.bl_delay_apply > 0: