setMorphAnimationData method

  1. @JSExport()
JSPromise<JSAny?> setMorphAnimationData(
  1. ThermionEntity entity,
  2. JSArray<JSArray<JSNumber>> animation,
  3. JSArray<JSString> morphTargets,
  4. JSArray<JSString>? targetMeshNames,
  5. double frameLengthInMs,
)

Implementation

@JSExport()
JSPromise setMorphAnimationData(
    ThermionEntity entity,
    JSArray<JSArray<JSNumber>> animation,
    JSArray<JSString> morphTargets,
    JSArray<JSString>? targetMeshNames,
    double frameLengthInMs) {
  try {
    var morphTargetsDart = morphTargets.toDart.map((m) => m.toDart).toList();
    var animationDataDart = animation.toDart
        .map((x) => x.toDart.map((y) => y.toDartDouble).toList())
        .toList();

    var morphAnimationData = MorphAnimationData(
        animationDataDart, morphTargetsDart,
        frameLengthInMs: frameLengthInMs);
    var targetMeshNamesDart =
        targetMeshNames?.toDart.map((x) => x.toDart).toList();
    if (animationDataDart.first.length != morphTargetsDart.length) {
      throw Exception(
          "Length mismatch between morph targets and animation data");
    }
    var result = viewer
        .setMorphAnimationData(
      entity,
      morphAnimationData,
      targetMeshNames: targetMeshNamesDart,
    )
        .onError((err, st) {
      _logger.severe("ERROR SETTING MORPH ANIMATION DATA : $err\n$st");
      return null;
    });
    return result.toJS;
  } catch (err, st) {
    _logger.severe(err);
    _logger.severe(st);
    rethrow;
  }
}