public async Task <IObject3D> CreateItem(ILibraryItem item, Action <double, string> reporter) { const double DefaultSizeMm = 40; return(await Task.Run(async() => { if (imageBuffer != null) { // Build an ImageBuffer from some svg content double scaleMmPerPixels = Math.Min(DefaultSizeMm / imageBuffer.Width, DefaultSizeMm / imageBuffer.Height); // Create texture mesh double width = scaleMmPerPixels * imageBuffer.Width; double height = scaleMmPerPixels * imageBuffer.Height; Mesh textureMesh = PlatonicSolids.CreateCube(width, height, 0.2); textureMesh.PlaceTextureOnFaces(0, imageBuffer); string assetPath = null; if (item is ILibraryAssetStream assetStream) { assetPath = assetStream.AssetPath; if (string.IsNullOrWhiteSpace(assetPath)) { using (var streamAndLength = await assetStream.GetStream(null)) { string assetID = AssetObject3D.AssetManager.StoreStream(streamAndLength.Stream, ".svg"); assetPath = assetID; } } } var svgObject = new SvgObject3D() { DString = "", // How to acquire? SvgPath = assetPath }; svgObject.Children.Add(new Object3D() { Mesh = textureMesh }); await svgObject.Rebuild(); return svgObject; } else { return null; } })); }
public GuiWidget Create(IObject3D item, UndoBuffer undoBuffer, ThemeConfig theme) { this.injectedItem = item as SvgObject3D; if (this.injectedItem == null) { return(null); } var column = new FlowLayoutWidget(FlowDirection.TopToBottom) { VAnchor = VAnchor.Fit, HAnchor = HAnchor.Absolute, Width = 210, Padding = new BorderDouble(12), }; column.Closed += (s, e) => { //unregisterEvents?.Invoke(this, null); }; var rightPanel = new FlowLayoutWidget(FlowDirection.TopToBottom) { HAnchor = HAnchor.Stretch }; var label = new TextWidget("All Paths", textColor: AppContext.Theme.TextColor) { HAnchor = HAnchor.Left, Margin = new BorderDouble(0, 0, 0, 15) }; column.AddChild(label); var row = new FlowLayoutWidget() { }; column.AddChild(row); var editButton = new TextButton("Edit".Localize(), theme) { Enabled = false, }; editButton.Click += async(s, e) => { ApplicationController.Instance.OpenIntoNewTab(new[] { new InMemoryLibraryItem(new VertexStorageObject3D(lastDPath)) }); }; int pathCount = 1; var droplist = new PopupMenu(theme) { BackgroundColor = theme.InactiveTabColor }; row.AddChild(droplist); row.AddChild(editButton); var allPaths = SvgParser.GetPaths(this.injectedItem.SvgPath); selectedItems = new HashSet <SvgParser.SvgNodeInfo>(allPaths); foreach (var pathItem in allPaths) { bool itemChecked = true; PopupMenu.MenuItem menuItem = null; menuItem = droplist.CreateBoolMenuItem( $"Path {pathCount++}", () => itemChecked, (isChecked) => { lastDPath = (pathItem as SvgParser.SvgPathInfo)?.DString; editButton.Enabled = true; if (isChecked) { selectedItems.Add(pathItem); } else { selectedItems.Remove(pathItem); } this.Rebuild(); }); } this.Rebuild(); return(column); }