Skip to content

Commit

Permalink
Update to latest Spatial Hash Module package
Browse files Browse the repository at this point in the history
  • Loading branch information
mtschoen-unity committed Feb 12, 2020
1 parent c48853a commit 5a57f9c
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Runtime/Actions/Duplicate.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Actions/Paste.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 6 additions & 13 deletions Runtime/Scripts/Core/EditorXRMiniWorldModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@
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;

namespace Unity.Labs.EditorXR.Core
{
class EditorXRMiniWorldModule : IModuleDependency<EditorXRToolModule>, IModuleDependency<EditorXRDirectSelectionModule>,
IModuleDependency<SpatialHashModule>, IModuleDependency<HighlightModule>, IModuleDependency<IntersectionModule>,
IModuleDependency<WorkspaceModule>, IModuleDependency<EditorXRRayModule>, IUsesPlaceSceneObjects, IUsesViewerScale,
IUsesSpatialHash, IUsesRayVisibilitySettings, IProvidesIsInMiniWorld
IModuleDependency<HighlightModule>, IModuleDependency<IntersectionModule>, IModuleDependency<WorkspaceModule>,
IModuleDependency<EditorXRRayModule>, IUsesPlaceSceneObjects, IUsesViewerScale, IUsesSpatialHash,
IUsesRayVisibilitySettings, IProvidesIsInMiniWorld
{
internal class MiniWorldRay
{
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<IProvidesSpatialHash>() ? this.GetAggregateBounds().size.MaxComponent() : 10f;
miniWorldWorkspace.zoomSliderMax = maxBounds / miniWorldWorkspace.contentBounds.size.MaxComponent();

var miniWorld = miniWorldWorkspace.miniWorld;
var worldID = m_Worlds.Count;
Expand Down
8 changes: 4 additions & 4 deletions Runtime/Scripts/Core/EditorXRViewerModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class EditorXRViewerModule : ScriptableSettings<EditorXRViewerModule>,
IModuleDependency<EditorXRDirectSelectionModule>, IInterfaceConnector,
ISerializePreferences, IUsesConnectInterfaces, IDelayedInitializationModule, IModuleBehaviorCallbacks,
IUsesFunctionalityInjection, IProvidesViewerScale, IProvidesViewerBody, IProvidesMoveCameraRig,
IProvidesGetVRPlayerObjects
IProvidesGetVRPlayerObjects, IUsesSpatialHash
{
[Serializable]
class Preferences
Expand Down Expand Up @@ -101,6 +101,7 @@ public float cameraRigScale
#if !FI_AUTOFILL
IProvidesFunctionalityInjection IFunctionalitySubscriber<IProvidesFunctionalityInjection>.provider { get; set; }
IProvidesConnectInterfaces IFunctionalitySubscriber<IProvidesConnectInterfaces>.provider { get; set; }
IProvidesSpatialHash IFunctionalitySubscriber<IProvidesSpatialHash>.provider { get; set; }
#endif

public void ConnectDependency(EditorXRDirectSelectionModule dependency)
Expand Down Expand Up @@ -242,9 +243,8 @@ void AddPlayerModel()
{
m_PlayerBody = EditorXRUtils.Instantiate(m_PlayerModelPrefab, CameraUtils.GetMainCamera().transform, false).GetComponent<PlayerBody>();
this.InjectFunctionalitySingle(m_PlayerBody);
var spatialHashModule = ModuleLoaderCore.instance.GetModule<SpatialHashModule>();
if (spatialHashModule != null)
spatialHashModule.AddRenderer(m_PlayerBody.GetComponent<Renderer>());
if (this.HasProvider<IProvidesSpatialHash>())
this.AddRendererToSpatialHash(m_PlayerBody.GetComponent<Renderer>());

var playerObjects = m_PlayerBody.GetComponentsInChildren<Renderer>(true);
foreach (var playerObject in playerObjects)
Expand Down
21 changes: 9 additions & 12 deletions Runtime/Scripts/Modules/IntersectionModule/IntersectionModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Unity.Labs.EditorXR.Modules
{
sealed class IntersectionModule : ScriptableSettings<IntersectionModule>, IDelayedInitializationModule, IModuleBehaviorCallbacks,
IUsesGameObjectLocking, IUsesGetVRPlayerObjects, IProvidesSceneRaycast, IProvidesControlInputIntersection,
IProvidesContainsVRPlayerCompletely, IProvidesCheckSphere, IProvidesCheckBounds
IProvidesContainsVRPlayerCompletely, IProvidesCheckSphere, IProvidesCheckBounds, IUsesSpatialHash
{
class RayIntersection
{
Expand Down Expand Up @@ -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<IProvidesGameObjectLocking>.provider { get; set; }
IProvidesGetVRPlayerObjects IFunctionalitySubscriber<IProvidesGetVRPlayerObjects>.provider { get; set; }
IProvidesSpatialHash IFunctionalitySubscriber<IProvidesSpatialHash>.provider { get; set; }
#endif

// Local method use only -- created here to reduce garbage collection. Collections must be cleared before use
Expand All @@ -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<SpatialHashModule>();
}

public void UnloadModule() { }
Expand All @@ -78,10 +76,10 @@ public void Initialize()
collisionTesterObject.transform.SetParent(moduleParent.transform, false);
m_CollisionTester = collisionTesterObject.AddComponent<MeshCollider>();

if (m_SpatialHashModule != null)
if (this.HasProvider<IProvidesSpatialHash>())
{
m_SpatialHashModule.Clear();
m_SpatialHashContainer = m_SpatialHashModule.GetOrCreateContainer<Renderer>();
this.ClearSpatialHash();
m_SpatialHashContainer = this.GetOrCreateSpatialHashContainer<Renderer>();
}

m_IntersectedObjects.Clear();
Expand Down Expand Up @@ -124,7 +122,7 @@ void SetupObjects()
}
}

m_SpatialHashModule.AddRenderers(k_Renderers);
this.AddRenderersToSpatialHash(k_Renderers);
}

IEnumerator UpdateDynamicObjects()
Expand All @@ -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;
Expand All @@ -161,8 +158,8 @@ IEnumerator UpdateDynamicObjects()
public void Shutdown()
{
EditorMonoBehaviour.instance.StopCoroutine(m_UpdateCoroutine);
if (m_SpatialHashModule != null)
m_SpatialHashModule.Clear();
if (this.HasProvider<IProvidesSpatialHash>())
this.ClearSpatialHash();

if (m_CollisionTester != null)
UnityObjectUtils.Destroy(m_CollisionTester.gameObject);
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Scripts/Modules/SceneObjectModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Tools/AnnotationTool/AnnotationTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Tools/CreatePrimitiveTool/CreatePrimitiveTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 7 additions & 3 deletions Runtime/Unity.Labs.EditorXR.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -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": []
}
2 changes: 1 addition & 1 deletion Runtime/Workspaces/PolyWorkspace/Scripts/PolyGridItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 5a57f9c

Please sign in to comment.