diff --git a/Runtime/Actions/Duplicate.cs b/Runtime/Actions/Duplicate.cs index 9b5721a1f..f007b63de 100644 --- a/Runtime/Actions/Duplicate.cs +++ b/Runtime/Actions/Duplicate.cs @@ -1,7 +1,7 @@ using Unity.Labs.EditorXR.Interfaces; using Unity.Labs.EditorXR.Utilities; using Unity.Labs.ModuleLoader; -using Unity.Labs.SpatialHash.Interfaces; +using Unity.Labs.SpatialHash; using Unity.Labs.Utils; using UnityEditor; using UnityEngine; diff --git a/Runtime/Actions/Paste.cs b/Runtime/Actions/Paste.cs index ac79f6710..620bab99f 100644 --- a/Runtime/Actions/Paste.cs +++ b/Runtime/Actions/Paste.cs @@ -2,7 +2,7 @@ using Unity.Labs.EditorXR.Interfaces; using Unity.Labs.EditorXR.Utilities; using Unity.Labs.ModuleLoader; -using Unity.Labs.SpatialHash.Interfaces; +using Unity.Labs.SpatialHash; using Unity.Labs.Utils; using UnityEditor; using UnityEngine; diff --git a/Runtime/Scripts/Core/EditorXRMiniWorldModule.cs b/Runtime/Scripts/Core/EditorXRMiniWorldModule.cs index 9970df054..c93e56afd 100644 --- a/Runtime/Scripts/Core/EditorXRMiniWorldModule.cs +++ b/Runtime/Scripts/Core/EditorXRMiniWorldModule.cs @@ -7,7 +7,6 @@ using Unity.Labs.EditorXR.Workspaces; using Unity.Labs.ModuleLoader; using Unity.Labs.SpatialHash; -using Unity.Labs.SpatialHash.Interfaces; using Unity.Labs.Utils; using UnityEditor; using UnityEngine; @@ -15,9 +14,9 @@ namespace Unity.Labs.EditorXR.Core { class EditorXRMiniWorldModule : IModuleDependency, IModuleDependency, - IModuleDependency, IModuleDependency, IModuleDependency, - IModuleDependency, IModuleDependency, IUsesPlaceSceneObjects, IUsesViewerScale, - IUsesSpatialHash, IUsesRayVisibilitySettings, IProvidesIsInMiniWorld + IModuleDependency, IModuleDependency, IModuleDependency, + IModuleDependency, IUsesPlaceSceneObjects, IUsesViewerScale, IUsesSpatialHash, + IUsesRayVisibilitySettings, IProvidesIsInMiniWorld { internal class MiniWorldRay { @@ -178,7 +177,6 @@ public void UpdatePreview() EditorXRToolModule m_ToolModule; EditorXRDirectSelectionModule m_DirectSelectionModule; EditorXRRayModule m_RayModule; - SpatialHashModule m_SpatialHashModule; HighlightModule m_HighlightModule; IntersectionModule m_IntersectionModule; @@ -217,11 +215,6 @@ public void ConnectDependency(EditorXRRayModule dependency) m_RayModule = dependency; } - public void ConnectDependency(SpatialHashModule dependency) - { - m_SpatialHashModule = dependency; - } - public void ConnectDependency(HighlightModule dependency) { m_HighlightModule = dependency; @@ -560,11 +553,11 @@ void UpdateRayContainment(DeviceData data) internal void OnWorkspaceCreated(IWorkspace workspace) { var miniWorldWorkspace = workspace as MiniWorldWorkspace; - if (!miniWorldWorkspace) + if (miniWorldWorkspace == null) return; - miniWorldWorkspace.zoomSliderMax = m_SpatialHashModule.GetMaxBounds().size.MaxComponent() - / miniWorldWorkspace.contentBounds.size.MaxComponent(); + var maxBounds = this.HasProvider() ? this.GetAggregateBounds().size.MaxComponent() : 10f; + miniWorldWorkspace.zoomSliderMax = maxBounds / miniWorldWorkspace.contentBounds.size.MaxComponent(); var miniWorld = miniWorldWorkspace.miniWorld; var worldID = m_Worlds.Count; diff --git a/Runtime/Scripts/Core/EditorXRViewerModule.cs b/Runtime/Scripts/Core/EditorXRViewerModule.cs index e87b70bf3..0b2346986 100644 --- a/Runtime/Scripts/Core/EditorXRViewerModule.cs +++ b/Runtime/Scripts/Core/EditorXRViewerModule.cs @@ -17,7 +17,7 @@ class EditorXRViewerModule : ScriptableSettings, IModuleDependency, IInterfaceConnector, ISerializePreferences, IUsesConnectInterfaces, IDelayedInitializationModule, IModuleBehaviorCallbacks, IUsesFunctionalityInjection, IProvidesViewerScale, IProvidesViewerBody, IProvidesMoveCameraRig, - IProvidesGetVRPlayerObjects + IProvidesGetVRPlayerObjects, IUsesSpatialHash { [Serializable] class Preferences @@ -101,6 +101,7 @@ public float cameraRigScale #if !FI_AUTOFILL IProvidesFunctionalityInjection IFunctionalitySubscriber.provider { get; set; } IProvidesConnectInterfaces IFunctionalitySubscriber.provider { get; set; } + IProvidesSpatialHash IFunctionalitySubscriber.provider { get; set; } #endif public void ConnectDependency(EditorXRDirectSelectionModule dependency) @@ -242,9 +243,8 @@ void AddPlayerModel() { m_PlayerBody = EditorXRUtils.Instantiate(m_PlayerModelPrefab, CameraUtils.GetMainCamera().transform, false).GetComponent(); this.InjectFunctionalitySingle(m_PlayerBody); - var spatialHashModule = ModuleLoaderCore.instance.GetModule(); - if (spatialHashModule != null) - spatialHashModule.AddRenderer(m_PlayerBody.GetComponent()); + if (this.HasProvider()) + this.AddRendererToSpatialHash(m_PlayerBody.GetComponent()); var playerObjects = m_PlayerBody.GetComponentsInChildren(true); foreach (var playerObject in playerObjects) diff --git a/Runtime/Scripts/Modules/IntersectionModule/IntersectionModule.cs b/Runtime/Scripts/Modules/IntersectionModule/IntersectionModule.cs index 11c594894..c4520a856 100644 --- a/Runtime/Scripts/Modules/IntersectionModule/IntersectionModule.cs +++ b/Runtime/Scripts/Modules/IntersectionModule/IntersectionModule.cs @@ -12,7 +12,7 @@ namespace Unity.Labs.EditorXR.Modules { sealed class IntersectionModule : ScriptableSettings, IDelayedInitializationModule, IModuleBehaviorCallbacks, IUsesGameObjectLocking, IUsesGetVRPlayerObjects, IProvidesSceneRaycast, IProvidesControlInputIntersection, - IProvidesContainsVRPlayerCompletely, IProvidesCheckSphere, IProvidesCheckBounds + IProvidesContainsVRPlayerCompletely, IProvidesCheckSphere, IProvidesCheckBounds, IUsesSpatialHash { class RayIntersection { @@ -45,11 +45,10 @@ class DirectIntersection public int initializationOrder { get { return -3; } } public int shutdownOrder { get { return 0; } } - SpatialHashModule m_SpatialHashModule; - #if !FI_AUTOFILL IProvidesGameObjectLocking IFunctionalitySubscriber.provider { get; set; } IProvidesGetVRPlayerObjects IFunctionalitySubscriber.provider { get; set; } + IProvidesSpatialHash IFunctionalitySubscriber.provider { get; set; } #endif // Local method use only -- created here to reduce garbage collection. Collections must be cleared before use @@ -66,7 +65,6 @@ struct SortableRenderer public void LoadModule() { IntersectionUtils.BakedMesh = new Mesh(); // Create a new Mesh in LoadModule because it is destroyed on scene load - m_SpatialHashModule = ModuleLoaderCore.instance.GetModule(); } public void UnloadModule() { } @@ -78,10 +76,10 @@ public void Initialize() collisionTesterObject.transform.SetParent(moduleParent.transform, false); m_CollisionTester = collisionTesterObject.AddComponent(); - if (m_SpatialHashModule != null) + if (this.HasProvider()) { - m_SpatialHashModule.Clear(); - m_SpatialHashContainer = m_SpatialHashModule.GetOrCreateContainer(); + this.ClearSpatialHash(); + m_SpatialHashContainer = this.GetOrCreateSpatialHashContainer(); } m_IntersectedObjects.Clear(); @@ -124,7 +122,7 @@ void SetupObjects() } } - m_SpatialHashModule.AddRenderers(k_Renderers); + this.AddRenderersToSpatialHash(k_Renderers); } IEnumerator UpdateDynamicObjects() @@ -150,8 +148,7 @@ IEnumerator UpdateDynamicObjects() } } - m_SpatialHashModule.RemoveObjects(k_ChangedObjects); - m_SpatialHashModule.AddRenderers(k_ChangedObjects); + this.UpdateRenderersInSpatialHash(k_ChangedObjects); m_SpatialHashContainer.Trim(); yield return null; @@ -161,8 +158,8 @@ IEnumerator UpdateDynamicObjects() public void Shutdown() { EditorMonoBehaviour.instance.StopCoroutine(m_UpdateCoroutine); - if (m_SpatialHashModule != null) - m_SpatialHashModule.Clear(); + if (this.HasProvider()) + this.ClearSpatialHash(); if (m_CollisionTester != null) UnityObjectUtils.Destroy(m_CollisionTester.gameObject); diff --git a/Runtime/Scripts/Modules/SceneObjectModule.cs b/Runtime/Scripts/Modules/SceneObjectModule.cs index 510522b2b..c22b0e4c1 100644 --- a/Runtime/Scripts/Modules/SceneObjectModule.cs +++ b/Runtime/Scripts/Modules/SceneObjectModule.cs @@ -3,7 +3,7 @@ using Unity.Labs.EditorXR.Interfaces; using Unity.Labs.EditorXR.Utilities; using Unity.Labs.ModuleLoader; -using Unity.Labs.SpatialHash.Interfaces; +using Unity.Labs.SpatialHash; using Unity.Labs.Utils; using UnityEditor; using UnityEngine; diff --git a/Runtime/Tools/AnnotationTool/AnnotationTool.cs b/Runtime/Tools/AnnotationTool/AnnotationTool.cs index 874ed6c7e..1dc7f637c 100644 --- a/Runtime/Tools/AnnotationTool/AnnotationTool.cs +++ b/Runtime/Tools/AnnotationTool/AnnotationTool.cs @@ -9,7 +9,7 @@ using Unity.Labs.EditorXR.Proxies; using Unity.Labs.EditorXR.Utilities; using Unity.Labs.ModuleLoader; -using Unity.Labs.SpatialHash.Interfaces; +using Unity.Labs.SpatialHash; using Unity.Labs.Utils; using UnityEditor; using UnityEngine; diff --git a/Runtime/Tools/CreatePrimitiveTool/CreatePrimitiveTool.cs b/Runtime/Tools/CreatePrimitiveTool/CreatePrimitiveTool.cs index 90b685ef6..2f0116e34 100644 --- a/Runtime/Tools/CreatePrimitiveTool/CreatePrimitiveTool.cs +++ b/Runtime/Tools/CreatePrimitiveTool/CreatePrimitiveTool.cs @@ -2,7 +2,7 @@ using Unity.Labs.EditorXR.Proxies; using Unity.Labs.EditorXR.Utilities; using Unity.Labs.ModuleLoader; -using Unity.Labs.SpatialHash.Interfaces; +using Unity.Labs.SpatialHash; using Unity.Labs.Utils; using UnityEditor; using UnityEngine; diff --git a/Runtime/Unity.Labs.EditorXR.asmdef b/Runtime/Unity.Labs.EditorXR.asmdef index 9c2f79e0f..cf44ad670 100644 --- a/Runtime/Unity.Labs.EditorXR.asmdef +++ b/Runtime/Unity.Labs.EditorXR.asmdef @@ -12,11 +12,15 @@ "Unity.Labs.ModuleLoader", "Unity.Labs.EditorXR.Interfaces", "UnityEngine.SpatialTracking", - "Unity.Labs.SpatialHash.Interfaces", - "Unity.Labs.SpatialHash" + "Unity.Labs.SpatialHash.Public" ], "optionalUnityReferences": [], "includePlatforms": [], "excludePlatforms": [], - "allowUnsafeCode": false + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [] } \ No newline at end of file diff --git a/Runtime/Workspaces/PolyWorkspace/Scripts/PolyGridItem.cs b/Runtime/Workspaces/PolyWorkspace/Scripts/PolyGridItem.cs index 6205e1eac..8e401ad75 100644 --- a/Runtime/Workspaces/PolyWorkspace/Scripts/PolyGridItem.cs +++ b/Runtime/Workspaces/PolyWorkspace/Scripts/PolyGridItem.cs @@ -9,7 +9,7 @@ using Unity.Labs.EditorXR.Proxies; using Unity.Labs.EditorXR.Utilities; using Unity.Labs.ModuleLoader; -using Unity.Labs.SpatialHash.Interfaces; +using Unity.Labs.SpatialHash; using Unity.Labs.Utils; using UnityEngine; using UnityEngine.InputNew; diff --git a/Runtime/Workspaces/ProjectWorkspace/Scripts/AssetGridItem.cs b/Runtime/Workspaces/ProjectWorkspace/Scripts/AssetGridItem.cs index 451bf2c28..f6ff0fe14 100644 --- a/Runtime/Workspaces/ProjectWorkspace/Scripts/AssetGridItem.cs +++ b/Runtime/Workspaces/ProjectWorkspace/Scripts/AssetGridItem.cs @@ -11,7 +11,7 @@ using Unity.Labs.EditorXR.Proxies; using Unity.Labs.EditorXR.Utilities; using Unity.Labs.ModuleLoader; -using Unity.Labs.SpatialHash.Interfaces; +using Unity.Labs.SpatialHash; using Unity.Labs.Utils; using UnityEditor; using UnityEngine;