TBatchSprite -- batch sprites for minib3d

BlitzMax Forums/MiniB3D Module/TBatchSprite -- batch sprites for minib3d

AdamRedwoods(Posted 2012) [#1]
TBatchSprite is an addon to minib3d which allows sprites to be drawn into one surface, thus saving opengl overhead and resulting in speed increases.

TO ADD:
- copy TBatchSprite.bmx into the minib3d/inc folder.
- add Include "inc/TBatchSprite.bmx" to the "minib3d.bmx" file.

TO USE:
- TBatchSprite.LoadBatchTexture(imagefile)
- entity=TBatchSprite.CreateSprite()
- entity is then treated like any other entity

- the base controller (TBatchSpriteMesh) can be controlled via batchmesh_entity = TBatchSprite.BatchSpriteEntity() or via LoadBatchTexture() and treated like any entity
- multiple batches: to CreateSprite(parent), set parent to specific TBatchSpriteMesh (via TBatchSprite.BatchSpriteEntity() or when loading)

LIMITATIONS:
- textures must be all the same (per batch)
- if camera and the controller (TBatchSpriteMesh) are in the same position, alpha problems may occur. to resolve, TBatchSprite.BatchSpriteEntity().PositionEntity(x,y,z)

----------------

TBatchSprite.bmx


Last edited 2012


AdamRedwoods(Posted 2012) [#2]
firepaint 3d example:



Last edited 2012


Pete Carter(Posted 2012) [#3]
You my friend are awesome :-)


Pete Carter(Posted 2012) [#4]
Ok can't get it to run I followed the above instuctions and I get an error

Compile Error: Identifier 'TBatchSprite' not found

I used Import sidesign.minib3d does that make any difference?


ima747(Posted 2012) [#5]
You might need to recompile your modules if you added it under there...


Pete Carter(Posted 2012) [#6]
God how stupid. thanks! think thats it now just to put the media in the right place


Pete Carter(Posted 2012) [#7]
Yes working now. I've just printed it out I must work out how this works :O)


Pete Carter(Posted 2012) [#8]
Ok just one question about Tbatchsprite. Its working great but is there a way to make the particles move with the emiter I thought i could parent the particles to the ship model but it compiles with no error but doen't make a difference the particles still don't move with the ship. I know the natural movement of the particles is realistic but it would look better in this intance if the particle did follow the ship. I may be misunderstanding how it works.


ima747(Posted 2012) [#9]
I haven't played with the above implementation but what did you try parenting, looks like theres a mesh as well as sprite extensions involved did you try parenting both?


Pete Carter(Posted 2012) [#10]
Thats what ive been trying but i must be missing something because i can't get it to work


AdamRedwoods(Posted 2012) [#11]
spritebatch.EntityParent(parent, false)

I think the default is true (true = keep global position, false = use parent position).


Pete Carter(Posted 2012) [#12]
Oh so it would effect all sprites not just the one batchcontroller?


Pete Carter(Posted 2012) [#13]
spritebatch.EntityParent(parent, false)


Where is this as its not in TBatchSprite or your sample?


Pete Carter(Posted 2012) [#14]
I'm also trying to get a second batch to work. Do you need a controller for each and how do you sort out the id. The introductions at the top of the page confuse me. I've tried looking at the comments in the TBatchSprite code but its very had to follow as the function and method names are so similar. Sorry I'm sure you are beginning to regret posting the code but I am very grateful.


AdamRedwoods(Posted 2012) [#15]
Yes, the code and example I wrote is very confusing, as it was done quickly.

re:Parenting
by each sprite entitiy
sprite.EntityParent(parent, false)
is just like any other entity in minib3d.

The trick comes when the "controller mesh" needs to be located for depth testing, if you have alpha sorting problems.


re:second batch
'' you will need to create each additional batch by an id number
'' id's can be 0,1,2,3,4, etc
'' then use that new batch controller as the parent (although it doesn't have to be the parent) to CreateSprite()
Local batch0:TBatchSpriteMesh = TBatchSprite.CreateBatchMesh(0)
local mysprite0:TBatchSprite = CreateSprite(batch0)

Local batch1:TBatchSpriteMesh = TBatchSprite.CreateBatchMesh(1)
local mysprite1:TBatchSprite = CreateSprite(batch1)


Let me know if you have problems with this. (I don't think I tested multiple sprites... shame on me!)

Also let me know if this is a bad implementation, as CreateSprite() could be broken out into CreateSprite(parent, batchmesh) or even CreateSprite(parent, batchid) instead for clarity.


Pete Carter(Posted 2012) [#16]
thanks for explaining much clearer now :O)


Sonic(Posted 2014) [#17]
hi Adam,

i wonder if you could clarify about how you'd go about implementing animated textures with this system?

or is that not possible?

cheers!


Sonic(Posted 2014) [#18]
never mind, i have implemented it, by passing texture coordinates. it works great. thanks for this, Adam!