Coding the CiF

Got a bit side tracked with cobbling together a video for the Cameron interview over the weekend but here’s an update on the CiF graph.

I had to learn python for this, but I grew up programmatically speaking in the C and perl world so when I say “learn”, I really mean “find out how things I already know are done in” python. And I have to say it was fun – just being able to slap data types together without having to worry about pointers or references, and get at the stored data without heavy table knocking and ouiji boarding was refreshing.

So to cut a long story short, I now have this:

1 import bpy
3 vertices= [(-.1,.1,0),(.1,.1,0),(.1,-.1,0),(-.1,-.1,0),(-.1,.1,.2),(.1,.1,.2),(.1,-.1,.2),(-.1,-.1,.2)]
4 faces =[(0,1,2,3),(0,4,5,1),(2,6,7,3),(0,4,7,3),(1,5,6,2),(4,5,6,7)]
5 mesh ="Roachclip")
6 object ="Roachclip",mesh)
7 object.location = (-7.75,-8.10,0)
8 object.show_name = True
12 mesh.from_pydata(vertices, [], faces)
13 mesh.update()

which gives me this:

A small cube called Roachclip

If you know a bit of programming it should be easy enough to read what’s going on, but specific to Blender is the way it draws shapes. I could have used a stock shape, but because I wanted to control the size of the cube from the outset, I have to specify to Blender how to draw it, starting with points in 3D space (the numbers in line 3), and how to then join up the points to make filled or empty faces, (the numbers in line 4).

Which is all groovey, except when Blender counts to 10 it starts at zero and stops at 9 (cmon quickly now, what’s the number 5 in Blender?), and, describing how to join up the vertices to draw a face is a bit, well, “don’t cross the beams!” like.

Luckily enough for placing, Blender’s co-ordinates system matches the data used by

How Blender axis map to's scatter plot

the crossing point of all the axis have co-ordinates of 0,0,0. The last zero is the height axis which I’m planning to use to show how morally toxic, or not, each “person” on the chart is. So with a little formatting, with the code above, I can pass in each name and data and get a cube named after the owner on a specific spot in the chart.