| 1 | #undef OBJECT_CAST |
|---|
| 2 | #define OBJECT_CAST dynamic_cast |
|---|
| 3 | |
|---|
| 4 | #include <osg/AnimationPath> |
|---|
| 5 | #include <osgDB/ObjectWrapper> |
|---|
| 6 | #include <osgDB/InputStream> |
|---|
| 7 | #include <osgDB/OutputStream> |
|---|
| 8 | |
|---|
| 9 | static bool checkTimeControlPointMap( const osg::AnimationPath& path ) |
|---|
| 10 | { |
|---|
| 11 | return path.getTimeControlPointMap().size()>0; |
|---|
| 12 | } |
|---|
| 13 | |
|---|
| 14 | static bool readTimeControlPointMap( osgDB::InputStream& is, osg::AnimationPath& path ) |
|---|
| 15 | { |
|---|
| 16 | unsigned int size = is.readSize(); |
|---|
| 17 | if ( size>0 ) |
|---|
| 18 | { |
|---|
| 19 | is >> osgDB::BEGIN_BRACKET; |
|---|
| 20 | for ( unsigned int i=0; i<size; ++i ) |
|---|
| 21 | { |
|---|
| 22 | double time = 0.0; |
|---|
| 23 | osg::Vec3d pos, scale; |
|---|
| 24 | osg::Quat rot; |
|---|
| 25 | is >> osgDB::PROPERTY("Time") >> time >> osgDB::BEGIN_BRACKET; |
|---|
| 26 | is >> osgDB::PROPERTY("Position") >> pos; |
|---|
| 27 | is >> osgDB::PROPERTY("Rotation") >> rot; |
|---|
| 28 | is >> osgDB::PROPERTY("Scale") >> scale; |
|---|
| 29 | is >> osgDB::END_BRACKET; |
|---|
| 30 | path.insert( time, osg::AnimationPath::ControlPoint(pos, rot, scale) ); |
|---|
| 31 | } |
|---|
| 32 | is >> osgDB::END_BRACKET; |
|---|
| 33 | } |
|---|
| 34 | return true; |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | static bool writeTimeControlPointMap( osgDB::OutputStream& os, const osg::AnimationPath& path ) |
|---|
| 38 | { |
|---|
| 39 | const osg::AnimationPath::TimeControlPointMap& map = path.getTimeControlPointMap(); |
|---|
| 40 | os.writeSize(map.size()); |
|---|
| 41 | if ( map.size()>0 ) |
|---|
| 42 | { |
|---|
| 43 | os << osgDB::BEGIN_BRACKET << std::endl; |
|---|
| 44 | for ( osg::AnimationPath::TimeControlPointMap::const_iterator itr=map.begin(); |
|---|
| 45 | itr!=map.end(); ++itr ) |
|---|
| 46 | { |
|---|
| 47 | const osg::AnimationPath::ControlPoint& pt = itr->second; |
|---|
| 48 | os << osgDB::PROPERTY("Time") << itr->first << osgDB::BEGIN_BRACKET << std::endl; |
|---|
| 49 | os << osgDB::PROPERTY("Position") << pt.getPosition() << std::endl; |
|---|
| 50 | os << osgDB::PROPERTY("Rotation") << pt.getRotation() << std::endl; |
|---|
| 51 | os << osgDB::PROPERTY("Scale") << pt.getScale() << std::endl; |
|---|
| 52 | os << osgDB::END_BRACKET << std::endl; |
|---|
| 53 | } |
|---|
| 54 | os << osgDB::END_BRACKET; |
|---|
| 55 | } |
|---|
| 56 | os << std::endl; |
|---|
| 57 | return true; |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | REGISTER_OBJECT_WRAPPER( AnimationPath, |
|---|
| 61 | new osg::AnimationPath, |
|---|
| 62 | osg::AnimationPath, |
|---|
| 63 | "osg::Object osg::AnimationPath" ) |
|---|
| 64 | { |
|---|
| 65 | ADD_USER_SERIALIZER( TimeControlPointMap ); |
|---|
| 66 | |
|---|
| 67 | BEGIN_ENUM_SERIALIZER( LoopMode, LOOP ); |
|---|
| 68 | ADD_ENUM_VALUE( SWING ); |
|---|
| 69 | ADD_ENUM_VALUE( LOOP ); |
|---|
| 70 | ADD_ENUM_VALUE( NO_LOOPING ); |
|---|
| 71 | END_ENUM_SERIALIZER(); |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | #undef OBJECT_CAST |
|---|
| 75 | #define OBJECT_CAST static_cast |
|---|