3

I am currently a non-user of Blender, not having used it for about six years.

I have the need to wrap a number of large number of images around a sphere and produce a 3d render (poss with or without the sphere being rendered to help in composite work).

Can Blender be automated to iterate over a number of images, apply an image with the same mapping coords, and then produce a render?

Gwen
  • 11,636
  • 14
  • 68
  • 88
user3791372
  • 133
  • 4

1 Answers1

4

If you have a scene set up with your camera in position, and a sphere that's been UV mapped, has a material applied with an Image Texture connected and setting the color, you can use this script to automate loading images and rendering the results:

import bpy
from os import listdir
from os.path import join, dirname

s = bpy.data.objects['Sphere']  # <-- REPLACE OBJECT NAME IF NEEDED
m = s.active_material
t = m.texture_slots[0].texture

img = t.image

imagesFolder = "C:/SomeFolderWithImges"  # <-- REPLACE THIS WITH ACTUAL PATH TO YOUR IMAGES

isImage = lambda fp: fp.endswith( tuple( bpy.path.extensions_image ) )

for f in listdir(imagesFolder):
    if isImage( f ):
        t.image.filepath = join( imagesFolder, f )
        bpy.context.scene.render.filepath = join( dirname( bpy.context.scene.render.filepath ), f )
        bpy.ops.render.render( write_still = True )

Just copy this into a new textfile in the text editor, replace the path to the images you want to map to your sphere on line 11, and press Run Script.

Sample scene initial setup: Scene initial setup

Rendered results after running script: enter image description here

TLousky
  • 16,043
  • 1
  • 40
  • 72
  • Wow, great answer! As an aside, is it possible to composite in Blender as a single frame image. I'm thinking of setting up a scene and then changing textures, and this would save having to manually composite with other means. – user3791372 Nov 25 '15 at 23:21
  • 1
    Sure, you can create compositor node setups as well using the python API. Here's some places to start: http://blender.stackexchange.com/questions/23436/control-cycles-material-nodes-and-material-properties-in-python/23446#23446 and also: http://blender.stackexchange.com/questions/5413/how-to-connect-nodes-to-node-group-inputs-and-outputs-in-python – TLousky Nov 25 '15 at 23:34