【问题标题】:How do I set a world background texture in Blender 2.49 using Python?如何使用 Python 在 Blender 2.49 中设置世界背景纹理?
【发布时间】:2011-03-18 02:19:16
【问题描述】:

我正在尝试在 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 包含一个无元组。 所以这行不通:

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

'world MTex' 对象让我思考了一下。是否有另一种 Mtex 对象?一个世界 MTEX​​ ?它在哪里定义,如何创建实例?

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

谢谢

【问题讨论】:

    标签: python 3d textures blender bpython


    【解决方案1】:

    Blender 2.5x 具有更好的 Python API。我真的建议您观看 Christopher Webber 的 video from 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
    

    【讨论】:

    • 非常有趣的演讲,感谢您提供的资源。确实 Blender 2.5 会更好,但是当时需要 Blender 2.49,这也是为什么特别提到 2.49 的原因。作为一个肮脏的解决方法,我在默认的搅拌机模板中添加了一个材质槽,这样我就可以继续前进,但我仍然对那里发生的事情以及真正的解决方案感兴趣。
    • 我从 2.5x 开始使用 Blender,所以在这里我帮不了你。对不起。
    猜你喜欢
    • 2011-10-04
    • 1970-01-01
    • 2019-06-03
    • 2019-09-17
    • 2018-08-11
    • 2016-06-24
    • 1970-01-01
    • 2013-05-08
    • 1970-01-01
    相关资源
    最近更新 更多