예제 #1
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    
예제 #2
0
def createSpotLightDecoratorState(lightNum, textureUnit):

    
    stateset = osg.StateSet()
    
    stateset.setMode(GL_LIGHT0+lightNum, osg.StateAttribute.ON)

    centerColour = osg.Vec4(1.0,1.0,1.0,1.0)
    ambientColour = osg.Vec4(0.05,0.05,0.05,1.0) 

    # set up spot light texture
    texture = osg.Texture2D()
    texture.setImage(createSpotLightImage(centerColour, ambientColour, 64, 1.0))
    texture.setBorderColor(osg.Vec4(ambientColour))
    texture.setWrap(osg.Texture.WRAP_S,osg.Texture.CLAMP_TO_BORDER)
    texture.setWrap(osg.Texture.WRAP_T,osg.Texture.CLAMP_TO_BORDER)
    texture.setWrap(osg.Texture.WRAP_R,osg.Texture.CLAMP_TO_BORDER)
    
    stateset.setTextureAttributeAndModes(textureUnit, texture, osg.StateAttribute.ON)
    
    # set up tex gens
    stateset.setTextureMode(textureUnit, GL_TEXTURE_GEN_S, osg.StateAttribute.ON)
    stateset.setTextureMode(textureUnit, GL_TEXTURE_GEN_T, osg.StateAttribute.ON)
    stateset.setTextureMode(textureUnit, GL_TEXTURE_GEN_R, osg.StateAttribute.ON)
    stateset.setTextureMode(textureUnit, GL_TEXTURE_GEN_Q, osg.StateAttribute.ON)
    
    return stateset
예제 #3
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
예제 #4
0
def createScalarBar():

    
#if 1
    #ScalarsToColors* stc = ScalarsToColors(0.0,1.0)
    #ScalarBar* sb = ScalarBar(2,3,stc,"STC_ScalarBar")

    # Create a custom color set
    cs = std.vector<osg.Vec4>()
    cs.push_back(osg.Vec4(1.0,0.0,0.0,1.0))   # R
    cs.push_back(osg.Vec4(0.0,1.0,0.0,1.0))   # G
    cs.push_back(osg.Vec4(1.0,1.0,0.0,1.0))   # G
    cs.push_back(osg.Vec4(0.0,0.0,1.0,1.0))   # B
    cs.push_back(osg.Vec4(0.0,1.0,1.0,1.0))   # R


    cr = ColorRange(0.0,1.0,cs)
    sb = ScalarBar(20, 11, cr, "ScalarBar", ScalarBar.VERTICAL, 0.1, MyScalarPrinter)()
    sb.setScalarPrinter(MyScalarPrinter)()

    return sb
#else:
    sb = ScalarBar()
    tp = ScalarBar.TextProperties()
    tp._fontFile = "fonts/times.ttf"

    sb.setTextProperties(tp)

    return sb
예제 #5
0
def create1DTextureStateToDecorate(loadedModel):
    
    image = osg.Image()

    noPixels = 1024
    
    # allocate the image data, noPixels x 1 x 1 with 4 rgba floats - equivalent to a Vec4 not 
    image.allocateImage(noPixels,1,1,GL_RGBA,GL_FLOAT)
    image.setInternalTextureFormat(GL_RGBA)
    
    typedef std.vector<osg.Vec4> ColorBands
    colorbands = ColorBands()
    colorbands.push_back(osg.Vec4(0.0,0.0,0.0,1.0))
    colorbands.push_back(osg.Vec4(1.0,0.0,0.0,1.0))
    colorbands.push_back(osg.Vec4(1.0,1.0,0.0,1.0))
    colorbands.push_back(osg.Vec4(0.0,1.0,0.0,1.0))
    colorbands.push_back(osg.Vec4(0.0,1.0,1.0,1.0))
    colorbands.push_back(osg.Vec4(0.0,0.0,1.0,1.0))
    colorbands.push_back(osg.Vec4(1.0,0.0,1.0,1.0))
    colorbands.push_back(osg.Vec4(1.0,1.0,1.0,1.0))

    nobands = colorbands.size()
    delta = nobands/(float)noPixels
    pos = 0.0

    # fill in the image data.    
    dataPtr = (osg.Vec4*)image.data()
    for(int i=0i<noPixels++i,pos+=delta)
        #float p = floorf(pos)
        #float r = pos-p
        #osg.Vec4 color = colorbands[(int)p]*(1.0-r)
        #if p+1<colorbands.size() : color += colorbands[(int)p+1]*r
        color = colorbands[(int)pos]
        *dataPtr++ = color
예제 #6
0
def createAxis(previousJoint):

    
    height = 12.0
    radius = .5

    zmt = osg.MatrixTransform()

    previousJoint.addChild(zmt)
    zShape = osg.ShapeDrawable(osg.Cylinder(osg.Vec3(0.0,0.0,height/2),radius,height),hints)
    zCone = osg.ShapeDrawable(osg.Cone(osg.Vec3(0.0,0.0,1.0),radius+1.0,2.0),hints)

    zmtCone = osg.MatrixTransform()
    zgCone = osg.Geode()

    zmtCone.setMatrix( osg.Matrix.translate(0.0,0.0,height))
    previousJoint.addChild(zmtCone)

    zShape.setColor(osg.Vec4(0.0, 0.0, 1.0, 1.0))
    zCone.setColor(osg.Vec4(0.0, 0.0, 1.0, 1.0))
    z = osg.Geode()
    z.addDrawable(zShape)
    zgCone.addDrawable(zCone)
    zmtCone.addChild(zgCone)
    zmt.addChild(z)

    mt = osg.MatrixTransform()
    previousJoint.addChild(mt)

    xMatrix = osg.Matrix.rotate(-osg.PI_2, 0.0, 1.0, 0.0)
    mt.setMatrix(xMatrix)


    xShape = osg.ShapeDrawable(osg.Cylinder(osg.Vec3(0.0,0.0,height/2),radius,height),hints)
    xShape.setColor(osg.Vec4(1.0, 0.0, 0.0, 1.0))
    x = osg.Geode()
    x.addDrawable(xShape)
    mt.addChild(x)


    yMt = osg.MatrixTransform()
    previousJoint.addChild(yMt)
    yMatrix = osg.Matrix.rotate(osg.PI_2, 1.0, 0.0, 0.0)
    yMt.setMatrix(yMatrix)

    yShape = osg.ShapeDrawable(osg.Cylinder(osg.Vec3(0.0,0.0,height/2),radius,height),hints)
    yShape.setColor(osg.Vec4(0.0, 1.0, 0.0, 1.0))
    y = osg.Geode()
    y.addDrawable(yShape)
    yMt.addChild(y)
예제 #7
0
 def createTouchRepresentations(parent_group, num_objects):
     
     # create some geometry which is shown for every touch-point
     for(unsigned int i = 0 i  not = num_objects ++i) 
         ss = std.ostringstream()
         
         geode = osg.Geode()
         
         drawable = osg.ShapeDrawable(osg.Box(osg.Vec3(0,0,0), 100))
         drawable.setColor(osg.Vec4(0.5, 0.5, 0.5,1))
         geode.addDrawable(drawable)
         
         ss, "Touch ", i
         
         text = osgText.Text()
         geode.addDrawable( text )
         drawable.setDataVariance(osg.Object.DYNAMIC)
         _drawables.push_back(drawable)
         
         
         text.setFont("fonts/arial.ttf")
         text.setPosition(osg.Vec3(110,0,0))
         text.setText(ss.str())
         _texts.push_back(text)
         text.setDataVariance(osg.Object.DYNAMIC)
         
         
         
         mat = osg.MatrixTransform()
         mat.addChild(geode)
         mat.setNodeMask(0x0)
         
         _mats.push_back(mat)
         
         parent_group.addChild(mat)
예제 #8
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)
예제 #9
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 )
예제 #10
0
def buildEndEffector():

    
    mt = osg.MatrixTransform()
    m = osg.Matrix()
    length = 17.0
    m.makeTranslate(0,0,length/2)
    mt.setMatrix(m)
    geode_3 = osg.Geode()
    shape1 = osg.ShapeDrawable(osg.Box(osg.Vec3(-EndEffector, 0.0, 0.0), .5, 1.5, length), hints)
    shape2 = osg.ShapeDrawable(osg.Box(osg.Vec3( EndEffector, 0.0, 0.0), .5, 1.5, length), hints)
    shape1.setColor(osg.Vec4(0.8, 0.8, 0.4, 1.0))
    shape2.setColor(osg.Vec4(0.8, 0.8, 0.4, 1.0))
    geode_3.addDrawable(shape1)
    geode_3.addDrawable(shape2)
    mt.addChild(geode_3)
    return mt
예제 #11
0
def main(argv):

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

    # load the nodes from the commandline arguments.
    rootnode = osgDB.readNodeFiles(arguments)
    
    # if not loaded assume no arguments passed in, try use default mode instead.
    if  not rootnode : rootnode = osgDB.readNodeFile("cessnafire.osgt")
    
    if  not rootnode :
        osg.notify(osg.NOTICE), "Please specify a model filename on the command line."
        return 1
    
    image = osgDB.readImageFile("Images/reflect.rgb")
    if image :
        texture = osg.Texture2D()
        texture.setImage(image)

        texgen = osg.TexGen()
        texgen.setMode(osg.TexGen.SPHERE_MAP)

        texenv = osg.TexEnv()
        texenv.setMode(osg.TexEnv.BLEND)
        texenv.setColor(osg.Vec4(0.3,0.3,0.3,0.3))

        stateset = osg.StateSet()
        stateset.setTextureAttributeAndModes(1,texture,osg.StateAttribute.ON)
        stateset.setTextureAttributeAndModes(1,texgen,osg.StateAttribute.ON)
        stateset.setTextureAttribute(1,texenv)
        
        rootnode.setStateSet(stateset)
    else:
        osg.notify(osg.NOTICE), "unable to load reflect map, model will not be mutlitextured"

    # run optimization over the scene graph
    optimzer = osgUtil.Optimizer()
    optimzer.optimize(rootnode)
     
    # add a viewport to the viewer and attach the scene graph.
    viewer.setSceneData( rootnode )
    
    # create the windows and run the threads.
    viewer.realize()

    for(unsigned int contextID = 0 
        contextID<osg.DisplaySettings.instance().getMaxNumberOfGraphicsContexts()
        ++contextID)
        textExt = osg.Texture.getExtensions(contextID,False)
        if textExt :
            if  not textExt.isMultiTexturingSupported() :
                print "Warning: multi-texturing not supported by OpenGL drivers, unable to run application."
                return 1
    def update(t, w):

        
        if  not w : return
        _motion.update(t*_direction) 
        val = _motion.getValue()*0.5
        val += 0.5
        if val >= 1.0 :
            val = 1.0
        w.setColor(osg.Vec4(val, val, val, 1))
예제 #13
0
def main(argv):


    
    # Qt requires that we construct the global QApplication before creating any widgets.
    app = QApplication(argc, argv)

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

    useFrameLoopThread = False
    if arguments.read("--no-frame-thread") : useFrameLoopThread = False
    if arguments.read("--frame-thread") : useFrameLoopThread = True

    image = osgQt.QWebViewImage()

    if arguments.argc()>1 : image.navigateTo((arguments[1]))
    else image.navigateTo("http:#www.youtube.com/")

    hints = osgWidget.GeometryHints(osg.Vec3(0.0,0.0,0.0),
                                   osg.Vec3(1.0,0.0,0.0),
                                   osg.Vec3(0.0,0.0,1.0),
                                   osg.Vec4(1.0,1.0,1.0,1.0),
                                   osgWidget.GeometryHints.RESIZE_HEIGHT_TO_MAINTAINCE_ASPECT_RATIO)


    browser = osgWidget.Browser()
    browser.assign(image, hints)

    # image.focusBrowser(True)

    viewer = osgViewer.Viewer(arguments)
    viewer.setSceneData(browser)
    viewer.setCameraManipulator(osgGA.TrackballManipulator())
    viewer.addEventHandler(osgViewer.StatsHandler)()
    viewer.addEventHandler(osgViewer.WindowSizeHandler)()

    if useFrameLoopThread :
        # create a thread to run the viewer's frame loop
        viewerThread = ViewerFrameThread(viewer, True)
        viewerThread.startThread()

        # now start the standard Qt event loop, then exists when the viewerThead sends the QApplication.exit() signal.
        return QApplication.exec()

    else:
        # run the frame loop, interleaving Qt and the main OSG frame loop
        while  not viewer.done() :
            # process Qt events - this handles both events and paints the browser image
            QCoreApplication.processEvents(QEventLoop.AllEvents, 100)

            viewer.frame()

        return 0
예제 #14
0
def createScene():

    
    # Create the Earth, in blue
    earth_sd = osg.ShapeDrawable()
    earth_sphere = osg.Sphere()
    earth_sphere.setName("EarthSphere")
    earth_sphere.setRadius(r_earth)
    earth_sd.setShape(earth_sphere)
    earth_sd.setColor(osg.Vec4(0, 0, 1.0, 1.0))

    earth_geode = osg.Geode()
    earth_geode.setName("EarthGeode")
    earth_geode.addDrawable(earth_sd)

    # Create the Sun, in yellow
    sun_sd = osg.ShapeDrawable()
    sun_sphere = osg.Sphere()
    sun_sphere.setName("SunSphere")
    sun_sphere.setRadius(r_sun)
    sun_sd.setShape(sun_sphere)
    sun_sd.setColor(osg.Vec4(1.0, 0.0, 0.0, 1.0))

    sun_geode = osg.Geode()
    sun_geode.setName("SunGeode")
    sun_geode.addDrawable(sun_sd)

    # Move the sun behind the earth
    pat = osg.PositionAttitudeTransform()
    pat.setPosition(osg.Vec3d(0.0, AU, 0.0))
    pat.addChild(sun_geode)

    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) 
예제 #15
0
def makeFrustumFromCamera(camera):
    
    # Projection and ModelView matrices
    proj = osg.Matrixd()
    mv = osg.Matrixd()
    if camera :
        proj = camera.getProjectionMatrix()
        mv = camera.getViewMatrix()
    else:
        # Create some kind of reasonable default Projection matrix.
        proj.makePerspective( 30., 1., 1., 10. )
        # leave mv as identity

    # Get near and far from the Projection matrix.
    near = proj(3,2) / (proj(2,2)-1.0)
    far = proj(3,2) / (1.0+proj(2,2))

    # Get the sides of the near plane.
    nLeft = near * (proj(2,0)-1.0) / proj(0,0)
    nRight = near * (1.0+proj(2,0)) / proj(0,0)
    nTop = near * (1.0+proj(2,1)) / proj(1,1)
    nBottom = near * (proj(2,1)-1.0) / proj(1,1)

    # Get the sides of the far plane.
    fLeft = far * (proj(2,0)-1.0) / proj(0,0)
    fRight = far * (1.0+proj(2,0)) / proj(0,0)
    fTop = far * (1.0+proj(2,1)) / proj(1,1)
    fBottom = far * (proj(2,1)-1.0) / proj(1,1)

    # Our vertex array needs only 9 vertices: The origin, and the
    # eight corners of the near and far planes.
    v = osg.Vec3Array()
    v.resize( 9 )
    (*v)[0].set( 0., 0., 0. )
    (*v)[1].set( nLeft, nBottom, -near )
    (*v)[2].set( nRight, nBottom, -near )
    (*v)[3].set( nRight, nTop, -near )
    (*v)[4].set( nLeft, nTop, -near )
    (*v)[5].set( fLeft, fBottom, -far )
    (*v)[6].set( fRight, fBottom, -far )
    (*v)[7].set( fRight, fTop, -far )
    (*v)[8].set( fLeft, fTop, -far )

    geom = osg.Geometry()
    geom.setUseDisplayList( False )
    geom.setVertexArray( v )

    c = osg.Vec4Array()
    c.push_back( osg.Vec4( 1., 1., 1., 1. ) )
    geom.setColorArray( c, osg.Array.BIND_OVERALL )

    GLushort idxLines[8] = 
        0, 5, 0, 6, 0, 7, 0, 8 
예제 #16
0
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
예제 #17
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
예제 #18
0
def createBase(center, radius):
    numTilesX = 10
    numTilesY = 10
    width = 2*radius
    height = 2*radius
    v000 = center - osg.Vec3(width*0.5,height*0.5,0.0)
    dx = osg.Vec3(width/(float(numTilesX)),0.0,0.0)
    dy = osg.Vec3(0.0,height/(float(numTilesY)),0.0)
    # fill in vertices for grid, note numTilesX+1 * numTilesY+1...
    coords = osg.Vec3Array()
    for iy in range(numTilesY):
        for ix in range(numTilesX):
            coords.append(v000+dx*float(ix)+dy*float(iy))
    #Just two colours - black and white.
    colors = osg.Vec4Array()
    colors.append(osg.Vec4(1.0,1.0,1.0,1.0)) # white
    colors.append(osg.Vec4(0.0,0.0,0.0,1.0)) # black
    whitePrimitives = osg.DrawElementsUShort(osg.GL_QUADS)
    blackPrimitives = osg.DrawElementsUShort(osg.GL_QUADS)
    numIndicesPerRow = numTilesX+1
    for iy in range(numTilesY):
        for ix in range(numTilesX):
            primitives =  whitePrimitives if (((iy+ix)%2==0)) else  blackPrimitives
            primitives.append(ix    +(iy+1)*numIndicesPerRow)
            primitives.append(ix    +iy*numIndicesPerRow)
            primitives.append((ix+1)+iy*numIndicesPerRow)
            primitives.append((ix+1)+(iy+1)*numIndicesPerRow)
    # set up a single normal
    normals = osg.Vec3Array()
    normals.append(osg.Vec3(0.0,0.0,1.0))
    geom = osg.Geometry()
    geom.setVertexArray(coords)
    geom.setColorArray(colors, osg.Array.BIND_PER_PRIMITIVE_SET)
    geom.setNormalArray(normals, osg.Array.BIND_OVERALL)
    geom.addPrimitiveSet(whitePrimitives)
    geom.addPrimitiveSet(blackPrimitives)
    geode = osg.Geode()
    geode.addDrawable(geom)
    return geode
    def update(t, w):

        
        if  not w : return

        _motion.update(t / _fadeOutTime)

        val = _motion.getValue()

        if val >= 1.0 : 
            _motion.reset()
            _active = False

        w.setFontColor(osg.Vec4(0.0, 0.0, 0.0, (1.0 - val) * 0.7))
예제 #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))
예제 #21
0
def main(argv):
    arguments = osg.ArgumentParser(argv)
    viewer = osgViewer.Viewer(arguments)
    hints = osgWidget.GeometryHints(
        osg.Vec3(0.0, 0.0, 0.0), osg.Vec3(1.0, 0.0, 0.0),
        osg.Vec3(0.0, 0.0, 1.0), osg.Vec4(1.0, 1.0, 1.0, 1.0),
        osgWidget.GeometryHints.RESIZE_HEIGHT_TO_MAINTAINCE_ASPECT_RATIO)
    group = osg.Group()
    for i in range(len(argv)):
        if not arguments.isOption(i):
            pdfReader = osgWidget.PdfReader()
            if pdfReader.open(arguments[i], hints):
                group.addChild(pdfReader.get())
                hints.position.x += 1.1
    viewer.setSceneData(group)
    viewer.addEventHandler(osgViewer.StatsHandler())
    return viewer.run()
예제 #22
0
def create_specular_highlights(node):

    
    ss = node.getOrCreateStateSet()
    
    # create and setup the texture object
    tcm = osg.TextureCubeMap()
    tcm.setWrap(osg.Texture.WRAP_S, osg.Texture.CLAMP)
    tcm.setWrap(osg.Texture.WRAP_T, osg.Texture.CLAMP)
    tcm.setWrap(osg.Texture.WRAP_R, osg.Texture.CLAMP)
    tcm.setFilter(osg.Texture.MIN_FILTER, osg.Texture.LINEAR_MIPMAP_LINEAR)
    tcm.setFilter(osg.Texture.MAG_FILTER, osg.Texture.LINEAR)    

    # generate the six highlight map images (light direction = [1, 1, -1])
    mapgen = osgUtil.HighlightMapGenerator(
        osg.Vec3(1, 1, -1),            # light direction
        osg.Vec4(1, 0.9, 0.8, 1),    # light color
        8)                             # specular exponent
    
    mapgen.generateMap()

    # assign the six images to the texture object
    tcm.setImage(osg.TextureCubeMap.POSITIVE_X, mapgen.getImage(osg.TextureCubeMap.POSITIVE_X))
    tcm.setImage(osg.TextureCubeMap.NEGATIVE_X, mapgen.getImage(osg.TextureCubeMap.NEGATIVE_X))
    tcm.setImage(osg.TextureCubeMap.POSITIVE_Y, mapgen.getImage(osg.TextureCubeMap.POSITIVE_Y))
    tcm.setImage(osg.TextureCubeMap.NEGATIVE_Y, mapgen.getImage(osg.TextureCubeMap.NEGATIVE_Y))
    tcm.setImage(osg.TextureCubeMap.POSITIVE_Z, mapgen.getImage(osg.TextureCubeMap.POSITIVE_Z))
    tcm.setImage(osg.TextureCubeMap.NEGATIVE_Z, mapgen.getImage(osg.TextureCubeMap.NEGATIVE_Z))

    # enable texturing, replacing any textures in the subgraphs
    ss.setTextureAttributeAndModes(0, tcm, osg.StateAttribute.OVERRIDE | osg.StateAttribute.ON)

    # texture coordinate generation
    tg = osg.TexGen()
    tg.setMode(osg.TexGen.REFLECTION_MAP)
    ss.setTextureAttributeAndModes(0, tg, osg.StateAttribute.OVERRIDE | osg.StateAttribute.ON)

    # use TexEnvCombine to add the highlights to the original lighting
    te = osg.TexEnvCombine()    
    te.setCombine_RGB(osg.TexEnvCombine.ADD)
    te.setSource0_RGB(osg.TexEnvCombine.TEXTURE)
    te.setOperand0_RGB(osg.TexEnvCombine.SRC_COLOR)
    te.setSource1_RGB(osg.TexEnvCombine.PRIMARY_COLOR)
    te.setOperand1_RGB(osg.TexEnvCombine.SRC_COLOR)
    ss.setTextureAttributeAndModes(0, te, osg.StateAttribute.OVERRIDE | osg.StateAttribute.ON)
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
예제 #24
0
def main(argv):


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


    # read the scene from the list of file specified commandline args.
    scene = osgDB.readNodeFiles(arguments)
    
    # if not loaded assume no arguments passed in, try use default model instead.
    if  not scene : scene = osgDB.readNodeFile("dumptruck.osgt")
    
    if  not scene : 
            geode = osg.Geode()
            drawable = osg.ShapeDrawable(osg.Box(osg.Vec3(0,0,0), 100))
            drawable.setColor(osg.Vec4(0.5, 0.5, 0.5,1))
            geode.addDrawable(drawable)
            scene = geode


    # construct the viewer.
    viewer = osgViewer.Viewer()
    
    
    group = osg.Group()

    # add the HUD subgraph.    
    if scene.valid() : group.addChild(scene)
    
    viewer.setCameraManipulator(osgGA.MultiTouchTrackballManipulator())
    viewer.realize()
    
    gc = viewer.getCamera().getGraphicsContext()
    
    #ifdef __APPLE__
        # as multitouch is disabled by default, enable it now
        win = dynamic_cast<osgViewer.GraphicsWindowCocoa*>(gc)
        if win : win.setMultiTouchEnabled(True)
예제 #25
0
def setupStateSet():

    
    st = osg.StateSet()
    st.setAttributeAndModes(osg.Material, True)()
    st.setMode(GL_BLEND, True)
    callback = AnimtkStateSetUpdateCallback()
    keys = callback._sampler.getOrCreateKeyframeContainer()
    keys.push_back(osgAnimation.Vec4Keyframe(0, osg.Vec4(0,0,0,0)))
    keys.push_back(osgAnimation.Vec4Keyframe(2, osg.Vec4(0.5,0,0,0.5)))
    keys.push_back(osgAnimation.Vec4Keyframe(4, osg.Vec4(0,0.5,0,1)))
    keys.push_back(osgAnimation.Vec4Keyframe(6, osg.Vec4(0,0,0.5,1)))
    keys.push_back(osgAnimation.Vec4Keyframe(8, osg.Vec4(1,1,1,0.5)))
    keys.push_back(osgAnimation.Vec4Keyframe(10, osg.Vec4(0,0,0,0)))
    callback.start()
    st.setUpdateCallback(callback)
    return st
예제 #26
0
def createLabel(l, f, size):

    
    static osg.Vec3 pos(10.0, 10.0, 0.0)

    label = osgText.Text()
    font = osgText.readFontFile(f)

    label.setFont(font)
    label.setCharacterSize(size)
    label.setFontResolution(size, size)
    label.setColor(osg.Vec4(1.0, 1.0, 1.0, 1.0))
    label.setPosition(pos)
    label.setAlignment(osgText.Text.LEFT_BOTTOM)

    # It seems to be important we do this last to get best results?
    label.setText(l)

    textInfo(label)

    pos.y() += size + 10.0

    return label
예제 #27
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)
예제 #28
0
def createHUD(updateText):

        # create the hud. derived from osgHud.cpp
    # adds a set of quads, each in a separate Geode - which can be picked individually
    # eg to be used as a menuing/help system not 
    # Can pick texts too not 
    modelview_abs = osg.MatrixTransform()
    modelview_abs.setReferenceFrame(osg.Transform.ABSOLUTE_RF)
    modelview_abs.setMatrix(osg.Matrix.identity())
    
    projection = osg.Projection()
    projection.setMatrix(osg.Matrix.ortho2D(0,1280,0,1024))
    projection.addChild(modelview_abs)
    
    
    timesFont = str("fonts/times.ttf")
    
    # turn lighting off for the text and disable depth test to ensure its always ontop.
    position = osg.Vec3(50.0,510.0,0.0)
    delta = osg.Vec3(0.0,-60.0,0.0)

     # 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 )
        modelview_abs.addChild(geode)
        
        updateText.setCharacterSize(20.0)
        updateText.setFont(timesFont)
        updateText.setColor(osg.Vec4(1.0,1.0,0.0,1.0))
        updateText.setText("")
        updateText.setPosition(position)
        
        position += delta
예제 #29
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)
예제 #30
0
            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)
        

        numCoords = sizeof(myCoords)/sizeof(osg.Vec3)

        vertices = osg.Vec3Array(numCoords,myCoords)

        # 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_LOOP,0,numCoords))


        # add the points geometry to the geode.