addBoneAnimation method

  1. @override
Future<void> addBoneAnimation(
  1. ThermionEntity entity,
  2. BoneAnimationData animation, {
  3. int skinIndex = 0,
  4. double fadeInInSecs = 0.0,
  5. double fadeOutInSecs = 0.0,
  6. double maxDelta = 1.0,
})
override

Enqueues and plays the animation for the specified bone(s). By default, frame data is interpreted as being in parent bone space; a 45 degree around Y means the bone will rotate 45 degrees around the Y axis of the parent bone in its current orientation. (i.e NOT the parent bone's rest position!). Currently, only Space.ParentBone and Space.Model are supported; if you want to transform to another space, you will need to do so manually.

fadeInInSecs/fadeOutInSecs/maxDelta are used to cross-fade between the current active glTF animation ("animation1") and the animation you set via this method ("animation2"). The bone orientations will be linearly interpolated between animation1 and animation2; at time 0, the orientation will be 100% animation1, at time fadeInInSecs, the animation will be ((1 - maxDelta) * animation1) + (maxDelta * animation2). This will be applied in reverse after fadeOutInSecs.

Implementation

@override
Future<void> addBoneAnimation(
    ThermionEntity entity, BoneAnimationData animation,
    {int skinIndex = 0,
    double fadeInInSecs = 0.0,
    double fadeOutInSecs = 0.0,
    double maxDelta = 1.0}) async {
  var boneNames = animation.bones.map((n) => n.toJS).toList().toJS;
  var frameData = animation.frameData
      .map((frame) => frame
          .map((q) => [
                q.translation[0].toJS,
                q.translation[1].toJS,
                q.translation[2].toJS,
                q.rotation.x.toJS,
                q.rotation.y.toJS,
                q.rotation.z.toJS,
                q.rotation.w.toJS,
              ].toJS)
          .toList()
          .toJS)
      .toList()
      .toJS;

  await _shim
      .addBoneAnimation(
          entity,
          boneNames,
          frameData,
          animation.frameLengthInMs.toJS,
          animation.space.index.toJS,
          skinIndex.toJS,
          fadeInInSecs.toJS,
          fadeOutInSecs.toJS,
          maxDelta.toJS)
      .toDart;
}