Texture: materialID

materialID(obj, name)
  • Returns a numeric value that can be used in the Video Texture module to create a dynamic texture.

Return Type: 

  • integer

obj:

  • The game object that holds the texture.
  • Type: KX_GameObject
     
name:
  • Name of the texture or material you want to make dynamic.
  • Type:  string
Note:
  • Material name must have MA prefix.
    Material must have an image in the first texture channel.
    If the material name is Canvas, you'd use "MACanvas"
     
  • Texture image name must have IM prefix.
    Texture image must be in the first texture channel.
    If the texture image name is Static.jpg, you'd use "IMStatic.jpg"
Sample Code

###################### get materialID

# import bge module
import bge

# get current scene
scene = bge.logic.getCurrentScene()

# get list of objects in scene
objList = scene.objects

# get object to render to
# my object is named Security_Monitor
obj = objList["Security_Monitor"]

# get the Security_Monitor material ID
# Name of my render material is Screen
matID = bge.texture.materialID(obj, "MAScreen")

# use the first texture slot
texID = 0

# use the default objTex value

# set the texture
viewport_texture = bge.texture.Texture(obj, matID, texID)

# get the texture image
viewport_texture.source = bge.texture.ImageViewport()

# save as an object property
obj["image_viewport"] = viewport_texture

# update texture
viewport_texture.refresh(True)