From 38b419ce6b87623cd91735d1fbb81ea1c25dab95 Mon Sep 17 00:00:00 2001 From: Angela Hillier Date: Mon, 1 Aug 2016 15:34:19 -0700 Subject: [PATCH] Spatial Mapping updates (issue #146) This commit addresses issue #146. The SpatialMappingComponent folder is no longer needed in the HoloToolkit, because these components (SpatialMappingRenderer and SpatialMappingCollider) are now built into Unity. However, providing a basic sample scene is useful to show how to use the components, so I moved the old test scene into the new HoloToolit-Examples folder and updated it to use the new built-in Unity components. --- .../Editor.meta => HoloToolkit-Examples.meta} | 4 +- .../README.md.meta} | 5 +- .../SpatialMappingComponent.meta | 0 .../SpatialMappingComponent/DropCube.cs | 0 .../SpatialMappingComponent/DropCube.cs.meta | 0 .../SpatialMappingComponent/Example.unity | 74 +-- .../Example.unity.meta | 0 .../SpatialMappingComponent/README.md | 24 + .../SpatialMappingComponent/README.md.meta} | 5 +- .../Editor/SpatialMappingColliderInspector.cs | 52 -- .../SpatialMappingColliderInspector.cs.meta | 12 - .../Editor/SpatialMappingRendererInspector.cs | 60 -- .../SpatialMappingRendererInspector.cs.meta | 12 - .../SpatialMappingCollider.cs | 88 --- .../SpatialMappingCollider.cs.meta | 12 - .../SpatialMappingRenderer.cs | 153 ----- .../SpatialMappingRenderer.cs.meta | 12 - .../Support/SMBaseAbstract.cs | 602 ------------------ .../Support/SMBaseAbstract.cs.meta | 12 - ProjectSettings/GraphicsSettings.asset | 19 +- ProjectSettings/ProjectSettings.asset | 3 + ProjectSettings/ProjectVersion.txt | 2 +- README.md | 61 -- 23 files changed, 78 insertions(+), 1134 deletions(-) rename Assets/{HoloToolkit/SpatialMapping/Editor.meta => HoloToolkit-Examples.meta} (67%) rename Assets/{HoloToolkit/SpatialMapping/Scripts/SpatialMappingComponent/Support.meta => HoloToolkit-Examples/README.md.meta} (58%) rename Assets/{HoloToolkit/SpatialMapping/Tests => HoloToolkit-Examples}/SpatialMappingComponent.meta (100%) rename Assets/{HoloToolkit/SpatialMapping/Tests => HoloToolkit-Examples}/SpatialMappingComponent/DropCube.cs (100%) rename Assets/{HoloToolkit/SpatialMapping/Tests => HoloToolkit-Examples}/SpatialMappingComponent/DropCube.cs.meta (100%) rename Assets/{HoloToolkit/SpatialMapping/Tests => HoloToolkit-Examples}/SpatialMappingComponent/Example.unity (88%) rename Assets/{HoloToolkit/SpatialMapping/Tests => HoloToolkit-Examples}/SpatialMappingComponent/Example.unity.meta (100%) create mode 100644 Assets/HoloToolkit-Examples/SpatialMappingComponent/README.md rename Assets/{HoloToolkit/SpatialMapping/Scripts/SpatialMappingComponent.meta => HoloToolkit-Examples/SpatialMappingComponent/README.md.meta} (58%) delete mode 100644 Assets/HoloToolkit/SpatialMapping/Editor/SpatialMappingColliderInspector.cs delete mode 100644 Assets/HoloToolkit/SpatialMapping/Editor/SpatialMappingColliderInspector.cs.meta delete mode 100644 Assets/HoloToolkit/SpatialMapping/Editor/SpatialMappingRendererInspector.cs delete mode 100644 Assets/HoloToolkit/SpatialMapping/Editor/SpatialMappingRendererInspector.cs.meta delete mode 100644 Assets/HoloToolkit/SpatialMapping/Scripts/SpatialMappingComponent/SpatialMappingCollider.cs delete mode 100644 Assets/HoloToolkit/SpatialMapping/Scripts/SpatialMappingComponent/SpatialMappingCollider.cs.meta delete mode 100644 Assets/HoloToolkit/SpatialMapping/Scripts/SpatialMappingComponent/SpatialMappingRenderer.cs delete mode 100644 Assets/HoloToolkit/SpatialMapping/Scripts/SpatialMappingComponent/SpatialMappingRenderer.cs.meta delete mode 100644 Assets/HoloToolkit/SpatialMapping/Scripts/SpatialMappingComponent/Support/SMBaseAbstract.cs delete mode 100644 Assets/HoloToolkit/SpatialMapping/Scripts/SpatialMappingComponent/Support/SMBaseAbstract.cs.meta diff --git a/Assets/HoloToolkit/SpatialMapping/Editor.meta b/Assets/HoloToolkit-Examples.meta similarity index 67% rename from Assets/HoloToolkit/SpatialMapping/Editor.meta rename to Assets/HoloToolkit-Examples.meta index 764ef9ccc71..b1aeb1f3ef1 100644 --- a/Assets/HoloToolkit/SpatialMapping/Editor.meta +++ b/Assets/HoloToolkit-Examples.meta @@ -1,7 +1,7 @@ fileFormatVersion: 2 -guid: 59a021118f316f6439daac3bcd6d7032 +guid: 16df83dcd3a639747aa947b3378d0cc0 folderAsset: yes -timeCreated: 1460418045 +timeCreated: 1470084529 licenseType: Pro DefaultImporter: userData: diff --git a/Assets/HoloToolkit/SpatialMapping/Scripts/SpatialMappingComponent/Support.meta b/Assets/HoloToolkit-Examples/README.md.meta similarity index 58% rename from Assets/HoloToolkit/SpatialMapping/Scripts/SpatialMappingComponent/Support.meta rename to Assets/HoloToolkit-Examples/README.md.meta index a967ff97a76..563ba8ba086 100644 --- a/Assets/HoloToolkit/SpatialMapping/Scripts/SpatialMappingComponent/Support.meta +++ b/Assets/HoloToolkit-Examples/README.md.meta @@ -1,7 +1,6 @@ fileFormatVersion: 2 -guid: 842eca2cee724724e946a2c0f37e64f8 -folderAsset: yes -timeCreated: 1458842124 +guid: 31b8a47ee28438d479567ace43f86def +timeCreated: 1470084530 licenseType: Pro DefaultImporter: userData: diff --git a/Assets/HoloToolkit/SpatialMapping/Tests/SpatialMappingComponent.meta b/Assets/HoloToolkit-Examples/SpatialMappingComponent.meta similarity index 100% rename from Assets/HoloToolkit/SpatialMapping/Tests/SpatialMappingComponent.meta rename to Assets/HoloToolkit-Examples/SpatialMappingComponent.meta diff --git a/Assets/HoloToolkit/SpatialMapping/Tests/SpatialMappingComponent/DropCube.cs b/Assets/HoloToolkit-Examples/SpatialMappingComponent/DropCube.cs similarity index 100% rename from Assets/HoloToolkit/SpatialMapping/Tests/SpatialMappingComponent/DropCube.cs rename to Assets/HoloToolkit-Examples/SpatialMappingComponent/DropCube.cs diff --git a/Assets/HoloToolkit/SpatialMapping/Tests/SpatialMappingComponent/DropCube.cs.meta b/Assets/HoloToolkit-Examples/SpatialMappingComponent/DropCube.cs.meta similarity index 100% rename from Assets/HoloToolkit/SpatialMapping/Tests/SpatialMappingComponent/DropCube.cs.meta rename to Assets/HoloToolkit-Examples/SpatialMappingComponent/DropCube.cs.meta diff --git a/Assets/HoloToolkit/SpatialMapping/Tests/SpatialMappingComponent/Example.unity b/Assets/HoloToolkit-Examples/SpatialMappingComponent/Example.unity similarity index 88% rename from Assets/HoloToolkit/SpatialMapping/Tests/SpatialMappingComponent/Example.unity rename to Assets/HoloToolkit-Examples/SpatialMappingComponent/Example.unity index 336cc5e3321..3a34ae0d20d 100644 --- a/Assets/HoloToolkit/SpatialMapping/Tests/SpatialMappingComponent/Example.unity +++ b/Assets/HoloToolkit-Examples/SpatialMappingComponent/Example.unity @@ -178,21 +178,22 @@ MonoBehaviour: m_GameObject: {fileID: 387044609} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 53755a21bd4f3454981c6de4efdfec5d, type: 3} + m_Script: {fileID: 247442469, guid: f7b54ff4a43d4fcf81b4538b678e0bcc, type: 3} m_Name: m_EditorClassIdentifier: - FreezeMeshUpdates: 0 - UseSphereBounds: 0 - Extents: {x: 5, y: 5, z: 5} - SphereRadius: 10 - _levelOfDetailSet: 1 - _levelOfDetail: 2 - TimeBetweenUpdates: 2.5 - NumUpdatesBeforeRemoval: 10 - MeshLayer: + m_SurfaceParent: {fileID: 387044609} + m_FreezeUpdates: 0 + m_Volume: 1 + m_SphereRadiusMeters: 2 + m_BoxExtentsMeters: {x: 5, y: 5, z: 5} + m_LOD: 2 + m_NumUpdatesBeforeRemoval: 10 + m_SecondsBetweenUpdates: 2.5 + m_Layer: serializedVersion: 2 - m_Bits: 0 - PhysicMaterial: {fileID: 0} + m_Bits: 1 + m_Material: {fileID: 0} + m_EnableCollisions: 1 --- !u!1 &428511244 GameObject: m_ObjectHideFlags: 0 @@ -285,20 +286,20 @@ MonoBehaviour: m_GameObject: {fileID: 1783506190} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 6ca2f6b8dee51ea4bb59100b8f16fc1f, type: 3} + m_Script: {fileID: -594688902, guid: f7b54ff4a43d4fcf81b4538b678e0bcc, type: 3} m_Name: m_EditorClassIdentifier: - FreezeMeshUpdates: 0 - UseSphereBounds: 0 - Extents: {x: 5, y: 5, z: 5} - SphereRadius: 10 - _levelOfDetailSet: 1 - _levelOfDetail: 1 - TimeBetweenUpdates: 2.5 - NumUpdatesBeforeRemoval: 10 - _currentRenderingSetting: 1 - _renderingMaterial: {fileID: 2100000, guid: d698790d3facd3d4289a13fa1243030a, type: 2} - _occlusionMaterial: {fileID: 2100000, guid: df172103f5fba4a4d8636aeca60cb0d7, type: 2} + m_SurfaceParent: {fileID: 0} + m_FreezeUpdates: 0 + m_Volume: 1 + m_SphereRadiusMeters: 2 + m_BoxExtentsMeters: {x: 5, y: 5, z: 5} + m_LOD: 1 + m_NumUpdatesBeforeRemoval: 10 + m_SecondsBetweenUpdates: 2.5 + m_CurrentRenderSetting: 2 + m_CustomMaterial: {fileID: 15303, guid: 0000000000000000f000000000000000, type: 0} + m_OcclusionMaterial: {fileID: 15302, guid: 0000000000000000f000000000000000, type: 0} --- !u!114 &1783506192 MonoBehaviour: m_ObjectHideFlags: 0 @@ -307,21 +308,22 @@ MonoBehaviour: m_GameObject: {fileID: 1783506190} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 53755a21bd4f3454981c6de4efdfec5d, type: 3} + m_Script: {fileID: 247442469, guid: f7b54ff4a43d4fcf81b4538b678e0bcc, type: 3} m_Name: m_EditorClassIdentifier: - FreezeMeshUpdates: 0 - UseSphereBounds: 1 - Extents: {x: 10, y: 10, z: 10} - SphereRadius: 5 - _levelOfDetailSet: 1 - _levelOfDetail: 2 - TimeBetweenUpdates: 2.5 - NumUpdatesBeforeRemoval: 10 - MeshLayer: + m_SurfaceParent: {fileID: 0} + m_FreezeUpdates: 0 + m_Volume: 0 + m_SphereRadiusMeters: 5 + m_BoxExtentsMeters: {x: 4, y: 4, z: 4} + m_LOD: 2 + m_NumUpdatesBeforeRemoval: 10 + m_SecondsBetweenUpdates: 2.5 + m_Layer: serializedVersion: 2 - m_Bits: 0 - PhysicMaterial: {fileID: 0} + m_Bits: 1 + m_Material: {fileID: 0} + m_EnableCollisions: 1 --- !u!81 &1783506193 AudioListener: m_ObjectHideFlags: 0 diff --git a/Assets/HoloToolkit/SpatialMapping/Tests/SpatialMappingComponent/Example.unity.meta b/Assets/HoloToolkit-Examples/SpatialMappingComponent/Example.unity.meta similarity index 100% rename from Assets/HoloToolkit/SpatialMapping/Tests/SpatialMappingComponent/Example.unity.meta rename to Assets/HoloToolkit-Examples/SpatialMappingComponent/Example.unity.meta diff --git a/Assets/HoloToolkit-Examples/SpatialMappingComponent/README.md b/Assets/HoloToolkit-Examples/SpatialMappingComponent/README.md new file mode 100644 index 00000000000..8743cc18edc --- /dev/null +++ b/Assets/HoloToolkit-Examples/SpatialMappingComponent/README.md @@ -0,0 +1,24 @@ +# SpatialMappingComponent Example +This example shows how to use the built-in Unity components for spatial mapping: SpatialMappingRenderer and SpatialMappingCollider. It shows an example of a static play space which preserves physics around it (marked by a cube) while maintaining physics and wire frame rendering of Spatial Mapping around the camera. + +Additionally, you can tap to drop a cube in front of the camera with a Rigidbody component to interact with physics. As you drop cubes, you will notice that only the cubes that are dropped within the static play space will maintain a connection with the floor. If you wander too far from the static play space, cubes dropped outside of the space will eventually fall through the floor and disappear as you walk away from them. + +#### SpatialMappingCollider: +Use this component for performing physics collisions with the Spatial Mapping mesh. + +The example scene contains two 'SpatialMappingCollider' components. One is attached to the MainCamera object, and the second is attached to the 'StaticPlaySpaceLocation' object. As the user moves around, they can perform an 'air tap' gesture to drop cubes on the floor. + +#### SpatialMappingRenderer: +Use this component for rendering the Spatial Mapping mesh. + +The example scene has a 'SpatialMappingRenderer' attached to the MainCamera object. As the user moves around, a wireframe mesh will appear wherever they go. The color of the mesh will change based on distance from user. + +#### Design Considerations + +1. If you want spatial mapping to work wherever the user travels, attach the components to the camera and the specified bounds will move with the user. +2. If you want collisions to continue working even after walking away, you may want to leave a second SpatialMappingCollider around the play space where collisions should continue. +3. If you want physics collisions and to render the Spatial Mapping mesh for an area, you should add both a SpatialMappingCollider and a SpatialMappingRenderer + +Though all of the defaults are usable out of the box with no customization, you can also customize the component to your scenario. Through script, additions such as PlaneFinding.cs can also be used with these components. + +These components by default implement caching of removed Spatial Mapping meshes such that removed meshes will still be present for at least 10 updates after they are actually removed. This number and the feature can be configured via script. This feature enables mesh a great distance from the user to not be removed as well as quick re-hydration of mesh only removed as a user moved away and back to a single location. \ No newline at end of file diff --git a/Assets/HoloToolkit/SpatialMapping/Scripts/SpatialMappingComponent.meta b/Assets/HoloToolkit-Examples/SpatialMappingComponent/README.md.meta similarity index 58% rename from Assets/HoloToolkit/SpatialMapping/Scripts/SpatialMappingComponent.meta rename to Assets/HoloToolkit-Examples/SpatialMappingComponent/README.md.meta index da7f1c9e4ce..7a8fd6c66bf 100644 --- a/Assets/HoloToolkit/SpatialMapping/Scripts/SpatialMappingComponent.meta +++ b/Assets/HoloToolkit-Examples/SpatialMappingComponent/README.md.meta @@ -1,7 +1,6 @@ fileFormatVersion: 2 -guid: ddd7617ab2dc8f04ab445ff726acd687 -folderAsset: yes -timeCreated: 1460418045 +guid: bd03a477af7d4904eb8832a680f91ef8 +timeCreated: 1470089537 licenseType: Pro DefaultImporter: userData: diff --git a/Assets/HoloToolkit/SpatialMapping/Editor/SpatialMappingColliderInspector.cs b/Assets/HoloToolkit/SpatialMapping/Editor/SpatialMappingColliderInspector.cs deleted file mode 100644 index 679976a1a57..00000000000 --- a/Assets/HoloToolkit/SpatialMapping/Editor/SpatialMappingColliderInspector.cs +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See LICENSE in the project root for license information. - -#if UNITY_EDITOR -using UnityEngine; -using UnityEditor; -using System.Collections; - -[CustomEditor(typeof(SpatialMappingCollider))] -public class SpatialMappingColliderInspector : Editor -{ - /// - /// The SpatialMappingCollider we are adjusting the settings for - /// - private SpatialMappingCollider _collider; - - void OnEnable() - { - _collider = target as SpatialMappingCollider; - } - - public override void OnInspectorGUI() - { - _collider.EnableCollisions = EditorGUILayout.Toggle(new GUIContent("Enable Collisions", "Toggles whether colliders are enabled on mesh"), _collider.EnableCollisions); - _collider.PhysicMaterial = (PhysicMaterial)EditorGUILayout.ObjectField(new GUIContent("Physic Material", "Material describing the physical properties of the mesh"), _collider.PhysicMaterial, typeof(PhysicMaterial), false); - _collider.MeshLayer = EditorGUILayout.LayerField(new GUIContent("Physics Layer", "The layer to be used for raycasts into the mesh"), _collider.MeshLayer); - - _collider.FreezeMeshUpdates = EditorGUILayout.Toggle(new GUIContent("Freeze Mesh Updates", ""), _collider.FreezeMeshUpdates); - GUIContent[] boundsChoices = { new GUIContent("Bounding Box"), new GUIContent("Sphere") }; - int currentChoice = _collider.UseSphereBounds ? 1 : 0; - int choice = EditorGUILayout.Popup(new GUIContent("Bounding Volume", "The shape of the bounds for the observed region"), currentChoice, boundsChoices); - switch (choice) - { - case 0: - _collider.UseSphereBounds = false; - _collider.Extents = EditorGUILayout.Vector3Field(new GUIContent("Extents", "The extents of the observation volume"), _collider.Extents); - break; - case 1: - _collider.UseSphereBounds = true; - _collider.SphereRadius = EditorGUILayout.FloatField(new GUIContent("Radius", "The radius of the observation sphere volume"), _collider.SphereRadius); - break; - default: - throw new System.Exception("Unexpected option!"); - } - - GUIContent[] lodChoices = { new GUIContent("High"), new GUIContent("Medium"), new GUIContent("Low") }; - _collider.LevelOfDetail = (SMBaseAbstract.MeshLevelOfDetail)EditorGUILayout.Popup(new GUIContent("Level of Detail", "The quality of the resulting mesh. Lower is better for performance and physics while higher will look more accurate and is better for rendering"), (int)_collider.LevelOfDetail, lodChoices); - _collider.TimeBetweenUpdates = EditorGUILayout.FloatField(new GUIContent("Time Between Updates", "How long to wait (in seconds) between Spatial Mapping updates"), _collider.TimeBetweenUpdates); - - } -} -#endif diff --git a/Assets/HoloToolkit/SpatialMapping/Editor/SpatialMappingColliderInspector.cs.meta b/Assets/HoloToolkit/SpatialMapping/Editor/SpatialMappingColliderInspector.cs.meta deleted file mode 100644 index a20e744db04..00000000000 --- a/Assets/HoloToolkit/SpatialMapping/Editor/SpatialMappingColliderInspector.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 0b049ea5fdad7004a9b2e2ea1d7a28ee -timeCreated: 1458842124 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/HoloToolkit/SpatialMapping/Editor/SpatialMappingRendererInspector.cs b/Assets/HoloToolkit/SpatialMapping/Editor/SpatialMappingRendererInspector.cs deleted file mode 100644 index 069a3658412..00000000000 --- a/Assets/HoloToolkit/SpatialMapping/Editor/SpatialMappingRendererInspector.cs +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See LICENSE in the project root for license information. - -#if UNITY_EDITOR -using UnityEngine; -using UnityEditor; - -[CustomEditor(typeof(SpatialMappingRenderer))] -public class SpatialMappingRendererInspector : Editor -{ - /// - /// The SpatialMappingRenderer we are setting options for - /// - private SpatialMappingRenderer _smRenderer; - - void OnEnable() - { - _smRenderer = target as SpatialMappingRenderer; - } - - public override void OnInspectorGUI() - { - GUIContent[] renderingSettingChoices = { new GUIContent("Occlusion"), new GUIContent("Material"), new GUIContent("None") }; - _smRenderer.CurrentRenderingSetting = (SpatialMappingRenderer.RenderingSetting)EditorGUILayout.Popup(new GUIContent("Render Mode"), (int)_smRenderer.CurrentRenderingSetting, renderingSettingChoices); - switch (_smRenderer.CurrentRenderingSetting) - { - case SpatialMappingRenderer.RenderingSetting.Occlusion: - Material occlusionMaterial = _smRenderer.OcclusionMaterial; - _smRenderer.OcclusionMaterial = (Material)EditorGUILayout.ObjectField(new GUIContent("Occlusion Material", "Material used for surface occlusion"), (UnityEngine.Object)occlusionMaterial, typeof(Material), false); - break; - case SpatialMappingRenderer.RenderingSetting.Material: - Material defaultMaterial = _smRenderer.RenderingMaterial; - _smRenderer.RenderingMaterial = (Material)EditorGUILayout.ObjectField(new GUIContent("Render Material", "Material used to render the mesh"), (UnityEngine.Object)defaultMaterial, typeof(Material), false); - break; - } - - _smRenderer.FreezeMeshUpdates = EditorGUILayout.Toggle(new GUIContent("Freeze Mesh Updates", ""), _smRenderer.FreezeMeshUpdates); - GUIContent[] boundsChoices = { new GUIContent("Bounding Box"), new GUIContent("Sphere") }; - int currentChoice = _smRenderer.UseSphereBounds ? 1 : 0; - int choice = EditorGUILayout.Popup(new GUIContent("Bounding Volume", "The shape of the bounds for the observed region"), currentChoice, boundsChoices); - switch (choice) - { - case 0: - _smRenderer.UseSphereBounds = false; - _smRenderer.Extents = EditorGUILayout.Vector3Field(new GUIContent("Extents", "The extents of the observation volume"), _smRenderer.Extents); - break; - case 1: - _smRenderer.UseSphereBounds = true; - _smRenderer.SphereRadius = EditorGUILayout.FloatField(new GUIContent("Radius", "The radius of the observation sphere volume"), _smRenderer.SphereRadius); - break; - default: - throw new System.Exception("Unexpected option!"); - } - - GUIContent[] lodChoices = { new GUIContent("High"), new GUIContent("Medium"), new GUIContent("Low") }; - _smRenderer.LevelOfDetail = (SMBaseAbstract.MeshLevelOfDetail)EditorGUILayout.Popup(new GUIContent("Level of Detail", "The quality of the resulting mesh. Lower is better for performance and physics while higher will look more accurate and is better for rendering"), (int)_smRenderer.LevelOfDetail, lodChoices); - _smRenderer.TimeBetweenUpdates = EditorGUILayout.FloatField(new GUIContent("Time Between Updates", "How long to wait (in seconds) between Spatial Mapping updates"), _smRenderer.TimeBetweenUpdates); - } -} -#endif diff --git a/Assets/HoloToolkit/SpatialMapping/Editor/SpatialMappingRendererInspector.cs.meta b/Assets/HoloToolkit/SpatialMapping/Editor/SpatialMappingRendererInspector.cs.meta deleted file mode 100644 index de01a0f89c8..00000000000 --- a/Assets/HoloToolkit/SpatialMapping/Editor/SpatialMappingRendererInspector.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 47e84d50e7e2697419a2337c8ee1d4b1 -timeCreated: 1458842124 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/HoloToolkit/SpatialMapping/Scripts/SpatialMappingComponent/SpatialMappingCollider.cs b/Assets/HoloToolkit/SpatialMapping/Scripts/SpatialMappingComponent/SpatialMappingCollider.cs deleted file mode 100644 index 90b07146bec..00000000000 --- a/Assets/HoloToolkit/SpatialMapping/Scripts/SpatialMappingComponent/SpatialMappingCollider.cs +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See LICENSE in the project root for license information. - -using UnityEngine; -using UnityEngine.VR.WSA; - -public class SpatialMappingCollider : SMBaseAbstract -{ - /// - /// The layer mask to apply to the mesh. - /// - public LayerMask MeshLayer; - - /// - /// Material describing the physical properties of the mesh. - /// - public PhysicMaterial PhysicMaterial; - - /// - /// Whether or not colliders are enabled on mesh - /// - private bool _enableCollisions = true; - /// - /// Toggles whether colliders are enabled on mesh - /// - public bool EnableCollisions - { - get { return _enableCollisions; } - set { _enableCollisions = value; ToggleColliders(); } - } - - protected void Awake() - { - bakeMeshes = true; - } - - /// - /// Handler for RequestMeshAsync which will be used to set the layer, material, and collision options on the resulting mesh - /// - /// The resulting data from the RequestMeshAsync call - /// Whether or not the output was written - /// How long the baking took in seconds - protected override void SurfaceObserver_OnDataReady(SurfaceData bakedData, bool outputWritten, float elapsedBakeTimeSeconds) - { - if (bakedData.outputMesh != null) - { - base.SurfaceObserver_OnDataReady(bakedData, outputWritten, elapsedBakeTimeSeconds); - bakedData.outputCollider.gameObject.layer = MeshLayer; - if (PhysicMaterial != null) - { - bakedData.outputCollider.material = PhysicMaterial; - } - bakedData.outputCollider.enabled = _enableCollisions; - } - } - - /// - /// Helper to update the active state of the colliders - /// - private void ToggleColliders() - { - foreach (GameObject go in SpatialMeshObjects.Values) - { - if (go != null) - { - MeshCollider collider = go.GetComponent(); - if (collider != null) - { - collider.enabled = _enableCollisions; - } - } - } - - foreach (RemovedSurfaceHolder rsh in RemovedMeshObjects.Values) - { - rsh.SetColliderEnabled(_enableCollisions); - - if (ShouldBeActiveWhileRemoved(rsh.gameObject)) - { - MeshCollider collider = rsh.gameObject.GetComponent(); - if (collider != null) - { - collider.enabled = _enableCollisions; - } - } - } - } -} diff --git a/Assets/HoloToolkit/SpatialMapping/Scripts/SpatialMappingComponent/SpatialMappingCollider.cs.meta b/Assets/HoloToolkit/SpatialMapping/Scripts/SpatialMappingComponent/SpatialMappingCollider.cs.meta deleted file mode 100644 index 637d3c14b29..00000000000 --- a/Assets/HoloToolkit/SpatialMapping/Scripts/SpatialMappingComponent/SpatialMappingCollider.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 53755a21bd4f3454981c6de4efdfec5d -timeCreated: 1458842124 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/HoloToolkit/SpatialMapping/Scripts/SpatialMappingComponent/SpatialMappingRenderer.cs b/Assets/HoloToolkit/SpatialMapping/Scripts/SpatialMappingComponent/SpatialMappingRenderer.cs deleted file mode 100644 index 0ad7576861d..00000000000 --- a/Assets/HoloToolkit/SpatialMapping/Scripts/SpatialMappingComponent/SpatialMappingRenderer.cs +++ /dev/null @@ -1,153 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See LICENSE in the project root for license information. - -using UnityEngine; -using UnityEngine.VR.WSA; - -public class SpatialMappingRenderer : SMBaseAbstract -{ - /// - /// Enum representing the choices for rendering - /// - /// Ensure any updates here are reflected in SpatialMappingRendererInspector - /// - public enum RenderingSetting { Occlusion = 0, Material = 1, None = 2 } - - /// - /// The current rendering setting - /// - [SerializeField] - private RenderingSetting _currentRenderingSetting = RenderingSetting.Occlusion; - /// - /// The current option for how rendering will be handled - /// - public RenderingSetting CurrentRenderingSetting - { - get { return _currentRenderingSetting; } - set { _currentRenderingSetting = value; ApplyRenderingSettingToCache(); } - } - - /// - /// The material used to render the mesh if _currentRenderingSetting is RenderingSetting.Material - /// - [SerializeField] - private Material _renderingMaterial = null; - - /// - /// The material used to render the mesh if _currentRenderingSetting is RenderingSetting.Material - /// - public Material RenderingMaterial - { - get { return _renderingMaterial; } - set { _renderingMaterial = value; ApplyRenderingSettingToCache(); } - } - /// - /// The material used to render the mesh if _currentRenderingSetting is RenderingSetting.Occlusion - /// - [SerializeField] - private Material _occlusionMaterial = null; - - /// - /// The material used to render the mesh if _currentRenderingSetting is RenderingSetting.Occlusion - /// - public Material OcclusionMaterial - { - get { return _occlusionMaterial; } - set { _occlusionMaterial = value; ApplyRenderingSettingToCache(); } - } - - protected override void Start() - { - base.Start(); - } - - /// - /// Handler for RequestMeshAsync which will be used to set the material on the resulting mesh - /// - /// The resulting data from the RequestMeshAsync call - /// Whether or not the output was written - /// How long the baking took in seconds - protected override void SurfaceObserver_OnDataReady(SurfaceData bakedData, bool outputWritten, float elapsedBakeTimeSeconds) - { - if (bakedData.outputMesh != null) - { - GameObject go; - if (SpatialMeshObjects.TryGetValue(bakedData.id, out go) && go != null) - { - if (go.GetComponent() == null) - { - MeshRenderer meshRenderer = go.AddComponent(); - meshRenderer.receiveShadows = false; - meshRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; - } - - ApplyRenderingSetting(bakedData.outputMesh.GetComponent()); - } - } - } - - /// - /// Gives the default Level of Detail for the inspector. - /// - /// For rendering, we default to MeshLevelOfDetail.Medium - /// - /// MeshLevelOfDetail.Medium - protected override MeshLevelOfDetail GetDefaultLevelOfDetail() - { - return MeshLevelOfDetail.Medium; - } - - /// - /// Helper to update the currently cached SpatialMeshObjects to the new rendering setting or material - /// - private void ApplyRenderingSettingToCache() - { - foreach (GameObject go in SpatialMeshObjects.Values) - { - if (go != null) - { - ApplyRenderingSetting(go.GetComponent()); - } - } - - foreach (RemovedSurfaceHolder rsh in RemovedMeshObjects.Values) - { - rsh.SetRendererEnabled(CurrentRenderingSetting != RenderingSetting.None); - MeshRenderer r = rsh.gameObject.GetComponent(); - if (r != null) - { - ApplyRenderingSetting(r); - - if (ShouldBeActiveWhileRemoved(rsh.gameObject)) - { - r.enabled = CurrentRenderingSetting != RenderingSetting.None; - } - } - } - } - - /// - /// Helper to actually apply the new render setting and material to a single MeshRenderer instance - /// - /// The MeshRenderer to apply the current rendering setting and material to - private void ApplyRenderingSetting(MeshRenderer r) - { - if (r == null) - { - return; - } - - switch (CurrentRenderingSetting) - { - case RenderingSetting.Material: - r.material = RenderingMaterial; - break; - case RenderingSetting.Occlusion: - r.material = OcclusionMaterial; - break; - case RenderingSetting.None: - r.enabled = false; - break; - } - } -} diff --git a/Assets/HoloToolkit/SpatialMapping/Scripts/SpatialMappingComponent/SpatialMappingRenderer.cs.meta b/Assets/HoloToolkit/SpatialMapping/Scripts/SpatialMappingComponent/SpatialMappingRenderer.cs.meta deleted file mode 100644 index d48657cc7aa..00000000000 --- a/Assets/HoloToolkit/SpatialMapping/Scripts/SpatialMappingComponent/SpatialMappingRenderer.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 6ca2f6b8dee51ea4bb59100b8f16fc1f -timeCreated: 1458842124 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/HoloToolkit/SpatialMapping/Scripts/SpatialMappingComponent/Support/SMBaseAbstract.cs b/Assets/HoloToolkit/SpatialMapping/Scripts/SpatialMappingComponent/Support/SMBaseAbstract.cs deleted file mode 100644 index f753f203014..00000000000 --- a/Assets/HoloToolkit/SpatialMapping/Scripts/SpatialMappingComponent/Support/SMBaseAbstract.cs +++ /dev/null @@ -1,602 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See LICENSE in the project root for license information. - -using UnityEngine; -using System.Collections; -using UnityEngine.VR.WSA; -using System.Collections.Generic; - -public abstract class SMBaseAbstract : MonoBehaviour -{ - /// - /// Toggles whether to stop requesting changes to observed region. - /// - public bool FreezeMeshUpdates; - - /// - /// Use a sphere as the bounding volume instead of a cube - /// - public bool UseSphereBounds = false; - - /// - /// The extents of the observation volume. - /// - public Vector3 Extents = Vector3.one * 10.0f; - - /// - /// The radius of the observation sphere volume. - /// - public float SphereRadius = 10.0f; - - /// - /// The Level of Detail for the mesh - /// - public enum MeshLevelOfDetail { High = 0, Medium = 1, Low = 2 } - - - /// - /// Whether or not the Level of Detail has been set to know to use _levelOfDetail or the default - /// - [SerializeField] - private bool _levelOfDetailSet = false; - /// - /// The Level of Detail to use if set. If not set, we will use the default from GetDefaultLevelOfDetail - /// - [SerializeField] - private MeshLevelOfDetail _levelOfDetail; - /// - /// The level of detail to use in the mesh - /// - public MeshLevelOfDetail LevelOfDetail - { - get - { - if (_levelOfDetailSet) - { - return _levelOfDetail; - } - return GetDefaultLevelOfDetail(); - } - set - { - _levelOfDetail = value; - _levelOfDetailSet = true; - } - } - - /// - /// An array that converts the logical level of detail to the Triangles per Cubic Meter needed by the API - /// - protected int[] LevelOfDetailToTPCM = - { - 2000, 750, 100 - }; - /// - /// The current Level of Detail setting once converted to Triangles per Cubic Meter - /// - protected int TrianglesPerCubicMeter { get { return LevelOfDetailToTPCM[(int)LevelOfDetail]; } } - - /// - /// How long to wait (in sec) between Spatial Mapping updates. - /// - public float TimeBetweenUpdates = 2.5f; - - /// - /// The SurfaceObserver we will use to get data about the physical surroundings - /// - protected SurfaceObserver surfaceObserver; - /// - /// The collection of all of the active meshes indexed by SurfaceId. - /// - /// The mesh itself can be accessed by getting the MeshFilter off of the GameObject - /// - public Dictionary SpatialMeshObjects = new Dictionary(); - - /// - /// Set this value to change how quickly objects will be actually removed from the scene - /// - /// When set to less than 1, objects will immediately be removed even if only transiently removed. - /// When 1 or greater, at least that number of update intervals will occur before objects will actually leave the scene. - /// Update intervals will not be processed if the object is within an observed region and the user is > 10.0 from the center - /// - public int NumUpdatesBeforeRemoval = 10; - - /// - /// The struct that will be used when caching meshes marked for deletion before the NumUpdatesBeforeRemoval has been reached - /// - public struct RemovedSurfaceHolder - { - /// - /// The number of remaining updates before the referenced mesh will be removed - /// - public int updatesBeforeRemoval; - /// - /// The GameObject that holds the MeshFilter as well as any other components associated with this mesh (colliders, renderers, etc.) - /// - public GameObject gameObject; - /// - /// The identifier of this surface - /// - public SurfaceId id; - /// - /// Whether the MeshCollider was present and enabled when this object was marked for removal. - /// - /// If this object is re-added before it is Destroyed, the MeshCollider.enabled state will be restored assuming the MeshCollider still exists - /// - public bool wasMeshColliderEnabled; - /// - /// Whether the MeshRenderer was present and enabled when this object was marked for removal. - /// - /// If this object is re-added before it is Destroyed, the MehsRenderer.enabled state will be restored assuming the MeshRenderer still exists - /// - public bool wasMeshRendererEnabled; - - /// - /// Decrements the number of updates remaining by one - /// - public void DecrementUpdatesRemaining() - { - if (updatesBeforeRemoval > 0) - { - updatesBeforeRemoval--; - } - } - - /// - /// Updates whether to enable the collider if the mesh is re-added - /// - /// Whether or not to re-enable the collider if the mesh is re-added - public void SetColliderEnabled(bool colliderEnabled) - { - wasMeshColliderEnabled = colliderEnabled; - } - - /// - /// Updates whether to enable the renderer if the mesh is re-added - /// - /// Whether or not to re-enable the renderer if the mesh is re-added - public void SetRendererEnabled(bool rendererEnabled) - { - wasMeshRendererEnabled = rendererEnabled; - } - - /// - /// Constructor for the struct taking all the parameters in - /// - /// The number of updates which will pass before this object is removed. - /// The GameObject owner of all of the mesh components - /// The SurfaceId identifying this surface - /// Whether or not a MeshCollider was present and enabled - /// Whether or not a MeshRenderer was present and enabled - public RemovedSurfaceHolder(int updatesBeforeRemoval, GameObject gameObject, SurfaceId id, bool wasMeshColliderEnabled, bool wasMeshRendererEnabled) - { - this.updatesBeforeRemoval = updatesBeforeRemoval; - this.gameObject = gameObject; - this.id = id; - this.wasMeshColliderEnabled = wasMeshColliderEnabled; - this.wasMeshRendererEnabled = wasMeshRendererEnabled; - } - } - - /// - /// The collection of meshes that may have been removed by the system but are being cached currently - /// - /// These objects may have been removed from the system due to being too far away or due to tracking loss as well - /// actually not needing to exist. To disable this behavior, set [SurfaceObserver].NumUpdatesBeforeRemoval = 0 or manually clear this dictionary - /// Surfaces in this collection will move back to the SpatialMeshObjects if they return to the scene before the number of update intervals has elapsed - /// - public Dictionary RemovedMeshObjects = new Dictionary(); - - /// - /// Whether or not the bake meshes (generate a collider) when processing - /// - protected bool bakeMeshes = false; - - /// - /// The bounds described by the extents of the observer - /// - /// This property is used to determine if a mesh is contained within the observed bounds when not using a sphere observed region - /// - protected Bounds bounds; - - /// - /// Standard initialization method creating our properties - /// - protected virtual void Start() - { - surfaceObserver = new SurfaceObserver(); - UpdateSurfaceObserverPosition(); - StartCoroutine(UpdateLoop()); - bounds = new Bounds(transform.position, Extents); - } - - /// - /// A helper to correctly update the bounding volume for the SurfaceObserver - /// - private void UpdateSurfaceObserverPosition() - { - if (UseSphereBounds) - { - surfaceObserver.SetVolumeAsSphere(transform.position, SphereRadius); - } - else - { - surfaceObserver.SetVolumeAsAxisAlignedBox(transform.position, Extents); - bounds.center = transform.position; - bounds.extents = Extents; - } - } - - /// - /// Standard method called when the component is destroyed. - /// - /// When this component is destroyed, we clean up all of our tracked GameObjects - /// - protected virtual void OnDestroy() - { - foreach (GameObject go in SpatialMeshObjects.Values) - { - if (go != null) - { - FinalDestroy(go); - } - } - SpatialMeshObjects.Clear(); - - foreach (RemovedSurfaceHolder rsh in RemovedMeshObjects.Values) - { - if (rsh.gameObject != null) - { - FinalDestroy(rsh.gameObject); - } - } - RemovedMeshObjects.Clear(); - } - - /// - /// Standard method called when the component is disabled - /// - /// When this component is disabled, we disable all of the tracked GameObjects - /// - protected virtual void OnDisable() - { - foreach (GameObject go in SpatialMeshObjects.Values) - { - if (go != null) - { - go.SetActive(false); - } - } - - foreach (RemovedSurfaceHolder rsh in RemovedMeshObjects.Values) - { - if (rsh.gameObject != null) - { - rsh.gameObject.SetActive(false); - } - } - } - - - /// - /// Standard method called when the component is enabled - /// - /// When this component is enabled, we enable all of the tracked GameObjects - /// - protected virtual void OnEnable() - { - foreach (GameObject go in SpatialMeshObjects.Values) - { - if (go != null) - { - go.SetActive(true); - } - } - - foreach (RemovedSurfaceHolder rsh in RemovedMeshObjects.Values) - { - if (rsh.gameObject != null) - { - rsh.gameObject.SetActive(true); - } - } - } - - /// - /// Handler for when the SurfaceObserver completes RequestMeshAsync - /// - /// The base class defines this function to make it easier for subclasses to modify meshes upon completion without needing to handle the actual processing - /// - /// The processed SurfaceData - /// Whether or not output was written - /// The time in seconds it took to request and populate the mesh - protected virtual void SurfaceObserver_OnDataReady(SurfaceData bakedData, bool outputWritten, float elapsedBakeTimeSeconds) - { - // Passthrough - } - - /// - /// The Coroutine which actually updates the meshes and processes our removed mesh's list - /// - /// This Coroutine runs forever and checks that the component is enabled and FreezeMeshUpdates has not been specified. If either are not true, we do nothing here and continue waiting. - /// - /// The WaitForSeconds to continue to wait - protected IEnumerator UpdateLoop() - { - var wait = new WaitForSeconds(TimeBetweenUpdates); - while (true) - { - if (enabled && !FreezeMeshUpdates) - { - // Make sure we ProcessRemoveList after Update because it might add some surfaces back - UpdateManager.AddToUpdateQueue(() => { surfaceObserver.Update(SurfaceObserver_OnSurfaceChanged); ProcessRemoveList(); }); - } - yield return wait; - } - } - - /// - /// Standard Update loop - /// - /// During our Update, we update the observed volume for the SurfaceObserver and ensure we do one step of processing - /// - protected virtual void Update() - { - UpdateSurfaceObserverPosition(); - UpdateManager.DoProcessingForFrame(); - } - - /// - /// Handler for calling SurfaceObserver.Update which will then handle the changes - /// - /// The actual changes will be handled via HandleAdd (for SurfaceChange.Added and SurfaceChange.Updated) and HandleDelete (for SurfaceChange.Removed) - /// - /// The identifier of the surface in question - /// What type of change this is (add, update, or remove) - /// The bounds of the mesh - /// The time the update occurred - protected virtual void SurfaceObserver_OnSurfaceChanged(SurfaceId surfaceId, SurfaceChange changeType, Bounds bounds, System.DateTime updateTime) - { - switch (changeType) - { - case SurfaceChange.Added: - case SurfaceChange.Updated: - HandleAdd(surfaceId, updateTime, bakeMeshes); - break; - case SurfaceChange.Removed: - HandleDelete(surfaceId); - break; - default: - break; - } - } - - /// - /// Handles cleaning up a known mesh or moving it to the RemovedMeshObjects list - /// - /// If NumUpdatesBeforeRemoval < 1, the mesh will immediately be destroyed upon removal - /// Else we will create a new RemoveSurfaceHolder and add that to the RemovedMeshObjects list to cache the mesh until we believe it should actually be removed - /// - /// - protected virtual void HandleDelete(SurfaceId surfaceId) - { - GameObject obj = SpatialMeshObjects[surfaceId]; - SpatialMeshObjects.Remove(surfaceId); - - if (NumUpdatesBeforeRemoval < 1) - { - FinalDestroy(obj); - } - else if (obj != null) - { - bool shouldDisable = !ShouldBeActiveWhileRemoved(obj); - - MeshCollider collider = obj.GetComponent(); - bool collisionsEnabled = (collider != null && collider.enabled); - if (collisionsEnabled && shouldDisable) - { - collider.enabled = false; - } - - MeshRenderer mr = obj.GetComponent(); - bool rendererEnabled = (mr != null && mr.enabled); - if (rendererEnabled && shouldDisable) - { - mr.enabled = false; - } - RemovedSurfaceHolder holder = new RemovedSurfaceHolder(NumUpdatesBeforeRemoval + 1 /*+1 because we are going to process it now*/, obj, surfaceId, collisionsEnabled, rendererEnabled); - RemovedMeshObjects.Add(surfaceId, holder); - } - } - - /// - /// Destroys the provided GameObject and The MeshFilter.mesh if present - /// - /// The GameObject to destroy - protected void FinalDestroy(GameObject surfaceObject) - { - if (surfaceObject != null) - { - MeshFilter filter = surfaceObject.GetComponent(); - if (filter != null) - { - if (filter.mesh != null) - { - Destroy(filter.mesh); - } - } - - Destroy(surfaceObject); - } - } - - /// - /// Handles when a surface is added or updated by either creating the needed components or finding them in either the RemovedMeshObjects collection or the SpatialMeshObjects collection - /// - /// If a surface is contained in the RemovedMeshObjects collection, the enabled state for its MeshCollider or MeshRenderer is restored if appropriate. The GameObject will be moved into SpatialMeshObjects, and the RemovedMeshHolder will be removed from RemovedMeshObject - /// If a surface is not found in either collection, a new GameObject will be created for it and it will be added to SpatialMeshObjects indexed by its id. - /// After the GameObject is handled as appropriately, SurfaceObserver.RequestMeshAsync will be called for the appropriate settings. - /// - /// The id of the surface that was added or updated - /// The time at which the surface was modified - /// Whether or not this component should request to back a collider for the surface - protected virtual void HandleAdd(SurfaceId surfaceId, System.DateTime updateTime, bool bake) - { - if (RemovedMeshObjects.ContainsKey(surfaceId)) - { - SpatialMeshObjects[surfaceId] = RemovedMeshObjects[surfaceId].gameObject; - if (RemovedMeshObjects[surfaceId].wasMeshColliderEnabled) - { - MeshCollider collider = SpatialMeshObjects[surfaceId].GetComponent(); - collider.enabled = true; - } - if (RemovedMeshObjects[surfaceId].wasMeshRendererEnabled) - { - MeshRenderer mr = SpatialMeshObjects[surfaceId].GetComponent(); - mr.enabled = true; - } - - RemovedMeshObjects.Remove(surfaceId); - } - else if (!SpatialMeshObjects.ContainsKey(surfaceId)) - { - SpatialMeshObjects[surfaceId] = new GameObject("spatial-mapping-" + surfaceId.handle); - SpatialMeshObjects[surfaceId].transform.parent = this.transform; - } - GameObject target = SpatialMeshObjects[surfaceId]; - SurfaceData sd = new SurfaceData( - //the surface id returned from the system - surfaceId, - //the mesh filter that is populated with the spatial mapping data for this mesh - (target.GetComponent() == null) ? target.AddComponent() : target.GetComponent(), - //the world anchor used to position the spatial mapping mesh in the world - (target.GetComponent() == null) ? target.AddComponent() : target.GetComponent(), - //the mesh collider that is populated with collider data for this mesh, if true is passed to bakeMeshes below - (target.GetComponent() == null) ? target.AddComponent() : target.GetComponent(), - //triangles per cubic meter requested for this mesh - TrianglesPerCubicMeter, - //bakeMeshes - if true, the mesh collider is populated, if false, the mesh collider is empty. - bake - ); - surfaceObserver.RequestMeshAsync(sd, SurfaceObserver_OnDataReady); - } - - /// - /// Iterates through the RemovedMeshObjects list and decrements the updates remaining and removes objects if appropriate - /// - /// The criteria for decrementing the update count and removing the entry if appropriate is either - /// - The mesh is not within the observed bounds (so in theory this observer does not actually care to observe it - /// - Or the main camera (user) is within 10m of the surface (if the user is that close to the mesh, the HoloLens is likely actively reporting on that space) - /// - protected virtual void ProcessRemoveList() - { - foreach (var kvp in RemovedMeshObjects) - { - // Only tick the count if either the object is not in the observed bounds or the user is within 10m of it - if (!BoundsContains(kvp.Value.gameObject.transform.position) || - Vector3.Distance(kvp.Value.gameObject.transform.position, Camera.main.transform.position) < 10.0f) - { - kvp.Value.DecrementUpdatesRemaining(); - if (kvp.Value.updatesBeforeRemoval < 1) - { - FinalDestroy(kvp.Value.gameObject); - RemovedMeshObjects.Remove(kvp.Key); - } - } - } - } - - /// - /// Gets the default Level of Detail. Subclasses can override to change the default Level of Detail. - /// - /// MeshLevelOfDetail.Low - protected virtual MeshLevelOfDetail GetDefaultLevelOfDetail() - { - return MeshLevelOfDetail.Low; - } - - /// - /// Helper method to determine if the bounds of this component contains the provided coordinate - /// - /// The position to test if it is within the current bounds of the component - /// Whether or not the position is contained within the current bounds of this component - protected bool BoundsContains(Vector3 position) - { - if (UseSphereBounds) - { - return (Vector3.Distance(transform.position, position) <= SphereRadius); - } - else - { - return bounds.Contains(position); - } - } - - /// - /// Helper to determine if the GameObject should continue to render and/or have physics even if marked for removal by the system - /// - /// An object should render and/or have physics if it is within the bounds of the observer and not parented to the camera - /// - /// The GameObject in question - /// Whether or not the GameObject should remain active even if marked for removal by the system - protected bool ShouldBeActiveWhileRemoved(GameObject go) - { - // If this is parented to the main camera, we have to disable it regardless of it being within bounds. - // If we don't, the mesh could appear to be locked to the user's head which can make them feel sick. - bool parentedToCamera = Camera.main.gameObject == go; - Transform parent = go.transform.parent; - while (!parentedToCamera && parent != null) - { - if (parent.gameObject == Camera.main.gameObject) - { - parentedToCamera = true; - break; - } - parent = parent.parent; - } - - bool containedSurface = BoundsContains(go.transform.position); - - return containedSurface && !parentedToCamera; - } - - /// - /// Helper static class to ensure only one SurfaceObserver is processed per frame - /// - protected static class UpdateManager - { - /// - /// The queue of pending updates to process - /// - private static Queue updatesToProcess = new Queue(); - /// - /// The Time.frameCount of the last frame where we executed an update - /// - /// If the current Time.frameCount != lastFrameProcessed, calling DoProcessingForFrame will execute the next update - /// If the current Time.frameCount == lastFrameProcessed, calling DoProcessingForFrame will do nothing - /// - private static int lastFrameProcessed = -1; - - /// - /// Queues the provided command to be processed on its own frame - /// - /// The command to be processed - public static void AddToUpdateQueue(System.Action command) - { - updatesToProcess.Enqueue(command); - } - - /// - /// Executes the next update if no updates have been executed on this frame or does nothing - /// - public static void DoProcessingForFrame() - { - if (lastFrameProcessed != Time.frameCount && updatesToProcess.Count > 0) - { - System.Action update = updatesToProcess.Dequeue(); - update(); - lastFrameProcessed = Time.frameCount; - } - } - } -} diff --git a/Assets/HoloToolkit/SpatialMapping/Scripts/SpatialMappingComponent/Support/SMBaseAbstract.cs.meta b/Assets/HoloToolkit/SpatialMapping/Scripts/SpatialMappingComponent/Support/SMBaseAbstract.cs.meta deleted file mode 100644 index c3df24f7d55..00000000000 --- a/Assets/HoloToolkit/SpatialMapping/Scripts/SpatialMappingComponent/Support/SMBaseAbstract.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: ce2b47ebae498b041bc28573dae917b7 -timeCreated: 1458842124 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/ProjectSettings/GraphicsSettings.asset b/ProjectSettings/GraphicsSettings.asset index b41307002b2..8b1929615d7 100644 --- a/ProjectSettings/GraphicsSettings.asset +++ b/ProjectSettings/GraphicsSettings.asset @@ -3,7 +3,7 @@ --- !u!30 &1 GraphicsSettings: m_ObjectHideFlags: 0 - serializedVersion: 6 + serializedVersion: 7 m_Deferred: m_Mode: 1 m_Shader: {fileID: 69, guid: 0000000000000000f000000000000000, type: 0} @@ -19,15 +19,15 @@ GraphicsSettings: m_DepthNormals: m_Mode: 1 m_Shader: {fileID: 62, guid: 0000000000000000f000000000000000, type: 0} + m_MotionVectors: + m_Mode: 1 + m_Shader: {fileID: 75, guid: 0000000000000000f000000000000000, type: 0} m_LightHalo: m_Mode: 1 m_Shader: {fileID: 105, guid: 0000000000000000f000000000000000, type: 0} m_LensFlare: m_Mode: 1 m_Shader: {fileID: 102, guid: 0000000000000000f000000000000000, type: 0} - m_SpritesDefault: - m_Mode: 1 - m_Shader: {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0} m_AlwaysIncludedShaders: - {fileID: 7, guid: 0000000000000000f000000000000000, type: 0} - {fileID: 15104, guid: 0000000000000000f000000000000000, type: 0} @@ -36,27 +36,20 @@ GraphicsSettings: - {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0} - {fileID: 10782, guid: 0000000000000000f000000000000000, type: 0} m_PreloadedShaders: [] + m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000, + type: 0} m_ShaderSettings_Tier1: useCascadedShadowMaps: 0 - useSinglePassStereoRendering: 0 standardShaderQuality: 0 useReflectionProbeBoxProjection: 0 useReflectionProbeBlending: 0 m_ShaderSettings_Tier2: useCascadedShadowMaps: 1 - useSinglePassStereoRendering: 0 standardShaderQuality: 2 useReflectionProbeBoxProjection: 1 useReflectionProbeBlending: 1 m_ShaderSettings_Tier3: useCascadedShadowMaps: 1 - useSinglePassStereoRendering: 0 - standardShaderQuality: 2 - useReflectionProbeBoxProjection: 1 - useReflectionProbeBlending: 1 - m_ShaderSettings_Tier4: - useCascadedShadowMaps: 1 - useSinglePassStereoRendering: 0 standardShaderQuality: 2 useReflectionProbeBoxProjection: 1 useReflectionProbeBlending: 1 diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index ff81a732a96..4c88d7f821d 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -73,6 +73,7 @@ PlayerSettings: uiUse16BitDepthBuffer: 1 ignoreAlphaClear: 0 xboxOneResolution: 0 + xboxOneMonoLoggingLevel: 0 ps3SplashScreen: {fileID: 0} videoMemoryForVertexBuffers: 0 psp2PowerMode: 0 @@ -262,6 +263,7 @@ PlayerSettings: ps4NPtitleDatPath: ps4RemotePlayKeyAssignment: -1 ps4RemotePlayKeyMappingDir: + ps4PlayTogetherPlayerCount: 0 ps4EnterButtonAssignment: 1 ps4ApplicationParam1: 0 ps4ApplicationParam2: 0 @@ -288,6 +290,7 @@ PlayerSettings: ps4attribMoveSupport: 0 ps4attrib3DSupport: 0 ps4attribShareSupport: 0 + ps4disableAutoHideSplash: 0 ps4IncludedModules: [] monoEnv: psp2Splashimage: {fileID: 0} diff --git a/ProjectSettings/ProjectVersion.txt b/ProjectSettings/ProjectVersion.txt index 5f719c7e106..a12138abfcc 100644 --- a/ProjectSettings/ProjectVersion.txt +++ b/ProjectSettings/ProjectVersion.txt @@ -1,2 +1,2 @@ -m_EditorVersion: 5.4.0b14-HTP +m_EditorVersion: 5.4.0b24-HTP m_StandardAssetsVersion: 0 diff --git a/README.md b/README.md index f66410de4c7..1758942cfb2 100644 --- a/README.md +++ b/README.md @@ -257,63 +257,6 @@ PlaneFinding addon that can be used to find planar surfaces (ie: walls/floors/ta ### [Scripts](https://github.com/Microsoft/HoloToolkit-Unity/tree/master/Assets/HoloToolkit/SpatialMapping/Scripts) -####[SpatialMappingComponent](https://github.com/Microsoft/HoloToolkit-Unity/tree/master/Assets/HoloToolkit/SpatialMapping/Scripts/SpatialMappingComponent) -A unified set of scripts adhering to best practices for providing physics or rendering support for Spatial Mapping. -Add a SpatialMappingCollider or SpatialMappingRenderer component onto a GameObject and spatial mapping will just start working. - -#### SpatialMappingRenderer.cs -Use this script for rendering Spatial Mapping. - -**Rendering Mode**: (Default: **Occlusion**). How to render the mesh. Occlusion will cause the mesh to occlude holograms behind it. Material will apply the specified material. None will cause the meshes to not render at all. - -**Occlusion Material**: (Set this to: **Occlusion**). The material to use for occluding holograms with the spatial mapping mesh. The Occlusion material is located in the HoloToolkit\SpatialMapping\Materials folder. - -**Rendering Material**: (Set this to: **Wireframe**). The material to render the Spatial Mapping mesh with. This is only relevant when Rendering Mode is set to Material. The Wireframe material can be found in HoloToolkit\SpatialMapping\Materials folder. - -**Freeze Mesh Updates**: (Default: **no**). When enabled, no further updates will be processed. Use this to delay initial starting of Spatial Mapping processing or to stop updates at a certain point. - -**Bounding Volume**: (Default: **Bounding Box**). The shape of the bounds to observe for new surfaces. The choices are Bounding Box with Extents or Sphere with Radius. - -**Extents**: (Default: **(10, 10, 10)**). The extents of the bounding box in meters. Only applicable with Bounding Box set for Bounding Volume. - -**Radius**: (Default: **10**). The radius of the bounding sphere in meters. Only applicable with Sphere set for Bounding Volume. - -**Level of Detail**: (Default: **Medium**). The amount of detail in the resulting meshes. Possible values are Low, Medium, and High. Higher levels of detail will result in lower performance. - -**Time Between Updates**: (Default: **2.5**). The frequency in seconds for when updates to Spatial Mapping surfaces will be processed. - -#### SpatialMappingCollider.cs -Use this script for performing physics collisions with the Spatial Mapping mesh. - -**Enable Collisions**: (Default: **yes**). Whether or not to create a collider for RigidBody physics - -**Physic Material**: (Default: **none**). Custom PhysicMaterial to define physical interactions (like bounciness) with the mesh. - -**Physics Layer**: (Default: **default**). The layer to apply to the meshes for Raycasting. - -**Freeze Mesh Updates**: (Default: **no**). When enabled, no further updates will be processed. Use this to delay initial starting of Spatial Mapping processing or to stop updates at a certain point. - -**Bounding Volume**: (Default: **Bounding Box**). The shape of the bounds to observe for new surfaces. The choices are Bounding Box with Extents or Sphere with Radius. - -**Extents**: (Default: **(10, 10, 10)**). The extents of the bounding box in meters. Only applicable with Bounding Box set for Bounding Volume. - -**Radius**: (Default: **10**). The radius of the bounding sphere in meters. Only applicable with Sphere set for Bounding Volume. - -**Level of Detail**: (Default: **Low**). The amount of detail in the resulting meshes. Possible values are Low, Medium, and High. Higher levels of detail will result in lower performance. - -**Time Between Updates**: (Default: **2.5**). The frequency in seconds for when updates to Spatial Mapping surfaces will be processed. - -#### Design Considerations - -1. If you want spatial mapping to work wherever the user travels, attach the components to the camera and the specified bounds will move with the user. -2. If you want collisions to continue working even after walking away, you may want to leave a second SpatialMappingCollider around the play space where collisions should continue. -3. If you want physics collisions and to render the Spatial Mapping mesh for an area, you should add both a SpatialMappingCollider and a SpatialMappingRenderer - -Though all of the defaults are usable out of the box with no customization, you can also customize the component to your scenario. Through script, additions such as PlaneFinding.cs can also be used with these components. - -These components by default implement caching of removed Spatial Mapping meshes such that removed meshes will still be present for at least 10 updates after they are actually removed. -This number and the feature can be configured via script. This feature enables mesh a great distance from the user to not be removed as well as quick re-hydration of mesh only removed as a user moved away and back to a single location. - The following scripts give you the ability to load the spatial mapping mesh from a file or the network into your Unity scene for debugging in the editor. #### FileSurfaceObserver.cs @@ -435,10 +378,6 @@ If you already have a .room file saved, it will automatically load the file and If not, you can use the RemoteMapping prefab to send/save mesh files from the HoloLens. You can also run this test directly in the HoloLens. This scene will scan your area for 15 seconds and then convert all meshes to planes. If a floor plane is found, it will remove vertices from surface meshes that fall within the bounds of any active plane. -#### SpatialMappingComponent\Example.unity -This scene shows an example of a static play space which preserves physics around it (marked by a cube) while maintaining physics and wire frame rendering of Spatial Mapping around the camera. -Additionally, you can tap to drop a cube in front of the camera with a Rigidbody component to interact with physics. - #### TapToPlace.unity This scene is the minimum setup to use the TapToPlace script. It includes GazeManager, GestureManager, and SpatialMapping prefab. BasicCursor prefab is included for ease of use. There is a cube in the scene with TapToPlace added on it. Gaze at and tap the cube. It will move along the spatial mapping mesh based on user's gaze.