| 1 | #include "osg/Drawable" |
|---|
| 2 | #include "osg/Notify" |
|---|
| 3 | |
|---|
| 4 | #include "osgDB/Registry" |
|---|
| 5 | #include "osgDB/Input" |
|---|
| 6 | #include "osgDB/Output" |
|---|
| 7 | |
|---|
| 8 | using namespace osg; |
|---|
| 9 | using namespace osgDB; |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | bool Drawable_readLocalData(Object& obj, Input& fr); |
|---|
| 13 | bool Drawable_writeLocalData(const Object& obj, Output& fw); |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | REGISTER_DOTOSGWRAPPER(Drawable) |
|---|
| 17 | ( NULL, |
|---|
| 18 | "Drawable", |
|---|
| 19 | "Object Drawable", |
|---|
| 20 | &Drawable_readLocalData, |
|---|
| 21 | &Drawable_writeLocalData |
|---|
| 22 | ); |
|---|
| 23 | |
|---|
| 24 | bool Drawable_readLocalData(Object& obj, Input& fr) |
|---|
| 25 | { |
|---|
| 26 | bool iteratorAdvanced = false; |
|---|
| 27 | |
|---|
| 28 | Drawable& drawable = static_cast<Drawable&>(obj); |
|---|
| 29 | |
|---|
| 30 | static ref_ptr<StateSet> s_drawstate = new osg::StateSet; |
|---|
| 31 | if (StateSet* readState = static_cast<StateSet*>(fr.readObjectOfType(*s_drawstate))) |
|---|
| 32 | { |
|---|
| 33 | drawable.setStateSet(readState); |
|---|
| 34 | iteratorAdvanced = true; |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | Shape* shape = static_cast<Shape *>(fr.readObjectOfType(type_wrapper<Shape>())); |
|---|
| 38 | if (shape) |
|---|
| 39 | { |
|---|
| 40 | drawable.setShape(shape); |
|---|
| 41 | iteratorAdvanced = true; |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | Drawable::UpdateCallback* uc = dynamic_cast<Drawable::UpdateCallback *>(fr.readObjectOfType(type_wrapper<Drawable::UpdateCallback>())); |
|---|
| 45 | if (uc) |
|---|
| 46 | { |
|---|
| 47 | drawable.setUpdateCallback(uc); |
|---|
| 48 | iteratorAdvanced = true; |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | Drawable::CullCallback* cc = dynamic_cast<Drawable::CullCallback *>(fr.readObjectOfType(type_wrapper<Drawable::CullCallback>())); |
|---|
| 52 | if (cc) |
|---|
| 53 | { |
|---|
| 54 | drawable.setCullCallback(cc); |
|---|
| 55 | iteratorAdvanced = true; |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | Drawable::DrawCallback* dc = dynamic_cast<Drawable::DrawCallback *>(fr.readObjectOfType(type_wrapper<Drawable::DrawCallback>())); |
|---|
| 59 | if (dc) |
|---|
| 60 | { |
|---|
| 61 | drawable.setDrawCallback(dc); |
|---|
| 62 | iteratorAdvanced = true; |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | if (fr.matchSequence("initialBound %f %f %f %f %f %f")) |
|---|
| 66 | { |
|---|
| 67 | BoundingBox bb; |
|---|
| 68 | fr[1].getFloat(bb.xMin()); |
|---|
| 69 | fr[2].getFloat(bb.yMin()); |
|---|
| 70 | fr[3].getFloat(bb.zMin()); |
|---|
| 71 | fr[4].getFloat(bb.xMax()); |
|---|
| 72 | fr[5].getFloat(bb.yMax()); |
|---|
| 73 | fr[6].getFloat(bb.zMax()); |
|---|
| 74 | drawable.setInitialBound(bb); |
|---|
| 75 | fr += 7; |
|---|
| 76 | iteratorAdvanced = true; |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | Drawable::ComputeBoundingBoxCallback* cbc = dynamic_cast<Drawable::ComputeBoundingBoxCallback *>(fr.readObjectOfType(type_wrapper<Drawable::ComputeBoundingBoxCallback>())); |
|---|
| 80 | if (cbc) |
|---|
| 81 | { |
|---|
| 82 | drawable.setComputeBoundingBoxCallback(cbc); |
|---|
| 83 | iteratorAdvanced = true; |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | if (fr[0].matchWord("supportsDisplayList")) |
|---|
| 87 | { |
|---|
| 88 | if (fr[1].matchWord("TRUE")) |
|---|
| 89 | { |
|---|
| 90 | drawable.setSupportsDisplayList(true); |
|---|
| 91 | fr+=2; |
|---|
| 92 | iteratorAdvanced = true; |
|---|
| 93 | } |
|---|
| 94 | else if (fr[1].matchWord("FALSE")) |
|---|
| 95 | { |
|---|
| 96 | drawable.setSupportsDisplayList(false); |
|---|
| 97 | fr+=2; |
|---|
| 98 | iteratorAdvanced = true; |
|---|
| 99 | } |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | if (fr[0].matchWord("useDisplayList")) |
|---|
| 103 | { |
|---|
| 104 | if (fr[1].matchWord("TRUE")) |
|---|
| 105 | { |
|---|
| 106 | drawable.setUseDisplayList(true); |
|---|
| 107 | fr+=2; |
|---|
| 108 | iteratorAdvanced = true; |
|---|
| 109 | } |
|---|
| 110 | else if (fr[1].matchWord("FALSE")) |
|---|
| 111 | { |
|---|
| 112 | drawable.setUseDisplayList(false); |
|---|
| 113 | fr+=2; |
|---|
| 114 | iteratorAdvanced = true; |
|---|
| 115 | } |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | if (fr[0].matchWord("useVertexBufferObjects")) |
|---|
| 119 | { |
|---|
| 120 | if (fr[1].matchWord("TRUE")) |
|---|
| 121 | { |
|---|
| 122 | drawable.setUseVertexBufferObjects(true); |
|---|
| 123 | fr+=2; |
|---|
| 124 | iteratorAdvanced = true; |
|---|
| 125 | } |
|---|
| 126 | else if (fr[1].matchWord("FALSE")) |
|---|
| 127 | { |
|---|
| 128 | drawable.setUseVertexBufferObjects(false); |
|---|
| 129 | fr+=2; |
|---|
| 130 | iteratorAdvanced = true; |
|---|
| 131 | } |
|---|
| 132 | } |
|---|
| 133 | |
|---|
| 134 | return iteratorAdvanced; |
|---|
| 135 | } |
|---|
| 136 | |
|---|
| 137 | |
|---|
| 138 | bool Drawable_writeLocalData(const Object& obj, Output& fw) |
|---|
| 139 | { |
|---|
| 140 | const Drawable& drawable = static_cast<const Drawable&>(obj); |
|---|
| 141 | |
|---|
| 142 | if (drawable.getStateSet()) |
|---|
| 143 | { |
|---|
| 144 | fw.writeObject(*drawable.getStateSet()); |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | if (drawable.getShape()) |
|---|
| 148 | { |
|---|
| 149 | fw.writeObject(*drawable.getShape()); |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | if (drawable.getUpdateCallback()) |
|---|
| 153 | { |
|---|
| 154 | fw.writeObject(*drawable.getUpdateCallback()); |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | if (drawable.getEventCallback()) |
|---|
| 158 | { |
|---|
| 159 | fw.writeObject(*drawable.getEventCallback()); |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | if (drawable.getCullCallback()) |
|---|
| 163 | { |
|---|
| 164 | fw.writeObject(*drawable.getCullCallback()); |
|---|
| 165 | } |
|---|
| 166 | |
|---|
| 167 | if (drawable.getDrawCallback()) |
|---|
| 168 | { |
|---|
| 169 | fw.writeObject(*drawable.getDrawCallback()); |
|---|
| 170 | } |
|---|
| 171 | |
|---|
| 172 | |
|---|
| 173 | if (drawable.getInitialBound().valid()) |
|---|
| 174 | { |
|---|
| 175 | const osg::BoundingBox& bb = drawable.getInitialBound(); |
|---|
| 176 | fw.indent()<<"initialBound "<<bb.xMin()<<" "<<bb.yMin()<<" "<<bb.zMin()<<" " |
|---|
| 177 | <<bb.xMax()<<" "<<bb.yMax()<<" "<<bb.zMax()<<std::endl; |
|---|
| 178 | } |
|---|
| 179 | |
|---|
| 180 | if (drawable.getComputeBoundingBoxCallback()) |
|---|
| 181 | { |
|---|
| 182 | fw.writeObject(*drawable.getComputeBoundingBoxCallback()); |
|---|
| 183 | } |
|---|
| 184 | |
|---|
| 185 | |
|---|
| 186 | if (!drawable.getSupportsDisplayList()) |
|---|
| 187 | { |
|---|
| 188 | fw.indent()<<"supportsDisplayList "; |
|---|
| 189 | if (drawable.getSupportsDisplayList()) fw << "TRUE" << std::endl; |
|---|
| 190 | else fw << "FALSE" << std::endl; |
|---|
| 191 | } |
|---|
| 192 | |
|---|
| 193 | fw.indent()<<"useDisplayList "; |
|---|
| 194 | if (drawable.getUseDisplayList()) fw << "TRUE" << std::endl; |
|---|
| 195 | else fw << "FALSE" << std::endl; |
|---|
| 196 | |
|---|
| 197 | fw.indent()<<"useVertexBufferObjects "; |
|---|
| 198 | if (drawable.getUseVertexBufferObjects()) fw << "TRUE" << std::endl; |
|---|
| 199 | else fw << "FALSE" << std::endl; |
|---|
| 200 | |
|---|
| 201 | return true; |
|---|
| 202 | } |
|---|