public void BakeGeometry(RhinoDoc doc, ObjectAttributes att, List <System.Guid> obj_ids) { System.Collections.IEnumerator enumerator = new List <GuanacoListItem> .Enumerator(); if (att == null) { att = doc.CreateDefaultAttributes(); } try { enumerator = this.m_data.GetEnumerator(); while (enumerator.MoveNext()) { object item = System.Runtime.CompilerServices.RuntimeHelpers.GetObjectValue(enumerator.Current); if (item != null) { if (item is IGH_BakeAwareData) { IGH_BakeAwareData bake_item = (IGH_BakeAwareData)item; System.Guid id; if (bake_item.BakeGeometry(doc, att, out id)) { obj_ids.Add(id); } } } } } finally { ((System.IDisposable)enumerator).Dispose(); } }
public void BakeGeometry(RhinoDoc doc, ObjectAttributes att, List<Guid> obj_ids) { List<Text3d>.Enumerator tag; if (att == null) { att = doc.CreateDefaultAttributes(); } try { tag = this.m_tags.GetEnumerator(); while (tag.MoveNext()) { Text3d tag3d = tag.Current; Guid id = doc.Objects.AddText(tag3d, att); if (!(id == Guid.Empty)) { obj_ids.Add(id); } } } finally { tag.Dispose(); } }
public override void BakeGeometry(RhinoDoc doc, List <Guid> obj_ids) { var attr = doc.CreateDefaultAttributes(); attr.ColorSource = Rhino.DocObjects.ObjectColorSource.ColorFromObject; attr.ObjectColor = this.FillColor; doc.Objects.AddTextDot(this.Dot, attr); }
public override void BakeGeometry(RhinoDoc doc, List <Guid> obj_ids) { base.BakeGeometry(doc, obj_ids); for (int i = 0; i < c_Pose.Geometries.Count(); i++) { var attributes = doc.CreateDefaultAttributes(); attributes.ColorSource = Rhino.DocObjects.ObjectColorSource.ColorFromObject; attributes.ObjectColor = c_Pose.Colors[i]; obj_ids.Add(doc.Objects.AddMesh(c_Pose.Geometries[i], attributes)); } }
public override void BakeGeometry(RhinoDoc doc, ObjectAttributes att, List <Guid> obj_ids) { if (att == null) { att = doc.CreateDefaultAttributes(); } var layerIndex = doc.Layers.CurrentLayerIndex; foreach (var line in _explicitLines) { var lineAttributes = att.Duplicate(); lineAttributes.ObjectColor = line.Color; lineAttributes.ColorSource = ObjectColorSource.ColorFromObject; lineAttributes.LayerIndex = layerIndex; obj_ids.Add(doc.Objects.AddLine(line.Line, lineAttributes)); } foreach (var line in _typedLines) { var lineAttributes = att.Duplicate(); lineAttributes.ObjectColor = line.Color; lineAttributes.ColorSource = ObjectColorSource.ColorFromObject; lineAttributes.LayerIndex = layerIndex; obj_ids.Add(doc.Objects.AddLine(line.Line, lineAttributes)); var oneQuarterPoint = line.Line.From + (line.Line.To - line.Line.From) / 4; var dotAttributes = att.Duplicate(); dotAttributes.ObjectColor = line.Color; dotAttributes.ColorSource = ObjectColorSource.ColorFromObject; dotAttributes.LayerIndex = layerIndex; obj_ids.Add(doc.Objects.AddTextDot(line.Type, oneQuarterPoint, dotAttributes)); } foreach (var line in _outLines) { var lineAttributes = att.Duplicate(); lineAttributes.ObjectColor = line.Color; lineAttributes.ColorSource = ObjectColorSource.ColorFromObject; lineAttributes.LayerIndex = layerIndex; obj_ids.Add(doc.Objects.AddLine(line.Line, lineAttributes)); var dotAttributes = att.Duplicate(); dotAttributes.ObjectColor = line.Color; dotAttributes.ColorSource = ObjectColorSource.ColorFromObject; dotAttributes.LayerIndex = layerIndex; obj_ids.Add(doc.Objects.AddTextDot(Config.OUTER_MODULE_NAME, line.Line.To, dotAttributes)); } }
public void BakeGeometry(RhinoDoc doc, ObjectAttributes att, List <Guid> obj_ids) { if (att == null) { att = doc.CreateDefaultAttributes(); } foreach (object obj in m_data) { Guid guid; if (obj != null && obj is IGH_BakeAwareData && ((IGH_BakeAwareData)obj).BakeGeometry((RhinoDoc)doc, (ObjectAttributes)att, out guid)) { obj_ids.Add(guid); } } }
bool IGH_BakeAwareData.BakeGeometry(RhinoDoc doc, ObjectAttributes att, out Guid id) { id = Guid.Empty; if (m_value == null) { return(false); } if (att == null) { att = doc.CreateDefaultAttributes(); } id = doc.Objects.AddText(m_value, att); return(true); }
public void BakeGeometry(RhinoDoc doc, ObjectAttributes att, List <Guid> obj_ids) { if (att == null) { att = doc.CreateDefaultAttributes(); } foreach (IGH_BakeAwareObject item in m_data) { if (item != null) { var idsOut = new List <Guid>(); item.BakeGeometry(doc, att, idsOut); obj_ids.AddRange(idsOut); } } }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { Point3d[] corners; var rc = RhinoGet.GetRectangle(out corners); if (rc != Result.Success) { return(rc); } var plane = new Plane(corners[0], corners[1], corners[2]); var plane_surface = new PlaneSurface( plane, new Interval(0, corners[0].DistanceTo(corners[1])), new Interval(0, corners[1].DistanceTo(corners[2])) ); rc = Result.Cancel; if (plane_surface.IsValid) { var layer_name = doc.Layers.GetUnusedLayerName(); rc = RhinoGet.GetString("Name of layer to create", true, ref layer_name); if (rc == Result.Success && !string.IsNullOrEmpty(layer_name)) { var layer_index = doc.Layers.FindByFullPath(layer_name, -1); if (-1 == layer_index) { layer_index = doc.Layers.Add(layer_name, System.Drawing.Color.Black); } if (layer_index >= 0) { var attribs = doc.CreateDefaultAttributes(); attribs.LayerIndex = layer_index; attribs.Name = layer_name; doc.Objects.AddSurface(plane_surface, attribs); doc.Views.Redraw(); rc = Result.Success; } } } return(rc); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // Define a line var line = new Rhino.Geometry.Line(new Rhino.Geometry.Point3d(0, 0, 0), new Rhino.Geometry.Point3d(10, 0, 0)); // Make a copy of Rhino's default object attributes var attribs = doc.CreateDefaultAttributes(); // Modify the object decoration style attribs.ObjectDecoration = Rhino.DocObjects.ObjectDecoration.StartArrowhead; // Create a new curve object with our attributes doc.Objects.AddLine(line, attribs); doc.Views.Redraw(); return(Rhino.Commands.Result.Success); }
public static ObjectAttributes GetAttributes(RhinoDoc document, JObject data) { var attributes = document.CreateDefaultAttributes(); if (data.TryGetValue <string>("key", out var key)) { attributes.Name = key; } if (data.TryGetValue <string>("color", out var color)) { var argb = int.Parse(color.Replace("#", ""), System.Globalization.NumberStyles.HexNumber); attributes.ColorSource = ObjectColorSource.ColorFromObject; attributes.ObjectColor = System.Drawing.Color.FromArgb(argb); } if (data.TryGetValue <string>("layer", out var layer)) { attributes.LayerIndex = CreateLayer(document, layer).Index; } if (data.TryGetValue <string>("arrowhead", out var arrowhead)) { if (arrowhead == "start") { attributes.ObjectDecoration = ObjectDecoration.StartArrowhead; } if (arrowhead == "end") { attributes.ObjectDecoration = ObjectDecoration.EndArrowhead; } if (arrowhead == "both") { attributes.ObjectDecoration = ObjectDecoration.BothArrowhead; } } return(attributes); }
/// <summary> /// Bakes the <see cref="Cage"/> in color hinting its entropy. Required /// by Grasshopper. /// </summary> /// <param name="doc">The doc.</param> /// <param name="att">The att.</param> /// <param name="obj_ids">The obj_ids.</param> public void BakeGeometry(RhinoDoc doc, ObjectAttributes att, List <Guid> obj_ids) { if (att == null) { att = doc.CreateDefaultAttributes(); } var color = Config.CAGE_UNKNOWN_COLOR; if (AllowsAnyModule) { color = Config.CAGE_EVERYTHING_COLOR; } if (IsContradictory || !IsValid) { color = Config.CAGE_NONE_COLOR; } var partsCount = AllowedPartNames.Count; if (partsCount == 1 && AllPartsCount != 0) { color = Config.CAGE_ONE_COLOR; } if (partsCount != 1 && AllPartsCount != 0) { var t = (double)partsCount / AllPartsCount; color = InterpolateColor(Config.CAGE_TWO_COLOR, Config.CAGE_EVERYTHING_COLOR, t); } var cageAttributes = att.Duplicate(); cageAttributes.ObjectColor = color; cageAttributes.ColorSource = ObjectColorSource.ColorFromObject; obj_ids.Add(doc.Objects.AddBox(Cage, cageAttributes)); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // Create a circle curve var circle = new Circle(Plane.WorldXY, 5.0); var curve0 = new ArcCurve(circle); // Add an instance defintion that uses the circle curve var attrib = doc.CreateDefaultAttributes(); var idef0_index = doc.InstanceDefinitions.Add("Circle", "Circle", Point3d.Origin, curve0, attrib); // Create a reference to the instance definition var idef0_id = doc.InstanceDefinitions[idef0_index].Id; var iref0 = new InstanceReferenceGeometry(idef0_id, Transform.Identity); // Create a polyline curve var rect = new Point3d[5]; rect[0] = new Point3d(-5.0, -5.0, 0.0); rect[1] = new Point3d(5.0, -5.0, 0.0); rect[2] = new Point3d(5.0, 5.0, 0.0); rect[3] = new Point3d(-5.0, 5.0, 0.0); rect[4] = rect[0]; var curve1 = new PolylineCurve(rect); // Add another instance definition that uses the polyline curve // and the instance reference var geometry = new GeometryBase[] { curve1, iref0 }; var attributes = new[] { attrib, attrib }; var idef1_index = doc.InstanceDefinitions.Add("Rectangle and Circle", "Rectangle and Circle", Point3d.Origin, geometry, attributes); // Add an instace of the new defintion to the document and redraw doc.Objects.AddInstanceObject(idef1_index, Transform.Identity); doc.Views.Redraw(); return(Result.Success); }
public bool BakeGeometry(RhinoDoc doc, ObjectAttributes att, out Guid obj_guid) { obj_guid = Guid.Empty; if (att == null) { att = doc.CreateDefaultAttributes(); } string id = Guid.NewGuid().ToString(); int idxGr = doc.Groups.Add("IG-" + id); int idxLy = doc.Layers.Add("IG-" + id, Color.Aqua); ObjectAttributes att1 = att.Duplicate(); att1.AddToGroup(idxGr); att1.LayerIndex = idxLy; Line ln; List <long> edgesID = new List <long>(); long data1, data2; Point3d p1, p2; int next, count; int[] hf; foreach (int elementID in ElementsKeys) { IElement e = GetElementWithKey(elementID); for (int halfFacetID = 1; halfFacetID <= e.HalfFacetsCount; halfFacetID++) { e.GetHalfFacet(halfFacetID, out hf); count = 1; if (e.TopologicDimension == 3) { count = hf.Length; } for (int i = 0; i < count; i++) { next = i + 1; if (i == count - 1) { if (count > 1) { next = 0; } else { next = 1; } } data1 = (Int64)hf[i] << 32 | (Int64)hf[next]; data2 = (Int64)hf[next] << 32 | (Int64)hf[i]; if (!edgesID.Contains(data1) && !edgesID.Contains(data2)) { p1 = GetVertexWithKey(hf[i]).RhinoPoint; p2 = GetVertexWithKey(hf[next]).RhinoPoint; ln = new Line(p1, p2); doc.Objects.AddLine(ln, att1); edgesID.Add(data1); } } } } return(true); }
/// <summary> /// Command.RunCommand override /// </summary> protected override Result RunCommand(RhinoDoc doc, RunMode mode) { Potrace.Clear(); // Prompt the user for the name of the image file to vectorize. string path = GetImageFileName(mode); if (string.IsNullOrEmpty(path)) { return(Result.Cancel); } // Creates a bitmap from the specified file. var bitmap = Image.FromFile(path) as Bitmap; if (null == bitmap) { RhinoApp.WriteLine("The specified file cannot be identifed as a supported type."); return(Result.Failure); } // Verify bitmap size if (0 == bitmap.Width || 0 == bitmap.Height) { RhinoApp.WriteLine("Error reading the specified file."); return(Result.Failure); } // Calculate scale factor so curves of a reasonable size are added to Rhino var unit_scale = (doc.ModelUnitSystem != UnitSystem.Inches) ? RhinoMath.UnitScale(UnitSystem.Inches, doc.ModelUnitSystem) : 1.0; var scale = (double)(1.0 / bitmap.HorizontalResolution * unit_scale); // I'm not convinced this is useful... if (true) { var format = $"F{doc.DistanceDisplayPrecision}"; // Print image size in pixels RhinoApp.WriteLine("Image size in pixels: {0} x {1}", bitmap.Width, bitmap.Height ); // Print image size in inches var width = (double)(bitmap.Width / bitmap.HorizontalResolution); var height = (double)(bitmap.Height / bitmap.VerticalResolution); RhinoApp.WriteLine("Image size in inches: {0} x {1}", width.ToString(format, CultureInfo.InvariantCulture), height.ToString(format, CultureInfo.InvariantCulture) ); // Image size in in model units, if needed if (doc.ModelUnitSystem != UnitSystem.Inches) { width = (double)(bitmap.Width / bitmap.HorizontalResolution * unit_scale); height = (double)(bitmap.Height / bitmap.VerticalResolution * unit_scale); RhinoApp.WriteLine("Image size in {0}: {1} x {2}", doc.ModelUnitSystem.ToString().ToLower(), width.ToString(format, CultureInfo.InvariantCulture), height.ToString(format, CultureInfo.InvariantCulture) ); } } // Convert the bitmap to an Eto bitmap var eto_bitmap = ConvertBitmapToEto(bitmap); if (null == eto_bitmap) { RhinoApp.WriteLine("Unable to convert image to Eto bitmap."); return(Result.Failure); } // 12-Jan-2021 Dale Fugier // This should prevent Eto.Drawing.BitmapData.GetPixels() from throwing an exception if (!IsCompatibleBitmap(eto_bitmap)) { RhinoApp.WriteLine("The image has an incompatible pixel format. Please select an image with 24 or 32 bits per pixel, or 8 bit indexed."); return(Result.Failure); } // This bitmap is not needed anymore, so dispose of it bitmap.Dispose(); // Gets the Potrace settings from the plug-in settings file GetPotraceSettings(); // Create the conduit, which does most of the work var conduit = new VectorizeConduit( eto_bitmap, scale, doc.ModelAbsoluteTolerance, m_select_output ? Rhino.ApplicationSettings.AppearanceSettings.SelectedObjectColor : doc.Layers.CurrentLayer.Color ) { Enabled = true }; if (mode == RunMode.Interactive) { // Show the interactive dialog box var dialog = new VectorizeDialog(doc, conduit); dialog.RestorePosition(); var result = dialog.ShowSemiModal(doc, RhinoEtoApp.MainWindow); dialog.SavePosition(); if (result != Result.Success) { conduit.Enabled = false; Potrace.Clear(); doc.Views.Redraw(); return(Result.Cancel); } } else { // Show the command line options var go = new GetOption(); go.SetCommandPrompt("Vectorization options. Press Enter when done"); go.AcceptNothing(true); while (true) { conduit.TraceBitmap(); doc.Views.Redraw(); go.ClearCommandOptions(); // IgnoreArea var turdsize_opt = new OptionInteger(Potrace.turdsize, 2, 100); var turdsize_idx = go.AddOptionInteger("FilterSize", ref turdsize_opt, "Filter speckles of up to this size in pixels"); // TurnPolicy var turnpolicy_idx = go.AddOptionEnumList("TurnPolicy", Potrace.turnpolicy); // Optimizing var curveoptimizing_opt = new OptionToggle(Potrace.curveoptimizing, "No", "Yes"); var curveoptimizing_idx = go.AddOptionToggle("Optimizing", ref curveoptimizing_opt); // Tolerance var opttolerance_opt = new OptionDouble(Potrace.opttolerance, 0.0, 1.0); var opttolerance_idx = go.AddOptionDouble("Tolerance", ref opttolerance_opt, "Optimizing tolerance"); // CornerThreshold var alphamax_opt = new OptionDouble(Potrace.alphamax, 0.0, 100.0); var alphamax_idx = go.AddOptionDouble("CornerRounding", ref alphamax_opt, "Corner rounding threshold"); // Threshold var threshold_opt = new OptionDouble(Potrace.Treshold, 0.0, 100.0); var threshold_idx = go.AddOptionDouble("Threshold", ref threshold_opt, "Threshold"); // RestoreDefaults var defaults_idx = go.AddOption("RestoreDefaults"); var res = go.Get(); if (res == GetResult.Option) { var option = go.Option(); if (null != option) { if (turdsize_idx == option.Index) { Potrace.turdsize = turdsize_opt.CurrentValue; } if (turnpolicy_idx == option.Index) { var list = Enum.GetValues(typeof(TurnPolicy)).Cast <TurnPolicy>().ToList(); Potrace.turnpolicy = list[option.CurrentListOptionIndex]; } if (curveoptimizing_idx == option.Index) { Potrace.curveoptimizing = curveoptimizing_opt.CurrentValue; } if (opttolerance_idx == option.Index) { Potrace.opttolerance = opttolerance_opt.CurrentValue; } if (alphamax_idx == option.Index) { Potrace.alphamax = alphamax_opt.CurrentValue; } if (threshold_idx == option.Index) { Potrace.Treshold = threshold_opt.CurrentValue; } if (defaults_idx == option.Index) { Potrace.RestoreDefaults(); } } continue; } if (res != GetResult.Nothing) { conduit.Enabled = false; doc.Views.Redraw(); Potrace.Clear(); return(Result.Cancel); } break; } } // Group curves var attributes = doc.CreateDefaultAttributes(); attributes.AddToGroup(doc.Groups.Add()); for (var i = 0; i < conduit.OutlineCurves.Count; i++) { var rhobj_id = doc.Objects.AddCurve(conduit.OutlineCurves[i], attributes); if (m_select_output) { var rhobj = doc.Objects.Find(rhobj_id); if (null != rhobj) { rhobj.Select(true); } } } conduit.Enabled = false; Potrace.Clear(); doc.Views.Redraw(); // Set the Potrace settings to the plug -in settings file. SetPotraceSettings(); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // A properties of a Rhino material define what is required to draw an // object using OpenGL. Most rendering plug-ins require a much richer // defintion than this. And, not all rendering plug-ins support the // same material properties. This is where Render materials come in. // An Render material is an abstract material - one that is defined // by the the owning render plug-in. But a basic Render material does // share some properties with a Rhino material. // This example demonstrates how to create a basic Render material. // This material will appear in Rhino's Materials panel. It it called // basic material because it does not target any particular rendering // plug-in. // 1.) Create some Rhino materials var red_material = new Material { DiffuseColor = Color.Red, Name = "Red" }; var green_material = new Material { DiffuseColor = Color.Green, Name = "Green" }; var blue_material = new Material { DiffuseColor = Color.Blue, Name = "Blue" }; // 2.) Create basic Render materials from Rhino materials var red_render_material = RenderMaterial.CreateBasicMaterial(red_material); var green_render_material = RenderMaterial.CreateBasicMaterial(green_material); var blue_render_material = RenderMaterial.CreateBasicMaterial(blue_material); // 3.) Add basic Render materials to the RDK document RenderContent.AddPersistentRenderContent(red_render_material); RenderContent.AddPersistentRenderContent(green_render_material); RenderContent.AddPersistentRenderContent(blue_render_material); // At this point, you will see render materials show up in Rhino's // Materials panel. Note, doc.Materials.Count will equal 0. This is // because we have not added any Rhino materials. We've only added // Render materials. When you assign a Render material to an object // or a layer, a compatible Rhino material will be added doc.Materials, // and this materiall will be referenced by the Render material. // Note, it is possible to add Rhino materials to the document. However, // they will not appear in the Materials panel until they are assigned // to objects or layers. Here is an example of this. // 1.) Create a Rhino material var magenta_material = new Material { DiffuseColor = Color.Magenta, Name = "Magenta" }; // 2.) Add the Rhino material to the document var magenta_material_index = doc.Materials.Add(magenta_material); // 3.) Create an object and assign the Rhino material to it. var sphere = new Sphere(Plane.WorldXY, 5); var attributes = doc.CreateDefaultAttributes(); attributes.MaterialSource = ObjectMaterialSource.MaterialFromObject; attributes.MaterialIndex = magenta_material_index; doc.Objects.AddSphere(sphere, attributes); doc.Views.Redraw(); return(Result.Success); }
public Guid Bake(RhinoDoc doc, ObjectAttributes att = null, bool flipYZ = false) { if (att == null) { att = doc.CreateDefaultAttributes(); } if (!string.IsNullOrEmpty(Layer)) { var layer = doc.Layers.FindName(Layer, RhinoMath.UnsetIntIndex); if (layer == null) { att.LayerIndex = doc.Layers.Add(new Layer() { Name = Layer }); } else { att.LayerIndex = layer.Index; } } var geometry = Geometry; if (Geometry is Mesh) { if (flipYZ) { geometry = (Geometry as Mesh).FlipYZ(); } if (Material != null) { att.ColorSource = ObjectColorSource.ColorFromMaterial; att.MaterialSource = ObjectMaterialSource.MaterialFromObject; double transparency = Material.Transparency; if (flipYZ) { transparency = 1 - transparency; } var material = new Material { DiffuseColor = Material.Diffuse, EmissionColor = Material.Emission, Transparency = transparency }; var texture = Material.GetBitmapTexture(true); if (texture != null) { material.SetBitmapTexture(texture); } var matIndex = doc.Materials.Add(material); att.MaterialIndex = matIndex; } } else if (Material != null) { att.ColorSource = ObjectColorSource.ColorFromObject; att.ObjectColor = Material.Diffuse; } return(doc.Objects.Add(geometry, att)); }