def main():
    parser = argparse.ArgumentParser(description='Progressively loads a scene')
    parser.add_argument('--capture', '-c', metavar='motioncap.json', type=argparse.FileType('r'),
                        help='File of the motion capture to use for the camera. If not specified, keyboard and mouse controls are enabled.')
    parser.add_argument('--scene', '-s', metavar='scene.json', type=argparse.FileType('r'), required=True,
                        help='Scene file to render.')
    parser.add_argument('--show-stats', action='store_true', default=False,
                        help='Display on-screen statistics about scene while loading')
    parser.add_argument('--dump-screenshot', '-d', metavar='directory', help='Directory to dump screenshots to')
    parser.add_argument('--cache-dir', metavar='directory', help='Directory to use for cache files')
    parser.add_argument('--priority-algorithm', choices=priority.get_priority_algorithm_names(),
                        help='The algorithm used for prioritizing tasks')
    parser.add_argument('--priority-input', metavar='vars.json', type=argparse.FileType('r'),
                        help='Input file for priority algorithm if chosen type is FromFile')
    parser.add_argument('--cdn-domain', metavar='example.com')
    
    args = parser.parse_args()
    
    outdir = None
    if args.dump_screenshot is not None:
        outdir = os.path.abspath(args.dump_screenshot)
        if os.path.exists(outdir) and not os.path.isdir(outdir):
            parser.error('Invalid screenshots directory: %s' % outdir)
        elif not os.path.exists(os.path.join(outdir, 'realtime')):
            os.makedirs(os.path.join(outdir, 'realtime'))
    
    cachedir = None
    if args.cache_dir is not None:
        cachedir = os.path.abspath(args.cache_dir)
        if os.path.exists(cachedir) and not os.path.isdir(cachedir):
            parser.error('Invalid cache directory: %s' % cachedir)
        elif not os.path.exists(cachedir):
            os.mkdir(cachedir)
    
    cache.init_cache(cachedir)
    
    if args.priority_algorithm is not None:
        algorithm = priority.get_algorithm_by_name(args.priority_algorithm)
        
        algo_inputs = []
        if issubclass(algorithm, priority.FromFile):
            if args.priority_input is None:
                parser.error("An input file must be specified for FromFile priority algorithm")
            algo_inputs = [args.priority_input]
        
        priority.set_priority_algorithm(algorithm(*algo_inputs))
    
    if args.cdn_domain is not None:
        open3dhub.set_cdn_domain(args.cdn_domain)
    
    app = loader.ProgressiveLoader(args.scene,
                                   capturefile=args.capture,
                                   showstats=args.show_stats,
                                   screenshot_dir=outdir)
    app.run()
def main():
    parser = argparse.ArgumentParser(
        description="Fully loads a scene and then captures screenshots based on a previous run of loadscene.py"
    )
    parser.add_argument(
        "--scene", "-s", metavar="scene.json", type=argparse.FileType("r"), required=True, help="Scene file to render."
    )
    parser.add_argument(
        "--screenshot-dir",
        "-d",
        metavar="directory",
        default=list(),
        action="append",
        help="Directory where screenshots were dumped and will be dumped",
    )
    parser.add_argument("--cache-dir", metavar="directory", help="Directory to use for cache files")
    parser.add_argument(
        "--priority-algorithm",
        choices=priority.get_priority_algorithm_names(),
        help="The algorithm used for prioritizing tasks",
    )
    parser.add_argument("--cdn-domain", metavar="example.com")

    args = parser.parse_args()

    screenshot_dirs = []
    for outdir in args.screenshot_dir:
        outdir = os.path.abspath(outdir)
        screenshot_dirs.append(outdir)
        if os.path.exists(outdir) and not os.path.isdir(outdir):
            parser.error("Invalid screenshots directory: %s" % outdir)
        elif not os.path.exists(os.path.join(outdir, "groundtruth")):
            os.makedirs(os.path.join(outdir, "groundtruth"))

    cachedir = None
    if args.cache_dir is not None:
        cachedir = os.path.abspath(args.cache_dir)
        if os.path.exists(cachedir) and not os.path.isdir(cachedir):
            parser.error("Invalid cache directory: %s" % cachedir)
        elif not os.path.exists(cachedir):
            os.mkdir(cachedir)

    cache.init_cache(cachedir)

    if args.priority_algorithm is not None:
        algorithm = priority.get_algorithm_by_name(args.priority_algorithm)
        priority.set_priority_algorithm(algorithm())

    if args.cdn_domain is not None:
        open3dhub.set_cdn_domain(args.cdn_domain)

    app = FullSceneScreenshotLoader(args.scene, screenshot_dirs)
    app.run()