I want to visualize a massive database, with each data point being a cube with a value expressed using a color intensity.
Each data point can have either positive or negative value, I thought I would use Emission shader to visualize the data. I would like to assign green color to a negative value, red to a positive, with the value itself being strength of the emission shader.
While I know how to import CSV data and create a cube for each datapoint, I couldn't find the way to color code the data or even create the shader. All the tutorials I found describe creating materials in BI, but not Cycles using nodes.
Here's some code I'm starting with (main source is Blender Sushi)
Code: Select all
import bpy import csv import math file = csv.reader(open('\\Documents and Settings\user\Desktop\data_for_blender.csv', newline=''), delimiter=',') numLines = 0 for row in enumerate(file): numLines = numLines +1 curRow =  for idx, row in enumerate(file): if idx<numLines: curRow=row #add cube bpy.ops.mesh.primitive_cube_add(view_align=False, enter_editmode=False, location=(0,0,0), rotation=(0,0,0)) #cursor location saved_location = bpy.context.scene.cursor_location.copy() bpy.context.scene.cursor_location = (0.0, 0.0, -1.0) bpy.ops.object.origin_set(type='ORIGIN_CURSOR') bpy.context.scene.cursor_location = saved_location #resize cubes bpy.ops.transform.resize(value=(0.5, 0.5, 0.5)) #move cubes #at this point cubes are just located along a line, but there will be other spatial organization later bpy.ops.transform.translate(value=(5, idx*2,0)) #create material/shader here #read value from the second column:= myValue= int(curRow) #absolute value for shader strength myabsValue= math.fabs(myValue) myColor='' #PSEUDOCODE #if myValue < 0: # myColor = 'green' #if myValue > 0: # myColor = 'red' #[... assign material with emission shader with myColor for color and myabsValue for emission strength ...]