|
|||||||||||||||||
In your script, you defined three different axes, which will be called using the CASE expression. The position of the vertex in each axis will be modified, using a sine expression. This expression has another parameter, center, which is the center position of the object. This allows you to use this value as part of the formula. In Listing 18.10, center defines where the deformation is zero, because when p.z is equal to center.z, sine will evaluate zero.
Creating Render Effects Render effects can also be created through MAXScript. They can access the rendered image and the rendered channels, manipulate them, and output an image at the end. This type of script works exactly like a modifier plug-in, but the event that triggers the action is on apply bmp, where bmp is the bitmap containing the rendered image. This way, you can manipulate the image and output another bitmap with the adjusted values. You will now make a script that shifts the Hue of an image. This script will also have a nice UI, to help the user understand what is happening.
Start a new script and type the code shown in Listing 18.11, or from the CD open the file plugin_hue.ms.
LISTING 18.11: The Change Hue plug-in script (plugin_hue.ms) plugin renderEffect Hue_control name:”Change Hue” classID:#(0x31705a72, 0x4f48bbc7) ( parameters pblock rollout:params ( On_Off type:#boolean default:true animatable:true Hue type:#integer default:0 animatable:true ui:(h_level,h_slid) on Hue set value do ( if Hue > 127 then Hue = 127 if Hue < (-127) then Hue = (-127) ) ) rollout params “Hue Settings” ( local bmp1 = bitmap 255 4 local bmp2 = bitmap 255 4 checkbox a_only “Affect Background” checked:false label c_mark2 “|” pos:[160,21] label c_mark3 “|” pos:[160,34] label c_mark1 “|” pos:[160,26] bitmap normal_hue bitmap:bmp1 pos:[33,25] bitmap adjusted_hue bitmap:bmp2 pos:[33,36] label h_lbl “Hue” align:#left pos:[20,53] spinner h_level range:[-127,127,0] type:#integer fieldwidth:50 \ pos:[75,52] slider h_slid range:[-127,127,0] type:#integer label rnd “Rendering:” align:#left progressbar prog align:#center width:300 button reset_h “Reset” pos:[250,50] fn make_ramp val_h = ( local start_clr local color_ramp = #() start_clr = color 255 0 0 start_hue = start_clr.hue + 127 if (start_hue + val_h) > 255 then start_hue += (val_h - 255) else start_hue += val_h if start_hue > 255 then start_hue -= 255 if start_hue > 255 then start_hue -= 255 start_clr.hue = start_hue for i in 1 to 255 do ( mid_clr = copy start_clr start_hue = mid_clr.hue if (start_hue + i) > 255 then start_hue += (i - 255) else start_hue += i if start_hue > 255 then start_hue -= 255 if start_hue > 255 then start_hue -= 255 mid_clr.hue = start_hue color_ramp[i] = mid_clr ) return color_ramp ) fn upd_ramp = ( bmp2 = bitmap 255 4 clr = make_ramp h_level.value for i in 1 to 4 do setpixels bmp2 [0,i-1] clr adjusted_hue.bitmap = bmp2 ) on reset_h pressed do (h_level.value = 0; upd_ramp() ) on h_level changed val do upd_ramp() on h_slid changed val do upd_ramp() on params open do ( bmp1 = bitmap 255 4 bmp2 = bitmap 255 4 clr = make_ramp 0 for i in 1 to 4 do setpixels bmp1 [0,i-1] clr clr = make_ramp h_level.value for i in 1 to 4 do setpixels bmp2 [0,i-1] clr adjusted_hue.bitmap = bmp2 normal_hue.bitmap = bmp1 ) ) on apply bmp do ( if On_Off then ( for h=0 to bmp.height do ( local sline = getPixels bmp [0,h] bmp.width for w = 1 to sline.count do ( if params.a_only.checked then ( calc = true ) else ( if sline[w].alpha == 0 then calc = false else calc = true ) if calc then ( slineh = sline[w].hue + Hue if slineh > 255 then slineh = (slineh - 255) else if slineh < 0 then slineh = 255 + slineh sline[w].hue = slineh ) ) params.prog.value = h*100/bmp.height setPixels bmp [0,h] sline ) params.prog.value = 0 ) ) ) Evaluate this script and add the Change Hue effect in the Rendering Effects dialog box. Notice that changing the spinner or the slider will update the bitmaps in the UI, helping us visualize the Hue change, as seen in Figure 18.12. These bitmaps are controlled by the functions make_ramp and upd_ramp.
The script action is in on apply bmp. First, it checks to see if the effect is on. Then it checks to see if the alpha channel should or not be calculated. A temporary variable is created to hold the current hue value. This value will be modified by the spinner value, which will be checked, because it cannot be bigger than 255 or smaller than 0. At the end, the corrected value will be written to the original bmp. You also used a progressbar UI item, which is updated as the bitmap is processed. Similarly to the RENDER() command, if you want to work with rendered channels, you need to call a specific event to create them. This event is on channelsrequired do channel_array, where channel_array is the same channel array you specify in the RENDER() command. This event needs to be called before the on apply bmp event, so you can use these channels in your process. Take some time now and rewrite the Render Channels script you made in Chapter 16 as a Render Effect plug-in script. It will work similarly to the File Output render effect, but youll be able to output all channels, instead of only the three channels that are output through File Output.
© 2000, Frol (selection, edition, publication) |
|||||||||||||||||
|