2
$\begingroup$

I want to do an animation of a blender object which changes the color over time, in dependence of the temperature. Therefore zeffi already wrote a script which transforms different colormaps into blender. (Set color of Blender object based on external data (e. g. temperature) using a colormap)

Now I would like to create a node based material with a script, set the colormap to jet and when the temperature changes, I would like to change also the color.

Can someone post a little piece of script, how I can achieve this?

Thanks

$\endgroup$
3
  • $\begingroup$ do you have some kind of text file with the temperature over time? $\endgroup$
    – zeffii
    Commented Oct 29, 2015 at 17:08
  • $\begingroup$ related: blender.stackexchange.com/q/23436/47 , blender.stackexchange.com/a/5445/47 Scripting a node material is pretty well documented. and blender.stackexchange.com/questions/23882/… $\endgroup$
    – zeffii
    Commented Oct 29, 2015 at 17:15
  • $\begingroup$ This question is really 3 or 4 questions rolled into one, we encourage you to split problems up into separate concepts so they can be asked and answered separately. The scripting of materials, and material animation are definitely easy to find using the this site's search feature. The only part of this question that isn't readily found relates to the add-on you mention (which is mine so I feel some responsibility for answering questions about it: see below) . $\endgroup$
    – zeffii
    Commented Oct 30, 2015 at 8:07

2 Answers 2

1
$\begingroup$

I can answer one of your questions but you will need to download and install the add-on again if you haven't yet. The add-on now lets you access functionality via the script shown below.

  • This assumes a recent version of the octave_gradients add-on is available locally.

code for using the add-on inside a script:

import bpy
import addon_utils

addon_utils.enable("octave_gradients")

# add material, or reuse existing one
mymat = bpy.data.materials.get('lazy_cube')
if not mymat:
    mymat = bpy.data.materials.new('lazy_cube')
    mymat.use_nodes = True

nodes = mymat.node_tree.nodes

if not 'ColorRamp' in nodes:
    nodes.new(type="ShaderNodeValToRGB")    
ColorRamp = nodes['ColorRamp']

# reuse the Octave Gradient maker code, when calling from this context, 
# it will add a function called 'external_octave' to the driver_namespace
# this function doesn't care what context you are in, all it wants
# is a reference to the ColorRamp node, and a number between 0..13
bpy.ops.scene.gradient_pusher()
external_octave = bpy.app.driver_namespace['external_octave']

# force ramp theme
external_octave(ColorRamp, 12)  # jet=12

# hook the ColorRamp up to the DiffuseBSDF node.
DiffuseBSDF = nodes.get("Diffuse BSDF")
mymat.node_tree.links.new(ColorRamp.outputs[0], DiffuseBSDF.inputs[0])

What you should be able to solve on your own is how to get temperatures into a range of 0 to 1, so the color ramp can map them.

$\endgroup$
3
  • $\begingroup$ I have updated the readme on github.com/zeffii/octave_gradients to include comprehensive explanation of how to use it in the context of a script. $\endgroup$
    – zeffii
    Commented Oct 30, 2015 at 7:39
  • $\begingroup$ Thanks for your quick answer! When I try running your script, I get an Error: AttributeError: 'NoneType' object has no attribute 'inputs' Error: Python script fail, look in the console for now... It refers to this line: mymat.node_tree.links.new(ColorRamp.outputs[0], DiffuseBSDF.inputs[0]) Do you know why I get this failure message? $\endgroup$
    – qube13
    Commented Oct 30, 2015 at 16:31
  • $\begingroup$ nope, do this (to see if it works). start with an empty .blend file, add the script to the TextEditor and hit Run. Then go to the nodeview, materials view, and see if it created a material called 'lazy_cube' $\endgroup$
    – zeffii
    Commented Oct 31, 2015 at 13:33
0
$\begingroup$

Not that this is necessarily the answer you want, but it's very easy to change colors using vert colors (can be changed in a script very easily). In your noodle you can use vert colors to change what texture is shown. You could also probably have a material that uses alpha and lets the vert color show through your texture. Guessing.

$\endgroup$

You must log in to answer this question.

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