| 1 | #include "osg/LightSource" |
|---|
| 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 LightSource_readLocalData(Object& obj, Input& fr); |
|---|
| 12 | bool LightSource_writeLocalData(const Object& obj, Output& fw); |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | REGISTER_DOTOSGWRAPPER(LightSource) |
|---|
| 16 | ( |
|---|
| 17 | new osg::LightSource, |
|---|
| 18 | "LightSource", |
|---|
| 19 | "Object Node LightSource Group", |
|---|
| 20 | &LightSource_readLocalData, |
|---|
| 21 | &LightSource_writeLocalData |
|---|
| 22 | ); |
|---|
| 23 | |
|---|
| 24 | bool LightSource_readLocalData(Object& obj, Input& fr) |
|---|
| 25 | { |
|---|
| 26 | bool iteratorAdvanced = false; |
|---|
| 27 | |
|---|
| 28 | LightSource& lightsource = static_cast<LightSource&>(obj); |
|---|
| 29 | |
|---|
| 30 | if (fr[0].matchWord("referenceFrame")) |
|---|
| 31 | { |
|---|
| 32 | bool cullingActiveBefore = lightsource.getCullingActive(); |
|---|
| 33 | |
|---|
| 34 | if (fr[1].matchWord("RELATIVE_TO_ABSOLUTE") || fr[1].matchWord("ABSOLUTE")) |
|---|
| 35 | { |
|---|
| 36 | lightsource.setReferenceFrame(LightSource::ABSOLUTE_RF); |
|---|
| 37 | fr += 2; |
|---|
| 38 | iteratorAdvanced = true; |
|---|
| 39 | } |
|---|
| 40 | if (fr[1].matchWord("RELATIVE_TO_PARENTS") || fr[1].matchWord("RELATIVE")) |
|---|
| 41 | { |
|---|
| 42 | lightsource.setReferenceFrame(LightSource::RELATIVE_RF); |
|---|
| 43 | fr += 2; |
|---|
| 44 | iteratorAdvanced = true; |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | if (!cullingActiveBefore && lightsource.getCullingActive()) |
|---|
| 49 | { |
|---|
| 50 | lightsource.setCullingActive(cullingActiveBefore); |
|---|
| 51 | } |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | osg::ref_ptr<StateAttribute> sa=fr.readStateAttribute(); |
|---|
| 55 | osg::Light* light = dynamic_cast<Light*>(sa.get()); |
|---|
| 56 | if (light) |
|---|
| 57 | { |
|---|
| 58 | lightsource.setLight(light); |
|---|
| 59 | iteratorAdvanced = true; |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | return iteratorAdvanced; |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | bool LightSource_writeLocalData(const Object& obj, Output& fw) |
|---|
| 67 | { |
|---|
| 68 | const LightSource& lightsource = static_cast<const LightSource&>(obj); |
|---|
| 69 | |
|---|
| 70 | fw.indent() << "referenceFrame "; |
|---|
| 71 | switch (lightsource.getReferenceFrame()) |
|---|
| 72 | { |
|---|
| 73 | case LightSource::ABSOLUTE_RF: |
|---|
| 74 | fw << "ABSOLUTE\n"; |
|---|
| 75 | break; |
|---|
| 76 | case LightSource::RELATIVE_RF: |
|---|
| 77 | default: |
|---|
| 78 | fw << "RELATIVE\n"; |
|---|
| 79 | }; |
|---|
| 80 | |
|---|
| 81 | if (lightsource.getLight()) fw.writeObject(*lightsource.getLight()); |
|---|
| 82 | |
|---|
| 83 | return true; |
|---|
| 84 | } |
|---|