Exemple #1
0
        private async Task <(string hash, GeometryInfo geoInfo, int resolution)> RebuildPreview(
            IFileSource source, string filePath,
            ConfigVector3?rotation, ConfigVector3?scale,
            string knownHash = null)
        {
            var fileName = Path.GetFileName(filePath);

            var fileBytes = await source
                            .GetFileBytesAsync(filePath)
                            .Timed("Reading file {0}", fileName);

            var(mesh, hash) = await StlImporter
                              .ImportMeshAsync(fileName, fileBytes, computeHash : knownHash == null)
                              .Timed("Imported {0}", fileName);

            var geoInfo = await GeometryInfo.FromMeshAsync(mesh, rotation, scale);

            var(previewData, resolution) = await _previewBuilder
                                           .GetPreviewImageDataAsync(mesh, rotation)
                                           .Timed("Building preview for {0}", fileName);

            StlImporter.Destroy(mesh);

            await _previewStore.StorePreviewAsync(hash ?? knownHash, previewData);

            return(hash, geoInfo, resolution);
        }
Exemple #2
0
 private void DestroyMesh(Mesh mesh)
 {
     if (_lookup.TryGetValue(mesh, out var gameObj))
     {
         Destroy(gameObj);
         StlImporter.Destroy(mesh);
         _lookup.Remove(mesh);
     }
 }
Exemple #3
0
    private IEnumerator DownloadObject(string url, string name, float scale, Vector3 offset)
    {
        UnityWebRequest webop = UnityWebRequest.Get(url);

        webop.chunkedTransfer = false;
        webop.SetRequestHeader("Accept", "multipart/related");
        webop.downloadHandler = new DownloadHandlerBuffer();
        yield return(webop.SendWebRequest());

        if (webop.isNetworkError && webop.responseCode != 200L)
        {
            Debug.Log(webop.error);
        }
        else
        {
            byte[]      text     = webop.downloadHandler.data;
            StlImporter importer = new StlImporter();
            GameObject  obj      = GameObject.Find("Holograms/" + name).gameObject;
            obj.transform.localScale    = new Vector3(scale, scale, scale);
            obj.transform.localPosition = offset;
            obj.name  = name;
            obj.layer = 0;
            obj.AddComponent <MeshRenderer>();
            obj.AddComponent <MeshFilter>();
            obj.AddComponent <MeshCollider>();
            obj.GetComponent <MeshFilter>().mesh       = importer.ImportFile(text);
            obj.GetComponent <MeshFilter>().sharedMesh = obj.GetComponent <MeshFilter>().mesh;
            obj.GetComponent <MeshFilter>().mesh.RecalculateNormals();
            obj.GetComponent <MeshFilter>().mesh.RecalculateTangents();
            obj.GetComponent <MeshFilter>().mesh.RecalculateBounds();
            obj.GetComponent <MeshCollider>().sharedMesh = null;
            obj.GetComponent <MeshCollider>().sharedMesh = obj.GetComponent <MeshFilter>().mesh;
            obj.GetComponent <MeshCollider>().convex     = false;
            obj.GetComponent <MeshCollider>().enabled    = true;
            obj.GetComponent <Renderer>().material       = Resources.Load <Material>("Materials/defaultMat");
            obj.GetComponent <Renderer>().enabled        = true;
            obj.SetActive(true);
        }
    }
Exemple #4
0
        public async Task <Mesh> GetMeshAsync(ItemPreviewModel previewModel)
        {
            IFileSource source   = null;
            string      filePath = null;

            _lock.Read(() => (source, filePath) = _previewModels.TryGetFileSource(previewModel));

            if (source == null || filePath == null)
            {
                return(null);
            }

            var fileName = Path.GetFileName(filePath);

            var fileBytes = await source
                            .GetFileBytesAsync(filePath)
                            .Timed("Reading file {0}", fileName);

            var(mesh, _) = await StlImporter
                           .ImportMeshAsync(fileName, fileBytes, centerVertices : false, computeHash : false)
                           .Timed("Imported {0}", fileName);

            return(mesh);
        }