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()
def addViewWidget(gw, scene): view = osgViewer.View() addView( view ) camera = view.getCamera() camera.setGraphicsContext( gw ) traits = gw.getTraits() camera.setClearColor( osg.Vec4(0.2, 0.2, 0.6, 1.0) ) camera.setViewport( osg.Viewport(0, 0, traits.width, traits.height) ) camera.setProjectionMatrixAsPerspective(30.0, static_cast<double>(traits.width)/static_cast<double>(traits.height), 1.0, 10000.0 ) view.setSceneData( scene ) view.addEventHandler( osgViewer.StatsHandler )() view.setCameraManipulator( osgGA.TrackballManipulator )() return gw.getGLWidget()
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()
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. view = osgViewer.View() viewer.addView( view ) view.setUpViewInWindow( 10, 10, 640, 480 ) view.setSceneData( scene ) view.setCameraManipulator( osgGA.TrackballManipulator )() # Create view 1 -- Contains the loaded moel, as well as a wireframe frustum derived from View 0's Camera. view = osgViewer.View() viewer.addView( view ) view.setUpViewInWindow( 10, 510, 640, 480 ) view.setSceneData( root ) view.setCameraManipulator( osgGA.TrackballManipulator )() while not viewer.done() :
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()
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 : print argv[0], ": requires filename argument." return 1 # construct the viewer. viewer = osgViewer.CompositeViewer(arguments) if arguments.read("-1") : view = osgViewer.View() view.setName("Single view") view.setSceneData(osgDB.readNodeFile("fountain.osgt")) view.addEventHandler( osgViewer.StatsHandler )() view.setUpViewAcrossAllScreens() view.setCameraManipulator(osgGA.TrackballManipulator)() viewer.addView(view) if arguments.read("-2") : # view one view = osgViewer.View() view.setName("View one") viewer.addView(view) view.setUpViewOnSingleScreen(0) view.setSceneData(scene) view.setCameraManipulator(osgGA.TrackballManipulator)() # add the state manipulator statesetManipulator = osgGA.StateSetManipulator() statesetManipulator.setStateSet(view.getCamera().getOrCreateStateSet()) view.addEventHandler( statesetManipulator ) # view two view = osgViewer.View() view.setName("View two") viewer.addView(view) view.setUpViewOnSingleScreen(1) view.setSceneData(scene) view.setCameraManipulator(osgGA.TrackballManipulator)() view.addEventHandler( osgViewer.StatsHandler )() # add the handler for doing the picking view.addEventHandler(PickHandler()) if arguments.read("-3") or viewer.getNumViews()==0 : wsi = osg.GraphicsContext.getWindowingSystemInterface() if not wsi : osg.notify(osg.NOTICE), "Error, no WindowSystemInterface available, cannot create windows." return 1 unsigned int width, height wsi.getScreenResolution(osg.GraphicsContext.ScreenIdentifier(0), width, height) traits = osg.GraphicsContext.Traits() traits.x = 100 traits.y = 100 traits.width = 1000 traits.height = 800 traits.windowDecoration = True traits.doubleBuffer = True traits.sharedContext = 0 gc = osg.GraphicsContext.createGraphicsContext(traits) if gc.valid() : osg.notify(osg.INFO), " GraphicsWindow has been created successfully." # need to ensure that the window is cleared make sure that the complete window is set the correct colour # rather than just the parts of the window that are under the camera's viewports gc.setClearColor(osg.Vec4f(0.2,0.2,0.6,1.0)) gc.setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) else: osg.notify(osg.NOTICE), " GraphicsWindow has not been created successfully." # view one view = osgViewer.View() view.setName("View one") viewer.addView(view) view.setSceneData(scene) view.getCamera().setName("Cam one") view.getCamera().setViewport(osg.Viewport(0,0, traits.width/2, traits.height/2)) view.getCamera().setGraphicsContext(gc) view.setCameraManipulator(osgGA.TrackballManipulator)() # add the state manipulator statesetManipulator = osgGA.StateSetManipulator() statesetManipulator.setStateSet(view.getCamera().getOrCreateStateSet()) view.addEventHandler( statesetManipulator ) view.addEventHandler( osgViewer.StatsHandler )() view.addEventHandler( osgViewer.HelpHandler )() view.addEventHandler( osgViewer.WindowSizeHandler )() view.addEventHandler( osgViewer.ThreadingHandler )() view.addEventHandler( osgViewer.RecordCameraPathHandler )() # view two view = osgViewer.View() view.setName("View two") viewer.addView(view) view.setSceneData(scene) view.getCamera().setName("Cam two") view.getCamera().setViewport(osg.Viewport(traits.width/2,0, traits.width/2, traits.height/2)) view.getCamera().setGraphicsContext(gc) view.setCameraManipulator(osgGA.TrackballManipulator)() # add the handler for doing the picking view.addEventHandler(PickHandler()) # view three view = osgViewer.View() view.setName("View three") viewer.addView(view) view.setSceneData(osgDB.readNodeFile("cessnafire.osgt")) view.getCamera().setName("Cam three") view.getCamera().setProjectionMatrixAsPerspective(30.0, double(traits.width) / double(traits.height/2), 1.0, 1000.0) view.getCamera().setViewport(osg.Viewport(0, traits.height/2, traits.width, traits.height/2)) view.getCamera().setGraphicsContext(gc) view.setCameraManipulator(osgGA.TrackballManipulator)() while arguments.read("-s") : viewer.setThreadingModel(osgViewer.CompositeViewer.SingleThreaded) while arguments.read("-g") : viewer.setThreadingModel(osgViewer.CompositeViewer.CullDrawThreadPerContext) while arguments.read("-c") : viewer.setThreadingModel(osgViewer.CompositeViewer.CullThreadPerCameraDrawThreadPerContext) # run the viewer's main frame loop return viewer.run()
def main(argv): # use an ArgumentParser object to manage the program arguments. arguments = osg.ArgumentParser(argv) arguments.getApplicationUsage().addCommandLineOption("--zeroconf","uses zeroconf to advertise the osc-plugin and to discover it") arguments.getApplicationUsage().addCommandLineOption("--sender","create a view which sends its events via osc") arguments.getApplicationUsage().addCommandLineOption("--recevier","create a view which receive its events via osc") # read the scene from the list of file specified commandline args. scene = osgDB.readNodeFiles(arguments) if not scene : print argv[0], ": requires filename argument." return 1 use_zeroconf = bool(False) use_sender = bool(False) use_receiver = bool(False) if arguments.find("--zeroconf") > 0 : use_zeroconf = True if arguments.find("--sender") > 0 : use_sender = True if arguments.find("--receiver") > 0 : use_receiver = True # construct the viewer. viewer = osgViewer.CompositeViewer(arguments) # receiver view if use_receiver : traits = osg.GraphicsContext.Traits() traits.x = 600 traits.y = 100 traits.width = 400 traits.height = 400 traits.windowDecoration = True traits.doubleBuffer = True traits.sharedContext = 0 traits.windowName = "Receiver / view two" gc = osg.GraphicsContext.createGraphicsContext(traits) view = osgViewer.View() view.setName("View two") viewer.addView(view) group = osg.Group() group.addChild(scene) geode = osg.Geode() group.addChild(geode) text = osgText.Text() geode.addDrawable( text ) text.setFont("Arial.ttf") text.setText("Waiting for data") text.setPosition(osg.Vec3(-50,0,30)) text.setAxisAlignment(osgText.TextBase.SCREEN) text.setDataVariance(osg.Object.DYNAMIC) text.setCharacterSize(2.0) view.setSceneData(group) view.getCamera().setName("Cam two") view.getCamera().setViewport(osg.Viewport(0,0, traits.width, traits.height)) view.getCamera().setGraphicsContext(gc) view.addEventHandler( osgViewer.StatsHandler )() view.addEventHandler( UserEventHandler(text) ) device = osgDB.readFile<osgGA.Device>("0.0.0.0:9000.receiver.osc") if device.valid() and (device.getCapabilities() osgGA.Device.RECEIVE_EVENTS) : view.addDevice(device) # add a zeroconf device, advertising the osc-device if use_zeroconf : zeroconf_device = osgDB.readFile<osgGA.Device>("_osc._udp:9000.advertise.zeroconf") if zeroconf_device : view.addDevice(zeroconf_device) else: OSG_WARN, "could not open osc-device, receiving will not work"