[Closed] Fast way to get tri polygon count on editable_polys?
Is there a fast way to get the trimesh polygon count on objects?
This is a problem I have juggled with quite a bit and so far it’s not easy to do it in an efficient way. Basically I want a function that I can call for all kinds of objects in max and it will return the tri mesh (as we would have in games).
Some possible solutions
-get the editable_polygon face count and multiply with 2.
-write object.mesh.numFaces. This however I think will cause a memory leak in max8, I also think it creats a mesh in memory which is slow so not cool if you do it on 1000 objects. Anyone know more about this feature?
- get the vertices and do some kind of approximation.
Ideas?
/Andreas
I think the only way would be to access it as object.mesh.numfaces, but you’re right that it creates the trimesh in memory, you can visually see the jump in the task manager when the command is executed (editable poly sphere with 20000 faces took 776k memory to convert to trimesh). gc() drops the memory again obviously, so as long as you manually garbage collect I’d think you’d be fine, unless speed is of utmost importance. The problem with getting editable_poly face count and multiplying by two is that it would only ever be an approximation, unless it was certified that all faces were quads beforehand.
edit come to think of it… maybe there is a way to get the vert, edge, and face count of the poly object, then from those numbers deduce how many tris there are.
The speed is a problem, but the memory needs is perhaps even more problematic. I checked on an 200k object and it took 100ms to get the polygon count.
Running gc()
clearls the undo which isn’t very cool either.
/Andreas
fn getFaceCount theObj =
(
local theMesh = snapshotasmesh theObj
local theResult = theMesh.numfaces
delete theMesh
theResult
)
st = timestamp()
for i = 1 to 1000 do getFaceCount $Teapot01
(timestamp()-st)
I run this on a teapot with 64 segs (262144 faces).
It takes 35 seconds and memory stays low. This means 35 milliseconds per call and no leaking
Cool, thanks. That is faster than I thought. snapshop is always a good friend when you need something really fast.
/Andreas
This one was slightly faster in my test:
(getTrimeshFaceCount $)[1]
It is the one used in the polygoncounter macroscript in earlier versions of 3ds max(9 doesn’t have it).
CML