home *** CD-ROM | disk | FTP | other *** search
- /* Breakup your model into many models. Very cool to use with SPARKS */
- /* Enter x y z slice and the volume select will break apart and save each */
- /* Then use SPARKS to bulk load and reposition the models for the start */
- /* Save source will center the fragments & write a source to position them */
- /* No save source needs v2.056 or better to write a move pivot into scene */
- /* this is an alternate method but objects dont bounce well because of the */
- /* offset pivot point fools the groundplane detection routine */
- /* © march 25 1994 Jon Tindall. This macro is not public domain. */
- /* many thanks for not passing it around */
-
-
- NUMERIC DIGITS 6
- libadd = addlib("LWModelerARexx.port",0)
- signal on error
- signal on syntax
-
- RexxMathLib = "rexxmathlib.library"
- IF POS(RexxMathLib , SHOW('Libraries')) = 0 THEN
- IF ~ADDLIB(RexxMathLib , 0 , -30 , 0) THEN DO
- call notify(1,"!Can't find rexxmathlib.library")
- exit
- end
-
- version = 'v1.2'
- sysnam = 'BreakUp' version
- filnam = 'ENV:Breakup.state'
- fnam = "ram:"
- div = "3 3 3"
- cnt = 1
- home = CURLAYER()
- scratch = Word(EMPTYLAYERS(),1)
- source = 1
- explosioncenter="0 0 0"
- pi=3.14159265358
- DegreesPerRadian=180/pi
- extent = 2
- reversex= 1
- reversey= 2
- reversez= 1
- random = 1
- primary = 1
- inside = 1
- voltype = 1
-
-
- Do Forever
- call req_begin sysnam
- id_mes = req_addcontrol("",'T',"Break-up 1 model into many models")
- id_div = req_addcontrol("X, Y, Z subdivision", 'V')
- id_explosioncenter = req_addcontrol("Explosion center",'V')
- id_extent = req_addcontrol("Maximum explosion radius",'n')
- id_mes2 = req_addcontrol("",'T',"Reset fragment origins by")
- id_source = req_addcontrol("Centering mode",'CH',"MovePivotPoint MakeSourceFile")
- id_reversex = req_addcontrol("Fragment ordering",'CH'," forward reverseX ")
- id_reversey = req_addcontrol("",'CH'," forward reverseY ")
- id_reversez = req_addcontrol("",'CH'," forward reverseZ ")
- id_primary = req_addcontrol("Primary breakup axis",'CH',"X Y Z")
- id_random = req_addcontrol("Random ordering",'CH'," no yes")
- id_inside = req_addcontrol("Create inner geometry?",'CH',"no yes")
- id_voltype = req_addcontrol("Volume select type",'CH',"include exclude")
-
- call req_setval id_div, div
- call req_setval id_explosioncenter, explosioncenter
- call req_setval id_source, source
- call req_setval id_extent, extent
- call req_setval id_reversex, reversex
- call req_setval id_reversey, reversey
- call req_setval id_reversez, reversez
- call req_setval id_primary, primary
- call req_setval id_random, random
- call req_setval id_inside, inside
- call req_setval id_voltype, voltype
-
- If (~req_post()) then do
- call req_end
- exit
- end
-
- div = req_getval(id_div)
- explosioncenter = req_getval(id_explosioncenter)
- source = req_getval(id_source)
- extent = req_getval(id_extent)
- reversex = req_getval(id_reversex)
- reversey = req_getval(id_reversey)
- reversez = req_getval(id_reversez)
- primary = req_getval(id_primary)
- random = req_getval(id_random)
- inside = req_getval(id_inside)
- voltype = req_getval(id_voltype)
-
-
- call SEL_MODE('global')
- Box=BoundingBox()
- parse var box n x1 x2 y1 y2 z1 z2
- If n=0 then do
- call notify(1,"!Need data on this layer!")
- exit
- end
- fnam = getfilename("Base save name",fnam)
- if fnam='(none)' then do
- call req_end
- exit
- end
-
- If voltype=1 then voltype="volincl"
- else voltype="volexcl"
- xslice = Word(div,1)
- yslice = Word(div,2)
- zslice = Word(div,3)
- cx = Word(explosioncenter,1)
- cy = Word(explosioncenter,2)
- cz = Word(explosioncenter,3)
- say xslice yslice zslice
-
- /* find cell size */
- xsize = x2-x1
- If xsize=0 then xsize=.01
- ysize = y2-y1
- If ysize=0 then ysize=.01
- zsize = z2-z1
- If zsize=0 then zsize=.01
- say xsize ysize zsize
-
-
- If random = 1 then do
- xover = xsize*.005 /* .05% bigger to insure capturing all polys */
- yover = ysize*.005 /* along the coplanar edges */
- zover = zsize*.005
- xstart = x1-(xover*.5)
- ystart = y1-(yover*.5)
- zstart = z1-(zover*.5)
- say xstart ystart zstart
- x = (xsize+xover)/xslice /* cell size */
- y = (ysize+yover)/yslice
- z = (zsize+zover)/zslice
- If reversex=1 then do
- xlo = 0
- xhi = xslice-1
- xc = 1
- end
- If reversex=2 then do
- xhi = 0
- xlo = xslice-1
- xc = -1
- end
-
- If reversey=1 then do
- ylo = 0
- yhi = yslice-1
- yc = 1
- end
- If reversey=2 then do
- yhi = 0
- ylo = yslice-1
- yc = -1
- end
-
- If reversez=1 then do
- zlo = 0
- zhi = zslice-1
- zc = 1
- end
- If reversez=2 then do
- zhi = 0
- zlo = zslice-1
- zc = -1
- end
- say xlo xhi ylo yhi zlo zhi
- If primary = 1 then do
- prim.1 ='Do i = ' xlo ' to ' xhi ' by ' xc
- prim.2 ='Do j = ' ylo ' to ' yhi ' by ' yc
- prim.3 ='Do k = ' zlo ' to ' zhi ' by ' zc
- end
- If primary = 2 then do
- prim.3 = 'Do i = ' xlo ' to ' xhi ' by ' xc
- prim.1 = 'Do j = ' ylo ' to ' yhi ' by ' yc
- prim.2 = 'Do k = ' zlo ' to ' zhi ' by ' zc
- end
- If primary = 3 then do
- prim.2 = 'Do i = ' xlo ' to ' xhi ' by ' xc
- prim.3 = 'Do j = ' ylo ' to ' yhi ' by ' yc
- prim.1 = 'Do k = ' zlo ' to ' zhi ' by ' zc
- end
- primaryaxis = prim.1 d2c(10) prim.2 d2c(10) prim.3 d2c(10)
- say primaryaxis
-
- /* say nx1 xstart x i j k */
- prim2='nx1 = '||xstart||'+('||x||'*i)'||D2C(10)
- prim2=prim2||'ny1 = '||ystart||'+('||y||'*j)'||D2C(10)
- prim2=prim2||'nz1 = '||zstart||'+('||z||'*k)'||D2C(10)
- prim2=prim2||'nx2 = nx1 + '||x||d2c(10)
- prim2=prim2||'ny2 = ny1 + '||y||d2c(10)
- prim2=prim2||'nz2 = nz1 + '||z||d2c(10)
- /* say i j k */
- /* say nx1 ny2 nz1 nx2 ny1 nz2 */
- prim2=prim2||'call SEL_MODE("'"user"'")'||d2c(10)
- prim2=prim2||'call SEL_POLYGON("'"clear"'")'||d2c(10)
- prim2=prim2||'call SEL_POLYGON("'"set"'","'"volincl"'",nx1 ny1 nz1, nx2 ny2 nz2)'||d2c(10)
- prim2=prim2||'call CUT()'||d2c(10)
- prim2=prim2||'If Word(BOUNDINGBOX(),1)~= 0 then call nibble' || d2c(10)
- prim2=prim2||'else call PASTE()'||d2c(10)
- prim2=prim2||'call SETLAYER(home)'||d2c(10)
- prim2=prim2||'end'||d2c(10)
- prim2=prim2||'end'||d2c(10)
- prim2=prim2||'end'
-
- primaryaxis = primaryaxis prim2
- say primaryaxis
- interpret primaryaxis
- end
-
-
- If random = 2 then do
-
- xstart = x1
- ystart = y1
- zstart = z1
-
- x = xsize/xslice /* cell size */
- y = ysize/yslice
- z = zsize/zslice
-
- list=''
- do i = 1 to (xslice*yslice*zslice)
- list = list||i||' '
- end
- c=1
- Do i = 0 to xslice-1
- Do j = 0 to yslice-1
- Do k = 0 to zslice-1
- nx1 = (xstart+(x*i))-(x*.1)
- ny1 = (ystart+(y*j))-(y*.1)
- nz1 = (zstart+(z*k))-(z*.1)
- rand.c=nx1 ny1 nz1
- nx2 = nx1 + x + (x*.2)
- ny2 = ny1 + y + (y*.2)
- nz2 = nz1 + z + (z*.2)
- rand2.c=nx2 ny2 nz2
- c=c+1
- end
- end
- end
-
- Do in = 1 to (xslice*yslice*zslice)
- if words(list)>1 then t=random(1,words(list),Time('S'))
- else t=1
- i=word(list,t)
- say "i=" i list
- list=strip(delword(list,t,1))
- call SEL_MODE('user')
- call SEL_POLYGON('clear')
- call SEL_POLYGON('set',voltype , rand.i, rand2.i)
- call CUT()
- If Word(BOUNDINGBOX(),1)~= 0 then call nibble
- else call PASTE() /* put it back, cut got it all */
- call SETLAYER(home)
- end
- end
-
-
- Box=BoundingBox()
- parse var box n
- If n~=0 then do
- call CUT()
- call nibble
- end
- call SETLAYER(home)
- call writecenter
- call writetarget
- qty = Trunc(xslice*yslice*zslice)
- call notify(1,"!saved " cnt-1 " fragments out of " qty)
- exit
- call end_all
- end /* forever */
-
-
- nibble:
- call SETLAYER(scratch)
- call PASTE()
- call sel_mode('USER')
- c=xfrm_begin()
- sx=0; sy=0; sz=0
- do n=1 to c
- v=xfrm_getpos(n)
- sx=sx+word(v,1)
- sy=sy+word(v,2)
- sz=sz+word(v,3)
- v=sx/c sy/c sz/c
- end
- call xfrm_end()
- If source = 2 then do
- v1 = -1*Word(v,1)
- v2 = -1*Word(v,2)
- v3 = -1*Word(v,3)
- call Move(v1 v2 v3) /* center object */
- end
- If inside = 2 then call inr
- call SAVE(fnam||Right(cnt,3,0))
- call CUT()
- pp.cnt = v
- cnt = cnt + 1
- return
-
- inr:
- call copy()
- call changesurface("inside")
- call flip()
- call paste()
- call mergepoints()
- call surface("default")
- return
-
- writecenter: /* file to move pivot point only, needs SPARKS v2.056 or < */
- If (open(state, "t:pp.dat", 'W')) then do i = 1 to cnt-1
- call writeln state, pp.i
- end i
- call close state
- /* source file to set up SPARKS origins */
- If (open(state, "t:source", 'W')) then do i = 1 to cnt-1
- call writeln state, pp.i
- end i
- call close state
-
- return
-
- writetarget:
- do i = 1 to cnt-1
- dx = Word(pp.i,1) - cx
- dy = Word(pp.i,2) - cy
- dz = Word(pp.i,3) - cz
- r = sqrt(dx * dx + dy * dy + dz * dz)
- If r<extent then do
- factor = (1-(r/extent))+1
- tx = cx + dx * factor
- ty = cy + dy * factor
- tz = cz + dz * factor
- end
-
- If r>=extent then do
- tx = cx + dx * 1
- ty = cy + dy * 1
- tz = cz + dz * 1
- end
- target.i = tx ty tz
- end
-
- If (open(state, "t:target", 'W')) then do i = 1 to cnt-1
- call writeln state, target.i
- end i
- call close state
-
- return
-
-
-
-
- syntax:
- error:
- call end_all
- t=Notify(1,'!Rexx Script Error','@'ErrorText(rc),'Line 'SIGL||sourceline(SIGL))
- exit
-