public static Rhino.Commands.Result UnrollSurface2(Rhino.RhinoDoc doc) { const ObjectType filter = Rhino.DocObjects.ObjectType.Brep | Rhino.DocObjects.ObjectType.Surface; Rhino.DocObjects.ObjRef objref; Result rc = Rhino.Input.RhinoGet.GetOneObject("Select surface or brep to unroll", false, filter, out objref); if (rc != Rhino.Commands.Result.Success) { return(rc); } Rhino.Geometry.Unroller unroll = null; Rhino.Geometry.Brep brep = objref.Brep(); Rhino.Geometry.Mesh mesh = null; if (brep != null) { unroll = new Rhino.Geometry.Unroller(brep); mesh = brep.Faces[0].GetMesh(Rhino.Geometry.MeshType.Render); } else { Rhino.Geometry.Surface srf = objref.Surface(); if (srf != null) { unroll = new Rhino.Geometry.Unroller(srf); } } if (unroll == null || mesh == null) { return(Rhino.Commands.Result.Cancel); } unroll.AddFollowingGeometry(mesh.Vertices.ToPoint3dArray()); unroll.ExplodeOutput = false; Rhino.Geometry.Curve[] curves; Rhino.Geometry.Point3d[] points; Rhino.Geometry.TextDot[] dots; unroll.PerformUnroll(out curves, out points, out dots); // change the mesh vertices to the flattened form and add it to the document if (points.Length == mesh.Vertices.Count) { for (int i = 0; i < points.Length; i++) { mesh.Vertices.SetVertex(i, points[i]); } mesh.Normals.ComputeNormals(); } doc.Objects.AddMesh(mesh, objref.Object().Attributes); doc.Views.Redraw(); return(Rhino.Commands.Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select surface or polysurface to smash"); go.GeometryFilter = Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.PolysrfFilter; go.Get(); if (go.CommandResult() != Rhino.Commands.Result.Success) { return(go.CommandResult()); } Rhino.Geometry.Brep brep = go.Object(0).Brep(); if (null == brep) { return(Rhino.Commands.Result.Failure); } Rhino.Geometry.Unroller unroller = new Rhino.Geometry.Unroller(brep); unroller.AbsoluteTolerance = doc.ModelAbsoluteTolerance; unroller.RelativeTolerance = 1.0; // big relative tolerance for smash unroller.ExplodeSpacing = 2.0; unroller.ExplodeOutput = true; Rhino.Geometry.Curve[] unrolledCurves = null; Rhino.Geometry.Point3d[] unrolledPoints = null; Rhino.Geometry.TextDot[] unrolledDots = null; Rhino.Geometry.Brep[] output = unroller.PerformUnroll(out unrolledCurves, out unrolledPoints, out unrolledDots); if (null != output) { for (int i = 0; i < output.Length; i++) { doc.Objects.Add(output[i]); } } doc.Views.Redraw(); return(Rhino.Commands.Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // TODO: complete command. var filter = Rhino.DocObjects.ObjectType.Brep | Rhino.DocObjects.ObjectType.Surface; Rhino.DocObjects.ObjRef objref; Result rc = Rhino.Input.RhinoGet.GetOneObject("Select surface or brep to unroll", false, filter, out objref); if (rc != Rhino.Commands.Result.Success) { return(rc); } Rhino.Geometry.Unroller unroll = null; Rhino.Geometry.Brep brep = objref.Brep(); if (brep != null) { unroll = new Rhino.Geometry.Unroller(brep); } else { Rhino.Geometry.Surface srf = objref.Surface(); if (srf != null) { unroll = new Rhino.Geometry.Unroller(srf); } } if (unroll == null) { return(Rhino.Commands.Result.Cancel); } unroll.AbsoluteTolerance = 0.01; unroll.RelativeTolerance = 0.01; Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select points, curves, and dots to unroll with surface"); go.GeometryFilter = Rhino.DocObjects.ObjectType.Point | Rhino.DocObjects.ObjectType.Curve | Rhino.DocObjects.ObjectType.TextDot; go.AcceptNothing(true); go.GetMultiple(0, 0); if (go.CommandResult() != Rhino.Commands.Result.Success) { return(go.CommandResult()); } for (int i = 0; i < go.ObjectCount; i++) { objref = go.Object(i); Rhino.Geometry.GeometryBase g = objref.Geometry(); Rhino.Geometry.Point pt = g as Rhino.Geometry.Point; Rhino.Geometry.Curve crv = g as Rhino.Geometry.Curve; Rhino.Geometry.TextDot dot = g as Rhino.Geometry.TextDot; if (pt != null) { unroll.AddFollowingGeometry(pt.Location); } else if (crv != null) { unroll.AddFollowingGeometry(crv); } else if (dot != null) { unroll.AddFollowingGeometry(dot); } } unroll.ExplodeOutput = false; Rhino.Geometry.Curve[] curves; Rhino.Geometry.Point3d[] points; Rhino.Geometry.TextDot[] dots; Rhino.Geometry.Brep[] breps = unroll.PerformUnroll(out curves, out points, out dots); if (breps == null || breps.Length < 1) { return(Rhino.Commands.Result.Failure); } for (int i = 0; i < breps.Length; i++) { doc.Objects.AddBrep(breps[i]); } for (int i = 0; i < curves.Length; i++) { doc.Objects.AddCurve(curves[i]); } doc.Objects.AddPoints(points); for (int i = 0; i < dots.Length; i++) { doc.Objects.AddTextDot(dots[i]); } doc.Views.Redraw(); return(Rhino.Commands.Result.Success); }