Vizard 7 » Tutorials & Examples » Example scripts » Texturing » Swapping
7.5

Texture swapping

\examples\tex_lighting\swapping.py

This script demonstrates how to quickly swap textures on and off an object to create the illusion of motion. If you already have a AVI or MPEG files, then elsewhere in the tutorial is an example that shows how to directly use video files. That's easier to use if you don't need the level of precision control that the texture swapping methods gives you.

"""
This script demonstrates how to perform texture swapping.
It displays a sequence of images onto a quad,
creating the illusion of a movie.
"""
import viz
import vizact
import vizinfo

viz.setMultiSample(4)
viz.fov(60)
viz.go()

vizinfo.InfoPanel()

FRAME_RATE  = 10        # in Hertz

#Create cycle of textures
movieImages = viz.cycle( [ viz.addTexture('launch_stills/sts90launch%d.jpg' % i) for i in range(1,32) ] )

#Add and position the movie screen
screen = viz.addTexQuad()
screen.setPosition([0, 1.82, 1.5])
screen.setScale([4.0/3, 1, 1])

#Setup timer to swap texture at specified frame rate
def NextMovieFrame():
    screen.texture(movieImages.next())

vizact.ontimer(1.0/FRAME_RATE, NextMovieFrame)