示例#1
0
    public static async Task <ObjectAnchorsLocation?> LocateAndSetFromEnvironmentObservation(this Mesh mesh, EnvironmentObservation observation)
    {
        ObjectAnchorsLocation?observationLocation = null;
        await mesh.SetFromSystemMeshDataAsync(() =>
        {
            observationLocation = observation.Origin.ToSpatialCoordinateSystem().TryGetTransformTo(ObjectAnchorsWorldManager.WorldOrigin)?.ToUnityLocation();
            return(SystemMeshData.FromEnvironmentObseration(observation));
        });

        return(observationLocation);
    }
示例#2
0
        // We need to flip handedness of vertices and modify triangle list to
        // clockwise winding in order to be usable in Unity.
        public static Task <UnityMeshData> FromSystemDataAsync(Func <SystemMeshData> getMeshData)
        {
            return(Task.Run(() =>
            {
                SystemMeshData systemMeshData = getMeshData();
                if (systemMeshData.Vertices.Length != systemMeshData.Normals.Length)
                {
                    throw new System.ArgumentException($"Count of normals ({systemMeshData.Normals.Length}) does not match count of vertices ({systemMeshData.Vertices.Length})", "systemMeshData.Normals");
                }

                UnityMeshData meshData;
                meshData.Vertices = new Vector3[systemMeshData.Vertices.Length];
                meshData.Normals = new Vector3[systemMeshData.Vertices.Length];
                for (uint i = 0; i < systemMeshData.Vertices.Length; ++i)
                {
                    meshData.Vertices[i] = systemMeshData.Vertices[i].ToUnity();
                    meshData.Normals[i] = systemMeshData.Normals[i].ToUnity();
                }

                if (systemMeshData.Indices != null && systemMeshData.Indices.Length != 0)
                {
                    if (systemMeshData.Indices.Length % 3 != 0)
                    {
                        throw new System.ArgumentException($"Count of triangle indices ({systemMeshData.Indices.Length}) is not a multiple of three", "systemMeshData.Indices");
                    }

                    // Clock wise
                    meshData.Indices = new int[systemMeshData.Indices.Length];
                    for (uint i = 0; i < systemMeshData.Indices.Length; i += 3)
                    {
                        meshData.Indices[i + 0] = (int)systemMeshData.Indices[i + 2];
                        meshData.Indices[i + 1] = (int)systemMeshData.Indices[i + 1];
                        meshData.Indices[i + 2] = (int)systemMeshData.Indices[i + 0];
                    }

                    meshData.Topology = MeshTopology.Triangles;
                }
                else
                {
                    meshData.Indices = new int[systemMeshData.Vertices.Length];
                    for (int i = 0; i < systemMeshData.Vertices.Length; ++i)
                    {
                        meshData.Indices[i] = i;
                    }
                    meshData.Topology = MeshTopology.Points;
                }

                return meshData;
            }));
        }
示例#3
0
        public static SystemMeshData FromEnvironmentObseration(EnvironmentObservation observation)
        {
            var meshData = new SystemMeshData()
            {
                Vertices = new Numerics.Vector3[observation.VertexCount],
                Normals  = new Numerics.Vector3[observation.VertexCount],
                Indices  = new uint[observation.TriangleIndexCount]
            };

#if UNITY_WSA
            observation.GetVertexPositions(meshData.Vertices);
            observation.GetVertexNormals(meshData.Normals);
            observation.GetTriangleIndices(meshData.Indices);
#endif
            return(meshData);
        }
示例#4
0
 public static Task SetFromObjectModel(this Mesh mesh, Guid modelId)
 {
     return(mesh.SetFromSystemMeshDataAsync(() => SystemMeshData.FromObjectModel(modelId)));
 }