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
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()
tracker.getOrCreateCalibration().load("data/camera_para.dat") # initialize the tracker tracker.setImage(video) # add a tracker callback osgART.TrackerCallback.addOrSet(root,tracker) # create a marker marker = tracker.addMarker("single;data/patt.hiro;80;0;0") # set the marker active marker.setActive(True) # create a matrix transfrom utilised through osgART ar_transform = osg.MatrixTransform() # add the default chain of event handlers osgART.attachDefaultEventCallbacks(ar_transform,marker) # add a cube ar_transform.addChild(osgART.testCube()) # need to set the renderbin > render this one last ar_transform.getOrCreateStateSet().setRenderBinDetails(100, "RenderBin") # create a video background video_background = createImageBackground(video) # set the renderbin on the video background > rendered first video_background.getOrCreateStateSet().setRenderBinDetails(0, "RenderBin");
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()
else: pot = osg.NodeToPositionAttitudeTransform(node) if pot: pot.setAttitude(self._quat) # Increment the angle. self._angle += 0.01 # call traverse self.traverse(node, nv) #load the model loadedModel = osgDB.readNodeFile("cow.osg") #create a dynamic transformation node, we can use a MatrixTransform dynamicTransform = osg.MatrixTransform() #or we can use a PositionAttitudeTransform: dynamic = osg.PositionAttitudeTransform() #add the loaded model to the transform node dynamicTransform.addChild(loadedModel) #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