Convert Sprite to Mesh

BlitzMax Forums/MiniB3D Module/Convert Sprite to Mesh

Kittomer(Posted 2012) [#1]
Just a quick question: Is it somehow possible to convert a TSprite into a TMesh?

I tried Addmesh and casting (haha), but while it produced no errors nothing seemed to happen, either.

I'm asking this since right now I'm creating grass in my game by the way of sprites and it would be dapper if I could merge them all into a single mesh so that I only have to expend one drawcall on it.

I could swear to remember that MiniB3D does some singlesurface stuff with sprites, but considering how much framerate suffers when I have a moderate amount of grass sprites in my scene, I tend not to believe that.

If there is no easy way to do that, I guess I will have to put the mesh together manually, not like I don't know how that works. I would prefer the easy way, though.


AdamRedwoods(Posted 2012) [#2]
Tell you what...

Here's my TBatchSprite for monkey+minib3d, but you'll have to convert it to BlitzMax yourself. If you do, please repost it so others can benefit. I was going to do this afterwards, as I have several methods of speeding up BMax minib3d.

Conversion Notes:

- has no Copy() method, instead use CreateSprite()

- you'll have to convert over monkey-specific classes like IntStack

- make sure the batchorigin is not the came as the camera (0,0,0). i may have to add a check in here for this.



Other thoughts re: Grass sprites
.... so when rendering sprites as one mesh, you lose alpha depth sorting (order independent depth sorting anyone? bleh).

Therefore, you would have to use Alpha testing mask (but no alpha), which means you'll get fringe artifacts on your transparent pngs.
Or you could just render the mesh first (set origin far away from camera) and handle cases where grass overlaps transparent objects
(ie. glass cylinder in open fields, will render over the grass if the grass batch sprite is transparent)

Last edited 2012


Kittomer(Posted 2012) [#3]
Thanks, I'll look into it!
Although I'm not sure I need something quite that comprehensive.
Also I know nothing about monkey.

Being on the subject, how likely is it that my code will just... work if I'd just copy it into monkey, if I don't use anything except standard blitzmax and minib3d code?


AdamRedwoods(Posted 2012) [#4]
re: copying into monkey

from blitz to monkey, you might do ok, but i would also hesitate and say no, monkey has too many 'gotchas' that will require some thinking if portability is a requirement.


Kittomer(Posted 2012) [#5]
Converting that code was a bit above my head, so I ended up adapting my chunk meshing code to build a single grass mesh. Is a lot faster now.