llpolymesh.h

Go to the documentation of this file.
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 //#include "lldarray.h"
00048 
00049 class LLSkinJoint;
00050 class LLVOAvatar;
00051 
00052 //#define USE_STRIPS    // Use tri-strips for rendering.
00053 
00054 //-----------------------------------------------------------------------------
00055 // LLPolyFace
00056 // A set of 4 vertex indices.
00057 // An LLPolyFace can represent either a triangle or quad.
00058 // If the last index is -1, it's a triangle.
00059 //-----------------------------------------------------------------------------
00060 typedef S32 LLPolyFace[3];
00061 
00062 //struct PrimitiveGroup;
00063 
00064 //-----------------------------------------------------------------------------
00065 // LLPolyMesh
00066 // A polyhedra consisting of any number of triangles and quads.
00067 // All instances contain a set of faces, and optionally may include
00068 // faces grouped into named face sets.
00069 //-----------------------------------------------------------------------------
00070 class LLPolyMorphTarget;
00071 
00072 class LLPolyMeshSharedData
00073 {
00074         friend class LLPolyMesh;
00075 private:
00076         // transform data
00077         LLVector3                               mPosition;
00078         LLQuaternion                    mRotation;
00079         LLVector3                               mScale;
00080                                                         
00081         // vertex data                  
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         // face data                    
00094         S32                                             mNumFaces;
00095         LLPolyFace                              *mFaces;
00096                                                         
00097         // face set data                
00098         U32                                             mNumJointNames;
00099         std::string*                    mJointNames;
00100 
00101         // morph targets
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         // Temporarily...
00112         // Triangle indices
00113         U32                             mNumTriangleIndices;
00114         U32                             *mTriangleIndices;
00115 
00116 private:
00117         LLPolyMeshSharedData();
00118 
00119         ~LLPolyMeshSharedData();
00120 
00121         void setupLOD(LLPolyMeshSharedData* reference_data);
00122 
00123         // Frees all mesh memory resources 
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         // Retrieve the number of KB of memory used by this instance
00137         U32 getNumKB();
00138 
00139         // Load mesh data from file
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         // Constructor
00169         LLPolyMesh(LLPolyMeshSharedData *shared_data, LLPolyMesh *reference_mesh);
00170 
00171         // Destructor 
00172         ~LLPolyMesh();
00173 
00174         // Requests a mesh by name.
00175         // If the mesh already exists in the global mesh table, it is returned,
00176         // otherwise it is loaded from file, added to the table, and returned.
00177         static LLPolyMesh *getMesh( const LLString &name, LLPolyMesh* reference_mesh = NULL);
00178 
00179         // Frees all loaded meshes.
00180         // This should only be called once you know there are no outstanding
00181         // references to these objects.  Generally, upon exit of the application.
00182         static void freeAllMeshes();
00183 
00184         //--------------------------------------------------------------------
00185         // Transform Data Access
00186         //--------------------------------------------------------------------
00187         // Get position
00188         const LLVector3 &getPosition() { 
00189                 llassert (mSharedData);
00190                 return mSharedData->mPosition; 
00191         }
00192 
00193         // Get rotation
00194         const LLQuaternion &getRotation() { 
00195                 llassert (mSharedData);
00196                 return mSharedData->mRotation; 
00197         }
00198 
00199         // Get scale
00200         const LLVector3 &getScale() { 
00201                 llassert (mSharedData);
00202                 return mSharedData->mScale; 
00203         }
00204 
00205         //--------------------------------------------------------------------
00206         // Vertex Data Access
00207         //--------------------------------------------------------------------
00208         // Get number of vertices
00209         U32 getNumVertices() { 
00210                 llassert (mSharedData);
00211                 return mSharedData->mNumVertices; 
00212         }
00213 
00214         // Returns whether or not the mesh has detail texture coords
00215         BOOL hasDetailTexCoords() { 
00216                 llassert (mSharedData);
00217                 return mSharedData->mHasDetailTexCoords; 
00218         }
00219 
00220         // Returns whether or not the mesh has vertex weights
00221         BOOL hasWeights() const{ 
00222                 llassert (mSharedData);
00223                 return mSharedData->mHasWeights; 
00224         }
00225 
00226         // Get coords
00227         const LLVector3 *getCoords() const;
00228 
00229         // non const version
00230         LLVector3 *getWritableCoords();
00231 
00232         // Get normals
00233         const LLVector3 *getNormals() const{ 
00234                 return mNormals; 
00235         }
00236 
00237         // Get normals
00238         const LLVector3 *getBinormals() const{ 
00239                 return mBinormals; 
00240         }
00241 
00242         // Get base mesh normals
00243         const LLVector3 *getBaseNormals() const{
00244                 llassert(mSharedData);
00245                 return mSharedData->mBaseNormals;
00246         }
00247 
00248         // Get base mesh normals
00249         const LLVector3 *getBaseBinormals() const{
00250                 llassert(mSharedData);
00251                 return mSharedData->mBaseBinormals;
00252         }
00253 
00254         // intermediate morphed normals and output normals
00255         LLVector3 *getWritableNormals();
00256         LLVector3 *getScaledNormals();
00257 
00258         LLVector3 *getWritableBinormals();
00259         LLVector3 *getScaledBinormals();
00260 
00261         // Get texCoords
00262         const LLVector2 *getTexCoords() const { 
00263                 return mTexCoords; 
00264         }
00265 
00266         // non const version
00267         LLVector2 *getWritableTexCoords();
00268 
00269         // Get detailTexCoords
00270         const LLVector2 *getDetailTexCoords() const { 
00271                 llassert (mSharedData);
00272                 return mSharedData->mDetailTexCoords; 
00273         }
00274 
00275         // Get weights
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         // Face Data Access
00289         //--------------------------------------------------------------------
00290         // Get number of faces
00291         S32 getNumFaces() { 
00292                 llassert (mSharedData);
00293                 return mSharedData->mNumFaces; 
00294         }
00295 
00296         // Get faces
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         // Get indices
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         // Dumps diagnostic information about the global mesh table
00338         static void dumpDiagInfo();
00339 
00340 protected:
00341         // mesh data shared across all instances of a given mesh
00342         LLPolyMeshSharedData    *mSharedData;
00343         // Single array of floats for allocation / deletion
00344         F32                                             *mVertexData;
00345         // deformed vertices (resulting from application of morph targets)
00346         LLVector3                               *mCoords;
00347         // deformed normals (resulting from application of morph targets)
00348         LLVector3                               *mScaledNormals;
00349         // output normals (after normalization)
00350         LLVector3                               *mNormals;
00351         // deformed binormals (resulting from application of morph targets)
00352         LLVector3                               *mScaledBinormals;
00353         // output binormals (after normalization)
00354         LLVector3                               *mBinormals;
00355         // weight values that mark verts as clothing/skin
00356         LLVector4                               *mClothingWeights;
00357         // output texture coordinates
00358         LLVector2                               *mTexCoords;
00359         
00360         LLPolyMesh                              *mReferenceMesh;
00361 
00362         // global mesh list
00363         typedef LLAssocList<std::string, LLPolyMeshSharedData*> LLPolyMeshSharedDataTable; 
00364         static LLPolyMeshSharedDataTable sGlobalSharedMeshList;
00365 
00366         // Backlink only; don't make this an LLPointer.
00367         LLVOAvatar* mAvatarp;
00368 };
00369 
00370 //-----------------------------------------------------------------------------
00371 // LLPolySkeletalDeformationInfo
00372 // Shared information for LLPolySkeletalDeformations
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         /*virtual*/ ~LLPolySkeletalDistortionInfo() {};
00393         
00394         /*virtual*/ 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 // LLPolySkeletalDeformation
00403 // A set of joint scale data for deforming the avatar mesh
00404 //-----------------------------------------------------------------------------
00405 class LLPolySkeletalDistortion : public LLViewerVisualParam
00406 {
00407 public:
00408         LLPolySkeletalDistortion(LLVOAvatar *avatarp);
00409         ~LLPolySkeletalDistortion();
00410 
00411         // Special: These functions are overridden by child classes
00412         LLPolySkeletalDistortionInfo*   getInfo() const { return (LLPolySkeletalDistortionInfo*)mInfo; }
00413         //   This sets mInfo and calls initialization functions
00414         BOOL                                                    setInfo(LLPolySkeletalDistortionInfo *info);
00415 
00416         // LLVisualParam Virtual functions
00418         /*virtual*/ void                                apply( ESex sex );
00419         
00420         // LLViewerVisualParam Virtual functions
00421         /*virtual*/ F32                                 getTotalDistortion() { return 0.1f; }
00422         /*virtual*/ const LLVector3&    getAvgDistortion()      { return mDefaultVec; }
00423         /*virtual*/ F32                                 getMaxDistortion() { return 0.1f; }
00424         /*virtual*/ LLVector3                   getVertexDistortion(S32 index, LLPolyMesh *poly_mesh){return LLVector3(0.001f, 0.001f, 0.001f);}
00425         /*virtual*/ const LLVector3*    getFirstDistortion(U32 *index, LLPolyMesh **poly_mesh){index = 0; poly_mesh = NULL; return &mDefaultVec;};
00426         /*virtual*/ 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         // Backlink only; don't make this an LLPointer.
00434         LLVOAvatar *mAvatar;
00435 };
00436 
00437 #endif // LL_LLPOLYMESH_H
00438 

Generated on Thu Jul 1 06:09:01 2010 for Second Life Viewer by  doxygen 1.4.7