__author__ = 'thoth'
#http://blender.stackexchange.com/questions/61308/same-video-on-each-face-but-with-different-time-delay
import bpy
def get_movie(movie_fname):
for img in bpy.data.images:
if img.filepath == movie_fname:
return img
return bpy.data.images.load(movie_fname, check_existing=True)
def mission1(obj, n_materials=6):
movie_fname = "/var/tmp/blender/meow-gun.mp4"
img = get_movie(movie_fname)
textures = []
for i in range(n_materials):
tex = bpy.data.textures.new("movie", 'IMAGE')
#tex.type = 'IMAGE'
tex.image = img
tex.image_user.frame_start = i*300
tex.image_user.use_cyclic=True
tex.image_user.frame_duration = img.frame_duration
textures.append(tex)
materials = []
for i in range(n_materials):
mat = bpy.data.materials.new("movie")
if i>=len(mat.texture_slots) or mat.texture_slots[i] is None:
tslot = mat.texture_slots.add()
else:
tslot = mat.texture_slots[i]
tslot.texture = textures[i]
#many other material customizations can go here
mat.emit = 1
tslot.texture_coords = 'UV'
materials.append(mat)
for i in range(n_materials):
if i<len(obj.data.materials):
obj.data.materials[i] = materials[i]
else:
obj.data.materials.append(materials[i])
for j in range(len(obj.data.polygons)):
obj.data.polygons[j].material_index = j%len(obj.data.materials)
obj = bpy.context.active_object
obj = bpy.data.objects["Cube"]
mission1(obj)
|
Blender python API quick-start
Syntax highlighting by Pygments.