Skip to content

Commit 8558487

Browse files
committed
Hide webcam in XR after calibration + Allow calibration with 2 controllers
1 parent fa9e595 commit 8558487

File tree

2 files changed

+48
-10
lines changed

2 files changed

+48
-10
lines changed

MainProject/ProjectSettings/TagManager.asset

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ TagManager:
2222
-
2323
-
2424
- Ground
25-
-
25+
- Webcam
2626
-
2727
-
2828
-

Packages/webxr-interactions/Runtime/Scripts/MixedRealityCaptureController.cs

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,15 @@ private enum ControllerState
2626
private bool enableInXR = false;
2727
private WebXRState currentXRState = WebXRState.NORMAL;
2828

29+
[SerializeField]
30+
private LayerMask webcamLayer;
2931
[SerializeField]
3032
private Transform camerasBase;
3133
[SerializeField]
3234
private Transform cameraFollower;
3335
[SerializeField]
36+
private Camera[] xrCameras;
37+
[SerializeField]
3438
private Camera spectatorCamera;
3539
[SerializeField]
3640
private Transform spectatorCameraTransform;
@@ -51,7 +55,9 @@ private enum ControllerState
5155
[SerializeField]
5256
private GameObject calibrationHintBottom;
5357
[SerializeField]
54-
private WebXRController webxrController;
58+
private WebXRController leftController;
59+
[SerializeField]
60+
private WebXRController rightController;
5561

5662
private ControllerState state = ControllerState.None;
5763
private float webcamBaseSize = 1f;
@@ -111,6 +117,7 @@ private IEnumerator ControllerProcess()
111117
calibrationHintBottom.SetActive(false);
112118
webcamParent.localScale = Vector3.one * WEBCAM_SIZE_CALIBRATION;
113119
webcamParent.gameObject.SetActive(true);
120+
AddWebcamLayer();
114121
spectatorCameraParent.SetPositionAndRotation(camerasBase.position, camerasBase.rotation);
115122
state = ControllerState.SetCameraPoint;
116123
while (state != ControllerState.Ended)
@@ -135,6 +142,7 @@ private IEnumerator ControllerProcess()
135142
break;
136143
case ControllerState.CalcAndSet:
137144
CalcAndSet();
145+
RemoveWebcamLayer();
138146
state = ControllerState.Playing;
139147
break;
140148
case ControllerState.Playing:
@@ -156,9 +164,9 @@ private void Ended()
156164

157165
private void SetPoint(Transform point, GameObject hint, ControllerState nextState, GameObject nextHint)
158166
{
159-
if (GetControllersButtonDown())
167+
if (GetControllersButtonDown(out Vector3 position))
160168
{
161-
point.position = webxrController.transform.position;
169+
point.position = position;
162170
point.gameObject.SetActive(true);
163171
hint.SetActive(false);
164172
nextHint.SetActive(true);
@@ -168,10 +176,10 @@ private void SetPoint(Transform point, GameObject hint, ControllerState nextStat
168176

169177
private void SetBottomPoint()
170178
{
171-
if (GetControllersButtonDown())
179+
if (GetControllersButtonDown(out Vector3 position))
172180
{
173181
float cameraToTopDistance = Vector3.Distance(calibrationPointCamera.position, calibrationPointTop.position);
174-
Vector3 cameraToBottomDirection = (webxrController.transform.position - calibrationPointCamera.position).normalized;
182+
Vector3 cameraToBottomDirection = (position - calibrationPointCamera.position).normalized;
175183
calibrationPointBottom.position = calibrationPointCamera.position + cameraToBottomDirection * cameraToTopDistance;
176184
calibrationPointBottom.gameObject.SetActive(true);
177185
calibrationHintBottom.SetActive(false);
@@ -181,7 +189,7 @@ private void SetBottomPoint()
181189

182190
private void Confirm()
183191
{
184-
if (GetControllersButtonDown())
192+
if (GetControllersButtonDown(out Vector3 position))
185193
{
186194
calibrationPointCamera.gameObject.SetActive(false);
187195
calibrationPointTop.gameObject.SetActive(false);
@@ -228,10 +236,40 @@ private void SetCameraPositionRotation()
228236
spectatorCameraTransform.SetPositionAndRotation(calibrationPointCamera.position, Quaternion.LookRotation(plane.normal, up) * LEFT_STEP_ROTATION);
229237
}
230238

231-
bool GetControllersButtonDown()
239+
private bool GetControllersButtonDown(out Vector3 position)
232240
{
233-
return (webxrController.isHandActive || webxrController.isControllerActive)
234-
&& (webxrController.GetButtonDown(WebXRController.ButtonTypes.Trigger));
241+
bool leftDown = (leftController.isHandActive || leftController.isControllerActive)
242+
&& leftController.GetButtonDown(WebXRController.ButtonTypes.Trigger);
243+
if (leftDown)
244+
{
245+
position = leftController.transform.position;
246+
return true;
247+
}
248+
bool rightDown = (rightController.isHandActive || rightController.isControllerActive)
249+
&& rightController.GetButtonDown(WebXRController.ButtonTypes.Trigger);
250+
if (rightDown)
251+
{
252+
position = rightController.transform.position;
253+
return true;
254+
}
255+
position = Vector3.zero;
256+
return false;
257+
}
258+
259+
private void AddWebcamLayer()
260+
{
261+
for (int i = 0; i < xrCameras.Length; i++)
262+
{
263+
xrCameras[i].cullingMask |= webcamLayer;
264+
}
265+
}
266+
267+
private void RemoveWebcamLayer()
268+
{
269+
for (int i = 0; i < xrCameras.Length; i++)
270+
{
271+
xrCameras[i].cullingMask &= ~webcamLayer;
272+
}
235273
}
236274
}
237275
}

0 commit comments

Comments
 (0)