| 1 | #include "osg/Billboard" |
|---|
| 2 | |
|---|
| 3 | #include "osgDB/Registry" |
|---|
| 4 | #include "osgDB/Input" |
|---|
| 5 | #include "osgDB/Output" |
|---|
| 6 | |
|---|
| 7 | using namespace osg; |
|---|
| 8 | using namespace osgDB; |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | bool Billboard_readLocalData(Object& obj, Input& fr); |
|---|
| 12 | bool Billboard_writeLocalData(const Object& obj, Output& fw); |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | REGISTER_DOTOSGWRAPPER(Billboard) |
|---|
| 16 | ( |
|---|
| 17 | new osg::Billboard, |
|---|
| 18 | "Billboard", |
|---|
| 19 | "Object Node Geode Billboard", |
|---|
| 20 | &Billboard_readLocalData, |
|---|
| 21 | &Billboard_writeLocalData |
|---|
| 22 | ); |
|---|
| 23 | |
|---|
| 24 | bool Billboard_readLocalData(Object& obj, Input& fr) |
|---|
| 25 | { |
|---|
| 26 | bool iteratorAdvanced = false; |
|---|
| 27 | |
|---|
| 28 | Billboard& billboard = static_cast<Billboard&>(obj); |
|---|
| 29 | |
|---|
| 30 | if (fr[0].matchWord("Mode")) |
|---|
| 31 | { |
|---|
| 32 | if (fr[1].matchWord("AXIAL_ROT")) |
|---|
| 33 | { |
|---|
| 34 | billboard.setMode(Billboard::AXIAL_ROT); |
|---|
| 35 | fr+=2; |
|---|
| 36 | iteratorAdvanced = true; |
|---|
| 37 | } |
|---|
| 38 | else if (fr[1].matchWord("POINT_ROT_EYE")) |
|---|
| 39 | { |
|---|
| 40 | billboard.setMode(Billboard::POINT_ROT_EYE); |
|---|
| 41 | fr+=2; |
|---|
| 42 | iteratorAdvanced = true; |
|---|
| 43 | } |
|---|
| 44 | else if (fr[1].matchWord("POINT_ROT_WORLD")) |
|---|
| 45 | { |
|---|
| 46 | billboard.setMode(Billboard::POINT_ROT_WORLD); |
|---|
| 47 | fr+=2; |
|---|
| 48 | iteratorAdvanced = true; |
|---|
| 49 | } |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | if (fr[0].matchWord("Axis")) |
|---|
| 53 | { |
|---|
| 54 | float x,y,z; |
|---|
| 55 | if (fr[1].getFloat(x) && fr[2].getFloat(y) && fr[3].getFloat(z)) |
|---|
| 56 | { |
|---|
| 57 | billboard.setAxis(Vec3(x,y,z)); |
|---|
| 58 | fr+=4; |
|---|
| 59 | iteratorAdvanced = true; |
|---|
| 60 | } |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | if (fr[0].matchWord("Normal")) |
|---|
| 64 | { |
|---|
| 65 | float x,y,z; |
|---|
| 66 | if (fr[1].getFloat(x) && fr[2].getFloat(y) && fr[3].getFloat(z)) |
|---|
| 67 | { |
|---|
| 68 | billboard.setNormal(Vec3(x,y,z)); |
|---|
| 69 | fr+=4; |
|---|
| 70 | iteratorAdvanced = true; |
|---|
| 71 | } |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | bool matchFirst = false; |
|---|
| 77 | if ((matchFirst=fr.matchSequence("Positions {")) || fr.matchSequence("Positions %i {")) |
|---|
| 78 | { |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | int entry = fr[0].getNoNestedBrackets(); |
|---|
| 82 | |
|---|
| 83 | Billboard::PositionList& positionList = billboard.getPositionList(); |
|---|
| 84 | positionList.clear(); |
|---|
| 85 | |
|---|
| 86 | if (matchFirst) |
|---|
| 87 | { |
|---|
| 88 | fr += 2; |
|---|
| 89 | } |
|---|
| 90 | else |
|---|
| 91 | { |
|---|
| 92 | |
|---|
| 93 | fr += 3; |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | Vec3 pos; |
|---|
| 97 | while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) |
|---|
| 98 | { |
|---|
| 99 | if (fr[0].getFloat(pos[0]) && fr[1].getFloat(pos[1]) && fr[2].getFloat(pos[2])) |
|---|
| 100 | { |
|---|
| 101 | fr += 3; |
|---|
| 102 | positionList.push_back(pos); |
|---|
| 103 | } |
|---|
| 104 | else |
|---|
| 105 | { |
|---|
| 106 | ++fr; |
|---|
| 107 | } |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | iteratorAdvanced = true; |
|---|
| 111 | ++fr; |
|---|
| 112 | |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | return iteratorAdvanced; |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | bool Billboard_writeLocalData(const Object& obj, Output& fw) |
|---|
| 120 | { |
|---|
| 121 | |
|---|
| 122 | const Billboard& billboard = static_cast<const Billboard&>(obj); |
|---|
| 123 | |
|---|
| 124 | switch(billboard.getMode()) |
|---|
| 125 | { |
|---|
| 126 | case(Billboard::AXIAL_ROT): fw.indent() << "Mode AXIAL_ROT"<<std::endl; break; |
|---|
| 127 | case(Billboard::POINT_ROT_EYE): fw.indent() << "Mode POINT_ROT_EYE"<<std::endl; break; |
|---|
| 128 | case(Billboard::POINT_ROT_WORLD): fw.indent() << "Mode POINT_ROT_WORLD"<<std::endl; break; |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | const Vec3& axis = billboard.getAxis(); |
|---|
| 132 | fw.indent() << "Axis " << axis[0] << " "<<axis[1]<<" "<<axis[2]<<std::endl; |
|---|
| 133 | |
|---|
| 134 | const Vec3& normal = billboard.getNormal(); |
|---|
| 135 | fw.indent() << "Normal " << normal[0] << " "<<normal[1]<<" "<<normal[2]<<std::endl; |
|---|
| 136 | |
|---|
| 137 | fw.indent() << "Positions {"<<std::endl; |
|---|
| 138 | fw.moveIn(); |
|---|
| 139 | |
|---|
| 140 | |
|---|
| 141 | Billboard::PositionList positionList = billboard.getPositionList(); |
|---|
| 142 | for(Billboard::PositionList::iterator piter = positionList.begin(); |
|---|
| 143 | piter != positionList.end(); |
|---|
| 144 | ++piter) |
|---|
| 145 | { |
|---|
| 146 | fw.indent() << (*piter)[0] << " "<<(*piter)[1]<<" "<<(*piter)[2]<<std::endl; |
|---|
| 147 | } |
|---|
| 148 | fw.moveOut(); |
|---|
| 149 | fw.indent() << "}"<<std::endl; |
|---|
| 150 | |
|---|
| 151 | return true; |
|---|
| 152 | } |
|---|