Exemplo n.º 1
0
    class Cell (osg.Referenced) :
        typedef std.vector< Cell > CellList

        Cell():_parent(0) 
        Cell(osg.BoundingBox bb):_parent(0), _bb(bb) 

        def addCell(cell):

             cell._parent=this _cells.push_back(cell) 

        def addTree(tree):

             _trees.push_back(tree) 

        def addTrees(trees):

             _trees.insert(_trees.end(),trees.begin(),trees.end()) 

        computeBound = void()

        def contains(position):

             return _bb.contains(position) 

        divide = bool(unsigned int maxNumTreesPerCell=10)

        divide = bool(bool xAxis, bool yAxis, bool zAxis)

        bin = void()


        _parent = Cell*()
        _bb = osg.BoundingBox()
        _cells = CellList()
        _trees = TreeList()
Exemplo n.º 2
0
def LayoutAsGrid():

    
    # calculate bounding box
    bbox = osg.BoundingBox()
    for (NodeIterator node = nodes.begin() node  not = nodes.end() ++node)
        bbox.expandBy((*node).getBound())
Exemplo n.º 3
0
        def computeBound():
            
            bbox = osg.BoundingBox()

            # follow is some truely horrible code required to calculate the 
            # bounding box of the teapot.  Have used the original code above to do
            # help compute it.
            float p[4][4][3], q[4][4][3], r[4][4][3], s[4][4][3]
            long i, j, k, l

            for (i = 0 i < 10 i++) 
              for (j = 0 j < 4 j++) 
                for (k = 0 k < 4 k++) 
                
                  for (l = 0 l < 3 l++) 
                    p[j][k][l] = cpdata[patchdata[i][j * 4 + k]][l]
                    q[j][k][l] = cpdata[patchdata[i][j * 4 + (3 - k)]][l]
                    if l == 1 :
                      q[j][k][l] *= -1.0
                      
                    if i < 6 : 
                      r[j][k][l] =
                        cpdata[patchdata[i][j * 4 + (3 - k)]][l]
                      if l == 0 :
                        r[j][k][l] *= -1.0
                      s[j][k][l] = cpdata[patchdata[i][j * 4 + k]][l]
                      if l == 0 :
                        s[j][k][l] *= -1.0
                      if l == 1 :
                        s[j][k][l] *= -1.0
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
Exemplo n.º 5
0
        def computeBound():

            
            geom_box = _geometry.getBound()
            bb = osg.BoundingBox()
            for(PositionSizeList.const_iterator itr = _trees.begin()
                not = _trees.end()
                ++itr)
                bb.expandBy(geom_box.corner(0)*(*itr)[3] +
                            osg.Vec3( (*itr)[0], (*itr)[1], (*itr)[2] ))
                bb.expandBy(geom_box.corner(7)*(*itr)[3] +
                            osg.Vec3( (*itr)[0], (*itr)[1], (*itr)[2] ))
Exemplo n.º 6
0
def createOccludersAroundModel(model):

    
    scene = osg.Group()
    scene.setName("rootgroup")


    # add the loaded model into a the scene group.
    scene.addChild(model)
    model.setName("model")

    # get the bounding volume of the model.
    bs = model.getBound()

    # create a bounding box around the sphere.
    bb = osg.BoundingBox()
    bb.expandBy(bs)
Exemplo n.º 7
0
def createHUD():


    
    # create a camera to set up the projection and model view matrices, and the subgraph to draw in the HUD
    camera = osg.Camera()

    # set the projection matrix
    camera.setProjectionMatrix(osg.Matrix.ortho2D(0,1280,0,1024))

    # set the view matrix
    camera.setReferenceFrame(osg.Transform.ABSOLUTE_RF)
    camera.setViewMatrix(osg.Matrix.identity())

    # only clear the depth buffer
    camera.setClearMask(GL_DEPTH_BUFFER_BIT)

    # draw subgraph after main camera view.
    camera.setRenderOrder(osg.Camera.POST_RENDER)

    # we don't want the camera to grab event focus from the viewers main camera(s).
    camera.setAllowEventFocus(False)



    # add to this camera a subgraph to render

        geode = osg.Geode()

        timesFont = str("fonts/arial.ttf")

        # turn lighting off for the text and disable depth test to ensure it's always ontop.
        stateset = geode.getOrCreateStateSet()
        stateset.setMode(GL_LIGHTING,osg.StateAttribute.OFF)

        position = osg.Vec3(150.0,800.0,0.0)
        delta = osg.Vec3(0.0,-120.0,0.0)

            text = osgText.Text()
            geode.addDrawable( text )

            text.setFont(timesFont)
            text.setPosition(position)
            text.setText("Head Up Displays are simple :-)")

            position += delta


            text = osgText.Text()
            geode.addDrawable( text )

            text.setFont(timesFont)
            text.setPosition(position)
            text.setText("All you need to do is create your text in a subgraph.")

            position += delta


            text = osgText.Text()
            geode.addDrawable( text )

            text.setFont(timesFont)
            text.setPosition(position)
            text.setText("Then place an osg.Camera above the subgraph\n"
                          "to create an orthographic projection.\n")

            position += delta

            text = osgText.Text()
            geode.addDrawable( text )

            text.setFont(timesFont)
            text.setPosition(position)
            text.setText("Set the Camera's ReferenceFrame to ABSOLUTE_RF to ensure\n"
                          "it remains independent from any external model view matrices.")

            position += delta

            text = osgText.Text()
            geode.addDrawable( text )

            text.setFont(timesFont)
            text.setPosition(position)
            text.setText("And set the Camera's clear mask to just clear the depth buffer.")

            position += delta

            text = osgText.Text()
            geode.addDrawable( text )

            text.setFont(timesFont)
            text.setPosition(position)
            text.setText("And finally set the Camera's RenderOrder to POST_RENDER\n"
                          "to make sure it's drawn last.")

            position += delta


            bb = osg.BoundingBox()
            for(unsigned int i=0i<geode.getNumDrawables()++i)
                bb.expandBy(geode.getDrawable(i).getBound())
Exemplo n.º 8
0
def createRoom(loadedModel):


    
    # default scale for this model.
    bs = osg.BoundingSphere(osg.Vec3(0.0,0.0,0.0),1.0)

    root = osg.Group()

    if loadedModel :
        loaded_bs = loadedModel.getBound()

        pat = osg.PositionAttitudeTransform()
        pat.setPivotPoint(loaded_bs.center())

        pat.setUpdateCallback(ModelTransformCallback(loaded_bs))
        pat.addChild(loadedModel)

        bs = pat.getBound()

        root.addChild(pat)


    bs.radius()*=1.5

    # create a bounding box, which we'll use to size the room.
    bb = osg.BoundingBox()
    bb.expandBy(bs)


    # create statesets.
    rootStateSet = osg.StateSet()
    root.setStateSet(rootStateSet)

    wall = osg.StateSet()
    wall.setMode(GL_CULL_FACE,osg.StateAttribute.ON)

    floor = osg.StateSet()
    floor.setMode(GL_CULL_FACE,osg.StateAttribute.ON)

    roof = osg.StateSet()
    roof.setMode(GL_CULL_FACE,osg.StateAttribute.ON)

    geode = osg.Geode()

    # create front side.
    geode.addDrawable(createWall(bb.corner(0),
                                  bb.corner(4),
                                  bb.corner(1),
                                  wall))

    # right side
    geode.addDrawable(createWall(bb.corner(1),
                                  bb.corner(5),
                                  bb.corner(3),
                                  wall))

    # left side
    geode.addDrawable(createWall(bb.corner(2),
                                  bb.corner(6),
                                  bb.corner(0),
                                  wall))
    # back side
    geode.addDrawable(createWall(bb.corner(3),
                                  bb.corner(7),
                                  bb.corner(2),
                                  wall))

    # floor
    geode.addDrawable(createWall(bb.corner(0),
                                  bb.corner(1),
                                  bb.corner(2),
                                  floor))

    # roof
    geode.addDrawable(createWall(bb.corner(6),
                                  bb.corner(7),
                                  bb.corner(4),
                                  roof))

    root.addChild(geode)

    root.addChild(createLights(bb,rootStateSet))

    return root
Exemplo n.º 9
0
def decorate_with_clip_node(subgraph):

    rootnode = osg.Group()

    # create wireframe view of the model so the user can see
    # what parts are being culled away.
    stateset = osg.StateSet()
    #osg.Material* material = osg.Material()
    polymode = osg.PolygonMode()
    polymode.setMode(osg.PolygonMode.FRONT_AND_BACK, osg.PolygonMode.LINE)
    stateset.setAttributeAndModes(
        polymode, osg.StateAttribute.OVERRIDE | osg.StateAttribute.ON)

    wireframe_subgraph = osg.Group()
    wireframe_subgraph.setStateSet(stateset)
    wireframe_subgraph.addChild(subgraph)
    rootnode.addChild(wireframe_subgraph)

    #
    #    # simple approach to adding a clipnode above a subrgaph.
    #
    #    # create clipped part.
    #    clipped_subgraph = osg.ClipNode()
    #
    #    bs = subgraph.getBound()
    #    bs.radius()*= 0.4
    #
    #    bb = osg.BoundingBox()
    #    bb.expandBy(bs)
    #
    #
    #    clipped_subgraph.createClipBox(bb)
    #    clipped_subgraph.addChild(subgraph)
    #    rootnode.addChild(clipped_subgraph)
    #

    # more complex approach to managing ClipNode, allowing
    # ClipNode node to be transformed independantly from the subgraph
    # that it is clipping.

    transform = osg.MatrixTransform()

    nc = osg.AnimationPathCallback(subgraph.getBound().center(),
                                   osg.Vec3(0.0, 0.0, 1.0),
                                   osg.inDegrees(45.0))
    transform.setUpdateCallback(nc)

    clipnode = osg.ClipNode()
    bs = subgraph.getBound()
    bs.radius() *= 0.4

    bb = osg.BoundingBox()
    bb.expandBy(bs)

    clipnode.createClipBox(bb)
    clipnode.setCullingActive(False)

    transform.addChild(clipnode)
    rootnode.addChild(transform)

    # create clipped part.
    clipped_subgraph = osg.Group()

    clipped_subgraph.setStateSet(clipnode.getStateSet())
    clipped_subgraph.addChild(subgraph)
    rootnode.addChild(clipped_subgraph)

    return rootnode
Exemplo n.º 10
0
#*
# * Overloaded Geometry class to return predefined bounds
# 
class MyGeometry (osg.Geometry) :
    MyGeometry(osg.BoundingBox bounds)
        m_bounds = bounds
        m_bsphere = osg.BoundingSphere(bounds)

    # an attempt to return a reasonable bounding box. Still does not prevent clipping of the heat map.
    def getBoundingBox():
        return m_bounds
    def computeBound():
        return m_bounds
    def getBound():
        return m_bsphere
    m_bounds = osg.BoundingBox()
    m_bsphere = osg.BoundingSphere()


Heatmap.Heatmap(float width, float depth, float maxheight, unsigned int K, unsigned int N, float maximum, float transparency)
    m_K = K
    m_N = N
    O = 4

    # create Geometry object to store all the vertices primitives.
    meshGeom = MyGeometry(osg.BoundingBox(osg.Vec3(-width/2, -depth/2, 0), osg.Vec3(width/2, depth/2, maxheight)))

    # we use a float attribute array storing texcoords
    xypositions = osg.Vec2Array()
    xypositions.setName("xypos")
Exemplo n.º 11
0
    while arguments.read("--wind", wind.x(), wind.y(), wind.z()) : precipitationEffect.setWind(wind)
    
    while arguments.read("--particleSpeed", value) : precipitationEffect.setParticleSpeed(value)

    while arguments.read("--nearTransition", value ) : precipitationEffect.setNearTransition(value)
    while arguments.read("--farTransition", value ) : precipitationEffect.setFarTransition(value)

    while arguments.read("--particleDensity", value ) : precipitationEffect.setMaximumParticleDensity(value)

    cellSize = osg.Vec3()
    while arguments.read("--cellSize", cellSize.x(), cellSize.y(), cellSize.z()) : precipitationEffect.setCellSize(cellSize) 

    clipDistance = 0.0
    while arguments.read("--clip",clipDistance) : 

    bb = osg.BoundingBox()
    while arguments.read("--boundingBox", bb.xMin(),
                                           bb.yMin(),
                                           bb.zMin(),
                                           bb.xMax(),
                                           bb.yMax(),
                                           bb.zMax()) : 

    while arguments.read("--fogDensity", value ) : precipitationEffect.getFog().setDensity(value)
    while arguments.read("--fogColor", color.r(), color.g(), color.b(), color.a() ) :  precipitationEffect.getFog().setColor(color)
    while arguments.read("--fogColour", color.r(), color.g(), color.b(), color.a() ) :  precipitationEffect.getFog().setColor(color)
 
    while arguments.read("--useFarLineSegments") :  precipitationEffect.setUseFarLineSegments(True) 

    
    viewer.getCamera().setClearColor( precipitationEffect.getFog().getColor() )
Exemplo n.º 12
0
def createLogo(filename, label, subscript):

    
    bb = osg.BoundingBox(osg.Vec3(0.0,0.0,0.0),osg.Vec3(100.0,100.0,100.0))
    chordRatio = 0.5
    sphereRatio = 0.6

    # create a group to hold the whole model.
    logo_group = osg.Group()

    osg.Quat r1,r2
    r1.makeRotate(-osg.inDegrees(45.0),0.0,0.0,1.0)
    r2.makeRotate(osg.inDegrees(45.0),1.0,0.0,0.0)


    xform = MyBillboardTransform()
    xform.setPivotPoint(bb.center())
    xform.setPosition(bb.center())
    xform.setAttitude(r1*r2)


#     # create a transform to orientate the box and globe.
#     osg.MatrixTransform* xform = osg.MatrixTransform()
#     xform.setDataVariance(osg.Object.STATIC)
#     xform.setMatrix(osg.Matrix.translate(-bb.center())*
#                      osg.Matrix.rotate(-osg.inDegrees(45.0),0.0,0.0,1.0)*
#                      osg.Matrix.rotate(osg.inDegrees(45.0),1.0,0.0,0.0)*
#                      osg.Matrix.translate(bb.center()))

    # add the box and globe to it.
    #xform.addChild(createBox(bb,chordRatio))
    #xform.addChild(createBoxNo5(bb,chordRatio))
    xform.addChild(createBoxNo5No2(bb,chordRatio))
    # add the transform to the group.
    logo_group.addChild(xform)

    logo_group.addChild(createGlobe(bb,sphereRatio,filename))

    # add the text to the group.
    #group.addChild(createTextBelow(bb))
    logo_group.addChild(createTextLeft(bb, label, subscript))


    # create the backdrop to render the shadow to.
    corner = osg.Vec3(-900.0,150.0,-100.0)
    top = osg.Vec3(0.0,0.0,300.0) top += corner
    right = osg.Vec3(1100.0,0.0,0.0) right += corner


#     osg.Group* backdrop = osg.Group()
#     backdrop.addChild(createBackdrop(corner,top,right))

    backdrop = osg.ClearNode()
    backdrop.setClearColor(osg.Vec4(1.0,1.0,1.0,0.0))

    #osg.Vec3 lightPosition(-500.0,-2500.0,500.0)
    #osg.Node* scene = createShadowedScene(logo_group,backdrop,lightPosition,0.0,0)

    scene = osg.Group()

    stateset = scene.getOrCreateStateSet()
    stateset.setMode(GL_LIGHTING,osg.StateAttribute.OVERRIDE|osg.StateAttribute.OFF)


    scene.addChild(logo_group)
    scene.addChild(backdrop)

    return scene
Exemplo n.º 13
0
    
    arguments = osg.ArgumentParser(argv)

   # Make a scene graph consisting of a single Geode, containing
    # a single Geometry, and a single PrimitiveSet.
     geode = osg.Geode()

     geom = osg.Geometry()
    # Configure the Geometry for use with EXT_draw_arrays:
    # DL off and buffer objects on.
    geom.setUseDisplayList( False )
    geom.setUseVertexBufferObjects( True )
    # OSG has no clue where out vertex shader will place the geometric data,
    # so specify an initial bound to allow proper culling and near/far computation.
    bb = osg.BoundingBox( -1., -.1, -1., 49., 1., 49. )
    geom.setInitialBound( bb )
    # Add geometric data and the PrimitiveSet. Specify numInstances as 32*32 or 1024.
    createDAIGeometry( *geom, 32*32 )
    geode.addDrawable( geom )

    # Create a StateSet to render the instanced Geometry.
     ss = createStateSet()
    geode.setStateSet( ss )

    # osgDB.writeNodeFile(*geode, "instanced.osgt")

    viewer = osgViewer.Viewer(arguments)
    viewer.setSceneData( geode )
    return viewer.run()