| 1 | #if defined(_MSC_VER) |
|---|
| 2 | #pragma warning( disable : 4786 ) |
|---|
| 3 | #endif |
|---|
| 4 | |
|---|
| 5 | #include "osg/TexGen" |
|---|
| 6 | #include "osg/io_utils" |
|---|
| 7 | |
|---|
| 8 | #include "osgDB/Registry" |
|---|
| 9 | #include "osgDB/Input" |
|---|
| 10 | #include "osgDB/Output" |
|---|
| 11 | |
|---|
| 12 | #include <string.h> |
|---|
| 13 | |
|---|
| 14 | using namespace osg; |
|---|
| 15 | using namespace osgDB; |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | bool TexGen_readLocalData(Object& obj, Input& fr); |
|---|
| 19 | bool TexGen_writeLocalData(const Object& obj, Output& fw); |
|---|
| 20 | bool TexGen_matchModeStr(const char* str,TexGen::Mode& mode); |
|---|
| 21 | const char* TexGen_getModeStr(TexGen::Mode mode); |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | REGISTER_DOTOSGWRAPPER(TexGen) |
|---|
| 25 | ( |
|---|
| 26 | new osg::TexGen, |
|---|
| 27 | "TexGen", |
|---|
| 28 | "Object StateAttribute TexGen", |
|---|
| 29 | &TexGen_readLocalData, |
|---|
| 30 | &TexGen_writeLocalData |
|---|
| 31 | ); |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | bool TexGen_readLocalData(Object& obj, Input& fr) |
|---|
| 35 | { |
|---|
| 36 | bool iteratorAdvanced = false; |
|---|
| 37 | |
|---|
| 38 | TexGen& texgen = static_cast<TexGen&>(obj); |
|---|
| 39 | |
|---|
| 40 | TexGen::Mode mode; |
|---|
| 41 | |
|---|
| 42 | if (fr[0].matchWord("mode") && TexGen_matchModeStr(fr[1].getStr(),mode)) |
|---|
| 43 | { |
|---|
| 44 | texgen.setMode(mode); |
|---|
| 45 | fr+=2; |
|---|
| 46 | iteratorAdvanced = true; |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | osg::Plane plane; |
|---|
| 50 | if (fr[0].matchWord("plane_s")) |
|---|
| 51 | { |
|---|
| 52 | if (fr[1].getFloat(plane[0]) && fr[2].getFloat(plane[1]) && |
|---|
| 53 | fr[3].getFloat(plane[2]) && fr[4].getFloat(plane[3])) |
|---|
| 54 | { |
|---|
| 55 | texgen.setPlane(TexGen::S,plane); |
|---|
| 56 | fr+=5; |
|---|
| 57 | iteratorAdvanced = true; |
|---|
| 58 | } |
|---|
| 59 | } |
|---|
| 60 | if (fr[0].matchWord("plane_t")) |
|---|
| 61 | { |
|---|
| 62 | if (fr[1].getFloat(plane[0]) && fr[2].getFloat(plane[1]) && |
|---|
| 63 | fr[3].getFloat(plane[2]) && fr[4].getFloat(plane[3])) |
|---|
| 64 | { |
|---|
| 65 | texgen.setPlane(TexGen::T,plane); |
|---|
| 66 | fr+=5; |
|---|
| 67 | iteratorAdvanced = true; |
|---|
| 68 | } |
|---|
| 69 | } |
|---|
| 70 | if (fr[0].matchWord("plane_r")) |
|---|
| 71 | { |
|---|
| 72 | if (fr[1].getFloat(plane[0]) && fr[2].getFloat(plane[1]) && |
|---|
| 73 | fr[3].getFloat(plane[2]) && fr[4].getFloat(plane[3])) |
|---|
| 74 | { |
|---|
| 75 | texgen.setPlane(TexGen::R,plane); |
|---|
| 76 | fr+=5; |
|---|
| 77 | iteratorAdvanced = true; |
|---|
| 78 | } |
|---|
| 79 | } |
|---|
| 80 | if (fr[0].matchWord("plane_q")) |
|---|
| 81 | { |
|---|
| 82 | if (fr[1].getFloat(plane[0]) && fr[2].getFloat(plane[1]) && |
|---|
| 83 | fr[3].getFloat(plane[2]) && fr[4].getFloat(plane[3])) |
|---|
| 84 | { |
|---|
| 85 | texgen.setPlane(TexGen::Q,plane); |
|---|
| 86 | fr+=5; |
|---|
| 87 | iteratorAdvanced = true; |
|---|
| 88 | } |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | return iteratorAdvanced; |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | |
|---|
| 95 | bool TexGen_matchModeStr(const char* str,TexGen::Mode& mode) |
|---|
| 96 | { |
|---|
| 97 | if (strcmp(str,"EYE_LINEAR")==0) mode = TexGen::EYE_LINEAR; |
|---|
| 98 | else if (strcmp(str,"OBJECT_LINEAR")==0) mode = TexGen::OBJECT_LINEAR; |
|---|
| 99 | else if (strcmp(str,"SPHERE_MAP")==0) mode = TexGen::SPHERE_MAP; |
|---|
| 100 | else if (strcmp(str,"NORMAL_MAP")==0) mode = TexGen::NORMAL_MAP; |
|---|
| 101 | else if (strcmp(str,"REFLECTION_MAP")==0) mode = TexGen::REFLECTION_MAP; |
|---|
| 102 | else return false; |
|---|
| 103 | return true; |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | const char* TexGen_getModeStr(TexGen::Mode mode) |
|---|
| 108 | { |
|---|
| 109 | switch(mode) |
|---|
| 110 | { |
|---|
| 111 | case(TexGen::EYE_LINEAR): return "EYE_LINEAR"; |
|---|
| 112 | case(TexGen::OBJECT_LINEAR): return "OBJECT_LINEAR"; |
|---|
| 113 | case(TexGen::SPHERE_MAP): return "SPHERE_MAP"; |
|---|
| 114 | case(TexGen::NORMAL_MAP): return "NORMAL_MAP"; |
|---|
| 115 | case(TexGen::REFLECTION_MAP): return "REFLECTION_MAP"; |
|---|
| 116 | } |
|---|
| 117 | return ""; |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | |
|---|
| 121 | bool TexGen_writeLocalData(const Object& obj, Output& fw) |
|---|
| 122 | { |
|---|
| 123 | const TexGen& texgen = static_cast<const TexGen&>(obj); |
|---|
| 124 | |
|---|
| 125 | fw.indent() << "mode " << TexGen_getModeStr(texgen.getMode()) << std::endl; |
|---|
| 126 | if (texgen.getMode() == TexGen::OBJECT_LINEAR || texgen.getMode() == TexGen::EYE_LINEAR) |
|---|
| 127 | { |
|---|
| 128 | fw.indent() << "plane_s " << texgen.getPlane(TexGen::S) << std::endl; |
|---|
| 129 | fw.indent() << "plane_t " << texgen.getPlane(TexGen::T) << std::endl; |
|---|
| 130 | fw.indent() << "plane_r " << texgen.getPlane(TexGen::R) << std::endl; |
|---|
| 131 | fw.indent() << "plane_q " << texgen.getPlane(TexGen::Q) << std::endl; |
|---|
| 132 | } |
|---|
| 133 | |
|---|
| 134 | return true; |
|---|
| 135 | } |
|---|