Hello.
I need your help to make my code work faster. I know it’s possible to make it ~2x faster because one popular script can do that 
I need to randomize uv shells, not uv polygons, but this code is just an example to understand my issue. It creates plane 70x70, breaks all vertices to get 4900 uv elements and then randomizes their position in Unwrap.
For now I have 3 methods:
-
Method 1.
Works fine. But as I said, I’m sure it’s possible to randomize 4900 uv polys 2 times faster. -
Method 2.
I think it could be faster because it doesn’t need face>vert conversion, but “moveSelected” function eats ~2.2GB of RAM (3dsmax process, not script itself) maybe because of TheHold.Put inside C++ method. Also I suppose this method could be faster without this undo issue but I don’t understand how to disable TheHold.Put. I tried SuperBegin-SuperAccept and “undo off” with no luck. -
Method 3.
Here I’m trying to check if selecting vertices is faster than selecting polys and converting to vertices (Method 1). So I selected #{1…4} verts just to test it, and this method is surprisingly slower than Method 1.
I will appreciative any help.
(
-- create test object
local obj = Plane width:1000 length:1000 lengthsegs:70 widthsegs:70
convertToPoly obj
polyop.breakVerts obj #{1..(polyop.getNumVerts obj)}
local numfaces = polyop.getNumFaces obj
local allUvPolys = #{1..numfaces}
local unwMod = Unwrap_UVW()
addmodifier obj unwMod
select obj
-- cache functions
c_selectPolygonsUpdate = unwMod.selectPolygonsUpdate
c_selectVertices = unwMod.selectVertices
c_moveSelectedVertices = unwMod.moveSelectedVertices
c_moveSelected = unwMod.moveSelected
c_getSelectionFromFace = unwMod.GetSelectionFromFace
clearlistener()
ts1 = timestamp()
-- move uv elements method 1
subobjectlevel = 1
for p in allUvPolys do (
c_selectPolygonsUpdate #{p} false
c_getSelectionFromFace()
theOffset = [random -0.1 0.1 , random -0.1 0.1 , 0]
c_moveSelectedVertices theOffset
)
subobjectlevel = 0
format "uv move METHOD 1: % ms\n" (timestamp() - ts1)
ts2 = timestamp()
-- move uv elements method 2
for p in allUvPolys do (
c_selectPolygonsUpdate #{p} false
theOffset = [random -0.1 0.1 , random -0.1 0.1 , 0]
c_moveSelected theOffset
)
format "uv move METHOD 2: % ms\n" (timestamp() - ts2)
ts3 = timestamp()
-- move uv elements method 3
for p in allUvPolys do (
c_selectVertices #{1..4} -- selecting any vertices
theOffset = [random -0.1 0.1 , random -0.1 0.1 , 0]
c_moveSelectedVertices theOffset
)
format "uv move METHOD 3: % ms\n" (timestamp() - ts3)
)
My time:
uv move METHOD 1: 2663 ms
uv move METHOD 2: 2701 ms
uv move METHOD 3: 3467 ms
