| 1 | #include <osgSim/LightPointNode> |
|---|
| 2 | #include <osgDB/ObjectWrapper> |
|---|
| 3 | #include <osgDB/InputStream> |
|---|
| 4 | #include <osgDB/OutputStream> |
|---|
| 5 | |
|---|
| 6 | static bool checkLightPointList( const osgSim::LightPointNode& node ) |
|---|
| 7 | { |
|---|
| 8 | return node.getNumLightPoints()>0; |
|---|
| 9 | } |
|---|
| 10 | |
|---|
| 11 | static bool readLightPointList( osgDB::InputStream& is, osgSim::LightPointNode& node ) |
|---|
| 12 | { |
|---|
| 13 | unsigned int size = 0; is >> size >> osgDB::BEGIN_BRACKET; |
|---|
| 14 | for ( unsigned int i=0; i<size; ++i ) |
|---|
| 15 | { |
|---|
| 16 | osgSim::LightPoint pt; |
|---|
| 17 | is >> osgDB::PROPERTY("LightPoint") >> osgDB::BEGIN_BRACKET; |
|---|
| 18 | is >> osgDB::PROPERTY("Position") >> pt._position; |
|---|
| 19 | is >> osgDB::PROPERTY("Color") >> pt._color; |
|---|
| 20 | |
|---|
| 21 | int blendingMode = 0; |
|---|
| 22 | is >> osgDB::PROPERTY("Attributes") >> pt._on >> blendingMode >> pt._intensity >> pt._radius; |
|---|
| 23 | pt._blendingMode = (osgSim::LightPoint::BlendingMode)blendingMode; |
|---|
| 24 | |
|---|
| 25 | bool hasObject = false; is >> osgDB::PROPERTY("Sector") >> hasObject; |
|---|
| 26 | if ( hasObject ) |
|---|
| 27 | { |
|---|
| 28 | is >> osgDB::BEGIN_BRACKET; |
|---|
| 29 | pt._sector = dynamic_cast<osgSim::Sector*>( is.readObject() ); |
|---|
| 30 | is >> osgDB::END_BRACKET; |
|---|
| 31 | } |
|---|
| 32 | hasObject = false; is >> osgDB::PROPERTY("BlinkSequence") >> hasObject; |
|---|
| 33 | if ( hasObject ) |
|---|
| 34 | { |
|---|
| 35 | is >> osgDB::BEGIN_BRACKET; |
|---|
| 36 | pt._blinkSequence = dynamic_cast<osgSim::BlinkSequence*>( is.readObject() ); |
|---|
| 37 | is >> osgDB::END_BRACKET; |
|---|
| 38 | } |
|---|
| 39 | is >> osgDB::END_BRACKET; |
|---|
| 40 | node.addLightPoint( pt ); |
|---|
| 41 | } |
|---|
| 42 | is >> osgDB::END_BRACKET; |
|---|
| 43 | return true; |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | static bool writeLightPointList( osgDB::OutputStream& os, const osgSim::LightPointNode& node ) |
|---|
| 47 | { |
|---|
| 48 | unsigned int size = node.getNumLightPoints(); |
|---|
| 49 | os << size << osgDB::BEGIN_BRACKET << std::endl; |
|---|
| 50 | for ( unsigned int i=0; i<size; ++i ) |
|---|
| 51 | { |
|---|
| 52 | const osgSim::LightPoint& pt = node.getLightPoint(i); |
|---|
| 53 | os << osgDB::PROPERTY("LightPoint") << osgDB::BEGIN_BRACKET << std::endl; |
|---|
| 54 | os << osgDB::PROPERTY("Position") << pt._position << std::endl; |
|---|
| 55 | os << osgDB::PROPERTY("Color") << pt._color << std::endl; |
|---|
| 56 | os << osgDB::PROPERTY("Attributes") << pt._on << (int)pt._blendingMode |
|---|
| 57 | << pt._intensity << pt._radius << std::endl; |
|---|
| 58 | os << osgDB::PROPERTY("Sector") << (pt._sector!=NULL); |
|---|
| 59 | if ( pt._sector!=NULL ) |
|---|
| 60 | { |
|---|
| 61 | os << osgDB::BEGIN_BRACKET << std::endl; |
|---|
| 62 | os.writeObject( pt._sector.get() ); |
|---|
| 63 | os << osgDB::END_BRACKET << std::endl; |
|---|
| 64 | } |
|---|
| 65 | os << osgDB::PROPERTY("BlinkSequence") << (pt._blinkSequence!=NULL); |
|---|
| 66 | if ( pt._blinkSequence!=NULL ) |
|---|
| 67 | { |
|---|
| 68 | os << osgDB::BEGIN_BRACKET << std::endl; |
|---|
| 69 | os.writeObject( pt._blinkSequence.get() ); |
|---|
| 70 | os << osgDB::END_BRACKET << std::endl; |
|---|
| 71 | } |
|---|
| 72 | os << osgDB::END_BRACKET << std::endl; |
|---|
| 73 | } |
|---|
| 74 | os << osgDB::END_BRACKET << std::endl; |
|---|
| 75 | return true; |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | REGISTER_OBJECT_WRAPPER( osgSim_LightPointNode, |
|---|
| 79 | new osgSim::LightPointNode, |
|---|
| 80 | osgSim::LightPointNode, |
|---|
| 81 | "osg::Object osg::Node osgSim::LightPointNode" ) |
|---|
| 82 | { |
|---|
| 83 | ADD_USER_SERIALIZER( LightPointList ); |
|---|
| 84 | ADD_FLOAT_SERIALIZER( MinPixelSize, 0.0f ); |
|---|
| 85 | ADD_FLOAT_SERIALIZER( MaxPixelSize, 30.0f ); |
|---|
| 86 | ADD_FLOAT_SERIALIZER( MaxVisibleDistance2, FLT_MAX ); |
|---|
| 87 | ADD_OBJECT_SERIALIZER( LightPointSystem, osgSim::LightPointSystem, NULL ); |
|---|
| 88 | ADD_BOOL_SERIALIZER( PointSprite, false ); |
|---|
| 89 | } |
|---|