#include #include #include #include #include #include using namespace osg; using namespace osgDB; ////////////////////////////////////////////////////////////////////////////// // forward declare functions to use later. bool Sphere_readLocalData(Object& obj, Input& fr); bool Sphere_writeLocalData(const Object& obj, Output& fw); //register the read and write functions with the osgDB::Registry. RegisterDotOsgWrapperProxy g_SphereFuncProxy ( new osg::Sphere, "Sphere", "Object Sphere", &Sphere_readLocalData, &Sphere_writeLocalData, DotOsgWrapper::READ_AND_WRITE ); bool Sphere_readLocalData(Object& obj, Input& fr) { bool iteratorAdvanced = false; Sphere& sphere = static_cast(obj); if (fr.matchSequence("Center %f %f %f")) { osg::Vec3 center; fr[1].getFloat(center.x()); fr[2].getFloat(center.y()); fr[3].getFloat(center.z()); sphere.setCenter(center); fr+=4; iteratorAdvanced = true; } if (fr.matchSequence("Radius %f")) { float radius; fr[1].getFloat(radius); sphere.setRadius(radius); fr+=2; iteratorAdvanced = true; } return iteratorAdvanced; } bool Sphere_writeLocalData(const Object& obj, Output& fw) { const Sphere& sphere = static_cast(obj); fw.indent()<<"Center "<(obj); if (fr.matchSequence("Center %f %f %f")) { osg::Vec3 center; fr[1].getFloat(center.x()); fr[2].getFloat(center.y()); fr[3].getFloat(center.z()); box.setCenter(center); fr+=4; iteratorAdvanced = true; } if (fr.matchSequence("HalfLengths %f %f %f")) { osg::Vec3 lenghts; fr[1].getFloat(lenghts.x()); fr[2].getFloat(lenghts.y()); fr[3].getFloat(lenghts.z()); box.setHalfLengths(lenghts); fr+=4; iteratorAdvanced = true; } if (fr.matchSequence("Rotation %f %f %f %f")) { osg::Quat rotation; fr[1].getFloat(rotation.x()); fr[2].getFloat(rotation.y()); fr[3].getFloat(rotation.z()); fr[4].getFloat(rotation.w()); box.setRotation(rotation); fr+=5; iteratorAdvanced = true; } return iteratorAdvanced; } bool Box_writeLocalData(const Object& obj, Output& fw) { const Box& box = static_cast(obj); fw.indent()<<"Center "<(obj); if (fr.matchSequence("Center %f %f %f")) { osg::Vec3 center; fr[1].getFloat(center.x()); fr[2].getFloat(center.y()); fr[3].getFloat(center.z()); cone.setCenter(center); fr+=4; iteratorAdvanced = true; } if (fr.matchSequence("Radius %f")) { float radius; fr[1].getFloat(radius); cone.setRadius(radius); fr+=2; iteratorAdvanced = true; } if (fr.matchSequence("Height %f")) { float height; fr[1].getFloat(height); cone.setHeight(height); fr+=2; iteratorAdvanced = true; } if (fr.matchSequence("Rotation %f %f %f %f")) { osg::Quat rotation; fr[1].getFloat(rotation.x()); fr[2].getFloat(rotation.y()); fr[3].getFloat(rotation.z()); fr[4].getFloat(rotation.w()); cone.setRotation(rotation); fr+=5; iteratorAdvanced = true; } return iteratorAdvanced; } bool Cone_writeLocalData(const Object& obj, Output& fw) { const Cone& cone = static_cast(obj); fw.indent()<<"Center "<(obj); if (fr.matchSequence("Center %f %f %f")) { osg::Vec3 center; fr[1].getFloat(center.x()); fr[2].getFloat(center.y()); fr[3].getFloat(center.z()); cylinder.setCenter(center); fr+=4; iteratorAdvanced = true; } if (fr.matchSequence("Radius %f")) { float radius; fr[1].getFloat(radius); cylinder.setRadius(radius); fr+=2; iteratorAdvanced = true; } if (fr.matchSequence("Height %f")) { float height; fr[1].getFloat(height); cylinder.setHeight(height); fr+=2; iteratorAdvanced = true; } if (fr.matchSequence("Rotation %f %f %f %f")) { osg::Quat rotation; fr[1].getFloat(rotation.x()); fr[2].getFloat(rotation.y()); fr[3].getFloat(rotation.z()); fr[4].getFloat(rotation.w()); cylinder.setRotation(rotation); fr+=5; iteratorAdvanced = true; } return iteratorAdvanced; } bool Cylinder_writeLocalData(const Object& obj, Output& fw) { const Cylinder& cylinder = static_cast(obj); fw.indent()<<"Center "<(obj); if (fr.matchSequence("Center %f %f %f")) { osg::Vec3 center; fr[1].getFloat(center.x()); fr[2].getFloat(center.y()); fr[3].getFloat(center.z()); capsule.setCenter(center); fr+=4; iteratorAdvanced = true; } if (fr.matchSequence("Radius %f")) { float radius; fr[1].getFloat(radius); capsule.setRadius(radius); fr+=2; iteratorAdvanced = true; } if (fr.matchSequence("Height %f")) { float height; fr[1].getFloat(height); capsule.setHeight(height); fr+=2; iteratorAdvanced = true; } if (fr.matchSequence("Rotation %f %f %f %f")) { osg::Quat rotation; fr[1].getFloat(rotation.x()); fr[2].getFloat(rotation.y()); fr[3].getFloat(rotation.z()); fr[4].getFloat(rotation.w()); capsule.setRotation(rotation); fr+=5; iteratorAdvanced = true; } return iteratorAdvanced; } bool Capsule_writeLocalData(const Object& obj, Output& fw) { const Capsule& capsule = static_cast(obj); fw.indent()<<"Center "<(obj); if (fr.matchSequence("Origin %f %f %f")) { osg::Vec3 origin; fr[1].getFloat(origin.x()); fr[2].getFloat(origin.y()); fr[3].getFloat(origin.z()); heightfield.setOrigin(origin); fr+=4; } if (fr.matchSequence("XInterval %f")) { float interval; fr[1].getFloat(interval); heightfield.setXInterval(interval); fr+=2; iteratorAdvanced = true; } if (fr.matchSequence("YInterval %f")) { float interval; fr[1].getFloat(interval); heightfield.setYInterval(interval); fr+=2; iteratorAdvanced = true; } if (fr.matchSequence("SkirtHeight %f")) { float height; fr[1].getFloat(height); heightfield.setSkirtHeight(height); fr+=2; iteratorAdvanced = true; } if (fr.matchSequence("BorderWidth %i")) { unsigned int width; fr[1].getUInt(width); heightfield.setBorderWidth(width); fr+=2; iteratorAdvanced = true; } if (fr.matchSequence("Rotation %f %f %f %f")) { osg::Quat rotation; fr[1].getFloat(rotation.x()); fr[2].getFloat(rotation.y()); fr[3].getFloat(rotation.z()); fr[4].getFloat(rotation.w()); heightfield.setRotation(rotation); fr+=5; iteratorAdvanced = true; } if (fr.matchSequence("NumColumnsAndRows %i %i")) { int numcolumns,numrows; fr[1].getInt(numcolumns); fr[2].getInt(numrows); heightfield.allocate(numcolumns,numrows); fr+=3; iteratorAdvanced = true; } if (fr.matchSequence("Heights {")) { int entry = fr[0].getNoNestedBrackets(); fr += 2; float height; unsigned int row = 0; unsigned int column = 0; while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) { if (fr.readSequence(height)) { heightfield.setHeight(column,row,height); ++column; if (column>=heightfield.getNumColumns()) { column = 0; ++row; } } else { ++fr; } } iteratorAdvanced = true; ++fr; } return iteratorAdvanced; } bool HeightField_writeLocalData(const Object& obj, Output& fw) { const HeightField& heightfield = static_cast(obj); int prec = fw.precision(); fw.precision(15); fw.indent()<<"Origin "<(obj); ref_ptr readObject; if (fr[0].matchWord("Shape")) { readObject = fr.readObject(); if (readObject.valid()) { osg::Shape* shape = dynamic_cast(readObject.get()); if (shape) composite.setShape(shape); else notify(WARN)<<"Warning:: "<className()<<" loaded but cannot not be attached to Drawable."<())).valid()) { osg::Shape* shape = static_cast(readObject.get()); composite.addChild(shape); iteratorAdvanced = true; } return iteratorAdvanced; } bool CompositeShape_writeLocalData(const Object& obj, Output& fw) { const CompositeShape& composite = static_cast(obj); if (composite.getShape()) { fw.indent() << "Shape "; fw.writeObject(*composite.getShape()); } for(unsigned int i=0;i(obj); // // return iteratorAdvanced; // } // // bool InfinitePlane_writeLocalData(const Object& obj, Output& fw) // { // //const InfinitePlane& infplane = static_cast(obj); // // return true; // } // // // ////////////////////////////////////////////////////////////////////////////// // // // forward declare functions to use later. // bool TriangleMesh_readLocalData(Object& obj, Input& fr); // bool TriangleMesh_writeLocalData(const Object& obj, Output& fw); // // //register the read and write functions with the osgDB::Registry. // RegisterDotOsgWrapperProxy g_TriangleMeshFuncProxy // ( // new osg::TriangleMesh, // "TriangleMesh", // "Object ", // &TriangleMesh_readLocalData, // &TriangleMesh_writeLocalData, // DotOsgWrapper::READ_AND_WRITE // ); // // bool TriangleMesh_readLocalData(Object& obj, Input& fr) // { // bool iteratorAdvanced = false; // // // TriangleMesh& mesh = static_cast(obj); // // return iteratorAdvanced; // } // // bool TriangleMesh_writeLocalData(const Object& obj, Output& fw) // { // // const TriangleMesh& mesh = static_cast(obj); // // return true; // } // // // ////////////////////////////////////////////////////////////////////////////// // // forward declare functions to use later. // bool ConvexHull_readLocalData(Object& obj, Input& fr); // bool ConvexHull_writeLocalData(const Object& obj, Output& fw); // // //register the read and write functions with the osgDB::Registry. // RegisterDotOsgWrapperProxy g_ConvexHullFuncProxy // ( // new osg::ConvexHull, // "ConvexHull", // "Object ", // &ConvexHull_readLocalData, // &ConvexHull_writeLocalData, // DotOsgWrapper::READ_AND_WRITE // ); // // bool ConvexHull_readLocalData(Object& obj, Input& fr) // { // bool iteratorAdvanced = false; // // // ConvexHull& geom = static_cast(obj); // // return iteratorAdvanced; // } // // bool ConvexHull_writeLocalData(const Object& obj, Output& fw) // { // // const ConvexHull& geom = static_cast(obj); // // return true; // } // //