Search code examples
3dthree.jsautodeskautodesk-forgeautodesk-viewer

Finding edges or holes in a shape of a node in the model


Is there a way to recognize if a node in the model has holes?

For example, we want to know if there's a window in a wall or some other opening, and how many such openings and their location.

I tried to iterate over the polygons of the node, taking their centroid and normal and trying to find a discontinuity, but it doesn't give a high confidence result.

Also tried to count straight lines other than the ones at the edges but sometimes a straight line appears in the middle of a wall.

So is there another way to do this? Maybe there's a built-in function in Three.js to count edges of a mesh?


Solution

  • There are probably very easy ways to count edges and so on, but I am afraid they will not help much unless you have extremely simple geometry, and no exceptional cases.

    For a more general solution, I think your best bet will be to generate a solid model from your polygons using their vertices, edges, normals, etc., and some 3D geometry library that is capable of working with solids to analyse their topology.

    Here is the first one that came up when searching for "js 3d boolean"

    https://duckduckgo.com/?q=js+3d+boolean

    FinalMesh Boolean 3D Library:

    http://finalmesh.com/boolean3d.htm

    This one says that it can process polygons with holes and optimise them, including removing holes, removing extra points and generating polygons from triangles.

    Given a polygon P, you could remove its holes to generate a hole-less polygon Q, then subtract P from Q to obtain all the openings in P.

    I am sure there are many others available out there for you to evaluate and compare as well.