How sim.getShapeMesh works?

Typically: "How do I... ", "How can I... " questions
Post Reply
allen0413
Posts: 7
Joined: 05 May 2020, 10:43

How sim.getShapeMesh works?

Post by allen0413 »

Hello,

My goal is to retrieve the orientation and position of normal to every surface on a shape, and I'm pretty sure the API needed is sim.getShapeMesh, but not sure how it works.

For example, for a pure shape cuboid, it gives me normals like below:
{0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0}
but why are there so many values while the cuboid only has 6 surfaces? Thought it should be only 6 normals?

Do they represent orientations of the normals? Then how may I get the position of every normal (Like at the center of mass in every surface)?

Excuse for my poor presentation, thank u.

fferri
Posts: 1222
Joined: 09 Sep 2013, 19:28

Re: How sim.getShapeMesh works?

Post by fferri »

allen0413 wrote: 20 Feb 2021, 10:14 For example, for a pure shape cuboid, it gives me normals like below:
{0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0}
Those are 36 normals = ( 3 normals / triangle ) * ( 2 triangles / face ) * ( 6 faces )

It is one normal for each triangle's vertex, so normals will be duplicated for vertices shared by multiple triangles, e.g. in the above case a cuboid has only 8 vertices, but because of the triangle count, you get 36.

Post Reply