From 72f38bae00f17c83d3ce872c0c0c0f19534cbbfe Mon Sep 17 00:00:00 2001 From: yl-msft Date: Fri, 2 Sep 2022 16:44:49 -0700 Subject: [PATCH 1/2] Refactor to simplify OpenXR sample --- Sample/.gitignore | 2 +- .../ProjectPreferences.asset | 5 +- Sample/Assets/Scripts/QRCode.cs | 4 +- Sample/Assets/Scripts/QRCodesManager.cs | 2 +- Sample/Assets/Scripts/QRCodesSetup.cs | 2 +- Sample/Assets/Scripts/QRCodesVisualizer.cs | 6 +- Sample/Assets/Scripts/SampleQRCodes.asmdef | 17 +++ .../Assets/Scripts/SampleQRCodes.asmdef.meta | 7 + Sample/Assets/Scripts/Singleton.cs | 2 +- .../Scripts/SpatialGraphCoordinateSystem.cs | 130 ------------------ Sample/Assets/Scripts/SpatialGraphNode.cs | 79 +++++++++++ .../Assets/Scripts/SpatialGraphNode.cs.meta | 11 ++ .../Assets/Scripts/SpatialGraphNodeTracker.cs | 70 ++++++++++ ...s.meta => SpatialGraphNodeTracker.cs.meta} | 0 Sample/ProjectSettings/ProjectSettings.asset | 7 +- Sample/ProjectSettings/QualitySettings.asset | 37 +++-- Sample/ProjectSettings/TimelineSettings.asset | 15 ++ 17 files changed, 238 insertions(+), 158 deletions(-) create mode 100644 Sample/Assets/Scripts/SampleQRCodes.asmdef create mode 100644 Sample/Assets/Scripts/SampleQRCodes.asmdef.meta delete mode 100644 Sample/Assets/Scripts/SpatialGraphCoordinateSystem.cs create mode 100644 Sample/Assets/Scripts/SpatialGraphNode.cs create mode 100644 Sample/Assets/Scripts/SpatialGraphNode.cs.meta create mode 100644 Sample/Assets/Scripts/SpatialGraphNodeTracker.cs rename Sample/Assets/Scripts/{SpatialGraphCoordinateSystem.cs.meta => SpatialGraphNodeTracker.cs.meta} (100%) create mode 100644 Sample/ProjectSettings/TimelineSettings.asset diff --git a/Sample/.gitignore b/Sample/.gitignore index bddd745..0c62053 100644 --- a/Sample/.gitignore +++ b/Sample/.gitignore @@ -77,6 +77,6 @@ crashlytics-build.properties # Sample specific -/[Aa]pp/ +/[Aa]pp*/ /[Aa]ssets/Packages/ /UWP*/ diff --git a/Sample/Assets/MixedRealityToolkit.Generated/ProjectPreferences.asset b/Sample/Assets/MixedRealityToolkit.Generated/ProjectPreferences.asset index f6f5955..ff650d9 100644 --- a/Sample/Assets/MixedRealityToolkit.Generated/ProjectPreferences.asset +++ b/Sample/Assets/MixedRealityToolkit.Generated/ProjectPreferences.asset @@ -19,11 +19,12 @@ MonoBehaviour: - _MixedRealityToolkit_Editor_AutoEnableUWPCapabilities - MixedRealityToolkit_Editor_RunOptimalConfig - MixedRealityToolkit_Editor_NullDataProviders - values: 0001010100 + values: 0101010100 intPreferences: keys: - MixedRealityToolkit_Editor_AudioSpatializerCount - values: 01000000 + - _MixedRealityToolkit_Editor_ConfiguratorState + values: 0100000000000000 floatPreferences: keys: [] values: [] diff --git a/Sample/Assets/Scripts/QRCode.cs b/Sample/Assets/Scripts/QRCode.cs index 97760c5..4e71950 100644 --- a/Sample/Assets/Scripts/QRCode.cs +++ b/Sample/Assets/Scripts/QRCode.cs @@ -4,9 +4,9 @@ using Microsoft.MixedReality.Toolkit.Input; using UnityEngine; -namespace QRTracking +namespace SampleQRCodes { - [RequireComponent(typeof(SpatialGraphCoordinateSystem))] + [RequireComponent(typeof(SpatialGraphNodeTracker))] public class QRCode : MonoBehaviour, IMixedRealityPointerHandler { public Microsoft.MixedReality.QR.QRCode qrCode; diff --git a/Sample/Assets/Scripts/QRCodesManager.cs b/Sample/Assets/Scripts/QRCodesManager.cs index 87aa7b7..692ae9a 100644 --- a/Sample/Assets/Scripts/QRCodesManager.cs +++ b/Sample/Assets/Scripts/QRCodesManager.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using UnityEngine; -namespace QRTracking +namespace SampleQRCodes { public static class QRCodeEventArgs { diff --git a/Sample/Assets/Scripts/QRCodesSetup.cs b/Sample/Assets/Scripts/QRCodesSetup.cs index 7732a43..cffe025 100644 --- a/Sample/Assets/Scripts/QRCodesSetup.cs +++ b/Sample/Assets/Scripts/QRCodesSetup.cs @@ -3,7 +3,7 @@ using UnityEngine; -namespace QRTracking +namespace SampleQRCodes { public class QRCodesSetup : MonoBehaviour { diff --git a/Sample/Assets/Scripts/QRCodesVisualizer.cs b/Sample/Assets/Scripts/QRCodesVisualizer.cs index e7b27c4..da0e8ac 100644 --- a/Sample/Assets/Scripts/QRCodesVisualizer.cs +++ b/Sample/Assets/Scripts/QRCodesVisualizer.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using UnityEngine; -namespace QRTracking +namespace SampleQRCodes { public class QRCodesVisualizer : MonoBehaviour { @@ -96,7 +96,7 @@ private void HandleEvents() if (action.type == ActionData.Type.Added) { GameObject qrCodeObject = Instantiate(qrCodePrefab, new Vector3(0, 0, 0), Quaternion.identity); - qrCodeObject.GetComponent().Id = action.qrCode.SpatialGraphNodeId; + qrCodeObject.GetComponent().Id = action.qrCode.SpatialGraphNodeId; qrCodeObject.GetComponent().qrCode = action.qrCode; qrCodesObjectsList.Add(action.qrCode.Id, qrCodeObject); } @@ -105,7 +105,7 @@ private void HandleEvents() if (!qrCodesObjectsList.ContainsKey(action.qrCode.Id)) { GameObject qrCodeObject = Instantiate(qrCodePrefab, new Vector3(0, 0, 0), Quaternion.identity); - qrCodeObject.GetComponent().Id = action.qrCode.SpatialGraphNodeId; + qrCodeObject.GetComponent().Id = action.qrCode.SpatialGraphNodeId; qrCodeObject.GetComponent().qrCode = action.qrCode; qrCodesObjectsList.Add(action.qrCode.Id, qrCodeObject); } diff --git a/Sample/Assets/Scripts/SampleQRCodes.asmdef b/Sample/Assets/Scripts/SampleQRCodes.asmdef new file mode 100644 index 0000000..fec49fc --- /dev/null +++ b/Sample/Assets/Scripts/SampleQRCodes.asmdef @@ -0,0 +1,17 @@ +{ + "name": "SampleQRCodes", + "rootNamespace": "", + "references": [ + "Microsoft.MixedReality.Toolkit", + "Unity.XR.WindowsMixedReality" + ], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Sample/Assets/Scripts/SampleQRCodes.asmdef.meta b/Sample/Assets/Scripts/SampleQRCodes.asmdef.meta new file mode 100644 index 0000000..ecef1f5 --- /dev/null +++ b/Sample/Assets/Scripts/SampleQRCodes.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 5f89e8918ff2838459daf50638767329 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Sample/Assets/Scripts/Singleton.cs b/Sample/Assets/Scripts/Singleton.cs index 48fe95c..7cc10a1 100644 --- a/Sample/Assets/Scripts/Singleton.cs +++ b/Sample/Assets/Scripts/Singleton.cs @@ -3,7 +3,7 @@ using UnityEngine; -namespace QRTracking +namespace SampleQRCodes { /// /// Inherit from this base class to create a singleton. diff --git a/Sample/Assets/Scripts/SpatialGraphCoordinateSystem.cs b/Sample/Assets/Scripts/SpatialGraphCoordinateSystem.cs deleted file mode 100644 index e163d5c..0000000 --- a/Sample/Assets/Scripts/SpatialGraphCoordinateSystem.cs +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -using UnityEngine; - -#if WINDOWS_UWP -using Microsoft.MixedReality.Toolkit.Utilities; -using Windows.Perception.Spatial; -#endif - -namespace QRTracking -{ - public class SpatialGraphCoordinateSystem : MonoBehaviour - { -#if WINDOWS_UWP - private SpatialCoordinateSystem CoordinateSystem = null; -#endif - private System.Guid id; - public System.Guid Id - { - get - { - return id; - } - - set - { - id = value; -#if WINDOWS_UWP - CoordinateSystem = Windows.Perception.Spatial.Preview.SpatialGraphInteropPreview.CreateCoordinateSystemForNode(id); - if (CoordinateSystem == null) - { - Debug.Log("Id= " + id + " Failed to acquire coordinate system"); - } -#endif - } - } - - // Use this for initialization - void Start() - { -#if WINDOWS_UWP - if (CoordinateSystem == null) - { - CoordinateSystem = Windows.Perception.Spatial.Preview.SpatialGraphInteropPreview.CreateCoordinateSystemForNode(id); - if (CoordinateSystem == null) - { - Debug.Log("Id= " + id + " Failed to acquire coordinate system"); - } - } -#endif - } - - private void UpdateLocation() - { -#if WINDOWS_UWP - if (CoordinateSystem == null) - { - CoordinateSystem = Windows.Perception.Spatial.Preview.SpatialGraphInteropPreview.CreateCoordinateSystemForNode(id); - - if (CoordinateSystem == null) - { - Debug.Log("Id= " + id + " Failed to acquire coordinate system"); - } - } - - if (CoordinateSystem != null) - { - Quaternion rotation = Quaternion.identity; - Vector3 translation = new Vector3(0.0f, 0.0f, 0.0f); - - System.IntPtr rootCoordnateSystemPtr = UnityEngine.XR.WindowsMR.WindowsMREnvironment.OriginSpatialCoordinateSystem; - SpatialCoordinateSystem rootSpatialCoordinateSystem = (SpatialCoordinateSystem)System.Runtime.InteropServices.Marshal.GetObjectForIUnknown(rootCoordnateSystemPtr); - - // Get the relative transform from the unity origin - System.Numerics.Matrix4x4? relativePose = CoordinateSystem.TryGetTransformTo(rootSpatialCoordinateSystem); - - if (relativePose != null) - { - System.Numerics.Vector3 scale; - System.Numerics.Quaternion rotation1; - System.Numerics.Vector3 translation1; - - System.Numerics.Matrix4x4 newMatrix = relativePose.Value; - - // Platform coordinates are all right handed and unity uses left handed matrices. so we convert the matrix - // from rhs-rhs to lhs-lhs - // Convert from right to left coordinate system - newMatrix.M13 = -newMatrix.M13; - newMatrix.M23 = -newMatrix.M23; - newMatrix.M43 = -newMatrix.M43; - - newMatrix.M31 = -newMatrix.M31; - newMatrix.M32 = -newMatrix.M32; - newMatrix.M34 = -newMatrix.M34; - - System.Numerics.Matrix4x4.Decompose(newMatrix, out scale, out rotation1, out translation1); - translation = new Vector3(translation1.X, translation1.Y, translation1.Z); - rotation = new Quaternion(rotation1.X, rotation1.Y, rotation1.Z, rotation1.W); - Pose pose = new Pose(translation, rotation); - - // If there is a parent to the camera that means we are using teleport and we should not apply the teleport - // to these objects so apply the inverse - if (CameraCache.Main.transform.parent != null) - { - pose = pose.GetTransformedBy(CameraCache.Main.transform.parent); - } - - gameObject.transform.SetPositionAndRotation(pose.position, pose.rotation); - //Debug.Log("Id= " + id + " QRPose = " + pose.position.ToString("F7") + " QRRot = " + pose.rotation.ToString("F7")); - } - else - { - // Debug.Log("Id= " + id + " Unable to locate qrcode" ); - } - } - else - { - gameObject.SetActive(false); - } -#endif - } - - // Update is called once per frame - void Update() - { - UpdateLocation(); - } - } -} diff --git a/Sample/Assets/Scripts/SpatialGraphNode.cs b/Sample/Assets/Scripts/SpatialGraphNode.cs new file mode 100644 index 0000000..b008836 --- /dev/null +++ b/Sample/Assets/Scripts/SpatialGraphNode.cs @@ -0,0 +1,79 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using UnityEngine; + +namespace SampleQRCodes.WindowsXR +{ + internal class SpatialGraphNode + { + public System.Guid Id { get; private set; } +#if WINDOWS_UWP && XR_PLUGIN_WINDOWSMR + private Windows.Perception.Spatial.SpatialCoordinateSystem CoordinateSystem = null; +#endif + + public static SpatialGraphNode FromStaticNodeId(System.Guid id) + { +#if WINDOWS_UWP && XR_PLUGIN_WINDOWSMR + var coordinateSystem = Windows.Perception.Spatial.Preview.SpatialGraphInteropPreview.CreateCoordinateSystemForNode(id); + return coordinateSystem == null ? null : + new SpatialGraphNode() + { + Id = id, + CoordinateSystem = coordinateSystem + }; +#else + return null; +#endif + } + + + public bool TryLocate(out Pose pose) + { + pose = Pose.identity; + +#if WINDOWS_UWP && XR_PLUGIN_WINDOWSMR + Quaternion rotation = Quaternion.identity; + Vector3 translation = new Vector3(0.0f, 0.0f, 0.0f); + + System.IntPtr rootCoordnateSystemPtr = UnityEngine.XR.WindowsMR.WindowsMREnvironment.OriginSpatialCoordinateSystem; + Windows.Perception.Spatial.SpatialCoordinateSystem rootSpatialCoordinateSystem = + (Windows.Perception.Spatial.SpatialCoordinateSystem)System.Runtime.InteropServices.Marshal.GetObjectForIUnknown(rootCoordnateSystemPtr); + + // Get the relative transform from the unity origin + System.Numerics.Matrix4x4? relativePose = CoordinateSystem.TryGetTransformTo(rootSpatialCoordinateSystem); + + if (relativePose != null) + { + System.Numerics.Vector3 scale; + System.Numerics.Quaternion rotation1; + System.Numerics.Vector3 translation1; + + System.Numerics.Matrix4x4 newMatrix = relativePose.Value; + + // Platform coordinates are all right handed and unity uses left handed matrices. so we convert the matrix + // from rhs-rhs to lhs-lhs + // Convert from right to left coordinate system + newMatrix.M13 = -newMatrix.M13; + newMatrix.M23 = -newMatrix.M23; + newMatrix.M43 = -newMatrix.M43; + + newMatrix.M31 = -newMatrix.M31; + newMatrix.M32 = -newMatrix.M32; + newMatrix.M34 = -newMatrix.M34; + + System.Numerics.Matrix4x4.Decompose(newMatrix, out scale, out rotation1, out translation1); + translation = new Vector3(translation1.X, translation1.Y, translation1.Z); + rotation = new Quaternion(rotation1.X, rotation1.Y, rotation1.Z, rotation1.W); + pose = new Pose(translation, rotation); + return true; + } + else + { + // Debug.Log("Id= " + id + " Unable to locate qrcode" ); + } +#endif // WINDOWS_UWP + return false; + } + } +} \ No newline at end of file diff --git a/Sample/Assets/Scripts/SpatialGraphNode.cs.meta b/Sample/Assets/Scripts/SpatialGraphNode.cs.meta new file mode 100644 index 0000000..9244a01 --- /dev/null +++ b/Sample/Assets/Scripts/SpatialGraphNode.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 317e715d033e39f498c9ab0b5fe90949 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Sample/Assets/Scripts/SpatialGraphNodeTracker.cs b/Sample/Assets/Scripts/SpatialGraphNodeTracker.cs new file mode 100644 index 0000000..21e922b --- /dev/null +++ b/Sample/Assets/Scripts/SpatialGraphNodeTracker.cs @@ -0,0 +1,70 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using UnityEngine; +using Microsoft.MixedReality.Toolkit.Utilities; +using SpatialGraphNode = SampleQRCodes.WindowsXR.SpatialGraphNode; + +namespace SampleQRCodes +{ + internal class SpatialGraphNodeTracker : MonoBehaviour + { + private System.Guid _id; + private SpatialGraphNode node; + + public System.Guid Id + { + get => _id; + + set + { + if (_id != value) + { + _id = value; + InitializeSpatialGraphNode(force: true); + } + } + } + + // Use this for initialization + void Start() + { + InitializeSpatialGraphNode(); + } + + // Update is called once per frame + void Update() + { + InitializeSpatialGraphNode(); + + if (node != null) + { + if (node.TryLocate(out Pose pose)) + { + // If there is a parent to the camera that means we are using teleport and we should not apply the teleport + // to these objects so apply the inverse + if (CameraCache.Main.transform.parent != null) + { + pose = pose.GetTransformedBy(CameraCache.Main.transform.parent); + } + + gameObject.transform.SetPositionAndRotation(pose.position, pose.rotation); + Debug.Log("Id= " + Id + " QRPose = " + pose.position.ToString("F7") + " QRRot = " + pose.rotation.ToString("F7")); + } + else + { + Debug.LogWarning("Cannot locate " + Id); + } + } + } + + private void InitializeSpatialGraphNode(bool force = false) + { + if (node == null || force) + { + node = (Id != System.Guid.Empty) ? SpatialGraphNode.FromStaticNodeId(Id) : null; + Debug.Log("Initialize SpatialGraphNode Id= " + Id); + } + } + } +} \ No newline at end of file diff --git a/Sample/Assets/Scripts/SpatialGraphCoordinateSystem.cs.meta b/Sample/Assets/Scripts/SpatialGraphNodeTracker.cs.meta similarity index 100% rename from Sample/Assets/Scripts/SpatialGraphCoordinateSystem.cs.meta rename to Sample/Assets/Scripts/SpatialGraphNodeTracker.cs.meta diff --git a/Sample/ProjectSettings/ProjectSettings.asset b/Sample/ProjectSettings/ProjectSettings.asset index ec803bb..5f74170 100644 --- a/Sample/ProjectSettings/ProjectSettings.asset +++ b/Sample/ProjectSettings/ProjectSettings.asset @@ -76,7 +76,7 @@ PlayerSettings: androidFullscreenMode: 1 defaultIsNativeResolution: 1 macRetinaSupport: 1 - runInBackground: 1 + runInBackground: 0 captureSingleScreen: 0 muteOtherAudioSources: 0 Prepare IOS For Recording: 0 @@ -643,7 +643,6 @@ PlayerSettings: metroSplashScreenUseBackgroundColor: 0 platformCapabilities: WindowsStoreApps: - EnterpriseAuthentication: False OfflineMapsManagement: False HumanInterfaceDevice: False Location: False @@ -678,9 +677,9 @@ PlayerSettings: RecordedCallsFolder: False Contacts: False Proximity: False - InternetClient: True CodeGeneration: False BackgroundMediaPlayback: False + EnterpriseAuthentication: False metroTargetDeviceFamilies: Desktop: False Holographic: False @@ -735,7 +734,7 @@ PlayerSettings: m_VersionCode: 1 m_VersionName: apiCompatibilityLevel: 6 - activeInputHandler: 0 + activeInputHandler: 2 cloudProjectId: framebufferDepthMemorylessMode: 0 qualitySettingsNames: [] diff --git a/Sample/ProjectSettings/QualitySettings.asset b/Sample/ProjectSettings/QualitySettings.asset index 7b7658d..58961e8 100644 --- a/Sample/ProjectSettings/QualitySettings.asset +++ b/Sample/ProjectSettings/QualitySettings.asset @@ -18,7 +18,7 @@ QualitySettings: shadowCascade2Split: 0.33333334 shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} shadowmaskMode: 0 - blendWeights: 1 + skinWeights: 1 textureQuality: 1 anisotropicTextures: 0 antiAliasing: 0 @@ -40,6 +40,7 @@ QualitySettings: asyncUploadBufferSize: 16 asyncUploadPersistentBuffer: 1 resolutionScalingFixedDPIFactor: 1 + customRenderPipeline: {fileID: 0} excludedTargetPlatforms: [] - serializedVersion: 2 name: Low @@ -53,7 +54,7 @@ QualitySettings: shadowCascade2Split: 0.33333334 shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} shadowmaskMode: 0 - blendWeights: 2 + skinWeights: 2 textureQuality: 0 anisotropicTextures: 0 antiAliasing: 0 @@ -75,11 +76,13 @@ QualitySettings: asyncUploadBufferSize: 16 asyncUploadPersistentBuffer: 1 resolutionScalingFixedDPIFactor: 1 - excludedTargetPlatforms: [] + customRenderPipeline: {fileID: 0} + excludedTargetPlatforms: + - Windows Store Apps - serializedVersion: 2 name: Medium pixelLightCount: 1 - shadows: 1 + shadows: 0 shadowResolution: 0 shadowProjection: 1 shadowCascades: 1 @@ -88,7 +91,7 @@ QualitySettings: shadowCascade2Split: 0.33333334 shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} shadowmaskMode: 0 - blendWeights: 2 + skinWeights: 2 textureQuality: 0 anisotropicTextures: 1 antiAliasing: 0 @@ -110,7 +113,9 @@ QualitySettings: asyncUploadBufferSize: 16 asyncUploadPersistentBuffer: 1 resolutionScalingFixedDPIFactor: 1 - excludedTargetPlatforms: [] + customRenderPipeline: {fileID: 0} + excludedTargetPlatforms: + - Windows Store Apps - serializedVersion: 2 name: High pixelLightCount: 2 @@ -123,7 +128,7 @@ QualitySettings: shadowCascade2Split: 0.33333334 shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} shadowmaskMode: 1 - blendWeights: 2 + skinWeights: 2 textureQuality: 0 anisotropicTextures: 1 antiAliasing: 0 @@ -145,7 +150,9 @@ QualitySettings: asyncUploadBufferSize: 16 asyncUploadPersistentBuffer: 1 resolutionScalingFixedDPIFactor: 1 - excludedTargetPlatforms: [] + customRenderPipeline: {fileID: 0} + excludedTargetPlatforms: + - Windows Store Apps - serializedVersion: 2 name: Very High pixelLightCount: 3 @@ -158,7 +165,7 @@ QualitySettings: shadowCascade2Split: 0.33333334 shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} shadowmaskMode: 1 - blendWeights: 4 + skinWeights: 4 textureQuality: 0 anisotropicTextures: 2 antiAliasing: 2 @@ -180,7 +187,9 @@ QualitySettings: asyncUploadBufferSize: 16 asyncUploadPersistentBuffer: 1 resolutionScalingFixedDPIFactor: 1 - excludedTargetPlatforms: [] + customRenderPipeline: {fileID: 0} + excludedTargetPlatforms: + - Windows Store Apps - serializedVersion: 2 name: Ultra pixelLightCount: 4 @@ -193,7 +202,7 @@ QualitySettings: shadowCascade2Split: 0.33333334 shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} shadowmaskMode: 1 - blendWeights: 4 + skinWeights: 4 textureQuality: 0 anisotropicTextures: 2 antiAliasing: 2 @@ -215,7 +224,9 @@ QualitySettings: asyncUploadBufferSize: 16 asyncUploadPersistentBuffer: 1 resolutionScalingFixedDPIFactor: 1 - excludedTargetPlatforms: [] + customRenderPipeline: {fileID: 0} + excludedTargetPlatforms: + - Windows Store Apps m_PerPlatformDefaultQuality: Android: 2 Lumin: 5 @@ -226,7 +237,7 @@ QualitySettings: Stadia: 5 Standalone: 5 WebGL: 3 - Windows Store Apps: 5 + Windows Store Apps: 0 XboxOne: 5 iPhone: 2 tvOS: 2 diff --git a/Sample/ProjectSettings/TimelineSettings.asset b/Sample/ProjectSettings/TimelineSettings.asset new file mode 100644 index 0000000..b4fbdb0 --- /dev/null +++ b/Sample/ProjectSettings/TimelineSettings.asset @@ -0,0 +1,15 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &1 +MonoBehaviour: + m_ObjectHideFlags: 61 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: a287be6c49135cd4f9b2b8666c39d999, type: 3} + m_Name: + m_EditorClassIdentifier: + assetDefaultFramerate: 60 From ea196bed9b4d29fb12027b22025d89fe8f0fc842 Mon Sep 17 00:00:00 2001 From: yl-msft Date: Fri, 2 Sep 2022 17:41:53 -0700 Subject: [PATCH 2/2] Fix conditional build flag and simplify SpatialGraphNodeTracker script --- Sample/Assets/Scripts/SampleQRCodes.asmdef | 8 +++- Sample/Assets/Scripts/SpatialGraphNode.cs | 6 +-- .../Assets/Scripts/SpatialGraphNodeTracker.cs | 39 ++++--------------- 3 files changed, 17 insertions(+), 36 deletions(-) diff --git a/Sample/Assets/Scripts/SampleQRCodes.asmdef b/Sample/Assets/Scripts/SampleQRCodes.asmdef index fec49fc..826aacc 100644 --- a/Sample/Assets/Scripts/SampleQRCodes.asmdef +++ b/Sample/Assets/Scripts/SampleQRCodes.asmdef @@ -12,6 +12,12 @@ "precompiledReferences": [], "autoReferenced": true, "defineConstraints": [], - "versionDefines": [], + "versionDefines": [ + { + "name": "com.unity.xr.windowsmr", + "expression": "1.0.0", + "define": "UNITY_XR_WINDOWSMR" + } + ], "noEngineReferences": false } \ No newline at end of file diff --git a/Sample/Assets/Scripts/SpatialGraphNode.cs b/Sample/Assets/Scripts/SpatialGraphNode.cs index b008836..cb45d87 100644 --- a/Sample/Assets/Scripts/SpatialGraphNode.cs +++ b/Sample/Assets/Scripts/SpatialGraphNode.cs @@ -8,13 +8,13 @@ namespace SampleQRCodes.WindowsXR internal class SpatialGraphNode { public System.Guid Id { get; private set; } -#if WINDOWS_UWP && XR_PLUGIN_WINDOWSMR +#if WINDOWS_UWP && UNITY_XR_WINDOWSMR private Windows.Perception.Spatial.SpatialCoordinateSystem CoordinateSystem = null; #endif public static SpatialGraphNode FromStaticNodeId(System.Guid id) { -#if WINDOWS_UWP && XR_PLUGIN_WINDOWSMR +#if WINDOWS_UWP && UNITY_XR_WINDOWSMR var coordinateSystem = Windows.Perception.Spatial.Preview.SpatialGraphInteropPreview.CreateCoordinateSystemForNode(id); return coordinateSystem == null ? null : new SpatialGraphNode() @@ -32,7 +32,7 @@ public bool TryLocate(out Pose pose) { pose = Pose.identity; -#if WINDOWS_UWP && XR_PLUGIN_WINDOWSMR +#if WINDOWS_UWP && UNITY_XR_WINDOWSMR Quaternion rotation = Quaternion.identity; Vector3 translation = new Vector3(0.0f, 0.0f, 0.0f); diff --git a/Sample/Assets/Scripts/SpatialGraphNodeTracker.cs b/Sample/Assets/Scripts/SpatialGraphNodeTracker.cs index 21e922b..bfcff8a 100644 --- a/Sample/Assets/Scripts/SpatialGraphNodeTracker.cs +++ b/Sample/Assets/Scripts/SpatialGraphNodeTracker.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. +// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using UnityEngine; @@ -9,33 +9,17 @@ namespace SampleQRCodes { internal class SpatialGraphNodeTracker : MonoBehaviour { - private System.Guid _id; private SpatialGraphNode node; - public System.Guid Id - { - get => _id; + public System.Guid Id { get; set; } - set - { - if (_id != value) - { - _id = value; - InitializeSpatialGraphNode(force: true); - } - } - } - - // Use this for initialization - void Start() - { - InitializeSpatialGraphNode(); - } - - // Update is called once per frame void Update() { - InitializeSpatialGraphNode(); + if (node == null || node.Id != Id) + { + node = (Id != System.Guid.Empty) ? SpatialGraphNode.FromStaticNodeId(Id) : null; + Debug.Log("Initialize SpatialGraphNode Id= " + Id); + } if (node != null) { @@ -57,14 +41,5 @@ void Update() } } } - - private void InitializeSpatialGraphNode(bool force = false) - { - if (node == null || force) - { - node = (Id != System.Guid.Empty) ? SpatialGraphNode.FromStaticNodeId(Id) : null; - Debug.Log("Initialize SpatialGraphNode Id= " + Id); - } - } } } \ No newline at end of file