| 1 | #include <osg/PagedLOD> |
|---|
| 2 | #include <osgDB/ObjectWrapper> |
|---|
| 3 | #include <osgDB/InputStream> |
|---|
| 4 | #include <osgDB/OutputStream> |
|---|
| 5 | #include <osgDB/Options> |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | static bool checkDatabasePath( const osg::PagedLOD& node ) |
|---|
| 9 | { |
|---|
| 10 | return true; |
|---|
| 11 | } |
|---|
| 12 | |
|---|
| 13 | static bool readDatabasePath( osgDB::InputStream& is, osg::PagedLOD& node ) |
|---|
| 14 | { |
|---|
| 15 | bool hasPath; is >> hasPath; |
|---|
| 16 | if ( !hasPath ) |
|---|
| 17 | { |
|---|
| 18 | if ( is.getOptions() && !is.getOptions()->getDatabasePathList().empty() ) |
|---|
| 19 | { |
|---|
| 20 | const std::string& optionPath = is.getOptions()->getDatabasePathList().front(); |
|---|
| 21 | if ( !optionPath.empty() ) node.setDatabasePath( optionPath ); |
|---|
| 22 | } |
|---|
| 23 | } |
|---|
| 24 | else |
|---|
| 25 | { |
|---|
| 26 | std::string path; is.readWrappedString( path ); |
|---|
| 27 | node.setDatabasePath( path ); |
|---|
| 28 | } |
|---|
| 29 | return true; |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | static bool writeDatabasePath( osgDB::OutputStream& os, const osg::PagedLOD& node ) |
|---|
| 33 | { |
|---|
| 34 | os << (!node.getDatabasePath().empty()); |
|---|
| 35 | if ( !node.getDatabasePath().empty() ) |
|---|
| 36 | os.writeWrappedString( node.getDatabasePath() ); |
|---|
| 37 | os << std::endl; |
|---|
| 38 | return true; |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | static bool checkRangeDataList( const osg::PagedLOD& node ) |
|---|
| 43 | { |
|---|
| 44 | return node.getNumFileNames()>0; |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | static bool readRangeDataList( osgDB::InputStream& is, osg::PagedLOD& node ) |
|---|
| 48 | { |
|---|
| 49 | unsigned int size = 0; is >> size >> osgDB::BEGIN_BRACKET; |
|---|
| 50 | for ( unsigned int i=0; i<size; ++i ) |
|---|
| 51 | { |
|---|
| 52 | std::string name; is.readWrappedString( name ); |
|---|
| 53 | node.setFileName( i, name ); |
|---|
| 54 | } |
|---|
| 55 | is >> osgDB::END_BRACKET; |
|---|
| 56 | |
|---|
| 57 | size = 0; is >> osgDB::PROPERTY("PriorityList") >> size >> osgDB::BEGIN_BRACKET; |
|---|
| 58 | for ( unsigned int i=0; i<size; ++i ) |
|---|
| 59 | { |
|---|
| 60 | float offset, scale; |
|---|
| 61 | is >> offset >> scale; |
|---|
| 62 | |
|---|
| 63 | node.setPriorityOffset( i, offset ); |
|---|
| 64 | node.setPriorityScale( i, scale ); |
|---|
| 65 | } |
|---|
| 66 | is >> osgDB::END_BRACKET; |
|---|
| 67 | return true; |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | static bool writeRangeDataList( osgDB::OutputStream& os, const osg::PagedLOD& node ) |
|---|
| 71 | { |
|---|
| 72 | unsigned int size = node.getNumFileNames(); |
|---|
| 73 | os << size << osgDB::BEGIN_BRACKET << std::endl; |
|---|
| 74 | for ( unsigned int i=0; i<size; ++i ) |
|---|
| 75 | { |
|---|
| 76 | os.writeWrappedString( node.getFileName(i) ); |
|---|
| 77 | os << std::endl; |
|---|
| 78 | } |
|---|
| 79 | os << osgDB::END_BRACKET << std::endl; |
|---|
| 80 | |
|---|
| 81 | size = node.getNumPriorityOffsets(); |
|---|
| 82 | os << osgDB::PROPERTY("PriorityList") << size << osgDB::BEGIN_BRACKET << std::endl; |
|---|
| 83 | for ( unsigned int i=0; i<size; ++i ) |
|---|
| 84 | { |
|---|
| 85 | os << node.getPriorityOffset(i) << node.getPriorityScale(i) << std::endl; |
|---|
| 86 | } |
|---|
| 87 | os << osgDB::END_BRACKET << std::endl; |
|---|
| 88 | return true; |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | |
|---|
| 92 | static bool checkChildren( const osg::PagedLOD& node ) |
|---|
| 93 | { |
|---|
| 94 | return node.getNumChildren()>0; |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | static bool readChildren( osgDB::InputStream& is, osg::PagedLOD& node ) |
|---|
| 98 | { |
|---|
| 99 | unsigned int size = 0; is >> size >> osgDB::BEGIN_BRACKET; |
|---|
| 100 | for ( unsigned int i=0; i<size; ++i ) |
|---|
| 101 | { |
|---|
| 102 | osg::Node* child = dynamic_cast<osg::Node*>( is.readObject() ); |
|---|
| 103 | if ( child ) node.addChild( child ); |
|---|
| 104 | } |
|---|
| 105 | is >> osgDB::END_BRACKET; |
|---|
| 106 | return true; |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | static bool writeChildren( osgDB::OutputStream& os, const osg::PagedLOD& node ) |
|---|
| 110 | { |
|---|
| 111 | unsigned int size=node.getNumFileNames(), dynamicLoadedSize=0; |
|---|
| 112 | for ( unsigned int i=0; i<size; ++i ) |
|---|
| 113 | { |
|---|
| 114 | if ( !node.getFileName(i).empty() ) |
|---|
| 115 | dynamicLoadedSize++; |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | unsigned int realSize = size-dynamicLoadedSize; os << realSize; |
|---|
| 119 | if ( realSize>0 ) |
|---|
| 120 | { |
|---|
| 121 | os << osgDB::BEGIN_BRACKET << std::endl; |
|---|
| 122 | for ( unsigned int i=0; i<size; ++i ) |
|---|
| 123 | { |
|---|
| 124 | if ( !node.getFileName(i).empty() ) continue; |
|---|
| 125 | if ( i<node.getNumChildren() ) |
|---|
| 126 | os << node.getChild(i); |
|---|
| 127 | } |
|---|
| 128 | os << osgDB::END_BRACKET; |
|---|
| 129 | } |
|---|
| 130 | os << std::endl; |
|---|
| 131 | return true; |
|---|
| 132 | } |
|---|
| 133 | |
|---|
| 134 | REGISTER_OBJECT_WRAPPER( PagedLOD, |
|---|
| 135 | new osg::PagedLOD, |
|---|
| 136 | osg::PagedLOD, |
|---|
| 137 | "osg::Object osg::Node osg::LOD osg::PagedLOD" ) |
|---|
| 138 | { |
|---|
| 139 | |
|---|
| 140 | |
|---|
| 141 | ADD_USER_SERIALIZER( DatabasePath ); |
|---|
| 142 | ADD_UINT_SERIALIZER( FrameNumberOfLastTraversal, 0 ); |
|---|
| 143 | ADD_UINT_SERIALIZER( NumChildrenThatCannotBeExpired, 0 ); |
|---|
| 144 | ADD_BOOL_SERIALIZER( DisableExternalChildrenPaging, false ); |
|---|
| 145 | ADD_USER_SERIALIZER( RangeDataList ); |
|---|
| 146 | ADD_USER_SERIALIZER( Children ); |
|---|
| 147 | |
|---|
| 148 | UPDATE_TO_VERSION( 70 ) |
|---|
| 149 | { |
|---|
| 150 | REMOVE_SERIALIZER( FrameNumberOfLastTraversal ); |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | |
|---|
| 154 | |
|---|
| 155 | } |
|---|