Created
April 21, 2023 22:47
-
-
Save AndrewHazelden/869b5de24e3d01e61236a83a186e50ec to your computer and use it in GitHub Desktop.
A BMD Fusion Studio Fuse that probes an image for values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Code example by Jacob Danell. Released with permission under an open-source Apache-2 license.