| 1 | #include <osg/Shape> |
|---|
| 2 | #include <osgDB/ObjectWrapper> |
|---|
| 3 | #include <osgDB/InputStream> |
|---|
| 4 | #include <osgDB/OutputStream> |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | static bool checkArea( const osg::HeightField& shape ) |
|---|
| 8 | { |
|---|
| 9 | return true; |
|---|
| 10 | } |
|---|
| 11 | |
|---|
| 12 | static bool readArea( osgDB::InputStream& is, osg::HeightField& shape ) |
|---|
| 13 | { |
|---|
| 14 | unsigned int numCols, numRows; |
|---|
| 15 | is >> numCols >> numRows; |
|---|
| 16 | shape.allocate( numCols, numRows ); |
|---|
| 17 | return true; |
|---|
| 18 | } |
|---|
| 19 | |
|---|
| 20 | static bool writeArea( osgDB::OutputStream& os, const osg::HeightField& shape ) |
|---|
| 21 | { |
|---|
| 22 | os << shape.getNumColumns() << shape.getNumRows() << std::endl; |
|---|
| 23 | return true; |
|---|
| 24 | } |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | static bool checkHeights( const osg::HeightField& shape ) |
|---|
| 28 | { |
|---|
| 29 | return shape.getFloatArray()!=NULL; |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | static bool readHeights( osgDB::InputStream& is, osg::HeightField& shape ) |
|---|
| 33 | { |
|---|
| 34 | osg::FloatArray* array = dynamic_cast<osg::FloatArray*>( is.readArray() ); |
|---|
| 35 | if ( array ) |
|---|
| 36 | { |
|---|
| 37 | unsigned int numCols = shape.getNumColumns(), numRows = shape.getNumRows(); |
|---|
| 38 | if ( array->size()<numRows*numCols ) return false; |
|---|
| 39 | |
|---|
| 40 | unsigned int index = 0; |
|---|
| 41 | for ( unsigned int r=0; r<numRows; ++r ) |
|---|
| 42 | { |
|---|
| 43 | for ( unsigned int c=0; c<numCols; ++c ) |
|---|
| 44 | shape.setHeight( c, r, (*array)[index++] ); |
|---|
| 45 | } |
|---|
| 46 | } |
|---|
| 47 | return true; |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | static bool writeHeights( osgDB::OutputStream& os, const osg::HeightField& shape ) |
|---|
| 51 | { |
|---|
| 52 | os.writeArray( shape.getFloatArray() ); |
|---|
| 53 | return true; |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | REGISTER_OBJECT_WRAPPER( HeightField, |
|---|
| 57 | new osg::HeightField, |
|---|
| 58 | osg::HeightField, |
|---|
| 59 | "osg::Object osg::Shape osg::HeightField" ) |
|---|
| 60 | { |
|---|
| 61 | ADD_USER_SERIALIZER( Area ); |
|---|
| 62 | ADD_VEC3_SERIALIZER( Origin, osg::Vec3() ); |
|---|
| 63 | ADD_FLOAT_SERIALIZER( XInterval, 0.0f ); |
|---|
| 64 | ADD_FLOAT_SERIALIZER( YInterval, 0.0f ); |
|---|
| 65 | ADD_FLOAT_SERIALIZER( SkirtHeight, 0.0f ); |
|---|
| 66 | ADD_UINT_SERIALIZER( BorderWidth, 0 ); |
|---|
| 67 | ADD_QUAT_SERIALIZER( Rotation, osg::Quat() ); |
|---|
| 68 | ADD_USER_SERIALIZER( Heights ); |
|---|
| 69 | } |
|---|