Jubber

Hi there -

this is probably a very simple problem but I've not stumbled over the answer yet. My Art Monkey has just sent me a model with an animated gif file attached. XNA complains about this texture so presumably gifs are not yet supported. Is there a way round this For instance a simple way to apply a texture to a model, or change the UV coordinates a model is using, so I could have a big bitmap with the necessary graphics on it and just change the UV Or even some way to load a bitmap into another structure, perhaps a Texture3D, which I've just noticed, and apply it to a model.

Apologies if this is painfully simple or has been covered elsewhere.

Cheers

Robin.



Re: XNA Game Studio Express animating textures

wakawaka54

The problem is you are assigning an animated gif to a model. An animated gif has a different format than just a regular gif. I haven't really checked out the 3D part of XNA. I'm currently working on a 2D Halo game therefore I might not give the best answer but I will give you a solution. First, I would get a program that turns that animated gif into a several gifs (because an animated gif is just a bunch of gifs compressed into one and put on a cycle). Then after this I would put those gifs into one bitmap file with equal spacing (Place them in equal rows, or columns). After this, I would create a class that would cycle there these frames (by getting the bitmaps data then assigning a part of it to the model). I think this would work but you would need to right a bit of code.

Hope this helps...

wakawaka54!!!!!!

13 year old genius

PS. By placing them in columns and rows I mean like making a sprite sheet (look up tilesheet or sprite sheet on google and you will get examples).






Re: XNA Game Studio Express animating textures

Jon Watte

Three options:

1) Texture sheet the individual frames. Put them all in a long row, if they'll fit, or put them in a grid, into a large texture. Scale and offset the U/V using either the texture matrix, or a multiply/add on the UV coordinates in your custom vertex shader.

2) Extract each individual frame into a separate texture. Swap out which texture is being used on the effect when the model is drawn.

3) Bake the texture frames into a 3D texture. Change the "Z" coordinate of the U/V based on what frame to play. This won't look right if you get lots of MIP mapping, but will work well for many other cases. Again, with a custom vertex shader, you can select the frame to play as an effect parameter.






Re: XNA Game Studio Express animating textures

creasso

Hi Jubber!

I have almost the same problem and wakka told me about the Texture2D.Getdata( ) and Texture2D.Setdata( ) methods, one of their overloads have a sourcerectangle that we can use to get just part of our texture inside an array that can feed another "temporary" texture. So after build the sprite map we can try update the texturing with just some texture sectors. I did not have tested this yet to tell you about performance but I bet that have everything to work fine.

Best!





Re: XNA Game Studio Express animating textures

Jubber

Hi chaps - thanks for the responses. I've not yet even touched vertex shaders, so that might have to wait - but the various suggestions you've all posted make me think just loading up some bitmaps as textures and using effect.texture = textures[anim_number] will do the trick. I'll also have a look at matrix calculations on textures as suggested by Jon (not sure what that is yet, but sounds interesting). If I need only one texture in a model animated I can always get my Art Monkey to export two models, one with just the polys that need texture animation. Bit laborious, but will work, which is the main thing. Creasso and Waka - thanks for the tips about texture2D - another avenue to explore. Will report back if all works like clockwork.

Cheers,

Jubber

P.S. as an aside - anyone have trouble getting effect.alpha = n to do anything to a model Perhaps the associated texture needs an alpha channel or something else in the pipeline needs to be turned on. Bear in mind I don't know diddly about effects yet and am using the basic one.





Re: XNA Game Studio Express animating textures

parlance

The correct and most efficient method for animating a texture is to compile the frames of animation into a larger 2D texture, and modify the texture matrix depending on the frame of animation you would like to display. Attempting copy texture data using Texture2D.Getdata() and Texture2D.SetData() is horrendously inefficient because of the huge amount of memory that it would require to copy to video memory each time the frame of animation changes. Furthermore, with the problem would become compounded when dealing with more than 1 object sharing the animated texture with a different current frame in it's animation.

As far as getting blending to 'do something' goes, the texture doesn't necessarily need an alpha channel for certain kinds of blending, but for others, you will. See this post to learn a little about how blending works:

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1068970&SiteID=1





Re: XNA Game Studio Express animating textures

Jon Watte

To get alpha to work, you have to turn on alpha blending in the output, and set alpha functions for srcblend and destblend.






Re: XNA Game Studio Express animating textures

Aki pl

Do You have some programs to make that sprote sheet I made 5 png pics from animated gif. Now i want to put all of them on one big png and then change coordinates. But program that makes rows will help me much.

Must this rows be the same Because I have standing fighter and kicking. And second one is bigger. (wide)




Re: XNA Game Studio Express animating textures

parlance

Aki pl wrote:
Do You have some programs to make that sprote sheet I made 5 png pics from animated gif. Now i want to put all of them on one big png and then change coordinates. But program that makes rows will help me much.

Must this rows be the same Because I have standing fighter and kicking. And second one is bigger. (wide)

For simplicity's sake when generating the source rectangle used for drawing your sprite, you may want to use uniformly sized and spaced frames in your large texture, but nothing is preventing you from using non-uniformly spaced or sized frames. You just need to store the information somewhere (I would do this in a seperate xml file per sprite) that represents the source rectangle for each frame. It's probably just easier to use uniformly sized and spaced frames.





Re: XNA Game Studio Express animating textures

LeeC22

Could anybody post a small, example project of this... I have been considering animated textures as my brain goes numb trying to figure out vertex shaders Little examples like this are great supplements to the rather lacking documentation I find. I know from experience, with the few I have written for people, they take about 5 - 10 mins but save others hours.

A simple cube, 4 frame texture and the basiceffect (if you can do this with basiceffect)

I'm assuming you could do animated water or similar with this if you lay out 2 tileable textures side by side and shift the texture matrix across the texture, resetting it when it got to the end.