Пример #1
0
def main(argv):

    
    loadedModel = osg.Node()
    
    # load the scene.
    if argc>1 : loadedModel = osgDB.readNodeFile(argv[1])
    
    # if not loaded assume no arguments passed in, try use default mode instead.
    if  not loadedModel : loadedModel = osgDB.readNodeFile("dumptruck.osgt")
    
    if  not loadedModel : 
        print argv[0], ": No data loaded."
        return 1
    
    # create the window to draw to.
    traits = osg.GraphicsContext.Traits()
    traits.x = 200
    traits.y = 200
    traits.width = 800
    traits.height = 600
    traits.windowDecoration = True
    traits.doubleBuffer = True
    traits.sharedContext = 0

    gc = osg.GraphicsContext.createGraphicsContext(traits)
    gw = dynamic_cast<osgViewer.GraphicsWindow*>(gc)
    if  not gw :
        osg.notify(osg.NOTICE), "Error: unable to create graphics window."
        return 1

    # create the view of the scene.
    viewer = osgViewer.Viewer()
    viewer.getCamera().setGraphicsContext(gc)
    viewer.getCamera().setViewport(0,0,800,600)
    viewer.setSceneData(loadedModel)
    
    # create a tracball manipulator to move the camera around in response to keyboard/mouse events
    viewer.setCameraManipulator( osgGA.TrackballManipulator )()

    statesetManipulator = osgGA.StateSetManipulator(viewer.getCamera().getStateSet())
    viewer.addEventHandler(statesetManipulator)

    # add the pick handler
    viewer.addEventHandler(PickHandler())

    viewer.realize()

    # main loop (note, window toolkits which take control over the main loop will require a window redraw callback containing the code below.)
    while  not viewer.done() :
        viewer.frame()

    return 0
Пример #2
0
def main(argv):

    
    arguments = osg.ArgumentParser( argc, argv )
    
    # Create the texture as both the output of compute shader and the input of a normal quad
    tex2D = osg.Texture2D()
    tex2D.setTextureSize( 512, 512 )
    tex2D.setFilter( osg.Texture2D.MIN_FILTER, osg.Texture2D.LINEAR )
    tex2D.setFilter( osg.Texture2D.MAG_FILTER, osg.Texture2D.LINEAR )
    tex2D.setInternalFormat( GL_R32F )
    tex2D.setSourceFormat( GL_RED )
    tex2D.setSourceType( GL_FLOAT )
    tex2D.bindToImageUnit( 0, osg.Texture.WRITE_ONLY )  # So we can use 'image2D' in the compute shader
    
    # The compute shader can't work with other kinds of shaders
    # It also requires the work group numbers. Setting them to 0 will disable the compute shader
    computeProg = osg.Program()
    computeProg.setComputeGroups( 512/16, 512/16, 1 )
    computeProg.addShader( osg.Shader(osg.Shader.COMPUTE, computeSrc) )
    
    # Create a node for outputting to the texture.
    # It is OK to have just an empty node here, but seems inbuilt uniforms like osg_FrameTime won't work then.
    # TODO: maybe we can have a custom drawable which also will implement  sourceNode = osgDB: if (glMemoryBarrier) else readNodeFile("axes.osgt")
    if   not sourceNode  : sourceNode = osg.Node()
    sourceNode.setDataVariance( osg.Object.DYNAMIC )
    sourceNode.getOrCreateStateSet().setAttributeAndModes( computeProg )
    sourceNode.getOrCreateStateSet().addUniform( osg.Uniform("targetTex", (int)0) )
    sourceNode.getOrCreateStateSet().setTextureAttributeAndModes( 0, tex2D )
    
    # Display the texture on a quad. We will also be able to operate on the data if reading back to CPU side
    geom = osg.createTexturedQuadGeometry(
        osg.Vec3(), osg.Vec3(1.0,0.0,0.0), osg.Vec3(0.0,0.0,1.0) )
    quad = osg.Geode()
    quad.addDrawable( geom )
    quad.getOrCreateStateSet().setMode( GL_LIGHTING, osg.StateAttribute.OFF )
    quad.getOrCreateStateSet().setTextureAttributeAndModes( 0, tex2D )
    
    # Create the scene graph and start the viewer
    scene = osg.Group()
    scene.addChild( sourceNode )
    scene.addChild( quad )
    
    viewer = osgViewer.Viewer()
    viewer.addEventHandler( osgGA.StateSetManipulator(viewer.getCamera().getOrCreateStateSet()) )
    viewer.addEventHandler( osgViewer.StatsHandler )()
    viewer.addEventHandler( osgViewer.WindowSizeHandler )()
    viewer.setSceneData( scene )
    return viewer.run()
Пример #3
0
def main(argv):

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

    osg.DisplaySettings.instance().setMinimumNumAlphaBits(8)

    # 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

    label = "OpenSceneGraph"
    subscript = ""

    showVersion = False
    while arguments.read("--version") :  showVersion = True 
    if  showVersion  :
        label += " "
        label += osgGetVersion()

    while arguments.read("--label", label) : 
    while arguments.read("--subscript", subscript) : 

    node = osg.Node()

    if arguments.argc()>1 : node = createLogo(arguments[1], label, subscript)
    node = createLogo("", label, subscript)

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

    return viewer.run()


if __name__ == "__main__":
    main(sys.argv)
Пример #4
0
class TestManipulator (osgGA.CameraManipulator) :

        TestManipulator()
        virtual ~TestManipulator()

        #* set the position of the matrix manipulator using a 4x4 Matrix.
        setByMatrix = virtual void( osg.Matrixd matrix)

        #* set the position of the matrix manipulator using a 4x4 Matrix.
        def setByInverseMatrix(matrix):
             setByMatrix(osg.Matrixd.inverse(matrix)) 

        #* get the position of the manipulator as 4x4 Matrix.
        virtual osg.Matrixd getMatrix() 

        #* get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.
        virtual osg.Matrixd getInverseMatrix() 

        #* Attach a node to the manipulator. 
#            Automatically detaches previously attached node.
#            setNode(NULL) detaches previously nodes.
#            Is ignored by manipulators which do not require a reference model.
        setNode = virtual void(osg.Node*)

        #* Return node if attached.
        virtual  osg.Node* getNode() 

        #* Return node if attached.
        getNode = virtual osg.Node*()

        #* Move the camera to the default position. 
#            May be ignored by manipulators if home functionality is not appropriate.
        home = virtual void( osgGA.GUIEventAdapter ea,osgGA.GUIActionAdapter us)
        
        #* Start/restart the manipulator.
        init = virtual void( osgGA.GUIEventAdapter ea,osgGA.GUIActionAdapter us)


        #* handle events, return True if handled, False otherwise.
        handle = virtual bool( osgGA.GUIEventAdapter ea,osgGA.GUIActionAdapter us)

        #* Reset the internal GUIEvent stack.
        flushMouseEventStack = void()
        #* Add the current mouse GUIEvent to internal stack.
        addMouseEvent = void( osgGA.GUIEventAdapter ea)

        computePosition = void( osg.Vec3 eye, osg.Vec3 lv, osg.Vec3 up)

        #* For the give mouse movement calculate the movement of the camera.
#            Return True is camera has moved and a redraw is required.
        calcMovement = bool()
        
        #* Check the speed at which the mouse is moving.
#            If speed is below a threshold then return False, otherwise return True.
        isMouseMoving = bool()

        # Internal event stack comprising last three mouse events.
        _ga_t1 =  osgGA.GUIEventAdapter()
        _ga_t0 =  osgGA.GUIEventAdapter()

        _node = osg.Node()

        _modelScale = float()
        _minimumZoomScale = float()

        _thrown = bool()
        
        _center = osg.Vec3()
        _rotation = osg.Quat()
        _distance = float()
Пример #5
0
    return mt


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 )
        _loadedModel = osgDB.readNodeFile(_filename)

        if _loadedModel.valid()  and  _incrementalCompileOperation.valid() :
            compileSet = osgUtil.IncrementalCompileOperation.CompileSet(_loadedModel)

            compileSet._compileCompletedCallback = ReleaseBlockOnCompileCompleted(_block)

            _incrementalCompileOperation.add(compileSet)
        else:
            if _block.valid() : _block.completed()

        # osg.notify(osg.NOTICE), "done LoadAndCompileOperation ", _filename
    
    _filename = str()
    _loadedModel = osg.Node()
    _incrementalCompileOperation = osgUtil.IncrementalCompileOperation()
    _block = osg.RefBlockCount()



class MasterOperation (osg.Operation) :

    typedef std.set<str> Files
    typedef std.map<str, osg.Node >  FilenameNodeMap
    typedef std.vector< osg.Node >  Nodes


    MasterOperation( str filename, osgUtil.IncrementalCompileOperation* ico):
        Operation("Master reading operation",True),
        _filename(filename),
Пример #7
0
                    # F9 -- Remove all OcclusionQueryNodes
                    roqv = RemoveOcclusionQueryVisitor()
                    _node.accept( roqv )
                    return True
                elif ea.getKey()==ord("o") :
                    if osgDB.writeNodeFile( _node, "saved_model.osgt" ) :
                        osg.notify( osg.ALWAYS ), "osgOQ: Wrote scene graph to \"saved_model.osgt\""
                    else:
                        osg.notify( osg.ALWAYS ), "osgOQ: Wrote failed for \"saved_model.osgt\""
                    return True
                return False
            default:
                break
        return False

    _node = osg.Node()

    bool _enable, _debug


# Create a cube with one side missing. This makes a great simple occluder.
def createBox():
    
    box = osg.Geode()

    state = box.getOrCreateStateSet()
    pm = osg.PolygonMode(
        osg.PolygonMode.FRONT_AND_BACK, osg.PolygonMode.FILL )
    state.setAttributeAndModes( pm,
        osg.StateAttribute.ON | osg.StateAttribute.PROTECTED )
Пример #8
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

    viewer = osgViewer.Viewer(arguments)
    
    outputfile = str("output.osgt")
    while arguments.read("-o",outputfile) : 

    while arguments.read("-s") :  viewer.setThreadingModel(osgViewer.Viewer.SingleThreaded) 
    while arguments.read("-g") :  viewer.setThreadingModel(osgViewer.Viewer.CullDrawThreadPerContext) 
    while arguments.read("-d") :  viewer.setThreadingModel(osgViewer.Viewer.DrawThreadPerContext) 
    while arguments.read("-c") :  viewer.setThreadingModel(osgViewer.Viewer.CullThreadPerCameraDrawThreadPerContext) 
    
    singleWindowSideBySideCameras(viewer)

    viewer.setCameraManipulator( osgGA.TrackballManipulator() )
    viewer.addEventHandler(osgViewer.StatsHandler)()
    viewer.addEventHandler(osgViewer.ThreadingHandler)()
    viewer.addEventHandler(osgViewer.WindowSizeHandler())
    viewer.addEventHandler(osgViewer.LODScaleHandler())
    viewer.addEventHandler(osgGA.StateSetManipulator())

    visit = SwitchDOFVisitor()
    viewer.addEventHandler(visit)
    
    loadedModel = osg.Node()
    # load the scene.
    loadedModel = osgDB.readNodeFiles(arguments)

    if  not loadedModel : 
        print argv[0], ": No data loaded."
        return 1

    group = osg.Group()
    
    group1 = osg.Group()
    group1.addChild(loadedModel)
    group1.setNodeMask(1)

    # Uncomment these lines if you like to compare the loaded model to the resulting model in a merge/diff tool
    #osgDB.writeNodeFile(*loadedModel, "dummy1.osgt")

    osgDB.writeNodeFile(*loadedModel, outputfile)
    convertedModel = osgDB.readNodeFile(outputfile)

    #osgDB.writeNodeFile(*convertedModel, "dummy2.osgt")

    group2 = osg.Group()
    group2.addChild(convertedModel)
    group2.setNodeMask(2)

    # Activate DOF animations and collect switches
    loadedModel.accept(*visit)
    convertedModel.accept(*visit)

    group.addChild(group1)
    group.addChild(group2)

    viewer.setSceneData(group)

    viewer.setThreadingModel(osgViewer.Viewer.DrawThreadPerContext)
    viewer.realize()

    viewer.run()

    return 0



if __name__ == "__main__":
    main(sys.argv)
Пример #9
0
 def test_resultTypes(self):
     g = osg.GraphicsCostEstimator()
     node = osg.Node()
     g.estimateCompileCost(node)