# Roof facing facet.

## Recommended Posts

Hi all,

I have a simple requirement but i have no clue how to  do it.

I have a mesh (may look like box).

1. I need to identify its top/roof facing facet(s).

2. Devide this plane into cells (like each cell is a 5*5 in size) and get the coordinates of these cells.

##### Share on other sites

1. for each facet look at the direction of normal in world space (compute dot of face normal and vector up or down for instance).

2. I do not understand the question or goal (seems similar to what facet partitioning is doing)

##### Share on other sites

Thank you @sebavan and @jerome.

I have gone thru this but I could not understand as I am new to these concepts.

What I understood is each facet is a triangle. Now, how to get the 3 points (world coordinates) of a facet?

##### Share on other sites

You will need to find out more about the data structure of a mesh from

##### Share on other sites

Thank you @JohnK

I now understood how the information is stored internally. The below function get the details.

var getFacetTrianglesOfMesh = function (mesh) {
var indices = mesh.getIndices();
var positions = mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind);

var nbFaces = indices.length / 3;

var triangles = [];
for (var i = 0; i < nbFaces; i++) {
var triangle = [];
for (var j = 0; j < 3; j++) {
var ind = (i * 3) + j;
var point = new BABYLON.Vector3(positions[ind], positions[ind + 1], positions[ind + 2]);
triangle.push(point);
}

triangles.push(triangle);
}

return triangle;
};

Now I need to do face sampling. I need to divide each facet into a grid of equal sized cells.

Any clue how to do this? Gone thru this article but could not understand. https://chrischoy.github.io/research/barycentric-coordinate-for-mesh-sampling/

##### Share on other sites

You can look at the partitioning code from @jerome in the facet tools.

Basically go over each face

compute if center is in a box or if area in > area out (depending on the precision and time you have)

put in a list of triangle for this box.

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.