| 1 | #include <osgFX/BumpMapping> |
|---|
| 2 | |
|---|
| 3 | #include <osgDB/Registry> |
|---|
| 4 | #include <osgDB/Input> |
|---|
| 5 | #include <osgDB/Output> |
|---|
| 6 | |
|---|
| 7 | bool BumpMapping_readLocalData(osg::Object &obj, osgDB::Input &fr); |
|---|
| 8 | bool BumpMapping_writeLocalData(const osg::Object &obj, osgDB::Output &fw); |
|---|
| 9 | |
|---|
| 10 | REGISTER_DOTOSGWRAPPER(BumpMapping_Proxy) |
|---|
| 11 | ( |
|---|
| 12 | new osgFX::BumpMapping, |
|---|
| 13 | "osgFX::BumpMapping", |
|---|
| 14 | "Object Node Group osgFX::Effect osgFX::BumpMapping", |
|---|
| 15 | BumpMapping_readLocalData, |
|---|
| 16 | BumpMapping_writeLocalData |
|---|
| 17 | ); |
|---|
| 18 | |
|---|
| 19 | bool BumpMapping_readLocalData(osg::Object &obj, osgDB::Input &fr) |
|---|
| 20 | { |
|---|
| 21 | osgFX::BumpMapping &myobj = static_cast<osgFX::BumpMapping &>(obj); |
|---|
| 22 | bool itAdvanced = false; |
|---|
| 23 | |
|---|
| 24 | if (fr[0].matchWord("lightNumber")) { |
|---|
| 25 | int n; |
|---|
| 26 | if (fr[1].getInt(n)) { |
|---|
| 27 | myobj.setLightNumber(n); |
|---|
| 28 | fr += 2; |
|---|
| 29 | itAdvanced = true; |
|---|
| 30 | } |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | if (fr[0].matchWord("diffuseUnit")) { |
|---|
| 34 | int n; |
|---|
| 35 | if (fr[1].getInt(n)) { |
|---|
| 36 | myobj.setDiffuseTextureUnit(n); |
|---|
| 37 | fr += 2; |
|---|
| 38 | itAdvanced = true; |
|---|
| 39 | } |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | if (fr[0].matchWord("normalMapUnit")) { |
|---|
| 43 | int n; |
|---|
| 44 | if (fr[1].getInt(n)) { |
|---|
| 45 | myobj.setNormalMapTextureUnit(n); |
|---|
| 46 | fr += 2; |
|---|
| 47 | itAdvanced = true; |
|---|
| 48 | } |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | osg::ref_ptr<osg::Texture2D> diffuse_tex = static_cast<osg::Texture2D *>(fr.readObjectOfType(osgDB::type_wrapper<osg::Texture2D>())); |
|---|
| 52 | if (diffuse_tex.valid()) { |
|---|
| 53 | myobj.setOverrideDiffuseTexture(diffuse_tex.get()); |
|---|
| 54 | itAdvanced = true; |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | osg::ref_ptr<osg::Texture2D> normal_tex = static_cast<osg::Texture2D *>(fr.readObjectOfType(osgDB::type_wrapper<osg::Texture2D>())); |
|---|
| 58 | if (normal_tex.valid()) { |
|---|
| 59 | myobj.setOverrideNormalMapTexture(normal_tex.get()); |
|---|
| 60 | itAdvanced = true; |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | return itAdvanced; |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | bool BumpMapping_writeLocalData(const osg::Object &obj, osgDB::Output &fw) |
|---|
| 67 | { |
|---|
| 68 | const osgFX::BumpMapping &myobj = static_cast<const osgFX::BumpMapping &>(obj); |
|---|
| 69 | |
|---|
| 70 | fw.indent() << "lightNumber " << myobj.getLightNumber() << "\n"; |
|---|
| 71 | fw.indent() << "diffuseUnit " << myobj.getDiffuseTextureUnit() << "\n"; |
|---|
| 72 | fw.indent() << "normalMapUnit " << myobj.getNormalMapTextureUnit() << "\n"; |
|---|
| 73 | |
|---|
| 74 | if (myobj.getOverrideDiffuseTexture()) { |
|---|
| 75 | fw.writeObject(*myobj.getOverrideDiffuseTexture()); |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | if (myobj.getOverrideNormalMapTexture()) { |
|---|
| 79 | fw.writeObject(*myobj.getOverrideNormalMapTexture()); |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | return true; |
|---|
| 83 | } |
|---|