Panda3D Manual: Texture TransformsIt is possible to apply a matrix to transform the (u, v) texture coordinates of a model before rendering. In this way, you can adjust the position, rotation, or scale of a texture, sliding the texture around to suit your particular needs. Use the following NodePath methods to do this: nodePath.setTexOffset(TextureStage, uOffset, vOffset); If you don't have a particular TextureStage, use
Note that the operation in each case is applied to the (u, v) texture
coordinates, not to the texture; so it will have the opposite effect
on the texture. For instance, the call The above methods apply a 2-d transform to your texture coordinates, which is appropriate, since texture coordinates are usually two-dimensional. However, sometimes you are working with 3-d texture coordinates, and you really do want to apply a 3-d transform. For those cases, there are the following methods: nodePath.setTexPos(TextureStage, uOffset, vOffset, wOffset); And there is also one generic form: nodePath.setTexTransform(TextureStage, transform); This last method sets a generic
TransformState object. This is the same kind of 4x4 transform matrix
object that you can get from a NodePath via e.g.,
Note that the texture transform is associated with a particular TextureStage; it is not a fixed property of the model or its texture coordinates. You can therefore apply a different texture transform to each different TextureStage, so that if you have multiple textures in effect on a particular node, they need not all be in the same place, even if they all use the same texture coordinates. For instance, this technique was used to generate the sample images in the Texture Blend Modes section. In fact, the following code was used to place this sample texture (excerpted): smiley = loader.loadModel('smiley.egg') and the resulting texture:
In the above example, we have applied a scale of (8, 4) to reduce the size of the decal image substantially, and then we specified an offset of (-4, -2) to slide it around in the positive (u, v) direction to smiley's face (since the (0, 0) coordinate happens to be on smiley's backside). However, these operations affect only the decal image; the original smiley texture is unchanged from its normal position, even though both textures are using the same texture coordinates. © Carnegie Mellon University 2010 |