Skip to content

Commit 1e237cf

Browse files
committed
body2Playspace: making the mixed reality manager initialize playspace
replaced all instances of getting Camera's parent with playspace parm
1 parent 3e190d4 commit 1e237cf

File tree

9 files changed

+50
-35
lines changed

9 files changed

+50
-35
lines changed

Assets/MixedRealityToolkit-Examples/Demos/Boundary/Scripts/BoundaryVisualizationDemo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ private void Awake()
4444
{
4545
markerParent = new GameObject();
4646
markerParent.name = "Boundary Demo Markers";
47-
markerParent.transform.parent = CameraCache.Main.transform.parent;
47+
markerParent.transform.parent = MixedRealityManager.Instance.MixedRealityPlayspace.transform;
4848
}
4949

5050
private void Start()

Assets/MixedRealityToolkit-SDK/Features/Boundary/MixedRealityBoundaryManager.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public override void Destroy()
189189
private GameObject CreateBoundaryVisualizationParent()
190190
{
191191
GameObject visualizationParent = new GameObject("Boundary System Visualizations");
192-
visualizationParent.transform.parent = CameraCache.Main.transform.parent;
192+
visualizationParent.transform.parent = MixedRealityManager.Instance.MixedRealityPlayspace.transform;
193193

194194
return visualizationParent;
195195
}
@@ -456,7 +456,7 @@ public bool Contains(Vector3 location, Boundary.Type boundaryType = Boundary.Typ
456456
}
457457

458458
// Handle the user teleporting (boundary moves with them).
459-
location = CameraCache.Main.transform.parent.InverseTransformPoint(location);
459+
location = MixedRealityManager.Instance.MixedRealityPlayspace.transform.InverseTransformPoint(location);
460460

461461
if (FloorHeight.Value > location.y ||
462462
BoundaryHeight < location.y)
@@ -499,7 +499,7 @@ public bool TryGetRectangularBoundsParams(out Vector2 center, out float angle, o
499499
}
500500

501501
// Handle the user teleporting (boundary moves with them).
502-
Vector3 transformedCenter = CameraCache.Main.transform.parent.TransformPoint(
502+
Vector3 transformedCenter = MixedRealityManager.Instance.MixedRealityPlayspace.transform.TransformPoint(
503503
new Vector3(rectangularBounds.Center.x, 0f, rectangularBounds.Center.y));
504504

505505
center = new Vector2(transformedCenter.x, transformedCenter.z);
@@ -530,9 +530,9 @@ public GameObject GetFloorVisualization()
530530
currentFloorObject.name = "Boundary System Floor";
531531
currentFloorObject.transform.localScale = new Vector3(floorScale.x, boundaryObjectThickness, floorScale.y);
532532
currentFloorObject.transform.Translate(new Vector3(
533-
CameraCache.Main.transform.parent.position.x,
533+
MixedRealityManager.Instance.MixedRealityPlayspace.transform.position.x,
534534
FloorHeight.Value - (currentFloorObject.transform.localScale.y * 0.5f),
535-
CameraCache.Main.transform.parent.position.z));
535+
MixedRealityManager.Instance.MixedRealityPlayspace.transform.position.z));
536536
currentFloorObject.GetComponent<Renderer>().sharedMaterial = MixedRealityManager.Instance.ActiveProfile.BoundaryVisualizationProfile.FloorMaterial;
537537

538538
return currentFloorObject;
@@ -606,9 +606,9 @@ public GameObject GetTrackedAreaVisualization()
606606
currentTrackedAreaObject.layer = ignoreRaycastLayerValue;
607607
currentTrackedAreaObject.AddComponent<LineRenderer>();
608608
currentTrackedAreaObject.transform.Translate(new Vector3(
609-
CameraCache.Main.transform.parent.position.x,
609+
MixedRealityManager.Instance.MixedRealityPlayspace.transform.position.x,
610610
boundaryObjectRenderOffset,
611-
CameraCache.Main.transform.parent.position.z));
611+
MixedRealityManager.Instance.MixedRealityPlayspace.transform.position.z));
612612

613613
// Configure the renderer properties.
614614
float lineWidth = 0.01f;

Assets/MixedRealityToolkit-SDK/Features/Input/MixedRealityInputManager.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,6 @@ public override void Initialize()
9191

9292
private void InitializeInternal()
9393
{
94-
if (CameraCache.Main.transform.parent == null)
95-
{
96-
var cameraParent = new GameObject("Body");
97-
CameraCache.Main.transform.SetParent(cameraParent.transform);
98-
}
99-
10094
focusProvider = CameraCache.Main.gameObject.EnsureComponent<FocusProvider>();
10195
gazeProvider = CameraCache.Main.gameObject.EnsureComponent<GazeProvider>();
10296

Assets/MixedRealityToolkit-SDK/Features/Teleportation/MixedRealityTeleportManager.cs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

44
using Microsoft.MixedReality.Toolkit.Core.EventDatum.Teleport;
@@ -40,16 +40,6 @@ public override void Initialize()
4040

4141
private void InitializeInternal()
4242
{
43-
if (CameraCache.Main.transform.parent == null)
44-
{
45-
var cameraParent = new GameObject("Body");
46-
CameraCache.Main.transform.SetParent(cameraParent.transform);
47-
}
48-
49-
// Make sure the camera is at the scene origin.
50-
CameraCache.Main.transform.parent.transform.position = Vector3.zero;
51-
CameraCache.Main.transform.localPosition = Vector3.zero;
52-
5343
#if UNITY_EDITOR
5444
if (!UnityEditor.EditorApplication.isPlaying)
5545
{
@@ -248,7 +238,7 @@ private void ProcessTeleportationRequest(TeleportEventData eventData)
248238
{
249239
isProcessingTeleportRequest = true;
250240

251-
var cameraParent = CameraCache.Main.transform.parent;
241+
var cameraParent = MixedRealityManager.Instance.MixedRealityPlayspace.transform;
252242

253243
targetRotation = Vector3.zero;
254244
targetRotation.y = eventData.Pointer.PointerOrientation;

Assets/MixedRealityToolkit-SDK/Features/UX/Scripts/Pointers/TeleportPointer.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Microsoft.MixedReality.Toolkit.Core.Definitions.Physics;
66
using Microsoft.MixedReality.Toolkit.Core.EventDatum.Input;
77
using Microsoft.MixedReality.Toolkit.Core.EventDatum.Teleport;
8+
using Microsoft.MixedReality.Toolkit.Core.Managers;
89
using Microsoft.MixedReality.Toolkit.Core.Utilities;
910
using Microsoft.MixedReality.Toolkit.Core.Utilities.Physics;
1011
using System;
@@ -302,7 +303,7 @@ public override void OnPositionInputChanged(InputEventData<Vector2> eventData)
302303
{
303304
canMove = false;
304305
// Rotate the camera by the rotation amount. If our angle is positive then rotate in the positive direction, otherwise in the opposite direction.
305-
CameraCache.Main.transform.parent.RotateAround(CameraCache.Main.transform.position, Vector3.up, angle >= 0.0f ? rotationAmount : -rotationAmount);
306+
MixedRealityManager.Instance.MixedRealityPlayspace.transform.RotateAround(CameraCache.Main.transform.position, Vector3.up, angle >= 0.0f ? rotationAmount : -rotationAmount);
306307
}
307308
else // We may be trying to strafe backwards.
308309
{
@@ -316,10 +317,10 @@ public override void OnPositionInputChanged(InputEventData<Vector2> eventData)
316317
if (offsetStrafeAngle > 0 && offsetStrafeAngle < backStrafeActivationAngle)
317318
{
318319
canMove = false;
319-
var height = CameraCache.Main.transform.parent.position.y;
320-
var newPosition = -CameraCache.Main.transform.forward * strafeAmount + CameraCache.Main.transform.parent.position;
320+
var height = MixedRealityManager.Instance.MixedRealityPlayspace.transform.position.y;
321+
var newPosition = -CameraCache.Main.transform.forward * strafeAmount + MixedRealityManager.Instance.MixedRealityPlayspace.transform.position;
321322
newPosition.y = height;
322-
CameraCache.Main.transform.parent.position = newPosition;
323+
MixedRealityManager.Instance.MixedRealityPlayspace.transform.position = newPosition;
323324
}
324325
}
325326
}

Assets/MixedRealityToolkit/_Core/Devices/BaseController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ private void TryRenderControllerModel(Type controllerType)
203203
// If we've got a controller model prefab, then place it in the scene.
204204
if (controllerModel != null)
205205
{
206-
var controllerObject = UnityEngine.Object.Instantiate(controllerModel, CameraCache.Main.transform.parent);
206+
var controllerObject = UnityEngine.Object.Instantiate(controllerModel, MixedRealityManager.Instance.MixedRealityPlayspace.transform);
207207
controllerObject.name = $"{ControllerHandedness}_{controllerObject.name}";
208208
var poseSynchronizer = controllerObject.GetComponent<IMixedRealityControllerPoseSynchronizer>();
209209

Assets/MixedRealityToolkit/_Core/Devices/BaseDeviceManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ protected virtual IMixedRealityPointer[] RequestPointers(SystemType controllerTy
9999
{
100100
var pointerObject = Object.Instantiate(pointerProfile.PointerPrefab);
101101
var pointer = pointerObject.GetComponent<IMixedRealityPointer>();
102-
pointerObject.transform.SetParent(CameraCache.Main.transform.parent);
102+
pointerObject.transform.SetParent(MixedRealityManager.Instance.MixedRealityPlayspace.transform);
103103

104104
if (pointer != null)
105105
{

Assets/MixedRealityToolkit/_Core/Devices/MixedReality/WindowsMixedRealityController.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,10 @@ private void UpdateGripData(InteractionSourceState interactionSourceState, Mixed
243243
interactionSourceState.sourcePose.TryGetPosition(out currentGripPosition, InteractionSourceNode.Grip);
244244
interactionSourceState.sourcePose.TryGetRotation(out currentGripRotation, InteractionSourceNode.Grip);
245245

246-
if (CameraCache.Main.transform.parent != null)
246+
if (MixedRealityManager.Instance.MixedRealityPlayspace.transform != null)
247247
{
248-
currentGripPose.Position = CameraCache.Main.transform.parent.TransformPoint(currentGripPosition);
249-
currentGripPose.Rotation = Quaternion.Euler(CameraCache.Main.transform.parent.TransformDirection(currentGripRotation.eulerAngles));
248+
currentGripPose.Position = MixedRealityManager.Instance.MixedRealityPlayspace.transform.TransformPoint(currentGripPosition);
249+
currentGripPose.Rotation = Quaternion.Euler(MixedRealityManager.Instance.MixedRealityPlayspace.transform.TransformDirection(currentGripRotation.eulerAngles));
250250
}
251251
else
252252
{

Assets/MixedRealityToolkit/_Core/Managers/MixedRealityManager.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,36 @@ private void InitializeInternal()
341341
}
342342
}
343343

344+
private GameObject mixedRealityPlayspace;
345+
346+
/// <summary>
347+
/// Returns the MixedRealityPlayspace for the local player
348+
/// </summary>
349+
public GameObject MixedRealityPlayspace
350+
{
351+
get {
352+
AssertIsInitialized();
353+
if (mixedRealityPlayspace)
354+
{
355+
return mixedRealityPlayspace;
356+
}
357+
else
358+
{
359+
mixedRealityPlayspace = new GameObject("MixedRealityPlayspace");
360+
CameraCache.Main.transform.SetParent(mixedRealityPlayspace.transform);
361+
362+
// It's very important that the MixedRealityPlayspace align with the tracked space,
363+
// otherwise reality-locked things like playspace boundaries won't be aligned properly.
364+
// For now, we'll just assume that when the playspace is first initialized, the
365+
// tracked space origin overlaps with the world space origin. If a platform ever does
366+
// something else (i.e, placing the lower left hand corner of the tracked space at world
367+
// space 0,0,0), we should compensate for that here.
368+
369+
return mixedRealityPlayspace;
370+
}
371+
}
372+
}
373+
344374
private void ApplicationOnQuitting()
345375
{
346376
DisableAllManagers();

0 commit comments

Comments
 (0)