/// <summary>
        /// Updates an element of the behavior's mesh list from an element of the the spatial mapping's surface object list.
        /// Element will be either added or updated to match up to the surfaceObject list.
        /// </summary>
        /// <param name="surfaceId">The unique ID for the mesh (matches the id provided by spatial mapping)</param>
        /// <param name="surfaceObjectIndex">Index in the surfaceObjects list</param>
        /// <param name="surfaceObjects">The list of surfaceObjects</param>
        /// <param name="meshDataIndex">Index into the locally stored mesh data list</param>
        private void AddOrUpdateMeshInList(
            int surfaceId,
            int surfaceObjectIndex,
            List <SpatialMappingSource.SurfaceObject> surfaceObjects,
            int meshDataIndex = -1)
        {
            SpatialUnderstandingDll.MeshData meshData = new SpatialUnderstandingDll.MeshData();
            int meshUpdateID = (meshDataIndex > 0) ? (inputMeshList[meshDataIndex].LastUpdateID + 1) : 0;

            // Checks.
            MeshFilter meshFilter = surfaceObjects[surfaceObjectIndex].Filter;

            if ((meshFilter != null) &&
                (meshFilter.mesh != null) &&
                (meshFilter.mesh.triangles.Length > 0))
            {
                // Fix surface mesh normals so we can get correct plane orientation.
                meshFilter.mesh.RecalculateNormals();

                // Convert
                meshData.CopyFrom(meshFilter, surfaceId, meshUpdateID);
            }
            else
            {
                // No filter yet, add as an empty mesh (will be updated later in the update loop)
                meshData.CopyFrom(null, surfaceId, meshUpdateID);
            }

            // And add it (unless an index of an update item is specified)
            if (meshDataIndex < 0)
            {
                inputMeshList.Add(meshData);
            }
            else
            {
                inputMeshList[meshDataIndex] = meshData;
            }
        }
        /// <summary>
        /// Updates an element of the behavior's mesh list from an element of the the spatial mapping's surface object list.
        /// Element will be either added or updated to match up to the surfaceObject list.
        /// </summary>
        /// <param name="surfaceId">The unique ID for the mesh (matches the id provided by spatial mapping)</param>
        /// <param name="surfaceObjectIndex">Index in the surfaceObjects list</param>
        /// <param name="surfaceObjects">The list of surfaceObjects</param>
        /// <param name="meshDataIndex">Index into the locally stored mesh data list</param>
        private void AddOrUpdateMeshInList(
            SurfaceData bakedData)
        {
            SurfaceId  surfaceId     = bakedData.id;
            MeshFilter meshFilter    = bakedData.outputMesh;
            int        meshDataIndex = FindMeshIndexInInputMeshList(surfaceId.handle);

            SpatialUnderstandingDll.MeshData meshData = new SpatialUnderstandingDll.MeshData();
            int meshUpdateID = (meshDataIndex >= 0) ? (inputMeshList[meshDataIndex].LastUpdateID + 1) : 1;

            if ((meshFilter != null) &&
                (meshFilter.mesh != null) &&
                (meshFilter.mesh.triangles.Length > 0))
            {
                // Fix surface mesh normals so we can get correct plane orientation.
                meshFilter.mesh.RecalculateNormals();

                // Convert
                meshData.CopyFrom(meshFilter, surfaceId.handle, meshUpdateID);
            }
            else
            {
                // No filter yet, add as an empty mesh (will be updated later in the update loop)
                meshData.CopyFrom(null, surfaceId.handle, meshUpdateID);
            }

            // And add it (unless an index of an update item is specified)
            if (meshDataIndex < 0)
            {
                inputMeshList.Add(meshData);
            }
            else
            {
                inputMeshList[meshDataIndex] = meshData;
            }
        }
        private static SpatialUnderstandingDll.MeshData CreateMeshData(SpatialMappingSource.SurfaceObject surface, int meshUpdateID)
        {
            MeshFilter meshFilter = surface.Filter;

            SpatialUnderstandingDll.MeshData meshData = new SpatialUnderstandingDll.MeshData();

            if ((meshFilter != null) &&
                (meshFilter.mesh != null) &&
                (meshFilter.mesh.triangles.Length > 0))
            {
                // Fix surface mesh normals so we can get correct plane orientation.
                meshFilter.mesh.RecalculateNormals();

                // Convert
                meshData.CopyFrom(meshFilter, surface.ID, meshUpdateID);
            }
            else
            {
                // No filter yet, add as an empty mesh (will be updated later in the update loop)
                meshData.CopyFrom(null, surface.ID, meshUpdateID);
            }

            return(meshData);
        }