Example #1
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);
        }
Example #2
0
    // Update is called once per frame
    async void Update()
    {
        if (!_updateInProgress &&
            Query != null &&
            EnvironmentMaterial != null &&
            (!_lastMeshUpdateTime.HasValue || DateTime.Now - _lastMeshUpdateTime.Value > TimeSpan.FromSeconds(2)))
        {
            _updateInProgress = true;
            EnvironmentObservation observation = await Query.ComputeLatestEnvironmentObservationAsync(EnvironmentObservationTopology.PointCloud);

            MeshLoader.MeshData?  meshData            = null;
            ObjectAnchorsLocation?observationLocation = null;

            await Task.Run(() =>
            {
                var vertexPositions = new System.Numerics.Vector3[observation.VertexCount];
                var vertexNormals   = new System.Numerics.Vector3[vertexPositions.Length];
                var triangleIndices = new uint[observation.TriangleIndexCount];
                observation.GetVertexPositions(vertexPositions);
                observation.GetVertexNormals(vertexNormals);
                observation.GetTriangleIndices(triangleIndices);
                meshData = new MeshLoader.MeshData(vertexPositions, vertexNormals, triangleIndices);

#if SPATIALCOORDINATESYSTEM_API_PRESENT
                observationLocation = observation.Origin.ToSpatialCoordinateSystem().TryGetTransformTo(ObjectAnchorsWorldManager.WorldOrigin)?.ToUnityLocation();
#endif
            });


            if (observationLocation.HasValue && meshData.HasValue)
            {
                MeshLoader.LoadMesh(_meshFilter.mesh, meshData.Value);
                transform.SetPositionAndRotation(observationLocation.Value.Position, observationLocation.Value.Orientation);
            }

            _lastMeshUpdateTime = DateTime.Now;
            _updateInProgress   = false;
        }
    }