Notifications
Clear all

[Closed] Accessing trimesh faces/vertices directly?

Looking to optimise one of my current scripts.
Is there a way to get an array of vertices or faces directly from a trimesh?

Ive tried $.mesh.vertices and it displays in the console #verts(#all : TriMesh).

I would love to find a way to just grab all faces and put them into an array so i can work on the mesh then when im done just output it back out!

7 Replies

I find the collect function to be fastest

m = snapshotAsMesh $myObject -- create a trimesh
 vertArr = for i = 1 to numVerts m collect getVert m i

Off the top of my head I think getVert is faster than meshop.getVert as well. Something to keep in mind…

ok that does save 0.1ms instead of doing it via a loop, which is good news. So using collect to collect the same value types before doing a loop will always save time?

i dont know if it will always save time by storing it into an array first but i usually do anyway for arrays like verts etc because i often want to access them more than once.

something else i forgot to mention before was that you should use snapshotAsMesh instead of $.mesh because every time you call $.mesh it creates a new trimesh in memory which slows things down quite a bit.

I assume its faster to say get the trimesh ($.mesh) and then use mesh operations on this mesh while its in memory. Then when I am done assign the mesh back into my original.
This is instead of using setvert for each vertex of the mesh.

Is this right?

2 Replies
(@reform)
Joined: 11 months ago

Posts: 0

You don’t need to do setvert on each vertex individually. You can simply setvert an array of vertices with an array of positions. (I think!) Someone can correct me if I’m wrong.

(@xcise)
Joined: 10 months ago

Posts: 0

yes you can define two arrays for vertices and positions. however this came with 3dsmax 2008. so earlier versions will not be able to process the script…

ah so you can do the mesh.face/verts to setup the faces and vert? But you cannot read them from there?