/// <summary> /// Converts a <see cref="Microsoft.MixedReality.SceneUnderstanding"/> <see cref="SceneObjectKind"/> to a MRTK/platform agnostic <see cref="SpatialAwarenessSurfaceTypes"/> /// </summary> /// <param name="label">The <see cref="Microsoft.MixedReality.SceneUnderstanding"/> <see cref="SceneObjectKind"/> to convert.</param> /// <returns>The equivalent <see cref="SpatialAwarenessSurfaceTypes"/></returns> private SpatialAwarenessSurfaceTypes SpatialAwarenessSurfaceType(SceneObjectKind label) { switch (label) { case SceneObjectKind.Background: return(SpatialAwarenessSurfaceTypes.Background); case SceneObjectKind.Wall: return(SpatialAwarenessSurfaceTypes.Wall); case SceneObjectKind.Floor: return(SpatialAwarenessSurfaceTypes.Floor); case SceneObjectKind.Ceiling: return(SpatialAwarenessSurfaceTypes.Ceiling); case SceneObjectKind.Platform: return(SpatialAwarenessSurfaceTypes.Platform); case SceneObjectKind.World: return(SpatialAwarenessSurfaceTypes.World); case SceneObjectKind.CompletelyInferred: return(SpatialAwarenessSurfaceTypes.CompletelyInferred); case SceneObjectKind.Unknown: default: return(SpatialAwarenessSurfaceTypes.Unknown); } }
/// <summary> /// Get the corresponding layer for each SceneObject Kind /// </summary> /// <param name="kind">The Scene Understanding kind from which to query the layer</param> private int GetLayer(SceneObjectKind kind) { switch (kind) { case SceneObjectKind.Background: return(LayerForBackgroundObjects); case SceneObjectKind.Wall: return(LayerForWallObjects); case SceneObjectKind.Floor: return(LayerForFloorObjects); case SceneObjectKind.Ceiling: return(LayerForCeilingObjects); case SceneObjectKind.Platform: return(LayerForPlatformsObjects); case SceneObjectKind.Unknown: return(LayerForUnknownObjects); case SceneObjectKind.CompletelyInferred: return(LayerForInferredObjects); case SceneObjectKind.World: return(LayerForWorldObjects); default: return(0); } }
/// <summary> /// Get the cached material for each SceneObject Kind /// </summary> /// <param name="kind"> /// The <see cref="SceneObjectKind"/> to obtain the material for. /// </param> /// <param name="mode"> /// The <see cref="RenderMode"/> to obtain the material for. /// </param> /// <remarks> /// If <see cref="IsInGhostMode"/> is true, the ghost material will be returned. /// </remarks> private Material GetMaterial(SceneObjectKind kind, RenderMode mode) { // If in ghost mode, just return transparent if (IsInGhostMode) { return(TransparentOcclussion); } // Make sure we have a cache if (materialCache == null) { materialCache = new Dictionary <SceneObjectKind, Dictionary <RenderMode, Material> >(); } // Find or create cache specific to this Kind Dictionary <RenderMode, Material> kindModeCache; if (!materialCache.TryGetValue(kind, out kindModeCache)) { kindModeCache = new Dictionary <RenderMode, Material>(); materialCache[kind] = kindModeCache; } // Find or create material specific to this Mode Material mat; if (!kindModeCache.TryGetValue(mode, out mat)) { // Determine the source material by kind Material sourceMat; switch (mode) { case RenderMode.Quad: case RenderMode.QuadWithMask: sourceMat = SceneObjectQuadMaterial; break; case RenderMode.Wireframe: sourceMat = SceneObjectWireframeMaterial; break; default: sourceMat = SceneObjectMeshMaterial; break; } // Create an instance mat = Instantiate(sourceMat); // Set color to match the kind Color?color = GetColor(kind); if (color != null) { mat.color = color.Value; mat.SetColor("_WireColor", color.Value); } // Store kindModeCache[mode] = mat; } // Return the found or created material return(mat); }
/// <summary> /// Create a Unity Game Object for an individual Scene Understanding Object /// </summary> /// <param name="suObject">The Scene Understanding Object to generate in Unity</param> private bool DisplaySceneObject(SceneObject suObject) { if (suObject == null) { Debug.LogWarning("SceneUnderstandingManager.DisplaySceneObj: Object is null"); return(false); } // If requested, scene objects can be excluded from the generation, the World Mesh is considered // a separate object hence is not affected by this filter if (RenderSceneObjects == false && suObject.Kind != SceneObjectKind.World) { return(false); } // If an individual type of object is requested to not be rendered, avoid generation of unity object SceneObjectKind kind = suObject.Kind; switch (kind) { case SceneObjectKind.World: if (!RenderWorldMesh) { return(false); } break; case SceneObjectKind.Platform: if (!RenderPlatformSceneObjects) { return(false); } break; case SceneObjectKind.Background: if (!RenderBackgroundSceneObjects) { return(false); } break; case SceneObjectKind.Unknown: if (!RenderUnknownSceneObjects) { return(false); } break; case SceneObjectKind.CompletelyInferred: if (!RenderCompletelyInferredSceneObjects) { return(false); } break; } // This gameobject will hold all the geometry that represents the Scene Understanding Object GameObject unityParentHolderObject = new GameObject(suObject.Kind.ToString()); unityParentHolderObject.transform.parent = SceneRoot.transform; // Scene Understanding uses a Right Handed Coordinate System and Unity uses a left handed one, convert. System.Numerics.Matrix4x4 converted4x4LocationMatrix = ConvertRightHandedMatrix4x4ToLeftHanded(suObject.GetLocationAsMatrix()); // From the converted Matrix pass its values into the unity transform (Numerics -> Unity.Transform) SetUnityTransformFromMatrix4x4(unityParentHolderObject.transform, converted4x4LocationMatrix, true); // This list will keep track of all the individual objects that represent the geometry of // the Scene Understanding Object List <GameObject> unityGeometryObjects = null; /*switch (kind) * { * // Create all the geometry and store it in the list * case SceneObjectKind.World: * unityGeometryObjects = CreateWorldMeshInUnity(suObject); * break; * default: * unityGeometryObjects = CreateSUObjectInUnity(suObject); * break; * }*/ switch (kind) { // Create all the geometry and store it in the list case SceneObjectKind.World: unityGeometryObjects = CreateWorldMeshInUnity(suObject); break; default: if (renderForNavigation) { if (kind == SceneObjectKind.Floor) { unityGeometryObjects = CreateSUObjectInUnity(suObject); break; } return(false); } unityGeometryObjects = CreateSUObjectInUnity(suObject); break; } // For all the Unity Game Objects that represent The Scene Understanding Object // Of this iteration, make sure they are all children of the UnityParent object // And that their local postion and rotation is relative to their parent foreach (GameObject geometryObject in unityGeometryObjects) { geometryObject.transform.parent = unityParentHolderObject.transform; geometryObject.transform.localPosition = Vector3.zero; geometryObject.transform.localRotation = Quaternion.identity; } // If the Scene is running on a device, add a World Anchor to align the Unity object // to the XR scene unityParentHolderObject.AddComponent <UnityEngine.XR.WSA.WorldAnchor>(); //Return that the Scene Object was indeed represented as a unity object and wasn't skipped return(true); }