root/OpenSceneGraph/trunk/src/osgWrappers/serializers/osgTerrain/TerrainTile.cpp @ 13041

Revision 13041, 3.6 kB (checked in by robert, 3 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
Line 
1#include <osgTerrain/TerrainTile>
2#include <osgDB/ObjectWrapper>
3#include <osgDB/InputStream>
4#include <osgDB/OutputStream>
5
6// _tileID
7static bool checkTileID( const osgTerrain::TerrainTile& tile )
8{
9    return tile.getTileID().valid();
10}
11
12static bool readTileID( osgDB::InputStream& is, osgTerrain::TerrainTile& tile )
13{
14    osgTerrain::TileID id;
15    is >> id.level >> id.x >> id.y;
16    tile.setTileID( id );
17    return true;
18}
19
20static bool writeTileID( osgDB::OutputStream& os, const osgTerrain::TerrainTile& tile )
21{
22    const osgTerrain::TileID& id = tile.getTileID();
23    os << id.level << id.x << id.y << std::endl;
24    return true;
25}
26
27// _colorLayers
28static bool checkColorLayers( const osgTerrain::TerrainTile& tile )
29{
30    return tile.getNumColorLayers()>0;
31}
32
33static bool readColorLayers( osgDB::InputStream& is, osgTerrain::TerrainTile& tile )
34{
35    unsigned int numValidLayers = 0; is >> numValidLayers >> osgDB::BEGIN_BRACKET;
36    for ( unsigned int i=0; i<numValidLayers; ++i )
37    {
38        unsigned int layerNum=0; is >> osgDB::PROPERTY("Layer") >> layerNum;
39        osgTerrain::Layer* layer = dynamic_cast<osgTerrain::Layer*>( is.readObject() );
40        if ( layer ) tile.setColorLayer( layerNum, layer );
41    }
42    is >> osgDB::END_BRACKET;
43    return true;
44}
45
46static bool writeColorLayers( osgDB::OutputStream& os, const osgTerrain::TerrainTile& tile )
47{
48    unsigned int numValidLayers = 0;
49    for ( unsigned int i=0; i<tile.getNumColorLayers(); ++i )
50    {
51        if (tile.getColorLayer(i)) ++numValidLayers;
52    }
53
54    os << numValidLayers << osgDB::BEGIN_BRACKET << std::endl;
55    for ( unsigned int i=0; i<tile.getNumColorLayers(); ++i )
56    {
57        if (tile.getColorLayer(i)) os << osgDB::PROPERTY("Layer") << i << tile.getColorLayer(i);
58    }
59    os << osgDB::END_BRACKET << std::endl;
60    return true;
61}
62
63struct TerrainTileFinishedObjectReadCallback : public osgDB::FinishedObjectReadCallback
64{
65    virtual void objectRead(osgDB::InputStream& is, osg::Object& obj)
66    {
67        osgTerrain::TerrainTile& tile = static_cast<osgTerrain::TerrainTile&>(obj);
68
69        if (is.getOptions())
70        {
71            osg::ref_ptr<osg::Node> node;
72            if (is.getOptions()->getTerrain().lock(node))
73            {
74                tile.setTerrain(node->asTerrain());
75            }
76        }
77
78        if ( osgTerrain::TerrainTile::getTileLoadedCallback().valid() )
79            osgTerrain::TerrainTile::getTileLoadedCallback()->loaded( &tile, is.getOptions() );
80        }
81};
82
83
84REGISTER_OBJECT_WRAPPER( osgTerrain_TerrainTile,
85                         new osgTerrain::TerrainTile,
86                         osgTerrain::TerrainTile,
87                         "osg::Object osg::Node osg::Group osgTerrain::TerrainTile" )
88{
89    ADD_USER_SERIALIZER( TileID );  // _tileID
90    ADD_OBJECT_SERIALIZER( TerrainTechnique, osgTerrain::TerrainTechnique, NULL );  // _terrainTechnique
91    ADD_OBJECT_SERIALIZER( Locator, osgTerrain::Locator, NULL );  // _locator
92    ADD_OBJECT_SERIALIZER( ElevationLayer, osgTerrain::Layer, NULL );  // _elevationLayer
93    ADD_USER_SERIALIZER( ColorLayers );  // _colorLayers
94    ADD_BOOL_SERIALIZER( RequiresNormals, true );  // _requiresNormals
95    ADD_BOOL_SERIALIZER( TreatBoundariesToValidDataAsDefaultValue, false );  // _treatBoundariesToValidDataAsDefaultValue
96    BEGIN_ENUM_SERIALIZER( BlendingPolicy, INHERIT );
97        ADD_ENUM_VALUE( INHERIT );
98        ADD_ENUM_VALUE( DO_NOT_SET_BLENDING );
99        ADD_ENUM_VALUE( ENABLE_BLENDING );
100        ADD_ENUM_VALUE( ENABLE_BLENDING_WHEN_ALPHA_PRESENT );
101    END_ENUM_SERIALIZER();  // BlendingPolicy
102
103    wrapper->addFinishedObjectReadCallback( new TerrainTileFinishedObjectReadCallback() );
104}
Note: See TracBrowser for help on using the browser.