diff options
Diffstat (limited to 'indra/llappearance/llpolymesh.cpp')
-rw-r--r-- | indra/llappearance/llpolymesh.cpp | 326 |
1 files changed, 163 insertions, 163 deletions
diff --git a/indra/llappearance/llpolymesh.cpp b/indra/llappearance/llpolymesh.cpp index dab14851c8..97f9ca68b6 100644 --- a/indra/llappearance/llpolymesh.cpp +++ b/indra/llappearance/llpolymesh.cpp @@ -1,25 +1,25 @@ -/** +/** * @file llpolymesh.cpp * @brief Implementation of LLPolyMesh class * * $LicenseInfo:firstyear=2001&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2010, Linden Research, Inc. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License only. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * + * * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ @@ -47,10 +47,10 @@ //extern LLControlGroup gSavedSettings; // read only LLPolyMorphData *clone_morph_param_duplicate(const LLPolyMorphData *src_data, - const std::string &name); + const std::string &name); LLPolyMorphData *clone_morph_param_direction(const LLPolyMorphData *src_data, - const LLVector3 &direction, - const std::string &name); + const LLVector3 &direction, + const std::string &name); LLPolyMorphData *clone_morph_param_cleavage(const LLPolyMorphData *src_data, F32 scale, const std::string &name); @@ -72,8 +72,8 @@ LLPolyMeshSharedData::LLPolyMeshSharedData() mTexCoords = NULL; mDetailTexCoords = NULL; mWeights = NULL; - mHasWeights = FALSE; - mHasDetailTexCoords = FALSE; + mHasWeights = false; + mHasDetailTexCoords = false; mNumFaces = 0; mFaces = NULL; @@ -225,7 +225,7 @@ U32 LLPolyMeshSharedData::getNumKB() //----------------------------------------------------------------------------- // LLPolyMeshSharedData::allocateVertexData() //----------------------------------------------------------------------------- -BOOL LLPolyMeshSharedData::allocateVertexData( U32 numVertices ) +bool LLPolyMeshSharedData::allocateVertexData( U32 numVertices ) { U32 i; mBaseCoords = (LLVector4a*) ll_aligned_malloc_16(numVertices*sizeof(LLVector4a)); @@ -236,41 +236,41 @@ BOOL LLPolyMeshSharedData::allocateVertexData( U32 numVertices ) mWeights = (F32*) ll_aligned_malloc_16(numVertices*sizeof(F32)); for (i = 0; i < numVertices; i++) { - mBaseCoords[i].clear(); - mBaseNormals[i].clear(); - mBaseBinormals[i].clear(); - mTexCoords[i].clear(); + mBaseCoords[i].clear(); + mBaseNormals[i].clear(); + mBaseBinormals[i].clear(); + mTexCoords[i].clear(); mWeights[i] = 0.f; } mNumVertices = numVertices; - return TRUE; + return true; } //----------------------------------------------------------------------------- // LLPolyMeshSharedData::allocateFaceData() //----------------------------------------------------------------------------- -BOOL LLPolyMeshSharedData::allocateFaceData( U32 numFaces ) +bool LLPolyMeshSharedData::allocateFaceData( U32 numFaces ) { mFaces = new LLPolyFace[ numFaces ]; mNumFaces = numFaces; mNumTriangleIndices = mNumFaces * 3; - return TRUE; + return true; } //----------------------------------------------------------------------------- // LLPolyMeshSharedData::allocateJointNames() //----------------------------------------------------------------------------- -BOOL LLPolyMeshSharedData::allocateJointNames( U32 numJointNames ) +bool LLPolyMeshSharedData::allocateJointNames( U32 numJointNames ) { mJointNames = new std::string[ numJointNames ]; mNumJointNames = numJointNames; - return TRUE; + return true; } //-------------------------------------------------------------------- // LLPolyMeshSharedData::loadMesh() //-------------------------------------------------------------------- -BOOL LLPolyMeshSharedData::loadMesh( const std::string& fileName ) +bool LLPolyMeshSharedData::loadMesh( const std::string& fileName ) { //------------------------------------------------------------------------- // Open the file @@ -278,13 +278,13 @@ BOOL LLPolyMeshSharedData::loadMesh( const std::string& fileName ) if(fileName.empty()) { LL_ERRS() << "Filename is Empty!" << LL_ENDL; - return FALSE; + return false; } LLFILE* fp = LLFile::fopen(fileName, "rb"); /*Flawfinder: ignore*/ if (!fp) { LL_ERRS() << "can't open: " << fileName << LL_ENDL; - return FALSE; + return false; } //------------------------------------------------------------------------- @@ -299,7 +299,7 @@ BOOL LLPolyMeshSharedData::loadMesh( const std::string& fileName ) //------------------------------------------------------------------------- // Check for proper binary header //------------------------------------------------------------------------- - BOOL status = FALSE; + bool status = false; if ( strncmp(header, HEADER_BINARY, strlen(HEADER_BINARY)) == 0 ) /*Flawfinder: ignore*/ { LL_DEBUGS() << "Loading " << fileName << LL_ENDL; @@ -317,11 +317,11 @@ BOOL LLPolyMeshSharedData::loadMesh( const std::string& fileName ) if (numRead != 1) { LL_ERRS() << "can't read HasWeights flag from " << fileName << LL_ENDL; - return FALSE; + return false; } if (!isLOD()) { - mHasWeights = (hasWeights==0) ? FALSE : TRUE; + mHasWeights = hasWeights > 0; } //---------------------------------------------------------------- @@ -332,7 +332,7 @@ BOOL LLPolyMeshSharedData::loadMesh( const std::string& fileName ) if (numRead != 1) { LL_ERRS() << "can't read HasDetailTexCoords flag from " << fileName << LL_ENDL; - return FALSE; + return false; } //---------------------------------------------------------------- @@ -344,7 +344,7 @@ BOOL LLPolyMeshSharedData::loadMesh( const std::string& fileName ) if (numRead != 3) { LL_ERRS() << "can't read Position from " << fileName << LL_ENDL; - return FALSE; + return false; } setPosition( position ); @@ -357,7 +357,7 @@ BOOL LLPolyMeshSharedData::loadMesh( const std::string& fileName ) if (numRead != 3) { LL_ERRS() << "can't read RotationAngles from " << fileName << LL_ENDL; - return FALSE; + return false; } U8 rotationOrder; @@ -366,7 +366,7 @@ BOOL LLPolyMeshSharedData::loadMesh( const std::string& fileName ) if (numRead != 1) { LL_ERRS() << "can't read RotationOrder from " << fileName << LL_ENDL; - return FALSE; + return false; } rotationOrder = 0; @@ -385,7 +385,7 @@ BOOL LLPolyMeshSharedData::loadMesh( const std::string& fileName ) if (numRead != 3) { LL_ERRS() << "can't read Scale from " << fileName << LL_ENDL; - return FALSE; + return false; } setScale( scale ); @@ -406,52 +406,52 @@ BOOL LLPolyMeshSharedData::loadMesh( const std::string& fileName ) if (numRead != 1) { LL_ERRS() << "can't read NumVertices from " << fileName << LL_ENDL; - return FALSE; + return false; } - allocateVertexData( numVertices ); - - for (U16 i = 0; i < numVertices; ++i) - { - //---------------------------------------------------------------- - // Coords - //---------------------------------------------------------------- - numRead = fread(&mBaseCoords[i], sizeof(float), 3, fp); - llendianswizzle(&mBaseCoords[i], sizeof(float), 3); - if (numRead != 3) - { - LL_ERRS() << "can't read Coordinates from " << fileName << LL_ENDL; - return FALSE; - } - } - - for (U16 i = 0; i < numVertices; ++i) - { - //---------------------------------------------------------------- - // Normals - //---------------------------------------------------------------- - numRead = fread(&mBaseNormals[i], sizeof(float), 3, fp); - llendianswizzle(&mBaseNormals[i], sizeof(float), 3); - if (numRead != 3) - { - LL_ERRS() << " can't read Normals from " << fileName << LL_ENDL; - return FALSE; - } - } - - for (U16 i = 0; i < numVertices; ++i) - { - //---------------------------------------------------------------- - // Binormals - //---------------------------------------------------------------- - numRead = fread(&mBaseBinormals[i], sizeof(float), 3, fp); - llendianswizzle(&mBaseBinormals[i], sizeof(float), 3); - if (numRead != 3) - { - LL_ERRS() << " can't read Binormals from " << fileName << LL_ENDL; - return FALSE; - } - } + allocateVertexData( numVertices ); + + for (U16 i = 0; i < numVertices; ++i) + { + //---------------------------------------------------------------- + // Coords + //---------------------------------------------------------------- + numRead = fread(&mBaseCoords[i], sizeof(float), 3, fp); + llendianswizzle(&mBaseCoords[i], sizeof(float), 3); + if (numRead != 3) + { + LL_ERRS() << "can't read Coordinates from " << fileName << LL_ENDL; + return false; + } + } + + for (U16 i = 0; i < numVertices; ++i) + { + //---------------------------------------------------------------- + // Normals + //---------------------------------------------------------------- + numRead = fread(&mBaseNormals[i], sizeof(float), 3, fp); + llendianswizzle(&mBaseNormals[i], sizeof(float), 3); + if (numRead != 3) + { + LL_ERRS() << " can't read Normals from " << fileName << LL_ENDL; + return false; + } + } + + for (U16 i = 0; i < numVertices; ++i) + { + //---------------------------------------------------------------- + // Binormals + //---------------------------------------------------------------- + numRead = fread(&mBaseBinormals[i], sizeof(float), 3, fp); + llendianswizzle(&mBaseBinormals[i], sizeof(float), 3); + if (numRead != 3) + { + LL_ERRS() << " can't read Binormals from " << fileName << LL_ENDL; + return false; + } + } //---------------------------------------------------------------- // TexCoords @@ -461,7 +461,7 @@ BOOL LLPolyMeshSharedData::loadMesh( const std::string& fileName ) if (numRead != numVertices) { LL_ERRS() << "can't read TexCoords from " << fileName << LL_ENDL; - return FALSE; + return false; } //---------------------------------------------------------------- @@ -474,7 +474,7 @@ BOOL LLPolyMeshSharedData::loadMesh( const std::string& fileName ) if (numRead != numVertices) { LL_ERRS() << "can't read DetailTexCoords from " << fileName << LL_ENDL; - return FALSE; + return false; } } @@ -488,7 +488,7 @@ BOOL LLPolyMeshSharedData::loadMesh( const std::string& fileName ) if (numRead != numVertices) { LL_ERRS() << "can't read Weights from " << fileName << LL_ENDL; - return FALSE; + return false; } } } @@ -502,7 +502,7 @@ BOOL LLPolyMeshSharedData::loadMesh( const std::string& fileName ) if (numRead != 1) { LL_ERRS() << "can't read NumFaces from " << fileName << LL_ENDL; - return FALSE; + return false; } allocateFaceData( numFaces ); @@ -520,7 +520,7 @@ BOOL LLPolyMeshSharedData::loadMesh( const std::string& fileName ) if (numRead != 3) { LL_ERRS() << "can't read Face[" << i << "] from " << fileName << LL_ENDL; - return FALSE; + return false; } if (mReferenceData) { @@ -528,7 +528,7 @@ BOOL LLPolyMeshSharedData::loadMesh( const std::string& fileName ) llassert(face[1] < mReferenceData->mNumVertices); llassert(face[2] < mReferenceData->mNumVertices); } - + if (isLOD()) { // store largest index in case of LODs @@ -559,7 +559,7 @@ BOOL LLPolyMeshSharedData::loadMesh( const std::string& fileName ) numTris++; } - LL_DEBUGS() << "verts: " << numVertices + LL_DEBUGS() << "verts: " << numVertices << ", faces: " << numFaces << ", tris: " << numTris << LL_ENDL; @@ -577,7 +577,7 @@ BOOL LLPolyMeshSharedData::loadMesh( const std::string& fileName ) if (numRead != 1) { LL_ERRS() << "can't read NumSkinJoints from " << fileName << LL_ENDL; - return FALSE; + return false; } allocateJointNames( numSkinJoints ); } @@ -593,7 +593,7 @@ BOOL LLPolyMeshSharedData::loadMesh( const std::string& fileName ) if (numRead != 1) { LL_ERRS() << "can't read Skin[" << i << "].Name from " << fileName << LL_ENDL; - return FALSE; + return false; } std::string *jn = &mJointNames[i]; @@ -615,7 +615,7 @@ BOOL LLPolyMeshSharedData::loadMesh( const std::string& fileName ) std::string morph_name(morphName); LLPolyMorphData* morph_data = new LLPolyMorphData(morph_name); - BOOL result = morph_data->loadBinary(fp, this); + bool result = morph_data->loadBinary(fp, this); if (!result) { @@ -636,46 +636,46 @@ BOOL LLPolyMeshSharedData::loadMesh( const std::string& fileName ) if (!strcmp(morphName, "Breast_Female_Cleavage")) { mMorphData.insert(clone_morph_param_duplicate(morph_data, - "Breast_Physics_InOut_Driven")); + "Breast_Physics_InOut_Driven")); } if (!strcmp(morphName, "Breast_Gravity")) { mMorphData.insert(clone_morph_param_duplicate(morph_data, - "Breast_Physics_UpDown_Driven")); + "Breast_Physics_UpDown_Driven")); } if (!strcmp(morphName, "Big_Belly_Torso")) { mMorphData.insert(clone_morph_param_direction(morph_data, - LLVector3(0,0,0.05f), - "Belly_Physics_Torso_UpDown_Driven")); + LLVector3(0,0,0.05f), + "Belly_Physics_Torso_UpDown_Driven")); } if (!strcmp(morphName, "Big_Belly_Legs")) { mMorphData.insert(clone_morph_param_direction(morph_data, - LLVector3(0,0,0.05f), - "Belly_Physics_Legs_UpDown_Driven")); + LLVector3(0,0,0.05f), + "Belly_Physics_Legs_UpDown_Driven")); } if (!strcmp(morphName, "skirt_belly")) { mMorphData.insert(clone_morph_param_direction(morph_data, - LLVector3(0,0,0.05f), - "Belly_Physics_Skirt_UpDown_Driven")); + LLVector3(0,0,0.05f), + "Belly_Physics_Skirt_UpDown_Driven")); } if (!strcmp(morphName, "Small_Butt")) { mMorphData.insert(clone_morph_param_direction(morph_data, - LLVector3(0,0,0.05f), - "Butt_Physics_UpDown_Driven")); + LLVector3(0,0,0.05f), + "Butt_Physics_UpDown_Driven")); } if (!strcmp(morphName, "Small_Butt")) { mMorphData.insert(clone_morph_param_direction(morph_data, - LLVector3(0,0.03f,0), - "Butt_Physics_LeftRight_Driven")); + LLVector3(0,0.03f,0), + "Butt_Physics_LeftRight_Driven")); } } @@ -705,12 +705,12 @@ BOOL LLPolyMeshSharedData::loadMesh( const std::string& fileName ) } } - status = TRUE; + status = true; } else { LL_ERRS() << "invalid mesh file header: " << fileName << LL_ENDL; - status = FALSE; + status = false; } if (0 == mNumJointNames) @@ -750,58 +750,58 @@ const LLVector2 &LLPolyMeshSharedData::getUVs(U32 index) // LLPolyMesh() //----------------------------------------------------------------------------- LLPolyMesh::LLPolyMesh(LLPolyMeshSharedData *shared_data, LLPolyMesh *reference_mesh) -{ - llassert(shared_data); - - mSharedData = shared_data; - mReferenceMesh = reference_mesh; - mAvatarp = NULL; - mVertexData = NULL; - - mCurVertexCount = 0; - mFaceIndexCount = 0; - mFaceIndexOffset = 0; - mFaceVertexCount = 0; - mFaceVertexOffset = 0; - - if (shared_data->isLOD() && reference_mesh) - { - mCoords = reference_mesh->mCoords; - mNormals = reference_mesh->mNormals; - mScaledNormals = reference_mesh->mScaledNormals; - mBinormals = reference_mesh->mBinormals; - mScaledBinormals = reference_mesh->mScaledBinormals; - mTexCoords = reference_mesh->mTexCoords; - mClothingWeights = reference_mesh->mClothingWeights; - } - else - { - // Allocate memory without initializing every vector - // NOTE: This makes asusmptions about the size of LLVector[234] - S32 nverts = mSharedData->mNumVertices; - //make sure it's an even number of verts for alignment - nverts += nverts%2; - S32 nfloats = nverts * ( - 4 + //coords - 4 + //normals - 4 + //weights - 2 + //coords - 4 + //scaled normals - 4 + //binormals - 4); //scaled binormals - - //use 16 byte aligned vertex data to make LLPolyMesh SSE friendly - mVertexData = (F32*) ll_aligned_malloc_16(nfloats*4); - S32 offset = 0; - mCoords = (LLVector4a*)(mVertexData + offset); offset += 4*nverts; - mNormals = (LLVector4a*)(mVertexData + offset); offset += 4*nverts; - mClothingWeights = (LLVector4a*)(mVertexData + offset); offset += 4*nverts; - mTexCoords = (LLVector2*)(mVertexData + offset); offset += 2*nverts; - mScaledNormals = (LLVector4a*)(mVertexData + offset); offset += 4*nverts; - mBinormals = (LLVector4a*)(mVertexData + offset); offset += 4*nverts; - mScaledBinormals = (LLVector4a*)(mVertexData + offset); offset += 4*nverts; - initializeForMorph(); - } +{ + llassert(shared_data); + + mSharedData = shared_data; + mReferenceMesh = reference_mesh; + mAvatarp = NULL; + mVertexData = NULL; + + mCurVertexCount = 0; + mFaceIndexCount = 0; + mFaceIndexOffset = 0; + mFaceVertexCount = 0; + mFaceVertexOffset = 0; + + if (shared_data->isLOD() && reference_mesh) + { + mCoords = reference_mesh->mCoords; + mNormals = reference_mesh->mNormals; + mScaledNormals = reference_mesh->mScaledNormals; + mBinormals = reference_mesh->mBinormals; + mScaledBinormals = reference_mesh->mScaledBinormals; + mTexCoords = reference_mesh->mTexCoords; + mClothingWeights = reference_mesh->mClothingWeights; + } + else + { + // Allocate memory without initializing every vector + // NOTE: This makes asusmptions about the size of LLVector[234] + S32 nverts = mSharedData->mNumVertices; + //make sure it's an even number of verts for alignment + nverts += nverts%2; + S32 nfloats = nverts * ( + 4 + //coords + 4 + //normals + 4 + //weights + 2 + //coords + 4 + //scaled normals + 4 + //binormals + 4); //scaled binormals + + //use 16 byte aligned vertex data to make LLPolyMesh SSE friendly + mVertexData = (F32*) ll_aligned_malloc_16(nfloats*4); + S32 offset = 0; + mCoords = (LLVector4a*)(mVertexData + offset); offset += 4*nverts; + mNormals = (LLVector4a*)(mVertexData + offset); offset += 4*nverts; + mClothingWeights = (LLVector4a*)(mVertexData + offset); offset += 4*nverts; + mTexCoords = (LLVector2*)(mVertexData + offset); offset += 2*nverts; + mScaledNormals = (LLVector4a*)(mVertexData + offset); offset += 4*nverts; + mBinormals = (LLVector4a*)(mVertexData + offset); offset += 4*nverts; + mScaledBinormals = (LLVector4a*)(mVertexData + offset); offset += 4*nverts; + initializeForMorph(); + } } @@ -810,8 +810,8 @@ LLPolyMesh::LLPolyMesh(LLPolyMeshSharedData *shared_data, LLPolyMesh *reference_ //----------------------------------------------------------------------------- LLPolyMesh::~LLPolyMesh() { - delete_and_clear(mJointRenderData); - ll_aligned_free_16(mVertexData); + delete_and_clear(mJointRenderData); + ll_aligned_free_16(mVertexData); } @@ -977,16 +977,16 @@ LLVector4a *LLPolyMesh::getScaledBinormals() void LLPolyMesh::initializeForMorph() { LLVector4a::memcpyNonAliased16((F32*) mCoords, (F32*) mSharedData->mBaseCoords, sizeof(LLVector4a) * mSharedData->mNumVertices); - LLVector4a::memcpyNonAliased16((F32*) mNormals, (F32*) mSharedData->mBaseNormals, sizeof(LLVector4a) * mSharedData->mNumVertices); - LLVector4a::memcpyNonAliased16((F32*) mScaledNormals, (F32*) mSharedData->mBaseNormals, sizeof(LLVector4a) * mSharedData->mNumVertices); - LLVector4a::memcpyNonAliased16((F32*) mBinormals, (F32*) mSharedData->mBaseNormals, sizeof(LLVector4a) * mSharedData->mNumVertices); - LLVector4a::memcpyNonAliased16((F32*) mScaledBinormals, (F32*) mSharedData->mBaseNormals, sizeof(LLVector4a) * mSharedData->mNumVertices); - LLVector4a::memcpyNonAliased16((F32*) mTexCoords, (F32*) mSharedData->mTexCoords, sizeof(LLVector2) * (mSharedData->mNumVertices + mSharedData->mNumVertices%2)); - - for (U32 i = 0; i < mSharedData->mNumVertices; ++i) - { - mClothingWeights[i].clear(); - } + LLVector4a::memcpyNonAliased16((F32*) mNormals, (F32*) mSharedData->mBaseNormals, sizeof(LLVector4a) * mSharedData->mNumVertices); + LLVector4a::memcpyNonAliased16((F32*) mScaledNormals, (F32*) mSharedData->mBaseNormals, sizeof(LLVector4a) * mSharedData->mNumVertices); + LLVector4a::memcpyNonAliased16((F32*) mBinormals, (F32*) mSharedData->mBaseNormals, sizeof(LLVector4a) * mSharedData->mNumVertices); + LLVector4a::memcpyNonAliased16((F32*) mScaledBinormals, (F32*) mSharedData->mBaseNormals, sizeof(LLVector4a) * mSharedData->mNumVertices); + LLVector4a::memcpyNonAliased16((F32*) mTexCoords, (F32*) mSharedData->mTexCoords, sizeof(LLVector2) * (mSharedData->mNumVertices + mSharedData->mNumVertices%2)); + + for (S32 i = 0; i < mSharedData->mNumVertices; ++i) + { + mClothingWeights[i].clear(); + } } //----------------------------------------------------------------------------- |