Hi,
I’ve made a script that aligns UV islands to the bottom left. It needs to be faster though.
Can anyone have a look through and see if there are any optimizations possible?
Can I somehow avoid selecting vertices? Are there other methods of selecting UV elements?
Since the script is WIP, there’s some commented out stuff you can ignore. I’ve commented out the actual moving of the UV islands.
Alternative 1
Here I use the selection bounding box to align the islands to the bottom left.
uv = modPanel.getCurrentObject()
TVsub = uv.unwrap2.getTVSubObjectMode()
case TVsub of (
2: (uv.unwrap2.edgeToVertSelect()
uv.unwrap2.setTVSubObjectMode 1)
3: (uv.unwrap2.faceToVertSelect()
uv.unwrap2.setTVSubObjectMode 1)
)
bitarr = uv.unwrap.getSelectedVertices()
bitarrc = bitarr.count
rollout progresspopup "Progress"
(
progressBar progbar value:0.0
)
--createDialog progresspopup
start = timeStamp()
with redraw off
for v = 1 to bitarrc do (
--progresspopup.progbar.value = 100.0*v/bitarrc
if bitarr[v] == 1 then (
uv.unwrap.selectVertices #{v}
--uv.unwrap.selectVertices #{v}
uv.unwrap2.selectElement()
--uv.unwrap2.selectElement()
uv.unwrap2.snapPivot 2
elemoffset=uv.unwrap2.getPivotOffset()
elempos=uv.unwrap2.getSelCenter()
elemmove=elemoffset+elempos
--uv.unwrap2.moveSelected -elemmove
elemarr = #()
elemarr = uv.unwrap.getSelectedVertices() as array
for i = 1 to elemarr.count do
bitarr[elemarr[i]] = 0
)
)
end = timeStamp()
format "Processing took % seconds\n" ((end - start) / 1000.0)
--destroyDialog progresspopup
uv.unwrap2.setTVSubObjectMode TVsub
Alternative 2
Here I put all vertex coordinates in two arrays and find the smallest x and y values.
Slightly slower, but can maybe be made faster.
uv = modPanel.getCurrentObject()
TVsub = uv.unwrap2.getTVSubObjectMode()
case TVsub of (
2: (uv.unwrap2.edgeToVertSelect()
uv.unwrap2.setTVSubObjectMode 1)
3: (uv.unwrap2.faceToVertSelect()
uv.unwrap2.setTVSubObjectMode 1)
)
bitarr = uv.unwrap.getSelectedVertices()
bitarrc = bitarr.count
rollout progresspopup "Progress"
(
progressBar progbar value:0.0
)
--createDialog progresspopup
start = timeStamp()
with redraw off
for v = 1 to bitarrc do (
--progresspopup.progbar.value = 100.0*v/bitarrc
if bitarr[v] == 1 then (
uv.unwrap.selectVertices #{v}
uv.unwrap2.selectElement()
tempselba = uv.unwrap.getSelectedVertices()
tempsel = tempselba as array
temparrx = #()
temparry = #()
for t=1 to tempsel.count do (
--if tempsel[t] == 1 then (
temppos = uv.unwrap.getVertexPosition 0 tempsel[t]
append temparrx temppos[1]
append temparry temppos[2]
--)
)
--xmin = amin temparrx
--ymin = amin temparry
/*
uv.unwrap2.moveSelected [-xmin,-ymin,0]*/
bitarr -= tempselba
)
)
end = timeStamp()
format "Processing took % seconds\n" ((end - start) / 1000.0)
--destroyDialog progresspopup
uv.unwrap2.setTVSubObjectMode TVsub
Grateful for any help