public DrawBlueMeshConduit(Mesh mesh) { // set up as much data as possible so we do the minimum amount of work possible inside // the actual display code m_mesh = mesh; m_color = System.Drawing.Color.Blue; m_material = new DisplayMaterial(); m_material.Diffuse = m_color; if (m_mesh != null && m_mesh.IsValid) { m_bbox = m_mesh.GetBoundingBox(true); } }
/***************************************************/ /**** Public Methods - Interfaces ****/ /***************************************************/ public static void IRenderRhinoMeshes(this object obj, GH_PreviewMeshArgs args, Color custom) { if (obj == null) { return; } DisplayMaterial material = RenderMaterial(args.Material, custom); try { RenderRhinoMeshes(obj as dynamic, args.Pipeline, material); } catch (Exception) { } }
public DrawPreviewMeshConduit(Mesh mesh, Mesh wireFrameMesh) { _mesh = mesh.ColorPolyhedron(); _wireFrameMesh = wireFrameMesh; _previewWireFrameMesh = mesh.ToWireFrame(); _wireFrameColor = Color.LightYellow; _color = Color.Red; _material = new DisplayMaterial(_color); _shouldDrawVertexColors = false; if (_mesh != null && _mesh.IsValid) { _bbox = _mesh.GetBoundingBox(true); } }
protected override void OnDraw(DrawEventArgs e) { if (e.Display.DrawingSurfaces) { var material = new DisplayMaterial(Color.FromArgb(120, 75, 190), 0.2); var mesh = Mesh.CreateFromBrep(this.BrepGeometry, MeshingParameters.Default)[0]; e.Display.DrawBrepWires(this.BrepGeometry, this.Attributes.DrawColor(e.RhinoDoc), this.Attributes.WireDensity); e.Display.DrawMeshShaded(mesh, material); } else { base.OnDraw(e); } }
public DrawPFBrepConduit(IList <Brep> breps, Color color, double transparency) { pfBrep = new List <Brep>(breps) ?? throw new System.ArgumentNullException(nameof(breps)); var allBrep = new Brep(); for (int i = 0; i < pfBrep.Count; i++) { DisplayMaterial mat = new DisplayMaterial(color, 0.8); material.Add(mat); allBrep.Append(pfBrep[i]); } bbox = allBrep.GetBoundingBox(false); }
internal void AddPreviewItem(string bitmap, Curve c, Rectangle3d bounds) { var mesh = Mesh.CreateFromPlanarBoundary(c, MeshingParameters.FastRenderMesh, 0.1); TextureMapping tm = TextureMapping.CreatePlaneMapping(bounds.Plane, bounds.X, bounds.Y, new Interval(-1, 1)); mesh.SetTextureCoordinates(tm, Transform.Identity, true); var mat = new DisplayMaterial(System.Drawing.Color.White); mat.SetBitmapTexture(bitmap, true); _previewItems.Add(new HeronRasterPreviewItem() { mesh = mesh, mat = mat }); }
public DrawPFMeshConduit(IList <Mesh> meshes, Color color, double transparency) { pfMesh = new List <Mesh>(meshes) ?? throw new System.ArgumentNullException(nameof(meshes)); var allMesh = new Mesh(); for (int i = 0; i < pfMesh.Count; i++) { DisplayMaterial mat = new DisplayMaterial(color, 0.8); material.Add(mat); allMesh.Append(pfMesh[i]); } bbox = allMesh.GetBoundingBox(false); }
/***************************************************/ /**** Public Methods ****/ /***************************************************/ public static DisplayMaterial RenderMaterial(DisplayMaterial material, Color custom) { Color pColour = GH.Instances.ActiveCanvas.Document.PreviewColour; Color ghColour = material.Diffuse; if (ghColour.R == pColour.R && // If the color sent by PreviewArgs is the default object PreviewColour ghColour.G == pColour.G && ghColour.B == pColour.B) // Excluding Alpha channel from comparison { double transparency = (255 - custom.A) / (double)255; return(new DisplayMaterial(custom, transparency)); } else { return(material); } }
protected override void SolveInstance(IGH_DataAccess DA) { Mesh mesh = new Mesh(); string file = string.Empty; DA.GetData(0, ref mesh); DA.GetData(1, ref file); Mesh outMesh = RenderExtensions.BitmapFromVertexColors(mesh, file); var material = new DisplayMaterial(); material.SetBitmapTexture(file, true); var display = new DisplayGeometry(outMesh, material); DA.SetData(0, new GH_DisplayGeometry(display)); }
//////////OVERRIDING DISPLAY IN VIEWPORT public override void DrawViewportMeshes(IGH_PreviewArgs args) { //Params.Output[0].VolatileData.AllData(true) //int myWireDensity = 1; System.Drawing.Color myGreen = System.Drawing.Color.FromArgb(0, 255, 0); System.Drawing.Color myYellow = System.Drawing.Color.FromArgb(255, 255, 0); System.Drawing.Color myRed = System.Drawing.Color.FromArgb(255, 0, 0); // base.DrawViewportMeshes(args); //////////:- //foreach (Mesh mm in meshes) //{ // args.Display.DrawMeshFalseColors(mm); //} //////////:- if (myPlanarSurface != null) { foreach (Surface temp in myPlanarSurface) { Brep temp2 = temp.ToBrep(); DisplayMaterial myMaterial = new DisplayMaterial(myGreen); //args.Display.DrawSurface(temp, myGreen, myWireDensity); args.Display.DrawBrepShaded(temp2, myMaterial); } } if (mySingleCurved != null) { foreach (Surface temp in mySingleCurved) { Brep temp2 = temp.ToBrep(); DisplayMaterial myMaterial = new DisplayMaterial(myYellow); //args.Display.DrawSurface(temp, myYellow, myWireDensity); args.Display.DrawBrepShaded(temp2, myMaterial); } } if (myDoubleCurved != null) { foreach (Surface temp in myDoubleCurved) { Brep temp2 = temp.ToBrep(); DisplayMaterial myMaterial = new DisplayMaterial(myRed); //args.Display.DrawSurface(temp, myRed, myWireDensity); args.Display.DrawBrepShaded(temp2, myMaterial); } } }
/***************************************************/ /**** Public Methods - Interfaces ****/ /***************************************************/ public static void IRenderMeshes(this BHG.IGeometry geometry, GH_PreviewMeshArgs args) { if (geometry == null) { return; } else if (!(geometry is BHG.ISurface) & !(geometry is BHG.Mesh)) { return; } DisplayMaterial bhMaterial = RenderMaterial(args.Material, Color.FromArgb(80, 255, 41, 105));//BHoM pink! try { RenderMeshes(geometry as dynamic, args.Pipeline, bhMaterial); } catch (Exception) { } }
protected override void OnDraw(DrawEventArgs e) { if (e.Display.DrawingSurfaces) { var material = new DisplayMaterial(Color.FromArgb(230, 180, 60), 0.2); material.BackDiffuse = Color.FromArgb(230, 180, 60); material.IsTwoSided = true; var m = new Mesh(); var meshs = Mesh.CreateFromBrep(this.BrepGeometry, MeshingParameters.Default); m.Append(meshs); e.Display.DrawBrepWires(this.BrepGeometry, this.Attributes.DrawColor(e.RhinoDoc), this.Attributes.WireDensity); e.Display.DrawMeshShaded(m, material); } else { base.OnDraw(e); } }
protected override void SolveInstance(IGH_DataAccess DA) { IGH_GeometricGoo geometry = null; DisplayMaterial material = null; string layer = ""; if (!DA.GetData(0, ref geometry)) { return; } DA.GetData(1, ref material); DA.GetData(2, ref layer); var target = GH_Convert.ToGeometryBase(geometry); var displayStyle = new DisplayGeometry(target, material, layer); DA.SetData(0, new GH_DisplayGeometry(displayStyle)); }
/***************************************************/ public static DisplayMaterial RenderMaterial(DisplayMaterial material, DisplayMaterial custom) { if (custom == null) { return(material); } Color pColour = GH.Instances.ActiveCanvas.Document.PreviewColour; Color ghColour = material.Diffuse; if (ghColour.R == pColour.R && // If the color sent by PreviewArgs is the default object PreviewColour ghColour.G == pColour.G && ghColour.B == pColour.B) // Excluding Alpha channel from comparison { return(custom); } else { return(material); } }
public void preview(IGH_PreviewArgs args) { DisplayMaterial m = new DisplayMaterial(Color.Red, 0.8); args.Display.DrawMeshShaded(Meshi, m); }
public DisplayGeometry(GeometryBase geometry, DisplayMaterial material, string layer = "") { Geometry = geometry; Material = material; Layer = layer; }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object can be used to retrieve data from input parameters and /// to store data in output parameters.</param> protected override void SolveInstance(IGH_DataAccess DA) { #region INPUTS // INPUTS // import Silkworm Movement List <GH_ObjectWrapper> s_Movement = new List <GH_ObjectWrapper>(); if (!DA.GetDataList(0, s_Movement)) { return; } int res = new int(); //if (!DA.GetData(4, ref res)) { } double startPrev = 0.0; if (!DA.GetData(1, ref startPrev)) { } double endPrev = 1.0; if (!DA.GetData(2, ref endPrev)) { } bool showlogistics = false; if (!DA.GetData(3, ref showlogistics)) { } bool showvalues = false; if (!DA.GetData(4, ref showvalues)) { } bool showmesh = false; if (!DA.GetData(5, ref showmesh)) { } bool showprinter = false; if (!DA.GetData(6, ref showprinter)) { } #endregion //Initialise these properties as soon as solveinstance begins if (DA.Iteration == 0) { //Visualise Print Logistics displayLogistics = new bool(); startPoints = new List <Line>(); endPoints = new List <Line>(); DelimitMarkers = new List <Line>(); //Visualise Print Values displayValues = new bool(); lineThicknesses = new List <double>(); Colors = new List <Color>(); Movements = new List <Line>(); blobPts = new List <Point3d>(); blobDiameter = new List <double>(); //Visualise Print Realistic displayMesh = new bool(); //m_meshes = new List<Mesh>(); //Visualise Printer displayPrinter = new bool(); bboxAll = new BoundingBox(); extclearance = new Mesh(); xcarriage = new List <Mesh>(); vizmaterial = new DisplayMaterial(Color.Yellow, 0.5); printArea = new List <Point3d>(); } //Output Holders Mesh sMesh = new Mesh(); displayLogistics = showlogistics; displayValues = showvalues; displayMesh = showmesh; displayPrinter = showprinter; List <Point3d> startPts = new List <Point3d>(); List <Point3d> endPts = new List <Point3d>(); //Sort through input geometry, check that it is a Silkworm Model foreach (GH_ObjectWrapper movement in s_Movement) { if (movement.Value is SilkwormModel) { SilkwormModel sModel = (SilkwormModel)movement.Value; printArea.Add(new Point3d(0, 0, 0)); printArea.Add(new Point3d(0, sModel.bed_size.Y, 0)); printArea.Add(new Point3d(sModel.bed_size.X, sModel.bed_size.Y, 0)); printArea.Add(new Point3d(sModel.bed_size.X, 0, 0)); bboxAll = new BoundingBox(new Point3d(0, 0, 0), new Point3d(sModel.bed_size.X, sModel.bed_size.Y, sModel.bed_size.Z)); sModel.displayModel(startPrev, endPrev, showmesh, res, out Movements, out lineThicknesses, out DelimitMarkers, out blobPts, out blobDiameter, out Colors, out sMesh, out startPts, out endPts); //Create Clearance Visualisation Geometry Point3d endPt = Movements[Movements.Count - 1].To; Plane plane = new Plane(endPt, Plane.WorldXY.ZAxis); Cone extcl = new Cone(plane, sModel.extruder_clearance_height, sModel.extruder_clearance_radius); extclearance = Mesh.CreateFromCone(extcl, 12, 30); double roddiameter = 8; Point3d PtA1 = new Point3d(0, endPt.Y + ((sModel.xbar_width / 2) - (roddiameter / 2)), endPt.Z + (roddiameter / 2) + sModel.extruder_clearance_height); Point3d PtA2 = new Point3d(0, endPt.Y - ((sModel.xbar_width / 2) - (roddiameter / 2)), endPt.Z + (roddiameter / 2) + sModel.extruder_clearance_height); Cylinder clyA = new Cylinder(new Circle(new Plane(PtA1, Plane.WorldYZ.ZAxis), roddiameter / 2), sModel.bed_size.X); Cylinder clyB = new Cylinder(new Circle(new Plane(PtA2, Plane.WorldYZ.ZAxis), roddiameter / 2), sModel.bed_size.X); Mesh cylA = Mesh.CreateFromCylinder(clyA, 12, 30); Mesh cylB = Mesh.CreateFromCylinder(clyB, 12, 30); xcarriage.AddRange(new Mesh[] { cylA, cylB }); foreach (Point3d point in startPts) { startPoints.Add(new Line(point, Plane.WorldXY.ZAxis, 0.01)); } foreach (Point3d point in endPts) { endPoints.Add(new Line(point, Plane.WorldXY.ZAxis, 0.01)); } } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Please Input Only Silkworm Models"); continue; } } //GH_Mesh outPipes = new GH_Mesh(sMesh); //DA.SetData(0, outPipes); }
/***************************************************/ /**** Public Methods - Curves ****/ /***************************************************/ public static void RenderMeshes(BHG.Arc arc, Rhino.Display.DisplayPipeline pipeline, DisplayMaterial material) { return; }
public void SetDeviceMaterial(DisplayMaterial device_material) { m_device_material = device_material; }
/// <summary> /// Pipeline constructor /// </summary> /// <param name="display"></param> public RhinoRenderingParameters(DisplayPipeline display, DisplayMaterial overrideMaterial = null) { Display = display; OverrideMaterial = overrideMaterial; }
/// <summary> /// Draw the specified mesh with the specified material in the current viewport /// </summary> /// <param name="mesh"></param> /// <param name="material"></param> public void Draw(RC.Mesh mesh, DisplayMaterial material) { Display.DrawMeshShaded(mesh, OverrideMaterial ?? material); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { List <IGH_GeometricGoo> objs = new List <IGH_GeometricGoo>(); DA.GetDataList(0, objs); string layerName = "Default"; object material = null; bool clearL = false; DA.GetData(1, ref layerName); DA.GetData(2, ref material); /*Rhino.DocObjects.ObjectAttributes att = new Rhino.DocObjects.ObjectAttributes(); * att.LayerIndex = doc.Layers.Find(layerName, true); * att.MaterialIndex = doc.Materials.Find(matName, true);*/ Rhino.DocObjects.ObjectAttributes att = new Rhino.DocObjects.ObjectAttributes(); //Set material if (material != null) { string matName = ""; DisplayMaterial mat = new DisplayMaterial(); Color col = new Color(); int isName = -1; int materialIndex = -1; try { matName = (material as GH_String).Value; isName = 1; } catch { try { mat = (material as GH_Material).Value; isName = 0; } catch { try { col = (material as GH_Colour).Value; mat = new DisplayMaterial(col); isName = 0; } catch { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Can't identify material object. Please supply render material name, GH material or color."); } } } if (isName == 1) { materialIndex = doc.Materials.Find(matName, true); att.MaterialSource = Rhino.DocObjects.ObjectMaterialSource.MaterialFromObject; if (materialIndex < 0) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Couldn't find material by name. If you're sure the material exists in the Rhino Material list, try adding it to one object manually. After that it should work."); } att.MaterialIndex = materialIndex; } else { materialIndex = doc.Materials.Add(); if (materialIndex > -1) { Rhino.DocObjects.Material m = doc.Materials[materialIndex]; m.Name = matName; m.AmbientColor = mat.Ambient; m.DiffuseColor = mat.Diffuse; m.EmissionColor = mat.Emission; //m.ReflectionColor = no equivalent m.SpecularColor = mat.Specular; m.Shine = mat.Shine; m.Transparency = mat.Transparency; //m.TransparentColor = no equivalent m.CommitChanges(); att.MaterialSource = Rhino.DocObjects.ObjectMaterialSource.MaterialFromObject; att.MaterialIndex = materialIndex; } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Couldn't add material. Try cleaning up your materials."); //This never happened to me. } } } DA.GetData(3, ref att); DA.GetData(4, ref clearL); //Delete objects by GUID doc.Objects.Delete(ids, true); for (int i = 0; i < objs.Count; i++) { GeometryBase gb; Point3d pt; Brep b; if (ids.Count <= i) { ids.Add(Guid.NewGuid()); } att.ObjectId = ids[i]; if (objs[i].CastTo <Point3d>(out pt)) { doc.Objects.AddPoint(pt, att); } else if (objs[i].CastTo <Brep>(out b)) { doc.Objects.AddBrep(b, att); } else if (objs[i].CastTo <GeometryBase>(out gb)) { doc.Objects.Add(gb, att); } else { throw new Exception("Object nr. " + i + " is not bakeable:\n" + objs[i].ToString() + ".\nIf it's a box or a curve, try turning it into a Brep by wiring it through a Brep container component before feeding it to Instant Bake."); } } if (clearL) { foreach (Rhino.DocObjects.RhinoObject o in doc.Objects.FindByLayer(layerName)) { doc.Objects.Delete(o, true); } } if (counter >= 10) { Rhino.RhinoDoc.ActiveDoc.ClearUndoRecords(true); counter = 0; } DA.SetDataList(0, ids); counter++; }
/// <summary> /// Draw a shaded BRep /// </summary> /// <param name="brep"></param> /// <param name="material"></param> public void Draw(RC.Brep brep, DisplayMaterial material) { Display.DrawBrepShaded(brep, material); }
protected override void PostDrawObjects(DrawEventArgs e) { if (VisibleList.Count == 0) { return; } base.PostDrawObjects(e); int count = 0; var LocalCopy = Geometry.ToArray(); foreach (var obj in LocalCopy) { if (VisibleList[count] && obj != null && !obj.IsDocumentControlled) { switch (obj.ObjectType) { case Rhino.DocObjects.ObjectType.Point: e.Display.DrawPoint(((Rhino.Geometry.Point)obj).Location, PointStyle.X, 2, Colors[count]); break; case Rhino.DocObjects.ObjectType.Curve: e.Display.DrawCurve(( Curve )obj, Colors[count]); break; case Rhino.DocObjects.ObjectType.Extrusion: DisplayMaterial eMaterial = new DisplayMaterial(Colors[count], 0.5); e.Display.DrawBrepShaded((( Extrusion )obj).ToBrep(), eMaterial); break; case Rhino.DocObjects.ObjectType.Brep: DisplayMaterial bMaterial = new DisplayMaterial(Colors[count], 0.5); e.Display.DrawBrepShaded(( Brep )obj, bMaterial); //e.Display.DrawBrepWires((Brep)obj, Color.DarkGray, 1); break; case Rhino.DocObjects.ObjectType.Mesh: var mesh = obj as Mesh; if (mesh.VertexColors.Count > 0) { for (int i = 0; i < mesh.VertexColors.Count; i++) { mesh.VertexColors[i] = Color.FromArgb(100, mesh.VertexColors[i]); } e.Display.DrawMeshFalseColors(mesh); } else { DisplayMaterial mMaterial = new DisplayMaterial(Colors[count], 0.5); e.Display.DrawMeshShaded(mesh, mMaterial); } //e.Display.DrawMeshWires((Mesh)obj, Color.DarkGray); break; case Rhino.DocObjects.ObjectType.TextDot: //e.Display.Draw3dText( ((TextDot)obj).Text, Colors[count], new Plane(((TextDot)obj).Point)); var textDot = ( TextDot )obj; e.Display.DrawDot(textDot.Point, textDot.Text, Colors[count], Color.White); break; case Rhino.DocObjects.ObjectType.Annotation: if (obj is TextEntity) { var textObj = (Rhino.Geometry.TextEntity)obj; #if WINR6 var textHeight = Rhino.RhinoDoc.ActiveDoc.DimStyles.FindId(textObj.DimensionStyleId).TextHeight; e.Display.Draw3dText(textObj.PlainText, Colors[count], textObj.Plane, textHeight, textObj.Font.FaceName); #else e.Display.Draw3dText(textObj.Text, Color.Black, textObj.Plane, textObj.TextHeight, Rhino.RhinoDoc.ActiveDoc.Fonts[textObj.FontIndex].FaceName); #endif } break; } } count++; } }
/***************************************************/ /**** Public Methods - Miscellanea ****/ /***************************************************/ public static void RenderMeshes(BHG.BoundingBox bbBox, Rhino.Display.DisplayPipeline pipeline, DisplayMaterial material) { pipeline.DrawBrepShaded(RHG.Brep.CreateFromBox(bbBox.ToRhino()), material); }
/***************************************************/ public static void RenderMeshes(BHG.CompositeGeometry composite, Rhino.Display.DisplayPipeline pipeline, DisplayMaterial material) { if (composite.Elements.Count == 0) { return; } foreach (BHG.IGeometry geom in composite.Elements) { try { RenderMeshes(geom as dynamic, pipeline, material); } catch (Exception) { } } }
protected static DisplayMaterial CreateDefaultMaterial() { var result = new DisplayMaterial(Color.Gray, Color.White, Color.FromArgb(40, 40, 60), Color.FromArgb(60, 60, 60), 0.75, 0); return(result); }
public void SetPointerMeshMaterial(DisplayMaterial pointer_mesh_material) { m_pointer_mesh_material = pointer_mesh_material; }
protected override void DrawOverlay(DrawEventArgs e) { base.DrawOverlay(e); if (HoverRange == null) { return; } var LocalCopy = Geometry.ToArray(); for (int i = ( int )HoverRange.Value.T0; i < HoverRange.Value.T1; i++) { if (LocalCopy[i] != null) { var obj = LocalCopy[i]; if (obj.IsDocumentControlled) { continue; } switch (obj.ObjectType) { case Rhino.DocObjects.ObjectType.Point: e.Display.DrawPoint(((Rhino.Geometry.Point)obj).Location, PointStyle.X, 4, Color.Orange); break; case Rhino.DocObjects.ObjectType.Curve: e.Display.DrawCurve(( Curve )obj, Color.Orange); break; case Rhino.DocObjects.ObjectType.Brep: DisplayMaterial bMaterial = new DisplayMaterial(Color.Orange, 0.5); e.Display.DrawBrepShaded(( Brep )obj, bMaterial); //e.Display.DrawBrepWires((Brep)obj, Color.DarkGray, 1); break; case Rhino.DocObjects.ObjectType.Mesh: DisplayMaterial mMaterial = new DisplayMaterial(Color.Orange, 0.5); e.Display.DrawMeshShaded(( Mesh )obj, mMaterial); //e.Display.DrawMeshWires((Mesh)obj, Color.DarkGray); break; case Rhino.DocObjects.ObjectType.TextDot: var textDot = ( TextDot )obj; e.Display.DrawDot(textDot.Point, textDot.Text, Color.Orange, Color.Black); break; case Rhino.DocObjects.ObjectType.Annotation: if (obj is TextEntity) { var textObj = (Rhino.Geometry.TextEntity)obj; #if WINR6 e.Display.Draw3dText(textObj.PlainText, Color.Orange, textObj.Plane, textObj.TextHeight, textObj.Font.FaceName); #else e.Display.Draw3dText(textObj.Text, Color.Black, textObj.Plane, textObj.TextHeight, Rhino.RhinoDoc.ActiveDoc.Fonts[textObj.FontIndex].FaceName); #endif } break; } //var bbox = ( ( GeometryBase ) Geometry[ i ] ).GetBoundingBox( false ); bbox.Inflate( 5 ); //e.Display.DrawBoxCorners( bbox, Color.Orange, 5, 1 ); } } }
/***************************************************/ public static void RenderMeshes(BHG.CoordinateSystem.Cartesian coordinateSystem, Rhino.Display.DisplayPipeline pipeline, DisplayMaterial material) { return; }