Quantcast
Channel: Rhino Developer - McNeel Forum
Viewing all articles
Browse latest Browse all 8558

brep.Faces return untrimmed faces

$
0
0

Hi everyone!

I am trying to highlight the face of the selected polysurface according to the algorithm below, but when I add BrepFace as a new object to the ActiveDoc, an untrimmed version of the face appears. What is the reason for that? and how to fix it? Thanks!

    public static (Surface,string) extractSurface(ObjRef objRef)
    {
        RhinoDoc doc = RhinoDoc.ActiveDoc;
        // set point
        RhinoObject obj = objRef.Object();
        Point3d Pt= new Point3d(23000, 0.5, 13000); // example point
        // get thickness value of object
        string thickness = obj.Attributes.GetUserString("Thickness"); // not important
        if (thickness == null) thickness = CommonMethods.getThickness(objRef).ToString();

        string layerName = doc.Layers[obj.Attributes.LayerIndex].Name;
        string objName = obj.Attributes.Name;

        var brep = objRef.Brep();
        var faces = brep.Faces;
        Dictionary<BrepFace, double> faceDict = new Dictionary<BrepFace, double>();
        foreach(var face in faces)
            faceDict.Add(face, AreaMassProperties.Compute(face).Area);
        var faceList = faceDict.ToList();
        faceList.Sort((pair1, pair2) => pair1.Value.CompareTo(pair2.Value)); faceList.Reverse();
        var face1 = faceList[0].Key;
        var face2 = faceList[1].Key;

        var dist1 = AreaMassProperties.Compute(face1).Centroid.DistanceTo(Pt);
        var dist2 = AreaMassProperties.Compute(face2).Centroid.DistanceTo(Pt);

        BrepFace finalFace;
        if (layerName.Contains("ControlString"))
        {
            if (dist2 > dist1) finalFace = face1;
            else finalFace = face2;
        } else
        {
            if (dist1 > dist2) finalFace = face1;
            else finalFace = face2;
        }
        finalFace.SetUserString("Thickness", thickness);
        var guid = doc.Objects.Add(finalFace);
        var faceObj = doc.Objects.FindId(guid);
        faceObj.Attributes.ColorSource = ObjectColorSource.ColorFromObject;
        faceObj.Attributes.ObjectColor = Color.Red;
        faceObj.CommitChanges();
        return (finalFace, thickness);
    }

brepFaceUntrimmed.3dm (387.7 KB)

3 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 8558

Trending Articles