簡體   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