# Identifying Different surfaces in a 3D asset

**URL:** <https://forum.babylonjs.com/t/identifying-different-surfaces-in-a-3d-asset/41357>\
**Category:** Questions\
**Tags:** mesh\
**Created:** [June 4, 2023, 6:02am UTC](https://forum.babylonjs.com/t/identifying-different-surfaces-in-a-3d-asset/41357 "2023-06-04T06:02:38Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Akshat\_Agrawal](https://avatars.discourse-cdn.com/v4/letter/a/4af34b/32.png) [@Akshat\_Agrawal](https://forum.babylonjs.com/u/Akshat_Agrawal)\
**Post date:** [June 4, 2023, 6:02am UTC](https://forum.babylonjs.com/t/identifying-different-surfaces-in-a-3d-asset/41357/1 "2023-06-04T06:02:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![labris](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/labris/32/12576_2.png) [@labris](https://forum.babylonjs.com/u/labris)\
**Post date:** [June 4, 2023, 10:39am UTC](https://forum.babylonjs.com/t/identifying-different-surfaces-in-a-3d-asset/41357/2 "2023-06-04T10:39:57Z")

</div>

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](https://doc.babylonjs.com/features/featuresDeepDive/materials/using/texturePerBoxFace)  
Here is another link from docs with very simple example - [Getting Started - Chapter 2 - Face Materials | Babylon.js Documentation](https://doc.babylonjs.com/features/introductionToFeatures/chap2/face_material)

---

<div class="post-metadata">

**Author:** ![Akshat\_Agrawal](https://avatars.discourse-cdn.com/v4/letter/a/4af34b/32.png) [@Akshat\_Agrawal](https://forum.babylonjs.com/u/Akshat_Agrawal)\
**Post date:** [June 4, 2023, 11:08am UTC](https://forum.babylonjs.com/t/identifying-different-surfaces-in-a-3d-asset/41357/3 "2023-06-04T11:08:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![WillemCramer](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/willemcramer/32/11696_2.png) [@WillemCramer](https://forum.babylonjs.com/u/WillemCramer)\
**Post date:** [June 4, 2023, 12:52pm UTC](https://forum.babylonjs.com/t/identifying-different-surfaces-in-a-3d-asset/41357/4 "2023-06-04T12:52:40Z")

</div>

> **[Babylon.js Playground](https://playground.babylonjs.com/#0XYMA9%23148)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

Hope this helps.

---

<div class="post-metadata">

**Author:** ![labris](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/labris/32/12576_2.png) [@labris](https://forum.babylonjs.com/u/labris)\
**Post date:** [June 4, 2023, 12:54pm UTC](https://forum.babylonjs.com/t/identifying-different-surfaces-in-a-3d-asset/41357/5 "2023-06-04T12:54:40Z")

</div>

For GLB assets see [Facet Data | Babylon.js Documentation](https://doc.babylonjs.com/features/featuresDeepDive/mesh/facetData)

---

<div class="post-metadata">

**Author:** ![WillemCramer](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/willemcramer/32/11696_2.png) [@WillemCramer](https://forum.babylonjs.com/u/WillemCramer)\
**Post date:** [June 4, 2023, 3:10pm UTC](https://forum.babylonjs.com/t/identifying-different-surfaces-in-a-3d-asset/41357/6 "2023-06-04T15:10:59Z")

</div>

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 …

---

<div class="post-metadata">

**Author:** ![Akshat\_Agrawal](https://avatars.discourse-cdn.com/v4/letter/a/4af34b/32.png) [@Akshat\_Agrawal](https://forum.babylonjs.com/u/Akshat_Agrawal)\
**Post date:** [June 4, 2023, 3:19pm UTC](https://forum.babylonjs.com/t/identifying-different-surfaces-in-a-3d-asset/41357/7 "2023-06-04T15:19:23Z")

</div>

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

> **[Babylon.js Playground](https://playground.babylonjs.com/#5JBH1S%233)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

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.

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [June 5, 2023, 7:42pm UTC](https://forum.babylonjs.com/t/identifying-different-surfaces-in-a-3d-asset/41357/8 "2023-06-05T19:42:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ericwood73](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ericwood73/32/22967_2.png) [@ericwood73](https://forum.babylonjs.com/u/ericwood73)\
**Post date:** [June 5, 2023, 8:00pm UTC](https://forum.babylonjs.com/t/identifying-different-surfaces-in-a-3d-asset/41357/9 "2023-06-05T20:00:58Z")

</div>

I did this for a dice roller that can, in theory, handle any dice model. [Detecting flat mesh faces - #25 by ericwood73](https://forum.babylonjs.com/t/detecting-flat-mesh-faces/35477/25). PG link is [https://playground.babylonjs.com/#P5F4RL#28](https://playground.babylonjs.com/#P5F4RL#28). 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.
