SmoothingVisitor 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
  2. *
  3. * This library is open source and may be redistributed and/or modified under
  4. * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
  5. * (at your option) any later version. The full license is in LICENSE file
  6. * included with this distribution, and on the openscenegraph.org website.
  7. *
  8. * This library is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * OpenSceneGraph Public License for more details.
  12. */
  13. #ifndef OSGUTIL_SMOOTHINGVISITOR
  14. #define OSGUTIL_SMOOTHINGVISITOR 1
  15. #include <osg/NodeVisitor>
  16. #include <osg/Geode>
  17. #include <osg/Geometry>
  18. #include <osgUtil/Export>
  19. namespace osgUtil {
  20. /** A smoothing visitor for calculating smoothed normals for
  21. * osg::GeoSet's which contains surface primitives.
  22. */
  23. class OSGUTIL_EXPORT SmoothingVisitor : public osg::NodeVisitor
  24. {
  25. public:
  26. /// default to traversing all children.
  27. SmoothingVisitor();
  28. virtual ~SmoothingVisitor();
  29. /// smooth geoset by creating per vertex normals.
  30. static void smooth(osg::Geometry& geoset, double creaseAngle=osg::PI);
  31. /// apply smoothing method to all geometries.
  32. virtual void apply(osg::Geometry& geom);
  33. /// set the maximum angle, in radians, at which angle between adjacent triangles that normals are smoothed
  34. /// for edges that greater the shared vertices are duplicated
  35. void setCreaseAngle(double angle) { _creaseAngle = angle; }
  36. double getCreaseAngle() const { return _creaseAngle; }
  37. protected:
  38. double _creaseAngle;
  39. };
  40. }
  41. #endif