Exemplo n.º 1
0
def main():

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

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

    #need to use singlethreaded mode 
    viewer.setThreadingModel(viewer.SingleThreaded)
   
    # add the stats
    viewer.addEventHandler (osgViewer.StatsHandler())

    # add the record camera path handler
    viewer.addEventHandler(osgViewer.RecordCameraPathHandler())

    #add the threading handler
    viewer.addEventHandler(osgViewer.ThreadingHandler())

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

    tex_width = 1024;
    tex_height = 512;
    samples = 0;
    colorSamples = 0;

    renderImplementation = osg.Camera.FRAME_BUFFER_OBJECT

    useImage = False;
    useTextureRectangle = False;
    useHDR = False;

    # if not loaded assume no arguments passed in, try use default mode instead.
    loadedModel = osgDB.readNodeFile("cessna.osg")

    # create a transform to spin the model.
    loadedModelTransform = osg.MatrixTransform()
    loadedModelTransform.addChild(loadedModel)

    nc = osg.AnimationPathCallback(osg.Vec3d(loadedModelTransform.getBound().center()),osg.Vec3d(0.0,0.0,1.0),osg.inDegrees(45.0))
    loadedModelTransform.setUpdateCallback(nc);
    
    rootNode = osg.Group()
    rootNode.addChild(createPreRenderSubGraph(loadedModelTransform,\
                                                                            tex_width,tex_height, \
                                                                            renderImplementation, \
                                                                            useImage, useTextureRectangle, \
                                                                            useHDR, samples, colorSamples))
    
    osgDB.writeNodeFile(rootNode, "test.ive")

    # add model to the viewer.
    viewer.setSceneData( rootNode );
 
    viewer.run()
Exemplo n.º 2
0
 def write_tile(tile_name,node_tile,trasf,veg,out_dir,suffix):
     #write previous tile
     ##print "writing tile ",prev," num trees ",tile_tree_count
     for t in trasf.keys():
         ##trasf[t].removeChild(0)
         trasf[t].addChild(veg[t].get_geom())
     outfile = os.path.join(out_dir,os.path.splitext(tile_name)[0]+suffix)
     osgDB.writeNodeFile(node_tile,outfile)
     #devo fare unref, se no fa esplodere la memoria
     node_tile.unref()
Exemplo n.º 3
0
def createCrossQuadTree(width,height,rot,texbox,outfile ) :
    v=osg.Vec3Array(8)
    sw = math.sin(math.radians(rot)) * width * 0.5
    cw = math.cos(math.radians(rot)) * width * 0.5
    v[0].set(-sw,-cw,0.0)
    v[1].set( sw, cw,0.0)
    v[2].set( sw, cw,height) 
    v[3].set(-sw,-cw,height)

    v[4].set(-cw,sw,0.0);
    v[5].set(cw,-sw,0.0);
    v[6].set(cw,-sw,height) 
    v[7].set(-cw,sw,height)
    
    t=osg.Vec2Array(8)
    #TODO: finisci questo bene
    
    t[0].set(texbox[0],texbox[1])
    t[1].set(texbox[2],texbox[1])
    t[2].set(texbox[2],texbox[3])
    t[3].set(texbox[0],texbox[3])

    t[4].set(texbox[0],texbox[1])
    t[5].set(texbox[2],texbox[1])
    t[6].set(texbox[2],texbox[3])
    t[7].set(texbox[0],texbox[3])

    #p=osg.DrawArrays(osg.PrimitiveSet.QUADS,0,8)
    p=osg.DrawArrays()
    p.setMode(osg.PrimitiveSet.QUADS)
    p.setFirst(0)
    p.setCount(8)
   
    geoNode = osg.Geode()
    geom = osg.Geometry()
    geom.setDataVariance(osg.Object.STATIC)
    geom.setVertexArray(v)
    geom.setTexCoordArray(0,t)
    geom.addPrimitiveSet(p)
    
    dstate = osg.StateSet()
    blendFunc = osg.BlendFunc()
    dstate.setAttributeAndModes(blendFunc,osg.StateAttribute.ON)
    alphaFunc = osg.AlphaFunc()
    alphaFunc.setFunction(osg.AlphaFunc.GEQUAL,0.99)
    dstate.setAttributeAndModes(alphaFunc,osg.StateAttribute.ON)
    #equivalent of , taken from Gl.h##  dstate.setMode(GL_LIGHTING,osg.StateAttribute.ON)
    dstate.setMode(0x0B50,osg.StateAttribute.OFF)
    dstate.setRenderingHint(osg.StateSet.TRANSPARENT_BIN)
    geoNode.setStateSet(dstate)
    geoNode.addDrawable( geom )
    for pointer in [dstate, geom, alphaFunc,blendFunc,geoNode,p,t,v]:
        pointer.thisown = False
    print "scrivo -->",outfile
    osgDB.writeNodeFile(geoNode,outfile)
Exemplo n.º 4
0
    def SaveNode( self, node, name):
        
        name = name.replace('*','')
        filename = self.ive_path + name + self.ext

        if self.texture_inside_ive:
            osgDB.writeNodeFile( node, filename )
        else:
            osgDB.writeNodeFile_s( node, filename, "noTexturesInIVEFile useOriginalExternalReferences" )
            
        # delays memory leak alerts
        self.garbage.addChild(node)
Exemplo n.º 5
0
def write_top_group_texture(tex_file,root_file,outfile) :
    g = osg.Group()
    s = osg.StateSet()
    tex = osg.Texture2D() 
    tex.setWrap(osg.Texture2D.WRAP_S,osg.Texture2D.CLAMP)
    tex.setWrap(osg.Texture2D.WRAP_T,osg.Texture2D.CLAMP)
    image = osgDB.readImageFile(tex_file)
    tex.setImage(image)
    s.setTextureAttributeAndModes(0,tex,osg.StateAttribute.ON)
    tenv = osg.TexEnv()
    s.setTextureAttribute(0,tenv)
    g.setStateSet(s)
    p = osg.ProxyNode()
    p.setFileName(0,root_file)
    print "scrivo -->",outfile
    g.addChild(p)
    for pointer in [g,s,tex,image,tenv,p]:
        pointer.thisown = False
    osgDB.writeNodeFile(g,outfile)
Exemplo n.º 6
0
    def test_000_osgCamera(self):
        cam = osg.Camera()
        cam.setViewport(0,0,480,320) #tested
        cam.setClearColor(osg.Vec4f(0,1,45,0)) #tested
        cam.setClearMask(0x4030) #availability, test below
        #try:
        #    cam.setClearMask(0xfffffffff)
        #    self.fail('No overflow when setting extremely large clear mask')
        #except OverflowError:
        #    pass

        cam.setProjectionMatrixAsFrustum(-10,100,-20,10,0.0,100.0)
        mt = osg.Matrixd()
        cam.setReferenceFrame(osg.Camera.ABSOLUTE_RF) #tested
        cam.setViewMatrixAsLookAt(osg.Vec3d(),osg.Vec3d(),osg.Vec3d())
        cam.setRenderOrder(osg.Camera.POST_RENDER,0); #tested
        cam.setRenderTargetImplementation(osg.Camera.FRAME_BUFFER_OBJECT) #tested
        cam.setDefaultClearMask() #availability
        texture = osg.Texture2D()
        cam.attach(osg.Camera.COLOR_BUFFER, texture, 0, 0, False, 0, 0); #tested
        cam.addChild(osg.Geode()) #tested
        cam.setClearMask(0x4545) #tested
        #write scene graph to disc
        if os.path.exists('out.osg'):
            os.remove('out.osg')
        osgDB.writeNodeFile(cam, 'out.osg')
        #read in scene graph file in text and search for specified patterns
        t = TestFile('out.osg',self)
        re.DOTALL = True #whitespace pattern \s shall match newline, too
        self.assert_(t.shouldContain('.*FRAME_BUFFER_OBJECT.*'))
        self.assert_(t.shouldContain('referenceFrame ABSOLUTE'))
        self.assert_(t.shouldContain('renderOrder POST_RENDER'))
        self.assert_(not t.shouldContain('i am a string that should not appear' ))
        self.assert_(t.shouldContain('clearMask 0x4545'))
        self.assert_(t.shouldContain('bufferComponent COLOR_BUFFER'))
        self.assert_(t.shouldContain('clearColor 0 1 45 0'))
        self.assert_(t.shouldContain(r'x\s+0\s+y\s+0\s+width\s+480\s+height\s+320'))
        self.assert_(t.shouldContain('Geode'))
        if os.path.exists('out.osg'):
            os.remove('out.osg')
Exemplo n.º 7
0
def main(argv):
    # use an ArgumentParser object to manage the program arguments.
    viewer = osgViewer.Viewer()
#    viewer.setThreadingModel(osgViewer.Viewer.SingleThreaded)

    # read the scene from the list of file specified commandline args.
    loadedModel = osgDB.readNodeFile("cessna.osg")
    if loadedModel == None:
        raise Exception('Could not load model file (is OSG_FILE_PATH set and correct?)')

    # create a transform to spin the model.
    loadedModelTransform = osg.MatrixTransform()
    loadedModelTransform.addChild(loadedModel)

    print loadedModelTransform.getBound()._center
#todo:    nc = osg.AnimationPathCallback(loadedModelTransform.getBound()._center,osg.Vec3(0.0,0.0,1.0),osg.inDegrees(45.0));
#    loadedModelTransform.setUpdateCallback(nc)

    rootNode = osg.Group()
    rootNode.stateSet.dataVariance = osg.Object.DYNAMIC
    rootNode.addChild(createMirroredScene(loadedModelTransform))

    viewer.addEventHandler(osgViewer.HelpHandler())
    viewer.addEventHandler(osgViewer.StatsHandler())
    viewer.addEventHandler(osgGA.StateSetManipulator(rootNode.stateSet))
    viewer.setSceneData(rootNode)
    print "set scene data"

    #hint to tell viewer to request stencil buffer when setting up windows
    osg.DisplaySettings().setMinimumNumStencilBits(8)
#    osg.DisplaySettings.instance().setMinimumNumStencilBits(8);

    osgDB.writeNodeFile(rootNode, "test_reflect.osg");

    viewer.run() #we need run, because that sets up a trackballmanipulator and so we have the correct "look" into the scene.
    return 0
Exemplo n.º 8
0
def main():

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

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

    #need to use singlethreaded mode
    viewer.setThreadingModel(viewer.SingleThreaded)

    # add the stats
    viewer.addEventHandler(osgViewer.StatsHandler())

    # add the record camera path handler
    viewer.addEventHandler(osgViewer.RecordCameraPathHandler())

    #add the threading handler
    viewer.addEventHandler(osgViewer.ThreadingHandler())

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

    tex_width = 1024
    tex_height = 512
    samples = 0
    colorSamples = 0

    renderImplementation = osg.Camera.FRAME_BUFFER_OBJECT

    useImage = False
    useTextureRectangle = False
    useHDR = False

    # if not loaded assume no arguments passed in, try use default mode instead.
    loadedModel = osgDB.readNodeFile("cessna.osg")

    # create a transform to spin the model.
    loadedModelTransform = osg.MatrixTransform()
    loadedModelTransform.addChild(loadedModel)

    nc = osg.AnimationPathCallback(
        osg.Vec3d(loadedModelTransform.getBound().center()),
        osg.Vec3d(0.0, 0.0, 1.0), osg.inDegrees(45.0))
    loadedModelTransform.setUpdateCallback(nc)

    rootNode = osg.Group()
    rootNode.addChild(createPreRenderSubGraph(loadedModelTransform,\
                                                                            tex_width,tex_height, \
                                                                            renderImplementation, \
                                                                            useImage, useTextureRectangle, \
                                                                            useHDR, samples, colorSamples))

    osgDB.writeNodeFile(rootNode, "test.ive")

    # add model to the viewer.
    viewer.setSceneData(rootNode)

    viewer.run()
Exemplo n.º 9
0
 def write(self, outfile):
     print "inizio di write -->",outfile
     gg = self.get_geom()
     print "scrivo -->",outfile
     osgDB.writeNodeFile(gg,outfile)
Exemplo n.º 10
0
import osg
import osgDB

def replica(path,rx,ry,rz,scale=1.0):
    root=osg.Group()
    prox=osg.ProxyNode()
    prox.setFileName(0,path)
    tz=0.0
    while tz < rz[1]:
        ty=0.0
        while ty < ry[1]:
            tx=0.0
            while tx < rx[1]:
                t=osg.PositionAttitudeTransform()  
                t.setScale(osg.Vec3d(scale,scale,scale))  
                t.setPosition(osg.Vec3d(tx,ty,tz))
                t.addChild(prox)
                root.addChild(t)
                tx += rx[0]
            ty += ry[0]
        tz += rz[0]
    return root

osgDB.writeNodeFile(replica('pesante.osg',(0.2,1.0),(0.2,1.0),(0.2,1.0),0.1),'N:\\scuola\\models\\example_occlusion\\pesanti.osg')