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

Revision 13041, 4.1 kB (checked in by robert, 3 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_RECORD_H
21#define FLT_RECORD_H 1
22
23#include <stdexcept>
24#include <string>
25#include <osg/Array>
26#include <osg/Geometry>
27#include <osg/Geode>
28#include <osg/Group>
29#include <osg/MatrixTransform>
30#include "Vertex.h"
31
32namespace flt
33{
34
35class RecordInputStream;
36class Document;
37class PrimaryRecord;
38class Matrix;
39
40#define META_Record(name) \
41        virtual flt::Record* cloneType() const { return new name (); } \
42        virtual bool isSameKindAs(const flt::Record* rec) const { return dynamic_cast<const name *>(rec)!=NULL; }
43#define META_setID(imp) virtual void setID(const std::string& id) { if (imp.valid()) imp->setName(id); }
44#define META_setComment(imp) virtual void setComment(const std::string& id) { if (imp.valid()) imp->addDescription(id); }
45#define META_setMultitexture(imp) virtual void setMultitexture(osg::StateSet& multitexture) { if (imp.valid()) imp->getOrCreateStateSet()->merge(multitexture); }
46#define META_addChild(imp) virtual void addChild(osg::Node& child) { if (imp.valid()) imp->addChild(&child); }
47#define META_dispose(imp) virtual void dispose(Document&) { if (imp.valid() && _matrix.valid()) insertMatrixTransform(*imp,*_matrix,_numberOfReplications); }
48
49// pure virtual base class
50class Record : public osg::Referenced
51{
52public:
53
54    Record();
55
56    virtual Record* cloneType() const = 0;
57    virtual bool isSameKindAs(const Record* rec) const = 0;
58    virtual void read(RecordInputStream& in, Document& document);
59
60    void setParent(PrimaryRecord* parent);
61
62protected:
63
64    virtual ~Record();
65
66    virtual void readRecord(RecordInputStream& in, Document& document);
67
68    osg::ref_ptr<PrimaryRecord> _parent;
69};
70
71
72class PrimaryRecord : public Record
73{
74public:
75
76    PrimaryRecord();
77
78    virtual void read(RecordInputStream& in, Document& document);
79    virtual void dispose(Document& /*document*/) {}
80
81    // Ancillary operations
82    virtual void setID(const std::string& /*id*/) {}
83    virtual void setComment(const std::string& /*comment*/) {}
84    virtual void setMultitexture(osg::StateSet& /*multitexture*/) {}
85    virtual void addChild(osg::Node& /*child*/) {}
86    virtual void addVertex(Vertex& /*vertex*/) {}
87    virtual void addVertexUV(int /*layer*/,const osg::Vec2& /*uv*/) {}
88    virtual void addMorphVertex(Vertex& /*vertex0*/, Vertex& /*vertex100*/) {}
89    virtual void setMultiSwitchValueName(unsigned int /*switchSet*/, const std::string& /*name*/) {}
90
91    void setNumberOfReplications(int num) { _numberOfReplications = num; }
92    void setMatrix(const osg::Matrix& matrix) { _matrix = new osg::RefMatrix(matrix); }
93
94    void setLocalVertexPool(VertexList* pool) { _localVertexPool = pool; }
95    VertexList* getLocalVertexPool() { return _localVertexPool.get(); }
96
97protected:
98
99    virtual ~PrimaryRecord() {}
100
101    int _numberOfReplications;
102    osg::ref_ptr<osg::RefMatrix> _matrix;
103    osg::ref_ptr<VertexList> _localVertexPool;
104};
105
106
107/** DummyRecord -
108  */
109class DummyRecord : public Record
110{
111    public:
112
113        DummyRecord() {}
114
115        META_Record(DummyRecord)
116
117    protected:
118
119        virtual ~DummyRecord() {}
120};
121
122
123void insertMatrixTransform(osg::Node& node, const osg::Matrix& matrix, int numberOfReplications);
124
125osg::Vec3Array* getOrCreateVertexArray(osg::Geometry& geometry);
126osg::Vec3Array* getOrCreateNormalArray(osg::Geometry& geometry);
127osg::Vec4Array* getOrCreateColorArray(osg::Geometry& geometry);
128osg::Vec2Array* getOrCreateTextureArray(osg::Geometry& geometry, int unit);
129
130
131} // end namespace
132
133#endif
Note: See TracBrowser for help on using the browser.