/
OpenSceneGraph Katia Oleinik:  koleinik@bu.edu OpenSceneGraph Katia Oleinik:  koleinik@bu.edu

OpenSceneGraph Katia Oleinik: koleinik@bu.edu - PowerPoint Presentation

genevieve
genevieve . @genevieve
Follow
27 views
Uploaded On 2024-02-03

OpenSceneGraph Katia Oleinik: koleinik@bu.edu - PPT Presentation

based on materials from httpwwwopenscenegraphorg Agenda Introduction to OpenSceneGraph Hardware requirements Overview of OSG structure First example displaying a model Building primitives ID: 1044678

cone osg geode push osg cone push geode texture viewer root create node arrow addchild openscenegraph group lod matrix

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "OpenSceneGraph Katia Oleinik: koleinik@..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

1. OpenSceneGraphKatia Oleinik: koleinik@bu.edubased on materials from http://www.openscenegraph.org/

2. Agenda:Introduction to OpenSceneGraphHardware requirementsOverview of OSG structureFirst example – displaying a modelBuilding primitivesTransformationsUsing OpenGL primitivesTextureSpecial nodes

3. Introduction to OpenSceneGraphOpenSceneGraph an open source 3D graphics API (application programming interface)used for - visual simulation, - computer games, - scientific visualization, - modeling, - training, etc.

4. OpenSceneGraph written in C++ (encourages object oriented programming);runs on a number of operating systems, including: - MS Windows - Max OS X - Linux - IRIX - Solaris - Sony Playstationuses OpenGL for rendering (allows for high performance graphics);supports the standard template library (STL);Introduction to OpenSceneGraph

5. OpenSceneGraph 3.0 Features:Support for performance increasing featuresView frustum, small feature and occlusion cullingLevel of detail (LOD)State sorting and lazy state updatingOpenGL latest extensionsMulti-threading and database optimizationSupport for OpenGL, from 1.1 through 2.0 including the latest extensionsSupport for OpenGL Shading LanguageSupport for a wide range of 2D image and 3D database formatsLoaders available for OpenFlight, TerraPage, OBJ, 3DS, JPEG, PNG and GeoTIFFParticle effectsSupport for anti-aliased TrueType textMulti-threaded and configurable support for multiple CPU/multiple GPU machinesIntroduction to OpenSceneGraph

6. OpenSceneGraph 3.0 latest updates:Support for Windows MS Visual StudioSupport for Android on tablets and phonesSupport for IOS (iPhone OS) on tablets and phonesImprovements to osgVolume class enabling high quality volume renderingIntroduction to OpenSceneGraph

7. FightGear Flight Simulator

8. FightGear Flight Simulator

9. FightGear Flight Simulator

10.

11.

12. Hardware requirementsProcessorOSG runs on most contemporary CPUs. OSG is thread-safe and can take advantage of multi-processor and dual core architectures. OSG runs on both 32- and 64-bit processors.GraphicsOSG requires graphics hardware with robust OpenGL support256 MB of graphics RAM – good starting pointRAM1GB – good enough for many application, but you might need more, depending on your datasetDiscDepends on your data requirements

13. Overview of OSG structure

14. MatrixMatrixOverview of OSG structure

15. First example – displaying a modelex_simple_viewer.cpp// load the nodes from the command line arguments.osg::Node* model = osgDB::readNodeFile(argv[1]);// initialize the viewer and set the scene to render osgViewer::Viewer viewer;viewer.setSceneData(model);// run viewerreturn viewer.run();Root Node

16. First example – displaying a modelex_simple_viewer.cpp: compiling, linking and runningTo compile and link% make ex_simple_viewerTo run the viewer% ex_simple_viewer cow.objFirst button – rotate the modelSecond button – translateThird button – scalePress “q” (“Esc” for Windows) button to exit

17. First example – displaying a modelex_viewer_args.cpp// call argument parserosg::ArgumentParser arguments (&argc, argv);std::string filename;// define the argument line optionarguments.read("--model", filename);// load the nodes from the command line argumentsosg::Node* model = osgDB::readNodeFile(filename);

18. First example – displaying a modelex_viewer_args.cpp: runningTo compile and link% make ex_viewer_argsTo run the viewer% ex_viewer_args –-model cow.objTry a few different models:dumptruck.osgteapot.osg

19. First example – displaying a modelInput OSG model file structureGeode { name "teapot.osg" nodeMask 0xffffffff cullingActive TRUE num_drawables 1 Geometry { DataVariance STATIC useDisplayList FALSE useVertexBufferObjects TRUE PrimitiveSets 1 { DrawArrays TRIANGLES 0 9744 } VertexArray Vec3Array 9744 { 0.367875 -0 0.237053 0.375 -0 0.225 0.365248 0.086895 0.225 ..... } ColorBinding OVERALL ColorArray Vec4Array 1 { 1 1 1 1 } }}

20. Building geometric primitivesex_simple_cone.cpp// Create a vector to represent the "center of the cone"Vec3 vcen(xcen, ycen, zcen);osg::Cone* cone = new Cone(vcen, radius, height);// Create a drawable object based on the coneosg::ShapeDrawable *drawable = new ShapeDrawable(cone);// create a new geode (root node)osg::Geode* geode = new Geode();geode->addDrawable(drawable);Root NodeGeodeDrawablecone

21. Building geometric primitivesImproving ex_simple_cone.cpp// Create a vector to represent the "center of the cone"osg:: Vec3 vcen(xcen, ycen, zcen);osg::Cone* cone = new Cone(vcen, radius, height);// Create a drawable object based on the coneosg:: ShapeDrawable *drawable = new ShapeDrawable(cone);drawable->setColor(osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f));// create a new geode osg:: Geode* geode = new Geode();geode->addDrawable(drawable);// create a root nodeosg::Group *root = new osg::Group();root->addChild(geode);Root NodeGeodeDrawablecone

22. Building geometric primitivesTo compile and link% make ex_simple_coneTo run the viewer% ex_simple_coneex_simple_cone.cpp

23. Building geometric primitivesOSG comes with a number of primitivesBoxSphereConeCylinderCapsuleSpecial shapes (e.g. InfinitePlane)ex_simple_cone.cpp

24. MatrixMatrixBuilding geometric primitivesex_arrow.cpp// Create a cone and a cylinderGeode *make_cone( float xcen, …){}Geode *make_cylinder( float xcen, …){}// create an arrow, as a transform node MatrixTransform* arrow = new MatrixTransform;arrow->setMatrix(Matrix::scale(1.0, 1.0, 1.0));arrow->addChild(cone); arrow->addChild(cylinder);// add the arrow to the upper transformMatrixTransform* mt = new MatrixTransform();mt->setMatrix( Matrix::rotate(inDegrees(30.0), 1.0, 0.0, 0.0));mt->addChild(arrow);// create a root nodeosg::Group *root = new osg::Group();root->addChild(mt);Root NodeconecylinderTransformTransform

25. Building geometric primitivesExercise Building 3 arrowsMatrixRoot NodeTransformMatrixconecylinderTransformMatrixconecylinderTransformMatrixconecylinderTransform

26. Building geometric primitivesExercise: Building 3 arrowsGroup *make_vec_arrow(float shaft_radius, float total_length, float r, float g, float b){ float cone_radius = 2*shaft_radius; float cone_height = cone_radius; float shaft_length = total_length - cone_height; osg::Geode *cylinder = make_cylinder(0.0, 0.0, shaft_length/2.0, shaft_radius, shaft_length, r,g,b,1.0); osg::Geode *cone = make_cone(0.0, 0.0, shaft_length + cone_height/4.0, cone_radius, cone_height, r, g, b, 1.0); osg::Group* vec_arrow = new Group; vec_arrow->addChild(cylinder); vec_arrow->addChild(cone); return vec_arrow;}osg::Group *red_arrow = make_vec_arrow(…);osg::MatrixTransform* xaxis = new MatrixTransform;xaxis->addChild(red_arrow);xaxis->setMatrix(…);

27. Building geometric primitivesReusing the geometryMatrixRoot NodeTransformMatrixTransformMatrixTransform MatrixTransformGeode 3Geode 2Geode 1GeometryVerticesFacesColors

28. Using OpenGL primitivesPrimitiveSet Class21430Points2143Lines43210LineStrip43210LineLoopPolygon01234Triangles012Quads3021024135TriangleStrip13570246QuadStrip0123456TriangleFan

29. Using OpenGL primitivesPrimitiveSet Classosg::Group *root = new osg::Group();…osg::Geode* primGeode = new osg::Geode();root->addChild(primGeode);…osg::Geometry* primGeom = new osg::Geometry();primGeode->addDrawable(primGeom);…viewer.setSceneData(root)

30. Using OpenGL primitivesPrimitiveSet Classosg::Vec3Array* pyramidVertices = new osg::Vec3Array;pyramidVertices->push_back( osg::Vec3( 0, 0, 0) ); // front left pyramidVertices->push_back( osg::Vec3(10, 0, 0) ); // front right pyramidVertices->push_back( osg::Vec3(10,10, 0) ); // back right pyramidVertices->push_back( osg::Vec3( 0,10, 0) ); // back left pyramidVertices->push_back( osg::Vec3( 5, 5,10) ); // peak// create primitives: quad for the baseosg::DrawElementsUInt* pyramidBase = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0);pyramidBase->push_back(3);pyramidBase->push_back(2);pyramidBase->push_back(1);pyramidBase->push_back(0);// create primitives: triangles for the sides osg::DrawElementsUInt* pyramidFaceOne = new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, 0);pyramidFaceOne->push_back(0);pyramidFaceOne->push_back(1);pyramidFaceOne->push_back(4);

31. Using OpenGL primitivesPrimitiveSet Class// assign all primitives to the Geometry nodeosg::Geometry* pyramidGeometry = new osg::Geometry();pyramidGeometry->setVertexArray( pyramidVertices );pyramidGeometry->addPrimitiveSet(pyramidBase);pyramidGeometry->addPrimitiveSet(pyramidFaceOne);pyramidGeometry->addPrimitiveSet(pyramidFaceTwo);pyramidGeometry->addPrimitiveSet(pyramidFaceThree);pyramidGeometry->addPrimitiveSet(pyramidFaceFour);// create a geode and add the geometry to the geodeosg::Geode* pyramidGeode = new osg::Geode();pyramidGeode->addDrawable(pyramidGeometry);// Create a root node and add the geodeosg::Group* root = new osg::Group();root->addChild(pyramidGeode);Root NodeGeodegeometry

32. Using OpenGL primitivesPrimitiveSet Class// create an array of colorsosg::Vec4Array* colors = new osg::Vec4Array;colors->push_back(osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f) ); //index 0 redcolors->push_back(osg::Vec4(0.0f, 1.0f, 0.0f, 1.0f) ); //index 1 greencolors->push_back(osg::Vec4(0.0f, 0.0f, 1.0f, 1.0f) ); //index 2 bluecolors->push_back(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f) ); //index 3 white// create an index arrayosg::TemplateIndexArray <unsigned int, osg::Array::UIntArrayType,4,4> *colorIndexArray;colorIndexArray = new osg::TemplateIndexArray<unsigned int, osg::Array::UIntArrayType,4,4>;colorIndexArray->push_back(0); // vertex 0 assigned color array element 0colorIndexArray->push_back(1); // vertex 1 assigned color array element 1colorIndexArray->push_back(2); // vertex 2 assigned color array element 2colorIndexArray->push_back(3); // vertex 3 assigned color array element 3colorIndexArray->push_back(0); // vertex 4 assigned color array element 0// assign the arrays to the geometrypyramidGeometry->setColorArray(colors);pyramidGeometry->setColorIndices(colorIndexArray);pyramidGeometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX);

33. TransformationsOSG allows for hierarchies of transformation node. Such structure makes it much easier to control the motions of each limb, part or the whole body.transformtransformtransformtransformgeodegeodegeodetransformtransformtransformtransformgeodegeodegeodegeodegeode

34. TransformationsOSG MatrixTransform Class:// direct transformation specificationtransform->getMatrix();transform->setMatrix();// set identityIdentity();// navigationosg::Matrix mt1 = osg::Matrix::Translate(x, y, z);osg::Matrix mt2 = osg::Matrix::Rotate(angle, x, y, z);osg::Matrix mt3 = osg::Matrix:: Scale(x, y, z);// for multiplying matricesosg::Matrix resultMat = mt1 * t2 * mt3;// invert matrixosg::Matrix::Invert();

35. AddingTexture// initialize texture classosg::Texture2D* texture = new osg::Texture2D;texture->setDataVariance(osg::Object::DYNAMIC); // load the texture image from the file: osg::Image* texImage = osgDB::readImageFile(texture_file);if (! texImage){ std::cout << " couldn't find texture, quiting." << std::endl; return -1;}// Assign the texture to the image we read from file: texture->setImage(texImage);// Create a new StateSet with default settings: osg::StateSet* stateTex = new osg::StateSet();// Assign texture unit 0 of our new StateSet to the texture // enable the texture.stateTex->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON);// Associate this state set with the Geode that contains// the primitive: geode->setStateSet(stateTex);Any file format supported by the plugins

36. AddingTexture// Add parsing texture option from a command line// call argument parserosg::ArgumentParser arguments (&argc, argv);std::string filename;// define the argument line optionarguments.read("--texture", texfilename);osg::Texture2D* texture = new osg::Texture2D;texture->setDataVariance(osg::Object::DYNAMIC); // load the texture image from the file: osg::Image* texImage = osgDB::readImageFile(texture_file);if (! texImage){ std::cout << " couldn't find texture, quiting." << std::endl; return -1;}…Exercise: Reading texture from the command line

37. Special NodesSwitch node - Node for switching between different states of an objectLOD node - Rendering Optimization nodeBillboard node – rendering optimization nodeText node – node for presenting text on the screen

38. Special NodesLOD (“level of detail” node - Rendering Optimization nodeThis node “switches” based on the distance from the viewer to the object.It works like a regular group node: load.addChild(detailedNode);Set the visible range from the viewer to the object: load.setRange(childNumber, near, far);

39. Special NodesLOD lod = new LOD();Lod.addChild(detailedNode);Lod.setRange(0, 0, 10);Lod.addChild(NotSodetailedNode);Lod.setRange(1, 10, 100);Lod.addChild(CorseNode);Lod.setRange(2, 100, 1000);Lod.addChild(NoDetailNode);Lod.setRange(2,1000,10000);

40. For up-to-date information on the project, in-depth details on how to compile and run libraries and examples, see the documentation on the OpenSceneGraph website: http://www.openscenegraph.org For support subscribe to OSG public mailing list: http://www.openscenegraph.org/projects/osg/wiki/MailingLists or forum: http://forum.openscenegraph.org

41. Contact me: Katia Oleinik: koleinik@bu.eduTutorial presentations and examples online:www.bu.edu/tech/research/training/presentations/list/Online evaluation:http://scv.bu.edu/survey/tutorial_evaluation.html

42. Autodesk MayaResourcesBU Scientific Computing and Visualization: http://www.bu.edu/tech/research/scv/OpenSceneGraph: http://www.openscenegraph.org/