Hi everyone,
I am trying to close an inner hole with this script but it returns a null. Does anyone know what I am doing wrong?
Thank you!
Hi everyone,
I am trying to close an inner hole with this script but it returns a null. Does anyone know what I am doing wrong?
Thank you!
Share the GH
The general - explicit - case of this (any valid Brep List - where Brep can contain one or many BrepFaces with Outer/Inner Loops blah, blah) has as follows:
public DataTree<Brep> bTree;
static double tol = RhinoDoc.ActiveDoc.ModelAbsoluteTolerance;
static Random random = new Random();
public void RemoveLoops(List<Brep> bList, int mode){
for(int i = 0; i < bList.Count;i++){
Brep brep = bList[i];
List<Brep> newBrepFaces = new List<Brep>();
for(int j = 0;j < brep.Faces.Count;j++){
BrepFace face = brep.Faces[j];
if(face.IsSurface){ // mode here has no meaning (for obvious reasons)
newBrepFaces.Add(face.DuplicateFace(true));
Print("At: {0},{1} Face is Surface", i, j);
continue;
}
Surface s = face.UnderlyingSurface();
Brep sb = s.ToBrep(); BrepFace sbf = sb.Faces[0];
List<Curve> splitCrvs = new List<Curve>();
if(mode == 1) {
splitCrvs.Add(face.OuterLoop.To3dCurve());
}
else{
foreach(BrepLoop loop in face.Loops){
if (loop.LoopType == BrepLoopType.Inner){
splitCrvs.Add(loop.To3dCurve());
}
}
}
Brep newBrep = sbf.Split(splitCrvs, tol);
newBrep = GetCorrectPiece(newBrep, face);
if(newBrep != null) newBrepFaces.Add(newBrep);
else Print("Split error at: {0},{1}", i, j);
}
if(newBrepFaces.Any()){
if(mode == 1) {
bTree.AddRange(newBrepFaces, new GH_Path(i));
}
else{
Brep[] newBreps = Brep.JoinBreps(newBrepFaces, tol);
if(newBreps != null && newBreps.Length > 0){
bTree.AddRange(newBreps, new GH_Path(i));
}
}
}
else Print("Major error at: {0}", i);
}
}
public Brep GetCorrectPiece(Brep b, BrepFace face){
u = face.Domain(0); v = face.Domain(1);
foreach(BrepFace f in b.Faces){
Point3d p = GetPoint(f);
double up, vp; face.ClosestPoint(p, out up, out vp);
PointFaceRelation pfr = face.IsPointOnFace(up, vp);
if(pfr != PointFaceRelation.Exterior){
return f.DuplicateFace(true);
}
}
return null;
}
public Interval u, v;
private Point3d GetPoint(BrepFace face){
while(true){
double randu = u.ParameterAt(random.NextDouble());
double randv = v.ParameterAt(random.NextDouble());
if (face.IsPointOnFace(randu, randv) == PointFaceRelation.Interior)return face.PointAt(randu, randv);
}
}
So … If you can translate C# to P … notify
BTW: If a given Brep has Faces that are not a Surface AND you want to remove the Outer Loop … then Joining has no meaning … so you get a collection of Breps.