1
$\begingroup$

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?

$\endgroup$
  • $\begingroup$ who downvoted ? $\endgroup$ – Leo Ervin Sep 5 '15 at 7:40
  • 2
    $\begingroup$ 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? $\endgroup$ – TLousky Sep 5 '15 at 7:46
  • 3
    $\begingroup$ 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. $\endgroup$ – TLousky Sep 5 '15 at 7:51
  • 3
    $\begingroup$ @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) $\endgroup$ – gandalf3 Sep 5 '15 at 7:54
  • 2
    $\begingroup$ @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. $\endgroup$ – p2or Sep 5 '15 at 8:19
4
$\begingroup$

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 )
$\endgroup$
  • $\begingroup$ 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 $\endgroup$ – Leo Ervin Sep 5 '15 at 8:23
  • $\begingroup$ This script assumes that you have many images, not one - as long as all the images are in the same folder. $\endgroup$ – TLousky Sep 5 '15 at 8:24
  • $\begingroup$ No, I don't mean multiple "frames". I mean 6 images (the 6 sides) for each view for each frame. $\endgroup$ – Leo Ervin Sep 5 '15 at 8:25
  • 3
    $\begingroup$ @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 $\endgroup$ – TLousky Sep 5 '15 at 9:23
  • 1
    $\begingroup$ 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. $\endgroup$ – Leo Ervin Sep 5 '15 at 14:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.