---------------------------------------
--ChannelSaver RenderEffect
--Version 0.1 
--Started: 2/7/2000
--Edited:  2/7/2000
--by Borislav Petrov
--http.//gfxcentral.com/bobo/
---------------------------------------

plugin RenderEffect ChannelSaver name:"ChannelSaver"
classID:#(0xb816a681, 0x531ab96d)
(

rollout sc_roll "ChannelSaver"
(
group "Options"
(
button get_out_path "Out Path" align:#left across:2 width:60 height:18
edittext out_path text:(getDir #image) align:#right fieldwidth:232
edittext out_name " Base Name" text:"channels"
spinner last_layer "Export Layers Up To" range:[1,999,1] type:#integer fieldwidth:40
)

on get_out_path pressed do 
(
new_path = getSavePath ()
if new_path != undefined then out_path.text = new_path
)

group "Channels"
(
checkbutton use_Zdepth "ZDepth Channel" align:#left width:146 across:2 highlightcolor:(color 200 255 200)
checkbutton use_matid "MatID Channel" align:#right width:146 highlightcolor:(color 200 255 200)
checkbutton use_objectID "ObjectID Channel" align:#left width:146 across:2 highlightcolor:(color 200 255 200)
checkbutton use_UV "UV Coords Channel" align:#right width:146 highlightcolor:(color 200 255 200)
checkbutton use_normal "Normal Channel" align:#left width:146 across:2 highlightcolor:(color 200 255 200)
checkbutton use_unclamped "Unclamped Channel" align:#right width:146 highlightcolor:(color 200 255 200)
checkbutton use_coverage "Coverage Channel" align:#left width:146 across:2 highlightcolor:(color 200 255 200)
checkbutton use_node "Node Channel" align:#right width:146 highlightcolor:(color 200 255 200)
checkbutton use_transp "Shader Alpha Channel" align:#left width:146 across:2 highlightcolor:(color 200 255 200)
checkbutton use_weight "Weight Channel" align:#right width:146 highlightcolor:(color 200 255 200)
checkbutton use_velmag "Velocity Magnitude" align:#left width:146 across:2 highlightcolor:(color 200 255 200) \
tooltip:"Pixel Colors represent Velocity Magnitude (Speed)"
checkbutton use_velangle "Velocity Angle" align:#right width:146  highlightcolor:(color 200 255 200) \
tooltip:"Pixel Colors represent Velocity Vector Direction, Black = 0 deg., Mid.Grey = 180 deg., White = 360 deg."
)

group "About"
(
label about01 "ChannelSaver RenderEffect"
label about02 "Version 0.1 - 2/7/2000"
label about03 "by Borislav Petrov"
label about04 "http://gfxcentral.com/bobo/"
)

)

on channelsRequired do 
(
req_channels = #()
if sc_roll.use_Zdepth.checked then append req_channels #zdepth
if sc_roll.use_matid.checked then append req_channels #matid
if sc_roll.use_objectid.checked then append req_channels #objectid
if sc_roll.use_uv.checked then append req_channels #uvcoords
if sc_roll.use_normal.checked then append req_channels #normal
if sc_roll.use_unclamped.checked then append req_channels #unclamped
if sc_roll.use_coverage.checked then append req_channels #coverage
if sc_roll.use_node.checked then append req_channels #node
if sc_roll.use_transp.checked then append req_channels #shaderTransparency
if sc_roll.use_weight.checked then append req_channels #weight
if sc_roll.use_velmag.checked or sc_roll.use_velangle.checked then append req_channels #velocity
req_channels
)


on apply image_file do
(

fn null_return cnt =
(
local dig1
if cnt<10 then dig1="000"
if cnt<100 and cnt>9 then dig1="00"
if cnt<1000 and cnt>99 then dig1="0"
if cnt<10000 and cnt>999 then dig1=""
dig1
)

c_time = ((currentTime as integer/ TicksPerFrame))
current_time = (null_return c_time) + c_time as string

for l = 1 to sc_roll.last_layer.value do
(

if sc_roll.use_zdepth.checked then
(
out_path = sc_roll.out_path.text+"\\"+ sc_roll.out_name.text + "_zdepth_"+ "L"+l as string+ "_"+ current_time  +".tga" 
out_bmp = getchannelasmask image_file #zdepth filename:out_path layer:l
save out_bmp
close out_bmp
)

if sc_roll.use_matid.checked then
(
out_path = sc_roll.out_path.text+"\\"+ sc_roll.out_name.text + "_matid_"+ "L"+l as string+ "_"+ current_time  +".tga" 
out_bmp = getchannelasmask image_file #matid filename:out_path layer:l
save out_bmp
close out_bmp
)

if sc_roll.use_objectID.checked then
(
out_path = sc_roll.out_path.text+"\\"+ sc_roll.out_name.text + "_objectid_"+ "L"+l as string+ "_"+ current_time  +".tga" 
out_bmp = getchannelasmask image_file #objectid filename:out_path layer:l
save out_bmp
close out_bmp
)

if sc_roll.use_uv.checked then
(
out_path = sc_roll.out_path.text+"\\"+ sc_roll.out_name.text + "_uv_"+ "L"+l as string+ "_"+ current_time  +".tga" 
out_bmp = getchannelasmask image_file #uvcoords filename:out_path layer:l
save out_bmp
close out_bmp
)

if sc_roll.use_normal.checked then
(
out_path = sc_roll.out_path.text+"\\"+ sc_roll.out_name.text + "_normal_"+ "L"+l as string+ "_"+ current_time  +".tga" 
out_bmp = getchannelasmask image_file #normal filename:out_path layer:l
save out_bmp
close out_bmp
)

if sc_roll.use_unclamped.checked then
(
out_path = sc_roll.out_path.text+"\\"+ sc_roll.out_name.text + "_unclamped_"+ "L"+l as string+ "_"+ current_time  +".tga" 
out_bmp = getchannelasmask image_file #unclamped filename:out_path layer:l
save out_bmp
close out_bmp
)

if sc_roll.use_coverage.checked then
(
out_path = sc_roll.out_path.text+"\\"+ sc_roll.out_name.text + "_coverage_"+ "L"+l as string+ "_"+ current_time  +".tga" 
out_bmp = getchannelasmask image_file #coverage filename:out_path layer:l
save out_bmp
close out_bmp
)


if sc_roll.use_node.checked then
(
out_path = sc_roll.out_path.text+"\\"+ sc_roll.out_name.text + "_node_"+ "L"+l as string+ "_"+ current_time  +".tga" 
out_bmp = getchannelasmask image_file #node filename:out_path layer:l
save out_bmp
close out_bmp
)

if sc_roll.use_transp.checked then
(
out_path = sc_roll.out_path.text+"\\"+ sc_roll.out_name.text + "_shaderalpha_"+ "L"+l as string+ "_"+ current_time  +".tga" 
out_bmp = getchannelasmask image_file #shaderTransparency filename:out_path layer:l
save out_bmp
close out_bmp
)

if sc_roll.use_velmag.checked then
(
out_path = sc_roll.out_path.text+"\\"+ sc_roll.out_name.text + "_vel_magnitude_"+ "L"+l as string+ "_"+ current_time  +".tga" 
out_bmp = getchannelasmask image_file #velocity filename:out_path layer:l velocity:#magnitude
save out_bmp
close out_bmp
)

if sc_roll.use_velangle.checked then
(
out_path = sc_roll.out_path.text+"\\"+ sc_roll.out_name.text + "_vel_angle_"+ "L"+l as string+ "_"+ current_time  +".tga" 

out_bmp = getchannelasmask image_file #velocity filename:out_path layer:l velocity:#angle
save out_bmp
close out_bmp
)


if sc_roll.use_weight.checked then
(
out_path = sc_roll.out_path.text+"\\"+ sc_roll.out_name.text + "_weight_"+ "L"+l as string+ "_"+ current_time  +".tga" 
out_bmp = getchannelasmask image_file #weight filename:out_path layer:l
save out_bmp
close out_bmp
)



)--end i loop

)--end apply
)--end script