diff options
Diffstat (limited to 'linden/indra/newview/llvotreenew.h')
-rw-r--r-- | linden/indra/newview/llvotreenew.h | 219 |
1 files changed, 219 insertions, 0 deletions
diff --git a/linden/indra/newview/llvotreenew.h b/linden/indra/newview/llvotreenew.h new file mode 100644 index 0000000..058bd19 --- /dev/null +++ b/linden/indra/newview/llvotreenew.h | |||
@@ -0,0 +1,219 @@ | |||
1 | /** | ||
2 | * @file llvotreenew.h | ||
3 | * @brief LLVOTreeNew class header file | ||
4 | * | ||
5 | * Copyright (c) 2003-2007, Linden Research, Inc. | ||
6 | * | ||
7 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
8 | * to you under the terms of the GNU General Public License, version 2.0 | ||
9 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
10 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
11 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
12 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
13 | * | ||
14 | * There are special exceptions to the terms and conditions of the GPL as | ||
15 | * it is applied to this Source Code. View the full text of the exception | ||
16 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
17 | * online at http://secondlife.com/developers/opensource/flossexception | ||
18 | * | ||
19 | * By copying, modifying or distributing this software, you acknowledge | ||
20 | * that you have read and understood your obligations described above, | ||
21 | * and agree to abide by those obligations. | ||
22 | * | ||
23 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
24 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
25 | * COMPLETENESS OR PERFORMANCE. | ||
26 | */ | ||
27 | |||
28 | #ifndef LL_LLVOTREENEW_H | ||
29 | #define LL_LLVOTREENEW_H | ||
30 | |||
31 | #include "llviewerobject.h" | ||
32 | #include "lldarray.h" | ||
33 | #include "xform.h" | ||
34 | |||
35 | #include "lltreeparams.h" | ||
36 | #include "llstrider.h" | ||
37 | #include "v2math.h" | ||
38 | #include "v3math.h" | ||
39 | #include "llviewerimage.h" | ||
40 | |||
41 | class LLFace; | ||
42 | class LLDrawPool; | ||
43 | |||
44 | // number of static arrays created | ||
45 | const U8 MAX_SPECIES = 16; // max species of trees | ||
46 | const U8 MAX_PARTS = 15; // trunk, 2 or 3 branches per species? | ||
47 | const U8 MAX_RES = 6; // max # cross sections for a branch curve | ||
48 | const U8 MAX_FLARE = 6; // max # cross sections for flare of trunk | ||
49 | const U8 MAX_LEVELS = 3; | ||
50 | |||
51 | // initial vertex array allocations | ||
52 | const U32 NUM_INIT_VERTS = 5000; // number of vertices/normals/texcoords | ||
53 | const U32 NUM_INIT_INDICES = 15000; // number of indices to vert array (3 vertices per triangle, roughly 3x) | ||
54 | const U32 NUM_TIMES_TO_DOUBLE = 2; // if we go over initial allocations, num times to double each step | ||
55 | |||
56 | // for finding the closest parts... | ||
57 | |||
58 | // the parts are searched based on: | ||
59 | const F32 MAX_LOBES_DIFF = 2; | ||
60 | const F32 MAX_LOBEDEPTH_DIFF = .3f; | ||
61 | const F32 MAX_CURVEBACK_DIFF = 20.0f; | ||
62 | const F32 MAX_CURVE_DIFF = 15.0f; | ||
63 | const F32 MAX_CURVE_V_DIFF = 20.0f; | ||
64 | |||
65 | const F32 CURVEV_DIVIDER = 10.0f; // curveV/CURVEV_DIVIDER = # branch variances... | ||
66 | const U8 MAX_VARS = 3; // max number of variations of branches | ||
67 | |||
68 | const U8 MAX_RAND_NUMS = 100; // max number of rand numbers to pregenerate and store | ||
69 | |||
70 | // texture params | ||
71 | const F32 WIDTH_OF_BARK = .48f; | ||
72 | |||
73 | class LLVOTreeNew : public LLViewerObject | ||
74 | { | ||
75 | public: | ||
76 | |||
77 | // Some random number generators using the pre-generated random numbers | ||
78 | // return +- negPos | ||
79 | static S32 llrand_signed(S32 negPos) | ||
80 | { | ||
81 | return (gLindenLabRandomNumber.llrand((U32)negPos * 2) - negPos); | ||
82 | }; | ||
83 | |||
84 | static S32 llrand_signed(S32 negPos, U32 index) | ||
85 | { | ||
86 | return lltrunc((sRandNums[index % MAX_RAND_NUMS] * (negPos * 2.0f) - negPos)); | ||
87 | }; | ||
88 | |||
89 | static S32 llrand_unsigned(S32 pos, U32 index) | ||
90 | { | ||
91 | return lltrunc((sRandNums[index % MAX_RAND_NUMS] * pos)); | ||
92 | }; | ||
93 | |||
94 | // return +- negPos | ||
95 | static F32 llfrand_signed(F32 negPos) | ||
96 | { | ||
97 | return (gLindenLabRandomNumber.llfrand(negPos * 2.0f) - negPos); | ||
98 | }; | ||
99 | |||
100 | static F32 llfrand_signed(F32 negPos, U32 index) | ||
101 | { | ||
102 | return (sRandNums[index % MAX_RAND_NUMS] * negPos * 2.0f) - negPos; | ||
103 | }; | ||
104 | |||
105 | static F32 llfrand_unsigned(F32 pos, U32 index) | ||
106 | { | ||
107 | return sRandNums[index % MAX_RAND_NUMS] * pos; | ||
108 | }; | ||
109 | |||
110 | // return between 0-pos | ||
111 | static F32 llfrand_unsigned(F32 pos) | ||
112 | { | ||
113 | return gLindenLabRandomNumber.llfrand(pos); | ||
114 | }; | ||
115 | |||
116 | static void cleanupTextures() {}; // not needed anymore | ||
117 | |||
118 | struct TreePart | ||
119 | { | ||
120 | F32 mRadius; // scale x/y | ||
121 | F32 mLength; // scale z | ||
122 | F32 mCurve; | ||
123 | F32 mCurveV; | ||
124 | F32 mCurveRes; | ||
125 | F32 mCurveBack; | ||
126 | U8 mLobes; | ||
127 | F32 mLobeDepth; | ||
128 | U8 mLevel; | ||
129 | U32 mNumTris; | ||
130 | U8 mVertsPerSection; | ||
131 | U8 mNumVariants; | ||
132 | |||
133 | // first index into the drawpool arrays for this particular branch | ||
134 | U32 mIndiceIndex[MAX_VARS]; | ||
135 | U32 mOffsets[MAX_VARS][MAX_RES]; // offsets for the partial branch pieces | ||
136 | // local section frames for this branch | ||
137 | LLMatrix4 mFrames[MAX_VARS][(MAX_RES*(MAX_RES + 1))/2]; // (0...n) + (1...n) + ... + (n-1..n) | ||
138 | LLDynamicArray<LLVector3> mFaceNormals; | ||
139 | |||
140 | }; | ||
141 | |||
142 | LLVOTreeNew(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp); | ||
143 | virtual ~LLVOTreeNew(); | ||
144 | |||
145 | /*virtual*/ | ||
146 | U32 processUpdateMessage(LLMessageSystem *mesgsys, | ||
147 | void **user_data, | ||
148 | U32 block_num, const EObjectUpdateType update_type, | ||
149 | LLDataPacker *dp); | ||
150 | |||
151 | /*virtual*/ BOOL idleUpdate(LLAgent &agent, LLWorld &world, const F64 &time); | ||
152 | |||
153 | /*virtual*/ void render(LLAgent &agent); | ||
154 | /*virtual*/ void updateTextures(LLAgent &agent); | ||
155 | |||
156 | /*virtual*/ LLDrawable* createDrawable(LLPipeline *pipeline); | ||
157 | /*virtual*/ BOOL updateGeometry(LLDrawable *drawable); | ||
158 | |||
159 | F32 CalcZStep(TreePart *part, U8 section); | ||
160 | |||
161 | void createPart(U8 level, F32 length, F32 radius, LLStrider<LLVector3> &vertices, LLStrider<LLVector3> &normals, | ||
162 | LLStrider<LLVector2> &tex_coords, U32 *indices, | ||
163 | U32 &curVertexIndex, U32 &curTexCoordIndex, | ||
164 | U32 &curNormalIndex, U32 &curIndiceIndex); | ||
165 | |||
166 | S32 findSimilarPart(U8 level); | ||
167 | |||
168 | F32 CalculateSectionRadius(U8 level, F32 y, F32 stemLength, F32 stemRadius); | ||
169 | //F32 CalculateVerticalAttraction(U8 level, LLMatrix4 §ionFrame); | ||
170 | |||
171 | void createSection(LLMatrix4 &frame, TreePart *part, F32 sectionRadius, F32 stemZ, | ||
172 | LLStrider<LLVector3> &vertices, LLStrider<LLVector2> &tex_coords, U32 *indices, | ||
173 | U32 &curVertexIndex, U32 &curTexCoordIndex, U32 &curIndiceIndex, U8 curSection, BOOL firstBranch); | ||
174 | |||
175 | void genIndicesAndFaceNormalsForLastSection(TreePart *part, U8 numVerts, LLStrider<LLVector3> &vertices, U32 curVertexIndex, U32 *indices, U32 &curIndiceIndex, BOOL firstBranch); | ||
176 | |||
177 | void genVertexNormals(TreePart *part, LLStrider<LLVector3> &normals, U8 numSections, U32 curNormalOffset); | ||
178 | |||
179 | 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); | ||
180 | void drawTree(LLDrawPool &draw_pool); | ||
181 | |||
182 | |||
183 | //LLTreeParams mParams; | ||
184 | U8 mSpecies; | ||
185 | LLPointer<LLViewerImage> mTreeImagep; | ||
186 | LLMatrix4 mTrunkFlareFrames[MAX_FLARE]; | ||
187 | F32 mSegSplitsError[3]; | ||
188 | U32 mRandOffset[MAX_LEVELS]; | ||
189 | |||
190 | U32 mNumTrisDrawn; | ||
191 | U32 mTotalIndices; | ||
192 | U32 mTotalVerts; | ||
193 | |||
194 | static void initClass(); | ||
195 | |||
196 | // tree params | ||
197 | static LLTreeParams sParameters; | ||
198 | |||
199 | // next indexes used to drawpool arrays | ||
200 | static U32 sNextVertexIndex[MAX_SPECIES]; | ||
201 | static U32 sNextIndiceIndex[MAX_SPECIES]; | ||
202 | |||
203 | // tree parts | ||
204 | static U32 sNextPartIndex[MAX_PARTS]; | ||
205 | static TreePart sTreeParts[MAX_SPECIES][MAX_PARTS]; | ||
206 | |||
207 | // species images | ||
208 | static LLUUID sTreeImageIDs[MAX_SPECIES]; | ||
209 | |||
210 | // random numbers | ||
211 | static F32 sRandNums[MAX_RAND_NUMS]; | ||
212 | |||
213 | // usage data | ||
214 | static U32 sTreePartsUsed[MAX_SPECIES][MAX_PARTS][MAX_VARS]; | ||
215 | |||
216 | |||
217 | }; | ||
218 | |||
219 | #endif | ||