llpartdata.h

Go to the documentation of this file.
00001 
00032 #ifndef LL_LLPARTDATA_H
00033 #define LL_LLPARTDATA_H
00034 
00035 #include "lluuid.h"
00036 #include "v3math.h"
00037 #include "v3dmath.h"
00038 #include "v2math.h"
00039 #include "v4color.h"
00040 
00041 class LLMessageSystem;
00042 class LLDataPacker;
00043 
00044 const S32 PS_CUR_VERSION = 18;
00045 
00046 //
00047 // These constants are used by the script code, not by the particle system itself
00048 //
00049 
00050 enum LLPSScriptFlags
00051 {
00052         // Flags for the different parameters of individual particles
00053         LLPS_PART_FLAGS,
00054         LLPS_PART_START_COLOR,
00055         LLPS_PART_START_ALPHA,
00056         LLPS_PART_END_COLOR,
00057         LLPS_PART_END_ALPHA,
00058         LLPS_PART_START_SCALE,
00059         LLPS_PART_END_SCALE,
00060         LLPS_PART_MAX_AGE,
00061 
00062         // Flags for the different parameters of the particle source
00063         LLPS_SRC_ACCEL,
00064         LLPS_SRC_PATTERN,
00065         LLPS_SRC_INNERANGLE,
00066         LLPS_SRC_OUTERANGLE,
00067         LLPS_SRC_TEXTURE,
00068         LLPS_SRC_BURST_RATE,
00069         LLPS_SRC_BURST_DURATION,
00070         LLPS_SRC_BURST_PART_COUNT,
00071         LLPS_SRC_BURST_RADIUS,
00072         LLPS_SRC_BURST_SPEED_MIN,
00073         LLPS_SRC_BURST_SPEED_MAX,
00074         LLPS_SRC_MAX_AGE,
00075         LLPS_SRC_TARGET_UUID,
00076         LLPS_SRC_OMEGA,
00077         LLPS_SRC_ANGLE_BEGIN,
00078         LLPS_SRC_ANGLE_END
00079 };
00080 
00081 
00082 class LLPartData
00083 {
00084 public:
00085         LLPartData() :
00086                 mFlags(0),
00087                 mMaxAge(0)
00088         {
00089         }
00090         BOOL unpack(LLDataPacker &dp);
00091         BOOL pack(LLDataPacker &dp);
00092         LLSD asLLSD() const;
00093         operator LLSD() const {return asLLSD(); }
00094         bool fromLLSD(LLSD& sd);
00095 
00096         // Masks for the different particle flags
00097         enum
00098         {
00099                 LL_PART_INTERP_COLOR_MASK =             0x01,
00100                 LL_PART_INTERP_SCALE_MASK =             0x02,
00101                 LL_PART_BOUNCE_MASK =                   0x04,
00102                 LL_PART_WIND_MASK =                             0x08,
00103                 LL_PART_FOLLOW_SRC_MASK =               0x10,           // Follows source, no rotation following (expensive!)
00104                 LL_PART_FOLLOW_VELOCITY_MASK =  0x20,           // Particles orient themselves with velocity
00105                 LL_PART_TARGET_POS_MASK =               0x40,
00106                 LL_PART_TARGET_LINEAR_MASK =    0x80,           // Particle uses a direct linear interpolation
00107                 LL_PART_EMISSIVE_MASK =                 0x100,          // Particle is "emissive", instead of being lit
00108                 LL_PART_BEAM_MASK =                             0x200,          // Particle is a "beam" connecting source and target
00109 
00110                 // Not implemented yet!
00111                 //LL_PART_RANDOM_ACCEL_MASK =           0x100,          // Patricles have random accelearation
00112                 //LL_PART_RANDOM_VEL_MASK =             0x200,          // Particles have random velocity shifts"
00113                 //LL_PART_TRAIL_MASK =                  0x400,          // Particles have historical "trails"
00114 
00115                 // Viewer side use only!
00116                 LL_PART_DEAD_MASK =                             0x80000000,
00117         };
00118 
00119         void setFlags(const U32 flags);
00120         void setMaxAge(const F32 max_age);
00121         void setStartScale(const F32 xs, F32 ys);
00122         void setEndScale(const F32 xs, F32 ys);
00123         void setStartColor(const LLVector3 &rgb);
00124         void setEndColor(const LLVector3 &rgb);
00125         void setStartAlpha(const F32 alpha);
00126         void setEndAlpha(const F32 alpha);
00127 
00128 
00129         friend class LLPartSysData;
00130         friend class LLViewerPartSourceScript;
00131 
00132         // These are public because I'm really lazy...
00133 public:
00134         U32                                     mFlags;                                         // Particle state/interpolators in effect
00135         F32                                     mMaxAge;                                        // Maximum age of the particle
00136         LLColor4                        mStartColor;                            // Start color
00137         LLColor4                        mEndColor;                                      // End color
00138         LLVector2                       mStartScale;                            // Start scale
00139         LLVector2                       mEndScale;                                      // End scale
00140 
00141         LLVector3                       mPosOffset;                                     // Offset from source if using FOLLOW_SOURCE
00142         F32                                     mParameter;                                     // A single floating point parameter
00143 };
00144 
00145 
00146 class LLPartSysData
00147 {
00148 public:
00149         LLPartSysData();
00150 
00151         BOOL unpack(LLDataPacker &dp);
00152         BOOL pack(LLDataPacker &dp);
00153 
00154         
00155         BOOL unpackBlock(const S32 block_num);
00156         BOOL packBlock();
00157 
00158         static BOOL packNull();
00159         static BOOL isNullPS(const S32 block_num); // Returns FALSE if this is a "NULL" particle system (i.e. no system)
00160 
00161         // Different masks for effects on the source
00162         enum
00163         {
00164                 LL_PART_SRC_OBJ_REL_MASK                =       0x01,           // Accel and velocity for particles relative object rotation
00165                 LL_PART_USE_NEW_ANGLE                   =       0x02,           // Particles uses new 'correct' angle parameters.
00166         };
00167 
00168         // The different patterns for how particles are created
00169         enum
00170         {
00171                 LL_PART_SRC_PATTERN_DROP =                              0x01,
00172                 LL_PART_SRC_PATTERN_EXPLODE =                   0x02,
00173                 // Not implemented fully yet
00174                 LL_PART_SRC_PATTERN_ANGLE =                             0x04,
00175                 LL_PART_SRC_PATTERN_ANGLE_CONE =                0x08,
00176                 LL_PART_SRC_PATTERN_ANGLE_CONE_EMPTY =  0x10,
00177         };
00178 
00179 
00180         void setBurstSpeedMin(const F32 spd) {  mBurstSpeedMin = llclamp(spd, -100.f, 100.f); }
00181         void setBurstSpeedMax(const F32 spd) {  mBurstSpeedMax = llclamp(spd, -100.f, 100.f); }
00182         void setBurstRadius(const F32 rad)       {      mBurstRadius = llclamp(rad, 0.f, 50.f); }
00183         void setPartAccel(const LLVector3 &accel);
00184         void setUseNewAngle()   { mFlags |=  LL_PART_USE_NEW_ANGLE; }
00185         void unsetUseNewAngle() { mFlags &= ~LL_PART_USE_NEW_ANGLE; }
00186 
00187         // Since the actual particle creation rate is
00188         // a combination of multiple parameters, we
00189         // need to clamp it using a separate method instead of an accessor.
00190         void clampSourceParticleRate();
00191         
00192         friend std::ostream&     operator<<(std::ostream& s, const LLPartSysData &data);                // Stream a
00193         
00194 public:
00195         // Public because I'm lazy....
00196 
00197         //
00198         // There are two kinds of data for the particle system
00199         // 1. Parameters which specify parameters of the source (mSource*)
00200         // 2. Parameters which specify parameters of the particles generated by the source (mPart*)
00201         //
00202 
00203         U32             mCRC;
00204         U32             mFlags;
00205 
00206         U8              mPattern;                                               // Pattern for particle velocity/output
00207         F32             mInnerAngle;                                    // Inner angle for PATTERN_ANGLE
00208         F32             mOuterAngle;                                    // Outer angle for PATTERN_ANGLE
00209         LLVector3 mAngularVelocity;                             // Angular velocity for emission axis (for PATTERN_ANGLE)
00210 
00211         F32             mBurstRate;                                             // How often to do a burst of particles
00212         U8              mBurstPartCount;                                // How many particles in a burst
00213         F32             mBurstRadius;
00214         F32             mBurstSpeedMin;                                 // Minimum particle velocity
00215         F32             mBurstSpeedMax;                                 // Maximum particle velocity
00216 
00217         F32             mMaxAge;                                                // Maximum lifetime of this particle source
00218 
00219         LLUUID  mTargetUUID;                                    // Target UUID for the particle system
00220 
00221         F32             mStartAge;                                              // Age at which to start the particle system (for an update after the
00222                                                                                         // particle system has started)
00223 
00224 
00225         //
00226         // These are actually particle properties, but can be mutated by the source,
00227         // so are stored here instead
00228         //
00229         LLVector3       mPartAccel;
00230         LLUUID          mPartImageID;
00231 
00232         //
00233         // The "template" partdata where we actually store the non-mutable particle parameters
00234         //
00235         LLPartData      mPartData;
00236 
00237 protected:
00238         S32             mNumParticles;                                  // Number of particles generated
00239 };
00240 
00241 #endif // LL_LLPARTDATA_H

Generated on Thu Jul 1 06:09:00 2010 for Second Life Viewer by  doxygen 1.4.7