Beispiel #1
0
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]))
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()
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()
            switch(ea.getEventType())
                case(osgGA.GUIEventAdapter.KEYDOWN):
                    _keyboardModel.keyChange(ea.getKey(), ea.getUnmodifiedKey(),1)
                    return True
                case(osgGA.GUIEventAdapter.KEYUP):
                    _keyboardModel.keyChange(ea.getKey(), ea.getUnmodifiedKey(),0)
                    return True

                default:
                    return False
        
        _keyboardModel = KeyboardModel()
        


int main(int , char **)
    viewer = osgViewer.Viewer()

    keyboardModel = KeyboardModel()

    viewer.addEventHandler(osgViewer.StatsHandler)()
    viewer.addEventHandler(osgViewer.WindowSizeHandler())
    viewer.addEventHandler(KeyboardEventHandler(keyboardModel))
    viewer.setSceneData( keyboardModel.getScene() )

    return viewer.run()


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

    
    arguments = osg.ArgumentParser(argv)

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

    # set up 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() )

        keyForAnimationPath = ord("8")
        animationSpeed = 1.0
        while arguments.read("--speed",animationSpeed)  : 

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

        viewer.setCameraManipulator( keyswitchManipulator )

    # set up event handlers 
        viewer.addEventHandler( osgViewer.StatsHandler())
        viewer.addEventHandler( osgViewer.WindowSizeHandler() )
        viewer.addEventHandler( osgGA.StateSetManipulator(viewer.getCamera().getOrCreateStateSet()) )
        viewer.addEventHandler( TexturePoolHandler() )

    ########################################/
    #
    # IncrementalCompileOperation settings
    #
    incrementalCompile = osgUtil.IncrementalCompileOperation()
    viewer.setIncrementalCompileOperation(incrementalCompile)

    if arguments.read("--force")  or  arguments.read("-f") :
        incrementalCompile.assignForceTextureDownloadGeometry()

    if arguments.read("-a") :
        incrementalCompile.setMinimumTimeAvailableForGLCompileAndDeletePerFrame(1)
        incrementalCompile.setConservativeTimeRatio(1)
        incrementalCompile.setMaximumNumOfObjectsToCompilePerFrame(100)
    elif arguments.read("-c") :
        incrementalCompile.setMinimumTimeAvailableForGLCompileAndDeletePerFrame(0.0001)
        incrementalCompile.setConservativeTimeRatio(0.01)
        incrementalCompile.setMaximumNumOfObjectsToCompilePerFrame(1)

    ########################################/
    #
    # SceneGraph processing setup
    #
    sceneGraphProcessor = SceneGraphProcessor(arguments)

    ########################################/
    #
    # Database settings
    #
    timeBetweenMerges = 2.0
    while arguments.read("--interval",timeBetweenMerges) : 

    outputPostfix = str()
    while arguments.read("-o",outputPostfix) :  OSG_NOTICE, "Set ouputPostfix to ", outputPostfix 


    typedef std.vector< str > FileNames
    fileNames = FileNames()
    for(int pos=1pos<arguments.argc()++pos)
        if  not arguments.isOption(pos) :
            fileNames.push_back(arguments[pos])

    if fileNames.empty() :
        OSG_NOTICE, "No files loaded, please specify files on commandline."
        return 1

    # load the models using a paging thread and use the incremental compile operation to
    # manage the compilation of GL objects without breaking frame.

    modelIndex = 0

    databasePagingThread = osg.OperationThread()
    databasePagingOperation = DatabasePagingOperation()

    databasePagingThread = osg.OperationThread()
    databasePagingThread.startThread()


    group = osg.Group()
    viewer.setSceneData(group)

    viewer.realize()

    filename = fileNames[modelIndex++]
    outputFilename =  str() : osgDB: if (outputPostfix.empty()) else getStrippedName(filename)+outputPostfix

    databasePagingOperation = DatabasePagingOperation(
        filename,
        outputFilename,
        sceneGraphProcessor,
        incrementalCompile)

    databasePagingThread.add(databasePagingOperation)


    timeOfLastMerge = viewer.getFrameStamp().getReferenceTime()

    while  not viewer.done() :
        viewer.frame()

        currentTime = viewer.getFrameStamp().getReferenceTime()

        if  not databasePagingOperation  and 
            modelIndex<fileNames.size()  and 
            (currentTime-timeOfLastMerge)>timeBetweenMerges :
            filename = fileNames[modelIndex++]
            outputFilename =  str() : osgDB: if (outputPostfix.empty()) else getStrippedName(filename)+outputPostfix

            databasePagingOperation = DatabasePagingOperation(
                filename,
                outputFilename,
                sceneGraphProcessor,
                incrementalCompile)

            databasePagingThread.add(databasePagingOperation)

        if databasePagingOperation  and  databasePagingOperation._modelReadyToMerge :
            OSG_NOTICE, "Merging subgraph"
            
            timeOfLastMerge = currentTime

            group.removeChildren(0,group.getNumChildren())

            group.addChild(databasePagingOperation._loadedModel)

            viewer.home()

            # we no longer need the paging operation as it's done it's job.
            databasePagingOperation = 0

            viewer.home()
def main(argv):

    
    viewer = osgViewer.Viewer()
    
    # Let's get busy not  The WindowManager class is actually an osg.Switch,
    # so you can add it to (ideally) an orthographic camera and have it behave as
    # expected. Note that you create a WindowManager with a NodeMask--it is very important
    # that this be unique for picking to work properly. This also makes it possible to have
    # multiple WindowManagers each operating on their own, unique set of Window objects.
    # The final bool argument is a group of flags that introduce optional functionality
    # for the WindowManager. In our case we include the flags USE_PYTHON and USE_LUA,
    # to demonstrate (and test) their usage. Finally, we pass the temporary WM_NO_BETA_WARN
    # argument, which prevents creating the orange warning window. :) It will be shown
    # in other examples...
    wm = osgWidget.WindowManager(
        viewer,
        1280.0,
        1024.0,
        MASK_2D,
        osgWidget.WindowManager.WM_USE_LUA |
        osgWidget.WindowManager.WM_USE_PYTHON |
        osgWidget.WindowManager.WM_PICK_DEBUG
    )

    # An actual osgWidget.Window is pure virtual, so we've got to use the osgWidget.Box
    # implementation for now. At a later time, support for Tables and other kinds of
    # advanced layout Window types will be added.
    box = osgWidget.Box("box", osgWidget.Box.HORIZONTAL)

    # Now we actually attach our two types of callbacks to the box instance. The first
    # uses the simple function signature, the second uses a bound method, passing "this"
    # as the second argument to the Callback constructor.
    # Object obj

    static str data = "lol ur face not "

    #
#    box.addCallback(osgWidget.Callback(windowClicked, osgWidget.EVENT_MOUSE_PUSH, data))
#    box.addCallback(osgWidget.Callback(windowScrolled, osgWidget.EVENT_MOUSE_SCROLL))
#    box.addCallback(osgWidget.Callback(
#        Object.windowClicked,
#        obj,
#        osgWidget.EVENT_MOUSE_PUSH
#    ))
#    

    box.addCallback(CallbackObject(osgWidget.EVENT_MOUSE_PUSH))

    # Create some of our "testing" Widgets included are two Widget subclasses I made
    # during testing which I've kept around for testing purposes. You'll notice
    # that you cannot move the box using the NullWidget, and that the NotifyWidget
    # is a bit verbose. :)
    widget1 = osgWidget.NotifyWidget("widget1", 300.0, 100.0)
    widget2 = osgWidget.NullWidget("widget2", 400.0, 75.0)
    widget3 = osgWidget.Widget("widget3", 100.0, 100.0)
    # Set the colors of widget1 and widget3 to green.
    widget1.setColor(0.0, 1.0, 0.0, 1.0)
    widget1.setCanFill(True)
    widget3.setColor(0.0, 1.0, 0.0, 1.0)

    widget1.setImage(osgDB.readImageFile("Images/Saturn.TGA"), True)

    # Set the color of widget2, to differentiate it and make it sassy. This is
    # like a poor man's gradient not 
    widget2.setColor(0.9, 0.0, 0.0, 0.9, osgWidget.Widget.LOWER_LEFT)
    widget2.setColor(0.9, 0.0, 0.0, 0.9, osgWidget.Widget.LOWER_RIGHT)
    widget2.setColor(0.0, 0.0, 0.9, 0.9, osgWidget.Widget.UPPER_RIGHT)
    widget2.setColor(0.0, 0.0, 0.9, 0.9, osgWidget.Widget.UPPER_LEFT)

    # Now add our newly created widgets to our box.
    box.addWidget(widget1)
    box.addWidget(widget2)
    box.addWidget(widget3)

    # For maximum efficiency, Windows don't automatically reallocate their geometry
    # and internal positioning every time a widget is added. Thus, we either have to
    # call the WindowManger.resizeAllWindows method or manually call
    # Window.resize when we're ready.
    box.resize()

    # Now, lets clone our existing box and create a copy of of it, also adding that
    # to the WindowManager. This demonstrates the usages of OSG's .clone() support,
    # though that is abstracted by our META_UIObject macro.
    boxCopy = osg.clone(box, "newBox", osg.CopyOp.DEEP_COPY_ALL)

    # Move our copy to make it visible.
    boxCopy.setOrigin(0.0, 125.0)

    boxCopy.getByName("widget1").setColor(0.5, 0.0, 1.0, 1.0)
    boxCopy.getByName("widget3").setColor(0.5, 0.0, 1.0, 1.0)

    # Add the successfully created Box (if we get this far) into the WindowManager, so
    # that they can receive events.
    wm.addChild(box)
    wm.addChild(boxCopy)

    # Now, ask our box to be 100% the width of the WindowManager.
    boxCopy.resizePercent(100.0, 0.0)

    # Here we demonstrate the use of osgWidget/io_utils. This is really only useful for
    # debugging at the moment.
    # print *box, *boxCopy

    # Setup our OSG objects for our scene note the use of the utility function
    # createOrthoCamera, which is just a helper for setting up a proper viewing area.
    # An alternative (and a MUCH easier alternative at that not ) is to
    # simply use the createParentOrthoCamera method of the WindowManager class,
    # which will wrap the calls to createOrthoCamera and addChild for us not  Check out
    # some of the other examples to see this in action...
    group = osg.Group()
    camera = osgWidget.createOrthoCamera(1280.0, 1024.0)
    model = osgDB.readNodeFile("cow.osgt")

    # Add our event handler is this better as a MatrixManipulator? Add a few other
    # helpful ViewerEventHandlers.
    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.StatsHandler())
    viewer.addEventHandler(osgViewer.WindowSizeHandler())
    viewer.addEventHandler(osgGA.StateSetManipulator(
        viewer.getCamera().getOrCreateStateSet()
    ))

    # Set our first non-UI node to be something other than the mask we created our
    # WindowManager with to avoid picking.
    # TODO: Do I need to create a mechanism for doing this automatically, or should
    # that be the responsibility of the users of osgWidget?
    model.setNodeMask(MASK_3D)

    # Add the WindowManager instance to the 2D camera. This isn't strictly necessary,
    # and you can get some cool results putting the WindowManager directly into a
    # 3D scene. This is not necessary if you use WindowManager.createParentOrthoCamera.
    camera.addChild(wm)

    # Add our camera and a testing 3D model to the scene.
    group.addChild(camera)
    group.addChild(model)

    # Here we show how to both run simple strings of code AND run entire files. These
    # assume that you're running the osgwidgetwindow example from the build directory,
    # otherwise you'll need to adjust the file path below in the call to runFile().
    wm.getLuaEngine().eval("window = osgwidget.newWindow()")
    wm.getLuaEngine().runFile("osgWidget/osgwidgetwindow.lua")

    wm.getPythonEngine().eval("import osgwidget")
    wm.getPythonEngine().runFile("osgWidget/osgwidgetwindow.py")

    viewer.setUpViewInWindow(0, 0, 1280, 1024)
    viewer.setSceneData(group)

    #
#    cameras = osgViewer.Viewer.Cameras() 
#    viewer.getCameras(cameras)
#    c = cameras[0]
#    s = osg.Matrix.scale(1.0, -1.0, 1.0)
#    c.setProjectionMatrix(s * c.getProjectionMatrix())
#    

    return viewer.run()
Beispiel #7
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)
def main(argv):

    
    arguments = osg.ArgumentParser(argv)
    arguments.getApplicationUsage().setApplicationName(arguments.getApplicationName())
    arguments.getApplicationUsage().setDescription(arguments.getApplicationName()+" is an example for viewing osgAnimation animations.")
    arguments.getApplicationUsage().addCommandLineOption("-h or --help","List command line options.")
    arguments.getApplicationUsage().addCommandLineOption("--drawbone","draw helps to display bones.")

    if arguments.read("-h")  or  arguments.read("--help") :
        arguments.getApplicationUsage().write(std.cout, osg.ApplicationUsage.COMMAND_LINE_OPTION)
        return 0

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

    drawBone = False
    if arguments.read("--drawbone") :
        drawBone = True

    viewer = osgViewer.Viewer(arguments)
    group = osg.Group()

    node = dynamic_cast<osg.Group*>(osgDB.readNodeFiles(arguments)) #dynamic_cast<osgAnimation.AnimationManager*>(osgDB.readNodeFile(psr[1]))
    if  not node :
        print arguments.getApplicationName(), ": No data loaded"
        return 1

    # Set our Singleton's model.
    finder = AnimationManagerFinder()
    node.accept(finder)
    if finder._am.valid() : 
        node.setUpdateCallback(finder._am)
        AnimtkViewerModelController.setModel(finder._am)
     else:
        osg.notify(osg.WARN), "no osgAnimation.AnimationManagerBase found in the subgraph, no animations available"

    if drawBone : 
        osg.notify(osg.INFO), "Add Bones Helper"
        addHelper = AddHelperBone()
        node.accept(addHelper)
    node.addChild(createAxis())

    gui = AnimtkViewerGUI(viewer, WIDTH, HEIGHT, 0x1234)
    camera = gui.createParentOrthoCamera()

    node.setNodeMask(0x0001)

    group.addChild(node)
    group.addChild(camera)

    viewer.addEventHandler(AnimtkKeyEventHandler())
    viewer.addEventHandler(osgViewer.StatsHandler())
    viewer.addEventHandler(osgViewer.WindowSizeHandler())
    viewer.addEventHandler(osgGA.StateSetManipulator(viewer.getCamera().getOrCreateStateSet()))
    viewer.addEventHandler(osgWidget.MouseHandler(gui))
    viewer.addEventHandler(osgWidget.KeyboardHandler(gui))
    viewer.addEventHandler(osgWidget.ResizeHandler(gui, camera))
    viewer.setSceneData(group)

    viewer.setUpViewInWindow(40, 40, WIDTH, HEIGHT)

    return viewer.run()