Example #1
0
def main(argv):

    
    # use an ArgumentParser object to manage the program arguments.
    arguments = osg.ArgumentParser(argv)
    
    # set up the usage document, in case we need to print out how to use this program.
    arguments.getApplicationUsage().setApplicationName(arguments.getApplicationName())
    arguments.getApplicationUsage().setDescription(arguments.getApplicationName()+" is a utility for converting glsl shader files into char arrays that can be compiled into applications.")
    arguments.getApplicationUsage().setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...")
    arguments.getApplicationUsage().addCommandLineOption("--shader <filename>","Shader file to create a .cpp file for.")
    arguments.getApplicationUsage().addCommandLineOption("-h or --help","Display command line parameters")

    # if user request help write it out to cout.
    if arguments.read("-h")  or  arguments.read("--help") :
        arguments.getApplicationUsage().write(std.cout)
        return 1
    
    filename = str()
    if arguments.read("--shader",filename) :
        shader = osgDB.readShaderFile(filename)
        if shader.valid() :
            name = osgDB.getStrippedName(filename)
            path = osgDB.getFilePath(filename)
            invalidCharacters = "-+/\\*=()[]:<>,.?@'~#` not \""
            numbericCharacters = "0123456789"
            pos = name.find_first_of(invalidCharacters)
            while pos  not = str.npos :
                name[pos] = ord("_")
                pos = name.find_first_of(invalidCharacters)
            
            ext = osgDB.getFileExtension(filename)
            cppFileName = osgDB.concatPaths(path, name + "_" + ext + ".cpp")
            variableName = name + "_" + ext
            writeShader(shader, cppFileName, variableName)

            return 0
        else:
            print "Error: could not find file '", filename, "'"
            return 1
        

    print "No appropriate command line options used."

    arguments.getApplicationUsage().write(std.cout)
    return 1
Example #2
0
def main(argv):

    
    # use an ArgumentParser object to manage the program arguments.
    arguments = osg.ArgumentParser(argv)
    
    # set up the usage document, in case we need to print out how to use this program.
    arguments.getApplicationUsage().setApplicationName(arguments.getApplicationName())
    arguments.getApplicationUsage().setDescription(arguments.getApplicationName()+" is a utility for converting glsl shader files into char arrays that can be compiled into applications.")
    arguments.getApplicationUsage().setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...")
    arguments.getApplicationUsage().addCommandLineOption("--shader <filename>","Shader file to create a .cpp file for.")
    arguments.getApplicationUsage().addCommandLineOption("-h or --help","Display command line parameters")

    # if user request help write it out to cout.
    if arguments.read("-h")  or  arguments.read("--help") :
        arguments.getApplicationUsage().write(std.cout)
        return 1
    
    filename = str()
    if arguments.read("--shader",filename) :
        shader = osgDB.readShaderFile(filename)
        if shader.valid() :
            name = osgDB.getStrippedName(filename)
            path = osgDB.getFilePath(filename)
            invalidCharacters = "-+/\\*=()[]:<>,.?@'~#` not \""
            numbericCharacters = "0123456789"
            pos = name.find_first_of(invalidCharacters)
            while pos  not = str.npos :
                name[pos] = ord("_")
                pos = name.find_first_of(invalidCharacters)
            
            ext = osgDB.getFileExtension(filename)
            cppFileName = osgDB.concatPaths(path, name + "_" + ext + ".cpp")
            variableName = name + "_" + ext
            writeShader(shader, cppFileName, variableName)

            return 0
        else:
            print "Error: could not find file '", filename, "'"
            return 1
Example #3
0
def main(argv):


    

    # use an ArgumentParser object to manage the program arguments.
    arguments = osg.ArgumentParser(argv)
    
    # set up the usage document, in case we need to print out how to use this program.
    arguments.getApplicationUsage().setApplicationName(arguments.getApplicationName())
    arguments.getApplicationUsage().setDescription(arguments.getApplicationName()+" creates a hierarchy of files for paging which can be later loaded by viewers.")
    arguments.getApplicationUsage().setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...")
    arguments.getApplicationUsage().addCommandLineOption("-h or --help","Display this information")
    arguments.getApplicationUsage().addCommandLineOption("-o","set the output file (defaults to output.ive)")
    arguments.getApplicationUsage().addCommandLineOption("--makeAllChildrenPaged","Force all children of LOD to be written out as external PagedLOD children")

    # if user request help write it out to cout.
    if arguments.read("-h")  or  arguments.read("--help") :
        arguments.getApplicationUsage().write(std.cout)
        return 1

    outputfile = str("output.ive")
    while arguments.read("-o",outputfile) : 
    
    
    makeAllChildrenPaged = False
    while arguments.read("--makeAllChildrenPaged") :  makeAllChildrenPaged = True 

    # any option left unread are converted into errors to write out later.
    arguments.reportRemainingOptionsAsUnrecognized()

    # report any errors if they have occurred when parsing the program arguments.
    if arguments.errors() :
        arguments.writeErrorMessages(std.cout)
        return 1
    
#     if arguments.argc()<=1 :
#     
#         arguments.getApplicationUsage().write(std.cout,osg.ApplicationUsage.COMMAND_LINE_OPTION)
#         return 1
#     


    model = osgDB.readNodeFiles(arguments)
    
    if  not model :
        osg.notify(osg.NOTICE), "No model loaded."
        return 1
    
    basename = str( osgDB.getNameLessExtension(outputfile) )
    ext = ord(".")+ osgDB.getFileExtension(outputfile)
    
    converter = ConvertToPageLODVistor(basename,ext, makeAllChildrenPaged)
    model.accept(converter)
    converter.convert()
    
    nameNodes = NameVistor()
    model.accept(nameNodes)

    #CheckVisitor checkNodes
    #model.accept(checkNodes)

    if model.valid() :
        osgDB.writeNodeFile(*model,outputfile)
        
        woplsv = WriteOutPagedLODSubgraphsVistor()
        model.accept(woplsv)

    return 0


if __name__ == "__main__":
    main(sys.argv)