Can thin instances be animated?

I’m trying to switch over to using thin instances, but am scratching my head on how I can animate things when they are clicked?

What options do I have there?

It is a pretty good question for @Evgeni_Popov :slight_smile:

With thin instances you can only update their matrices to update the translation/scaling/rotation. Maybe you can fake what you want to do by creating a real mesh once a thin instance is clicked and animate this mesh instead?

Gotcha, I could definitely see that working.

Can a thin instance be removed/deleted, or hidden/shown, or does the whole thing need to be rebuilt? I can just use an add stuff to a buffer, including removing the thin instance.

Animating a tile might look like:

  1. Remove thin instance
  2. Create an instance in it’s place
  3. Animate the instance
  4. Delete the instance
  5. Add a thin instance in it’s place

Create a regular mesh instead of an instance. You can’t have both instances and thin instances for a mesh.

Seems that cloning of the original mesh is also possible - https://playground.babylonjs.com/#217750#49

There is a playground example with animated instances here: Advanced instanced buffer control | Babylon.js Playground (babylonjs.com) :smiley:

1 Like

The new Vertex Animation Texture system might be able to help you. It was just released in alpha61.

  1. use a picker normally. There’s a good demo in the docs
  2. bake the animations and load them.
  3. set the animation parameters array with your animation. You can set the start/end animations for the same frame to keep that instance still, and set to the correct frames to animate the object.

I’m not sure how @Evgeni_Popov forgot about it, because he just helped me A LOT to write that PR. I think he was traumatized from reading my code and having to fix it so much :wink:

1 Like

I did not forget about it :slight_smile:

But in my understanding @douglasg14b does not need bone animations but more standard anims (see some others posts where he is animating a hex cell when clicking on it). It’s easier to do it by updating the thin instance matrix directly.

I got this working by building a small abstraction layer around my thin instances, so that when I need to animate one it removes the thin instance, puts an instance in it’s place, animates it, removes it in the callback, and replaces it with a thin instance.

Works pretty well, though if I have many animations triggering while other animations are going I notice that thin instances at the end of the buffer vanish and come back.

I might instead just move the thin instances off screen, and then back on screen to avoid changing the count.


@carolhmj I was looking at that earlier, it’s pretty neat, though that’s a pretty CPU-bound way to animate (Unless I misunderstand normal animations), and there are difficulties with managing more complicated animation curves that way, as well as many different animations occurring at the same time.

@brunobg That’s pretty neat! Though probably a bit too much for my needs right now. However, I may find I need to use it in the future, so that’s good to know about.