rendering non-particle sprites

How are you supposed to make sprites in Panda3D?

I can’t find any mention of sprites in the manual outside the context of particle rendering.

I know someone might say “why bother with sprites when you can render in full 3d?” but they do have uses, like, billboards, or imposters. Or suppose I wanted to make a 2d platform game that uses Panda3d’s scenegraph and collision detection functionality, then sprites would be nice.

I looked through the included tutorials and the forums, but I can’t seem to find a straight answer:
“Asteroids” & “Basic Animated Textures” and uses a plane.egg file which appears to be a simple quad, but motion trails uses base.win.getTextureCard() There also seems to be mention of a “cardmaker” function in the forums.

What is the diffenence between all these approaches, and is there a better way to make a sprite?

The CardMaker class is an object that generates a simple quad. It’s a convenient way to generate a quad at runtime; see the API documentation for the use of this class. Or, you can load a quad from an egg file, as in plane.egg; it amounts to the same thing.

Once you have a quad, you can texture it and use nodePath.setBillboardAxis() or setBillboardPointEye() or setBillboardPointWorld() to make it rotate to face the camera. This is the way billboards are normally constructed.

There’s a small cost per billboard, which won’t be a problem if you only want a handful of these to be onscreen at once. If you want to put hundreds or thousands of these things onscreen, similar to the way the SpriteParticleRenderer does, it’s a bit more complicated. In this case, construct a cloud of points, as described in the manual (use a GeomPoints object, and a GeomVertexWriter, and so on). Use one vertex for each sprite; the vertex describes the center of the sprite. To make the sprites render as perspective quads, instead of as points, do:

cloud.setRenderModePerspective(True)
cloud.setRenderModeThickness(1.0) # or whatever size you want
cloud.setTexGen(TextureStage.getDefault(), TexGenAttrib.MPointSprite)
cloud.setTexture(myTexture)

Now, you pay only a small cost per cloud, but all of the sprites in the cloud have to share the same texture.

David

Incidentally, base.win.getTextureCard() is something different. That retrieves a special quad that matches the alignment of the main window, specifically for the purpose of re-rendering to the main framebuffer, as in the particular special effect demonstrated by the motion trails demo.

David