global tab = #() global mody = #() global tmpmesh = undefined global tpivot = [0,0,0] global tab_przes = #() global tab_pos = #() global upSize2 global dialog2 try(destroyDialog splines_rollout) catch() rollout rollout_0 "Objects" ( button addb "Add objects (reset)" width:106 height:22 align:#left pos:[7,7] label cold "0 objects added." pos:[123,11] align:#left on rollout_0 rolledUp bState do ( upSize2() ) on addb pressed do ( tab = #() mody = #() tpivot = [0,0,0] tab_przes = #() tab_pos = #() for o in selection do append tab o for o in 1 to tab.count do ( append mody (#(undefined, undefined)) local jest_vs = false local jest_em = false --szukam volsel for i in tab[o].modifiers do ( if (classof i) as string == "Vol__Select" then ( jest_vs = true i.level = 1 i.volume = 3 mody[o][1] = i i.enabled = false ) if (classof i) as string == "Edit_Mesh" then ( jest_em = true i.enabled = false mody[o][2] = i ) ) if jest_vs == false then ( local vs = VolumeSelect level:1 volume:3 addModifier tab[o] vs mody[o][1] = vs vs.enabled = false ) if jest_em == false then ( local nem = Edit_mesh() nem.enabled = false addModifier tab[o] nem mody[o][2] = nem ) tpivot += tab[o].pos append tab_przes [0,0,0] append tab_pos (tab[o].pos) ) tpivot /= tab.count tmpmesh = snapshot (tab[1]) hide tmpmesh cold.caption = tab.count as string+" objects added." ) ) rollout rollout_1 "Push" ( radiobuttons rb1 "Method:" labels:#("Vertex Vol. Select", "Bounding Box") align:#left columns:1 spinner sp "Max iterations (1 = n^2):" type:#integer range:[1,1000000,3] width:180 align:#right spinner sp2 "Move step:" type:#worldunits range:[0.0001,1000000,1] width:125 pos:[99,80] checkbox xc "X" pos:[15,118] checkbox yc "Y" pos:[55,118] checkbox zc "Z" pos:[95,118] button create "Start" width:140 height:22 align:#center label lab "Exclude move axe:" pos:[15,101] on xc changed state do ( if state == true then ( yc.state = false zc.state = false ) ) on yc changed state do ( if state == true then ( xc.state = false zc.state = false ) ) on zc changed state do ( if state == true then ( xc.state = false yc.state = false ) ) on rollout_1 rolledUp bState do ( upSize2() ) on create pressed do ( local step = sp2.value local maxiter = sp.value startt = timestamp() local zrobilemCos = true local aiter = 0 if rb1.state == 1 then ( for i in mody do ( i[1].enabled = true i[2].enabled = true ) ) while zrobilemCos == true and aiter < maxiter do ( aiter += 1 zrobilemCos = false for o in 1 to tab.count do ( for p in o+1 to tab.count do ( if o != p and (intersects tab[o] tab[p]) then ( if rb1.state == 1 then ( max modify mode mody[o][1].Node = tab[p] local vs = getVertSelection tab[o] while ((vs as array).count) > 0 do ( local w = (normalize (tab[o].pos - tab[p].pos)) * step local od = distance tpivot tab[o].pos local pd = distance tpivot tab[p].pos if xc.checked then w.x = 0 if yc.checked then w.y = 0 if zc.checked then w.z = 0 if od > pd then tab[o].pos += w else tab[p].pos -= w vs = getVertSelection tab[o] zrobilemCos = true ) ) else ( while (intersects tab[o] tab[p]) do ( local w = (normalize (tab[o].pos - tab[p].pos)) * step local od = distance tpivot tab[o].pos local pd = distance tpivot tab[p].pos if xc.checked then w.x = 0 if yc.checked then w.y = 0 if zc.checked then w.z = 0 if od > pd then tab[o].pos += w else tab[p].pos -= w zrobilemCos = true ) ) ) ) mody[o][1].Node = tmpmesh CompleteRedraw() ) ) for i in mody do ( i[1].enabled = false i[2].enabled = false ) endt = timestamp() print (endt-startt) if zrobilemCos == false then ( messageBox "Objects do not collide!" ) ) ) rollout rollout_2 "Minimum distance" ( spinner sp1 "Distance:" type:#worldunits range:[0.00001, 1000000, 10.0] width:116 align:#right scale:0.01 spinner sp2 "Move step:" type:#worldunits range:[0.0001,1000000,0.5] width:125 align:#right spinner sp3 "Iterations:" type:#integer range:[1, 1000000, 50] width:121 align:#right button guess "Guess" width:42 height:27 pos:[33,11] checkbox xc "X" pos:[15,86] checkbox yc "Y" pos:[55,86] checkbox zc "Z" pos:[95,86] button create "Start" width:140 height:25 align:#center label lab "Exclude move axe:" pos:[15,69] on xc changed state do ( if state == true then ( yc.state = false zc.state = false ) ) on yc changed state do ( if state == true then ( xc.state = false zc.state = false ) ) on zc changed state do ( if state == true then ( xc.state = false yc.state = false ) ) on rollout_2 rolledUp bState do ( upSize2() ) on guess pressed do ( try ( local bbs = 0.0 for o in tab do ( local suma = 0.0 if xc.state == false then suma += (o.max.x - o.min.x) if yc.state == false then suma += (o.max.y - o.min.y) if zc.state == false then suma += (o.max.z - o.min.z) if xc.state == true or yc.state == true or zc.state == true then suma /= 2.0 else suma /= 3.0 bbs += suma ) bbs = bbs / (tab.count as float) sp1.value = bbs * 1.25 sp2.value = bbs / 15.0 ) catch() ) on addb pressed do ( tab = #() for o in selection do append tab o tab_przes = #() for o in tab do append tab_przes [0,0,0] ) on create pressed do ( local dist = sp1.value local power = sp2.value local iter = sp3.value for ia in 1 to iter do ( for o in 1 to tab.count do ( local best = undefined local besti = 0 for p in 1 to tab.count do ( if o != p then ( if best == undefined or (distance tab[o].pos tab[p].pos < distance tab[o].pos best.pos) then ( besti = p best = tab[p] ) ) ) local ratio = dist / (distance tab[o].pos best.pos) local w = [0,0,0] if (distance tab[o].pos best.pos) > dist then w = best.pos - tab[o].pos else w = tab[o].pos - best.pos if xc.checked then w.x = 0 if yc.checked then w.y = 0 if zc.checked then w.z = 0 local mov = (normalize w) * sp2.value * ratio if length mov > power then mov = (normalize mov) * power if distance tab[o].pos tpivot > distance best.pos tpivot then tab_przes[o] += (mov/3.0) else tab_przes[besti] -= (mov/3.0) tab_przes[o] += (mov/1.5) ) for o in 1 to tab.count do ( tab[o].pos = tab[o].pos + tab_przes[o] tab_przes[o] = 0 ) CompleteRedraw() ) ) ) rollout rollout_4 "About" ( label lab "Created by Kamil Malagowski." pos:[10,7] hyperLink km3d "KM-3D.COM" color:[120,200,220] address:"www.km-3d.com" hoverColor:white pos:[170,7] on rollout_4 rolledUp bState do ( upSize2() ) ) rollout rollout_3 "Position scale" ( spinner scax "X:" type:#float width:90 range:[0.01,100000,1.0] align:#center scale:0.01 spinner scay "Y:" type:#float width:90 range:[0.01,100000,1.0] align:#center scale:0.01 enabled: false spinner scaz "Z:" type:#float width:90 range:[0.01,100000,1.0] align:#center scale:0.01 enabled: false checkbutton lockbut "Lock" width:35 height:21 align:#center pos:[170,26] checked:true fn scaluj = ( for o in 1 to tab.count do ( local wp = tab_pos[o] - tpivot tab[o].pos = tpivot + [(wp.x*scax.value), (wp.y*scay.value), (wp.z*scaz.value)] ) ) on rollout_3 rolledUp bState do ( upSize2() ) on lockbut changed val do ( if val == true then ( scay.enabled = false scaz.enabled = false ) else ( scay.enabled = true scaz.enabled = true ) ) on scax changed val do ( if lockbut.state == true then ( scay.value = val scaz.value = val ) scaluj() ) on scay changed val do ( scaluj() ) on scaz changed val do ( scaluj() ) ) fn upSize2 = ( local sizey = 0 local dod = 25 if rollout_0.open == false then sizey += 21 else sizey += rollout_0.height + dod if rollout_1.open == false then sizey += 21 else sizey += rollout_1.height + dod if rollout_2.open == false then sizey += 21 else sizey += rollout_2.height + dod if rollout_3.open == false then sizey += 21 else sizey += rollout_3.height + dod if rollout_4.open == false then sizey += 21 else sizey += rollout_4.height + dod if sizey > ((sysInfo.DesktopSize.y - 72) - dialog2.pos.y) then sizey = ((sysInfo.DesktopSize.y - 72) - dialog2.pos.y) dialog2.size = [dialog2.size.x , sizey] ) if dialog2 != undefined then CloseRolloutFloater dialog2 dialog2 = newRolloutFloater "Uncollider 1.0" 250 562 addRollout rollout_0 dialog2 addRollout rollout_3 dialog2 --rolledUp:true addRollout rollout_1 dialog2 --rolledUp:true addRollout rollout_2 dialog2 --rolledUp:true addRollout rollout_4 dialog2