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 			:
82 			  projection(PLANAR),
83 			  axis(X),
84 			  image_map(-1),
85 			  clip(0),
86 			  width_wrap(REPEAT),
87 			  height_wrap(REPEAT),
88 			  wrap_amount_w(1),
89 			  wrap_amount_h(1),
90 			  texture_amplitude(1)
91 		{}
92 	};
93 
94 	class Block {
95 	public:
96 
97 		enum Axis_type {
98 			X = 0,
99 			Y = 1,
100 			Z = 2
101 		};
102 
103 		enum Opacity_type {
104 			NORMAL = 0,
105 			SUBTRACTIVE = 1,
106 			DIFFERENCE = 2,
107 			MULTIPLY = 3,
108 			DIVIDE = 4,
109 			ALPHA = 5,
110 			TEXTURE_DISPLACEMENT = 6,
111 			ADDITIVE = 7
112 		};
113 
114 		Block(const lwo2::FORM::SURF::BLOK *blok = 0);
115 
116 		void compile(const lwo2::FORM::SURF::BLOK *blok = 0);
117 
get_type()118 		inline const std::string &get_type() const { return type_; }
get_ordinal()119 		inline const std::string &get_ordinal() const { return ordinal_; }
get_channel()120 		inline const std::string &get_channel() const { return channel_; }
enabled()121 		inline bool enabled() const { return enabled_; }
get_opacity_type()122 		inline Opacity_type get_opacity_type() const { return opacity_type_; }
get_opacity_amount()123 		inline float get_opacity_amount() const { return opacity_amount_; }
get_displacement_axis()124 		inline Axis_type get_displacement_axis() const { return displacement_axis_; }
get_image_map()125 		inline const Image_map &get_image_map() const { return imap_; }
get_image_map()126 		inline Image_map &get_image_map() { return imap_; }
127 
128 		osg::Vec3 setup_texture_point(const osg::Vec3 &P) const;
129 
130 	protected:
131 		void read_common_attributes(const iff::Chunk_list &subchunks);
132 
133 	private:
134 		std::string type_;
135 		std::string ordinal_;
136 		std::string channel_;
137 		bool enabled_;
138 		Opacity_type opacity_type_;
139 		float opacity_amount_;
140 		Axis_type displacement_axis_;
141 
142 		Image_map imap_;
143 	};
144 
145 }
146 
147 #endif
148