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

Commit

Permalink
Updating Spatial Mapping course to Unity 5.5.0f3
Browse files Browse the repository at this point in the history
Updating Spatial Mapping 230 to Unity 5.5. Includes changes to the
HoloToolkit folder (now called 'HoloToolkit-SpatialMapping-230' and uses
namespace Academy.HoloToolkit.Unity) to distinguish it from the official
HoloToolkit found on GitHub.
  • Loading branch information
angelaHillier committed Dec 6, 2016
1 parent 4aea3d9 commit fc38186
Show file tree
Hide file tree
Showing 135 changed files with 531 additions and 395 deletions.

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

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

Expand Up @@ -3,7 +3,7 @@

using UnityEngine;

namespace HoloToolkit.Unity
namespace Academy.HoloToolkit.Unity
{
/// <summary>
/// 1. Decides when to show the cursor.
Expand Down
Expand Up @@ -4,7 +4,7 @@
using UnityEngine;
using UnityEngine.VR.WSA;

namespace HoloToolkit.Unity
namespace Academy.HoloToolkit.Unity
{
/// <summary>
/// GazeManager determines the location of the user's gaze, hit position and normals.
Expand Down
Expand Up @@ -4,7 +4,7 @@
using UnityEngine;
using UnityEngine.VR.WSA.Input;

namespace HoloToolkit.Unity
namespace Academy.HoloToolkit.Unity
{
/// <summary>
/// GestureManager creates a gesture recognizer and signs up for a tap gesture.
Expand Down
Expand Up @@ -4,7 +4,7 @@
using System.Collections.Generic;
using UnityEngine.VR.WSA.Input;

namespace HoloToolkit.Unity
namespace Academy.HoloToolkit.Unity
{
/// <summary>
/// HandsDetected determines if the hand is currently detected or not.
Expand Down
@@ -1,16 +1,29 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System.Collections.Generic;
using UnityEngine;

namespace HoloToolkit.Unity
namespace Academy.HoloToolkit.Unity
{
public class ObjectSurfaceObserver : SpatialMappingSource
{
[Tooltip("The room model to use when loading meshes in Unity.")]
public GameObject roomModel;

// Use this for initialization.
private void Start()
{
#if UNITY_EDITOR
// When in the Unity editor, try loading saved meshes from a model.
Load(roomModel);

if (GetMeshFilters().Count > 0)
{
SpatialMappingManager.Instance.SetSpatialMappingSource(this);
}
#endif
}

/// <summary>
/// Loads the SpatialMapping mesh from the specified room object.
/// </summary>
Expand All @@ -32,7 +45,7 @@ public void Load(GameObject roomModel)

foreach (MeshFilter filter in roomFilters)
{
GameObject surface = AddSurfaceObject(filter.sharedMesh, "roomMesh-" + surfaceObjects.Count, transform);
GameObject surface = AddSurfaceObject(filter.sharedMesh, "roomMesh-" + SurfaceObjects.Count, transform);
Renderer renderer = surface.GetComponent<MeshRenderer>();

if (SpatialMappingManager.Instance.DrawVisualMeshes == false)
Expand Down
@@ -1,9 +1,12 @@
using System;
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;

namespace HoloToolkit.Unity
namespace Academy.HoloToolkit.Unity
{
[StructLayout(LayoutKind.Sequential)]
public struct OrientedBoundingBox
Expand All @@ -19,6 +22,21 @@ public struct BoundedPlane
public Plane Plane;
public OrientedBoundingBox Bounds;
public float Area;

/// <summary>
/// Builds the bounded plane to match the obb defined by xform
/// </summary>
public BoundedPlane(Transform xform)
{
Plane = new Plane(xform.forward, xform.position);
Bounds = new OrientedBoundingBox()
{
Center = xform.position,
Extents = xform.localScale / 2,
Rotation = xform.rotation
};
Area = Bounds.Extents.x * Bounds.Extents.y;
}
};

public class PlaneFinding
Expand Down
@@ -1,9 +1,12 @@
using System;
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace HoloToolkit.Unity
namespace Academy.HoloToolkit.Unity
{
/// <summary>
/// RemoveSurfaceVertices will remove any vertices from the Spatial Mapping Mesh that fall within the bounding volume.
Expand Down Expand Up @@ -37,7 +40,7 @@ public class RemoveSurfaceVertices : Singleton<RemoveSurfaceVertices>
/// </summary>
private Queue<Bounds> boundingObjectsQueue;

#if UNITY_EDITOR
#if UNITY_EDITOR || UNITY_STANDALONE
/// <summary>
/// How much time (in sec), while running in the Unity Editor, to allow RemoveSurfaceVertices to consume before returning control to the main program.
/// </summary>
Expand Down Expand Up @@ -132,8 +135,15 @@ private IEnumerator RemoveSurfaceVerticesWithinBoundsRoutine()
}

Mesh mesh = filter.sharedMesh;

if (mesh != null || !mesh.bounds.Intersects(bounds))
MeshRenderer renderer = filter.GetComponent<MeshRenderer>();

// The mesh renderer bounds are in world space.
// If the mesh is null there is nothing to process
// If the renderer is null we can't get the renderer bounds
// If the renderer's bounds aren't contained inside of the current
// bounds from the bounds queue there is no reason to process
// If any of the above conditions are met, then we should go to the next meshfilter.
if (mesh == null || renderer == null || !renderer.bounds.Intersects(bounds))
{
// We don't need to do anything to this mesh, move to the next one.
continue;
Expand All @@ -146,7 +156,7 @@ private IEnumerator RemoveSurfaceVerticesWithinBoundsRoutine()
// Find which mesh vertices are within the bounds.
for (int i = 0; i < verts.Length; ++i)
{
if (bounds.Contains(verts[i]))
if (bounds.Contains(filter.transform.TransformPoint(verts[i])))
{
// These vertices are within bounds, so mark them for removal.
vertsToRemove.Add(i);
Expand Down
Expand Up @@ -4,7 +4,11 @@
using System.Collections.Generic;
using UnityEngine;

namespace HoloToolkit.Unity
#if UNITY_EDITOR
using UnityEditor;
#endif

namespace Academy.HoloToolkit.Unity
{
/// <summary>
/// The SpatialMappingManager class allows applications to use a SurfaceObserver or a stored
Expand Down Expand Up @@ -32,11 +36,6 @@ public partial class SpatialMappingManager : Singleton<SpatialMappingManager>
/// </summary>
private SpatialMappingObserver surfaceObserver;

/// <summary>
/// Used for loading spatial mapping data from a room model.
/// </summary>
private ObjectSurfaceObserver objectSurfaceObserver;

/// <summary>
/// Time when StartObserver() was called.
/// </summary>
Expand All @@ -49,36 +48,12 @@ public partial class SpatialMappingManager : Singleton<SpatialMappingManager>
public SpatialMappingSource Source { get; private set; }

// Called when the GameObject is first created.
private void Awake()
protected void Awake()
{
surfaceObserver = gameObject.GetComponent<SpatialMappingObserver>();
Source = surfaceObserver;
}

// Use for initialization.
private void Start()
{

#if !UNITY_EDITOR
StartObserver();
#endif

#if UNITY_EDITOR
objectSurfaceObserver = GetComponent<ObjectSurfaceObserver>();

if (objectSurfaceObserver != null)
{
// In the Unity editor, try loading saved meshes from a model.
objectSurfaceObserver.Load(objectSurfaceObserver.roomModel);

if (objectSurfaceObserver.GetMeshFilters().Count > 0)
{
SetSpatialMappingSource(objectSurfaceObserver);
}
}
#endif
}

/// <summary>
/// Returns the layer as a bit mask.
/// </summary>
Expand Down Expand Up @@ -197,6 +172,10 @@ public bool IsObserverRunning()
/// </summary>
public void StartObserver()
{
#if UNITY_EDITOR
// Allow observering if a device is present (Holographic Remoting)
if (!UnityEngine.VR.VRDevice.isPresent) return;
#endif
if (!IsObserverRunning())
{
surfaceObserver.StartObserving();
Expand All @@ -205,16 +184,28 @@ public void StartObserver()
}

/// <summary>
/// Instructs the SurfacesurfaceObserver to stop updating the SpatialMapping mesh.
/// Instructs the SurfaceObserver to stop updating the SpatialMapping mesh.
/// </summary>
public void StopObserver()
{
#if UNITY_EDITOR
// Allow observering if a device is present (Holographic Remoting)
if (!UnityEngine.VR.VRDevice.isPresent) return;
#endif
if (IsObserverRunning())
{
surfaceObserver.StopObserving();
}
}

/// <summary>
/// Instructs the SurfaceObserver to stop and cleanup all meshes.
/// </summary>
public void CleanupObserver()
{
surfaceObserver.CleanupObserver();
}

/// <summary>
/// Gets all meshes that are associated with the SpatialMapping mesh.
/// </summary>
Expand All @@ -236,6 +227,15 @@ public List<Mesh> GetMeshes()
return meshes;
}

/// <summary>
/// Gets all the surface objects associated with the Spatial Mapping mesh.
/// </summary>
/// <returns>Collection of SurfaceObjects.</returns>
public List<SpatialMappingSource.SurfaceObject> GetSurfaceObjects()
{
return Source.SurfaceObjects;
}

/// <summary>
/// Gets all Mesh Filter objects associated with the Spatial Mapping mesh.
/// </summary>
Expand Down Expand Up @@ -269,6 +269,7 @@ private void SetShadowCasting(bool castShadows)

/// <summary>
/// Updates the rendering state on the currently enabled surfaces.
/// Updates the material and shadow casting mode for each renderer.
/// </summary>
/// <param name="Enable">True, if meshes should be rendered.</param>
private void UpdateRendering(bool Enable)
Expand Down

0 comments on commit fc38186

Please sign in to comment.