private void InstantiateMesh(Mesh mesh, ItemPreviewModel model) { if (_lookup.ContainsKey(mesh)) { return; } var newGameObj = new GameObject(mesh.name); newGameObj.transform.SetParent(_meshParent); var geoInfo = model.GeometryInfo.Value; newGameObj.transform.localPosition = Vector3.zero; newGameObj.transform.localScale = 0.1f * geoInfo.Scale; newGameObj.transform.localRotation = Quaternion.Euler(geoInfo.Rotation); var meshFilter = newGameObj.AddComponent <MeshFilter>(); meshFilter.sharedMesh = mesh; var meshRenderer = newGameObj.AddComponent <MeshRenderer>(); meshRenderer.sharedMaterial = _material; _lookup.Add(mesh, newGameObj); }
public async Task RotateAsync(ItemPreviewModel previewModel, Vector3 newRotation) { try { IFileSource source = null; string filePath = null; _lock.Read(() => (source, filePath) = _previewModels.TryGetFileSource(previewModel)); if (source == null || filePath == null) { return; } var(_, geoInfo, resolution) = await RebuildPreview( source, filePath, newRotation, previewModel.GeometryInfo.Value.Scale, previewModel.FileHash); _lock.Write(() => { previewModel.PreviewResolution = resolution; previewModel.GeometryInfo.Value = geoInfo; }); previewModel.OnPreviewChanged(); } catch (Exception ex) { Logger.Error(ex, "Error while rotating `{0}`", previewModel.Name); } }
public Vector3 GetImportRotation(ItemPreviewModel previewModel) { var rotation = Vector3.zero; _lock.Read(() => { var(source, _) = _previewModels.TryGetFileSource(previewModel); rotation = source.Config.Rotation ?? Vector3.zero; }); return(rotation); }
public bool TryGetLocalPath(ItemPreviewModel previewModel, out string localPath) { try { IFileSource source = null; string filePath = null; _lock.Read(() => (source, filePath) = _previewModels.TryGetFileSource(previewModel)); localPath = Path.Combine(source.Id, filePath); return(File.Exists(localPath)); } catch { localPath = null; } return(false); }
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); }