replace more than one texture to videotextures

Hi,
I am a bge noob, so sorry in advance… :slight_smile:

I am trying to use a videotexture combined with another videotexture for alpha, so I can have a transparent videotexture.

I used this example of how to replace a texture with a video
http://www.blender.org/api/blender_python_api_2_62_1/bge.texture.html
and that works good.

import bge
from bge import texture
from bge import logic

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

# the creation of the texture must be done once: save the
# texture object in an attribute of bge.logic module makes it persistent
if not hasattr(logic, 'video'):

    # identify a static texture by name
    matID = texture.materialID(obj, 'IMvideo.png')

    # create a dynamic texture that will replace the static texture
    logic.video = texture.Texture(obj, matID)

    # define a source of image for the texture, here a movie
    movie = logic.expandPath('//trailer_400p.ogg')
    logic.video.source = texture.VideoFFmpeg(movie)
    logic.video.source.scale = True

    # quick off the movie, but it wont play in the background
    logic.video.source.play()

# you need to call this function every frame to ensure update of the texture.
logic.video.refresh(True)

No I want to replace the second texture in the stack with the alpha video (black/white)

How can I add a second texture in the script?

Well, copy code and set it up for second texture using hte same method’s - that’s the easiest way.

You are right! Thanks!
I think I got it to work after I found out how to refer to the other texture slots
(e g
texID = 1
logic.video = texture.Texture(obj, matID, texID)

I unsolved the thread prefix again, because need some more help after all…
it seems like the videos are not perfectly synched. It looks good on some frames, but not all.
for example - here is a screenshot from my test in the gameengine
[ATTACH=CONFIG]384706[/ATTACH]
and here is a render of the same frame
[ATTACH=CONFIG]384707[/ATTACH]

Here is the code (that I just copied and pasted and changed some names (probably in some wrong way…))
I tried a delay sensor and also an always sensor to combine with the python controller.

import bge
from bge import texture
from bge import logic

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

# the creation of the texture must be done once: save the
# texture object in an attribute of bge.logic module makes it persistent

    
if not hasattr(logic, 'video'):

    # identify a static texture by name
    matID = bge.texture.materialID(obj, "MAMaterial")
    texID = 0

    #matID = texture.materialID(obj, 'IMcol0001.png')

    # create a dynamic texture that will replace the static texture
    logic.video = texture.Texture(obj, matID, texID)

    # define a source of image for the texture, here a movie
    movie = logic.expandPath('//col0001-0100.mov')
    logic.video.source = texture.VideoFFmpeg(movie)
    logic.video.source.scale = True
    logic.video.source.repeat = -1

    # quick off the movie, but it wont play in the background
    logic.video.source.play()
if not hasattr(logic, 'video2'):

    # identify a static texture by name
    matID = bge.texture.materialID(obj, "MAMaterial")
    texID2 = 1

    #matID = texture.materialID(obj, 'IMalpha0001.png')

    # create a dynamic texture that will replace the static texture
    logic.video2 = texture.Texture(obj, matID, texID2)

    # define a source of image for the texture, here a movie
    movie = logic.expandPath('//alpha0001-0100.mov')
    logic.video2.source = texture.VideoFFmpeg(movie)
    logic.video2.source.scale = True
    logic.video2.source.repeat = -1

    # quick off the movie, but it wont play in the background
    logic.video2.source.play()


# you need to call this function every frame to ensure update of the texture.
logic.video.refresh(True)
logic.video2.refresh(True)

I also found the FilterBlueScreen() as another way to get transparent videotextures but I don´t really know how to make it transparent.
If I have a blue background - it just change it to white, so I need to add something to make it transparent, but… I am a noob
[ATTACH=CONFIG]384709[/ATTACH]

import bge
from bge import texture
from bge import logic

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

# the creation of the texture must be done once: save the
# texture object in an attribute of bge.logic module makes it persistent
if not hasattr(logic, 'video'):

    # identify a static texture by name
    matID = bge.texture.materialID(obj, "MAMaterial")
    texID = 0

    #matID = texture.materialID(obj, 'IMcol0001.png')

    # create a dynamic texture that will replace the static texture
    logic.video = texture.Texture(obj, matID, texID)

    # define a source of image for the texture, here a movie
    movie = logic.expandPath('//blueBG.mov')
    logic.video.source = texture.VideoFFmpeg(movie)
    logic.video.source.filter = bge.texture.FilterBlueScreen()
    logic.video.source.scale = True
    logic.video.source.repeat = -1

    # quick off the movie, but it wont play in the background
    logic.video.source.play()

# you need to call this function every frame to ensure update of the texture.
logic.video.refresh(True)

Difficult, but fun this part of Blender!

Edit: The FilterBlueScreen() worked perfect. It was just me mixing up videos.
So I don´t need 2 separate videotextures anymore. Will mark this solved again :slight_smile:

it seems like the videos are not perfectly synched. It looks good on some frames, but not all.
for example - here is a screenshot from my test in the gameengine

from bge import logic, texture


def play(cont):


    obj = cont.owner


    # the creation of the texture must be done once: save the
    # texture object in an attribute of bge.logic module makes it persistent
    if not hasattr(logic, 'video'):


        # put a material and a texture(uvgrid or screenshot of the movie) on the object, put the name of the material below. and at MA in front of the material name
        matID = texture.materialID(obj, 'MAmaterialname')


        # create a dynamic texture that will replace the static texture
        logic.video = texture.Texture(obj, matID)
    
        # define a source of image for the texture, here a movie
        movie = logic.expandPath('//locationofthemovie')
        logic.video.source = texture.VideoFFmpeg(movie)
        logic.video.source.scale = True


        # quick off the movie, but it wont play in the background
        logic.video.source.play()


    # you need to call this function every frame to ensure update of the texture.
    logic.video.refresh(True)

always->python(true pulse) module mode -> scriptname.play

Tested and runs sync on 50 cubes with all sides playing the movie.

Thanks cotax! I will try this