computeJointsPerSurface method

Map<int, List<Matrix4>> computeJointsPerSurface(
  1. Map<int, ProcessedNode> processedNodes
)

Implementation

Map<int, List<Matrix4>> computeJointsPerSurface(
  Map<int, ProcessedNode> processedNodes,
) {
  final jointTransformsPerSurface = <int, List<Matrix4>>{};
  final surfaces = mesh?.surfaces ?? [];
  for (final (index, surface) in surfaces.indexed) {
    final globalToLocalJointMap = surface.jointMap;
    if (globalToLocalJointMap == null) {
      continue;
    }

    final jointTransforms =
        (globalToLocalJointMap.entries..sortedBy((e) => e.value))
            .map((e) => e.key)
            .map((jointIndex) {
              final joint = joints[jointIndex];
              if (joint == null) {
                throw StateError('Missing joint $jointIndex');
              }

              final jointNodeIndex = joint.nodeIndex;
              final jointNode = processedNodes[jointNodeIndex];

              final transform = Matrix4.identity()
                ..multiply(jointNode?.combinedTransform ?? Matrix4.identity())
                ..multiply(joint.inverseBindMatrix);

              return transform;
            })
            .toList();

    jointTransformsPerSurface[index] = jointTransforms;
  }

  return jointTransformsPerSurface;
}