The .mesh command

So you are working with objects from dozens of artists, some using Editable Poly and some using Editable Mesh, and you need to perform data collection on them.

GetNumfaces will return the polycount of an object, but it returns a tri count for emesh objects and a n-gon count for epoly objects. The tri count is the one we are generally more interested in knowing.

There are 2 methods that people seem to use for getting the tri count:

  • Create a virtual copy of the object as an editable mesh. This one is the most common.
  • Access the underlying mesh using the .mesh command. I had been writing script for years before I discovered this.

If you create a box that is 2x2x2 you can see how this works. I called the box epolyobj and then cloned it to an editable mesh that I called emeshobj. Let’s run some commands on those items.


getnumfaces $emeshobj -- gives a tri count on the mesh object
48
getnumfaces $epolyobj -- gives an n-gon count on the poly object
24
getnumfaces $epolyobj.mesh -- gives a tri count on the poly object
48
virtualmesh = snapshotAsMesh $epolyobj -- clone the poly object in memory as a mesh object
TriMesh
getnumfaces virtualmesh -- gives a tri count on the virtual poly object (that we've made into a mesh)
48

This can only be used to read data from the mesh and do selections, it can’t be used to write data (like vertex colours) to the mesh.

Oh, and it seems that querying (epolyobj.mesh) is much slower than querying (copy epolyobj.mesh).

One Response to “The .mesh command”

  1. Swordslayer Says:

    Nice post, it is also worth mentioning that .mesh returns a new object each time you call it and when you’re done using it, good practice is to delete it. So the sample would then be virtualmesh = copy $epolyobj.mesh; getnumfaces virtualmesh; delete virtualmesh.

    You can directly manipulate this virtualmesh – for example something like virtualmesh .vertices[1].pos += 10 will work, the mesh itself will return changed position when you query it – but it is usually not all that much useful, only in scripted simpleObject and the like. Don’t ask me why setting selection on object’s .mesh works and setting vertex positions not, though, I have absolutely no idea :)

Thoughts on this?