Panda3D Manual: Projected TexturesIn a previous section, we introduced ways to apply an explicit transformation to a model's texture coordinates, with methods like nodePath.setTexProjector(textureStage, fromNodePath, toNodePath) When you have enabled this mode, the relative scene-graph transform
from nodePath.setTexTransform(textureStage, fromNodePath.getTransform(toNodePath)) There is no need for either This has several useful applications. We have already introduced
one application, in conjunction
with Interval-animated texture transformsAnother handy application for a TexProjector is to enable the use of the various LerpIntervals to animate a texture transform. Although there are no LerpIntervals that directly animate texture transforms, you can make a LerpInterval animate a NodePath--and then set up a TexProjector effect to follow that NodePath. For example: smiley = loader.loadModel('smiley.egg') Note that you don't even have to parent the animated NodePath into the
scene graph. In the above example, we have set up the interval
Projected TexturesAnother useful application of the TexProjector is to implement projected textures--that is, a texture applied to geometry as if it has been projected from a lens somewhere in the world, something like a slide projector. You can use this to implement a flashlight effect, for instance, or simple projected shadows. This works because the TexProjector effect does one additional trick:
if the second NodePath in the To implement projected textures, you need to do three steps: 1. Apply the texture you want to the model you want to project it onto, usually on its own TextureStage, so that it is multitextured. 2. Put the 3. Call For your convenience, the NodePath class defines the following method that performs these three steps at once: nodePath.projectTexture(textureStage, texture, lensNodePath) For instance, we could use it to project the bamboo texture ("envir-reeds.png") onto the ripple.egg model, like this: You could move around the projector in the world, or even change the lens field of view, and the bamboo image would follow it. (In the above image, the camera model and the projection lines are made visible only for illustration purposes; normally you wouldn't see them.) This image was generated with the following code (excerpted; click here for the complete program): ripple = Actor.Actor('ripple.egg') © Carnegie Mellon University 2010 |