| 1 | #include <osgText/Text3D> |
|---|
| 2 | |
|---|
| 3 | #include <iostream> |
|---|
| 4 | #include <string> |
|---|
| 5 | |
|---|
| 6 | #include <osg/Vec3> |
|---|
| 7 | #include <osg/Vec4> |
|---|
| 8 | #include <osg/io_utils> |
|---|
| 9 | |
|---|
| 10 | #include <osgDB/Registry> |
|---|
| 11 | #include <osgDB/Input> |
|---|
| 12 | #include <osgDB/Output> |
|---|
| 13 | #include <osgDB/ParameterOutput> |
|---|
| 14 | |
|---|
| 15 | bool Text3D_readLocalData(osg::Object &obj, osgDB::Input &fr); |
|---|
| 16 | bool Text3D_writeLocalData(const osg::Object &obj, osgDB::Output &fw); |
|---|
| 17 | |
|---|
| 18 | REGISTER_DOTOSGWRAPPER(Text3D_Proxy) |
|---|
| 19 | ( |
|---|
| 20 | new osgText::Text3D, |
|---|
| 21 | "Text3D", |
|---|
| 22 | "Object Drawable TextBase Text3D", |
|---|
| 23 | Text3D_readLocalData, |
|---|
| 24 | Text3D_writeLocalData |
|---|
| 25 | ); |
|---|
| 26 | |
|---|
| 27 | osgText::Text3D::RenderMode convertRenderModeStringToEnum(const std::string str) |
|---|
| 28 | { |
|---|
| 29 | if (str == "PER_GLYPH") return osgText::Text3D::PER_GLYPH; |
|---|
| 30 | else if (str == "PER_FACE") return osgText::Text3D::PER_FACE; |
|---|
| 31 | return static_cast<osgText::Text3D::RenderMode>(-1); |
|---|
| 32 | } |
|---|
| 33 | std::string convertRenderModeEnumToString(osgText::Text3D::RenderMode renderMode) |
|---|
| 34 | { |
|---|
| 35 | switch (renderMode) |
|---|
| 36 | { |
|---|
| 37 | case osgText::Text3D::PER_GLYPH: return "PER_GLYPH"; |
|---|
| 38 | case osgText::Text3D::PER_FACE: return "PER_FACE"; |
|---|
| 39 | default: return ""; |
|---|
| 40 | } |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | bool Text3D_readLocalData(osg::Object &obj, osgDB::Input &fr) |
|---|
| 44 | { |
|---|
| 45 | osgText::Text3D &text = static_cast<osgText::Text3D &>(obj); |
|---|
| 46 | bool itAdvanced = false; |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | if (fr[0].matchWord("characterDepth")) |
|---|
| 51 | { |
|---|
| 52 | float depth; |
|---|
| 53 | if (fr[1].getFloat(depth)) |
|---|
| 54 | { |
|---|
| 55 | text.setCharacterDepth(depth); |
|---|
| 56 | fr += 2; |
|---|
| 57 | itAdvanced = true; |
|---|
| 58 | } |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | if (fr[0].matchWord("renderMode")) |
|---|
| 63 | { |
|---|
| 64 | osgText::Text3D::RenderMode renderMode = convertRenderModeStringToEnum(fr[1].getStr()); |
|---|
| 65 | if (renderMode != static_cast<osgText::Text3D::RenderMode>(-1)) |
|---|
| 66 | { |
|---|
| 67 | text.setRenderMode(renderMode); |
|---|
| 68 | } |
|---|
| 69 | fr += 2; |
|---|
| 70 | itAdvanced = true; |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | return itAdvanced; |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | bool Text3D_writeLocalData(const osg::Object &obj, osgDB::Output &fw) |
|---|
| 77 | { |
|---|
| 78 | const osgText::Text3D &text = static_cast<const osgText::Text3D &>(obj); |
|---|
| 79 | |
|---|
| 80 | fw.indent() << "characterDepth " << text.getCharacterDepth() << std::endl; |
|---|
| 81 | |
|---|
| 82 | fw.indent() << "renderMode " << convertRenderModeEnumToString(text.getRenderMode()) << std::endl; |
|---|
| 83 | |
|---|
| 84 | return true; |
|---|
| 85 | } |
|---|