root/OpenSceneGraph/trunk/src/osgWrappers/deprecated-dotosg/osg/LightSource.cpp @ 13041

Revision 13041, 2.2 kB (checked in by robert, 2 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1#include "osg/LightSource"
2
3#include "osgDB/Registry"
4#include "osgDB/Input"
5#include "osgDB/Output"
6
7using namespace osg;
8using namespace osgDB;
9
10// forward declare functions to use later.
11bool LightSource_readLocalData(Object& obj, Input& fr);
12bool LightSource_writeLocalData(const Object& obj, Output& fw);
13
14// register the read and write functions with the osgDB::Registry.
15REGISTER_DOTOSGWRAPPER(LightSource)
16(
17    new osg::LightSource,
18    "LightSource",
19    "Object Node LightSource Group",
20    &LightSource_readLocalData,
21    &LightSource_writeLocalData
22);
23
24bool 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        // if culling wasn't before reset it to off.
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
66bool 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}
Note: See TracBrowser for help on using the browser.