[Bf-extensions-cvs] [d273f4af] soc-2019-openxr: Add gizmo indicating VR camera/viewer position in regular 3D Views

Julian Eisel noreply at git.blender.org
Fri Dec 13 16:22:22 CET 2019


Commit: d273f4afb394a65d280d34779e140403982fd1ff
Author: Julian Eisel
Date:   Fri Dec 13 16:19:30 2019 +0100
Branches: soc-2019-openxr
https://developer.blender.org/rBAd273f4afb394a65d280d34779e140403982fd1ff

Add gizmo indicating VR camera/viewer position in regular 3D Views

Currently only indicates the position, should be easy to add rotation.

===================================================================

M	viewport_vr_preview.py

===================================================================

diff --git a/viewport_vr_preview.py b/viewport_vr_preview.py
index 2f367e4a..064d17a4 100644
--- a/viewport_vr_preview.py
+++ b/viewport_vr_preview.py
@@ -19,6 +19,9 @@
 # <pep8 compliant>
 
 import bpy
+from bpy.types import (
+    GizmoGroup,
+)
 
 bl_info = {
     "name": "Basic VR Viewer",
@@ -71,8 +74,49 @@ class VIEW3D_PT_vr_session(bpy.types.Panel):
         layout.prop(session_settings, "use_positional_tracking")
 
 
+class VIEW3D_GGT_vr_viewer(GizmoGroup):
+    bl_idname = "VIEW3D_GGT_vr_viewer"
+    bl_label = "VR Viewer Indicator"
+    bl_space_type = 'VIEW_3D'
+    bl_region_type = 'WINDOW'
+    bl_options = {'3D', 'PERSISTENT'}
+
+    @classmethod
+    def poll(cls, context):
+        return bpy.types.XrSessionState.is_running(context)
+
+    def _get_viewer_matrix(self, context):
+        from mathutils import Matrix
+        import math
+
+        wm = context.window_manager
+        rv3d = context.region_data
+
+        rotmat = Matrix.Identity(3)
+        rotmat.rotate(rv3d.view_rotation)
+        rotmat.resize_4x4()
+        transmat = Matrix.Translation(wm.xr_session_state.viewer_location)
+
+        return transmat @ rotmat
+
+    def setup(self, context):
+        gizmo = self.gizmos.new("GIZMO_GT_dial_3d")
+        gizmo.draw_options = {'FILL'}
+
+        gizmo.color = gizmo.color_highlight = 0.2, 0.6, 1.0
+        gizmo.alpha = 1.0
+        gizmo.scale_basis = 0.1
+
+        self.gizmo = gizmo
+
+    def draw_prepare(self, context):
+        self.gizmo.matrix_basis = self._get_viewer_matrix(context)
+
+
 classes = (
     VIEW3D_PT_vr_session,
+
+    VIEW3D_GGT_vr_viewer,
 )



More information about the Bf-extensions-cvs mailing list