1 /******************************************************* 2 Lightwave Object Loader for OSG 3 4 Copyright (C) 2004 Marco Jez <marco.jez@poste.it> 5 OpenSceneGraph is (C) 2004 Robert Osfield 6 ********************************************************/ 7 8 #ifndef LWOSG_BLOCK_ 9 #define LWOSG_BLOCK_ 10 11 #include "lwo2chunks.h" 12 13 #include <osg/Vec3> 14 15 #ifdef DIFFERENCE 16 #undef DIFFERENCE 17 #endif 18 19 namespace lwosg 20 { 21 22 class Clip; 23 24 struct Texture_mapping { 25 26 enum Coordinate_system_type { 27 OBJECT = 0, 28 WORLD = 1 29 }; 30 31 osg::Vec3 center_; 32 osg::Vec3 size_; 33 osg::Vec3 rotation_; 34 // missing: OREF, FALL 35 Coordinate_system_type csys_; 36 Texture_mappingTexture_mapping37 Texture_mapping() 38 : size_(1, 1, 1), 39 csys_(OBJECT) 40 {} 41 }; 42 43 struct Image_map { 44 45 enum Axis_type { 46 X = 0, 47 Y = 1, 48 Z = 2 49 }; 50 51 enum Projection_mode { 52 PLANAR = 0, 53 CYLINDRICAL = 1, 54 SPHERICAL = 2, 55 CUBIC = 3, 56 FRONT_PROJECTION = 4, 57 UV = 5 58 }; 59 60 enum Wrap_type { 61 RESET = 0, 62 REPEAT = 1, 63 MIRROR = 2, 64 EDGE = 3 65 }; 66 67 Texture_mapping mapping; 68 Projection_mode projection; 69 Axis_type axis; 70 int image_map; 71 const Clip *clip; // is filled by Surface::compile() 72 Wrap_type width_wrap; 73 Wrap_type height_wrap; 74 float wrap_amount_w; 75 float wrap_amount_h; 76 std::string uv_map; 77 // missing: AAST, PIXB, STCK 78 float texture_amplitude; 79 Image_mapImage_map80 Image_map() 81 : image_map(-1), 82 clip(0), 83 width_wrap(REPEAT), 84 height_wrap(REPEAT), 85 wrap_amount_w(1), 86 wrap_amount_h(1), 87 texture_amplitude(1) 88 {} 89 }; 90 91 class Block { 92 public: 93 94 enum Axis_type { 95 X = 0, 96 Y = 1, 97 Z = 2 98 }; 99 100 enum Opacity_type { 101 NORMAL = 0, 102 SUBTRACTIVE = 1, 103 DIFFERENCE = 2, 104 MULTIPLY = 3, 105 DIVIDE = 4, 106 ALPHA = 5, 107 TEXTURE_DISPLACEMENT = 6, 108 ADDITIVE = 7 109 }; 110 111 Block(const lwo2::FORM::SURF::BLOK *blok = 0); 112 113 void compile(const lwo2::FORM::SURF::BLOK *blok = 0); 114 get_type()115 inline const std::string &get_type() const { return type_; } get_ordinal()116 inline const std::string &get_ordinal() const { return ordinal_; } get_channel()117 inline const std::string &get_channel() const { return channel_; } enabled()118 inline bool enabled() const { return enabled_; } get_opacity_type()119 inline Opacity_type get_opacity_type() const { return opacity_type_; } get_opacity_amount()120 inline float get_opacity_amount() const { return opacity_amount_; } get_displacement_axis()121 inline Axis_type get_displacement_axis() const { return displacement_axis_; } get_image_map()122 inline const Image_map &get_image_map() const { return imap_; } get_image_map()123 inline Image_map &get_image_map() { return imap_; } 124 125 osg::Vec3 setup_texture_point(const osg::Vec3 &P) const; 126 127 protected: 128 void read_common_attributes(const iff::Chunk_list &subchunks); 129 130 private: 131 std::string type_; 132 std::string ordinal_; 133 std::string channel_; 134 bool enabled_; 135 Opacity_type opacity_type_; 136 float opacity_amount_; 137 Axis_type displacement_axis_; 138 139 Image_map imap_; 140 }; 141 142 } 143 144 #endif 145