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): # 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): 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) # 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): # 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 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()
def main(argv): # use an ArgumentParser object to manage the program arguments. arguments = osg.ArgumentParser(argv) # construct the viewer. viewer = osgViewer.Viewer() # 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("cessna.osgt") # if no model has been successfully loaded report failure. if not loadedModel : print arguments.getApplicationName(), ": No data loaded" return 1 # optimize the scene graph, remove redundant nodes and state etc. optimizer = osgUtil.Optimizer() optimizer.optimize(loadedModel) # add a transform with a callback to animate the loaded model. loadedModelTransform = osg.MatrixTransform() loadedModelTransform.addChild(loadedModel) nc = osg.AnimationPathCallback(loadedModelTransform.getBound().center(),osg.Vec3(0.0,0.0,1.0),osg.inDegrees(45.0)) loadedModelTransform.setUpdateCallback(nc) # finally decorate the loaded model so that it has the required multipass/bin scene graph to do the reflection effect. rootNode = createMirroredScene(loadedModelTransform) # set the scene to render viewer.setSceneData(rootNode) # hint to tell viewer to request stencil buffer when setting up windows osg.DisplaySettings.instance().setMinimumNumStencilBits(8) #osgDB.writeNodeFile(*rootNode, "test.osgt") 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 use high quality light point, typically used for naviagional lights.") arguments.getApplicationUsage().setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...") arguments.getApplicationUsage().addCommandLineOption("-h or --help","Display this information") arguments.getApplicationUsage().addCommandLineOption("--sprites","Point sprites.") # 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 usePointSprites = False while arguments.read("--sprites") : usePointSprites = True rootnode = osg.Group() # load the nodes from the commandline arguments. rootnode.addChild(osgDB.readNodeFiles(arguments)) rootnode.addChild(createLightPointsDatabase()) rootnode.addChild(CreateBlinkSequenceLightNode()) # 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 ) return viewer.run()
def main(argv): arguments = osg.ArgumentParser(argv) viewer = osgViewer.Viewer(arguments) if arguments.argc() <= 1 : cerr, "Need a scene.\n" return 1 loadedModel = osgDB.readNodeFiles(arguments) if not loadedModel : cerr, "couldn't load ", argv[1], "\n" return 1 optimizer = osgUtil.Optimizer() optimizer.optimize(loadedModel) bound = loadedModel.getBound() displacement = 2.25 * bound.radius() scene = Group() rootSS = scene.getOrCreateStateSet() vertexShader = Shader(Shader.VERTEX) vertexShader.setShaderSource(vertexShaderSource) fragmentShader = Shader(Shader.FRAGMENT) fragmentShader.setShaderSource(fragmentShaderSource) prog = Program() prog.addShader(vertexShader) prog.addShader(fragmentShader) prog.addBindUniformBlock("colors0", 0) rootSS.setAttributeAndModes(prog, StateAttribute.ON) # Place 3 instances of the loaded model with different uniform # blocks for each. # # The blocksize is known because of the std140 format. blockSize = 20 * sizeof(GLfloat) colorArray = FloatArray(colors1[0], colors1[sizeof(colors1) / sizeof(GLfloat)]) ubo = UniformBufferObject() colorArray.setBufferObject(ubo) group1 = Group() ss1 = group1.getOrCreateStateSet() group1.addChild(loadedModel) scene.addChild(group1) ubb1 = UniformBufferBinding(0, ubo, 0, blockSize) ss1.setAttributeAndModes(ubb1, StateAttribute.ON) colorArray2 = FloatArray(colors2[0], colors2[sizeof(colors2) / sizeof(GLfloat)]) ubo2 = UniformBufferObject() colorArray2.setBufferObject(ubo2) group2 = MatrixTransform() mat2 = Matrix.translate(-displacement, 0.0, 0.0) group2.setMatrix(mat2) ss2 = group2.getOrCreateStateSet() group2.addChild(loadedModel) scene.addChild(group2) ubb2 = UniformBufferBinding(0, ubo2, 0, blockSize) ss2.setAttributeAndModes(ubb2, StateAttribute.ON) colorArray3 = FloatArray(colors2[0], colors2[sizeof(colors2) / sizeof(GLfloat)]) ubo3 = UniformBufferObject() colorArray3.setBufferObject(ubo3) group3 = MatrixTransform() mat3 = Matrix.translate(displacement, 0.0, 0.0) group3.setMatrix(mat3) ss3 = group3.getOrCreateStateSet() group3.addChild(loadedModel) scene.addChild(group3) ubb3 = UniformBufferBinding(0, ubo3, 0, blockSize) ubb3.setUpdateCallback(UniformCallback)() ubb3.setDataVariance(Object.DYNAMIC) ss3.setAttributeAndModes(ubb3, StateAttribute.ON) viewer.setSceneData(scene) viewer.realize() return viewer.run()
tragger2Scene=False # any option left unread are converted into errors to write out later. arguments.reportRemainingOptionsAsUnrecognized() # report any errors if they have occurred when parsing the program arguments. if arguments.errors() : arguments.writeErrorMessages(std.cout) end_tick = osg.Timer.instance().tick() print "Time to load = ", osg.Timer.instance().delta_s(start_tick,end_tick) # optimize the scene graph, remove redundant nodes and state etc. optimizer = osgUtil.Optimizer() optimizer.optimize(loadedModel) # pass the loaded scene graph to the viewer. if tragger2Scene : viewer.setSceneData(addDraggerToScene(loadedModel, dragger_name, fixedSizeInScreen)) else: viewer.setSceneData(loadedModel) return viewer.run() if __name__ == "__main__":
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("--sprites","Point sprites.") arguments.getApplicationUsage().addCommandLineOption("--points","Sets the polygon mode to GL_POINT for front and back faces.") # construct the viewer. viewer = osgViewer.Viewer() shader = False while arguments.read("--shader") : shader = True # if user request help write it out to cout. if arguments.read("-h") or arguments.read("--help") : arguments.getApplicationUsage().write(std.cout) return 1 usePointSprites = False while arguments.read("--sprites") : usePointSprites = True forcePointMode = False while arguments.read("--points") : forcePointMode = True if arguments.argc()<=1 : arguments.getApplicationUsage().write(std.cout,osg.ApplicationUsage.COMMAND_LINE_OPTION) return 1 # read the scene from the list of file specified commandline args. loadedModel = osgDB.readNodeFiles(arguments) # if no model has been successfully loaded report failure. if not loadedModel : print arguments.getApplicationName(), ": No data loaded" return 1 # optimize the scene graph, remove redundant nodes and state etc. optimizer = osgUtil.Optimizer() optimizer.optimize(loadedModel) # set the scene to render viewer.setSceneData(loadedModel) stateset = loadedModel.getOrCreateStateSet() if usePointSprites : #/ Setup cool blending fn = osg.BlendFunc() stateset.setAttributeAndModes(fn, osg.StateAttribute.ON) #/ Setup the point sprites sprite = osg.PointSprite() stateset.setTextureAttributeAndModes(0, sprite, osg.StateAttribute.ON) #/ The texture for the sprites tex = osg.Texture2D() tex.setImage(osgDB.readImageFile("Images/particle.rgb")) stateset.setTextureAttributeAndModes(0, tex, osg.StateAttribute.ON) if forcePointMode : #/ Set polygon mode to GL_POINT pm = osg.PolygonMode( osg.PolygonMode.FRONT_AND_BACK, osg.PolygonMode.POINT ) stateset.setAttributeAndModes( pm, osg.StateAttribute.ON | osg.StateAttribute.OVERRIDE) # register the handler for modifying the point size viewer.addEventHandler(KeyboardEventHandler(viewer.getCamera().getOrCreateStateSet())) if shader : stateset = loadedModel.getOrCreateStateSet() #################################/ # vertex shader using just Vec4 coefficients char vertexShaderSource[] = "void main(void) \n" " \n" "\n" " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex\n" "\n" program = osg.Program() stateset.setAttribute(program) vertex_shader = osg.Shader(osg.Shader.VERTEX, vertexShaderSource) program.addShader(vertex_shader) #if 0 ################################# # fragment shader # char fragmentShaderSource[] = "void main(void) \n" " \n" " gl_FragColor = gl_Color \n" "\n"
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()+" demonstrates OpenGL occlusion query in OSG using the OcclusionQueryNode.") arguments.getApplicationUsage().setCommandLineUsage(arguments.getApplicationName()+" [options] [filename(s)]") arguments.getApplicationUsage().addCommandLineOption("-h or --help","Display command line parameters") # if user request help write it out to cout. if arguments.read("-h") or arguments.read("--help") : arguments.getApplicationUsage().write(std.cout, osg.ApplicationUsage.COMMAND_LINE_OPTION) return 1 # report any errors if they have occurred when parsing the program arguments. if arguments.errors() : arguments.writeErrorMessages(std.cout) return 1 viewer = osgViewer.Viewer( arguments ) # add the state manipulator viewer.addEventHandler( osgGA.StateSetManipulator(viewer.getCamera().getOrCreateStateSet()) ) # add the stats handler viewer.addEventHandler(osgViewer.StatsHandler)() # add the help handler viewer.addEventHandler(osgViewer.HelpHandler(arguments.getApplicationUsage())) optimize = arguments.read( "--opt" ) # load the specified model root = 0 if arguments.argc()>1 : root = osgDB.readNodeFiles( arguments ) if root.valid() : # Run a NodeVisitor to insert OcclusionQueryNodes in the scene graph. oqv = OcclusionQueryVisitor() root.accept( oqv ) else: print arguments.getApplicationName(), ": unable to load specified data." return 1 else: root = createStockScene() if not root : print arguments.getApplicationName(), ": Failed to create stock scene." return 1 # any option left unread are converted into errors to write out later. arguments.reportRemainingOptionsAsUnrecognized() # report any errors if they have occurred when parsing the program arguments. if arguments.errors() : arguments.writeErrorMessages(std.cout) return 1 # optimize the scene graph, remove redundant nodes and state etc. if optimize : optimizer = osgUtil.Optimizer() optimizer.optimize( root ) viewer.setSceneData( root ) kh = KeyHandler( *root ) viewer.addEventHandler( kh ) return viewer.run()
def main(argv): # use an ArgumentParser object to manage the program arguments. arguments = osg.ArgumentParser(argv) # initialize the viewer. viewer = osgViewer.Viewer() # load the nodes from the commandline arguments. rootnode = osgDB.readNodeFiles(arguments) if not rootnode : 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(rootnode) # ------------- Start of copy specific code ------------------------------------------------------- # do a deep copy, using MyCopyOp to reveal whats going on under the good, # in your own code you'd typically just use the basic osg.CopyOp something like mycopy = dynamic_cast<osg.Node*>(rootnode.clone(osg.CopyOp.DEEP_COPY_ALL)) print "Doing a deep copy of scene graph" # note, we need the dyanmic_cast because MS Visual Studio can't handle covarient # return types, so that clone has return just Object*. bahh hum bug deep_copy = dynamic_cast<osg.Node*>(rootnode.clone(MyCopyOp(osg.CopyOp.DEEP_COPY_ALL))) print "----------------------------------------------------------------" # do a graph preserving deep copy. print "Doing a graph preserving deep copy of scene graph nodes" graph_copy = dynamic_cast<osg.Node*>(rootnode.clone(GraphCopyOp(osg.CopyOp.DEEP_COPY_NODES))) # do a shallow copy. print "Doing a shallow copy of scene graph" shallow_copy = dynamic_cast<osg.Node*>(rootnode.clone(MyCopyOp(osg.CopyOp.SHALLOW_COPY))) # write out the various scene graphs so that they can be browsed, either # in an editor or using a graphics diff tool gdiff/xdiff/xxdiff. print std.endl, "Writing out the original scene graph as 'original.osgt'" osgDB.writeNodeFile(*rootnode,"original.osgt") print std.endl, "Writing out the graph preserving scene graph as 'graph_copy.osgt'" osgDB.writeNodeFile(*graph_copy,"graph_copy.osgt") print "Writing out the deep copied scene graph as 'deep_copy.osgt'" osgDB.writeNodeFile(*deep_copy,"deep_copy.osgt") print "Writing out the shallow copied scene graph as 'shallow_copy.osgt'" osgDB.writeNodeFile(*shallow_copy,"shallow_copy.osgt") # You can use a bit mask to control which parts of the scene graph are shallow copied # vs deep copied. The options are (from include/osg/CopyOp) : # enum Options # SHALLOW_COPY = 0, # DEEP_COPY_OBJECTS = 1, # DEEP_COPY_NODES = 2, # DEEP_COPY_DRAWABLES = 4, # DEEP_COPY_STATESETS = 8, # DEEP_COPY_STATEATTRIBUTES = 16, # DEEP_COPY_TEXTURES = 32, # DEEP_COPY_IMAGES = 64, # DEEP_COPY_ALL = 0xffffffff # # # These options you can use together such as : # osg.Node* mycopy = dynamic_cast<osg.Node*>(rootnode.clone(osg.CopyOp.DEEP_COPY_NODES | DEEP_COPY_DRAWABLES)) # Which shares state but creates copies of all nodes and drawables (which contain the geometry). # # You may also want to subclass from CopyOp to provide finer grained control of what gets shared (shallow copy) vs # cloned (deep copy). # ------------- End of copy specific code ------------------------------------------------------- # set the scene to render viewer.setSceneData(rootnode) # viewer.setThreadingModel(osgViewer.Viewer.SingleThreaded) 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() # 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 model filename on the command line." 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() 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( polyoffset, osg.StateAttribute.OVERRIDE | osg.StateAttribute.ON) stateset.setAttributeAndModes( polymode, osg.StateAttribute.OVERRIDE | osg.StateAttribute.ON) #if 1 material = osg.Material() stateset.setAttributeAndModes( material, osg.StateAttribute.OVERRIDE | osg.StateAttribute.ON) stateset.setMode(GL_LIGHTING, osg.StateAttribute.OVERRIDE | osg.StateAttribute.OFF) #else: # version which sets the color of the wireframe. material = osg.Material() material.setColorMode(osg.Material.OFF) # switch glColor usage off # turn all lighting off material.setAmbient(osg.Material.FRONT_AND_BACK, osg.Vec4(0.0, 0.0, 0.0, 1.0)) material.setDiffuse(osg.Material.FRONT_AND_BACK, osg.Vec4(0.0, 0.0, 0.0, 1.0)) material.setSpecular(osg.Material.FRONT_AND_BACK, osg.Vec4(0.0, 0.0, 0.0, 1.0)) # except emission... in which we set the color we desire material.setEmission(osg.Material.FRONT_AND_BACK, osg.Vec4(0.0, 1.0, 0.0, 1.0)) stateset.setAttributeAndModes( material, osg.StateAttribute.OVERRIDE | osg.StateAttribute.ON) stateset.setMode(GL_LIGHTING, osg.StateAttribute.OVERRIDE | osg.StateAttribute.ON) #endif stateset.setTextureMode( 0, GL_TEXTURE_2D, osg.StateAttribute.OVERRIDE | osg.StateAttribute.OFF) # osg.LineStipple* linestipple = osg.LineStipple() # linestipple.setFactor(1) # linestipple.setPattern(0xf0f0) # stateset.setAttributeAndModes(linestipple,osg.StateAttribute.OVERRIDE_ON) decorator.setStateSet(stateset) # 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) return viewer.run()