# Is there a relation between the facetData and the indices of the mesh?

**URL:** <https://forum.babylonjs.com/t/is-there-a-relation-between-the-facetdata-and-the-indices-of-the-mesh/20101>\
**Category:** Questions\
**Created:** [April 18, 2021, 1:26pm UTC](https://forum.babylonjs.com/t/is-there-a-relation-between-the-facetdata-and-the-indices-of-the-mesh/20101 "2021-04-18T13:26:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tawfik](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tawfik/32/15213_2.png) [@Tawfik](https://forum.babylonjs.com/u/Tawfik)\
**Post date:** [April 18, 2021, 1:26pm UTC](https://forum.babylonjs.com/t/is-there-a-relation-between-the-facetdata-and-the-indices-of-the-mesh/20101/1 "2021-04-18T13:26:13Z")

</div>

I’m wondering if the facet number has a relation to the mesh indices.

is it like `facetNumber*3 = facetIndex` ?

---

<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:** [April 18, 2021, 5:02pm UTC](https://forum.babylonjs.com/t/is-there-a-relation-between-the-facetdata-and-the-indices-of-the-mesh/20101/2 "2021-04-18T17:02:34Z")

</div>

Adding @jerome who knows it all about facets 🙂

---

<div class="post-metadata">

**Author:** ![jerome](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jerome/32/22_2.png) [@jerome](https://forum.babylonjs.com/u/jerome)\
**Post date:** [April 18, 2021, 6:31pm UTC](https://forum.babylonjs.com/t/is-there-a-relation-between-the-facetdata-and-the-indices-of-the-mesh/20101/3 "2021-04-18T18:31:50Z")

</div>

I can’t remember what is facetNumber …

---

<div class="post-metadata">

**Author:** ![adam](https://avatars.discourse-cdn.com/v4/letter/a/4af34b/32.png) [@adam](https://forum.babylonjs.com/u/adam)\
**Post date:** [April 18, 2021, 7:00pm UTC](https://forum.babylonjs.com/t/is-there-a-relation-between-the-facetdata-and-the-indices-of-the-mesh/20101/4 "2021-04-18T19:00:35Z")

</div>

This might help:

> [@Facet Data Issue](https://forum.babylonjs.com/t/facet-data-issue/20093/4):
>
> I figured out how to get the vertices that make up a facet: let index = mesh.getClosestFacetAtCoordinates(x, y, z); let facetPosition = BABYLON.Vector3.Zero(); mesh.getFacetPositionToRef(index, facetPosition); let positions = mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind); let indices = mesh.getIndices(); let v1x = indices[index \* 3] \* 3; let v1y = v1x + 1; let v1z = v1x + 2; let v2x = indices[index \* 3 + 1] \* 3; let v2y = v2x + 1; let v2z = v2x + 2; let v3x = indices[index \* 3 + 2…

---

<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:** [April 19, 2021, 9:44am UTC](https://forum.babylonjs.com/t/is-there-a-relation-between-the-facetdata-and-the-indices-of-the-mesh/20101/5 "2021-04-19T09:44:25Z")

</div>

Thanks @adam 🙂

---

<div class="post-metadata">

**Author:** ![samevision](https://avatars.discourse-cdn.com/v4/letter/s/73ab20/32.png) [@samevision](https://forum.babylonjs.com/u/samevision)\
**Post date:** [April 19, 2021, 4:53pm UTC](https://forum.babylonjs.com/t/is-there-a-relation-between-the-facetdata-and-the-indices-of-the-mesh/20101/6 "2021-04-19T16:53:37Z")

</div>

This could also be interesting:

```
const getFaceVertices = mesh => {
	var pdata = mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind)
	var idata = mesh.getIndices()
	
    let vertices = []
	for (let i = 0; i < idata.length; i += 3) {
		let facet = [idata[i], idata[i+1], idata[i+2]]
		let pstring = []
		for (var j = 0; j < 3; j++) {
			pstring[j] = []
			for (var k = 0; k < 3; k++) {
				if (Math.abs(pdata[3*facet[j] + k]) < 0.0001) pdata[3*facet[j] + k] = 0
				pstring[j] = [...pstring[j], pdata[3*facet[j] + k]]
            }
            pstring[j] = new BABYLON.Vector3(pstring[j][0], pstring[j][1], pstring[j][2])
		}
        vertices = [...vertices, pstring]
	}

    return vertices
}
```
