Skip to content

Commit f825a57

Browse files
Stephen Hodgsonkeveleigh
authored andcommitted
Htk spatial mapping refactor (#403)
* [ ! ] Spatial Mapping Refactor. No files removed, only namespaces changed in scripts and files rearranged. * Removed Shader Will be introduced in a later PR * Removed unused meta file * Added missing SRMesh obj * Updated SpatialMapping/Readme Fixed path links for tests/scenes * Updated SpatialMapping/Readme.md Updated documentation about TapToPlace.cs Test/Scripts * Fixed links in SpatialMapping/Readme * Reverted SpatialMapping/Readme TapToPlace Changes * Moved TapToPlace back into SpatialMapping/Scripts folder * Optimizations and fixes to hidden members in SpatialMappingManager, and sorted access modifiers in SpatialMappingSource. * Updated ObjectSurfaceObserver.cs: Fixed naming of public variable RoomModel, and hidden names. * FileSurfaceObserver.cs fixed hidden property names. * SpatialMappingObserver: fixed property name hiding. * More fixes for hidden parameters. * SpatialMappingSource.cs: fixed hidden parameter warning * Serialized some fields in SpatialMappingManager and exposed them in the inspector while keeping proper access modifiers. minor formatting changes to SpatialMappingObserver. Updated access modifiers in RemoteMeshTarget, with minor formatting changes.
1 parent b8e74e1 commit f825a57

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+127114
-127068
lines changed

Assets/HoloToolkit/SpatialMapping/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ A basic occlusion shader that can be used to occlude objects behind spatial mapp
153153
#### Wireframe.shader
154154
A basic wire frame shader that can be used for rendering spatial mapping meshes. Use SpatialMappingManager.SetSurfaceMaterial() to use this material with the spatial mapping data.
155155

156-
### [Tests](Tests)
156+
### [Tests Scenes](Tests/Scenes)
157157

158158
#### PlaneFinding.unity
159159
To use this sample code, load the PlaneFinding scene and hit Play. The PlaneFinding algorithm will run in a loop. Switch to the scene view to see a visualization of the planes found.
@@ -178,4 +178,4 @@ This scene is the minimum setup to use the TapToPlace script. It includes GazeM
178178

179179
---
180180
##### [Go back up to the table of contents.](../../../README.md)
181-
---
181+
---

Assets/HoloToolkit/SpatialMapping/Scripts/ObjectSurfaceObserver.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

44
using UnityEngine;
5+
using UnityEngine.Rendering;
56

6-
namespace HoloToolkit.Unity
7+
namespace HoloToolkit.Unity.SpatialMapping
78
{
89
public class ObjectSurfaceObserver : SpatialMappingSource
910
{
1011
[Tooltip("The room model to use when loading meshes in Unity.")]
11-
public GameObject roomModel;
12+
public GameObject RoomModel;
1213

1314
// Use this for initialization.
1415
private void Start()
1516
{
1617
#if UNITY_EDITOR
1718
// When in the Unity editor, try loading saved meshes from a model.
18-
Load(roomModel);
19+
Load(RoomModel);
1920

2021
if (GetMeshFilters().Count > 0)
2122
{
@@ -36,7 +37,7 @@ public void Load(GameObject roomModel)
3637
return;
3738
}
3839

39-
GameObject roomObject = GameObject.Instantiate(roomModel);
40+
GameObject roomObject = Instantiate(roomModel);
4041
Cleanup();
4142

4243
try
@@ -46,25 +47,25 @@ public void Load(GameObject roomModel)
4647
foreach (MeshFilter filter in roomFilters)
4748
{
4849
GameObject surface = AddSurfaceObject(filter.sharedMesh, "roomMesh-" + SurfaceObjects.Count, transform);
49-
Renderer renderer = surface.GetComponent<MeshRenderer>();
50+
Renderer meshRenderer = surface.GetComponent<MeshRenderer>();
5051

5152
if (SpatialMappingManager.Instance.DrawVisualMeshes == false)
5253
{
53-
renderer.enabled = false;
54+
meshRenderer.enabled = false;
5455
}
5556

5657
if (SpatialMappingManager.Instance.CastShadows == false)
5758
{
58-
renderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
59+
meshRenderer.shadowCastingMode = ShadowCastingMode.Off;
5960
}
6061

6162
// Reset the surface mesh collider to fit the updated mesh.
6263
// Unity tribal knowledge indicates that to change the mesh assigned to a
6364
// mesh collider, the mesh must first be set to null. Presumably there
6465
// is a side effect in the setter when setting the shared mesh to null.
65-
MeshCollider collider = surface.GetComponent<MeshCollider>();
66-
collider.sharedMesh = null;
67-
collider.sharedMesh = surface.GetComponent<MeshFilter>().sharedMesh;
66+
MeshCollider meshCollider = surface.GetComponent<MeshCollider>();
67+
meshCollider.sharedMesh = null;
68+
meshCollider.sharedMesh = surface.GetComponent<MeshFilter>().sharedMesh;
6869
}
6970
}
7071
catch
@@ -73,9 +74,9 @@ public void Load(GameObject roomModel)
7374
}
7475
finally
7576
{
76-
if (roomModel != null && roomObject != null)
77+
if (roomObject != null)
7778
{
78-
GameObject.DestroyImmediate(roomObject);
79+
DestroyImmediate(roomObject);
7980
}
8081
}
8182
}

Assets/HoloToolkit/SpatialMapping/Scripts/RemoteMapping/FileSurfaceObserver.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.Collections.Generic;
55
using UnityEngine;
66

7-
namespace HoloToolkit.Unity
7+
namespace HoloToolkit.Unity.SpatialMapping
88
{
99
public class FileSurfaceObserver : SpatialMappingSource
1010
{
@@ -39,25 +39,25 @@ public void Load(string fileName)
3939
foreach (Mesh mesh in storedMeshes)
4040
{
4141
GameObject surface = AddSurfaceObject(mesh, "storedmesh-" + SurfaceObjects.Count, transform);
42-
Renderer renderer = surface.GetComponent<MeshRenderer>();
42+
Renderer meshRenderer = surface.GetComponent<MeshRenderer>();
4343

4444
if (SpatialMappingManager.Instance.DrawVisualMeshes == false)
4545
{
46-
renderer.enabled = false;
46+
meshRenderer.enabled = false;
4747
}
4848

4949
if (SpatialMappingManager.Instance.CastShadows == false)
5050
{
51-
renderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
51+
meshRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
5252
}
5353

5454
// Reset the surface mesh collider to fit the updated mesh.
5555
// Unity tribal knowledge indicates that to change the mesh assigned to a
5656
// mesh collider, the mesh must first be set to null. Presumably there
5757
// is a side effect in the setter when setting the shared mesh to null.
58-
MeshCollider collider = surface.GetComponent<MeshCollider>();
59-
collider.sharedMesh = null;
60-
collider.sharedMesh = surface.GetComponent<MeshFilter>().mesh;
58+
MeshCollider meshCollider = surface.GetComponent<MeshCollider>();
59+
meshCollider.sharedMesh = null;
60+
meshCollider.sharedMesh = surface.GetComponent<MeshFilter>().mesh;
6161
}
6262
}
6363
catch

Assets/HoloToolkit/SpatialMapping/Scripts/RemoteMapping/MeshSaver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
using Windows.Storage;
1212
#endif
1313

14-
namespace HoloToolkit.Unity
14+
namespace HoloToolkit.Unity.SpatialMapping
1515
{
1616
/// <summary>
1717
/// MeshSaver is a static class containing methods used for saving and loading meshes.

Assets/HoloToolkit/SpatialMapping/Scripts/RemoteMapping/RemoteMappingManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using UnityEngine;
77
using UnityEngine.Windows.Speech;
88

9-
namespace HoloToolkit.Unity
9+
namespace HoloToolkit.Unity.SpatialMapping
1010
{
1111
[RequireComponent(typeof(RemoteMeshTarget))]
1212
public partial class RemoteMappingManager : Singleton<RemoteMappingManager>

Assets/HoloToolkit/SpatialMapping/Scripts/RemoteMapping/RemoteMeshSource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
using Windows.Foundation;
1212
#endif
1313

14-
namespace HoloToolkit.Unity
14+
namespace HoloToolkit.Unity.SpatialMapping
1515
{
1616
/// <summary>
1717
/// RemoteMeshSource will try to send meshes from the HoloLens to a remote system that is running the Unity editor.

Assets/HoloToolkit/SpatialMapping/Scripts/RemoteMapping/RemoteMeshTarget.cs

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

4-
using System.Collections.Generic;
54
using System;
5+
using System.Collections.Generic;
66
using System.IO;
7-
using UnityEngine;
8-
97
#if UNITY_EDITOR || UNITY_STANDALONE
108
using System.Net;
119
using System.Net.Sockets;
1210
#endif
11+
using UnityEngine;
12+
using UnityEngine.Rendering;
1313

14-
namespace HoloToolkit.Unity
14+
namespace HoloToolkit.Unity.SpatialMapping
1515
{
1616
/// <summary>
1717
/// RemoteMeshTarget will listen for meshes being sent from a remote system (HoloLens).
@@ -40,26 +40,26 @@ public class RemoteMeshTarget : SpatialMappingSource
4040
/// <summary>
4141
/// Tracks if a client is connected.
4242
/// </summary>
43-
private bool ClientConnected = false;
43+
private bool clientConnected;
4444

4545
// Use this for initialization.
46-
void Start()
46+
private void Start()
4747
{
4848
// Setup the network listener.
4949
IPAddress localAddr = IPAddress.Parse(ServerIP.Trim());
5050
networkListener = new TcpListener(localAddr, ConnectionPort);
5151
networkListener.Start();
5252

5353
// Request the network listener to wait for connections asynchronously.
54-
AsyncCallback callback = new AsyncCallback(OnClientConnect);
54+
AsyncCallback callback = OnClientConnect;
5555
networkListener.BeginAcceptTcpClient(callback, this);
5656
}
5757

5858
// Update is called once per frame.
59-
void Update()
59+
private void Update()
6060
{
6161
// If we have a connected client, presumably the client wants to send some meshes.
62-
if (ClientConnected)
62+
if (clientConnected)
6363
{
6464
// Get the clients stream.
6565
NetworkStream stream = networkClient.GetStream();
@@ -103,16 +103,16 @@ void Update()
103103

104104
if (SpatialMappingManager.Instance.CastShadows == false)
105105
{
106-
surface.GetComponent<MeshRenderer>().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
106+
surface.GetComponent<MeshRenderer>().shadowCastingMode = ShadowCastingMode.Off;
107107
}
108108
}
109109

110110
// Finally disconnect.
111-
ClientConnected = false;
111+
clientConnected = false;
112112
networkClient.Close();
113113

114114
// And wait for the next connection.
115-
AsyncCallback callback = new AsyncCallback(OnClientConnect);
115+
AsyncCallback callback = OnClientConnect;
116116
networkListener.BeginAcceptTcpClient(callback, this);
117117
}
118118
}
@@ -123,7 +123,7 @@ void Update()
123123
/// </summary>
124124
/// <param name="stream">The stream to read the bytes from.</param>
125125
/// <returns>An integer representing the bytes.</returns>
126-
int ReadInt(Stream stream)
126+
private int ReadInt(Stream stream)
127127
{
128128
// The bytes arrive in the wrong order, so swap them.
129129
byte[] bytes = new byte[4];
@@ -144,15 +144,15 @@ int ReadInt(Stream stream)
144144
/// Called when a client connects.
145145
/// </summary>
146146
/// <param name="result">The result of the connection.</param>
147-
void OnClientConnect(IAsyncResult result)
147+
private void OnClientConnect(IAsyncResult result)
148148
{
149149
if (result.IsCompleted)
150150
{
151151
networkClient = networkListener.EndAcceptTcpClient(result);
152152
if (networkClient != null)
153153
{
154154
Debug.Log("Connected");
155-
ClientConnected = true;
155+
clientConnected = true;
156156
}
157157
}
158158
}

Assets/HoloToolkit/SpatialMapping/Scripts/RemoteMapping/SimpleMeshSerializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using System.IO;
77
using UnityEngine;
88

9-
namespace HoloToolkit.Unity
9+
namespace HoloToolkit.Unity.SpatialMapping
1010
{
1111
/// <summary>
1212
/// SimpleMeshSerializer converts a UnityEngine.Mesh object to and from an array of bytes.

0 commit comments

Comments
 (0)