#!/bin/env python import sys import math from PyOSG import Producer from PyOSG import osg from PyOSG import osgGA from PyOSG import osgUtil from PyOSG import osgProducer from PyOSG import osgDB from PyOSG import osgText from OpenGL.GL import * def createLabel(pos, size, label): geode = osg.Geode() timesFont = "fonts/arial.ttf" if 1: text = osgText.Text() geode.addDrawable( text ) text.setFont(timesFont) text.setPosition(pos) text.setCharacterSize(size) text.setAlignment(osgText.Text.CENTER_CENTER) text.setText(label) return geode def createLabel3(pos, size, label): geode = osg.Geode() timesFont = "fonts/arial.ttf" if 1: text = osgText.Text() geode.addDrawable( text ) text.setFont(timesFont) text.setPosition(pos) text.setFontResolution(40,40) text.setCharacterSize(size) text.setAlignment(osgText.Text.CENTER_CENTER) text.setAutoRotateToScreen(true) text.setCharacterSizeMode(osgText.Text.OBJECT_COORDS_WITH_MAXIMUM_SCREEN_SIZE_CAPPED_BY_FONT_HEIGHT) text.setText(label) return geode def createAxis(s, e, numReps, autoRotateMode, string): group = osg.Group() dv = e-s dv /= float(numReps-1) pos = s useAuto = True if useAuto: vertices = osg.Vec3Array() for i in range(numReps): at = osg.AutoTransform() at.setPosition(pos) at.setAutoRotateMode(autoRotateMode) at.addChild(createLabel(osg.Vec3(0.0,0.0,0.0),dv.length()*0.2,string)) vertices.push_back(pos) pos += dv group.addChild(at) colors = osg.Vec4Array() colors.push_back(osg.Vec4(1.0,1.0,1.0,1.0)) geom = osg.Geometry() geom.setVertexArray(vertices) geom.setColorArray(colors) geom.addPrimitiveSet(osg.DrawArrays(GL_LINE_STRIP,0,vertices.size())) geode = osg.Geode() geode.addDrawable(geom) group.addChild(geode) else: vertices = osg.Vec3Array for i in range(numReps): group.addChild(createLabel3(osg.Vec3(pos),dv.length()*0.5,string)) vertices.push_back(pos) pos += dv colors = osg.Vec4Array() colors.push_back(osg.Vec4(1.0,1.0,1.0,1.0)) geom = osg.Geometry() geom.setVertexArray(vertices) geom.setColorArray(colors) geom.addPrimitiveSet(osg.DrawArrays(GL_LINE_STRIP,0,vertices.size())) geode = osg.Geode() geode.addDrawable(geom) group.addChild(geode) return group def createScene(): root = osg.Group() # numReps = 3333 numReps = 10 root.addChild(createAxis(osg.Vec3(0.0,0.0,0.0),osg.Vec3(1000.0,0.0,0.0),numReps,osg.AutoTransform.ROTATE_TO_CAMERA,"ROTATE_TO_CAMERA")) root.addChild(createAxis(osg.Vec3(0.0,0.0,0.0),osg.Vec3(0.0,1000.0,0.0),numReps,osg.AutoTransform.ROTATE_TO_SCREEN,"ROTATE_TO_SCREEN")) root.addChild(createAxis(osg.Vec3(0.0,0.0,0.0),osg.Vec3(0.0,0.0,1000.0),numReps,osg.AutoTransform.NO_ROTATION,"NO_ROTATION")) return root def main(argv): # use an ArgumentParser object to manage the program arguments. arguments = osg.ArgumentParser(argv) # set up the usage document, in case we need to print out how to use this program. arguments.getApplicationUsage().setDescription(arguments.getApplicationName()+" is the standard OpenSceneGraph example which loads and visualises 3d models.") arguments.getApplicationUsage().setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...") arguments.getApplicationUsage().addCommandLineOption("-h or --help","Display this information") # construct the viewer. viewer = osgProducer.Viewer(arguments) # set up the value with sensible default event handlers. viewer.setUpViewer(osgProducer.Viewer.STANDARD_SETTINGS) # get details on keyboard and mouse bindings used by the viewer. viewer.getUsage(arguments.getApplicationUsage()) # if user request help write it out to cout. if arguments.read("-h") or arguments.read("--help"): arguments.getApplicationUsage().write() return 1 # any option left unread are converted into errors to write out later. arguments.reportRemainingOptionsAsUnrecognized() # report any errors if they have occured when parsing the program aguments. if arguments.errors(): arguments.writeErrorMessages(std.cout) return 1 # set the scene to render viewer.setSceneData(createScene()) # create the windows and run the threads. viewer.realize() while not viewer.done(): # wait for all cull and draw threads to complete. viewer.sync() # update the scene by traversing it with the the update visitor which will # call all node update callbacks and animations. viewer.update() # fire off the cull and draw traversals of the scene. viewer.frame() # wait for all cull and draw threads to complete before exit. viewer.sync() return 0 if __name__ == "__main__": main(sys.argv)