Panda3D Manual: Playing MPG and AVI files
  <<prev top next>>     

Panda now supports AVI format for textures in Panda.

Usage

myMovieTexture=loader.loadTexture("myMovie.avi")
myObject.setTexture(myMovieTexture)

there are also a bunch of utility functions (by default the texture loops)

myMovieTexture.play()
myMovieTexture.play(<first frame>, <end frame>)
myMovieTexture.loop()
myMovieTexture.loop(<first frame>, <end frame>)
myMovieTexture.stop()
myMovieTexture.pose(<frame to jump to>)


For powers-of-two limited graphics hardware

If your graphics hardware does not support non power-of-two texture, your movie texture size would be shifted up to the next larger power of two size. For example, it you have a movie of 640 x 360 in size, the generated texture would be actually 1024 x 512. The result is a partially textured object, i.e. the movie only covers some part (left corner) of your object. To work around this limit, you have to scale down the texture coordinate, so that it covers the whole object entirely. The following scene renders a movie texture on a full screen-wide card, and preserve the movie's proportion.

from pandac.PandaModules import NodePath, CardMaker, TextureStage
import direct.directbase.DirectStart

def createMovieScreen(movieName, screenWidth, loop=1):
    print 'MOVIE :',movieName
    movieTex=loader.loadTexture(movieName)
    if not loop:
       movieTex.play()
    movScale=movieTex.getTexScale()
    actualSize=(movieTex.getXSize()*movScale[0], movieTex.getYSize()*movScale[1])
    texRatio=actualSize[0]/actualSize[1]
    screenWidth*=.5
    screenHeight=screenWidth/texRatio
    print '  -> Actual size : %i x %i' %(actualSize[0],actualSize[1])

    CM=CardMaker('movie screen')
    CM.setFrame(-screenWidth, screenWidth, -screenHeight, screenHeight)
    card=NodePath(CM.generate())
    ts = TextureStage.getDefault()
    card.setTexture(ts,movieTex)
    card.setTexScale(ts,movScale)

    return card

support=["DOES NOT support","supports"]
nonPow2=base.win.getGsg().getSupportsTexNonPow2()
print '\nYour graphics hardware %s non power-of-2 sized texture.\n' %support[nonPow2]

base.setBackgroundColor(0,0,0,1)
screen=createMovieScreen('myMovie.mov', screenWidth=2*base.getAspectRatio(), loop=0)
screen.reparentTo(aspect2d)

run()


Issues

The video texure works by decoding on a frame by frame basis and copying into the texture buffer. As such, it is inadvisable to use more than a few high res video textures at the same time.

Certain encoding formats do not work. So far, DV format has been determined incompatible with Panda.

  <<prev top next>>