Page 1 of 2

How to make a scrolling texture for conveyor belt

Posted: Sun Dec 18, 2005 4:38 am
by pfo
I've got a problem that's got me stumped: if I made a conveyor belt, how could I get the texture to scroll? I tried going through the vertices each frame and adjusting the UV coords, but getVertices() doesn't get the render buffer vertices. I suppose I could modify the engine to expose the render buffer vertices, but I'd rather not do that.

Another approach I thought of is using shaders, but I don't think it's possible for a shader to know what direction each conveyor is going in and how fast, unless I made conveyor belts move in only 1 direction at only 1 speed (boring....)

Anyone else got any ideas?

Posted: Sun Dec 18, 2005 4:10 pm
by Aquarius
I had the same problem when i was trying to improve the water-node. Its absolutely annoying that i did not find a way to adjust uvs. An animated texture or shaders are simply not the same.
Maybe some good soul who knows how has merci....












So you think you can tell, heaven from hell....

Posted: Wed Dec 21, 2005 10:10 am
by krama757
Use Emil Halim's Magic 2D library, its really awesome.

A bit hard to understand when you dont know whats in the library, but Emil is very nice and he will help ya out.

Posted: Wed Dec 21, 2005 11:02 am
by Guest
Ya saying his 2d library has code to scroll textures in 3d on meshes?

Posted: Wed Dec 21, 2005 11:11 am
by krama757
His library allows you to make scrolling textures and save them so that you can apply them to 3D meshes...yes :)

Posted: Wed Dec 21, 2005 11:51 am
by Guest
Assuming that a) Irrlicht lets you specify tiled textures and b) lets you modify the texture matrix the easiest way short of a vertex shader would be to apply a translation to the texture matrix (but reset it every once in a while before the values become too ridiculous).

texture matrix support would be very nice

Posted: Wed Dec 21, 2005 6:39 pm
by peterparker
I have to agree to Guests statement:
an Interface to the texture matrix would be very nice. Also some Quake3 shader can be supported more easy and a lot of vitality would be added to models and scenes if it were possible.

Peter

Posted: Wed Dec 21, 2005 9:04 pm
by krama757
Try out the Magic library before you bust out your shaders. I think it may solve your problems and give you some more speed.

Posted: Thu Dec 22, 2005 1:20 am
by pfo
Krama: I took a look at the Magic 2D library, and it's not clear to me what I could use in it to scroll a texture. Besides that, it works mostly with OpenGL, and what would I do for DirectX then?

Guest: (a) is correct, (b) I have no idea how to get that matrix, if I could find it somewhere and expose it that would save the day for me.

It's sad because I got the physics of the conveyor belt working, you'd think the scrolling texture would be easier.

Edit: more problems, this particular mesh buffer is contained in an IOCTTreeSceneNode, when that node gets created it creates additional mesh buffers from the mesh, making it impossible to differentiate which particular mesh buffer contains my conveyor texture (?!?). This would also explain why storing a pointer to the mesh buffer at creation and modifying it every frame doesn't work (that mesh buffer is not being rendered). I'm going to have to re-think this strategy, maybe make a special node for this purpose.

Posted: Thu Dec 22, 2005 1:27 am
by michael520
Ah, I encounter the same problem with texture-animation for a conveyor belt !
I am new on this, I think we should change the uv of vertexes in every frame so that the texture on the mesh would look animating... right?

Posted: Thu Dec 22, 2005 7:21 am
by Guest
pfo wrote:Guest: (a) is correct, (b) I have no idea how to get that matrix, if I could find it somewhere and expose it that would save the day for me.
That's a bit tricky then. You could probably just bypass the engine and do d3d or ogl calls yourself in some way, but that might introduce more trouble than it's worth, plus would break support for more than one api. The other option would include recompiling the engine after adding a few functions to get the texture matrix (or least set it). The last option would be resorting to shaders.

ATI advices to not change the texture matrix unless you really have to. I don't know how much impact it would have, but seeing their general "gently caress flexibility if it buys us 2fps more in benchmarks vs. nVidia"-approach and how using non-4byte-aligned vertex data turns 1200fps into 0.0001fps.. who knows.
For a shader you would simply specify an offset as shader constant and add a line to add that to the uv coords.

Though none of that solves the problem if you can't be sure which part to render with the shader/changed matrix. How complex is that belt? Without dropping the octtree I could only suggest making the actual belt using the texture its own mesh. As it technically uses a different material it should be anyway (and will surely end up as a seperate submesh one way or another).

Maybe the engine could be extended to support simple texture "animation" as a material property, specifying some kind of "transformation per second" or at least video like "frames". But these days I would still say "why add that kind of specialized functionality when there are shaders".

Posted: Thu Dec 22, 2005 9:42 am
by krama757
Well Magic also has a Direct X library that you can work with. If you want confirmation that a conveyer belt could be implemented with an animated texture just pm Emil Halim, he is very kind and will most definately answer.

Posted: Thu Dec 22, 2005 11:16 am
by Guest
krama757 wrote:Well Magic also has a Direct X library that you can work with. If you want confirmation that a conveyer belt could be implemented with an animated texture just pm Emil Halim, he is very kind and will most definately answer.
What exactly is your definition of an "animated texture" anyway? An animated gif? A video file? And what good would that be, when Irrlicht surely doesn't support either to be loaded as texture?

Posted: Thu Dec 22, 2005 8:35 pm
by krama757
Emils library allows you to do what irrlicht doesnt. If you see some of his examples he combines 2D and 3D....I believe you can load an animated gif or even an avi file as a skin for a mesh.

But I am a complete newbie to his library, please pm him.

Posted: Fri Dec 23, 2005 2:23 am
by pfo
I'm not really interested in a solution that uses an animated gif or movie to simulate the texture moving because I am using a physics engine and I want it to look realistic. Using an animated GIF or movie, and trying to calibrate it to work with any given conveyor belt at any given angle and have it correlate to the speed that the texture moves and the force the conveyor exerts sounds like a nightmare that would yield passable results at best. It seems the easiest way would be to calculate distances in 3d along the conveyor direction and use that to shift UV coordinates, probably via a custom scene node. I'm making my levels in DeleD, I wrote a custom loader so I could use the UserTag info in polygons as MetaData for my game. This way you could easily build levels in DeleD and import them into Irrlicht with lots of parameters setup automatically. I'm trying to make the MetaData as lite as possible, with an animated texture I'd have to reference each image's path each time I wanted to make one of these...
when Irrlicht surely doesn't support either to be loaded as texture?
Actually, Irrlicht does support sequences of textures for a material buffer with the texture animator. You could use it to load each frame of a GIF and control its animation speed. It also supports playing AVIs in texture, I think its in one of the examples, or someone on the forum did it.