royibernthal Posted September 27, 2016 Share Posted September 27, 2016 I'd like to animate a rigged 3d model I'm loading from a .babylon file, as concluded in the previous topic: http://www.html5gamedevs.com/topic/24180-3d-models-animations/ I read the following according to @JohnK's suggestion: http://doc.babylonjs.com/tutorials/Animations http://doc.babylonjs.com/tutorials/How_to_use_Bones_and_Skeletons 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? Quote Link to comment Share on other sites More sharing options...
gryff Posted September 27, 2016 Share Posted September 27, 2016 Answer to both your questions is - yes Simple Example But don't use skeletons with a huge number of bones - limit of hardware not the exporter. cheers, gryff royibernthal 1 Quote Link to comment Share on other sites More sharing options...
royibernthal Posted September 27, 2016 Author Share Posted September 27, 2016 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). Quote Link to comment Share on other sites More sharing options...
gryff Posted September 27, 2016 Share Posted September 27, 2016 @royibernthal : here you go: base_model 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 Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted September 27, 2016 Share Posted September 27, 2016 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: #include<bonesDeclaration> // Uniforms #include<instancesDeclaration> uniform mat4 view; uniform mat4 viewProjection; #ifdef DIFFUSE uniform mat4 diffuseMatrix; uniform vec2 vDiffuseInfos; #endif #ifdef AMBIENT uniform mat4 ambientMatrix; uniform vec2 vAmbientInfos; #endif #ifdef OPACITY uniform mat4 opacityMatrix; uniform vec2 vOpacityInfos; #endif #ifdef EMISSIVE uniform vec2 vEmissiveInfos; uniform mat4 emissiveMatrix; #endif #ifdef LIGHTMAP uniform vec2 vLightmapInfos; uniform mat4 lightmapMatrix; #endif #if defined(SPECULAR) && defined(SPECULARTERM) uniform vec2 vSpecularInfos; uniform mat4 specularMatrix; #endif #ifdef BUMP uniform vec3 vBumpInfos; uniform mat4 bumpMatrix; #endif #include<pointCloudVertexDeclaration> #include<clipPlaneVertexDeclaration> #include<fogVertexDeclaration> #include<shadowsVertexDeclaration>[0..maxSimultaneousLights] #include<logDepthDeclaration> 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. royibernthal, gryff and Wingnut 3 Quote Link to comment Share on other sites More sharing options...
gryff Posted September 27, 2016 Share Posted September 27, 2016 @JCPalmer : TY for the explanation Jeff. Good to get a handle on WHY. Currently playing with the "OpenSim" rig for MH1.1 - which has 26 bones but two "toe ends" can be deleted. It is a MH user contributed asset. cheers, gryff Quote Link to comment Share on other sites More sharing options...
royibernthal Posted September 27, 2016 Author Share Posted September 27, 2016 @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? Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted September 27, 2016 Share Posted September 27, 2016 1) Nope, depends on what else you do. Subtract accordingly. 2) Nope, 4 vector 4's per light. Add up all your extra stuff. Subtract it from 128, then divide by 4 to see max bones before forced to skin on the cpu, which is not good. Quote Link to comment Share on other sites More sharing options...
royibernthal Posted September 27, 2016 Author Share Posted September 27, 2016 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? Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted September 28, 2016 Share Posted September 28, 2016 1) per shader, in BJS terms a material 2) worst case. 3) try it. 4) No, there is a way to pass uniforms via buffers though. To take advantage, vertex shaders would need recoding. Quote Link to comment Share on other sites More sharing options...
royibernthal Posted September 28, 2016 Author Share Posted September 28, 2016 3) How can I try it and see how many vector 4's are used? Anyhow, I just wanted to know if I got the logic right. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.