1 / 19

Open Scene Graph by Ray Wisman rwisman@ius

Open Scene Graph by Ray Wisman rwisman@ius.edu. with material from OpenSceneGraph Quick Start Guide by Paul Martz and Skew Matrix Software LLC http://www.lulu.com/items/volume_51/767000/767629/3/print/OSGQSG.pdf. Resources. Examples

Download Presentation

Open Scene Graph by Ray Wisman rwisman@ius

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Open Scene Graph by Ray Wisman rwisman@ius.edu with material from OpenSceneGraph Quick Start Guide by Paul Martz and Skew Matrix Software LLC http://www.lulu.com/items/volume_51/767000/767629/3/print/OSGQSG.pdf

  2. Resources • Examples • http://www.openscenegraph.org/projects/osg/wiki/Support/UserGuides/Examples • Tutorials • http://www.openscenegraph.org/projects/osg/wiki/Support/Tutorials • Online Texts • http://www.lulu.com/items/volume_51/767000/767629/3/print/OSGQSG.pdf

  3. Objectives • Introduce Open Scene Graph (OSG). • OSG is a set of open source libraries that primarily provide an API for scene management and graphics rendering optimization functionality to applications. • Install and verify. • Compile simple application similar to the text scene graph. • Discuss features applicable for project.

  4. OpenSceneGraph • OpenSceneGraph is a C++ scene graph API based on OpenGL. • Wide support on hardware/OS. • Most OSG-based applications are in the visualization and simulation industries. • OSG is found in nearly every field that employs 3D graphics, including GIS, CAD, modeling and digital content creation (DCC), database development, virtual reality, animation, gaming, and entertainment.

  5. Installing OSG • Binaries for OSG is available for many OS including Mac and Windows. • Binaries include precompiled libraries. • Windows and Mac are not always the most recent version. • OSG main page: http://www.openscenegraph.org/projects/osg • Windows binary: http://mew.cx/osg/

  6. Installing OSG Windows • Download the OSG Win32 Binaries .zip file for OSG. • After the download completes, extract the .zip file. Extracting creates a directory named OpenSceneGraph. • To set paths and file locations, edit the file in the extraction directory OpenSceneGraph\bin\OSG_ENVARS.bat, the line:REM set OSG_ROOT=C:\Program Files\OpenSceneGraph to the extraction location. Remove the REM. • Open a command prompt and execute:OSG_ENVARS osgshell

  7. Verify Installation of OSG Windows • Verify installation by opening a command shell prompt and entering: osgversion • To verify OSG can render enter: osglogo • Press esc key to exit.

  8. OSG viewer • OSG has a .osg file format for representing scene graphs. • .osg files can be viewed by the osgviewer. • To view the cow.osg (with the appropriate installation path): osgviewer C:\Apps\OpenSceneGraph\data\cow.osg • Holding the right button and moving the mouse allows panning around the scene. • Help displayed by: osgviewer --help-all

  9. Compiling OSG applicationsMicrosoft Visual Studio • Easiest to create an empty Windows console application. • Open Project Properties (assuming install to default directories) and change: • C/C++/General/Additional Include Directories property to: C:\Program Files\OpenSceneGraph\include • Linker/General/Additional Library Directories property to: C:\Program Files\OpenSceneGraph\lib • Linker/Input/Additional Dependencies use debug or release versions. Debug version libraries end with d. • For Debug build to:osgGAd.lib osgViewerd.lib osgDBd.lib osgUtild.lib osgd.lib • For Release build Linker/Input/Additional Dependencies to: osgGA.lib osgViewer.lib osgDB.lib osgUtil.lib osg.lib • For OpenGL add: glut32.lib opengl32.lib glu32.lib

  10. Key OSG Classes Node— The Node class is the base class for all nodes in the scene graph. It contains methods to facilitate scene graph traversals, culling, application callbacks, and state management. • Group— The Group class is the base class for any node that can have children. It is a key class in the spatial organization of scene graphs. • Geode— The Geode (or Geometry Node) class corresponds to the leaf node in OSG. It has no children, but contains osg::Drawable objects that contain geometry for rendering. • MatrixTransform— The MatrixTransform class contains a matrix that transforms the geometry of its children, allowing scene objects to be rotated, translated, scaled, skewed, projected, etc.

  11. A Scene Graph A simple, abstract scene graph To render a scene consisting of terrain, a cow, and a truck, the scene graph takes the form of a top-level node with three child nodes. Each child node contains the geometry to draw its object.

  12. Scene graph traversals Rendering a scene graph typically requires three traversals. The update traversal modifies geometry, rendering state, or node parameters to ensure the scene graph is up-to-date for the current frame. Cull traversal checks for visibility, and places geometry and state references in a new structure (called the render graph in OSG). Draw traversal traverses the render graph and issues drawing commands to the graphics hardware.

  13. OSG Simple program Download #include <osgViewer/Viewer> #include <osg/ShapeDrawable> void main() { osg::Capsule *MYcap = new osg::Capsule(osg::Vec3f(),1,2); osg::ShapeDrawable *MYcapDrawable = new osg::ShapeDrawable(MYcap); osg::Geode *MYgeode = new osg::Geode(); MYgeode->addDrawable(MYcapDrawable); osg::Group *MYroot = new osg::Group(); MYroot->addChild(MYgeode); osgViewer::Viewer MYviewer ; MYviewer.setSceneData( MYroot); MYviewer.run(); } MYroot MYgeode MYcapDrawable MYcap

  14. Robot Scene Graph Children MYroot Attributes MYtransformBase MYtransformHead MYgeodeBase MYgeodeHead MYbaseDrawable MYbase MYheadDrawable MYhead

  15. OSG Robot programDownload #include <osgViewer/Viewer> #include <osg/ShapeDrawable> #include <osg/MatrixTransform> void main() { osg::Cylinder *MYbase = new osg::Cylinder(osg::Vec3f(),.25,1); osg::ShapeDrawable *MYbaseDrawable = new osg::ShapeDrawable(MYbase); osg::Geode *MYgeodeBase = new osg::Geode(); MYgeodeBase->addDrawable(MYbaseDrawable); osg::Sphere *MYhead = new osg::Sphere(osg::Vec3f(),.25); osg::ShapeDrawable *MYheadDrawable = new osg::ShapeDrawable(MYhead); osg::Geode *MYgeodeHead = new osg::Geode(); MYgeodeHead->addDrawable(MYheadDrawable); MYgeodeBase MYbaseDrawable MYbase

  16. OSG Robot program osg::MatrixTransform* MYtransformHead = new osg::MatrixTransform(); MYtransformHead->setMatrix(osg::Matrix::translate(0,0,.75)); MYtransformHead->addChild(MYgeodeHead); osg::MatrixTransform* MYtransformBase=new osg::MatrixTransform(); MYtransformBase->setMatrix(osg::Matrix::rotate(.15,0,1,0)); MYtransformBase->addChild(MYtransformHead); MYtransformBase->addChild(MYgeodeBase); osg::Group *MYroot = new osg::Group(); MYroot->addChild(MYtransformBase); osgViewer::Viewer MYviewer ; MYviewer.setSceneData( MYroot ); MYviewer.run(); } MYroot MYtransformBase MYtransformHead MYgeodeBase MYgeodeHead

  17. OSG Robot programAdding light and material • Light and material attributes same as OpenGL. • Root children, light and base transform, are applied to entire scene. Effect is that light moves with scene. • Materials part of a group, transformation or geode state. MYroot MYmaterial MYstate MYtransformBase MYLightsource MYtransformHead MYgeodeBase MYgeodeHead

  18. OSG Robot programAdding light and material osg::Light *MYlight= new osg::Light(); MYlight->setAmbient(osg::Vec4d(.5,0,1, 1)); MYlight->setDiffuse(osg::Vec4d(.5,0,1, 1)); MYlight->setSpecular(osg::Vec4d(1,1,1, 1)); MYlight->setPosition(osg::Vec4d(-2, -3, 1.5, 1)); osg::LightSource * MYlightsource = new osg::LightSource(); MYlightsource->setLight(MYlight); osg::Material *MYmaterial = new osg::Material; MYmaterial->setSpecular( osg::Material::FRONT,osg::Vec4( 1,1,1,1 ) ); MYmaterial->setAmbient( osg::Material::FRONT,osg::Vec4( .5,0,1,1 ) ); MYmaterial->setDiffuse( osg::Material::FRONT,osg::Vec4( .5,0,1,1 ) ); MYmaterial->setShininess( osg::Material::FRONT, 100 );

  19. OSG Robot programAdding light and material osg::MatrixTransform* MYtransformBase = new osg::MatrixTransform(); MYtransformBase->setMatrix(osg::Matrix::rotate(3.14/12,0,1,0)); MYtransformBase->addChild(MYtransformHead); MYtransformBase->addChild(MYgeodeBase); osg::StateSet* MYstate = MYtransformBase->getOrCreateStateSet(); MYstate->setAttribute( MYmaterial ); osg::Group *MYroot = new osg::Group(); MYroot->addChild(MYtransformBase); MYroot->addChild(MYlightsource); MYroot MYtransformBase MYLightsource MYmaterial MYstate MYtransformHead MYgeodeBase MYgeodeHead

More Related