2012-03-22 01:36:20 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2005-03-07 22:06:09 +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
|
2005-03-07 22:06:09 +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
|
|
|
*
|
2005-03-07 22:06:09 +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
|
2005-03-07 22:06:09 +08:00
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef OSG_ProxyNode
|
|
|
|
#define OSG_ProxyNode 1
|
|
|
|
|
|
|
|
#include <osg/Group>
|
|
|
|
|
|
|
|
namespace osg {
|
|
|
|
|
|
|
|
/** ProxyNode.
|
|
|
|
*/
|
2005-04-12 01:14:17 +08:00
|
|
|
class OSG_EXPORT ProxyNode : public Group
|
2005-03-07 22:06:09 +08:00
|
|
|
{
|
|
|
|
public :
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2005-03-07 22:06:09 +08:00
|
|
|
ProxyNode();
|
|
|
|
|
|
|
|
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
|
|
|
ProxyNode(const ProxyNode&,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
|
|
|
|
|
|
|
META_Node(osg, ProxyNode);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2008-04-04 02:36:50 +08:00
|
|
|
typedef osg::BoundingSphere::vec_type vec_type;
|
|
|
|
typedef osg::BoundingSphere::value_type value_type;
|
|
|
|
|
2005-03-07 22:06:09 +08:00
|
|
|
virtual void traverse(NodeVisitor& nv);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2015-10-22 22:14:53 +08:00
|
|
|
using osg::Group::addChild;
|
|
|
|
|
2005-03-07 22:06:09 +08:00
|
|
|
virtual bool addChild(Node *child);
|
2015-10-22 22:14:53 +08:00
|
|
|
|
2005-03-07 22:06:09 +08:00
|
|
|
virtual bool addChild(Node *child, const std::string& filename);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2015-10-22 22:14:53 +08:00
|
|
|
template<class T> bool addChild( const ref_ptr<T>& child, const std::string& filename) { return addChild(child.get(), filename); }
|
|
|
|
|
2006-05-02 17:45:31 +08:00
|
|
|
virtual bool removeChildren(unsigned int pos,unsigned int numChildrenToRemove);
|
2005-03-07 22:06:09 +08:00
|
|
|
|
2009-06-12 18:08:15 +08:00
|
|
|
|
2012-03-29 23:08:15 +08:00
|
|
|
/** Set the optional database osgDB::Options object to use when loading children.*/
|
2009-06-12 18:08:15 +08:00
|
|
|
void setDatabaseOptions(osg::Referenced* options) { _databaseOptions = options; }
|
|
|
|
|
2012-03-29 23:08:15 +08:00
|
|
|
/** Get the optional database osgDB::Options object used when loading children.*/
|
2009-06-12 18:08:15 +08:00
|
|
|
osg::Referenced* getDatabaseOptions() { return _databaseOptions.get(); }
|
|
|
|
|
2012-03-29 23:08:15 +08:00
|
|
|
/** Get the optional database osgDB::Options object used when loading children.*/
|
2009-06-12 18:08:15 +08:00
|
|
|
const osg::Referenced* getDatabaseOptions() const { return _databaseOptions.get(); }
|
|
|
|
|
|
|
|
|
2005-03-07 22:06:09 +08:00
|
|
|
/** Set the database path to prepend to children's filenames.*/
|
|
|
|
void setDatabasePath(const std::string& path);
|
|
|
|
/** Get the database path used to prepend to children's filenames.*/
|
|
|
|
inline const std::string& getDatabasePath() const { return _databasePath; }
|
|
|
|
|
2008-05-22 05:09:45 +08:00
|
|
|
void setFileName(unsigned int childNo, const std::string& filename) { expandFileNameListTo(childNo); _filenameList[childNo].first=filename; }
|
|
|
|
const std::string& getFileName(unsigned int childNo) const { return _filenameList[childNo].first; }
|
2005-03-07 22:06:09 +08:00
|
|
|
unsigned int getNumFileNames() const { return _filenameList.size(); }
|
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
/** Return the DatabaseRequest object used by the DatabasePager to keep track of file load requests
|
2012-03-29 23:08:15 +08:00
|
|
|
* being carried out on behalf of the DatabasePager.
|
2012-03-22 01:36:20 +08:00
|
|
|
* Note, in normal OSG usage you should not set this value yourself, as this will be managed by
|
2008-05-22 05:09:45 +08:00
|
|
|
* the osgDB::DatabasePager.*/
|
|
|
|
osg::ref_ptr<osg::Referenced>& getDatabaseRequest(unsigned int childNo) { return _filenameList[childNo].second; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
|
|
|
/** Return the const DatabaseRequest object.*/
|
2008-05-22 05:09:45 +08:00
|
|
|
const osg::ref_ptr<osg::Referenced>& getDatabaseRequest(unsigned int childNo) const { return _filenameList[childNo].second; }
|
|
|
|
|
|
|
|
|
2012-03-29 23:08:15 +08:00
|
|
|
/** Modes which control how the center of object should be determined when computing which child is active.*/
|
2005-03-07 22:06:09 +08:00
|
|
|
enum CenterMode
|
|
|
|
{
|
|
|
|
USE_BOUNDING_SPHERE_CENTER,
|
2011-09-19 18:34:31 +08:00
|
|
|
USER_DEFINED_CENTER,
|
|
|
|
UNION_OF_BOUNDING_SPHERE_AND_USER_DEFINED
|
2005-03-07 22:06:09 +08:00
|
|
|
};
|
|
|
|
|
2012-03-29 23:08:15 +08:00
|
|
|
/** Set how the center of object should be determined when computing which child is active.*/
|
2005-03-07 22:06:09 +08:00
|
|
|
void setCenterMode(CenterMode mode) { _centerMode=mode; }
|
|
|
|
|
2012-03-29 23:08:15 +08:00
|
|
|
/** Get how the center of object should be determined when computing which child is active.*/
|
2005-03-07 22:06:09 +08:00
|
|
|
CenterMode getCenterMode() const { return _centerMode; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2008-02-25 23:07:35 +08:00
|
|
|
/** Modes which control how the proxynode external reference are loaded.*/
|
|
|
|
enum LoadingExternalReferenceMode
|
|
|
|
{
|
|
|
|
LOAD_IMMEDIATELY,
|
|
|
|
DEFER_LOADING_TO_DATABASE_PAGER,
|
|
|
|
NO_AUTOMATIC_LOADING
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Set how the child loading is done.*/
|
|
|
|
void setLoadingExternalReferenceMode(LoadingExternalReferenceMode mode) { _loadingExtReference=mode; }
|
|
|
|
|
2012-03-29 23:08:15 +08:00
|
|
|
/** Get the loading mode.*/
|
2008-02-25 23:07:35 +08:00
|
|
|
LoadingExternalReferenceMode getLoadingExternalReferenceMode() const { return _loadingExtReference; }
|
2005-03-07 22:06:09 +08:00
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
/** Sets the object-space point which defines the center of the osg::ProxyNode.
|
2012-03-29 23:08:15 +08:00
|
|
|
Center is affected by any transforms in the hierarchy above the osg::ProxyNode.*/
|
2011-09-19 18:34:31 +08:00
|
|
|
inline void setCenter(const vec_type& center) { if (_centerMode!=UNION_OF_BOUNDING_SPHERE_AND_USER_DEFINED) { _centerMode=USER_DEFINED_CENTER; } _userDefinedCenter = center; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2012-03-29 23:08:15 +08:00
|
|
|
/** Return the ProxyNode center point. */
|
2011-09-19 18:34:31 +08:00
|
|
|
inline const vec_type& getCenter() const { if ((_centerMode==USER_DEFINED_CENTER)||(_centerMode==UNION_OF_BOUNDING_SPHERE_AND_USER_DEFINED)) return _userDefinedCenter; else return getBound().center(); }
|
2005-03-07 22:06:09 +08:00
|
|
|
|
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
/** Set the object-space reference radius of the volume enclosed by the ProxyNode.
|
2007-12-11 01:30:18 +08:00
|
|
|
* Used to determine the bounding sphere of the ProxyNode in the absence of any children.*/
|
2008-04-04 02:36:50 +08:00
|
|
|
inline void setRadius(value_type radius) { _radius = radius; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2005-04-30 23:16:05 +08:00
|
|
|
/** Get the object-space radius of the volume enclosed by the ProxyNode.*/
|
2008-04-04 02:36:50 +08:00
|
|
|
inline value_type getRadius() const { return _radius; }
|
2005-03-07 22:06:09 +08:00
|
|
|
|
2005-05-12 22:03:22 +08:00
|
|
|
virtual BoundingSphere computeBound() const;
|
|
|
|
|
2005-03-07 22:06:09 +08:00
|
|
|
protected :
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2005-03-07 22:06:09 +08:00
|
|
|
virtual ~ProxyNode() {}
|
|
|
|
|
|
|
|
void expandFileNameListTo(unsigned int pos);
|
|
|
|
|
2008-05-22 05:09:45 +08:00
|
|
|
typedef std::pair< std::string, osg::ref_ptr<osg::Referenced> > FileNameDatabaseRequestPair;
|
|
|
|
typedef std::vector<FileNameDatabaseRequestPair> FileNameDatabaseRequestList;
|
|
|
|
|
|
|
|
FileNameDatabaseRequestList _filenameList;
|
2009-06-12 18:08:15 +08:00
|
|
|
ref_ptr<Referenced> _databaseOptions;
|
2008-05-22 05:09:45 +08:00
|
|
|
std::string _databasePath;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2008-05-22 05:09:45 +08:00
|
|
|
LoadingExternalReferenceMode _loadingExtReference;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2008-05-22 05:09:45 +08:00
|
|
|
CenterMode _centerMode;
|
|
|
|
vec_type _userDefinedCenter;
|
|
|
|
value_type _radius;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2005-03-07 22:06:09 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|