def createMask():

    
    vertices = osg.Vec3Array()
    vertices.push_back(osg.Vec3(-0.5, -0.5, 0.0))
    vertices.push_back(osg.Vec3(0.5, -0.5, 0.0))
    vertices.push_back(osg.Vec3(0.5, 0.5, 0.0))
    vertices.push_back(osg.Vec3(-0.5, 0.5, 0.0))

    geom = osg.Geometry()
    geom.setVertexArray(vertices)
    geom.addPrimitiveSet(osg.DrawArrays(GL_QUADS, 0, 4))

    geode = osg.Geode()
    geode.addDrawable(geom)

    stencil = osg.Stencil()
    stencil.setFunction(osg.Stencil.ALWAYS, 1, ~0u)
    stencil.setOperation(osg.Stencil.KEEP, osg.Stencil.KEEP, osg.Stencil.REPLACE)

    ss = geode.getOrCreateStateSet()
    ss.setAttributeAndModes(stencil, 
        osg.StateAttribute.ON | osg.StateAttribute.OVERRIDE)
    ss.setAttribute(osg.ColorMask(False, False, False, False), 
        osg.StateAttribute.ON | osg.StateAttribute.OVERRIDE)

    return geode
Example #2
0
def createSquare(textureCoordMax):
    
    # set up the Geometry.
    geom = osg.Geometry()

    coords = osg.Vec3Array(4)
    (*coords)[0].set(-1.0,0.0,1.0)
    (*coords)[1].set(-1.0,0.0,-1.0)
    (*coords)[2].set(1.0,0.0,-1.0)
    (*coords)[3].set(1.0,0.0,1.0)
    geom.setVertexArray(coords)

    norms = osg.Vec3Array(1)
    (*norms)[0].set(0.0,-1.0,0.0)
    geom.setNormalArray(norms, osg.Array.BIND_OVERALL)

    tcoords = osg.Vec2Array(4)
    (*tcoords)[0].set(0.0,textureCoordMax)
    (*tcoords)[1].set(0.0,0.0)
    (*tcoords)[2].set(textureCoordMax,0.0)
    (*tcoords)[3].set(textureCoordMax,textureCoordMax)
    geom.setTexCoordArray(0,tcoords)

    geom.addPrimitiveSet(osg.DrawArrays(osg.PrimitiveSet.QUADS,0,4))

    return geom
def createTextureQuad(texture):

    
    vertices = osg.Vec3Array()
    vertices.push_back(osg.Vec3(-0.8, 0.0, -0.8))
    vertices.push_back(osg.Vec3(0.8, 0.0, -0.8))
    vertices.push_back(osg.Vec3(0.8, 0.0, 0.8))
    vertices.push_back(osg.Vec3(-0.8, 0.0, 0.8))

    texcoord = osg.Vec2Array()
    texcoord.push_back(osg.Vec2(0.0, 0.0))
    texcoord.push_back(osg.Vec2(1.0, 0.0))
    texcoord.push_back(osg.Vec2(1.0, 1.0))
    texcoord.push_back(osg.Vec2(0.0, 1.0))

    geom = osg.Geometry()
    geom.setVertexArray(vertices)
    geom.setTexCoordArray(0, texcoord)
    geom.addPrimitiveSet(osg.DrawArrays(GL_QUADS, 0, 4))

    geode = osg.Geode()
    geode.addDrawable(geom)
    geode.getOrCreateStateSet().setTextureAttributeAndModes(0, texture, osg.StateAttribute.ON)

    return geode
def createGeometry():
    
    geode = osg.Geode()

    # create Geometry
    geom = osg.Geometry(osg.Geometry())

    # add vertices using MyArray class
    numVertices = sizeof(myVertices)/sizeof(myVertices[0])
    geom.setVertexArray(MyArray(numVertices,const_cast<osg.Vec3*>(myVertices[0])))

    # add normals
    numNormals = sizeof(myNormals)/sizeof(myNormals[0])
    geom.setNormalArray(osg.Vec3Array(numNormals,const_cast<osg.Vec3*>(myNormals[0])), osg.Array.BIND_PER_VERTEX)

    # add colors
    numColors = sizeof(myColors)/sizeof(myColors[0])
    normal_array = osg.Vec4Array(numColors,const_cast<osg.Vec4*>(myColors[0]))
    geom.setColorArray(normal_array, osg.Array.BIND_PER_VERTEX)

    # add PrimitiveSet
    geom.addPrimitiveSet(osg.DrawArrays(osg.PrimitiveSet.QUADS, 0, numVertices))

    # Changing these flags will tickle different cases in
    # Geometry.drawImplementation. They should all work fine
    # with the shared array.
    geom.setUseVertexBufferObjects(False)
    geom.setUseDisplayList(False)

    geode.addDrawable( geom )

    return geode
Example #5
0
def createTexturedQuadGeometry(corner, widthVec, heightVec, l, b, r, t):
    g = osg.Geometry()

    # Create vertex array
    vertices = osg.Vec3Array()
    vertices.append(corner + widthVec)
    vertices.append(corner)
    vertices.append(corner + heightVec)
    vertices.append(corner + widthVec + heightVec)
    g.setVertexArray(vertices)

    # Create texcoord array
    texcoords = osg.Vec2Array()
    texcoords.append(osg.Vec2f(l, t))
    texcoords.append(osg.Vec2f(l, b))
    texcoords.append(osg.Vec2f(r, b))
    texcoords.append(osg.Vec2f(r, t))
    g.setTexCoordArray(0, texcoords)

    # Create color array (single value, white)
    colors = osg.Vec4Array()
    colors.append(osg.Vec4f(1, 1, 1, 1))
    g.setColorArray(colors)
    g.colorBinding = osg.Geometry.BIND_OVERALL

    # Create normal array (single value for all vertices)
    normals = osg.Vec3Array()
    normals.append(osg.Vec3f(0, -1, 0))
    g.setNormalArray(normals)
    g.normalBinding = osg.Geometry.BIND_OVERALL

    # Add primitive set
    g.addPrimitiveSet(osg.DrawArrays(osg.PrimitiveSet.QUADS, 0, 4))

    return g
Example #6
0
def createMirrorSurface(xMin, xMax, yMin, yMax, z):


    

    # set up the drawstate.

    # set up the Geometry.
    geom = osg.Geometry()

    coords = osg.Vec3Array(4)
    (*coords)[0].set(xMin,yMax,z)
    (*coords)[1].set(xMin,yMin,z)
    (*coords)[2].set(xMax,yMin,z)
    (*coords)[3].set(xMax,yMax,z)
    geom.setVertexArray(coords)

    norms = osg.Vec3Array(1)
    (*norms)[0].set(0.0,0.0,1.0)
    geom.setNormalArray(norms, osg.Array.BIND_OVERALL)

    tcoords = osg.Vec2Array(4)
    (*tcoords)[0].set(0.0,1.0)
    (*tcoords)[1].set(0.0,0.0)
    (*tcoords)[2].set(1.0,0.0)
    (*tcoords)[3].set(1.0,1.0)
    geom.setTexCoordArray(0,tcoords)

    colours = osg.Vec4Array(1)
    (*colours)[0].set(1.0,1.0,1.0,1.0)
    geom.setColorArray(colours, osg.Array.BIND_OVERALL)

    geom.addPrimitiveSet(osg.DrawArrays(osg.PrimitiveSet.QUADS,0,4))

    return geom
Example #7
0
class SomePoints (osg.Geometry) :
    SomePoints()
        cAry = osg.Vec4Array()
        setColorArray( cAry, osg.Array.BIND_OVERALL )
        cAry.push_back( osg.Vec4(1,1,1,1) )

        vAry = osg.Vec3Array()
        setVertexArray( vAry )
        vAry.push_back( osg.Vec3(0,0,0) )
        vAry.push_back( osg.Vec3(0,1,0) )
        vAry.push_back( osg.Vec3(1,0,0) )
        vAry.push_back( osg.Vec3(1,1,0) )
        vAry.push_back( osg.Vec3(0,0,1) )
        vAry.push_back( osg.Vec3(0,1,1) )
        vAry.push_back( osg.Vec3(1,0,1) )
        vAry.push_back( osg.Vec3(1,1,1) )

        addPrimitiveSet( osg.DrawArrays( GL_POINTS, 0, vAry.size() ) )

        sset = getOrCreateStateSet()
        sset.setMode( GL_LIGHTING, osg.StateAttribute.OFF )

        # if things go wrong, fall back to big points
        p = osg.Point()
        p.setSize(6)
        sset.setAttribute( p )

#ifdef ENABLE_GLSL
        sset.setAttribute( createShader() )

        # a generic cyclic animation value
        u_anim1 = osg.Uniform*( osg.Uniform( "u_anim1", 0.0 ) )
        u_anim1.setUpdateCallback( SineAnimation( 4, 0.5, 0.5 ) )
        sset.addUniform( u_anim1 )
def createAxis():

    
    geode = osg.Geode(osg.Geode())
    geometry = osg.Geometry(osg.Geometry())

    vertices = osg.Vec3Array(osg.Vec3Array())
    vertices.push_back (osg.Vec3 ( 0.0, 0.0, 0.0))
    vertices.push_back (osg.Vec3 ( 10.0, 0.0, 0.0))
    vertices.push_back (osg.Vec3 ( 0.0, 0.0, 0.0))
    vertices.push_back (osg.Vec3 ( 0.0, 10.0, 0.0))
    vertices.push_back (osg.Vec3 ( 0.0, 0.0, 0.0))
    vertices.push_back (osg.Vec3 ( 0.0, 0.0, 10.0))
    geometry.setVertexArray (vertices)

    colors = osg.Vec4Array(osg.Vec4Array())
    colors.push_back (osg.Vec4 (1.0, 0.0, 0.0, 1.0))
    colors.push_back (osg.Vec4 (1.0, 0.0, 0.0, 1.0))
    colors.push_back (osg.Vec4 (0.0, 1.0, 0.0, 1.0))
    colors.push_back (osg.Vec4 (0.0, 1.0, 0.0, 1.0))
    colors.push_back (osg.Vec4 (0.0, 0.0, 1.0, 1.0))
    colors.push_back (osg.Vec4 (0.0, 0.0, 1.0, 1.0))
    geometry.setColorArray (colors, osg.Array.BIND_PER_VERTEX)
    geometry.addPrimitiveSet(osg.DrawArrays(osg.PrimitiveSet.LINES,0,6))

    geode.addDrawable( geometry )
    geode.getOrCreateStateSet().setMode(GL_LIGHTING, False)
    return geode
Example #9
0
def createMirrorSurface(xMin,xMax,yMin,yMax,z):
    #// set up the drawstate.

    #// set up the Geometry.
    geom = osg.Geometry();

    coords = osg.Vec3Array();
    coords.append(osg.Vec3f(xMin,yMax,z))
    coords.append(osg.Vec3f(xMin,yMin,z))
    coords.append(osg.Vec3f(xMax,yMin,z))
    coords.append(osg.Vec3f(xMax,yMax,z))
    geom.setVertexArray(coords);

    norms = osg.Vec3Array();
    norms.append(osg.Vec3f(0.0,0.0,1.0))
    geom.setNormalArray(norms);
    geom.normalBinding = osg.Geometry.BIND_OVERALL

    tcoords = osg.Vec2Array()
    tcoords.append(osg.Vec2f(0.0,1.0))
    tcoords.append(osg.Vec2f(0.0,0.0))
    tcoords.append(osg.Vec2f(1.0,0.0))
    tcoords.append(osg.Vec2f(1.0,1.0))
    geom.setTexCoordArray(0,tcoords);

    colours = osg.Vec4Array();
    colours.append(osg.Vec4f(1.0,1.0,1.0,1.0))
    geom.setColorArray(colours);
    geom.colorBinding = osg.Geometry.BIND_OVERALL;

    geom.addPrimitiveSet(osg.DrawArrays(osg.PrimitiveSet.QUADS,0,4));

    return geom;
def createGeometry():

    
    vertices = osg.Vec3Array()
    vertices.push_back(osg.Vec3(-1.0, -1.0, 0.0))
    vertices.push_back(osg.Vec3(1.0, -1.0, 0.0))
    vertices.push_back(osg.Vec3(1.0, 1.0, 0.0))
    vertices.push_back(osg.Vec3(-1.0, 1.0, 0.0))

    geom = osg.Geometry()
    geom.setVertexArray(vertices)
    geom.addPrimitiveSet(osg.DrawArrays(GL_QUADS, 0, 4))

    geode = osg.Geode()
    geode.addDrawable(geom)

    stencil = osg.Stencil()
    stencil.setFunction(osg.Stencil.NOTEQUAL, 1, ~0u)
    stencil.setOperation(osg.Stencil.KEEP, osg.Stencil.KEEP, osg.Stencil.KEEP)

    ss = geode.getOrCreateStateSet()
    ss.setAttributeAndModes(stencil,
        osg.StateAttribute.ON | osg.StateAttribute.OVERRIDE)

    return geode
Example #11
0
def createSquare(corner, width, height, image):
    
    # set up the Geometry.
    geom = osg.Geometry()

    coords = osg.Vec3Array(4)
    (*coords)[0] = corner
    (*coords)[1] = corner+width
    (*coords)[2] = corner+width+height
    (*coords)[3] = corner+height


    geom.setVertexArray(coords)

    norms = osg.Vec3Array(1)
    (*norms)[0] = width^height
    (*norms)[0].normalize()

    geom.setNormalArray(norms, osg.Array.BIND_OVERALL)

    tcoords = osg.Vec2Array(4)
    (*tcoords)[0].set(0.0,0.0)
    (*tcoords)[1].set(1.0,0.0)
    (*tcoords)[2].set(1.0,1.0)
    (*tcoords)[3].set(0.0,1.0)
    geom.setTexCoordArray(0,tcoords)

    colours = osg.Vec4Array(1)
    (*colours)[0].set(1.0,1.0,1.0,1.0)
    geom.setColorArray(colours, osg.Array.BIND_OVERALL)


    geom.addPrimitiveSet(osg.DrawArrays(osg.PrimitiveSet.QUADS,0,4))

    if image :
        stateset = osg.StateSet()
        texture = osg.Texture2D()
        texture.setImage(image)
        stateset.setTextureAttributeAndModes(0,texture,osg.StateAttribute.ON)
        stateset.setMode(GL_LIGHTING, osg.StateAttribute.OFF)
        stateset.setMode(GL_BLEND, osg.StateAttribute.ON)
        stateset.setRenderingHint(osg.StateSet.TRANSPARENT_BIN)
        geom.setStateSet(stateset)

    return geom
Example #12
0
def createDAIGeometry(geom, nInstances):

    
    halfDimX =  float( .5 )
    halfDimZ =  float( .5 )

    v = osg.Vec3Array()
    v.resize( 4 )
    geom.setVertexArray( v )

    # Geometry for a single quad.
    (*v)[ 0 ] = osg.Vec3( -halfDimX, 0., -halfDimZ )
    (*v)[ 1 ] = osg.Vec3( halfDimX, 0., -halfDimZ )
    (*v)[ 2 ] = osg.Vec3( halfDimX, 0., halfDimZ )
    (*v)[ 3 ] = osg.Vec3( -halfDimX, 0., halfDimZ )

    # Use the DrawArraysInstanced PrimitiveSet and tell it to draw 1024 instances.
    geom.addPrimitiveSet( osg.DrawArrays( GL_QUADS, 0, 4, nInstances ) )
def createEaseMotionGeometry(motion):

    
    geom = osg.Geometry()
    cols = osg.Vec4Array()
    v = osg.Vec3Array()

    for(float i = 0.0 i < M_DURATION i += M_DURATION / 256.0) v.push_back(
        osg.Vec3(i * 30.0, motion.getValueAt(i) * 30.0, 0.0)
        )

    cols.push_back(osg.Vec4(1.0, 1.0, 1.0, 1.0))

    geom.setUseDisplayList(False)
    geom.setVertexArray(v)
    geom.setColorArray(cols, osg.Array.BIND_OVERALL)
    geom.addPrimitiveSet(osg.DrawArrays(osg.PrimitiveSet.LINE_STRIP, 0, v.size()))

    return geom
Example #14
0
def createAxis(corner, xdir, ydir, zdir):

    
    # set up the Geometry.
    geom = osg.Geometry()

    coords = osg.Vec3Array(6)
    (*coords)[0] = corner
    (*coords)[1] = corner+xdir
    (*coords)[2] = corner
    (*coords)[3] = corner+ydir
    (*coords)[4] = corner
    (*coords)[5] = corner+zdir

    geom.setVertexArray(coords)

    x_color = osg.Vec4(0.0,1.0,1.0,1.0)
    y_color = osg.Vec4(0.0,1.0,1.0,1.0)
    z_color = osg.Vec4(1.0,0.0,0.0,1.0)

    color = osg.Vec4Array(6)
    (*color)[0] = x_color
    (*color)[1] = x_color
    (*color)[2] = y_color
    (*color)[3] = y_color
    (*color)[4] = z_color
    (*color)[5] = z_color

    geom.setColorArray(color, osg.Array.BIND_PER_VERTEX)

    geom.addPrimitiveSet(osg.DrawArrays(osg.PrimitiveSet.LINES,0,6))

    stateset = osg.StateSet()
    linewidth = osg.LineWidth()
    linewidth.setWidth(4.0)
    stateset.setAttributeAndModes(linewidth,osg.StateAttribute.ON)
    stateset.setMode(GL_LIGHTING,osg.StateAttribute.OFF)
    geom.setStateSet(stateset)

    return geom
Example #15
0
def createAxis(s, e, numReps, autoRotateMode, axisAlignment, str):

    
    group = osg.Group()

    dv = e-s
    dv /= float(numReps-1)

    pos = s

    useAuto = True
    if useAuto :
        vertices = osg.Vec3Array()

        for(int i=0i<numReps++i)
            at = osg.AutoTransform()
            at.setPosition(pos)
            at.setAutoRotateMode(autoRotateMode)
            at.addChild(createLabel(osg.Vec3(0.0,0.0,0.0),dv.length()*0.2,str, axisAlignment))
            vertices.push_back(pos)
            pos += dv


            group.addChild(at)

        colors = osg.Vec4Array()
        colors.push_back(osg.Vec4(1.0,1.0,1.0,1.0))

        geom = osg.Geometry()
        geom.setVertexArray(vertices)
        geom.setColorArray(colors, osg.Array.BIND_OVERALL)
        geom.addPrimitiveSet(osg.DrawArrays(GL_LINE_STRIP,0,vertices.size()))

        geode = osg.Geode()
        geode.addDrawable(geom)

        group.addChild(geode)
Example #16
0
        # set the colors as before, plus using the above
        colors = osg.Vec4Array()
        colors.push_back(osg.Vec4(1.0,1.0,0.0,1.0))
        linesGeom.setColorArray(colors, osg.Array.BIND_OVERALL)


        # set the normal in the same way color.
        normals = osg.Vec3Array()
        normals.push_back(osg.Vec3(0.0,-1.0,0.0))
        linesGeom.setNormalArray(normals, osg.Array.BIND_OVERALL)


        # This time we simply use primitive, and hardwire the number of coords to use
        # since we know up front,
        linesGeom.addPrimitiveSet(osg.DrawArrays(osg.PrimitiveSet.LINE_LOOP,0,numCoords))


        # add the points geometry to the geode.
        geode.addDrawable(linesGeom)




    # now we'll stop creating separate normal and color arrays
    # since we are using the same values all the time, we'll just
    # share the same ColorArray and NormalArrays..

    # set the colors as before, use a ref_ptr rather than just
    # standard C pointer, as that in the case of it not being
    # assigned it will still be cleaned up automatically.
Example #17
0
def createScene():


    
    # create the Geode (Geometry Node) to contain all our osg.Geometry objects.
    geode = osg.Geode()

    # following are separate blocks for creating POINTS, LINES, LINE_STRIP, LINE_LOOP, POLYGON, QUADS,
    # QUAD_STRIP, TRIANGLES, TRIANGLE_STRIP and TRIANGLE_FAN primitives. An image of these primitives
    # is provided in the distribution: OpenSceneGraph-Data/Images/primitives.gif.


    # create POINTS
        # create Geometry object to store all the vertices and points primitive.
        pointsGeom = osg.Geometry()

        # create a Vec3Array and add to it all my coordinates.
        # Like all the *Array variants (see include/osg/Array) , Vec3Array is derived from both osg.Array
        # and std.vector<>.  osg.Array's are reference counted and hence sharable,
        # which std.vector<> provides all the convenience, flexibility and robustness
        # of the most popular of all STL containers.
        vertices = osg.Vec3Array()
        vertices.push_back(osg.Vec3(-1.02168, -2.15188e-09, 0.885735))
        vertices.push_back(osg.Vec3(-0.976368, -2.15188e-09, 0.832179))
        vertices.push_back(osg.Vec3(-0.873376, 9.18133e-09, 0.832179))
        vertices.push_back(osg.Vec3(-0.836299, -2.15188e-09, 0.885735))
        vertices.push_back(osg.Vec3(-0.790982, 9.18133e-09, 0.959889))

        # pass the created vertex array to the points geometry object.
        pointsGeom.setVertexArray(vertices)



        # create the color of the geometry, one single for the whole geometry.
        # for consistency of design even one single color must added as an element
        # in a color array.
        colors = osg.Vec4Array()
        # add a white color, colors take the form r,g,b,a with 0.0 off, 1.0 full on.
        colors.push_back(osg.Vec4(1.0,1.0,0.0,1.0))

        # pass the color array to points geometry, note the binding to tell the geometry
        # that only use one color for the whole object.
        pointsGeom.setColorArray(colors, osg.Array.BIND_OVERALL)


        # set the normal in the same way color.
        normals = osg.Vec3Array()
        normals.push_back(osg.Vec3(0.0,-1.0,0.0))
        pointsGeom.setNormalArray(normals, osg.Array.BIND_OVERALL)


        # create and add a DrawArray Primitive (see include/osg/Primitive).  The first
        # parameter passed to the DrawArrays constructor is the Primitive.Mode which
        # in this case is POINTS (which has the same value GL_POINTS), the second
        # parameter is the index position into the vertex array of the first point
        # to draw, and the third parameter is the number of points to draw.
        pointsGeom.addPrimitiveSet(osg.DrawArrays(osg.PrimitiveSet.POINTS,0,vertices.size()))


        # add the points geometry to the geode.
        geode.addDrawable(pointsGeom)

    # create LINES
        # create Geometry object to store all the vertices and lines primitive.
        linesGeom = osg.Geometry()

        # this time we'll preallocate the vertex array to the size we
        # need and then simple set them as array elements, 8 points
        # makes 4 line segments.
        vertices = osg.Vec3Array(8)
        (*vertices)[0].set(-1.13704, -2.15188e-09, 0.40373)
        (*vertices)[1].set(-0.856897, -2.15188e-09, 0.531441)
        (*vertices)[2].set(-0.889855, -2.15188e-09, 0.444927)
        (*vertices)[3].set(-0.568518, -2.15188e-09, 0.40373)
        (*vertices)[4].set(-1.00933, -2.15188e-09, 0.370773)
        (*vertices)[5].set(-0.716827, -2.15188e-09, 0.292498)
        (*vertices)[6].set(-1.07936, 9.18133e-09, 0.317217)
        (*vertices)[7].set(-0.700348, 9.18133e-09, 0.362533)


        # pass the created vertex array to the points geometry object.
        linesGeom.setVertexArray(vertices)

        # set the colors as before, plus using the above
        colors = osg.Vec4Array()
        colors.push_back(osg.Vec4(1.0,1.0,0.0,1.0))
        linesGeom.setColorArray(colors, osg.Array.BIND_OVERALL)


        # set the normal in the same way color.
        normals = osg.Vec3Array()
        normals.push_back(osg.Vec3(0.0,-1.0,0.0))
        linesGeom.setNormalArray(normals, osg.Array.BIND_OVERALL)


        # This time we simply use primitive, and hardwire the number of coords to use
        # since we know up front,
        linesGeom.addPrimitiveSet(osg.DrawArrays(osg.PrimitiveSet.LINES,0,8))


        # add the points geometry to the geode.
        geode.addDrawable(linesGeom)

    # create LINE_STRIP
        # create Geometry object to store all the vertices and lines primitive.
        linesGeom = osg.Geometry()

        # this time we'll preallocate the vertex array to the size
        # and then use an iterator to fill in the values, a bit perverse
        # but does demonstrate that we have just a standard std.vector underneath.
        vertices = osg.Vec3Array(5)
        vitr = vertices.begin()
        (vitr++).set(-0.0741545, -2.15188e-09, 0.416089)
        (vitr++).set(0.234823, -2.15188e-09, 0.259541)
        (vitr++).set(0.164788, -2.15188e-09, 0.366653)
        (vitr++).set(-0.0288379, -2.15188e-09, 0.333695)
        (vitr++).set(-0.0453167, -2.15188e-09, 0.280139)

        # pass the created vertex array to the points geometry object.
        linesGeom.setVertexArray(vertices)

        # set the colors as before, plus using the above
        colors = osg.Vec4Array()
        colors.push_back(osg.Vec4(1.0,1.0,0.0,1.0))
        linesGeom.setColorArray(colors, osg.Array.BIND_OVERALL)


        # set the normal in the same way color.
        normals = osg.Vec3Array()
        normals.push_back(osg.Vec3(0.0,-1.0,0.0))
        linesGeom.setNormalArray(normals, osg.Array.BIND_OVERALL)


        # This time we simply use primitive, and hardwire the number of coords to use
        # since we know up front,
        linesGeom.addPrimitiveSet(osg.DrawArrays(osg.PrimitiveSet.LINE_STRIP,0,5))


        # add the points geometry to the geode.
        geode.addDrawable(linesGeom)

    # create LINE_LOOP
        # create Geometry object to store all the vertices and lines primitive.
        linesGeom = osg.Geometry()

        # this time we'll a C arrays to initialize the vertices.

        osg.Vec3 myCoords[] =
            osg.Vec3(0.741546, -2.15188e-09, 0.453167),
            osg.Vec3(0.840418, -2.15188e-09, 0.304858),
            osg.Vec3(1.12468, -2.15188e-09, 0.300738),
            osg.Vec3(1.03816, 9.18133e-09, 0.453167),
            osg.Vec3(0.968129, -2.15188e-09, 0.337815),
            osg.Vec3(0.869256, -2.15188e-09, 0.531441)
Example #18
0
    min = -1.0
    max = 1.0
    j = 0
    i = 0
    for(i=0i<noStars++i,j+=2)
        (*vertices)[j].set(random(min,max),random(min,max),random(min,max))
        (*vertices)[j+1] = (*vertices)[j]+osg.Vec3(0.0,0.0,0.001)

    # set up colours
    colours = osg.Vec4Array(1)
    geometry.setColorArray(colours, osg.Array.BIND_OVERALL)
    (*colours)[0].set(1.0,1.0,1.0,1.0)

    # set up the primitive set to draw lines
    geometry.addPrimitiveSet(osg.DrawArrays(GL_LINES,0,noStars*2))

    # set up the points for the stars.
    points = osg.DrawElementsUShort(GL_POINTS,noStars)
    geometry.addPrimitiveSet(points)
    for(i=0i<noStars++i)
        (*points)[i] = i*2

    geometry.setUseDisplayList(False)
    geometry.setDrawCallback(DrawCallback)()

    geode = osg.Geode()
    geode.addDrawable(geometry)
    geode.getOrCreateStateSet().setMode(GL_LIGHTING,osg.StateAttribute.OFF)

    group = osg.Group()
Example #19
0
    (*normals)[6] = osg.Vec3( 0.0, 1.0,  0.0)
    (*normals)[7] = osg.Vec3( 0.0, 1.0,  0.0)
    (*normals)[8] = osg.Vec3(-1.0,  -0.0,  0.0)
    (*normals)[9] = osg.Vec3(-1.0,  -0.0,  0.0)
    (*normals)[10] = osg.Vec3( 0.0,  -0.928477, 0.371391)
    (*normals)[11] = osg.Vec3( 0.0, 0.928477, 0.371391)
    (*normals)[12] = osg.Vec3( 0.707107,  0.0, 0.707107)
    (*normals)[13] = osg.Vec3( 0.707107,  0.0, 0.707107)
    (*normals)[14] = osg.Vec3(-0.707107,  0.0, 0.707107)
    (*normals)[15] = osg.Vec3(-0.707107,  0.0, 0.707107)

    # coordIndices
    coordIndices = osg.UByteArray(48,indices)

    # share the primitive set.
    primitives = osg.DrawArrays(osg.PrimitiveSet.TRIANGLES,0,48)

    for (int q = 0 q < HOUSES_SIZE q++)
        xPos = ((static_cast<double> (rand()) /
                      static_cast<double> (RAND_MAX))
                     * 2.0 * XDim) - XDim

        yPos = ((static_cast<double> (rand()) /
                      static_cast<double> (RAND_MAX))
                     * 2 * ZDim) - ZDim

        scale = 10.0

        offset = osg.Vec3(xPos,yPos,0.0)

        # coords
Example #20
0
            texcoords.push_back(top_texcoord)
            texcoords.push_back(bottom_texcoord)
            top_texcoord+=dv_texcoord
            bottom_texcoord+=dv_texcoord


        # pass the created vertex array to the points geometry object.
        polyGeom.setVertexArray(vertices)

        polyGeom.setTexCoordArray(0,texcoords)

        colors = osg.Vec4Array()
        colors.push_back(osg.Vec4(1.0,1.0,1.0,1.0))
        polyGeom.setColorArray(colors, osg.Array.BIND_OVERALL)

        polyGeom.addPrimitiveSet(osg.DrawArrays(osg.PrimitiveSet.QUAD_STRIP,0,vertices.size()))

        # we need to add the texture to the Drawable, we do so by creating a
        # StateSet to contain the Texture StateAttribute.
        stateset = osg.StateSet()

        stateset.setTextureAttributeAndModes(0, texture,osg.StateAttribute.ON)

        polyGeom.setStateSet(stateset)

        polyGeom.setUpdateCallback(MyGeometryCallback(origin,xAxis,yAxis,zAxis,1.0,1.0/width,0.2))

        geode = osg.Geode()
        geode.addDrawable(polyGeom)

        parent.addChild(geode)
Example #21
0
        stateset.setMode(GL_DEPTH_TEST,osg.StateAttribute.OFF)
        name = "subOption"
        name += " "
        name += str(opts[i])
        geode.setName(name)
        vertices = osg.Vec3Array(4) # 1 quad
        colors = osg.Vec4Array()
        colors = osg.Vec4Array()
        colors.push_back(osg.Vec4(0.8-0.1*i,0.1*i,0.2*i, 1.0))
        quad.setColorArray(colors, osg.Array.BIND_OVERALL)
        (*vertices)[0]=position
        (*vertices)[1]=position+dx
        (*vertices)[2]=position+dx+dy
        (*vertices)[3]=position+dy
        quad.setVertexArray(vertices)
        quad.addPrimitiveSet(osg.DrawArrays(osg.PrimitiveSet.QUADS,0,4))
        geode.addDrawable(quad)
        hudCamera.addChild(geode)

        position += delta



     # this displays what has been selected
        geode = osg.Geode()
        stateset = geode.getOrCreateStateSet()
        stateset.setMode(GL_LIGHTING,osg.StateAttribute.OFF)
        stateset.setMode(GL_DEPTH_TEST,osg.StateAttribute.OFF)
        geode.setName("The text label")
        geode.addDrawable( updateText )
        hudCamera.addChild(geode)
Example #22
0
            depth = bb.zMin()-0.1
            vertices.push_back(osg.Vec3(bb.xMin(),bb.yMax(),depth))
            vertices.push_back(osg.Vec3(bb.xMin(),bb.yMin(),depth))
            vertices.push_back(osg.Vec3(bb.xMax(),bb.yMin(),depth))
            vertices.push_back(osg.Vec3(bb.xMax(),bb.yMax(),depth))
            geom.setVertexArray(vertices)

            normals = osg.Vec3Array()
            normals.push_back(osg.Vec3(0.0,0.0,1.0))
            geom.setNormalArray(normals, osg.Array.BIND_OVERALL)

            colors = osg.Vec4Array()
            colors.push_back(osg.Vec4(1.0,1.0,0.8,0.2))
            geom.setColorArray(colors, osg.Array.BIND_OVERALL)

            geom.addPrimitiveSet(osg.DrawArrays(GL_QUADS,0,4))

            stateset = geom.getOrCreateStateSet()
            stateset.setMode(GL_BLEND,osg.StateAttribute.ON)
            #stateset.setAttribute(osg.PolygonOffset(1.0,1.0),osg.StateAttribute.ON)
            stateset.setRenderingHint(osg.StateSet.TRANSPARENT_BIN)

            geode.addDrawable(geom)

        camera.addChild(geode)

    return camera

class SnapImage (osg.Camera.DrawCallback) :
SnapImage( str filename):
        _filename(filename),
Example #23
0
    vertices.push_back(nose)

    geom.setVertexArray(vertices)


    normals = osg.Vec3Array()
    normals.push_back(normal)
    geom.setNormalArray(normals, osg.Array.BIND_OVERALL)


    colors = osg.Vec4Array()
    colors.push_back(color)
    geom.setColorArray(colors, osg.Array.BIND_OVERALL)


    geom.addPrimitiveSet(osg.DrawArrays(GL_POLYGON,0,vertices.getNumElements()))

    tessellator = osgUtil.Tessellator()
    tessellator.retessellatePolygons(*geom)

    return geom


osg. Node* createTextBelow( osg.BoundingBox bb,  str label,  str)
    geode = osg.Geode()

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

    text = osgText.Text()

    text.setFont(font)
Example #24
0
class IntersectionUpdateCallback (osg.NodeCallback) :
virtual void operator()(osg.Node* #node, osg.NodeVisitor* nv)
            if  not root_  or   not terrain_  or   not ss_  or   not intersectionGroup_ :
                osg.notify(osg.NOTICE), "IntersectionUpdateCallback not set up correctly."
                return

            #traverse(node,nv)
            frameCount_++
            if frameCount_ > 200 :
                # first we need find the transformation matrix that takes
                # the terrain into the coordinate frame of the sphere segment.
                terrainLocalToWorld = osg.Matrixd()
                terrain_worldMatrices = terrain_.getWorldMatrices(root_)
                if terrain_worldMatrices.empty() : terrainLocalToWorld.makeIdentity()
                elif terrain_worldMatrices.size()==1 : terrainLocalToWorld = terrain_worldMatrices.front()
                else:
                    osg.notify(osg.NOTICE), "IntersectionUpdateCallback: warning cannot interestect with multiple terrain instances, just uses first one."
                    terrainLocalToWorld = terrain_worldMatrices.front()

                # sphere segment is easier as this callback is attached to the node, so the node visitor has the unique path to it already.
                ssWorldToLocal = osg.computeWorldToLocal(nv.getNodePath())

                # now we can compute the terrain to ss transform
                possie = terrainLocalToWorld*ssWorldToLocal

                lines = ss_.computeIntersection(possie, terrain_)
                if  not lines.empty() :
                    if intersectionGroup_.valid() :
                        # now we need to place the intersections which are in the SphereSegmenet's coordinate frame into
                        # to the final position.
                        mt = osg.MatrixTransform()
                        mt.setMatrix(osg.computeLocalToWorld(nv.getNodePath()))
                        intersectionGroup_.addChild(mt)

                        # print "matrix = ", mt.getMatrix()

                        geode = osg.Geode()
                        mt.addChild(geode)

                        geode.getOrCreateStateSet().setMode(GL_LIGHTING,osg.StateAttribute.OFF)

                        for(osgSim.SphereSegment.LineList.iterator itr=lines.begin()
                           not = lines.end()
                           ++itr)
                            geom = osg.Geometry()
                            geode.addDrawable(geom)

                            vertices = itr
                            geom.setVertexArray(vertices)
                            geom.addPrimitiveSet(osg.DrawArrays(GL_LINE_STRIP, 0, vertices.getNumElements()))
                else:
                       osg.notify(osg.NOTICE), "No intersections found"


                frameCount_ = 0
    root_ = osg.observer_ptr<osg.Group>()
    terrain_ = osg.observer_ptr<osg.Geode>()
    ss_ = osg.observer_ptr<osgSim.SphereSegment>()
    intersectionGroup_ = osg.observer_ptr<osg.Group>()
    frameCount_ = unsigned()


class RotateUpdateCallback (osg.NodeCallback) :
    RotateUpdateCallback()  i=0
        virtual void operator()(osg.Node* node, osg.NodeVisitor* nv)
            ss = dynamic_cast<osgSim.SphereSegment *>(node)
            if ss :
                ss.setArea(osg.Vec3(cos(i/(2*osg.PI)),sin(i/(2*osg.PI)),0), osg.PI_2, osg.PI_2)

                i += 0.1

    i = float()


def createMovingModel(center, radius, terrainGeode, root, createMovingRadar):

    
    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.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(-90.0),0.0,0.0,1.0))

        positioned.addChild(glider)

        xform = osg.PositionAttitudeTransform()
        xform.getOrCreateStateSet().setMode(GL_NORMALIZE, osg.StateAttribute.ON)
        xform.setUpdateCallback(osg.AnimationPathCallback(animationPath,0.0,1.0))
        xform.addChild(positioned)
        model.addChild(xform)

    if createMovingRadar :
        # The IntersectionUpdateCallback has to have a safe place to put all its generated geometry into,
        # and this group can't be in the parental chain of the callback otherwise we will end up invalidating
        # traversal iterators.
        intersectionGroup = osg.Group()
        root.addChild(intersectionGroup)

        xform = osg.PositionAttitudeTransform()
        xform.setUpdateCallback(osg.AnimationPathCallback(animationPath,0.0,1.0))

        ss = osgSim.SphereSegment(osg.Vec3d(0.0,0.0,0.0),
                                700.0, # radius
                                osg.DegreesToRadians(135.0),
                                osg.DegreesToRadians(240.0),
                                osg.DegreesToRadians(-60.0),
                                osg.DegreesToRadians(-40.0),
                                60)

        iuc = IntersectionUpdateCallback()
        iuc.frameCount_ = 0
        iuc.root_ = root
        iuc.terrain_ = terrainGeode
        iuc.ss_ = ss
        iuc.intersectionGroup_ = intersectionGroup
        ss.setUpdateCallback(iuc)
        ss.setAllColors(osg.Vec4(1.0,1.0,1.0,0.5))
        ss.setSideColor(osg.Vec4(0.5,1.0,1.0,0.1))
        xform.addChild(ss)
        model.addChild(xform)

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

        text = osgText.Text()
        size = radius/bs.radius()*0.3

        text.setPosition(bs.center())
        text.setText("Cessna")
        text.setAlignment(osgText.Text.CENTER_CENTER)
        text.setAxisAlignment(osgText.Text.SCREEN)
        text.setCharacterSize(40.0)
        text.setCharacterSizeMode(osgText.Text.OBJECT_COORDS)

        geode = osg.Geode()
        geode.addDrawable(text)

        lod = osg.LOD()
        lod.setRangeMode(osg.LOD.PIXEL_SIZE_ON_SCREEN)
        lod.setRadius(cessna.getBound().radius())
        lod.addChild(geode,0.0,100.0)
        lod.addChild(cessna,100.0,10000.0)


        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(lod)

        xform = osg.MatrixTransform()
        xform.setUpdateCallback(osg.AnimationPathCallback(animationPath,0.0,2.0))
        xform.addChild(positioned)

        model.addChild(xform)

    return model

def createOverlay(center, radius):

    
    group = osg.Group()

    # create a grid of lines.
        geom = osg.Geometry()

        num_rows = 10

        left = center+osg.Vec3(-radius,-radius,0.0)
        right = center+osg.Vec3(radius,-radius,0.0)
        delta_row = osg.Vec3(0.0,2.0*radius/float(num_rows-1),0.0)

        top = center+osg.Vec3(-radius,radius,0.0)
        bottom = center+osg.Vec3(-radius,-radius,0.0)
        delta_column = osg.Vec3(2.0*radius/float(num_rows-1),0.0,0.0)

        vertices = osg.Vec3Array()
        for(unsigned int i=0 i<num_rows ++i)
            vertices.push_back(left)
            vertices.push_back(right)
            left += delta_row
            right += delta_row

            vertices.push_back(top)
            vertices.push_back(bottom)
            top += delta_column
            bottom += delta_column

        geom.setVertexArray(vertices)

        color = *(osg.Vec4ubArray(1))
        color[0].set(0,0,0,255)
        geom.setColorArray(color, osg.Array.BIND_OVERALL)

        geom.addPrimitiveSet(osg.DrawArrays(GL_LINES,0,vertices.getNumElements()))

        geom.getOrCreateStateSet().setMode(GL_LIGHTING,osg.StateAttribute.OFF)

        geode = osg.Geode()
        geode.addDrawable(geom)
        group.addChild(geode)

    return group

def computeTerrainIntersection(subgraph, x, y):

    
    bs = subgraph.getBound()
    zMax = bs.center().z()+bs.radius()
    zMin = bs.center().z()-bs.radius()

    intersector = osgUtil.LineSegmentIntersector(osg.Vec3(x,y,zMin),osg.Vec3(x,y,zMax))

    iv = osgUtil.IntersectionVisitor(intersector)

    subgraph.accept(iv)

    if intersector.containsIntersections() :
        return intersector.getFirstIntersection().getWorldIntersectPoint()

    return osg.Vec3(x,y,0.0)


#######################################
# MAIN SCENE GRAPH BUILDING FUNCTION
#######################################

def build_world(root, testCase, useOverlay, technique):

    

    # create terrain
    terrainGeode = 0
        terrainGeode = osg.Geode()

        stateset = osg.StateSet()
        image = osgDB.readImageFile("Images/lz.rgb")
        if image :
            texture = osg.Texture2D()
            texture.setImage(image)
            stateset.setTextureAttributeAndModes(0,texture,osg.StateAttribute.ON)

        terrainGeode.setStateSet( stateset )


            numColumns = 38
            numRows = 39
            unsigned int r, c

            origin = osg.Vec3(0.0,0.0,0.0)
            size = osg.Vec3(1000.0,1000.0,250.0)

            geometry = osg.Geometry()

            v = *(osg.Vec3Array(numColumns*numRows))
            tc = *(osg.Vec2Array(numColumns*numRows))
            color = *(osg.Vec4ubArray(1))

            color[0].set(255,255,255,255)

            rowCoordDelta = size.y()/(float)(numRows-1)
            columnCoordDelta = size.x()/(float)(numColumns-1)

            rowTexDelta = 1.0/(float)(numRows-1)
            columnTexDelta = 1.0/(float)(numColumns-1)

            # compute z range of z values of grid data so we can scale it.
            min_z = FLT_MAX
            max_z = -FLT_MAX
            for(r=0r<numRows++r)
                for(c=0c<numColumns++c)
                    min_z = osg.minimum(min_z,vertex[r+c*numRows][2])
                    max_z = osg.maximum(max_z,vertex[r+c*numRows][2])

            scale_z = size.z()/(max_z-min_z)

            pos = origin
            tex = osg.Vec2(0.0,0.0)
            vi = 0
            for(r=0r<numRows++r)
                pos.x() = origin.x()
                tex.x() = 0.0
                for(c=0c<numColumns++c)
                    v[vi].set(pos.x(),pos.y(),pos.z()+(vertex[r+c*numRows][2]-min_z)*scale_z)
                    tc[vi] = tex
                    pos.x()+=columnCoordDelta
                    tex.x()+=columnTexDelta
                    ++vi
                pos.y() += rowCoordDelta
                tex.y() += rowTexDelta

            geometry.setVertexArray(v)
            geometry.setTexCoordArray(0, tc)
            geometry.setColorArray(color, osg.Array.BIND_OVERALL)

            for(r=0r<numRows-1++r)
                drawElements = *(osg.DrawElementsUShort(GL_QUAD_STRIP,2*numColumns))
                geometry.addPrimitiveSet(drawElements)
                ei = 0
                for(c=0c<numColumns++c)
                    drawElements[ei++] = (r+1)*numColumns+c
                    drawElements[ei++] = (r)*numColumns+c

            smoother = osgUtil.SmoothingVisitor()
            smoother.smooth(*geometry)

            terrainGeode.addDrawable(geometry)



    # create sphere segment
    ss = 0

        terrainToSS = osg.Matrix()

        switch(testCase)
            case(0):
                ss = osgSim.SphereSegment(
                                computeTerrainIntersection(terrainGeode,550.0,780.0), # center
                                510.0, # radius
                                osg.DegreesToRadians(135.0),
                                osg.DegreesToRadians(240.0),
                                osg.DegreesToRadians(-10.0),
                                osg.DegreesToRadians(30.0),
                                60)
                root.addChild(ss)
                break
            case(1):
                ss = osgSim.SphereSegment(
                                computeTerrainIntersection(terrainGeode,550.0,780.0), # center
                                510.0, # radius
                                osg.DegreesToRadians(45.0),
                                osg.DegreesToRadians(240.0),
                                osg.DegreesToRadians(-10.0),
                                osg.DegreesToRadians(30.0),
                                60)
                root.addChild(ss)
                break
            case(2):
                ss = osgSim.SphereSegment(
                                computeTerrainIntersection(terrainGeode,550.0,780.0), # center
                                510.0, # radius
                                osg.DegreesToRadians(5.0),
                                osg.DegreesToRadians(355.0),
                                osg.DegreesToRadians(-10.0),
                                osg.DegreesToRadians(30.0),
                                60)
                root.addChild(ss)
                break
            case(3):
                ss = osgSim.SphereSegment(
                                computeTerrainIntersection(terrainGeode,550.0,780.0), # center
                                510.0, # radius
                                osg.DegreesToRadians(0.0),
                                osg.DegreesToRadians(360.0),
                                osg.DegreesToRadians(-10.0),
                                osg.DegreesToRadians(30.0),
                                60)
                root.addChild(ss)
                break
            case(4):
                ss = osgSim.SphereSegment(osg.Vec3d(0.0,0.0,0.0),
                                700.0, # radius
                                osg.DegreesToRadians(135.0),
                                osg.DegreesToRadians(240.0),
                                osg.DegreesToRadians(-60.0),
                                osg.DegreesToRadians(-40.0),
                                60)

                mt = osg.MatrixTransform()

                mt.setMatrix(osg.Matrix(-0.851781, 0.156428, -0.5, 0,
                                          -0.180627, -0.983552, -6.93889e-18, 0,
                                          -0.491776, 0.0903136, 0.866025, 0,
                                          598.217, 481.957, 100, 1))
                mt.addChild(ss)

                terrainToSS.invert(mt.getMatrix())

                root.addChild(mt)
                break
            case(5):
                ss = osgSim.SphereSegment(osg.Vec3d(0.0,0.0,0.0),
                                700.0, # radius
                                osg.DegreesToRadians(35.0),
                                osg.DegreesToRadians(135.0),
                                osg.DegreesToRadians(-60.0),
                                osg.DegreesToRadians(-40.0),
                                60)

                mt = osg.MatrixTransform()

                mt.setMatrix(osg.Matrix(-0.851781, 0.156428, -0.5, 0,
                                          -0.180627, -0.983552, -6.93889e-18, 0,
                                          -0.491776, 0.0903136, 0.866025, 0,
                                          598.217, 481.957, 100, 1))
                mt.addChild(ss)

                terrainToSS.invert(mt.getMatrix())

                root.addChild(mt)
                break
            case(6):
                ss = osgSim.SphereSegment(osg.Vec3d(0.0,0.0,0.0),
                                700.0, # radius
                                osg.DegreesToRadians(-45.0),
                                osg.DegreesToRadians(45.0),
                                osg.DegreesToRadians(-60.0),
                                osg.DegreesToRadians(-40.0),
                                60)

                mt = osg.MatrixTransform()

                mt.setMatrix(osg.Matrix(-0.851781, 0.156428, -0.5, 0,
                                          -0.180627, -0.983552, -6.93889e-18, 0,
                                          -0.491776, 0.0903136, 0.866025, 0,
                                          598.217, 481.957, 100, 1))
                mt.addChild(ss)

                terrainToSS.invert(mt.getMatrix())

                root.addChild(mt)
                break
            case(7):
                ss = osgSim.SphereSegment(
                                computeTerrainIntersection(terrainGeode,550.0,780.0), # center
                                510.0, # radius
                                osg.DegreesToRadians(-240.0),
                                osg.DegreesToRadians(-135.0),
                                osg.DegreesToRadians(-10.0),
                                osg.DegreesToRadians(30.0),
                                60)
                ss.setUpdateCallback(RotateUpdateCallback())
                root.addChild(ss)
                break
        

        if ss.valid() :
            ss.setAllColors(osg.Vec4(1.0,1.0,1.0,0.5))
            ss.setSideColor(osg.Vec4(0.0,1.0,1.0,0.1))

            if  not ss.getParents().empty() :
                ss.getParent(0).addChild(ss.computeIntersectionSubgraph(terrainToSS, terrainGeode))



    if useOverlay :
        overlayNode = osgSim.OverlayNode(technique)
        overlayNode.getOrCreateStateSet().setTextureAttribute(1, osg.TexEnv(osg.TexEnv.DECAL))

        bs = terrainGeode.getBound()
        overlaySubgraph = createOverlay(bs.center(), bs.radius()*0.5)
        overlaySubgraph.addChild(ss)
        overlayNode.setOverlaySubgraph(overlaySubgraph)
        overlayNode.setOverlayTextureSizeHint(1024)
        overlayNode.setOverlayBaseHeight(0.0)
        overlayNode.addChild(terrainGeode)

        root.addChild(overlayNode)
    else:
      root.addChild(terrainGeode)

    # create particle effects
        position = computeTerrainIntersection(terrainGeode,100.0,100.0)

        explosion = osgParticle.ExplosionEffect(position, 10.0)
        smoke = osgParticle.SmokeEffect(position, 10.0)
        fire = osgParticle.FireEffect(position, 10.0)

        root.addChild(explosion)
        root.addChild(smoke)
        root.addChild(fire)

    # create particle effects
        position = computeTerrainIntersection(terrainGeode,200.0,100.0)

        explosion = osgParticle.ExplosionEffect(position, 1.0)
        smoke = osgParticle.SmokeEffect(position, 1.0)
        fire = osgParticle.FireEffect(position, 1.0)

        root.addChild(explosion)
        root.addChild(smoke)
        root.addChild(fire)


    createMovingRadar = True

    # create the moving models.
        root.addChild(createMovingModel(osg.Vec3(500.0,500.0,500.0),100.0, terrainGeode, root, createMovingRadar))


#######################################
# main()
#######################################


def main(argv):


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

    # set up the usage document, in case we need to print out how to use this program.
    arguments.getApplicationUsage().setDescription(arguments.getApplicationName()+" is the example which demonstrates use of particle systems.")
    arguments.getApplicationUsage().setCommandLineUsage(arguments.getApplicationName()+" [options] image_file_left_eye image_file_right_eye")
    arguments.getApplicationUsage().addCommandLineOption("-h or --help","Display this information")


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

    # if user request help write it out to cout.
    testCase = 0
    while arguments.read("-t", testCase) : 

    useOverlay = False
    technique = osgSim.OverlayNode.OBJECT_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY
    while arguments.read("--object") :  useOverlay = True technique = osgSim.OverlayNode.OBJECT_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY 
    while arguments.read("--ortho")  or  arguments.read("--orthographic") :  useOverlay = True technique = osgSim.OverlayNode.VIEW_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY 
    while arguments.read("--persp")  or  arguments.read("--perspective") :  useOverlay = True technique = osgSim.OverlayNode.VIEW_DEPENDENT_WITH_PERSPECTIVE_OVERLAY 


    # if user request help write it out to cout.
    if arguments.read("-h")  or  arguments.read("--help") :
        arguments.getApplicationUsage().write(std.cout)
        return 1

    # any option left unread are converted into errors to write out later.
    arguments.reportRemainingOptionsAsUnrecognized()

    # report any errors if they have occurred when parsing the program arguments.
    if arguments.errors() :
        arguments.writeErrorMessages(std.cout)
        return 1

    root = osg.Group()
    build_world(root, testCase, useOverlay, technique)

    # add a viewport to the viewer and attach the scene graph.
    viewer.setSceneData(root)

    return viewer.run()


if __name__ == "__main__":
    main(sys.argv)
Example #25
0
        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))

    # create marker for point light.
    marker = osg.Geometry()
    vertices = osg.Vec3Array()
    vertices.push_back(osg.Vec3(0.0,0.0,0.0))
    marker.setVertexArray(vertices)
    marker.addPrimitiveSet(osg.DrawArrays(GL_POINTS,0,1))

    stateset = osg.StateSet()
    point = osg.Point()
    point.setSize(4.0)
    stateset.setAttribute(point)

    marker.setStateSet(stateset)

    markerGeode = osg.Geode()
    markerGeode.addDrawable(marker)

    mt.addChild(lightS2)
    mt.addChild(markerGeode)

    lightGroup.addChild(mt)
Example #26
0
    c[0] = color

    t[0].set(0.0,0.0)
    t[1].set(1.0,0.0)
    t[2].set(1.0,1.0)
    t[3].set(0.0,1.0)

    geom = osg.Geometry()

    geom.setVertexArray( v )

    geom.setTexCoordArray( 0, t )

    geom.setColorArray( c, osg.Array.BIND_OVERALL )

    geom.addPrimitiveSet( osg.DrawArrays(osg.PrimitiveSet.QUADS,0,4) )

    return geom

osg.Geometry* ForestTechniqueManager.createOrthogonalQuads(  osg.Vec3 pos, float w, float h, osg.Vec4ub color )
    # set up the coords
    v = *(osg.Vec3Array(8))
    t = *(osg.Vec2Array(8))
    c = *(osg.Vec4ubArray(1))

    rotation = random(0.0,osg.PI/2.0)
    sw = sinf(rotation)*w*0.5
    cw = cosf(rotation)*w*0.5

    v[0].set(pos.x()-sw,pos.y()-cw,pos.z()+0.0)
    v[1].set(pos.x()+sw,pos.y()+cw,pos.z()+0.0)
    quad_coords = osg.Vec3Array() # vertex coords
    # counter-clockwise
    quad_coords.push_back(osg.Vec3d(0, 0, -1))
    quad_coords.push_back(osg.Vec3d(1, 0, -1))
    quad_coords.push_back(osg.Vec3d(1, 1, -1))
    quad_coords.push_back(osg.Vec3d(0, 1, -1))

    quad_tcoords = osg.Vec2Array() # texture coords
    quad_tcoords.push_back(osg.Vec2(0, 0))
    quad_tcoords.push_back(osg.Vec2(tex_width, 0))
    quad_tcoords.push_back(osg.Vec2(tex_width, tex_height))
    quad_tcoords.push_back(osg.Vec2(0, tex_height))

    quad_geom = osg.Geometry()
    quad_da = osg.DrawArrays(osg.PrimitiveSet.QUADS,0,4)

    quad_colors = osg.Vec4Array()
    quad_colors.push_back(osg.Vec4(1.0,1.0,1.0,1.0))

    quad_geom.setVertexArray(quad_coords)
    quad_geom.setTexCoordArray(0, quad_tcoords)
    quad_geom.addPrimitiveSet(quad_da)
    quad_geom.setColorArray(quad_colors, osg.Array.BIND_OVERALL)

    stateset = quad_geom.getOrCreateStateSet()
    stateset.setMode(GL_LIGHTING,osg.StateAttribute.OFF)

    stateset.addUniform(osg.Uniform("width", (int)tex_width))

    # Attach shader, glFragData is used to create data for multiple render targets
Example #28
0
    unitCircle = osg.Geometry()
      colours = osg.Vec4Array(1)
      (*colours)[0] = osg.Vec4d(1.0,1.0,1.0,1.0)
      unitCircle.setColorArray(colours, osg.Array.BIND_OVERALL)
      n_points = 1024
      coords = osg.Vec3Array(n_points)
      dx = 2.0*osg.PI/n_points
      double s,c
      for (unsigned int j=0 j<n_points ++j) 
    s = sin(dx*j)
    c = cos(dx*j)
    (*coords)[j].set(osg.Vec3d(c,s,0.0))
      unitCircle.setVertexArray(coords)
      unitCircle.getOrCreateStateSet().setMode(GL_LIGHTING,osg.StateAttribute.OFF)
      unitCircle.addPrimitiveSet(osg.DrawArrays(osg.PrimitiveSet.LINE_LOOP,0,n_points))

    axes = osg.Geometry()
      colours = osg.Vec4Array(1)
      (*colours)[0] = osg.Vec4d(1.0,0.0,0.0,1.0)
      axes.setColorArray(colours, osg.Array.BIND_OVERALL)
      coords = osg.Vec3Array(6)
      (*coords)[0].set(osg.Vec3d(0.0, 0.0, 0.0))
      (*coords)[1].set(osg.Vec3d(0.5, 0.0, 0.0))
      (*coords)[2].set(osg.Vec3d(0.0, 0.0, 0.0))
      (*coords)[3].set(osg.Vec3d(0.0, 0.5, 0.0))
      (*coords)[4].set(osg.Vec3d(0.0, 0.0, 0.0))
      (*coords)[5].set(osg.Vec3d(0.0, 0.0, 0.5))
      axes.setVertexArray(coords)
      axes.getOrCreateStateSet().setMode(GL_LIGHTING,osg.StateAttribute.OFF)
      axes.addPrimitiveSet(osg.DrawArrays(osg.PrimitiveSet.LINES,0,6))
Example #29
0
    c = osg.Vec4Array()
    geom.setColorArray( c )
    geom.setColorBinding( deprecated_osg.Geometry.BIND_OVERALL )
    c.push_back( osg.Vec4( 0., 1., 1., 1. ) )

    n = osg.Vec3Array()
    geom.setNormalArray( n )
    geom.setNormalBinding( deprecated_osg.Geometry.BIND_PER_PRIMITIVE )
    n.push_back( osg.Vec3( -1., 0., 0. ) )
    n.push_back( osg.Vec3( 1., 0., 0. ) )
    n.push_back( osg.Vec3( 0., 0., -1. ) )
    n.push_back( osg.Vec3( 0., 0., 1. ) )
    n.push_back( osg.Vec3( 0., 1., 0. ) )

    geom.addPrimitiveSet( osg.DrawArrays( GL_QUADS, 0, 20 ) )
    box.addDrawable( geom )

    return box

# Make a Geometry that renders slow intentionally.
# To make sure it renders slow, we do the following:
#  * Disable display lists
#  * Force glBegin/glEnd slow path
#  * Lots of vertices and color data per vertex
#  * No vertex sharing
#  * Draw the triangles as wireframe
def createRandomTriangles(num):
    
    tris = osg.Geode()
Example #30
0
        alpha = color.w() * 0.5
        black =  osg.Vec3(0, 0, 0)

        clr.push_back(osg.Vec4(black, 0))
        clr.push_back(osg.Vec4(black, 0))
        clr.push_back(osg.Vec4(black, alpha))
        clr.push_back(osg.Vec4(black, alpha))

        clr.push_back(osg.Vec4(black, alpha))
        clr.push_back(osg.Vec4(black, alpha))
        clr.push_back(osg.Vec4(black, 0))
        clr.push_back(osg.Vec4(black, 0))

    geo.setColorArray(clr, osg.Array.BIND_PER_VERTEX)

    geo.addPrimitiveSet(osg.DrawArrays(GL_QUADS, 0,  12 if (shadow) else  4))

    return geo.release()


# Translated from file 'Frame.h'

# -*-c++-*-
#*
#*  OpenSceneGraph example, osgfxbrowser.
#*
#*  Permission is hereby granted, free of charge, to any person obtaining a copy
#*  of this software and associated documentation files (the "Software"), to deal
#*  in the Software without restriction, including without limitation the rights
#*  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#*  copies of the Software, and to permit persons to whom the Software is