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 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 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 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 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 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 setupAnimtkNode(staticGeode): osg.Vec3 v[5] v[0] = osg.Vec3( 0, 0, 0) v[1] = osg.Vec3(20, 40, 60) v[2] = osg.Vec3(40, 60, 20) v[3] = osg.Vec3(60, 20, 40) v[4] = osg.Vec3( 0, 0, 0) node = osg.MatrixTransform() callback = MakePathDistanceCallback(staticGeode) keys = callback._sampler.getOrCreateKeyframeContainer() keys.push_back(osgAnimation.Vec3CubicBezierKeyframe(0, osgAnimation.Vec3CubicBezier( v[0], v[0] + (v[0] - v[3]), v[1] - (v[1] - v[0]) ))) keys.push_back(osgAnimation.Vec3CubicBezierKeyframe(2, osgAnimation.Vec3CubicBezier( v[1], v[1] + (v[1] - v[0]), v[2] - (v[2] - v[1]) ))) keys.push_back(osgAnimation.Vec3CubicBezierKeyframe(4, osgAnimation.Vec3CubicBezier( v[2], v[2] + (v[2] - v[1]), v[3] - (v[3] - v[2]) ))) keys.push_back(osgAnimation.Vec3CubicBezierKeyframe(6, osgAnimation.Vec3CubicBezier( v[3], v[3] + (v[3] - v[2]), v[4] - (v[4] - v[3]) ))) keys.push_back(osgAnimation.Vec3CubicBezierKeyframe(8, osgAnimation.Vec3CubicBezier( v[4], v[4] + (v[4] - v[3]), v[0] - (v[0] - v[4]) ))) callback.start() node.setUpdateCallback(callback) geode = osg.Geode() geode.setStateSet(setupStateSet()) geode.addDrawable(osg.ShapeDrawable(osg.Sphere(osg.Vec3(0.0, 0.0, 0.0), 2))) node.addChild(geode) return node
def createShapes(): geode = osg.Geode() # --------------------------------------- # Set up a StateSet to texture the objects # --------------------------------------- stateset = osg.StateSet() image = osgDB.readImageFile( "Images/lz.rgb" ) if image : texture = osg.Texture2D() texture.setImage(image) texture.setFilter(osg.Texture.MIN_FILTER, osg.Texture.LINEAR) stateset.setTextureAttributeAndModes(0,texture, osg.StateAttribute.ON) stateset.setMode(GL_LIGHTING, osg.StateAttribute.ON) geode.setStateSet( stateset ) radius = 0.8 height = 1.0 hints = osg.TessellationHints() hints.setDetailRatio(0.5) geode.addDrawable(osg.ShapeDrawable(osg.Sphere(osg.Vec3(0.0,0.0,0.0),radius),hints)) geode.addDrawable(osg.ShapeDrawable(osg.Box(osg.Vec3(2.0,0.0,0.0),2*radius),hints)) geode.addDrawable(osg.ShapeDrawable(osg.Cone(osg.Vec3(4.0,0.0,0.0),radius,height),hints)) geode.addDrawable(osg.ShapeDrawable(osg.Cylinder(osg.Vec3(6.0,0.0,0.0),radius,height),hints)) geode.addDrawable(osg.ShapeDrawable(osg.Capsule(osg.Vec3(8.0,0.0,0.0),radius,height),hints)) grid = osg.HeightField() grid.allocate(38,39) grid.setXInterval(0.28) grid.setYInterval(0.28) for(unsigned int r=0r<39++r) for(unsigned int c=0c<38++c) grid.setHeight(c,r,vertex[r+c*39][2])
def createScene(): # Create the Earth, in blue earth_sd = osg.ShapeDrawable() earth_sphere = osg.Sphere() earth_sphere.setName("EarthSphere") earth_sphere.setRadius(r_earth) earth_sd.setShape(earth_sphere) earth_sd.setColor(osg.Vec4(0, 0, 1.0, 1.0)) earth_geode = osg.Geode() earth_geode.setName("EarthGeode") earth_geode.addDrawable(earth_sd) # Create the Sun, in yellow sun_sd = osg.ShapeDrawable() sun_sphere = osg.Sphere() sun_sphere.setName("SunSphere") sun_sphere.setRadius(r_sun) sun_sd.setShape(sun_sphere) sun_sd.setColor(osg.Vec4(1.0, 0.0, 0.0, 1.0)) sun_geode = osg.Geode() sun_geode.setName("SunGeode") sun_geode.addDrawable(sun_sd) # Move the sun behind the earth pat = osg.PositionAttitudeTransform() pat.setPosition(osg.Vec3d(0.0, AU, 0.0)) pat.addChild(sun_geode) unitCircle = osg.Geometry() colours = osg.Vec4Array(1) (*colours)[0] = osg.Vec4d(1.0,1.0,1.0,1.0) unitCircle.setColorArray(colours, osg.Array.BIND_OVERALL) n_points = 1024 coords = osg.Vec3Array(n_points) dx = 2.0*osg.PI/n_points double s,c for (unsigned int j=0 j<n_points ++j)
def createSkyBox(): stateset = osg.StateSet() te = osg.TexEnv() te.setMode(osg.TexEnv.REPLACE) stateset.setTextureAttributeAndModes(0, te, osg.StateAttribute.ON) tg = osg.TexGen() tg.setMode(osg.TexGen.NORMAL_MAP) stateset.setTextureAttributeAndModes(0, tg, osg.StateAttribute.ON) tm = osg.TexMat() stateset.setTextureAttribute(0, tm) skymap = readCubeMap() stateset.setTextureAttributeAndModes(0, skymap, osg.StateAttribute.ON) stateset.setMode( GL_LIGHTING, osg.StateAttribute.OFF ) stateset.setMode( GL_CULL_FACE, osg.StateAttribute.OFF ) # clear the depth to the far plane. depth = osg.Depth() depth.setFunction(osg.Depth.ALWAYS) depth.setRange(1.0,1.0) stateset.setAttributeAndModes(depth, osg.StateAttribute.ON ) stateset.setRenderBinDetails(-1,"RenderBin") drawable = osg.ShapeDrawable(osg.Sphere(osg.Vec3(0.0,0.0,0.0),1)) geode = osg.Geode() geode.setCullingActive(False) geode.setStateSet( stateset ) geode.addDrawable(drawable) transform = MoveEarthySkyWithEyePointTransform() transform.setCullingActive(False) transform.addChild(geode) clearNode = osg.ClearNode() # clearNode.setRequiresClear(False) clearNode.setCullCallback(TexMatCallback(*tm)) clearNode.addChild(transform) return clearNode
def buildJoint6(previousJoint): height = 3.0 radius = 1.0 joint = osg.Geode() joint.addDrawable(osg.ShapeDrawable(osg.Cylinder(osg.Vec3(0.0,0.0,height/2),radius,height),hints)) xTransform = osg.MatrixTransform() xRot = osg.Matrix.rotate(osg.PI_2, 1.0, 0.0, 0.0) xTransform.setMatrix(xRot) xTransform.addChild(joint) previousJoint.addChild(xTransform) if showAxis : createAxis(xTransform) return xTransform
def buildJoint1(previousJoint): xTransform = osg.MatrixTransform() previousJoint.addChild(xTransform) radius = 6.7640 height = 45.0 joint = osg.Geode() xTransform.addChild(joint) joint.addDrawable(osg.ShapeDrawable(osg.Cylinder(osg.Vec3(0.0,0.0,height/2),radius,height),hints)) zTransform = osg.MatrixTransform() xTransform.addChild(zTransform) zTrans = osg.Matrix.translate(0.0, 0.0, height) zRot = osg.Matrix.rotate(jointAngle1, 0.0, 0.0, 1.0) zTransform.setMatrix(zTrans*zRot) return zTransform
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)
def createEarth(): hints = osg.TessellationHints() hints.setDetailRatio(5.0) sd = osg.ShapeDrawable(osg.Sphere(osg.Vec3(0.0,0.0,0.0), osg.WGS_84_RADIUS_POLAR), hints) geode = osg.Geode() geode.addDrawable(sd) filename = osgDB.findDataFile("Images/land_shallow_topo_2048.jpg") geode.getOrCreateStateSet().setTextureAttributeAndModes(0, osg.Texture2D(osgDB.readImageFile(filename))) csn = osg.CoordinateSystemNode() csn.setEllipsoidModel(osg.EllipsoidModel()) csn.addChild(geode) return csn
def buildTube2(previousJoint): if showAxis : createAxis(previousJoint) height = 17.6 radius = 4.45633 xTransform = osg.MatrixTransform() previousJoint.addChild(xTransform) xRot = osg.Matrix.rotate(osg.PI_2, 1.0,0.0,0.0) xTransform.setMatrix(xRot) tube3 = osg.Geode() xTransform.addChild(tube3) tube3.addDrawable(osg.ShapeDrawable(osg.Capsule(osg.Vec3(0.0,0.0,height/2),radius,height),hints)) zTransform = osg.MatrixTransform() xTransform.addChild(zTransform) zTrans = osg.Matrix.translate(0,0,height) zTransform.setMatrix(zTrans) return zTransform
def buildJoint2(previousJoint): if showAxis : createAxis(previousJoint) height = 17.6 radius = 4.45633 xTransform = osg.MatrixTransform() previousJoint.addChild(xTransform) xRot = osg.Matrix.rotate(osg.PI_2, 1.0, 0.0, 0.0) xTransform.setMatrix(xRot) joint = osg.Geode() joint.addDrawable(osg.ShapeDrawable(osg.Capsule(osg.Vec3(0.0,0.0,height/2),radius,height),hints)) xTransform.addChild(joint) zTransform = osg.MatrixTransform() zTrans = osg.Matrix.translate( 0.0, 0.0, height) zRot = osg.Matrix.rotate(osg.PI_2+jointAngle2, 0.0,0.0,1.0) zTransform.setMatrix(zTrans*zRot) xTransform.addChild(zTransform) return zTransform
def main(argv): # use an ArgumentParser object to manage the program arguments. arguments = osg.ArgumentParser(argv) # read the scene from the list of file specified commandline args. scene = osgDB.readNodeFiles(arguments) # if not loaded assume no arguments passed in, try use default model instead. if not scene : scene = osgDB.readNodeFile("dumptruck.osgt") if not scene : 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) scene = geode # construct the viewer. viewer = osgViewer.Viewer() group = osg.Group() # add the HUD subgraph. if scene.valid() : group.addChild(scene) viewer.setCameraManipulator(osgGA.MultiTouchTrackballManipulator()) viewer.realize() gc = viewer.getCamera().getGraphicsContext() #ifdef __APPLE__ # as multitouch is disabled by default, enable it now win = dynamic_cast<osgViewer.GraphicsWindowCocoa*>(gc) if win : win.setMultiTouchEnabled(True)
def buildJoint5(previousJoint): radius = 2.86479 height = 2.86479*2 joint = osg.Geode() shape = osg.ShapeDrawable(osg.Cylinder(osg.Vec3(0.0,0.0,0.0),radius,height),hints) joint.addDrawable(shape) xTransform = osg.MatrixTransform() previousJoint.addChild(xTransform) xRot = osg.Matrix.rotate(-osg.PI_2, 1.0,0,0) xTransform.setMatrix(xRot) xTransform.addChild(joint) if showAxis : createAxis(xTransform) zTransform = osg.MatrixTransform() zRot = osg.Matrix.rotate(jointAngle5, 0,0,1) zTrans = osg.Matrix.translate(0,0,0) zTransform.setMatrix(zTrans*zRot) xTransform.addChild(zTransform) return zTransform
def createTexturedCube(fRadius, vPosition, texture, geodeName): # create a cube shape bCube = osg.Box(vPosition,fRadius) # osg.Box *bCube = osg.Box(vPosition,fRadius) # create a container that makes the cube drawable sdCube = osg.ShapeDrawable(bCube) # create a geode object to as a container for our drawable cube object geodeCube = osg.Geode() geodeCube.setName( geodeName ) # set the object texture state SetObjectTextureState(geodeCube, texture) # add our drawable cube to the geode container geodeCube.addDrawable(sdCube) return(geodeCube)
def buildTube5(previousJoint): if showAxis : createAxis(previousJoint) height = 7.5 radius = 2.86479 height = 15.0 joint = osg.Geode() shape = osg.ShapeDrawable(osg.Cylinder(osg.Vec3(0.0,0.0,height/2),radius,height),hints) joint.addDrawable(shape) xTransform = osg.MatrixTransform() previousJoint.addChild(xTransform) xTransform.addChild(joint) zTransform = osg.MatrixTransform() zTrans = osg.Matrix.translate(0,0,height) zTransform.setMatrix(zTrans) xTransform.addChild(zTransform) return zTransform
def buildJoint4(previousJoint): height = 17.5 radius = 2.86479 tube4 = osg.Geode() tube4.addDrawable(osg.ShapeDrawable(osg.Capsule(osg.Vec3(0.0,0.0,height/2),radius,height),hints)) xTransform = osg.MatrixTransform() #if showAxis : # #createAxis(xTransform) # previousJoint.addChild(xTransform) xTransform.addChild(tube4) xRot = osg.Matrix.rotate(osg.PI_2, 1,0,0) xTransform.setMatrix(xRot) height = 7.5 zTrans = osg.Matrix.translate(0,0,17.5) zRot = osg.Matrix.rotate(jointAngle4-osg.PI_2, 0,0,1) zTransform = osg.MatrixTransform() zTransform.setMatrix(zTrans*zRot) xTransform.addChild(zTransform) return zTransform
def create3DText(center, radius): geode = osg.Geode() #################################################### # # Examples of how to set up axis/orientation alignments # characterSize = radius*0.2 pos = osg.Vec3(center.x()-radius*.5,center.y()-radius*.5,center.z()-radius*.5) text1 = osgText.Text() text1.setFont(osgText.Font(osgQt.QFontImplementation(QFont("Times")))) text1.setCharacterSize(characterSize) text1.setPosition(pos) text1.setAxisAlignment(osgText.Text.XY_PLANE) text1.setText("XY_PLANE") geode.addDrawable(text1) text2 = osgText.Text() text2.setFont(osgText.Font(osgQt.QFontImplementation(QFont("Times")))) text2.setCharacterSize(characterSize) text2.setPosition(pos) text2.setAxisAlignment(osgText.Text.YZ_PLANE) text2.setText("YZ_PLANE") geode.addDrawable(text2) text3 = osgText.Text() text3.setFont(osgText.Font(osgQt.QFontImplementation(QFont("Times")))) text3.setCharacterSize(characterSize) text3.setPosition(pos) text3.setAxisAlignment(osgText.Text.XZ_PLANE) text3.setText("XZ_PLANE") geode.addDrawable(text3) text4 = osgText.Text() text4.setFont(osgText.Font(osgQt.QFontImplementation(QFont("Times")))) text4.setCharacterSize(characterSize) text4.setPosition(center) text4.setAxisAlignment(osgText.Text.SCREEN) characterSizeModeColor = osg.Vec4(1.0,0.0,0.5,1.0) text5 = osgText.Text() text5.setColor(characterSizeModeColor) text5.setFont(osgText.Font(osgQt.QFontImplementation(QFont("Times")))) #text5.setCharacterSize(characterSize) text5.setCharacterSize(32.0) # medium text5.setPosition(center - osg.Vec3(0.0, 0.0, 0.2)) text5.setAxisAlignment(osgText.Text.SCREEN) text5.setCharacterSizeMode(osgText.Text.SCREEN_COORDS) text5.setText("CharacterSizeMode SCREEN_COORDS(size 32.0)") geode.addDrawable(text5) text6 = osgText.Text() text6.setColor(characterSizeModeColor) text6.setFont(osgText.Font(osgQt.QFontImplementation(QFont("Times")))) text6.setCharacterSize(characterSize) text6.setPosition(center - osg.Vec3(0.0, 0.0, 0.4)) text6.setAxisAlignment(osgText.Text.SCREEN) text6.setCharacterSizeMode(osgText.Text.OBJECT_COORDS_WITH_MAXIMUM_SCREEN_SIZE_CAPPED_BY_FONT_HEIGHT) text6.setText("CharacterSizeMode OBJECT_COORDS_WITH_MAXIMUM_SCREEN_SIZE_CAPPED_BY_FONT_HEIGHT") geode.addDrawable(text6) text7 = osgText.Text() text7.setColor(characterSizeModeColor) text7.setFont(osgText.Font(osgQt.QFontImplementation(QFont("Times")))) text7.setCharacterSize(characterSize) text7.setPosition(center - osg.Vec3(0.0, 0.0, 0.6)) text7.setAxisAlignment(osgText.Text.SCREEN) text7.setCharacterSizeMode(osgText.Text.OBJECT_COORDS) text7.setText("CharacterSizeMode OBJECT_COORDS (default)") geode.addDrawable(text7) #if 1 # reproduce outline bounding box compute problem with backdrop on. text4.setBackdropType(osgText.Text.OUTLINE) text4.setDrawMode(osgText.Text.TEXT | osgText.Text.BOUNDINGBOX) #endif text4.setText("SCREEN") geode.addDrawable(text4) 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) return rootNode
def main(argv): # use an ArgumentParser object to manage the program arguments. arguments = osg.ArgumentParser(argv) # read the scene from the list of file specified commandline args. scene = osgDB.readNodeFiles(arguments) if not scene and arguments.read("--relative-camera-scene") : # Create a test scene with a camera that has a relative reference frame. group = osg.Group() sphere = osg.Geode() sphere.setName("Sphere") sphere.addDrawable(osg.ShapeDrawable(osg.Sphere())) cube = osg.Geode() cube.setName("Cube") cube.addDrawable(osg.ShapeDrawable(osg.Box())) camera = osg.Camera() camera.setRenderOrder(osg.Camera.POST_RENDER) camera.setClearMask(GL_DEPTH_BUFFER_BIT) camera.setReferenceFrame(osg.Transform.RELATIVE_RF) camera.setViewMatrix(osg.Matrix.translate(-2, 0, 0)) xform = osg.MatrixTransform(osg.Matrix.translate(1, 1, 1)) xform.addChild(camera) group.addChild(sphere) group.addChild(xform) camera.addChild(cube) scene = group # if not loaded assume no arguments passed in, try use default mode instead. if not scene : scene = osgDB.readNodeFile("fountain.osgt") group = dynamic_cast<osg.Group*>(scene) if not group : group = osg.Group() group.addChild(scene) updateText = osgText.Text() # add the HUD subgraph. group.addChild(createHUD(updateText)) if arguments.read("--CompositeViewer") : view = osgViewer.View() # add the handler for doing the picking view.addEventHandler(PickHandler(updateText)) # set the scene to render view.setSceneData(group) view.setUpViewAcrossAllScreens() viewer = osgViewer.CompositeViewer() viewer.addView(view) return viewer.run() else: viewer = osgViewer.Viewer() # add all the camera manipulators keyswitchManipulator = osgGA.KeySwitchMatrixManipulator() keyswitchManipulator.addMatrixManipulator( ord("1"), "Trackball", osgGA.TrackballManipulator() ) keyswitchManipulator.addMatrixManipulator( ord("2"), "Flight", osgGA.FlightManipulator() ) keyswitchManipulator.addMatrixManipulator( ord("3"), "Drive", osgGA.DriveManipulator() ) num = keyswitchManipulator.getNumMatrixManipulators() keyswitchManipulator.addMatrixManipulator( ord("4"), "Terrain", osgGA.TerrainManipulator() ) pathfile = str() keyForAnimationPath = ord("5") while arguments.read("-p",pathfile) : apm = osgGA.AnimationPathManipulator(pathfile) if apm or not apm.valid() : num = keyswitchManipulator.getNumMatrixManipulators() keyswitchManipulator.addMatrixManipulator( keyForAnimationPath, "Path", apm ) ++keyForAnimationPath keyswitchManipulator.selectMatrixManipulator(num) viewer.setCameraManipulator( keyswitchManipulator ) # add the handler for doing the picking viewer.addEventHandler(PickHandler(updateText)) # set the scene to render viewer.setSceneData(group) return viewer.run()
_lastAdd = float() _addSeconds = float() MakePathTimeCallback(osg.Geode* geode): _geode(geode), _lastAdd(0.0), _addSeconds(0.08) virtual void operator()(osg.Node* node, osg.NodeVisitor* nv) t = osg.Timer.instance().delta_s(_startTime, _currentTime) if _lastAdd + _addSeconds <= t and t <= 8.0 : pos = osg.Vec3() _sampler.getValueAt(t, pos) _geode.addDrawable(osg.ShapeDrawable(osg.Sphere(pos, 0.5))) _geode.dirtyBound() _lastAdd += _addSeconds AnimtkUpdateCallback.operator()(node, nv) # This will give great results if you DO NOT have VSYNC enabled and can generate # decent FPS. class MakePathDistanceCallback (AnimtkUpdateCallback) : _geode = osg.Geode() _lastAdd = osg.Vec3() _threshold = float() _count = unsigned int() MakePathDistanceCallback(osg.Geode* geode):
AnimateCallback(Operation op) : _operation(op) virtual void operator() ( osg.Uniform* uniform, osg.NodeVisitor* nv ) angle = 2.0 * nv.getFrameStamp().getSimulationTime() sine = sinf( angle ) # -1 . 1 switch(_operation) case SIN : uniform.set( sine ) break _operation = Operation() int main(int, char **) # construct the viewer. viewer = osgViewer.Viewer() # use a geode with a Box ShapeDrawable basicModel = osg.Geode() basicModel.addDrawable(osg.ShapeDrawable(osg.Box(osg.Vec3(0.0,0.0,0.0),1.0))) # create the "blocky" shader, a simple animation test ss = basicModel.getOrCreateStateSet() program = osg.Program() program.setName( "blocky" ) program.addShader( osg.Shader( osg.Shader.VERTEX, blockyVertSource ) ) program.addShader( osg.Shader( osg.Shader.FRAGMENT, blockyFragSource ) ) ss.setAttributeAndModes(program, osg.StateAttribute.ON) # attach some animated Uniform variable to the state set SineUniform = osg.Uniform( "Sine", 0.0 ) ss.addUniform( SineUniform ) SineUniform.setUpdateCallback(AnimateCallback(AnimateCallback.SIN)) # run the osg.Viewer using our model
"varying vec4 color\n" "void main(void)\n" "\n" " gl_FragColor = clamp( color, 0.0, 1.0 )\n" "\n" #####################################/ static osg.Group rootNode # Create some geometry upon which to render GLSL shaders. static osg.Geode* CreateModel() geode = osg.Geode() geode.addDrawable(osg.ShapeDrawable(osg.Sphere(osg.Vec3(0.0,0.0,0.0),1.0))) geode.addDrawable(osg.ShapeDrawable(osg.Cone(osg.Vec3(2.2,0.0,-0.4),0.9,1.8))) geode.addDrawable(osg.ShapeDrawable(osg.Cylinder(osg.Vec3(4.4,0.0,0.0),1.0,1.4))) return geode # Add a reference to the masterModel at the specified translation, and # return its StateSet so we can easily attach StateAttributes. static osg.StateSet* ModelInstance() static float zvalue = 0.0 static osg.Node* masterModel = CreateModel() xform = osg.PositionAttitudeTransform() xform.setPosition(osg.Vec3( 0.0, -1.0, zvalue )) zvalue = zvalue + 2.2 xform.addChild(masterModel)
osg.MatrixTransform* SolarSystem.createTranslationAndTilt( double #translation, double tilt ) moonPositioned = osg.MatrixTransform() moonPositioned.setMatrix(osg.Matrix.translate(osg.Vec3( 0.0, _RorbitMoon, 0.0 ) )* osg.Matrix.scale(1.0, 1.0, 1.0)* osg.Matrix.rotate(osg.inDegrees( tilt ),0.0,0.0,1.0)) return moonPositioned # end SolarSystem.createTranslationAndTilt osg.Geode* SolarSystem.createSpace( str name, str textureName ) spaceSphere = osg.Sphere( osg.Vec3( 0.0, 0.0, 0.0 ), _radiusSpace ) sSpaceSphere = osg.ShapeDrawable( spaceSphere ) if not textureName.empty() : image = osgDB.readImageFile( textureName ) if image : sSpaceSphere.getOrCreateStateSet().setTextureAttributeAndModes( 0, osg.Texture2D( image ), osg.StateAttribute.ON ) # reset the object color to white to allow the texture to set the colour. sSpaceSphere.setColor( osg.Vec4(1.0,1.0,1.0,1.0) ) geodeSpace = osg.Geode() geodeSpace.setName( name ) geodeSpace.addDrawable( sSpaceSphere ) return( geodeSpace )
def createDemoScene(fixedSizeInScreen): root = osg.Group() geode_1 = osg.Geode() transform_1 = osg.MatrixTransform() geode_2 = osg.Geode() transform_2 = osg.MatrixTransform() geode_3 = osg.Geode() transform_3 = osg.MatrixTransform() geode_4 = osg.Geode() transform_4 = osg.MatrixTransform() geode_5 = osg.Geode() transform_5 = osg.MatrixTransform() geode_6 = osg.Geode() transform_6 = osg.MatrixTransform() geode_7 = osg.Geode() transform_7 = osg.MatrixTransform() radius = 0.8 height = 1.0 hints = osg.TessellationHints() hints.setDetailRatio(2.0) shape = osg.ShapeDrawable() shape = osg.ShapeDrawable(osg.Box(osg.Vec3(0.0, 0.0, -2.0), 10, 10.0, 0.1), hints) shape.setColor(osg.Vec4(0.5, 0.5, 0.7, 1.0)) geode_1.addDrawable(shape) shape = osg.ShapeDrawable(osg.Cylinder(osg.Vec3(0.0, 0.0, 0.0), radius * 2,radius), hints) shape.setColor(osg.Vec4(0.8, 0.8, 0.8, 1.0)) geode_2.addDrawable(shape) shape = osg.ShapeDrawable(osg.Cylinder(osg.Vec3(-3.0, 0.0, 0.0), radius,radius), hints) shape.setColor(osg.Vec4(0.6, 0.8, 0.8, 1.0)) geode_3.addDrawable(shape) shape = osg.ShapeDrawable(osg.Cone(osg.Vec3(3.0, 0.0, 0.0), 2 * radius,radius), hints) shape.setColor(osg.Vec4(0.4, 0.9, 0.3, 1.0)) geode_4.addDrawable(shape) shape = osg.ShapeDrawable(osg.Cone(osg.Vec3(0.0, -3.0, 0.0), radius, height), hints) shape.setColor(osg.Vec4(0.2, 0.5, 0.7, 1.0)) geode_5.addDrawable(shape) shape = osg.ShapeDrawable(osg.Cylinder(osg.Vec3(0.0, 3.0, 0.0), radius, height), hints) shape.setColor(osg.Vec4(1.0, 0.3, 0.3, 1.0)) geode_6.addDrawable(shape) shape = osg.ShapeDrawable(osg.Cone(osg.Vec3(0.0, 0.0, 3.0), 2.0, 2.0), hints) shape.setColor(osg.Vec4(0.8, 0.8, 0.4, 1.0)) geode_7.addDrawable(shape) # material matirial = osg.Material() matirial.setColorMode(osg.Material.DIFFUSE) matirial.setAmbient(osg.Material.FRONT_AND_BACK, osg.Vec4(0, 0, 0, 1)) matirial.setSpecular(osg.Material.FRONT_AND_BACK, osg.Vec4(1, 1, 1, 1)) matirial.setShininess(osg.Material.FRONT_AND_BACK, 64.0) root.getOrCreateStateSet().setAttributeAndModes(matirial, osg.StateAttribute.ON) transform_1.addChild(addDraggerToScene(geode_1,"TabBoxDragger",fixedSizeInScreen)) transform_2.addChild(addDraggerToScene(geode_2,"TabPlaneDragger",fixedSizeInScreen)) transform_3.addChild(addDraggerToScene(geode_3,"TabBoxTrackballDragger",fixedSizeInScreen)) transform_4.addChild(addDraggerToScene(geode_4,"TrackballDragger",fixedSizeInScreen)) transform_5.addChild(addDraggerToScene(geode_5,"Translate1DDragger",fixedSizeInScreen)) transform_6.addChild(addDraggerToScene(geode_6,"Translate2DDragger",fixedSizeInScreen)) transform_7.addChild(addDraggerToScene(geode_7,"TranslateAxisDragger",fixedSizeInScreen)) root.addChild(transform_1) root.addChild(transform_2) root.addChild(transform_3) root.addChild(transform_4) root.addChild(transform_5) root.addChild(transform_6) root.addChild(transform_7) return root
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 hieghtScale = radius*0.5/(maxHeight-minHeight) hieghtOffset = -(minHeight+maxHeight)*0.5 for(r=0r<39++r) for(unsigned int c=0c<38++c) h = vertex[r+c*39][2] grid.setHeight(c,r,(h+hieghtOffset)*hieghtScale) geode.addDrawable(osg.ShapeDrawable(grid)) group = osg.Group() group.addChild(geode) return group def createMovingModel(center, radius): animationLength = 10.0 animationPath = createAnimationPath(center,radius,animationLength) model = osg.Group()
# use an ArgumentParser object to manage the program arguments. arguments = osg.ArgumentParser(argv) # construct the viewer. viewer = osgViewer.Viewer() rootnode = osg.Group() rootnode.addChild(createSkyBox()) # load the nodes from the commandline arguments. model = osgDB.readNodeFiles(arguments) if not model : radius = 1.0 geode = osg.Geode() geode.addDrawable(osg.ShapeDrawable(osg.Sphere(osg.Vec3(0.0,0.0,0.0),radius))) model = geode # run optimization over the scene graph optimzer = osgUtil.Optimizer() optimzer.optimize(model) # create normals. smoother = osgUtil.SmoothingVisitor() model.accept(smoother) rootnode.addChild( addRefractStateSet(model) ) # add a viewport to the viewer and attach the scene graph. viewer.setSceneData(rootnode)