Skip to content

Instantly share code, notes, and snippets.

@AndrewHazelden
Created April 21, 2023 22:47
Show Gist options
  • Save AndrewHazelden/869b5de24e3d01e61236a83a186e50ec to your computer and use it in GitHub Desktop.
Save AndrewHazelden/869b5de24e3d01e61236a83a186e50ec to your computer and use it in GitHub Desktop.
A BMD Fusion Studio Fuse that probes an image for values
FuRegisterClass("TestModifier", CT_Modifier, {
REGS_Name = "TestModifier",
REGS_Category = "Modifiers",
REGS_OpDescription = "Test Modifier",
REGID_DataType = "Point",
REGID_InputDataType = "Point",
})
function Create()
InForeground = self:AddInput("Foreground", "Foreground", {
LINKID_DataType = "Image",
INPID_InputControl = "ImageControl",
LINK_Main = 1,
INP_Required = true,
})
InLocator = self:AddInput("Locator", "Locator", {
LINKID_DataType = "Point",
INPID_InputControl = "OffsetControl",
INPID_PreviewControl = "CrosshairControl",
LINK_Main = 2,
})
OutValue = self:AddOutput("Output", "Output", {
LINKID_DataType = "Point",
LINK_Main = 1,
})
end
function CheckRequest(req)
if (req:GetPri() == 0 ) then
req:ClearInputFlags( InForeground , REQF_PreCalc)
end
end
function Process(req)
local pos = Point(0.5, 0.5)
if not req:IsPreCalc() then
local location = InLocator:GetValue(req)
local img = InForeground:GetValue(req)
local x = location.X * img.Width
local y = location.Y * img.Height
x = math.min ((math.max(x,0)), img.Width-1)
y = math.min ((math.max(y,0)), img.Height-1)
local p = Pixel()
img:GetPixel(x,y, p)
pos = Point(p.R, p.G)
else
local location = InLocator:GetValue(req)
local img = InForeground:GetValue(req)
local x = location.X * img.Width
local y = location.Y * img.Height
x = math.min ((math.max(x,0)), img.Width-1)
y = math.min ((math.max(y,0)), img.Height-1)
local p = Pixel()
img:GetPixel(x,y, p)
pos = Point(p.R, p.G)
end
OutValue:Set(req, pos)
end
@AndrewHazelden
Copy link
Author

Code example by Jacob Danell. Released with permission under an open-source Apache-2 license.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment