← All ideas
  • Published 15 Oct 2024

Data-driven blender architecture.

Everything in blender should be data-first. You change any data in python, the UI reacts to it.

At the moment, a lot of data can only be changed through the UI operators, which makes it very difficult to automate the creation of scenes, models, and renders.

33.3%

Development Status: Open

Upvote 1 Downvote 2
iperov
15 Oct 2024

6 Comments

chris.lend

do you have examples for this. The python API allows you to change everything afaik

iperov Author

At the moment, Python APIs are mostly UI operators. You change data through the UI. For example you can't add a Modifier from the data, you have to make the object active in the UI context, then call the UI operator to add the modifier

bpy.ops.object.modifier_add

In a data-driven architecture, data is primary, and separate from the View/ViewModel, I'm talking about MVVM. You manipulate all the data in the “blend_data” tree directly from the programming language. In this mode, you don't know how the data is displayed at all. BlenderUI is just one way of displaying the data. Data can also be displayed by sending it to the Cycles Renderer.

But it is also worth adding “Immutable Data Parallel” to the MVVM paradigm to maximize flexibility, code transparency, increase performance and reduce bugs. View/ViewModel is subscribed to data change events. When data changes, e.g. the list of modifiers in the object has changed, View/ViewModel receives the event and gets the latest version of immutable data containing all information about modifiers.

This is just an example, of course, research is needed to apply it directly to Blender.

Maybe you could start discussing this with the developers?

chris.lend

running operators is possible, but it's better to do e.g.

bpy.context.active_object.modifiers.new(name="test", type="DECIMATE")

that way you don't need to use the GUI.

iperov Author

it's the same thing. Contexts, active objects, etc.

what it should look like:

mod = data.objects['Cube'].modifiers.new(..., type='PARTCLE_SYSTEM')
mod.particle_system.settings. ... = 
Lauloque

What do you mean by "don't need to use the GUI" exactly? Haven't tried on Blender CLI in background mode, but you absolutely can set the selected and active objects in full python "without needing the GUI"

chris.lend

yeah but what you are writing is possible so I am not sure what you are getting at. Just that it is bpy.data.objects...