/// <summary> /// Convert a Rhino mesh to a Nucleus one /// </summary> /// <param name="mesh"></param> /// <returns></returns> public static Mesh Convert(RC.Mesh mesh) { if (mesh == null) { return(null); } Mesh result = new Mesh(); for (int i = 0; i < mesh.Vertices.Count; i++) { result.AddVertex(Convert(mesh.Vertices[i])); // TODO: Vertex colours? } for (int i = 0; i < mesh.Faces.Count; i++) { RC.MeshFace mF = mesh.Faces[i]; if (mF.IsTriangle) { result.AddFace(mF.A, mF.B, mF.C); } else { result.AddFace(mF.A, mF.B, mF.C, mF.D); } } return(result); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { Rhino.Geometry.Point3d[] corners; Result rc = Rhino.Input.RhinoGet.GetRectangle(out corners); if (rc != Result.Success) { return(rc); } Rhino.Geometry.Plane plane = new Rhino.Geometry.Plane(corners[0], corners[1], corners[2]); Rhino.Geometry.Interval x_interval = new Rhino.Geometry.Interval(0, corners[0].DistanceTo(corners[1])); Rhino.Geometry.Interval y_interval = new Rhino.Geometry.Interval(0, corners[1].DistanceTo(corners[2])); Rhino.Geometry.Mesh mesh = Rhino.Geometry.Mesh.CreateFromPlane(plane, x_interval, y_interval, 10, 10); //mesh.FaceNormals.ComputeFaceNormals(); //mesh.Normals.ComputeNormals(); SampleCsDrawMeshConduit conduit = new SampleCsDrawMeshConduit(); conduit.Mesh = mesh; conduit.Enabled = true; doc.Views.Redraw(); string out_str = null; rc = Rhino.Input.RhinoGet.GetString("Press <Enter> to continue", true, ref out_str); conduit.Enabled = false; doc.Views.Redraw(); return(Result.Success); }
/***************************************************/ // Convert Guanaco mesh to Rhino mesh. public static Rhino.Geometry.Mesh GetRhinoMesh(Mesh mesh, out List <LineCurve> barElements) { barElements = new List <LineCurve>(); Rhino.Geometry.Mesh rhinoMesh = new Rhino.Geometry.Mesh(); foreach (Node node in mesh.Nodes) { rhinoMesh.Vertices.Add(node.Location); } foreach (Element element in mesh.Elements) { if (element is Element2D) { Element2D e = element as Element2D; int[] nodeIds = e.Nodes.Take(e.PrimaryNodeCount).Select(n => n.Id.AsInteger).ToArray(); if (nodeIds.Length == 4) { rhinoMesh.Faces.AddFace(nodeIds[0], nodeIds[1], nodeIds[2], nodeIds[3]); } else if (nodeIds.Length == 3) { rhinoMesh.Faces.AddFace(nodeIds[0], nodeIds[1], nodeIds[2]); } } else if (element is Element1D) { Element1D e = element as Element1D; barElements.Add(new LineCurve(rhinoMesh.Vertices[e.Nodes.First().Id.AsInteger], rhinoMesh.Vertices[e.Nodes.Last().Id.AsInteger])); } } return(rhinoMesh); }
/// <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) { List <Mesh> parts = new List <Mesh>(); List <Mesh> brdies = new List <Mesh>(); if (!DA.GetDataList(0, parts)) { return; } DA.GetDataList(1, brdies); IntPtr graphData = TopoCreator.initContactGraph(); for (int kd = 0; kd < parts.Count; kd++) { var mesh = parts[kd]; addToContactGraph(mesh, false, graphData); } for (int kd = 0; kd < brdies.Count; kd++) { var mesh = brdies[kd]; addToContactGraph(mesh, true, graphData); } Rhino.Geometry.Mesh rhmesh = new Rhino.Geometry.Mesh(); TopoCreator.getContactMesh(rhmesh, graphData); DA.SetData(0, rhmesh); TopoCreator.deleteContactGraph(graphData); return; }
/***************************************************/ /**** Public Methods - Mesh ****/ /***************************************************/ public static BHG.Mesh FromRhino(this RHG.Mesh rMesh) { if (rMesh == null) { return(null); } List <BHG.Point> vertices = rMesh.Vertices.ToList().Select(x => x.FromRhino()).ToList(); List <RHG.MeshFace> rFaces = rMesh.Faces.ToList(); List <BHG.Face> faces = new List <BHG.Face>(); for (int i = 0; i < rFaces.Count; i++) { if (rFaces[i].IsQuad) { faces.Add(new BHG.Face { A = rFaces[i].A, B = rFaces[i].B, C = rFaces[i].C, D = rFaces[i].D }); } if (rFaces[i].IsTriangle) { faces.Add(new BHG.Face { A = rFaces[i].A, B = rFaces[i].B, C = rFaces[i].C }); } } return(new BHG.Mesh { Vertices = vertices, Faces = faces }); }
/// <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) { var meshA = new Rhino.Geometry.Mesh(); var meshB = new Rhino.Geometry.Mesh(); bool fastApprox = false; if (!DA.GetData(0, ref meshA)) { return; } if (!DA.GetData(1, ref meshB)) { return; } if (!DA.GetData(2, ref fastApprox)) { return; } var iPt = new Point3d(); bool intersects = MeshMeshIntersect.TestIntersect(meshA, meshB, ref iPt); DA.SetData(0, intersects); if (intersects) { DA.SetData(1, iPt); } }
/// <summary> /// Convert to mesh to rhino mesh. If the mesh is already of type /// <see cref="RhinoMesh"/>, the underlying mesh <see cref="RhinoMesh.Mesh"/> /// is returned without creating a copy of it. Otherwise, a new rhino /// mesh instance is created from the supplied mesh. /// /// The following attributes/properties are taken into account. /// /// (1) Mesh topology (vertices, faces) /// (2) Vertex normals. /// (3) Vertex colors. /// /// </summary> /// /// <param name="mesh">Mesh.</param> /// /// <returns>Rhino mesh.</returns> /// /// <exception cref="ArgumentNullException">Is thrown when the mesh is null. /// </exception> public static Rhino.Geometry.Mesh Convert( this IReadonlyMesh mesh) { if (mesh == null) { throw new ArgumentNullException(nameof(mesh)); } var rmesh = mesh as RhinoMesh; if (rmesh != null) { return(rmesh.Mesh); } else { var out_mesh = new Rhino.Geometry.Mesh(); foreach (var v in mesh.Vertices) { out_mesh.Vertices.Add(v.Convert()); } foreach (var c in mesh.VertexColors) { out_mesh.VertexColors.Add(c); } foreach (var c in mesh.Faces) { out_mesh.Faces.AddFace(c.A, c.B, c.C, c.D); } return(out_mesh); } }
///////////////////////////////////////////////////// public static Mesh PointsToMesh(List <Point3d> pts1, List <Point3d> pts2, int nx, ref DataTree <LineCurve> listUCurves, ref DataTree <LineCurve> listVCurves) { int ny = pts1.Count; Rhino.Geometry.Mesh mesh = new Rhino.Geometry.Mesh(); for (int iy = 0; iy < ny; iy++) { for (int ix = 0; ix < nx; ix++) { mesh.Vertices.Add(new Point3d(pts1[iy] + (pts2[iy] - pts1[iy]) * (double)ix / (double)(nx - 1))); } } int i0, i1, i2, i3; for (int ix = 0; ix < (nx - 1); ix++) { for (int iy = 0; iy < (ny - 1); iy++) { i0 = ix + iy * nx; i1 = (ix + 1) + iy * nx; i2 = (ix + 1) + (iy + 1) * nx; i3 = ix + (iy + 1) * nx; mesh.Faces.AddFace(i0, i1, i2, i3); listUCurves.Add(new LineCurve(mesh.Vertices[i0], mesh.Vertices[i1]), new GH_Path(iy)); listVCurves.Add(new LineCurve(mesh.Vertices[i1], mesh.Vertices[i2]), new GH_Path(iy)); listUCurves.Add(new LineCurve(mesh.Vertices[i2], mesh.Vertices[i3]), new GH_Path(iy + 1)); listVCurves.Add(new LineCurve(mesh.Vertices[i3], mesh.Vertices[i0]), new GH_Path(iy)); } } mesh.Normals.ComputeNormals(); mesh.Compact(); return(mesh); }
/// <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) { Rhino.Geometry.Mesh mesh = new Rhino.Geometry.Mesh(); if (!DA.GetData(0, ref mesh)) { return; } if (!mesh.IsValid) { return; } // call the cpp function to solve the adjacency list var res = IGLRhinoCommon.Utils.getAdjacencyLst(ref mesh); // construct the index & pt tree from the adjacency list Grasshopper.DataTree <int> treeArray = new Grasshopper.DataTree <int>(); Grasshopper.DataTree <Point3d> ptArray = new Grasshopper.DataTree <Point3d>(); for (int i = 0; i < res.Count; i++) { var path = new Grasshopper.Kernel.Data.GH_Path(i); treeArray.AddRange(res[i], path); foreach (var id in res[i]) { ptArray.Add(mesh.Vertices[id], path); } } // assign to the output DA.SetDataTree(0, treeArray); DA.SetDataTree(1, ptArray); }
public void AddToRhino(MeshFilter meshFilter) { // get mesh from meshFilter component UnityEngine.Mesh mesh = meshFilter.mesh; // Vector3[] vertices = mesh.vertices; // Vector3[] normals = mesh.normals; Rhino.Geometry.Mesh RHmesh = new Rhino.Geometry.Mesh(); UnityEngine.Transform loc = meshFilter.transform; // extract each face foreach (Vector3 vect in mesh.vertices) { Vector3 pos = Vector3.Scale(vect, loc.localScale); RHmesh.Vertices.Add(pos.x + loc.localPosition.x, pos.z + loc.localPosition.z, pos.y + loc.localPosition.y); } // extract mesh faces for (int i = 0; i < mesh.triangles.Length; i += 3) { RHmesh.Faces.AddFace(mesh.triangles[i], mesh.triangles[i + 1], mesh.triangles[i + 2]); } RHmesh.Normals.ComputeNormals(); doc.Objects.AddMesh(RHmesh); doc.Views.Redraw(); }
private Vector3d findAndUpdateNewAverageNormal()//send some of this out to smaller function? { Vector3d newNormal = new Vector3d(0.0, 0.0, 0.0); double totalArea = AreaMassProperties.Compute(proxyAsMesh).Area; for (int i = 0; i < assignedFaces.Count; i++) { Vector3f normal = partition.controller.rhinoMesh.FaceNormals[assignedFaces[i]]; Rhino.Geometry.Mesh mesh = new Rhino.Geometry.Mesh(); for (int j = 0; j < partition.controller.wingMesh.faces[assignedFaces[i]].faceVerts.Count; j++) { Vector3f position = partition.controller.wingMesh.faces[assignedFaces[i]].faceVerts[j].position; mesh.Vertices.Add(position.X, position.Y, position.Z); } if (partition.controller.wingMesh.faces[assignedFaces[i]].faceVerts.Count == 3) { mesh.Faces.AddFace(0, 1, 2); } else if (partition.controller.wingMesh.faces[assignedFaces[i]].faceVerts.Count == 4) { mesh.Faces.AddFace(0, 1, 2, 3); } double area = AreaMassProperties.Compute(mesh).Area; mesh.Normals.ComputeNormals(); Vector3d areaWeightedNormal = Vector3d.Multiply(area / totalArea, mesh.FaceNormals[0]); newNormal = Vector3d.Add(newNormal, areaWeightedNormal); } return(Vector3d.Divide(newNormal, assignedFaces.Count)); }
static public UnityEngine.Mesh ToHost(this Rhino.Geometry.Mesh _mesh) { var result = new UnityEngine.Mesh(); if (_mesh.Vertices.Count > 65535) { result.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32; } using (var mesh = _mesh.DuplicateMesh()) { mesh.Faces.ConvertQuadsToTriangles(); result.SetVertices(mesh.Vertices.ToHost()); result.SetNormals(mesh.Normals.ToHost()); result.SetUVs(0, mesh.TextureCoordinates.ToHost()); int i = 0; int[] indices = new int[mesh.Faces.Count * 3]; foreach (var face in mesh.Faces) { indices[i++] = (face.C); indices[i++] = (face.B); indices[i++] = (face.A); } result.SetColors(mesh.VertexColors.ToHost()); result.SetIndices(indices, MeshTopology.Triangles, 0); } result.RecalculateBounds(); result.RecalculateNormals(); result.RecalculateTangents(); return(result); }
static public UnityEngine.Mesh ToHost(this Rhino.Geometry.Mesh _mesh) { var result = new UnityEngine.Mesh(); result.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32; using (var mesh = _mesh.DuplicateMesh()) { mesh.Faces.ConvertQuadsToTriangles(); result.SetVertices(mesh.Vertices.ToHost()); result.SetNormals(mesh.Normals.ToHost()); var colors = mesh.VertexColors.Select(col => new Color(col.R / 255.0f, col.G / 255.0f, col.B / 255.0f)).ToArray(); result.SetColors(colors); int i = 0; int[] indices = new int[mesh.Faces.Count * 3]; foreach (var face in mesh.Faces) { indices[i++] = (face.C); indices[i++] = (face.B); indices[i++] = (face.A); } result.SetIndices(indices, MeshTopology.Triangles, 0); } return(result); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // Pick a mesh ObjRef obj_ref; Result rc = RhinoGet.GetOneObject("Select mesh", false, ObjectType.Mesh, out obj_ref); if (rc != Result.Success) { return(rc); } Rhino.Geometry.Mesh mesh = obj_ref.Mesh(); if (null == mesh) { return(Result.Failure); } // Pick a point that is contrained to the mesh GetPoint gp = new GetPoint(); gp.SetCommandPrompt("Pick point on mesh"); gp.Constrain(mesh, false); gp.Get(); if (gp.CommandResult() != Result.Success) { return(gp.CommandResult()); } Point3d point = gp.Point(); doc.Objects.AddPoint(point); doc.Views.Redraw(); return(Result.Success); }
static public UnityEngine.Mesh ToHost(this Rhino.Geometry.Mesh _mesh) { var result = new UnityEngine.Mesh(); using (var mesh = _mesh.DuplicateMesh()) { mesh.Faces.ConvertQuadsToTriangles(); result.SetVertices(mesh.Vertices.ToHost()); result.SetNormals(mesh.Normals.ToHost()); int i = 0; int[] indices = new int[mesh.Faces.Count * 3]; foreach (var face in mesh.Faces) { indices[i++] = (face.C); indices[i++] = (face.B); indices[i++] = (face.A); } result.SetIndices(indices, MeshTopology.Triangles, 0); } return(result); }
/// <summary> /// Constructor to build a custom mesh from Rhino's mesh type /// </summary> /// <param name="source">the Rhino mesh</param> public Mesh(Rhino.Geometry.Mesh source) : this() { // Check that the mesh is oriented and manifold bool isOriented, hasBoundary; var isManifold = source.IsManifold(true, out isOriented, out hasBoundary); if (!isManifold || !isOriented) { return; } // Remove unused vertices source.Vertices.CullUnused(); //var faces = Enumerable.Range(0, source.Faces.Count).Select(i => source.TopologyVertices.IndicesFromFace(i)); //InitIndexed(source.TopologyVertices, faces); // Add vertices Vertices.Capacity = source.TopologyVertices.Count; foreach (Point3f p in source.TopologyVertices) { Vertices.Add(new Vertex(p)); } // Add faces (and construct halfedges and store in hash table) for (int i = 0; i < source.Faces.Count; i++) { var vertices = source.TopologyVertices.IndicesFromFace(i).Select(v => Vertices[v]); Faces.Add(vertices); } // Find and link halfedge pairs Halfedges.MatchPairs(); }
public static Mesh ToMesh(this rg.Mesh mesh) { List <Vertex> vertexCache = new List <Vertex>(); var meshOut = new Mesh(); var hasVertexColors = mesh.VertexColors.Count > 0; var hasVertexUVs = mesh.TextureCoordinates.Count > 0; for (int i = 0; i < mesh.Vertices.Count; i++) { var vertex = mesh.Vertices[i]; var vtxNormal = mesh.Normals[i]; var vtxUV = hasVertexUVs ? mesh.TextureCoordinates[i].ToUV() : default(UV); var color = hasVertexColors ? mesh.VertexColors[i].ToColor() : default(Color); var newVertex = meshOut.AddVertex(vertex.ToVector3(), vtxUV, vtxNormal.ToVector3(), color); vertexCache.Add(newVertex); } foreach (var face in mesh.Faces) { if (face.IsQuad) { var t1 = new Triangle(vertexCache[face.A], vertexCache[face.B], vertexCache[face.C]); var t2 = new Triangle(vertexCache[face.C], vertexCache[face.D], vertexCache[face.A]); meshOut.AddTriangle(t1); meshOut.AddTriangle(t2); } else { var triangle = new Triangle(vertexCache[face.A], vertexCache[face.B], vertexCache[face.C]); meshOut.AddTriangle(triangle); } } return(meshOut); }
/// <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) { Rhino.Geometry.Mesh mesh = new Rhino.Geometry.Mesh(); DA.GetData(0, ref mesh); DA.SetData(0, mesh.ToCustomMesh()); }
/***************************************************/ public static RHG.Mesh ToRhino(this BH.oM.Graphics.RenderMesh mesh) { if (mesh == null) { return(null); } List <RHG.Point3d> rVertices = mesh.Vertices.Select(x => x.ToRhino()).ToList(); List <BHG.Face> faces = mesh.Faces; List <RHG.MeshFace> rFaces = new List <RHG.MeshFace>(); for (int i = 0; i < faces.Count; i++) { if (faces[i].IsQuad()) { rFaces.Add(new RHG.MeshFace(faces[i].A, faces[i].B, faces[i].C, faces[i].D)); } else { rFaces.Add(new RHG.MeshFace(faces[i].A, faces[i].B, faces[i].C)); } } RHG.Mesh rMesh = new RHG.Mesh(); rMesh.Faces.AddFaces(rFaces); rMesh.Vertices.AddVertices(rVertices); Color[] colors = mesh.Vertices.Select(x => x.Color).ToArray(); rMesh.VertexColors.SetColors(colors); return(rMesh); }
// // Rhino Utilities // public static RhinoNamespace.Geometry.Mesh ToRhinoMesh(double[,] vertices, int[,] faces) { Mesh mesh = new RhinoNamespace.Geometry.Mesh(); for (int i = 0; i < vertices.GetLength(0); i++) { mesh.Vertices.Add(vertices[i, 0], vertices[i, 1], vertices[i, 2]); } if (faces.GetLength(1) == 3) { for (int i = 0; i < faces.GetLength(0); i++) { mesh.Faces.AddFace(faces[i, 0], faces[i, 1], faces[i, 2]); } } else // (faces.GetLength(1) == 4) { for (int i = 0; i < faces.GetLength(0); i++) { mesh.Faces.AddFace(faces[i, 0], faces[i, 1], faces[i, 2], faces[i, 3]); } } mesh.Normals.ComputeNormals(); mesh.Compact(); return(mesh); }
public bool MeshLineIntersect(Rhino.Geometry.Mesh x, Rhino.Geometry.Line L) //this is now for reading triangles from Rhino Mesh objects; can be eventually replaced with something, which reads OBJ mesh objects { //List<Point3d[]> TVs = new List<Point3d[]>(); //List of Triangle Vertices Point3d[] TV = new Point3d[3]; //Triangle Vertices Point3f av = default(Point3f); Point3f bv = default(Point3f); Point3f cv = default(Point3f); Point3f dv = default(Point3f); //Each face As MeshFace In x.Faces bool does = false; for (int k = 0; k <= x.Faces.Count - 1; k++) { x.Faces.GetFaceVertices(k, out av, out bv, out cv, out dv); TV = new Point3d[] { new Point3d(av), new Point3d(bv), new Point3d(cv) }; //TVs.Add(TV); if (TriangleLineIntersect(TV, x.FaceNormals[k], L)) { does = true; } } return(does);//TVs.Exists(Lambda => TriangleLineIntersect(Lambda, L)); }
public static int[][] RhinoMeshFaces(RhinoNamespace.Geometry.Mesh mesh) { int n = mesh.Faces.Count; int[][] vertexIndices = new int[n][]; var e = mesh.Faces.GetEnumerator(); for (int i = 0; i < n; i++) { e.MoveNext(); if (e.Current.IsTriangle) { vertexIndices[i] = new int[3]; vertexIndices[i][0] = e.Current.A + 1; vertexIndices[i][1] = e.Current.B + 1; vertexIndices[i][2] = e.Current.C + 1; } else { vertexIndices[i] = new int[4]; vertexIndices[i][0] = e.Current.A + 1; vertexIndices[i][1] = e.Current.B + 1; vertexIndices[i][2] = e.Current.C + 1; vertexIndices[i][3] = e.Current.D + 1; } } return(vertexIndices); }
public static RG.Mesh ToRhino(this Mesh mesh) { var result = new RG.Mesh(); foreach (var vertex in mesh.Vertices) { result.Vertices.Add(vertex.X, vertex.Y, vertex.Z); } foreach (var faceVertices in mesh.Faces.Select(face => face.AdjacentVertices())) { switch (faceVertices.Count) { case 3: result.Faces.AddFace(new RG.MeshFace( faceVertices[0].Index, faceVertices[1].Index, faceVertices[2].Index)); break; case 4: result.Faces.AddFace(new RG.MeshFace( faceVertices[0].Index, faceVertices[1].Index, faceVertices[2].Index, faceVertices[3].Index)); break; } } return(result); }
public IMesh Triangulated() { // test whether the mesh contains triangles only if (!ContainsQuads) { return(this); } var nmesh = new Rhino.Geometry.Mesh(); nmesh.CopyFrom(mesh); for (int face_ind = 0; face_ind < nmesh.Faces.Count; ++face_ind) { var face = nmesh.Faces[face_ind]; if (face.IsQuad) { var l_ac = nmesh.Vertices[face.A].DistanceTo(nmesh.Vertices[face.C]); var l_bd = nmesh.Vertices[face.B].DistanceTo(nmesh.Vertices[face.D]); Rhino.Geometry.MeshFace face1, face2; if (l_ac < l_bd) { face1 = new Rhino.Geometry.MeshFace(face.A, face.B, face.C); face2 = new Rhino.Geometry.MeshFace(face.A, face.C, face.D); } else { face1 = new Rhino.Geometry.MeshFace(face.A, face.B, face.D); face2 = new Rhino.Geometry.MeshFace(face.B, face.C, face.D); } nmesh.Faces.SetFace(face_ind, face1); nmesh.Faces.AddFace(face2); } } return(new RhinoMesh(nmesh)); }
public static GameObject TileShow(List <Rhino.Geometry.Point3d> grid, int gridSize, Color color, bool convertM = true, string name = "TileGrid") { var gridObj = new GameObject(name); Brep[] breps = new Brep[grid.Count]; // List<Brep> breps = new List<Brep>(); for (int i = 0; i < grid.Count; i++) { var pt = grid[i]; if (convertM) { var mPt = pt * (0.001); var plane = new Rhino.Geometry.Plane(mPt, Vector3d.ZAxis); var interval = new Interval((-gridSize / 2) * (0.001), (gridSize / 2) * (0.001)); var srf = new Rhino.Geometry.PlaneSurface(plane, interval, interval); var brep = srf.ToBrep(); // breps.Add(brep); breps[i] = brep; } else { var plane = new Rhino.Geometry.Plane(pt, Vector3d.ZAxis); var interval = new Interval(-gridSize / 2, gridSize / 2); var srf = new Rhino.Geometry.PlaneSurface(plane, interval, interval); var brep = srf.ToBrep(); //breps.Add(brep); breps[i] = brep; } } var joinedBrep = Rhino.Geometry.Brep.CreateBooleanUnion(breps, 0.1); var meshParam = MeshingParameters.FastRenderMesh; var meshs = Rhino.Geometry.Mesh.CreateFromBrep(joinedBrep[0], meshParam); var joinedMesh = new Rhino.Geometry.Mesh(); foreach (var m in meshs) { joinedMesh.Append(m); } joinedMesh.Weld(180); //attatch Mesh var UnityMesh = joinedMesh.ToHost(); var meshRender = gridObj.AddComponent <MeshRenderer>(); meshRender.material.color = color; meshRender.material.shader = Shader.Find("UI/Default"); var meshFilter = gridObj.AddComponent <MeshFilter>(); meshFilter.mesh = UnityMesh; return(gridObj); }
public IMesh Copy() { // Create copy of rhino mesh. var nmesh = new Rhino.Geometry.Mesh(); nmesh.CopyFrom(mesh); return(new RhinoMesh(nmesh)); }
public static Mesh ToMesh(this rg.Brep brep) { var rgMesh = MeshCompute.CreateFromBrep(brep); var union = new rg.Mesh(); union.Append(rgMesh); return(union.ToMesh()); }
/// <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) { Rhino.Geometry.Mesh inputMesh = null; DroidVolume vol = null; double x = new double(); double y = new double(); if (!DA.GetData(0, ref inputMesh)) { return; } if (!DA.GetData(1, ref vol)) { return; } if (!DA.GetData(2, ref x)) { return; } if (!DA.GetData(3, ref y)) { return; } Vector3d normal = new Vector3d(0, 0, 1); Plane worldXY = new Plane(Point3d.Origin, normal); Vector3d trans = new Vector3d(x, y, 0); Rhino.Geometry.Mesh _inputMesh = new Rhino.Geometry.Mesh(); if (vol.volumeOutline.Length == 2) { _inputMesh = inputMesh; BoundingBox bbx = _inputMesh.GetBoundingBox(worldXY); Point3d cnr = bbx.Corner(true, true, true); Point3d center = bbx.Center; center.Z = cnr.Z; Vector3d toMiddle = new Vector3d((Point3d.Origin - center + trans)); _inputMesh.Transform(Transform.Translation(toMiddle)); } if (vol.volumeOutline.Length == 6) { _inputMesh = inputMesh; BoundingBox bbx = _inputMesh.GetBoundingBox(worldXY); Point3d cnr = bbx.Corner(true, true, true); Point3d center = bbx.Center; center.Z = cnr.Z; Point3d middle = new Point3d((vol.size[0] / 2), (vol.size[1] / 2), 0); Vector3d toMiddle = new Vector3d((middle - center + trans)); _inputMesh.Transform(Transform.Translation(toMiddle)); } DroidMesh dMesh = new DroidMesh(_inputMesh); DA.SetData(0, dMesh); DA.SetData(1, _inputMesh); }
/// <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) { // INPUT // declaration Rhino.Geometry.Mesh meshA = null; Rhino.Geometry.Mesh meshB = null; int num = 0; double offset = 0.00; double blend = 1.00; bool runIt = false; bool showIt = false; bool writeObj = false; string path = null; DA.GetData(0, ref meshA); DA.GetData(1, ref meshB); DA.GetData(2, ref num); DA.GetData(3, ref blend); DA.GetData(4, ref offset); DA.GetData(5, ref runIt); DA.GetData(6, ref showIt); DA.GetData(7, ref writeObj); DA.GetData(8, ref path); // run if (runIt) { DMesh3 g3MeshA = ConvertDMesh(meshA); DMesh3 g3MeshB = ConvertDMesh(meshB); BoundedImplicitFunction3d implicitA = MeshMorphoLib.MeshClassFnc.MeshToImplicitF(g3MeshA, num, offset); BoundedImplicitFunction3d implicitB = MeshMorphoLib.MeshClassFnc.MeshToImplicitF(g3MeshB, num, offset); var implicitBlendDone = MeshMorphoLib.MeshClassFnc.ImplicitBlend(implicitA, implicitB, blend); DMesh3 newMesh = MeshMorphoLib.MeshClassFnc.GenerateMeshF(implicitBlendDone, num); if (showIt) { Rhino.Geometry.Mesh resultMesh = MeshMorphoLib.MeshIntegration.ConvertToRhinoMesh(newMesh); DA.SetData(0, resultMesh); } if (writeObj) { try { string fullFolder = System.IO.Path.Combine(path, "MorphoModel.obj"); MeshClassIO.WriteMesh(newMesh, fullFolder); DA.SetData(1, fullFolder); } catch { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Please provide a valid path."); } } } }
/// <summary> /// Replace a mesh object in the current Rhino document /// </summary> /// <param name="objID"></param> /// <param name="mesh"></param> /// <returns></returns> public static bool ReplaceMesh(Guid objID, RC.Mesh mesh) { bool result = false; Writing = true; result = RhinoDoc.ActiveDoc.Objects.Replace(objID, mesh); Writing = false; return(result); }
protected override void SolveInstance(IGH_DataAccess DA) { //container for errors/messages passed by controller, partition, etc. List<String> errorContainer = new List<String>(); GH_PreviewUtil preview = new GH_PreviewUtil(true); //declare placeholder variables and assign initial empty mesh Mesh baseMesh = new Rhino.Geometry.Mesh(); int errorMetricIdentifer = -1; int numPanels = -1; //Retrieve input data if (!DA.GetData(0, ref baseMesh)) { return; } if (!DA.GetData(1, ref errorMetricIdentifer)) { return; } if (!DA.GetData(2, ref numPanels)) { return; } if (baseMesh.DisjointMeshCount > 1) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Problem with mesh input - disjoint mesh"); } else { //compute and unify normal baseMesh.Normals.ComputeNormals(); baseMesh.UnifyNormals(); //create wingedmesh from rhinomesh WingedMesh myMesh = new WingedMesh(errorContainer, baseMesh); PlanarMesher controller = new PlanarMesher(errorContainer, myMesh, baseMesh, numPanels, errorMetricIdentifer, preview); controller.createFirstCluster(); for (int i = 0; i < 40; i++) { controller.iterateCluster(); //controller.currentPartition.drawProxies(preview); } controller.createConnectivityMesh(); //creating voronoi WingedMesh voronoiMesh = new WingedMesh(errorContainer, controller.currentPartition.proxyToMesh.convertWingedMeshToPolylines()); //set all the output data DA.SetDataList(0, voronoiMesh.convertWingedMeshToPolylines()); } foreach (var item in errorContainer) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, item); } }
protected override void SolveInstance(IGH_DataAccess DA) { //container for errors/messages List<String> errorContainer = new List<String>(); GH_PreviewUtil preview = new GH_PreviewUtil(true); //declare placeholder variables and assign initial empty mesh Mesh baseMesh = new Rhino.Geometry.Mesh(); int errorMetricIdentifer = -1; int numPanels = -1; Boolean run = false; //Retrieve input data if (!DA.GetData(0, ref baseMesh)) { return; } if (!DA.GetData(1, ref errorMetricIdentifer)) { return; } if (!DA.GetData(2, ref numPanels)) { return; } if (!DA.GetData(3, ref run)) { return; } if (run) { if (baseMesh.DisjointMeshCount > 1) { errorContainer.Add("Problem with mesh input - disjoint mesh"); } else { //compute and unify normal baseMesh.Normals.ComputeNormals(); baseMesh.UnifyNormals(); //create wingedmesh from rhinomesh WingedMesh myMesh = new WingedMesh(errorContainer, baseMesh); PlanarMesher controller = new PlanarMesher(errorContainer, myMesh, baseMesh, numPanels, errorMetricIdentifer, preview); controller.createFirstCluster(); for (int i = 0; i < 40; i++) { controller.iterateCluster(); controller.currentPartition.drawProxies(preview); } controller.createConnectivityMesh(); //creating voronoi WingedMesh voronoiMesh = new WingedMesh(errorContainer, controller.currentPartition.proxyToMesh.convertWingedMeshToPolylines()); controller.planariseConnectivityMesh(); //convert faces edges to polylines for viewing List<Polyline> boundaryEdges = controller.currentPartition.proxyToMesh.convertWingedMeshToPolylines(); List<Plane> proxyPlanes = new List<Plane>(); foreach (Proxy proxy in controller.currentPartition.proxies) { proxyPlanes.Add(proxy.rhinoPlane); } List<Mesh> proxyMeshes = new List<Mesh>(); foreach (Proxy proxy in controller.currentPartition.proxies) { proxyMeshes.Add(proxy.proxyAsMesh); } List<Vector3d> faceNormals = new List<Vector3d>(); List<Point3d> faceCentres = new List<Point3d>(); for (int i = 0; i < controller.currentPartition.proxyToMesh.faces.Count; i++) { faceNormals.Add(new Vector3d(controller.currentPartition.proxyToMesh.faces[i].faceNormal)); faceCentres.Add(new Point3d(controller.currentPartition.proxyToMesh.faces[i].faceCentre)); } //set all the output data DA.SetDataList(1, proxyPlanes); DA.SetDataList(2, boundaryEdges); DA.SetData(3, controller.currentPartition.proxyToMesh); DA.SetDataList(4, faceNormals); DA.SetDataList(5, faceCentres); DA.SetDataList(6, voronoiMesh.convertWingedMeshToPolylines()); } DA.SetDataList(0, errorContainer); } }
private Vector3d findAndUpdateNewAverageNormal()//send some of this out to smaller function? { Vector3d newNormal = new Vector3d(0.0,0.0,0.0); double totalArea = AreaMassProperties.Compute(proxyAsMesh).Area; for (int i=0; i<assignedFaces.Count; i++) { Vector3f normal = partition.controller.rhinoMesh.FaceNormals[assignedFaces[i]]; Rhino.Geometry.Mesh mesh = new Rhino.Geometry.Mesh(); for (int j = 0; j < partition.controller.wingMesh.faces[assignedFaces[i]].faceVerts.Count; j++) { Vector3f position = partition.controller.wingMesh.faces[assignedFaces[i]].faceVerts[j].position; mesh.Vertices.Add(position.X,position.Y,position.Z); } if (partition.controller.wingMesh.faces[assignedFaces[i]].faceVerts.Count == 3) { mesh.Faces.AddFace(0, 1, 2); } else if (partition.controller.wingMesh.faces[assignedFaces[i]].faceVerts.Count == 4) { mesh.Faces.AddFace(0, 1, 2, 3); } double area = AreaMassProperties.Compute(mesh).Area; mesh.Normals.ComputeNormals(); Vector3d areaWeightedNormal = Vector3d.Multiply(area/totalArea, mesh.FaceNormals[0]); newNormal = Vector3d.Add(newNormal, areaWeightedNormal); } return Vector3d.Divide(newNormal, assignedFaces.Count); }