Jump to content

Attach mesh to bone


joshcamas
 Share

Recommended Posts

Hi,

 

DK appears to have already pointed to one key reason why you might be observing unexpected behaviors of a meshs' vertices - and more problematically the mesh's local axis when animating a weighted mesh using one or more bones in a skeleton.  But if I understand correctly, I might be able to explain what is happening on a larger scale.  Most people generally aren't aware that the local axis of a mesh which is weighted to one or more bones is not being driven (or generally affected at all unless parented to the bone) by the bone(s) when these bone(s) are animated.  Once weighted, bones only drive a mesh's vertices, and depending on which 3D software you used to bind the mesh to the bone, the local axis of any weighted mesh will behave differently from the axis of the bone to which it is weighted.  So if you want to affect the local axis of any mesh by animating a bone, then it must be done through parenting - or if conditional behavior is required, then a proceedural process may be used for which this can dramatically vary from scene to scene, depending on many factors.

 

Also, depending on which software you used to export your mesh or scene, there is always more than one matrix which is calculating pitch, roll, and yaw in cartesian space using quaternions which are displayed as x, y, and z.  I know some of this is likely remedial info, but there is no way around the way in which bones move a mesh weighted to them, as it is generally quite predictable.  You also generally want to either parent - or weight a mesh to a bone - but never both; and use extreme caution in how you set up your parenting if the mesh is weighted to any bones in any hierarchy.  I almost never parent a weighted mesh to it's skeleton or any part of a skeleton hierarchy unless I'm simply using the bone to drive the mesh's local axis as a parent.  So if you are experiencing odd behavior, it may be due to both wieighting a mesh to a bone which may also be set up as a parent of the mesh or the mesh's hierarchy.  As previously mentioned, this is almost always a very bad thing to do.  And in addition, there are often other dependancies which many programs have set up - often as a "feature" -  which can cause indescribable object and vertex behavior.

 

I know I keep promising to post documentation on the doc site addressing many of the practices, terminology, nuances, etc. of dimensional space and axis' as represented in most 3D software; and I promise I will find time to do so very soon, as this info is often directly related to many of the questions I see posted, and often try and explain such behaviors observed when animating or manipulating axis' (matrices) in cartesian space.  Again, I hope this very general overview might help explain what you may be seeing in the behavior of your object.

 

Cheers,

 

DBawel

Link to comment
Share on other sites

Okay... I'm pretty sure I understand what you are saying.

Basically moving bones only moves vertices, yes? If so, then good - I assumed this before. 

Also, it is impossible (as far as I know) to parent to a bone - so no problems there.

However.... are you saying parenting to any mesh is bad?

 

Here's a question - ok, so lets say you wanted to scale the skeleton. So a leg swings really far. To do this you simply scale the mesh, correct?

Is there a local and global scale for a mesh?

 

Also, attached the lab system to the pg:

 

http://www.babylonjs-playground.com/#11BH6Z#12

Link to comment
Share on other sites

Nice walk cycle, by the way. :)

 

Yes, when a mesh is weighted to a skeleton, bones will only affect transforms on mesh vertices (translate, rotate, scale), and not affect the mesh axis.  The mesh axis will only be transformed by a bone if parented to a bone.  This can be highly usable especially for translation and rotation without affecting deformation.  Just make sure you're never both parenting to a bone and weighting (binding) to the same bone or skeleton hierarchy as well.  If you want to parent to a bone and the software your using won't allow this, you may need to use software such as Maya or Motionbuilder which you can then write out an FBX file or export out the mesh parented to the bone and the mesh's local axis will transform with the bone's axis to which it is parented.  This is very useful for props such as swords, weapons, etc - where you want the weapon to move with the hand, but remain rigid and not deform on the vertex level when bones are transformed.  But you don't want to scale your mesh on it's local axis if it is weighted/bound to a skeleton.  You want to transform the bones that the vertices are weighted/bound to.

 

Also, you can transform most any object to either it's local or the global/world axis.  However, if you want to scale "extend/extrude" a mesh such as a leg, then if you want to do this using scaling, you definately have to scale the bone to which the mesh is weighted on it's local axis, so the vertices transform along the bones local axis.  Transforming a mesh to the global axis will be quite messy.  Usually the z axis runs down the length of the bone - depending on which software you used to bind the mesh to the skeleton.  So you most likely want to scale on only the z axis (or appropriate single axis running the length) of the bone in which the leg mesh is weighted - if you want to extend the leg to be longer un-naturally - using scale.  

 

However, depending on which bone you scale, this will also affect the bone's children which can look quite bad and really un-natural.  So if you want to extend the leg for a kick that will make the leg un-naturally longer, then I wouldn't scale - I would set up your skeleton hierarchy in a way that allows you to physically translate the leg bones down their parent's z axis, and I would personally do this by using a null as a parent to the thigh bone and translate this in the direction of the axis that would extent the leg to make it appear longer - if you really wanted to do this.  I would translate and scale on the bones themselves as little as possible, as this can cause unwanted deformations - especially since the leg is most likely bending as well - however, if parented to a null, it's far more controllable and you can orient your null parent any direction and on any axis that is optimal to transform.  This also allows you to bend the leg at the same time without unwanted/un-natural vertex deformations.  I hope this make sense.  It takes a bit of playing around with different configurations of parenting to null objects or other small bones used only for the translation - and experimenting with different hierarchies to make it work optimally.  Good luck.

Link to comment
Share on other sites

  • 2 weeks later...

I haven't worked on this. Sadly I don't think I'll know how to do it, so if someone has the time/wants to do it, please do lol

 

@dbawel - the problem is, you can't parent to the bone. It don't work. So we need to find a way to replicate the position/rotation/scaling of the bone, aka emulate parenting. How do you do this?

 

I still don't know exactly how to get the correct position of the bone. Could someone make a playground of it if they know how?

 

Thanks!

Link to comment
Share on other sites

  • 4 weeks later...
  • 1 month later...

No there is not yet a suitable solution. you can attach an object to a bone, but it must be able to manage the movement of this object that follows the bone on which the object is attached. Relationship subject to the mesh does not work.

Link to comment
Share on other sites

http://www.html5gamedevs.com/topic/3736-babylonboneprototypesetabsoluteposition/?p=28846  Not sure if pertinent, but what the heck. 

 

I'm looking for a very small, simple playground demo with a few bones and a mesh "weighted" onto them... but I'd prefer no importing.  Basic babylon mesh hanging-on some basic bones... and I want to see it all in wireframe... and I want to bounce the bone, and play with the bindings, and gravity, and and and... ahem.  Anyone seen one?

 

When my gramma would stir soup in her kitchen, her big ol' chunk of hanging arm fat would weeble and wobble, and me and my brother would jump up there and clamp onto it with our teeth, and hang there... swinging back and forth.  Fun!

Link to comment
Share on other sites

It's really such a shame this isn't possible with BabylonJS. I think many people will go with other frameworks because of this - since many people want to make some sort of RPG game which includes possibilities to change outfit and similair features.

Link to comment
Share on other sites

DK,

 

You are awesome.  I use bones and bone hierarchies as a religion to solve for so many varying issues in animation, as the behavior of bone chains in a hierarchy is unique and provides paractically any variation needed when animating objects and their children.  As we've been reading in many posts recently, this can solve so many issues, however, most people associate bones with deformations and characters - when they are invaluable inserting in object hierarchies and animating.

 

So without a formal request (at least from me,) you made life a whole lot easier for everyone.  Thank you.  Now we all need is to provide examples in using bones for other purposes than just surface deformations and animation.  This will really make a difference to anyone who experiments a bit with "non-traditional" uses of bones and bone chains.

 

BRAVO!  :D

Link to comment
Share on other sites

  • 2 months later...

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...
 Share

  • Recently Browsing   0 members

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