export function resolveLinksTransform()

in modules/core/src/utils/transform.js [32:63]


export function resolveLinksTransform(links, streams, streamName) {
  const transforms = [];
  let parentPose = links[streamName] && links[streamName].target_pose;

  // TODO(twojtasz): we could cache the resulting transform based on the entry
  // into the link structure.

  let missingPose = false;

  // Collect all poses from child to root
  while (parentPose) {
    if (!streams[parentPose]) {
      missingPose = true;
      break;
    }
    transforms.push(streams[parentPose]);
    parentPose = links[parentPose] && links[parentPose].target_pose;
  }

  // Resolve pose transforms. If missingPose is true, which can happen if a
  // persistent link is defined before normal state has been sent, ignore it
  // TODO(twojtasz): Flag stream affected by missingPose so it can be reported
  // by application
  if (!missingPose && transforms.length) {
    // process from root to child
    return transforms.reduceRight((acc, val) => {
      return acc.multiplyRight(new Pose(val).getTransformationMatrix());
    }, new Matrix4());
  }

  return null;
}