Here is how I am doing image sequences via code for my new Space Battle AddOn.
Code:
if MANAGE_IMAGE_SEQUENCE == True:
# Create image texture from image
temp_tex = bpy.data.textures.get(texture_name)
if temp_tex == None:
temp_tex = bpy.data.textures.new(texture_name, type = 'IMAGE')
#realpath = os.path.expanduser('~/snippets/textures/color.png')
# Pick a random explosion sequence. HARD CODED FILENAMES!
the_path = "E:\\Documents and Settings\\Admin\\My Documents\\" #Renderbox
the_path = "C:\\Users\\Overseer\\Documents\\Maps" #Laptop.
explosion_map_index = random.randint(0,5)
realpath = "%sMaps\\Animated\\fireball-3_large\\fireball-3_large_0001.png" % the_path
explosion_duration = 90 # Set length of image sequence, in frame, here.
if explosion_map_index == 1:
realpath = "%sMaps\\Animated\\explosion-5\\explosion-5_0001.tif" % the_path
explosion_duration = 64 # Set length of image sequence, in frame, here.
ex_dur_middle = int(explosion_duration/3)
try:
temp_tex.image = bpy.data.images.load(realpath) # Load the file, may need try/except to handle file not found.
temp_tex.image.use_premultiply = True
temp_tex.image.source = 'SEQUENCE'
temp_tex.image_user.frame_duration = explosion_duration
temp_tex.image_user.frame_start = end_frame
temp_tex.image_user.frame_offset = 0
temp_tex.image_user.use_cyclic = False
temp_tex.image_user.use_auto_refresh = True
temp_mat.diffuse_color = (0.0,1.0,0.0)
except:
print("trace_missile_particles: Failure to load texture file [%s]." % realpath)
temp_mat.diffuse_color = (1.0,1.0,0.0)
# Add texture slot for image texture.
temp_ts = temp_mat.texture_slots.add()
temp_ts.texture = temp_tex
temp_ts.texture_coords = 'UV'
temp_ts.use_map_color_diffuse = True
temp_ts.use_map_color_emission = True
temp_ts.emission_color_factor = 1.0
temp_ts.use_map_density = True
temp_ts.mapping = 'FLAT'
# UV map the plane for rendering, not viewport.
uv_name = "uv_explosion%s" % post_fix
temp_ob.data.uv_textures.new(name=uv_name)
if temp_tex.image != None:
temp_ob.data.uv_textures[0].data[0].image = temp_tex.image
This way you don't have to worry about edit modes, the context or bpy.ops screwing you down the line come render time.
Bookmarks