/* CMD: Dice By GLYPH Dice an object and make a scene of it The pivot points of the pieces are in their centers for proper rotations. Screws up occaisionally because of that frigging 'Polygon partitioning error' that Boolean commands like to bring up. */ JUNK: mxx="LWModelerARexx.port" signal on error signal on syntax mxx_add = addlib(mxx,0) call main if (mxx_add) then call remlib(mxx) exit syntax: error: t=Notify(1,'!Rexx Script Error','@'ErrorText(rc),'Line 'SIGL) if (mxx_add) then call remlib(mxx) exit return main: Address 'LWModelerARexx.port' call random(,,time('s')) scenename = 'toaster:3d/scenes/test.scn' objbase = 'toaster:3d/objects/test/testobj' call Menu call GetSize call CutObject call SaveScene return Menu: cutx = 4 cuty = 4 cutz = 4 call req_begin 'Dice Object by GLYPH' req1 = req_addcontrol('X divisions',N,0) req2 = req_addcontrol('Y divisions',N,0) req3 = req_addcontrol('Z divisions',N,0) call req_setval req1, cutx, cutx call req_setval req2, cuty, cuty call req_setval req3, cutz, cutz if (~req_post()) then exit(0) cutx = req_getval(req1) cuty = req_getval(req2) cutz = req_getval(req3) scenename = getfilename('Scene File','toaster:3d/scenes') if scenename = '(none)' then exit(0) objbase = getfilename('Object Prefix','toaster:3d/objects') if objbase = '(none)' then exit(0) return GetSize: curlay=curlayer() emp = emptylayers() if (words(emp) = 0) then do ok = notify(1,'!No empty layer.') break end if (words(emp) > 0) then do freelay = word(emp,1) end box=boundingbox() parse var box n x1 x2 y1 y2 z1 z2 dx = (x2-x1) dy = (y2-y1) dz = (z2-z1) x1 = x1-dx*0.01 x2 = x2+dx*0.01 y1 = y1-dy*0.01 y2 = y2+dy*0.01 z1 = z1-dz*0.01 z2 = z2+dz*0.01 dx = (x2-x1) dy = (y2-y1) dz = (z2-z1) return CutObject: curobj = 0 call setlayer(freelay) call setblayer(curlay) do xn = 1 to cutx do yn = 1 to cuty do zn = 1 to cutz call cut() call makebox(x1+(xn-1)*dx/cutx y1+(yn-1)*dy/cuty z1+(zn-1)*dz/cutz,x1+xn*dx/cutx y1+yn*dy/cuty z1+zn*dz/cutz) call boolean('intersect') call SaveIt end end end return SaveIt: box=boundingbox() parse var box n d1 d2 d3 d4 d5 d6 if n=0 then return if d1x1+xn*dx/cutx+dx/1000 then return if d3y1+yn*dy/cuty+dy/1000 then return if d5z1+zn*dz/cutz+dz/1000 then return curobj = curobj+1 cx.curobj = (d1+d2)/2 cy.curobj = (d3+d4)/2 cz.curobj = (d5+d6)/2 call save(objbase||'.'||curobj) return SaveScene: call open(scene, scenename, 'W') call writeln(scene, 'LWSC') call writeln(scene, 1) call writeln(scene, '') do o = 1 to curobj objname = objbase||'.'||o call writeln(scene, 'LoadObject '||objname) call writeln(scene, 'ObjectMotion (unnamed)') call writeln(scene, ' '||9) call writeln(scene, ' '||1) x=cx.o y=cy.o z=cz.o h=0 p=0 b=0 xs=1 ys=1 zs=1 linear = 1 frame = 0 call WriteKey call writeln(scene, 'EndBehavior 1') call writeln(scene, 'PivotPoint '||cx.o||' '||cy.o||' '||cz.o) call writeln(scene, 'ShadowOptions 7') call writeln(scene, '') end call close scene return WriteKey: call writeln(scene, ' '||x||' '||y||' '||z||' '||h||' '||p||' '||b||' '||xs||' '||ys||' '||zs) call writeln(scene, ' '||frame||' '||linear||' 0.0 0.0 0.0') return