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 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 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 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 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 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
_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):
"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)
return rotation # end SolarSystem.createEarthRotation 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 )
# 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)
def main(): viewer = osgViewer.Viewer() # Declare a group to act as root node of a scene: root = osg.Group() # Declare a box class (derived from shape class) instance # This constructor takes an osg.Vec3 to define the center # and a float to define the height, width and depth. # (an overloaded constructor allows you to specify unique # height, width and height values.) unitCube = osg.Box( osg.Vec3(0,0,0), 1.0) unitCube.setDataVariance(osg.Object.DYNAMIC) # Declare an instance of the shape drawable class and initialize # it with the unitCube shape we created above. # This class is derived from 'drawable' so instances of this # class can be added to Geode instances. unitCubeDrawable = osg.ShapeDrawable(unitCube) # Declare a instance of the geode class: basicShapesGeode = osg.Geode() # Add the unit cube drawable to the geode: basicShapesGeode.addDrawable(unitCubeDrawable) # Add the goede to the scene: root.addChild(basicShapesGeode) unitSphere = osg.Sphere( osg.Vec3(0,0,0), 1.0) unitSphereDrawable = osg.ShapeDrawable(unitSphere) unitSphereDrawable.setColor( osg.Vec4(0.1, 0.1, 0.1, 0.1) ) unitSphereXForm = osg.PositionAttitudeTransform() unitSphereXForm.setPosition(osg.Vec3(3.0,0,0)) unitSphereGeode = osg.Geode() root.addChild(unitSphereXForm) unitSphereXForm.addChild(unitSphereGeode) unitSphereGeode.addDrawable(unitSphereDrawable) pyramidGeode = createPyramid() pyramidXForm = osg.PositionAttitudeTransform() pyramidXForm.setPosition(osg.Vec3(0,-3.0,0)) root.addChild(pyramidXForm) pyramidXForm.addChild(pyramidGeode) KLN89FaceTexture = osg.Texture2D() # protect from being optimized away as static state: KLN89FaceTexture.setDataVariance(osg.Object.DYNAMIC) klnFace = osgDB.readImageFile("../NPS_Data/Textures/KLN89FaceB.tga") if klnFace is None: print " couldn't find texture, quitting." sys.exit(-1) KLN89FaceTexture.setImage(klnFace) # Declare a state set for 'BLEND' texture mode blendStateSet = osg.StateSet() # Declare a TexEnv instance, set the mode to 'BLEND' blendTexEnv = osg.TexEnv() blendTexEnv.setMode(osg.TexEnv.BLEND) # Turn the attribute of texture 0 'ON' blendStateSet.setTextureAttributeAndModes(0,KLN89FaceTexture,osg.StateAttribute.ON) # Set the texture texture environment for texture 0 to the # texture envirnoment we declared above: blendStateSet.setTextureAttribute(0,blendTexEnv) decalStateSet = osg.StateSet() decalTexEnv = osg.TexEnv() decalTexEnv.setMode(osg.TexEnv.DECAL) decalStateSet.setTextureAttributeAndModes(0,KLN89FaceTexture,osg.StateAttribute.ON) decalStateSet.setTextureAttribute(0,decalTexEnv) root.setStateSet(blendStateSet) unitSphereGeode.setStateSet(decalStateSet) # OSG1 viewer.setUpViewer(osgProducer.Viewer.STANDARD_SETTINGS) viewer.setSceneData( root ) viewer.setCameraManipulator(osgGA.TrackballManipulator()) viewer.realize() while not viewer.done(): viewer.frame() return 0
geode = osg.Geode() geode.addDrawable(explosion.getParticleSystem()) geode.addDrawable(explosionDebri.getParticleSystem()) geode.addDrawable(smoke.getParticleSystem()) geode.addDrawable(fire.getParticleSystem()) root.addChild(geode) else: # when we don't have moving models we can simple insert the particle effect into the root of the scene graph osg.notify(osg.INFO), "PickHandler.pick(,) adding particle effects to root node." root.addChild(effectsGroup) #if 0 geode = osg.Geode() geode.addDrawable(osg.ShapeDrawable(osg.Sphere(position,scale))) group.addChild(geode) #endif virtual ~PickHandler() # function used in debugging def insertParticle(root, center, radius): handleMovingModels = False position = center + osg.Vec3( radius * (((float)rand() / (float)RAND_MAX)-0.5)*2.0, radius * (((float)rand() / (float)RAND_MAX)-0.5)*2.0, 0.0)
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()
geode = osg.Geode() stateset = geode.getOrCreateStateSet() image = osgDB.readImageFile("Images/land_shallow_topo_2048.jpg") if image : texture = osg.Texture2D() texture.setImage(image) texture.setMaxAnisotropy(8) stateset.setTextureAttributeAndModes(0,texture,osg.StateAttribute.ON) material = osg.Material() stateset.setAttribute(material) # the globe geode.addDrawable(osg.ShapeDrawable(osg.Sphere(bb.center(),bb.radius()*ratio))) xform.addChild(geode) return xform osg. Node* createBox( osg.BoundingBox bb,float chordRatio) geode = osg.Geode() white = osg.Vec4(1.0,1.0,1.0,1.0) # front faces. geode.addDrawable(createWing(bb.corner(4),bb.corner(6),bb.corner(7),chordRatio,white)) geode.addDrawable(createWing(bb.corner(7),bb.corner(5),bb.corner(4),chordRatio,white)) geode.addDrawable(createWing(bb.corner(4),bb.corner(5),bb.corner(1),chordRatio,white))
def main(argv): arguments = osg.ArgumentParser(argv) viewer = osgViewer.Viewer(arguments) fontFile = str("arial.ttf") while arguments.read("-f",fontFile) : font = osgText.readFontFile(fontFile) if not font : return 1 OSG_NOTICE, "Read font ", fontFile, " font=", font word = str("This is a test.")() while arguments.read("-w",word) : style = osgText.Style() thickness = 0.1 while arguments.read("--thickness",thickness) : style.setThicknessRatio(thickness) # set up any bevel if required r = float() bevel = osgText.Bevel() while arguments.read("--rounded",r) : bevel = osgText.Bevel() bevel.roundedBevel2(r) while arguments.read("--rounded") : bevel = osgText.Bevel() bevel.roundedBevel2(0.25) while arguments.read("--flat",r) : bevel = osgText.Bevel() bevel.flatBevel(r) while arguments.read("--flat") : bevel = osgText.Bevel() bevel.flatBevel(0.25) while arguments.read("--bevel-thickness",r) : if bevel.valid() : bevel.setBevelThickness(r) style.setBevel(bevel) # set up outline. while arguments.read("--outline",r) : style.setOutlineRatio(r) viewer.addEventHandler( osgGA.StateSetManipulator(viewer.getCamera().getOrCreateStateSet()) ) viewer.addEventHandler(osgViewer.StatsHandler)() #if 1 group = osg.Group() characterSize = 1.0 while arguments.read("--size",characterSize) : if arguments.read("--2d") : text2D = osgText.Text() text2D.setFont(font) text2D.setCharacterSize(characterSize) text2D.setFontResolution(256,256) text2D.setDrawMode(osgText.Text.TEXT | osgText.Text.BOUNDINGBOX) text2D.setAxisAlignment(osgText.Text.XZ_PLANE) text2D.setText(word) geode = osg.Geode() geode.addDrawable(text2D) group.addChild(geode) if arguments.read("--TextNode") : # experimental text node text = osgText.TextNode() text.setFont(font) text.setStyle(style) text.setTextTechnique(osgText.TextTechnique)() text.setText(word) text.update() group.addChild(text) elif not arguments.read("--no-3d") : text3D = osgText.Text3D() text3D.setFont(font) text3D.setStyle(style) text3D.setCharacterSize(characterSize) text3D.setDrawMode(osgText.Text3D.TEXT | osgText.Text3D.BOUNDINGBOX) text3D.setAxisAlignment(osgText.Text3D.XZ_PLANE) text3D.setText(word) geode = osg.Geode() geode.addDrawable(text3D) group.addChild(geode) color = osg.Vec4(1.0, 1.0, 1.0, 1.0) while arguments.read("--color",color.r(),color.g(),color.b(),color.a()) : OSG_NOTICE, "--color ", color text3D.setColor(color) imageFilename = str() while arguments.read("--image",imageFilename) : OSG_NOTICE, "--image ", imageFilename image = osgDB.readImageFile(imageFilename) if image.valid() : OSG_NOTICE, " loaded image ", imageFilename stateset = text3D.getOrCreateStateSet() stateset.setTextureAttributeAndModes(0, osg.Texture2D(image), osg.StateAttribute.ON) while arguments.read("--wall-color",color.r(),color.g(),color.b(),color.a()) : stateset = text3D.getOrCreateWallStateSet() material = osg.Material() material.setDiffuse(osg.Material.FRONT_AND_BACK, color) stateset.setAttribute(material) while arguments.read("--wall-image",imageFilename) : image = osgDB.readImageFile(imageFilename) if image.valid() : stateset = text3D.getOrCreateWallStateSet() stateset.setTextureAttributeAndModes(0, osg.Texture2D(image), osg.StateAttribute.ON) while arguments.read("--back-color",color.r(),color.g(),color.b(),color.a()) : stateset = text3D.getOrCreateBackStateSet() material = osg.Material() material.setDiffuse(osg.Material.FRONT_AND_BACK, color) stateset.setAttribute(material) while arguments.read("--back-image",imageFilename) : image = osgDB.readImageFile(imageFilename) if image.valid() : stateset = text3D.getOrCreateBackStateSet() stateset.setTextureAttributeAndModes(0, osg.Texture2D(image), osg.StateAttribute.ON) if arguments.read("--size-quad") : geode.addDrawable( osg.createTexturedQuadGeometry(osg.Vec3(0.0,characterSize*thickness,0.0),osg.Vec3(characterSize,0.0,0.0),osg.Vec3(0.0,0.0,characterSize), 0.0, 0.0, 1.0, 1.0) ) viewer.setSceneData(group) #endif return viewer.run() # Translated from file 'osgtext3D_orig.cpp' # OpenSceneGraph example, osgtext. #* #* Permission is hereby granted, free of charge, to any person obtaining a copy #* of this software and associated documentation files (the "Software"), to deal #* in the Software without restriction, including without limitation the rights #* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell #* copies of the Software, and to permit persons to whom the Software is #* furnished to do so, subject to the following conditions: #* #* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE #* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, #* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN #* THE SOFTWARE. # #include <osgViewer/Viewer> #include <osgViewer/ViewerEventHandlers> #include <osgDB/ReadFile> #include <osgGA/TrackballManipulator> #include <osgGA/StateSetManipulator> #include <osg/Geode> #include <osg/Geometry> #include <osg/Material> #include <osg/Shape> #include <osg/ShapeDrawable> #include <osgText/Text3D> #include <iostream> #include <sstream> # create text which sits in 3D space such as would be inserted into a normal model def create3DText(center, radius): geode = osg.Geode() #################################################### # # Examples of how to set up axis/orientation alignments # characterSize = radius*0.2 characterDepth = characterSize*0.2 pos = osg.Vec3(center.x()-radius*.5,center.y()-radius*.5,center.z()-radius*.5) text1 = osgText.Text3D() text1.setFont("fonts/arial.ttf") text1.setCharacterSize(characterSize) text1.setCharacterDepth(characterDepth) text1.setPosition(pos) text1.setDrawMode(osgText.Text3D.TEXT | osgText.Text3D.BOUNDINGBOX) text1.setAxisAlignment(osgText.Text3D.XY_PLANE) text1.setText("XY_PLANE") geode.addDrawable(text1) text2 = osgText.Text3D() text2.setFont("fonts/times.ttf") text2.setCharacterSize(characterSize) text2.setCharacterDepth(characterDepth) text2.setPosition(pos) text2.setDrawMode(osgText.Text3D.TEXT | osgText.Text3D.BOUNDINGBOX) text2.setAxisAlignment(osgText.Text3D.YZ_PLANE) text2.setText("YZ_PLANE") geode.addDrawable(text2) 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("XZ_PLANE") geode.addDrawable(text3) style = osgText.Style() bevel = osgText.Bevel() bevel.roundedBevel2(0.25) style.setBevel(bevel) style.setWidthRatio(0.4) text7 = osgText.Text3D() text7.setFont("fonts/times.ttf") text7.setStyle(style) text7.setCharacterSize(characterSize) text7.setCharacterDepth(characterSize*0.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("CharacterSizeMode OBJECT_COORDS (default)") geode.addDrawable(text7) 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) 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) return rootNode int main_orig(int, char**) viewer = osgViewer.Viewer() center = osg.Vec3(0.0,0.0,0.0) radius = 1.0 root = osg.Group() root.addChild(create3DText(center, radius)) viewer.setSceneData(root) viewer.setCameraManipulator(osgGA.TrackballManipulator()) viewer.addEventHandler( osgGA.StateSetManipulator(viewer.getCamera().getOrCreateStateSet()) ) viewer.addEventHandler(osgViewer.ThreadingHandler)() viewer.addEventHandler(osgViewer.WindowSizeHandler)() viewer.addEventHandler(osgViewer.StatsHandler)() viewer.run() return 0 # Translated from file 'osgtext3D_test.cpp' #include <osgViewer/Viewer> #include <osgViewer/ViewerEventHandlers> #include <osgDB/ReadFile> #include <osgGA/TrackballManipulator> #include <osgGA/StateSetManipulator> #include <osg/Geode> #include <osg/Geometry> #include <osg/Material> #include <osg/Shape> #include <osg/ShapeDrawable> #include <osgText/Text3D> #include <iostream> #include <sstream> 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 ##################################### #include <osg/PositionAttitudeTransform> #include <osg/ShapeDrawable> class CInputHandler (osgGA.GUIEventHandler) : CInputHandler( osg.PositionAttitudeTransform* pPatSphere ) m_rPatSphere = pPatSphere def handle(ea, aa, pObject, pNodeVisitor): pViewer = dynamic_cast<osgViewer.Viewer*>(aa) if not pViewer : return False if ea.getEventType()==osgGA.GUIEventAdapter.PUSH : cams = osgViewer.ViewerBase.Cameras() pViewer.getCameras( cams ) x = ea.getXnormalized() y = ea.getYnormalized() picker = osgUtil.LineSegmentIntersector( osgUtil.Intersector.PROJECTION, x, y ) iv = osgUtil.IntersectionVisitor( picker ) cams[0].accept( iv ) if picker.containsIntersections() : intersection = picker.getFirstIntersection() v = intersection.getWorldIntersectPoint() m_rPatSphere.setPosition( v ) return True # return True, event handled return False m_rPatSphere = osg.PositionAttitudeTransform() ##################################### int main_test(int, char**) viewer = osgViewer.Viewer() viewer.setUpViewInWindow(99,99,666,666, 0) rPat = osg.PositionAttitudeTransform() # add the handler to the viewer viewer.addEventHandler( CInputHandler(rPat) ) # create a group to contain our scene and sphere pGroup = osg.Group() # create sphere pGeodeSphere = osg.Geode() pGeodeSphere.addDrawable( osg.ShapeDrawable( osg.Sphere(osg.Vec3(0.0,0.0,0.0),0.01) ) ) rPat.addChild( pGeodeSphere ) pGroup.addChild( rPat ) center = osg.Vec3(0.0,0.0,0.0) radius = 1.0 root = osg.Group() root.addChild(test_create3DText(center, radius)) #viewer.setSceneData(root) pGroup.addChild(root) viewer.setSceneData(pGroup) viewer.setCameraManipulator(osgGA.TrackballManipulator()) viewer.addEventHandler( osgGA.StateSetManipulator(viewer.getCamera().getOrCreateStateSet()) ) viewer.addEventHandler(osgViewer.ThreadingHandler)() viewer.addEventHandler(osgViewer.WindowSizeHandler)() viewer.addEventHandler(osgViewer.StatsHandler)() return viewer.run() # Translated from file 'TextNode.cpp' # -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 Robert Osfield # * # * This library is open source and may be redistributed and/or modified under # * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or # * (at your option) any later version. The full license is in LICENSE file # * included with this distribution, and on the openscenegraph.org website. # * # * This library is distributed in the hope that it will be useful, # * but WITHOUT ANY WARRANTY without even the implied warranty of # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # * OpenSceneGraph Public License for more details. # #include "TextNode.h" #include "../../src/osgText/GlyphGeometry.h" #include <osg/PositionAttitudeTransform> #include <osg/Geode> #include <osgUtil/SmoothingVisitor> #include <osg/io_utils> using namespace osgText ############################################/ # # Layout # Layout.Layout() Layout.Layout( Layout layout, osg.CopyOp copyop): osg.Object(layout,copyop)
def create3DText(center, radius): geode = osg.Geode() #################################################### # # Examples of how to set up axis/orientation alignments # characterSize = radius*0.2 characterDepth = characterSize*0.2 pos = osg.Vec3(center.x()-radius*.5,center.y()-radius*.5,center.z()-radius*.5) text1 = osgText.Text3D() text1.setFont("fonts/arial.ttf") text1.setCharacterSize(characterSize) text1.setCharacterDepth(characterDepth) text1.setPosition(pos) text1.setDrawMode(osgText.Text3D.TEXT | osgText.Text3D.BOUNDINGBOX) text1.setAxisAlignment(osgText.Text3D.XY_PLANE) text1.setText("XY_PLANE") geode.addDrawable(text1) text2 = osgText.Text3D() text2.setFont("fonts/times.ttf") text2.setCharacterSize(characterSize) text2.setCharacterDepth(characterDepth) text2.setPosition(pos) text2.setDrawMode(osgText.Text3D.TEXT | osgText.Text3D.BOUNDINGBOX) text2.setAxisAlignment(osgText.Text3D.YZ_PLANE) text2.setText("YZ_PLANE") geode.addDrawable(text2) 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("XZ_PLANE") geode.addDrawable(text3) style = osgText.Style() bevel = osgText.Bevel() bevel.roundedBevel2(0.25) style.setBevel(bevel) style.setWidthRatio(0.4) text7 = osgText.Text3D() text7.setFont("fonts/times.ttf") text7.setStyle(style) text7.setCharacterSize(characterSize) text7.setCharacterDepth(characterSize*0.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("CharacterSizeMode OBJECT_COORDS (default)") geode.addDrawable(text7) 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) 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) return rootNode
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
#include <osg/ShapeDrawable> #include <osg/Material> extern osg.Node * CreateSimpleHierarchy( osg.Node * model ) extern osg.Node * CreateAdvancedHierarchy( osg.Node * model ) ######################################## osg.Node * CreateGlobe( void ) # File not found - create textured sphere geode = osg.Geode() hints = osg.TessellationHints() hints.setDetailRatio( 0.3 ) #if 1 shape = osg.ShapeDrawable ( osg.Sphere(osg.Vec3(0.0, 0.0, 0.0), 4.0 ), hints ) #else: shape = osg.ShapeDrawable ( osg.Box( osg.Vec3(-1.0, -1.0, -1.0), 2.0, 2.0, 2.0 ) ) #endif shape.setColor(osg.Vec4(0.8, 0.8, 0.8, 1.0)) geode.addDrawable( shape ) stateSet = osg.StateSet() texture = osg.Texture2D( osgDB.readImageFile("Images/land_shallow_topo_2048.jpg") )