Пример #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);
        }
Пример #2
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);
        }