Eyeon:Script/Reference/Applications/Fuse/Creating Fuses
From VFXPedia
Creating Fuses
Contents |
Structure of a Fuse
Fuse scripts are generally composed of a call to the FuRegisterClass function, to register our plugin, and several standard functions, called event functions. These are the Create event, the Process event, and the NotifyChanged event.
When Fusion is first launched, it will load and run all the Fuse files it can find, typically executing the FuRegisterClass call to tell Fusion what to call the new tool, what category to put it in, and other information.
When the Fuse tool is added to the composition the Create event function is triggered. This is used to setup the various inputs and outputs presented by the tool.
When Fusion requests an image from the tool, it will pass an object called a 'request' to the Process event function. This contains the meat of the tool - all of the code which performs the actual operation on the image(s).
The above three events are required in all Fuse tools. In addition, an optional DoNotifyChanged event function will be executed everytime one of the tools controls changes. This is used in cases where a change to one control might disable or automatically set another control in the tool. If present, the NotifyChanged event will be triggered before the Process event.
FuRegisterClass Function
The FuRegisterClass call describes the Fuse in a way that Fusion can recognize. This section tells Fusion where the fuse tool should appear in the Tool menus, what the tools name and abbreviation are, and other pertinent details required to make the tool available to the artist. It is executed when Fusion starts up.
This section should contain a single function call to FuRegisterClass(). The FuRegisterClass function requires three arguments. The first sets the tools name, the second sets the tools type, as defined in Fusion's internal registry, and the last argument is a table containing attributes which define the tools name, icon and other particulars.
The following example shows the Class Registry for a sample tool called GainTool which will appear in the Tools/Script category.
FuRegisterClass("GainTool", CT_Tool, { REGS_Category = "Script", REGS_OpIconString = "Gn", REGS_OpDescription = "Gain Tool", REG_OpNoMask = true, REG_NoBlendCtrls = true, REG_NoObjMatCtrls = true, REG_NoMotionBlurCtrls = true, })
See the Fuse tool reference for a complete description of the options and attributes available to the FuRegisterClass function.
Create Event
The create function is run when the Fuse tool is added to the composition, or a composition containing that fuse tool is loaded. It describes the controls presented by the tools control window, and the inputs and outputs shown on the tools tile in the flow. The Create function takes no arguments.
The following example shows the Create function for the Gain tool described above. It presents a single slider named 'Gain' in the control window, and the tool has one image input and one image output on it's tool tile.
function Create() InGain = self:AddInput("Gain", "Gain", { INPID_InputControl = "SliderControl", INP_Default = 1.0, }) InImage = self:AddInput("Input", "Input", { LINKID_DataType = "Image", LINK_Main = 1, }) OutImage = self:AddOutput("Output", "Output", { LINKID_DataType = "Image", LINK_Main = 1, }) end
Process Event
The Process event function is executed whenever Fusion asks the fuse tool to render a frame. Fusion's renderer will pass the Process function a single argument, an object called the Request. This argument contains all the information the tool needs to know about the current render environment.
The following example also comes from the GainTool used as an example above. It assigns the values of the tools various controls to local variables, then runs a function that applies a change to every pixel in the image, then finally sets the resulting image to the fuse tools output.
function Process(req) local img = InImage:GetValue(req) local gain = InGain:GetValue(req).Value local out = Image({IMG_Like = img}) out:ProcessPixels(0,0, img.Width, img.Height, img, function(x,y,p) p.R = p.R * gain p.G = p.G * gain p.B = p.B * gain return p end) OutImage:Set(req, out) end
To learn more about creating Fuses, consult the Tutorials, the Fuse Reference Manual, and the Example Fuses.