| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | #ifndef __TXPARCHIVE_H_ |
|---|
| 35 | #define __TXPARCHIVE_H_ |
|---|
| 36 | |
|---|
| 37 | #include "trpage_sys.h" |
|---|
| 38 | #include "trpage_read.h" |
|---|
| 39 | #include "trpage_geom.h" |
|---|
| 40 | |
|---|
| 41 | #include <osg/Referenced> |
|---|
| 42 | #include <osg/BoundingBox> |
|---|
| 43 | #include <osg/Texture2D> |
|---|
| 44 | #include <osg/StateSet> |
|---|
| 45 | #include <osg/Node> |
|---|
| 46 | #include <osg/PagedLOD> |
|---|
| 47 | #include <osg/Array> |
|---|
| 48 | #include <osgSim/LightPointNode> |
|---|
| 49 | #include <osgText/Font> |
|---|
| 50 | |
|---|
| 51 | #include <OpenThreads/Mutex> |
|---|
| 52 | |
|---|
| 53 | namespace txp |
|---|
| 54 | { |
|---|
| 55 | |
|---|
| 56 | struct DeferredLightAttribute |
|---|
| 57 | { |
|---|
| 58 | |
|---|
| 59 | osg::ref_ptr<osgSim::LightPointNode> lightPoint; |
|---|
| 60 | osg::ref_ptr<osg::StateSet> fallback; |
|---|
| 61 | osg::Vec3 attitude; |
|---|
| 62 | }; |
|---|
| 63 | |
|---|
| 64 | class TXPParser; |
|---|
| 65 | class TXPArchive : public trpgr_Archive, public osg::Referenced |
|---|
| 66 | { |
|---|
| 67 | public: |
|---|
| 68 | |
|---|
| 69 | TXPArchive(); |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | bool openFile(const std::string& archiveName); |
|---|
| 73 | |
|---|
| 74 | bool loadMaterials(); |
|---|
| 75 | bool loadMaterial(int ix); |
|---|
| 76 | bool loadTexture(int i); |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | bool loadModels(); |
|---|
| 80 | bool loadModel(int ix); |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | bool loadLightAttributes(); |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | bool loadTextStyles(); |
|---|
| 87 | inline std::map<int, osg::ref_ptr<osgText::Font> >& getStyles() |
|---|
| 88 | { |
|---|
| 89 | return _fonts; |
|---|
| 90 | } |
|---|
| 91 | inline std::map<int, osg::Vec4 >& getTextColors() |
|---|
| 92 | { |
|---|
| 93 | return _fcolors; |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | |
|---|
| 97 | void addLightAttribute(osgSim::LightPointNode* lpn, osg::StateSet* fallback , const osg::Vec3& attitude,int handle); |
|---|
| 98 | |
|---|
| 99 | int getNumLightAttributes() |
|---|
| 100 | { |
|---|
| 101 | return _lights.size(); |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | inline DeferredLightAttribute& getLightAttribute(unsigned int i) |
|---|
| 106 | { |
|---|
| 107 | return _lights[i]; |
|---|
| 108 | }; |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | struct TileInfo |
|---|
| 112 | { |
|---|
| 113 | osg::Vec3 center; |
|---|
| 114 | double minRange; |
|---|
| 115 | double maxRange; |
|---|
| 116 | double lod0Range; |
|---|
| 117 | float radius; |
|---|
| 118 | osg::Vec3 size; |
|---|
| 119 | osg::BoundingBox bbox; |
|---|
| 120 | }; |
|---|
| 121 | struct TileLocationInfo |
|---|
| 122 | { |
|---|
| 123 | TileLocationInfo() : x( -1 ), y( -1 ), lod( -1 ) |
|---|
| 124 | {} |
|---|
| 125 | TileLocationInfo(int gx, int gy, int glod, const trpgwAppAddress& gaddr, float gzmin = 0.0f, float gzmax = 0.0f): |
|---|
| 126 | x( gx ), y( gy ), lod( glod ), addr( gaddr ), zmin( gzmin ), zmax( gzmax ) |
|---|
| 127 | {} |
|---|
| 128 | int x, y, lod; |
|---|
| 129 | trpgwAppAddress addr; |
|---|
| 130 | float zmin, zmax; |
|---|
| 131 | }; |
|---|
| 132 | |
|---|
| 133 | bool getTileInfo(int x, int y, int lod, TileInfo& info); |
|---|
| 134 | bool getTileInfo(const TileLocationInfo& loc, TileInfo& info); |
|---|
| 135 | |
|---|
| 136 | |
|---|
| 137 | inline void setId(int id) |
|---|
| 138 | { |
|---|
| 139 | _id = id; |
|---|
| 140 | } |
|---|
| 141 | inline const int& getId() const |
|---|
| 142 | { |
|---|
| 143 | return _id; |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | inline const int& getNumLODs() const |
|---|
| 148 | { |
|---|
| 149 | return _numLODs; |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | |
|---|
| 153 | |
|---|
| 154 | void getExtents(osg::BoundingBox& extents); |
|---|
| 155 | |
|---|
| 156 | |
|---|
| 157 | |
|---|
| 158 | |
|---|
| 159 | |
|---|
| 160 | inline void getOrigin(double& x, double& y) |
|---|
| 161 | { |
|---|
| 162 | x=_swExtents.x; |
|---|
| 163 | y=_swExtents.y; |
|---|
| 164 | } |
|---|
| 165 | |
|---|
| 166 | |
|---|
| 167 | inline osg::Texture2D* getGlobalTexture(int id) |
|---|
| 168 | { |
|---|
| 169 | return GetTexMapEntry(id).get(); |
|---|
| 170 | } |
|---|
| 171 | |
|---|
| 172 | |
|---|
| 173 | |
|---|
| 174 | |
|---|
| 175 | |
|---|
| 176 | osg::Group* getTileContent( |
|---|
| 177 | int x, |
|---|
| 178 | int y, |
|---|
| 179 | int lod, |
|---|
| 180 | double realMinRange, |
|---|
| 181 | double realMaxRange, |
|---|
| 182 | double usedMaxRange, |
|---|
| 183 | osg::Vec3& tileCenter, |
|---|
| 184 | std::vector<TileLocationInfo>& childInfoList); |
|---|
| 185 | |
|---|
| 186 | |
|---|
| 187 | osg::Group* getTileContent( |
|---|
| 188 | const TileLocationInfo& loc, |
|---|
| 189 | double realMinRange, |
|---|
| 190 | double realMaxRange, |
|---|
| 191 | double usedMaxRange, |
|---|
| 192 | osg::Vec3& tileCenter, |
|---|
| 193 | std::vector<TileLocationInfo>& childInfoList); |
|---|
| 194 | |
|---|
| 195 | |
|---|
| 196 | bool getLODSize(int lod, int& x, int& y); |
|---|
| 197 | |
|---|
| 198 | void GetVersion(int& majorVer, int& minorVer) const |
|---|
| 199 | { |
|---|
| 200 | majorVer = _majorVersion; |
|---|
| 201 | minorVer = _minorVersion; |
|---|
| 202 | } |
|---|
| 203 | |
|---|
| 204 | |
|---|
| 205 | |
|---|
| 206 | |
|---|
| 207 | |
|---|
| 208 | |
|---|
| 209 | |
|---|
| 210 | |
|---|
| 211 | void SetUserDataToMaterialAttributes(osg::StateSet& osg_state_set, const trpgMaterial& mat) |
|---|
| 212 | { |
|---|
| 213 | if(!_loadMaterialsToStateSet) |
|---|
| 214 | return; |
|---|
| 215 | |
|---|
| 216 | int attr_values = 0; |
|---|
| 217 | osg::ref_ptr<osg::IntArray> ourValueArray = new osg::IntArray(); |
|---|
| 218 | for(int attrIter = 0 ; attrIter < 4; ++attrIter) |
|---|
| 219 | { |
|---|
| 220 | mat.GetAttr(attrIter, attr_values); |
|---|
| 221 | ourValueArray->push_back(attr_values); |
|---|
| 222 | } |
|---|
| 223 | osg_state_set.setUserData(ourValueArray.get()); |
|---|
| 224 | } |
|---|
| 225 | |
|---|
| 226 | void SetMaterialAttributesToStateSetVar(bool value) {_loadMaterialsToStateSet = value;} |
|---|
| 227 | |
|---|
| 228 | protected: |
|---|
| 229 | |
|---|
| 230 | |
|---|
| 231 | virtual ~TXPArchive(); |
|---|
| 232 | |
|---|
| 233 | |
|---|
| 234 | int _id; |
|---|
| 235 | |
|---|
| 236 | |
|---|
| 237 | int _numLODs; |
|---|
| 238 | |
|---|
| 239 | |
|---|
| 240 | trpg2dPoint _swExtents; |
|---|
| 241 | trpg2dPoint _neExtents; |
|---|
| 242 | |
|---|
| 243 | |
|---|
| 244 | osg::ref_ptr<TXPParser> _parser; |
|---|
| 245 | |
|---|
| 246 | |
|---|
| 247 | typedef std::map<int,osg::ref_ptr<osg::Texture2D> > OSGTexMapType; |
|---|
| 248 | OSGTexMapType _texmap; |
|---|
| 249 | |
|---|
| 250 | void SetTexMap(int key,osg::ref_ptr<osg::Texture2D> ref); |
|---|
| 251 | osg::ref_ptr<osg::Texture2D> GetTexMapEntry(int key); |
|---|
| 252 | |
|---|
| 253 | |
|---|
| 254 | |
|---|
| 255 | typedef std::map<int,osg::ref_ptr<osg::StateSet> > OSGStatesMapType; |
|---|
| 256 | OSGStatesMapType _statesMap; |
|---|
| 257 | |
|---|
| 258 | void SetStatesMap(int key,osg::ref_ptr<osg::StateSet> ref); |
|---|
| 259 | osg::ref_ptr<osg::StateSet> GetStatesMapEntry(int key); |
|---|
| 260 | |
|---|
| 261 | |
|---|
| 262 | typedef std::map<int,osg::ref_ptr<osg::Node> > OSGModelsMapType; |
|---|
| 263 | OSGModelsMapType _models; |
|---|
| 264 | |
|---|
| 265 | |
|---|
| 266 | std::map<int, DeferredLightAttribute> _lights; |
|---|
| 267 | |
|---|
| 268 | |
|---|
| 269 | std::map<int, osg::ref_ptr<osgText::Font> > _fonts; |
|---|
| 270 | |
|---|
| 271 | |
|---|
| 272 | std::map<int, osg::Vec4 > _fcolors; |
|---|
| 273 | |
|---|
| 274 | |
|---|
| 275 | OpenThreads::Mutex _mutex; |
|---|
| 276 | |
|---|
| 277 | |
|---|
| 278 | int _majorVersion, _minorVersion; |
|---|
| 279 | |
|---|
| 280 | bool _isMaster; |
|---|
| 281 | |
|---|
| 282 | bool _loadMaterialsToStateSet; |
|---|
| 283 | |
|---|
| 284 | }; |
|---|
| 285 | |
|---|
| 286 | } |
|---|
| 287 | |
|---|
| 288 | #endif // __TXPARCHIVE_H_ |
|---|
| 289 | |
|---|