#!/usr/bin/env python import sys from PyOSG import osg from PyOSG import osgDB from PyOSG import osgUtil from PyOSG import osgGLUT from PyOSG import osgGA import OpenGL import OpenGL.GLUT def write_usage(name): print "usage:" print " ",name," [options] infile1 [infile2 ...]" print print "options:" print " -l libraryName - load plugin of name libraryName" print " i.e. -l osgdb_pfb" print " Useful for loading reader/writers which can load" print " other file formats in addition to its extension." print " -e extensionName - load reader/wrter plugin for file extension" print " i.e. -e pfb" print " Useful short hand for specifying full library name as" print " done with -l above, as it automatically expands to" print " the full library name appropriate for each platform." print print " -stereo - switch on stereo rendering, using the default of," print " ANAGLYPHIC or the value set in the OSG_STEREO_MODE " print " environmental variable. See doc/stereo.html for " print " further details on setting up accurate stereo " print " for your system. " print " -stereo ANAGLYPHIC - switch on anaglyphic(red/cyan) stereo rendering." print " -stereo QUAD_BUFFER - switch on quad buffered stereo rendering." print print " -stencil - use a visual with stencil buffer enabled, this " print " also allows the depth complexity statistics mode" print " to be used (press 'p' three times to cycle to it)." print def main(): #initialize the GLUT OpenGL.GLUT.glutInit(sys.argv) if len(sys.argv)<2: write_usage(sys.argv[0]) return 0 # create the commandline args. commandLine = [] for x in range(1, len(sys.argv)): commandLine.append(sys.argv[x]) # initialize the viewer. viewer = osgGLUT.Viewer() viewer.setWindowTitle(sys.argv[0]) # configure the viewer from the commandline arguments, and eat any # parameters that have been matched. viewer.readCommandLine(commandLine) # configure the plugin registry from the commandline arguments, and # eat any parameters that have been matched. osgDB.readCommandLine(commandLine) # load the nodes from the commandline arguments. loadedModel = osgDB.readNodeFiles(commandLine) if loadedModel == None: write_usage(sys.argv[0]) return 1 # to do scribe mode we create a top most group to contain the # original model, and then a second group contains the same model # but overrides various state attributes, so that the second instance # is rendered as wireframe. rootnode = osg.Group() decorator = osg.Group() rootnode.addChild(loadedModel) rootnode.addChild(decorator) decorator.addChild(loadedModel) # set up the state so that the underlying color is not seen through # and that the drawing mode is changed to wireframe, and a polygon offset # is added to ensure that we see the wireframe itself, and turn off # so texturing too. stateset = osg.StateSet() material = osg.Material() polyoffset = osg.PolygonOffset() polyoffset.setFactor(-1.0) polyoffset.setUnits(-1.0) polymode = osg.PolygonMode() polymode.setMode(osg.PolygonMode.FRONT_AND_BACK,osg.PolygonMode.LINE) stateset.setAttributeAndModes(material,osg.StateAttribute.OVERRIDE|osg.StateAttribute.ON) stateset.setAttributeAndModes(polyoffset,osg.StateAttribute.OVERRIDE|osg.StateAttribute.ON) stateset.setAttributeAndModes(polymode,osg.StateAttribute.OVERRIDE|osg.StateAttribute.ON) stateset.setMode(OpenGL.GL.GL_LIGHTING,osg.StateAttribute.OVERRIDE|osg.StateAttribute.OFF) stateset.setTextureMode(0,OpenGL.GL.GL_TEXTURE_2D,osg.StateAttribute.OVERRIDE|osg.StateAttribute.OFF) #linestipple = osg.LineStipple() #linestipple.setFactor(1) #linestipple.setPattern(0xf0f0) #stateset.setAttributeAndModes(linestipple,osg.StateAttribute.OVERRIDE|osg.StateAttribute.ON) decorator.setStateSet(stateset) # run optimization over the scene graph optimizer = osgUtil.Optimizer() optimizer.optimize(rootnode) # add a viewport to the viewer and attach the scene graph. viewer.addViewport( rootnode ) # register trackball, flight and drive. viewer.registerCameraManipulator(osgGA.TrackballManipulator()) viewer.registerCameraManipulator(osgGA.FlightManipulator()) viewer.registerCameraManipulator(osgGA.DriveManipulator()) # open the viewer window. viewer.open() # fire up the event loop. viewer.run() return 0 if __name__ == "__main__": main()