2006-03-09 05:38:37 +08:00
|
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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.
|
|
|
|
|
*/
|
|
|
|
|
//
|
|
|
|
|
// OpenFlight<68> loader for OpenSceneGraph
|
|
|
|
|
//
|
|
|
|
|
// Copyright (C) 2005-2006 Brede Johansen
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#ifndef OSGSIM_OPENFLIGHTOPTIMIZER
|
|
|
|
|
#define OSGSIM_OPENFLIGHTOPTIMIZER
|
|
|
|
|
|
|
|
|
|
#include <osg/NodeVisitor>
|
|
|
|
|
#include <osg/Group>
|
|
|
|
|
#include <osg/Geometry>
|
|
|
|
|
|
|
|
|
|
#include <osgSim/Export>
|
|
|
|
|
|
2007-06-16 00:08:33 +08:00
|
|
|
|
namespace osgSim {
|
2006-03-09 05:38:37 +08:00
|
|
|
|
|
|
|
|
|
/** Flight optimizer
|
|
|
|
|
*/
|
|
|
|
|
class OSGSIM_EXPORT Optimizer
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
Optimizer() {}
|
|
|
|
|
virtual ~Optimizer() {}
|
|
|
|
|
|
|
|
|
|
enum OptimizationOptions
|
|
|
|
|
{
|
2007-01-09 05:29:49 +08:00
|
|
|
|
TESSELLATE_POLYGON = 0x001,
|
2006-03-09 05:38:37 +08:00
|
|
|
|
MERGE_GEODES = 0x002,
|
|
|
|
|
MAKE_LIT = 0x004,
|
2007-01-09 05:29:49 +08:00
|
|
|
|
DEFAULT_OPTIMIZATIONS = TESSELLATE_POLYGON | MERGE_GEODES,
|
|
|
|
|
ALL_OPTIMIZATIONS = TESSELLATE_POLYGON | MERGE_GEODES
|
2006-03-09 05:38:37 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Traverse the node and its subgraph with a series of optimization
|
|
|
|
|
* visitors, specified by the OptimizationOptions.*/
|
|
|
|
|
void optimize(osg::Node* node);
|
|
|
|
|
|
|
|
|
|
/** Traverse the node and its subgraph with a series of optimization
|
|
|
|
|
* visitors, specified by the OptimizationOptions.*/
|
|
|
|
|
virtual void optimize(osg::Node* node, unsigned int options);
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
2007-01-09 05:29:49 +08:00
|
|
|
|
class OSGSIM_EXPORT TessellateVisitor : public osg::NodeVisitor
|
2006-03-09 05:38:37 +08:00
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
/// default to traversing all children.
|
2007-01-09 05:29:49 +08:00
|
|
|
|
TessellateVisitor() :
|
2006-03-09 05:38:37 +08:00
|
|
|
|
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {}
|
|
|
|
|
|
|
|
|
|
virtual void apply(osg::Geode& geode);
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
|
|
bool hasPolygons(osg::Geometry& geometry);
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
2006-03-18 06:23:37 +08:00
|
|
|
|
class OSGSIM_EXPORT MakeLitVisitor : public osg::NodeVisitor
|
2006-03-09 05:38:37 +08:00
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
/// default to traversing all children.
|
|
|
|
|
MakeLitVisitor() :
|
|
|
|
|
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {}
|
|
|
|
|
|
|
|
|
|
virtual void apply(osg::Geode& geode);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Combine geodes
|
|
|
|
|
*/
|
2006-03-18 06:23:37 +08:00
|
|
|
|
class OSGSIM_EXPORT MergeGeodesVisitor : public osg::NodeVisitor
|
2006-03-09 05:38:37 +08:00
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
/// default to traversing all children.
|
|
|
|
|
MergeGeodesVisitor() :
|
|
|
|
|
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {}
|
|
|
|
|
|
|
|
|
|
virtual void apply(osg::Group& group);
|
|
|
|
|
|
|
|
|
|
void mergeGeodes(osg::Group& group);
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
|
|
bool mergeGeode(osg::Geode& lhs, osg::Geode& rhs);
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // end namespace
|
|
|
|
|
|
|
|
|
|
#endif
|