本文整理汇总了C#中Mesh.SplitDisjointPieces方法的典型用法代码示例。如果您正苦于以下问题:C# Mesh.SplitDisjointPieces方法的具体用法?C# Mesh.SplitDisjointPieces怎么用?C# Mesh.SplitDisjointPieces使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mesh
的用法示例。
在下文中一共展示了Mesh.SplitDisjointPieces方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetRhinoMesh
public Mesh GetRhinoMesh()
{
var mesh = new Mesh();
mesh.Vertices.AddVertices(Vertices);
foreach (var face in Faces)
{
mesh.Faces.AddFace(new MeshFace(face[0], face[1], face[2]));
}
mesh.Normals.ComputeNormals();
mesh.FaceNormals.ComputeFaceNormals();
mesh.UnifyNormals();
mesh.Normals.ComputeNormals();
var meshes = mesh.SplitDisjointPieces();
mesh = new Mesh();
for (int i = 0; i < meshes.Count(); i++)
{
if (meshes[i].SolidOrientation() == -1)
meshes[i].Flip(true, true, true);
mesh.Append(meshes[i]);
}
Rhino.RhinoApp.WriteLine(mesh.SolidOrientation().ToString());
return mesh;
}
示例2: SolveInstance
//.........这里部分代码省略.........
}
//delete all faces whose vertices are associated with the same plane
List<int> DeleteFaces = new List<int>();
for (int FaceIdx = 0; FaceIdx < HullMesh.Faces.Count; FaceIdx++)
{
if ((FaceVertices[HullMesh.Faces[FaceIdx].A] !=-1) && (FaceVertices[HullMesh.Faces[FaceIdx].A] == FaceVertices[HullMesh.Faces[FaceIdx].B]) &&
(FaceVertices[HullMesh.Faces[FaceIdx].B] == FaceVertices[HullMesh.Faces[FaceIdx].C])) DeleteFaces.Add(FaceIdx);
}
HullMesh.Faces.DeleteFaces(DeleteFaces);
ExoTools.NormaliseMesh(ref HullMesh);
Hulls.Append(HullMesh);
}
else if (!O)
{
Mesh EndMesh = new Mesh();
double KnuckleOffset = ND * 0.5;
EndMesh.Vertices.Add(Nodes[NodeIdx] + (Knuckles[0] * KnuckleOffset));
for (int HullVtx = 0; HullVtx < S; HullVtx++)
{
EndMesh.Vertices.Add(StrutHullVtc[StrutIndices[0], HullVtx]);
int StartVtx = HullVtx + 1;
int EndVtx = HullVtx + 2;
if (HullVtx == S - 1) EndVtx = 1;
EndMesh.Faces.AddFace(0, StartVtx, EndVtx);
}
Hulls.Append(EndMesh);
}
}
//add stocking meshes between struts
Rhino.Collections.Point3dList MatchPts = new Rhino.Collections.Point3dList(Hulls.Vertices.ToPoint3dArray());
Mesh StrutMeshes = new Mesh();
//if a strut is overwhelmed by its nodes then output a sphere centered on the failing strut
Mesh FailStruts = new Mesh();
for (int I1 = 0; I1 <= Struts.Count; I1++)
{
if (I1 % 2 !=0)
{
if (StrutPlanes[I1-1].Origin.DistanceTo(Struts[I1-1].PointAtStart) + StrutPlanes[I1].Origin.DistanceTo(Struts[I1].PointAtStart) > Struts[I1-1].GetLength()*2)
{
Plane FailPlane = new Plane(Struts[I1 - 1].PointAtStart, Struts[I1 - 1].TangentAtStart);
Cylinder FailCylinder = new Cylinder(new Circle(FailPlane, (StrutRadii[I1] + StrutRadii[I1 - 1]) / 2), Struts[I1 - 1].GetLength()*2);
FailStruts.Append(Mesh.CreateFromCylinder(FailCylinder,5,10));
}
Mesh StrutMesh = new Mesh();
double StrutLength = StrutPlanes[I1 - 1].Origin.DistanceTo(StrutPlanes[I1].Origin);
//calculate the number of segments between nodes
int Segments =(int)(Math.Round((StrutLength * 0.5) / D, 0) * 2) + 2;
double PlnZ = StrutLength / Segments;
bool Match = true;
if (O && StrutSolo[I1 - 1]) Match = false;
//build up vertices
ExoTools.VertexAdd(ref StrutMesh, StrutPlanes[I1 - 1], (double)S, StrutRadii[I1 - 1], Match, MatchPts, Hulls);
double StrutIncrement = (StrutRadii[I1] - StrutRadii[I1 - 1]) / Segments;
for (int PlnIdx = 1; PlnIdx <= Segments; PlnIdx++)
{
Plane PlnSet = new Plane(StrutPlanes[I1-1]);
PlnSet.Rotate((PlnIdx % 2) * -(Math.PI / (double)S), PlnSet.ZAxis);
PlnSet.Origin = PlnSet.PointAt(0, 0, PlnIdx * PlnZ);
bool Affix = false;
if (PlnIdx == Segments && (!StrutSolo[I1] || (StrutSolo[I1] && !O))) Affix = true;
ExoTools.VertexAdd(ref StrutMesh, PlnSet, (double)S, StrutRadii[I1 - 1] + (StrutIncrement * PlnIdx), Affix, MatchPts, Hulls);
}
//build up faces
ExoTools.StockingStitch(ref StrutMesh, Segments, S);
ExoTools.NormaliseMesh(ref StrutMesh);
Hulls.Append(StrutMesh);
}
}
if (FailStruts.Vertices.Count > 0)
{
DA.SetData(0, FailStruts);
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "One or more struts is engulfed by its nodes");
return;
}
Hulls.Faces.CullDegenerateFaces();
Hulls.Vertices.CullUnused();
Mesh[] OutMeshes = Hulls.SplitDisjointPieces();
for (int SplitMesh = 0; SplitMesh < OutMeshes.Length; SplitMesh++) { ExoTools.NormaliseMesh(ref OutMeshes[SplitMesh]); }
//ExoTools.NormaliseMesh(ref Hulls);
DA.SetDataList(0, OutMeshes);
}
示例3: Smooth
public Mesh[] Smooth(Mesh mesh, int smooth)
{
////////////////////////////
Mesh[] msh_smooth = mesh.SplitDisjointPieces();
for (int k = 0; k < msh_smooth.Length; k++)
{
msh_smooth[k].Vertices.CombineIdentical(true, true);
msh_smooth[k].FaceNormals.ComputeFaceNormals();
msh_smooth[k].Normals.ComputeNormals();
msh_smooth[k].UnifyNormals();
for (int j = 0; j < smooth; j++)
{
#region LaplaceFunction
Point3f[] new_v = msh_smooth[k].Vertices.ToArray<Point3f>();
for (int i = 0; i < msh_smooth[k].TopologyVertices.Count; i++)
{
int[] mv = msh_smooth[k].TopologyVertices.MeshVertexIndices(i);
int[] ctv = msh_smooth[k].TopologyVertices.ConnectedTopologyVertices(i);
Single new_x = 0;
Single new_y = 0;
Single new_z = 0;
foreach (int ctv_i in ctv)
{
int[] vtc = msh_smooth[k].TopologyVertices.MeshVertexIndices(ctv_i);
new_x += msh_smooth[k].Vertices[vtc[0]].X / (Single)ctv.Length;
new_y += msh_smooth[k].Vertices[vtc[0]].Y / (Single)ctv.Length;
new_z += msh_smooth[k].Vertices[vtc[0]].Z / (Single)ctv.Length;
}
new_v[mv[0]] = new Point3f(new_x, new_y, new_z);
}
for (int i = 0; i < msh_smooth[k].Vertices.Count; i++)
{
msh_smooth[k].Vertices[i] = new_v[i];
}
#endregion
msh_smooth[k].FaceNormals.ComputeFaceNormals();
msh_smooth[k].Normals.ComputeNormals();
for (int i = 0; i < new_v.Length; i++)
{
Point3d pointd3 = new_v[i];
Point3d pointd4 = pointd3 + (Vector3d)msh_smooth[k].Normals[i] * (res / 10);
double v1 = this.calculate_field(pointd3);
double v2 = this.calculate_field(pointd4);
Point3d pointd2 = new Point3d();
if (v2 != v1)
{
pointd2 = this.interp_vertex(pointd3, pointd4, v1, v2);
}
else
{
pointd2 = pointd3;
}
if (pointd3.DistanceTo(pointd2) > this.res)
{
new_v[i] = new Point3f((float)pointd3.X, (float)pointd3.Y, (float)pointd3.Z);
}
else
{
new_v[i] = new Point3f((float)pointd2.X, (float)pointd2.Y, (float)pointd2.Z);
}
}
for (int i = 0; i < msh_smooth[k].Vertices.Count; i++)
{
msh_smooth[k].Vertices[i] = new_v[i];
}
}
}
//*/
return msh_smooth;
}