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()
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()
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): 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()
def main(argv): # use an ArgumentParser object to manage the program arguments. arguments = osg.ArgumentParser(argv) arguments.getApplicationUsage().setApplicationName(arguments.getApplicationName()) arguments.getApplicationUsage().setDescription(arguments.getApplicationName()+" is the standard OpenSceneGraph example which loads and visualises 3d models.") 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("--SingleThreaded","Select SingleThreaded threading model for viewer.") arguments.getApplicationUsage().addCommandLineOption("--CullDrawThreadPerContext","Select CullDrawThreadPerContext threading model for viewer.") arguments.getApplicationUsage().addCommandLineOption("--DrawThreadPerContext","Select DrawThreadPerContext threading model for viewer.") arguments.getApplicationUsage().addCommandLineOption("--CullThreadPerCameraDrawThreadPerContext","Select CullThreadPerCameraDrawThreadPerContext threading model for viewer.") # 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 )
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()
def main(argv): arguments = osg.ArgumentParser( argc, argv ) root = osg.Group()
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()
def main(argv): arguments = osg.ArgumentParser(argv) arguments.getApplicationUsage().setCommandLineUsage(arguments.getApplicationName()+" [options] <file>") arguments.getApplicationUsage().addCommandLineOption("--testOcclusion","Test occlusion by other objects") arguments.getApplicationUsage().addCommandLineOption("-h or --help","Display this information") testOcclusion = False while arguments.read("--testOcclusion") : testOcclusion = True # load outlined object modelFilename = arguments.argc() > arguments[1] if (1) else "dumptruck.osgt" outlineModel = osgDB.readNodeFile(modelFilename) if not outlineModel : osg.notify(osg.FATAL), "Unable to load model '", modelFilename, "'\n" return -1 # create scene root = osg.Group() # create outline effect outline = osgFX.Outline() root.addChild(outline) outline.setWidth(8) outline.setColor(osg.Vec4(1,1,0,1)) outline.addChild(outlineModel)
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): # 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)
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 )
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 )
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()
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
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()
def test_is_option(self): argv = ["foo", "bar", "baz", "--chang", "boom"] ap = osg.ArgumentParser(argv) ap.isOptionStr("bar") # Boost.Python.ArgumentError: Python argument types in # ArgumentParser.isOption(int) # did not match C++ signature: # isOption(class osg::ArgumentParser {lvalue}, int pos) # isOption(char const * str) ap.isOption(4) # Causes error
def main(argv): arguments = osg.ArgumentParser(argv) node = osg.Group() if arguments.read("--MyUserDataContainer") or arguments.read("--mydc") : node.setUserDataContainer(MyNamespace.MyUserDataContainer)() i = 10 node.setUserValue("Int value",i) testString = str("All seems fine") node.setUserValue("Status",testString) node.setUserValue("Height",float(1.4)) drawable = osg.Geometry() drawable.setName("myDrawable") node.getOrCreateUserDataContainer().addUserObject(drawable) node.setUserValue("fred",12) node.setUserValue("john",1.1) node.setUserValue("david",1.9) node.setUserValue("char",char(65)) node.setUserValue("matrixd",osg.Matrixd.translate(1.0,2.0,3.0)) node.setUserValue("flag-on",True) node.setUserValue("flag-off",False) OSG_NOTICE, "Testing results for values set directly on scene graph" testResults(node) osgDB.writeNodeFile(*node, "results.osgt") from_osgt = osgDB.readNodeFile("results.osgt") if from_osgt.valid() : OSG_NOTICE, "Testing results for values from scene graph read from .osgt file" testResults(from_osgt) osgDB.writeNodeFile(*node, "results.osgb") from_osgb = osgDB.readNodeFile("results.osgb") if from_osgb.valid() : OSG_NOTICE, "Testing results for values from scene graph read from .osgb file" testResults(from_osgb) osgDB.writeNodeFile(*node, "results.osgx") from_osgx = osgDB.readNodeFile("results.osgx") if from_osgx.valid() : OSG_NOTICE, "Testing results for values from scene graph read from .osgx file" testResults(from_osgx)
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
def main(argv): arguments = osg.ArgumentParser(argv) # Make a scene graph consisting of a single Geode, containing # a single Geometry, and a single PrimitiveSet. geode = osg.Geode() geom = osg.Geometry()
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 )
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()
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()
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 )
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()
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
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()
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()
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()
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()