function addToQueueRecursive(
  spatialNode,
  visibilityPlaneMask,
  that,
  frameState,
) {
  const { camera, context, pixelRatio, frameNumber } = frameState;
  const { positionWC, frustum } = camera;
  const screenHeight = context.drawingBufferHeight / pixelRatio;
  const screenSpaceErrorMultiplier = screenHeight / frustum.sseDenominator;

  spatialNode.computeScreenSpaceError(positionWC, screenSpaceErrorMultiplier);

  visibilityPlaneMask = spatialNode.visibility(frameState, visibilityPlaneMask);
  if (visibilityPlaneMask === CullingVolume.MASK_OUTSIDE) {
    return;
  }
  spatialNode.visitedFrameNumber = frameNumber;

  const primitive = that._primitive;
  const shape = primitive._shape;
  const targetScreenSpaceError = primitive.screenSpaceError;
  const priorityQueue = that._priorityQueue;
  const keyframeCount = that._keyframeCount;
  const previousKeyframe = CesiumMath.clamp(
    Math.floor(that._keyframeLocation),
    0,
    keyframeCount - 2,
  );
  const nextKeyframe = previousKeyframe + 1;

  // Create keyframe nodes at the playhead.
  // If they already exist, nothing will be created.
  if (keyframeCount === 1) {
    spatialNode.createKeyframeNode(0);
  } else if (spatialNode.keyframeNodes.length !== keyframeCount) {
    for (let k = 0; k < keyframeCount; k++) {
      spatialNode.createKeyframeNode(k);
    }
  }
  const { screenSpaceError, keyframeNodes } = spatialNode;
  const ssePriority = mapInfiniteRangeToZeroOne(screenSpaceError);

  let hasLoadedKeyframe = false;
  for (let i = 0; i < keyframeNodes.length; i++) {
    const keyframeNode = keyframeNodes[i];

    keyframeNode.priority =
      10.0 * ssePriority +
      keyframePriority(
        previousKeyframe,
        keyframeNode.keyframe,
        nextKeyframe,
        that,
      );

    if (
      keyframeNode.state !== KeyframeNode.LoadState.UNAVAILABLE &&
      keyframeNode.state !== KeyframeNode.LoadState.FAILED &&
      keyframeNode.priority !== -Number.MAX_VALUE
    ) {
      priorityQueue.insert(keyframeNode);
    }
    if (keyframeNode.state === KeyframeNode.LoadState.LOADED) {
      hasLoadedKeyframe = true;
    }
  }

  if (screenSpaceError < targetScreenSpaceError || !hasLoadedKeyframe) {
    // Free up memory
    spatialNode.children = undefined;
    return;
  }

  if (!defined(spatialNode.children)) {
    spatialNode.constructChildNodes(shape);
  }
  for (let childIndex = 0; childIndex < 8; childIndex++) {
    const child = spatialNode.children[childIndex];
    addToQueueRecursive(child, visibilityPlaneMask, that, frameState);
  }
}
@param {SpatialNode} spatialNode
@param {number} visibilityPlaneMask
@param {VoxelTraversal} that
@param {FrameState} frameState

@private