MorphTargetData constructor

MorphTargetData({
  1. required int vertexCount,
  2. required int targetCount,
  3. required Float32List positionDeltas,
  4. Float32List? normalDeltas,
  5. Float32List? tangentDeltas,
  6. List<String>? targetNames,
  7. List<double>? defaultWeights,
})

Creates morph data covering targetCount targets of vertexCount vertices each.

positionDeltas holds targetCount * vertexCount * 3 floats; the optional normalDeltas and tangentDeltas match that shape (tangent deltas are xyz only, the bitangent sign always comes from the base tangent). targetNames and defaultWeights are padded/truncated to targetCount.

Implementation

MorphTargetData({
  required this.vertexCount,
  required this.targetCount,
  required this.positionDeltas,
  this.normalDeltas,
  this.tangentDeltas,
  List<String>? targetNames,
  List<double>? defaultWeights,
}) : targetNames = List.unmodifiable([
       for (var i = 0; i < targetCount; i++)
         (targetNames != null && i < targetNames.length)
             ? targetNames[i]
             : '',
     ]),
     defaultWeights = Float32List(targetCount) {
  if (positionDeltas.length != targetCount * vertexCount * 3) {
    throw ArgumentError(
      'positionDeltas has ${positionDeltas.length} floats; expected '
      '${targetCount * vertexCount * 3} for $targetCount targets of '
      '$vertexCount vertices',
    );
  }
  for (final (name, deltas) in [
    ('normalDeltas', normalDeltas),
    ('tangentDeltas', tangentDeltas),
  ]) {
    if (deltas != null && deltas.length != positionDeltas.length) {
      throw ArgumentError(
        '$name has ${deltas.length} floats; expected '
        '${positionDeltas.length} to match positionDeltas',
      );
    }
  }
  if (defaultWeights != null) {
    for (var i = 0; i < targetCount && i < defaultWeights.length; i++) {
      this.defaultWeights[i] = defaultWeights[i];
    }
  }
}