How to put a weapon in a character's hand?

This is a hero model from WhyDungeons:

Hand has 4 bones (not meshes, bones in the armature) - shoulder, arm, hand, slot.
In code, the last bone is picked up by id:

As:

const slots = [];

model.traverse((child) => {
  const name = child.name.trim(); // Exported bones don't have dots in their names

  if (name.match(/^bone.*/)) {
    slots[name.split('bone')[0]] = child;
  }
});

// Character picked up a new legendary weapon? Add it to a slot.
if (slots.weapon && character.weaponObject) {
  slots.weapon.add(character.weaponObject);
}
2 Likes