Finding which face the triangles belong to

Finding which face the triangles belong to

Anonymous
Not applicable
597 Views
2 Replies
Message 1 of 3

Finding which face the triangles belong to

Anonymous
Not applicable

Hi,

 

Is there a way to find out which triangles in a generated mesh correspond to which BRep faces?

 

I'd like to have a set of faces and a corresponding set of the generated triangles for each face. I need to do this for all of the triangles, not just a single one. Of course, I can generate the mesh for each face separately, but I need the resulting mesh to be watertight/manifold and I don't believe there is any guarantee (or I can't find one Smiley Wink ) that in the seams between the meshes the same vertices will be used.

 

Can anyone help me with this?

 

Thanks,

Jeremy

0 Likes
Accepted solutions (1)
598 Views
2 Replies
Replies (2)
Message 2 of 3

liujac
Alumni
Alumni

How about to check if the three points of each triangle are on the face? If the three points of one triangle are all on the face, the triangle is on the face. I wrote a function “isTriangleOnFace”, hope it’s helpful.

 

import adsk.core, adsk.fusion, adsk.cam, traceback

# point0, point1, point2 - Point3D object, point of triangle
# face - BRepFace object
def isTriangleOnFace(point0, point1, point2, face):
    # Get surface evaluator of the face
    eva = face.evaluator
    
    # Get the parameter positions that correspond to a set of points on the surface
    # If the points do not lie on the surface, the parameter of the nearest point on the surface will generally be returned
    (retVal, params) = eva.getParametersAtPoints([point0, point1, point2])
    if len(params) != 3:
        return False
        
    # Check if the parameters are out of the extent of the face
    if not eva.isParameterOnFace(params[0]) or not eva.isParameterOnFace(params[1]) or not eva.isParameterOnFace(params[2]):
        return False
        
    # The returned points should be on the face
    retPoints = None
    (retVal, retPoints) = eva.getPointsAtParameters(params)
    
    if len(retPoints) != 3:
        return False

    return point0.isEqualTo(retPoints[0]) and point1.isEqualTo(retPoints[1]) and point2.isEqualTo(retPoints[2])

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        
        face = ui.selectEntity("Select a BRepFace", "Faces").entity;
        
        triangle0 = [adsk.core.Point3D.create(0, 0, 0), adsk.core.Point3D.create(1, 0, 0), adsk.core.Point3D.create(0, 1, 0)]
        ret = isTriangleOnFace(triangle0[0], triangle0[1], triangle0[2], face)
       
        ui.messageBox('isTriangleOnFace: ' + str(ret))
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

Jack

0 Likes
Message 3 of 3

ekinsb
Alumni
Alumni
Accepted solution

Because of the way Fusion tesselates the model, you should get a watertight mesh if you go face-by-face, as long as you use the same tolerance to generate the mesh.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog