Hi guys, i had the same problem about animating textures on real time, and i decided to share how i resolved the situation.
First the video texture:
We will need a jpg file with sequencial images in it.
lets say we have 10 frames of 320x240 then we will need to create an image canvas size of 3200x240 and put each frame side by side.
for example:
this image is 1600x300= 4 frames * 400 each x height (300)
Setup the scene:
Well start blender, delete the default cube and add a plane
Split an uv image editor window
With plane selected enter edit mode, press U, Reset (we got our uvs)
Open the image file at uv image editor.
The uvs should cover all the image so we need to stretch to 400 px
Well, select the right most uvs, press G, X, -1200 (4 images x 400 px width)
Exit edit mode now.
We should see the first frame on the plane.
The gamelogic
Press F4 and lets logic.
Select the plane.
Lets create some properties we will need
1.- The timer. click the big “Add property” buttom, name it “now” (without quotes) ,change the type float to timer and click D for debug.
2.-Add an int and name it “frame”, click “D” for debug too.
3.-Add an int and name it “curframe”
4.-Add a float, name it “imgwidth” with value 400
5.-Add a float, name it “videolg” with value 1600
We will need some python scripting so dont panic, its very simple.
Create a text script (Text Editor window) and name it “animtex” for example
Once we have our text file created. with the plane selected lets add an Always sensor with pulse mode true (this is the first “” buttom) attached to a python controller
associated to our “animtex” script
Now lets write the script:
#here we are retrieving the controller(cont), the plane(obj), and the property "frame"
#inside the plane
cont = GameLogic.getCurrentController()
obj = cont.getOwner()
#we can change fps value to set the time speed
fps=1
obj.frame = int(obj.now*fps)
#here when "frame" changes, we retrieve the plane´s mesh(me), inside the mesh
#we retrieve the materials(mats), inside the materials we retrieve the vertexs(vertex)
#inside the vertex we retrieve the uvs (uv).
if obj.frame!=obj.curframe:
me = obj.getMesh()
for mats in range(me.getNumMaterials()):
for vtx in range(me.getVertexArrayLength(mats)):
vertex = me.getVertex(mats,vtx)
uv = vertex.getUV()
#once we got the uvs we can play with them
#in this case each time obj.frame changes, we translate the uvs on x axis(uv[0])
uv[0]+=(obj.imgwidth/obj.videolg)
#uv[1]+=obj.imgwidth/500.0
vertex.setUV(uv)
obj.curframe=obj.frame
this is the blend file.
http://cid-d4c4ffac4d29c5ac.skydrive.live.com/self.aspx/P%c3%bablico/animtex.zip
Hope that helps.