I read some article how to get the z-Depth values from the Viewer Node. So i created a scene with a camera and a Plane with distance z=2. Then i tried to get RGB values and also z-Depth with compositing Nodes.
Code from my Plugin:
bpy.context.scene.render.use_compositing = True bpy.context.scene.use_nodes = True tree = bpy.context.scene.node_tree links = tree.links for n in tree.nodes: tree.nodes.remove(n) rl = tree.nodes.new('CompositorNodeRLayers') viewer = tree.nodes.new('CompositorNodeViewer') viewer.use_alpha = False links.new(rl.outputs, viewer.inputs) # link Image output to Viewer input # render and get result bpy.ops.render.render() links.new(rl.outputs, viewer.inputs) # link Image output to Viewer input pixels = bpy.data.images['Viewer Node'].pixels print(pixels) arr = np.array(pixels[:]) arr = np.delete(arr, np.arange(3, arr.size, 4)) # delete alpha arr = arr.reshape((height,width,3)) # save z-depth links.new(rl.outputs, viewer.inputs) # link Image output to Viewer input bpy.ops.image.reload() pixelsZ = bpy.data.images['Viewer Node'].pixels print(pixelsZ) arrZ = np.array(pixels[:])[::4] # every 4th px
Both pixel arrays are the same. I tried this also manually and there it works perfectly. I thought about refreshing the image (in the image editor it refreshs the Viewer Node automatically when i change the node links), but even this didn't work.
Have anybody an idea how to fix this or what i'm doing wrong?
edit: I think i got the problem: I have to render again, after changing the nodes. is there an option to change and read the information without rerendering?