| 1 | #include <osgAnimation/MorphGeometry> |
|---|
| 2 | #include <osgDB/ObjectWrapper> |
|---|
| 3 | #include <osgDB/InputStream> |
|---|
| 4 | #include <osgDB/OutputStream> |
|---|
| 5 | |
|---|
| 6 | static bool checkMorphTargets( const osgAnimation::MorphGeometry& geom ) |
|---|
| 7 | { |
|---|
| 8 | return geom.getMorphTargetList().size()>0; |
|---|
| 9 | } |
|---|
| 10 | |
|---|
| 11 | static bool readMorphTargets( osgDB::InputStream& is, osgAnimation::MorphGeometry& geom ) |
|---|
| 12 | { |
|---|
| 13 | unsigned int size = is.readSize(); is >> osgDB::BEGIN_BRACKET; |
|---|
| 14 | for ( unsigned int i=0; i<size; ++i ) |
|---|
| 15 | { |
|---|
| 16 | float weight = 0.0f; |
|---|
| 17 | is >> osgDB::PROPERTY("MorphTarget") >> weight; |
|---|
| 18 | osg::Geometry* target = dynamic_cast<osg::Geometry*>( is.readObject() ); |
|---|
| 19 | if ( target ) geom.addMorphTarget( target, weight ); |
|---|
| 20 | } |
|---|
| 21 | is >> osgDB::END_BRACKET; |
|---|
| 22 | return true; |
|---|
| 23 | } |
|---|
| 24 | |
|---|
| 25 | static bool writeMorphTargets( osgDB::OutputStream& os, const osgAnimation::MorphGeometry& geom ) |
|---|
| 26 | { |
|---|
| 27 | const osgAnimation::MorphGeometry::MorphTargetList& targets = geom.getMorphTargetList(); |
|---|
| 28 | os.writeSize(targets.size()); os << osgDB::BEGIN_BRACKET << std::endl; |
|---|
| 29 | for ( osgAnimation::MorphGeometry::MorphTargetList::const_iterator itr=targets.begin(); |
|---|
| 30 | itr!=targets.end(); ++itr ) |
|---|
| 31 | { |
|---|
| 32 | os << osgDB::PROPERTY("MorphTarget") << itr->getWeight() << std::endl; |
|---|
| 33 | os << itr->getGeometry(); |
|---|
| 34 | } |
|---|
| 35 | os << osgDB::END_BRACKET << std::endl; |
|---|
| 36 | return true; |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | REGISTER_OBJECT_WRAPPER( osgAnimation_MorphGeometry, |
|---|
| 40 | new osgAnimation::MorphGeometry, |
|---|
| 41 | osgAnimation::MorphGeometry, |
|---|
| 42 | "osg::Object osg::Drawable osg::Geometry osgAnimation::MorphGeometry" ) |
|---|
| 43 | { |
|---|
| 44 | BEGIN_ENUM_SERIALIZER( Method, NORMALIZED ); |
|---|
| 45 | ADD_ENUM_VALUE( NORMALIZED ); |
|---|
| 46 | ADD_ENUM_VALUE( RELATIVE ); |
|---|
| 47 | END_ENUM_SERIALIZER(); |
|---|
| 48 | |
|---|
| 49 | ADD_USER_SERIALIZER( MorphTargets ); |
|---|
| 50 | ADD_BOOL_SERIALIZER( MorphNormals, true ); |
|---|
| 51 | } |
|---|