MackeyK24

InstancedMesh With Separate Skeleton ???

Recommended Posts

Do anybody know if its possible to create a class Like InstancedMesh BUT use a separate skeleton... So I can either clone or build up a skeleton for each instancedMesh to use... that way each instanced mesh could play a separate animation... Don't know if its possible with the current InstancedMesh class but maybe can be re-write a class of subclass that can handle using a seperate skeleton... Maybe just wishful thinking :)

Yo @Deltakosh do you think would be possible at all ???

 

Share this post


Link to post
Share on other sites
On 8/11/2017 at 7:32 PM, Deltakosh said:

Not possible because of how instances work. They cannot have different info than the root.

If you want different skeletons you need to use clone

Well actually, I do have a working proof of concept of "skinned instancing" in my fork of Babylon.js. I based the implementation on a "famous" nvidia's presentation.

Basically, it works like this:

  1. Bake skeleton matrices into a RGBA texture
  2. Assign each instance two numbers: animationIndex and animationFrameOffset
  3. Send these two numbers as instanceData: (most hacky part - 16 attribute limit per instance i believe)
    // Replace the zeroes in the matrix with animation data ;)
    this._instancesData[offset+3] = instance._animationIndex;
    this._instancesData[offset+7] = instance._animationFrameOffset;
  4. In the vertex shader, use animationIndex and animationFrameOffset to lookup the skeleton matrices using texelFetch
  5. Fix the world matrix (by inserting zeroes where we inserted animationIndex and animationFrameOffset)
  6. Multiply the world matrix with skeleton matrices fetched from the texture in step 4.
  7. animationFrameOffset is incremented in registerBeforeRender for running animations per-instance.

That's basically all that I needed to  do. Of course, bear in mind that:

  • not every animation-related functionality is supported,
  • it is just a basic POC of independently animated instances,
  • it only works on WebGL2

I'm happy to share the (ugly) code if you're interested or contribute the functionality to Babylon.js if the community wants to have this feature. But of course, my code only proves it should be doable and is far far from anything production-ready :)

I'll also try to post a video of it later today.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.