InternalImage

import Blender

# export settings ------------------------------------

# glay_scale -> 8, color -> 32
IMAGE_DEPTH = 8

#detail
GENERATE_DEPTH = 4 

TEXTURE_NAME = "internal_texture"
WIDTH = 512
HEIGHT = 512

#------------------------------------------------------

def write_texture_to_image(image, tex, w, h, image_depth, generate_depth):
  image.makeCurrent()
  dep = generate_depth
  for y in range(h):
  for x in range(w):
  xyz = (x/float(w)*dep, y/float(h)*dep, 0)
  pixel = tex.evaluate(xyz)
  if (image_depth==8):
  pixel[0] = pixel[1] = pixel[2] = pixel[3]
  image.setPixelF(x,y,pixel)
  image.save()
 
textures = Blender.Texture.Get()
if len(textures) and textures[0].users:
  image = Blender.Image.New(TEXTURE_NAME, WIDTH, HEIGHT, 32)
  write_texture_to_image(image, textures[0], WIDTH, HEIGHT, IMAGE_DEPTH, GENERATE_DEPTH)


Comments