def createTextureQuad(texture): vertices = osg.Vec3Array() vertices.push_back(osg.Vec3(-0.8, 0.0, -0.8)) vertices.push_back(osg.Vec3(0.8, 0.0, -0.8)) vertices.push_back(osg.Vec3(0.8, 0.0, 0.8)) vertices.push_back(osg.Vec3(-0.8, 0.0, 0.8)) texcoord = osg.Vec2Array() texcoord.push_back(osg.Vec2(0.0, 0.0)) texcoord.push_back(osg.Vec2(1.0, 0.0)) texcoord.push_back(osg.Vec2(1.0, 1.0)) texcoord.push_back(osg.Vec2(0.0, 1.0)) geom = osg.Geometry() geom.setVertexArray(vertices) geom.setTexCoordArray(0, texcoord) geom.addPrimitiveSet(osg.DrawArrays(GL_QUADS, 0, 4)) geode = osg.Geode() geode.addDrawable(geom) geode.getOrCreateStateSet().setTextureAttributeAndModes(0, texture, osg.StateAttribute.ON) return geode
def createModel(): center = osg.Vec3(0.0,0.0,0.0) radius = 100.0 lightPosition = osg.Vec3(center+osg.Vec3(0.0,0.0,radius)) # the shadower model shadower = createMovingModel(center,radius*0.5) # the shadowed model shadowed = createBase(center-osg.Vec3(0.0,0.0,radius*0.1),radius) # combine the models together to create one which has the shadower and the shadowed with the required callback. root = osg.Group() root.setStateSet(createSpotLightDecoratorState(0,1)) root.addChild(shadower) root.addChild(shadowed) return root
def createMask(): vertices = osg.Vec3Array() vertices.push_back(osg.Vec3(-0.5, -0.5, 0.0)) vertices.push_back(osg.Vec3(0.5, -0.5, 0.0)) vertices.push_back(osg.Vec3(0.5, 0.5, 0.0)) vertices.push_back(osg.Vec3(-0.5, 0.5, 0.0)) geom = osg.Geometry() geom.setVertexArray(vertices) geom.addPrimitiveSet(osg.DrawArrays(GL_QUADS, 0, 4)) geode = osg.Geode() geode.addDrawable(geom) stencil = osg.Stencil() stencil.setFunction(osg.Stencil.ALWAYS, 1, ~0u) stencil.setOperation(osg.Stencil.KEEP, osg.Stencil.KEEP, osg.Stencil.REPLACE) ss = geode.getOrCreateStateSet() ss.setAttributeAndModes(stencil, osg.StateAttribute.ON | osg.StateAttribute.OVERRIDE) ss.setAttribute(osg.ColorMask(False, False, False, False), osg.StateAttribute.ON | osg.StateAttribute.OVERRIDE) return geode
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)
def createModel(overlay, technique): center = osg.Vec3(0.0,0.0,0.0) radius = 100.0 root = osg.Group() baseHeight = center.z()-radius*0.5 baseModel = createBase(osg.Vec3(center.x(), center.y(), baseHeight),radius) movingModel = createMovingModel(center,radius*0.8) if overlay : overlayNode = osgSim.OverlayNode(technique) overlayNode.setContinuousUpdate(True) overlayNode.setOverlaySubgraph(movingModel) overlayNode.setOverlayBaseHeight(baseHeight-0.01) overlayNode.addChild(baseModel) root.addChild(overlayNode) else: root.addChild(baseModel) root.addChild(movingModel) return root
def createTextGroup(text): group = osg.Group() pos = osg.Vec3(120.0, 800.0, 0.0) delta = osg.Vec3(0.0, -60.0, 0.0) # header t = text group.addChild(createText(*t++, pos)) pos += delta # remainder of text under sequence seq = osg.Sequence() group.addChild(seq) while *t : seq.addChild(createText(*t++, pos)) seq.setTime(seq.getNumChildren()-1, 2.0) pos += delta # loop through all children seq.setInterval(osg.Sequence.LOOP, 0,-1) # real-time playback, repeat indefinitively seq.setDuration(1.0, -1) # must be started explicitly seq.setMode(osg.Sequence.START) return group
def creatQuad(name, image, formatMode, minFilter): group = osg.Group() geode = osg.Geode() geode.addDrawable(createTexturedQuadGeometry( osg.Vec3(0.0,0.0,0.0), osg.Vec3(float(image.s()),0.0,0.0), osg.Vec3(0.0,0.0,float(image.t())))) geode.setName(name) stateset = geode.getOrCreateStateSet() texture = osg.Texture2D(image) texture.setInternalFormatMode(formatMode) texture.setFilter(osg.Texture.MIN_FILTER, minFilter) stateset.setTextureAttributeAndModes(0, texture, osg.StateAttribute.ON) group.addChild(geode) group.addChild(createHUD(name))
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
def createMovingModel(center, radius): animationLength = 10.0 animationPath = createAnimationPath(center,radius,animationLength) model = osg.Group() cessna = osgDB.readNodeFile("cessna.osgt") if cessna : bs = cessna.getBound() size = radius/bs.radius()*0.3 positioned = osg.MatrixTransform() positioned.setDataVariance(osg.Object.STATIC) positioned.setMatrix(osg.Matrix.translate(-bs.center())* osg.Matrix.scale(size,size,size)* osg.Matrix.rotate(osg.inDegrees(180.0),0.0,0.0,2.0)) positioned.addChild(cessna) xform = osg.MatrixTransform() xform.setUpdateCallback(osg.AnimationPathCallback(animationPath,0.0,2.0)) xform.addChild(positioned) xform.addChild(createSpotLightNode(osg.Vec3(0.0,0.0,0.0), osg.Vec3(0.0,1.0,-1.0), 60.0, 0, 1)) model.addChild(xform) return model
def createTesselatedBox(nsplit, size): riggeometry = osgAnimation.RigGeometry() geometry = osg.Geometry() vertices = osg.Vec3Array(osg.Vec3Array()) colors = osg.Vec3Array(osg.Vec3Array()) geometry.setVertexArray (vertices) geometry.setColorArray (colors, osg.Array.BIND_PER_VERTEX) step = size / static_cast<float>(nsplit) s = 0.5/4.0 for (int i = 0 i < nsplit i++) x = -1.0 + static_cast<float>(i) * step print x vertices.push_back (osg.Vec3 ( x, s, s)) vertices.push_back (osg.Vec3 ( x, -s, s)) vertices.push_back (osg.Vec3 ( x, -s, -s)) vertices.push_back (osg.Vec3 ( x, s, -s)) c = osg.Vec3(0.0,0.0,0.0) c[i%3] = 1.0 colors.push_back (c) colors.push_back (c) colors.push_back (c) colors.push_back (c)
def createRandomTriangles(num): tris = osg.Geode() ss = tris.getOrCreateStateSet() # Force wireframe. Many gfx cards handle this poorly. pm = osg.PolygonMode( osg.PolygonMode.FRONT_AND_BACK, osg.PolygonMode.LINE ) ss.setAttributeAndModes( pm, osg.StateAttribute.ON | osg.StateAttribute.PROTECTED) ss.setMode( GL_LIGHTING, osg.StateAttribute.OFF | osg.StateAttribute.PROTECTED) geom = deprecated_osg.Geometry() # Disable display lists to decrease performance. geom.setUseDisplayList( False ) v = osg.Vec3Array() geom.setVertexArray( v ) v.resize( num*3 ) i = unsigned int() srand( 0 ) #define RAND_NEG1_TO_1 ( ((rand()%20)-10)*.1 ) for (i=0 i<num i++) v0 = (*v)[ i*3+0 ] v1 = (*v)[ i*3+1 ] v2 = (*v)[ i*3+2 ] v0 = osg.Vec3( RAND_NEG1_TO_1, RAND_NEG1_TO_1, RAND_NEG1_TO_1 ) v1 = osg.Vec3( RAND_NEG1_TO_1, RAND_NEG1_TO_1, RAND_NEG1_TO_1 ) v2 = osg.Vec3( RAND_NEG1_TO_1, RAND_NEG1_TO_1, RAND_NEG1_TO_1 )
def createGeometry(): vertices = osg.Vec3Array() vertices.push_back(osg.Vec3(-1.0, -1.0, 0.0)) vertices.push_back(osg.Vec3(1.0, -1.0, 0.0)) vertices.push_back(osg.Vec3(1.0, 1.0, 0.0)) vertices.push_back(osg.Vec3(-1.0, 1.0, 0.0)) geom = osg.Geometry() geom.setVertexArray(vertices) geom.addPrimitiveSet(osg.DrawArrays(GL_QUADS, 0, 4)) geode = osg.Geode() geode.addDrawable(geom) stencil = osg.Stencil() stencil.setFunction(osg.Stencil.NOTEQUAL, 1, ~0u) stencil.setOperation(osg.Stencil.KEEP, osg.Stencil.KEEP, osg.Stencil.KEEP) ss = geode.getOrCreateStateSet() ss.setAttributeAndModes(stencil, osg.StateAttribute.ON | osg.StateAttribute.OVERRIDE) return geode
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
def computeBound(): geom_box = _geometry.getBound() bb = osg.BoundingBox() for(PositionSizeList.const_iterator itr = _trees.begin() not = _trees.end() ++itr) bb.expandBy(geom_box.corner(0)*(*itr)[3] + osg.Vec3( (*itr)[0], (*itr)[1], (*itr)[2] )) bb.expandBy(geom_box.corner(7)*(*itr)[3] + osg.Vec3( (*itr)[0], (*itr)[1], (*itr)[2] ))
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 )
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)
def main(argv): arguments = osg.ArgumentParser( argc, argv ) # Create the texture as both the output of compute shader and the input of a normal quad tex2D = osg.Texture2D() tex2D.setTextureSize( 512, 512 ) tex2D.setFilter( osg.Texture2D.MIN_FILTER, osg.Texture2D.LINEAR ) tex2D.setFilter( osg.Texture2D.MAG_FILTER, osg.Texture2D.LINEAR ) tex2D.setInternalFormat( GL_R32F ) tex2D.setSourceFormat( GL_RED ) tex2D.setSourceType( GL_FLOAT ) tex2D.bindToImageUnit( 0, osg.Texture.WRITE_ONLY ) # So we can use 'image2D' in the compute shader # The compute shader can't work with other kinds of shaders # It also requires the work group numbers. Setting them to 0 will disable the compute shader computeProg = osg.Program() computeProg.setComputeGroups( 512/16, 512/16, 1 ) computeProg.addShader( osg.Shader(osg.Shader.COMPUTE, computeSrc) ) # Create a node for outputting to the texture. # It is OK to have just an empty node here, but seems inbuilt uniforms like osg_FrameTime won't work then. # TODO: maybe we can have a custom drawable which also will implement sourceNode = osgDB: if (glMemoryBarrier) else readNodeFile("axes.osgt") if not sourceNode : sourceNode = osg.Node() sourceNode.setDataVariance( osg.Object.DYNAMIC ) sourceNode.getOrCreateStateSet().setAttributeAndModes( computeProg ) sourceNode.getOrCreateStateSet().addUniform( osg.Uniform("targetTex", (int)0) ) sourceNode.getOrCreateStateSet().setTextureAttributeAndModes( 0, tex2D ) # Display the texture on a quad. We will also be able to operate on the data if reading back to CPU side geom = osg.createTexturedQuadGeometry( osg.Vec3(), osg.Vec3(1.0,0.0,0.0), osg.Vec3(0.0,0.0,1.0) ) quad = osg.Geode() quad.addDrawable( geom ) quad.getOrCreateStateSet().setMode( GL_LIGHTING, osg.StateAttribute.OFF ) quad.getOrCreateStateSet().setTextureAttributeAndModes( 0, tex2D ) # Create the scene graph and start the viewer scene = osg.Group() scene.addChild( sourceNode ) scene.addChild( quad ) viewer = osgViewer.Viewer() viewer.addEventHandler( osgGA.StateSetManipulator(viewer.getCamera().getOrCreateStateSet()) ) viewer.addEventHandler( osgViewer.StatsHandler )() viewer.addEventHandler( osgViewer.WindowSizeHandler )() viewer.setSceneData( scene ) return viewer.run()
class Character (osg.Referenced) : Character() setCharacter = void( str filename, str name, osg.Vec3 orgin, osg.Vec3 width, osg.Vec3 catchPos, float positionRatio) setLives = void( str filename, osg.Vec3 orgin, osg.Vec3 delta, unsigned int numLives) setCatches = void( str filename, osg.Vec3 orgin, osg.Vec3 delta, unsigned int numLives) moveLeft = void() moveRight = void() moveTo = void(float positionRatio) reset = void() resetCatches = void() addCatch = bool() looseLife = bool() def getCurrentCenterOfBasket(): return _character.getPosition()+_centerBasket def getCurrentRadiusOfBasket(): return _radiusBasket def getLowerLeft(): return _character.getPosition() def getUpperRight(): return _character.getPosition() _origin = osg.Vec3() _width = osg.Vec3() _positionRatio = float() _character = osg.PositionAttitudeTransform() _numLives = unsigned int() _livesSwitch = osg.Switch() _numCatches = unsigned int() _catchSwitch = osg.Switch() _objectsGroup = osg.Group() _centerBasket = osg.Vec3() _radiusBasket = float()
def setupCube(): geode = osg.Geode() geode.addDrawable(osg.ShapeDrawable(osg.Box(osg.Vec3(0.0,0.0,0.0),2))) geode.setStateSet(setupStateSet()) return geode
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
def buildJoint3(previousJoint): height = 7.5 radius = 4.45633 joint = osg.Geode() xTransform = osg.MatrixTransform() previousJoint.addChild(xTransform) xRot = osg.Matrix.rotate(-osg.PI_2, 1.0, 0.0, 0.0) xTransform.setMatrix(xRot) zCheat = osg.MatrixTransform() zTransCheat = osg.Matrix.translate(0.0,0.0,-height) zCheat.setMatrix(zTransCheat) xTransform.addChild(zCheat) shape = osg.ShapeDrawable(osg.Capsule(osg.Vec3(0.0,0.0,height/2),radius,height),hints) joint.addDrawable(shape) zCheat.addChild(joint) zTransform = osg.MatrixTransform() zCheat.addChild(zTransform) zRot = osg.Matrix.rotate((float)jointAngle3, 0.0, 0.0, 1.0) zTrans = osg.Matrix.translate(0,0,0) zTransform.setMatrix(zTrans*zRot) if showAxis : createAxis(zTransform) return zTransform
def createBase(center, radius): geode = osg.Geode() # set up the texture of the base. stateset = osg.StateSet() image = osgDB.readImageFile("Images/lz.rgb") if image : texture = osg.Texture2D() texture.setImage(image) stateset.setTextureAttributeAndModes(0,texture,osg.StateAttribute.ON) geode.setStateSet( stateset ) grid = osg.HeightField() grid.allocate(38,39) grid.setOrigin(center+osg.Vec3(-radius,-radius,0.0)) grid.setXInterval(radius*2.0/(float)(38-1)) grid.setYInterval(radius*2.0/(float)(39-1)) minHeight = FLT_MAX maxHeight = -FLT_MAX r = unsigned int() for(r=0r<39++r) for(unsigned int c=0c<38++c) h = vertex[r+c*39][2] if h>maxHeight : maxHeight=h if h<minHeight : minHeight=h
def main(argv): arguments = osg.ArgumentParser(argv) viewer = osgViewer.Viewer(arguments) tbm = osgGA.TrackballManipulator() viewer.setCameraManipulator(tbm) viewer.addEventHandler(osgViewer.StatsHandler()) viewer.addEventHandler(osgViewer.WindowSizeHandler()) root = osg.Group() geode = osg.Geode() geode.setStateSet(setupStateSet()) root.setInitialBound(osg.BoundingSphere(osg.Vec3(10,0,20), 50)) root.addChild(setupAnimtkNode(geode)) root.addChild(geode) viewer.setSceneData(root) # tbm.setDistance(150) return viewer.run()
def main(argv): app = QApplication(argc, argv) # prepare scene. center = osg.Vec3(0.0,0.0,0.0) radius = 1.0 # create the hud. camera = osg.Camera() camera.setReferenceFrame(osg.Transform.ABSOLUTE_RF) camera.setProjectionMatrixAsOrtho2D(0,1280,0,1024) camera.setViewMatrix(osg.Matrix.identity()) camera.setClearMask(GL_DEPTH_BUFFER_BIT) camera.addChild(createHUDText()) camera.getOrCreateStateSet().setMode(GL_LIGHTING,osg.StateAttribute.OFF) # make sure the root node is group so we can add extra nodes to it. group = osg.Group() group.addChild(camera) group.addChild(create3DText(center, radius)) # The qt window widget = MainWindow() # set the scene to render widget.setSceneData(group) widget.setCameraManipulator(osgGA.TrackballManipulator)() widget.setGeometry(100, 100, 800, 600) widget.show() return app.exec()
class KeyboardEventHandler (osgGA.GUIEventHandler) : KeyboardEventHandler(osg.StateSet* stateset): _stateset(stateset) _point = osg.Point() _point.setDistanceAttenuation(osg.Vec3(0.0,0.0000,0.05)) _stateset.setAttribute(_point)
def createAnimationPath(center, radius, looptime): # set up the animation path animationPath = osg.AnimationPath() animationPath.setLoopMode(osg.AnimationPath.LOOP) numSamples = 40 yaw = 0.0 yaw_delta = 2.0*osg.PI/(numSamples-1.0) roll = osg.inDegrees(30.0) time = 0.0 time_delta = looptime/float(numSamples) for i in range(numSamples): position = center+osg.Vec3(math.sin(yaw)*radius,math.cos(yaw)*radius,0.0) rotation = osg.Quat(roll,osg.Vec3(0.0,1.0,0.0))*osg.Quat(-(yaw+osg.inDegrees(90.0)),osg.Vec3(0.0,0.0,1.0)) animationPath.insert(time,osg.AnimationPath.ControlPoint(position,rotation)) yaw += yaw_delta time += time_delta return animationPath
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()
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
def createSectorForImage(image, texmat, s, t, radius, height, length): flip = image.getOrigin()==osg.Image.TOP_LEFT numSegments = 20 Theta = length/radius dTheta = Theta/(float)(numSegments-1) ThetaZero = height*s/(t*radius) # set up the texture. texture = osg.Texture2D() texture.setFilter(osg.Texture2D.MIN_FILTER,osg.Texture2D.LINEAR) texture.setFilter(osg.Texture2D.MAG_FILTER,osg.Texture2D.LINEAR) texture.setWrap(osg.Texture2D.WRAP_S,osg.Texture2D.CLAMP_TO_BORDER) texture.setWrap(osg.Texture2D.WRAP_T,osg.Texture2D.CLAMP_TO_BORDER) texture.setResizeNonPowerOfTwoHint(False) texture.setImage(image) # set up the drawstate. dstate = osg.StateSet() dstate.setMode(GL_CULL_FACE,osg.StateAttribute.OFF) dstate.setMode(GL_LIGHTING,osg.StateAttribute.OFF) dstate.setTextureAttributeAndModes(0, texture,osg.StateAttribute.ON) dstate.setTextureAttribute(0, texmat) # set up the geoset. geom = osg.Geometry() geom.setStateSet(dstate) coords = osg.Vec3Array() tcoords = osg.Vec2Array() i = int() angle = -Theta/2.0 for(i=0 i<numSegments ++i, angle+=dTheta) coords.push_back(osg.Vec3(sinf(angle)*radius,cosf(angle)*radius,height*0.5)) # top coords.push_back(osg.Vec3(sinf(angle)*radius,cosf(angle)*radius,-height*0.5)) # bottom. tcoords.push_back(osg.Vec2(angle/ThetaZero+0.5, 0.0 if (flip) else 1.0)) # top tcoords.push_back(osg.Vec2(angle/ThetaZero+0.5, 1.0 if (flip) else 0.0)) # bottom.
def main(argv): viewer = osgViewer.Viewer() wm = osgWidget.WindowManager( viewer, WINDOW_WIDTH, WINDOW_HEIGHT, MASK_2D ) menu = osgWidget.Box("menu", osgWidget.Box.HORIZONTAL) menu.addWidget(ColorLabelMenu("Choose EaseMotion")) menu.getBackground().setColor(1.0, 1.0, 1.0, 1.0) menu.setPosition(15.0, 15.0, 0.0) wm.addChild(menu) group = osg.Group() geode = osg.Geode() mt = osg.MatrixTransform() geode.addDrawable(osg.ShapeDrawable(osg.Sphere(osg.Vec3(), 4.0))) EASE_MOTION_SAMPLER = EaseMotionSampler(osg.Vec3(50.0, 0.0, 0.0)) EASE_MOTION_GEODE = osg.Geode() mt.addChild(geode) mt.setUpdateCallback(EASE_MOTION_SAMPLER) mt.setNodeMask(MASK_3D) viewer.setCameraManipulator(osgGA.TrackballManipulator()) viewer.getCameraManipulator().setHomePosition( osg.Vec3d(0.0, 0.0, 200.0), osg.Vec3d(20.0, 0.0, 0.0), osg.Vec3d(0.0, 1.0, 0.0) ) viewer.home() group.addChild(mt) group.addChild(EASE_MOTION_GEODE) return osgWidget.createExample(viewer, wm, group)