Spritesheet support for instanced meshes take 2

This is a continuation of a semi old conversation here Spritesheet example / support for instanced meshes? - Questions & Answers - HTML5 Game Devs Forum

I’m finally going back to this and created a playground to show a simple example of what I am trying to do with it. For one example: In my game, In order to not create 2 million advanced dynamic textures, I am creating instances of the numbers 0-9. Right now I am not using a sprite sheet, so I am loading 9 512x512 textures into GPU, with 9 master meshes to create instances from (yuck) - I would like to use a texture atlas instead, to get rid of 8 draw calls. SpriteManager does not work for me due to it not being a real mesh/parenting/animation issues.

I’m still having trouble wrapping my head around buffers/attributes, but specifically how I can use buffers/attributes to send the data for a particular sprite cell, for the fragment shader (and how to track which instance corresponds to which sprite cell). I’ve been trying to understand the code in the sprite manager class, however it’s confusing since it does so much. In my case I just want to take 1 master number mesh, and slice it up for each of the numbers, so that I can use createInstance on 1 master mesh instead of 9

Any chance you can help me fill in the blanks in the playground below @Deltakosh ?

(I’m hoping it’s much simpler than the sprite manager class since it is managing multiple sprites and drawing them all at once, but I’m not sure how much of the code is necessary to get to a working version).


I see nothing when running your example.
Can you tell me more about what you are not managing to get working?

Sorry I forgot you have to rotate camera a bit, fixed camera here


– basically trying to figure out how to use a single material as a spritesheet with actual instances support. In this example I am trying to create instanced meshes for the numbers 1-9, rather than what I am doing in my actual game, which is. Create 9 source meshes 1-9, with 9 textures, and then each time I need a 1, I create an instance of the 1 mesh. This is a small example, but I’d also be able to use this a bunch of other places in my game to make it much faster by reducing the amount of draw calls dramatically.

In the scene I have the spritesheet wired up, but I still am lost as to how to only display the 1,2,3,4 number, on an instance of a mesh.


@jerome the reason I don’t think my use case will work with SPS is because the numbers are all parented to individual meshes, parented to other individual meshes, etc. I don’t think SPS will allow for this use case unless I am missing something (i.e. attributes on cards, where each card is a mesh containing many children number meshes, as an oversimplified example).

maybe this : Babylon.js Documentation

The main issue with that is I need to be able to parent to other individual non particle meshes (which may or may not be moving/rotating throughout the scene). I don’t believe that’s possible with SPS unless missing something? I’d also like to be able to treat each thing as real actual meshes, which are a lot of the same problems as to why I can’t use spritesheet also.

@thrice sorry to take so long answering but caught up in other things.

In principle this is possible. In this PG digits are parented to the first digit and the first digit parented to the box and the box parented to sphere Babylon.js Playground

Instead of using box and sphere multiple times in the SPS you could add individual pairs of meshes in the same way.

Of course whether this is a practical solution for your project depends on what you want to do with the meshes.

Good luck and I hope you find a workable solution.

1 Like

@JohnK No worries at all!

Thanks for sharing, PG is interesting, however I think it still wouldn’t work for my use cae. Reason being, each of the meshes needs to be able to move independently and fit within the normal architecture of the scene, for many reasons, but action managers, animations, being important among them – But even if I could use the SPS to parent individual particles to a mesh outside of the particle system (which I don’t see in your PG, and that’s a base requirement of what I’d need to make it work), it still feels like SPS would be the wrong tool for the job

1 Like