| 1 | #include <osgParticle/Particle> |
|---|
| 2 | #include <osgDB/ObjectWrapper> |
|---|
| 3 | #include <osgDB/InputStream> |
|---|
| 4 | #include <osgDB/OutputStream> |
|---|
| 5 | |
|---|
| 6 | BEGIN_USER_TABLE( Shape, osgParticle::Particle ); |
|---|
| 7 | ADD_USER_VALUE( POINT ); |
|---|
| 8 | ADD_USER_VALUE( QUAD ); |
|---|
| 9 | ADD_USER_VALUE( QUAD_TRIANGLESTRIP ); |
|---|
| 10 | ADD_USER_VALUE( HEXAGON ); |
|---|
| 11 | ADD_USER_VALUE( LINE ); |
|---|
| 12 | ADD_USER_VALUE( USER ); |
|---|
| 13 | END_USER_TABLE() |
|---|
| 14 | |
|---|
| 15 | USER_READ_FUNC( Shape, readShapeValue ) |
|---|
| 16 | USER_WRITE_FUNC( Shape, writeShapeValue ) |
|---|
| 17 | |
|---|
| 18 | bool readParticle( osgDB::InputStream& is, osgParticle::Particle& p ) |
|---|
| 19 | { |
|---|
| 20 | is >> osgDB::BEGIN_BRACKET; |
|---|
| 21 | |
|---|
| 22 | is >> osgDB::PROPERTY("Shape"); |
|---|
| 23 | p.setShape( static_cast<osgParticle::Particle::Shape>(readShapeValue(is)) ); |
|---|
| 24 | |
|---|
| 25 | double lifeTime; is >> osgDB::PROPERTY("LifeTime") >> lifeTime; |
|---|
| 26 | p.setLifeTime( lifeTime ); |
|---|
| 27 | |
|---|
| 28 | float min, max; osg::Vec4d minV, maxV; |
|---|
| 29 | is >> osgDB::PROPERTY("SizeRange") >> min >> max; p.setSizeRange( osgParticle::rangef(min, max) ); |
|---|
| 30 | is >> osgDB::PROPERTY("AlphaRange") >> min >> max; p.setAlphaRange( osgParticle::rangef(min, max) ); |
|---|
| 31 | is >> osgDB::PROPERTY("ColorRange") >> minV >> maxV; p.setColorRange( osgParticle::rangev4(minV, maxV) ); |
|---|
| 32 | |
|---|
| 33 | bool hasInterpolator = false; |
|---|
| 34 | is >> osgDB::PROPERTY("SizeInterpolator") >> hasInterpolator; |
|---|
| 35 | if ( hasInterpolator ) |
|---|
| 36 | { |
|---|
| 37 | is >> osgDB::BEGIN_BRACKET; |
|---|
| 38 | p.setSizeInterpolator( static_cast<osgParticle::Interpolator*>(is.readObject()) ); |
|---|
| 39 | is >> osgDB::END_BRACKET; |
|---|
| 40 | } |
|---|
| 41 | is >> osgDB::PROPERTY("AlphaInterpolator") >> hasInterpolator; |
|---|
| 42 | if ( hasInterpolator ) |
|---|
| 43 | { |
|---|
| 44 | is >> osgDB::BEGIN_BRACKET; |
|---|
| 45 | p.setAlphaInterpolator( static_cast<osgParticle::Interpolator*>(is.readObject()) ); |
|---|
| 46 | is >> osgDB::END_BRACKET; |
|---|
| 47 | } |
|---|
| 48 | is >> osgDB::PROPERTY("ColorInterpolator") >> hasInterpolator; |
|---|
| 49 | if ( hasInterpolator ) |
|---|
| 50 | { |
|---|
| 51 | is >> osgDB::BEGIN_BRACKET; |
|---|
| 52 | p.setColorInterpolator( static_cast<osgParticle::Interpolator*>(is.readObject()) ); |
|---|
| 53 | is >> osgDB::END_BRACKET; |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | float radius; is >> osgDB::PROPERTY("Radius") >> radius; |
|---|
| 57 | float mass; is >> osgDB::PROPERTY("Mass") >> mass; |
|---|
| 58 | osg::Vec3d pos; is >> osgDB::PROPERTY("Position") >> pos; |
|---|
| 59 | osg::Vec3d vel; is >> osgDB::PROPERTY("Velocity") >> vel; |
|---|
| 60 | osg::Vec3d angle; is >> osgDB::PROPERTY("Angle") >> angle; |
|---|
| 61 | osg::Vec3d angleV; is >> osgDB::PROPERTY("AngularVelocity") >> angleV; |
|---|
| 62 | int s, t, num; is >> osgDB::PROPERTY("TextureTile") >> s >> t >> num; |
|---|
| 63 | |
|---|
| 64 | p.setRadius( radius ); |
|---|
| 65 | p.setMass( mass ); |
|---|
| 66 | p.setPosition( pos ); |
|---|
| 67 | p.setVelocity( vel ); |
|---|
| 68 | p.setAngle( angle ); |
|---|
| 69 | p.setAngularVelocity( angleV ); |
|---|
| 70 | p.setTextureTile( s, t, num ); |
|---|
| 71 | |
|---|
| 72 | bool hasObject = false; is >> osgDB::PROPERTY("Drawable") >> hasObject; |
|---|
| 73 | if ( hasObject ) |
|---|
| 74 | { |
|---|
| 75 | is >> osgDB::BEGIN_BRACKET; |
|---|
| 76 | p.setDrawable( dynamic_cast<osg::Drawable*>(is.readObject()) ); |
|---|
| 77 | is >> osgDB::END_BRACKET; |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | is >> osgDB::END_BRACKET; |
|---|
| 81 | return true; |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | bool writeParticle( osgDB::OutputStream& os, const osgParticle::Particle& p ) |
|---|
| 85 | { |
|---|
| 86 | os << osgDB::BEGIN_BRACKET << std::endl; |
|---|
| 87 | |
|---|
| 88 | os << osgDB::PROPERTY("Shape"); writeShapeValue( os, (int)p.getShape() ); os << std::endl; |
|---|
| 89 | |
|---|
| 90 | os << osgDB::PROPERTY("LifeTime") << p.getLifeTime() << std::endl; |
|---|
| 91 | os << osgDB::PROPERTY("SizeRange") << p.getSizeRange().minimum << p.getSizeRange().maximum << std::endl; |
|---|
| 92 | os << osgDB::PROPERTY("AlphaRange") << p.getAlphaRange().minimum << p.getAlphaRange().maximum << std::endl; |
|---|
| 93 | os << osgDB::PROPERTY("ColorRange") << osg::Vec4d(p.getColorRange().minimum) |
|---|
| 94 | << osg::Vec4d(p.getColorRange().maximum) << std::endl; |
|---|
| 95 | |
|---|
| 96 | os << osgDB::PROPERTY("SizeInterpolator") << (p.getSizeInterpolator()!=NULL); |
|---|
| 97 | if ( p.getSizeInterpolator()!=NULL ) |
|---|
| 98 | os << osgDB::BEGIN_BRACKET << std::endl << p.getSizeInterpolator() << osgDB::END_BRACKET << std::endl; |
|---|
| 99 | os << osgDB::PROPERTY("AlphaInterpolator") << (p.getAlphaInterpolator()!=NULL); |
|---|
| 100 | if ( p.getAlphaInterpolator()!=NULL ) |
|---|
| 101 | os << osgDB::BEGIN_BRACKET << std::endl << p.getAlphaInterpolator() << osgDB::END_BRACKET << std::endl; |
|---|
| 102 | os << osgDB::PROPERTY("ColorInterpolator") << (p.getColorInterpolator()!=NULL); |
|---|
| 103 | if ( p.getColorInterpolator()!=NULL ) |
|---|
| 104 | os << osgDB::BEGIN_BRACKET << std::endl << p.getColorInterpolator() << osgDB::END_BRACKET << std::endl; |
|---|
| 105 | |
|---|
| 106 | os << osgDB::PROPERTY("Radius") << p.getRadius() << std::endl; |
|---|
| 107 | os << osgDB::PROPERTY("Mass") << p.getMass() << std::endl; |
|---|
| 108 | os << osgDB::PROPERTY("Position") << osg::Vec3d(p.getPosition()) << std::endl; |
|---|
| 109 | os << osgDB::PROPERTY("Velocity") << osg::Vec3d(p.getVelocity()) << std::endl; |
|---|
| 110 | os << osgDB::PROPERTY("Angle") << osg::Vec3d(p.getAngle()) << std::endl; |
|---|
| 111 | os << osgDB::PROPERTY("AngularVelocity") << osg::Vec3d(p.getAngularVelocity()) << std::endl; |
|---|
| 112 | os << osgDB::PROPERTY("TextureTile") << p.getTileS() << p.getTileT() << p.getNumTiles() << std::endl; |
|---|
| 113 | |
|---|
| 114 | os << osgDB::PROPERTY("Drawable") << (p.getDrawable()!=NULL); |
|---|
| 115 | if ( p.getDrawable()!=NULL ) |
|---|
| 116 | { |
|---|
| 117 | os << osgDB::BEGIN_BRACKET << std::endl; |
|---|
| 118 | os.writeObject( p.getDrawable() ); |
|---|
| 119 | os << osgDB::END_BRACKET; |
|---|
| 120 | } |
|---|
| 121 | os << std::endl; |
|---|
| 122 | |
|---|
| 123 | os << osgDB::END_BRACKET << std::endl; |
|---|
| 124 | return true; |
|---|
| 125 | } |
|---|