2012-03-22 01:36:20 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2003-01-22 00:45:36 +08:00
|
|
|
*
|
2012-03-22 01:36:20 +08:00
|
|
|
* 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
|
2003-01-22 00:45:36 +08:00
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
2012-03-22 01:36:20 +08:00
|
|
|
*
|
2003-01-22 00:45:36 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-03-22 01:36:20 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2003-01-22 00:45:36 +08:00
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
2001-10-04 23:12:57 +08:00
|
|
|
|
2005-05-02 03:48:49 +08:00
|
|
|
#ifndef OSGSIM_IMPOSTOR
|
|
|
|
#define OSGSIM_IMPOSTOR 1
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
#include <osg/LOD>
|
2003-04-10 20:11:40 +08:00
|
|
|
#include <osg/buffered_value>
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2005-07-23 00:25:38 +08:00
|
|
|
#include <osgUtil/CullVisitor>
|
|
|
|
|
2005-05-02 03:48:49 +08:00
|
|
|
#include <osgSim/ImpostorSprite>
|
|
|
|
|
|
|
|
namespace osgSim {
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
/** Impostor - is a form of Level Of Detail group node which allows both switching
|
2001-09-20 05:19:47 +08:00
|
|
|
* between children depending on distance from eye point and image caching.
|
2012-03-22 01:36:20 +08:00
|
|
|
*
|
|
|
|
* The principle behind Imposters is that they cache an image of real geometry and then the image is drawn
|
2004-09-13 23:14:11 +08:00
|
|
|
* in subsequent frames instead of the real geometry. It's a bit like a
|
|
|
|
* Billboard *but* is updated at runtime and w.r.t view point. By drawing
|
2001-09-20 05:19:47 +08:00
|
|
|
* just the texture mapped quad you can cut down scene complexity and
|
|
|
|
* improve performance.
|
2012-03-22 01:36:20 +08:00
|
|
|
*
|
2001-09-20 05:19:47 +08:00
|
|
|
* For more details have a look at:
|
2012-03-22 01:36:20 +08:00
|
|
|
*
|
2001-09-20 05:19:47 +08:00
|
|
|
* http://grail.cs.washington.edu/projects/hic/
|
2012-03-22 01:36:20 +08:00
|
|
|
*
|
2001-09-20 05:19:47 +08:00
|
|
|
* The OSG doesn't implement exactly the same technique as above, but its
|
2004-09-13 23:14:11 +08:00
|
|
|
* should be a good starting place. The OSG's impostors are much less
|
2001-09-20 05:19:47 +08:00
|
|
|
* intrusive since you don't need to restructure your whole scene to use
|
|
|
|
* them.
|
|
|
|
*
|
|
|
|
* All you need to do to use Impostors is to set up the visible
|
|
|
|
* range values for each LOD child of the Impostor, as per osg::LOD,
|
|
|
|
* and set an Impostor threshold to tell the renderer at what distance
|
2001-10-01 19:15:55 +08:00
|
|
|
* the Impostor's image caching should cut in. The osg::CullVisitor
|
2001-09-20 05:19:47 +08:00
|
|
|
* automatically handles all the setting of pre-rendering stages to
|
|
|
|
* calculate the required ImpostorSprites (which encapsulates the image
|
2012-03-22 01:36:20 +08:00
|
|
|
* cache and quad), and updates them as the view point changes. If you
|
|
|
|
* use osg::SceneView/CullVisitor all the complexity of supporting
|
2001-09-20 05:19:47 +08:00
|
|
|
* Impostor will be nicely hidden away.
|
|
|
|
*
|
|
|
|
* TODO:
|
|
|
|
* Various improvements are planned for the Impostor-
|
|
|
|
* 1) Estimation of how many frames an ImpostorSprite will be reused, if
|
|
|
|
* it won't be used more often than a minimum threshold then do not create
|
|
|
|
* ImpostorSprite - use the real geometry.
|
|
|
|
* 2) Sharing of texture memory between ImpostorSprites.
|
|
|
|
* 3) Simple 3D geometry for ImpostorSprite's rather than Billboarding.
|
|
|
|
* 4) Shrinking of the ImpostorSprite size to more closely fit the underlying
|
|
|
|
* geometry.
|
|
|
|
*/
|
2005-05-02 03:48:49 +08:00
|
|
|
class OSGSIM_EXPORT Impostor : public osg::LOD
|
2001-09-20 05:19:47 +08:00
|
|
|
{
|
|
|
|
public :
|
|
|
|
Impostor();
|
|
|
|
|
2005-05-02 03:48:49 +08:00
|
|
|
Impostor(const Impostor& es, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
|
|
|
|
osg::LOD(es,copyop),
|
Added support for shallow and deep copy of nodes, drawables and state, via a
copy constructor which takes an optional Cloner object, and the old
osg::Object::clone() has changed so that it now requires a Cloner as paramter.
This is passed on to the copy constructor to help control the shallow vs
deep copying. The old functionality of clone() which was clone of type has
been renamed to cloneType().
Updated all of the OSG to work with these new conventions, implemention all
the required copy constructors etc. A couple of areas will do shallow
copies by design, a couple of other still need to be updated to do either
shallow or deep.
Neither of the shallow or deep copy operations have been tested yet, only
the old functionality of the OSG has been checked so far, such running the
viewer on various demo datasets.
Also fixed a problem in osg::Optimize::RemoveRendundentNodesVisitor which
was not checking that Group didn't have have any attached StateSet's, Callbacks
or UserData. These checks have now been added, which fixes a bug which was
revealled by the new osgscribe demo, this related to removal of group acting
as state decorator.
method
2002-01-29 05:17:01 +08:00
|
|
|
_impostorThreshold(es._impostorThreshold) {}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2005-05-02 03:48:49 +08:00
|
|
|
META_Node(osgSim, Impostor);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2005-05-02 03:48:49 +08:00
|
|
|
virtual void traverse(osg::NodeVisitor& nv);
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2005-05-02 03:48:49 +08:00
|
|
|
typedef std::vector< osg::ref_ptr<ImpostorSprite> > ImpostorSpriteList;
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
/** Set the Impostor threshold distance.
|
|
|
|
* For eye points further than this threshold the Imposter is used if appropriate,
|
2004-09-13 23:14:11 +08:00
|
|
|
* otherwise the LOD children as chosen as per a standard LOD node.
|
2005-11-18 01:44:48 +08:00
|
|
|
*/
|
2001-09-20 05:19:47 +08:00
|
|
|
inline void setImpostorThreshold(float distance) { _impostorThreshold = distance; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/* Get the Impostor threshold distance. */
|
2002-09-02 20:31:35 +08:00
|
|
|
inline float getImpostorThreshold() const { return _impostorThreshold; }
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2004-12-17 09:06:33 +08:00
|
|
|
/** Set the Impostor threshold distance relative to the node's bounding
|
|
|
|
* sphere's radius.
|
|
|
|
*/
|
|
|
|
inline void setImpostorThresholdToBound(float ratio=1.0f) { _impostorThreshold = getBound().radius()*ratio; }
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Find the ImposterSprite which fits the current eye point best. */
|
2003-04-10 20:11:40 +08:00
|
|
|
ImpostorSprite* findBestImpostorSprite(unsigned int contextID, const osg::Vec3& currLocalEyePoint) const;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Add an ImpostorSprite to the Impostor. */
|
2003-04-10 20:11:40 +08:00
|
|
|
void addImpostorSprite(unsigned int contextID, ImpostorSprite* is);
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Get the list of ImpostorSprites attached to this Impostor. */
|
2003-04-10 20:11:40 +08:00
|
|
|
inline ImpostorSpriteList& getImpostorSpriteList(unsigned int contexID) { return _impostorSpriteListBuffer[contexID]; }
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Get a const list of ImpostorSprites attached to this const Impostor. */
|
2003-04-10 20:11:40 +08:00
|
|
|
inline const ImpostorSpriteList& getImpostorSpriteList(unsigned int contexID) const { return _impostorSpriteListBuffer[contexID]; }
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2005-05-12 22:03:22 +08:00
|
|
|
virtual osg::BoundingSphere computeBound() const;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
protected :
|
|
|
|
|
|
|
|
virtual ~Impostor() {}
|
|
|
|
|
2005-05-02 03:48:49 +08:00
|
|
|
mutable osg::buffered_object<ImpostorSpriteList> _impostorSpriteListBuffer;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2005-07-23 00:25:38 +08:00
|
|
|
ImpostorSprite* createImpostorSprite(osgUtil::CullVisitor* cv);
|
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
float _impostorThreshold;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2002-02-03 20:33:41 +08:00
|
|
|
}
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
#endif
|