Eyeon Talk:Script/Reference/Applications/Fuse/Classes/Input/SetSource

From VFXPedia

< Eyeon Talk:Script | Reference/Applications/Fuse
Revision as of 17:16, 13 February 2012 by Stuart (Talk | contribs)
(diff) ← Older revision | Current revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The example fuse doesn't work. Here's a version that runs, but even this one will cause Fusion to re-render the tool over and over again (of course it will - the inputs get modified, causing the tool to need to render again, and that render will modify the inputs, causing the tool to need to render again, and so on). SetSource works best when called from DoNotifyChanged.

Is there a way to stop this updating cycle when SetSource is called from Process()? --Tilt 10:42, 13 February 2012 (EST)
Only manually - check if you're going to change the value (by comparing what you want to set it to, with what was already in the request), and only SetSource() if you are. Stuart 12:16, 13 February 2012 (EST)
FuRegisterClass("MinFinder", CT_Tool, {
	REGS_Category = "Color",
	REGS_OpIconString = "MF",
	REGS_OpDescription = "Minimum Value Finder",
	REG_OpNoMask = true,
	REG_NoBlendCtrls = false,
	REG_NoObjMatCtrls = true,
	REG_NoMotionBlurCtrls = true,
	})
 
function Create()
	InRed = self:AddInput("Red", "Red", {
		INPID_InputControl = "SliderControl",
		INP_Default = 1.0,
		INP_DoNotifyChanged = true,
		INP_External = false
		})
	InGreen = self:AddInput("Green", "Green", {
		INPID_InputControl = "SliderControl",
		INP_Default = 1.0,
		INP_DoNotifyChanged = true,
		INP_External = false
		})
	InBlue = self:AddInput("Blue", "Blue", {
		INPID_InputControl = "SliderControl",
		INP_Default = 1.0,
		INP_DoNotifyChanged = true,
		INP_External = false,
		})
	InAlpha = self:AddInput("Alpha", "Alpha", {
		INPID_InputControl = "SliderControl",
		INP_Default = 1.0,
		INP_DoNotifyChanged = true,
		INP_External = false
		})
		
	InImage1 = self:AddInput("Input 1", "Input1", {
		LINKID_DataType = "Image",
		LINK_Main = 1,
		})
	OutImage = self:AddOutput("Output", "Output", {
		LINKID_DataType = "Image",
		LINK_Main = 1,
		})				
end
 
 
function Process(req) 
 
	gLow = 100
	bLow = 100
	rLow = 100
	aLow = 100
 
	local img1 = InImage1:GetValue(req)
	
	out = Image({IMG_Like = img1})
 
	function func(x,y,p1) -- div	
		if p1.G < gLow then
			gLow = p1.G
		end
		if p1.R < rLow then
			rLow = p1.R
		end
		if p1.B < bLow then
			bLow = p1.B
		end
		if p1.A < aLow then
			aLow = p1.A
		end
		return p1
	end
	
	out:ProcessPixels(0,0, img1.Width, img1.Height, img1, func)
	
	InRed:SetSource(Number(rLow),0)
	InBlue:SetSource(Number(bLow),0)
	InGreen:SetSource(Number(gLow),0)
	InAlpha:SetSource(Number(aLow),0)
	
	OutImage:Set(req, out)
end