예제 #1
0
class Character (osg.Referenced) :
    Character()
    
    setCharacter = void( str filename,  str name,  osg.Vec3 orgin,  osg.Vec3 width,  osg.Vec3 catchPos, float positionRatio)
    
    setLives = void( str filename,  osg.Vec3 orgin,  osg.Vec3 delta, unsigned int numLives)
    
    setCatches = void( str filename,  osg.Vec3 orgin,  osg.Vec3 delta, unsigned int numLives)

    moveLeft = void()
    moveRight = void()
    moveTo = void(float positionRatio)

    reset = void()

    resetCatches = void()

    addCatch = bool()
    
    looseLife = bool()

    def getCurrentCenterOfBasket():

         return _character.getPosition()+_centerBasket 
    def getCurrentRadiusOfBasket():
         return _radiusBasket 

    def getLowerLeft():

         return _character.getPosition() 
    def getUpperRight():
         return _character.getPosition() 

    _origin = osg.Vec3()
    _width = osg.Vec3()

    _positionRatio = float()
    _character = osg.PositionAttitudeTransform()

    _numLives = unsigned int()
    _livesSwitch = osg.Switch()

    _numCatches = unsigned int()
    _catchSwitch = osg.Switch()
    
    _objectsGroup = osg.Group()
    
    _centerBasket = osg.Vec3()
    _radiusBasket = float()
예제 #2
0
def createScene(fileList, texmatLeft, texmatRight, radius, height, length):
    
    sw = osg.Switch()

    # load the images.
    for(unsigned int i=0i+1<fileList.size()i+=2)
        imageGroup = loadImages(fileList[i],fileList[i+1],texmatLeft,texmatRight, radius,  height, length)
        if imageGroup : sw.addChild(imageGroup)
예제 #3
0
class SlideEventHandler (osgGA.GUIEventHandler) :

    SlideEventHandler()

    META_Object(osgStereImageApp,SlideEventHandler)


    set = void(osg.Switch* sw, float offsetX, float offsetY, osg.TexMat* texmatLeft, osg.TexMat* texmatRight, float timePerSlide, bool autoSteppingActive)

    set = void(FileList fileList, osg.Switch* sw, float offsetX, float offsetY, osg.TexMat* texmatLeft, osg.TexMat* texmatRight, float radius, float height, float length, float timePerSlide, bool autoSteppingActive)


    handle = virtual bool( osgGA.GUIEventAdapter ea,osgGA.GUIActionAdapter)

    virtual void getUsage(osg.ApplicationUsage usage) 

    virtual void operator()(osg.Node* node, osg.NodeVisitor* nv)

    nextSlide = void()

    previousSlide = void()

    scaleImage = void(float s)

    offsetImage = void(float ds,float dt)

    rotateImage = void(float rx,float ry)

    initTexMatrices = void()

    ~SlideEventHandler() 
    SlideEventHandler( SlideEventHandler, osg.CopyOp) 

    _switch = osg.Switch()
    _texmatLeft = osg.TexMat()
    _texmatRight = osg.TexMat()
    _radius = float()
    _height = float()
    _length = float()
    _firstTraversal = bool()
    _activeSlide = unsigned int()
    _previousTime = double()
    _timePerSlide = double()
    _autoSteppingActive = bool()
    _initSeperationX = float()
    _currentSeperationX = float()
    _initSeperationY = float()
    _currentSeperationY = float()
    _fileList = FileList()
예제 #4
0
        geodeUp.addDrawable(textUp)
    
    geodeDown = osg.Geode()
        textDown = osgText.Text()
        textDown.setFont("fonts/arial.ttf")
        textDown.setColor(osg.Vec4(1.0,0.0,1.0,1.0))
        textDown.setCharacterSize(height)
        textDown.setPosition(pos)
        textDown.setDrawMode(osgText.Text.TEXT# or osgText.Text.BOUNDINGBOX)
        textDown.setAlignment(osgText.Text.LEFT_CENTER)
        textDown.setAxisAlignment(osgText.Text.XZ_PLANE)
        textDown.setText(text)
        
        geodeDown.addDrawable(textDown)

    model = osg.Switch()
    model.addChild(geodeUp,True)
    model.addChild(geodeDown,False)
    
    _scene.addChild(model)

    _keyModelMap[key] = model
    
    pos.x() += width
    
    return model
    

void KeyboardModel.createKeyboard()
    _scene = osg.Group()
    
예제 #5
0
    createHUDWithText = osg.Node*( str text)

    createScene = osg.Node*(unsigned int numTreesToCreates, unsigned int maxNumTreesPerCell)

    def advanceToNextTechnique(delta):

        
        if _techniqueSwitch.valid() :
            _currentTechnique += delta
            if _currentTechnique<0 :
                _currentTechnique = _techniqueSwitch.getNumChildren()-1
            if _currentTechnique>=(int)_techniqueSwitch.getNumChildren() :
                _currentTechnique = 0
            _techniqueSwitch.setSingleChildOn(_currentTechnique)

    _techniqueSwitch = osg.Switch()
    _currentTechnique = int()




# event handler to capture keyboard events and use them to advance the technique used for rendering
class TechniqueEventHandler (osgGA.GUIEventHandler) :

    TechniqueEventHandler(ForestTechniqueManager* ttm=0)  _ForestTechniqueManager = ttm 

    META_Object(osgforestApp,TechniqueEventHandler)

    handle = virtual bool( osgGA.GUIEventAdapter ea,osgGA.GUIActionAdapter, osg.Object*, osg.NodeVisitor*)

    virtual void getUsage(osg.ApplicationUsage usage) 
예제 #6
0
def main(argv):
    
    arguments = osg.ArgumentParser( argc, argv )
    usage = arguments.getApplicationUsage()
    usage.setDescription( arguments.getApplicationName() +
                           " is the example which demonstrates how to render high-resolution images (posters).")
    usage.setCommandLineUsage( arguments.getApplicationName() + " [options] scene_file" )
    usage.addCommandLineOption( "-h or --help", "Display this information." )
    usage.addCommandLineOption( "--color <r> <g> <b>", "The background color." )
    usage.addCommandLineOption( "--ext <ext>", "The output tiles' extension (Default: bmp)." )
    usage.addCommandLineOption( "--poster <filename>", "The output poster's name (Default: poster.bmp)." )
    usage.addCommandLineOption( "--tilesize <w> <h>", "Size of each image tile (Default: 640 480)." )
    usage.addCommandLineOption( "--finalsize <w> <h>", "Size of the poster (Default: 6400 4800)." )
    usage.addCommandLineOption( "--enable-output-poster", "Output the final poster file (Default)." )
    usage.addCommandLineOption( "--disable-output-poster", "Don't output the final poster file." )
    #usage.addCommandLineOption( "--enable-output-tiles", "Output all tile files." )
    #usage.addCommandLineOption( "--disable-output-tiles", "Don't output all tile files (Default)." )
    usage.addCommandLineOption( "--use-fb", "Use Frame Buffer for rendering tiles (Default, recommended).")
    usage.addCommandLineOption( "--use-fbo", "Use Frame Buffer Object for rendering tiles.")
    usage.addCommandLineOption( "--use-pbuffer","Use Pixel Buffer for rendering tiles.")
    usage.addCommandLineOption( "--use-pbuffer-rtt","Use Pixel Buffer RTT for rendering tiles.")
    usage.addCommandLineOption( "--inactive", "Inactive capturing mode." )
    usage.addCommandLineOption( "--camera-eye <x> <y> <z>", "Set eye position in inactive mode." )
    usage.addCommandLineOption( "--camera-latlongheight <lat> <lon> <h>", "Set eye position on earth in inactive mode." )
    usage.addCommandLineOption( "--camera-hpr <h> <p> <r>", "Set eye rotation in inactive mode." )
    
    if  arguments.read("-h")  or  arguments.read("--help")  :
        usage.write( std.cout )
        return 1
    
    # Poster arguments
    activeMode = True
    outputPoster = True
    #bool outputTiles = False
    tileWidth = 640, tileHeight = 480
    posterWidth = 640*2, posterHeight = 480*2
    posterName = "poster.bmp", extName = "bmp"
    bgColor = osg.Vec4(0.2, 0.2, 0.6, 1.0)
    renderImplementation = osg.Camera.FRAME_BUFFER_OBJECT
    
    while  arguments.read("--inactive")  :  activeMode = False 
    while  arguments.read("--color", bgColor.r(), bgColor.g(), bgColor.b())  : 
    while  arguments.read("--tilesize", tileWidth, tileHeight)  : 
    while  arguments.read("--finalsize", posterWidth, posterHeight)  : 
    while  arguments.read("--poster", posterName)  : 
    while  arguments.read("--ext", extName)  : 
    while  arguments.read("--enable-output-poster")  :  outputPoster = True 
    while  arguments.read("--disable-output-poster")  :  outputPoster = False 
    #while  arguments.read("--enable-output-tiles")  :  outputTiles = True 
    #while  arguments.read("--disable-output-tiles")  :  outputTiles = False 
    while  arguments.read("--use-fbo") :  renderImplementation = osg.Camera.FRAME_BUFFER_OBJECT 
    while  arguments.read("--use-pbuffer") :  renderImplementation = osg.Camera.PIXEL_BUFFER 
    while  arguments.read("--use-pbuffer-rtt") :  renderImplementation = osg.Camera.PIXEL_BUFFER_RTT 
    while  arguments.read("--use-fb") :  renderImplementation = osg.Camera.FRAME_BUFFER 
    
    # Camera settings for inactive screenshot
    useLatLongHeight = True
    eye = osg.Vec3d()
    latLongHeight = osg.Vec3d( 50.0, 10.0, 2000.0 )
    hpr = osg.Vec3d( 0.0, 0.0, 0.0 )
    if  arguments.read("--camera-eye", eye.x(), eye.y(), eye.z())  :
        useLatLongHeight = False
        activeMode = False
    elif  arguments.read("--camera-latlongheight", latLongHeight.x(), latLongHeight.y(), latLongHeight.z())  :
        activeMode = False
        latLongHeight.x() = osg.DegreesToRadians( latLongHeight.x() )
        latLongHeight.y() = osg.DegreesToRadians( latLongHeight.y() )
    if  arguments.read("--camera-hpr", hpr.x(), hpr.y(), hpr.z())  :
        activeMode = False
        hpr.x() = osg.DegreesToRadians( hpr.x() )
        hpr.y() = osg.DegreesToRadians( hpr.y() )
        hpr.z() = osg.DegreesToRadians( hpr.z() )
    
    # Construct scene graph
    scene = osgDB.readNodeFiles( arguments )
    if   not scene  : scene = osgDB.readNodeFile( "cow.osgt" )
    if   not scene  :
        print arguments.getApplicationName(), ": No data loaded"
        return 1
    
    # Create camera for rendering tiles offscreen. FrameBuffer is recommended because it requires less memory.
    camera = osg.Camera()
    camera.setClearColor( bgColor )
    camera.setClearMask( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT )
    camera.setReferenceFrame( osg.Transform.ABSOLUTE_RF )
    camera.setRenderOrder( osg.Camera.PRE_RENDER )
    camera.setRenderTargetImplementation( renderImplementation )
    camera.setViewport( 0, 0, tileWidth, tileHeight )
    camera.addChild( scene )
    
    # Set the printer
    printer = PosterPrinter()
    printer.setTileSize( tileWidth, tileHeight )
    printer.setPosterSize( posterWidth, posterHeight )
    printer.setCamera( camera )
    
    posterImage = 0
    if  outputPoster  :
        posterImage = osg.Image()
        posterImage.allocateImage( posterWidth, posterHeight, 1, GL_RGBA, GL_UNSIGNED_BYTE )
        printer.setFinalPoster( posterImage )
        printer.setOutputPosterName( posterName )
    
#if 0
    # While recording sub-images of the poster, the scene will always be traversed twice, from its two
    # parent node: root and camera. Sometimes this may not be so comfortable.
    # To prevent this behaviour, we can use a switch node to enable one parent and disable the other.
    # However, the solution also needs to be used with care, as the window will go blank while taking
    # snapshots and recover later.
    root = osg.Switch()
    root.addChild( scene, True )
    root.addChild( camera, False )
#else:
    root = osg.Group()
    root.addChild( scene )
    root.addChild( camera )
#endif
    
    viewer = osgViewer.Viewer()
    viewer.setSceneData( root )
    viewer.getDatabasePager().setDoPreCompile( False )
    
    if  renderImplementation==osg.Camera.FRAME_BUFFER  :
        # FRAME_BUFFER requires the window resolution equal or greater than the to-be-copied size
        viewer.setUpViewInWindow( 100, 100, tileWidth, tileHeight )
    else:
        # We want to see the console output, so just render in a window
        viewer.setUpViewInWindow( 100, 100, 800, 600 )
    
    if  activeMode  :
        viewer.addEventHandler( PrintPosterHandler(printer) )
        viewer.addEventHandler( osgViewer.StatsHandler )()
        viewer.addEventHandler( osgGA.StateSetManipulator(viewer.getCamera().getOrCreateStateSet()) )
        viewer.setCameraManipulator( osgGA.TrackballManipulator )()
        viewer.run()
    else:
        camera = viewer.getCamera()
        if   not useLatLongHeight  : computeViewMatrix( camera, eye, hpr )
        computeViewMatrixOnEarth = else( camera, scene, latLongHeight, hpr )
        
        renderer = CustomRenderer( camera )
        camera.setRenderer( renderer )
        viewer.setThreadingModel( osgViewer.Viewer.SingleThreaded )
        
        # Realize and initiate the first PagedLOD request
        viewer.realize()
        viewer.frame()
        
        printer.init( camera )
        while   not printer.done()  :
            viewer.advance()
            
            # Keep updating and culling until full level of detail is reached
            renderer.setCullOnly( True )
            while  viewer.getDatabasePager().getRequestsInProgress()  :
                viewer.updateTraversal()
                viewer.renderingTraversals()
            
            renderer.setCullOnly( False )
            printer.frame( viewer.getFrameStamp(), viewer.getSceneData() )
            viewer.renderingTraversals()
    return 0

# Translated from file 'PosterPrinter.cpp'

#include <osg/ClusterCullingCallback>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
#include <string.h>
#include <iostream>
#include <sstream>
#include "PosterPrinter.h"

# PagedLoadingCallback: Callback for loading paged nodes while doing intersecting test 
class PagedLoadingCallback (osgUtil.IntersectionVisitor.ReadCallback) :
def readNodeFile(filename):
    
        return osgDB.readNodeFile( filename )

static PagedLoadingCallback g_pagedLoadingCallback = PagedLoadingCallback()

# LodCullingCallback: Callback for culling LODs and selecting the highest level 
class LodCullingCallback (osg.NodeCallback) :
    virtual void operator()( osg.Node* node, osg.NodeVisitor* nv )
        lod = static_cast<osg.LOD*>(node)
        if  lod  and  lod.getNumChildren()>0  :
            lod.getChild(lod.getNumChildren()-1).accept(*nv)

static LodCullingCallback g_lodCullingCallback = LodCullingCallback()

# PagedCullingCallback: Callback for culling paged nodes and selecting the highest level 
class PagedCullingCallback (osg.NodeCallback) :
    virtual void operator()( osg.Node* node, osg.NodeVisitor* nv )
        pagedLOD = static_cast<osg.PagedLOD*>(node)
        if  pagedLOD  and  pagedLOD.getNumChildren()>0  :
            numChildren = pagedLOD.getNumChildren()
            updateTimeStamp = nv.getVisitorType()==osg.NodeVisitor.CULL_VISITOR
            if  nv.getFrameStamp()  and  updateTimeStamp  :
                timeStamp =  nv.getFrameStamp().getReferenceTime() if (nv.getFrameStamp()) else 0.0
                frameNumber =  nv.getFrameStamp().getFrameNumber() if (nv.getFrameStamp()) else 0
                
                pagedLOD.setFrameNumberOfLastTraversal( frameNumber )
                pagedLOD.setTimeStamp( numChildren-1, timeStamp )
                pagedLOD.setFrameNumber( numChildren-1, frameNumber )
                pagedLOD.getChild(numChildren-1).accept(*nv)
            
            # Request for child
            if   not pagedLOD.getDisableExternalChildrenPaging()  and 
                 nv.getDatabaseRequestHandler()  and 
                 numChildren<pagedLOD.getNumRanges()  :
                if  pagedLOD.getDatabasePath().empty()  :
                    nv.getDatabaseRequestHandler().requestNodeFile(
                        pagedLOD.getFileName(numChildren), nv.getNodePath(),
                        1.0, nv.getFrameStamp(),
                        pagedLOD.getDatabaseRequest(numChildren), pagedLOD.getDatabaseOptions() )
                else:
                    nv.getDatabaseRequestHandler().requestNodeFile(
                        pagedLOD.getDatabasePath()+pagedLOD.getFileName(numChildren), nv.getNodePath(),
                        1.0, nv.getFrameStamp(),
                        pagedLOD.getDatabaseRequest(numChildren), pagedLOD.getDatabaseOptions() )
        #node.traverse(*nv)

static PagedCullingCallback g_pagedCullingCallback = PagedCullingCallback()

# PosterVisitor: A visitor for adding culling callbacks to newly allocated paged nodes 
PosterVisitor.PosterVisitor()
:   osg.NodeVisitor(osg.NodeVisitor.TRAVERSE_ALL_CHILDREN),
    _appliedCount(0), _needToApplyCount(0),
    _addingCallbacks(True)

void PosterVisitor.apply( osg.LOD node )
    #if   not hasCullCallback(node.getCullCallback(), g_lodCullingCallback)  :
#    
#        if   not node.getName().empty()  :
#        
#            itr = _pagedNodeNames.find( node.getName() )
#            if  itr not =_pagedNodeNames.end()  :
#            
#                insertCullCallback( node, g_lodCullingCallback )
#                _appliedCount++
#            
#        
#    
#    def if _addingCallbacks .
#        
#        node.removeCullCallback( g_lodCullingCallback )
#        _appliedCount--
#    
    traverse( node )

void PosterVisitor.apply( osg.PagedLOD node )
    if   not hasCullCallback(node.getCullCallback(), g_pagedCullingCallback)  :
        for ( unsigned int i=0 i<node.getNumFileNames() ++i )
            if  node.getFileName(i).empty()  : continue
            
            itr = _pagedNodeNames.find( node.getFileName(i) )
            if  itr not =_pagedNodeNames.end()  :
                node.addCullCallback( g_pagedCullingCallback )
                _appliedCount++
            break
예제 #7
0
        _character = osg.PositionAttitudeTransform()
        _character.setName(name)
        _character.addChild(geode)
        
        moveTo(positionRatio)

        _centerBasket = width*catchPos.x() + height*catchPos.y() + pos
        _radiusBasket = width.length()*catchPos.z()

    

void Character.setLives( str filename,  osg.Vec3 origin,  osg.Vec3 delta, unsigned int numLives)
    characterSize = delta.length()

    _numLives = numLives
    _livesSwitch = osg.Switch()

    image = osgDB.readImageFile(filename)
    if image :
        stateset = _livesSwitch.getOrCreateStateSet()
        stateset.setTextureAttributeAndModes(0,osg.Texture2D(image),osg.StateAttribute.ON)
        stateset.setMode(GL_BLEND,osg.StateAttribute.ON)
        stateset.setRenderingHint(osg.StateSet.TRANSPARENT_BIN)

        for(unsigned int i=0 i<numLives ++i)
            pos = origin + delta*(float)i + osg.Vec3(0.0,0.0,0.0)
            width = osg.Vec3(characterSize*((float)image.s())/(float)(image.t()),0.0,0.0)
            height = osg.Vec3(0.0,0.0,characterSize)

            geometry = osg.createTexturedQuadGeometry(pos,width,height)
예제 #8
0
    def getMatrix():

         return _pageOffset*osg.Matrix.rotate(-_rotation,0.0,0.0,1.0) 
    def getInverseMatrix():
         return osg.Matrix.inverse(getMatrix()) 

    Page(Album* album, unsigned int pageNo,  str frontFileName,  str backFileName, float width, float height)

    _rotation = float()
    _pageOffset = osg.Matrix()

    _targetRotation = float()
    _targetTime = float()
    _lastTimeTraverse = float()

    _switch = osg.Switch()




class Album (osg.Referenced) :

    Album(osg.ArgumentParser ap, float width, float height)

    def getScene():

         return _group 

    def getScene():

         return _group 
예제 #9
0
    # now the windows have been realized we switch off the cursor to prevent it
    # distracting the people seeing the stereo images.
    double fovy, aspectRatio, zNear, zFar
    viewer.getCamera().getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar)

    radius = 1.0
    height = 2*radius*tan(osg.DegreesToRadians(fovy)*0.5)
    length = osg.PI*radius  # half a cylinder.

    # use a texture matrix to control the placement of the image.
    texmatLeft = osg.TexMat()
    texmatRight = osg.TexMat()

    # creat the scene from the file list.
    rootNode = osg.Switch()
    if  not onDisk :  rootNode = createScene(fileList,texmatLeft,texmatRight,radius,height,length)
    rootNode = osg.Switch()

    #osgDB.writeNodeFile(*rootNode,"test.osgt")



    viewer.getCamera().setCullMask(0xffffffff)
    viewer.getCamera().setCullMaskLeft(0x00000001)
    viewer.getCamera().setCullMaskRight(0x00000002)

    # set up the use of stereo by default.
    osg.DisplaySettings.instance().setStereo(True)

    if osg.DisplaySettings.instance().getStereoMode()==osg.DisplaySettings.ANAGLYPHIC :