Hello,
I was using rhinocompute and rhinocommon to create a box by extruding a curve, but when I drew on rhino, the box was drawn strangely.
Specifically, I created a box with the following 4 patterns.
1.extrude the curve
2.cap the brep made in 1
3.Extrude a surface on a curve
4.CreateFromLoft from two curves to create a face and extrude it
Of these, 2 and 4 were rendered incorrectly, as shown in the following pictures.
Is there any way to improve these?
using Rhino.Geometry;
using Rhino.FileIO;
using Rhino.DocObjects;
using Rhino.Compute;
namespace Extrusion_test
{
internal class Program
{
static void Main(string[] args)
{
/// Make 3dm file
var file = new File3dm();
/// create layer
ObjectAttributes attributes = new ObjectAttributes();
file.AllLayers.Add(new Layer { Name = "1.extrude the curve" });
file.AllLayers.Add(new Layer { Name = "2.cap the brep made in 1" });
file.AllLayers.Add(new Layer { Name = "3.Extrude a surface on a curve" });
file.AllLayers.Add(new Layer { Name = "4.CreateFromLoft from two curves to create a face and extrude it" });
/// Create a curve to extrude
Plane plane_xy = Plane.WorldXY;
var rec = new Rectangle3d(plane_xy, 100,100);
Curve curve = rec.ToNurbsCurve();
/// Create a offset curve to extrude
float offsetnum = 20;
Point3d pt1 = new Point3d(offsetnum, offsetnum, 0);
Point3d pt2 = new Point3d(100 - offsetnum, 100 - offsetnum, 0);
Rectangle3d offsetrec = new Rectangle3d(plane_xy, pt1, pt2);
Curve offset_curve = offsetrec.ToNurbsCurve();
/// Extrude the curve in four ways
/// Checking these drawings, 2 and 4 go wrong.
/// 1.extrude the curve
Surface extrudedSrf = SurfaceCompute.CreateExtrusion(curve, new Vector3d(0,0,100));
var extruded_brep = extrudedSrf.ToBrep();
attributes.LayerIndex = 0;
file.Objects.AddBrep(extruded_brep, attributes);
/// 2.cap the brep made in 1
Brep cappedBrep = BrepCompute.CapPlanarHoles(extruded_brep, 0.01);
cappedBrep.Transform(Transform.Translation(new Vector3d(200, 0, 0)));
attributes.LayerIndex = 1;
file.Objects.AddBrep(cappedBrep, attributes);
/// 3.Extrude a surface on a curve
var pathCurve = new LineCurve(new Point3d(0, 0, 0), new Point3d(0, 0, 100));
Brep[] breps = BrepCompute.CreatePlanarBreps(curve);
extruded_brep = breps[0].Faces[0].CreateExtrusion(pathCurve, true);
extruded_brep.Transform(Transform.Translation(new Vector3d(400, 0, 0)));
attributes.LayerIndex = 2;
file.Objects.AddBrep(extruded_brep, attributes);
/// 4.CreateFromLoft from two curves to create a face and extrude it
pathCurve = new LineCurve(new Point3d(0, 0, 0), new Point3d(0, 0, 100));
Brep[] loftSurfaces = BrepCompute.CreateFromLoft(new Curve[] { curve, offset_curve }, Point3d.Unset, Point3d.Unset, LoftType.Normal, false);
extruded_brep = loftSurfaces[0].Faces[0].CreateExtrusion(pathCurve, true);
extruded_brep.Transform(Transform.Translation(new Vector3d(600, 0, 0)));
attributes.LayerIndex = 3;
file.Objects.AddBrep(extruded_brep, attributes);
/// Save file
file.Write("extrusion.3dm", 6);
}
}
}
Any help is much appreciated
Thanks