PDA

View Full Version : Accessing trimesh faces/vertices directly?


Gibbz
01-14-2009, 02:19 AM
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!

Gravey
01-14-2009, 02:50 AM
I find the collect function to be fastest
m = snapshotAsMesh $myObject -- create a trimesh
vertArr = for i = 1 to numVerts m collect getVert m iOff the top of my head I think getVert is faster than meshop.getVert as well. Something to keep in mind...

Gibbz
01-14-2009, 06:44 AM
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?

Gravey
01-14-2009, 07:11 AM
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.

Gibbz
01-14-2009, 07:21 AM
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?

reForm
01-14-2009, 08:42 AM
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?

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
01-14-2009, 09:06 AM
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.

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...

Gibbz
01-14-2009, 10:06 AM
ah so you can do the mesh.face/verts to setup the faces and vert? But you cannot read them from there?

CGTalk Moderation
01-14-2009, 10:06 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.