Notifications
Clear all

[Closed] verts setVert eat all RAM for big mesh

HI, I have a simple script to copy vertices position from one mesh to another mesh with same point order, different pose.

theMesh = selection[1]
theMesh2 = selection[2]

for vert in (theMesh.mesh.verts as bitarray) do
(
polyop.setVert theMesh2 vert [((polyop.getVert theMesh vert).x),((polyop.getVert theMesh vert).y),((polyop.getVert theMesh vert).z)]
)

But when i run with huge polycount meshes it eat ALL ram up to 24GB and run forever. Is there anyway to optimize that? I am very new to maxscript.

Thanks!

4 Replies

I think the problem is here

theMesh.mesh

on each iteration the script creates a copy of theMesh and this increase the RAM usage.

Try this:


(
	local poGetVert = polyop.getVert
	local poSetVert = polyop.setVert
	theMesh = selection[1]
	theMesh2 = selection[2]
	
	tmpMesh = snapshotAsMesh theMesh
	vertsBA = #{1..(tmpMesh.numVerts)}
	for vert in vertsBA do
	(
		vertPos = poGetVert theMesh vert
		poSetVert theMesh2 vert [(vertPos.x),(vertPos.y),(vertPos.z)]
	)
	delete tmpMesh
)

Hey thanks for the response! unfortunatly it does exactly the same thing. RAM goes up up up and then the apocalypse! I also tried an option with a for loop with the vertex count and does the same…

How much are the vertices on your scene?
Can you upload it?
The polyop.SetVert can be used to set the position of all verts at once, not per vertex, which is a lot faster.


(
	local poGetVert = polyop.getVert
	local poSetVert = polyop.setVert
	theMesh = selection[1]
	theMesh2 = selection[2]
	
	vertsBA = #{1..(theMesh.numVerts)}
	theMeshVertsPosArr = for vert in vertsBA collect vertPos = poGetVert theMesh vert
	--
	poSetVert theMesh2 #{1..(theMesh2.numVerts)}  theMeshVertsPosArr

)

Wow that is quick!!! works #1!!! and no wait time! thank very much sir!