Animating sprites in 3d and 2d. Is it the same?

Blitz3D Forums/Blitz3D Programming/Animating sprites in 3d and 2d. Is it the same?

Cubed Inc.(Posted 2011) [#1]
hey
I think I have a pretty good question. Is animating sprites in 3d the same as animating sprites in 2d, or are there different functions for animating a sprite in 3d then there is in 2d?

The reason i'm asking is becuase I am currently learning how to animate sprite like these for a 3d game.

http://www.spriters-resource.com/other_systems/pm/sheet/10746

I would greatly appreciate if someone would explain it to me.

DISCLAIMER : paper mario is in copyright of nintendo. I nor blitz3d owns them.

Last edited 2011


Rroff(Posted 2011) [#2]
Its generally worth avoiding blitz3d built in (3D) sprites and either implementing your own or licensing/using a 3rd party sprite library... the built in ones have potential compatibility issues on some setups and aren't great performance wise compared to a single surface sprite system.

Last edited 2011


Cubed Inc.(Posted 2011) [#3]
...huh?
I'm a little confused on what your saying. What i'm asking is if animating a sprite is done the same way in 3d as it is in 2d and if so, how do you do it?

Here's and example
http://www.youtube.com/watch?v=WoGJd0k_FR8

The characters are animated sprites in a 3d world. That's what I am trying to pull of in bliz3d


Gabriel(Posted 2011) [#4]
He's saying (among other things*) that Blitz3D doesn't come with any functionality to automatically use sprite sheets like those in 3D. If you want to use sprite sheets, you either have to use a library or write your own.

* He's also pointing out that even if you did write your own, using them with Blitz3D sprites can also have compatibility issues. I thought those were all/mostly fixed now, but I could be wrong.

Last edited 2011


Rroff(Posted 2011) [#5]
I think the Windows 7 sprite issues are mostly fixed with the latest patch but even so there are systems where the built in Blitz3D sprite commands can have issues - even ignoring that tho performance with the built in sprites isn't great so it pays in the long run to look at 3rd party sprite libraries rather than use the built in stuff.

You can probably use loadanimtexture with createsprite - not sure really as I've avoided the built in sprite commands from the off due to known issues and implemented my own from scratch.


Kryzon(Posted 2011) [#6]
Is animating sprites in 3d the same as animating sprites in 2d, or are there different functions for animating a sprite in 3d then there is in 2d?

From what I understand of the technique, it is a little bit different. First, mostly blitzers use the word 'sprite' for this 3D element. In other circles it's known as 'billboard', 'particle' or 'quad'.

Each billboard is commonly formed by two triangles.



The billboard must have the same size ratio as the texture to be mapped into it.
So, say each frame of your paper character is 256x256 pixels. This has a 1 : 1 ratio, and any square billboard will serve, no matter the size of it (1x1, 5x5, 3.795x3.795 etc.), as long as both sides serve the ratio.
This is very important, because if the billboard has a different size ratio than the texture frame you are using, the texture will be distorted to fit properly.

To change the frame or texture sheet, you change the current texture applied to the billboard with EntityTexture().
This change is persistent, which means you don't need to keep calling EntityTexture() every game-cycle unless there is a reason to change frame or change texture-sheet. It's not like it's going to make a difference to keep applying the same texture to a mesh that already uses it.

To change the current frame, use
EntityTexture( mesh, texture, frame )

To change the entire texture, use
EntityTexture( mesh, texture ) ;With 'texture' being a different texture than the one currently applied to the mesh.

Every billboard in Paper Mario uses the eye-plane alignment. This means that each billboard is aligned, rotation-wise, to the camera, instead of pointing at it as some may think.
Each billboard has their own individual position and scale, but their rotation is always equal to the camera's. Using this image as guide, the eye-plane alignment would be the one on the left, the "single eye-vector". It is the same way Blitz3D's native sprites work.

Last edited 2011


Cubed Inc.(Posted 2011) [#7]
Kryzon
ahhhh....I think I see what you mean

Your saying that the actual sprite sheet would be animating the same way in 3d as it would in 2d, but it would have to be applied to the "billboard" as a masked animated texture in order to work.

So there really is no such thing as a "3d animated sprite". It's pretty much a masked animated texture on 2 triangles.

Am I correct or am I just confusing myself even more?


Kryzon(Posted 2011) [#8]
Yes, an animated texture behaves similarly to an animated image (within Blitz3D, at least).

You use LoadAnimTexture() to load an animated texture for 3D use, and LoadAnimImage() to load an animated image for 2D use.
These two functions have very similar parameters, and the sprite sheet you would use for an animated image can also be used for an animated texture (apply this animated texture to a billboard with the constraints mentioned above and you have your paper character).

If the texture is masked or not it's up to you, since you can use any of the texture flags and blend modes with your animated texture.
You can also use alpha blending to have smoother outlines if your texture has an alpha channel.


Cubed Inc.(Posted 2011) [#9]
Kryzon
Now it makes sense.
Do you know of any tutorial of how to use these methods in such a way? I'm new to pretty much all the commands used for something like this.


Gabriel(Posted 2011) [#10]
You can probably use loadanimtexture with createsprite - not sure really as I've avoided the built in sprite commands from the off due to known issues and implemented my own from scratch.

I'm sure you can, but unless my eyes deceive me, the spritesheet that TaGames linked to is a non-uniform spritesheet. It's packed so that each frame is a different number of pixels in size to the others. I don't think LoadAnimTexture can handle that, can it?


Cubed Inc.(Posted 2011) [#11]
Gabriel
If loadanimtexture can't handle it, can load animimage? If it can, then can the image be used as an animated masked texture?

Last edited 2011


Kryzon(Posted 2011) [#12]
Yeah, you're right. Giving it closer look... they really are strangely apart. EDIT: @TaGames: if you want to use that sheet you'll need to rearrange them so that LoadAnimTexture can grab them without clipping away important stuff.

Do you know of any tutorial of how to use these methods in such a way? I'm new to pretty much all the commands used for something like this.

Googling LoadAnimTexture came up with this:

http://www.jnoodle.com/Blitz3D/lesson4.html
http://blitzbasic.com/Community/posts.php?topic=40431#454013
http://blitzbasic.com/Community/posts.php?topic=38569#428113
http://blitzbasic.com/codearcs/codearcs.php?code=557

Last edited 2011


Cubed Inc.(Posted 2011) [#13]
Kryzon
Actually the sprites are supposed to be like that.

Take a look at this sprite sheet.
http://www.spriters-resource.com/other_systems/pm/sheet/10579

When luigi is walking, his body is supposed to bob up and down, becuase thats whats supposed to happen when you walk.

Now look at this one.
http://www.spriters-resource.com/other_systems/pm/sheet/7878

The sprites are perfectly lined up, becuase he's not supposed to walk nor bob up and down for any reason. He's only programmed to do so in the game, where luigi's run bob is put in directly, to save time I suppose.

Just wanted to explain that. Thanks for the tutorials! I was actually looking for the same exact one yesterday but I couldn't find it.

Odds are i'm still gonna be asking more questions so if you could try to keep an eye on this topic every once in a while, that would great:)

Last edited 2011


Kryzon(Posted 2011) [#14]
It's not that. If you circumscribe the first frame of the last row with its bounding box you'll see that the frames are not lined up.



LoadAnimTexture uses the same rectangle size for all frames. They all need to be evenly arranged, just like the imagestrip in that "lesson 4" tutorial.


Cubed Inc.(Posted 2011) [#15]
Kryzon
Is there anyway to increase the rectangle size?


Kryzon(Posted 2011) [#16]
No, it's the same for the entire texture.

You need to see which of your character's frames is the biggest, then create a texture grided with this biggest bounding box.
Then grab all frames from the original sheet and re-arrange them in this new texture.
Then erase the grid so it's not visible when you use the texture.


Cubed Inc.(Posted 2011) [#17]
Kryzon
Does the sprite sheets size have to be by the power of 2?


Gabriel(Posted 2011) [#18]
All textures are power of 2. If you try to create or load them with another size, they'll be automatically resized to the next (higher) power of 2.


Kryzon(Posted 2011) [#19]
If, with all your frames arranged, you don't end up with a power of two texture, then add some blank space so it becomes power-of-two.


Gabriel(Posted 2011) [#20]
Definitely. Or just use one of the imagepacker/texturepacker tools which get posted on the forums every now and again. They'll take a list of frames, build it into an animated texture and automatically pad/resize the texture to ensure that the final sheet is a power of two. They'll also export the pixel/texture coordinates in text file or xml file so that you can easily retrieve the information you need to show any frame at will. Unless you particularly relish the challenge of doing this stuff yourself, of course. Existing solutions do exist though.