#include "osg/Node" #include "osg/io_utils" #include "osgDB/Registry" #include "osgDB/Input" #include "osgDB/Output" using namespace osg; using namespace osgDB; using namespace std; // forward declare functions to use later. bool Node_readLocalData(Object& obj, Input& fr); bool Node_writeLocalData(const Object& obj, Output& fw); // register the read and write functions with the osgDB::Registry. RegisterDotOsgWrapperProxy g_NodeProxy ( new osg::Node, "Node", "Object Node", &Node_readLocalData, &Node_writeLocalData ); bool Node_readLocalData(Object& obj, Input& fr) { bool iteratorAdvanced = false; Node& node = static_cast(obj); unsigned int mask = node.getNodeMask(); if (fr[0].matchWord("nodeMask") && fr[1].getUInt(mask)) { node.setNodeMask(mask); fr+=2; iteratorAdvanced = true; } if (fr[0].matchWord("cullingActive")) { if (fr[1].matchWord("FALSE")) { node.setCullingActive(false); iteratorAdvanced = true; fr+=2; } else if (fr[1].matchWord("TRUE")) { node.setCullingActive(true); iteratorAdvanced = true; fr+=2; } } while (fr.matchSequence("description {")) { int entry = fr[0].getNoNestedBrackets(); fr += 2; while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) { if (fr[0].getStr()) node.addDescription(std::string(fr[0].getStr())); ++fr; } iteratorAdvanced = true; } while (fr.matchSequence("description %s")) { if (fr[1].getStr()) node.addDescription(fr[1].getStr()); fr+=2; iteratorAdvanced = true; } static ref_ptr s_drawstate = new osg::StateSet; if (StateSet* readState = static_cast(fr.readObjectOfType(*s_drawstate))) { node.setStateSet(readState); iteratorAdvanced = true; } static ref_ptr s_nodecallback = new osg::NodeCallback; while (fr.matchSequence("UpdateCallback {")) { int entry = fr[0].getNoNestedBrackets(); fr += 2; while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) { NodeCallback* nodecallback = dynamic_cast(fr.readObjectOfType(*s_nodecallback)); if (nodecallback) { if (node.getUpdateCallback() == NULL) { node.setUpdateCallback(nodecallback); } else { node.getUpdateCallback()->addNestedCallback(nodecallback); } } else ++fr; } iteratorAdvanced = true; } while (fr.matchSequence("EventCallback {")) { int entry = fr[0].getNoNestedBrackets(); fr += 2; while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) { NodeCallback* nodecallback = dynamic_cast(fr.readObjectOfType(*s_nodecallback)); if (nodecallback) { if (node.getEventCallback() == NULL) { node.setEventCallback(nodecallback); } else { node.getEventCallback()->addNestedCallback(nodecallback); } } else ++fr; } iteratorAdvanced = true; } while (fr.matchSequence("CullCallbacks {")) { int entry = fr[0].getNoNestedBrackets(); fr += 2; while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) { NodeCallback* nodecallback = dynamic_cast(fr.readObjectOfType(*s_nodecallback)); if (nodecallback) { if (node.getCullCallback() == NULL) { node.setCullCallback(nodecallback); } else { node.getCullCallback()->addNestedCallback(nodecallback); } } else ++fr; } iteratorAdvanced = true; } if (fr.matchSequence("initialBound %f %f %f %f")) { BoundingSphere bs; fr[1].getFloat(bs.center().x()); fr[2].getFloat(bs.center().y()); fr[3].getFloat(bs.center().z()); fr[4].getFloat(bs.radius()); node.setInitialBound(bs); fr += 5; iteratorAdvanced = true; } while (fr.matchSequence("ComputeBoundingSphereCallback {")) { int entry = fr[0].getNoNestedBrackets(); fr += 2; while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) { Node::ComputeBoundingSphereCallback* callback = dynamic_cast(fr.readObjectOfType(type_wrapper())); if (callback) { node.setComputeBoundingSphereCallback(callback); } else ++fr; } iteratorAdvanced = true; } return iteratorAdvanced; } bool Node_writeLocalData(const Object& obj, Output& fw) { const Node& node = static_cast(obj); fw.indent() << "nodeMask 0x" << hex << node.getNodeMask() << dec << std::endl; fw.indent() << "cullingActive "; if (node.getCullingActive()) fw << "TRUE"<< std::endl; else fw << "FALSE"<< std::endl; if (!node.getDescriptions().empty()) { if (node.getDescriptions().size()==1) { fw.indent() << "description "<