Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

Commit

Permalink
Camera System Refactor (#517)
Browse files Browse the repository at this point in the history
* removed profile references from outside constructor

* First pass at camera system refactor

* put some files in their proper place

* Added camera data provider

* updated how we applied the head height

* Fixed a race condition after we've reset the profile and started re-initialization

Fixed platforms so they only return true outside of the editor

* reverted some changes

* added GameObject reference to camera rig

* updated sdk

* reverted quality settings change

* updated sdk

* updated lumin checkout

* removed extra line

* Added a reference to the camera system since the toolkit static accessor comes back null when the application is either quitting or resetting

* Added an optional flag to set the head height on all registered providers

* moved logic about how we get main camera rig into the getter property itself instead of having it set on registration

* removed the Enable call searching for main camera. Not lives in property accessor

* updated wmr checkout

* updated boundary system to utilize enable and disable properly

* updated base camera provider

* refactored the platforms to include IsBuildTargetAvailible and IsBuildTargetActive

Added configuration flag to determine if more than one data provider can be registered with a service per platform

* Better inspector

* reverted single service per platform

* updated Icon

* updated submodules

* reverted inspector changes

* fixed sdk checkout

* updated submodules

* better dropdown menu

* optimized and made sure we call gui changed correctly

* updated sdk checkout

* reverted name change

* Updated Service Locator

Added IMixedRealityDataProvider.ParentService
Added IMixedRealityService partent to all data provider constructors
Updated IMixedRealityDataProvider.Priority to also include the parent's priority so it's ordered better in the registry
Added Try prefix to all registration methods to conform to industry standard naming conventions
Updated tests

* updated sdk checkout

* updated usage for TryRegisterServiceConfigurations

* removed unused reference

* Updated TryUnregisterService to also unregister any data providers it's a parent of

Updated Unit Test to reflect changes

* fixed head height for services that start at the origin

* Added priority override to camera system

* optimized Check Service Match

* removed redundant type arg

* updated wmr checkout

* Apply the default head height settings if the camera's opacity flag changes

* Made sure we're resetting the transforms of the visualizations for each system

Fixed teleportation height

* updated some documentation

* updated wmr and sdk checkouts

* removed oculus head height getting set in the controllers

* removed adjustment of plays pace transform in ApplySettingsForDefaultHeadHeight when head height == 0

* updated lumin checkout

added virtual HeadHeight property

* updated lumin checkout

* updated sdk checkout

* removed comment

* updated sdk checkout

* updated oculus checkout

* updated submodule checkouts

* Removed duplicated serialized fields for the camera data provider global settings.

Instead we'll just create a default camera data provider profile and use it as our global settings

* added configuration foldout

* updated foldout label content to include the interface type this configuration expects

* updated sdk checkout

* updated usage with configuration foldout

* updated oculus checkout

* updated oculus and sdk checkouts

* Added platform overrides

* removed debug

* updated oculus checkout

* updated sdk checkout

* updated oculus checkout and fixed platform definitions for all configurations

* used camera parent transform instead of querying for camera system playspace

* updated submodules

* cleaned up docs

cleaned up profile value assignments
cleaned up magic numbers

* Changed from input system refactor

* Update XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/BaseMixedRealityCameraDataProviderProfileInspector.cs

* added camera cache fallbacks
  • Loading branch information
StephenHodgson authored Apr 24, 2020
1 parent c1bf32d commit bc9e87b
Show file tree
Hide file tree
Showing 33 changed files with 689 additions and 298 deletions.
8 changes: 8 additions & 0 deletions Definitions/CameraSystem.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) XRTK. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using UnityEngine;
using XRTK.Attributes;
using XRTK.Definitions.Utilities;
using XRTK.Interfaces;
using XRTK.Interfaces.CameraSystem;
using XRTK.Services.CameraSystem;

namespace XRTK.Definitions
namespace XRTK.Definitions.CameraSystem
{
/// <summary>
/// This <see cref="ScriptableObject"/> tells you if your head mounted display (HMD)
/// is a transparent device or an occluded device.
/// Based on those values, you can customize your camera and quality settings.
/// Provides configuration options for <see cref="IMixedRealityCameraDataProvider"/>s.
/// </summary>
[CreateAssetMenu(menuName = "Mixed Reality Toolkit/Camera Profile", fileName = "MixedRealityCameraProfile", order = (int)CreateProfileMenuItemIndices.Camera)]
public class MixedRealityCameraProfile : BaseMixedRealityProfile
public class BaseMixedRealityCameraDataProviderProfile : BaseMixedRealityProfile
{
[SerializeField]
private bool isCameraPersistent = false;
private bool isCameraPersistent = true;

/// <summary>
/// Should the camera be reused in each scene?
Expand Down Expand Up @@ -116,6 +113,7 @@ public SystemType CameraRigType
internal set => cameraRigType = value;
}

[Range(0f, 3f)]
[SerializeField]
[Tooltip("The default head height the rig will start at if a platform doesn't automatically adjust the height for you.")]
private float defaultHeadHeight = 1.6f;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions Definitions/CameraSystem/MixedRealityCameraSystemProfile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) XRTK. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using UnityEngine;
using XRTK.Definitions.Utilities;
using XRTK.Interfaces.CameraSystem;

namespace XRTK.Definitions.CameraSystem
{
/// <summary>
/// This <see cref="BaseMixedRealityProfile"/> to configuring your applications <see cref="IMixedRealityCameraDataProvider"/>s.
/// </summary>
[CreateAssetMenu(menuName = "Mixed Reality Toolkit/Camera System Profile", fileName = "MixedRealityCameraSystemProfile", order = (int)CreateProfileMenuItemIndices.Camera)]
public class MixedRealityCameraSystemProfile : BaseMixedRealityServiceProfile<IMixedRealityCameraDataProvider>
{
[SerializeField]
[Tooltip("The Global Camera Profile Settings.")]
private BaseMixedRealityCameraDataProviderProfile globalCameraProfile = null;

/// <summary>
/// The default camera data provider profile <see cref="IMixedRealityCameraDataProvider"/>s will use if no profile is assigned.
/// </summary>
public BaseMixedRealityCameraDataProviderProfile GlobalCameraProfile => globalCameraProfile;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using XRTK.Definitions.Controllers.Hands;
using XRTK.Definitions.Utilities;
using XRTK.Services;
using XRTK.Utilities;

namespace XRTK.Definitions.Controllers.Simulation.Hands
{
Expand Down Expand Up @@ -151,7 +152,9 @@ private static void OffsetJointsRelativeToOpenPosePalmPosition(SimulatedHandCont
/// </summary>
public void ComputeJointPoses(Handedness handedness, Quaternion rotation, Vector3 position, MixedRealityPose[] jointsOut)
{
Quaternion cameraRotation = MixedRealityToolkit.CameraSystem.CameraRig.PlayerCamera.transform.rotation;
Quaternion cameraRotation = MixedRealityToolkit.CameraSystem != null
? MixedRealityToolkit.CameraSystem.MainCameraRig.PlayerCamera.transform.rotation
: CameraCache.Main.transform.rotation;

for (int i = 0; i < HandData.JointCount; i++)
{
Expand Down Expand Up @@ -185,7 +188,9 @@ public void ComputeJointPoses(Handedness handedness, Quaternion rotation, Vector
public void ParseFromJointPoses(MixedRealityPose[] joints, Handedness handedness, Quaternion rotation, Vector3 position)
{
var invRotation = Quaternion.Inverse(rotation);
var invCameraRotation = Quaternion.Inverse(MixedRealityToolkit.CameraSystem.CameraRig.PlayerCamera.transform.rotation);
var invCameraRotation = Quaternion.Inverse(MixedRealityToolkit.CameraSystem != null
? MixedRealityToolkit.CameraSystem.MainCameraRig.PlayerCamera.transform.rotation
: CameraCache.Main.transform.rotation);

for (int i = 0; i < HandData.JointCount; i++)
{
Expand Down
15 changes: 9 additions & 6 deletions Definitions/MixedRealityToolkitRootProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using UnityEngine;
using UnityEngine.Serialization;
using XRTK.Attributes;
using XRTK.Definitions.BoundarySystem;
using XRTK.Definitions.CameraSystem;
using XRTK.Definitions.DiagnosticsSystem;
using XRTK.Definitions.InputSystem;
using XRTK.Definitions.NetworkingSystem;
Expand Down Expand Up @@ -38,7 +40,7 @@ public sealed class MixedRealityToolkitRootProfile : BaseMixedRealityProfile
/// </summary>
public bool IsCameraSystemEnabled
{
get => CameraProfile != null && cameraSystemType != null && cameraSystemType.Type != null && enableCameraSystem;
get => CameraSystemProfile != null && cameraSystemType != null && cameraSystemType.Type != null && enableCameraSystem;
internal set => enableCameraSystem = value;
}

Expand All @@ -57,17 +59,18 @@ public SystemType CameraSystemType
}

[SerializeField]
[Tooltip("Camera profile.")]
private MixedRealityCameraProfile cameraProfile;
[Tooltip("Camera system profile.")]
[FormerlySerializedAs("cameraProfile")]
private MixedRealityCameraSystemProfile cameraSystemProfile;

/// <summary>
/// Profile for customizing your camera and quality settings based on if your
/// head mounted display (HMD) is a transparent device or an occluded device.
/// </summary>
public MixedRealityCameraProfile CameraProfile
public MixedRealityCameraSystemProfile CameraSystemProfile
{
get => cameraProfile;
internal set => cameraProfile = value;
get => cameraSystemProfile;
internal set => cameraSystemProfile = value;
}

#endregion Camera System Properties
Expand Down
2 changes: 1 addition & 1 deletion Definitions/Utilities/TrackedObjectType.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using XRTK.Interfaces;
using XRTK.Interfaces.CameraSystem;

namespace XRTK.Definitions.Utilities
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@

using UnityEditor;
using UnityEngine;
using XRTK.Definitions;
using XRTK.Definitions.CameraSystem;
using XRTK.Services;

namespace XRTK.Inspectors.Profiles
namespace XRTK.Inspectors.Profiles.CameraSystem
{
[CustomEditor(typeof(MixedRealityCameraProfile))]
public class MixedRealityCameraProfileInspector : BaseMixedRealityProfileInspector
[CustomEditor(typeof(BaseMixedRealityCameraDataProviderProfile), true, isFallback = true)]
public class BaseMixedRealityCameraDataProviderProfileInspector : BaseMixedRealityProfileInspector
{
private SerializedProperty isCameraPersistent;

private SerializedProperty nearClipPlaneOpaqueDisplay;
private SerializedProperty cameraClearFlagsOpaqueDisplay;
private SerializedProperty backgroundColorOpaqueDisplay;
Expand Down Expand Up @@ -53,14 +54,14 @@ protected override void OnEnable()

public override void OnInspectorGUI()
{
RenderHeader("The Camera Profile helps tweak camera settings no matter what platform you're building for.");
RenderHeader("The Camera Data Provider Profile helps tweak camera settings no matter what platform you're building for.");

serializedObject.Update();

EditorGUI.BeginChangeCheck();

EditorGUILayout.Space();
EditorGUILayout.LabelField("Global Settings:", EditorStyles.boldLabel);
EditorGUILayout.LabelField("Platform Specific Settings:", EditorStyles.boldLabel);

EditorGUILayout.PropertyField(isCameraPersistent);
EditorGUILayout.PropertyField(cameraRigType);
EditorGUILayout.PropertyField(defaultHeadHeight);
Expand Down Expand Up @@ -99,4 +100,4 @@ public override void OnInspectorGUI()
}
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions Inspectors/Profiles/MixedRealityCameraSystemProfileInspector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) XRTK. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using UnityEditor;
using XRTK.Definitions.CameraSystem;
using XRTK.Services;

namespace XRTK.Inspectors.Profiles.CameraSystem
{
[CustomEditor(typeof(MixedRealityCameraSystemProfile))]
public class MixedRealityCameraSystemProfileInspector : MixedRealityServiceProfileInspector
{
private SerializedProperty globalCameraProfile;

protected override void OnEnable()
{
base.OnEnable();

globalCameraProfile = serializedObject.FindProperty(nameof(globalCameraProfile));
}

public override void OnInspectorGUI()
{
RenderHeader("The Camera Profile helps tweak camera settings no matter what platform you're building for.");

serializedObject.Update();

EditorGUI.BeginChangeCheck();

EditorGUILayout.PropertyField(globalCameraProfile);

base.OnInspectorGUI();

serializedObject.ApplyModifiedProperties();

if (MixedRealityToolkit.IsInitialized && EditorGUI.EndChangeCheck())
{
EditorApplication.delayCall += () => MixedRealityToolkit.Instance.ResetProfile(MixedRealityToolkit.Instance.ActiveProfile);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class MixedRealityToolkitRootProfileInspector : BaseMixedRealityProfileIn
// Camera system properties
private SerializedProperty enableCameraSystem;
private SerializedProperty cameraSystemType;
private SerializedProperty cameraProfile;
private SerializedProperty cameraSystemProfile;

// Input system properties
private SerializedProperty enableInputSystem;
Expand Down Expand Up @@ -78,7 +78,7 @@ protected override void OnEnable()
{
if (MixedRealityToolkit.CameraSystem != null)
{
var playspace = MixedRealityToolkit.CameraSystem.CameraRig.PlayspaceTransform;
var playspace = MixedRealityToolkit.CameraSystem.MainCameraRig.PlayspaceTransform;
Debug.Assert(playspace != null);
}

Expand All @@ -94,7 +94,7 @@ protected override void OnEnable()
// Camera system configuration
enableCameraSystem = serializedObject.FindProperty(nameof(enableCameraSystem));
cameraSystemType = serializedObject.FindProperty(nameof(cameraSystemType));
cameraProfile = serializedObject.FindProperty(nameof(cameraProfile));
cameraSystemProfile = serializedObject.FindProperty(nameof(cameraSystemProfile));

// Input system configuration
enableInputSystem = serializedObject.FindProperty(nameof(enableInputSystem));
Expand Down Expand Up @@ -143,7 +143,7 @@ public override void OnInspectorGUI()
EditorGUILayout.LabelField("Camera System Settings", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(enableCameraSystem);
EditorGUILayout.PropertyField(cameraSystemType);
EditorGUILayout.PropertyField(cameraProfile);
EditorGUILayout.PropertyField(cameraSystemProfile);

// Input System configuration
GUILayout.Space(12f);
Expand Down
36 changes: 36 additions & 0 deletions Interfaces/CameraSystem/IMixedRealityCameraDataProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) XRTK. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

namespace XRTK.Interfaces.CameraSystem
{
/// <summary>
/// Base interface for implementing camera data providers to be registered with the <see cref="IMixedRealityCameraSystem"/>
/// </summary>
public interface IMixedRealityCameraDataProvider : IMixedRealityDataProvider
{
/// <summary>
/// Is the current camera displaying on an Opaque (AR) device or a VR / immersive device
/// </summary>
bool IsOpaque { get; }

/// <summary>
/// Is the current camera displaying on a traditional 2d screen or a stereoscopic display?
/// </summary>
bool IsStereoscopic { get; }

/// <summary>
/// The <see cref="IMixedRealityCameraRig"/> reference for this data provider.
/// </summary>
IMixedRealityCameraRig CameraRig { get; }

/// <summary>
/// The default head height when a platform doesn't automatically set it.
/// </summary>
float DefaultHeadHeight { get; }

/// <summary>
/// The current head height of the player
/// </summary>
float HeadHeight { get; set; }
}
}
11 changes: 11 additions & 0 deletions Interfaces/CameraSystem/IMixedRealityCameraDataProvider.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit bc9e87b

Please sign in to comment.