| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | #ifndef LWOSG_OBJECT_ |
|---|
| 9 | #define LWOSG_OBJECT_ |
|---|
| 10 | |
|---|
| 11 | #include "Layer.h" |
|---|
| 12 | #include "Surface.h" |
|---|
| 13 | #include "Clip.h" |
|---|
| 14 | #include "Unit.h" |
|---|
| 15 | |
|---|
| 16 | #include "iffparser.h" |
|---|
| 17 | |
|---|
| 18 | #include <osg/Referenced> |
|---|
| 19 | #include <osg/ref_ptr> |
|---|
| 20 | |
|---|
| 21 | #include <string> |
|---|
| 22 | #include <vector> |
|---|
| 23 | #include <map> |
|---|
| 24 | |
|---|
| 25 | namespace lwosg |
|---|
| 26 | { |
|---|
| 27 | |
|---|
| 28 | class CoordinateSystemFixer: public osg::Referenced { |
|---|
| 29 | public: |
|---|
| 30 | virtual osg::Vec3 fix_point(const osg::Vec3 &P) const = 0; |
|---|
| 31 | virtual osg::Vec4 fix_point(const osg::Vec4 &P) const = 0; |
|---|
| 32 | virtual osg::Vec3 fix_vector(const osg::Vec3 &V) const = 0; |
|---|
| 33 | virtual osg::Vec4 fix_vector(const osg::Vec4 &V) const = 0; |
|---|
| 34 | virtual inline bool invert_winding() const { return false; } |
|---|
| 35 | |
|---|
| 36 | protected: |
|---|
| 37 | virtual ~CoordinateSystemFixer() {} |
|---|
| 38 | CoordinateSystemFixer &operator=(const CoordinateSystemFixer &) { return *this; } |
|---|
| 39 | }; |
|---|
| 40 | |
|---|
| 41 | class LwoCoordFixer: public CoordinateSystemFixer { |
|---|
| 42 | public: |
|---|
| 43 | inline osg::Vec3 fix_point(const osg::Vec3 &P) const; |
|---|
| 44 | inline osg::Vec4 fix_point(const osg::Vec4 &P) const; |
|---|
| 45 | inline osg::Vec3 fix_vector(const osg::Vec3 &V) const; |
|---|
| 46 | inline osg::Vec4 fix_vector(const osg::Vec4 &V) const; |
|---|
| 47 | inline bool invert_winding() const { return true; } |
|---|
| 48 | |
|---|
| 49 | protected: |
|---|
| 50 | virtual ~LwoCoordFixer() {} |
|---|
| 51 | LwoCoordFixer &operator=(const LwoCoordFixer &) { return *this; } |
|---|
| 52 | }; |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | class Object { |
|---|
| 57 | public: |
|---|
| 58 | |
|---|
| 59 | typedef std::map<int, Layer> Layer_map; |
|---|
| 60 | typedef std::map<std::string, Surface> Surface_map; |
|---|
| 61 | |
|---|
| 62 | Object(); |
|---|
| 63 | Object(const iff::Chunk_list &data); |
|---|
| 64 | |
|---|
| 65 | inline CoordinateSystemFixer *get_coordinate_system_fixer() { return csf_.get(); } |
|---|
| 66 | inline const CoordinateSystemFixer *get_coordinate_system_fixer() const { return csf_.get(); } |
|---|
| 67 | inline void set_coordinate_system_fixer(CoordinateSystemFixer *csf) { csf_ = csf; } |
|---|
| 68 | |
|---|
| 69 | void build(const iff::Chunk_list &data); |
|---|
| 70 | |
|---|
| 71 | inline Layer_map &layers() { return layers_; } |
|---|
| 72 | inline const Layer_map &layers() const { return layers_; } |
|---|
| 73 | |
|---|
| 74 | inline Surface_map &surfaces() { return surfaces_; } |
|---|
| 75 | inline const Surface_map &surfaces() const { return surfaces_; } |
|---|
| 76 | |
|---|
| 77 | inline const std::string &get_comment() const { return comment_; } |
|---|
| 78 | inline const std::string &get_description() const { return description_; } |
|---|
| 79 | |
|---|
| 80 | protected: |
|---|
| 81 | void scan_clips(const iff::Chunk_list &data); |
|---|
| 82 | void scan_surfaces(const iff::Chunk_list &data); |
|---|
| 83 | void parse(const iff::Chunk_list &data); |
|---|
| 84 | |
|---|
| 85 | void generate_normals(); |
|---|
| 86 | void generate_auto_texture_maps(); |
|---|
| 87 | |
|---|
| 88 | private: |
|---|
| 89 | Layer_map layers_; |
|---|
| 90 | |
|---|
| 91 | typedef std::map<int, Clip> Clip_map; |
|---|
| 92 | Clip_map clips_; |
|---|
| 93 | |
|---|
| 94 | Surface_map surfaces_; |
|---|
| 95 | |
|---|
| 96 | std::string comment_; |
|---|
| 97 | std::string description_; |
|---|
| 98 | |
|---|
| 99 | osg::ref_ptr<CoordinateSystemFixer> csf_; |
|---|
| 100 | }; |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | |
|---|
| 104 | inline osg::Vec3 LwoCoordFixer::fix_point(const osg::Vec3 &P) const |
|---|
| 105 | { |
|---|
| 106 | return osg::Vec3(P.x(), P.z(), P.y()); |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | inline osg::Vec4 LwoCoordFixer::fix_point(const osg::Vec4 &P) const |
|---|
| 110 | { |
|---|
| 111 | return osg::Vec4(fix_point(osg::Vec3(P.x(), P.y(), P.z())), P.w()); |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | inline osg::Vec3 LwoCoordFixer::fix_vector(const osg::Vec3 &V) const |
|---|
| 115 | { |
|---|
| 116 | return fix_point(V); |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | inline osg::Vec4 LwoCoordFixer::fix_vector(const osg::Vec4 &V) const |
|---|
| 120 | { |
|---|
| 121 | return fix_point(V); |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | #endif |
|---|