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