Find Edges vs Faces of Extruded shape

Hi Guys,

I have a rather strange question. I’m new to babylon so I’m still trying to figure things out. In the picture I have colored some faces. In my world, we consider the narrow faces to be “edges”. So, if you imagine the picture below to be a sheet of plywood, and we’ve cut that shape out of the sheet of plywood. I need the ability to retrieve all the “edges” from this shape, and also the count. Is there a way to do the following.

#1. Call a function that would tell me that (in the picture) I have 7 total edges, and 2 faces.
#2. Call a function to retrieve a specific edge by index ID.
For example…
edges[4].length = 8"
edges[4].width = 0.75"

Hoping someone can point me in the right direction. Thank You

Hi gladiator-media,

I’m not sure this is a Babylon question as it seems to be about retrieving information from an image as opposed to rendering information to an image. As such, this is something of a computer vision question, and depending on the constraints it might be relatively easy or borderline impossible. :smiley:

Based on the image you presented, it looks like your starting input is an orthographic rendering of a piecewise structure where no two adjacent (in screen space) surfaces are colored the same. From this, you could use BFS-like logic to cluster your pixels into coherent groups, discard groups that didn’t contain the correct characteristics (size, shape, etc.) to be an “edge,” then consider the remaining groups to be edges and assess their characteristics (edge length, etc.) in pixel space by looking at the top edges of of the clusters. If you know the length of any one of these edges in real space, you could then deduce the real-world length of everything else because this is an orthographic render; there is insufficient information in this image to retrieve edge size a priori.

So an approach like that will work for this image and may work for your scenario more broadly — as long as a large number of constraints remain in effect.

  • If your model can have multiple layers, this approach won’t work.
  • If it’s possible to view your model from other angles or from the bottom, this approach may not work.
  • If it’s possible for the view to contain two visually adjacent edges that are colored the same, this approach won’t work.
  • If colored pixels can ever touch the edge of the image, this approach will not work.
  • If the camera can ever be perspective rather than orthographic, this approach will not work.

So there are a lot of ways for this to fail, some of which would require alternative approaches and some of which would take this into the realm of a research problem. I think, in order to properly understand whether this is feasible and how, it will be important to establish the constraints of the problem so that you can build an algorithm that is robust to the inputs you will have to handle. Hope this helps, and best of luck!

Allow me to clarify.

If I have the same shape as shown in the image. Only done as a CSG. How can I retrieve the colored faces specifically? The top and bottom faces are transparent in the image to give clarity to the faces in question, otherwise they would be hidden.

If you consider the edges to be in planes parallel to the xy plane, If you consider the top and bottom faces to be in the xz plane the edges will all have facets with normals that have y = 0.

For an easier way than CSG have you tried

I’m going to make you my best friend soon John. In my situation I am generating a 2D polyline, then extruding it to make the shape based on my material thickness. I am making cabinet parts in 3D. So, if you consider an end panel to a cabinet, there is the perimeter shape, then there is drilling and routing in the face of the panel that does not go all the way through, only goes half way through. Can that be done without CSG? I was also using CSG because I am attaching some functions so that when a horizontal part touches a vertical part, it will add drilling for dowel holes, or perhaps a groove. See the sample image below

As far as I know CSG is the way to go for what you are describing.

What I am not clear about for your original question is why, if you are creating the meshes you cannot get the info you need from your data.

what I am uncertain about is how to retrieve an edge programmatically. For example, using the image above. Lets say we have a piece of material attached to the top face [what we call “edgebanding” in my world]. I need the ability to check which material is assigned to that edge [which I will use meta for this]. So, I need to know like a face index so I could call it. Like face[1] == ‘myMaterial’

Here are some points to study, if you need further help with something specific about any of these please ask.

I have made a start at looking at a mesh that represents a shape that is cut out of plywood to see how you would determine the edges as defined by @gladiator-media. This turns out to be more of a problem than I though it would.

Why?
The task is to

which I take to mean without reference to the original construction data and to only use the vertex data contained by the mesh.

Making the assumption that the edges are perpendicular to th xz plane then the normal for each edge will have y = 0 and so will the triangular factes that make up the edges. This can be used to determine all the facets that belong to one of the edges.

All facets on a particular edge will have the same normal. The reverse is not true. As you can see for the image below there are three edges (black) where the facets making up the edges will all have the same normal.

image

Facets belonging to a particular edge will be adjacent to each other. So how you find adjacent facets that share the same normals? Since, because of the nature of the project, the edges and top and bottom all appear flat the mesh must be a flat shaded mesh. This means the facets do not share vertex indices which would be one way to find adjacency. What this means is that you have to check vertex positions. Two facets will be adjacent when two vertices in one facet share positions with two vertices in the other facet.

WARNING the following has only been tested with one mesh created using ExtrudePolygon, more testing with meshes (of the correct form) of unknow construction is necessary.

Click on an edge (vertical side) to swap its color.

In the above PG the function getEdgesData(mesh) will return an object with the following properties

edges - an array of an array of triangular facet indices, eg edge[i] = [facet_index0, facet_index1];
the number of edges is given by edges.length;

faceToEdge - maps a triangular facet index to the edge it belongs to

edgeToEdge - maps an edge to the two adjoing edges, eg edgeToEdge[edge] = [adjoing0, adjoining1];

Hopefully it will satisfy

With more work the following should be possible

3 Likes