Undocumented trimesh properties


#1

I noticed that by accesing directly the mesh value of geometry I can achieve things faster and easier. For example:

m=myMesh.mesh
for v in m.verts do
(
    p=v.pos
    ...
)

In the for loop I have an easier acces to the verts as using getVert, and I don´t even have to care about node transformation. If tallking about transormation there some other very useful posibilities like this:

m=myMesh.mesh
move m [x, y, z]
rotate m rot
myMesh.mesh

This alows me to manipulate only mesh transformation without the one from the node.
Wondering if there is some other such really usefull things I can perfor on a trimesh? Unfortunatelly nothing from this stuff is mentioned in the documentation.

wondering if it´s posible to iterate the faces same way as verts?


#2

Of course, you can do it like this:

m = $.mesh
for f in 1 to m.numFaces do
(
   faceVerts = getFace m f
   print faceVerts
)

see this:

  1. http://help.autodesk.com/view/3DSMAX/2018/ENU/?guid=__files_GUID_58D1F8B6_0012_4727_AA29_B2C79EA46E16_htm#WS73099CC142F48755-2231E4B3128F27E2F8C122E

  2. http://help.autodesk.com/view/3DSMAX/2018/ENU/?guid=__files_GUID_BD473113_389F_4C96_BE07_217FF75796EF_htm

  3. http://help.autodesk.com/view/3DSMAX/2018/ENU/?guid=__files_GUID_2616CE55_CE46_404B_8BB9_2C7E4D379D8C_htm

  4. http://help.autodesk.com/view/3DSMAX/2018/ENU/?guid=__files_GUID_D05BCFB5_BD5A_4B17_B053_64841171A8C8_htm


#3

Sorry, what I was meaning is something like this

m = $.mesh
for f in m.faces do
(
...
)

so without using geter or seter fns. I know how to get faces with the getFace fn.


#4

Okay, but why do you need that? As far as I know there’s no performance differences between for v in m.verts do and for vi in 1 to m.numVerts do. Both functions work with triMesh, so you don’t have to bother the node transformation.


#5

Posibly I understood something wrong, but have heared somewhere that for v in m.verts do should be faster then for vi in 1 to m.numVerts do. Also a geter fn, as far I know, is a bit slower then direkt access, but my knowledge about that thing is very low, so can be complete wrong.


#6

Whenever you hear such statements it is a good practice to try it by yourself.

Sometimes, performance varies depending on the situation, including OS, Max version, the whole code and the scene in question.

For instance, I could say that BitArrays are much faster than Arrays, and while that may be true in most situations, it can’t be taken as a general statement as in many cases Bitarrays will be much slower than Arrays.

In your case, if you take the time to write a little test script, you’ll find that what you heard don’t hold true in these examples.

(
	delete objects
	gc()
	
	obj = converttomesh (geosphere radius:50 segs:256)

	st=timestamp(); sh=heapfree
	for j = 1 to obj.numverts collect getvert obj j
	format "obj.numverts\n"
	format "\ttime:% heap:%\n" (timestamp()-st) (sh-heapfree)
	
	st=timestamp(); sh=heapfree
	for j in obj.verts collect j.pos
	format "obj.verts\n"
	format "\ttime:% heap:%\n" (timestamp()-st) (sh-heapfree)
	
	tmesh = snapshotasmesh obj
	
	st=timestamp(); sh=heapfree
	for j = 1 to tmesh.numverts collect getvert tmesh j
	format "trimesh.numverts\n"
	format "\ttime:% heap:%\n" (timestamp()-st) (sh-heapfree)
	
	st=timestamp(); sh=heapfree
	for j in tmesh.verts collect j.pos
	format "trimesh.verts\n"
	format "\ttime:% heap:%\n" (timestamp()-st) (sh-heapfree)
)

obj.numverts
time:215 heap:25640504L
obj.verts
time:252 heap:64000680L
trimesh.numverts
time:129 heap:25600384L
trimesh.verts
time:148 heap:64009704L


#7

So I was wrong, thanks for explanation.