Identifying Different surfaces in a 3D asset

I am trying to figure out how can i identify surfaces in a 3d object. for example if i have a cube in the scene then i want to be able to mark the faces of the cube with some numbers or tags. I am new to this framework so i was hoping to find some lead/links to solve this problem.

Hello and welcome!

For a cube you may use this way (only available when creating a mesh using the MeshBuilder method) - Map Materials to Individual Mesh Faces | Babylon.js Documentation
Here is another link from docs with very simple example - Getting Started - Chapter 2 - Face Materials | Babylon.js Documentation

1 Like

Thanks for the help @labris . This helped to get started. Although I would like to do something more general. Like I should be able to import a glb asset (not necessarily a cube) and then find the faces of that object. Right now, I am only interested with identifying flat surfaces and later maybe do something similar to curved surfaces as well.

Hope this helps.

For GLB assets see Facet Data | Babylon.js Documentation

I was assuming he would be importing meshes from another program and wanted some info on how to access the faces if his imported mesh …

Yes that’s exactly what I’m trying to do

Here is I what I managed to do following different discussions till now. I can now detect the faces of cube. But if I try the flat surface like a top of cylinder, it behaves differently, possibly because of the circle, so now the problem I’m facing is how to identify flat “curved” surface. I’m thinking I need to use the face normals somehow to achieve this.

yup basically the normals needs to be as close as possible so the face is as flat as possible. dot product close to one for normalized normals.

I did this for a dice roller that can, in theory, handle any dice model. Detecting flat mesh faces - #25 by ericwood73. PG link is It may not work exactly for your use case as I was able to make assumptions about the nature of the faces (the only faces that are not on a flat side would be on the edges or pips/numbers/etc…), but you may get some ideas from it.

1 Like