Hi,

Attached is Wang Rui's fix so the TerrainTileLoaded callback is called by the 
new serializers. I was sure I had tried exactly this code without luck but I 
guess it was late :  )

I have tested the fix and it works correctly. Thanks Wang Rui.

Cheers,

Brad

From: [email protected] 
[mailto:[email protected]] On Behalf Of Wang Rui
Sent: Friday, 25 June 2010 2:44 PM
To: OpenSceneGraph Users
Subject: Re: [osg-users] New osgTerrain serializer not calling 
TileLoadedCallback

Hi Brad,

A solution for serialziers to call static functions at the end of 
reading/writing is to use a user serializer. The 
serialziers/osgManipulator/Draggers.cpp uses a DefaultGeometry serializer to 
run setupDefaultGeometry() once the reading process is finished, and this can 
also be applied to load the TerrainTileCallback.

I've attached the modified serializer/osgTerrain/TerrainTile.cpp for tracing 
and solving current problem. But I'm a little busy today and have no time to 
compile OSG and VPB myself in time. Could you please test to see if it works 
and submit it to osg-submissions?

Thanks for improving the serializers and making it stronger all the time. :)

Wang Rui



2010/6/25 Christiansen, Brad 
<[email protected]<mailto:[email protected]>>
Hi,

Thanks Wang Rui. I am also on GMT +8 (Perth Australia) so yes, it is a little 
late :  )

I am still investigating the issue but it seems the previous problem yourself 
and Robert fixed in relation to the reading of .source file has re-appeared. I 
will post details if I can confirm the issue as well as having a look at the 
changes you made to solve the problem before.

Cheers,

Brad




DISCLAIMER:---------------------------------------------------------------------------
This e-mail transmission and any documents, files and previous e-mail messages
attached to it are private and confidential. They may contain proprietary or 
copyright
material or information that is subject to legal professional privilege. They 
are for
the use of the intended recipient only.  Any unauthorised viewing, use, 
disclosure,
copying, alteration, storage or distribution of, or reliance on, this message is
strictly prohibited. No part may be reproduced, adapted or transmitted without 
the
written permission of the owner. If you have received this transmission in 
error, or
are not an authorised recipient, please immediately notify the sender by return 
email,
delete this message and all copies from your e-mail system, and destroy any 
printed
copies. Receipt by anyone other than the intended recipient should not be 
deemed a
waiver of any privilege or protection. Thales Australia does not warrant or 
represent
that this e-mail or any documents, files and previous e-mail messages attached 
are
error or virus free.
--------------------------------------------------------------------------------------

#include <osgTerrain/TerrainTile>
#include <osgDB/ObjectWrapper>
#include <osgDB/InputStream>
#include <osgDB/OutputStream>

// _tileID
static bool checkTileID( const osgTerrain::TerrainTile& tile )
{
    return tile.getTileID().valid();
}

static bool readTileID( osgDB::InputStream& is, osgTerrain::TerrainTile& tile )
{
    osgTerrain::TileID id;
    is >> id.level >> id.x >> id.y;
    tile.setTileID( id );
    return true;
}

static bool writeTileID( osgDB::OutputStream& os, const 
osgTerrain::TerrainTile& tile )
{
    const osgTerrain::TileID& id = tile.getTileID();
    os << id.level << id.x << id.y << std::endl;
    return true;
}

// _colorLayers
static bool checkColorLayers( const osgTerrain::TerrainTile& tile )
{
    return tile.getNumColorLayers()>0;
}

static bool readColorLayers( osgDB::InputStream& is, osgTerrain::TerrainTile& 
tile )
{
    unsigned int numValidLayers = 0; is >> numValidLayers >> 
osgDB::BEGIN_BRACKET;
    for ( unsigned int i=0; i<numValidLayers; ++i )
    {
        unsigned int layerNum=0; is >> osgDB::PROPERTY("Layer") >> layerNum;
        osgTerrain::Layer* layer = dynamic_cast<osgTerrain::Layer*>( 
is.readObject() );
        if ( layer ) tile.setColorLayer( layerNum, layer );
    }
    is >> osgDB::END_BRACKET;
    return true;
}

static bool writeColorLayers( osgDB::OutputStream& os, const 
osgTerrain::TerrainTile& tile )
{
    unsigned int numValidLayers = 0;
    for ( unsigned int i=0; i<tile.getNumColorLayers(); ++i )
    {
        if (tile.getColorLayer(i)) ++numValidLayers;
    }

    os << numValidLayers << osgDB::BEGIN_BRACKET << std::endl;
    for ( unsigned int i=0; i<tile.getNumColorLayers(); ++i )
    {
        if (tile.getColorLayer(i)) os << osgDB::PROPERTY("Layer") << i << 
tile.getColorLayer(i);
    }
    os << osgDB::END_BRACKET << std::endl;
    return true;
}

// TileLoadedCallback
static bool checkTileLoadedCallback( const osgTerrain::TerrainTile& tile )
{ return true; }

static bool readTileLoadedCallback( osgDB::InputStream& is, 
osgTerrain::TerrainTile& tile )
{
    if ( osgTerrain::TerrainTile::getTileLoadedCallback().valid() ) 
        osgTerrain::TerrainTile::getTileLoadedCallback()->loaded( &terrainTile, 
is.getOptions() );
    return true;
}

static bool writeTileLoadedCallback( osgDB::OutputStream& os, const 
osgTerrain::TerrainTile& tile )
{ return true; }

REGISTER_OBJECT_WRAPPER( osgTerrain_TerrainTile,
                         new osgTerrain::TerrainTile,
                         osgTerrain::TerrainTile,
                         "osg::Object osg::Node osg::Group 
osgTerrain::TerrainTile" )
{
    ADD_USER_SERIALIZER( TileID );  // _tileID
    ADD_OBJECT_SERIALIZER( TerrainTechnique, osgTerrain::TerrainTechnique, NULL 
);  // _terrainTechnique
    ADD_OBJECT_SERIALIZER( Locator, osgTerrain::Locator, NULL );  // _locator
    ADD_OBJECT_SERIALIZER( ElevationLayer, osgTerrain::Layer, NULL );  // 
_elevationLayer
    ADD_USER_SERIALIZER( ColorLayers );  // _colorLayers
    ADD_BOOL_SERIALIZER( RequiresNormals, true );  // _requiresNormals
    ADD_BOOL_SERIALIZER( TreatBoundariesToValidDataAsDefaultValue, false );  // 
_treatBoundariesToValidDataAsDefaultValue
    BEGIN_ENUM_SERIALIZER( BlendingPolicy, INHERIT );
        ADD_ENUM_VALUE( INHERIT );
        ADD_ENUM_VALUE( DO_NOT_SET_BLENDING );
        ADD_ENUM_VALUE( ENABLE_BLENDING );
        ADD_ENUM_VALUE( ENABLE_BLENDING_WHEN_ALPHA_PRESENT );
    END_ENUM_SERIALIZER();  // BlendingPolicy
    
    ADD_USER_SERIALIZER( TileLoadedCallback );
}
_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org

Reply via email to