ImageRender: 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 a list of the cameras
camList = scene.cameras

# get camera being used for render to texture
# my camera is named Security_Cam

cam = camList["Security_Cam"]

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

# get object to render to
# my object is named SecurityMonitor

obj = objList["SecurityMonitor"]

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

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

# get the texture image
renderToTexture.source = bge.texture.ImageRender(scene,cam)

# save RenderToTexture as an object variable
obj["Render"] = renderToTexture

# update the texture
renderToTexture.refresh(True)