指定された URL から動的に作成された画像ファイルを取得し、その画像ファイルでマテリアルを作成するPython スクリプトが必要です。
次に、そのマテリアルをブレンダー オブジェクトに適用します。
以下の Python コードは、ローカルの画像ファイルに対して機能します。
import bpy, os
def run(origin):
# Load image file from given path.
realpath = os.path.expanduser('D:/color.png')
try:
img = bpy.data.images.load(realpath)
except:
raise NameError("Cannot load image %s" % realpath)
# Create image texture from image
cTex = bpy.data.textures.new('ColorTex', type = 'IMAGE')
cTex.image = img
# Create material
mat = bpy.data.materials.new('TexMat')
# Add texture slot for color texture
mtex = mat.texture_slots.add()
mtex.texture = cTex
# Create new cube
bpy.ops.mesh.primitive_cube_add(location=origin)
# Add material to created cube
ob = bpy.context.object
me = ob.data
me.materials.append(mat)
return
run((0,0,0))
私は試した :
import urllib, cStringIO
file = cStringIO.StringIO(urllib.urlopen(URL).read())
img = Image.open(file)
しかし、私はそれで運がありませんでした。私が得た最初のエラーは
ImportError: 'StringIO' という名前のモジュールがありません
Blender の python スクリプト API は制限付きモジュールを使用していますか?
ご協力ありがとうございました。