Esempio n. 1
0
	def __init__(self,parent,id,x,y,width,height):
		style = wx.WANTS_CHARS | wx.FULL_REPAINT_ON_RESIZE
		wx.glcanvas.GLCanvas.__init__(self,parent,id,wx.DefaultPosition,wx.DefaultSize,style)

		width,height = self.GetClientSize()

		self.viewer = osgViewer.Viewer()

		self.viewer.setThreadingModel(osgViewer.Viewer.SingleThreaded)
		self.viewer.addEventHandler(osgViewer.StatsHandler())		
		self.viewer.setCameraManipulator(osgGA.TrackballManipulator())

		self.graphicswindow = self.viewer.setUpViewerAsEmbeddedInWindow(0,0,width,height)

		if self.graphicswindow.valid():

			self.old_cursor = wx.STANDARD_CURSOR

			self.Bind(wx.EVT_SIZE, self.OnSize)
			self.Bind(wx.EVT_PAINT, self.OnPaint)
			self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)

			self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
			self.Bind(wx.EVT_KEY_UP, self.OnKeyUp)
			self.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouse)
Esempio n. 2
0
 def createViewer (self):
     """create a osgViewer.Viewer and set the viewport, camera and previously created graphical context """
     viewer = osgViewer.Viewer()
     viewer.getCamera().setViewport(osg.Viewport(0,0, self.width(), self.height()))
     viewer.getCamera().setProjectionMatrixAsPerspective(30.0,float(self.width())/float(self.height()), 1.0, 10000.0)
     if not self.gw:
         raise Exception("GraphicsWindow not yet created")
     viewer.getCamera().setGraphicsContext(self.gw)        
     return viewer
Esempio n. 3
0
    def __init__(self, glconfig, viewer=None, window=None):
        gtk.DrawingArea.__init__(self)

        # Set OpenGL-capability to the drawing area
        self.set_gl_capability(glconfig)

        # Connect the relevant signals.
        self.connect_after('realize', self._on_realize)
        self.connect('configure_event', self._on_configure_event)
        self.connect('expose_event', self._on_expose_event)
        self.connect("key_press_event", self._on_key_press_event)

        self.add_events(gtk.gdk.BUTTON_PRESS_MASK
                        | gtk.gdk.BUTTON_RELEASE_MASK)

        self.__motion_events = 0
        self.__motion_events |= gtk.gdk.BUTTON_MOTION_MASK
        self.__motion_events |= gtk.gdk.POINTER_MOTION_MASK
        self.add_events(self.__motion_events)
        self.connect('motion_notify_event', self._on_mouse_event)
        self.connect("button_press_event", self._on_mouse_event)
        self.connect("button_release_event", self._on_mouse_event)

        #experimental: Stereo in a window
        #self.ds = osg.DisplaySettings_instance()
        #self.ds.setStereo(True)
        #self.ds.setStereoMode(osg.DisplaySettings.QUAD_BUFFER)

        if viewer is None:
            self.viewer = osgViewer.Viewer()
        else:
            self.viewer = viewer
        self.osgwindow = self.viewer.setUpViewerAsEmbeddedInWindow(
            0, 0, 200, 200)
        # one could try using a pythonic alternative:
        #  self.osgwindow = self.setup_osgwindow(0,0,200,200)
        self.viewer.setCameraManipulator(osgGA.TrackballManipulator())

        self.viewer.addEventHandler(osgViewer.StatsHandler())
        self.viewer.addEventHandler(osgViewer.HelpHandler())

        self.rootnode = osg.MatrixTransformRef(osg.MatrixTransform())
        self.viewer.setSceneData(self.rootnode.get())

        self._x, self._y = 0, 0
Esempio n. 4
0
dynamicTransform4.addChild(loadedModel)
dynamicTransform4.setPosition(osg.Vec3d(10, 0, 10))

#add the transform nodes to the scene root
root.addChild(dynamicTransform1.__disown__())
root.addChild(dynamicTransform2.__disown__())
root.addChild(dynamicTransform3.__disown__())
root.addChild(dynamicTransform4.__disown__())

#to prevent direct destruction you can create a variable for the callback
#rotcb = RotateCB()
#dynamicTransform.setUpdateCallback(rotcb.__disown__())
#or call the disown function: dynamicTransform.setUpdateCallback(RotateCB().__disown__())

#create the viewer, set the scene and run
viewer = osgViewer.Viewer()
viewer.setThreadingModel(osgViewer.Viewer.SingleThreaded)

#set the scene data
viewer.setSceneData(root.__disown__())

#add the stats event handler
viewer.addEventHandler(osgViewer.StatsHandler())
pickhandler = PickHandler()
#pickhandler = osgGA.GUIEventHandler()
viewer.addEventHandler(pickhandler.__disown__())

#run the viewer
viewer.run()
#or call the following functions
#viewer.realize()
Esempio n. 5
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()
Esempio n. 6
0
def main():

    #arguments = osg.ArgumentParses(len(sys.argv),sys.argv)
    viewer = osgViewer.Viewer()  #arguments)

    viewer.setCameraManipulator(osgGA.TrackballManipulator())

    skelroot = osgAnimation.Skeleton()
    skelroot.setDefaultUpdateCallback()
    root = osgAnimation.Bone()
    root.setBindMatrixInBoneSpace(osg.Matrixd_identity())
    root.setBindMatrixInBoneSpace(osg.Matrixd_translate(-1, 0, 0))
    root.setName("root")
    root.setDefaultUpdateCallback()

    right0 = osgAnimation.Bone()
    right0.setBindMatrixInBoneSpace(osg.Matrixd_translate(1, 0, 0))
    right0.setName("right0")
    right0.setDefaultUpdateCallback("right0")

    right1 = osgAnimation.Bone()
    right1.setBindMatrixInBoneSpace(osg.Matrixd_translate(1, 0, 0))
    right1.setName("right1")
    right1.setDefaultUpdateCallback("right1")

    root.addChild(right0)
    right0.addChild(right1)
    skelroot.addChild(root)

    scene = osg.Group()
    manager = osgAnimation.BasicAnimationManager()
    scene.setUpdateCallback(manager)

    anim = osgAnimation.Animation()
    keys0 = osgAnimation.QuatKeyframeContainer()
    keys1 = osgAnimation.QuatKeyframeContainer()
    pKeys0 = int(keys0.this)
    pKeys1 = int(keys1.this)
    rotate = osg.Quat()
    rotate.makeRotate(PI_2, osg.Vec3(0, 0, 1))
    keys0.push_back(osgAnimation.QuatKeyframe(0, osg.Quat(0, 0, 0, 1)))
    keys0.push_back(osgAnimation.QuatKeyframe(3, rotate))
    keys0.push_back(osgAnimation.QuatKeyframe(6, rotate))
    keys1.push_back(osgAnimation.QuatKeyframe(0, osg.Quat(0, 0, 0, 1)))
    keys1.push_back(osgAnimation.QuatKeyframe(3, osg.Quat(0, 0, 0, 1)))
    keys1.push_back(osgAnimation.QuatKeyframe(6, rotate))

    sampler0 = osgAnimation.QuatSphericalLinearSampler()
    sampler0.setKeyframeContainer(keys0)
    channel0 = osgAnimation.QuatSphericalLinearChannel(sampler0)
    channel0.setName("quaternion")
    channel0.setTargetName("right0")
    anim.addChannel(channel0)
    sampler1 = osgAnimation.QuatSphericalLinearSampler()
    sampler1.setKeyframeContainer(keys1)
    channel1 = osgAnimation.QuatSphericalLinearChannel(sampler1)
    channel1.setName("quaternion")
    channel1.setTargetName("right1")
    anim.addChannel(channel1)
    manager.registerAnimation(anim)
    manager.buildTargetReference()

    # let's start !
    manager.playAnimation(anim)

    # we will use local data from the skeleton
    rootTransform = osg.MatrixTransform()
    rootTransform.setMatrix(osg.Matrixd_rotate(PI_2, osg.Vec3(1, 0, 0)))
    right0.addChild(createAxis())
    right0.setDataVariance(osg.Object.DYNAMIC)
    right1.addChild(createAxis())
    right1.setDataVariance(osg.Object.DYNAMIC)
    trueroot = osg.MatrixTransform()
    trueroot.setMatrix(osg.Matrixd(root.getMatrixInBoneSpace()))
    trueroot.addChild(createAxis())
    trueroot.addChild(skelroot)
    trueroot.setDataVariance(osg.Object.DYNAMIC)
    rootTransform.addChild(trueroot)
    scene.addChild(rootTransform)

    geom = createTesselatedBox(4, 4.0)
    geode = osg.Geode()
    geode.addDrawable(geom)
    skelroot.addChild(geode)
    src = geom.getVertexArray().asVec3Array()
    geom.getOrCreateStateSet().setMode(osg.GL_LIGHTING, False)
    geom.setDataVariance(osg.Object.DYNAMIC)

    initVertexMap(root, right0, right1, geom, src)

    #let's run !
    viewer.setSceneData(scene)
    viewer.realize()

    while not viewer.done():
        viewer.frame()