Hi Robert,
attached is a change to the ProxyNode that also includes ProxyNode local
database options like recently added to PagedLOD.
Also there is a change to the traverse method:
The previous ProxyNode checks the VisitorType to be a CULL_VISITOR and the
presence of a request handler to submit a database request.
In contrast to that PagedLOD uses the request handler if it is there - even if
the visitor type is not a cull visitor.
The change removes the cull visitor test from the ProxyNode so that it behaves
like the PagedLOD.
I believe that the presence of a request handler in a visitor might be
sufficient to trigger the requests as this is done in the PagedLOD anyway.
Based on rev 10332.
Please apply!
Thanks!
Mathias
/* -*-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.
*/
#ifndef OSG_ProxyNode
#define OSG_ProxyNode 1
#include <osg/Group>
namespace osg {
/** ProxyNode.
*/
class OSG_EXPORT ProxyNode : public Group
{
public :
ProxyNode();
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
ProxyNode(const ProxyNode&,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
META_Node(osg, ProxyNode);
typedef osg::BoundingSphere::vec_type vec_type;
typedef osg::BoundingSphere::value_type value_type;
virtual void traverse(NodeVisitor& nv);
virtual bool addChild(Node *child);
virtual bool addChild(Node *child, const std::string& filename);
virtual bool removeChildren(unsigned int pos,unsigned int numChildrenToRemove);
/** Set the optional database osgDB::Options object to use when loaded children.*/
void setDatabaseOptions(osg::Referenced* options) { _databaseOptions = options; }
/** Get the optional database osgDB::Options object used when loaded children.*/
osg::Referenced* getDatabaseOptions() { return _databaseOptions.get(); }
/** Get the optional database osgDB::Options object used when loaded children.*/
const osg::Referenced* getDatabaseOptions() const { return _databaseOptions.get(); }
/** 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; }
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; }
unsigned int getNumFileNames() const { return _filenameList.size(); }
/** Return the DatabaseRequest object used by the DatabasePager to keep track of file load requests
* being carried on behalf of the DatabasePager.
* Note, in normal OSG usage you should not set this value yourself, as this will be managed by
* the osgDB::DatabasePager.*/
osg::ref_ptr<osg::Referenced>& getDatabaseRequest(unsigned int childNo) { return _filenameList[childNo].second; }
/** Return the const DatabaseRequest object.*/
const osg::ref_ptr<osg::Referenced>& getDatabaseRequest(unsigned int childNo) const { return _filenameList[childNo].second; }
/** Modes which control how the center of object should be determined when computed which child is active.*/
enum CenterMode
{
USE_BOUNDING_SPHERE_CENTER,
USER_DEFINED_CENTER
};
/** Set how the center of object should be determined when computed which child is active.*/
void setCenterMode(CenterMode mode) { _centerMode=mode; }
/** Get how the center of object should be determined when computed which child is active.*/
CenterMode getCenterMode() const { return _centerMode; }
/** 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; }
/** Get the setted mode of loading.*/
LoadingExternalReferenceMode getLoadingExternalReferenceMode() const { return _loadingExtReference; }
/** Sets the object-space point which defines the center of the osg::ProxyNode.
center is affected by any transforms in the hierarchy above the osg::ProxyNode.*/
inline void setCenter(const Vec3& center) { _centerMode=USER_DEFINED_CENTER; _userDefinedCenter = center; }
/** return the ProxyNode center point. */
inline const vec_type& getCenter() const { if (_centerMode==USER_DEFINED_CENTER) return _userDefinedCenter; else return getBound().center(); }
/** Set the object-space reference radius of the volume enclosed by the ProxyNode.
* Used to determine the bounding sphere of the ProxyNode in the absence of any children.*/
inline void setRadius(value_type radius) { _radius = radius; }
/** Get the object-space radius of the volume enclosed by the ProxyNode.*/
inline value_type getRadius() const { return _radius; }
virtual BoundingSphere computeBound() const;
protected :
virtual ~ProxyNode() {}
void expandFileNameListTo(unsigned int pos);
typedef std::pair< std::string, osg::ref_ptr<osg::Referenced> > FileNameDatabaseRequestPair;
typedef std::vector<FileNameDatabaseRequestPair> FileNameDatabaseRequestList;
FileNameDatabaseRequestList _filenameList;
ref_ptr<Referenced> _databaseOptions;
std::string _databasePath;
LoadingExternalReferenceMode _loadingExtReference;
CenterMode _centerMode;
vec_type _userDefinedCenter;
value_type _radius;
};
}
#endif
/* -*-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.
*/
#include <osg/ProxyNode>
#include <osg/CullStack>
#include <osg/Notify>
using namespace osg;
ProxyNode::ProxyNode() :
_loadingExtReference(LOAD_IMMEDIATELY),
_centerMode(USER_DEFINED_CENTER),
_radius(-1)
{
}
ProxyNode::ProxyNode(const ProxyNode& proxynode,const CopyOp& copyop):
Group(proxynode,copyop),
_filenameList(proxynode._filenameList),
_databaseOptions(proxynode._databaseOptions),
_databasePath(proxynode._databasePath),
_loadingExtReference(proxynode._loadingExtReference),
_centerMode(proxynode._centerMode),
_userDefinedCenter(proxynode._userDefinedCenter),
_radius(proxynode._radius)
{
}
void ProxyNode::setDatabasePath(const std::string& path)
{
_databasePath = path;
if (!_databasePath.empty())
{
char& lastCharacter = _databasePath[_databasePath.size()-1];
const char unixSlash = '/';
const char winSlash = '\\';
if (lastCharacter==winSlash)
{
lastCharacter = unixSlash;
}
else if (lastCharacter!=unixSlash)
{
_databasePath += unixSlash;
}
}
}
void ProxyNode::traverse(NodeVisitor& nv)
{
if (nv.getDatabaseRequestHandler() && _filenameList.size()>_children.size() &&
_loadingExtReference!=NO_AUTOMATIC_LOADING)
{
for(unsigned int i=_children.size(); i<_filenameList.size(); ++i)
{
nv.getDatabaseRequestHandler()->requestNodeFile(_databasePath+_filenameList[i].first, this, 1.0f, nv.getFrameStamp(), _filenameList[i].second, _databaseOptions.get());
}
}
else
{
Group::traverse(nv);
}
}
void ProxyNode::expandFileNameListTo(unsigned int pos)
{
if (pos>=_filenameList.size()) _filenameList.resize(pos+1);
}
bool ProxyNode::addChild( Node *child )
{
if (Group::addChild(child))
{
expandFileNameListTo(_children.size()-1);
return true;
}
return false;
}
bool ProxyNode::addChild(Node *child, const std::string& filename)
{
if (Group::addChild(child))
{
setFileName(_children.size()-1,filename);
return true;
}
return false;
}
bool ProxyNode::removeChildren(unsigned int pos,unsigned int numChildrenToRemove)
{
if (pos<_filenameList.size()) _filenameList.erase(_filenameList.begin()+pos, osg::minimum(_filenameList.begin()+(pos+numChildrenToRemove), _filenameList.end()) );
return Group::removeChildren(pos,numChildrenToRemove);
}
BoundingSphere ProxyNode::computeBound() const
{
if (_centerMode==USER_DEFINED_CENTER && _radius>=0.0f)
{
return BoundingSphere(_userDefinedCenter,_radius);
}
else
{
return Group::computeBound();
}
}
_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org