Hi everyone , im starting using babylon to create a game, and im struggeling a lot attaching the weapon to the right hand. I want them to be joined from children nodes , in this particular case i want the weapon get attached from the child node same1_low to the righthand node from the character .
Both assets are loaded with gltf, the character asset has a bone but not the katana, How i can do this ?.
Here an example in the playground of what im trying to do Babylon.js Playground . As you can see it get mess up.
Could you please take a look and give me some advice to manage this ?
Thank you
Thank you a lot for your response Heaust-ops,
Its what i need but this way requires as you did to set the position from the root mesh. Without setting the quaternion and position the sword get attahed from the middle instead from the handler , i was trying to find a way that the sword get attached to the right hand by one of its sub nodes in this case is called same1_low , so we probably only need to set quaternion and will be much easier to fit the sword in the position it needs.
Do you know what requires to do this or if it is possible ?
Judging by playground, I think this is not going to work like that. If you want to use Mixamo animations, there is no guarantee that individual bones of different animations use the same rotations even if the pose does look the same. For example, Mixamo have a couple of rifle animations. But the wrist (mixamorig:RightHand) might be slightly rotated. You will see this instantly if you transition between animations.
I have not figured out a way to automaically fix that so if there is one please share
What I do is insert a “WeaponGrip” bone into the Mixamo rig - which I have to manually adjust per animation. Then you can attach the weapon to that bone.
First of all, regardless of centering on the lower part of the Katana (same1_low submesh), please note that the hand bone is not exactly the right place, you will always need a position offset any way.
As you can see, @Heaust-ops has added manually some position shift so that the katana is centered :
What you want is to be able to choose which submesh of the katana is going to be centered on the bone you have chosen. You can do this by accessing this submesh, and using its position, multiplied by 0.01 (because the root of the skeleton is scaled 0.01). Its basically about finding by code what @Heaust-ops has found manually.
But still, due to some rotation issue, I had to switch X and Z, etc, etc…
And the offset to be added (to have the katana IN the hand) is due to the position of the bone hand (mixamorig:RightHand) which is NOT the middle of the finger, but at the wrist. This info is neither in the bone transform, neither in the katana transform.
If the goal is to deal with a collection of weapons, and load them automatically, What I would advice is :
Reexport all you assets centered on the point where you want it to be hold (at least you eliminate the position offset)
Edit a .JSON for each asset, adding some custom rotation (eventually position offset as well, so that you can edit without reeporting again).
Automatically read the JSON along with each GLB file, and add the right offset
Thank you for your response Joe_Kerr .
I think attach to the bone doesn’t work when importing from gltf and we have to use transformed nodes seting the parent. How do you attach to the bone any mesh or transform node ?
Thank you for your response Tricotou.
do you know if there’s a way to make the bones visible , so i can see what is the failure in babylonjs? According to blender the righthand bone start in the wrist and ends when the thumbs start.
About the suggestions i do not get the first one
“Reexport all your assets , centered on the point where you want it to be hold”.
There is no a fixed position, i mean it is attached to the hand and the position of the hand changes dinamically. Could you expand on this point a bit ?
and in Babylon the default mesh.attachToBone just works fine. I use glb/Mixamo combo, too. The difference is I write a .json per “weaponGripBone” per animation. Either way works (what saves most time in the particular setup).
N.b. you center the weapon mesh on where it should be placed in the hand.