Hi, Justin D and others!
I’m experimenting with using Haxe for generating tools in BlackMagic Fusion (grafix FX software, also included in Davinci Resolve video editing sw.). What I want to accomplish is generating script code that programmatically can build complex vector graphics that could be mainpulated over time using Fusion’s animation capabilites, and rendering video output in the end.
Fusion internally uses lua for it’s tools (python is also an option but more of a workaround it seems), and there is two ways that I can accomplish working lua code:
-
Using Haxe for simple generation of custom .lua-compatible code-files.
I’ve tried this, and it works fine, as I just use Haxe logic for building a custom text file where I generate the .lua content. That means that the Haxe Lua target isn’t involved at all, I’m running in simple --interp mode. Quick, hacky and limited to my own “meta-programming”. -
Using actiual Haxe Lua target to generate the .lua code
(This is what I’m interested of here!) This means that I would mock the libraries included in the BlackMagic Fusion Lua environment, so that I could wire up the functionality in actual Haxe code, and compile it to Haxe generated Lua code that would run in Fusion.
Below is a minimal Fusion .lua code example showing the type of code that I would like to get as a result.
It clearly shows that a lot of functionality is set to the runtime “self”, like theFuRegisterClass
method, theWidth
andHeight
properties etc.
Is it doable to mock these, so that something like the code example below can be generated?
Jonas
----------------------------------------------------
-- BlackMagick Fusion/Davinci Resolve
-- Minimal test example for generating simple line graphic
-- .lua code, but named .fuse when used as tool in Fusion
----------------------------------------------------
FuRegisterClass("Minimal", CT_SourceTool, {
REGS_Name = "Minimal",
REGS_Category = "TestFuses",
})
function Create()
OutImage = self:AddOutput("Output", "Output", {
LINKID_DataType = "Image",
LINK_Main = 1,
})
end
function Process(req)
-- Standard set up for Creator tools
local realwidth = Width;
local realheight = Height;
-- We'll handle proxy ourselves
Width = Width / Scale
Height = Height / Scale
Scale = 1
-- Attributes for new images
local imgattrs = {
IMG_Document = self.Comp,
{ IMG_Channel = "Red", },
{ IMG_Channel = "Green", },
{ IMG_Channel = "Blue", },
{ IMG_Channel = "Alpha", },
IMG_Width = Width,
IMG_Height = Height,
IMG_XScale = XAspect,
IMG_YScale = YAspect,
IMAT_OriginalWidth = realwidth,
IMAT_OriginalHeight = realheight,
IMG_Quality = not req:IsQuick(),
IMG_MotionBlurQuality = not req:IsNoMotionBlur(),
}
-- Set up image
local img = Image(imgattrs)
local out = img:CopyOf()
local p = Pixel({R=0,G=0,B=0,A=0})
img:Fill(p) -- Clear the image so the next frame doesn't contain the previous one.
out:Fill(p)
-------------------------------------------------
local line = Shape()
line:MoveTo(0, 0)
line:LineTo(1, 1)
line = line:OutlineOfShape(0.01,"OLT_Solid")
local ic = ImageChannel(out, 8)
ic:ShapeFill(line)
local cs = ChannelStyle()
cs.Color = Pixel({R = 1, G = 0, B = 0, A = 1})
if self.Status == "OK" then
ic:PutToImage("CM_Merge", cs)
end
OutImage:Set(req, out)
end