예제 #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]))
예제 #2
0
def textInfo(text):

    
    tgqm = text.getTextureGlyphQuadMap()

    tgqmi = tgqm.begin()

    gq = tgqmi.second

    s = text.getText()

    for(unsigned int i = 0 i < s.size() i++)
        ul = gq.getCoords()[0 + (i * 4)] # upperLeft
        ll = gq.getCoords()[1 + (i * 4)] # lowerLeft
        lr = gq.getCoords()[2 + (i * 4)] # lowerRight
        ur = gq.getCoords()[3 + (i * 4)] # upperRight

        #
#        ul = gq.getTransformedCoords(0)[0 + (i * 4)]
#        ll = gq.getTransformedCoords(0)[1 + (i * 4)]
#        lr = gq.getTransformedCoords(0)[2 + (i * 4)]
#        ur = gq.getTransformedCoords(0)[3 + (i * 4)]
#        

        osg.notify(osg.NOTICE), "'", static_cast<char>(s[i]), "':", " width(", lr.x() - ll.x(), ")", " height(", ul.y() - ll.y(), ")", "\t", "ul(", ul, "), ", "ll(", ll, "), ", "lr(", lr, "), ", "ur(", ur, ")"
예제 #3
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()
예제 #4
0
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()
예제 #5
0
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)
예제 #6
0
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()
예제 #7
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()
예제 #8
0
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
예제 #9
0
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 compileCompleted(compileSet):

        
        if _block.valid() : _block.completed()
        
        # tell IncrementalCompileOperation that it's now safe to remove the compileSet
        
        osg.notify(osg.NOTICE), "compileCompleted(", compileSet, ")"
        
        return True
예제 #11
0
    def apply(plod):
    
        

        # go through all the named children and write them out to disk.
        for(unsigned int i=0i<plod.getNumChildren()++i)
            child = plod.getChild(i)
            filename = plod.getFileName(i)
            if  not filename.empty() :
                osg.notify(osg.NOTICE), "Writing out ", filename
                osgDB.writeNodeFile(*child,filename)
예제 #12
0
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()
예제 #13
0
def main(argv):

    
    loadedModel = osg.Node()
    
    # load the scene.
    if argc>1 : loadedModel = osgDB.readNodeFile(argv[1])
    
    # if not loaded assume no arguments passed in, try use default mode instead.
    if  not loadedModel : loadedModel = osgDB.readNodeFile("dumptruck.osgt")
    
    if  not loadedModel : 
        print argv[0], ": No data loaded."
        return 1
    
    # create the window to draw to.
    traits = osg.GraphicsContext.Traits()
    traits.x = 200
    traits.y = 200
    traits.width = 800
    traits.height = 600
    traits.windowDecoration = True
    traits.doubleBuffer = True
    traits.sharedContext = 0

    gc = osg.GraphicsContext.createGraphicsContext(traits)
    gw = dynamic_cast<osgViewer.GraphicsWindow*>(gc)
    if  not gw :
        osg.notify(osg.NOTICE), "Error: unable to create graphics window."
        return 1

    # create the view of the scene.
    viewer = osgViewer.Viewer()
    viewer.getCamera().setGraphicsContext(gc)
    viewer.getCamera().setViewport(0,0,800,600)
    viewer.setSceneData(loadedModel)
    
    # create a tracball manipulator to move the camera around in response to keyboard/mouse events
    viewer.setCameraManipulator( osgGA.TrackballManipulator )()

    statesetManipulator = osgGA.StateSetManipulator(viewer.getCamera().getStateSet())
    viewer.addEventHandler(statesetManipulator)

    # add the pick handler
    viewer.addEventHandler(PickHandler())

    viewer.realize()

    # main loop (note, window toolkits which take control over the main loop will require a window redraw callback containing the code below.)
    while  not viewer.done() :
        viewer.frame()

    return 0
예제 #14
0
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 open(group):
 
     
     files = Files()
     readMasterFile(files)
     for(Files.iterator itr = files.begin()
         not = files.end()
         ++itr)
         model = osgDB.readNodeFile(*itr)
         if model :
             osg.notify(osg.NOTICE), "open: Loaded file ", *itr
             group.addChild(model)
             _existingFilenameNodeMap[*itr] = model
    def init(geom):

        
        pos = dynamic_cast<osg.Vec3Array*>(geom.getVertexArray())
        if  not pos : 
            osg.notify(osg.WARN), "RigTransformHardware no vertex array in the geometry ", geom.getName()
            return False

        if  not geom.getSkeleton() : 
            osg.notify(osg.WARN), "RigTransformHardware no skeleting set in geometry ", geom.getName()
            return False

        mapVisitor = osgAnimation.BoneMapVisitor()
        geom.getSkeleton().accept(mapVisitor)
        bm = mapVisitor.getBoneMap()

        if  not createPalette(pos.size(),bm, geom.getVertexInfluenceSet().getVertexToBoneList()) :
            return False

        attribIndex = 11
        nbAttribs = getNumVertexAttrib()

        # use a global program for all avatar
        if  not program.valid() : 
            program = osg.Program()
            program.setName("HardwareSkinning")
            if  not _shader.valid() :
                _shader = osg.Shader.readShaderFile(osg.Shader.VERTEX,"shaders/skinning.vert")

            if  not _shader.valid() : 
                osg.notify(osg.WARN), "RigTransformHardware can't load VertexShader"
                return False

            # replace max matrix by the value from uniform
                str = _shader.getShaderSource()
                toreplace = str("MAX_MATRIX")
                start = str.find(toreplace)
                ss = strstream()
                ss, getMatrixPaletteUniform().getNumElements()
                str.replace(start, toreplace.size(), ss.str())
                _shader.setShaderSource(str)
                osg.notify(osg.INFO), "Shader ", str

            program.addShader(_shader)

            for (int i = 0 i < nbAttribs i++)
                ss = strstream()
                ss, "boneWeight", i
                program.addBindAttribLocation(ss.str(), attribIndex + i)

                osg.notify(osg.INFO), "set vertex attrib ", ss.str()
예제 #17
0
class Xample :
texture = str()
    app = str()
      Xample(str image, str prog)
        texture    = image
        app     = prog
        osg.notify(osg.INFO), "New Xample not "
예제 #18
0
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()
예제 #19
0
    def pick(ea, viewer):

        
        scene = viewer.getSceneData()
        if  not scene : return

        osg.notify(osg.NOTICE)

        node = 0
        parent = 0

        if _usePolytopeIntersector :
            picker = osgUtil.PolytopeIntersector*()
            if _useWindowCoordinates :
                # use window coordinates
                # remap the mouse x,y into viewport coordinates.
                viewport = viewer.getCamera().getViewport()
                mx = viewport.x() + (int)((double )viewport.width()*(ea.getXnormalized()*0.5+0.5))
                my = viewport.y() + (int)((double )viewport.height()*(ea.getYnormalized()*0.5+0.5))

                # half width, height.
                w = 5.0
                h = 5.0
                picker = osgUtil.PolytopeIntersector( osgUtil.Intersector.WINDOW, mx-w, my-h, mx+w, my+h )
             else:
                mx = ea.getXnormalized()
                my = ea.getYnormalized()
                w = 0.05
                h = 0.05
                picker = osgUtil.PolytopeIntersector( osgUtil.Intersector.PROJECTION, mx-w, my-h, mx+w, my+h )
            iv = osgUtil.IntersectionVisitor(picker)

            viewer.getCamera().accept(iv)

            if picker.containsIntersections() :
                intersection = picker.getFirstIntersection()

                osg.notify(osg.NOTICE), "Picked ", intersection.localIntersectionPoint, "  Distance to ref. plane ", intersection.distance, ", max. dist ", intersection.maxDistance, ", primitive index ", intersection.primitiveIndex, ", numIntersectionPoints ", intersection.numIntersectionPoints

                nodePath = intersection.nodePath
                node =  nodePath[nodePath.size()-1] if ((nodePath.size()>=1)) else 0
                parent =  dynamic_cast<osg.Group*>(nodePath[nodePath.size()-2]) if ((nodePath.size()>=2)) else 0

                if node : print "  Hits ", node.className(), " nodePath size ", nodePath.size()    
                toggleScribe(parent, node)
예제 #20
0
def main(argv):
    
    # construct the viewer.
    arguments = osg.ArgumentParser( argc, argv )
    viewer = osgViewer.Viewer( arguments )

    useSimpleExample = arguments.read("-s")  or  arguments.read("--simple") 

    model = NULL

    if arguments.argc()>1  and   not arguments.isOption(1)  : 
        filename = arguments[1]
        model = osgDB.readNodeFile( filename )
        if   not model  : 
            osg.notify( osg.NOTICE ), "Error, cannot read ", filename, ". Loading default earth model instead."

    if  model == NULL  :
        model = CreateGlobe( )

    node =  CreateSimpleHierarchy( model ) if (useSimpleExample) else 
        CreateAdvancedHierarchy( model )
예제 #21
0
def printBoundings(current, name):

    
    currentBound = current.getBound()
    osg.notify(osg.INFO), name
    osg.notify(osg.INFO), "center = ", currentBound.center()
    osg.notify(osg.INFO), "radius = ", currentBound.radius()
    def update(scene):
        
        # osg.notify(osg.NOTICE), "void update(Node*)"

        group = dynamic_cast<osg.Group*>(scene)
        if  not group :
            osg.notify(osg.NOTICE), "Error, MasterOperation.update(Node*) can only work with a Group as Viewer.getSceneData()."
            return
    
        lock = OpenThreads.ScopedLock<OpenThreads.Mutex>(_mutex)
        
        if  not _nodesToRemove.empty()  or   not _nodesToAdd.empty() :
            osg.notify(osg.NOTICE), "update().................. "

        if  not _nodesToRemove.empty() :
            for(Files.iterator itr = _nodesToRemove.begin()
                not = _nodesToRemove.end()
                ++itr)
                fnmItr = _existingFilenameNodeMap.find(*itr)
                if fnmItr  not = _existingFilenameNodeMap.end() :
                    osg.notify(osg.NOTICE), "  update():removing ", *itr
                
                    group.removeChild(fnmItr.second)
                    _existingFilenameNodeMap.erase(fnmItr)

            _nodesToRemove.clear()
예제 #23
0
    def convert():

        
        lodNum = 0
        for(LODSet.iterator itr = _lodSet.begin()
            not = _lodSet.end()
            ++itr, ++lodNum)
            lod = const_cast<osg.LOD*>(itr)
            
            if lod.getNumParents()==0 :
                osg.notify(osg.NOTICE), "Warning can't operator on root node."
                break

            if  not _makeAllChildrenPaged  and  lod.getNumRanges()<2 :
                osg.notify(osg.NOTICE), "Leaving LOD with one child as is."
                break

            osg.notify(osg.NOTICE), "Converting LOD to PagedLOD."
            
            plod = osg.PagedLOD()
            
            originalRangeList = lod.getRangeList()
            typedef std.multimap< osg.LOD.MinMaxPair , unsigned int > MinMaxPairMap
            rangeMap = MinMaxPairMap()
            pos = 0
            for(osg.LOD.RangeList.const_iterator ritr = originalRangeList.begin()
                not = originalRangeList.end()
                ++ritr, ++pos)
                rangeMap.insert(std.multimap< osg.LOD.MinMaxPair , unsigned int >.value_type(*ritr, pos))
예제 #24
0
def printList():


    
    osg.notify(osg.INFO), "start printList()"
    for (OP i = Xamplelist.begin()  i  not = Xamplelist.end()  ++i)
        x = *i
        osg.notify(osg.INFO), "current x.texture = ", x.getTexture()
        osg.notify(osg.INFO), "current x.app = ", x.getApp()
예제 #25
0
def runApp(xapp):


    
    osg.notify(osg.INFO), "start runApp()"
    for (OP i = Xamplelist.begin()  i  not = Xamplelist.end()  ++i)
        x = *i
        if  not xapp.compare(x.getApp()) :
            osg.notify(osg.INFO), "app found not "
            
            cxapp = xapp.c_str()
            
            osg.notify(osg.INFO), "char* = ", cxapp
            
            system = return(cxapp)
예제 #26
0
    def handle(ea, aa):

        
        switch(ea.getEventType())
            case(osgGA.GUIEventAdapter.KEYDOWN):
                if ea.getKey()==ord("r") :
                    _terrain.setSampleRatio(_terrain.getSampleRatio()*0.5)
                    osg.notify(osg.NOTICE), "Sample ratio ", _terrain.getSampleRatio()
                    return True
                elif ea.getKey()==ord("R") :
                    _terrain.setSampleRatio(_terrain.getSampleRatio()/0.5)
                    osg.notify(osg.NOTICE), "Sample ratio ", _terrain.getSampleRatio()
                    return True
                elif ea.getKey()==ord("v") :
                    _terrain.setVerticalScale(_terrain.getVerticalScale()*1.25)
                    osg.notify(osg.NOTICE), "Vertical scale ", _terrain.getVerticalScale()
                    return True
                elif ea.getKey()==ord("V") :
                    _terrain.setVerticalScale(_terrain.getVerticalScale()/1.25)
                    osg.notify(osg.NOTICE), "Vertical scale ", _terrain.getVerticalScale()
                    return True

                return False
예제 #27
0
    def handle(ea, aa):
    
        
        switch(ea.getEventType())
            case(osgGA.GUIEventAdapter.KEYDOWN):
                if ea.getKey()==ord("r") :
                    _terrain.setSampleRatio(_terrain.getSampleRatio()*0.5)
                    osg.notify(osg.NOTICE), "Sample ratio ", _terrain.getSampleRatio()
                    return True
                elif ea.getKey()==ord("R") :
                    _terrain.setSampleRatio(_terrain.getSampleRatio()/0.5)
                    osg.notify(osg.NOTICE), "Sample ratio ", _terrain.getSampleRatio()
                    return True
                elif ea.getKey()==ord("v") :
                    _terrain.setVerticalScale(_terrain.getVerticalScale()*1.25)
                    osg.notify(osg.NOTICE), "Vertical scale ", _terrain.getVerticalScale()
                    return True
                elif ea.getKey()==ord("V") :
                    _terrain.setVerticalScale(_terrain.getVerticalScale()/1.25)
                    osg.notify(osg.NOTICE), "Vertical scale ", _terrain.getVerticalScale()
                    return True

                return False
    def update(scene):
        
        # osg.notify(osg.NOTICE), "void update(Node*)"

        group = dynamic_cast<osg.Group*>(scene)
        if  not group :
            osg.notify(osg.NOTICE), "Error, MasterOperation.update(Node*) can only work with a Group as Viewer.getSceneData()."
            return
    
        lock = OpenThreads.ScopedLock<OpenThreads.Mutex>(_mutex)
        
        if  not _nodesToRemove.empty()  or   not _nodesToAdd.empty() :
            osg.notify(osg.NOTICE), "update().................. "

        if  not _nodesToRemove.empty() :
            for(Files.iterator itr = _nodesToRemove.begin()
                not = _nodesToRemove.end()
                ++itr)
                fnmItr = _existingFilenameNodeMap.find(*itr)
                if fnmItr  not = _existingFilenameNodeMap.end() :
                    osg.notify(osg.NOTICE), "  update():removing ", *itr
                
                    group.removeChild(fnmItr.second)
                    _existingFilenameNodeMap.erase(fnmItr)
예제 #29
0
        ~KeyboardModel() 

        addKey = osg.Switch*(osg.Vec3 pos, int key, str text,float width, float height)

        createKeyboard = void()

        typedef std.map<int, osg.Switch > KeyModelMap
        
        _scene = osg.Group()
        _keyModelMap = KeyModelMap()
        _inputText = osgText.Text()



void KeyboardModel.keyChange(int key, int virtualKey, int value)
    osg.notify(osg.INFO), "key value change, code=", std.hex, key, "\t value=", value, std.dec

    # toggle the keys graphical representation on or off via osg.Swithc
    itr = _keyModelMap.find(virtualKey)
    if itr not =_keyModelMap.end() :
        itr.second.setSingleChildOn(value)
    
    if value :
        # when a key is pressed add the data to the text field
        
        if key>0  and  key<256 :
            # just add ascii characters right now...
            _inputText.getText().push_back(key)
            _inputText.update()
        elif key==osgGA.GUIEventAdapter.KEY_Return :
            _inputText.getText().push_back('\n')
예제 #30
0
    xform = osg.PositionAttitudeTransform()
    xform.setPosition(osg.Vec3( 0.0, -1.0, zvalue ))
    zvalue = zvalue + 2.2
    xform.addChild(masterModel)
    rootNode.addChild(xform)
    return xform.getOrCreateStateSet()

# load source from a file.
static void
LoadShaderSource( osg.Shader* shader,  str fileName )
    fqFileName = osgDB.findDataFile(fileName)
    if  fqFileName.length()  not = 0  :
        shader.loadShaderSourceFromFile( fqFileName.c_str() )
    else:
        osg.notify(osg.WARN), "File \"", fileName, "\" not found."


#####################################/
# rude but convenient globals

static osg.Program* BlockyProgram
static osg.Shader*  BlockyVertObj
static osg.Shader*  BlockyFragObj

static osg.Program* ErodedProgram
static osg.Shader*  ErodedVertObj
static osg.Shader*  ErodedFragObj

static osg.Program* MarbleProgram
static osg.Shader*  MarbleVertObj
예제 #31
0
    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)

    if testOcclusion :
        # load occluder
        occludedModelFilename = "cow.osgt"
        occludedModel = osgDB.readNodeFile(occludedModelFilename)
        if  not occludedModel :
            osg.notify(osg.FATAL), "Unable to load model '", occludedModelFilename, "'\n"
            return -1

        # occluder offset
        bsphere = outlineModel.getBound()
        occluderOffset = osg.Vec3(0,1,0) * bsphere.radius() * 1.2

        # occluder behind outlined model
        modelTransform0 = osg.PositionAttitudeTransform()
        modelTransform0.setPosition(bsphere.center() + occluderOffset)
        modelTransform0.addChild(occludedModel)
        root.addChild(modelTransform0)

        # occluder in front of outlined model
        modelTransform1 = osg.PositionAttitudeTransform()
        modelTransform1.setPosition(bsphere.center() - occluderOffset)
예제 #32
0
    
    arguments = osg.ArgumentParser( argc, argv )

     root = osg.Group()

    # Child 0: We'll replace this every frame with an updated representation
    #   of the view frustum.
    root.addChild( makeFrustumFromCamera( NULL ) )

     scene = osg.Node()
    scene = osgDB.readNodeFiles( arguments )
    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 )
예제 #33
0
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()
예제 #34
0
        camera.addChild(geode)

    return camera

class SnapImage (osg.Camera.DrawCallback) :
SnapImage( str filename):
        _filename(filename),
        _snapImage(False)
        _image = osg.Image()

    virtual void operator () (osg.RenderInfo renderInfo) 

        if  not _snapImage : return

        osg.notify(osg.NOTICE), "Camera callback"

        camera = renderInfo.getCurrentCamera()
        viewport =  camera.getViewport() if (camera) else  0

        osg.notify(osg.NOTICE), "Camera callback ", camera, " ", viewport

        if viewport  and  _image.valid() :
            _image.readPixels(int(viewport.x()),int(viewport.y()),int(viewport.width()),int(viewport.height()),
                               GL_RGBA,
                               GL_UNSIGNED_BYTE)
            osgDB.writeImageFile(*_image, _filename)

            osg.notify(osg.NOTICE), "Taken screenshot, and written to '", _filename, "'"

        _snapImage = False
예제 #35
0
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 :
        print arguments.getApplicationName(), ": No data loaded"
        return 1


    if arguments.read("--dome")  or  arguments.read("--puffer")  :

        setDomeCorrection(viewer, arguments)

        viewer.setSceneData( loadedModel )
    elif arguments.read("--faces") :

        setDomeFaces(viewer, arguments)

        viewer.setSceneData( loadedModel )
    else:
        distortionNode = createDistortionSubgraph( loadedModel, viewer.getCamera().getClearColor())
        viewer.setSceneData( distortionNode )

    while arguments.read("--sky-light") :
        viewer.setLightingMode(osg.View.SKY_LIGHT)

    if viewer.getLightingMode()==osg.View.HEADLIGHT :
        viewer.getLight().setPosition(osg.Vec4(0.0,0.0,0.0,1.0))


    # load the nodes from the commandline arguments.
    if  not viewer.getSceneData() :
        osg.notify(osg.NOTICE), "Please specify a model filename on the command line."
        return 1


    # 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 )

    viewer.setThreadingModel(osgViewer.Viewer.SingleThreaded)

    # add the state manipulator
    viewer.addEventHandler( osgGA.StateSetManipulator(viewer.getCamera().getOrCreateStateSet()) )

    # add the stats handler
    viewer.addEventHandler(osgViewer.StatsHandler)()

    return viewer.run()
예제 #36
0
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()
            lock = OpenThreads.ScopedLock<OpenThreads.Mutex>(_mutex)

            for(Files.iterator fitr = files.begin()
                not = files.end()
                ++fitr)
                if _existingFilenameNodeMap.count(*fitr)==0 : newFiles.insert(*fitr)

            for(FilenameNodeMap.iterator litr = _existingFilenameNodeMap.begin()
                not = _existingFilenameNodeMap.end()
                ++litr)
                if files.count(litr.first)==0 :
                    removedFiles.insert(litr.first)
        
#if 0
        if  not newFiles.empty()  or   not removedFiles.empty() :
            osg.notify(osg.NOTICE), "void operator () files.size()=", files.size()
#endif

        # first load the files.
        nodesToAdd = FilenameNodeMap()
        if  not newFiles.empty() :

            typedef std.vector< osg.GraphicsThread > GraphicsThreads
            threads = GraphicsThreads()
        
            for(unsigned int i=0 i<= osg.GraphicsContext.getMaxContextID() ++i)
                gc = osg.GraphicsContext.getCompileContext(i)
                gt =  gc.getGraphicsThread() if (gc) else  0
                if gt : threads.push_back(gt)

            if _operationQueue.valid() :
    def handle(ea, aa):

        
        if  not _gt : return False

        switch(ea.getEventType())
        case(osgGA.GUIEventAdapter.KEYDOWN):
                if ea.getKey() == ord("g") :
                    osg.notify(osg.NOTICE), "Gaussian"
                    _gt.setFilterMatrixAs(osgTerrain.GeometryTechnique.GAUSSIAN)
                    return True
                elif ea.getKey() == ord("s") :
                    osg.notify(osg.NOTICE), "Smooth"
                    _gt.setFilterMatrixAs(osgTerrain.GeometryTechnique.SMOOTH)
                    return True
                elif ea.getKey() == ord("S") :
                    osg.notify(osg.NOTICE), "Sharpen"
                    _gt.setFilterMatrixAs(osgTerrain.GeometryTechnique.SHARPEN)
                    return True
                elif ea.getKey() == ord("+") :
                    _gt.setFilterWidth(_gt.getFilterWidth()*1.1)
                    osg.notify(osg.NOTICE), "Filter width = ", _gt.getFilterWidth()
                    return True
                elif ea.getKey() == ord("-") :
                    _gt.setFilterWidth(_gt.getFilterWidth()/1.1)
                    osg.notify(osg.NOTICE), "Filter width = ", _gt.getFilterWidth()
                    return True
                elif ea.getKey() == ord(">") :
                    _gt.setFilterBias(_gt.getFilterBias()+0.1)
                    osg.notify(osg.NOTICE), "Filter bias = ", _gt.getFilterBias()
                    return True
                elif ea.getKey() == ord("<") :
                    _gt.setFilterBias(_gt.getFilterBias()-0.1)
                    osg.notify(osg.NOTICE), "Filter bias = ", _gt.getFilterBias()
                    return True
                break