/********************************************************************/
/*                                                                  */
/* Transform Points  V1.3                                           */
/*                                                                  */
/* Converts (selected) Points to Spheres, Boxes, Discs or Cones     */
/*                                                                  */
/* © 1994  By  André Hotz    -=< Imaginative Systems >=-            */
/*                                                                  */
/********************************************************************/


call AddLib "LWModelerARexx.port", 0

ver = 'V1.3'

name = 'Transform Points '||ver

signal on error
signal on syntax

surf  = CurSurface()
layer = CurLayer()

call Req_Begin(name)

id1 = Req_AddControl('Transform Points to:','CH','Boxes' 'Spheres' 'Discs' 'Cones')

call Req_SetVal(id1,1)

if (~Req_Post()) then do
        call Req_End()
        exit
end

typ = Req_GetVal(id1)

call Req_End()

/*************************   BOXES   ********************************/

if typ=1 then do

call Req_Begin(name||' - Transform to Boxes')

id1 = Req_AddControl('Size (XYZ)','V',1)
id2 = Req_AddControl('Segments (XYZ)','V',1)
id4 = Req_AddControl('Surface','R')
id5 = Req_AddControl('Affected Points','CH','All' 'Selected')
id6 = Req_AddControl('Remove existing Points','B')
id9 = Req_AddControl('Put Objects into new Layer','B')
id10= Req_AddControl('Save Options:','CH','None' 'Objects' 'Scene&Objects')

call Req_SetVal(id1,'1 1 1','1 1 1')
call Req_SetVal(id2,'1 1 1','1 1 1')
call Req_SetVal(id4,Surf)
call Req_SetVal(id5,1)
call Req_SetVal(id6,0)
call Req_SetVal(id9,0)
call Req_SetVal(id10,1)

if (~Req_Post()) then do
    call Req_End()
    exit
end

size     = Req_GetVal(id1)
segments = Req_GetVal(id2)
surf     = Req_GetVal(id4)
mode     = Req_GetVal(id5)
cutoff   = Req_GetVal(id6)
saveopt  = Req_GetVal(id10)
copylay  = Req_GetVal(id9)

call Req_End()

if saveopt ~= 1  then filename  = GetFileName('Select Object Base Name')
if saveopt  = 3  then scenename = GetFileName('Select Scene Name')

if mode=1 then call Sel_Mode(GLOBAL)
if mode=2 then call Sel_Mode(USER)

call Surface(surf)

n = XFRM_Begin()

if n ~= 0 then do

do i = 1 to n
  Point.i= XFRM_GetPos(i)
end

call XFRM_End()

if cutoff ~= 0 then call Cut()

a = 2

if copylay ~= 0 then do
  layer = layer+1
  a = 1
  call SetLayer(layer)
  call Cut()
end

call Notify(1,'!Now transforming 'n' Points to Boxes...')

x1=word(size,1)/2
y1=word(size,2)/2
z1=word(size,3)/2


do i = 1 to n

   parse var Point.i x2 y2 z2

   low  = x2-x1||' '||y2-y1||' '||z2-z1
   high = x2+x1||' '||y2+y1||' '||z2+z1

   call MakeBox(low,high,segments)
   if ((saveopt ~= 1) & (filename ~= '(none)')) then do
      call SetLayer(layer+a)
      call Cut()
      call MakeBox(low,high,segments)
      call Save(filename||i)
      call SetLayer(layer)
   end
end
end
if n=0 then call Notify(1,'!Error: No points to transform !')

end

/*************************  SPHERES  ********************************/

if typ=2 then do

call Req_Begin(name||' - Transform to Spheres')

id1 = Req_AddControl('Radius (XYZ)','V',1)
id2 = Req_AddControl('Sides','N')
id3 = Req_AddControl('Segments','N')
id4 = Req_AddControl('Surface','R')
id5 = Req_AddControl('Affected Points','CH','All' 'Selected')
id6 = Req_AddControl('Remove existing Points','B')
id9 = Req_AddControl('Put Objects into new Layer','B')
id10= Req_AddControl('Save Options:','CH','None' 'Objects' 'Scene&Objects')

call Req_SetVal(id1,'1 1 1','1 1 1')
call Req_SetVal(id2,16)
call Req_SetVal(id3,8)
call Req_SetVal(id4,Surf)
call Req_SetVal(id5,1)
call Req_SetVal(id6,0)
call Req_SetVal(id9,0)
call Req_SetVal(id10,1)

if (~Req_Post()) then do
    call Req_End()
    exit
end

radius   = Req_GetVal(id1)
sides    = Req_GetVal(id2)
segments = Req_GetVal(id3)
surf     = Req_GetVal(id4)
mode     = Req_GetVal(id5)
cutoff   = Req_GetVal(id6)
saveopt  = Req_GetVal(id10)
copylay  = Req_GetVal(id9)

call Req_End()

if saveopt ~= 1  then filename  = GetFileName('Select Object Base Name')
if saveopt  = 3  then scenename = GetFileName('Select Scene Name')

if mode=1 then call Sel_Mode(GLOBAL)
if mode=2 then call Sel_Mode(USER)

call Surface(surf)

n = XFRM_Begin()

if n ~= 0 then do

do i = 1 to n
  Point.i= XFRM_GetPos(i)
end

call XFRM_End()

if cutoff ~= 0 then call Cut()

a = 2

if copylay ~= 0 then do
  layer = layer+1
  a = 1
  call SetLayer(layer)
  call Cut()
end

call Notify(1,'!Now transforming 'n' Points to Spheres...')

do i = 1 to n
   call MakeBall(radius,sides,segments,Point.i)
   if ((saveopt ~= 1) & (filename ~= '(none)')) then do
      call SetLayer(layer+a)
      call Cut()
      call MakeBall(radius,sides,segments,Point.i)
      call Save(filename||i)
      call SetLayer(layer)
   end
end

end
if n=0 then call Notify(1,'!Error: No points to transform !')

end

/*************************   DISCS   ********************************/

if typ=3 then do

call Req_Begin(name||' - Transform to Discs')

id1 = Req_AddControl('Radius (XYZ)','V',1)
id11= Req_AddControl('Thickness','N',1)
id2 = Req_AddControl('Sides','N')
id3 = Req_AddControl('Segments','N')
id13= Req_AddControl('Axis','CH','X' 'Y' 'Z')
id4 = Req_AddControl('Surface','R')
id14= Req_AddControl('Center Mode:','CH','DiscCenter' 'DiscTop' 'DiscBottom')
id5 = Req_AddControl('Affected Points','CH','All' 'Selected')
id6 = Req_AddControl('Remove existing Points','B')
id9 = Req_AddControl('Put Objects into new Layer','B')
id10= Req_AddControl('Save Options:','CH','None' 'Objects' 'Scene&Objects')

call Req_SetVal(id1,'1 1 1','1 1 1')
call Req_SetVal(id2,16)
call Req_SetVal(id3,8)
call Req_SetVal(id4,Surf)
call Req_SetVal(id5,1)
call Req_SetVal(id6,0)
call Req_SetVal(id11,1)
call Req_SetVal(id13,1)
call Req_SetVal(id9,0)
call Req_SetVal(id10,1)
call Req_SetVal(id14,1)

if (~Req_Post()) then do
    call Req_End()
    exit
end

radius   = Req_GetVal(id1)
sides    = Req_GetVal(id2)
segments = Req_GetVal(id3)
surf     = Req_GetVal(id4)
mode     = Req_GetVal(id5)
cutoff   = Req_GetVal(id6)
saveopt  = Req_GetVal(id10)
size     = Req_GetVal(id11)
axisi    = Req_GetVal(id13)
copylay  = Req_GetVal(id9)
centerm  = Req_GetVal(id14)

call Req_End()

if axisi = 1 then axis='X'
if axisi = 2 then axis='Y'
if axisi = 3 then axis='Z'

if saveopt ~= 1  then filename  = GetFileName('Select Object Base Name')
if saveopt  = 3  then scenename = GetFileName('Select Scene Name')

if mode=1 then call Sel_Mode(GLOBAL)
if mode=2 then call Sel_Mode(USER)

call Surface(surf)

n = XFRM_Begin()

if n ~= 0 then do

do i = 1 to n
  Point.i= XFRM_GetPos(i)
end

call XFRM_End()

if cutoff ~= 0 then call Cut()

a = 2

if copylay ~= 0 then do
  layer = layer+1
  a = 1
  call SetLayer(layer)
  call Cut()
end

call Notify(1,'!Now transforming 'n' Points to Discs...')

do i = 1 to n

   parse var Point.i x y z

   if axisi = 1 then do
      if centerm = 1 then center=Point.i
      if centerm = 2 then center=x+(size/2)||' '||y||' '||z
      if centerm = 3 then center=x-(size/2)||' '||y||' '||z

      parse var center x y z

      top = x+(size/2)
      bot = x-(size/2)

   end

   if axisi = 2 then do
      if centerm = 1 then center=Point.i
      if centerm = 2 then center=x||' '||y+(size/2)||' '||z
      if centerm = 3 then center=x||' '||y-(size/2)||' '||z

      parse var center x y z

      top = y+(size/2)
      bot = y-(size/2)
   end

   if axisi = 3 then do
      if centerm = 1 then center=Point.i
      if centerm = 2 then center=x||' '||y||' '||z+(size/2)
      if centerm = 3 then center=x||' '||y||' '||z-(size/2)

      parse var center x y z

      top = z+(size/2)
      bot = z-(size/2)
   end

   call MakeDisc(radius,top,bot,axis,sides,segments,center)

   if ((saveopt ~= 1) & (filename ~= '(none)')) then do
      call SetLayer(layer+a)
      call Cut()
      call MakeDisc(radius,top,bot,axis,sides,segments,center)
      call Save(filename||i)
      call SetLayer(layer)
   end
end
end
if n=0 then call Notify(1,'!Error: No points to transform !')
end

/*************************   CONES   ********************************/

if typ=4 then do

call Req_Begin(name||' - Transform to Cones')

id1 = Req_AddControl('Radius (XYZ)','V',1)
id11= Req_AddControl('Thickness','N',1)
id13= Req_AddControl('Axis','CH','X' 'Y' 'Z')
id2 = Req_AddControl('Sides','N')
id3 = Req_AddControl('Segments','N')
id4 = Req_AddControl('Surface','R')
id14= Req_AddControl('Center Mode:','CH','ConeCenter' 'ConeTop' 'ConeBottom')
id5 = Req_AddControl('Affected Points','CH','All' 'Selected')
id6 = Req_AddControl('Remove existing Points','B')
id9 = Req_AddControl('Put Objects into new Layer','B')
id10= Req_AddControl('Save Options:','CH','None' 'Objects' 'Scene&Objects')

call Req_SetVal(id1,'1 1 1','1 1 1')
call Req_SetVal(id2,16)
call Req_SetVal(id3,8)
call Req_SetVal(id4,Surf)
call Req_SetVal(id5,1)
call Req_SetVal(id6,0)
call Req_SetVal(id11,1)
call Req_SetVal(id13,1)
call Req_SetVal(id9,0)
call Req_SetVal(id10,1)
call Req_SetVal(id14,1)

if (~Req_Post()) then do
    call Req_End()
    exit
end

radius   = Req_GetVal(id1)
sides    = Req_GetVal(id2)
segments = Req_GetVal(id3)
surf     = Req_GetVal(id4)
mode     = Req_GetVal(id5)
cutoff   = Req_GetVal(id6)
saveopt  = Req_GetVal(id10)
size     = Req_GetVal(id11)
axisi    = Req_GetVal(id13)
copylay  = Req_GetVal(id9)
centerm  = Req_GetVal(id14)

call Req_End()

if axisi = 1 then axis='X'
if axisi = 2 then axis='Y'
if axisi = 3 then axis='Z'

if saveopt ~= 1  then filename  = GetFileName('Select Object Base Name')
if saveopt  = 3  then scenename = GetFileName('Select Scene Name')

if mode=1 then call Sel_Mode(GLOBAL)
if mode=2 then call Sel_Mode(USER)

call Surface(surf)

n = XFRM_Begin()

if n ~= 0 then do

do i = 1 to n
  Point.i= XFRM_GetPos(i)
end

call XFRM_End()

if cutoff ~= 0 then call Cut()

a = 2

if copylay ~= 0 then do
  layer = layer+1
  a = 1
  call SetLayer(layer)
  call Cut()
end

call Notify(1,'!Now transforming 'n' Points to Cones...')

do i = 1 to n

   parse var Point.i x y z

   if axisi = 1 then do
      if centerm = 1 then center=Point.i
      if centerm = 2 then center=x+(size/2)||' '||y||' '||z
      if centerm = 3 then center=x-(size/2)||' '||y||' '||z
      
      parse var center x y z

      top = x+(size/2)
      bot = x-(size/2)
   end

   if axisi = 2 then do
      if centerm = 1 then center=Point.i
      if centerm = 2 then center=x||' '||y+(size/2)||' '||z
      if centerm = 3 then center=x||' '||y-(size/2)||' '||z

      parse var center x y z

      top = y+(size/2)
      bot = y-(size/2)
   end

   if axisi = 3 then do
      if centerm = 1 then center=Point.i
      if centerm = 2 then center=x||' '||y||' '||z+(size/2)
      if centerm = 3 then center=x||' '||y||' '||z-(size/2)

      parse var center x y z

      top = z+(size/2)
      bot = z-(size/2)
   end

   call MakeCone(radius,top,bot,axis,sides,segments,center)

   if ((saveopt ~= 1) & (filename ~= '(none)')) then do
      call SetLayer(layer+a)
      call Cut()
      call MakeCone(radius,top,bot,axis,sides,segments,center)
      call Save(filename||i)
      call SetLayer(layer)
   end
end
end
if n=0 then call Notify(1,'!Error: No points to transform !')
end


if ((saveopt = 3) & (scenename ~= '(none)')) then call MakeScene()

if n ~= 0 then call Notify(1,'!Thanks for using Transform Points '||ver,'','@© 1994 By André Hotz','@of','-=> Imaginative Systems <=-','-=> Productions <=-','')


call RemLib "LWModelerARexx.port"
exit


MakeScene:

   call METER_BEGIN(n+2,"Saving Scene...")

   If (~Open(Scene,scenename,'W')) then return

   call Writeln(Scene,"LWSC")
   call Writeln(Scene,"1")
   call Writeln(Scene," ")
   call Writeln(Scene,"FirstFrame 1")
   call Writeln(Scene,"LastFrame 1")
   call Writeln(Scene,"FrameStep 1")
   call Writeln(Scene," ")
   call METER_STEP()
   Do i=1 To n
      call Writeln(Scene,"LoadObject "||filename||i)
      call Writeln(Scene,"ObjectMotion (unnamed)")
      call Writeln(Scene,"  9")
      call Writeln(Scene,"  1")
      call Writeln(Scene,"  0.0 0.0 0.0 0.0 0.0 0.0 1.0 1.0 1.0")
      call Writeln(Scene,"  0 0 0.0 0.0 0.0")
      call Writeln(Scene,"  0.0 0.0 0.0 0.0 0.0 0.0 1.0 1.0 1.0")
      call Writeln(Scene,"  0 0 0.0 0.0 0.0")
      call Writeln(Scene,"EndBehavior 1")
      call Writeln(Scene,"ShadowOptions 7")
      call Writeln(Scene,"")
      call METER_STEP()
   End
   call Writeln(Scene,"AmbientColor 255 255 255")
   call Writeln(Scene,"AmbIntensity 0.250000")
   call Writeln(Scene,"")
   call Writeln(Scene,"AddLight")
   call Writeln(Scene,"LightName Light")
   call Writeln(Scene,"LightMotion (unnamed)")
   call Writeln(Scene,"  9")
   call Writeln(Scene,"  1")
   call Writeln(Scene,"  0.0 0.0 0.0 59.999996 29.999998 0.0 1.0 1.0 1.0")
   call Writeln(Scene,"  0 0 0.0 0.0 0.0")
   call Writeln(Scene,"EndBehavior 1")
   call Writeln(Scene,"LightColor 255 255 255")
   call Writeln(Scene,"LgtIntensity 1.000000")
   call Writeln(Scene,"LightType 0")
   call Writeln(Scene,"LensFlare 0")
   call Writeln(Scene,"ShadowCasting 1")
   call Writeln(Scene,"")
   call Writeln(Scene,"CameraMotion (unnamed)")
   call Writeln(Scene,"  9")
   call Writeln(Scene,"  1")
   call Writeln(Scene,"  0.0 0.0 -6.120000 0.0 0.0 0.0 1.0 1.0 1.0")
   call Writeln(Scene,"  0 0 0.0 0.0 0.0")
   call Writeln(Scene,"EndBehavior 1")
   call Writeln(Scene,"ZoomFactor 3.200000")
   call Writeln(Scene,"RenderMode 2")
   call Writeln(Scene,"RayTraceEffects 0")
   call Writeln(Scene,"Resolution 1")
   call Writeln(Scene,"Overscan 1")
   call Writeln(Scene,"Antialiasing 0")
   call Writeln(Scene,"AdaptiveSampling 1")
   call Writeln(Scene,"AdaptiveThreshold 8")
   call Writeln(Scene,"FilmSize 2")
   call Writeln(Scene,"FieldRendering 0")
   call Writeln(Scene,"MotionBlur 0")
   call Writeln(Scene,"DepthOfField 0")
   call Writeln(Scene,"")
   call Writeln(Scene,"SolidBackdrop 1")
   call Writeln(Scene,"BackdropColor 0 0 0")
   call Writeln(Scene,"ZenithColor 0 40 80")
   call Writeln(Scene,"SkyColor 120 180 240")
   call Writeln(Scene,"GroundColor 50 40 30")
   call Writeln(Scene,"NadirColor 100 80 60")
   call Writeln(Scene,"FogType 0")
   call Writeln(Scene,"DitherIntensity 1")
   call Writeln(Scene,"AnimatedDither 0")
   call Writeln(Scene,"")
   call Writeln(Scene,"ViewMode 3")
   call Writeln(Scene,"ViewAimpoint 0.000000 0.000000 0.000000")
   call Writeln(Scene,"ViewDirection 0.000000 -0.174533 0.000000")
   call Writeln(Scene,"ViewZoomFactor 3.200000")
   call Writeln(Scene,"LayoutGrid 3")
   call Writeln(Scene,"GridSize 1.000000")
   call Writeln(Scene,"ShowObjects 1")
   call Writeln(Scene,"ShowBones 1")
   call Writeln(Scene,"ShowLights 0")
   call Writeln(Scene,"ShowCamera 1")
   call Writeln(Scene,"ShowMotionPath 1")
   call Writeln(Scene,"ShowSafeAreas 0")
   call Writeln(Scene,"ShowBGImage 0")
   call Writeln(Scene,"ShowFogRadius 0")
   call Writeln(Scene,"ShowRedraw 0")

   call close(Scene)

   call METER_STEP()
   call METER_END()

return


syntax:
error:
  call end_all
	t=Notify(1,'!Rexx Script Error','@'ErrorText(rc),'Line 'SIGL)
	exit

