开发者

How do I set a world background texture in Blender 2.49 using Python?

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
开发者_JAVA百科

'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


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜