Jump to content

Skeleton Animation


Recommended Posts

I'd like to animate a rigged 3d model I'm loading from a .babylon file, as concluded in the previous topic:


I read the following according to @JohnK's suggestion:




I'm using blender. Does @JCPalmer's Blender Exporter export skeletons with animations created in blender?

In other words, would I be able to simply animate a model in blender and then call scene.beginAnimation(skeleton...) to animate the loaded skeleton in bjs?

Link to comment
Share on other sites

Sounds good, thank you :)

Until I figure out some problems with my rigging on the blender forums, do you perhaps have a rigged model that I can play with?

Also - what is the maximum number of bones per mesh (/per scene?) that you would recommend? I need this to work on mobile devices with high performance (hopefully 60 fps).

Link to comment
Share on other sites

@royibernthal : here you go:


As for the number of bones - depends on your hardware target.

1.) Desktop - I have run 66 bones on my PC with a reasonable video graphics card.

2.) If you are using  a laptop with no dedicated graphics card - <40

3. Mobile device - @JCPalmer : recommends <30

The base model that I provide above has 33. However, it is possible to delete 8 thumb/finger bones, the jaw bone, the two eye bones and the two toe bones. Just depends on what type of animation you are looking at. So, for example, if there is no walking about you may not need the toe bones.

Just remember, if you delete bones to make sure the parts of the mesh they were associated with get re-weight painted.

cheers, gryff :)


Link to comment
Share on other sites

Vertex shaders have a minimum requirement to support 128, vector4, uniforms.  Desktop implementations typically exceed the minimum, iOS & Android do not.  Each bone is a mat4, which is 4 vector 4's.  The theoretical max on mobile is therefore 128 / 4, or 32.

Scanning default vertex shader, I see these uniform reservations:


// Uniforms

uniform mat4 view;
uniform mat4 viewProjection;

#ifdef DIFFUSE
uniform mat4 diffuseMatrix;
uniform vec2 vDiffuseInfos;

#ifdef AMBIENT
uniform mat4 ambientMatrix;
uniform vec2 vAmbientInfos;

#ifdef OPACITY
uniform mat4 opacityMatrix;
uniform vec2 vOpacityInfos;

uniform vec2 vEmissiveInfos;
uniform mat4 emissiveMatrix;

uniform vec2 vLightmapInfos;
uniform mat4 lightmapMatrix;

#if defined(SPECULAR) && defined(SPECULARTERM)
uniform vec2 vSpecularInfos;
uniform mat4 specularMatrix;

#ifdef BUMP
uniform vec3 vBumpInfos;
uniform mat4 bumpMatrix;





You need to be extremely careful not include types of textures like AMBIENT, OPACITY, EMISSIVE, LIGHTMAP, or SPECULAR, unless your bone count is low.

Assume you need DIFFUSE & BUMP that is 16. World Matrix is 4.  Point cloud is 1 / 4 (round up to 1).   Clip plane is 1.  Fog is 0.  If you use need LOGARITHMICDEPTH that is 1 / 4 (round up to 1).

If mesh receives shadows, there is 4 per light.  Blender exporter allows you to reduce max lights.  Not sure I got it all.

Link to comment
Share on other sites

@gryff Thank you :) I started to experiment on it. Animation is indeed simple to export and run, amazing.


@JCPalmer Thank you very much for the detailed explanation :)

2 Questions:

1) On mobile, would the limit be 32 bones per scene or per mesh?

2) I'd just like to make sure I'm understanding what you wrote correctly - If the meshes receive shadows, each mesh "costs" 8 instead of 4 vector 4's, meaning the max bones drop to 16. Is that correct?

Link to comment
Share on other sites

Sorry for being slow - 

1) 128 vector 4's limit refers to the whole scene and not to each mesh, right?

2) Does vec2 count as half vec4? Is there a reason why you round up non-integer or is just to be on the safe side?

3) Assuming I have 1 mesh with a diffused texture and 1 light. Is the following correct?

Total vector 4's limit: 128

view - 4
viewProjection - 4
diffuseMatrix - 4
vDiffuseInfos - 0.5
vLightmapInfos - 0.5
lightmapMatrix - 4

Vector 4's left before falling to CPU: 128-17=111 (enough for around 27 bones)

4) Is the Vector 4's minimum requirement to support going to increase on mobile in WebGL 2?

Link to comment
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.

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.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...