0
$\begingroup$

To the material output node, for the displacement value I wish to add an nd array. Example given below to understand:

import numpy as np
nval=np.random.rand(1000,1000,3)
mat=bpy.data.materials["mymaterial"]
nodes=mat.node_tree.nodes
nodes['Material Output'].inputs['Displacement']=nval

This obviously throws error at the last step since nval is an ndarray. I know I can add image texure to the displacement map which is 3 dimensional RGB normal map. But I wish to add my own ndarray as displacement map to my material output. How can I do this using python script.

$\endgroup$
1
$\begingroup$

You can only connect a node output socket to a node input socket, it isn't just an array.

While it is possible to create custom pynodes and be able to add them to a cycles material tree, they aren't fully integrated, mainly they fail to update properly. You can find a pynode template in blender's text editor. The two main projects using pynodes are sverchok and animation nodes and you will find both of these use bpy.app.handlers to update their custom node trees.

You might find drivers to offer a better solution. It is possible to add custom functions to the driver namespace to give you more control.

You can add a driver to control any value that can be keyframed, right-click RMB a value and choose add driver, you can further edit drivers in the graph editor.

values with drivers

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.