llvotreenew.h

Go to the documentation of this file.
00001 
00032 #ifndef LL_LLVOTREENEW_H
00033 #define LL_LLVOTREENEW_H
00034 
00035 #include "llviewerobject.h"
00036 #include "lldarray.h"
00037 #include "xform.h"
00038 
00039 #include "lltreeparams.h"
00040 #include "llstrider.h"
00041 #include "v2math.h"
00042 #include "v3math.h"
00043 #include "llviewerimage.h"
00044 
00045 class LLFace;
00046 class LLDrawPool;
00047 
00048 // number of static arrays created
00049 const U8 MAX_SPECIES = 16;      // max species of trees
00050 const U8 MAX_PARTS = 15;        // trunk, 2 or 3 branches per species?
00051 const U8 MAX_RES = 6;           // max # cross sections for a branch curve
00052 const U8 MAX_FLARE = 6;         // max # cross sections for flare of trunk
00053 const U8 MAX_LEVELS = 3;
00054 
00055 // initial vertex array allocations
00056 const U32 NUM_INIT_VERTS = 5000;                        // number of vertices/normals/texcoords
00057 const U32 NUM_INIT_INDICES = 15000;                     // number of indices to vert array (3 vertices per triangle, roughly 3x)
00058 const U32 NUM_TIMES_TO_DOUBLE = 2;                      // if we go over initial allocations, num times to double each step
00059 
00060 // for finding the closest parts...
00061 
00062 // the parts are searched based on:
00063 const F32 MAX_LOBES_DIFF = 2;
00064 const F32 MAX_LOBEDEPTH_DIFF = .3f;
00065 const F32 MAX_CURVEBACK_DIFF = 20.0f;
00066 const F32 MAX_CURVE_DIFF = 15.0f;
00067 const F32 MAX_CURVE_V_DIFF = 20.0f;
00068 
00069 const F32 CURVEV_DIVIDER = 10.0f;       // curveV/CURVEV_DIVIDER = # branch variances...
00070 const U8 MAX_VARS = 3;                          // max number of variations of branches
00071 
00072 const U8 MAX_RAND_NUMS = 100;           // max number of rand numbers to pregenerate and store
00073 
00074 // texture params
00075 const F32 WIDTH_OF_BARK = .48f;
00076 
00077 class LLVOTreeNew : public LLViewerObject
00078 {
00079 public:
00080 
00081         // Some random number generators using the pre-generated random numbers
00082         // return +- negPos
00083         static S32 llrand_signed(S32 negPos)
00084         {
00085                 return (ll_rand((U32)negPos * 2) - negPos);
00086         };
00087 
00088         static S32 llrand_signed(S32 negPos, U32 index)
00089         {
00090                 return lltrunc((sRandNums[index % MAX_RAND_NUMS] * (negPos * 2.0f) - negPos));
00091         };
00092         
00093         static S32 llrand_unsigned(S32 pos, U32 index)
00094         {
00095                 return lltrunc((sRandNums[index % MAX_RAND_NUMS] * pos));
00096         };
00097 
00098         // return +- negPos
00099         static F32 llfrand_signed(F32 negPos)
00100         {
00101                 return (ll_frand(negPos * 2.0f) - negPos);
00102         };
00103 
00104         static F32 llfrand_signed(F32 negPos, U32 index)
00105         {
00106                 return (sRandNums[index % MAX_RAND_NUMS] * negPos * 2.0f) - negPos;
00107         };
00108 
00109         static F32 llfrand_unsigned(F32 pos, U32 index)
00110         {
00111                 return sRandNums[index % MAX_RAND_NUMS] * pos;
00112         };
00113 
00114         // return between 0-pos
00115         static F32 llfrand_unsigned(F32 pos)
00116         {
00117                 return ll_frand(pos);
00118         };
00119 
00120         static void cleanupTextures() {};       // not needed anymore
00121 
00122         struct TreePart
00123         {
00124                 F32 mRadius;            // scale x/y
00125                 F32 mLength;            // scale z
00126                 F32 mCurve;
00127                 F32 mCurveV;
00128                 F32 mCurveRes;
00129                 F32 mCurveBack;
00130                 U8 mLobes;
00131                 F32 mLobeDepth;
00132                 U8 mLevel;
00133                 U32 mNumTris;
00134                 U8 mVertsPerSection;
00135                 U8 mNumVariants;
00136 
00137                 // first index into the drawpool arrays for this particular branch
00138                 U32 mIndiceIndex[MAX_VARS];
00139                 U32 mOffsets[MAX_VARS][MAX_RES];                // offsets for the partial branch pieces
00140                 // local section frames for this branch
00141                 LLMatrix4 mFrames[MAX_VARS][(MAX_RES*(MAX_RES + 1))/2]; // (0...n) + (1...n) + ... + (n-1..n)
00142                 LLDynamicArray<LLVector3> mFaceNormals;
00143 
00144         };
00145 
00146         LLVOTreeNew(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp);
00147         virtual ~LLVOTreeNew();
00148 
00149         /*virtual*/ 
00150         U32 processUpdateMessage(LLMessageSystem *mesgsys,
00151                                                                                         void **user_data,
00152                                                                                         U32 block_num, const EObjectUpdateType update_type,
00153                                                                                         LLDataPacker *dp);
00154 
00155         /*virtual*/ BOOL idleUpdate(LLAgent &agent, LLWorld &world, const F64 &time);
00156 
00157         /*virtual*/ void render(LLAgent &agent);
00158         /*virtual*/ void updateTextures(LLAgent &agent);
00159 
00160         /*virtual*/ LLDrawable* createDrawable(LLPipeline *pipeline);
00161         /*virtual*/ BOOL                updateGeometry(LLDrawable *drawable);
00162 
00163         F32 CalcZStep(TreePart *part, U8 section);
00164 
00165         void createPart(U8 level, F32 length, F32 radius, LLStrider<LLVector3> &vertices, LLStrider<LLVector3> &normals, 
00166                                                         LLStrider<LLVector2> &tex_coords, U32 *indices, 
00167                                                         U32 &curVertexIndex, U32 &curTexCoordIndex,
00168                                                         U32 &curNormalIndex, U32 &curIndiceIndex);
00169 
00170         S32 findSimilarPart(U8 level);
00171 
00172         F32 CalculateSectionRadius(U8 level, F32 y, F32 stemLength, F32 stemRadius);
00173         //F32 CalculateVerticalAttraction(U8 level, LLMatrix4 &sectionFrame);
00174 
00175         void createSection(LLMatrix4 &frame, TreePart *part, F32 sectionRadius, F32 stemZ, 
00176                                                           LLStrider<LLVector3> &vertices, LLStrider<LLVector2> &tex_coords, U32 *indices, 
00177                                                           U32 &curVertexIndex, U32 &curTexCoordIndex, U32 &curIndiceIndex, U8 curSection, BOOL firstBranch);
00178 
00179         void genIndicesAndFaceNormalsForLastSection(TreePart *part, U8 numVerts, LLStrider<LLVector3> &vertices, U32 curVertexIndex, U32 *indices, U32 &curIndiceIndex, BOOL firstBranch);
00180 
00181         void genVertexNormals(TreePart *part, LLStrider<LLVector3> &normals, U8 numSections, U32 curNormalOffset);
00182 
00183         void drawTree(LLDrawPool &draw_pool, const LLMatrix4 &frame, U8 level, F32 offsetChild, F32 curLength, F32 parentLength, F32 curRadius, F32 parentRadius, U8 part, U8 variant, U8 startSection);
00184         void drawTree(LLDrawPool &draw_pool);
00185 
00186         
00187         //LLTreeParams mParams;
00188         U8 mSpecies;
00189         LLPointer<LLViewerImage> mTreeImagep;
00190         LLMatrix4 mTrunkFlareFrames[MAX_FLARE];
00191         F32 mSegSplitsError[3];
00192         U32 mRandOffset[MAX_LEVELS];
00193 
00194         U32 mNumTrisDrawn;
00195         U32 mTotalIndices;
00196         U32 mTotalVerts;
00197 
00198         static void initClass();
00199 
00200         // tree params
00201         static LLTreeParams sParameters;
00202 
00203         // next indexes used to drawpool arrays
00204         static U32 sNextVertexIndex[MAX_SPECIES];
00205         static U32 sNextIndiceIndex[MAX_SPECIES];
00206 
00207         // tree parts
00208         static U32 sNextPartIndex[MAX_PARTS];
00209         static TreePart sTreeParts[MAX_SPECIES][MAX_PARTS];
00210 
00211         // species images
00212         static LLUUID sTreeImageIDs[MAX_SPECIES];
00213 
00214         // random numbers
00215         static F32 sRandNums[MAX_RAND_NUMS];
00216 
00217         // usage data
00218         static U32 sTreePartsUsed[MAX_SPECIES][MAX_PARTS][MAX_VARS];
00219         
00220         
00221 };
00222 
00223 #endif

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