Im thinking if this way of doing animated textures is a good idea: to have all of the frames loaded with loadTexture() and stored in a list and then run a task with node.setTexture(texturelist[i]) each frame (or depending on a specified framerate)?
Is this fast? Maybe theres a better way? (like creating sequenceNode, which I dont know much about).
or you could use only one texture, a tilesheet one!
greetz
dirk
'''
Created on 29.05.2011
@author: dirk hochegger
'''
from direct.showbase.DirectObject import DirectObject
from pandac.PandaModules import TextureStage
from pandac.PandaModules import NodePath ,CardMaker
class tileSHEET():
def __init__(self,speed,raws,cells,tex):
self.timer=0
self.offsetV = 0
self.offsetU = 0
self.u = 0
self.v = 0
self.speed = speed
self.raws = raws
self.sizeRAWS = 1.00/self.raws
self.cells = cells
self.sizeCELLS = 1.00/self.cells
self.ts = TextureStage('ts')
self.tile = self.createCARD(tex,
self.sizeCELLS,
self.sizeRAWS)
taskMgr.add(self.anim,"anim")
def createCARD(self,
tex,
sizeCELLS,
sizeRAWS):
card = CardMaker("tilesheet")
tile = NodePath(card.generate())
tile.reparentTo(render2d)
tile.setTexScale(self.ts,sizeCELLS,sizeRAWS)
tile.setTexture(self.ts, tex)
return tile
def setPOS(self,
x,
y,
z):
self.tile.setPos(x,y,z)
def swap(self,
timer):
self.tile.setTexOffset(self.ts,self.offsetU,self.offsetV)
if (self.timer > self.speed):
self.timer =0
self.offsetU+=self.sizeRAWS
self.u+=1
if (self.u >= self.cells):
self.u = 0
self.v+=1
self.offsetU = 0
self.offsetV+=self.sizeCELLS
if (self.v >= self.cells):
self.v= 0
self.offsetV = 0
def anim(self,
task):
self.timer+=1
self.swap(self.timer)
return task.cont
No, thats not an option (too many frames to colsolidate into a single texture).
then i would write my own picture format, which supports layers. or using existing ones, like gif, tiff ,…
I don’t think that answers my question either.
You can see from my first post that I’m asking for an advice on how is a good way to do it when you have a series of image files which are meant to replace each other.
why not using a video texture?
transparency
gif supports transparency!
please, just read my answer (*) very slowly and try to think a bit while readin it!
you only have to converte your images into one gif sequence thats all.
and a video format can also support transperancy, of course im not sure if the panda video player supports a alpha channel. so you would be in need to to write your own.
and of course you could do a sequence stream (dynamical preloaded), but really do you want to have “tousands” (depends on the length of the sequence) of files in a folder?
sorry, that i have to talk on that way with you!
(*) the answer from above!
Saying sorry after implying that im too retarded to understand your post is not changing much you know
I think you will help me more by simply not replying.
GIF has it’s issues. And I dont even know if panda supports it (as a video texture).
Many people actually do use hundreds of images to form a video texture. Even panda’s sample program for animated billboards uses individual images. Just because it doesn’t seem convenient to you, doesn’t mean it is. And when Im asking how to do something one way you don’t have to convince me to do it another way if you can’t give a reason other than preference.
really you are to strange for me!
im off of this thread!
Please, guys, let’s keep it civil in here.
Loading a set of separate PNG files should work fine. You can easily load a whole series of them with a glob pattern, and then switch them around every frame. It’s not going to take up more disk space than combining them into a single file.
Hm, OK. Im not worried about memory, but the speed of reading a file / unloading another one each frame.
def myFunc(task, img):
tex = loader.loadTexture(img)
np.setTexture(img)
# remove texture, not sure whats the method for this
return task.cont
You could just preload them and store them in a list. Depends on how many of them you will use.
I’m not sure. I think knowing how egg-texture-cards and the SequenceNode work could help.
For example 100 frames of one of my explosion effects are 3 mb in size. There will probably not be more than 10 of such effects loaded at once. I guess its what’s better: load around 12 kbyte image each frame or have around 30 mb in memory.
And I’m not sure if having few lists with few hundred string members each is a good idea too.
To calculate memory usage, you have to look at the uncompressed size, not the size of the file on disk. The uncompressed size is xsize * ysize * 4 for an RGBA texture.
You usually can’t realistically stream images from disk on demand; the load process is too slow. You have to preload them all if you’re going to go this route.
This is the same thing that egg-texture-cards does for you. It creates an egg file with all of the textures preloaded. When you display the egg file, it automatically rotates through all of the textures. You can either use egg-texture-cards for this, or you can do it yourself with a list of preloaded textures and a task; it amounts to the same thing.
Note that you can also use alpha with a movie file. Create one RGB movie file, and a separate grayscale movie file for the alpha channel. You can load them up into a single texture with the two-parameter form of loadTexture().
David
Hm, OK. I thought they were streamed.
Are video textures also not streamed? I think music files work like that.
Video textures are streamed.
So… wouldn’t it be a good idea to stream this as well?
It would be around 262 kbytes per frame.
Animated billoards are only one of hte ways Im going to use this. I’ll also need it for around 30 seconds title screen movie with transparency.
Video textures are streamable because they’re video textures, and the underlying video library handles the streaming. Individual textures are not streamable because they’re individual textures and have to be loaded individually.
If you want it to be streamed, then convert it to a video texture.
David
OK, I understand now.
Video texture supports video files which use lossy compression, right?
Can I have another black/white video texture for the transparency then? But since that video file for the transparency is lossy, then it’s a bad idea to use it for transparency right?
What do you suggest?
Maybe theres a format I don’t know about which will support both transparency and losless compression (I only need this for the alpha channel)?