| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | #ifndef __FLTEXP_VERTEX_PALETTE_MANAGER_H__ |
|---|
| 18 | #define __FLTEXP_VERTEX_PALETTE_MANAGER_H__ 1 |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | #include "DataOutputStream.h" |
|---|
| 22 | #include "ExportOptions.h" |
|---|
| 23 | #include <osg/Array> |
|---|
| 24 | #include <osgDB/fstream> |
|---|
| 25 | #include <map> |
|---|
| 26 | |
|---|
| 27 | namespace osg { |
|---|
| 28 | class Geometry; |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | namespace flt |
|---|
| 33 | { |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | class VertexPaletteManager |
|---|
| 44 | { |
|---|
| 45 | public: |
|---|
| 46 | VertexPaletteManager( const ExportOptions& fltOpt ); |
|---|
| 47 | ~VertexPaletteManager(); |
|---|
| 48 | |
|---|
| 49 | void add( const osg::Geometry& geom ); |
|---|
| 50 | void add( const osg::Array* key, |
|---|
| 51 | const osg::Vec3dArray* v, const osg::Vec4Array* c, |
|---|
| 52 | const osg::Vec3Array* n, const osg::Vec2Array* t, |
|---|
| 53 | bool colorPerVertex, bool normalPerVertex, bool allowSharing=true ); |
|---|
| 54 | |
|---|
| 55 | unsigned int byteOffset( unsigned int idx ) const; |
|---|
| 56 | |
|---|
| 57 | void write( DataOutputStream& dos ) const; |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | static osg::ref_ptr< const osg::Vec2Array > asVec2Array( const osg::Array* in, const unsigned int n ); |
|---|
| 64 | static osg::ref_ptr< const osg::Vec3Array > asVec3Array( const osg::Array* in, const unsigned int n ); |
|---|
| 65 | static osg::ref_ptr< const osg::Vec3dArray > asVec3dArray( const osg::Array* in, const unsigned int n ); |
|---|
| 66 | static osg::ref_ptr< const osg::Vec4Array > asVec4Array( const osg::Array* in, const unsigned int n ); |
|---|
| 67 | |
|---|
| 68 | protected: |
|---|
| 69 | typedef enum { |
|---|
| 70 | VERTEX_C, |
|---|
| 71 | VERTEX_CN, |
|---|
| 72 | VERTEX_CNT, |
|---|
| 73 | VERTEX_CT |
|---|
| 74 | } PaletteRecordType; |
|---|
| 75 | |
|---|
| 76 | static PaletteRecordType recordType( const osg::Array* v, const osg::Array* c, |
|---|
| 77 | const osg::Array* n, const osg::Array* t ); |
|---|
| 78 | unsigned int recordSize( PaletteRecordType recType ); |
|---|
| 79 | |
|---|
| 80 | void writeRecords( const osg::Vec3dArray* v, const osg::Vec4Array* c, |
|---|
| 81 | const osg::Vec3Array* n, const osg::Vec2Array* t, |
|---|
| 82 | bool colorPerVertex, bool normalPerVertex ); |
|---|
| 83 | |
|---|
| 84 | unsigned int _currentSizeBytes; |
|---|
| 85 | |
|---|
| 86 | struct ArrayInfo { |
|---|
| 87 | ArrayInfo(); |
|---|
| 88 | |
|---|
| 89 | unsigned int _byteStart; |
|---|
| 90 | unsigned int _idxSizeBytes; |
|---|
| 91 | unsigned int _idxCount; |
|---|
| 92 | }; |
|---|
| 93 | ArrayInfo* _current; |
|---|
| 94 | ArrayInfo _nonShared; |
|---|
| 95 | |
|---|
| 96 | typedef std::map< const osg::Array*, ArrayInfo > ArrayMap; |
|---|
| 97 | ArrayMap _arrayMap; |
|---|
| 98 | |
|---|
| 99 | mutable osgDB::ofstream _verticesStr; |
|---|
| 100 | DataOutputStream* _vertices; |
|---|
| 101 | std::string _verticesTempName; |
|---|
| 102 | |
|---|
| 103 | const ExportOptions& _fltOpt; |
|---|
| 104 | }; |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | #endif |
|---|