Paste Code
Paste Blends
Paste Images
#----------------------------------------------------------
# This script will generate 15 * 15 * 15 suzannes
# Each of them with a unique 1x1 pixel texture
#----------------------------------------------------------
import bpy

def makeMaterial(i, color):
tex_name = 'tex_'+str(i)
bpy.ops.image.new(name=tex_name, width=1, height=1)
img = bpy.data.images[tex_name]
img.pixels[0] = color[0]
img.pixels[1] = color[1]
img.pixels[2] = color[2]

mat_name = 'mat_'+str(i)
bpy.ops.material.new()
mat = bpy.data.materials[-1]
mat.name=mat_name
nodes = mat.node_tree.nodes
tex_node = nodes.new(type='ShaderNodeTexImage')
tex_node.image = img
links = mat.node_tree.links
link = links.new(tex_node.outputs[0], nodes[1].inputs[0])
return mat

def setMaterial(ob, mat):
me = ob.data
me.materials.append(mat)

def createTexturedMonkey(origin, i, color):
mat = makeMaterial(i, color)

# Create red cube
bpy.ops.mesh.primitive_monkey_add(radius=0.25,location=origin)
setMaterial(bpy.context.object, mat)

if __name__ == "__main__":
i = 0
xMax = 15
yMax = 15
zMax = 15
for x in range(xMax):
for y in range(yMax):
for z in range(zMax):
r = x / (xMax - 1.0)
g = y / (yMax - 1.0)
b = z / (zMax - 1.0)
createTexturedMonkey((x-xMax/2.0,y-yMax/2.0,z-zMax/2.0), i, (r, g, b))
i = i + 1
  1. #----------------------------------------------------------
  2. # This script will generate 15 * 15 * 15 suzannes
  3. # Each of them with a unique 1x1 pixel texture
  4. #----------------------------------------------------------
  5. import bpy
  6.  
  7. def makeMaterial(i, color):
  8.     tex_name = 'tex_'+str(i)
  9.     bpy.ops.image.new(name=tex_name, width=1, height=1)
  10.     img = bpy.data.images[tex_name]
  11.     img.pixels[0] = color[0]
  12.     img.pixels[1] = color[1]
  13.     img.pixels[2] = color[2]
  14.        
  15.     mat_name = 'mat_'+str(i)
  16.     bpy.ops.material.new()
  17.     mat = bpy.data.materials[-1]
  18.     mat.name=mat_name
  19.     nodes = mat.node_tree.nodes
  20.     tex_node = nodes.new(type='ShaderNodeTexImage')
  21.     tex_node.image = img
  22.     links = mat.node_tree.links
  23.     link = links.new(tex_node.outputs[0], nodes[1].inputs[0])
  24.     return mat
  25.  
  26. def setMaterial(ob, mat):
  27.     me = ob.data
  28.     me.materials.append(mat)
  29.  
  30. def createTexturedMonkey(origin, i, color):
  31.     mat = makeMaterial(i, color)
  32.  
  33.     # Create red cube
  34.     bpy.ops.mesh.primitive_monkey_add(radius=0.25,location=origin)
  35.     setMaterial(bpy.context.object, mat)
  36.  
  37. if __name__ == "__main__":
  38.     i = 0
  39.     xMax = 15
  40.     yMax = 15
  41.     zMax = 15
  42.     for x in range(xMax):
  43.         for y in range(yMax):
  44.             for z in range(zMax):
  45.                 r = x / (xMax - 1.0)
  46.                 g = y / (yMax - 1.0)
  47.                 b = z / (zMax - 1.0)
  48.                 createTexturedMonkey((x-xMax/2.0,y-yMax/2.0,z-zMax/2.0), i, (r, g, b))
  49.                 i = i + 1
  50.  
go to heaven