Worldspace 3d checkerboard texturing of blender objects created from within Python.

You probably read the title and said out loud something along the lines of “What?”

Click here and look at the pictures. This isn’t the best example but its the one I could find that has pictures. Imagine the blender 3D workspace was filled with a 3D checkerboard of white/black. This checkerboard was static relative to the origin, but not visible to the user directly. I want objects to be textured as if they were “carved out” of this 3D checkerboard, and the textures to change when the objects are rotated/transformed/scaled.

I don’t know if what Im after is actually possible, but hopefully someone can shed some light on that subject.

I’ve had limited success in setting face colors programmatically from python, by setting up materials of solid colors and toggling back and forth between them. This doesn’t actually always guarantee me a checkerboard pattern and doesn’t seem to reliably give me the same pattern each time:

def run(origin):    # Create two materials
    black ='Black')
    black.diffuse_color = (0,0,0)
    white ='White')
    white.diffuse_color = (1,1,1)
    # Create mesh and assign materials
    bpy.ops.mesh.primitive_uv_sphere_add(segments = 16,ring_count = 8,location=origin)
    ob = bpy.context.object = 'MultiMatSphere'
    me =
    # Assign materials to faces
    i = 0
    for f in me.polygons:
        f.material_index = f.index % 2

I figure there has to be a way to do this, and hopefully on a per-object basis but working with a worldspace material instead of having to create one for each object.

Looking forward to hearing thoughts on the subject.

You may try setting up a node material/texture.

The geometry node which you find at Add->Input->Geometry in the node editor provides access to the world coordinate.
If you know your coloring function gray_level(x,y,z) you can try to recreate it with math nodes and plug the result into the output color socket.

Maybe I can find a good tutorial on these nodes you refer to, because so far I’ve only been able to change the color of the faces of my object to solid colors linearly by index, which won’t do at all.

Okay, so, perhaps there is a way to know which faces are adjacent to each other, so I can alternate face colors in a semilinear fashion. Does any one know how I might go about that?