feat: draw xr-user frustum in regular user viewports

Related to https://gitlab.com/slumber/multi-user/-/issues/251
This commit is contained in:
Swann Martinez 2022-03-27 18:38:38 +02:00
parent 1b614f4fb6
commit 630e1c7494
2 changed files with 26 additions and 10 deletions

View File

@ -26,7 +26,7 @@ import bgl
import blf
import bpy
import gpu
from mathutils import Vector, Matrix
from mathutils import Vector, Matrix, Quaternion
from bpy_extras import view3d_utils
from gpu_extras.batch import batch_for_shader
from replication.constants import (STATE_ACTIVE, STATE_AUTH, STATE_CONFIG,
@ -278,9 +278,17 @@ class UserFrustumWidget(Widget):
def draw(self):
shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
view_matrix = Matrix(self.data.get('view_matrix')).inverted()
coords = [view_matrix @ Vector(vertex) for vertex in self.camera_vertex]
xr_state = self.data.get('xr')
transformation = Matrix()
if xr_state:
loc = Vector(xr_state.get('viewer_pose_location'))
rot = Quaternion(xr_state.get('viewer_pose_rotation'))
scale = Vector((1,1,1))
transformation = Matrix.LocRotScale(loc, rot, scale)
else:
transformation = Matrix(self.data.get('view_matrix')).inverted()
coords = [transformation @ Vector(vertex) for vertex in self.camera_vertex]
batch = batch_for_shader(
shader,
@ -390,7 +398,13 @@ class UserNameWidget(Widget):
self.settings.enable_presence
def draw(self):
position = Matrix(self.data.get('view_matrix')).inverted().to_translation()
xr_state = self.data.get('xr')
if xr_state:
position = xr_state.get('viewer_pose_location', [0,0,0])
else:
position = Matrix(self.data.get('view_matrix')).inverted().to_translation()
color = self.data.get('color')
coords = project_to_screen(position)

View File

@ -287,11 +287,13 @@ class ClientUpdate(Timer):
if cached_user_data is None:
self.users_metadata[username] = user_data['metadata']
elif 'view_matrix' in cached_user_data and 'view_matrix' in new_user_data and cached_user_data['view_matrix'] != new_user_data['view_matrix']:
elif 'view_matrix' in cached_user_data and \
'view_matrix' in new_user_data and \
cached_user_data['view_matrix'] != new_user_data['view_matrix'] or \
'xr' in cached_user_data and \
'xr' in new_user_data and \
cached_user_data['xr']['viewer_pose_location'] != new_user_data['xr']['viewer_pose_location']:
refresh_3d_view()
viewer = new_user_data.get('xr')
if viewer:
logging.info(viewer)
self.users_metadata[username] = user_data['metadata']
break
else:
@ -386,7 +388,7 @@ class MainThreadExecutor(Timer):
function(**kwargs)
class XrUserUpdate(Timer):
def __init__(self, timeout=1):
def __init__(self, timeout=.01):
# TODO: Add user refresh rate settings
super().__init__(timeout)