00001
00032 #ifndef LL_LLPOLYMESH_H
00033 #define LL_LLPOLYMESH_H
00034
00035 #include <string>
00036 #include <map>
00037 #include "llstl.h"
00038
00039 #include "v3math.h"
00040 #include "v2math.h"
00041 #include "llquaternion.h"
00042 #include "llskipmap.h"
00043 #include "llassoclist.h"
00044 #include "llpolymorph.h"
00045 #include "llptrskipmap.h"
00046 #include "lljoint.h"
00047
00048
00049 class LLSkinJoint;
00050 class LLVOAvatar;
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 typedef S32 LLPolyFace[3];
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070 class LLPolyMorphTarget;
00071
00072 class LLPolyMeshSharedData
00073 {
00074 friend class LLPolyMesh;
00075 private:
00076
00077 LLVector3 mPosition;
00078 LLQuaternion mRotation;
00079 LLVector3 mScale;
00080
00081
00082 S32 mNumVertices;
00083 LLVector3 *mBaseCoords;
00084 LLVector3 *mBaseNormals;
00085 LLVector3 *mBaseBinormals;
00086 LLVector2 *mTexCoords;
00087 LLVector2 *mDetailTexCoords;
00088 F32 *mWeights;
00089
00090 BOOL mHasWeights;
00091 BOOL mHasDetailTexCoords;
00092
00093
00094 S32 mNumFaces;
00095 LLPolyFace *mFaces;
00096
00097
00098 U32 mNumJointNames;
00099 std::string* mJointNames;
00100
00101
00102 typedef LLLinkedList<LLPolyMorphData> LLPolyMorphDataList;
00103 LLPolyMorphDataList mMorphData;
00104
00105 std::map<S32, S32> mSharedVerts;
00106
00107 LLPolyMeshSharedData* mReferenceData;
00108 S32 mLastIndexOffset;
00109
00110 public:
00111
00112
00113 U32 mNumTriangleIndices;
00114 U32 *mTriangleIndices;
00115
00116 private:
00117 LLPolyMeshSharedData();
00118
00119 ~LLPolyMeshSharedData();
00120
00121 void setupLOD(LLPolyMeshSharedData* reference_data);
00122
00123
00124 void freeMeshData();
00125
00126 void setPosition( const LLVector3 &pos ) { mPosition = pos; }
00127 void setRotation( const LLQuaternion &rot ) { mRotation = rot; }
00128 void setScale( const LLVector3 &scale ) { mScale = scale; }
00129
00130 BOOL allocateVertexData( U32 numVertices );
00131
00132 BOOL allocateFaceData( U32 numFaces );
00133
00134 BOOL allocateJointNames( U32 numJointNames );
00135
00136
00137 U32 getNumKB();
00138
00139
00140 BOOL loadMesh( const char *fileName );
00141
00142 public:
00143 void genIndices(S32 offset);
00144
00145 const LLVector2 &getUVs(U32 index);
00146
00147 const S32 *getSharedVert(S32 vert);
00148
00149 BOOL isLOD() { return (mReferenceData != NULL); }
00150 };
00151
00152
00153 class LLJointRenderData
00154 {
00155 public:
00156 LLJointRenderData(const LLMatrix4* world_matrix, LLSkinJoint* skin_joint) : mWorldMatrix(world_matrix), mSkinJoint(skin_joint){}
00157 ~LLJointRenderData(){}
00158
00159 const LLMatrix4* mWorldMatrix;
00160 LLSkinJoint* mSkinJoint;
00161 };
00162
00163
00164 class LLPolyMesh
00165 {
00166 public:
00167
00168
00169 LLPolyMesh(LLPolyMeshSharedData *shared_data, LLPolyMesh *reference_mesh);
00170
00171
00172 ~LLPolyMesh();
00173
00174
00175
00176
00177 static LLPolyMesh *getMesh( const LLString &name, LLPolyMesh* reference_mesh = NULL);
00178
00179
00180
00181
00182 static void freeAllMeshes();
00183
00184
00185
00186
00187
00188 const LLVector3 &getPosition() {
00189 llassert (mSharedData);
00190 return mSharedData->mPosition;
00191 }
00192
00193
00194 const LLQuaternion &getRotation() {
00195 llassert (mSharedData);
00196 return mSharedData->mRotation;
00197 }
00198
00199
00200 const LLVector3 &getScale() {
00201 llassert (mSharedData);
00202 return mSharedData->mScale;
00203 }
00204
00205
00206
00207
00208
00209 U32 getNumVertices() {
00210 llassert (mSharedData);
00211 return mSharedData->mNumVertices;
00212 }
00213
00214
00215 BOOL hasDetailTexCoords() {
00216 llassert (mSharedData);
00217 return mSharedData->mHasDetailTexCoords;
00218 }
00219
00220
00221 BOOL hasWeights() const{
00222 llassert (mSharedData);
00223 return mSharedData->mHasWeights;
00224 }
00225
00226
00227 const LLVector3 *getCoords() const;
00228
00229
00230 LLVector3 *getWritableCoords();
00231
00232
00233 const LLVector3 *getNormals() const{
00234 return mNormals;
00235 }
00236
00237
00238 const LLVector3 *getBinormals() const{
00239 return mBinormals;
00240 }
00241
00242
00243 const LLVector3 *getBaseNormals() const{
00244 llassert(mSharedData);
00245 return mSharedData->mBaseNormals;
00246 }
00247
00248
00249 const LLVector3 *getBaseBinormals() const{
00250 llassert(mSharedData);
00251 return mSharedData->mBaseBinormals;
00252 }
00253
00254
00255 LLVector3 *getWritableNormals();
00256 LLVector3 *getScaledNormals();
00257
00258 LLVector3 *getWritableBinormals();
00259 LLVector3 *getScaledBinormals();
00260
00261
00262 const LLVector2 *getTexCoords() const {
00263 return mTexCoords;
00264 }
00265
00266
00267 LLVector2 *getWritableTexCoords();
00268
00269
00270 const LLVector2 *getDetailTexCoords() const {
00271 llassert (mSharedData);
00272 return mSharedData->mDetailTexCoords;
00273 }
00274
00275
00276 const F32 *getWeights() const;
00277
00278 F32 *getWritableWeights() const;
00279
00280 LLVector4 *getWritableClothingWeights();
00281
00282 const LLVector4 *getClothingWeights()
00283 {
00284 return mClothingWeights;
00285 }
00286
00287
00288
00289
00290
00291 S32 getNumFaces() {
00292 llassert (mSharedData);
00293 return mSharedData->mNumFaces;
00294 }
00295
00296
00297 LLPolyFace *getFaces() {
00298 llassert (mSharedData);
00299 return mSharedData->mFaces;
00300 }
00301
00302 U32 getNumJointNames() {
00303 llassert (mSharedData);
00304 return mSharedData->mNumJointNames;
00305 }
00306
00307 std::string *getJointNames() {
00308 llassert (mSharedData);
00309 return mSharedData->mJointNames;
00310 }
00311
00312 LLPolyMorphData* getMorphData(const char *morph_name);
00313 void removeMorphData(LLPolyMorphData *morph_target);
00314 void deleteAllMorphData();
00315
00316 LLPolyMeshSharedData *getSharedData() const;
00317 LLPolyMesh *getReferenceMesh() { return mReferenceMesh ? mReferenceMesh : this; }
00318
00319
00320 U32* getIndices() { return mSharedData ? mSharedData->mTriangleIndices : NULL; }
00321
00322 BOOL isLOD() { return mSharedData && mSharedData->isLOD(); }
00323
00324 void setAvatar(LLVOAvatar* avatarp) { mAvatarp = avatarp; }
00325 LLVOAvatar* getAvatar() { return mAvatarp; }
00326
00327 LLDynamicArray<LLJointRenderData*> mJointRenderData;
00328
00329 U32 mFaceVertexOffset;
00330 U32 mFaceVertexCount;
00331 U32 mFaceIndexOffset;
00332 U32 mFaceIndexCount;
00333 U32 mCurVertexCount;
00334 private:
00335 void initializeForMorph();
00336
00337
00338 static void dumpDiagInfo();
00339
00340 protected:
00341
00342 LLPolyMeshSharedData *mSharedData;
00343
00344 F32 *mVertexData;
00345
00346 LLVector3 *mCoords;
00347
00348 LLVector3 *mScaledNormals;
00349
00350 LLVector3 *mNormals;
00351
00352 LLVector3 *mScaledBinormals;
00353
00354 LLVector3 *mBinormals;
00355
00356 LLVector4 *mClothingWeights;
00357
00358 LLVector2 *mTexCoords;
00359
00360 LLPolyMesh *mReferenceMesh;
00361
00362
00363 typedef LLAssocList<std::string, LLPolyMeshSharedData*> LLPolyMeshSharedDataTable;
00364 static LLPolyMeshSharedDataTable sGlobalSharedMeshList;
00365
00366
00367 LLVOAvatar* mAvatarp;
00368 };
00369
00370
00371
00372
00373
00374 struct LLPolySkeletalBoneInfo
00375 {
00376 LLPolySkeletalBoneInfo(LLString &name, LLVector3 &scale, LLVector3 &pos, BOOL haspos)
00377 : mBoneName(name),
00378 mScaleDeformation(scale),
00379 mPositionDeformation(pos),
00380 mHasPositionDeformation(haspos) {}
00381 LLString mBoneName;
00382 LLVector3 mScaleDeformation;
00383 LLVector3 mPositionDeformation;
00384 BOOL mHasPositionDeformation;
00385 };
00386
00387 class LLPolySkeletalDistortionInfo : public LLViewerVisualParamInfo
00388 {
00389 friend class LLPolySkeletalDistortion;
00390 public:
00391 LLPolySkeletalDistortionInfo();
00392 ~LLPolySkeletalDistortionInfo() {};
00393
00394 BOOL parseXml(LLXmlTreeNode* node);
00395
00396 protected:
00397 typedef std::vector<LLPolySkeletalBoneInfo> bone_info_list_t;
00398 bone_info_list_t mBoneInfoList;
00399 };
00400
00401
00402
00403
00404
00405 class LLPolySkeletalDistortion : public LLViewerVisualParam
00406 {
00407 public:
00408 LLPolySkeletalDistortion(LLVOAvatar *avatarp);
00409 ~LLPolySkeletalDistortion();
00410
00411
00412 LLPolySkeletalDistortionInfo* getInfo() const { return (LLPolySkeletalDistortionInfo*)mInfo; }
00413
00414 BOOL setInfo(LLPolySkeletalDistortionInfo *info);
00415
00416
00418 void apply( ESex sex );
00419
00420
00421 F32 getTotalDistortion() { return 0.1f; }
00422 const LLVector3& getAvgDistortion() { return mDefaultVec; }
00423 F32 getMaxDistortion() { return 0.1f; }
00424 LLVector3 getVertexDistortion(S32 index, LLPolyMesh *poly_mesh){return LLVector3(0.001f, 0.001f, 0.001f);}
00425 const LLVector3* getFirstDistortion(U32 *index, LLPolyMesh **poly_mesh){index = 0; poly_mesh = NULL; return &mDefaultVec;};
00426 const LLVector3* getNextDistortion(U32 *index, LLPolyMesh **poly_mesh){index = 0; poly_mesh = NULL; return NULL;};
00427
00428 protected:
00429 typedef std::map<LLJoint*, LLVector3> joint_vec_map_t;
00430 joint_vec_map_t mJointScales;
00431 joint_vec_map_t mJointOffsets;
00432 LLVector3 mDefaultVec;
00433
00434 LLVOAvatar *mAvatar;
00435 };
00436
00437 #endif // LL_LLPOLYMESH_H
00438