Exemplo n.º 1
0
def main(argv):

    
    # use an ArgumentParser object to manage the program arguments.
    arguments = osg.ArgumentParser(argv)

    if argc<2 : 
        print argv[0], ": requires filename argument."
        return 1

    numRepeats = 2
    if arguments.read("--repeat",numRepeats)  or  arguments.read("-r",numRepeats)  or  arguments.read("--repeat")  or  arguments.read("-r") :

        sharedModel = arguments.read("--shared")
        enableVBO = arguments.read("--vbo")

        model = osg.Node()
        if sharedModel :
            model = osgDB.readNodeFiles(arguments)
            if  not model : return 0

            if enableVBO :
                enableVBOs = EnableVBOVisitor()
                model.accept(enableVBOs)

        threadingModel = osgViewer.Viewer.AutomaticSelection
        while arguments.read("-s") :  threadingModel = osgViewer.Viewer.SingleThreaded 
        while arguments.read("-g") :  threadingModel = osgViewer.Viewer.CullDrawThreadPerContext 
        while arguments.read("-d") :  threadingModel = osgViewer.Viewer.DrawThreadPerContext 
        while arguments.read("-c") :  threadingModel = osgViewer.Viewer.CullThreadPerCameraDrawThreadPerContext 

        for(unsigned int i=0 i<numRepeats ++i)
            osg.notify(osg.NOTICE), "+++++++++++++ New viewer ++++++++++++"

                viewer = osgViewer.Viewer()

                viewer.setThreadingModel(threadingModel)

                if sharedModel : viewer.setSceneData(model)
                else:
                    node = osgDB.readNodeFiles(arguments)
                    if  not node : return 0

                    if enableVBO :
                        enableVBOs = EnableVBOVisitor()
                        node.accept(enableVBOs)

                    viewer.setSceneData(node)

                viewer.run()

            osg.notify(osg.NOTICE), "------------ Viewer ended ----------"
Exemplo n.º 2
0
def main(argv):


    
    arguments = osg.ArgumentParser(argv)

    # construct the viewer.
    viewer = osgViewer.Viewer(arguments)


    node = osgDB.readNodeFiles(arguments)
    if  not node : return 0

    gce = osg.GraphicsCostEstimator()

    viewer.setSceneData(node)

    viewer.realize()

    compileCost = gce.estimateCompileCost(node)
    drawCost = gce.estimateDrawCost(node)

    OSG_NOTICE, "estimateCompileCost(", node.getName(), "), CPU=", compileCost.first, " GPU=", compileCost.second
    OSG_NOTICE, "estimateDrawCost(", node.getName(), "), CPU=", drawCost.first, " GPU=", drawCost.second

    return viewer.run()
Exemplo n.º 3
0
def main(argv):
    # use an ArgumentParser object to manage the program arguments.
    arguments = osg.ArgumentParser(argv)
    # set the osgDB.Registy read file callback to catch all requests for reading files.
    osgDB.Registry.instance().setReadFileCallback(MyReadFileCallback())
    # initialize the viewer.
    viewer = osgViewer.Viewer()
    # load the nodes from the commandline arguments.
    rootnode = osgDB.readNodeFiles(arguments)
    # if not loaded assume no arguments passed in, try use default mode instead.
    if rootnode is None:
        rootnode = osgDB.readNodeFile("cow.osgt")
    if rootnode is None:
        osg.notify(osg.NOTICE), "Please specify a file on the command line"
        return 1
    # run optimization over the scene graph
    optimzer = osgUtil.Optimizer()
    optimzer.optimize(rootnode)
    # insert all the callbacks
    icv = InsertCallbacksVisitor()
    # rootnode.accept(icv)
    cuc = CameraUpdateCallback(
    )  # TODO - crashes if I do create this persistent reference
    viewer.getCamera().setUpdateCallback(cuc)
    ceu = CameraEventCallback(
    )  # TODO - crashes if I do create this persistent reference
    viewer.getCamera().setEventCallback(ceu)
    # set the scene to render
    viewer.setSceneData(rootnode)
    return viewer.run()
Exemplo n.º 4
0
def createSceneGraph(arguments):

    
    node = osgDB.readNodeFiles(arguments)
    if  not node : return 0

    group = osg.Group()
    spacing = node.getBound().radius() * 2.0

    position = osg.Vec3d(0.0,0.0,0.0)

    sa1 = NULL

        stateset = group.getOrCreateStateSet()
        sa = osg.ShaderAttribute()
        sa.setType(osg.StateAttribute.Type(10000))
        sa1 = sa
        stateset.setAttribute(sa)

            vertex_shader = osg.Shader(osg.Shader.VERTEX)
            vertex_shader.addCodeInjection(-1,"varying vec4 color\n")
            vertex_shader.addCodeInjection(-1,"varying vec4 texcoord\n")
            vertex_shader.addCodeInjection(0,"color = gl_Color\n")
            vertex_shader.addCodeInjection(0,"texcoord = gl_MultiTexCoord0\n")
            vertex_shader.addCodeInjection(0,"gl_Position = ftransform()\n")
            sa.addShader(vertex_shader)

            fragment_shader = osg.Shader(osg.Shader.FRAGMENT)
            fragment_shader.addCodeInjection(-1,"varying vec4 color\n")
            fragment_shader.addCodeInjection(-1,"varying vec4 texcoord\n")
            fragment_shader.addCodeInjection(-1,"uniform sampler2D baseTexture \n")
            fragment_shader.addCodeInjection(0,"gl_FragColor = color * texture2DProj( baseTexture, texcoord )\n")

            sa.addShader(fragment_shader)
Exemplo n.º 5
0
def main(argv):
    # use an ArgumentParser object to manage the program arguments.
    arguments = osg.ArgumentParser(argv)
    # set the osgDB.Registy read file callback to catch all requests for reading files.
    osgDB.Registry.instance().setReadFileCallback(MyReadFileCallback())
    # initialize the viewer.
    viewer = osgViewer.Viewer()
    # load the nodes from the commandline arguments.
    rootnode = osgDB.readNodeFiles(arguments)
    # if not loaded assume no arguments passed in, try use default mode instead.
    if rootnode is None:
        rootnode = osgDB.readNodeFile("cow.osgt")
    if rootnode is None:
        osg.notify(osg.NOTICE), "Please specify a file on the command line"
        return 1
    # run optimization over the scene graph
    optimzer = osgUtil.Optimizer()
    optimzer.optimize(rootnode)
    # insert all the callbacks
    icv = InsertCallbacksVisitor()
    # rootnode.accept(icv)
    cuc = CameraUpdateCallback() # TODO - crashes if I do create this persistent reference 
    viewer.getCamera().setUpdateCallback( cuc )
    ceu = CameraEventCallback() # TODO - crashes if I do create this persistent reference 
    viewer.getCamera().setEventCallback(ceu)
    # set the scene to render
    viewer.setSceneData(rootnode)
    return viewer.run()
Exemplo n.º 6
0
def main(argv):


    
    # use an ArgumentParser object to manage the program arguments.
    arguments = osg.ArgumentParser(argv)

    # load the nodes from the commandline arguments.
    loadedModel = osgDB.readNodeFiles(arguments)


    # if not loaded assume no arguments passed in, try use default mode instead.
    if  not loadedModel : loadedModel = osgDB.readNodeFile("cow.osgt")


    if  not loadedModel :
        osg.notify(osg.NOTICE), "Please specifiy a filename and the command line"
        return 1
  
    # decorate the scenegraph with a clip node.
    rootnode = decorate_with_clip_node(loadedModel)
      
    # run optimization over the scene graph
    optimzer = osgUtil.Optimizer()
    optimzer.optimize(rootnode)
    
    viewer = osgViewer.Viewer()
     
    # set the scene to render
    viewer.setSceneData(rootnode)

    return viewer.run()
Exemplo n.º 7
0
def main(argv):

    
    # use an ArgumentParser object to manage the program arguments.
    arguments = osg.ArgumentParser(argv)

    # construct the viewer.
    viewer = osgViewer.Viewer()

    # load the nodes from the commandline arguments.
    loadedModel = osgDB.readNodeFiles(arguments)

    # if not loaded assume no arguments passed in, try use default mode instead.
    if  not loadedModel : loadedModel = osgDB.readNodeFile("glider.osgt")

    # create a room made of foor walls, a floor, a roof, and swinging light fitting.
    rootnode = createRoom(loadedModel)

    # run optimization over the scene graph
    optimzer = osgUtil.Optimizer()
    optimzer.optimize(rootnode)

    # add a viewport to the viewer and attach the scene graph.
    viewer.setSceneData( rootnode )


    # create the windows and run the threads.
    viewer.realize()

    viewer.getCamera().setCullingMode( viewer.getCamera().getCullingMode()  ~osg.CullStack.SMALL_FEATURE_CULLING)

    return viewer.run()
Exemplo n.º 8
0
def main(argv):


    
    # use an ArgumentParser object to manage the program arguments.
    arguments = osg.ArgumentParser(argv)

    # construct the viewer.
    viewer = osgViewer.Viewer()

    # add local test manipulator more suitable for testing impostors.
    viewer.setCameraManipulator(TestManipulator)()


    # load the nodes from the commandline arguments.
    model = osgDB.readNodeFiles(arguments)
    if model :
        # the osgSim.InsertImpostorsVisitor used lower down to insert impostors
        # only operators on subclass of Group's, if the model top node is not
        # a group then it won't be able to insert an impostor.  We therefore
        # manually insert an impostor above the model.
        if dynamic_cast<osg.Group*>(model)==0 :
            bs = model.getBound()
            if bs.valid() :

                impostor = osgSim.Impostor()

                # standard LOD settings
                impostor.addChild(model)
                impostor.setRange(0,0.0,1e7f)
                impostor.setCenter(bs.center())

                # impostor specfic settings.
                impostor.setImpostorThresholdToBound(5.0)

                model = impostor


        # we insert an impostor node above the model, so we keep a handle
        # on the rootnode of the model, the is required since the
        # InsertImpostorsVisitor can add a root in automatically and
        # we would know about it, other than by following the parent path
        # up from model.  This is really what should be done, but I'll pass
        # on it right now as it requires a getRoots() method to be added to
        # osg.Node, and we're about to make a release so no features not 
        rootnode = osg.Group()
        rootnode.addChild(model)


        # now insert impostors in the model using the InsertImpostorsVisitor.
        ov = osgSim.InsertImpostorsVisitor()

        # traverse the model and collect all osg.Group's and osg.LOD's.
        # however, don't traverse the rootnode since we want to keep it as
        # the start of traversal, otherwise the insertImpostor could insert
        # and Impostor above the current root, making it nolonger a root not 
        model.accept(ov)

        # insert the Impostors above groups and LOD's
        ov.insertImpostors()
Exemplo n.º 9
0
def main(argv):

    
    # use an ArgumentParser object to manage the program arguments.
    arguments = osg.ArgumentParser(argv)
    
    maxNumLevels = 16
    targetNumIndicesPerLeaf = 16

    while arguments.read("--max", maxNumLevels) : 
    while arguments.read("--leaf", targetNumIndicesPerLeaf) : 
    
    osgDB.Registry.instance().setBuildKdTreesHint(osgDB.ReaderWriter.Options.BUILD_KDTREES)
    
    scene = osgDB.readNodeFiles(arguments)
    
    if  not scene : 
        print "No model loaded, please specify a valid model on the command line."
        return 0

    viewer = osgViewer.Viewer()
    viewer.setSceneData(scene)
    return viewer.run()


if __name__ == "__main__":
    main(sys.argv)
Exemplo n.º 10
0
def main(argv):

    # use an ArgumentParser object to manage the program arguments.
    arguments = osg.ArgumentParser(argv)

    # load the nodes from the commandline arguments.
    loadedModel = osgDB.readNodeFiles(arguments)

    # if not loaded assume no arguments passed in, try use default mode instead.
    if not loadedModel: loadedModel = osgDB.readNodeFile("cow.osgt")

    if not loadedModel:
        osg.notify(
            osg.NOTICE), "Please specifiy a filename and the command line"
        return 1

    # decorate the scenegraph with a clip node.
    rootnode = decorate_with_clip_node(loadedModel)

    # run optimization over the scene graph
    optimzer = osgUtil.Optimizer()
    optimzer.optimize(rootnode)

    viewer = osgViewer.Viewer()

    # set the scene to render
    viewer.setSceneData(rootnode)

    return viewer.run()
Exemplo n.º 11
0
def main(argv):

    
    # use an ArgumentParser object to manage the program arguments.
    arguments = osg.ArgumentParser(argv)
   
    # construct the viewer.
    viewer = osgViewer.Viewer()

    # load the nodes from the commandline arguments.
    rootnode = osgDB.readNodeFiles(arguments)
    
    # if not loaded assume no arguments passed in, try use default mode instead.
    if  not rootnode : rootnode = osgDB.readNodeFile("cessnafire.osgt")
    
    if  not rootnode :
        osg.notify(osg.NOTICE), "Please specify a model filename on the command line."
        return 1
    
    image = osgDB.readImageFile("Images/reflect.rgb")
    if image :
        texture = osg.Texture2D()
        texture.setImage(image)

        texgen = osg.TexGen()
        texgen.setMode(osg.TexGen.SPHERE_MAP)

        texenv = osg.TexEnv()
        texenv.setMode(osg.TexEnv.BLEND)
        texenv.setColor(osg.Vec4(0.3,0.3,0.3,0.3))

        stateset = osg.StateSet()
        stateset.setTextureAttributeAndModes(1,texture,osg.StateAttribute.ON)
        stateset.setTextureAttributeAndModes(1,texgen,osg.StateAttribute.ON)
        stateset.setTextureAttribute(1,texenv)
        
        rootnode.setStateSet(stateset)
    else:
        osg.notify(osg.NOTICE), "unable to load reflect map, model will not be mutlitextured"

    # run optimization over the scene graph
    optimzer = osgUtil.Optimizer()
    optimzer.optimize(rootnode)
     
    # add a viewport to the viewer and attach the scene graph.
    viewer.setSceneData( rootnode )
    
    # create the windows and run the threads.
    viewer.realize()

    for(unsigned int contextID = 0 
        contextID<osg.DisplaySettings.instance().getMaxNumberOfGraphicsContexts()
        ++contextID)
        textExt = osg.Texture.getExtensions(contextID,False)
        if textExt :
            if  not textExt.isMultiTexturingSupported() :
                print "Warning: multi-texturing not supported by OpenGL drivers, unable to run application."
                return 1
Exemplo n.º 12
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().setDescription(arguments.getApplicationName()+" is the example which demonstrates use of convex planer occluders.")
    arguments.getApplicationUsage().setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...")
    arguments.getApplicationUsage().addCommandLineOption("-h or --help","Display this information")
    arguments.getApplicationUsage().addCommandLineOption("-m","Mannually create occluders")

    # initialize the viewer.
    viewer = osgViewer.Viewer()

    manuallyCreateOccluders = False
    while arguments.read("-m") :  manuallyCreateOccluders = True 

    if manuallyCreateOccluders :
        viewer.addEventHandler(OccluderEventHandler(viewer))

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

    # load the nodes from the commandline arguments.
    loadedmodel = osgDB.readNodeFiles(arguments)

    # if not loaded assume no arguments passed in, try using default mode instead.
    if  not loadedmodel : loadedmodel = osgDB.readNodeFile("glider.osgt")

    if  not loadedmodel :
        osg.notify(osg.NOTICE), "Please specify a model filename on the command line."
        return 1

    # run optimization over the scene graph
    optimzer = osgUtil.Optimizer()
    optimzer.optimize(loadedmodel)

    # add the occluders to the loaded model.
    rootnode = osg.Group()

    if manuallyCreateOccluders :
        rootnode = osg.Group()
        rootnode.addChild(loadedmodel)
    else:
        rootnode = createOccludersAroundModel(loadedmodel)


    # add a viewport to the viewer and attach the scene graph.
    viewer.setSceneData( rootnode )

    return viewer.run()
Exemplo n.º 13
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 an OpenSceneGraph example that shows how to use the accumulation buffer to achieve a simple motion blur effect.")
    arguments.getApplicationUsage().setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...")
    arguments.getApplicationUsage().addCommandLineOption("-h or --help","Display this information")
    arguments.getApplicationUsage().addCommandLineOption("-P or --persistence","Set the motion blur persistence time")
    

    # construct the viewer.
    viewer = osgViewer.Viewer()

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

    persistence = 0.25
    arguments.read("-P", persistence)  or  arguments.read("--persistence", persistence)

    # read the scene from the list of file specified commandline args.
    loadedModel = osgDB.readNodeFiles(arguments)
    
    # if not loaded assume no arguments passed in, try use default mode instead.
    if  not loadedModel : loadedModel = osgDB.readNodeFile("cow.osgt")

    # if no model has been successfully loaded report failure.
    if  not loadedModel : 
        print arguments.getApplicationName(), ": No data loaded"
        return 1


    # set the display settings we can to request, OsgCameraGroup will read this.
    osg.DisplaySettings.instance().setMinimumNumAccumBits(8,8,8,8)

    # pass the loaded scene graph to the viewer.
    viewer.setSceneData(loadedModel)

    # create the windows and run the threads.
    viewer.realize()

    windows = osgViewer.Viewer.Windows()
    viewer.getWindows(windows)
    for(osgViewer.Viewer.Windows.iterator itr = windows.begin()
        not = windows.end()
        ++itr)
        (*itr).add(MotionBlurOperation(persistence))
Exemplo n.º 14
0
def main(argv):

    
    arguments = osg.ArgumentParser( argc, argv )

    root = osgDB.readNodeFiles( arguments )
    if  root == NULL  :
        osg.notify( osg.FATAL ), "Unable to load model from command line."
        return( 1 )
    configureShaders( root.getOrCreateStateSet() )

     int width( 800 ), height( 450 )
Exemplo n.º 15
0
def main(argv):


    

    # use an ArgumentParser object to manage the program arguments.
    arguments = osg.ArgumentParser(argv)
   
    # construct the viewer.
    viewer = osgViewer.Viewer()

    # load the images specified on command line
    loadedModel = osgDB.readNodeFiles(arguments)
  
    # if not loaded assume no arguments passed in, try use default mode instead.
    if  not loadedModel : loadedModel = osgDB.readNodeFile("dumptruck.osgt")
    
    if  not loadedModel :
        osg.notify(osg.NOTICE), arguments.getApplicationUsage().getCommandLineUsage()
        return 0

    stateset = create1DTextureStateToDecorate(loadedModel)
    if  not stateset :
        print "Error: failed to create 1D texture state."
        return 1


    loadedModel.setStateSet(stateset)

    osg. Group *root = osg. Group()
    root . addChild( loadedModel )

    # The contour banded color texture is used in conjunction with TexGenNode
    # to create contoured models, either in object linear coords - like
    # contours on a map, or eye linear which contour the distance from
    # the eye. An app callback toggles between the two tex gen modes.
    texgenNode = osg.TexGenNode()
    texgenNode.setReferenceFrame( osg.TexGenNode.ABSOLUTE_RF )
    texgenNode.getTexGen().setMode( osg.TexGen.OBJECT_LINEAR )

    bs = loadedModel.getBound()
    zBase = bs.center().z()-bs.radius()
    zScale = 2.0/bs.radius()
    texgenNode.getTexGen().setPlane(osg.TexGen.S,osg.Plane(0.0,0.0,zScale,-zBase))

    texgenNode.setUpdateCallback(AnimateTexGenCallback())

    root . addChild( texgenNode )


    viewer.setSceneData( root )

    return viewer.run()
Exemplo n.º 16
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().setDescription(arguments.getApplicationName()+" is the example which demonstrates how to use glBlendEquation for mixing rendered scene and the frame-buffer.")
    arguments.getApplicationUsage().setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...")
    arguments.getApplicationUsage().addCommandLineOption("-h or --help","Display this information")
   
    # construct the viewer.
    viewer = osgViewer.Viewer()

    # load the nodes from the commandline arguments.
    loadedModel = osgDB.readNodeFiles(arguments)

    # if not loaded assume no arguments passed in, try use default mode instead.
    if  not loadedModel : loadedModel = osgDB.readNodeFile("cessnafire.osgt")
  
    if  not loadedModel :
        print arguments.getApplicationName(), ": No data loaded"
        return 1

    root = osg.Group()
    root.addChild(loadedModel)
    
    
    stateset = osg.StateSet()
    stateset.setDataVariance(osg.Object.DYNAMIC)
    
    blendEquation = osg.BlendEquation(osg.BlendEquation.FUNC_ADD)
    blendEquation.setDataVariance(osg.Object.DYNAMIC)
    
    stateset.setAttributeAndModes(blendEquation,osg.StateAttribute.OVERRIDE|osg.StateAttribute.ON)
            
    #tell to sort the mesh before displaying it
    stateset.setRenderingHint(osg.StateSet.TRANSPARENT_BIN)           

    loadedModel.setStateSet(stateset)

    viewer.addEventHandler(TechniqueEventHandler(blendEquation))

    # add a viewport to the viewer and attach the scene graph.
    viewer.setSceneData( root )
    
    return viewer.run()
Exemplo n.º 17
0
def main(argv):

    

    # use an ArgumentParser object to manage the program arguments.
    arguments = osg.ArgumentParser(argv)

    # construct the viewer.
    viewer = osgViewer.Viewer()

    # add the state manipulator
    viewer.addEventHandler( osgGA.StateSetManipulator(viewer.getCamera().getOrCreateStateSet()) )

    # add stats
    viewer.addEventHandler( osgViewer.StatsHandler() )

    needToSetHomePosition = False

    # read the scene from the list of file specified commandline args.
    scene = osgDB.readNodeFiles(arguments)

    # if one hasn't been loaded create an earth and sun test model.
    if  not scene :
        scene = createScene()
        needToSetHomePosition = True
    # pass the loaded scene graph to the viewer.
    viewer.setSceneData(scene)

    viewer.setCameraManipulator(osgGA.TrackballManipulator)()

    if needToSetHomePosition :
        viewer.getCameraManipulator().setHomePosition(osg.Vec3d(0.0,-5.0*r_earth,0.0),osg.Vec3d(0.0,0.0,0.0),osg.Vec3d(0.0,0.0,1.0))

    zNear = 1.0, zMid=10.0, zFar=1000.0
    if arguments.read("--depth-partition",zNear, zMid, zFar) :
        # set up depth partitioning
        dps = osgViewer.DepthPartitionSettings()
        dps._mode = osgViewer.DepthPartitionSettings.FIXED_RANGE
        dps._zNear = zNear
        dps._zMid = zMid
        dps._zFar = zFar
        viewer.setUpDepthPartition(dps)
    else:
        # set up depth partitioning with default settings
        viewer.setUpDepthPartition()


    return viewer.run()
Exemplo n.º 18
0
def main(argv):


    
    
    if argc<2 :
        print argv[0], ": requires filename argument."
        return 1

    arguments = osg.ArgumentParser(argv)

    # load the scene.
    loadedModel = osgDB.readNodeFiles(arguments)
    if  not loadedModel :
        print argv[0], ": No data loaded."
        return 1


    if arguments.read("--CompositeViewer") :
        width = 1024
        height = 800

        viewerWindow = CompositeViewerFLTK(100,100,width,height)
        viewerWindow.resizable(viewerWindow)
        
            view1 = osgViewer.View()
            view1.getCamera().setGraphicsContext(viewerWindow.getGraphicsWindow())
            view1.getCamera().setProjectionMatrixAsPerspective(30.0, static_cast<double>(width)/static_cast<double>(height/2), 1.0, 1000.0)
            view1.getCamera().setViewport(osg.Viewport(0,0,width,height/2))
            view1.setCameraManipulator(osgGA.TrackballManipulator)()
            view1.setSceneData(loadedModel)
            
            viewerWindow.addView(view1)
        
            view2 = osgViewer.View()
            view2.getCamera().setGraphicsContext(viewerWindow.getGraphicsWindow())
            view2.getCamera().setProjectionMatrixAsPerspective(30.0, static_cast<double>(width)/static_cast<double>(height/2), 1.0, 1000.0)
            view2.getCamera().setViewport(osg.Viewport(0,height/2,width,height/2))
            view2.setCameraManipulator(osgGA.TrackballManipulator)()
            view2.setSceneData(loadedModel)
            
            viewerWindow.addView(view2)

        viewerWindow.show()

        Fl.set_idle(idle_cb)

        return Fl.run()
Exemplo n.º 19
0
def main(argv):




    
    # use an ArgumentParser object to manage the program arguments.
    arguments = osg.ArgumentParser(argv)

    # load the nodes from the commandline arguments.
    loadedModel = osgDB.readNodeFiles(arguments)
    
    # if not loaded assume no arguments passed in, try use default mode instead.
    if  not loadedModel : loadedModel = osgDB.readNodeFile("glider.osgt")
    
    if  not loadedModel :
        osg.notify(osg.NOTICE), "Please specify model filename on the command line."
        return 1
  
    root = osg.Group()
    root.addChild(loadedModel)
    
    stateset = osg.StateSet()
    logicOp = osg.LogicOp(osg.LogicOp.OR_INVERTED)

    stateset.setAttributeAndModes(logicOp,osg.StateAttribute.OVERRIDE|osg.StateAttribute.ON)

    #tell to sort the mesh before displaying it
    stateset.setRenderingHint(osg.StateSet.TRANSPARENT_BIN)


    loadedModel.setStateSet(stateset)

    # construct the viewer.
    viewer = osgViewer.Viewer()

    viewer.addEventHandler(TechniqueEventHandler(logicOp))
    
    # run optimization over the scene graph
    optimzer = osgUtil.Optimizer()
    optimzer.optimize(root)
     
    # add a viewport to the viewer and attach the scene graph.
    viewer.setSceneData( root )
    
    return viewer.run()
Exemplo n.º 20
0
def main(argv):

    
    arguments = osg.ArgumentParser( argc, argv )
    model = osgDB.readNodeFiles( arguments )
    if   not model  : model = osgDB.readNodeFile( "cow.osgt" )
    if   not model  : 
        print arguments.getApplicationName(), ": No data loaded"
        return 1
    
    viewer = CustomViewer()
    viewer.addEventHandler( JoystickHandler )()
    viewer.addEventHandler( osgViewer.StatsHandler )()
    viewer.addEventHandler( osgViewer.WindowSizeHandler )()
    viewer.addEventHandler( osgGA.StateSetManipulator(viewer.getCamera().getOrCreateStateSet()) )
    viewer.setSceneData( model )
    viewer.setUpViewInWindow( 250, 50, 800, 600 )
    return viewer.run()
Exemplo n.º 21
0
def main(argv):
    
    # use an ArgumentParser object to manage the program arguments.
    arguments = osg.ArgumentParser(argv)

    # construct the viewer.
    viewer = osgViewer.Viewer()

    # read the scene from the list of file specified commandline args.
    loadedModel = osgDB.readNodeFiles(arguments)

    # if not loaded assume no arguments passed in, try use default mode instead.
    if  not loadedModel : loadedModel = osgDB.readNodeFile("cessna.osgt")

    # if no model has been successfully loaded report failure.
    if  not loadedModel :
        print arguments.getApplicationName(), ": No data loaded"
        return 1


    # optimize the scene graph, remove redundant nodes and state etc.
    optimizer = osgUtil.Optimizer()
    optimizer.optimize(loadedModel)

    # add a transform with a callback to animate the loaded model.
    loadedModelTransform = osg.MatrixTransform()
    loadedModelTransform.addChild(loadedModel)

    nc = osg.AnimationPathCallback(loadedModelTransform.getBound().center(),osg.Vec3(0.0,0.0,1.0),osg.inDegrees(45.0))
    loadedModelTransform.setUpdateCallback(nc)


    # finally decorate the loaded model so that it has the required multipass/bin scene graph to do the reflection effect.
    rootNode = createMirroredScene(loadedModelTransform)

    # set the scene to render
    viewer.setSceneData(rootNode)

    # hint to tell viewer to request stencil buffer when setting up windows
    osg.DisplaySettings.instance().setMinimumNumStencilBits(8)

    #osgDB.writeNodeFile(*rootNode, "test.osgt")

    return viewer.run()
Exemplo n.º 22
0
def main(argv):


    
    # use an ArgumentParser object to manage the program arguments.
    arguments = osg.ArgumentParser(argv)


    # read the scene from the list of file specified commandline args.
    scene = osgDB.readNodeFiles(arguments)
    
    # if not loaded assume no arguments passed in, try use default model instead.
    if  not scene : scene = osgDB.readNodeFile("dumptruck.osgt")
    
    if  not scene : 
            geode = osg.Geode()
            drawable = osg.ShapeDrawable(osg.Box(osg.Vec3(0,0,0), 100))
            drawable.setColor(osg.Vec4(0.5, 0.5, 0.5,1))
            geode.addDrawable(drawable)
            scene = geode


    # construct the viewer.
    viewer = osgViewer.Viewer()
    
    
    group = osg.Group()

    # add the HUD subgraph.    
    if scene.valid() : group.addChild(scene)
    
    viewer.setCameraManipulator(osgGA.MultiTouchTrackballManipulator())
    viewer.realize()
    
    gc = viewer.getCamera().getGraphicsContext()
    
    #ifdef __APPLE__
        # as multitouch is disabled by default, enable it now
        win = dynamic_cast<osgViewer.GraphicsWindowCocoa*>(gc)
        if win : win.setMultiTouchEnabled(True)
Exemplo n.º 23
0
def main(argv):


    
    arguments = osg.ArgumentParser(argv)
    
    # initialize the viewer.
    viewer = osgViewer.Viewer(arguments)
    
    ds =  viewer.getDisplaySettings() : osg.DisplaySettings: if (viewer.getDisplaySettings()) else instance()
    ds.readCommandLine(arguments)

    model = osgDB.readNodeFiles(arguments)

    if  not model :
        OSG_NOTICE, "No models loaded, please specify a model file on the command line"
        return 1


    OSG_NOTICE, "Stereo ", ds.getStereo()
    OSG_NOTICE, "StereoMode ", ds.getStereoMode()

    viewer.setSceneData(model)
    
    # add the state manipulator
    viewer.addEventHandler( osgGA.StateSetManipulator(viewer.getCamera().getOrCreateStateSet()) )

    # add the stats handler
    viewer.addEventHandler(osgViewer.StatsHandler)()

    # add camera manipulator
    viewer.setCameraManipulator(osgGA.TrackballManipulator())

    OSG_NOTICE, "KeystoneFileNames.size()=", ds.getKeystoneFileNames().size()
    for(osg.DisplaySettings.FileNames.iterator itr = ds.getKeystoneFileNames().begin()
        not = ds.getKeystoneFileNames().end()
        ++itr)
        OSG_NOTICE, "   keystone filename = ", *itr
Exemplo n.º 24
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().setDescription(arguments.getApplicationName()+" is the example which demonstrates use high quality light point, typically used for naviagional lights.")
    arguments.getApplicationUsage().setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...")
    arguments.getApplicationUsage().addCommandLineOption("-h or --help","Display this information")
    arguments.getApplicationUsage().addCommandLineOption("--sprites","Point sprites.")

    # construct the viewer.
    viewer = osgViewer.Viewer()

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

    usePointSprites = False
    while arguments.read("--sprites") :  usePointSprites = True 

    rootnode = osg.Group()

    # load the nodes from the commandline arguments.
    rootnode.addChild(osgDB.readNodeFiles(arguments))
    rootnode.addChild(createLightPointsDatabase())
    rootnode.addChild(CreateBlinkSequenceLightNode())
    
    # run optimization over the scene graph
    optimzer = osgUtil.Optimizer()
    optimzer.optimize(rootnode)
     
    # add a viewport to the viewer and attach the scene graph.
    viewer.setSceneData( rootnode )
    
    return viewer.run()
Exemplo n.º 25
0
def main(argv):


    
    # use an ArgumentParser object to manage the program arguments.
    arguments = osg.ArgumentParser(argv)

    # construct the viewer.
    viewer = osgViewer.Viewer()

    # add local test manipulator more suitable for testing impostors.
    viewer.setCameraManipulator(TestManipulator)()


    # load the nodes from the commandline arguments.
    model = osgDB.readNodeFiles(arguments)
    if model :
        # the osgSim.InsertImpostorsVisitor used lower down to insert impostors
        # only operators on subclass of Group's, if the model top node is not
        # a group then it won't be able to insert an impostor.  We therefore
        # manually insert an impostor above the model.
        if dynamic_cast<osg.Group*>(model)==0 :
            bs = model.getBound()
            if bs.valid() :

                impostor = osgSim.Impostor()

                # standard LOD settings
                impostor.addChild(model)
                impostor.setRange(0,0.0,1e7f)
                impostor.setCenter(bs.center())

                # impostor specfic settings.
                impostor.setImpostorThresholdToBound(5.0)

                model = impostor


        # we insert an impostor node above the model, so we keep a handle
        # on the rootnode of the model, the is required since the
        # InsertImpostorsVisitor can add a root in automatically and
        # we would know about it, other than by following the parent path
        # up from model.  This is really what should be done, but I'll pass
        # on it right now as it requires a getRoots() method to be added to
        # osg.Node, and we're about to make a release so no features not 
        rootnode = osg.Group()
        rootnode.addChild(model)


        # now insert impostors in the model using the InsertImpostorsVisitor.
        ov = osgSim.InsertImpostorsVisitor()

        # traverse the model and collect all osg.Group's and osg.LOD's.
        # however, don't traverse the rootnode since we want to keep it as
        # the start of traversal, otherwise the insertImpostor could insert
        # and Impostor above the current root, making it nolonger a root not 
        model.accept(ov)

        # insert the Impostors above groups and LOD's
        ov.insertImpostors()
    else:
        # no user model so we'll create our own world.
        model = Root = osg.Group()
        CreateHouses()
        LayoutAsGrid()

    # add model to viewer.
    viewer.setSceneData(model)

    return viewer.run()
Exemplo n.º 26
0
def main(argv):
    
    
    arguments = osg.ArgumentParser(argv)
    viewer = osgViewer.Viewer(arguments)
    
    if arguments.argc() <= 1 : 
        cerr, "Need a scene.\n"
        return 1

    loadedModel = osgDB.readNodeFiles(arguments)
    if  not loadedModel : 
        cerr, "couldn't load ", argv[1], "\n"
        return 1
    optimizer = osgUtil.Optimizer()
    optimizer.optimize(loadedModel)
    bound = loadedModel.getBound()
    displacement = 2.25 * bound.radius()
    scene = Group()
    rootSS = scene.getOrCreateStateSet()

    vertexShader = Shader(Shader.VERTEX)
    vertexShader.setShaderSource(vertexShaderSource)
    fragmentShader = Shader(Shader.FRAGMENT)
    fragmentShader.setShaderSource(fragmentShaderSource)
    prog = Program()
    prog.addShader(vertexShader)
    prog.addShader(fragmentShader)
    prog.addBindUniformBlock("colors0", 0)
    rootSS.setAttributeAndModes(prog, StateAttribute.ON)
    # Place 3 instances of the loaded model with different uniform
    # blocks for each.
    #
    # The blocksize is known because of the std140 format.
    blockSize = 20 * sizeof(GLfloat)
    colorArray = FloatArray(colors1[0],
                         colors1[sizeof(colors1) / sizeof(GLfloat)])
    ubo = UniformBufferObject()
    colorArray.setBufferObject(ubo)
    group1 = Group()
    ss1 = group1.getOrCreateStateSet()
    group1.addChild(loadedModel)
    scene.addChild(group1)
    ubb1 = UniformBufferBinding(0, ubo, 0, blockSize)
    ss1.setAttributeAndModes(ubb1, StateAttribute.ON)
    
    colorArray2 = FloatArray(colors2[0],
                         colors2[sizeof(colors2) / sizeof(GLfloat)])
    ubo2 = UniformBufferObject()
    colorArray2.setBufferObject(ubo2)
    group2 = MatrixTransform()
    mat2 = Matrix.translate(-displacement, 0.0, 0.0)
    group2.setMatrix(mat2)
    ss2 = group2.getOrCreateStateSet()
    group2.addChild(loadedModel)
    scene.addChild(group2)
    ubb2 = UniformBufferBinding(0, ubo2, 0, blockSize)
    ss2.setAttributeAndModes(ubb2, StateAttribute.ON)

    colorArray3 = FloatArray(colors2[0],
                         colors2[sizeof(colors2) / sizeof(GLfloat)])
    ubo3 = UniformBufferObject()
    colorArray3.setBufferObject(ubo3)
    group3 = MatrixTransform()
    mat3 = Matrix.translate(displacement, 0.0, 0.0)
    group3.setMatrix(mat3)
    ss3 = group3.getOrCreateStateSet()
    group3.addChild(loadedModel)
    scene.addChild(group3)    
    ubb3 = UniformBufferBinding(0, ubo3, 0, blockSize)
    ubb3.setUpdateCallback(UniformCallback)()
    ubb3.setDataVariance(Object.DYNAMIC)
    ss3.setAttributeAndModes(ubb3, StateAttribute.ON)
    
    viewer.setSceneData(scene)
    viewer.realize()
    return viewer.run()
Exemplo n.º 27
0
    if helpType :
        arguments.getApplicationUsage().write(std.cout, helpType)
        return 1

    # report any errors if they have occurred when parsing the program arguments.
    if arguments.errors() :
        arguments.writeErrorMessages(std.cout)
        return 1

    dragger_name = "TabBoxDragger"
    arguments.read("--dragger", dragger_name)

    start_tick = osg.Timer.instance().tick()

    # read the scene from the list of file specified command line args.
    loadedModel = osgDB.readNodeFiles(arguments)

    # if no model has been successfully loaded report failure.
    tragger2Scene = bool(True)
    if  not loadedModel : 
        #print arguments.getApplicationName(), ": No data loaded"
        #return 1
        loadedModel = createDemoScene(fixedSizeInScreen)
        tragger2Scene=False

    # 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)
Exemplo n.º 28
0
def main(argv):

    
    # use an ArgumentParser object to manage the program arguments.
    arguments = osg.ArgumentParser(argv)

    # read the scene from the list of file specified commandline args.
    scene = osgDB.readNodeFiles(arguments)

    if  not scene  and  arguments.read("--relative-camera-scene") :
        # Create a test scene with a camera that has a relative reference frame.
        group = osg.Group()

        sphere = osg.Geode()
        sphere.setName("Sphere")
        sphere.addDrawable(osg.ShapeDrawable(osg.Sphere()))

        cube = osg.Geode()
        cube.setName("Cube")
        cube.addDrawable(osg.ShapeDrawable(osg.Box()))

        camera = osg.Camera()
        camera.setRenderOrder(osg.Camera.POST_RENDER)
        camera.setClearMask(GL_DEPTH_BUFFER_BIT)
        camera.setReferenceFrame(osg.Transform.RELATIVE_RF)
        camera.setViewMatrix(osg.Matrix.translate(-2, 0, 0))

        xform = osg.MatrixTransform(osg.Matrix.translate(1, 1, 1))
        xform.addChild(camera)

        group.addChild(sphere)
        group.addChild(xform)
        camera.addChild(cube)

        scene = group

    # if not loaded assume no arguments passed in, try use default mode instead.
    if  not scene : scene = osgDB.readNodeFile("fountain.osgt")

    group = dynamic_cast<osg.Group*>(scene)
    if  not group :
        group = osg.Group()
        group.addChild(scene)

    updateText = osgText.Text()

    # add the HUD subgraph.
    group.addChild(createHUD(updateText))

    if arguments.read("--CompositeViewer") :
        view = osgViewer.View()
        # add the handler for doing the picking
        view.addEventHandler(PickHandler(updateText))

        # set the scene to render
        view.setSceneData(group)

        view.setUpViewAcrossAllScreens()

        viewer = osgViewer.CompositeViewer()
        viewer.addView(view)

        return viewer.run()

    else:
        viewer = osgViewer.Viewer()


        # add all the camera manipulators
            keyswitchManipulator = osgGA.KeySwitchMatrixManipulator()

            keyswitchManipulator.addMatrixManipulator( ord("1"), "Trackball", osgGA.TrackballManipulator() )
            keyswitchManipulator.addMatrixManipulator( ord("2"), "Flight", osgGA.FlightManipulator() )
            keyswitchManipulator.addMatrixManipulator( ord("3"), "Drive", osgGA.DriveManipulator() )

            num = keyswitchManipulator.getNumMatrixManipulators()
            keyswitchManipulator.addMatrixManipulator( ord("4"), "Terrain", osgGA.TerrainManipulator() )

            pathfile = str()
            keyForAnimationPath = ord("5")
            while arguments.read("-p",pathfile) :
                apm = osgGA.AnimationPathManipulator(pathfile)
                if apm  or   not apm.valid() :
                    num = keyswitchManipulator.getNumMatrixManipulators()
                    keyswitchManipulator.addMatrixManipulator( keyForAnimationPath, "Path", apm )
                    ++keyForAnimationPath

            keyswitchManipulator.selectMatrixManipulator(num)

            viewer.setCameraManipulator( keyswitchManipulator )

        # add the handler for doing the picking
        viewer.addEventHandler(PickHandler(updateText))

        # set the scene to render
        viewer.setSceneData(group)

        return viewer.run()
Exemplo n.º 29
0

def main(argv):


    
    arguments = osg.ArgumentParser( argc, argv )

     root = osg.Group()

    # Child 0: We'll replace this every frame with an updated representation
    #   of the view frustum.
    root.addChild( makeFrustumFromCamera( NULL ) )

     scene = osg.Node()
    scene = osgDB.readNodeFiles( arguments )
    if  not scene :
        # User didn't specify anything, or file(s) didn't exist.
        # Try to load the cow...
        osg.notify( osg.WARN ), arguments.getApplicationName(), ": Could not find specified files. Trying \"cow.osgt\" instead."
        if   not (scene = osgDB.readNodeFile( str( "cow.osgt" ) ) )  :
            osg.notify( osg.FATAL ), arguments.getApplicationName(), ": No data loaded."
            return 1
    root.addChild( scene )


    viewer = osgViewer.CompositeViewer( arguments )
    # Turn on FSAA, makes the lines look better.
    osg.DisplaySettings.instance().setNumMultiSamples( 4 )

    # Create View 0 -- Just the loaded model.
Exemplo n.º 30
0
def main(argv):


    
    # use an ArgumentParser object to manage the program arguments.
    arguments = osg.ArgumentParser(argv)


    # read the scene from the list of file specified commandline args.
    scene = osgDB.readNodeFiles(arguments)

    # if not loaded assume no arguments passed in, try use default model instead.
    if  not scene : scene = osgDB.readNodeFile("dumptruck.osgt")


    if  not scene :
        osg.notify(osg.NOTICE), "No model loaded"
        return 1


    if arguments.read("--Viewer") :
        # construct the viewer.
        viewer = osgViewer.Viewer()

        # create a HUD as slave camera attached to the master view.

        viewer.setUpViewAcrossAllScreens()

        windows = osgViewer.Viewer.Windows()
        viewer.getWindows(windows)

        if windows.empty() : return 1

        hudCamera = createHUD()

        # set up cameras to render on the first window available.
        hudCamera.setGraphicsContext(windows[0])
        hudCamera.setViewport(0,0,windows[0].getTraits().width, windows[0].getTraits().height)

        viewer.addSlave(hudCamera, False)

        # set the scene to render
        viewer.setSceneData(scene)

        return viewer.run()

    if arguments.read("--CompositeViewer") :
        # construct the viewer.
        viewer = osgViewer.CompositeViewer()

        # create the main 3D view
        view = osgViewer.View()
        viewer.addView(view)

        view.setSceneData(scene)
        view.setUpViewAcrossAllScreens()
        view.setCameraManipulator(osgGA.TrackballManipulator)()

        # now create the HUD camera's view

        windows = osgViewer.Viewer.Windows()
        viewer.getWindows(windows)

        if windows.empty() : return 1

        hudCamera = createHUD()

        # set up cameras to render on the first window available.
        hudCamera.setGraphicsContext(windows[0])
        hudCamera.setViewport(0,0,windows[0].getTraits().width, windows[0].getTraits().height)

        hudView = osgViewer.View()
        hudView.setCamera(hudCamera)

        viewer.addView(hudView)

        return viewer.run()

    else:
        # construct the viewer.
        viewer = osgViewer.Viewer()

        postDrawCallback = SnapImage("PostDrawCallback.png")
        viewer.getCamera().setPostDrawCallback(postDrawCallback)
        viewer.addEventHandler(SnapeImageHandler(ord("p"),postDrawCallback))

        finalDrawCallback = SnapImage("FinalDrawCallback.png")
        viewer.getCamera().setFinalDrawCallback(finalDrawCallback)
        viewer.addEventHandler(SnapeImageHandler(ord("f"),finalDrawCallback))

        group = osg.Group()

        # add the HUD subgraph.
        if scene.valid() : group.addChild(scene)
        group.addChild(createHUD())

        # set the scene to render
        viewer.setSceneData(group)

        return viewer.run()
Exemplo n.º 31
0
def main(argv):


    
    # use an ArgumentParser object to manage the program arguments.
    arguments = osg.ArgumentParser(argv)
    
    scene = osgDB.readNodeFiles(arguments)
    
    if  not scene : 
        print "No model loaded, please specify a valid model on the command line."
        return 0
    
    print "Intersection "
    
    
    bs = scene.getBound()


    useIntersectorGroup = True
    useLineOfSight = True
    
    #osg.CoordinateSystemNode* csn = dynamic_cast<osg.CoordinateSystemNode*>(scene)
    #osg.EllipsoidModel* em =  csn.getEllipsoidModel() if (csn) else  0

    if useLineOfSight :
    
        start = bs.center() + osg.Vec3d(0.0,bs.radius(),0.0)
        end = bs.center() - osg.Vec3d(0.0, bs.radius(),0.0)
        deltaRow = osg.Vec3d( 0.0, 0.0, bs.radius()*0.01)
        deltaColumn = osg.Vec3d( bs.radius()*0.01, 0.0, 0.0)

        los = osgSim.LineOfSight()
        
#if 1
        numRows = 20
        numColumns = 20
        hat = osgSim.HeightAboveTerrain()
        hat.setDatabaseCacheReadCallback(los.getDatabaseCacheReadCallback())

        for(unsigned int r=0 r<numRows ++r)
            for(unsigned int c=0 c<numColumns ++c)
                s = start + deltaColumn * double(c) + deltaRow * double(r)
                e = end + deltaColumn * double(c) + deltaRow * double(r)
                los.addLOS(s,e)
                hat.addPoint(s)


            print "Computing LineOfSight"

            startTick = osg.Timer.instance().tick()

            los.computeIntersections(scene)

            endTick = osg.Timer.instance().tick()

            print "Completed in ", osg.Timer.instance().delta_s(startTick,endTick)

            for(unsigned int i=0 i<los.getNumLOS() i++)
                intersections = los.getIntersections(i)
                for(osgSim.LineOfSight.Intersections.const_iterator itr = intersections.begin()
                    not = intersections.end()
                    ++itr)
                     print "  point ", *itr
Exemplo n.º 32
0
def main(argv):


    
    # use an ArgumentParser object to manage the program arguments.
    arguments = osg.ArgumentParser(argv)

    # construct the viewer.
    viewer = osgViewer.Viewer()

    # load the nodes from the commandline arguments.
    loadedModel = osgDB.readNodeFiles(arguments)

    # if not loaded assume no arguments passed in, try use default mode instead.
    if  not loadedModel : loadedModel = osgDB.readNodeFile("cow.osgt")

    if  not loadedModel :
        print arguments.getApplicationName(), ": No data loaded"
        return 1


    if arguments.read("--dome")  or  arguments.read("--puffer")  :

        setDomeCorrection(viewer, arguments)

        viewer.setSceneData( loadedModel )
    elif arguments.read("--faces") :

        setDomeFaces(viewer, arguments)

        viewer.setSceneData( loadedModel )
    else:
        distortionNode = createDistortionSubgraph( loadedModel, viewer.getCamera().getClearColor())
        viewer.setSceneData( distortionNode )

    while arguments.read("--sky-light") :
        viewer.setLightingMode(osg.View.SKY_LIGHT)

    if viewer.getLightingMode()==osg.View.HEADLIGHT :
        viewer.getLight().setPosition(osg.Vec4(0.0,0.0,0.0,1.0))


    # load the nodes from the commandline arguments.
    if  not viewer.getSceneData() :
        osg.notify(osg.NOTICE), "Please specify a model filename on the command line."
        return 1


    # set up the camera manipulators.
        keyswitchManipulator = osgGA.KeySwitchMatrixManipulator()

        keyswitchManipulator.addMatrixManipulator( ord("1"), "Trackball", osgGA.TrackballManipulator() )
        keyswitchManipulator.addMatrixManipulator( ord("2"), "Flight", osgGA.FlightManipulator() )
        keyswitchManipulator.addMatrixManipulator( ord("3"), "Drive", osgGA.DriveManipulator() )
        keyswitchManipulator.addMatrixManipulator( ord("4"), "Terrain", osgGA.TerrainManipulator() )

        pathfile = str()
        keyForAnimationPath = ord("5")
        while arguments.read("-p",pathfile) :
            apm = osgGA.AnimationPathManipulator(pathfile)
            if apm  or   not apm.valid() :
                num = keyswitchManipulator.getNumMatrixManipulators()
                keyswitchManipulator.addMatrixManipulator( keyForAnimationPath, "Path", apm )
                keyswitchManipulator.selectMatrixManipulator(num)
                ++keyForAnimationPath

        viewer.setCameraManipulator( keyswitchManipulator )

    viewer.setThreadingModel(osgViewer.Viewer.SingleThreaded)

    # add the state manipulator
    viewer.addEventHandler( osgGA.StateSetManipulator(viewer.getCamera().getOrCreateStateSet()) )

    # add the stats handler
    viewer.addEventHandler(osgViewer.StatsHandler)()

    return viewer.run()
Exemplo n.º 33
0
def main(argv):
    
    arguments = osg.ArgumentParser( argc, argv )
    usage = arguments.getApplicationUsage()
    usage.setDescription( arguments.getApplicationName() +
                           " is the example which demonstrates how to render high-resolution images (posters).")
    usage.setCommandLineUsage( arguments.getApplicationName() + " [options] scene_file" )
    usage.addCommandLineOption( "-h or --help", "Display this information." )
    usage.addCommandLineOption( "--color <r> <g> <b>", "The background color." )
    usage.addCommandLineOption( "--ext <ext>", "The output tiles' extension (Default: bmp)." )
    usage.addCommandLineOption( "--poster <filename>", "The output poster's name (Default: poster.bmp)." )
    usage.addCommandLineOption( "--tilesize <w> <h>", "Size of each image tile (Default: 640 480)." )
    usage.addCommandLineOption( "--finalsize <w> <h>", "Size of the poster (Default: 6400 4800)." )
    usage.addCommandLineOption( "--enable-output-poster", "Output the final poster file (Default)." )
    usage.addCommandLineOption( "--disable-output-poster", "Don't output the final poster file." )
    #usage.addCommandLineOption( "--enable-output-tiles", "Output all tile files." )
    #usage.addCommandLineOption( "--disable-output-tiles", "Don't output all tile files (Default)." )
    usage.addCommandLineOption( "--use-fb", "Use Frame Buffer for rendering tiles (Default, recommended).")
    usage.addCommandLineOption( "--use-fbo", "Use Frame Buffer Object for rendering tiles.")
    usage.addCommandLineOption( "--use-pbuffer","Use Pixel Buffer for rendering tiles.")
    usage.addCommandLineOption( "--use-pbuffer-rtt","Use Pixel Buffer RTT for rendering tiles.")
    usage.addCommandLineOption( "--inactive", "Inactive capturing mode." )
    usage.addCommandLineOption( "--camera-eye <x> <y> <z>", "Set eye position in inactive mode." )
    usage.addCommandLineOption( "--camera-latlongheight <lat> <lon> <h>", "Set eye position on earth in inactive mode." )
    usage.addCommandLineOption( "--camera-hpr <h> <p> <r>", "Set eye rotation in inactive mode." )
    
    if  arguments.read("-h")  or  arguments.read("--help")  :
        usage.write( std.cout )
        return 1
    
    # Poster arguments
    activeMode = True
    outputPoster = True
    #bool outputTiles = False
    tileWidth = 640, tileHeight = 480
    posterWidth = 640*2, posterHeight = 480*2
    posterName = "poster.bmp", extName = "bmp"
    bgColor = osg.Vec4(0.2, 0.2, 0.6, 1.0)
    renderImplementation = osg.Camera.FRAME_BUFFER_OBJECT
    
    while  arguments.read("--inactive")  :  activeMode = False 
    while  arguments.read("--color", bgColor.r(), bgColor.g(), bgColor.b())  : 
    while  arguments.read("--tilesize", tileWidth, tileHeight)  : 
    while  arguments.read("--finalsize", posterWidth, posterHeight)  : 
    while  arguments.read("--poster", posterName)  : 
    while  arguments.read("--ext", extName)  : 
    while  arguments.read("--enable-output-poster")  :  outputPoster = True 
    while  arguments.read("--disable-output-poster")  :  outputPoster = False 
    #while  arguments.read("--enable-output-tiles")  :  outputTiles = True 
    #while  arguments.read("--disable-output-tiles")  :  outputTiles = False 
    while  arguments.read("--use-fbo") :  renderImplementation = osg.Camera.FRAME_BUFFER_OBJECT 
    while  arguments.read("--use-pbuffer") :  renderImplementation = osg.Camera.PIXEL_BUFFER 
    while  arguments.read("--use-pbuffer-rtt") :  renderImplementation = osg.Camera.PIXEL_BUFFER_RTT 
    while  arguments.read("--use-fb") :  renderImplementation = osg.Camera.FRAME_BUFFER 
    
    # Camera settings for inactive screenshot
    useLatLongHeight = True
    eye = osg.Vec3d()
    latLongHeight = osg.Vec3d( 50.0, 10.0, 2000.0 )
    hpr = osg.Vec3d( 0.0, 0.0, 0.0 )
    if  arguments.read("--camera-eye", eye.x(), eye.y(), eye.z())  :
        useLatLongHeight = False
        activeMode = False
    elif  arguments.read("--camera-latlongheight", latLongHeight.x(), latLongHeight.y(), latLongHeight.z())  :
        activeMode = False
        latLongHeight.x() = osg.DegreesToRadians( latLongHeight.x() )
        latLongHeight.y() = osg.DegreesToRadians( latLongHeight.y() )
    if  arguments.read("--camera-hpr", hpr.x(), hpr.y(), hpr.z())  :
        activeMode = False
        hpr.x() = osg.DegreesToRadians( hpr.x() )
        hpr.y() = osg.DegreesToRadians( hpr.y() )
        hpr.z() = osg.DegreesToRadians( hpr.z() )
    
    # Construct scene graph
    scene = osgDB.readNodeFiles( arguments )
    if   not scene  : scene = osgDB.readNodeFile( "cow.osgt" )
    if   not scene  :
        print arguments.getApplicationName(), ": No data loaded"
        return 1
    
    # Create camera for rendering tiles offscreen. FrameBuffer is recommended because it requires less memory.
    camera = osg.Camera()
    camera.setClearColor( bgColor )
    camera.setClearMask( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT )
    camera.setReferenceFrame( osg.Transform.ABSOLUTE_RF )
    camera.setRenderOrder( osg.Camera.PRE_RENDER )
    camera.setRenderTargetImplementation( renderImplementation )
    camera.setViewport( 0, 0, tileWidth, tileHeight )
    camera.addChild( scene )
    
    # Set the printer
    printer = PosterPrinter()
    printer.setTileSize( tileWidth, tileHeight )
    printer.setPosterSize( posterWidth, posterHeight )
    printer.setCamera( camera )
    
    posterImage = 0
    if  outputPoster  :
        posterImage = osg.Image()
        posterImage.allocateImage( posterWidth, posterHeight, 1, GL_RGBA, GL_UNSIGNED_BYTE )
        printer.setFinalPoster( posterImage )
        printer.setOutputPosterName( posterName )
    
#if 0
    # While recording sub-images of the poster, the scene will always be traversed twice, from its two
    # parent node: root and camera. Sometimes this may not be so comfortable.
    # To prevent this behaviour, we can use a switch node to enable one parent and disable the other.
    # However, the solution also needs to be used with care, as the window will go blank while taking
    # snapshots and recover later.
    root = osg.Switch()
    root.addChild( scene, True )
    root.addChild( camera, False )
#else:
    root = osg.Group()
    root.addChild( scene )
    root.addChild( camera )
#endif
    
    viewer = osgViewer.Viewer()
    viewer.setSceneData( root )
    viewer.getDatabasePager().setDoPreCompile( False )
    
    if  renderImplementation==osg.Camera.FRAME_BUFFER  :
        # FRAME_BUFFER requires the window resolution equal or greater than the to-be-copied size
        viewer.setUpViewInWindow( 100, 100, tileWidth, tileHeight )
    else:
        # We want to see the console output, so just render in a window
        viewer.setUpViewInWindow( 100, 100, 800, 600 )
    
    if  activeMode  :
        viewer.addEventHandler( PrintPosterHandler(printer) )
        viewer.addEventHandler( osgViewer.StatsHandler )()
        viewer.addEventHandler( osgGA.StateSetManipulator(viewer.getCamera().getOrCreateStateSet()) )
        viewer.setCameraManipulator( osgGA.TrackballManipulator )()
        viewer.run()
    else:
        camera = viewer.getCamera()
        if   not useLatLongHeight  : computeViewMatrix( camera, eye, hpr )
        computeViewMatrixOnEarth = else( camera, scene, latLongHeight, hpr )
        
        renderer = CustomRenderer( camera )
        camera.setRenderer( renderer )
        viewer.setThreadingModel( osgViewer.Viewer.SingleThreaded )
        
        # Realize and initiate the first PagedLOD request
        viewer.realize()
        viewer.frame()
        
        printer.init( camera )
        while   not printer.done()  :
            viewer.advance()
            
            # Keep updating and culling until full level of detail is reached
            renderer.setCullOnly( True )
            while  viewer.getDatabasePager().getRequestsInProgress()  :
                viewer.updateTraversal()
                viewer.renderingTraversals()
            
            renderer.setCullOnly( False )
            printer.frame( viewer.getFrameStamp(), viewer.getSceneData() )
            viewer.renderingTraversals()
    return 0

# Translated from file 'PosterPrinter.cpp'

#include <osg/ClusterCullingCallback>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
#include <string.h>
#include <iostream>
#include <sstream>
#include "PosterPrinter.h"

# PagedLoadingCallback: Callback for loading paged nodes while doing intersecting test 
class PagedLoadingCallback (osgUtil.IntersectionVisitor.ReadCallback) :
def readNodeFile(filename):
    
        return osgDB.readNodeFile( filename )

static PagedLoadingCallback g_pagedLoadingCallback = PagedLoadingCallback()

# LodCullingCallback: Callback for culling LODs and selecting the highest level 
class LodCullingCallback (osg.NodeCallback) :
    virtual void operator()( osg.Node* node, osg.NodeVisitor* nv )
        lod = static_cast<osg.LOD*>(node)
        if  lod  and  lod.getNumChildren()>0  :
            lod.getChild(lod.getNumChildren()-1).accept(*nv)

static LodCullingCallback g_lodCullingCallback = LodCullingCallback()

# PagedCullingCallback: Callback for culling paged nodes and selecting the highest level 
class PagedCullingCallback (osg.NodeCallback) :
    virtual void operator()( osg.Node* node, osg.NodeVisitor* nv )
        pagedLOD = static_cast<osg.PagedLOD*>(node)
        if  pagedLOD  and  pagedLOD.getNumChildren()>0  :
            numChildren = pagedLOD.getNumChildren()
            updateTimeStamp = nv.getVisitorType()==osg.NodeVisitor.CULL_VISITOR
            if  nv.getFrameStamp()  and  updateTimeStamp  :
                timeStamp =  nv.getFrameStamp().getReferenceTime() if (nv.getFrameStamp()) else 0.0
                frameNumber =  nv.getFrameStamp().getFrameNumber() if (nv.getFrameStamp()) else 0
                
                pagedLOD.setFrameNumberOfLastTraversal( frameNumber )
                pagedLOD.setTimeStamp( numChildren-1, timeStamp )
                pagedLOD.setFrameNumber( numChildren-1, frameNumber )
                pagedLOD.getChild(numChildren-1).accept(*nv)
            
            # Request for child
            if   not pagedLOD.getDisableExternalChildrenPaging()  and 
                 nv.getDatabaseRequestHandler()  and 
                 numChildren<pagedLOD.getNumRanges()  :
                if  pagedLOD.getDatabasePath().empty()  :
                    nv.getDatabaseRequestHandler().requestNodeFile(
                        pagedLOD.getFileName(numChildren), nv.getNodePath(),
                        1.0, nv.getFrameStamp(),
                        pagedLOD.getDatabaseRequest(numChildren), pagedLOD.getDatabaseOptions() )
                else:
                    nv.getDatabaseRequestHandler().requestNodeFile(
                        pagedLOD.getDatabasePath()+pagedLOD.getFileName(numChildren), nv.getNodePath(),
                        1.0, nv.getFrameStamp(),
                        pagedLOD.getDatabaseRequest(numChildren), pagedLOD.getDatabaseOptions() )
        #node.traverse(*nv)

static PagedCullingCallback g_pagedCullingCallback = PagedCullingCallback()

# PosterVisitor: A visitor for adding culling callbacks to newly allocated paged nodes 
PosterVisitor.PosterVisitor()
:   osg.NodeVisitor(osg.NodeVisitor.TRAVERSE_ALL_CHILDREN),
    _appliedCount(0), _needToApplyCount(0),
    _addingCallbacks(True)

void PosterVisitor.apply( osg.LOD node )
    #if   not hasCullCallback(node.getCullCallback(), g_lodCullingCallback)  :
#    
#        if   not node.getName().empty()  :
#        
#            itr = _pagedNodeNames.find( node.getName() )
#            if  itr not =_pagedNodeNames.end()  :
#            
#                insertCullCallback( node, g_lodCullingCallback )
#                _appliedCount++
#            
#        
#    
#    def if _addingCallbacks .
#        
#        node.removeCullCallback( g_lodCullingCallback )
#        _appliedCount--
#    
    traverse( node )

void PosterVisitor.apply( osg.PagedLOD node )
    if   not hasCullCallback(node.getCullCallback(), g_pagedCullingCallback)  :
        for ( unsigned int i=0 i<node.getNumFileNames() ++i )
            if  node.getFileName(i).empty()  : continue
            
            itr = _pagedNodeNames.find( node.getFileName(i) )
            if  itr not =_pagedNodeNames.end()  :
                node.addCullCallback( g_pagedCullingCallback )
                _appliedCount++
            break
    def if _addingCallbacks .
        
        node.removeCullCallback( g_pagedCullingCallback )
        if  _appliedCount>0  : _appliedCount--
    traverse( node )
Exemplo n.º 34
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)
Exemplo n.º 35
0
def main(argv):

    
    # use an ArgumentParser object to manage the program arguments.
    arguments = osg.ArgumentParser(argv)

    # construct the viewer.
    viewer = osgViewer.Viewer()

    # load the nodes from the commandline arguments.
    loadedModel = osgDB.readNodeFiles(arguments)

    # if not loaded assume no arguments passed in, try use default mode instead.
    if  not loadedModel : loadedModel = osgDB.readNodeFile("cow.osgt")
    
    if  not loadedModel :
        osg.notify(osg.NOTICE), "Please specifiy a model filename on the command line."
        return 1
  
    # to do scribe mode we create a top most group to contain the
    # original model, and then a second group contains the same model
    # but overrides various state attributes, so that the second instance
    # is rendered as wireframe.
    
    rootnode = osg.Group()

    decorator = osg.Group()
    
    rootnode.addChild(loadedModel)
    
    
    rootnode.addChild(decorator)
    
    decorator.addChild(loadedModel)  

    # set up the state so that the underlying color is not seen through
    # and that the drawing mode is changed to wireframe, and a polygon offset
    # is added to ensure that we see the wireframe itself, and turn off 
    # so texturing too.
    stateset = osg.StateSet()
    polyoffset = osg.PolygonOffset()
    polyoffset.setFactor(-1.0)
    polyoffset.setUnits(-1.0)
    polymode = osg.PolygonMode()
    polymode.setMode(osg.PolygonMode.FRONT_AND_BACK,osg.PolygonMode.LINE)
    stateset.setAttributeAndModes(polyoffset,osg.StateAttribute.OVERRIDE|osg.StateAttribute.ON)
    stateset.setAttributeAndModes(polymode,osg.StateAttribute.OVERRIDE|osg.StateAttribute.ON)

#if 1
    material = osg.Material()
    stateset.setAttributeAndModes(material,osg.StateAttribute.OVERRIDE|osg.StateAttribute.ON)
    stateset.setMode(GL_LIGHTING,osg.StateAttribute.OVERRIDE|osg.StateAttribute.OFF)
#else:
    # version which sets the color of the wireframe.
    material = osg.Material()
    material.setColorMode(osg.Material.OFF) # switch glColor usage off
    # turn all lighting off 
    material.setAmbient(osg.Material.FRONT_AND_BACK, osg.Vec4(0.0,0.0,0.0,1.0))
    material.setDiffuse(osg.Material.FRONT_AND_BACK, osg.Vec4(0.0,0.0,0.0,1.0))
    material.setSpecular(osg.Material.FRONT_AND_BACK, osg.Vec4(0.0,0.0,0.0,1.0))
    # except emission... in which we set the color we desire
    material.setEmission(osg.Material.FRONT_AND_BACK, osg.Vec4(0.0,1.0,0.0,1.0))
    stateset.setAttributeAndModes(material,osg.StateAttribute.OVERRIDE|osg.StateAttribute.ON)
    stateset.setMode(GL_LIGHTING,osg.StateAttribute.OVERRIDE|osg.StateAttribute.ON)
#endif

    stateset.setTextureMode(0,GL_TEXTURE_2D,osg.StateAttribute.OVERRIDE|osg.StateAttribute.OFF)
    
#     osg.LineStipple* linestipple = osg.LineStipple()
#     linestipple.setFactor(1)
#     linestipple.setPattern(0xf0f0)
#     stateset.setAttributeAndModes(linestipple,osg.StateAttribute.OVERRIDE_ON)
    
    decorator.setStateSet(stateset)
  
    
    # run optimization over the scene graph
    optimzer = osgUtil.Optimizer()
    optimzer.optimize(rootnode)
     
    # add a viewport to the viewer and attach the scene graph.
    viewer.setSceneData( rootnode )
    
    return viewer.run()
Exemplo n.º 36
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()+" example provides an interactive viewer for visualising point clouds..")
    arguments.getApplicationUsage().setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...")
    arguments.getApplicationUsage().addCommandLineOption("-h or --help","Display this information")
    arguments.getApplicationUsage().addCommandLineOption("--sprites","Point sprites.")
    arguments.getApplicationUsage().addCommandLineOption("--points","Sets the polygon mode to GL_POINT for front and back faces.")


    # construct the viewer.
    viewer = osgViewer.Viewer()

    shader = False
    while arguments.read("--shader") : shader = True

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

    forcePointMode = False
    while arguments.read("--points") :  forcePointMode = True 

    if arguments.argc()<=1 :
        arguments.getApplicationUsage().write(std.cout,osg.ApplicationUsage.COMMAND_LINE_OPTION)
        return 1

    # read the scene from the list of file specified commandline args.
    loadedModel = osgDB.readNodeFiles(arguments)

    # if no model has been successfully loaded report failure.
    if  not loadedModel : 
        print arguments.getApplicationName(), ": No data loaded"
        return 1

    # optimize the scene graph, remove redundant nodes and state etc.
    optimizer = osgUtil.Optimizer()
    optimizer.optimize(loadedModel)


    # set the scene to render
    viewer.setSceneData(loadedModel)
    

    stateset = loadedModel.getOrCreateStateSet()
    if usePointSprites :    
        #/ Setup cool blending
        fn = osg.BlendFunc()
        stateset.setAttributeAndModes(fn, osg.StateAttribute.ON)

        #/ Setup the point sprites
        sprite = osg.PointSprite()
        stateset.setTextureAttributeAndModes(0, sprite, osg.StateAttribute.ON)

        #/ The texture for the sprites
        tex = osg.Texture2D()
        tex.setImage(osgDB.readImageFile("Images/particle.rgb"))
        stateset.setTextureAttributeAndModes(0, tex, osg.StateAttribute.ON)

    if  forcePointMode  :
        #/ Set polygon mode to GL_POINT
        pm = osg.PolygonMode(
            osg.PolygonMode.FRONT_AND_BACK, osg.PolygonMode.POINT )
        stateset.setAttributeAndModes( pm, osg.StateAttribute.ON | osg.StateAttribute.OVERRIDE)
    

    # register the handler for modifying the point size
    viewer.addEventHandler(KeyboardEventHandler(viewer.getCamera().getOrCreateStateSet()))


    if shader :
        stateset = loadedModel.getOrCreateStateSet()
    
        #################################/
        # vertex shader using just Vec4 coefficients
        char vertexShaderSource[] = 
            "void main(void) \n"
            " \n"
            "\n"
            "    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex\n"
            "\n"



        program = osg.Program()
        stateset.setAttribute(program)

        vertex_shader = osg.Shader(osg.Shader.VERTEX, vertexShaderSource)
        program.addShader(vertex_shader)

#if 0
        #################################
        # fragment shader
        #
        char fragmentShaderSource[] = 
            "void main(void) \n"
            " \n"
            "    gl_FragColor = gl_Color \n"
            "\n"