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

4

1 回答 1

1

Blender 2.5x 有一个更好的 Python API。我真的建议您观看Christopher Webber的 PyCon 演讲视频。

在 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
于 2011-04-09T12:31:47.493 回答