Jump to: Board index » General » Fusion

Animate Parameter from External Data for Every Frame?

Learn about 3D compositing, animation, broadcast design and VFX workflows.
  • Author
  • Message
Offline

bentraje

  • Posts: 59
  • Joined: Mon Feb 24, 2020 5:44 pm
  • Real Name: Ben Traje

Animate Parameter from External Data for Every Frame?

PostWed Aug 19, 2020 11:12 am

Hi,

Is there a way to animate the parameter from external data for every frame?
For instance, with this LUA data ("sample_data.txt")
Code: Select all
{
   1= 10,
   2= 30,
   3= 40,
}


Assuming to affect size of a transform node, the expected result is to have
the size at 10 in Frame 10,
the size at 30 in Frame 2, and so forth.

On Sourcing External Data
I guess this is the code:
Code: Select all
assert(io.open(comp:MapPath("D:/sample_data.txt"), "r")):read("*all")


My problem is I don't know how to 1) assign it to a variable for accessing and eventually 2) fetch a corresponding number

In Python, this can be done like:
Code: Select all
# Assigning it in the variable
import json
with open("D:\sample_data.json", "r") as read_file:
    data = json.load(read_file)

transform_node = get_transform_node()
frame_number = get_frame_number()

# Fetching it and using it
transform_node.size = data[frame_number]



On Executing Every Frame
I guess this can be done through the Frame Render Script?

Is there a solution for this?
Any inputs are appreciated.

Thanks

P.S. If this can be done entirely done in Python, that is most preferred.
Offline
User avatar

TheBloke

  • Posts: 611
  • Joined: Sat Nov 02, 2019 11:49 pm
  • Real Name: Tom Jobbins

Re: Animate Parameter from External Data for Every Frame?

PostWed Aug 19, 2020 9:11 pm

As a general point, for more advanced scripting stuff I'd recommend browsing the Fusion 8 Scripting Guide if you haven't already.

I've heard that it might be possible to execute Python code in Frame Render Scripts, but I was unable to do so in my own testing. I know you can do either of:
Code: Select all
comp:Execute("!Py: print('Hello from Python')")
comp:RunScript("/path/to/pythonscript.py")
But I'm not sure if it's possible to write Python code directly in a Frame Render Script, and thus have the same scope as the Lua script would. Unfortunately it didn't work to prepend the Frame Render script with !Py:

Just for fun I did some playing about with JSON in Lua. Firstly I saved the following JSON file:
Code: Select all
[
  [1,10 ],
  [2,30 ],
  [3,40 ]
]
Then I downloaded the Lua module jsonrocks from its Github repository and installed it in the Modules/Lua directory of Fusion Studio. On macOS that's:
Code: Select all
Fusion Studio:
/Library/Application Support/Blackmagic Design/Fusion/Modules/Lua
DaVinci Resolve:
/Library/Application Support/Blackmagic Design/DaVinci Resolve/Fusion/Modules/Lua
You'll need to Google for Windows, but it's probably something along the lines of:
Code: Select all
%APPDATA%\Blackmagic Design\DaVinci Resolve\Fusion\Modules\Lua
I put the file and directory I linked above in that folder:
Code: Select all
lunajson.lua
lunajson/
And then I ran the following code in a Background node's Frame Render Script:
Code: Select all
lunajson = require 'lunajson'
file = io.open("/Users/tomj/sample_data.json", "r"):read("*all")
jsonparse = lunajson.decode ( file )
for k, v in ipairs(jsonparse) do
  if v[1] == comp.CurrentTime then TopLeftAlpha = v[2] end
end
And it worked as expected.

Just a quick hack/demo, probably much better ways to do it. But that did function OK.
Resolve Studio 17.1.1.9 and Fusion Studio 17.1.1 on macOS 11.4

Hackintosh:: X299, Intel i9-10980XE @ 4.6 Ghz, 128GB RAM, AMD 6900XT 16GB
Monitors: 1 x 3840x2160 (4K) & 3 x 1920x1200
Audio: Behringer UMC404HD
Blackmagic Speed Editor
Offline
User avatar

TheBloke

  • Posts: 611
  • Joined: Sat Nov 02, 2019 11:49 pm
  • Real Name: Tom Jobbins

Re: Animate Parameter from External Data for Every Frame?

PostWed Aug 19, 2020 9:20 pm

I should add that for a far more comprehensive and knowledgeable look at reading and writing data from Render scripts, check out Andrew Hazelden's excellent recent post on We Suck Less, describing a pair of scripts that read and write node data:

Node Editing

Andrew Hazelden wrote:For this experiment, I started using a CSV (comma-separated value) exporting technique then decided I should make the export more intelligent by naming each channel of data. The end result is a pair of intool scripts that read and write out Lua table structures, which are a bit like a JSON file but are friendlier for use inside of Fusion's expressions and intool scripting fields.


I'm sure you can take portions of these scripts and do everything you need with minimal effort, and without needing to install any Lua libraries.
Resolve Studio 17.1.1.9 and Fusion Studio 17.1.1 on macOS 11.4

Hackintosh:: X299, Intel i9-10980XE @ 4.6 Ghz, 128GB RAM, AMD 6900XT 16GB
Monitors: 1 x 3840x2160 (4K) & 3 x 1920x1200
Audio: Behringer UMC404HD
Blackmagic Speed Editor
Offline

bentraje

  • Posts: 59
  • Joined: Mon Feb 24, 2020 5:44 pm
  • Real Name: Ben Traje

Re: Animate Parameter from External Data for Every Frame?

PostThu May 06, 2021 3:38 pm

Hi @TheBloke

I'm terrible sorry for the late response. I totally missed your response (no excuse).

That said, I can confirm after re-performing your detailed write up, it works as expected.

Just some notes:
1) JSON format seems to be different with LUA and Python.
2) The feedback on reading the external file is live through the viewer but the UI (the slider doesn't update). It somehow stays at the value it was initially set.

I haven't tried the CSV method you linked above, but the JSON workflow works so far for my use case.

Thanks for the response and have a great day ahead!

Return to Fusion

Who is online

Users browsing this forum: No registered users and 15 guests