Updated various serialization support for .osg, .osgt/b/x and .ive.

This commit is contained in:
Robert Osfield 2010-03-16 18:44:27 +00:00
parent c4e82f0221
commit d5aea9c0f2
8 changed files with 88 additions and 1 deletions

View File

@ -862,9 +862,18 @@ public:
osg::ref_ptr<MySerializer> serializer = new MySerializer( \
#PROP, MyClass::DEF, &MyClass::get##PROP, &MyClass::set##PROP)
#define BEGIN_ENUM_SERIALIZER4(PROPERTIES_CLASS, PROP, DEF) \
{ typedef osgDB::EnumSerializer<MyClass, PROPERTIES_CLASS::PROP, void> MySerializer; \
osg::ref_ptr<MySerializer> serializer = new MySerializer( \
#PROP, PROPERTIES_CLASS::DEF, &MyClass::get##PROP, &MyClass::set##PROP)
#define ADD_ENUM_VALUE(VALUE) \
serializer->add(#VALUE, MyClass::VALUE)
#define ADD_ENUM_CLASS_VALUE(CLASS, VALUE) \
serializer->add(#VALUE, CLASS::VALUE)
#define END_ENUM_SERIALIZER() \
wrapper->addSerializer(serializer.get()); }

View File

@ -52,8 +52,9 @@
#define VERSION_0041 41
#define VERSION_0042 42
#define VERSION_0043 43
#define VERSION_0044 44
#define VERSION VERSION_0043
#define VERSION VERSION_0044
/* The BYTE_SEX tag is used to check the endian
of the IVE file being read in. The IVE format

View File

@ -31,6 +31,11 @@ void TerrainTile::write(DataOutputStream* out)
else
out_THROW_EXCEPTION("Terrain::write(): Could not cast this osgTerrain::Terrain to an osg::Group.");
if (out->getVersion() >= VERSION_0044)
{
out->writeInt(getBlendingPolicy());
}
if (out->getVersion() >= VERSION_0026)
{
out->writeInt(getTileID().level);
@ -84,6 +89,11 @@ void TerrainTile::read(DataInputStream* in)
else
in_THROW_EXCEPTION("Terrain::read(): Could not cast this osgTerrain::Terrain to an osg::Group.");
if (in->getVersion() >= VERSION_0044)
{
setBlendingPolicy(static_cast<osgTerrain::TerrainTile::BlendingPolicy>(in->readInt()));
}
if (in->getVersion() >= VERSION_0026)
{

View File

@ -28,6 +28,15 @@ bool Terrain_readLocalData(osg::Object& obj, osgDB::Input& fr)
if (fr.read("SampleRatio",value)) terrain.setSampleRatio(value);
if (fr.read("VerticalScale",value)) terrain.setVerticalScale(value);
std::string blendingPolicy;
if (fr.read("BlendingPolicy",blendingPolicy))
{
if (blendingPolicy == "INHERIT") terrain.setBlendingPolicy(osgTerrain::TerrainTile::INHERIT);
else if (blendingPolicy == "DO_NOT_SET_BLENDING") terrain.setBlendingPolicy(osgTerrain::TerrainTile::DO_NOT_SET_BLENDING);
else if (blendingPolicy == "ENABLE_BLENDING") terrain.setBlendingPolicy(osgTerrain::TerrainTile::ENABLE_BLENDING);
else if (blendingPolicy == "ENABLE_BLENDING_WHEN_ALPHA_PRESENT") terrain.setBlendingPolicy(osgTerrain::TerrainTile::ENABLE_BLENDING_WHEN_ALPHA_PRESENT);
}
return iteratorAdvanced;
}
@ -38,5 +47,13 @@ bool Terrain_writeLocalData(const osg::Object& obj, osgDB::Output& fw)
fw.indent()<<"SampleRatio "<<terrain.getSampleRatio()<<std::endl;
fw.indent()<<"VerticalScale "<<terrain.getVerticalScale()<<std::endl;
switch(terrain.getBlendingPolicy())
{
case(osgTerrain::TerrainTile::INHERIT): fw.indent()<<"BlendingPolicy INHERIT"<<std::endl; break;
case(osgTerrain::TerrainTile::DO_NOT_SET_BLENDING): fw.indent()<<"BlendingPolicy DO_NOT_SET_BLENDING"<<std::endl; break;
case(osgTerrain::TerrainTile::ENABLE_BLENDING): fw.indent()<<"BlendingPolicy ENABLE_BLENDING"<<std::endl; break;
case(osgTerrain::TerrainTile::ENABLE_BLENDING_WHEN_ALPHA_PRESENT): fw.indent()<<"BlendingPolicy ENABLE_BLENDING_WHEN_ALPHA_PRESENT"<<std::endl; break;
}
return true;
}

View File

@ -34,6 +34,15 @@ bool TerrainTile_readLocalData(osg::Object& obj, osgDB::Input &fr)
osg::ref_ptr<osg::Object> readObject = fr.readObjectOfType(osgDB::type_wrapper<osgTerrain::Locator>());
if (readObject.valid()) itrAdvanced = true;
std::string blendingPolicy;
if (fr.read("BlendingPolicy",blendingPolicy))
{
if (blendingPolicy == "INHERIT") terrainTile.setBlendingPolicy(osgTerrain::TerrainTile::INHERIT);
else if (blendingPolicy == "DO_NOT_SET_BLENDING") terrainTile.setBlendingPolicy(osgTerrain::TerrainTile::DO_NOT_SET_BLENDING);
else if (blendingPolicy == "ENABLE_BLENDING") terrainTile.setBlendingPolicy(osgTerrain::TerrainTile::ENABLE_BLENDING);
else if (blendingPolicy == "ENABLE_BLENDING_WHEN_ALPHA_PRESENT") terrainTile.setBlendingPolicy(osgTerrain::TerrainTile::ENABLE_BLENDING_WHEN_ALPHA_PRESENT);
}
osgTerrain::Locator* locator = dynamic_cast<osgTerrain::Locator*>(readObject.get());
if (locator) terrainTile.setLocator(locator);
@ -193,6 +202,14 @@ bool TerrainTile_writeLocalData(const osg::Object& obj, osgDB::Output& fw)
int prec = fw.precision();
fw.precision(15);
switch(terrainTile.getBlendingPolicy())
{
case(osgTerrain::TerrainTile::INHERIT): fw.indent()<<"BlendingPolicy INHERIT"<<std::endl; break;
case(osgTerrain::TerrainTile::DO_NOT_SET_BLENDING): fw.indent()<<"BlendingPolicy DO_NOT_SET_BLENDING"<<std::endl; break;
case(osgTerrain::TerrainTile::ENABLE_BLENDING): fw.indent()<<"BlendingPolicy ENABLE_BLENDING"<<std::endl; break;
case(osgTerrain::TerrainTile::ENABLE_BLENDING_WHEN_ALPHA_PRESENT): fw.indent()<<"BlendingPolicy ENABLE_BLENDING_WHEN_ALPHA_PRESENT"<<std::endl; break;
}
if (terrainTile.getLocator())
{
fw.writeObject(*terrainTile.getLocator());

View File

@ -30,6 +30,13 @@
#undef OUT
#endif
BEGIN_ENUM_REFLECTOR(osgTerrain::TerrainTile::BlendingPolicy)
I_DeclaringFile("osgTerrain/TerrainTile");
I_EnumLabel(osgTerrain::TerrainTile::DO_NOT_SET_BLENDING);
I_EnumLabel(osgTerrain::TerrainTile::ENABLE_BLENDING);
I_EnumLabel(osgTerrain::TerrainTile::ENABLE_BLENDING_WHEN_ALPHA_PRESENT);
END_REFLECTOR
BEGIN_OBJECT_REFLECTOR(osgTerrain::TerrainTile)
I_DeclaringFile("osgTerrain/TerrainTile");
I_BaseType(osg::Group);
@ -190,6 +197,16 @@ BEGIN_OBJECT_REFLECTOR(osgTerrain::TerrainTile)
__bool__getTreatBoundariesToValidDataAsDefaultValue,
"Get whether the TeatBoundariesToValidDataAsDefaultValue hint. ",
"");
I_Method1(void, setBlendingPolicy, IN, osgTerrain::TerrainTile::BlendingPolicy, policy,
Properties::NON_VIRTUAL,
__void__setBlendingPolicy__BlendingPolicy,
"Set the policy to use when deciding whether to enable/disable blending and use of transparent bin. ",
"");
I_Method0(osgTerrain::TerrainTile::BlendingPolicy, getBlendingPolicy,
Properties::NON_VIRTUAL,
__BlendingPolicy__getBlendingPolicy,
"Get the policy to use when deciding whether to enable/disable blending and use of transparent bin. ",
"");
I_Method1(void, setDirty, IN, bool, dirty,
Properties::NON_VIRTUAL,
__void__setDirty__bool,
@ -218,6 +235,9 @@ BEGIN_OBJECT_REFLECTOR(osgTerrain::TerrainTile)
__osg_ref_ptrT1_TileLoadedCallback__R1__getTileLoadedCallback_S,
"",
"");
I_SimpleProperty(osgTerrain::TerrainTile::BlendingPolicy, BlendingPolicy,
__BlendingPolicy__getBlendingPolicy,
__void__setBlendingPolicy__BlendingPolicy);
I_ArrayProperty(osgTerrain::Layer *, ColorLayer,
__Layer_P1__getColorLayer__unsigned_int,
__void__setColorLayer__unsigned_int__Layer_P1,

View File

@ -10,4 +10,11 @@ REGISTER_OBJECT_WRAPPER( osgTerrain_Terrain,
{
ADD_FLOAT_SERIALIZER( SampleRatio, 1.0f ); // _sampleRatio
ADD_FLOAT_SERIALIZER( VerticalScale, 1.0f ); // _verticalScale
BEGIN_ENUM_SERIALIZER4( osgTerrain::TerrainTile, BlendingPolicy, INHERIT );
ADD_ENUM_CLASS_VALUE( osgTerrain::TerrainTile, INHERIT );
ADD_ENUM_CLASS_VALUE( osgTerrain::TerrainTile, DO_NOT_SET_BLENDING );
ADD_ENUM_CLASS_VALUE( osgTerrain::TerrainTile, ENABLE_BLENDING );
ADD_ENUM_CLASS_VALUE( osgTerrain::TerrainTile, ENABLE_BLENDING_WHEN_ALPHA_PRESENT );
END_ENUM_SERIALIZER(); // BlendingPolicy
}

View File

@ -66,4 +66,10 @@ REGISTER_OBJECT_WRAPPER( osgTerrain_TerrainTile,
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
}