| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | #ifndef FLT_RECORD_H |
|---|
| 21 | #define FLT_RECORD_H 1 |
|---|
| 22 | |
|---|
| 23 | #include <stdexcept> |
|---|
| 24 | #include <string> |
|---|
| 25 | #include <osg/Array> |
|---|
| 26 | #include <osg/Geometry> |
|---|
| 27 | #include <osg/Geode> |
|---|
| 28 | #include <osg/Group> |
|---|
| 29 | #include <osg/MatrixTransform> |
|---|
| 30 | #include "Vertex.h" |
|---|
| 31 | |
|---|
| 32 | namespace flt |
|---|
| 33 | { |
|---|
| 34 | |
|---|
| 35 | class RecordInputStream; |
|---|
| 36 | class Document; |
|---|
| 37 | class PrimaryRecord; |
|---|
| 38 | class Matrix; |
|---|
| 39 | |
|---|
| 40 | #define META_Record(name) \ |
|---|
| 41 | virtual flt::Record* cloneType() const { return new name (); } \ |
|---|
| 42 | virtual bool isSameKindAs(const flt::Record* rec) const { return dynamic_cast<const name *>(rec)!=NULL; } |
|---|
| 43 | #define META_setID(imp) virtual void setID(const std::string& id) { if (imp.valid()) imp->setName(id); } |
|---|
| 44 | #define META_setComment(imp) virtual void setComment(const std::string& id) { if (imp.valid()) imp->addDescription(id); } |
|---|
| 45 | #define META_setMultitexture(imp) virtual void setMultitexture(osg::StateSet& multitexture) { if (imp.valid()) imp->getOrCreateStateSet()->merge(multitexture); } |
|---|
| 46 | #define META_addChild(imp) virtual void addChild(osg::Node& child) { if (imp.valid()) imp->addChild(&child); } |
|---|
| 47 | #define META_dispose(imp) virtual void dispose(Document&) { if (imp.valid() && _matrix.valid()) insertMatrixTransform(*imp,*_matrix,_numberOfReplications); } |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | class Record : public osg::Referenced |
|---|
| 51 | { |
|---|
| 52 | public: |
|---|
| 53 | |
|---|
| 54 | Record(); |
|---|
| 55 | |
|---|
| 56 | virtual Record* cloneType() const = 0; |
|---|
| 57 | virtual bool isSameKindAs(const Record* rec) const = 0; |
|---|
| 58 | virtual void read(RecordInputStream& in, Document& document); |
|---|
| 59 | |
|---|
| 60 | void setParent(PrimaryRecord* parent); |
|---|
| 61 | |
|---|
| 62 | protected: |
|---|
| 63 | |
|---|
| 64 | virtual ~Record(); |
|---|
| 65 | |
|---|
| 66 | virtual void readRecord(RecordInputStream& in, Document& document); |
|---|
| 67 | |
|---|
| 68 | osg::ref_ptr<PrimaryRecord> _parent; |
|---|
| 69 | }; |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | class PrimaryRecord : public Record |
|---|
| 73 | { |
|---|
| 74 | public: |
|---|
| 75 | |
|---|
| 76 | PrimaryRecord(); |
|---|
| 77 | |
|---|
| 78 | virtual void read(RecordInputStream& in, Document& document); |
|---|
| 79 | virtual void dispose(Document& ) {} |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | virtual void setID(const std::string& ) {} |
|---|
| 83 | virtual void setComment(const std::string& ) {} |
|---|
| 84 | virtual void setMultitexture(osg::StateSet& ) {} |
|---|
| 85 | virtual void addChild(osg::Node& ) {} |
|---|
| 86 | virtual void addVertex(Vertex& ) {} |
|---|
| 87 | virtual void addVertexUV(int ,const osg::Vec2& ) {} |
|---|
| 88 | virtual void addMorphVertex(Vertex& , Vertex& ) {} |
|---|
| 89 | virtual void setMultiSwitchValueName(unsigned int , const std::string& ) {} |
|---|
| 90 | |
|---|
| 91 | void setNumberOfReplications(int num) { _numberOfReplications = num; } |
|---|
| 92 | void setMatrix(const osg::Matrix& matrix) { _matrix = new osg::RefMatrix(matrix); } |
|---|
| 93 | |
|---|
| 94 | void setLocalVertexPool(VertexList* pool) { _localVertexPool = pool; } |
|---|
| 95 | VertexList* getLocalVertexPool() { return _localVertexPool.get(); } |
|---|
| 96 | |
|---|
| 97 | protected: |
|---|
| 98 | |
|---|
| 99 | virtual ~PrimaryRecord() {} |
|---|
| 100 | |
|---|
| 101 | int _numberOfReplications; |
|---|
| 102 | osg::ref_ptr<osg::RefMatrix> _matrix; |
|---|
| 103 | osg::ref_ptr<VertexList> _localVertexPool; |
|---|
| 104 | }; |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | class DummyRecord : public Record |
|---|
| 110 | { |
|---|
| 111 | public: |
|---|
| 112 | |
|---|
| 113 | DummyRecord() {} |
|---|
| 114 | |
|---|
| 115 | META_Record(DummyRecord) |
|---|
| 116 | |
|---|
| 117 | protected: |
|---|
| 118 | |
|---|
| 119 | virtual ~DummyRecord() {} |
|---|
| 120 | }; |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | void insertMatrixTransform(osg::Node& node, const osg::Matrix& matrix, int numberOfReplications); |
|---|
| 124 | |
|---|
| 125 | osg::Vec3Array* getOrCreateVertexArray(osg::Geometry& geometry); |
|---|
| 126 | osg::Vec3Array* getOrCreateNormalArray(osg::Geometry& geometry); |
|---|
| 127 | osg::Vec4Array* getOrCreateColorArray(osg::Geometry& geometry); |
|---|
| 128 | osg::Vec2Array* getOrCreateTextureArray(osg::Geometry& geometry, int unit); |
|---|
| 129 | |
|---|
| 130 | |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | #endif |
|---|