テクスチャの変更

2010/7/23

Blender2.49

VideoTexture モジュールを使うとできた。

キーボードでtex1.pngとtex2.pngを切り替える。

cont = GameLogic.getCurrentController()
obj = cont.owner

target_material = "Material"
imgs = ['tex1.png','tex2.png']

def init(im_file):
    import VideoTexture

    matID = VideoTexture.materialID(obj,"MA"+target_material)
    texture = VideoTexture.Texture(obj, matID)

    im = GameLogic.expandPath(im_file)
    texture.source = VideoTexture.ImageFFmpeg(im)
    obj["texture"] = texture
    obj["texture"].refresh(True)


def change(im_file):
    im = GameLogic.expandPath(im_file)
    obj["texture"].source.reload(im)
    obj["texture"].refresh(True)


def main():
    if not obj.has_key("texture"):
        init(imgs[0])

    sensor = cont.sensors["keyboard"]
    if sensor.positive:
        n = obj["n"]
        if n == 1: obj["n"] = 0
        else:       obj["n"] = 1
        change(imgs[n])

main()

正直、モジュールの使い方わかってないので、他の関数使ったほうがよいのかもしれない。

Dev:Source/GameEngine/2.49/VideoTexture
http://wiki.blender.org/index.php/Dev:Source/GameEngine/2.49/VideoTexture

和訳 VideoTexture モジュール
http://blender.jp/modules/xfsection/article.php?articleid=279

Ash on 3D Graphics Texture plug-in
http://www.ashsid.sk/wp/?p=8