static void Main(string[] args) { ComputeServer.AuthToken = Rhino.Compute.AuthToken.Get(); var cube = new Box(new BoundingBox(-0.5, -0.5, -0.5, 0.5, 0.5, 0.5)); var sphere = new Sphere(new Point3d(0.5, 0.5, 0.5), 0.8); Brep[] cubeBrep = new Brep[] { cube.ToBrep() }; Brep[] sphereBrep = new Brep[] { sphere.ToBrep() }; const double tolerance = 1.0e-8; List <Brep> allBreps = new List <Brep>(); allBreps.AddRange(cubeBrep); allBreps.AddRange(sphereBrep); Brep[] union = BrepCompute.CreateBooleanUnion(allBreps, tolerance); Rhino.Compute.ObjExport.ExportBrepsToObj("cube_sphere_union.obj", union); Brep[] intersection = BrepCompute.CreateBooleanIntersection(cubeBrep, sphereBrep, tolerance); Rhino.Compute.ObjExport.ExportBrepsToObj("cube_sphere_intersection.obj", intersection); Brep[] difference = BrepCompute.CreateBooleanDifference(cubeBrep, sphereBrep, tolerance); Rhino.Compute.ObjExport.ExportBrepsToObj("cube_sphere_difference.obj", difference); }
private void GenerateGeo() { model = new Rhino.FileIO.File3dm(); int num = 10; float outerRad = 2f; var curves = new List <Rhino.Geometry.NurbsCurve>(); for (int i = 0; i < num; i++) { var pt = new Rhino.Geometry.Point3d(0, 0, height / (num - 1) * i); var circle = new Rhino.Geometry.Circle(pt, pipeRad); var polygon = Rhino.Geometry.Polyline.CreateInscribedPolygon(circle, segments); var curve = polygon.ToNurbsCurve(); curve.Rotate(i * Mathf.Deg2Rad * angle, new Rhino.Geometry.Vector3d(0, 0, 1), new Rhino.Geometry.Point3d(0, 0, 0)); curve.Translate(new Rhino.Geometry.Vector3d(Mathf.Cos(Mathf.Deg2Rad * angle * i), Mathf.Sin(Mathf.Deg2Rad * angle * i), 0) * outerRad); curves.Add(curve); } var breps = BrepCompute.CreateFromLoft(curves, Rhino.Geometry.Point3d.Unset, Rhino.Geometry.Point3d.Unset, Rhino.Geometry.LoftType.Normal, false); var meshList = new List <Rhino.Geometry.Mesh>(); foreach (var brep in breps) { var brep2 = brep.CapPlanarHoles(0.001); // generates two additional breps var meshes = MeshCompute.CreateFromBrep(brep2); meshList.AddRange(meshes.ToList()); model.Objects.AddBrep(brep2); } foreach (var mesh in meshList) { Mesh meshObj = new Mesh(); var vertices = new List <Vector3>(); foreach (var meshVertex in mesh.Vertices) { var vertex = new Vector3(meshVertex.X, meshVertex.Z, meshVertex.Y); vertices.Add(vertex); } var triangles = new List <int>(); foreach (var meshFace in mesh.Faces) { if (meshFace.IsTriangle) { triangles.Add(meshFace.C); triangles.Add(meshFace.B); triangles.Add(meshFace.A); } else if (meshFace.IsQuad) { triangles.Add(meshFace.C); triangles.Add(meshFace.B); triangles.Add(meshFace.A); triangles.Add(meshFace.D); triangles.Add(meshFace.C); triangles.Add(meshFace.A); } } var normals = new List <Vector3>(); foreach (var normal in mesh.Normals) { normals.Add(new Vector3(normal.X, normal.Z, normal.Y)); } meshObj.vertices = vertices.ToArray(); meshObj.triangles = triangles.ToArray(); meshObj.normals = normals.ToArray(); GameObject gb = new GameObject(); gb.AddComponent <MeshFilter>().mesh = meshObj; gb.AddComponent <MeshRenderer>().material = mat; } }