| 1 | #include <osg/Shape> |
|---|
| 2 | #include <osg/Notify> |
|---|
| 3 | #include <osg/io_utils> |
|---|
| 4 | |
|---|
| 5 | #include <osgDB/Registry> |
|---|
| 6 | #include <osgDB/Input> |
|---|
| 7 | #include <osgDB/ParameterOutput> |
|---|
| 8 | |
|---|
| 9 | using namespace osg; |
|---|
| 10 | using namespace osgDB; |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | bool HeightField_readLocalData(Object& obj, Input& fr); |
|---|
| 16 | bool HeightField_writeLocalData(const Object& obj, Output& fw); |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | REGISTER_DOTOSGWRAPPER(HeightField) |
|---|
| 20 | ( |
|---|
| 21 | new osg::HeightField, |
|---|
| 22 | "HeightField", |
|---|
| 23 | "Object HeightField", |
|---|
| 24 | &HeightField_readLocalData, |
|---|
| 25 | &HeightField_writeLocalData, |
|---|
| 26 | DotOsgWrapper::READ_AND_WRITE |
|---|
| 27 | ); |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | REGISTER_DOTOSGWRAPPER(Grid) |
|---|
| 31 | ( |
|---|
| 32 | new osg::HeightField, |
|---|
| 33 | "Grid", |
|---|
| 34 | "Object HeightField", |
|---|
| 35 | 0, |
|---|
| 36 | 0, |
|---|
| 37 | DotOsgWrapper::READ_AND_WRITE |
|---|
| 38 | ); |
|---|
| 39 | |
|---|
| 40 | bool HeightField_readLocalData(Object& obj, Input& fr) |
|---|
| 41 | { |
|---|
| 42 | bool iteratorAdvanced = false; |
|---|
| 43 | |
|---|
| 44 | HeightField& heightfield = static_cast<HeightField&>(obj); |
|---|
| 45 | |
|---|
| 46 | if (fr.matchSequence("Origin %f %f %f")) |
|---|
| 47 | { |
|---|
| 48 | osg::Vec3 origin; |
|---|
| 49 | fr[1].getFloat(origin.x()); |
|---|
| 50 | fr[2].getFloat(origin.y()); |
|---|
| 51 | fr[3].getFloat(origin.z()); |
|---|
| 52 | heightfield.setOrigin(origin); |
|---|
| 53 | fr+=4; |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | if (fr.matchSequence("XInterval %f")) |
|---|
| 57 | { |
|---|
| 58 | float interval; |
|---|
| 59 | fr[1].getFloat(interval); |
|---|
| 60 | heightfield.setXInterval(interval); |
|---|
| 61 | fr+=2; |
|---|
| 62 | iteratorAdvanced = true; |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | if (fr.matchSequence("YInterval %f")) |
|---|
| 66 | { |
|---|
| 67 | float interval; |
|---|
| 68 | fr[1].getFloat(interval); |
|---|
| 69 | heightfield.setYInterval(interval); |
|---|
| 70 | fr+=2; |
|---|
| 71 | iteratorAdvanced = true; |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | if (fr.matchSequence("SkirtHeight %f")) |
|---|
| 75 | { |
|---|
| 76 | float height; |
|---|
| 77 | fr[1].getFloat(height); |
|---|
| 78 | heightfield.setSkirtHeight(height); |
|---|
| 79 | fr+=2; |
|---|
| 80 | iteratorAdvanced = true; |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | if (fr.matchSequence("BorderWidth %i")) |
|---|
| 84 | { |
|---|
| 85 | unsigned int width; |
|---|
| 86 | fr[1].getUInt(width); |
|---|
| 87 | heightfield.setBorderWidth(width); |
|---|
| 88 | fr+=2; |
|---|
| 89 | iteratorAdvanced = true; |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | if (fr.matchSequence("Rotation %f %f %f %f")) |
|---|
| 93 | { |
|---|
| 94 | osg::Quat rotation; |
|---|
| 95 | fr[1].getFloat(rotation.x()); |
|---|
| 96 | fr[2].getFloat(rotation.y()); |
|---|
| 97 | fr[3].getFloat(rotation.z()); |
|---|
| 98 | fr[4].getFloat(rotation.w()); |
|---|
| 99 | heightfield.setRotation(rotation); |
|---|
| 100 | fr+=5; |
|---|
| 101 | iteratorAdvanced = true; |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | if (fr.matchSequence("NumColumnsAndRows %i %i")) |
|---|
| 105 | { |
|---|
| 106 | int numcolumns,numrows; |
|---|
| 107 | fr[1].getInt(numcolumns); |
|---|
| 108 | fr[2].getInt(numrows); |
|---|
| 109 | heightfield.allocate(numcolumns,numrows); |
|---|
| 110 | fr+=3; |
|---|
| 111 | iteratorAdvanced = true; |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | if (fr.matchSequence("Heights {")) |
|---|
| 115 | { |
|---|
| 116 | |
|---|
| 117 | int entry = fr[0].getNoNestedBrackets(); |
|---|
| 118 | |
|---|
| 119 | fr += 2; |
|---|
| 120 | |
|---|
| 121 | float height; |
|---|
| 122 | unsigned int row = 0; |
|---|
| 123 | unsigned int column = 0; |
|---|
| 124 | |
|---|
| 125 | while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) |
|---|
| 126 | { |
|---|
| 127 | if (fr.readSequence(height)) |
|---|
| 128 | { |
|---|
| 129 | heightfield.setHeight(column,row,height); |
|---|
| 130 | ++column; |
|---|
| 131 | if (column>=heightfield.getNumColumns()) |
|---|
| 132 | { |
|---|
| 133 | column = 0; |
|---|
| 134 | ++row; |
|---|
| 135 | } |
|---|
| 136 | } |
|---|
| 137 | else |
|---|
| 138 | { |
|---|
| 139 | ++fr; |
|---|
| 140 | } |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| 143 | iteratorAdvanced = true; |
|---|
| 144 | ++fr; |
|---|
| 145 | |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | return iteratorAdvanced; |
|---|
| 149 | } |
|---|
| 150 | |
|---|
| 151 | bool HeightField_writeLocalData(const Object& obj, Output& fw) |
|---|
| 152 | { |
|---|
| 153 | const HeightField& heightfield = static_cast<const HeightField&>(obj); |
|---|
| 154 | |
|---|
| 155 | int prec = fw.precision(); |
|---|
| 156 | fw.precision(15); |
|---|
| 157 | fw.indent()<<"Origin "<<heightfield.getOrigin().x()<<" "<<heightfield.getOrigin().y()<<" "<<heightfield.getOrigin().z()<<std::endl; |
|---|
| 158 | fw.indent()<<"XInterval "<<heightfield.getXInterval()<<std::endl; |
|---|
| 159 | fw.indent()<<"YInterval "<<heightfield.getYInterval()<<std::endl; |
|---|
| 160 | fw.indent()<<"SkirtHeight "<<heightfield.getSkirtHeight()<<std::endl; |
|---|
| 161 | fw.indent()<<"BorderWidth "<<heightfield.getBorderWidth()<<std::endl; |
|---|
| 162 | fw.indent()<<"Rotation "<<heightfield.getRotation()<<std::endl; |
|---|
| 163 | fw.precision(prec); |
|---|
| 164 | |
|---|
| 165 | fw.indent()<<"NumColumnsAndRows "<<heightfield.getNumColumns()<<" "<<heightfield.getNumRows()<<std::endl; |
|---|
| 166 | |
|---|
| 167 | fw.indent()<<"Heights"<<std::endl; |
|---|
| 168 | |
|---|
| 169 | ParameterOutput po(fw); |
|---|
| 170 | po.begin(); |
|---|
| 171 | for(unsigned int row=0;row<heightfield.getNumRows();++row) |
|---|
| 172 | { |
|---|
| 173 | for(unsigned int column=0;column<heightfield.getNumColumns();++column) |
|---|
| 174 | { |
|---|
| 175 | po.write(heightfield.getHeight(column,row)); |
|---|
| 176 | } |
|---|
| 177 | po.newLine(); |
|---|
| 178 | } |
|---|
| 179 | po.end(); |
|---|
| 180 | |
|---|
| 181 | return true; |
|---|
| 182 | } |
|---|