| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | #include <osg/ProxyNode> |
|---|
| 15 | #include <osg/CullStack> |
|---|
| 16 | #include <osg/Notify> |
|---|
| 17 | |
|---|
| 18 | using namespace osg; |
|---|
| 19 | |
|---|
| 20 | ProxyNode::ProxyNode() : |
|---|
| 21 | _loadingExtReference(LOAD_IMMEDIATELY), |
|---|
| 22 | _centerMode(USER_DEFINED_CENTER), |
|---|
| 23 | _radius(-1) |
|---|
| 24 | { |
|---|
| 25 | } |
|---|
| 26 | |
|---|
| 27 | ProxyNode::ProxyNode(const ProxyNode& proxynode,const CopyOp& copyop): |
|---|
| 28 | Group(proxynode,copyop), |
|---|
| 29 | _filenameList(proxynode._filenameList), |
|---|
| 30 | _databaseOptions(proxynode._databaseOptions), |
|---|
| 31 | _databasePath(proxynode._databasePath), |
|---|
| 32 | _loadingExtReference(proxynode._loadingExtReference), |
|---|
| 33 | _centerMode(proxynode._centerMode), |
|---|
| 34 | _userDefinedCenter(proxynode._userDefinedCenter), |
|---|
| 35 | _radius(proxynode._radius) |
|---|
| 36 | { |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | void ProxyNode::setDatabasePath(const std::string& path) |
|---|
| 40 | { |
|---|
| 41 | _databasePath = path; |
|---|
| 42 | if (!_databasePath.empty()) |
|---|
| 43 | { |
|---|
| 44 | char& lastCharacter = _databasePath[_databasePath.size()-1]; |
|---|
| 45 | const char unixSlash = '/'; |
|---|
| 46 | const char winSlash = '\\'; |
|---|
| 47 | |
|---|
| 48 | if (lastCharacter==winSlash) |
|---|
| 49 | { |
|---|
| 50 | lastCharacter = unixSlash; |
|---|
| 51 | } |
|---|
| 52 | else if (lastCharacter!=unixSlash) |
|---|
| 53 | { |
|---|
| 54 | _databasePath += unixSlash; |
|---|
| 55 | } |
|---|
| 56 | } |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | void ProxyNode::traverse(NodeVisitor& nv) |
|---|
| 60 | { |
|---|
| 61 | if (nv.getDatabaseRequestHandler() && _filenameList.size()>_children.size() && |
|---|
| 62 | _loadingExtReference!=NO_AUTOMATIC_LOADING) |
|---|
| 63 | { |
|---|
| 64 | for(unsigned int i=_children.size(); i<_filenameList.size(); ++i) |
|---|
| 65 | { |
|---|
| 66 | nv.getDatabaseRequestHandler()->requestNodeFile(_databasePath+_filenameList[i].first, this, 1.0f, nv.getFrameStamp(), _filenameList[i].second, _databaseOptions.get()); |
|---|
| 67 | } |
|---|
| 68 | } |
|---|
| 69 | else |
|---|
| 70 | { |
|---|
| 71 | Group::traverse(nv); |
|---|
| 72 | } |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | void ProxyNode::expandFileNameListTo(unsigned int pos) |
|---|
| 76 | { |
|---|
| 77 | if (pos>=_filenameList.size()) _filenameList.resize(pos+1); |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | bool ProxyNode::addChild( Node *child ) |
|---|
| 81 | { |
|---|
| 82 | if (Group::addChild(child)) |
|---|
| 83 | { |
|---|
| 84 | expandFileNameListTo(_children.size()-1); |
|---|
| 85 | return true; |
|---|
| 86 | } |
|---|
| 87 | return false; |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | bool ProxyNode::addChild(Node *child, const std::string& filename) |
|---|
| 91 | { |
|---|
| 92 | if (Group::addChild(child)) |
|---|
| 93 | { |
|---|
| 94 | setFileName(_children.size()-1,filename); |
|---|
| 95 | return true; |
|---|
| 96 | } |
|---|
| 97 | return false; |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | bool ProxyNode::removeChildren(unsigned int pos,unsigned int numChildrenToRemove) |
|---|
| 101 | { |
|---|
| 102 | if (pos<_filenameList.size()) _filenameList.erase(_filenameList.begin()+pos, osg::minimum(_filenameList.begin()+(pos+numChildrenToRemove), _filenameList.end()) ); |
|---|
| 103 | |
|---|
| 104 | return Group::removeChildren(pos,numChildrenToRemove); |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | BoundingSphere ProxyNode::computeBound() const |
|---|
| 108 | { |
|---|
| 109 | if (_centerMode==USER_DEFINED_CENTER && _radius>=0.0f) |
|---|
| 110 | { |
|---|
| 111 | return BoundingSphere(_userDefinedCenter,_radius); |
|---|
| 112 | } |
|---|
| 113 | else |
|---|
| 114 | { |
|---|
| 115 | return Group::computeBound(); |
|---|
| 116 | } |
|---|
| 117 | } |
|---|
| 118 | |
|---|