2
#include "osg/io_utils"
4
#include "osgDB/Registry"
6
#include "osgDB/Output"
12
// forward declare functions to use later.
13
bool Node_readLocalData(Object& obj, Input& fr);
14
bool Node_writeLocalData(const Object& obj, Output& fw);
16
// register the read and write functions with the osgDB::Registry.
17
REGISTER_DOTOSGWRAPPER(Node)
26
bool Node_readLocalData(Object& obj, Input& fr)
28
bool iteratorAdvanced = false;
30
Node& node = static_cast<Node&>(obj);
32
unsigned int mask = node.getNodeMask();
33
if (fr[0].matchWord("nodeMask") && fr[1].getUInt(mask))
35
node.setNodeMask(mask);
37
iteratorAdvanced = true;
40
if (fr[0].matchWord("cullingActive"))
42
if (fr[1].matchWord("FALSE"))
44
node.setCullingActive(false);
45
iteratorAdvanced = true;
48
else if (fr[1].matchWord("TRUE"))
50
node.setCullingActive(true);
51
iteratorAdvanced = true;
56
while (fr.matchSequence("description {"))
58
int entry = fr[0].getNoNestedBrackets();
61
while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
63
if (fr[0].getStr()) node.addDescription(std::string(fr[0].getStr()));
66
iteratorAdvanced = true;
70
while (fr.matchSequence("description %s"))
72
if (fr[1].getStr()) node.addDescription(fr[1].getStr());
74
iteratorAdvanced = true;
77
static ref_ptr<StateSet> s_drawstate = new osg::StateSet;
78
if (StateSet* readState = static_cast<StateSet*>(fr.readObjectOfType(*s_drawstate)))
80
node.setStateSet(readState);
81
iteratorAdvanced = true;
85
static ref_ptr<NodeCallback> s_nodecallback = new osg::NodeCallback;
86
while (fr.matchSequence("UpdateCallback {"))
88
int entry = fr[0].getNoNestedBrackets();
91
while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
93
NodeCallback* nodecallback = dynamic_cast<NodeCallback*>(fr.readObjectOfType(*s_nodecallback));
95
if (node.getUpdateCallback() == NULL) {
96
node.setUpdateCallback(nodecallback);
98
node.getUpdateCallback()->addNestedCallback(nodecallback);
103
iteratorAdvanced = true;
107
while (fr.matchSequence("EventCallback {"))
109
int entry = fr[0].getNoNestedBrackets();
112
while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
114
NodeCallback* nodecallback = dynamic_cast<NodeCallback*>(fr.readObjectOfType(*s_nodecallback));
116
if (node.getEventCallback() == NULL) {
117
node.setEventCallback(nodecallback);
119
node.getEventCallback()->addNestedCallback(nodecallback);
124
iteratorAdvanced = true;
128
while (fr.matchSequence("CullCallbacks {"))
130
int entry = fr[0].getNoNestedBrackets();
133
while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
135
NodeCallback* nodecallback = dynamic_cast<NodeCallback*>(fr.readObjectOfType(*s_nodecallback));
137
if (node.getCullCallback() == NULL) {
138
node.setCullCallback(nodecallback);
140
node.getCullCallback()->addNestedCallback(nodecallback);
145
iteratorAdvanced = true;
149
if (fr.matchSequence("initialBound %f %f %f %f"))
152
fr[1].getFloat(bs.center().x());
153
fr[2].getFloat(bs.center().y());
154
fr[3].getFloat(bs.center().z());
155
fr[4].getFloat(bs.radius());
156
node.setInitialBound(bs);
158
iteratorAdvanced = true;
161
while (fr.matchSequence("ComputeBoundingSphereCallback {"))
163
int entry = fr[0].getNoNestedBrackets();
166
while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
168
Node::ComputeBoundingSphereCallback* callback = dynamic_cast<Node::ComputeBoundingSphereCallback*>(fr.readObjectOfType(type_wrapper<Node::ComputeBoundingSphereCallback>()));
170
node.setComputeBoundingSphereCallback(callback);
174
iteratorAdvanced = true;
178
return iteratorAdvanced;
182
bool Node_writeLocalData(const Object& obj, Output& fw)
184
const Node& node = static_cast<const Node&>(obj);
186
fw.indent() << "nodeMask 0x" << hex << node.getNodeMask() << dec << std::endl;
188
fw.indent() << "cullingActive ";
189
if (node.getCullingActive()) fw << "TRUE"<< std::endl;
190
else fw << "FALSE"<< std::endl;
193
if (!node.getDescriptions().empty())
195
if (node.getDescriptions().size()==1)
197
fw.indent() << "description "<<fw.wrapString(node.getDescriptions().front())<< std::endl;
201
fw.indent() << "description {"<< std::endl;
203
for(Node::DescriptionList::const_iterator ditr=node.getDescriptions().begin();
204
ditr!=node.getDescriptions().end();
207
fw.indent() << fw.wrapString(*ditr)<< std::endl;
210
fw.indent() << "}"<< std::endl;
214
if (node.getStateSet())
216
fw.writeObject(*node.getStateSet());
219
if (node.getUpdateCallback())
221
fw.indent() << "UpdateCallbacks {" << std::endl;
223
fw.writeObject(*node.getUpdateCallback());
225
fw.indent() << "}" << std::endl;
228
if (node.getEventCallback())
230
fw.indent() << "EventCallbacks {" << std::endl;
232
fw.writeObject(*node.getEventCallback());
234
fw.indent() << "}" << std::endl;
237
if (node.getCullCallback())
239
fw.indent() << "CullCallbacks {" << std::endl;
241
fw.writeObject(*node.getCullCallback());
243
fw.indent() << "}" << std::endl;
246
if (node.getInitialBound().valid())
248
const osg::BoundingSphere& bs = node.getInitialBound();
249
fw.indent()<<"initialBound "<<bs.center()<<" "<<bs.radius()<<std::endl;
252
if (node.getComputeBoundingSphereCallback())
254
fw.indent() << "ComputeBoundingSphereCallback {" << std::endl;
256
fw.writeObject(*node.getComputeBoundingSphereCallback());
258
fw.indent() << "}" << std::endl;