1 # SPDX-License-Identifier: GPL-2.0-or-later
5 importlib
.reload(properties
)
7 from . import properties
10 from bpy
.app
.translations
import pgettext_iface
as iface_
11 from bpy
.types
import (
16 # Add space_view3d.py to module search path for VIEW3D_PT_object_type_visibility import.
18 sys
.path
.append(os
.path
.abspath(os
.path
.join(os
.path
.dirname(__file__
), '../../startup/bl_ui')))
19 from space_view3d
import VIEW3D_PT_object_type_visibility
23 class VIEW3D_PT_vr_session(Panel
):
24 bl_space_type
= 'VIEW_3D'
27 bl_label
= "VR Session"
29 def draw(self
, context
):
31 session_settings
= context
.window_manager
.xr_session_settings
34 layout
.use_property_split
= True
35 layout
.use_property_decorate
= False # No animation.
37 is_session_running
= bpy
.types
.XrSessionState
.is_running(context
)
39 # Using SNAP_FACE because it looks like a stop icon -- I shouldn't
40 # have commit rights...
41 toggle_info
= ((iface_("Start VR Session"), 'PLAY') if not is_session_running
42 else (iface_("Stop VR Session"), 'SNAP_FACE'))
43 layout
.operator("wm.xr_session_toggle", text
=toggle_info
[0],
44 translate
=False, icon
=toggle_info
[1])
48 col
= layout
.column(align
=True, heading
="Tracking")
49 col
.prop(session_settings
, "use_positional_tracking", text
="Positional")
50 col
.prop(session_settings
, "use_absolute_tracking", text
="Absolute")
52 col
= layout
.column(align
=True, heading
="Actions")
53 col
.prop(scene
, "vr_actions_enable")
57 class VIEW3D_PT_vr_session_view(Panel
):
58 bl_space_type
= 'VIEW_3D'
63 def draw(self
, context
):
65 session_settings
= context
.window_manager
.xr_session_settings
67 layout
.use_property_split
= True
68 layout
.use_property_decorate
= False # No animation.
70 col
= layout
.column(align
=True, heading
="Show")
71 col
.prop(session_settings
, "show_floor", text
="Floor")
72 col
.prop(session_settings
, "show_annotation", text
="Annotations")
74 col
.prop(session_settings
, "show_selection", text
="Selection")
75 col
.prop(session_settings
, "show_controllers", text
="Controllers")
76 col
.prop(session_settings
, "show_custom_overlays", text
="Custom Overlays")
77 col
.prop(session_settings
, "show_object_extras", text
="Object Extras")
79 col
= col
.row(align
=True, heading
=" ")
82 panel
="VIEW3D_PT_vr_session_view_object_type_visibility",
83 icon_value
=session_settings
.icon_from_show_object_viewport
,
87 col
= layout
.column(align
=True)
88 col
.prop(session_settings
, "controller_draw_style", text
="Controller Style")
90 col
= layout
.column(align
=True)
91 col
.prop(session_settings
, "clip_start", text
="Clip Start")
92 col
.prop(session_settings
, "clip_end", text
="End")
95 class VIEW3D_PT_vr_session_view_object_type_visibility(VIEW3D_PT_object_type_visibility
):
96 def draw(self
, context
):
97 session_settings
= context
.window_manager
.xr_session_settings
98 self
.draw_ex(context
, session_settings
, False) # Pass session settings instead of 3D view.
102 class VIEW3D_MT_vr_landmark_menu(Menu
):
103 bl_label
= "Landmark Controls"
105 def draw(self
, _context
):
108 layout
.operator("view3d.vr_camera_landmark_from_session")
109 layout
.operator("view3d.vr_landmark_from_camera")
110 layout
.operator("view3d.update_vr_landmark")
112 layout
.operator("view3d.cursor_to_vr_landmark")
113 layout
.operator("view3d.camera_to_vr_landmark")
114 layout
.operator("view3d.add_camera_from_vr_landmark")
117 class VIEW3D_UL_vr_landmarks(UIList
):
118 def draw_item(self
, context
, layout
, _data
, item
, icon
, _active_data
,
119 _active_propname
, index
):
121 landmark_active_idx
= context
.scene
.vr_landmarks_active
123 layout
.emboss
= 'NONE'
125 layout
.prop(landmark
, "name", text
="")
128 'RADIOBUT_ON' if (index
== landmark_active_idx
) else 'RADIOBUT_OFF'
130 props
= layout
.operator(
131 "view3d.vr_landmark_activate", text
="", icon
=icon
)
135 class VIEW3D_PT_vr_landmarks(Panel
):
136 bl_space_type
= 'VIEW_3D'
137 bl_region_type
= 'UI'
139 bl_label
= "Landmarks"
140 bl_options
= {'DEFAULT_CLOSED'}
142 def draw(self
, context
):
144 scene
= context
.scene
145 landmark_selected
= properties
.VRLandmark
.get_selected_landmark(context
)
147 layout
.use_property_split
= True
148 layout
.use_property_decorate
= False # No animation.
152 row
.template_list("VIEW3D_UL_vr_landmarks", "", scene
, "vr_landmarks",
153 scene
, "vr_landmarks_selected", rows
=3)
155 col
= row
.column(align
=True)
156 col
.operator("view3d.vr_landmark_add", icon
='ADD', text
="")
157 col
.operator("view3d.vr_landmark_remove", icon
='REMOVE', text
="")
158 col
.operator("view3d.vr_landmark_from_session", icon
='PLUS', text
="")
160 col
.menu("VIEW3D_MT_vr_landmark_menu", icon
='DOWNARROW_HLT', text
="")
162 if landmark_selected
:
163 layout
.prop(landmark_selected
, "type")
165 if landmark_selected
.type == 'OBJECT':
166 layout
.prop(landmark_selected
, "base_pose_object")
167 layout
.prop(landmark_selected
, "base_scale", text
="Scale")
168 elif landmark_selected
.type == 'CUSTOM':
169 layout
.prop(landmark_selected
,
170 "base_pose_location", text
="Location")
171 layout
.prop(landmark_selected
,
172 "base_pose_angle", text
="Angle")
173 layout
.prop(landmark_selected
,
174 "base_scale", text
="Scale")
178 class VIEW3D_PT_vr_actionmaps(Panel
):
179 bl_space_type
= 'VIEW_3D'
180 bl_region_type
= 'UI'
182 bl_label
= "Action Maps"
183 bl_options
= {'DEFAULT_CLOSED'}
185 def draw(self
, context
):
187 scene
= context
.scene
189 layout
.use_property_split
= True
190 layout
.use_property_decorate
= False # No animation.
192 col
= layout
.column(align
=True)
193 col
.prop(scene
, "vr_actions_use_gamepad", text
="Gamepad")
195 col
= layout
.column(align
=True, heading
="Extensions")
196 col
.prop(scene
, "vr_actions_enable_reverb_g2", text
="HP Reverb G2")
197 col
.prop(scene
, "vr_actions_enable_vive_cosmos", text
="HTC Vive Cosmos")
198 col
.prop(scene
, "vr_actions_enable_vive_focus", text
="HTC Vive Focus")
199 col
.prop(scene
, "vr_actions_enable_huawei", text
="Huawei")
202 ### Viewport feedback.
203 class VIEW3D_PT_vr_viewport_feedback(Panel
):
204 bl_space_type
= 'VIEW_3D'
205 bl_region_type
= 'UI'
207 bl_label
= "Viewport Feedback"
208 bl_options
= {'DEFAULT_CLOSED'}
210 def draw(self
, context
):
212 scene
= context
.scene
213 view3d
= context
.space_data
214 session_settings
= context
.window_manager
.xr_session_settings
216 col
= layout
.column(align
=True)
217 col
.label(icon
='ERROR', text
="Note:")
218 col
.label(text
="Settings here may have a significant")
219 col
.label(text
="performance impact!")
223 layout
.prop(view3d
.shading
, "vr_show_virtual_camera")
224 layout
.prop(view3d
.shading
, "vr_show_controllers")
225 layout
.prop(view3d
.shading
, "vr_show_landmarks")
226 layout
.prop(view3d
, "mirror_xr_session")
230 class VIEW3D_PT_vr_info(bpy
.types
.Panel
):
231 bl_space_type
= 'VIEW_3D'
232 bl_region_type
= 'UI'
237 def poll(cls
, context
):
238 return not bpy
.app
.build_options
.xr_openxr
240 def draw(self
, context
):
242 layout
.label(icon
='ERROR', text
="Built without VR/OpenXR features")
246 VIEW3D_PT_vr_session
,
247 VIEW3D_PT_vr_session_view
,
248 VIEW3D_PT_vr_session_view_object_type_visibility
,
249 VIEW3D_PT_vr_landmarks
,
250 VIEW3D_PT_vr_actionmaps
,
251 VIEW3D_PT_vr_viewport_feedback
,
253 VIEW3D_UL_vr_landmarks
,
254 VIEW3D_MT_vr_landmark_menu
,
260 bpy
.utils
.register_class(cls
)
262 # View3DShading is the only per 3D-View struct with custom property
263 # support, so "abusing" that to get a per 3D-View option.
264 bpy
.types
.View3DShading
.vr_show_virtual_camera
= bpy
.props
.BoolProperty(
265 name
="Show VR Camera"
267 bpy
.types
.View3DShading
.vr_show_controllers
= bpy
.props
.BoolProperty(
268 name
="Show VR Controllers"
270 bpy
.types
.View3DShading
.vr_show_landmarks
= bpy
.props
.BoolProperty(
271 name
="Show Landmarks"
277 bpy
.utils
.unregister_class(cls
)
279 del bpy
.types
.View3DShading
.vr_show_virtual_camera
280 del bpy
.types
.View3DShading
.vr_show_controllers
281 del bpy
.types
.View3DShading
.vr_show_landmarks