| 1 | |
|---|
| 2 | #include <osgParticle/DomainOperator> |
|---|
| 3 | |
|---|
| 4 | #include <osgDB/Registry> |
|---|
| 5 | #include <osgDB/Input> |
|---|
| 6 | #include <osgDB/Output> |
|---|
| 7 | |
|---|
| 8 | #include <osg/Vec3> |
|---|
| 9 | #include <osg/io_utils> |
|---|
| 10 | #include <iostream> |
|---|
| 11 | |
|---|
| 12 | bool DomainOperator_readLocalData(osg::Object &obj, osgDB::Input &fr); |
|---|
| 13 | bool DomainOperator_writeLocalData(const osg::Object &obj, osgDB::Output &fw); |
|---|
| 14 | |
|---|
| 15 | REGISTER_DOTOSGWRAPPER(DomainOperator_Proxy) |
|---|
| 16 | ( |
|---|
| 17 | new osgParticle::DomainOperator, |
|---|
| 18 | "DomainOperator", |
|---|
| 19 | "Object Operator DomainOperator", |
|---|
| 20 | DomainOperator_readLocalData, |
|---|
| 21 | DomainOperator_writeLocalData |
|---|
| 22 | ); |
|---|
| 23 | |
|---|
| 24 | bool DomainOperator_readLocalData(osg::Object &obj, osgDB::Input &fr) |
|---|
| 25 | { |
|---|
| 26 | osgParticle::DomainOperator &dp = static_cast<osgParticle::DomainOperator &>(obj); |
|---|
| 27 | bool itAdvanced = false; |
|---|
| 28 | |
|---|
| 29 | std::string typeName; |
|---|
| 30 | while (fr.matchSequence("domain %s {")) |
|---|
| 31 | { |
|---|
| 32 | if (fr[1].getStr()) typeName = fr[1].getStr(); |
|---|
| 33 | fr += 3; |
|---|
| 34 | |
|---|
| 35 | osgParticle::DomainOperator::Domain::Type type = osgParticle::DomainOperator::Domain::UNDEFINED_DOMAIN; |
|---|
| 36 | if (typeName == "point") type = osgParticle::DomainOperator::Domain::POINT_DOMAIN; |
|---|
| 37 | else if (typeName == "line") type = osgParticle::DomainOperator::Domain::LINE_DOMAIN; |
|---|
| 38 | else if (typeName == "triangle") type = osgParticle::DomainOperator::Domain::TRI_DOMAIN; |
|---|
| 39 | else if (typeName == "rectangle") type = osgParticle::DomainOperator::Domain::RECT_DOMAIN; |
|---|
| 40 | else if (typeName == "plane") type = osgParticle::DomainOperator::Domain::PLANE_DOMAIN; |
|---|
| 41 | else if (typeName == "sphere") type = osgParticle::DomainOperator::Domain::SPHERE_DOMAIN; |
|---|
| 42 | else if (typeName == "box") type = osgParticle::DomainOperator::Domain::BOX_DOMAIN; |
|---|
| 43 | else if (typeName == "disk") type = osgParticle::DomainOperator::Domain::DISK_DOMAIN; |
|---|
| 44 | |
|---|
| 45 | osgParticle::DomainOperator::Domain domain(type); |
|---|
| 46 | if (fr[0].matchWord("plane")) { |
|---|
| 47 | if (fr[1].getFloat(domain.plane[0]) && fr[2].getFloat(domain.plane[1]) && |
|---|
| 48 | fr[3].getFloat(domain.plane[2]) && fr[4].getFloat(domain.plane[3])) |
|---|
| 49 | { |
|---|
| 50 | fr += 5; |
|---|
| 51 | } |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | if (fr[0].matchWord("vertices1")) { |
|---|
| 55 | if (fr[1].getFloat(domain.v1[0]) && fr[2].getFloat(domain.v1[1]) && fr[3].getFloat(domain.v1[2])) |
|---|
| 56 | { |
|---|
| 57 | fr += 4; |
|---|
| 58 | } |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | if (fr[0].matchWord("vertices2")) { |
|---|
| 62 | if (fr[1].getFloat(domain.v2[0]) && fr[2].getFloat(domain.v2[1]) && fr[3].getFloat(domain.v2[2])) |
|---|
| 63 | { |
|---|
| 64 | fr += 4; |
|---|
| 65 | } |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | if (fr[0].matchWord("vertices3")) { |
|---|
| 69 | if (fr[1].getFloat(domain.v3[0]) && fr[2].getFloat(domain.v3[1]) && fr[3].getFloat(domain.v3[2])) |
|---|
| 70 | { |
|---|
| 71 | fr += 4; |
|---|
| 72 | } |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | if (fr[0].matchWord("basis1")) { |
|---|
| 76 | if (fr[1].getFloat(domain.s1[0]) && fr[2].getFloat(domain.s1[1]) && fr[3].getFloat(domain.s1[2])) |
|---|
| 77 | { |
|---|
| 78 | fr += 4; |
|---|
| 79 | } |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | if (fr[0].matchWord("basis2")) { |
|---|
| 83 | if (fr[1].getFloat(domain.s2[0]) && fr[2].getFloat(domain.s2[1]) && fr[3].getFloat(domain.s2[2])) |
|---|
| 84 | { |
|---|
| 85 | fr += 4; |
|---|
| 86 | } |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | if (fr[0].matchWord("factors")) { |
|---|
| 90 | if (fr[1].getFloat(domain.r1) && fr[2].getFloat(domain.r2)) |
|---|
| 91 | { |
|---|
| 92 | fr += 3; |
|---|
| 93 | } |
|---|
| 94 | } |
|---|
| 95 | dp.addDomain(domain); |
|---|
| 96 | |
|---|
| 97 | ++fr; |
|---|
| 98 | itAdvanced = true; |
|---|
| 99 | } |
|---|
| 100 | return itAdvanced; |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | bool DomainOperator_writeLocalData(const osg::Object &obj, osgDB::Output &fw) |
|---|
| 104 | { |
|---|
| 105 | const osgParticle::DomainOperator &dp = static_cast<const osgParticle::DomainOperator &>(obj); |
|---|
| 106 | |
|---|
| 107 | for(unsigned int i=0;i<dp.getNumDomains();++i) |
|---|
| 108 | { |
|---|
| 109 | const osgParticle::DomainOperator::Domain& domain = dp.getDomain(i); |
|---|
| 110 | |
|---|
| 111 | switch (domain.type) |
|---|
| 112 | { |
|---|
| 113 | case osgParticle::DomainOperator::Domain::POINT_DOMAIN: |
|---|
| 114 | fw.indent() << "domain point {" << std::endl; break; |
|---|
| 115 | case osgParticle::DomainOperator::Domain::LINE_DOMAIN: |
|---|
| 116 | fw.indent() << "domain line {" << std::endl; break; |
|---|
| 117 | case osgParticle::DomainOperator::Domain::TRI_DOMAIN: |
|---|
| 118 | fw.indent() << "domain triangle {" << std::endl; break; |
|---|
| 119 | case osgParticle::DomainOperator::Domain::RECT_DOMAIN: |
|---|
| 120 | fw.indent() << "domain rectangle {" << std::endl; break; |
|---|
| 121 | case osgParticle::DomainOperator::Domain::PLANE_DOMAIN: |
|---|
| 122 | fw.indent() << "domain plane {" << std::endl; break; |
|---|
| 123 | case osgParticle::DomainOperator::Domain::SPHERE_DOMAIN: |
|---|
| 124 | fw.indent() << "domain sphere {" << std::endl; break; |
|---|
| 125 | case osgParticle::DomainOperator::Domain::BOX_DOMAIN: |
|---|
| 126 | fw.indent() << "domain box {" << std::endl; break; |
|---|
| 127 | case osgParticle::DomainOperator::Domain::DISK_DOMAIN: |
|---|
| 128 | fw.indent() << "domain disk {" << std::endl; break; |
|---|
| 129 | default: |
|---|
| 130 | fw.indent() << "domain undefined {" << std::endl; break; |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | fw.moveIn(); |
|---|
| 134 | fw.indent() << "plane " << domain.plane << std::endl; |
|---|
| 135 | fw.indent() << "vertices1 " << domain.v1 << std::endl; |
|---|
| 136 | fw.indent() << "vertices2 " << domain.v2 << std::endl; |
|---|
| 137 | fw.indent() << "vertices3 " << domain.v3 << std::endl; |
|---|
| 138 | fw.indent() << "basis1 " << domain.s1 << std::endl; |
|---|
| 139 | fw.indent() << "basis2 " << domain.s2 << std::endl; |
|---|
| 140 | fw.indent() << "factors " << domain.r1 << " " << domain.r2 << std::endl; |
|---|
| 141 | |
|---|
| 142 | fw.moveOut(); |
|---|
| 143 | fw.indent() << "}" << std::endl; |
|---|
| 144 | } |
|---|
| 145 | return true; |
|---|
| 146 | } |
|---|