Skip to content

Commit 4573cec

Browse files
committed
Added an option in WebXRCameraSettings to set flat/normal mode camera pose when returning from XR mode
1 parent e11795c commit 4573cec

File tree

3 files changed

+101
-1
lines changed

3 files changed

+101
-1
lines changed

MainProject/Assets/XR/Settings/Open XR Package Settings.asset

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ MonoBehaviour:
3232
m_Script: {fileID: 11500000, guid: 7de993716e042c6499d0c18eed3a773c, type: 3}
3333
m_Name: MockRuntime Standalone
3434
m_EditorClassIdentifier:
35-
m_enabled: 1
35+
m_enabled: 0
3636
nameUi: Mock Runtime
3737
version: 0.0.2
3838
featureIdInternal: com.unity.openxr.feature.mockruntime

Packages/webxr/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
### Added
10+
- An option in WebXRCameraSettings to set flat/normal mode camera pose when returning from XR mode.
11+
912
### Changed
1013
- XR Hand pinch is now detected manually instead of relying on system select event, to support Apple Vision Pro.
1114

Packages/webxr/Runtime/Scripts/WebXRCameraSettings.cs

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ public class WebXRCameraSettings : MonoBehaviour
77
[SerializeField]
88
private Camera m_camera;
99

10+
[SerializeField]
11+
private Transform m_transform;
12+
1013
[SerializeField]
1114
private CameraClearFlags m_normalClearFlags;
1215

@@ -34,6 +37,27 @@ public class WebXRCameraSettings : MonoBehaviour
3437
[SerializeField]
3538
private LayerMask m_arCullingMask;
3639

40+
[SerializeField]
41+
private bool m_updateNormalFieldOfView = true;
42+
43+
[SerializeField]
44+
private bool m_useNormalFieldOfViewFromAwake = true;
45+
46+
[SerializeField]
47+
private float m_normalFieldOfView = 60f;
48+
49+
[SerializeField]
50+
private bool m_updateNormalLocalPose = true;
51+
52+
[SerializeField]
53+
private bool m_useNormalPoseFromAwake = true;
54+
55+
[SerializeField]
56+
private Vector3 m_normalLocalPosition = Vector3.zero;
57+
58+
[SerializeField]
59+
private Quaternion m_normalLocalRotation = Quaternion.identity;
60+
3761
public Camera Camera
3862
{
3963
get { return m_camera; }
@@ -94,6 +118,66 @@ public LayerMask ARCullingMask
94118
set { m_arCullingMask = value; }
95119
}
96120

121+
public bool UpdateNormalFieldOfView
122+
{
123+
get { return m_updateNormalFieldOfView; }
124+
set { m_updateNormalFieldOfView = value; }
125+
}
126+
127+
public bool UseNormalFieldOfViewFromAwake
128+
{
129+
get { return m_useNormalFieldOfViewFromAwake; }
130+
set { m_useNormalFieldOfViewFromAwake = value; }
131+
}
132+
133+
public float NormalFieldOfView
134+
{
135+
get { return m_normalFieldOfView; }
136+
set { m_normalFieldOfView = value; }
137+
}
138+
139+
public bool UpdateNormalLocalPose
140+
{
141+
get { return m_updateNormalLocalPose; }
142+
set { m_updateNormalLocalPose = value; }
143+
}
144+
145+
public bool UseNormalPoseFromAwake
146+
{
147+
get { return m_useNormalPoseFromAwake; }
148+
set { m_useNormalPoseFromAwake = value; }
149+
}
150+
151+
public Vector3 NormalLocalPosition
152+
{
153+
get { return m_normalLocalPosition; }
154+
set { m_normalLocalPosition = value; }
155+
}
156+
157+
public Quaternion NormalLocalRotation
158+
{
159+
get { return m_normalLocalRotation; }
160+
set { m_normalLocalRotation = value; }
161+
}
162+
163+
private void Awake()
164+
{
165+
if (m_camera == null)
166+
{
167+
return;
168+
}
169+
m_transform = m_camera.transform;
170+
if (m_useNormalFieldOfViewFromAwake)
171+
{
172+
m_normalFieldOfView = m_camera.fieldOfView;
173+
}
174+
if (m_useNormalPoseFromAwake)
175+
{
176+
m_normalLocalPosition = m_transform.localPosition;
177+
m_normalLocalRotation = m_transform.localRotation;
178+
}
179+
}
180+
97181
private void OnEnable()
98182
{
99183
WebXRManager.OnXRChange += OnXRChange;
@@ -120,6 +204,19 @@ private void OnXRChange(WebXRState state, int viewsCount, Rect leftRect, Rect ri
120204
m_camera.clearFlags = m_normalClearFlags;
121205
m_camera.backgroundColor = m_normalBackgroundColor;
122206
m_camera.cullingMask = m_normalCullingMask;
207+
if (m_updateNormalFieldOfView)
208+
{
209+
m_camera.fieldOfView = m_normalFieldOfView;
210+
}
211+
if (m_updateNormalLocalPose)
212+
{
213+
#if HAS_POSITION_AND_ROTATION
214+
m_transform.SetLocalPositionAndRotation(m_normalLocalPosition, m_normalLocalRotation);
215+
#else
216+
m_transform.localPosition = m_normalLocalPosition;
217+
m_transform.localRotation = m_normalLocalRotation;
218+
#endif
219+
}
123220
break;
124221
case WebXRState.VR:
125222
m_camera.clearFlags = m_vrClearFlags;

0 commit comments

Comments
 (0)