# How can I make a script to make Cycles load a new texture each frame?

I need to load 6 cubemap images each "frame" and apply them to a cube and render that as equirectangular panorama frames via Cycles (camera inside cube, nothing else in the scene).

How would you do it?

• who downvoted ? – Leo Ervin Sep 5 '15 at 7:40
• Do you have any animations running? Does anything change at all between the different frames? Or do you simply want to change only the texture and render the cube with the 6 different maps? – TLousky Sep 5 '15 at 7:46
• No need to be touchy :-) I'm asking because in that case the script is much simpler, you don't really need to change frames at all, just load each texture and render in a loop. – TLousky Sep 5 '15 at 7:51
• @LeoErvin Does this need to be done with python? Could you use an image sequence texture node instead? (related: blender.stackexchange.com/q/5773/599) – gandalf3 Sep 5 '15 at 7:54
• @LeoErvin When you are asking a (complex) python question it's good practice here to show us some code or a bit effort at least. – p2or Sep 5 '15 at 8:19

Try this [Modified according to comments].

It assumes that:

1. You have one root folder (ReplaceMe1) that contains a subfolder for each cubemap. Each subfolder has 6 images, one for every side of the cube.
2. Your cube is comprised of 6 separate objects, appropriately named ('side' / 'front', etc. See script for full list).
3. Each side object has a separate cycles material with an image texture node.
4. You want to save all your renders to a specific folder (RepalceMe2)

Code:

import bpy
from os import listdir
from os.path import join, isdir, isfile

# Root folder which contains a subfolder for each environment map
imgFolder = 'C:/ReplaceMe1'

# Subfolders, each containing 6 images - 1 per side of the cube
mapSubFolders = [ d for d in listdir( imgFolder ) if isdir( join( imgFolder, d ) ) ]

# Output Path (where your renders will be saved)
outputPath = 'C:/ReplaceMe2'

S = bpy.context.scene

sides = [ 'top', 'bottom', 'left', 'right', 'front', 'back' ] # Object names

for d in mapSubFolders:
folderPath = join( imgFolder, d )
imgFiles   = [ f for f in listdir( folderPath ) if isfile( join( folderPath, f ) ) ]

for s in sides:
# This line will crash the script if this folder doesn't contain an image
# for each side, with the same name (for example: 'bottom.jpg'; format doesn't matter)
sideImg = [ f for f in imgFiles if s in f ][0]

imgPath = join( folderPath, sideImg )

# Open image file or apply the relevant image path to an existing image object with the same name
if sideImg not in bpy.data.images:
bpy.ops.image.open( filepath = imgPath )
else:
bpy.data.images[ sideImg ].filepath = imgPath

img = bpy.data.images[ sideImg ]

sideObj = S.objects[ s ]
t = sideObj.active_material.node_tree

t.nodes['Image Texture'].image = img # Apply current side's image to image texture node

outputFile = d + "_" + s + S.render.file_extension

S.render.filepath = join( outputPath, outputFile ) # Set render output path

bpy.ops.render.render( write_still = True )

• The cubemaps are separate images for left, right, top, down and front, back views, not a single image containing all 6 views. Such a thing can be rendered with Blender like this: pasteall.org/60978 I found no easy way to save all views as 1 image. Environment maps work but they do not support composite nodes being applied to them. And heres the code I use for that: pasteall.org/60979 – Leo Ervin Sep 5 '15 at 8:23
• This script assumes that you have many images, not one - as long as all the images are in the same folder. – TLousky Sep 5 '15 at 8:24
• No, I don't mean multiple "frames". I mean 6 images (the 6 sides) for each view for each frame. – Leo Ervin Sep 5 '15 at 8:25
• @LeoErvin, modified according to your comments. As you can see, a focused dialogue is often crucial to help you get the answer you need, so be nicer to the people asking questions next time :-P – TLousky Sep 5 '15 at 9:23
• I got frustrated from the downote and was pretty furstrated today already, sorry about that. BTW, this, combined with the code I posted above allows to render equirectangular videos with Blender Internal. I really miss the halo and line particles in Cycles, I think some people who want to render panoramic images or videos from Blender Renderer will find this workflow tedious but a solution nonetheless. – Leo Ervin Sep 5 '15 at 14:54