Blender 2.5 Python 动画世界纹理设置

3 投票
1 回答
869 浏览
提问于 2025-04-16 21:26

我需要在Blender 2.58中使用Python设置一个动画的(也就是从视频文件来的)世界纹理。我的纹理是这样创建的:

import bpy
# create new clouds texture
bpy.ops.texture.new()
wtex = bpy.data.textures[-1]
# set World texture
wrld = bpy.data.worlds['World']
slot = wrld.texture_slots.add()
slot.texture = wtex
slot.use_map_horizon = True

这段代码创建了一个新的CloudsTexture并将其绑定到一个槽位上。那我该怎么做才能创建一个ImageTexture并把视频作为它的来源呢?或者,我该如何指定通过bpy.ops.texture.new()创建的新纹理的类型呢?

1 个回答

0

在添加或删除数据时,最好不要使用运算符,我们可以使用bpy.data提供的API函数来完成这个操作。

import bpy
# create new clouds texture
wtex = bpy.data.textures.new(name="MyTexture", type='IMAGE')
# set World texture
wrld = bpy.context.scene.world
if wrld:
    slot = wrld.texture_slots.add()
    slot.texture = wtex
    slot.use_map_horizon = True

这是在blender 2.58a版本中测试过的。

撰写回答