0
$\begingroup$

I was able to get CompositorNodeTree with this code in headless mode:

scene = bpy.data.scenes['Scene']
print([y.name for y in scene.node_tree.nodes])
print(type(scene.node_tree))

Now how to get ShaderNodeTree?

If I were able to get ShaderNodeTree, I would just do:

shader_tree = get_shader_tree()
image_node = shader_tree.nodes["Image Texture"]
image_node.image = bpy.data.images["my_image.png"]

but blender seems to not store shader tree any where in data, how can I do it?


Context:

I want to generate synthetic image dataset of 10 000+ images with different lighting. For lighting I used sun object and set HDRI with image texture connected to background nodes in Shader editor. (Like most of the tutorials suggest).

In order to automate the process of generation, I need to substitude HDRI image in Shader Editor.

Because I don't have powerfull GPU on my PC, generation takes more than a week to render all images. However I have a Ubuntu server with very powerful GPUs, and I want to move rendering process there, here is where the problems come up:

In order to update ShaderNodeTexImage, I need to have access to ShaderNodeTree, but without GUI it's not possible to switch context.area.ui_type to "ShaderNodeTree" because ui_type is not present in headless mode.

$\endgroup$
1
  • $\begingroup$ Thank you, these answers explained me, that each object has ShaderTree. $\endgroup$
    – Mr Davron
    Apr 15, 2021 at 10:03

1 Answer 1

0
$\begingroup$

I found out that each object has shader node_tree. In order to manipulate HDRI, I need to change Shader Tree of World object.

Shader Tree is attached to World object too, here is how I get Shader Node Tree of world object in headless mode:

bpy.data.worlds['World'].node_tree
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .