Ive got a billboardSceneNode which always faces the camera and represents the players avatar as a 2d sprite in a 3d world like paper mario. Id like to give it walk and attack animations. How can I do that?
Is there a function that will let me change the uvs or update the texture somehow? Is there a demo?
Thanks!
How to animate a texture on a billboardSceneNode?
Re: How to animate a texture on a billboardSceneNode?
One quick idea might be to use createTextureAnimator for each animation and then attach/detach those animators depending on frame.
It works, but has the slight downside that you need one texture per animation frame. Which is fine for a while until at one point the game might become too big and this slows things down due to the amount of textures you get that way (cheaper to have one big texture with all animation frames on it).
You can use billboardNode->getMaterial(materialIdx). getTextureMatrix(textureIdx) to get a texture matrix you can modify. A mixture of setTextureScale and setTranslation (both functions of the matrix class) might be of use for this case. Which you can call on each update or write your own animator doing that for you.
Modifying the UV's directly is not yet suported in Irrlicht 1.8, but Irrlicht svn trunk version got a getMeshBuffer function added now (generally Irrlicht svn trunk is better to use anyway).
It works, but has the slight downside that you need one texture per animation frame. Which is fine for a while until at one point the game might become too big and this slows things down due to the amount of textures you get that way (cheaper to have one big texture with all animation frames on it).
You can use billboardNode->getMaterial(materialIdx). getTextureMatrix(textureIdx) to get a texture matrix you can modify. A mixture of setTextureScale and setTranslation (both functions of the matrix class) might be of use for this case. Which you can call on each update or write your own animator doing that for you.
Modifying the UV's directly is not yet suported in Irrlicht 1.8, but Irrlicht svn trunk version got a getMeshBuffer function added now (generally Irrlicht svn trunk is better to use anyway).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: How to animate a texture on a billboardSceneNode?
Thanks CuteAlien. I see that a texture matrix is created with an x and y size (I assume in pixels) and a column and row paramater which I assume indicated how many rows and cols the matrix will create.
However setTranslation takes a vector3 an input. Im not really sure what setTranslation is doing with that vect3. I assume that setTranslation would take a vec2, one int for the row and one for the col and somehow display only the portion of the texture that lies in that row and col?
I cant seem to find any documentation for these function?
However setTranslation takes a vector3 an input. Im not really sure what setTranslation is doing with that vect3. I assume that setTranslation would take a vec2, one int for the row and one for the col and somehow display only the portion of the texture that lies in that row and col?
I cant seem to find any documentation for these function?
Re: How to animate a texture on a billboardSceneNode?
Ah sorry, I meant setTextureTranslate not setTranslation.
So the idea was - use a big texture with lots of sprite animations. Scale down to the size of single one (scale by factor of spriteSize/textureSize) with setTextureScale. And then setTextureTranslate can move around the texture. Not sure about offset right, but it's probably between 0 and 1 - so 0.5 moves half the texture.So one pixel would be 1/textureSize (in each direction).
Note: I've not done this myself yet, just assuming this might work.
So the idea was - use a big texture with lots of sprite animations. Scale down to the size of single one (scale by factor of spriteSize/textureSize) with setTextureScale. And then setTextureTranslate can move around the texture. Not sure about offset right, but it's probably between 0 and 1 - so 0.5 moves half the texture.So one pixel would be 1/textureSize (in each direction).
Note: I've not done this myself yet, just assuming this might work.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: How to animate a texture on a billboardSceneNode?
Thanks for the response. Everything you said does work. Im about to modify CAnimatedMeslSceneNode and copy the way it uses timers and callbacks to keep up with the current frames.
I also found this thread viewtopic.php?t=22301&start=30
They animate using
Would that approach be better?
I also found this thread viewtopic.php?t=22301&start=30
They animate using
Code: Select all
Device->getVideoDriver()->draw2DImage(texture, position, frame[num], 0, 0, true);Re: How to animate a texture on a billboardSceneNode?
It's basically the lowest-level approach to draw 2d things (video driver functions are very close to the hardware drivers of the OS). If that's all you need then it's usually fine. But no 3d features then - so what is in front depends on what is drawn last. No easy zooming in/out, no camera support. You just draw images at given positions. Example 06.2DGraphics is working like that.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: How to animate a texture on a billboardSceneNode?
Oh got it. Ill go with your approach! Thank you so much for all your help!