PageRenderTime 30ms CodeModel.GetById 1ms app.highlight 22ms RepoModel.GetById 1ms app.codeStats 1ms

/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
  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
 27#ifndef LL_LLVOTREENEW_H
 28#define LL_LLVOTREENEW_H
 29
 30#include "llviewerobject.h"
 31#include "lldarray.h"
 32#include "xform.h"
 33
 34#include "lltreeparams.h"
 35#include "llstrider.h"
 36#include "v2math.h"
 37#include "v3math.h"
 38#include "llviewertexture.h"
 39
 40class LLFace;
 41class LLDrawPool;
 42
 43// number of static arrays created
 44const U8 MAX_SPECIES = 16;	// max species of trees
 45const U8 MAX_PARTS = 15;	// trunk, 2 or 3 branches per species?
 46const U8 MAX_RES = 6;		// max # cross sections for a branch curve
 47const U8 MAX_FLARE = 6;		// max # cross sections for flare of trunk
 48const U8 MAX_LEVELS = 3;
 49
 50// initial vertex array allocations
 51const U32 NUM_INIT_VERTS = 5000;			// number of vertices/normals/texcoords
 52const U32 NUM_INIT_INDICES = 15000;			// number of indices to vert array (3 vertices per triangle, roughly 3x)
 53const U32 NUM_TIMES_TO_DOUBLE = 2;			// if we go over initial allocations, num times to double each step
 54
 55// for finding the closest parts...
 56
 57// the parts are searched based on:
 58const F32 MAX_LOBES_DIFF = 2;
 59const F32 MAX_LOBEDEPTH_DIFF = .3f;
 60const F32 MAX_CURVEBACK_DIFF = 20.0f;
 61const F32 MAX_CURVE_DIFF = 15.0f;
 62const F32 MAX_CURVE_V_DIFF = 20.0f;
 63
 64const F32 CURVEV_DIVIDER = 10.0f;	// curveV/CURVEV_DIVIDER = # branch variances...
 65const U8 MAX_VARS = 3;				// max number of variations of branches
 66
 67const U8 MAX_RAND_NUMS = 100;		// max number of rand numbers to pregenerate and store
 68
 69// texture params
 70const F32 WIDTH_OF_BARK = .48f;
 71
 72class LLVOTreeNew : public LLViewerObject
 73{
 74public:
 75
 76	// Some random number generators using the pre-generated random numbers
 77	// return +- negPos
 78	static S32 llrand_signed(S32 negPos)
 79	{
 80		return (ll_rand((U32)negPos * 2) - negPos);
 81	};
 82
 83	static S32 llrand_signed(S32 negPos, U32 index)
 84	{
 85		return lltrunc((sRandNums[index % MAX_RAND_NUMS] * (negPos * 2.0f) - negPos));
 86	};
 87	
 88	static S32 llrand_unsigned(S32 pos, U32 index)
 89	{
 90		return lltrunc((sRandNums[index % MAX_RAND_NUMS] * pos));
 91	};
 92
 93	// return +- negPos
 94	static F32 llfrand_signed(F32 negPos)
 95	{
 96		return (ll_frand(negPos * 2.0f) - negPos);
 97	};
 98
 99	static F32 llfrand_signed(F32 negPos, U32 index)
100	{
101		return (sRandNums[index % MAX_RAND_NUMS] * negPos * 2.0f) - negPos;
102	};
103
104	static F32 llfrand_unsigned(F32 pos, U32 index)
105	{
106		return sRandNums[index % MAX_RAND_NUMS] * pos;
107	};
108
109	// return between 0-pos
110	static F32 llfrand_unsigned(F32 pos)
111	{
112		return ll_frand(pos);
113	};
114
115	static void cleanupTextures() {};	// not needed anymore
116
117	struct TreePart
118	{
119		F32 mRadius;		// scale x/y
120		F32 mLength;		// scale z
121		F32 mCurve;
122		F32 mCurveV;
123		F32 mCurveRes;
124		F32 mCurveBack;
125		U8 mLobes;
126		F32 mLobeDepth;
127		U8 mLevel;
128		U32 mNumTris;
129		U8 mVertsPerSection;
130		U8 mNumVariants;
131
132		// first index into the drawpool arrays for this particular branch
133		U32 mIndiceIndex[MAX_VARS];
134		U32 mOffsets[MAX_VARS][MAX_RES];		// offsets for the partial branch pieces
135		// local section frames for this branch
136		LLMatrix4 mFrames[MAX_VARS][(MAX_RES*(MAX_RES + 1))/2];	// (0...n) + (1...n) + ... + (n-1..n)
137		LLDynamicArray<LLVector3> mFaceNormals;
138
139	};
140
141	LLVOTreeNew(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp);
142	virtual ~LLVOTreeNew();
143
144	/*virtual*/ 
145	U32 processUpdateMessage(LLMessageSystem *mesgsys,
146											void **user_data,
147											U32 block_num, const EObjectUpdateType update_type,
148											LLDataPacker *dp);
149
150	/*virtual*/ BOOL idleUpdate(LLAgent &agent, LLWorld &world, const F64 &time);
151
152	/*virtual*/ void render(LLAgent &agent);
153	/*virtual*/ void updateTextures();
154
155	/*virtual*/ LLDrawable* createDrawable(LLPipeline *pipeline);
156	/*virtual*/ BOOL		updateGeometry(LLDrawable *drawable);
157
158	F32 CalcZStep(TreePart *part, U8 section);
159
160	void createPart(U8 level, F32 length, F32 radius, LLStrider<LLVector3> &vertices, LLStrider<LLVector3> &normals, 
161							LLStrider<LLVector2> &tex_coords, U32 *indices, 
162							U32 &curVertexIndex, U32 &curTexCoordIndex,
163							U32 &curNormalIndex, U32 &curIndiceIndex);
164
165	S32 findSimilarPart(U8 level);
166
167	F32 CalculateSectionRadius(U8 level, F32 y, F32 stemLength, F32 stemRadius);
168	//F32 CalculateVerticalAttraction(U8 level, LLMatrix4 &sectionFrame);
169
170	void createSection(LLMatrix4 &frame, TreePart *part, F32 sectionRadius, F32 stemZ, 
171							  LLStrider<LLVector3> &vertices, LLStrider<LLVector2> &tex_coords, U32 *indices, 
172							  U32 &curVertexIndex, U32 &curTexCoordIndex, U32 &curIndiceIndex, U8 curSection, BOOL firstBranch);
173
174	void genIndicesAndFaceNormalsForLastSection(TreePart *part, U8 numVerts, LLStrider<LLVector3> &vertices, U32 curVertexIndex, U32 *indices, U32 &curIndiceIndex, BOOL firstBranch);
175
176	void genVertexNormals(TreePart *part, LLStrider<LLVector3> &normals, U8 numSections, U32 curNormalOffset);
177
178	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);
179	void drawTree(LLDrawPool &draw_pool);
180
181	
182	//LLTreeParams mParams;
183	U8 mSpecies;
184	LLPointer<LLViewerTexture> mTreeImagep;
185	LLMatrix4 mTrunkFlareFrames[MAX_FLARE];
186	F32 mSegSplitsError[3];
187	U32 mRandOffset[MAX_LEVELS];
188
189	U32 mNumTrisDrawn;
190	U32 mTotalIndices;
191	U32 mTotalVerts;
192
193	static void initClass();
194
195	// tree params
196	static LLTreeParams sParameters;
197
198	// next indexes used to drawpool arrays
199	static U32 sNextVertexIndex[MAX_SPECIES];
200	static U32 sNextIndiceIndex[MAX_SPECIES];
201
202	// tree parts
203	static U32 sNextPartIndex[MAX_PARTS];
204	static TreePart sTreeParts[MAX_SPECIES][MAX_PARTS];
205
206	// species images
207	static LLUUID sTreeImageIDs[MAX_SPECIES];
208
209	// random numbers
210	static F32 sRandNums[MAX_RAND_NUMS];
211
212	// usage data
213	static U32 sTreePartsUsed[MAX_SPECIES][MAX_PARTS][MAX_VARS];
214	
215	
216};
217
218#endif