aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llpolymesh.h
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/newview/llpolymesh.h
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/newview/llpolymesh.h')
-rw-r--r--linden/indra/newview/llpolymesh.h431
1 files changed, 431 insertions, 0 deletions
diff --git a/linden/indra/newview/llpolymesh.h b/linden/indra/newview/llpolymesh.h
new file mode 100644
index 0000000..851a9bc
--- /dev/null
+++ b/linden/indra/newview/llpolymesh.h
@@ -0,0 +1,431 @@
1/**
2 * @file llpolymesh.h
3 * @brief Implementation of LLPolyMesh class
4 *
5 * Copyright (c) 2001-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_LLPOLYMESH_H
29#define LL_LLPOLYMESH_H
30
31#include <string>
32#include <map>
33#include "llstl.h"
34
35#include "v3math.h"
36#include "v2math.h"
37#include "llquaternion.h"
38#include "llskipmap.h"
39#include "llassoclist.h"
40#include "llpolymorph.h"
41#include "llptrskipmap.h"
42#include "lljoint.h"
43//#include "lldarray.h"
44
45class LLSkinJoint;
46class LLVOAvatar;
47
48//#define USE_STRIPS // Use tri-strips for rendering.
49
50//-----------------------------------------------------------------------------
51// LLPolyFace
52// A set of 4 vertex indices.
53// An LLPolyFace can represent either a triangle or quad.
54// If the last index is -1, it's a triangle.
55//-----------------------------------------------------------------------------
56typedef S32 LLPolyFace[3];
57
58//struct PrimitiveGroup;
59
60//-----------------------------------------------------------------------------
61// LLPolyMesh
62// A polyhedra consisting of any number of triangles and quads.
63// All instances contain a set of faces, and optionally may include
64// faces grouped into named face sets.
65//-----------------------------------------------------------------------------
66class LLPolyMorphTarget;
67
68class LLPolyMeshSharedData
69{
70 friend class LLPolyMesh;
71private:
72 // transform data
73 LLVector3 mPosition;
74 LLQuaternion mRotation;
75 LLVector3 mScale;
76
77 // vertex data
78 S32 mNumVertices;
79 LLVector3 *mBaseCoords;
80 LLVector3 *mBaseNormals;
81 LLVector3 *mBaseBinormals;
82 LLVector2 *mTexCoords;
83 LLVector2 *mDetailTexCoords;
84 F32 *mWeights;
85
86 BOOL mHasWeights;
87 BOOL mHasDetailTexCoords;
88
89 // face data
90 S32 mNumFaces;
91 LLPolyFace *mFaces;
92
93 // face set data
94 U32 mNumJointNames;
95 std::string* mJointNames;
96
97 // morph targets
98 typedef LLLinkedList<LLPolyMorphData> LLPolyMorphDataList;
99 LLPolyMorphDataList mMorphData;
100
101 std::map<S32, S32> mSharedVerts;
102
103 LLPolyMeshSharedData* mReferenceData;
104 S32 mLastIndexOffset;
105
106public:
107 // Temporarily...
108 // Triangle indices
109 U32 mNumTriangleIndices;
110 U32 *mTriangleIndices;
111
112private:
113 LLPolyMeshSharedData();
114
115 ~LLPolyMeshSharedData();
116
117 void setupLOD(LLPolyMeshSharedData* reference_data);
118
119 // Frees all mesh memory resources
120 void freeMeshData();
121
122 void setPosition( const LLVector3 &pos ) { mPosition = pos; }
123 void setRotation( const LLQuaternion &rot ) { mRotation = rot; }
124 void setScale( const LLVector3 &scale ) { mScale = scale; }
125
126 BOOL allocateVertexData( U32 numVertices );
127
128 BOOL allocateFaceData( U32 numFaces );
129
130 BOOL allocateJointNames( U32 numJointNames );
131
132 // Retrieve the number of KB of memory used by this instance
133 U32 getNumKB();
134
135 // Load mesh data from file
136 BOOL loadMesh( const char *fileName );
137
138public:
139 void genIndices(S32 offset);
140
141 const LLVector2 &getUVs(U32 index);
142
143 const S32 *getSharedVert(S32 vert);
144
145 BOOL isLOD() { return (mReferenceData != NULL); }
146};
147
148
149class LLJointRenderData
150{
151public:
152 LLJointRenderData(const LLMatrix4* world_matrix, LLSkinJoint* skin_joint) : mWorldMatrix(world_matrix), mSkinJoint(skin_joint){}
153 ~LLJointRenderData(){}
154
155 const LLMatrix4* mWorldMatrix;
156 LLSkinJoint* mSkinJoint;
157};
158
159
160class LLPolyMesh
161{
162public:
163
164 // Constructor
165 LLPolyMesh(LLPolyMeshSharedData *shared_data, LLPolyMesh *reference_mesh);
166
167 // Destructor
168 ~LLPolyMesh();
169
170 // Requests a mesh by name.
171 // If the mesh already exists in the global mesh table, it is returned,
172 // otherwise it is loaded from file, added to the table, and returned.
173 static LLPolyMesh *getMesh( const LLString &name, LLPolyMesh* reference_mesh = NULL);
174
175 // Frees all loaded meshes.
176 // This should only be called once you know there are no outstanding
177 // references to these objects. Generally, upon exit of the application.
178 static void freeAllMeshes();
179
180 //--------------------------------------------------------------------
181 // Transform Data Access
182 //--------------------------------------------------------------------
183 // Get position
184 const LLVector3 &getPosition() {
185 llassert (mSharedData);
186 return mSharedData->mPosition;
187 }
188
189 // Get rotation
190 const LLQuaternion &getRotation() {
191 llassert (mSharedData);
192 return mSharedData->mRotation;
193 }
194
195 // Get scale
196 const LLVector3 &getScale() {
197 llassert (mSharedData);
198 return mSharedData->mScale;
199 }
200
201 //--------------------------------------------------------------------
202 // Vertex Data Access
203 //--------------------------------------------------------------------
204 // Get number of vertices
205 U32 getNumVertices() {
206 llassert (mSharedData);
207 return mSharedData->mNumVertices;
208 }
209
210 // Returns whether or not the mesh has detail texture coords
211 BOOL hasDetailTexCoords() {
212 llassert (mSharedData);
213 return mSharedData->mHasDetailTexCoords;
214 }
215
216 // Returns whether or not the mesh has vertex weights
217 BOOL hasWeights() const{
218 llassert (mSharedData);
219 return mSharedData->mHasWeights;
220 }
221
222 // Get coords
223 const LLVector3 *getCoords() const;
224
225 // non const version
226 LLVector3 *getWritableCoords();
227
228 // Get normals
229 const LLVector3 *getNormals() const{
230 return mNormals;
231 }
232
233 // Get normals
234 const LLVector3 *getBinormals() const{
235 return mBinormals;
236 }
237
238 // Get base mesh normals
239 const LLVector3 *getBaseNormals() const{
240 llassert(mSharedData);
241 return mSharedData->mBaseNormals;
242 }
243
244 // Get base mesh normals
245 const LLVector3 *getBaseBinormals() const{
246 llassert(mSharedData);
247 return mSharedData->mBaseBinormals;
248 }
249
250 // intermediate morphed normals and output normals
251 LLVector3 *getWritableNormals();
252 LLVector3 *getScaledNormals();
253
254 LLVector3 *getWritableBinormals();
255 LLVector3 *getScaledBinormals();
256
257 // Get texCoords
258 const LLVector2 *getTexCoords() const {
259 return mTexCoords;
260 }
261
262 // non const version
263 LLVector2 *getWritableTexCoords();
264
265 // Get detailTexCoords
266 const LLVector2 *getDetailTexCoords() const {
267 llassert (mSharedData);
268 return mSharedData->mDetailTexCoords;
269 }
270
271 // Get weights
272 const F32 *getWeights() const;
273
274 F32 *getWritableWeights() const;
275
276 LLVector4 *getWritableClothingWeights();
277
278 const LLVector4 *getClothingWeights()
279 {
280 return mClothingWeights;
281 }
282
283 //--------------------------------------------------------------------
284 // Face Data Access
285 //--------------------------------------------------------------------
286 // Get number of faces
287 S32 getNumFaces() {
288 llassert (mSharedData);
289 return mSharedData->mNumFaces;
290 }
291
292 // Get faces
293 LLPolyFace *getFaces() {
294 llassert (mSharedData);
295 return mSharedData->mFaces;
296 }
297
298 U32 getNumJointNames() {
299 llassert (mSharedData);
300 return mSharedData->mNumJointNames;
301 }
302
303 std::string *getJointNames() {
304 llassert (mSharedData);
305 return mSharedData->mJointNames;
306 }
307
308 LLPolyMorphData* getMorphData(const char *morph_name);
309 void removeMorphData(LLPolyMorphData *morph_target);
310 void deleteAllMorphData();
311
312 LLPolyMeshSharedData *getSharedData() const;
313 LLPolyMesh *getReferenceMesh() { return mReferenceMesh ? mReferenceMesh : this; }
314
315 // Get indices
316 U32* getIndices() { return mSharedData ? mSharedData->mTriangleIndices : NULL; }
317
318 BOOL isLOD() { return mSharedData && mSharedData->isLOD(); }
319
320 void setAvatar(LLVOAvatar* avatarp) { mAvatarp = avatarp; }
321 LLVOAvatar* getAvatar() { return mAvatarp; }
322
323 LLDynamicArray<LLJointRenderData*> mJointRenderData;
324
325 U32 mFaceVertexOffset;
326 U32 mFaceVertexCount;
327 U32 mFaceIndexCount;
328 U32 mCurVertexCount;
329private:
330 void initializeForMorph();
331
332 // Dumps diagnostic information about the global mesh table
333 static void dumpDiagInfo();
334
335protected:
336 // mesh data shared across all instances of a given mesh
337 LLPolyMeshSharedData *mSharedData;
338 // Single array of floats for allocation / deletion
339 F32 *mVertexData;
340 // deformed vertices (resulting from application of morph targets)
341 LLVector3 *mCoords;
342 // deformed normals (resulting from application of morph targets)
343 LLVector3 *mScaledNormals;
344 // output normals (after normalization)
345 LLVector3 *mNormals;
346 // deformed binormals (resulting from application of morph targets)
347 LLVector3 *mScaledBinormals;
348 // output binormals (after normalization)
349 LLVector3 *mBinormals;
350 // weight values that mark verts as clothing/skin
351 LLVector4 *mClothingWeights;
352 // output texture coordinates
353 LLVector2 *mTexCoords;
354
355 LLPolyMesh *mReferenceMesh;
356
357 // global mesh list
358 typedef LLAssocList<std::string, LLPolyMeshSharedData*> LLPolyMeshSharedDataTable;
359 static LLPolyMeshSharedDataTable sGlobalSharedMeshList;
360
361 LLVOAvatar* mAvatarp;
362};
363
364//-----------------------------------------------------------------------------
365// LLPolySkeletalDeformationInfo
366// Shared information for LLPolySkeletalDeformations
367//-----------------------------------------------------------------------------
368struct LLPolySkeletalBoneInfo
369{
370 LLPolySkeletalBoneInfo(LLString &name, LLVector3 &scale, LLVector3 &pos, BOOL haspos)
371 : mBoneName(name),
372 mScaleDeformation(scale),
373 mPositionDeformation(pos),
374 mHasPositionDeformation(haspos) {}
375 LLString mBoneName;
376 LLVector3 mScaleDeformation;
377 LLVector3 mPositionDeformation;
378 BOOL mHasPositionDeformation;
379};
380
381class LLPolySkeletalDistortionInfo : public LLViewerVisualParamInfo
382{
383 friend class LLPolySkeletalDistortion;
384public:
385 LLPolySkeletalDistortionInfo();
386 /*virtual*/ ~LLPolySkeletalDistortionInfo() {};
387
388 /*virtual*/ BOOL parseXml(LLXmlTreeNode* node);
389
390protected:
391 typedef std::vector<LLPolySkeletalBoneInfo> bone_info_list_t;
392 bone_info_list_t mBoneInfoList;
393};
394
395//-----------------------------------------------------------------------------
396// LLPolySkeletalDeformation
397// A set of joint scale data for deforming the avatar mesh
398//-----------------------------------------------------------------------------
399class LLPolySkeletalDistortion : public LLViewerVisualParam
400{
401public:
402 LLPolySkeletalDistortion(LLVOAvatar *avatarp);
403 ~LLPolySkeletalDistortion();
404
405 // Special: These functions are overridden by child classes
406 LLPolySkeletalDistortionInfo* getInfo() const { return (LLPolySkeletalDistortionInfo*)mInfo; }
407 // This sets mInfo and calls initialization functions
408 BOOL setInfo(LLPolySkeletalDistortionInfo *info);
409
410 // LLVisualParam Virtual functions
411 ///*virtual*/ BOOL parseData(LLXmlTreeNode* node);
412 /*virtual*/ void apply( ESex sex );
413
414 // LLViewerVisualParam Virtual functions
415 /*virtual*/ F32 getTotalDistortion() { return 0.1f; }
416 /*virtual*/ const LLVector3& getAvgDistortion() { return mDefaultVec; }
417 /*virtual*/ F32 getMaxDistortion() { return 0.1f; }
418 /*virtual*/ LLVector3 getVertexDistortion(S32 index, LLPolyMesh *poly_mesh){return LLVector3(0.001f, 0.001f, 0.001f);}
419 /*virtual*/ const LLVector3* getFirstDistortion(U32 *index, LLPolyMesh **poly_mesh){index = 0; poly_mesh = NULL; return &mDefaultVec;};
420 /*virtual*/ const LLVector3* getNextDistortion(U32 *index, LLPolyMesh **poly_mesh){index = 0; poly_mesh = NULL; return NULL;};
421
422protected:
423 typedef std::map<LLJoint*, LLVector3> joint_vec_map_t;
424 joint_vec_map_t mJointScales;
425 joint_vec_map_t mJointOffsets;
426 LLVector3 mDefaultVec;
427 LLVOAvatar* mAvatar;
428};
429
430#endif // LL_LLPOLYMESH_H
431