root/OpenSceneGraph/trunk/src/osgWrappers/serializers/osgParticle/DomainOperator.cpp @ 13041

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

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
Line 
1#include <osgParticle/DomainOperator>
2#include <osgDB/ObjectWrapper>
3#include <osgDB/InputStream>
4#include <osgDB/OutputStream>
5
6static bool checkDomains( const osgParticle::DomainOperator& dp )
7{
8    return dp.getNumDomains()>0;
9}
10
11static bool readDomains( osgDB::InputStream& is, osgParticle::DomainOperator& dp )
12{
13    osgParticle::DomainOperator::Domain::Type type = osgParticle::DomainOperator::Domain::UNDEFINED_DOMAIN;
14    unsigned int size = 0; is >> size >> osgDB::BEGIN_BRACKET;
15    for ( unsigned int i=0; i<size; ++i )
16    {
17        std::string typeName;
18        is >> osgDB::PROPERTY("Domain") >> typeName >> osgDB::BEGIN_BRACKET;
19        if (typeName=="POINT") type = osgParticle::DomainOperator::Domain::POINT_DOMAIN;
20        else if (typeName=="LINE") type = osgParticle::DomainOperator::Domain::LINE_DOMAIN;
21        else if (typeName=="TRIANGLE") type = osgParticle::DomainOperator::Domain::TRI_DOMAIN;
22        else if (typeName=="RECTANGLE") type = osgParticle::DomainOperator::Domain::RECT_DOMAIN;
23        else if (typeName=="PLANE") type = osgParticle::DomainOperator::Domain::PLANE_DOMAIN;
24        else if (typeName=="SPHERE") type = osgParticle::DomainOperator::Domain::SPHERE_DOMAIN;
25        else if (typeName=="BOX") type = osgParticle::DomainOperator::Domain::BOX_DOMAIN;
26        else if (typeName=="DISK") type = osgParticle::DomainOperator::Domain::DISK_DOMAIN;
27
28        osgParticle::DomainOperator::Domain domain(type);
29        is >> osgDB::PROPERTY("Plane") >> domain.plane;
30        is >> osgDB::PROPERTY("Vertices1") >> domain.v1;
31        is >> osgDB::PROPERTY("Vertices2") >> domain.v2;
32        is >> osgDB::PROPERTY("Vertices3") >> domain.v3;
33        is >> osgDB::PROPERTY("Basis1") >> domain.s1;
34        is >> osgDB::PROPERTY("Basis2") >> domain.s2;
35        is >> osgDB::PROPERTY("Factors") >> domain.r1 >> domain.r2;
36        dp.addDomain(domain);
37
38        is >> osgDB::END_BRACKET;
39    }
40    is >> osgDB::END_BRACKET;
41    return true;
42}
43
44static bool writeDomains( osgDB::OutputStream& os, const osgParticle::DomainOperator& dp )
45{
46    unsigned int size = dp.getNumDomains();
47    os << size << osgDB::BEGIN_BRACKET << std::endl;
48    for ( unsigned int i=0; i<size; ++i )
49    {
50        const osgParticle::DomainOperator::Domain& domain = dp.getDomain(i);
51
52        os << osgDB::PROPERTY("Domain");
53        switch (domain.type)
54        {
55        case osgParticle::DomainOperator::Domain::POINT_DOMAIN:
56            os << std::string("POINT") << osgDB::BEGIN_BRACKET << std::endl; break;
57        case osgParticle::DomainOperator::Domain::LINE_DOMAIN:
58            os << std::string("LINE") << osgDB::BEGIN_BRACKET << std::endl; break;
59        case osgParticle::DomainOperator::Domain::TRI_DOMAIN:
60            os << std::string("TRIANGLE") << osgDB::BEGIN_BRACKET << std::endl; break;
61        case osgParticle::DomainOperator::Domain::RECT_DOMAIN:
62            os << std::string("RECTANGLE") << osgDB::BEGIN_BRACKET << std::endl; break;
63        case osgParticle::DomainOperator::Domain::PLANE_DOMAIN:
64            os << std::string("PLANE") << osgDB::BEGIN_BRACKET << std::endl; break;
65        case osgParticle::DomainOperator::Domain::SPHERE_DOMAIN:
66            os << std::string("SPHERE") << osgDB::BEGIN_BRACKET << std::endl; break;
67        case osgParticle::DomainOperator::Domain::BOX_DOMAIN:
68            os << std::string("BOX") << osgDB::BEGIN_BRACKET << std::endl; break;
69        case osgParticle::DomainOperator::Domain::DISK_DOMAIN:
70            os << std::string("DISK") << osgDB::BEGIN_BRACKET << std::endl; break;
71        default:
72            os << std::string("UNDEFINED") << osgDB::BEGIN_BRACKET << std::endl; break;
73        }
74
75        os << osgDB::PROPERTY("Plane") << domain.plane << std::endl;
76        os << osgDB::PROPERTY("Vertices1") << domain.v1 << std::endl;
77        os << osgDB::PROPERTY("Vertices2") << domain.v2 << std::endl;
78        os << osgDB::PROPERTY("Vertices3") << domain.v3 << std::endl;
79        os << osgDB::PROPERTY("Basis1") << domain.s1 << std::endl;
80        os << osgDB::PROPERTY("Basis2") << domain.s2 << std::endl;
81        os << osgDB::PROPERTY("Factors") << domain.r1 << domain.r2 << std::endl;
82        os << osgDB::END_BRACKET << std::endl;
83    }
84    os << osgDB::END_BRACKET << std::endl;
85    return true;
86}
87
88REGISTER_OBJECT_WRAPPER( osgParticleDomainOperator,
89                         new osgParticle::DomainOperator,
90                         osgParticle::DomainOperator,
91                         "osg::Object osgParticle::Operator osgParticle::DomainOperator" )
92{
93    ADD_USER_SERIALIZER( Domains );  // _placers
94}
Note: See TracBrowser for help on using the browser.