简体   繁体   English

如何使用Python在Blender 2.49中设置世界背景纹理?

[英]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. 我正在尝试在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. 当我尝试应用到世界时,会抛出错误,因为默认情况下world.textures包含一个None的元组。 so this wouldn't work: 所以这行不通:

world.textures[0].tex = worldTex

I've made a material so I can get an MTex instance: 我已经制作了材料,因此可以获得MTex实例:

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. “世界MTex ”物体让我有些思考。 Is there another kind of MTex object ? 还有另一种MTex对象吗? a world MTex ? 世界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. Blender 2.5x具有更好的Python API。 I really recommend watching this video from PyCon talk by Christopher Webber about it. 我真的建议您观看克里斯托弗·韦伯(Christopher Webber)的PyCon演讲中的这段视频

Setting texture in 2.5x API : 在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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM