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

Generated on Fri May 16 08:33:56 2008 for SecondLife by  doxygen 1.5.5