BGE错误:'视频纹理。纹理'对象没有属性'materialID'

2024-05-19 22:47:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着改变搅拌机游戏引擎中物体的纹理。 我认为使用Video Texture (bge.texture)中的纹理替换是个好主意。 我尝试运行以下脚本:

def createTexture(cont):
    obj = cont.owner

    # get the reference pointer (ID) of the internal texture
    ID = texture.materialID(obj, 'Kraftwerk2.png')

    # create a texture object
    object_texture = texture.Texture(obj, ID)

    # create a new source with an external image
    url = logic.expandPath(new_file)
    new_source = texture.ImageFFmpeg(url)

    # the texture has to be stored in a permanent Python object
    logic.texture = object_texture

    # update/replace the texture
    logic.texture.source = new_source
    logic.texture.refresh(False)

def removeTexture(cont):
    """Delete the Dynamic Texture, reversing back the final to its original state."""
    try:
        del logic.texture
    except Exception as e:
        print(e)

但它失败了,错误消息如下:

Python script error - object 'Plane', controller 'Python': Traceback (most recent call last): File "F:\Benutzer\Merlin\MW-Industries\Blender Dateien\Cinema\Render-Blend\MoonSpace.ble nd\Test.py", line 19, in createTexture AttributeError: 'VideoTexture.Texture' object has no attribute 'materialID'

有办法解决这个问题吗?你知道吗


Tags: theidobjsourcenewobjectdefcreate