Is there a fast way to move verts to verts to different locations? If you move everything to a single location it’s very fast, but if each vert needs a different location the performance can be terrible. Here’s an example, which on my PC takes 984ms to move the 8066 verts:
sp = Sphere segs:128 name:#test isSelected:on
max modify mode
modPanel.setCurrentObject sp
macros.run "Modifier Stack" "Convert_to_Poly"
numv = sp.GetNumVertices()
gvp = polyOp.getVert
vrtsToMove = #()
oldPositions = #()
for k=1 to numv do (
append vrtsToMove k
append oldPositions (gvp sp k)
)
seed 0
newPositions = #()
for i=1 to vrtsToMove.count do (
x=((random -0.4 0.4) + oldPositions[i].x)
y=((random -0.4 0.4) + oldPositions[i].y)
z=((random -0.4 0.4) + oldPositions[i].z)
append newPositions [x,y,z]
)
gc()
t1 = timeStamp()
svp = polyop.setVert
for i=1 to vrtsToMove.count do (svp sp #{vrtsToMove[i]} newPositions[i] node:sp)
format "maxscript\nresult:%\ntime:% ms\n" test (timeStamp() - t1)
One thing I know can speed it up is turning on undo for only the first and last vert being moved and having undo off for the rest. But in the above example that only brings it down to about 400ms, like such:
sp = Sphere segs:128 name:#test isSelected:on
max modify mode
modPanel.setCurrentObject sp
macros.run "Modifier Stack" "Convert_to_Poly"
numv = sp.GetNumVertices()
gvp = polyOp.getVert
vrtsToMove = #()
oldPositions = #()
for k=1 to numv do (
append vrtsToMove k
append oldPositions (gvp sp k)
)
seed 0
newPositions = #()
for i=1 to vrtsToMove.count do (
x=((random -0.4 0.4) + oldPositions[i].x)
y=((random -0.4 0.4) + oldPositions[i].y)
z=((random -0.4 0.4) + oldPositions[i].z)
append newPositions [x,y,z]
)
gc()
t1 = timeStamp()
svp = polyop.setVert
with undo on (svp sp #{vrtsToMove[1]} newPositions[1] node:sp)
with undo off (
for i=2 to (vrtsToMove.count - 1) do (svp sp #{vrtsToMove[i]} newPositions[i] node:sp)
)
with undo on (svp sp #{vrtsToMove[vrtsToMove.count]} newPositions[newPositions.count] node:sp)
format "maxscript\nresult:%\ntime:% ms\n" test (timeStamp() - t1)