PageRenderTime 101ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llvotreenew.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 218 lines | 124 code | 49 blank | 45 comment | 0 complexity | 09825ab5336ff0da5628e2ea96e2e968 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llvotreenew.h
  3. * @brief LLVOTreeNew class header file
  4. *
  5. * $LicenseInfo:firstyear=2003&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_LLVOTREENEW_H
  27. #define LL_LLVOTREENEW_H
  28. #include "llviewerobject.h"
  29. #include "lldarray.h"
  30. #include "xform.h"
  31. #include "lltreeparams.h"
  32. #include "llstrider.h"
  33. #include "v2math.h"
  34. #include "v3math.h"
  35. #include "llviewertexture.h"
  36. class LLFace;
  37. class LLDrawPool;
  38. // number of static arrays created
  39. const U8 MAX_SPECIES = 16; // max species of trees
  40. const U8 MAX_PARTS = 15; // trunk, 2 or 3 branches per species?
  41. const U8 MAX_RES = 6; // max # cross sections for a branch curve
  42. const U8 MAX_FLARE = 6; // max # cross sections for flare of trunk
  43. const U8 MAX_LEVELS = 3;
  44. // initial vertex array allocations
  45. const U32 NUM_INIT_VERTS = 5000; // number of vertices/normals/texcoords
  46. const U32 NUM_INIT_INDICES = 15000; // number of indices to vert array (3 vertices per triangle, roughly 3x)
  47. const U32 NUM_TIMES_TO_DOUBLE = 2; // if we go over initial allocations, num times to double each step
  48. // for finding the closest parts...
  49. // the parts are searched based on:
  50. const F32 MAX_LOBES_DIFF = 2;
  51. const F32 MAX_LOBEDEPTH_DIFF = .3f;
  52. const F32 MAX_CURVEBACK_DIFF = 20.0f;
  53. const F32 MAX_CURVE_DIFF = 15.0f;
  54. const F32 MAX_CURVE_V_DIFF = 20.0f;
  55. const F32 CURVEV_DIVIDER = 10.0f; // curveV/CURVEV_DIVIDER = # branch variances...
  56. const U8 MAX_VARS = 3; // max number of variations of branches
  57. const U8 MAX_RAND_NUMS = 100; // max number of rand numbers to pregenerate and store
  58. // texture params
  59. const F32 WIDTH_OF_BARK = .48f;
  60. class LLVOTreeNew : public LLViewerObject
  61. {
  62. public:
  63. // Some random number generators using the pre-generated random numbers
  64. // return +- negPos
  65. static S32 llrand_signed(S32 negPos)
  66. {
  67. return (ll_rand((U32)negPos * 2) - negPos);
  68. };
  69. static S32 llrand_signed(S32 negPos, U32 index)
  70. {
  71. return lltrunc((sRandNums[index % MAX_RAND_NUMS] * (negPos * 2.0f) - negPos));
  72. };
  73. static S32 llrand_unsigned(S32 pos, U32 index)
  74. {
  75. return lltrunc((sRandNums[index % MAX_RAND_NUMS] * pos));
  76. };
  77. // return +- negPos
  78. static F32 llfrand_signed(F32 negPos)
  79. {
  80. return (ll_frand(negPos * 2.0f) - negPos);
  81. };
  82. static F32 llfrand_signed(F32 negPos, U32 index)
  83. {
  84. return (sRandNums[index % MAX_RAND_NUMS] * negPos * 2.0f) - negPos;
  85. };
  86. static F32 llfrand_unsigned(F32 pos, U32 index)
  87. {
  88. return sRandNums[index % MAX_RAND_NUMS] * pos;
  89. };
  90. // return between 0-pos
  91. static F32 llfrand_unsigned(F32 pos)
  92. {
  93. return ll_frand(pos);
  94. };
  95. static void cleanupTextures() {}; // not needed anymore
  96. struct TreePart
  97. {
  98. F32 mRadius; // scale x/y
  99. F32 mLength; // scale z
  100. F32 mCurve;
  101. F32 mCurveV;
  102. F32 mCurveRes;
  103. F32 mCurveBack;
  104. U8 mLobes;
  105. F32 mLobeDepth;
  106. U8 mLevel;
  107. U32 mNumTris;
  108. U8 mVertsPerSection;
  109. U8 mNumVariants;
  110. // first index into the drawpool arrays for this particular branch
  111. U32 mIndiceIndex[MAX_VARS];
  112. U32 mOffsets[MAX_VARS][MAX_RES]; // offsets for the partial branch pieces
  113. // local section frames for this branch
  114. LLMatrix4 mFrames[MAX_VARS][(MAX_RES*(MAX_RES + 1))/2]; // (0...n) + (1...n) + ... + (n-1..n)
  115. LLDynamicArray<LLVector3> mFaceNormals;
  116. };
  117. LLVOTreeNew(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp);
  118. virtual ~LLVOTreeNew();
  119. /*virtual*/
  120. U32 processUpdateMessage(LLMessageSystem *mesgsys,
  121. void **user_data,
  122. U32 block_num, const EObjectUpdateType update_type,
  123. LLDataPacker *dp);
  124. /*virtual*/ BOOL idleUpdate(LLAgent &agent, LLWorld &world, const F64 &time);
  125. /*virtual*/ void render(LLAgent &agent);
  126. /*virtual*/ void updateTextures();
  127. /*virtual*/ LLDrawable* createDrawable(LLPipeline *pipeline);
  128. /*virtual*/ BOOL updateGeometry(LLDrawable *drawable);
  129. F32 CalcZStep(TreePart *part, U8 section);
  130. void createPart(U8 level, F32 length, F32 radius, LLStrider<LLVector3> &vertices, LLStrider<LLVector3> &normals,
  131. LLStrider<LLVector2> &tex_coords, U32 *indices,
  132. U32 &curVertexIndex, U32 &curTexCoordIndex,
  133. U32 &curNormalIndex, U32 &curIndiceIndex);
  134. S32 findSimilarPart(U8 level);
  135. F32 CalculateSectionRadius(U8 level, F32 y, F32 stemLength, F32 stemRadius);
  136. //F32 CalculateVerticalAttraction(U8 level, LLMatrix4 &sectionFrame);
  137. void createSection(LLMatrix4 &frame, TreePart *part, F32 sectionRadius, F32 stemZ,
  138. LLStrider<LLVector3> &vertices, LLStrider<LLVector2> &tex_coords, U32 *indices,
  139. U32 &curVertexIndex, U32 &curTexCoordIndex, U32 &curIndiceIndex, U8 curSection, BOOL firstBranch);
  140. void genIndicesAndFaceNormalsForLastSection(TreePart *part, U8 numVerts, LLStrider<LLVector3> &vertices, U32 curVertexIndex, U32 *indices, U32 &curIndiceIndex, BOOL firstBranch);
  141. void genVertexNormals(TreePart *part, LLStrider<LLVector3> &normals, U8 numSections, U32 curNormalOffset);
  142. 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);
  143. void drawTree(LLDrawPool &draw_pool);
  144. //LLTreeParams mParams;
  145. U8 mSpecies;
  146. LLPointer<LLViewerTexture> mTreeImagep;
  147. LLMatrix4 mTrunkFlareFrames[MAX_FLARE];
  148. F32 mSegSplitsError[3];
  149. U32 mRandOffset[MAX_LEVELS];
  150. U32 mNumTrisDrawn;
  151. U32 mTotalIndices;
  152. U32 mTotalVerts;
  153. static void initClass();
  154. // tree params
  155. static LLTreeParams sParameters;
  156. // next indexes used to drawpool arrays
  157. static U32 sNextVertexIndex[MAX_SPECIES];
  158. static U32 sNextIndiceIndex[MAX_SPECIES];
  159. // tree parts
  160. static U32 sNextPartIndex[MAX_PARTS];
  161. static TreePart sTreeParts[MAX_SPECIES][MAX_PARTS];
  162. // species images
  163. static LLUUID sTreeImageIDs[MAX_SPECIES];
  164. // random numbers
  165. static F32 sRandNums[MAX_RAND_NUMS];
  166. // usage data
  167. static U32 sTreePartsUsed[MAX_SPECIES][MAX_PARTS][MAX_VARS];
  168. };
  169. #endif