root/OpenSceneGraph/trunk/src/osgWrappers/serializers/osgAnimation/RigGeometry.cpp @ 13041

Revision 13041, 2.5 kB (checked in by robert, 2 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
Line 
1#include <osgAnimation/RigGeometry>
2#include <osgDB/ObjectWrapper>
3#include <osgDB/InputStream>
4#include <osgDB/OutputStream>
5
6static bool checkInfluenceMap( const osgAnimation::RigGeometry& geom )
7{
8    return geom.getInfluenceMap()->size()>0;
9}
10
11static bool readInfluenceMap( osgDB::InputStream& is, osgAnimation::RigGeometry& geom )
12{
13    osgAnimation::VertexInfluenceMap* map = new osgAnimation::VertexInfluenceMap;
14    unsigned int size = is.readSize(); is >> osgDB::BEGIN_BRACKET;
15    for ( unsigned int i=0; i<size; ++i )
16    {
17        std::string name;
18        unsigned int viSize = 0;
19        is >> osgDB::PROPERTY("VertexInfluence") >> name; viSize = is.readSize(); is >> osgDB::BEGIN_BRACKET;
20
21        osgAnimation::VertexInfluence vi;
22        vi.setName( name );
23        vi.reserve( viSize );
24        for ( unsigned int j=0; j<viSize; ++j )
25        {
26            int index = 0;
27            float weight = 0.0f;
28            is >> index >> weight;
29            vi.push_back( osgAnimation::VertexIndexWeight(index, weight) );
30        }
31        (*map)[name] = vi;
32        is >> osgDB::END_BRACKET;
33    }
34    is >> osgDB::END_BRACKET;
35
36    if ( !map->empty() ) geom.setInfluenceMap( map );
37    return true;
38}
39
40static bool writeInfluenceMap( osgDB::OutputStream& os, const osgAnimation::RigGeometry& geom )
41{
42    const osgAnimation::VertexInfluenceMap* map = geom.getInfluenceMap();
43    os.writeSize(map->size()); os << osgDB::BEGIN_BRACKET << std::endl;
44    for ( osgAnimation::VertexInfluenceMap::const_iterator itr=map->begin();
45          itr!=map->end(); ++itr )
46    {
47        std::string name = itr->first;
48        const osgAnimation::VertexInfluence& vi = itr->second;
49        if ( name.empty() ) name = "Empty";
50
51        os << osgDB::PROPERTY("VertexInfluence") << name; os.writeSize(vi.size()) ; os << osgDB::BEGIN_BRACKET << std::endl;
52
53        for ( osgAnimation::VertexInfluence::const_iterator vitr=vi.begin();
54              vitr != vi.end(); ++vitr )
55        {
56            os << vitr->first << vitr->second << std::endl;
57        }
58        os << osgDB::END_BRACKET << std::endl;
59    }
60    os << osgDB::END_BRACKET << std::endl;
61    return true;
62}
63
64REGISTER_OBJECT_WRAPPER( osgAnimation_RigGeometry,
65                         new osgAnimation::RigGeometry,
66                         osgAnimation::RigGeometry,
67                         "osg::Object osg::Drawable osg::Geometry osgAnimation::RigGeometry" )
68{
69    ADD_USER_SERIALIZER( InfluenceMap );  // _vertexInfluenceMap
70    ADD_OBJECT_SERIALIZER( SourceGeometry, osg::Geometry, NULL );  // _geometry
71}
Note: See TracBrowser for help on using the browser.