applyBoneTransform method

Vector3 applyBoneTransform(
  1. int index,
  2. Vector3 target
)

Applies the bone transform associated with the given index to the given position vector. Returns the updated vector.

Implementation

Vector3 applyBoneTransform(int index, Vector3 target) {
  final skeleton = this.skeleton;
  final geometry = this.geometry!;

  _skinIndex.fromBuffer(geometry.attributes["skinIndex"], index);
  _skinWeight.fromBuffer(geometry.attributes["skinWeight"], index);
  _basePosition..setFrom(target)..applyMatrix4(bindMatrix!);
  target.setValues(0, 0, 0);

  for (int i = 0; i < 4; i++) {
    final weight = _skinWeight[i];
    if (weight != 0) {
      final boneIndex = _skinIndex[i].toInt();
      _matrix.multiply2(skeleton!.bones[boneIndex].matrixWorld,
          skeleton.boneInverses[boneIndex]);
      target.addScaled(
          _vector..setFrom(_basePosition)..applyMatrix4(_matrix), weight);
    }
  }
  target.applyMatrix4(bindMatrixInverse);
  return target;
}