Animated texture via atlas (fake particles)

I’m not a big fan of the Panda particle engine, and using animated textures as per manual (using a SequenceNode) turned out to be a performance killer. So I’ve decided to use the oldest technique in the book - pre-rendered particles merged into one big texture atlas. Turned out not that bad so I’m sharing.

this is how it looks:

Here’s the code + 3 sample particle-textures [NEW NEW LINK]:
sendspace.com/file/njg588

The class P2Pvfx is to make Point-to-Point effects like lightnings, rays etc. going from one NodePath to another.
The vfx class is for stationary effects.
The code could probably be improved - it’s just a working sample how it could be done.

If you have some frames on an animation saved as individual images you can merge them like this ( the code is for 64 frames 128x128 packed into one 1024x1024 texture):

from panda3d.core import *
import os, sys

dirname=sys.argv[1]
maps=[]
dirList=os.listdir(dirname)
for fname in dirList:
    if fname[-3:]=="png":
        maps.append(fname) 
    
final_img=PNMImage(1024, 1024, 4)    
x=-128
y=0
for index in xrange(len(maps)):
    x=x+128
    if x>1024:
        x=0
        y=y+128
    new= PNMImage()
    print maps[index]
    new.read(dirname+'/'+maps[index]) 
    final_img.copySubImage(new, x, y, 0, 0, 128, 128) 
    
final_img.write(dirname+'.png')
1 Like

I’ve added one more class ‘MovingVfx’ it’s like the classical vfx but the effect is moved with a ProjectileInterval from one Node to another (for fireballs and suchlike).
Here’s the new code and effect texture:
sendspace.com/file/sv7i3b

And if someone want’s to use the code posted in the last post about making a atlas from individual images, then there’s a typo there it should be ‘if x>=1024:’ at line 16 else one in eight images is skipped.

That’s quite neat! :slight_smile:

If I may suggest, it might be a good idea to allow an optional rotation (or random rotation) to cover the fact that it’s the same effect every time, and you might be able to create more complex effects yet if you allow the system to mix two or more sets of textures via Texture Stages – perhaps create a “mixedVXF” that takes in a variable number of texture-operator pairs to feed to the Texture Stages.

Nice snippet
I also used textured Line Nodes for effects like lightnings

Is there an updated link? Sendspace is saying the files have been deleted.

sendspace.com/file/njg588
also updated in the first post. These things disappear after some time if there are no downloads, p3dp.com seems dead and I don’t have a host of my own.

You might try Dropbox; I may well be mistaken, but I’m at the least not aware of them deleting files after a period of time.

What is the license on the code and demo vfx? Any way to stop the vfx from moving when I move the camera?

Whoa, this demo looks like exactly what I was looking for!

Are the files (code and images) available anywhere I can download them?

License is CC0, Public Domain, Do What You Want or any compatible.

You mean face the camera? If that’s it look in the code for

self.vfx.lookAt(base.camera)

and comment/remove that.
If there’s any other type of movement that it’s not intended.

I’m attaching the code to this post, hopefully it won’t get lost here:
vfx.zip (12.5 MB)

Thanks! This is a great snippet!