[Closed] Modifying Soft Selection [SOLVED]
Hi.
Is there anything I can do to speed up setting nonzero values?
The goal is to have soft-selection without actual selection.
(
gc();t2=timestamp();hf = heapfree
with redraw off (
delete objects
obj = plane widthSegments:90 lengthSegments:90 width:100 length:100 isselected:on
convertToPoly obj
obj.useSoftSel = on
fsel = #{}
for f=1 to polyop.getNumFaces obj where (abs (polyop.getFaceCenter obj f).y) < 5 do fsel[f] = true
polyop.setFaceSelection obj fsel
subObjectLevel = 4
redrawViews()
getData = polyop.getVDataValue
setData = polyop.setVDataValue
ssZero = #{}
ssNonZero = #()
t1=timestamp()
for i = 1 to polyop.getNumVerts obj do
(
f = getData obj 1 i
case of
(
(f > 0.999) : ssZero[i] = true
(f < 0.001) : ssZero[i] = true
default : ssNonZero[i] = f
)
)
format "Get values % sec
" ((timestamp() - t1)/1000 as float)
obj.useSoftSel = off
t1=timestamp()
setData obj 1 ssZero 0.0
format "Set zeroes % sec
" ((timestamp() - t1)/1000 as float)
t1=timestamp()
for i = 1 to polyop.getNumVerts obj where ssNonZero[i] != undefined do setData obj 1 i ssNonZero[i]
format "Set nonzeroes % sec
" ((timestamp() - t1)/1000 as float)
t1=timestamp()
update obj
format "Updating % sec
" ((timestamp() - t1)/1000 as float)
polyop.setFaceSelection obj #{}
)
redrawViews()
format "Time: %sec. Mem: %
" ((timestamp()-t2)/1000 as float) (hf-heapfree)
)
[quote=]Get values 0.018 sec
Set zeroes 0.0 sec
Set nonzeroes 0.441 sec
Updating 0.0 sec
and the updated version which works fast enough
The trick was to group indexes by value and then set value for the whole group. Sure it introduces some error to initial values but it is acceptable.
(gc();t2=timestamp();hf = heapfree
with redraw off (
delete objects
obj = plane widthSegments:90 lengthSegments:90 width:100 length:100 isselected:on
convertToPoly obj
obj.useSoftSel = on
fsel = #{}
for f=1 to polyop.getNumFaces obj where (abs (polyop.getFaceCenter obj f).y) < 5 do fsel[f] = true
polyop.setFaceSelection obj fsel
subObjectLevel = 4
redrawViews()
disableRefMsgs()
getData = polyop.getVDataValue
setData = polyop.setVDataValue
fractions = 40
step = 1.0 / fractions
ssZero = #{}
ssNonZero = for i=1 to fractions collect #{}
t1=timestamp()
for i = 1 to polyop.getNumVerts obj do
(
f = getData obj 1 i
case of
(
(f < 0.001) : ssZero[i] = true
(f > 0.999) : ssZero[i] = true
default : ssNonZero[1 + int (f / step)][i] = true
)
)
format "Get values % sec
" ((timestamp() - t1)/1000 as float)
obj.useSoftSel = off
t1=timestamp()
setData obj 1 ssZero 0.0
format "Set zeroes % sec
" ((timestamp() - t1)/1000 as float)
t1=timestamp()
for i=1 to fractions do setData obj 1 ssNonZero[i] (step*i)
format "Set nonzeroes % sec
" ((timestamp() - t1)/1000 as float)
t1=timestamp()
update obj
format "Updating % sec
" ((timestamp() - t1)/1000 as float)
enableRefMsgs()
polyop.setFaceSelection obj #{}
)
redrawViews()
format "Time: %sec. Mem: %
" ((timestamp()-t2)/1000 as float) (hf-heapfree)
)
[quote=]Get values 0.023 sec
Set zeroes 0.001 sec
Set nonzeroes 0.004 sec
Updating 0.0 sec
Just an observation, in 2019.1 it doesn’t seem there’s a significant difference between the two:
Get values 0.015 sec
Set zeroes 0.0 sec
Set nonzeroes 0.003 sec
Updating 0.0 sec
Time: 0.163sec. Mem: 1340L
vs.
Get values 0.016 sec
Set zeroes 0.001 sec
Set nonzeroes 0.005 sec
Updating 0.001 sec
Time: 0.165sec. Mem: 4268L
Thanks.
Tested it in 2017 and the difference remains. Guess all versions up to 2018 will behave the same in that matter.