@CylinderMapping basic settings
--track0:PlayPos,0,1800,0
--track1:Opacity,0,100,100
--track2:rAspect,-100,100,0
--param:otype="text";val="Please set text/graphics name/filename";
ld_time=obj.track0
alpha=obj.track1/100
ld_aspect=obj.track2/100

fontName="MS UI Gothic";
fontSize=32
fontType=0
figColor=0xffffff
figSize=100
figLine=1000
cyl_cut=1
cyl_space=0
cyl_spin=0
kijun=0
shiftR=0
shiftX=0
shiftY=0
shiftZ=0

@Cylinder Text settings
--track0:Size,0,300,32
--track1:Type,0,4,0
--param:fontName="MS UI Gothic";
fontSize=obj.track0
fontType=obj.track1


@Cylinder Graphics settings
--track0:Size,0,1000,100
--track1:LineWidth,0,1000,1000
--param:figColor=0xffffff;
figSize=obj.track0
figLine=obj.track1


@CrossSection settings
--track0:#Cut,1,30,1
--track1:Gap,-1000,1000,0
--track2:Twist,-3600,3600,0
--track3:dRadius,-1000,1000,0
--param:kijun=0;
cyl_cut=math.floor(obj.track0)
cyl_space=obj.track1
cyl_spin=obj.track2
shiftR=obj.track3

@CrossSection drift settings
--track0:dx,-1000,1000,0
--track1:dy,-1000,1000,0
--track2:dz,-1000,1000,0
shiftX=obj.track0
shiftY=obj.track1
shiftZ=obj.track2

@CylinderMapping(Vert)
--track0:Slice,3,30,5
--track1:Disp#,0,30,5
--track2:RadiusAdj,-2000,2000,0
--track3:Spin,-3600,3600,0
--param:cyl_dir=1;effect=1;

cyl_div=math.floor(obj.track0)
cyl_disp=math.floor(obj.track1)
if(cyl_div<cyl_disp) then
  cyl_disp=cyl_div
end
cyl_r_adjust=obj.track2
cyl_rotshift=obj.track3

if(cyl_disp<=0) then
  obj.load("text","")
else
  obj.setfont(fontName,fontSize,fontType)
  if(otype=="figure") then
    obj.load(otype,val,figColor,figSize,figLine)
  elseif(otype=="framebuffer") then
    obj.load(otype)
  else
    obj.load(otype,val)
  end
  if(effect==1) then
    obj.effect()
  end
  if(ld_aspect>0) then
    cyl_w=obj.w*(1-ld_aspect)
  else
    cyl_w=obj.w
  end
  basesize = cyl_w/cyl_div
  clipW=obj.w/cyl_div
  if (cyl_dir==2) then
    rotbase = 180/cyl_div + cyl_rotshift
    rotdiff = 360/cyl_div
  else
    rotbase = 180*(cyl_div-1)/cyl_div + cyl_rotshift
    rotdiff = -360/cyl_div
  end
  
  if(ld_aspect<0) then
    cyl_h=obj.h*(1+ld_aspect)
  else
    cyl_h=obj.h
  end
  baseH = cyl_h/cyl_cut
  clipH = obj.h/cyl_cut
  
  if(kijun==1) then
    baseY = -0.5*(cyl_cut-1)*(cyl_space+shiftY)
    baseX = -0.5*(cyl_cut-1)*shiftX
    baseZ = -0.5*(cyl_cut-1)*shiftZ
    baseSpin = -0.5*(cyl_cut-1)*cyl_spin
    theta = math.pi*(cyl_div-2)/(2*cyl_div)
    baseR = basesize * math.tan(theta)/2 + cyl_r_adjust - 0.5*(cyl_cut-1)*shiftR
  elseif(kijun==2) then
    baseY = -(cyl_cut-1)*(cyl_space+shiftY)
    baseX = -(cyl_cut-1)*shiftX
    baseZ = -(cyl_cut-1)*shiftZ
    baseSpin = -(cyl_cut-1)*cyl_spin
    theta = math.pi*(cyl_div-2)/(2*cyl_div)
    baseR = basesize * math.tan(theta)/2 + cyl_r_adjust - (cyl_cut-1)*shiftR
  else
    baseY = 0
    baseX = 0
    baseZ = 0
    baseSpin = 0
    theta = math.pi*(cyl_div-2)/(2*cyl_div)
    baseR = basesize * math.tan(theta)/2 + cyl_r_adjust
  end
  
  for i=0,cyl_cut-1 do
    r = baseR + shiftR * i
    if(cyl_dir==2) then
      r = -r
    end
    py = baseY + (cyl_space+shiftY) * i
    diffX = baseX + shiftX * i
    diffZ = baseZ + shiftZ * i
    spinShift = baseSpin + cyl_spin * i
    for j=0,cyl_disp-1 do
      obj.setfont(fontName,fontSize,fontType)
      if(otype=="figure") then
        obj.load(otype,val,figColor,figSize,figLine)
      elseif(otype=="movie") then
        obj.load(otype,val,obj.time+ld_time)
      else
        obj.load(otype,val)
      end
      
      if(effect==1) then
        obj.effect()
      end
      divCenterX = -cyl_w/2 + basesize*( 0.5 + j )
      obj.aspect=ld_aspect
      rot = rotbase + spinShift + j * rotdiff
      sinY=math.sin(math.rad(rot))
      cosY=math.cos(math.rad(rot))
      if(cyl_dir==0) then
        rot=0
        px = -r * sinY - divCenterX
        pz = -r * cosY
      else
        px = -r * sinY - cosY * divCenterX
        pz = -r * cosY + sinY * divCenterX
      end
      obj.effect("Clipping","Top",clipH*i, "Bottom",clipH*(cyl_cut-1-i), "Left",clipW*j, "Right",clipW*(cyl_div-1-j))
      obj.draw(px+diffX,py,pz+diffZ,1,alpha,0,rot,0)
    end
  end
end


@CylinderMapping(Hori)
--track0:Slice,3,30,5
--track1:Disp#,0,30,5
--track2:RadiusAdj,-2000,2000,0
--track3:Spin,-3600,3600,0
--param:cyl_dir=1;effect=1;

cyl_div=math.floor(obj.track0)
cyl_disp=math.floor(obj.track1)
if(cyl_div<cyl_disp) then
  cyl_disp=cyl_div
end
cyl_r_adjust=obj.track2
cyl_rotshift=obj.track3
if(cyl_disp<=0) then
  obj.load("text","")
else

  obj.setfont(fontName,fontSize,fontType)
  if(otype=="figure") then
    obj.load(otype,val,figColor,figSize,figLine)
  elseif(otype=="framebuffer") then
    obj.load(otype)
  else
    obj.load(otype,val)
  end
  if(effect==1) then
    obj.effect()
  end
  if(ld_aspect<0) then
    cyl_h=obj.h*(1+ld_aspect)
  else
    cyl_h=obj.h
  end
  basesize = cyl_h/cyl_div
  clipH = obj.h/cyl_div
  rotbase = -180*(cyl_div-1)/cyl_div + cyl_rotshift
  rotdiff = 360/cyl_div

  if(ld_aspect>0) then
    cyl_w=obj.w*(1-ld_aspect)
  else
    cyl_w=obj.w
  end
  baseW = cyl_w/cyl_cut
  clipW=obj.w/cyl_cut
  if(cyl_dir==2) then
    shiftR = -shiftR
  end
  theta = math.pi*(cyl_div-2)/(2*cyl_div)
  if(kijun==1) then
    baseX = -0.5*(cyl_cut-1)*(cyl_space+shiftX)
    baseY = -0.5*(cyl_cut-1)*shiftY
    baseZ = -0.5*(cyl_cut-1)*shiftZ
    baseSpin = -0.5*(cyl_cut-1)*cyl_spin
    baseR = (basesize * math.tan(theta)/2 + cyl_r_adjust) - 0.5*(cyl_cut-1)*shiftR
  elseif(kijun==2) then
    if(cyl_dir==2) then
      baseX = 0
      baseY = 0
      baseZ = 0
      baseSpin = 0
      baseR = (basesize * math.tan(theta)/2 + cyl_r_adjust)
    else
      baseX = -(cyl_cut-1)*(cyl_space+shiftX)
      baseY = -(cyl_cut-1)*shiftY
      baseZ = -(cyl_cut-1)*shiftZ
      baseSpin = -(cyl_cut-1)*cyl_spin
      baseR = (basesize * math.tan(theta)/2 + cyl_r_adjust) - (cyl_cut-1)*shiftR
    end
  else
    if(cyl_dir==2) then
      baseX = -(cyl_cut-1)*(cyl_space+shiftX)
      baseY = -(cyl_cut-1)*shiftY
      baseZ = -(cyl_cut-1)*shiftZ
      baseSpin = -(cyl_cut-1)*cyl_spin
      baseR = (basesize * math.tan(theta)/2 + cyl_r_adjust) - (cyl_cut-1)*shiftR
    else
      baseX = 0
      baseY = 0
      baseZ = 0
      baseSpin = 0
      baseR = (basesize * math.tan(theta)/2 + cyl_r_adjust)
    end
  end
  
  for i=0,cyl_cut-1 do
    r = baseR + shiftR * i
    px = baseX + (cyl_space + shiftX) * i
    diffY = baseY + shiftY * i
    diffZ = baseZ + shiftZ * i
    spinShift = baseSpin + cyl_spin * i
    if(cyl_dir==2) then
      px = -px
      diffY = -diffY
      diffZ = -diffZ
      spinShift=-spinShift
    end
    for j=0,cyl_disp-1 do
      obj.setfont(fontName,fontSize,fontType)
      if(otype=="figure") then
        obj.load(otype,val,figColor,figSize,figLine)
      elseif(otype=="movie") then
        obj.load(otype,val,obj.time+ld_time)
      else
        obj.load(otype,val)
      end
      if(effect==1) then
        obj.effect()
      end
      divCenterY = -cyl_h/2 + basesize*( 0.5 + j )
      obj.aspect=ld_aspect
      rot = rotbase + spinShift + j * rotdiff
      sinX=math.sin(math.rad(rot))
      cosX=math.cos(math.rad(rot))
      if(cyl_dir==0) then
        ry=0
        rot=0
        py = r * sinX - divCenterY
        pz = -r * cosX
      elseif(cyl_dir==1) then
        ry=0
        py = r * sinX - divCenterY * cosX
        pz = -r * cosX - divCenterY * sinX
      else
        ry=180
        py = r * sinX - divCenterY * cosX
        pz = -r * cosX - divCenterY * sinX
      end
      obj.effect("Clipping","Left",clipW*i, "Right",clipW*(cyl_cut-1-i), "Top",clipH*j, "Bottom",clipH*(cyl_div-1-j))
      obj.draw(px,py+diffY,pz+diffZ,1,alpha,rot,ry,0)
    end
  end
end

