Exemplo 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)
Exemplo n.º 2
0
 def initializeGL (self):
     """initializeGL the context and create the osgViewer, also set manipulator and event handler """       
     self.gw = self.createContext()
     self.viewer = self.createViewer()
     #init the default eventhandler
     self.viewer.setCameraManipulator(osgGA.TrackballManipulator())
     self.viewer.addEventHandler(osgViewer.StatsHandler())
     self.viewer.addEventHandler(osgViewer.HelpHandler())
     QtCore.QObject.connect(self.timer, QtCore.SIGNAL("timeout ()"), self.updateGL)
     self.timer.start(0)
Exemplo 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
Exemplo n.º 4
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()
Exemplo n.º 5
0
    texture.setResizeNonPowerOfTwoHint(False)
    texture.setUnRefImageDataAfterApply(True)
    texture.setFilter(osg.Texture.MIN_FILTER, osg.Texture.LINEAR)
    texture.setFilter(osg.Texture.MAG_FILTER, osg.Texture.LINEAR)
    geom.getOrCreateStateSet().setTextureAttributeAndModes(0, texture)
    addShader(geom)
    geode = osg.Geode()
    geode.addDrawable(geom)
    sequence.addChild(geode, duration / iteration)

sequence.setDuration(1.0, -1)
sequence.setMode(osg.Sequence.START)

viewer = osgViewer.Viewer()
viewer.setSceneData(sequence)
viewer.addEventHandler(osgViewer.StatsHandler())

#viewer.run()
cam = osgGA.TrackballManipulator()
viewer.realize()
#GUIActionAdapterToViewer(cam)
viewer.setCameraManipulator(cam)
#viewer.setCameraManipulatorOneArg(cam)
#viewer.setCameraManipulatorAndResetView(cam, True)
#setupDefaultManipulator(viewer)
time = 0.0
for i in range(0, 1000):
    viewer.frameAtTime(time)
    time = time + 0.16666666
    print "time " + str(time)