source: OGRE/trunk/ogrenew/Tools/VRMLConverter/vrmllib/src/nodes.cpp @ 692

Revision 692, 3.6 KB checked in by mattausch, 18 years ago (diff)

adding ogre 1.2 and dependencies

Line 
1#include <vrmllib/nodes.h>
2
3#include <map>
4#include <stdexcept>
5
6#include <vrmllib/types_bits.h>
7
8#define BEGIN_NODE(type) \
9        namespace {\
10        node_creator<type> register_##type##_creator(#type); \
11        } \
12        void type::parse_attribute(const std::string &a_name, \
13                std::istream &a_stream, file &a_data) \
14        {
15
16#define ATTR(d_var) \
17                if (a_name == #d_var) { \
18                        using namespace bits; \
19                        return parse_value(d_var, a_stream, a_data); \
20                }
21#define VATTR(d_var) \
22                if (a_name == #d_var) { \
23                        using namespace bits; \
24                        return parse_vector(d_var, a_stream, a_data); \
25                }
26#define END_NODE \
27                base_type::parse_attribute(a_name, a_stream, a_data); \
28        }
29
30#define BEGIN_DEFAULTS(type) \
31        type::type() :
32#define END_DEFAULTS \
33        {}
34
35namespace vrmllib {
36namespace bits {
37
38class node_creator_base {
39public:
40        virtual ~node_creator_base() {}
41        virtual node *create() = 0;
42};
43
44std::map<std::string, node_creator_base *> g_node_creators;
45
46template<class Type>
47class node_creator : public node_creator_base {
48public:
49        node_creator(const char *type) { g_node_creators[type] = this; }
50        node *create() { return new Type; }
51};
52
53} // namespace bits
54
55using namespace bits;
56
57node *node::create_node(const std::string &type)
58{
59        node_creator_base *c = g_node_creators[type];
60
61        if (c)
62                return c->create();
63        else {
64                std::cerr << "unknown type: " << type << std::endl;
65                return 0;
66        }
67}
68
69BEGIN_NODE(grouping_node)
70        VATTR(children)
71END_NODE
72
73BEGIN_DEFAULTS(Transform)
74        translation(0,0,0),
75        center(0,0,0),
76        scale(1,1,1)
77END_DEFAULTS
78BEGIN_NODE(Transform)
79        ATTR(translation)
80        ATTR(rotation)
81        ATTR(center)
82        ATTR(scale)
83        ATTR(scaleOrientation)
84END_NODE
85
86BEGIN_NODE(Group)
87END_NODE
88
89BEGIN_DEFAULTS(Shape)
90        appearance(0),
91        geometry(0)
92END_DEFAULTS
93BEGIN_NODE(Shape)
94        ATTR(appearance)
95        ATTR(geometry)
96END_NODE
97
98BEGIN_DEFAULTS(Switch)
99        whichChoice(0)
100END_DEFAULTS
101BEGIN_NODE(Switch)
102        VATTR(choice)
103        ATTR(whichChoice)
104END_NODE
105
106BEGIN_DEFAULTS(Viewpoint)
107        fieldOfView(0.785398),
108        position(0,0,10)
109END_DEFAULTS
110BEGIN_NODE(Viewpoint)
111        ATTR(fieldOfView)
112        ATTR(orientation)
113        ATTR(position)
114        ATTR(description)
115END_NODE
116
117BEGIN_DEFAULTS(Appearance)
118        material(0),
119        texture(0)
120END_DEFAULTS
121BEGIN_NODE(Appearance)
122        ATTR(material)
123        ATTR(texture)
124END_NODE
125
126BEGIN_NODE(WorldInfo)
127        ATTR(title)
128        VATTR(info)
129END_NODE
130
131BEGIN_DEFAULTS(Material)
132        diffuseColor(204,204,204),
133        specularColor(0,0,0),
134        emissiveColor(0,0,0),
135        ambientIntensity(0.2),
136        shininess(0.2),
137        transparency(0)
138END_DEFAULTS
139BEGIN_NODE(Material)
140        ATTR(diffuseColor)
141        ATTR(specularColor)
142        ATTR(emissiveColor)
143        ATTR(ambientIntensity)
144        ATTR(shininess)
145        ATTR(transparency)
146END_NODE
147
148BEGIN_DEFAULTS(IndexedFaceSet)
149        solid(true),
150        convex(true),
151        ccw(true),
152        normalPerVertex(true),
153        colorPerVertex(true),
154        coord(0),
155        normal(0),
156        texCoord(0),
157        color(0)
158END_DEFAULTS
159BEGIN_NODE(IndexedFaceSet)
160        ATTR(solid)
161        ATTR(convex)
162        ATTR(ccw)
163        ATTR(normalPerVertex)
164        ATTR(colorPerVertex)
165        ATTR(coord)
166        ATTR(color)
167        ATTR(normal)
168        ATTR(texCoord)
169        VATTR(coordIndex)
170        VATTR(texCoordIndex)
171        VATTR(normalIndex)
172        VATTR(colorIndex)
173END_NODE
174
175BEGIN_NODE(Coordinate)
176        VATTR(point)
177END_NODE
178
179BEGIN_NODE(Color)
180        VATTR(color)
181END_NODE
182
183BEGIN_NODE(Box)
184        ATTR(size)
185END_NODE
186
187BEGIN_NODE(Sphere)
188        ATTR(radius)
189END_NODE
190
191BEGIN_NODE(TextureCoordinate)
192        VATTR(point)
193END_NODE
194
195BEGIN_NODE(Normal)
196        VATTR(vector)
197END_NODE
198
199BEGIN_DEFAULTS(ImageTexture)
200        repeatS(true), repeatT(true)
201END_DEFAULTS
202BEGIN_NODE(ImageTexture)
203        VATTR(url)
204        ATTR(repeatS)
205        ATTR(repeatT)
206END_NODE
207
208} // namespace vrmllib
Note: See TracBrowser for help on using the repository browser.