コード例 #1
0
def main(argv):

    
    arguments = osg.ArgumentParser(argv)

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

    # 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 )
コード例 #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()
コード例 #3
0
def main(argv):
    overlay = False
    arguments = osg.ArgumentParser(argv)
    while arguments.read("--overlay") : 
        overlay = True
    technique = osgSim.OverlayNode.OBJECT_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY
    while arguments.read("--object") :  
        technique = osgSim.OverlayNode.OBJECT_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY 
        overlay=True 
    while arguments.read("--ortho")  or  arguments.read("--orthographic") :  
        technique = osgSim.OverlayNode.VIEW_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY 
        overlay=True 
    while arguments.read("--persp")  or  arguments.read("--perspective") :  
        technique = osgSim.OverlayNode.VIEW_DEPENDENT_WITH_PERSPECTIVE_OVERLAY 
        overlay=True 
    # initialize the viewer.
    viewer = osgViewer.Viewer()
    # load the nodes from the commandline arguments.
    model = createModel(overlay, technique)
    if not model:
        return 1
    # tilt the scene so the default eye position is looking down on the model.
    rootnode = osg.MatrixTransform()
    rootnode.setMatrix(osg.Matrix.rotate(osg.inDegrees(30.0),1.0,0.0,0.0))
    rootnode.addChild(model)
    # run optimization over the scene graph
    optimzer = osgUtil.Optimizer()
    optimzer.optimize(rootnode)
    # set the scene to render
    viewer.setSceneData(rootnode)
    viewer.setCameraManipulator(osgGA.TrackballManipulator())
    # viewer.setUpViewOnSingleScreen(1)
    # normal viewer usage.
    return viewer.run()
コード例 #4
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()
コード例 #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()
コード例 #6
0
ファイル: osgfont.py プロジェクト: snowfox1939/osgpyplusplus
def main(argv):

    
    viewer = osgViewer.Viewer()
    args = osg.ArgumentParser(argv)

    # Make sure we have the minimum args...
    if argc <= 2 :
        osg.notify(osg.FATAL), "usage: ", args[0], " fontfile size1 [size2 ...]"

        return 1


    viewer.addEventHandler( osgGA.StateSetManipulator(viewer.getCamera().getOrCreateStateSet()) )
    viewer.addEventHandler(osgViewer.StatsHandler())
    viewer.addEventHandler(osgViewer.WindowSizeHandler())

    group = osg.Group()
    camera = createOrthoCamera(1280.0, 1024.0)

    # Create the list of desired sizes.
    sizes = Sizes()

    for(int i = 2 i < argc i++)
        if  not args.isNumber(i) : continue

        sizes.push_back(std.atoi(args[i]))
コード例 #7
0
def main(argv):

    
    viewer = osgViewer.Viewer()

    wm = osgWidget.WindowManager(
        viewer,
        1280.0,
        720.0,
        MASK_2D #,
        #osgWidget.WindowManager.WM_USE_RENDERBINS
    )

    notebook1 = Notebook("notebook1")
    notebook2 = Notebook("notebook2")

    notebook2.setOrigin(100.0, 100.0)

    notebook1.attachMoveCallback()
    notebook2.attachMoveCallback()

    wm.addChild(notebook1)
    wm.addChild(notebook2)

    return osgWidget.createExample(viewer, wm)
コード例 #8
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()
コード例 #9
0
def main(argv):

    
    arguments = osg.ArgumentParser(argv)
    viewer = osgViewer.Viewer(arguments)
    
    tbm = osgGA.TrackballManipulator()

    viewer.setCameraManipulator(tbm)

    viewer.addEventHandler(osgViewer.StatsHandler())
    viewer.addEventHandler(osgViewer.WindowSizeHandler())

    root = osg.Group()
    geode = osg.Geode()

    geode.setStateSet(setupStateSet())

    root.setInitialBound(osg.BoundingSphere(osg.Vec3(10,0,20), 50))
    root.addChild(setupAnimtkNode(geode))
    root.addChild(geode)

    viewer.setSceneData(root)

    # tbm.setDistance(150)

    return viewer.run()
コード例 #10
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)
コード例 #11
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().setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...")
    arguments.getApplicationUsage().addCommandLineOption("--image <filename>","Load an image and render it on a quad")
    arguments.getApplicationUsage().addCommandLineOption("--dem <filename>","Load an image/DEM and render it on a HeightField")
    arguments.getApplicationUsage().addCommandLineOption("-h or --help","Display command line parameters")
    arguments.getApplicationUsage().addCommandLineOption("--help-env","Display environmental variables available")
    arguments.getApplicationUsage().addCommandLineOption("--help-keys","Display keyboard  mouse bindings available")
    arguments.getApplicationUsage().addCommandLineOption("--help-all","Display all command line, env vars and keyboard  mouse bindings.")

    arguments.getApplicationUsage().addCommandLineOption("--dragger <draggername>","Use the specified dragger for manipulation [TabPlaneDragger, TabPlaneTrackballDragger, TrackballDragger, Translate1DDragger, Translate2DDragger, TranslateAxisDragger, TabBoxDragger, TranslatePlaneDragger, Scale1DDragger, Scale2DDragger, RotateCylinderDragger, RotateSphereDragger]")
    arguments.getApplicationUsage().addCommandLineOption("--fixedDraggerSize","Fix the size of the dragger geometry in the screen space")
    
    fixedSizeInScreen = False
    while arguments.read("--fixedDraggerSize") :  fixedSizeInScreen = True 

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

    # get details on keyboard and mouse bindings used by the viewer.
    viewer.getUsage(*arguments.getApplicationUsage())

    # if user request help write it out to cout.
    helpAll = arguments.read("--help-all")
    helpType = ( osg.ApplicationUsage.COMMAND_LINE_OPTION if ((helpAll  or  arguments.read("-h")  or  arguments.read("--help"))) else  0 ) |
                            ( osg.ApplicationUsage.ENVIRONMENTAL_VARIABLE if ((helpAll  or   arguments.read("--help-env"))) else  0 ) |
                            ( osg.ApplicationUsage.KEYBOARD_MOUSE_BINDING if ((helpAll  or   arguments.read("--help-keys"))) else  0 )
コード例 #12
0
def main(argv):    
    viewer = osgViewer.Viewer()
    wm = osgWidget.WindowManager(
        viewer,
        1280.0,
        1024.0,
        MASK_2D,
        osgWidget.WindowManager.WM_PICK_DEBUG
    )
    box = osgWidget.Box("vbox", osgWidget.Box.VERTICAL)
    input_ = osgWidget.Input("input", "", 50)
    input_.setFont("fonts/VeraMono.ttf")
    input_.setFontColor(0.0, 0.0, 0.0, 1.0)
    input_.setFontSize(15)
    input_.setYOffset(input_.calculateBestYOffset("y"))
    input_.setSize(400.0, input_.getText().getCharacterHeight())
    box.addWidget(input_)
    box.setOrigin(200.0, 200.0)
    wm.addChild(box)
    viewer.setUpViewInWindow(
        50,
        50,
        int(wm.getWidth()),
        int(wm.getHeight())
    )
    camera = wm.createParentOrthoCamera()
    viewer.addEventHandler(osgWidget.MouseHandler(wm))
    viewer.addEventHandler(osgWidget.KeyboardHandler(wm))
    viewer.addEventHandler(osgWidget.ResizeHandler(wm, camera))
    viewer.addEventHandler(osgWidget.CameraSwitchHandler(wm, camera))
    viewer.addEventHandler(osgViewer.WindowSizeHandler())
    wm.resizeAllWindows()
    viewer.setSceneData(camera)
    return viewer.run()
コード例 #13
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()
コード例 #14
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
コード例 #15
0
class MainFrame (wxFrame) :
    MainFrame(wxFrame *frame,  wxString title,  wxPoint pos,
         wxSize size, long style = wxDEFAULT_FRAME_STYLE)

    SetViewer = void(osgViewer.Viewer *viewer)
    OnIdle = void(wxIdleEvent event)
    _viewer = osgViewer.Viewer()

    DECLARE_EVENT_TABLE()
コード例 #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 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()
コード例 #17
0
def main(argv):


    
    # Qt requires that we construct the global QApplication before creating any widgets.
    app = QApplication(argc, argv)

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

    useFrameLoopThread = False
    if arguments.read("--no-frame-thread") : useFrameLoopThread = False
    if arguments.read("--frame-thread") : useFrameLoopThread = True

    image = osgQt.QWebViewImage()

    if arguments.argc()>1 : image.navigateTo((arguments[1]))
    else image.navigateTo("http:#www.youtube.com/")

    hints = osgWidget.GeometryHints(osg.Vec3(0.0,0.0,0.0),
                                   osg.Vec3(1.0,0.0,0.0),
                                   osg.Vec3(0.0,0.0,1.0),
                                   osg.Vec4(1.0,1.0,1.0,1.0),
                                   osgWidget.GeometryHints.RESIZE_HEIGHT_TO_MAINTAINCE_ASPECT_RATIO)


    browser = osgWidget.Browser()
    browser.assign(image, hints)

    # image.focusBrowser(True)

    viewer = osgViewer.Viewer(arguments)
    viewer.setSceneData(browser)
    viewer.setCameraManipulator(osgGA.TrackballManipulator())
    viewer.addEventHandler(osgViewer.StatsHandler)()
    viewer.addEventHandler(osgViewer.WindowSizeHandler)()

    if useFrameLoopThread :
        # create a thread to run the viewer's frame loop
        viewerThread = ViewerFrameThread(viewer, True)
        viewerThread.startThread()

        # now start the standard Qt event loop, then exists when the viewerThead sends the QApplication.exit() signal.
        return QApplication.exec()

    else:
        # run the frame loop, interleaving Qt and the main OSG frame loop
        while  not viewer.done() :
            # process Qt events - this handles both events and paints the browser image
            QCoreApplication.processEvents(QEventLoop.AllEvents, 100)

            viewer.frame()

        return 0
コード例 #18
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))
コード例 #19
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
コード例 #20
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()
コード例 #21
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 ----------"
コード例 #22
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()
コード例 #23
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("--snow <density>","Set the snow with a density between 0 and 1.0")
    arguments.getApplicationUsage().addCommandLineOption("--rain <density>","")
    arguments.getApplicationUsage().addCommandLineOption("--particleSize <size>","")
    arguments.getApplicationUsage().addCommandLineOption("--particleColour <red> <green> <blue> <alpha>","")
    arguments.getApplicationUsage().addCommandLineOption("--wind <x> <y> <z>","Set the wind speed in model coordinates")
    arguments.getApplicationUsage().addCommandLineOption("--particleSpeed <float>","Set the particle speed")
    arguments.getApplicationUsage().addCommandLineOption("--nearTransition <distance>","Set the near transistion distance")
    arguments.getApplicationUsage().addCommandLineOption("--farTransition  <distance>","Set the far transistion distance")
    arguments.getApplicationUsage().addCommandLineOption("--particleDensity <density>","Set the particle density")
    arguments.getApplicationUsage().addCommandLineOption("--cellSize <x> <y> <z>","Set the cell size in model coordinates")
    arguments.getApplicationUsage().addCommandLineOption("--fogDensity <density>","Set the fog density")
    arguments.getApplicationUsage().addCommandLineOption("--fogColour <red> <green> <blue> <alpha>","Set fog colour.")
    arguments.getApplicationUsage().addCommandLineOption("-useFarLineSegments","Switch on the use of line segments")
    

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

    # 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 )
コード例 #24
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()
コード例 #25
0
def main(argv):

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

    arguments.getApplicationUsage().setApplicationName(arguments.getApplicationName())
    arguments.getApplicationUsage().setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...")

    viewer = osgViewer.Viewer(arguments)

    helpType = 0
    if helpType = arguments.readHelpType() : :
        arguments.getApplicationUsage().write(std.cout, helpType)
        return 1
コード例 #26
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()
コード例 #27
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()
コード例 #28
0
def main(argv):
    arguments = osg.ArgumentParser(argv)
    viewer = osgViewer.Viewer(arguments)
    hints = osgWidget.GeometryHints(
        osg.Vec3(0.0, 0.0, 0.0), osg.Vec3(1.0, 0.0, 0.0),
        osg.Vec3(0.0, 0.0, 1.0), osg.Vec4(1.0, 1.0, 1.0, 1.0),
        osgWidget.GeometryHints.RESIZE_HEIGHT_TO_MAINTAINCE_ASPECT_RATIO)
    group = osg.Group()
    for i in range(len(argv)):
        if not arguments.isOption(i):
            pdfReader = osgWidget.PdfReader()
            if pdfReader.open(arguments[i], hints):
                group.addChild(pdfReader.get())
                hints.position.x += 1.1
    viewer.setSceneData(group)
    viewer.addEventHandler(osgViewer.StatsHandler())
    return viewer.run()
コード例 #29
0
def main(argv):


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

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

    # create a model from the images.
    rootNode = createModel((arguments.argc() >  arguments[1] if (1) else  "Images/lz.rgb"))

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

    return viewer.run()
コード例 #30
0
def main(argv):

    
    viewer = osgViewer.Viewer()

    wm = osgWidget.WindowManager(
        viewer,
        WINDOW_WIDTH,
        WINDOW_HEIGHT,
        MASK_2D
        )

    menu = osgWidget.Box("menu", osgWidget.Box.HORIZONTAL)

    menu.addWidget(ColorLabelMenu("Choose EaseMotion"))
    menu.getBackground().setColor(1.0, 1.0, 1.0, 1.0)
    menu.setPosition(15.0, 15.0, 0.0)

    wm.addChild(menu)

    group = osg.Group()
    geode = osg.Geode()
    mt = osg.MatrixTransform()

    geode.addDrawable(osg.ShapeDrawable(osg.Sphere(osg.Vec3(), 4.0)))

    EASE_MOTION_SAMPLER = EaseMotionSampler(osg.Vec3(50.0, 0.0, 0.0))
    EASE_MOTION_GEODE   = osg.Geode()

    mt.addChild(geode)
    mt.setUpdateCallback(EASE_MOTION_SAMPLER)
    mt.setNodeMask(MASK_3D)

    viewer.setCameraManipulator(osgGA.TrackballManipulator())
    viewer.getCameraManipulator().setHomePosition(
        osg.Vec3d(0.0, 0.0, 200.0),
        osg.Vec3d(20.0, 0.0, 0.0),
        osg.Vec3d(0.0, 1.0, 0.0)
        )
    viewer.home()

    group.addChild(mt)
    group.addChild(EASE_MOTION_GEODE)

    return osgWidget.createExample(viewer, wm, group)