root/OpenSceneGraph/trunk/src/osgPlugins/OpenFlight/Pools.h @ 13041

Revision 13041, 9.7 kB (checked in by robert, 2 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14//
15// OpenFlight® loader for OpenSceneGraph
16//
17//  Copyright (C) 2005-2007  Brede Johansen
18//
19
20#ifndef FLT_POOLS_H
21#define FLT_POOLS_H 1
22
23#include <vector>
24#include <map>
25#include <sstream>
26#include <osg/Vec4>
27#include <osg/StateSet>
28#include <osg/Material>
29#include <osg/Light>
30#include <osg/Program>
31#include "Types.h"
32
33
34namespace flt {
35
36class VertexPool : public osg::Referenced, public std::istringstream
37{
38public:
39
40    explicit VertexPool( const std::string& str) :
41        std::istringstream(str,std::istringstream::in|std::istringstream::binary) {}
42
43protected:
44
45    virtual ~VertexPool() {}
46};
47
48
49class ColorPool : public osg::Referenced , public std::vector<osg::Vec4>
50{
51public:
52
53    explicit ColorPool(bool old,int size) :
54        std::vector<osg::Vec4>(size),
55        _old(old) {}
56
57    osg::Vec4 getColor(int indexIntensity) const;
58
59protected:
60
61    virtual ~ColorPool() {}
62
63    bool _old; // true if version <= 13
64};
65
66
67class TexturePool : public osg::Referenced , public std::map<int,osg::ref_ptr<osg::StateSet> >
68{
69public:
70
71    TexturePool() {}
72
73    osg::StateSet* get(int index)
74    {
75        iterator itr = find(index);
76        if (itr != end())
77            return (*itr).second.get();
78        return NULL;
79    }
80
81protected:
82
83    virtual ~TexturePool() {}
84
85};
86
87
88class MaterialPool : public osg::Referenced , public std::map<int,osg::ref_ptr<osg::Material> >
89{
90public:
91
92    MaterialPool();
93
94    // Get material, return default material if not found in palette.
95    osg::Material* get(int index);
96
97    // Get or create material based on
98    // index: face material index
99    // color: face color with alpha set to 1-face transparency.
100    osg::Material* getOrCreateMaterial(int index, const osg::Vec4& faceColor);
101
102protected:
103
104    virtual ~MaterialPool() {}
105
106    osg::ref_ptr<osg::Material> _defaultMaterial;
107
108    struct MaterialParameters
109    {
110        int index;              // face index to material pool
111        osg::Vec4 color;        // face color with alpha set to 1-face transparency.
112
113        MaterialParameters():
114            index(-1) {}
115
116        MaterialParameters(int i, const osg::Vec4& c):
117            index(i),
118            color(c) {}
119
120        bool operator < (const MaterialParameters& rhs) const
121        {
122            if (index < rhs.index) return true;
123            else if (index > rhs.index) return false;
124            else return (color < rhs.color);
125        }
126    };
127
128    // Material from palette combined with face color stored here for reuse.
129    typedef std::map<MaterialParameters,osg::ref_ptr<osg::Material> > FinalMaterialMap;
130    FinalMaterialMap _finalMaterialMap;
131};
132
133
134class LightSourcePool : public osg::Referenced , public std::map<int,osg::ref_ptr<osg::Light> >
135{
136public:
137
138    LightSourcePool() {}
139
140    osg::Light* get(int index)
141    {
142        iterator itr = find(index);
143        if (itr != end())
144            return (*itr).second.get();
145        return NULL;
146    }
147
148protected:
149
150    virtual ~LightSourcePool() {}
151};
152
153
154struct LPAppearance : public osg::Referenced
155{
156    std::string name;
157    int32 index;
158    int16 materialCode;
159    int16 featureID;
160    osg::Vec4f backColor;
161    int32 displayMode;
162    float32 intensityFront;
163    float32 intensityBack;
164    float32 minDefocus;
165    float32 maxDefocus;
166    int32 fadingMode;
167    int32 fogPunchMode;
168    int32 directionalMode;
169    int32 rangeMode;
170    float32 minPixelSize;
171    float32 maxPixelSize;
172    float32 actualPixelSize;
173    float32 transparentFalloffPixelSize;
174    float32 transparentFalloffExponent;
175    float32 transparentFalloffScalar;
176    float32 transparentFalloffClamp;
177    float32 fogScalar;
178    float32 fogIntensity;
179    float32 sizeDifferenceThreshold;
180    int32 directionality;
181    float32 horizontalLobeAngle;
182    float32 verticalLobeAngle;
183    float32 lobeRollAngle;
184    float32 directionalFalloffExponent;
185    float32 directionalAmbientIntensity;
186    float32 significance;
187    uint32 flags;
188    float32 visibilityRange;
189    float32 fadeRangeRatio;
190    float32 fadeInDuration;
191    float32 fadeOutDuration;
192    float32 LODRangeRatio;
193    float32 LODScale;
194    int16 texturePatternIndex;
195};
196
197
198class LightPointAppearancePool : public osg::Referenced , public std::map<int,osg::ref_ptr<LPAppearance> >
199{
200public:
201
202    LightPointAppearancePool() {}
203
204    LPAppearance* get(int index)
205    {
206        iterator itr = find(index);
207        if (itr != end())
208            return (*itr).second.get();
209        return NULL;
210    }
211
212protected:
213
214    virtual ~LightPointAppearancePool() {}
215
216};
217
218struct LPAnimation : public osg::Referenced
219{
220    enum AnimationType
221    {
222        FLASHING_SEQUENCE = 0,
223        ROTATING = 1,
224        STROBE = 2,
225        MORSE_CODE = 3
226    };
227
228    enum State
229    {
230        ON = 0,
231        OFF = 1,
232        COLOR_CHANGE = 2
233    };
234
235    struct Pulse
236    {
237        uint32 state;
238        float32 duration;
239        osg::Vec4 color;
240    };
241
242    typedef std::vector<Pulse>  PulseArray;
243
244    std::string name;                        // animation name
245    int32 index;                            // animation index
246    float32 animationPeriod;                // animation period, in seconds
247    float32 animationPhaseDelay;            // animation phase delay, in seconds from start of period
248    float32 animationEnabledPeriod;            // animation enabled period (time on), in seconds
249    osg::Vec3f axisOfRotation;                // axis of rotation for rotating animation (i, j, k)
250    uint32 flags;                            // flags (bits, from left to right)
251                                            //     0 = flashing
252                                            //   1 = rotating
253                                            //   2 = rotate counter clockwise
254                                            //   3-31 = spare
255    int32 animationType;                    // animation type
256                                            //     0 = flashing sequence
257                                            //   1 = rotating
258                                            //   2 = strobe
259                                            //   3 = morse code
260    int32 morseCodeTiming;                    // morse code timing
261                                            //     0 = standard timing
262                                            //   1 = Farnsworth timing
263    int32 wordRate;                            // word rate (for Farnsworth timing)
264    int32 characterRate;                    // character rate (for Farnsworth timing)
265    std::string morseCodeString;            // morse code string
266    PulseArray sequence;
267};
268
269
270class LightPointAnimationPool : public osg::Referenced , public std::map<int,osg::ref_ptr<LPAnimation> >
271{
272public:
273
274    LightPointAnimationPool() {}
275
276    LPAnimation* get(int index)
277    {
278        iterator itr = find(index);
279        if (itr != end())
280            return (*itr).second.get();
281        return NULL;
282    }
283
284protected:
285
286    virtual ~LightPointAnimationPool() {}
287
288};
289
290class ShaderPool : public osg::Referenced , public std::map<int,osg::ref_ptr<osg::Program> >
291{
292public:
293
294    ShaderPool() {}
295
296    osg::Program* get(int index)
297    {
298        iterator itr = find(index);
299        if (itr != end())
300            return (*itr).second.get();
301        return NULL;
302    }
303
304protected:
305
306    virtual ~ShaderPool() {}
307};
308
309
310// This object records parent palettes for external record support.
311// When an external record is parsed, this object is instantiated and populated with
312// the parent model's palettes, then stored as UserData on the ProxyNode.
313// When the ReadExternalsVisitor hits the ProxyNode, it moves this object
314// into the ReaderWriter Options' UserData before calling osgDB::ReadNode,
315// enabling  access to the parent palettes during load of the ext ref model.
316class ParentPools : public osg::Referenced
317{
318public:
319
320    ParentPools() {}
321
322    void setColorPool(ColorPool* pool) { _colorPool=pool; }
323    ColorPool* getColorPool() const { return _colorPool.get(); }
324
325    void setTexturePool(TexturePool* pool) { _texturePool=pool; }
326    TexturePool* getTexturePool() const { return _texturePool.get(); }
327
328    void setMaterialPool(MaterialPool* pool) { _materialPool=pool; }
329    MaterialPool* getMaterialPool() const { return _materialPool.get(); }
330
331    void setLightSourcePool(LightSourcePool* pool) { _lightSourcePool=pool; }
332    LightSourcePool* getLightSourcePool() const { return _lightSourcePool.get(); }
333
334    void setLPAppearancePool(LightPointAppearancePool* pool) { _lpAppearancePool=pool; }
335    LightPointAppearancePool* getLPAppearancePool() const { return _lpAppearancePool.get(); }
336
337    void setLPAnimationPool(LightPointAnimationPool* pool) { _lpAnimationPool=pool; }
338    LightPointAnimationPool* getLPAnimationPool() const { return _lpAnimationPool.get(); }
339
340    void setShaderPool(ShaderPool* pool) { _shaderPool=pool; }
341    ShaderPool* getShaderPool() const { return _shaderPool.get(); }
342
343protected:
344
345    virtual ~ParentPools() {}
346
347    osg::ref_ptr<ColorPool> _colorPool;
348    osg::ref_ptr<MaterialPool> _materialPool;
349    osg::ref_ptr<TexturePool> _texturePool;
350    osg::ref_ptr<LightSourcePool> _lightSourcePool;
351    osg::ref_ptr<LightPointAppearancePool> _lpAppearancePool;
352    osg::ref_ptr<LightPointAnimationPool> _lpAnimationPool;
353    osg::ref_ptr<ShaderPool> _shaderPool;
354};
355
356
357} // end namespace
358
359#endif
Note: See TracBrowser for help on using the browser.