root/OpenSceneGraph/trunk/src/osgPlugins/OpenFlight/PaletteRecords.cpp @ 10283

Revision 10283, 27.8 kB (checked in by robert, 5 years ago)

From Gregory Jaegy and Robert Osfield, added support for static linking of OpenFlight? plugin

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
RevLine 
[7748]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
[5038]14//
15// OpenFlight® loader for OpenSceneGraph
16//
[7748]17//  Copyright (C) 2005-2007  Brede Johansen
[5038]18//
19
[5375]20#include <assert.h>
[6091]21#include <osg/Light>
[5038]22#include <osg/Texture2D>
23#include <osg/TexEnv>
24#include <osg/BlendFunc>
25#include <osgSim/LightPointNode>
26#include <osgDB/ReadFile>
27#include <osgDB/FileUtils>
28#include "Registry.h"
29#include "Document.h"
30#include "AttrData.h"
31#include "RecordInputStream.h"
32
33namespace flt {
34
35class VertexPalette : public Record
36{
37public:
38
39    VertexPalette() {}
40
41    META_Record(VertexPalette)
42
43protected:
44
45    virtual ~VertexPalette() {}
46
47    virtual void readRecord(RecordInputStream& in, Document& document)
48    {
49        uint32 paletteSize = in.readUInt32();
[5205]50
[8563]51        // Entries in vertex pool found by offset from start of this record.
[7669]52        const int RECORD_HEADER_SIZE = 4;
53        const int OFFSET = RECORD_HEADER_SIZE+sizeof(paletteSize);
54
[5205]55        std::string buffer(paletteSize,'\0');
[7669]56        in.read(&buffer[OFFSET], paletteSize-OFFSET);
57
58        // Keep a copy of the vertex pool in memory for later reference.
[5205]59        document.setVertexPool(new VertexPool(buffer));
[5038]60    }
61};
62
[10283]63REGISTER_FLTRECORD(VertexPalette, VERTEX_PALETTE_OP)
[5038]64
65
[10283]66
[5038]67class ColorPalette : public Record
68{
69public:
70
71    ColorPalette() {}
72
73    META_Record(ColorPalette)
74
75protected:
76
77    virtual ~ColorPalette() {}
78
79    virtual void readRecord(RecordInputStream& in, Document& document)
80    {
[5236]81        if (document.getColorPoolParent())
82            // Using parent's color pool -- ignore this record.
83            return;
84
[5038]85        if (document.version() > VERSION_13)
86        {
87            bool oldVersion = false;
88            bool colorNameSection = in.getRecordSize() > 4228;
89            int maxColors = (document.version()>=VERSION_15_1) ? 1024 : 512;
90
91            // It might be less.
92            if (!colorNameSection)
93            {
94                // Max colors calculated by record size.
95                int maxColorsByRecordSize = (in.getRecordBodySize()-128) / 4;
96                if (maxColorsByRecordSize < maxColors)
97                    maxColors = maxColorsByRecordSize;
98            }
99
100            ColorPool* cp = new ColorPool(oldVersion,maxColors);
101            document.setColorPool(cp);
102
103            in.forward(128);
104            for (int i=0; i<maxColors; i++)
105            {
106                uint8 alpha = in.readUInt8(1);
107                uint8 blue  = in.readUInt8(1);
108                uint8 green = in.readUInt8(1);
109                uint8 red   = in.readUInt8(1);
110
[5229]111                (*cp)[i] = osg::Vec4((float)red/255,(float)green/255,(float)blue/255,(float)alpha/255);
[5038]112            }
113        }
114        else // version <= 13
115        {
116            bool oldVersion = true;
117            int maxColors = 32+56;
118
119            ColorPool* cp = new ColorPool(oldVersion,maxColors);
120            document.setColorPool(cp);
121
122            // variable intensity
123            for (int i=0; i < 32; i++)
124            {
125                uint16 red   = in.readUInt16(1);
126                uint16 green = in.readUInt16(1);
127                uint16 blue  = in.readUInt16(1);
128                (*cp)[i] = osg::Vec4((float)red/255,(float)green/255,(float)blue/255,1);
129            }
130
131            // fixed intensity
132            for (int i=0; i < 56; i++)
133            {
134                uint16 red   = in.readUInt16(1);
135                uint16 green = in.readUInt16(1);
136                uint16 blue  = in.readUInt16(1);
137                (*cp)[i+32] = osg::Vec4((float)red/255,(float)green/255,(float)blue/255,1);
138            }
139        }
140    }
141};
142
143
[10283]144REGISTER_FLTRECORD(ColorPalette, COLOR_PALETTE_OP)
[5038]145
146
[10283]147
[5038]148class NameTable : public Record
149{
150public:
151
152    NameTable() {}
153
154    META_Record(NameTable)
155
156protected:
157
158    virtual ~NameTable() {}
159
[5229]160    virtual void readRecord(RecordInputStream& /*in*/, Document& /*document*/)
[5038]161    {
162    }
163};
164
[10283]165REGISTER_FLTRECORD(NameTable, NAME_TABLE_OP)
[5038]166
167
[10283]168
[5038]169class MaterialPalette : public Record
170{
171public:
172
173    MaterialPalette() {}
174
175    META_Record(MaterialPalette)
176
177protected:
178
179    virtual ~MaterialPalette() {}
180
181    virtual void readRecord(RecordInputStream& in, Document& document)
182    {
[5236]183        if (document.getMaterialPoolParent())
184            // Using parent's material pool -- ignore this record.
185            return;
186
[5038]187        int32 index = in.readInt32();
188        std::string name = in.readString(12);
[5229]189        /*uint32 flags =*/ in.readUInt32();
[5038]190        osg::Vec3f ambient = in.readVec3f();
191        osg::Vec3f diffuse = in.readVec3f();
192        osg::Vec3f specular = in.readVec3f();
193        osg::Vec3f emissive = in.readVec3f();
194        float32 shininess = in.readFloat32();
195        float32 alpha = in.readFloat32();
196
197        osg::Material* material = new osg::Material;
[8462]198        material->setName(name);
[5038]199        material->setAmbient(osg::Material::FRONT_AND_BACK,osg::Vec4(ambient,alpha));
200        material->setDiffuse (osg::Material::FRONT_AND_BACK,osg::Vec4(diffuse,alpha));
201        material->setSpecular(osg::Material::FRONT_AND_BACK,osg::Vec4(specular,alpha));
202        material->setEmission(osg::Material::FRONT_AND_BACK,osg::Vec4(emissive,alpha));
203        material->setShininess(osg::Material::FRONT_AND_BACK,shininess);
204       
205        MaterialPool* mp = document.getOrCreateMaterialPool();
206        (*mp)[index] = material;
207    }
208};
209
[10283]210REGISTER_FLTRECORD(MaterialPalette, MATERIAL_PALETTE_OP)
[5038]211
212
[10283]213
[5038]214class OldMaterialPalette : public Record
215{
216public:
217
218    OldMaterialPalette() {}
219
220    META_Record(OldMaterialPalette)
221
222protected:
223
224    virtual ~OldMaterialPalette() {}
225
226    virtual void readRecord(RecordInputStream& in, Document& document)
227    {
[5236]228        if (document.getMaterialPoolParent())
229            // Using parent's material pool -- ignore this record.
230            return;
231
[5038]232        for (int i=0; i < 64; i++)
233        {
234            osg::Vec3f ambient = in.readVec3f();
235            osg::Vec3f diffuse = in.readVec3f();
236            osg::Vec3f specular = in.readVec3f();
237            osg::Vec3f emissive = in.readVec3f();
238            float32 shininess = in.readFloat32();
239            float32 alpha = in.readFloat32();
[5229]240            /*uint32 flags =*/ in.readUInt32();
[5038]241            std::string name = in.readString(12);
242            in.forward(4*28);
243           
244            osg::Material* material = new osg::Material;
245            material->setAmbient(osg::Material::FRONT_AND_BACK,osg::Vec4(ambient,alpha));
246            material->setDiffuse (osg::Material::FRONT_AND_BACK,osg::Vec4(diffuse,alpha));
247            material->setSpecular(osg::Material::FRONT_AND_BACK,osg::Vec4(specular,alpha));
248            material->setEmission(osg::Material::FRONT_AND_BACK,osg::Vec4(emissive,alpha));
249            material->setShininess(osg::Material::FRONT_AND_BACK,shininess);
250           
251            MaterialPool* mp = document.getOrCreateMaterialPool();
252            (*mp)[i] = material;
253        }
254    }
255
256};
257
[10283]258REGISTER_FLTRECORD(OldMaterialPalette, OLD_MATERIAL_PALETTE_OP)
[5038]259
260
[10283]261
[5038]262class TexturePalette : public Record
263{
264public:
265
266    TexturePalette() {}
267
268    META_Record(TexturePalette)
269   
270protected:
271
272    virtual ~TexturePalette() {}
273
[5986]274    osg::Texture2D::WrapMode convertWrapMode(int32 attrWrapMode, const Document& document) const
[5138]275    {
[5794]276        osg::Texture2D::WrapMode osgWrapMode = osg::Texture2D::REPEAT;
277        switch (attrWrapMode)
[5138]278        {
279        case AttrData::WRAP_CLAMP:
[5794]280            if (document.getReplaceClampWithClampToEdge())
281                osgWrapMode = osg::Texture2D::CLAMP_TO_EDGE;
282            else
283                osgWrapMode = osg::Texture2D::CLAMP;
[5138]284            break;
285        case AttrData::WRAP_MIRRORED_REPEAT:
[5794]286            osgWrapMode = osg::Texture2D::MIRROR;
[5138]287            break;
288        case AttrData::WRAP_REPEAT:
[5794]289            osgWrapMode = osg::Texture2D::REPEAT;
[5138]290            break;
291        }
[5794]292
293        return osgWrapMode;
[5138]294    }
295
[5986]296    osg::StateSet* readTexture(const std::string& filename, const Document& document) const
[5038]297    {
[9527]298        osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile(filename,document.getOptions());
[5986]299        if (!image) return NULL;
[5236]300
[5986]301        // Create stateset to hold texture and attributes.
302        osg::StateSet* stateset = new osg::StateSet;
[5038]303
304        osg::Texture2D* texture = new osg::Texture2D;
[5223]305        texture->setWrap(osg::Texture2D::WRAP_S,osg::Texture2D::REPEAT);
306        texture->setWrap(osg::Texture2D::WRAP_T,osg::Texture2D::REPEAT);
[5038]307        texture->setResizeNonPowerOfTwoHint(true);
[9527]308        texture->setImage(image.get());
[5038]309        stateset->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON);
310
311        // Read attribute file
312        std::string attrname = filename + ".attr";
313        osg::ref_ptr<AttrData> attr = dynamic_cast<AttrData*>(osgDB::readObjectFile(attrname,document.getOptions()));
314        if (attr.valid())
315        {
316            // Wrap mode
[5794]317            osg::Texture2D::WrapMode wrap_s = convertWrapMode(attr->wrapMode_u,document);
[5038]318            texture->setWrap(osg::Texture2D::WRAP_S,wrap_s);
319
[5794]320            osg::Texture2D::WrapMode wrap_t = convertWrapMode(attr->wrapMode_v,document);
[5038]321            texture->setWrap(osg::Texture2D::WRAP_T,wrap_t);
322
323            // Min filter
324            switch (attr->minFilterMode)
325            {
326            case AttrData::MIN_FILTER_POINT:
327                texture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::NEAREST);
328                break;
329            case AttrData::MIN_FILTER_BILINEAR:
330                texture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR);
331                break;
332            case AttrData::MIN_FILTER_MIPMAP_POINT:
333                texture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::NEAREST_MIPMAP_NEAREST);
334                break;
335            case AttrData::MIN_FILTER_MIPMAP_LINEAR:
336                texture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::NEAREST_MIPMAP_LINEAR);
337                break;
338            case AttrData::MIN_FILTER_MIPMAP_BILINEAR:
339                texture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR_MIPMAP_NEAREST);
340                break;
341            case AttrData::MIN_FILTER_MIPMAP_TRILINEAR:
342                texture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR_MIPMAP_LINEAR);
343                break;
344            case AttrData::MIN_FILTER_BICUBIC:
345            case AttrData::MIN_FILTER_BILINEAR_GEQUAL:
346            case AttrData::MIN_FILTER_BILINEAR_LEQUAL:
347            case AttrData::MIN_FILTER_BICUBIC_GEQUAL:
348            case AttrData::MIN_FILTER_BICUBIC_LEQUAL:
349                texture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR_MIPMAP_NEAREST);
350                break;
351            default:
352                texture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR_MIPMAP_LINEAR);
353                break;
354            }
355
356            // Mag filter
357            switch (attr->magFilterMode)
358            {
359            case AttrData::MAG_FILTER_POINT:
360                texture->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::NEAREST);
361                break;
362            case AttrData::MAG_FILTER_BILINEAR:
363            case AttrData::MAG_FILTER_BILINEAR_GEQUAL:
364            case AttrData::MAG_FILTER_BILINEAR_LEQUAL:
365            case AttrData::MAG_FILTER_SHARPEN:
366            case AttrData::MAG_FILTER_BICUBIC:
367            case AttrData::MAG_FILTER_BICUBIC_GEQUAL:
368            case AttrData::MAG_FILTER_BICUBIC_LEQUAL:
369            case AttrData::MAG_FILTER_ADD_DETAIL:
370            case AttrData::MAG_FILTER_MODULATE_DETAIL:
371                texture->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR);
372                break;
373            }
374
[6844]375            // Internal mode
376            switch(attr->intFormat)
377            {
378            case AttrData::INTERNAL_FORMAT_TX_I_12A_4:
379                texture->setInternalFormat(GL_LUMINANCE12_ALPHA4);
380                break;
381            case AttrData::INTERNAL_FORMAT_TX_IA_8:
382                texture->setInternalFormat(GL_LUMINANCE_ALPHA);
383                break;
384            case AttrData::INTERNAL_FORMAT_TX_RGB_5:
385                texture->setInternalFormat(GL_RGB5);
386                break;
387            case AttrData::INTERNAL_FORMAT_TX_RGBA_4:
388                texture->setInternalFormat(GL_RGBA4);
389                break;
390            case AttrData::INTERNAL_FORMAT_TX_IA_12:
391                texture->setInternalFormat(GL_LUMINANCE12_ALPHA12);
392                break;
393            case AttrData::INTERNAL_FORMAT_TX_RGBA_8:
394                texture->setInternalFormat(GL_RGBA8);
395                break;
396            case AttrData::INTERNAL_FORMAT_TX_RGBA_12:
397                texture->setInternalFormat(GL_RGBA12);
398                break;
399            case AttrData::INTERNAL_FORMAT_TX_I_16:
400                texture->setInternalFormat(GL_INTENSITY16);
401                break;
402            case AttrData::INTERNAL_FORMAT_TX_RGB_12:
403                texture->setInternalFormat(GL_RGB12);
404                break;
405            case AttrData::INTERNAL_FORMAT_DEFAULT:
406            default:
[6902]407                // Do nothing, just use the image data format
[6844]408                break;
409            }
410
[5038]411            osg::TexEnv* texenv = new osg::TexEnv;
412            switch (attr->texEnvMode)
413            {
414            case AttrData::TEXENV_MODULATE:
415                texenv->setMode(osg::TexEnv::MODULATE);
416                break;
417            case AttrData::TEXENV_BLEND:
418                texenv->setMode(osg::TexEnv::BLEND);
419                break;
420            case AttrData::TEXENV_DECAL:
421                texenv->setMode(osg::TexEnv::DECAL);
422                break;
423            case AttrData::TEXENV_COLOR:
424                texenv->setMode(osg::TexEnv::REPLACE);
425                break;
[5138]426            case AttrData::TEXENV_ADD:
427                texenv->setMode(osg::TexEnv::ADD);
428                break;
[5038]429            }
430            stateset->setTextureAttribute(0, texenv);
431        }
432
[5986]433        return stateset;
434    }
435
436    virtual void readRecord(RecordInputStream& in, Document& document)
437    {
438        if (document.getTexturePoolParent())
439            // Using parent's texture pool -- ignore this record.
440            return;
441
442        int maxLength = (document.version() < VERSION_14) ? 80 : 200;
443        std::string filename = in.readString(maxLength);
444        int32 index = in.readInt32(-1);
445        /*int32 x =*/ in.readInt32();
446        /*int32 y =*/ in.readInt32();
447
448        // Need full path for unique key in local texture cache.
449        std::string pathname = osgDB::findDataFile(filename,document.getOptions());
450        if (pathname.empty())
451        {
452            osg::notify(osg::WARN) << "Can't find texture (" << index << ") " << filename << std::endl;
453            return;
454        }
455
456        // Is texture in local cache?
457        osg::StateSet* stateset = flt::Registry::instance()->getTextureFromLocalCache(pathname);
458
459        // Read file if not in cache.
460        if (!stateset)
461        {
462            stateset = readTexture(pathname,document);
463
464            // Add to texture cache.
465            flt::Registry::instance()->addTextureToLocalCache(pathname,stateset);
466        }
467
468        // Add to texture pool.
[5038]469        TexturePool* tp = document.getOrCreateTexturePool();
[5986]470        (*tp)[index] = stateset;
[5038]471    }
472};
473
[10283]474REGISTER_FLTRECORD(TexturePalette, TEXTURE_PALETTE_OP)
[5038]475
476
[10283]477
[5038]478class EyepointAndTrackplanePalette : public Record
479{
480public:
481
482    EyepointAndTrackplanePalette() {}
483
484    META_Record(EyepointAndTrackplanePalette)
485
486protected:
487
488    virtual ~EyepointAndTrackplanePalette() {}
489
[5229]490    virtual void readRecord(RecordInputStream& /*in*/, Document& /*document*/) {}
[5038]491};
492
[10283]493REGISTER_FLTRECORD(EyepointAndTrackplanePalette, EYEPOINT_AND_TRACKPLANE_PALETTE_OP)
[5038]494
495
[10283]496
[5038]497class LinkagePalette : public Record
498{
499public:
500
501    LinkagePalette() {}
502
503    META_Record(LinkagePalette)
504
505protected:
506
507    virtual ~LinkagePalette() {}
508
[5229]509    virtual void readRecord(RecordInputStream& /*in*/, Document& /*document*/) {}
[5038]510};
511
[10283]512REGISTER_FLTRECORD(LinkagePalette, LINKAGE_PALETTE_OP)
[5038]513
514
[10283]515
[5038]516class SoundPalette : public Record
517{
518public:
519
520    SoundPalette() {}
521
522    META_Record(SoundPalette)
523
524protected:
525
526    virtual ~SoundPalette() {}
527
[5229]528    virtual void readRecord(RecordInputStream& /*in*/, Document& /*document*/) {}
[5038]529};
530
[10283]531REGISTER_FLTRECORD(SoundPalette, SOUND_PALETTE_OP)
[5038]532
533
[10283]534
[5038]535class LightSourcePalette : public Record
536{
537public:
538
539    LightSourcePalette() {}
540
541    META_Record(LightSourcePalette)
542
[6091]543    enum LightType
544    {
545        INFINITE_LIGHT = 0,
546        LOCAL_LIGHT = 1,
547        SPOT_LIGHT = 2
548    };
549
[5038]550protected:
551
552    virtual ~LightSourcePalette() {}
553
[6091]554    virtual void readRecord(RecordInputStream& in, Document& document)
555    {
556        if (document.getLightSourcePoolParent())
557            // Using parent's texture pool -- ignore this record.
558            return;
559
560        int32 index = in.readInt32(-1);
561        in.forward(2*4);
562        std::string name = in.readString(20);
563        in.forward(4);
564        osg::Vec4f ambient = in.readVec4f();
565        osg::Vec4f diffuse = in.readVec4f();
566        osg::Vec4f specular = in.readVec4f();
567        int32 type = in.readInt32();
568        in.forward(4*10);
569        float32 spotExponent = in.readFloat32();
570        float32 spotCutoff = in.readFloat32();
[6201]571        /*float32 yaw =*/ in.readFloat32();
572        /*float32 pitch =*/ in.readFloat32();
[6091]573        float32 constantAttenuation = in.readFloat32();
574        float32 linearAttenuation = in.readFloat32();
575        float32 quadraticAttenuation = in.readFloat32();
[6201]576        /*int32 active =*/ in.readInt32();
[6091]577
578        osg::ref_ptr<osg::Light> light = new osg::Light;
579        light->setAmbient(ambient);
580        light->setDiffuse(diffuse);
581        light->setSpecular(specular);
582
583        switch (type)
584        {
585        case INFINITE_LIGHT:
586            light->setPosition(osg::Vec4(0.0f,0.0f,1.0f,0.0f));
587            break;
588        case LOCAL_LIGHT:
589            light->setPosition(osg::Vec4(0.0f,0.0f,0.0f,1.0f));
590            light->setConstantAttenuation(constantAttenuation);
591            light->setLinearAttenuation(linearAttenuation);
592            light->setQuadraticAttenuation(quadraticAttenuation);
593            break;
594        case SPOT_LIGHT:
595            light->setPosition(osg::Vec4(0.0f,0.0f,0.0f,1.0f));
596            light->setDirection(osg::Vec3(0.0f,1.0f,0.0f));
597            light->setConstantAttenuation(constantAttenuation);
598            light->setLinearAttenuation(linearAttenuation);
599            light->setQuadraticAttenuation(quadraticAttenuation);
600            light->setSpotExponent(spotExponent);
601            light->setSpotCutoff(spotCutoff);
602            break;
603        }
604
605        // Add to pool
606        LightSourcePool* pool = document.getOrCreateLightSourcePool();
607        (*pool)[index] = light.get();
608    }
[5038]609};
610
[10283]611REGISTER_FLTRECORD(LightSourcePalette, LIGHT_SOURCE_PALETTE_OP)
[5038]612
613
[10283]614
[5038]615class LightPointAppearancePalette : public Record
616{
617public:
618
619    LightPointAppearancePalette() {}
620
621    META_Record(LightPointAppearancePalette)
622
623protected:
624
625    virtual ~LightPointAppearancePalette() {}
626
627    virtual void readRecord(RecordInputStream& in, Document& document)
628    {
[5236]629        if (document.getLightPointAppearancePoolParent())
630            // Using parent's light point appearance pool -- ignore this record.
631            return;
632
[5038]633        osg::ref_ptr<LPAppearance> appearance = new LPAppearance;
634
635        in.forward(4);
636        appearance->name = in.readString(256);
637        appearance->index = in.readInt32(-1);
638        appearance->materialCode = in.readInt16();
639        appearance->featureID = in.readInt16();
[5404]640
641        int32 backColorIndex = in.readInt32();       
642        appearance->backColor = document.getColorPool() ?
643                            document.getColorPool()->getColor(backColorIndex) :
644                            osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f);
645
[5038]646        appearance->displayMode = in.readInt32();
647        appearance->intensityFront = in.readFloat32();
648        appearance->intensityBack = in.readFloat32();
649        appearance->minDefocus = in.readFloat32();
650        appearance->maxDefocus = in.readFloat32();
651        appearance->fadingMode = in.readInt32();
652        appearance->fogPunchMode = in.readInt32();
653        appearance->directionalMode = in.readInt32();
654        appearance->rangeMode = in.readInt32();
655        appearance->minPixelSize = in.readFloat32();
656        appearance->maxPixelSize = in.readFloat32();
657        appearance->actualPixelSize = in.readFloat32();
658        appearance->transparentFalloffPixelSize = in.readFloat32();
659        appearance->transparentFalloffExponent = in.readFloat32();
660        appearance->transparentFalloffScalar = in.readFloat32();
661        appearance->transparentFalloffClamp = in.readFloat32();
662        appearance->fogScalar = in.readFloat32();
663        appearance->fogIntensity = in.readFloat32();
664        appearance->sizeDifferenceThreshold = in.readFloat32();
665        appearance->directionality = in.readInt32();
666        appearance->horizontalLobeAngle = in.readFloat32();
667        appearance->verticalLobeAngle = in.readFloat32();
668        appearance->lobeRollAngle = in.readFloat32();
669        appearance->directionalFalloffExponent = in.readFloat32();
670        appearance->directionalAmbientIntensity = in.readFloat32();
671        appearance->significance = in.readFloat32();
672        appearance->flags = in.readUInt32();
673        appearance->visibilityRange = in.readFloat32();
674        appearance->fadeRangeRatio = in.readFloat32();
675        appearance->fadeInDuration = in.readFloat32();
676        appearance->fadeOutDuration = in.readFloat32();
677        appearance->LODRangeRatio = in.readFloat32();
678        appearance->LODScale = in.readFloat32();
[9493]679         
680        if(document.version() > VERSION_15_8)
681            appearance->texturePatternIndex = in.readInt16(-1);
682        else
683           appearance->texturePatternIndex = -1;
684 
[5168]685        // The final short is reserved; don't bother reading it.
[5205]686 
[5038]687        // Add to pool
688        LightPointAppearancePool* lpaPool = document.getOrCreateLightPointAppearancePool();
689        (*lpaPool)[appearance->index] = appearance.get();
690    }
691
692};
693
[10283]694REGISTER_FLTRECORD(LightPointAppearancePalette, LIGHT_POINT_APPEARANCE_PALETTE_OP)
[5038]695
696
[10283]697
[5038]698class LightPointAnimationPalette : public Record
699{
700public:
701
702    LightPointAnimationPalette() {}
703
704    META_Record(LightPointAnimationPalette)
705
706protected:
707
708    virtual ~LightPointAnimationPalette() {}
709
[6759]710    virtual void readRecord(RecordInputStream& in, Document& document)
[5038]711    {
[6759]712         if (document.getLightPointAnimationPoolParent())
713            // Using parent's light point animation pool -- ignore this record.
714            return;
715
716        osg::ref_ptr<LPAnimation> animation = new LPAnimation;
717
[5038]718        in.forward(4);
[6759]719        animation->name = in.readString(256);
720        animation->index = in.readInt32(-1);
721        // Rotating or strobe
722        animation->animationPeriod = in.readFloat32();
723        animation->animationPhaseDelay = in.readFloat32();
724        animation->animationEnabledPeriod = in.readFloat32();
725        animation->axisOfRotation = in.readVec3f();
726        animation->flags = in.readUInt32();
727        animation->animationType = in.readInt32();
728
729        // Morse code
730        animation->morseCodeTiming = in.readInt32();
731        animation->wordRate = in.readInt32();
732        animation->characterRate = in.readInt32();
733        animation->morseCodeString = in.readString(1024);
734
735        // Flashing sequence
[5038]736        int32 numberOfSequences = in.readInt32();
737        for (int n=0; n<numberOfSequences; ++n)
738        {
[6759]739            LPAnimation::Pulse pulse;
740            pulse.state = in.readUInt32();
741            pulse.duration = in.readFloat32();
742            pulse.color = in.readColor32();
743
744            animation->sequence.push_back(pulse);
[5038]745        }
[6759]746
747        // Add to pool
748        LightPointAnimationPool* lpaPool = document.getOrCreateLightPointAnimationPool();
749        (*lpaPool)[animation->index] = animation.get();
[5038]750    }
751};
752
[10283]753REGISTER_FLTRECORD(LightPointAnimationPalette, LIGHT_POINT_ANIMATION_PALETTE_OP)
[5038]754
755
[10283]756
[5038]757class LineStylePalette : public Record
758{
759public:
760
761    LineStylePalette() {}
762
763    META_Record(LineStylePalette)
764
765protected:
766
767    virtual ~LineStylePalette() {}
768
[5229]769    virtual void readRecord(RecordInputStream& /*in*/, Document& /*document*/)
[5038]770    {
771    }
772};
773
[10283]774REGISTER_FLTRECORD(LineStylePalette, LINE_STYLE_PALETTE_OP)
[5038]775
776
[10283]777
[5038]778class TextureMappingPalette : public Record
779{
780public:
781
782    TextureMappingPalette() {}
783
784    META_Record(TextureMappingPalette)
785
786protected:
787
788    virtual ~TextureMappingPalette() {}
789
[5229]790    virtual void readRecord(RecordInputStream& /*in*/, Document& /*document*/)
[5038]791    {
792    }
793};
794
[10283]795REGISTER_FLTRECORD(TextureMappingPalette, TEXTURE_MAPPING_PALETTE_OP)
[5038]796
797
[10283]798
[5038]799class ShaderPalette : public Record
800{
801public:
802
803    ShaderPalette() {}
804
805    META_Record(ShaderPalette)
806
807    enum ShaderType
808    {
809        CG=0,
810        CGFX=1,
811        GLSL=2
812    };
813
814protected:
815
816    virtual ~ShaderPalette() {}
817
818    virtual void readRecord(RecordInputStream& in, Document& document)
819    {
[5236]820        if (document.getShaderPoolParent())
821            // Using parent's shader pool -- ignore this record.
822            return;
823
[5251]824        int32 index = in.readInt32(-1);
825        int32 type = in.readInt32(-1);
[5038]826        std::string name = in.readString(1024);
827
[5145]828        if (type == CG)
829        {
830            // CG support is currently not implemented. Just parse.
831            std::string vertexProgramFilename = in.readString(1024);
832            std::string fragmentProgramFilename = in.readString(1024);
[5229]833            /*int32 vertexProgramProfile =*/ in.readInt32();
834            /*int32 fragmentProgramProfile =*/ in.readInt32();
[5145]835            std::string vertexProgramEntry = in.readString(256);
836            std::string fragmentProgramEntry = in.readString(256);
837        }
[5251]838        else if (type == GLSL)
[5038]839        {
[5251]840            int32 vertexProgramFileCount(1);
841            int32 fragmentProgramFileCount(1);
[5145]842
[5251]843            if (document.version() >= VERSION_16_1)
[5145]844            {
845                // In 16.1, possibly multiple filenames for each vertex and fragment program.
846                vertexProgramFileCount = in.readInt32();
847                fragmentProgramFileCount = in.readInt32();
848            }
849            // else 16.0
850            //   Technically, 16.0 didn't support GLSL, but this plugin
851            //   supports it with a single vertex shader filename and a
852            //   single fragment shader filename.
853
[5038]854            osg::Program* program = new osg::Program;
855            program->setName(name);
856
[6165]857            // Read vertex programs
[5145]858            int idx;
859            for( idx=0; idx<vertexProgramFileCount; idx++)
[5038]860            {
[5145]861                std::string vertexProgramFilename = in.readString(1024);
862
[6165]863                std::string vertexProgramFilePath = osgDB::findDataFile(vertexProgramFilename,document.getOptions());
[5145]864                if (!vertexProgramFilePath.empty())
865                {
866                    osg::Shader* vertexShader = osg::Shader::readShaderFile(osg::Shader::VERTEX, vertexProgramFilePath);
867                    if (vertexShader)
868                        program->addShader( vertexShader );
869                }
[5038]870            }
[6165]871
872            // Read fragment programs
[5145]873            for( idx=0; idx<fragmentProgramFileCount; idx++)
874            {
875                std::string fragmentProgramFilename = in.readString(1024);
[5038]876
[6165]877                std::string fragmentProgramFilePath = osgDB::findDataFile(fragmentProgramFilename,document.getOptions());
[5145]878                if (!fragmentProgramFilePath.empty())
879                {
880                    osg::Shader* fragmentShader = osg::Shader::readShaderFile(osg::Shader::FRAGMENT, fragmentProgramFilePath);
881                    if (fragmentShader)
882                        program->addShader( fragmentShader );
883                }
[5038]884            }
885
[6165]886            // Add to shader pool
[5038]887            ShaderPool* shaderPool = document.getOrCreateShaderPool();
888            (*shaderPool)[index] = program;
889        }
890    }
891};
892
[10283]893REGISTER_FLTRECORD(ShaderPalette, SHADER_PALETTE_OP)
[5038]894
[10283]895
[5038]896} // end namespace
897
Note: See TracBrowser for help on using the browser.