Issue with setTexOffset

I am attempting to animate a texture by using a LerpTexOffsetInterval. However, when I attempt to use setTexOffset it doesn’t seem to work. I load and texture a model using:

ts0 = TextureStage('texstage0')
trailmat = Material("material")
uvtex = loader.loadTexture('../models/tex/testuv.png')
testuv = loader.loadModel('../models/testuvnotex.glb')
testuv.setTexture(ts0, uvtex, 1)

And I create a copy with a TexOffset with:

uvcopy = NodePath('copy')
uvcopy.setTexOffset(ts0, 400, 6)

When I do this, there is no difference in textures. Any help is appreciated!

I think that the problem may simply be that you’re using whole numbers: The space in which UV-coordinates operate isn’t that of the associated texture’s width and height. Instead, it’s a normalised space: one in which the full extent of the image in both width and height is given coordinates running from zero to one.

This means that an offset of less than the entire width/height of the image would have an offset-value between zero and one. As a result, any whole-number offset simply ends up with the texture being offset by its entire width/height (possibly multiple times over, depending on the number)–and if the texture is set to repeat (to “tile”) then it will thus appear no different.

So, for example, to shift a texture by half its width, you would set the relevant texture-offset value to 0.5–regardless of the size of the texture. Conversely, an offset of, say, 3 in the dimension of its width will shift the image by three times its width.

1 Like

That was it, thanks!

1 Like