rendering cubemap from Blender scene?

I need to render a cubemap from a Blender scene.
Is this the correct way to do it?:
Set camera FOV to 90. Have one camera facing up, one down, left, right, front , back. Is that all to achieve a proper seamless cubemap?
If not, how then?

why would you want to render a cubemap in blender?

if you want to make a texture using blender then i would use a flat plane or a unwrapped cube, basically a plane shaped as the typical cross used for cubemaps, and set the camera to orthographic. press 7 on your numberpad to go to top view, CTRL ALT NUMPAD0 to add the camera to view, then go to the camera settings and select orthograpic. should be on the top.

if you want it to be seamless then make sure you only use a sunlamp as lightsorce, or use the world for lighting if you dont want any shading.

To use it in a different program.

Blender render does produce cube maps automatically, you just have to set up scene and point to the object which will be the center of the cube map.

Coming from World settings (IMPORTANT!), open Texture tab and choose Environment Map as a texture type, Static (or Animated) - Image will offer to load image - you do not want that. Mapping->Cube is set by default. View point - you should point to some Empty you add in the scene center, 2 BU above ground would be fine, like observer would stand there.
Render image (this absolutely doesn’t matter where your Camera points to - first you’ll see blender doing is rendering Environment map.
This will happen just once, on a second render you wont see this unless you click on the black triangle icon near where you did set Static Environment Map. Dropdown menu will show Save Environment or Clear or Clear all. You might want Save…To render different map (changed scene objects, World - btw influence needs to be set all 4 checkboxes - Zenith Up, Down, Horizon and optionally - Blend) click Clear and render/save map again.

Hope helps.

it doesnt for some reason

It should… http://www.pasteall.org/pic/92613

Oh wow, missed that arrow for saving the env map for some reason.

Anyway, I wrote this script for animated cubemaps but here is Blender again complaining about context. What should I change?


import bpy

# remember current frame to switch back after the script is finished
current_frame = bpy.context.scene.frame_current

for i in range(bpy.context.scene.frame_start, bpy.context.scene.frame_end+1):
    # set current frame
    bpy.context.scene.frame_current = i
    
    # create an image which will store the baked data
    image = bpy.data.images.new(str(i)+'.png', bpy.context.scene.render.resolution_x, bpy.context.scene.render.resolution_y, alpha = 0)
    image.file_format = 'PNG'
    image.filepath = "//"+str(i)+".png"
    #image.save()
    
    # need to render for some reason to save the cubemap below
    bpy.ops.render.render()
    
    # save cubemap image
    # needs proper context
    area = bpy.context.area
    old_type = area.type
    area.type = 'PROPERTIES'
    bpy.ops.texture.envmap_save(filepath=str(i)+'.png')
    area.type = old_type
    
    print ("Frame "+str(i)+" complete")
    
# switch back to the frame you were on before running this code
bpy.context.scene.frame_current = current_frame



What’s wrong in using button “Animated”? Make your sky dome get brighter/darker, clouds moving, fireworks going on and click a button. You should get your image sequence.

You’d need not only to save envmap after each frame but also delete image in order to generate a new. Contexts ain’t my best friends either. Ask in a python support forum?

Animated button seems to make Blender recalculate the cubemap each frame, but in the end if I render an animation then click on the same save button, only one file gets saved, not a sequence. If If im doing something wrong please tell me.

Nothing wrong on your side - this was my thinking wrong then - blender recalculates env map if Animated compensating for any object moves you might have had which is (somehow?) reflected in actual render.
Then script looks like a way to get env map for each frame.

See if this would work:
Console


>>> bpy.data.textures['Texture.001'].environment_map.save(
save()
EnvironmentMap.save(filepath, scene=None, layout=(0, 0, 1, 0, 2, 0, 0, 1, 1, 1, 2, 1))
Save the environment map to disc using the scene render settings

Where did you find the environment_map attribute? Maybe its somewhere but not in the Texture class.

AttributeError: 'ImageTexture' object has no attribute 'environment_map'

http://www.blender.org/api/blender_python_api_2_60_6/bpy.types.Texture.html#bpy.types.Texture

It’s under the Worlds

http://www.blender.org/api/blender_python_api_2_60_6/bpy.ops.texture.html?highlight=save

Not sure what I should be doing now

Doing that the environmental map is not updated.

EDIT: Okay, doing clear() fixes that. But I just noticed, filter nodes wont be exported from Blender if using this. Useless to me. heres the code. If other ideas please let me know


import bpy

# remember current frame to switch back after the script is finished
current_frame = bpy.context.scene.frame_current

for i in range(bpy.context.scene.frame_start, bpy.context.scene.frame_end+1):
    # set current frame
    bpy.context.scene.frame_set(i)

    # need to render for some reason to save the cubemap below
    bpy.ops.render.render()

    # save cubemap image
    bpy.data.worlds[0].texture_slots[0].texture.environment_map.save("//"+str(i)+".png")
    
    # need to do this for some reason or won't be updated
    bpy.data.worlds[0].texture_slots[0].texture.environment_map.clear()

    print ("Frame "+str(i)+" complete")

area.type = old_type
# switch back to the frame you were on before running this code
bpy.context.scene.frame_set(current_frame)

If i comment out my friends contexts ( which are not needed now) script renders env map for each frame; i had animated objects floating around - they are in different positions for each frame which suggests script succeeds. I did use Animated button.
I’m not sure it is correct to set image properties based on the scene render size though - env map has some kind of resolution selector. Also, making proper cube unwrap is a beeeep.ing waste of mental energy. Good morning designers!

without being affected by composite nodes this approach isnt useful for me…

Can render each side as separate file like this:


import bpy
from math import radians

camera = bpy.data.objects["Camera"]
camera.data.lens_unit = "FOV"

# remember current frame to switch back after the script is finished
current_frame = bpy.context.scene.frame_current

for i in range(bpy.context.scene.frame_start, bpy.context.scene.frame_end+1):
    # set frame
    bpy.context.scene.frame_current = i
    
    # front
    camera.rotation_euler = (radians(90),0,0)
    bpy.data.scenes['Scene'].render.filepath = "//"+str(i)+"_front"+".jpg"
    bpy.ops.render.render( write_still=True )
    # back
    camera.rotation_euler = (radians(90),0,radians(180))
    bpy.data.scenes['Scene'].render.filepath = "//"+str(i)+"_back"+".jpg"
    bpy.ops.render.render( write_still=True )
    # left
    camera.rotation_euler = (radians(90),0,radians(90))
    bpy.data.scenes['Scene'].render.filepath = "//"+str(i)+"_left"+".jpg"
    bpy.ops.render.render( write_still=True )
    # right
    camera.rotation_euler = (radians(90),0,radians(-90))
    bpy.data.scenes['Scene'].render.filepath = "//"+str(i)+"_right"+".jpg"
    bpy.ops.render.render( write_still=True )
    # top
    camera.rotation_euler = (radians(180),0,0)
    bpy.data.scenes['Scene'].render.filepath = "//"+str(i)+"_top"+".jpg"
    bpy.ops.render.render( write_still=True )
    # down
    camera.rotation_euler = (0,0,0)
    bpy.data.scenes['Scene'].render.filepath = "//"+str(i)+"_down"+".jpg"
    bpy.ops.render.render( write_still=True )
    
    print ("Frame "+str(i)+" complete")


Dont know if this is a good idea. 3rd party tool will need to know each side is in a separate file and how its named.

Where would you need to use composite nodes if that’s a mapped image sequence (or movie texture) you dress your env cube?

It’s ending up in a third party program which uses animated cubemaps. Kind of like panoramic video on youtube. Seen those?

Yup.
Problem is reflective materials do not reflect halos, particle lines, hair and such (in BI) so they are limited. I have some code and blend which uses that technique but I want to render halo particles…