def find_blend_shape_directory_by_blend_shape_idx(blend_shape, idx):
    """
    Find the target directory of the given blend shape index.

    If it's not found, return the root directory.
    """
    for directory in blend_shape.targetDirectory:
        # childIndices will be None if there are no entries.
        if idx in (directory.childIndices.get() or []):
            return directory

    # If we can't find it, return the root directory.
    return blend_shape.targetDirectory[0]