Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Mesh Count

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
john4TMYX
296 Views, 4 Replies

Mesh Count

Hi guys,

 

I have a face. Now I want to have the meshes from the face. 

 

Ptr<MeshManager> meshMgr = face_ptr->meshManager();
Ptr<TriangleMeshList> meshList = meshMgr->displayMeshes();
Ptr<TriangleMesh> pmesh = meshList->bestMesh();
std::vector<Ptr<Point3D>> mesh_xyz = pmesh->nodeCoordinates();
int triangle_count = pmesh->triangleCount();
std::vector<int> triangle_index = pmesh->nodeIndices();
int face_count = triangle_count / 3;
 
Then I can access the triangles:
for (int i = 0; i < face_count; i++)
{
int idx0 = triangle_index[i * 3];
int idx1 = triangle_index[i * 3 + 1];
int idx2 = triangle_index[i * 3 + 2];
 
Is this the right way?
 
I need all the mesh xyz to do my calculations. 
 
Thank you.
Regards
John
4 REPLIES 4
Message 2 of 5
MichaelT_123
in reply to: john4TMYX

Hi  Mr John4TMYX,

 

...Yes and No.

Meshes can come in different forms, ... triangular, quad or even polygonal.

 

polygonCountReturns the number of polygons (more than 4 sides) in the mesh.
polygonNodeIndicesReturns the index values that index into the NodeCoordinates and NormalVectors arrays to define the coordinates of each polygon and the corresponding normal.
quadCountReturns the number of quads in the mesh.
quadNodeIndicesReturns the index values that index into the NodeCoordinates and NormalVectors arrays to define the four coordinates of each quad and the corresponding normal.
triangleCountReturns the number of triangles in the mesh.
triangleNodeIndices

Returns the index values that index into the NodeCoordinates and NormalVectors arrays to define the three coordinates of each triangle and the corresponding normal.

... thus you have to address such diversity first ... unless you are sure that your mesh is of triangular type.

If the latter is the case ... the rest is easy.

 

myTriangleCoordsLst = []   

for tC in triangleCount:

     myTriangleCoord = [nodeCoordinates[triangleNodeIndices[3*tC+0]],

                                         nodeCoordinates[triangleNodeIndices[3*tC+1]],

                                         nodeCoordinates[triangleNodeIndices[3*tC+2]]]

    myTriangleCoordsLst.append(myTriangleCoord )

 

The code is similar or even the same as the one you presented ... as per my 5 sec glimpse.

 

Regards

MichaelT

 

MichaelT
Tags (2)
Message 3 of 5
john4TMYX
in reply to: john4TMYX

 

but I use the following way to get the mesh from a face:

 

Ptr<MeshManager> meshMgr = face_ptr->meshManager();
Ptr<TriangleMeshList> meshList = meshMgr->displayMeshes();

 

so I assume that the mesh should be triangle mesh, right?

I have printed all the mesh, it is not right at all. 

 

Here is the code snippet:

Ptr<TriangleMesh> pmesh                    = meshList->bestMesh();

std::vector<Ptr<Point3D>> mesh_xyz = pmesh->nodeCoordinates();
int triangle_count                                   = pmesh->triangleCount();
std::vector<int> triangle_index            = pmesh->nodeIndices();
int face_count = triangle_count / 3;
for (int i = 0; i < face_count; i++)
{
            int idx0 = triangle_index[i * 3];
            int idx1 = triangle_index[i * 3 + 1];
            int idx2 = triangle_index[i * 3 + 2];
 
           ON_3dPoint pnt0, pnt1, pnt2;
          ComUtils::get_Point(mesh_xyz[idx0], pnt0);
          ComUtils::get_Point(mesh_xyz[idx1], pnt1);
          ComUtils::get_Point(mesh_xyz[idx2], pnt2);
           ...
}
 
I can't think of other ways to do it based on the document I have read. but the result is not right!
Message 4 of 5
MichaelT_123
in reply to: john4TMYX

Hi Mr John4TMYX,

 

       int face_count = triangle_count / 3      ????

what about:

       int face_count = triangle_count 

 

... and by the way ... consider using F360 API to keep consistency of the code.

 

Regards

MichaelT

 

MichaelT
Message 5 of 5
john4TMYX
in reply to: john4TMYX

how do you access the xyz for each face?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report