Ejemplo n.º 1
0
class DepthPeeling (osg.Referenced) :

    DepthPeeling(unsigned int width, unsigned int height)
    setSolidScene = void(osg.Node* scene)
    setTransparentScene = void(osg.Node* scene)
    getRoot = osg.Node*()
    resize = void(int width, int height)
    setNumPasses = void(unsigned int numPasses)
    unsigned int getNumPasses() 
    setTexUnit = void(unsigned int texUnit)
    setShowAllLayers = void(bool showAllLayers)
    bool getShowAllLayers() 
    setOffsetValue = void(unsigned int offsetValue)
    unsigned int getOffsetValue() 

    static  char *PeelingShader # use this to support depth peeling in GLSL shaders in transparent objects 

    class EventHandler (osgGA.GUIEventHandler) :
        EventHandler(DepthPeeling* depthPeeling)

        #* Handle events, return True if handled, False otherwise. 
        handle = virtual bool( osgGA.GUIEventAdapter ea, osgGA.GUIActionAdapter, osg.Object*, osg.NodeVisitor*)
        _depthPeeling = DepthPeeling()
    
    *createQuad = osg.Node(unsigned int layerNumber, unsigned int numTiles)
    createPeeling = void()

    class CullCallback (osg.NodeCallback) :
        CullCallback(unsigned int texUnit, unsigned int texWidth, unsigned int texHeight, unsigned int offsetValue)
        virtual void operator()(osg.Node* node, osg.NodeVisitor* nv)
        _texUnit = unsigned int()
        _texWidth = unsigned int()
        _texHeight = unsigned int()
        _offsetValue = unsigned int()
    

    _numPasses = unsigned int()
    _texUnit = unsigned int()
    _texWidth = unsigned int()
    _texHeight = unsigned int()
    _showAllLayers = bool()
    _offsetValue = unsigned int()

    # The root node that is handed over to the viewer
    _root = osg.Group()

    # The scene that is displayed
    _solidscene = osg.Group()
    _transparentscene = osg.Group()

    # The final camera that composites the pre rendered textures to the final picture
    _compositeCamera = osg.Camera()

#ifdef USE_TEXTURE_RECTANGLE
    _depthTextures = std.vector<osg.TextureRectangle >()
    _colorTextures = std.vector<osg.TextureRectangle >()
#else:
    _depthTextures = std.vector<osg.Texture2D >()
    _colorTextures = std.vector<osg.Texture2D >()
Ejemplo n.º 2
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()
Ejemplo n.º 3
0
def createModel(overlay, technique):

    
    center = osg.Vec3(0.0,0.0,0.0)
    radius = 100.0

    root = osg.Group()

    baseHeight = center.z()-radius*0.5
    baseModel = createBase(osg.Vec3(center.x(), center.y(), baseHeight),radius)
    movingModel = createMovingModel(center,radius*0.8)

    if overlay :
        overlayNode = osgSim.OverlayNode(technique)
        overlayNode.setContinuousUpdate(True)
        overlayNode.setOverlaySubgraph(movingModel)
        overlayNode.setOverlayBaseHeight(baseHeight-0.01)
        overlayNode.addChild(baseModel)
        root.addChild(overlayNode)
    else:

        root.addChild(baseModel)

    root.addChild(movingModel)

    return root
Ejemplo n.º 4
0
def createModel():




    
    center = osg.Vec3(0.0,0.0,0.0)
    radius = 100.0
    lightPosition = osg.Vec3(center+osg.Vec3(0.0,0.0,radius))

    # the shadower model
    shadower = createMovingModel(center,radius*0.5)

    # the shadowed model
    shadowed = createBase(center-osg.Vec3(0.0,0.0,radius*0.1),radius)

    # combine the models together to create one which has the shadower and the shadowed with the required callback.
    root = osg.Group()
    
    root.setStateSet(createSpotLightDecoratorState(0,1))

    root.addChild(shadower)
    root.addChild(shadowed)

    return root
Ejemplo n.º 5
0
def loadImages(image1, image2, texmatLeft, texmatRight, radius, height, length):

    
    imageLeft = osgDB.readImageFile(image1)
    imageRight = osgDB.readImageFile(image2)
    if imageLeft.valid()  and  imageRight.valid() :
	streamLeft = dynamic_cast<osg.ImageStream*>(imageLeft)
	if streamLeft : streamLeft.play()

	streamRight = dynamic_cast<osg.ImageStream*>(imageRight)
	if streamRight : streamRight.play()


	average_s = (imageLeft.s()+imageRight.s())*0.5
	average_t = (imageLeft.t()+imageRight.t())*0.5
	geodeLeft = createSectorForImage(imageLeft,texmatLeft,average_s,average_t, radius, height, length)
	geodeLeft.setNodeMask(0x01)

	geodeRight = createSectorForImage(imageRight,texmatRight,average_s,average_t, radius, height, length)
	geodeRight.setNodeMask(0x02)

	imageGroup = osg.Group()

	imageGroup.addChild(geodeLeft)
	imageGroup.addChild(geodeRight)
	return imageGroup
    else:
	print "Warning: Unable to load both image files, '", image1, "'  '", image2, "', required for stereo imaging."
	return 0
Ejemplo n.º 6
0
def createSpotLightNode(position, direction, angle, lightNum, textureUnit):


    
    group = osg.Group()
    
    # create light source.
    lightsource = osg.LightSource()
    light = lightsource.getLight()
    light.setLightNum(lightNum)
    light.setPosition(osg.Vec4(position,1.0))
    light.setAmbient(osg.Vec4(0.00,0.00,0.05,1.0))
    light.setDiffuse(osg.Vec4(1.0,1.0,1.0,1.0))
    group.addChild(lightsource)
    
    # create tex gen.
    
    up = osg.Vec3(0.0,0.0,1.0)
    up = (direction ^ up) ^ direction
    up.normalize()
    
    texgenNode = osg.TexGenNode()
    texgenNode.setTextureUnit(textureUnit)
    texgen = texgenNode.getTexGen()
    texgen.setMode(osg.TexGen.EYE_LINEAR)
    texgen.setPlanesFromMatrix(osg.Matrixd.lookAt(position, position+direction, up)*
                                osg.Matrixd.perspective(angle,1.0,0.1,100)*
                                osg.Matrixd.translate(1.0,1.0,1.0)*
                                osg.Matrixd.scale(0.5,0.5,0.5))

    
    group.addChild(texgenNode)
    
    return group
Ejemplo n.º 7
0
def addDraggerToScene(scene, name, fixedSizeInScreen):

    
    scene.getOrCreateStateSet().setMode(GL_NORMALIZE, osg.StateAttribute.ON)

    transform = osg.MatrixTransform()
    transform.addChild(scene)

    dragger = createDragger(name)

    root = osg.Group()
    root.addChild(transform)

    if  fixedSizeInScreen  :
        draggerContainer = DraggerContainer()
        draggerContainer.setDragger( dragger )
        root.addChild(draggerContainer)
    else:
        root.addChild(dragger)

    scale = scene.getBound().radius() * 1.6
    dragger.setMatrix(osg.Matrix.scale(scale, scale, scale) *
                       osg.Matrix.translate(scene.getBound().center()))

    if dynamic_cast<osgManipulator.TabPlaneDragger*>(dragger) :
        dragger.addTransformUpdating(transform, osgManipulator.DraggerTransformCallback.HANDLE_TRANSLATE_IN_LINE)
def main(argv):

    
    arguments = osg.ArgumentParser(argv)
    viewer = osgViewer.Viewer(arguments)
    
    tbm = osgGA.TrackballManipulator()

    viewer.setCameraManipulator(tbm)

    viewer.addEventHandler(osgViewer.StatsHandler())
    viewer.addEventHandler(osgViewer.WindowSizeHandler())

    root = osg.Group()
    geode = osg.Geode()

    geode.setStateSet(setupStateSet())

    root.setInitialBound(osg.BoundingSphere(osg.Vec3(10,0,20), 50))
    root.addChild(setupAnimtkNode(geode))
    root.addChild(geode)

    viewer.setSceneData(root)

    # tbm.setDistance(150)

    return viewer.run()
Ejemplo n.º 9
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]))
Ejemplo n.º 10
0
def test_create3DText(center, radius):



    

    geode = osg.Geode()

    characterSize = radius*0.2
    characterDepth = characterSize*0.2
    
    pos = osg.Vec3(center.x()-radius*.5,center.y()-radius*.5,center.z()-radius*.5)
#define SHOW_INTESECTION_CEASH
#ifdef SHOW_INTESECTION_CEASH
    text3 = osgText.Text3D()
    text3.setFont("fonts/dirtydoz.ttf")
    text3.setCharacterSize(characterSize)
    text3.setCharacterDepth(characterDepth)
    text3.setPosition(pos)
    text3.setDrawMode(osgText.Text3D.TEXT | osgText.Text3D.BOUNDINGBOX)
    text3.setAxisAlignment(osgText.Text3D.XZ_PLANE)
    text3.setText("CRAS H") #intersection crash
    geode.addDrawable(text3)
#else:
    text7 = osgText.Text3D()
    text7.setFont("fonts/times.ttf")
    text7.setCharacterSize(characterSize)
    text7.setCharacterDepth(characterSize*2.2)
    text7.setPosition(center - osg.Vec3(0.0, 0.0, 0.6))
    text7.setDrawMode(osgText.Text3D.TEXT | osgText.Text3D.BOUNDINGBOX)
    text7.setAxisAlignment(osgText.Text3D.SCREEN)
    text7.setCharacterSizeMode(osgText.Text3D.OBJECT_COORDS)
    text7.setText("ABCDE") #wrong intersection
    geode.addDrawable(text7)
#endif

    shape = osg.ShapeDrawable(osg.Sphere(center,characterSize*0.2))
    shape.getOrCreateStateSet().setMode(GL_LIGHTING,osg.StateAttribute.ON)
    geode.addDrawable(shape)

    rootNode = osg.Group()
    rootNode.addChild(geode)

#define SHOW_WRONG_NORMAL
#ifdef SHOW_WRONG_NORMAL
    front = osg.Material() #
    front.setAlpha(osg.Material.FRONT_AND_BACK,1)
    front.setAmbient(osg.Material.FRONT_AND_BACK,osg.Vec4(0.2,0.2,0.2,1.0))
    front.setDiffuse(osg.Material.FRONT_AND_BACK,osg.Vec4(.0,.0,1.0,1.0))
    rootNode.getOrCreateStateSet().setAttributeAndModes(front)
#else:
    stateset = osg.StateSet() #Show wireframe
    polymode = osg.PolygonMode()
    polymode.setMode(osg.PolygonMode.FRONT_AND_BACK,osg.PolygonMode.LINE)
    stateset.setAttributeAndModes(polymode,osg.StateAttribute.OVERRIDE|osg.StateAttribute.ON)
    rootNode.setStateSet(stateset)
#endif
    
    
    return rootNode    
Ejemplo n.º 11
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)
Ejemplo n.º 12
0
def main(argv):

    
    app = QApplication(argc, argv)

    # prepare scene.
    center = osg.Vec3(0.0,0.0,0.0)
    radius = 1.0
    
    # create the hud.
    camera = osg.Camera()
    camera.setReferenceFrame(osg.Transform.ABSOLUTE_RF)
    camera.setProjectionMatrixAsOrtho2D(0,1280,0,1024)
    camera.setViewMatrix(osg.Matrix.identity())
    camera.setClearMask(GL_DEPTH_BUFFER_BIT)
    camera.addChild(createHUDText())
    camera.getOrCreateStateSet().setMode(GL_LIGHTING,osg.StateAttribute.OFF)
    
    # make sure the root node is group so we can add extra nodes to it.
    group = osg.Group()
    group.addChild(camera)
    group.addChild(create3DText(center, radius))

    # The qt window
    widget = MainWindow()
    
    # set the scene to render
    widget.setSceneData(group)
    widget.setCameraManipulator(osgGA.TrackballManipulator)()

    widget.setGeometry(100, 100, 800, 600)
    widget.show()

    return app.exec()
Ejemplo n.º 13
0
def main(argv):


    
    # use an ArgumentParser object to manage the program arguments.
    arguments = osg.ArgumentParser(argv)

    # construct the viewer.
    viewer = osgViewer.Viewer()

    # add local test manipulator more suitable for testing impostors.
    viewer.setCameraManipulator(TestManipulator)()


    # load the nodes from the commandline arguments.
    model = osgDB.readNodeFiles(arguments)
    if model :
        # the osgSim.InsertImpostorsVisitor used lower down to insert impostors
        # only operators on subclass of Group's, if the model top node is not
        # a group then it won't be able to insert an impostor.  We therefore
        # manually insert an impostor above the model.
        if dynamic_cast<osg.Group*>(model)==0 :
            bs = model.getBound()
            if bs.valid() :

                impostor = osgSim.Impostor()

                # standard LOD settings
                impostor.addChild(model)
                impostor.setRange(0,0.0,1e7f)
                impostor.setCenter(bs.center())

                # impostor specfic settings.
                impostor.setImpostorThresholdToBound(5.0)

                model = impostor


        # we insert an impostor node above the model, so we keep a handle
        # on the rootnode of the model, the is required since the
        # InsertImpostorsVisitor can add a root in automatically and
        # we would know about it, other than by following the parent path
        # up from model.  This is really what should be done, but I'll pass
        # on it right now as it requires a getRoots() method to be added to
        # osg.Node, and we're about to make a release so no features not 
        rootnode = osg.Group()
        rootnode.addChild(model)


        # now insert impostors in the model using the InsertImpostorsVisitor.
        ov = osgSim.InsertImpostorsVisitor()

        # traverse the model and collect all osg.Group's and osg.LOD's.
        # however, don't traverse the rootnode since we want to keep it as
        # the start of traversal, otherwise the insertImpostor could insert
        # and Impostor above the current root, making it nolonger a root not 
        model.accept(ov)

        # insert the Impostors above groups and LOD's
        ov.insertImpostors()
Ejemplo n.º 14
0
def creatQuad(name, image, formatMode, minFilter):

    

    group = osg.Group()
    
        geode = osg.Geode()

        geode.addDrawable(createTexturedQuadGeometry(
                osg.Vec3(0.0,0.0,0.0),
                osg.Vec3(float(image.s()),0.0,0.0),
                osg.Vec3(0.0,0.0,float(image.t()))))

        geode.setName(name)

        stateset = geode.getOrCreateStateSet()

        texture = osg.Texture2D(image)
        texture.setInternalFormatMode(formatMode)
        texture.setFilter(osg.Texture.MIN_FILTER, minFilter)
        stateset.setTextureAttributeAndModes(0, texture, osg.StateAttribute.ON)
        
        group.addChild(geode)
    
        group.addChild(createHUD(name))
Ejemplo n.º 15
0
def createFadeText(ellipsoid):

    
    group = osg.Group()

    group.getOrCreateStateSet().setMode(GL_DEPTH_TEST,osg.StateAttribute.OFF)
    
    geode = osg.Geode()
    group.addChild(geode)
    
    textList = std.vector<str>()
    textList.push_back("Town")
    textList.push_back("City")
    textList.push_back("Village")
    textList.push_back("River")
    textList.push_back("Mountain")
    textList.push_back("Road")
    textList.push_back("Lake")
    
    numLat = 15
    numLong = 20
    latitude = 0.0
    longitude = -100.0
    deltaLatitude = 1.0
    deltaLongitude = 1.0

    t = 0
    for(unsigned int i = 0 i < numLat ++i, latitude += deltaLatitude)
        lgnt = longitude
        for(unsigned int j = 0 j < numLong ++j, ++t, lgnt += deltaLongitude)
            geode.addDrawable( createText( ellipsoid, latitude, lgnt, 0, textList[t % textList.size()]) )
Ejemplo n.º 16
0
def createTextGroup(text):

    
    group = osg.Group()

    pos = osg.Vec3(120.0, 800.0, 0.0)
    delta =  osg.Vec3(0.0, -60.0, 0.0)

    # header
    t = text
    group.addChild(createText(*t++, pos))
    pos += delta

    # remainder of text under sequence
    seq = osg.Sequence()
    group.addChild(seq)
    while *t : 
        seq.addChild(createText(*t++, pos))
        seq.setTime(seq.getNumChildren()-1, 2.0)
        pos += delta

    # loop through all children
    seq.setInterval(osg.Sequence.LOOP, 0,-1)

    # real-time playback, repeat indefinitively
    seq.setDuration(1.0, -1)

    # must be started explicitly
    seq.setMode(osg.Sequence.START)

    return group
Ejemplo n.º 17
0
def createSceneGraph(arguments):

    
    node = osgDB.readNodeFiles(arguments)
    if  not node : return 0

    group = osg.Group()
    spacing = node.getBound().radius() * 2.0

    position = osg.Vec3d(0.0,0.0,0.0)

    sa1 = NULL

        stateset = group.getOrCreateStateSet()
        sa = osg.ShaderAttribute()
        sa.setType(osg.StateAttribute.Type(10000))
        sa1 = sa
        stateset.setAttribute(sa)

            vertex_shader = osg.Shader(osg.Shader.VERTEX)
            vertex_shader.addCodeInjection(-1,"varying vec4 color\n")
            vertex_shader.addCodeInjection(-1,"varying vec4 texcoord\n")
            vertex_shader.addCodeInjection(0,"color = gl_Color\n")
            vertex_shader.addCodeInjection(0,"texcoord = gl_MultiTexCoord0\n")
            vertex_shader.addCodeInjection(0,"gl_Position = ftransform()\n")
            sa.addShader(vertex_shader)

            fragment_shader = osg.Shader(osg.Shader.FRAGMENT)
            fragment_shader.addCodeInjection(-1,"varying vec4 color\n")
            fragment_shader.addCodeInjection(-1,"varying vec4 texcoord\n")
            fragment_shader.addCodeInjection(-1,"uniform sampler2D baseTexture \n")
            fragment_shader.addCodeInjection(0,"gl_FragColor = color * texture2DProj( baseTexture, texcoord )\n")

            sa.addShader(fragment_shader)
Ejemplo n.º 18
0
def createMovingModel(center, radius):

    
    animationLength = 10.0

    animationPath = createAnimationPath(center,radius,animationLength)

    model = osg.Group()
 
    cessna = osgDB.readNodeFile("cessna.osgt")
    if cessna :
        bs = cessna.getBound()

        size = radius/bs.radius()*0.3
        positioned = osg.MatrixTransform()
        positioned.setDataVariance(osg.Object.STATIC)
        positioned.setMatrix(osg.Matrix.translate(-bs.center())*
                              osg.Matrix.scale(size,size,size)*
                              osg.Matrix.rotate(osg.inDegrees(180.0),0.0,0.0,2.0))
    
        positioned.addChild(cessna)
    
        xform = osg.MatrixTransform()
        xform.setUpdateCallback(osg.AnimationPathCallback(animationPath,0.0,2.0))
        xform.addChild(positioned)

        xform.addChild(createSpotLightNode(osg.Vec3(0.0,0.0,0.0), osg.Vec3(0.0,1.0,-1.0), 60.0, 0, 1))

        model.addChild(xform)
    
    return model
Ejemplo n.º 19
0
def main(argv):


    
    arguments = osg.ArgumentParser( argc, argv )

     root = osg.Group()
Ejemplo n.º 20
0
def createLights(bb, rootStateSet):


    
    lightGroup = osg.Group()

    modelSize = bb.radius()

    # create a spot light.
    myLight1 = osg.Light()
    myLight1.setLightNum(0)
    myLight1.setPosition(osg.Vec4(bb.corner(4),1.0))
    myLight1.setAmbient(osg.Vec4(1.0,0.0,0.0,1.0))
    myLight1.setDiffuse(osg.Vec4(1.0,0.0,0.0,1.0))
    myLight1.setSpotCutoff(20.0)
    myLight1.setSpotExponent(50.0)
    myLight1.setDirection(osg.Vec3(1.0,1.0,-1.0))

    lightS1 = osg.LightSource()
    lightS1.setLight(myLight1)
    lightS1.setLocalStateSetModes(osg.StateAttribute.ON)

    lightS1.setStateSetModes(*rootStateSet,osg.StateAttribute.ON)
    lightGroup.addChild(lightS1)


    # create a local light.
    myLight2 = osg.Light()
    myLight2.setLightNum(1)
    myLight2.setPosition(osg.Vec4(0.0,0.0,0.0,1.0))
    myLight2.setAmbient(osg.Vec4(0.0,1.0,1.0,1.0))
    myLight2.setDiffuse(osg.Vec4(0.0,1.0,1.0,1.0))
    myLight2.setConstantAttenuation(1.0)
    myLight2.setLinearAttenuation(2.0/modelSize)
    myLight2.setQuadraticAttenuation(2.0/osg.square(modelSize))

    lightS2 = osg.LightSource()
    lightS2.setLight(myLight2)
    lightS2.setLocalStateSetModes(osg.StateAttribute.ON)

    lightS2.setStateSetModes(*rootStateSet,osg.StateAttribute.ON)

    mt = osg.MatrixTransform()
        # set up the animation path
        animationPath = osg.AnimationPath()
        animationPath.insert(0.0,osg.AnimationPath.ControlPoint(bb.corner(0)))
        animationPath.insert(1.0,osg.AnimationPath.ControlPoint(bb.corner(1)))
        animationPath.insert(2.0,osg.AnimationPath.ControlPoint(bb.corner(2)))
        animationPath.insert(3.0,osg.AnimationPath.ControlPoint(bb.corner(3)))
        animationPath.insert(4.0,osg.AnimationPath.ControlPoint(bb.corner(4)))
        animationPath.insert(5.0,osg.AnimationPath.ControlPoint(bb.corner(5)))
        animationPath.insert(6.0,osg.AnimationPath.ControlPoint(bb.corner(6)))
        animationPath.insert(7.0,osg.AnimationPath.ControlPoint(bb.corner(7)))
        animationPath.insert(8.0,osg.AnimationPath.ControlPoint(bb.corner(0)))
        animationPath.setLoopMode(osg.AnimationPath.SWING)

        mt.setUpdateCallback(osg.AnimationPathCallback(animationPath))
def createModel(filename):


    
    root = osg.Group()

    if filename  not = "X" : 
        bb = osg.BoundingBox(0.0,0.0,0.0,1.0,1.0,1.0)
        root.addChild(createRectangle(bb, filename)) # XXX
Ejemplo n.º 22
0
def main(argv):


    
    arguments = osg.ArgumentParser(argv)
    
    node = osg.Group()

    if arguments.read("--MyUserDataContainer")  or  arguments.read("--mydc") :
        node.setUserDataContainer(MyNamespace.MyUserDataContainer)()
    
    i = 10
    node.setUserValue("Int value",i)

    testString = str("All seems fine")
    node.setUserValue("Status",testString)

    node.setUserValue("Height",float(1.4))

    drawable = osg.Geometry()
    drawable.setName("myDrawable")
    node.getOrCreateUserDataContainer().addUserObject(drawable)

    node.setUserValue("fred",12)
    node.setUserValue("john",1.1)
    node.setUserValue("david",1.9)
    node.setUserValue("char",char(65))
    node.setUserValue("matrixd",osg.Matrixd.translate(1.0,2.0,3.0))
    node.setUserValue("flag-on",True)
    node.setUserValue("flag-off",False)

    OSG_NOTICE, "Testing results for values set directly on scene graph"
    testResults(node)

        osgDB.writeNodeFile(*node, "results.osgt")

        from_osgt = osgDB.readNodeFile("results.osgt")
        if from_osgt.valid() :
            OSG_NOTICE, "Testing results for values from scene graph read from .osgt file"
            testResults(from_osgt)
    
        osgDB.writeNodeFile(*node, "results.osgb")

        from_osgb = osgDB.readNodeFile("results.osgb")
        if from_osgb.valid() :
            OSG_NOTICE, "Testing results for values from scene graph read from .osgb file"
            testResults(from_osgb)

        osgDB.writeNodeFile(*node, "results.osgx")

        from_osgx = osgDB.readNodeFile("results.osgx")
        if from_osgx.valid() :
            OSG_NOTICE, "Testing results for values from scene graph read from .osgx file"
            testResults(from_osgx)
Ejemplo n.º 23
0
def createMovingModel(center, radius):

    
    animationLength = 10.0

    animationPath = createAnimationPath(center,radius,animationLength)

    model = osg.Group()

    glider = osgDB.readNodeFile("glider.osgt")
    if glider :
        bs = glider.getBound()
        size = radius/bs.radius()*0.15

        positioned = osg.MatrixTransform()
        positioned.setDataVariance(osg.Object.STATIC)
        positioned.setMatrix(osg.Matrix.translate(-bs.center())*
                                     osg.Matrix.scale(size,size,size)*
                                     osg.Matrix.rotate(osg.inDegrees(-90.0),0.0,0.0,1.0))
    
        positioned.addChild(glider)
    
        xform = osg.PositionAttitudeTransform()
        xform.setDataVariance(osg.Object.DYNAMIC)
        xform.getOrCreateStateSet().setMode(GL_NORMALIZE, osg.StateAttribute.ON)
        xform.setUpdateCallback(osg.AnimationPathCallback(animationPath,0.0,0.5))
        xform.addChild(positioned)

        model.addChild(xform)
 
    cessna = osgDB.readNodeFile("cessna.osgt")
    if cessna :
        bs = cessna.getBound()
        size = radius/bs.radius()*0.15

        positioned = osg.MatrixTransform()
        positioned.getOrCreateStateSet().setMode(GL_NORMALIZE, osg.StateAttribute.ON)
        positioned.setDataVariance(osg.Object.STATIC)
        positioned.setMatrix(osg.Matrix.translate(-bs.center())*
                                     osg.Matrix.scale(size,size,size)*
                                     osg.Matrix.rotate(osg.inDegrees(180.0),0.0,0.0,1.0))
    
        #positioned.addChild(cessna)
        positioned.addChild(cessna)
    
        xform = osg.MatrixTransform()
        xform.setDataVariance(osg.Object.DYNAMIC)
        xform.setUpdateCallback(osg.AnimationPathCallback(animationPath,0.0,1.0))
        xform.addChild(positioned)

        model.addChild(xform)
    
    return model
Ejemplo n.º 24
0
def createModel():

    

    # create the root node which will hold the model.
    root = osg.Group()

    # add the drawable into a single goede to be shared...
    center = osg.Billboard()
    center.setMode(osg.Billboard.POINT_ROT_EYE)
    center.addDrawable(
        createSquare(osg.Vec3(-0.5,0.0,-0.5),osg.Vec3(1.0,0.0,0.0),osg.Vec3(0.0,0.0,1.0),osgDB.readImageFile("Images/reflect.rgb")),
        osg.Vec3(0.0,0.0,0.0))

    x_arrow = osg.Billboard()
    x_arrow.setMode(osg.Billboard.AXIAL_ROT)
    x_arrow.setAxis(osg.Vec3(1.0,0.0,0.0))
    x_arrow.setNormal(osg.Vec3(0.0,-1.0,0.0))
    x_arrow.addDrawable(
       createSquare(osg.Vec3(-0.5,0.0,-0.5),osg.Vec3(1.0,0.0,0.0),osg.Vec3(0.0,0.0,1.0),osgDB.readImageFile("Cubemap_axis/posx.png")),
       osg.Vec3(5.0,0.0,0.0))

    y_arrow = osg.Billboard()
    y_arrow.setMode(osg.Billboard.AXIAL_ROT)
    y_arrow.setAxis(osg.Vec3(0.0,1.0,0.0))
    y_arrow.setNormal(osg.Vec3(1.0,0.0,0.0))
    y_arrow.addDrawable(
        createSquare(osg.Vec3(0.0,-0.5,-0.5),osg.Vec3(0.0,1.0,0.0),osg.Vec3(0.0,0.0,1.0),osgDB.readImageFile("Cubemap_axis/posy.png")),
        osg.Vec3(0.0,5.0,0.0))

    z_arrow = osg.Billboard()
    z_arrow.setMode(osg.Billboard.AXIAL_ROT)
    z_arrow.setAxis(osg.Vec3(0.0,0.0,1.0))
    z_arrow.setNormal(osg.Vec3(0.0,-1.0,0.0))
    z_arrow.addDrawable(
        createSquare(osg.Vec3(-0.5,0.0,-0.5),osg.Vec3(1.0,0.0,0.0),osg.Vec3(0.0,0.0,1.0),osgDB.readImageFile("Cubemap_axis/posz.png")),
        osg.Vec3(0.0,0.0,5.0))



    axis = osg.Geode()
    axis.addDrawable(createAxis(osg.Vec3(0.0,0.0,0.0),osg.Vec3(5.0,0.0,0.0),osg.Vec3(0.0,5.0,0.0),osg.Vec3(0.0,0.0,5.0)))


    root.addChild(center)
    root.addChild(x_arrow)
    root.addChild(y_arrow)
    root.addChild(z_arrow)
    root.addChild(axis)

    return root
Ejemplo n.º 25
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 how to use glBlendEquation for mixing rendered scene and the frame-buffer.")
    arguments.getApplicationUsage().setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...")
    arguments.getApplicationUsage().addCommandLineOption("-h or --help","Display this information")
   
    # construct the viewer.
    viewer = osgViewer.Viewer()

    # load the nodes from the commandline arguments.
    loadedModel = osgDB.readNodeFiles(arguments)

    # if not loaded assume no arguments passed in, try use default mode instead.
    if  not loadedModel : loadedModel = osgDB.readNodeFile("cessnafire.osgt")
  
    if  not loadedModel :
        print arguments.getApplicationName(), ": No data loaded"
        return 1

    root = osg.Group()
    root.addChild(loadedModel)
    
    
    stateset = osg.StateSet()
    stateset.setDataVariance(osg.Object.DYNAMIC)
    
    blendEquation = osg.BlendEquation(osg.BlendEquation.FUNC_ADD)
    blendEquation.setDataVariance(osg.Object.DYNAMIC)
    
    stateset.setAttributeAndModes(blendEquation,osg.StateAttribute.OVERRIDE|osg.StateAttribute.ON)
            
    #tell to sort the mesh before displaying it
    stateset.setRenderingHint(osg.StateSet.TRANSPARENT_BIN)           

    loadedModel.setStateSet(stateset)

    viewer.addEventHandler(TechniqueEventHandler(blendEquation))

    # add a viewport to the viewer and attach the scene graph.
    viewer.setSceneData( root )
    
    return viewer.run()
Ejemplo n.º 26
0
def setupBin2(rootNode, model,z):
    stencil = osg.Stencil();
    stencil.setFunction(osg.Stencil.ALWAYS,0,4294967295);
    stencil.setOperation(osg.Stencil.KEEP, osg.Stencil.KEEP, osg.Stencil.REPLACE);

    statesetBin2 = osg.StateSet();
    statesetBin2.setRenderBinDetails(2,"RenderBin");
    statesetBin2.setAttributeAndModes(stencil,osg.StateAttribute.ON);

    groupBin2 = osg.Group();
    groupBin2.setStateSet(statesetBin2);
    groupBin2.addChild(model);

    rootNode.addChild(groupBin2);
Ejemplo n.º 27
0
def createStockScene():
    
    # Create a simple box occluder
    root = osg.Group()
    root.addChild( createBox() )

    # Create a complex mess of triangles as a child below an
    #   OcclusionQueryNode. The OQN will ensure that the
    #   subgraph isn't rendered when it's not visible.
    oqn = osg.OcclusionQueryNode()
    oqn.addChild( createRandomTriangles( 20000 ) )
    root.addChild( oqn )

    return root
Ejemplo n.º 28
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()
Ejemplo n.º 29
0
def main(argv):

    
    arguments = osg.ArgumentParser( argc, argv )
    
    # Create the texture as both the output of compute shader and the input of a normal quad
    tex2D = osg.Texture2D()
    tex2D.setTextureSize( 512, 512 )
    tex2D.setFilter( osg.Texture2D.MIN_FILTER, osg.Texture2D.LINEAR )
    tex2D.setFilter( osg.Texture2D.MAG_FILTER, osg.Texture2D.LINEAR )
    tex2D.setInternalFormat( GL_R32F )
    tex2D.setSourceFormat( GL_RED )
    tex2D.setSourceType( GL_FLOAT )
    tex2D.bindToImageUnit( 0, osg.Texture.WRITE_ONLY )  # So we can use 'image2D' in the compute shader
    
    # The compute shader can't work with other kinds of shaders
    # It also requires the work group numbers. Setting them to 0 will disable the compute shader
    computeProg = osg.Program()
    computeProg.setComputeGroups( 512/16, 512/16, 1 )
    computeProg.addShader( osg.Shader(osg.Shader.COMPUTE, computeSrc) )
    
    # Create a node for outputting to the texture.
    # It is OK to have just an empty node here, but seems inbuilt uniforms like osg_FrameTime won't work then.
    # TODO: maybe we can have a custom drawable which also will implement  sourceNode = osgDB: if (glMemoryBarrier) else readNodeFile("axes.osgt")
    if   not sourceNode  : sourceNode = osg.Node()
    sourceNode.setDataVariance( osg.Object.DYNAMIC )
    sourceNode.getOrCreateStateSet().setAttributeAndModes( computeProg )
    sourceNode.getOrCreateStateSet().addUniform( osg.Uniform("targetTex", (int)0) )
    sourceNode.getOrCreateStateSet().setTextureAttributeAndModes( 0, tex2D )
    
    # Display the texture on a quad. We will also be able to operate on the data if reading back to CPU side
    geom = osg.createTexturedQuadGeometry(
        osg.Vec3(), osg.Vec3(1.0,0.0,0.0), osg.Vec3(0.0,0.0,1.0) )
    quad = osg.Geode()
    quad.addDrawable( geom )
    quad.getOrCreateStateSet().setMode( GL_LIGHTING, osg.StateAttribute.OFF )
    quad.getOrCreateStateSet().setTextureAttributeAndModes( 0, tex2D )
    
    # Create the scene graph and start the viewer
    scene = osg.Group()
    scene.addChild( sourceNode )
    scene.addChild( quad )
    
    viewer = osgViewer.Viewer()
    viewer.addEventHandler( osgGA.StateSetManipulator(viewer.getCamera().getOrCreateStateSet()) )
    viewer.addEventHandler( osgViewer.StatsHandler )()
    viewer.addEventHandler( osgViewer.WindowSizeHandler )()
    viewer.setSceneData( scene )
    return viewer.run()
Ejemplo n.º 30
0
def createScene():

    
    root = osg.Group()

#    int numReps = 3333
    numReps = 10
    root.addChild(createAxis(osg.Vec3(0.0,0.0,0.0),osg.Vec3(1000.0,0.0,0.0),numReps,osg.AutoTransform.ROTATE_TO_CAMERA,osgText.Text.XY_PLANE, "ROTATE_TO_CAMERA"))
    root.addChild(createAxis(osg.Vec3(0.0,0.0,0.0),osg.Vec3(0.0,1000.0,0.0),numReps,osg.AutoTransform.ROTATE_TO_SCREEN,osgText.Text.XY_PLANE, "ROTATE_TO_SCREEN"))
    root.addChild(createAxis(osg.Vec3(0.0,0.0,0.0),osg.Vec3(0.0,0.0,1000.0),numReps,osg.AutoTransform.NO_ROTATION,osgText.Text.XZ_PLANE, "NO_ROTATION"))

    root.addChild(createAutoScale(osg.Vec3(500.0,500.0,500.0), 25.0, "AutoScale with no min, max limits"))
    root.addChild(createAutoScale(osg.Vec3(500.0,500.0,300.0), 25.0, "AutoScale with minScale = 1, maxScale = 2.0 ", 1, 2.0))
    root.addChild(createAutoScale(osg.Vec3(500.0,500.0,700.0), 25.0, "AutoScale with minScale = 0.0, maxScale = 5.0 ", 0.0, 5.0))
    return root