Notifications
Clear all

[Closed] getVert mesh world position?

I’m trying to get the world position of a mesh vertex, if I do:

getVert $.mesh 1

it returns the local position of the vertex in relation to the object pos/rot even if i try “in coordsys world”

If I do polyop.getVert it returns the world position of the vertex but I want to do it for Trimesh.

Is there a fix for that or would I have to do:

(getvert $.mesh 1)*$.transform

Thanks

9 Replies

For Editable Poly

polyop.getvert $ <vertex index>

For Editable Mesh

getvert $ <vertex index>

Generic Function for Poly and Mesh (also works with modifiers)

getpointpos $ <vertex index>

All functions return the position in World Coordinates.

1 Reply
(@patan77)
Joined: 11 months ago

Posts: 0


OLD: Yeah, works now, something was just messed up with the mesh/ my 3ds max when i was trying it

EDIT: Or actually It still doesn’t work, if I do convert to mesh then I get world pos with getVert but If I just do $.mesh i only get local pos , so can i get world pos with $.mesh?
.

Or actually It still doesn’t work, if I do convert to mesh then I get world pos with getVert but If I just do $.mesh i only get local pos , so can i get world pos with $.mesh?

1 Reply
(@polytools3d)
Joined: 11 months ago

Posts: 0

The node and the node.mesh are different things.

getvert <node> <idx>
getvert <node.mesh> <idx>

Are difrerent if the node has been transformed.
Is there any reazon why you want to use the .Mesh of the node?
In that case the best would be to snapshot the node, which will create a memory version of the transformed node, with modifiers, etc. Basically it creates a mesh representation of how you see the node.

-tmpMesh = snapshotasmesh $

In your example you are retrieving the vertex position of the node’s mesh, which is different than the vertex position of the node if the node has been transformed.

The mesh of a node is an untransformed geometry, so if you have move, scaled or rotated the node, the positions of the vertices will be different.

To check if the node has been transformed you can verify if its transformation matrix is an identity matrix. You can also create a mesh from the node’s mesh to see if they are the same.

4 Replies
(@patan77)
Joined: 11 months ago

Posts: 0

Hmm, well I’m gonna perform the operation millions of times so I want it to be as fast as possible, I was thinking that max might be storing the vertex pos in world space and it would be fastest to just fetch that, this works to convert local to world pos:

(getvert $.mesh 1)*$.transform 

but was hoping not having to do any extra calculations.

(@polytools3d)
Joined: 11 months ago

Posts: 0

If you are working with an Editable Mesh (no modifiers), the faster is to just use:

Getvert $ <idx>

If the node has modifiers or is a poly, then the faster would be to snapshot it and get the vertices from memory.

Here are some examples:

(
	-- MESH EXAMPLE
	gc()
	delete objects
	obj = converttomesh (box wirecolor:red)
	tm = matrixfromnormal (random -[1,1,1] [1,1,1])
	tm.pos = random -[50,50,50] [50,50,50]
	
	-- This is a Transformed node
	obj.transform = tm
	
	node_v1 = getvert obj 1			-- World position (as you see it)
	mesh_v1 = getvert obj.mesh 1	-- Local position
	
	format "nodeVert:% meshVert:%
" node_v1 mesh_v1
	
	-- Let's create a visual mesh of the node's mesh to see why they are different
	mesh mesh:obj.mesh wirecolor:green
	ok
)
(
	-- POLY EXAMPLE
	gc()
	delete objects
	obj = converttopoly (box wirecolor:red)
	tm = matrixfromnormal (random -[1,1,1] [1,1,1])
	tm.pos = random -[50,50,50] [50,50,50]
	
	-- This is a Transformed node
	obj.transform = tm
	
	node_v1 = polyop.getvert obj 1	-- World position (as you see it)
	mesh_v1 = getvert obj.mesh 1	-- Local position
	
	format "nodeVert:% meshVert:%
" node_v1 mesh_v1
	
	-- Let's create a visual mesh of the node's mesh to see why they are different
	mesh mesh:obj.mesh wirecolor:green
	ok
)
(
	-- SNAPSHOT EXAMPLE
	gc()
	delete objects
	obj = converttopoly (box wirecolor:red)
	tm = matrixfromnormal (random -[1,1,1] [1,1,1])
	tm.pos = random -[50,50,50] [50,50,50]
	
	-- This is a Transformed node
	obj.transform = tm
	
	tmpMesh = snapshotasmesh obj	-- Snapshot the node
	node_v1 = polyop.getvert obj 1	-- World position (as you see it)
	mesh_v1 = getvert tmpMesh 1		-- Local position
	
	format "snapshotVert:% meshVert:%
" node_v1 mesh_v1
	
	-- Let's create a visual mesh of the node's mesh to see why they are different
	mesh mesh:obj.mesh wirecolor:green
	ok
)
(@polytools3d)
Joined: 11 months ago

Posts: 0

Actually snapshotting the mesh seems faster even for a mesh, even with the overhead of creating a copy of it.

(
	gc()
	delete objects
	obj = converttomesh (geosphere segs:128 wirecolor:red)
	tm = matrixfromnormal (random -[1,1,1] [1,1,1])
	tm.pos = random -[50,50,50] [50,50,50]
	obj.transform = tm
	
	st=timestamp(); sh=heapfree
	for j = 1 to obj.numverts do getvert obj j
	format "time:% heap:% verts:%
" (timestamp()-st) (sh-heapfree) obj.numverts
)

time:175 heap:14010320L verts:163842

(
	gc()
	delete objects
	obj = converttomesh (geosphere segs:128 wirecolor:red)
	tm = matrixfromnormal (random -[1,1,1] [1,1,1])
	tm.pos = random -[50,50,50] [50,50,50]
	obj.transform = tm
	
	st=timestamp(); sh=heapfree
	tmpMesh = snapshotasmesh obj
	for j = 1 to tmpMesh.numverts do getvert tmpMesh j
	format "time:% heap:% verts:%
" (timestamp()-st) (sh-heapfree) obj.numverts
)

time:111 heap:14010408L verts:163842

(@patan77)
Joined: 11 months ago

Posts: 0

OMG mind blown , created a speed test and snapshot is really really fast (200x faster), had no idea.
:surprised :drool:

Get vert as Reference speed: (5.001 sec)
33.275 sec (when set to 20 and disable true print )


--------------  Get vert simple (local pos)
fn fn_speedTestSimple inNumP = (
	delete $*
	gc()
	ary_obj = #()
	for i = 1 to inNumP do(
		tmp_plane = (plane width:100 length:100 lengthsegs:100 widthsegs:100)
		append ary_obj tmp_plane 
	)
	
	startTime = timestamp()
	for i = 1 to ary_obj.count do(
		theObj = (ary_obj[i].mesh)
		numVert = (getNumVerts theObj)
		for j = 1 to (numVert) do(
			if (getvert theObj j) == [0,0,0] then( -- the get vert speed test
				print "true"
			)
		)
	)
	print ("getVert Simple: " + (((timestamp() - startTime)/1000.0) as string) + " sec")
)
fn_speedTestSimple 3
---

getvert multiply transform speed test: (5.023 sec)



-------------- Get vert Tranform (local to world)
fn fn_speedTestTranform inNumP = (
	delete $*
	gc()
	ary_obj = #()
	for i = 1 to inNumP do(
		tmp_plane = (plane width:100 length:100 lengthsegs:100 widthsegs:100)
		append ary_obj tmp_plane 
	)
	
	startTime = timestamp()
	for i = 1 to ary_obj.count do(
		theObj = (ary_obj[i].mesh)
		theObjT = (ary_obj[i].transform)
		numVert = (getNumVerts theObj)
		for j = 1 to (numVert) do(
			if ((getvert theObj j)*theObjT)  == [0,0,0] then( -- the get vert speed test
				print "true"
			)
		)
	)
	print ("getVert Tranform: " + (((timestamp() - startTime)/1000.0) as string) + " sec")
)
fn_speedTestTranform 3
---

Snapshot speed test: (0.031 sec”)
0.176 sec (when set to 20 and disable true print )[/I]

-------------- Get vert Snapshot
fn fn_speedTestSnapshot inNumP = (
	delete $*
	gc()
	ary_obj = #()
	for i = 1 to inNumP do(
		tmp_plane = (plane width:100 length:100 lengthsegs:100 widthsegs:100)
		append ary_obj tmp_plane 
	)
	
	startTime = timestamp()
	for i = 1 to ary_obj.count do(
		theObj  = (snapshotasmesh ary_obj[i])
		numVert = (getNumVerts theObj)
		for j = 1 to (numVert) do(
			if (getvert theObj j)  == [0,0,0] then( -- the get vert speed test
				print "true"
			)
		)
	)
	print ("getVert Tranform: " + (((timestamp() - startTime)/1000.0) as string) + " sec")
)
fn_speedTestSnapshot 3
---