| 1 | #include <osg/LightModel> |
|---|
| 2 | #include <osg/io_utils> |
|---|
| 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 LightModel_readLocalData(Object& obj, Input& fr); |
|---|
| 13 | bool LightModel_writeLocalData(const Object& obj, Output& fw); |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | REGISTER_DOTOSGWRAPPER(LightModel) |
|---|
| 18 | ( |
|---|
| 19 | new osg::LightModel, |
|---|
| 20 | "LightModel", |
|---|
| 21 | "Object StateAttribute LightModel", |
|---|
| 22 | &LightModel_readLocalData, |
|---|
| 23 | &LightModel_writeLocalData |
|---|
| 24 | ); |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | bool LightModel_readLocalData(Object& obj, Input& fr) |
|---|
| 28 | { |
|---|
| 29 | bool iteratorAdvanced = false; |
|---|
| 30 | |
|---|
| 31 | LightModel& lightmodel = static_cast<LightModel&>(obj); |
|---|
| 32 | |
|---|
| 33 | osg::Vec4 ambient; |
|---|
| 34 | if (fr[0].matchWord("ambientIntensity") && |
|---|
| 35 | fr[1].getFloat(ambient[0]) && |
|---|
| 36 | fr[2].getFloat(ambient[1]) && |
|---|
| 37 | fr[3].getFloat(ambient[2]) && |
|---|
| 38 | fr[4].getFloat(ambient[3])) |
|---|
| 39 | { |
|---|
| 40 | lightmodel.setAmbientIntensity(ambient); |
|---|
| 41 | fr+=5; |
|---|
| 42 | iteratorAdvanced = true; |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | if (fr[0].matchWord("colorControl")) |
|---|
| 46 | { |
|---|
| 47 | if (fr[1].matchWord("SEPARATE_SPECULAR_COLOR")) |
|---|
| 48 | { |
|---|
| 49 | lightmodel.setColorControl(osg::LightModel::SEPARATE_SPECULAR_COLOR); |
|---|
| 50 | } |
|---|
| 51 | else if (fr[1].matchWord("SINGLE_COLOR")) |
|---|
| 52 | { |
|---|
| 53 | lightmodel.setColorControl(osg::LightModel::SINGLE_COLOR); |
|---|
| 54 | } |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | int result; |
|---|
| 58 | if (fr[0].matchWord("localViewer") && fr[1].getInt(result)) |
|---|
| 59 | { |
|---|
| 60 | if (fr[1].matchWord("TRUE")) |
|---|
| 61 | { |
|---|
| 62 | lightmodel.setLocalViewer(true); |
|---|
| 63 | fr+=2; |
|---|
| 64 | iteratorAdvanced = true; |
|---|
| 65 | } |
|---|
| 66 | else if (fr[1].matchWord("FALSE")) |
|---|
| 67 | { |
|---|
| 68 | lightmodel.setLocalViewer(false); |
|---|
| 69 | fr+=2; |
|---|
| 70 | iteratorAdvanced = true; |
|---|
| 71 | } |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | if (fr[0].matchWord("twoSided")) |
|---|
| 75 | { |
|---|
| 76 | if (fr[1].matchWord("TRUE")) |
|---|
| 77 | { |
|---|
| 78 | lightmodel.setTwoSided(true); |
|---|
| 79 | fr+=2; |
|---|
| 80 | iteratorAdvanced = true; |
|---|
| 81 | } |
|---|
| 82 | else if (fr[1].matchWord("FALSE")) |
|---|
| 83 | { |
|---|
| 84 | lightmodel.setTwoSided(false); |
|---|
| 85 | fr+=2; |
|---|
| 86 | iteratorAdvanced = true; |
|---|
| 87 | } |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | return iteratorAdvanced; |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | bool LightModel_writeLocalData(const Object& obj,Output& fw) |
|---|
| 94 | { |
|---|
| 95 | const LightModel& lightmodel = static_cast<const LightModel&>(obj); |
|---|
| 96 | |
|---|
| 97 | fw.indent() << "ambientIntensity " << lightmodel.getAmbientIntensity() << std::endl; |
|---|
| 98 | |
|---|
| 99 | if (lightmodel.getColorControl()==osg::LightModel::SEPARATE_SPECULAR_COLOR) |
|---|
| 100 | fw.indent() << "colorControl SEPARATE_SPECULAR_COLOR" << std::endl; |
|---|
| 101 | else |
|---|
| 102 | fw.indent() << "colorControl SINGLE_COLOR" << std::endl; |
|---|
| 103 | |
|---|
| 104 | if (lightmodel.getLocalViewer()) |
|---|
| 105 | fw.indent() << "localViewer TRUE"<< std::endl; |
|---|
| 106 | else |
|---|
| 107 | fw.indent() << "localViewer FALSE"<< std::endl; |
|---|
| 108 | |
|---|
| 109 | if (lightmodel.getTwoSided()) |
|---|
| 110 | fw.indent() << "twoSided TRUE"<< std::endl; |
|---|
| 111 | else |
|---|
| 112 | fw.indent() << "twoSided FALSE"<< std::endl; |
|---|
| 113 | |
|---|
| 114 | return true; |
|---|
| 115 | } |
|---|