| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | #include "Exception.h" |
|---|
| 16 | #include "PagedLOD.h" |
|---|
| 17 | #include "Node.h" |
|---|
| 18 | |
|---|
| 19 | #include <osgDB/Options> |
|---|
| 20 | |
|---|
| 21 | using namespace ive; |
|---|
| 22 | |
|---|
| 23 | void PagedLOD::write(DataOutputStream* out) |
|---|
| 24 | { |
|---|
| 25 | |
|---|
| 26 | out->writeInt(IVEPAGEDLOD); |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | osg::Node* node = dynamic_cast<osg::Node*>(this); |
|---|
| 30 | if(node){ |
|---|
| 31 | static_cast<ive::Node*>(node)->write(out); |
|---|
| 32 | } |
|---|
| 33 | else |
|---|
| 34 | out_THROW_EXCEPTION("PagedLOD::write(): Could not cast this osg::PagedLOD to an osg::Node."); |
|---|
| 35 | |
|---|
| 36 | out->writeString(getDatabasePath()); |
|---|
| 37 | out->writeFloat(getRadius()); |
|---|
| 38 | out->writeUInt(getNumChildrenThatCannotBeExpired()); |
|---|
| 39 | |
|---|
| 40 | if ( out->getVersion() >= VERSION_0041 ) |
|---|
| 41 | { |
|---|
| 42 | out->writeBool(getDisableExternalChildrenPaging()); |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | unsigned int numChildrenToWriteOut = 0; |
|---|
| 46 | |
|---|
| 47 | int i; |
|---|
| 48 | for(i=0; i<(int)getNumFileNames();++i) |
|---|
| 49 | { |
|---|
| 50 | if (getFileName(i).empty()) |
|---|
| 51 | { |
|---|
| 52 | ++numChildrenToWriteOut; |
|---|
| 53 | } |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | out->writeInt(numChildrenToWriteOut); |
|---|
| 59 | |
|---|
| 60 | for(i=0; i<(int)getNumChildren(); i++){ |
|---|
| 61 | if (getFileName(i).empty()) |
|---|
| 62 | { |
|---|
| 63 | osg::Node* child = getChild(i); |
|---|
| 64 | out->writeNode(child); |
|---|
| 65 | } |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | out->writeInt(getCenterMode()); |
|---|
| 71 | out->writeVec3(getCenter()); |
|---|
| 72 | |
|---|
| 73 | out->writeInt(getRangeMode()); |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | int size = getNumRanges(); |
|---|
| 78 | out->writeInt(size); |
|---|
| 79 | for(i=0;i<size;i++){ |
|---|
| 80 | out->writeFloat(getMinRange(i)); |
|---|
| 81 | out->writeFloat(getMaxRange(i)); |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | size = getNumFileNames(); |
|---|
| 87 | out->writeInt(size); |
|---|
| 88 | for(i=0;i<size;i++){ |
|---|
| 89 | out->writeString(getFileName(i)); |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | |
|---|
| 93 | |
|---|
| 94 | if ( out->getVersion() >= VERSION_0015 ) |
|---|
| 95 | { |
|---|
| 96 | size = getNumPriorityOffsets(); |
|---|
| 97 | out->writeInt( size ); |
|---|
| 98 | for(i=0; i<size; i++) |
|---|
| 99 | { |
|---|
| 100 | out->writeFloat( getPriorityOffset( i ) ); |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | size = getNumPriorityScales(); |
|---|
| 104 | out->writeInt( size ); |
|---|
| 105 | for(i=0; i<size; i++ ) |
|---|
| 106 | { |
|---|
| 107 | out->writeFloat( getPriorityScale( i ) ); |
|---|
| 108 | } |
|---|
| 109 | } |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | void PagedLOD::read(DataInputStream* in) |
|---|
| 113 | { |
|---|
| 114 | |
|---|
| 115 | int id = in->peekInt(); |
|---|
| 116 | if(id == IVEPAGEDLOD) |
|---|
| 117 | { |
|---|
| 118 | |
|---|
| 119 | id = in->readInt(); |
|---|
| 120 | |
|---|
| 121 | osg::Node* node = dynamic_cast<osg::Node*>(this); |
|---|
| 122 | if(node){ |
|---|
| 123 | ((ive::Node*)(node))->read(in); |
|---|
| 124 | } |
|---|
| 125 | else |
|---|
| 126 | in_THROW_EXCEPTION("PagedLOD::read(): Could not cast this osg::PagedLOD to an osg::Node."); |
|---|
| 127 | |
|---|
| 128 | |
|---|
| 129 | if ( in->getVersion() >= VERSION_0006 ) |
|---|
| 130 | { |
|---|
| 131 | setDatabasePath(in->readString()); |
|---|
| 132 | } |
|---|
| 133 | |
|---|
| 134 | if (getDatabasePath().empty() && in->getOptions() && !in->getOptions()->getDatabasePathList().empty()) |
|---|
| 135 | { |
|---|
| 136 | const std::string& path = in->getOptions()->getDatabasePathList().front(); |
|---|
| 137 | if (!path.empty()) |
|---|
| 138 | { |
|---|
| 139 | setDatabasePath(path); |
|---|
| 140 | } |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| 143 | |
|---|
| 144 | setRadius(in->readFloat()); |
|---|
| 145 | setNumChildrenThatCannotBeExpired(in->readUInt()); |
|---|
| 146 | |
|---|
| 147 | if ( in->getVersion() >= VERSION_0041 ) |
|---|
| 148 | { |
|---|
| 149 | setDisableExternalChildrenPaging(in->readBool()); |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | |
|---|
| 153 | |
|---|
| 154 | |
|---|
| 155 | int size = in->readInt(); |
|---|
| 156 | |
|---|
| 157 | int i; |
|---|
| 158 | for(i=0; i<size; i++) |
|---|
| 159 | { |
|---|
| 160 | addChild(in->readNode()); |
|---|
| 161 | } |
|---|
| 162 | |
|---|
| 163 | |
|---|
| 164 | setCenterMode((osg::LOD::CenterMode)in->readInt()); |
|---|
| 165 | setCenter(in->readVec3()); |
|---|
| 166 | |
|---|
| 167 | setRangeMode((RangeMode)in->readInt()); |
|---|
| 168 | |
|---|
| 169 | |
|---|
| 170 | size = in->readInt(); |
|---|
| 171 | for(i=0;i<size;i++){ |
|---|
| 172 | float min = in->readFloat(); |
|---|
| 173 | float max = in->readFloat(); |
|---|
| 174 | setRange(i, min, max); |
|---|
| 175 | } |
|---|
| 176 | |
|---|
| 177 | size = in->readInt(); |
|---|
| 178 | for(i=0;i<size;i++){ |
|---|
| 179 | setFileName(i, in->readString()); |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | |
|---|
| 183 | |
|---|
| 184 | |
|---|
| 185 | if ( in->getVersion() >= VERSION_0015 ) |
|---|
| 186 | { |
|---|
| 187 | |
|---|
| 188 | size = in->readInt(); |
|---|
| 189 | for(i=0; i<size; i++ ) |
|---|
| 190 | { |
|---|
| 191 | float pri_offset = in->readFloat(); |
|---|
| 192 | setPriorityOffset( i, pri_offset ); |
|---|
| 193 | } |
|---|
| 194 | |
|---|
| 195 | |
|---|
| 196 | size = in->readInt(); |
|---|
| 197 | for(i=0; i<size; i++ ) |
|---|
| 198 | { |
|---|
| 199 | float pri_scale = in->readFloat(); |
|---|
| 200 | setPriorityScale( i, pri_scale ); |
|---|
| 201 | } |
|---|
| 202 | |
|---|
| 203 | } |
|---|
| 204 | } |
|---|
| 205 | else{ |
|---|
| 206 | in_THROW_EXCEPTION("LOD::read(): Expected LOD identification."); |
|---|
| 207 | } |
|---|
| 208 | } |
|---|