Play Movies with Alpha (up to 4 at onde, single screen)

Hi guys, I’m building an interactive storytelling kiosk and I was wondering if anyone can give me a little help…

this is the setup:

and each sensor (represented by hand figures, they go on the top of the kiosk) will trigger different stories…that can be played at once since the videos don’t overlap…I’ve been trying something like this:

from panda3d.core import * 
# Tell Panda3D to use OpenAL, not FMOD 
loadPrcFileData("", "textures-power-2 none") 
loadPrcFileData("", "audio-library-name p3openal_audio") 
from direct.showbase.DirectObject import DirectObject 
from direct.gui.OnscreenText import OnscreenText 
import direct.directbase.DirectStart 

# The name of the media file. 
MEDIAFILE1="opacity_01.mov" 
MEDIAFILE2="alpha.mov" 
MEDIAFILE3="opacity_02.mov" 


# Function to put instructions on the screen. 
def addInstructions(pos, msg): 
    return OnscreenText(text=msg, style=1, fg=(0,0,0,1), mayChange=1, 
                        pos=(-1.3, pos), align=TextNode.ALeft, scale = .05, shadow=(1,1,1,1), shadowOffset=(0.1,0.1)) 

# Function to put title on the screen. 
def addTitle(text): 
    return OnscreenText(text=text, style=1, fg=(0,0,0,1), 
                        pos=(1.3,-0.95), align=TextNode.ARight, scale = .07, shadow=(1,1,1,1), shadowOffset=(0.05,0.05)) 


class World(DirectObject): 

    def __init__(self): 
      
        self.enterVideo1()
        self.enterVideo2()
        self.enterVideo3()
       
        self.inst1 = addInstructions(0.95,"") 
        
        base.setBackgroundColor(1,1,1,1) 
        
            
        self.accept('p', self.playpause) 
        self.accept('P', self.playpause) 

    def enterVideo1(self):    
         
        self.tex = MovieTexture("1") 
        
        assert self.tex.read(MEDIAFILE1), "Failed to load video!" 

        # Set up a fullscreen card to set the video texture on. 
        cm = CardMaker("My Fullscreen Card"); 
        cm.setFrameFullscreenQuad() 
        cm.setUvRange(self.tex) 
        card = NodePath(cm.generate()) 
        card.reparentTo(render2d) 
        card.setTransparency(TransparencyAttrib.MAlpha) 
        card.setScale(card, 0.8) 
        card.setTexture(self.tex) 
        card.setTexScale(TextureStage.getDefault(), self.tex.getTexScale()) 
        self.sound=loader.loadSfx('tree.wav') 
        # Synchronize the video to the sound. 
        self.tex.synchronizeTo(self.sound) 
        
    def enterVideoAlpha(self):    
         
        self.tex = MovieTexture("2") 
        
        assert self.tex.read(MEDIAFILE2), "Failed to load video!" 

        # Set up a fullscreen card to set the video texture on. 
        cm = CardMaker("My Fullscreen Card"); 
        cm.setFrameFullscreenQuad() 
        cm.setUvRange(self.tex) 
        card = NodePath(cm.generate()) 
        card.reparentTo(render2d) 
        card.setTransparency(TransparencyAttrib.MAlpha) 
        card.setScale(card, 0.8) 
        card.setTexture(self.tex) 
        card.setTexScale(TextureStage.getDefault(), self.tex.getTexScale()) 
        
    def enterVideo3(self):    
         
        self.tex = MovieTexture("3") 
        
        assert self.tex.read(MEDIAFILE3), "Failed to load video!" 

        # Set up a fullscreen card to set the video texture on. 
        cm = CardMaker("My Fullscreen Card"); 
        cm.setFrameFullscreenQuad() 
        cm.setUvRange(self.tex) 
        card = NodePath(cm.generate()) 
        card.reparentTo(render2d) 
        card.setTransparency(TransparencyAttrib.MAlpha) 
        card.setScale(card, 0.8) 
        card.setTexture(self.tex) 
        card.setTexScale(TextureStage.getDefault(), self.tex.getTexScale())    
        
  
    def stopsound(self): 
        self.sound.stop() 
        self.sound.setPlayRate(1.0) 

    def fastforward(self): 
        print self.sound.status() 
        if (self.sound.status() == AudioSound.PLAYING): 
          t = self.sound.getTime() 
          self.sound.stop() 
          if (self.sound.getPlayRate() == 1.0): 
            self.sound.setPlayRate(0.5) 
          else: 
            self.sound.setPlayRate(1.0) 
          self.sound.setTime(t) 
          self.sound.play() 

    def playpause(self): 
        if (self.sound.status() == AudioSound.PLAYING): 
          t = self.sound.getTime() 
          self.sound.stop() 
          self.sound.setTime(t) 
        else: 
          self.sound.play() 

w = World() 
run() 

As is, it plays one video, and black as alpha…should play 2 videos simultanesouly though…

Thank you for any help you can give me!!

Videos are here if needed!
jupiter.esec.pt/~apgomes/madeira/joo.rar
:smiley:

Your code seems to be loading up three videos, all at once, and applying each one to a card with is attached to render2d. With this strategy, you will only see the topmost video, which is the one you loaded last. The other two videos will also be playing, but they will be obscured behind the last one.

What is the effect that you wanted to see instead? If you wanted to load one video to represent the color channels, and a different video to serve as the alpha channel (or transparency mask) for that same video, then you would create only one MovieTexture, and use the two-parameter read() function to specify the two video files (color and alpha) that contribute to this MovieTexture.

If your second video (or the third video file) is intended to be viewed behind this one, through the transparent parts of the alpha mask, then this strategy should work. But here you will have only two MovieTextures, one with a two-parameter read, and the lower (or first) one with a one-parameter read.

David

Thank you David,

Indeed what i want is to be able to play videos simultaneously (they can be seen through the transparent top most video). I’ll give it a try :wink:

It did worked David :wink:

In case anyone ever needs

from panda3d.core import * 
# Tell Panda3D to use OpenAL, not FMOD 
loadPrcFileData("", "textures-power-2 none") 
loadPrcFileData("", "audio-library-name p3openal_audio") 
from direct.showbase.DirectObject import DirectObject 
from direct.gui.OnscreenText import OnscreenText 
import direct.directbase.DirectStart 

# The name of the media file. 
MEDIAFILE1="opacity_01.mov" 
MEDIAFILE2="opacity_02.mov" 
MEDIAFILE3="opacity_03.mov"
MEDIAFILE4="opacity_04.mov"
 

ALPHA1="opacity_01_alpha.mov"
ALPHA2="opacity_02_alpha.mov"
ALPHA3="opacity_03_alpha.mov"
ALPHA4="opacity_04_alpha.mov"


# Function to put instructions on the screen. 
def addInstructions(pos, msg): 
    return OnscreenText(text=msg, style=1, fg=(0,0,0,1), mayChange=1, 
                        pos=(-1.3, pos), align=TextNode.ALeft, scale = .05, shadow=(1,1,1,1), shadowOffset=(0.1,0.1)) 

# Function to put title on the screen. 
def addTitle(text): 
    return OnscreenText(text=text, style=1, fg=(0,0,0,1), 
                        pos=(1.3,-0.95), align=TextNode.ARight, scale = .07, shadow=(1,1,1,1), shadowOffset=(0.05,0.05)) 


class World(DirectObject): 

    def __init__(self): 
      
        self.enterVideo1() 
        self.enterVideo2() 
        self.enterVideo3()
        self.enterVideo4()  
        


    def enterVideo1(self):   
        
        self.inst1 = addInstructions(0.95,"") 
        
        base.setBackgroundColor(1,1,1,1) 
        
        self.tex1 = MovieTexture("1") 
        
        assert self.tex1.read(MEDIAFILE1,ALPHA1,3,1), "Failed to load video!" 

        # Set up a fullscreen card to set the video texture on. 
        cm = CardMaker("My Fullscreen Card"); 
        cm.setFrameFullscreenQuad() 
        cm.setUvRange(self.tex1) 
        card = NodePath(cm.generate()) 
        card.reparentTo(render2d) 
        card.setTransparency(TransparencyAttrib.MAlpha) 
        card.setScale(card, 0.8) 
        card.setTexture(self.tex1) 
        card.setTexScale(TextureStage.getDefault(), self.tex1.getTexScale()) 
        self.sound1=loader.loadSfx('opa1.wav') 
        # Synchronize the video to the sound. 
        self.tex1.synchronizeTo(self.sound1) 
        
        self.tex1.stop()
        
            
        self.accept('p', self.playpause,extraArgs=[self.sound1]) 
        
         
        
    def enterVideo2(self):    
        
        self.inst2 = addInstructions(0.90,"") 
        
        base.setBackgroundColor(1,1,1,1) 
          
        self.tex2 = MovieTexture("2") 
        
        assert self.tex2.read(MEDIAFILE2,ALPHA2,3,1), "Failed to load video!" 

        # Set up a fullscreen card to set the video texture on. 
        cm = CardMaker("My Fullscreen Card"); 
        cm.setFrameFullscreenQuad() 
        cm.setUvRange(self.tex2) 
        card = NodePath(cm.generate()) 
        card.reparentTo(render2d) 
        card.setTransparency(TransparencyAttrib.MAlpha) 
        card.setScale(card, 0.8) 
        card.setTexture(self.tex2) 
        card.setTexScale(TextureStage.getDefault(), self.tex2.getTexScale()) 
        self.sound2=loader.loadSfx('opa2.wav') 
        # Synchronize the video to the sound. 
        self.tex2.synchronizeTo(self.sound2) 
        
        self.tex2.stop()
        
        self.accept('o', self.playpause,extraArgs=[self.sound2])
        #self.accept('o', self.playpause)  
        
    def enterVideo3(self): 
        
        self.inst3 = addInstructions(0.85,"") 
        
        base.setBackgroundColor(1,1,1,1) 
          
        self.tex3 = MovieTexture("3") 
        
        assert self.tex3.read(MEDIAFILE3,ALPHA3,3,1), "Failed to load video!" 

        # Set up a fullscreen card to set the video texture on. 
        cm = CardMaker("My Fullscreen Card"); 
        cm.setFrameFullscreenQuad() 
        cm.setUvRange(self.tex3) 
        card = NodePath(cm.generate()) 
        card.reparentTo(render2d) 
        card.setTransparency(TransparencyAttrib.MAlpha) 
        card.setScale(card, 0.8) 
        card.setTexture(self.tex3) 
        card.setTexScale(TextureStage.getDefault(), self.tex3.getTexScale()) 
        self.sound3=loader.loadSfx('opa3.wav') 
        # Synchronize the video to the sound. 
        self.tex3.synchronizeTo(self.sound3) 
        
        self.tex3.stop()
        
        self.accept('i', self.playpause,extraArgs=[self.sound3])
        #self.accept('i', self.playpause)    
        
    def enterVideo4(self):    
        
        self.inst4 = addInstructions(0.80,"") 
        
        base.setBackgroundColor(1,1,1,1) 
          
        self.tex4 = MovieTexture("4") 
        
        assert self.tex4.read(MEDIAFILE4,ALPHA3,4,1), "Failed to load video!" 

        # Set up a fullscreen card to set the video texture on. 
        cm = CardMaker("My Fullscreen Card"); 
        cm.setFrameFullscreenQuad() 
        cm.setUvRange(self.tex4) 
        card = NodePath(cm.generate()) 
        card.reparentTo(render2d) 
        card.setTransparency(TransparencyAttrib.MAlpha) 
        card.setScale(card, 0.8) 
        card.setTexture(self.tex4) 
        card.setTexScale(TextureStage.getDefault(), self.tex4.getTexScale())
        self.sound4=loader.loadSfx('opa4.wav') 
        # Synchronize the video to the sound. 
        self.tex4.synchronizeTo(self.sound4) 
        
        self.tex4.stop()
        
        self.accept('u', self.playpause,extraArgs=[self.sound4])
       #self.accept('u', self.playpause)  
        
  
    def stopsound(self,sound): 
        sound.stop() 
        sound.setPlayRate(1.0) 
      
        

    def fastforward(self,sound): 
        #print self.sound.status() 
        if (sound.status() == AudioSound.PLAYING): 
          t = sound.getTime() 
          sound.stop() 
          if (sound.getPlayRate() == 1.0): 
            sound.setPlayRate(0.5) 
          else: 
            sound.setPlayRate(1.0) 
          sound.setTime(t) 
          sound.play() 
        
          
    def playpause(self,sound):
           if(sound.status()==AudioSound.PLAYING):
            t=sound.getTime()
            sound.stop()
            sound.setTime(t)
           else:
            sound.play()

w = World() 
run()