| 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 | |
|---|
| 35 | #ifndef __TXPPARSER_H_ |
|---|
| 36 | #define __TXPPARSER_H_ |
|---|
| 37 | |
|---|
| 38 | #include <osg/Referenced> |
|---|
| 39 | #include <osg/Texture2D> |
|---|
| 40 | #include <osg/StateSet> |
|---|
| 41 | #include <osg/Node> |
|---|
| 42 | |
|---|
| 43 | #include <stack> |
|---|
| 44 | |
|---|
| 45 | #include "trpage_read.h" |
|---|
| 46 | |
|---|
| 47 | #include "TXPArchive.h" |
|---|
| 48 | |
|---|
| 49 | namespace txp |
|---|
| 50 | { |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | osg::Texture2D* getLocalTexture(trpgrImageHelper& image_helper, const trpgTexture* tex); |
|---|
| 54 | osg::Texture2D* getTemplateTexture(trpgrImageHelper& image_helper, trpgLocalMaterial* locmat, const trpgTexture* tex, int index=0); |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | class GeodeGroup : public osg::Group |
|---|
| 78 | { |
|---|
| 79 | public: |
|---|
| 80 | |
|---|
| 81 | GeodeGroup() : osg::Group(), _geode(NULL) |
|---|
| 82 | {} |
|---|
| 83 | |
|---|
| 84 | GeodeGroup(const GeodeGroup& gg,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY): |
|---|
| 85 | osg::Group(gg, copyop), _geode(gg._geode) |
|---|
| 86 | {} |
|---|
| 87 | |
|---|
| 88 | META_Node(txp, GeodeGroup); |
|---|
| 89 | |
|---|
| 90 | osg::Geode* getGeode() |
|---|
| 91 | { |
|---|
| 92 | if (_geode == 0) |
|---|
| 93 | { |
|---|
| 94 | _geode = new osg::Geode(); |
|---|
| 95 | addChild(_geode); |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | return _geode; |
|---|
| 99 | } |
|---|
| 100 | protected: |
|---|
| 101 | osg::Geode* _geode; |
|---|
| 102 | }; |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | class TXPArchive; |
|---|
| 106 | class childRefRead; |
|---|
| 107 | struct DeferredLightAttribute; |
|---|
| 108 | |
|---|
| 109 | class TXPParser : public trpgSceneParser, public osg::Referenced |
|---|
| 110 | { |
|---|
| 111 | public: |
|---|
| 112 | TXPParser(); |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | inline void setArchive(TXPArchive* archive) |
|---|
| 116 | { |
|---|
| 117 | _archive = archive; |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | |
|---|
| 121 | inline TXPArchive* getArchive() |
|---|
| 122 | { |
|---|
| 123 | return _archive.get(); |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | |
|---|
| 127 | osg::Group *parseScene( |
|---|
| 128 | trpgReadBuffer &buf, |
|---|
| 129 | std::map<int,osg::ref_ptr<osg::StateSet> > &materials, |
|---|
| 130 | std::map<int,osg::ref_ptr<osg::Node> > &models, |
|---|
| 131 | double realMinRange, double realMaxRange, double usedMaxRange); |
|---|
| 132 | |
|---|
| 133 | |
|---|
| 134 | inline osg::Group* getCurrTop() |
|---|
| 135 | { |
|---|
| 136 | return _currentTop ? _currentTop : _root.get(); |
|---|
| 137 | } |
|---|
| 138 | |
|---|
| 139 | |
|---|
| 140 | inline void setPotentionalTileGroup(osg::Group* grp) |
|---|
| 141 | { |
|---|
| 142 | _tileGroups[grp] = 1; |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | |
|---|
| 146 | inline std::map<int,osg::ref_ptr<osg::StateSet> >* getMaterials() |
|---|
| 147 | { |
|---|
| 148 | return _materialMap; |
|---|
| 149 | } |
|---|
| 150 | |
|---|
| 151 | |
|---|
| 152 | inline void loadMaterial( int ix ) |
|---|
| 153 | { |
|---|
| 154 | _archive->loadMaterial( ix ); |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | |
|---|
| 158 | std::vector<osg::ref_ptr<osg::StateSet> >* getLocalMaterials() |
|---|
| 159 | { |
|---|
| 160 | return &_localMaterials; |
|---|
| 161 | } |
|---|
| 162 | |
|---|
| 163 | |
|---|
| 164 | void loadLocalMaterials(); |
|---|
| 165 | |
|---|
| 166 | |
|---|
| 167 | std::map<int,osg::ref_ptr<osg::Node> >* getModels() |
|---|
| 168 | { |
|---|
| 169 | return _models; |
|---|
| 170 | } |
|---|
| 171 | |
|---|
| 172 | |
|---|
| 173 | bool requestModel(int ix); |
|---|
| 174 | |
|---|
| 175 | |
|---|
| 176 | inline trpgTileHeader *getTileHeaderRef() |
|---|
| 177 | { |
|---|
| 178 | return &_tileHeader; |
|---|
| 179 | } |
|---|
| 180 | |
|---|
| 181 | |
|---|
| 182 | |
|---|
| 183 | inline const bool underBillboardSubgraph() const |
|---|
| 184 | { |
|---|
| 185 | return _underBillboardSubgraph; |
|---|
| 186 | } |
|---|
| 187 | |
|---|
| 188 | |
|---|
| 189 | inline void setUnderBillboardSubgraph(bool b) |
|---|
| 190 | { |
|---|
| 191 | _underBillboardSubgraph = b; |
|---|
| 192 | } |
|---|
| 193 | |
|---|
| 194 | |
|---|
| 195 | struct TXPBillboardInfo |
|---|
| 196 | { |
|---|
| 197 | int type; |
|---|
| 198 | int mode; |
|---|
| 199 | trpg3dPoint center; |
|---|
| 200 | trpg3dPoint axis; |
|---|
| 201 | }; |
|---|
| 202 | |
|---|
| 203 | |
|---|
| 204 | inline void setLastBillboardInfo(TXPBillboardInfo& info) |
|---|
| 205 | { |
|---|
| 206 | _lastBillboardInfo = info; |
|---|
| 207 | } |
|---|
| 208 | |
|---|
| 209 | |
|---|
| 210 | inline void getLastBillboardInfo(TXPBillboardInfo& info) |
|---|
| 211 | { |
|---|
| 212 | info = _lastBillboardInfo; |
|---|
| 213 | } |
|---|
| 214 | |
|---|
| 215 | |
|---|
| 216 | DeferredLightAttribute& getLightAttribute(int ix); |
|---|
| 217 | |
|---|
| 218 | |
|---|
| 219 | inline const bool underLayerSubgraph() const |
|---|
| 220 | { |
|---|
| 221 | return _underLayerSubgraph; |
|---|
| 222 | } |
|---|
| 223 | |
|---|
| 224 | |
|---|
| 225 | inline void setUnderLayerSubgraph(bool b) |
|---|
| 226 | { |
|---|
| 227 | _underLayerSubgraph = b; |
|---|
| 228 | } |
|---|
| 229 | |
|---|
| 230 | |
|---|
| 231 | inline void setLayerGeode(osg::Geode* layer) |
|---|
| 232 | { |
|---|
| 233 | _layerGeode = layer; |
|---|
| 234 | } |
|---|
| 235 | |
|---|
| 236 | |
|---|
| 237 | inline osg::Geode* getLayerGeode() const |
|---|
| 238 | { |
|---|
| 239 | return _layerGeode; |
|---|
| 240 | } |
|---|
| 241 | |
|---|
| 242 | inline unsigned int getNumLayerLavels() const { return _numLayerLevels; } |
|---|
| 243 | |
|---|
| 244 | |
|---|
| 245 | void setMaxAnisotropy(float anisotropy) |
|---|
| 246 | { |
|---|
| 247 | _defaultMaxAnisotropy = anisotropy; |
|---|
| 248 | } |
|---|
| 249 | float getMaxAnisotropy() const |
|---|
| 250 | { |
|---|
| 251 | return _defaultMaxAnisotropy; |
|---|
| 252 | } |
|---|
| 253 | |
|---|
| 254 | |
|---|
| 255 | |
|---|
| 256 | inline double checkAndGetMinRange(double range) |
|---|
| 257 | { |
|---|
| 258 | if ((range-_realMinRange) < 0.0001) |
|---|
| 259 | return 0.0; |
|---|
| 260 | else |
|---|
| 261 | return range; |
|---|
| 262 | } |
|---|
| 263 | inline double checkAndGetMaxRange(double range) |
|---|
| 264 | { |
|---|
| 265 | if ((range-_realMaxRange) < 0.0001) |
|---|
| 266 | return _usedMaxRange; |
|---|
| 267 | else |
|---|
| 268 | return range; |
|---|
| 269 | } |
|---|
| 270 | |
|---|
| 271 | |
|---|
| 272 | inline const osg::Vec3 getTileCenter() const |
|---|
| 273 | { |
|---|
| 274 | return _tileCenter; |
|---|
| 275 | } |
|---|
| 276 | |
|---|
| 277 | inline void setCurrentNode( osg::Node* node ) |
|---|
| 278 | { |
|---|
| 279 | _currentNode = node; |
|---|
| 280 | } |
|---|
| 281 | |
|---|
| 282 | |
|---|
| 283 | unsigned int GetNbChildrenRef() const; |
|---|
| 284 | |
|---|
| 285 | |
|---|
| 286 | |
|---|
| 287 | const trpgChildRef* GetChildRef(unsigned int idx) const; |
|---|
| 288 | |
|---|
| 289 | |
|---|
| 290 | |
|---|
| 291 | protected: |
|---|
| 292 | |
|---|
| 293 | virtual ~TXPParser(); |
|---|
| 294 | |
|---|
| 295 | |
|---|
| 296 | void removeEmptyGroups(); |
|---|
| 297 | |
|---|
| 298 | |
|---|
| 299 | bool StartChildren(void *); |
|---|
| 300 | |
|---|
| 301 | |
|---|
| 302 | bool EndChildren(void *); |
|---|
| 303 | |
|---|
| 304 | |
|---|
| 305 | osg::ref_ptr< TXPArchive > _archive; |
|---|
| 306 | |
|---|
| 307 | |
|---|
| 308 | osg::Group* _currentTop; |
|---|
| 309 | |
|---|
| 310 | |
|---|
| 311 | osg::Node* _currentNode; |
|---|
| 312 | |
|---|
| 313 | |
|---|
| 314 | osg::ref_ptr<osg::Group> _root; |
|---|
| 315 | |
|---|
| 316 | |
|---|
| 317 | std::stack<osg::Group*> _parents; |
|---|
| 318 | |
|---|
| 319 | |
|---|
| 320 | std::map<osg::Group*,int> _tileGroups; |
|---|
| 321 | |
|---|
| 322 | |
|---|
| 323 | void replaceTileLod(osg::Group*); |
|---|
| 324 | |
|---|
| 325 | |
|---|
| 326 | typedef std::map<int,osg::ref_ptr<osg::StateSet> >* MaterialMapType; |
|---|
| 327 | MaterialMapType _materialMap; |
|---|
| 328 | |
|---|
| 329 | |
|---|
| 330 | std::vector<osg::ref_ptr<osg::StateSet> > _localMaterials; |
|---|
| 331 | |
|---|
| 332 | |
|---|
| 333 | typedef std::map<int,osg::ref_ptr<osg::Node> > OSGModelsMapType; |
|---|
| 334 | OSGModelsMapType* _models; |
|---|
| 335 | |
|---|
| 336 | |
|---|
| 337 | trpgTileHeader _tileHeader; |
|---|
| 338 | |
|---|
| 339 | |
|---|
| 340 | bool _underBillboardSubgraph; |
|---|
| 341 | |
|---|
| 342 | |
|---|
| 343 | int _numBillboardLevels; |
|---|
| 344 | |
|---|
| 345 | |
|---|
| 346 | TXPBillboardInfo _lastBillboardInfo; |
|---|
| 347 | |
|---|
| 348 | |
|---|
| 349 | bool _underLayerSubgraph; |
|---|
| 350 | |
|---|
| 351 | |
|---|
| 352 | int _numLayerLevels; |
|---|
| 353 | |
|---|
| 354 | |
|---|
| 355 | osg::Geode* _layerGeode; |
|---|
| 356 | |
|---|
| 357 | |
|---|
| 358 | float _defaultMaxAnisotropy; |
|---|
| 359 | |
|---|
| 360 | |
|---|
| 361 | double _realMinRange; |
|---|
| 362 | double _realMaxRange; |
|---|
| 363 | double _usedMaxRange; |
|---|
| 364 | |
|---|
| 365 | |
|---|
| 366 | osg::Vec3 _tileCenter; |
|---|
| 367 | |
|---|
| 368 | |
|---|
| 369 | osg::Geode* createBoundingBox(int x,int y, int lod); |
|---|
| 370 | |
|---|
| 371 | private: |
|---|
| 372 | |
|---|
| 373 | childRefRead *_childRefCB; |
|---|
| 374 | |
|---|
| 375 | |
|---|
| 376 | }; |
|---|
| 377 | |
|---|
| 378 | |
|---|
| 379 | |
|---|
| 380 | |
|---|
| 381 | class geomRead : public trpgr_Callback |
|---|
| 382 | { |
|---|
| 383 | public: |
|---|
| 384 | |
|---|
| 385 | geomRead(TXPParser *in_parse) : _parse(in_parse) |
|---|
| 386 | {} |
|---|
| 387 | void *Parse(trpgToken tok,trpgReadBuffer &buf); |
|---|
| 388 | protected: |
|---|
| 389 | TXPParser *_parse; |
|---|
| 390 | }; |
|---|
| 391 | |
|---|
| 392 | |
|---|
| 393 | |
|---|
| 394 | class groupRead : public trpgr_Callback |
|---|
| 395 | { |
|---|
| 396 | public: |
|---|
| 397 | groupRead(TXPParser *in_parse) : _parse(in_parse) |
|---|
| 398 | {} |
|---|
| 399 | void *Parse(trpgToken tok,trpgReadBuffer &buf); |
|---|
| 400 | protected: |
|---|
| 401 | TXPParser *_parse; |
|---|
| 402 | }; |
|---|
| 403 | |
|---|
| 404 | |
|---|
| 405 | class attachRead : public trpgr_Callback |
|---|
| 406 | { |
|---|
| 407 | public: |
|---|
| 408 | attachRead(TXPParser *in_parse) : _parse(in_parse) |
|---|
| 409 | {} |
|---|
| 410 | void *Parse(trpgToken tok,trpgReadBuffer &buf); |
|---|
| 411 | protected: |
|---|
| 412 | TXPParser *_parse; |
|---|
| 413 | |
|---|
| 414 | }; |
|---|
| 415 | |
|---|
| 416 | class childRefRead : public trpgr_Callback |
|---|
| 417 | { |
|---|
| 418 | public: |
|---|
| 419 | typedef std::vector<trpgChildRef> ChildRefList; |
|---|
| 420 | |
|---|
| 421 | childRefRead(TXPParser *in_parse) : _parse(in_parse) |
|---|
| 422 | {} |
|---|
| 423 | void Reset(); |
|---|
| 424 | void *Parse(trpgToken tok,trpgReadBuffer &buf); |
|---|
| 425 | |
|---|
| 426 | |
|---|
| 427 | unsigned int GetNbChildrenRef() const |
|---|
| 428 | { |
|---|
| 429 | return childRefList.size(); |
|---|
| 430 | } |
|---|
| 431 | |
|---|
| 432 | |
|---|
| 433 | const trpgChildRef* GetChildRef(unsigned int idx) const |
|---|
| 434 | { |
|---|
| 435 | if(idx >= childRefList.size()) |
|---|
| 436 | return 0; |
|---|
| 437 | else |
|---|
| 438 | return &childRefList[idx]; |
|---|
| 439 | } |
|---|
| 440 | |
|---|
| 441 | protected: |
|---|
| 442 | TXPParser *_parse; |
|---|
| 443 | |
|---|
| 444 | |
|---|
| 445 | |
|---|
| 446 | private: |
|---|
| 447 | |
|---|
| 448 | ChildRefList childRefList; |
|---|
| 449 | |
|---|
| 450 | |
|---|
| 451 | }; |
|---|
| 452 | |
|---|
| 453 | |
|---|
| 454 | class lodRead : public trpgr_Callback |
|---|
| 455 | { |
|---|
| 456 | public: |
|---|
| 457 | lodRead(TXPParser *in_parse) : _parse(in_parse) |
|---|
| 458 | {} |
|---|
| 459 | void *Parse(trpgToken tok,trpgReadBuffer &buf); |
|---|
| 460 | protected: |
|---|
| 461 | TXPParser *_parse; |
|---|
| 462 | }; |
|---|
| 463 | |
|---|
| 464 | |
|---|
| 465 | class tileHeaderRead : public trpgr_Callback |
|---|
| 466 | { |
|---|
| 467 | public: |
|---|
| 468 | tileHeaderRead(TXPParser *in_parse) : _parse(in_parse) |
|---|
| 469 | {} |
|---|
| 470 | void *Parse(trpgToken tok,trpgReadBuffer &buf); |
|---|
| 471 | protected: |
|---|
| 472 | TXPParser *_parse; |
|---|
| 473 | }; |
|---|
| 474 | |
|---|
| 475 | |
|---|
| 476 | |
|---|
| 477 | class modelRefRead : public trpgr_Callback |
|---|
| 478 | { |
|---|
| 479 | public: |
|---|
| 480 | modelRefRead(TXPParser *in_parse) : _parse(in_parse) |
|---|
| 481 | {} |
|---|
| 482 | void *Parse(trpgToken tok,trpgReadBuffer &buf); |
|---|
| 483 | protected: |
|---|
| 484 | TXPParser *_parse; |
|---|
| 485 | }; |
|---|
| 486 | |
|---|
| 487 | |
|---|
| 488 | class billboardRead : public trpgr_Callback |
|---|
| 489 | { |
|---|
| 490 | public: |
|---|
| 491 | billboardRead(TXPParser *in_parse) : _parse(in_parse) |
|---|
| 492 | {} |
|---|
| 493 | void *Parse(trpgToken tok,trpgReadBuffer &buf); |
|---|
| 494 | protected: |
|---|
| 495 | TXPParser *_parse; |
|---|
| 496 | }; |
|---|
| 497 | |
|---|
| 498 | |
|---|
| 499 | class lightRead: public trpgr_Callback |
|---|
| 500 | { |
|---|
| 501 | public: |
|---|
| 502 | lightRead(TXPParser *in_parse) : _parse(in_parse) |
|---|
| 503 | {} |
|---|
| 504 | void *Parse(trpgToken tok,trpgReadBuffer &buf); |
|---|
| 505 | protected: |
|---|
| 506 | TXPParser *_parse; |
|---|
| 507 | }; |
|---|
| 508 | |
|---|
| 509 | |
|---|
| 510 | class layerRead: public trpgr_Callback |
|---|
| 511 | { |
|---|
| 512 | public: |
|---|
| 513 | layerRead(TXPParser *in_parse) : _parse(in_parse) |
|---|
| 514 | {} |
|---|
| 515 | void *Parse(trpgToken tok,trpgReadBuffer &buf); |
|---|
| 516 | protected: |
|---|
| 517 | TXPParser *_parse; |
|---|
| 518 | }; |
|---|
| 519 | |
|---|
| 520 | |
|---|
| 521 | class labelRead: public trpgr_Callback |
|---|
| 522 | { |
|---|
| 523 | public: |
|---|
| 524 | labelRead(TXPParser *in_parse) : _parse(in_parse) |
|---|
| 525 | {} |
|---|
| 526 | void *Parse(trpgToken tok,trpgReadBuffer &buf); |
|---|
| 527 | protected: |
|---|
| 528 | TXPParser *_parse; |
|---|
| 529 | }; |
|---|
| 530 | |
|---|
| 531 | } |
|---|
| 532 | |
|---|
| 533 | #endif // __TXPPARSER_H_ |
|---|
| 534 | |
|---|