I don’t realy know all reasons that lead to creation of python imbuf API, but python based effects was mentioned as possible use case. This is in line with my interest, so I started to work on this concept.
I am trying to create solution, that will be integrated in blender as much as possible, in order to benefit from implemented functionality(UI, data animation, data inputs).
There has been criticism on this feature due to fact, that python is slow, when processing data. Obviously we want to use python mainly as template language, calling functions of modules that will process images quickly such as SciPy, Pillow, and Blender’s own Py_Imbuf
following video shows possible usefulness and speed(debug build):
I tried to use Pillow also, but that resulted in ticket on their tracker(cannot import name '_imaging' from 'PIL' · Issue #3342 · python-pillow/Pillow · GitHub)…
Python effects concept
C side
Data storage:
Because concept of this effect is very universal, the biggest problem probably is, how to define & store effectdata.
I don’t know if there is, or can be flexible DNA structure, that can hold any amount of data of any type.
Actually effectdata itself almost does this because it can hold number of different types:
if (seq->effectdata) {
switch (seq->type) {
case SEQ_TYPE_COLOR:
writestruct(wd, DATA, SolidColorVars, 1, seq->effectdata);
break;
...
Therefore we can have array(or list) of properties along with identifiers without any problems with data storage.
This will require us to
- explicitly specify, which structures can be used with PYFX
- have constructor, getter, setter to access properties
- register prop as RNA prop if that’s possible. Or leave prop handling on python side - all callbacks are on python side by design.
Identification:
If I imagine effect addon to be one file, we can store checksum of that file in effectdata. On python side we can compare that checksum to list of checksums(past versions), so we don’t accidentaly try to handle fx sequence, that doesn’t belong to us. This way collisions can be detected during addon load and treated.
Rendering:
We call function, that is registered for rendering.
- in case the effect is generator, we will pass only effectdata and relative / absolute frame position
- in case the effect is doing processing, we will pass input images, effectdata and relative / absolute frame position
Cache:
Effect may use number of static images(same for multiple frames), that have to be composited before outputing final image. Cache implementation either in Imbuf API, or on python side(addon class providing storage) should be considered. This can improve performance significantly in some cases.
Return data:
After rendering image, other useful data can be returned, to improve UI.
For example lack of existance of multiline text box in blender can be replaced by effect acting as text box itself. Instead of rendering lines, we can render character by character and returning position of each letter.
Editing of text can be handled directly in preview area by modal operator supplied with effect.
Effect registration:
I have no idea how this works. I find embedded python documentation on how to deal with namespaces, well, non existant
But in principle, we are doing this already in one form or another.
Python side
Each effect is addon, that provides
- rendering function
- panel & UI stuff
- operators
- property handlers
Most details depends on C side implementation
Sci-fi
Users are complaining about compositor implementation in a way, that compositor in other applications a is perfect for creating effect templates. If compositor in blender was built to process 2D images effectively, I would agree and try to create solution using compositor, but afaik, this is not the case.
However, as I said, we want to use python mainly as template language.
I don’t know how much is node editor bound to scene, and how hard it would be to parse python code to represent it as nodes, but it should be possible.
If you look at code for my text box demo I used bunch of offsets, string and other than that just image functions.
I mean I can imagine for loop node, but worst case, parser would say sorry, you can not edit this in node editor…
Best(and easiest) case would probably be start with node editor and save as python code / new addon.