繁体   English   中英

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

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

我正在尝试在Blender 2.49中设置背景世界纹理。

我做了一个纹理:

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)

当我尝试应用到世界时,会抛出错误,因为默认情况下world.textures包含一个None的元组。 所以这行不通:

world.textures[0].tex = worldTex

我已经制作了材料,因此可以获得MTex实例:

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

如果我尝试设置第一个纹理:

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

这将引发错误,因为我无法将值分配给已初始化的元组。

如果我尝试更换它:

world.textures = worldMat.textures

我又遇到另一个错误:

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

“世界MTex ”物体让我有些思考。 还有另一种MTex对象吗? 世界MTex? 它在哪里定义,如何创建实例?

或者如标题所述...如何为世界设置纹理?

谢谢

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

暂无
暂无

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

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