1

I'm trying to set a background World Texture in Blender 2.49.

I've made a texture:

import Blender 
from Blender import * 
import bpy 

world = World.GetCurrent() 
worldTex = Texture.New('worldTex') 
worldTex.setType('Image') 
worldIm = Image.Load('//blender_scene/tex/bg 001.jpg') 
worldIm.source = Image.Sources.SEQUENCE 
worldTex.setImage(worldIm)

When I try to apply to the world, that will throw and error, because, by default world.textures contains a tuple of None. so this wouldn't work:

world.textures[0].tex = worldTex

I've made a material so I can get an MTex instance:

worldMat = Material.New('WorldMat')
worldMat.setTexture(worldTex)

If I try to set the first texture:

world.textures[0] = worldMat.textures[0]

That will throw an error, since I can't assign a value to an already initialized tuple.

If I try to replace it:

world.textures = worldMat.textures

I get yet another error:

TypeError: expected tuple or list containing world MTex objects and NONE

'world MTex' objects got me thinking a bit. Is there another kind of MTex object ? a world MTex ? Where is it defined, how can I create an instance ?

Or as the title states...how do I set a texture to a world ?

Thanks

George Profenza
  • 50,687
  • 19
  • 144
  • 218

1 Answers1

1

Blender 2.5x has a much better Python API. I really recommend watching this video from PyCon talk by Christopher Webber about it.

Setting texture in 2.5x API :

import bpy
# create new clouds texture
bpy.ops.texture.new()
t = bpy.data.textures[-1]
# set World texture
w = bpy.data.world['World']
slot = w.texture_slots.add()
slot.texture = t
slot.use_map_horizon = True
anatoly techtonik
  • 19,847
  • 9
  • 124
  • 140
  • very interesting talk, thank you for the resource. Indeed Blender 2.5 would be nicer, but Blender 2.49 was a requirement at the time, which is why specifically mentioned 2.49. As a dirty workaround, I added a material slot into the default blender template so I could move on, but I am still interested in what's going on there and what the real solution is. – George Profenza Apr 09 '11 at 19:48
  • I've started Blender from 2.5x, so I can't help you here. Sorry. – anatoly techtonik Apr 12 '11 at 14:35