Detecting flat mesh faces

I know understand that the D20 dice does not just have 20 facets and that by edge facet you do not mean a facet of a face that lies next to a different face.

You are not really ever talking about arbritary meshes but ones that have flat faces and rounded edges between them.

In which case as @SvenFrankson suggests it is about design desicions for creation.

For example you could have the faces of a d20 made of more than one facet.

EDIT
OK you are talking about imported meshes not ones you create so I understand the difficulty.

1 Like

This PG shows normals for all faces - https://playground.babylonjs.com/#P5F4RL#19 works for D20 however part of the technique was arrived at by trial and error. It will only work when the dice faces are single facets larger than any other, so you would need your other method for D6 for example.

Random Face for D20 PG https://playground.babylonjs.com/#P5F4RL#20

Each face is a facet where the edges are about equal in length.

All facets are checked and only those with this property will eventually be stored as faces.

The issue is that the comparison value on line 54 was arrived at by trial and error rather than calculation.

There maybe something in there that you could find useful.

1 Like

Thanks. I think the final solution will involve multiple filters, depending on the scenario. If their are enough facets per face so that their are facets that are not adjacent to the edge (complex d6) just checking the facet normal against the vertex normals will work. If the faces are comprised of very few facets, then I think filtering out facets by AR will work. So I think I first filter out facets by AR. If there more than about 36 facets (d12 min facets with no edges), then check facets and vertex normals. I get that there is some aspect of trial and error since these are imported meshes, but this could probably get me close enough to handle most cases.

1 Like

Final solution - https://playground.babylonjs.com/#P5F4RL#28

I implemented a 3 step algorithm. First if the number of facets is less than or equal to 36 (which is the min facets for a 12 sided die (simple d6 example), then all of the facets are side facets. If not, filter the facets by sorting by surface area and culling any facets whose area is less than 10% of the smallest area. After that, if the number of facets remaining is less than or equal to 36 (d20 example), we’ve found them all, else filter remaining facets by those whose facet normal is aligned with the vertex normals (complex d6).

It works for my 3 example meshes, though There could still be issues depending on how the die is modeled. Thanks for the help and advice.

2 Likes