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
00049 const U8 MAX_SPECIES = 16;
00050 const U8 MAX_PARTS = 15;
00051 const U8 MAX_RES = 6;
00052 const U8 MAX_FLARE = 6;
00053 const U8 MAX_LEVELS = 3;
00054
00055
00056 const U32 NUM_INIT_VERTS = 5000;
00057 const U32 NUM_INIT_INDICES = 15000;
00058 const U32 NUM_TIMES_TO_DOUBLE = 2;
00059
00060
00061
00062
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;
00070 const U8 MAX_VARS = 3;
00071
00072 const U8 MAX_RAND_NUMS = 100;
00073
00074
00075 const F32 WIDTH_OF_BARK = .48f;
00076
00077 class LLVOTreeNew : public LLViewerObject
00078 {
00079 public:
00080
00081
00082
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
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
00115 static F32 llfrand_unsigned(F32 pos)
00116 {
00117 return ll_frand(pos);
00118 };
00119
00120 static void cleanupTextures() {};
00121
00122 struct TreePart
00123 {
00124 F32 mRadius;
00125 F32 mLength;
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
00138 U32 mIndiceIndex[MAX_VARS];
00139 U32 mOffsets[MAX_VARS][MAX_RES];
00140
00141 LLMatrix4 mFrames[MAX_VARS][(MAX_RES*(MAX_RES + 1))/2];
00142 LLDynamicArray<LLVector3> mFaceNormals;
00143
00144 };
00145
00146 LLVOTreeNew(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp);
00147 virtual ~LLVOTreeNew();
00148
00149
00150 U32 processUpdateMessage(LLMessageSystem *mesgsys,
00151 void **user_data,
00152 U32 block_num, const EObjectUpdateType update_type,
00153 LLDataPacker *dp);
00154
00155 BOOL idleUpdate(LLAgent &agent, LLWorld &world, const F64 &time);
00156
00157 void render(LLAgent &agent);
00158 void updateTextures(LLAgent &agent);
00159
00160 LLDrawable* createDrawable(LLPipeline *pipeline);
00161 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
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
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
00201 static LLTreeParams sParameters;
00202
00203
00204 static U32 sNextVertexIndex[MAX_SPECIES];
00205 static U32 sNextIndiceIndex[MAX_SPECIES];
00206
00207
00208 static U32 sNextPartIndex[MAX_PARTS];
00209 static TreePart sTreeParts[MAX_SPECIES][MAX_PARTS];
00210
00211
00212 static LLUUID sTreeImageIDs[MAX_SPECIES];
00213
00214
00215 static F32 sRandNums[MAX_RAND_NUMS];
00216
00217
00218 static U32 sTreePartsUsed[MAX_SPECIES][MAX_PARTS][MAX_VARS];
00219
00220
00221 };
00222
00223 #endif