llvotree.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /**
  2. * @file llvotree.h
  3. * @brief LLVOTree class header file
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewergpl$
  6. *
  7. * Copyright (c) 2002-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLVOTREE_H
  33. #define LL_LLVOTREE_H
  34. #include "hbfastmap.h"
  35. #include "llxform.h"
  36. #include "lldrawpooltree.h"
  37. #include "llviewerobject.h"
  38. class LLFace;
  39. class LLDrawPool;
  40. class LLSelectNode;
  41. class LLViewerFetchedTexture;
  42. constexpr U32 MAX_NUM_TREE_LOD_LEVELS = 4;
  43. constexpr F32 TRUNK_STIFF = 22.f * DEG_TO_RAD;
  44. class LLVOTree final : public LLViewerObject
  45. {
  46. friend class LLDrawPoolTree;
  47. protected:
  48. LOG_CLASS(LLVOTree);
  49. ~LLVOTree() override;
  50. public:
  51. enum
  52. {
  53. VERTEX_DATA_MASK = (1 << LLVertexBuffer::TYPE_VERTEX) |
  54. (1 << LLVertexBuffer::TYPE_NORMAL) |
  55. (1 << LLVertexBuffer::TYPE_TEXCOORD0)
  56. };
  57. LLVOTree(const LLUUID& id, LLViewerRegion* regionp);
  58. // Call these only once:
  59. static void initClass();
  60. static void cleanupClass();
  61. // Call this whenever needed:
  62. static void updateSettings();
  63. static bool isTreeRenderingStopped();
  64. U32 processUpdateMessage(LLMessageSystem* mesgsys, void** user_data,
  65. U32 block_num, EObjectUpdateType upd_type,
  66. LLDataPacker* dp) override;
  67. void idleUpdate(F64 time) override;
  68. void setPixelAreaAndAngle() override;
  69. void updateTextures() override;
  70. LLDrawable* createDrawable() override;
  71. bool updateGeometry(LLDrawable* drawable) override;
  72. void updateSpatialExtents(LLVector4a& min, LLVector4a& max) override;
  73. U32 getPartitionType() const override;
  74. LL_INLINE void resetVertexBuffers() override
  75. {
  76. mReferenceBuffer = mUpdateMeshBuffer = NULL;
  77. }
  78. LL_INLINE LLViewerFetchedTexture* getTreeTexture() { return mTreeImagep.get(); }
  79. void updateRadius() override;
  80. void calcNumVerts(U32& vert_count, U32& index_count, S32 trunk_LOD,
  81. S32 stop_level, U16 depth, U16 trunk_depth,
  82. F32 branches);
  83. void updateMesh();
  84. void appendMesh(LLStrider<LLVector3>& vertices,
  85. LLStrider<LLVector3>& normals,
  86. LLStrider<LLVector2>& tex_coords,
  87. LLStrider<LLColor4U>& colors,
  88. LLStrider<U16>& indices, U16& idx_offset,
  89. const LLMatrix4& matrix, const LLMatrix4& norm_mat,
  90. S32 vertex_offset, S32 vertex_count,
  91. S32 index_count, S32 index_offset);
  92. void genBranchPipeline(LLStrider<LLVector3>& vertices,
  93. LLStrider<LLVector3>& normals,
  94. LLStrider<LLVector2>& tex_coords,
  95. LLStrider<LLColor4U>& colors,
  96. LLStrider<U16>& indices, U16& index_offset,
  97. const LLMatrix4& matrix,
  98. S32 trunk_LOD, S32 stop_level,
  99. U16 depth, U16 trunk_depth,
  100. F32 scale, F32 twist, F32 droop,
  101. F32 branches, F32 alpha);
  102. U32 drawBranchPipeline(LLMatrix4& matrix, U16* indicesp, S32 trunk_LOD,
  103. S32 stop_level, U16 depth, U16 trunk_depth,
  104. F32 scale, F32 twist, F32 droop, F32 branches,
  105. F32 alpha);
  106. bool lineSegmentIntersect(const LLVector4a& start, const LLVector4a& end,
  107. // Which face to check, -1=ALL_SIDES
  108. S32 face = -1,
  109. bool pick_transparent = false,
  110. bool pick_rigged = false,
  111. // Which face was hit
  112. S32* face_hit = NULL,
  113. // Intersection point
  114. LLVector4a* intersection = NULL,
  115. // Texture coordinates of the intersection point
  116. LLVector2* tex_coord = NULL,
  117. // Surface normal at the intersection point
  118. LLVector4a* normal = NULL,
  119. // Surface tangent at the intersection point
  120. LLVector4a* tangent = NULL) override;
  121. void generateSilhouette(LLSelectNode* nodep);
  122. private:
  123. void generateSilhouetteVertices(std::vector<LLVector3>& vertices,
  124. std::vector<LLVector3>& normals,
  125. const LLVector3& view_vec,
  126. const LLMatrix4& mat,
  127. const LLMatrix3& norm_mat);
  128. public:
  129. struct TreeSpeciesData
  130. {
  131. LLUUID mTextureID;
  132. F32 mBranchLength; // Scale (length) of tree branches
  133. F32 mDroop; // Droop from vertical (degrees) at each branch recursion
  134. F32 mTwist; // Twist
  135. F32 mBranches; // Number of branches emitted at each recursion level
  136. U8 mDepth; // Number of recursions to tips of branches
  137. F32 mScaleStep; // Multiplier for scale at each recursion level
  138. U8 mTrunkDepth;
  139. F32 mLeafScale; // Scales leaf texture when rendering
  140. F32 mTrunkLength; // Scales branch diameters when rendering
  141. F32 mBillboardScale; // Scales the billboard representation
  142. F32 mBillboardRatio; // Height to width aspect ratio
  143. F32 mTrunkAspect;
  144. F32 mBranchAspect;
  145. F32 mRandomLeafRotate;
  146. F32 mNoiseScale; // Scaling of noise function in perlin space (norm = 1.0)
  147. F32 mNoiseMag; // amount of perlin noise to deform by (0 = none)
  148. F32 mTaper; // amount of perlin noise to deform by (0 = none)
  149. F32 mRepeatTrunkZ; // Times to repeat the trunk texture vertically along trunk
  150. };
  151. static F32 sTreeFactor; // Tree level of detail factor
  152. static S32 sMaxTreeSpecies;
  153. static F32 sTreeAnimationDamping;
  154. static F32 sTreeTrunkStiffness;
  155. static F32 sTreeWindSensitivity;
  156. static bool sRenderAnimateTrees;
  157. typedef std::map<std::string, S32> species_list_t;
  158. static species_list_t sSpeciesNames;
  159. protected:
  160. TreeSpeciesData* mSpeciesData;
  161. // Reference geometry for generating tree mesh
  162. LLPointer<LLVertexBuffer> mReferenceBuffer;
  163. // Auxilliary buffer used when updating tree mesh
  164. LLPointer<LLVertexBuffer> mUpdateMeshBuffer;
  165. // Pointer to proper tree image
  166. LLPointer<LLViewerFetchedTexture> mTreeImagep;
  167. // Accumulated wind (used for blowing trees)
  168. LLVector3 mTrunkBend;
  169. LLVector3 mTrunkVel;
  170. LLVector3 mWind;
  171. // Complete rebuild when not animating
  172. LLVector3 mLastPosition;
  173. LLQuaternion mLastRotation;
  174. U32 mFrameCount;
  175. F32 mBranchLength; // Scale (length) of tree branches
  176. F32 mTrunkLength; // Trunk length (first recursion)
  177. F32 mDroop; // Droop from vertical (degrees) at each branch recursion
  178. F32 mTwist; // Twist
  179. F32 mBranches; // Number of branches emitted at each recursion level
  180. F32 mScaleStep; // Multiplier for scale at each recursion level
  181. U32 mTrunkLOD;
  182. F32 mLeafScale; // Scales leaf texture when rendering
  183. F32 mBillboardScale; // How big to draw the billboard?
  184. F32 mBillboardRatio; // Height to width ratio of billboard
  185. F32 mTrunkAspect; // Ratio between width/length of trunk
  186. F32 mBranchAspect; // Ratio between width/length of branch
  187. F32 mRandomLeafRotate; // How much to randomly rotate leaves about arbitrary axis
  188. U8 mSpecies; // Species of tree
  189. U8 mDepth; // Number of recursions to tips of branches
  190. U8 mTrunkDepth;
  191. typedef flat_hmap<U32, TreeSpeciesData*> data_map_t;
  192. static data_map_t sSpeciesTable;
  193. static S32 sLODIndexOffset[4];
  194. static S32 sLODIndexCount[4];
  195. static S32 sLODVertexOffset[4];
  196. static S32 sLODVertexCount[4];
  197. static S32 sLODSlices[4];
  198. static F32 sLODAngles[4];
  199. };
  200. #endif