This commit is contained in:
Shyotl
2012-07-18 03:04:12 -05:00
parent 9c58d42a3c
commit d57d0ceb0d
8 changed files with 424 additions and 353 deletions

View File

@@ -155,6 +155,7 @@ LLDriverParam::LLDriverParam(LLVOAvatar *avatarp) :
mAvatarp(avatarp),
mWearablep(NULL)
{
mDefaultVec.clear();
}
LLDriverParam::LLDriverParam(LLWearable *wearablep) :
@@ -162,6 +163,7 @@ LLDriverParam::LLDriverParam(LLWearable *wearablep) :
mAvatarp(NULL),
mWearablep(wearablep)
{
mDefaultVec.clear();
}
LLDriverParam::~LLDriverParam()
@@ -341,18 +343,19 @@ F32 LLDriverParam::getTotalDistortion()
return sum;
}
const LLVector3 &LLDriverParam::getAvgDistortion()
const LLVector4a &LLDriverParam::getAvgDistortion()
{
// It's not actually correct to take the average of averages, but it good enough here.
LLVector3 sum;
LLVector4a sum;
sum.clear();
S32 count = 0;
for( entry_list_t::iterator iter = mDriven.begin(); iter != mDriven.end(); iter++ )
{
LLDrivenEntry* driven = &(*iter);
sum += driven->mParam->getAvgDistortion();
sum.add(driven->mParam->getAvgDistortion());
count++;
}
sum /= (F32)count;
sum.mul( 1.f/(F32)count);
mDefaultVec = sum;
return mDefaultVec;
@@ -375,21 +378,22 @@ F32 LLDriverParam::getMaxDistortion()
}
LLVector3 LLDriverParam::getVertexDistortion(S32 index, LLPolyMesh *poly_mesh)
LLVector4a LLDriverParam::getVertexDistortion(S32 index, LLPolyMesh *poly_mesh)
{
LLVector3 sum;
LLVector4a sum;
sum.clear();
for( entry_list_t::iterator iter = mDriven.begin(); iter != mDriven.end(); iter++ )
{
LLDrivenEntry* driven = &(*iter);
sum += driven->mParam->getVertexDistortion( index, poly_mesh );
sum.add(driven->mParam->getVertexDistortion( index, poly_mesh ));
}
return sum;
}
const LLVector3* LLDriverParam::getFirstDistortion(U32 *index, LLPolyMesh **poly_mesh)
const LLVector4a* LLDriverParam::getFirstDistortion(U32 *index, LLPolyMesh **poly_mesh)
{
mCurrentDistortionParam = NULL;
const LLVector3* v = NULL;
const LLVector4a* v = NULL;
for( entry_list_t::iterator iter = mDriven.begin(); iter != mDriven.end(); iter++ )
{
LLDrivenEntry* driven = &(*iter);
@@ -404,7 +408,7 @@ const LLVector3* LLDriverParam::getFirstDistortion(U32 *index, LLPolyMesh **poly
return v;
};
const LLVector3* LLDriverParam::getNextDistortion(U32 *index, LLPolyMesh **poly_mesh)
const LLVector4a* LLDriverParam::getNextDistortion(U32 *index, LLPolyMesh **poly_mesh)
{
llassert( mCurrentDistortionParam );
if( !mCurrentDistortionParam )
@@ -432,7 +436,7 @@ const LLVector3* LLDriverParam::getNextDistortion(U32 *index, LLPolyMesh **poly_
}
// We're already in the middle of a param's distortions, so get the next one.
const LLVector3* v = driven->mParam->getNextDistortion( index, poly_mesh );
const LLVector4a* v = driven->mParam->getNextDistortion( index, poly_mesh );
if( (!v) && (iter != mDriven.end()) )
{
// This param is finished, so start the next param. It might not have any

View File

@@ -105,18 +105,18 @@ public:
// LLViewerVisualParam Virtual functions
/*virtual*/ F32 getTotalDistortion();
/*virtual*/ const LLVector3& getAvgDistortion();
/*virtual*/ const LLVector4a& getAvgDistortion();
/*virtual*/ F32 getMaxDistortion();
/*virtual*/ LLVector3 getVertexDistortion(S32 index, LLPolyMesh *poly_mesh);
/*virtual*/ const LLVector3* getFirstDistortion(U32 *index, LLPolyMesh **poly_mesh);
/*virtual*/ const LLVector3* getNextDistortion(U32 *index, LLPolyMesh **poly_mesh);
/*virtual*/ LLVector4a getVertexDistortion(S32 index, LLPolyMesh *poly_mesh);
/*virtual*/ const LLVector4a* getFirstDistortion(U32 *index, LLPolyMesh **poly_mesh);
/*virtual*/ const LLVector4a* getNextDistortion(U32 *index, LLPolyMesh **poly_mesh);
protected:
F32 getDrivenWeight(const LLDrivenEntry* driven, F32 input_weight);
void setDrivenWeight(LLDrivenEntry *driven, F32 driven_weight, bool upload_bake);
LLVector3 mDefaultVec; // temp holder
LLVector4a mDefaultVec; // temp holder
typedef std::vector<LLDrivenEntry> entry_list_t;
entry_list_t mDriven;
LLViewerVisualParam* mCurrentDistortionParam;

View File

@@ -229,16 +229,20 @@ U32 LLPolyMeshSharedData::getNumKB()
BOOL LLPolyMeshSharedData::allocateVertexData( U32 numVertices )
{
U32 i;
mBaseCoords = new LLVector3[ numVertices ];
mBaseNormals = new LLVector3[ numVertices ];
mBaseBinormals = new LLVector3[ numVertices ];
mBaseCoords = new LLVector4a[ numVertices ];
mBaseNormals = new LLVector4a[ numVertices ];
mBaseBinormals = new LLVector4a[ numVertices ];
mTexCoords = new LLVector2[ numVertices ];
mDetailTexCoords = new LLVector2[ numVertices ];
mWeights = new F32[ numVertices ];
for (i = 0; i < numVertices; i++)
{
mBaseCoords[i].clear();
mBaseNormals[i].clear();
mBaseBinormals[i].clear();
mTexCoords[i].clear();
mWeights[i] = 0.f;
}
}
mNumVertices = numVertices;
return TRUE;
}
@@ -408,40 +412,48 @@ BOOL LLPolyMeshSharedData::loadMesh( const std::string& fileName )
allocateVertexData( numVertices );
//----------------------------------------------------------------
// Coords
//----------------------------------------------------------------
numRead = fread(mBaseCoords, 3*sizeof(float), numVertices, fp);
llendianswizzle(mBaseCoords, sizeof(float), 3*numVertices);
if (numRead != numVertices)
for (U16 i = 0; i < numVertices; ++i)
{
llerrs << "can't read Coordinates from " << fileName << llendl;
return FALSE;
}
//----------------------------------------------------------------
// Coords
//----------------------------------------------------------------
numRead = fread(&mBaseCoords[i], sizeof(float), 3, fp);
llendianswizzle(&mBaseCoords[i], sizeof(float), 3);
if (numRead != 3)
{
llerrs << "can't read Coordinates from " << fileName << llendl;
return FALSE;
}
}
//----------------------------------------------------------------
// Normals
//----------------------------------------------------------------
numRead = fread(mBaseNormals, 3*sizeof(float), numVertices, fp);
llendianswizzle(mBaseNormals, sizeof(float), 3*numVertices);
if (numRead != numVertices)
{
llerrs << " can't read Normals from " << fileName << llendl;
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)
{
llerrs << " can't read Normals from " << fileName << llendl;
return FALSE;
}
}
//----------------------------------------------------------------
// Binormals
//----------------------------------------------------------------
numRead = fread(mBaseBinormals, 3*sizeof(float), numVertices, fp);
llendianswizzle(mBaseBinormals, sizeof(float), 3*numVertices);
if (numRead != numVertices)
{
llerrs << " can't read Binormals from " << fileName << llendl;
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)
{
llerrs << " can't read Binormals from " << fileName << llendl;
return FALSE;
}
}
//----------------------------------------------------------------
// TexCoords
//----------------------------------------------------------------
@@ -767,21 +779,28 @@ LLPolyMesh::LLPolyMesh(LLPolyMeshSharedData *shared_data, LLPolyMesh *reference_
{
// Allocate memory without initializing every vector
// NOTE: This makes asusmptions about the size of LLVector[234]
int nverts = mSharedData->mNumVertices;
int nfloats = nverts * (2*4 + 3*3 + 2 + 4);
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);
int offset = 0;
mCoords = (LLVector4*)(mVertexData + offset); offset += 4*nverts;
mNormals = (LLVector4*)(mVertexData + offset); offset += 4*nverts;
mClothingWeights = (LLVector4*)(mVertexData + offset); offset += 4*nverts;
mTexCoords = (LLVector2*)(mVertexData + offset); offset += 2*nverts;
// these members don't need to be 16-byte aligned, but the first one might be
// read during an aligned memcpy of mTexCoords
mScaledNormals = (LLVector3*)(mVertexData + offset); offset += 3*nverts;
mBinormals = (LLVector3*)(mVertexData + offset); offset += 3*nverts;
mScaledBinormals = (LLVector3*)(mVertexData + offset); offset += 3*nverts;
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();
}
}
@@ -966,38 +985,47 @@ BOOL LLPolyMesh::saveLLM(LLFILE *fp)
//----------------------------------------------------------------
// Coords
//----------------------------------------------------------------
LLVector3* coords = mSharedData->mBaseCoords;
llendianswizzle(coords, sizeof(float), 3*numVertices);
if (fwrite(coords, 3*sizeof(float), numVertices, fp) != numVertices)
for (U16 i = 0; i < numVertices; ++i)
{
llwarns << "Short write" << llendl;
LLVector4a& coords = mSharedData->mBaseCoords[i];
llendianswizzle(coords.getF32ptr(), sizeof(float), 3);
if (fwrite(coords.getF32ptr(), 3*sizeof(float), 1, fp) != 1)
{
llwarns << "Short write" << llendl;
}
llendianswizzle(coords.getF32ptr(), sizeof(float), 3);
}
llendianswizzle(coords, sizeof(float), 3*numVertices);
//----------------------------------------------------------------
// Normals
//----------------------------------------------------------------
LLVector3* normals = mSharedData->mBaseNormals;
llendianswizzle(normals, sizeof(float), 3*numVertices);
if (fwrite(normals, 3*sizeof(float), numVertices, fp) != numVertices)
for (U16 i = 0; i < numVertices; ++i)
{
llwarns << "Short write" << llendl;
LLVector4a& normals = mSharedData->mBaseNormals[i];
llendianswizzle(normals.getF32ptr(), sizeof(float), 3);
if (fwrite(normals.getF32ptr(), 3*sizeof(float), 1, fp) != 1)
{
llwarns << "Short write" << llendl;
}
llendianswizzle(normals.getF32ptr(), sizeof(float), 3);
}
llendianswizzle(normals, sizeof(float), 3*numVertices);
//----------------------------------------------------------------
// Binormals
//----------------------------------------------------------------
LLVector3* binormals = mSharedData->mBaseBinormals;
llendianswizzle(binormals, sizeof(float), 3*numVertices);
if (fwrite(binormals, 3*sizeof(float), numVertices, fp) != numVertices)
for (U16 i = 0; i < numVertices; ++i)
{
llwarns << "Short write" << llendl;
LLVector4a& binormals = mSharedData->mBaseBinormals[i];
llendianswizzle(binormals.getF32ptr(), sizeof(float), 3);
if (fwrite(binormals.getF32ptr(), 3*sizeof(float), 1, fp) != 1)
{
llwarns << "Short write" << llendl;
}
llendianswizzle(binormals.getF32ptr(), sizeof(float), 3);
}
llendianswizzle(binormals, sizeof(float), 3*numVertices);
//----------------------------------------------------------------
// TexCoords
@@ -1224,24 +1252,24 @@ BOOL LLPolyMesh::saveOBJ(LLFILE *fp)
int nfaces = mSharedData->mNumFaces;
int i;
LLVector4* coords = getWritableCoords();
LLVector4a* coords = getWritableCoords();
for ( i=0; i<nverts; i++) {
std::string outstring = llformat("v %f %f %f\n",
coords[i][0],
coords[i][1],
coords[i][2]);
coords[i].getF32ptr()[0],
coords[i].getF32ptr()[1],
coords[i].getF32ptr()[2]);
if (fwrite(outstring.c_str(), 1, outstring.length(), fp) != outstring.length())
{
llwarns << "Short write" << llendl;
}
}
LLVector4* normals = getWritableNormals();
LLVector4a* normals = getWritableNormals();
for ( i=0; i<nverts; i++) {
std::string outstring = llformat("vn %f %f %f\n",
normals[i][0],
normals[i][1],
normals[i][2]);
normals[i].getF32ptr()[0],
normals[i].getF32ptr()[1],
normals[i].getF32ptr()[2]);
if (fwrite(outstring.c_str(), 1, outstring.length(), fp) != outstring.length())
{
llwarns << "Short write" << llendl;
@@ -1293,9 +1321,9 @@ BOOL LLPolyMesh::loadOBJ(LLFILE *fp)
int nnormals = 0;
int ntexcoords = 0;
LLVector4* coords = getWritableCoords();
LLVector4* normals = getWritableNormals();
LLVector3* binormals = getWritableBinormals();
LLVector4a* coords = getWritableCoords();
LLVector4a* normals = getWritableNormals();
LLVector4a* binormals = getWritableBinormals();
LLVector2* tex = getWritableTexCoords();
LLPolyFace* faces = getFaces();
@@ -1398,7 +1426,7 @@ BOOL LLPolyMesh::loadOBJ(LLFILE *fp)
int v;
for ( v=0; v<nverts; v++)
{
binormals[v].setZero();
binormals[v].clear();
}
int f;
@@ -1408,29 +1436,18 @@ BOOL LLPolyMesh::loadOBJ(LLFILE *fp)
S32 f1 = faces[f][1];
S32 f2 = faces[f][2];
LLVector4a v0;
LLVector4a v1;
LLVector4a v2;
v0.load3(coords[f0].mV);;
v1.load3(coords[f1].mV);;
v2.load3(coords[f2].mV);;
LLVector2& t0 = tex[f0];
LLVector2& t1 = tex[f1];
LLVector2& t2 = tex[f2];
LLVector4a binorm;
calc_binormal_from_triangle(binorm, v0, t0, v1, t1, v2, t2);
calc_binormal_from_triangle(binorm, coords[f0], tex[f0], coords[f1], tex[f1], coords[f2], tex[f2]);
binorm.normalize3fast();
LLVector3 binormdelta(binorm.getF32ptr());
binormals[f0] += binormdelta;
binormals[f1] += binormdelta;
binormals[f2] += binormdelta;
binormals[f0].add(binorm);
binormals[f1].add(binorm);
binormals[f2].add(binorm);
}
for ( v=0; v<nverts; v++)
{
binormals[v].normVec();
binormals[v].normalize3();
}
return TRUE;
@@ -1449,26 +1466,26 @@ BOOL LLPolyMesh::setSharedFromCurrent()
LLPolyMesh delta(mSharedData, NULL);
U32 nverts = delta.getNumVertices();
LLVector4 *delta_coords = delta.getWritableCoords();
LLVector4 *delta_normals = delta.getWritableNormals();
LLVector3 *delta_binormals = delta.getWritableBinormals();
LLVector4a *delta_coords = delta.getWritableCoords();
LLVector4a *delta_normals = delta.getWritableNormals();
LLVector4a *delta_binormals = delta.getWritableBinormals();
LLVector2 *delta_tex_coords = delta.getWritableTexCoords();
U32 vert_index;
for( vert_index = 0; vert_index < nverts; vert_index++)
{
delta_coords[vert_index] -= mCoords[vert_index];
delta_normals[vert_index] -= mNormals[vert_index];
delta_binormals[vert_index] -= mBinormals[vert_index];
delta_tex_coords[vert_index] -= mTexCoords[vert_index];
delta_coords[vert_index].sub( mCoords[vert_index]);
delta_normals[vert_index].sub( mNormals[vert_index]);
delta_binormals[vert_index].sub( mBinormals[vert_index]);
delta_tex_coords[vert_index] -= mTexCoords[vert_index];
}
// Now copy the new base mesh
memcpy(mSharedData->mBaseCoords, mCoords, sizeof(LLVector3) * mSharedData->mNumVertices);
memcpy(mSharedData->mBaseNormals, mNormals, sizeof(LLVector3) * mSharedData->mNumVertices);
memcpy(mSharedData->mBaseBinormals, mBinormals, sizeof(LLVector3) * mSharedData->mNumVertices);
memcpy(mSharedData->mTexCoords, mTexCoords, sizeof(LLVector2) * mSharedData->mNumVertices);
LLVector4a::memcpyNonAliased16((F32*) mSharedData->mBaseCoords, (F32*) mCoords, sizeof(LLVector4a) * mSharedData->mNumVertices);
LLVector4a::memcpyNonAliased16((F32*) mSharedData->mBaseNormals, (F32*) mNormals, sizeof(LLVector4a) * mSharedData->mNumVertices);
LLVector4a::memcpyNonAliased16((F32*) mSharedData->mBaseBinormals, (F32*) mBinormals, sizeof(LLVector4a) * mSharedData->mNumVertices);
LLVector4a::memcpyNonAliased16((F32*) mSharedData->mTexCoords, (F32*) mTexCoords, sizeof(LLVector2) * (mSharedData->mNumVertices + mSharedData->mNumVertices%2));
// Update all avatars by applying the delta
@@ -1479,27 +1496,29 @@ BOOL LLPolyMesh::setSharedFromCurrent()
LLPolyMesh* mesh = avatarp->getMesh(mSharedData);
if (mesh)
{
LLVector4 *mesh_coords = mesh->getWritableCoords();
LLVector4 *mesh_normals = mesh->getWritableNormals();
LLVector3 *mesh_binormals = mesh->getWritableBinormals();
LLVector2 *mesh_tex_coords = mesh->getWritableTexCoords();
LLVector3 *mesh_scaled_normals = mesh->getScaledNormals();
LLVector3 *mesh_scaled_binormals = mesh->getScaledBinormals();
LLVector4a *mesh_coords = mesh->getWritableCoords();
LLVector4a *mesh_normals = mesh->getWritableNormals();
LLVector4a *mesh_binormals = mesh->getWritableBinormals();
LLVector2 *mesh_tex_coords = mesh->getWritableTexCoords();
LLVector4a *mesh_scaled_normals = mesh->getScaledNormals();
LLVector4a *mesh_scaled_binormals = mesh->getScaledBinormals();
for( vert_index = 0; vert_index < nverts; vert_index++)
{
mesh_coords[vert_index] -= delta_coords[vert_index];
mesh_coords[vert_index].sub(delta_coords[vert_index]);
mesh_tex_coords[vert_index] -= delta_tex_coords[vert_index];
mesh_scaled_normals[vert_index] -= LLVector3(delta_normals[vert_index]);
LLVector3 normalized_normal = mesh_scaled_normals[vert_index];
normalized_normal.normVec();
mesh_normals[vert_index] = LLVector4(normalized_normal);
mesh_scaled_normals[vert_index].sub(delta_normals[vert_index]);
LLVector4a normalized_normal = mesh_scaled_normals[vert_index];
normalized_normal.normalize3();
mesh_normals[vert_index] = normalized_normal;
mesh_scaled_binormals[vert_index] -= delta_binormals[vert_index];
LLVector3 tangent = mesh_scaled_binormals[vert_index] % normalized_normal;
LLVector3 normalized_binormal = normalized_normal % tangent;
normalized_binormal.normVec();
mesh_scaled_binormals[vert_index].sub(delta_binormals[vert_index]);
LLVector4a tangent;
tangent.setCross3(mesh_scaled_binormals[vert_index], normalized_normal);
LLVector4a normalized_binormal;
normalized_binormal.setCross3(normalized_normal, tangent);
normalized_binormal.normalize3();
mesh_binormals[vert_index] = normalized_binormal;
}
@@ -1598,7 +1617,7 @@ void LLPolyMesh::dumpDiagInfo(void*)
//-----------------------------------------------------------------------------
// getWritableCoords()
//-----------------------------------------------------------------------------
LLVector4 *LLPolyMesh::getWritableCoords()
LLVector4a *LLPolyMesh::getWritableCoords()
{
return mCoords;
}
@@ -1606,7 +1625,7 @@ LLVector4 *LLPolyMesh::getWritableCoords()
//-----------------------------------------------------------------------------
// getWritableNormals()
//-----------------------------------------------------------------------------
LLVector4 *LLPolyMesh::getWritableNormals()
LLVector4a *LLPolyMesh::getWritableNormals()
{
return mNormals;
}
@@ -1614,7 +1633,7 @@ LLVector4 *LLPolyMesh::getWritableNormals()
//-----------------------------------------------------------------------------
// getWritableBinormals()
//-----------------------------------------------------------------------------
LLVector3 *LLPolyMesh::getWritableBinormals()
LLVector4a *LLPolyMesh::getWritableBinormals()
{
return mBinormals;
}
@@ -1623,7 +1642,7 @@ LLVector3 *LLPolyMesh::getWritableBinormals()
//-----------------------------------------------------------------------------
// getWritableClothingWeights()
//-----------------------------------------------------------------------------
LLVector4 *LLPolyMesh::getWritableClothingWeights()
LLVector4a *LLPolyMesh::getWritableClothingWeights()
{
return mClothingWeights;
}
@@ -1639,7 +1658,7 @@ LLVector2 *LLPolyMesh::getWritableTexCoords()
//-----------------------------------------------------------------------------
// getScaledNormals()
//-----------------------------------------------------------------------------
LLVector3 *LLPolyMesh::getScaledNormals()
LLVector4a *LLPolyMesh::getScaledNormals()
{
return mScaledNormals;
}
@@ -1647,7 +1666,7 @@ LLVector3 *LLPolyMesh::getScaledNormals()
//-----------------------------------------------------------------------------
// getScaledBinormals()
//-----------------------------------------------------------------------------
LLVector3 *LLPolyMesh::getScaledBinormals()
LLVector4a *LLPolyMesh::getScaledBinormals()
{
return mScaledBinormals;
}
@@ -1661,19 +1680,20 @@ void LLPolyMesh::initializeForMorph()
if (!mSharedData)
return;
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 < (U32)mSharedData->mNumVertices; ++i)
{
mCoords[i] = LLVector4(mSharedData->mBaseCoords[i]);
mNormals[i] = LLVector4(mSharedData->mBaseNormals[i]);
mClothingWeights[i].clear();
}
memcpy(mScaledNormals, mSharedData->mBaseNormals, sizeof(LLVector3) * mSharedData->mNumVertices); /*Flawfinder: ignore*/
memcpy(mBinormals, mSharedData->mBaseBinormals, sizeof(LLVector3) * mSharedData->mNumVertices); /*Flawfinder: ignore*/
memcpy(mScaledBinormals, mSharedData->mBaseBinormals, sizeof(LLVector3) * mSharedData->mNumVertices); /*Flawfinder: ignore*/
memcpy(mTexCoords, mSharedData->mTexCoords, sizeof(LLVector2) * mSharedData->mNumVertices); /*Flawfinder: ignore*/
memset(mClothingWeights, 0, sizeof(LLVector4) * mSharedData->mNumVertices);
}
//-----------------------------------------------------------------------------
// getMorphList()
//-----------------------------------------------------------------------------
@@ -1818,8 +1838,8 @@ BOOL LLPolySkeletalDistortionInfo::parseXml(LLXmlTreeNode* node)
//-----------------------------------------------------------------------------
LLPolySkeletalDistortion::LLPolySkeletalDistortion(LLVOAvatar *avatarp)
{
mAvatar = avatarp;
mDefaultVec.setVec(0.001f, 0.001f, 0.001f);
mAvatar = avatarp;
mDefaultVec.splat(0.001f);
}
//-----------------------------------------------------------------------------
@@ -1947,36 +1967,49 @@ LLPolyMorphData *clone_morph_param_direction(const LLPolyMorphData *src_data,
const LLVector3 &direction,
const std::string &name)
{
LLPolyMorphData* cloned_morph_data = new LLPolyMorphData(*src_data);
cloned_morph_data->mName = name;
for (U32 v=0; v < cloned_morph_data->mNumIndices; v++)
{
cloned_morph_data->mCoords[v] = direction;
cloned_morph_data->mNormals[v] = LLVector3(0,0,0);
cloned_morph_data->mBinormals[v] = LLVector3(0,0,0);
}
return cloned_morph_data;
LLPolyMorphData* cloned_morph_data = new LLPolyMorphData(*src_data);
cloned_morph_data->mName = name;
LLVector4a dir;
dir.load3(direction.mV);
for (U32 v=0; v < cloned_morph_data->mNumIndices; v++)
{
cloned_morph_data->mCoords[v] = dir;
cloned_morph_data->mNormals[v].clear();
cloned_morph_data->mBinormals[v].clear();
}
return cloned_morph_data;
}
LLPolyMorphData *clone_morph_param_cleavage(const LLPolyMorphData *src_data,
F32 scale,
const std::string &name)
{
LLPolyMorphData* cloned_morph_data = new LLPolyMorphData(*src_data);
cloned_morph_data->mName = name;
for (U32 v=0; v < cloned_morph_data->mNumIndices; v++)
{
cloned_morph_data->mCoords[v] = src_data->mCoords[v]*scale;
cloned_morph_data->mNormals[v] = src_data->mNormals[v]*scale;
cloned_morph_data->mBinormals[v] = src_data->mBinormals[v]*scale;
if (cloned_morph_data->mCoords[v][1] < 0)
{
cloned_morph_data->mCoords[v][1] *= -1;
cloned_morph_data->mNormals[v][1] *= -1;
cloned_morph_data->mBinormals[v][1] *= -1;
}
}
return cloned_morph_data;
LLPolyMorphData* cloned_morph_data = new LLPolyMorphData(*src_data);
cloned_morph_data->mName = name;
LLVector4a sc;
sc.splat(scale);
LLVector4a nsc;
nsc.set(scale, -scale, scale, scale);
for (U32 v=0; v < cloned_morph_data->mNumIndices; v++)
{
if (cloned_morph_data->mCoords[v][1] < 0)
{
cloned_morph_data->mCoords[v].setMul(src_data->mCoords[v],nsc);
cloned_morph_data->mNormals[v].setMul(src_data->mNormals[v],nsc);
cloned_morph_data->mBinormals[v].setMul(src_data->mBinormals[v],nsc);
}
else
{
cloned_morph_data->mCoords[v].setMul(src_data->mCoords[v],sc);
cloned_morph_data->mNormals[v].setMul(src_data->mNormals[v], sc);
cloned_morph_data->mBinormals[v].setMul(src_data->mBinormals[v],sc);
}
}
return cloned_morph_data;
}
// End

View File

@@ -73,9 +73,9 @@ private:
// vertex data
S32 mNumVertices;
LLVector3 *mBaseCoords;
LLVector3 *mBaseNormals;
LLVector3 *mBaseBinormals;
LLVector4a *mBaseCoords;
LLVector4a *mBaseNormals;
LLVector4a *mBaseBinormals;
LLVector2 *mTexCoords;
LLVector2 *mDetailTexCoords;
F32 *mWeights;
@@ -235,41 +235,41 @@ public:
}
// Get coords
const LLVector4 *getCoords() const{
const LLVector4a *getCoords() const{
return mCoords;
}
// non const version
LLVector4 *getWritableCoords();
LLVector4a *getWritableCoords();
// Get normals
const LLVector4 *getNormals() const{
const LLVector4a *getNormals() const{
return mNormals;
}
// Get normals
const LLVector3 *getBinormals() const{
const LLVector4a *getBinormals() const{
return mBinormals;
}
// Get base mesh normals
const LLVector3 *getBaseNormals() const{
const LLVector4a *getBaseNormals() const{
llassert(mSharedData);
return mSharedData->mBaseNormals;
}
// Get base mesh normals
const LLVector3 *getBaseBinormals() const{
const LLVector4a *getBaseBinormals() const{
llassert(mSharedData);
return mSharedData->mBaseBinormals;
}
// intermediate morphed normals and output normals
LLVector4 *getWritableNormals();
LLVector3 *getScaledNormals();
LLVector4a *getWritableNormals();
LLVector4a *getScaledNormals();
LLVector3 *getWritableBinormals();
LLVector3 *getScaledBinormals();
LLVector4a *getWritableBinormals();
LLVector4a *getScaledBinormals();
// Get texCoords
const LLVector2 *getTexCoords() const {
@@ -293,9 +293,9 @@ public:
F32 *getWritableWeights() const;
LLVector4 *getWritableClothingWeights();
LLVector4a *getWritableClothingWeights();
const LLVector4 *getClothingWeights()
const LLVector4a *getClothingWeights()
{
return mClothingWeights;
}
@@ -363,17 +363,17 @@ protected:
// Single array of floats for allocation / deletion
F32 *mVertexData;
// deformed vertices (resulting from application of morph targets)
LLVector4 *mCoords;
LLVector4a *mCoords;
// deformed normals (resulting from application of morph targets)
LLVector3 *mScaledNormals;
LLVector4a *mScaledNormals;
// output normals (after normalization)
LLVector4 *mNormals;
LLVector4a *mNormals;
// deformed binormals (resulting from application of morph targets)
LLVector3 *mScaledBinormals;
LLVector4a *mScaledBinormals;
// output binormals (after normalization)
LLVector3 *mBinormals;
LLVector4a *mBinormals;
// weight values that mark verts as clothing/skin
LLVector4 *mClothingWeights;
LLVector4a *mClothingWeights;
// output texture coordinates
LLVector2 *mTexCoords;
@@ -441,17 +441,17 @@ public:
// LLViewerVisualParam Virtual functions
/*virtual*/ F32 getTotalDistortion() { return 0.1f; }
/*virtual*/ const LLVector3& getAvgDistortion() { return mDefaultVec; }
/*virtual*/ const LLVector4a& getAvgDistortion() { return mDefaultVec; }
/*virtual*/ F32 getMaxDistortion() { return 0.1f; }
/*virtual*/ LLVector3 getVertexDistortion(S32 index, LLPolyMesh *poly_mesh){return LLVector3(0.001f, 0.001f, 0.001f);}
/*virtual*/ const LLVector3* getFirstDistortion(U32 *index, LLPolyMesh **poly_mesh){index = 0; poly_mesh = NULL; return &mDefaultVec;};
/*virtual*/ const LLVector3* getNextDistortion(U32 *index, LLPolyMesh **poly_mesh){index = 0; poly_mesh = NULL; return NULL;};
/*virtual*/ LLVector4a getVertexDistortion(S32 index, LLPolyMesh *poly_mesh){return LLVector4a(0.001f, 0.001f, 0.001f);}
/*virtual*/ const LLVector4a* getFirstDistortion(U32 *index, LLPolyMesh **poly_mesh){index = 0; poly_mesh = NULL; return &mDefaultVec;};
/*virtual*/ const LLVector4a* getNextDistortion(U32 *index, LLPolyMesh **poly_mesh){index = 0; poly_mesh = NULL; return NULL;};
protected:
typedef std::map<LLJoint*, LLVector3> joint_vec_map_t;
joint_vec_map_t mJointScales;
joint_vec_map_t mJointOffsets;
LLVector3 mDefaultVec;
LLVector4a mDefaultVec;
// Backlink only; don't make this an LLPointer.
LLVOAvatar *mAvatar;
};

View File

@@ -49,7 +49,7 @@ LLPolyMorphData::LLPolyMorphData(const std::string& morph_name)
mNumIndices = 0;
mCurrentIndex = 0;
mTotalDistortion = 0.f;
mAvgDistortion.zeroVec();
mAvgDistortion.clear();
mMaxDistortion = 0.f;
mVertexIndices = NULL;
mCoords = NULL;
@@ -74,9 +74,9 @@ LLPolyMorphData::LLPolyMorphData(const LLPolyMorphData &rhs) :
{
const S32 numVertices = mNumIndices;
mCoords = new LLVector3[numVertices];
mNormals = new LLVector3[numVertices];
mBinormals = new LLVector3[numVertices];
mCoords = new LLVector4a[numVertices];
mNormals = new LLVector4a[numVertices];
mBinormals = new LLVector4a[numVertices];
mTexCoords = new LLVector2[numVertices];
mVertexIndices = new U32[numVertices];
@@ -90,6 +90,7 @@ LLPolyMorphData::LLPolyMorphData(const LLPolyMorphData &rhs) :
}
}
//-----------------------------------------------------------------------------
// ~LLPolyMorphData()
//-----------------------------------------------------------------------------
@@ -121,16 +122,16 @@ BOOL LLPolyMorphData::loadBinary(LLFILE *fp, LLPolyMeshSharedData *mesh)
//-------------------------------------------------------------------------
// allocate vertices
//-------------------------------------------------------------------------
mCoords = new LLVector3[numVertices];
mNormals = new LLVector3[numVertices];
mBinormals = new LLVector3[numVertices];
mCoords = new LLVector4a[numVertices];
mNormals = new LLVector4a[numVertices];
mBinormals = new LLVector4a[numVertices];
mTexCoords = new LLVector2[numVertices];
// Actually, we are allocating more space than we need for the skiplist
mVertexIndices = new U32[numVertices];
mNumIndices = 0;
mTotalDistortion = 0.f;
mMaxDistortion = 0.f;
mAvgDistortion.zeroVec();
mAvgDistortion.clear();
mMesh = mesh;
//-------------------------------------------------------------------------
@@ -152,36 +153,36 @@ BOOL LLPolyMorphData::loadBinary(LLFILE *fp, LLPolyMeshSharedData *mesh)
}
numRead = fread(&mCoords[v].mV, sizeof(F32), 3, fp);
llendianswizzle(&mCoords[v].mV, sizeof(F32), 3);
numRead = fread(&mCoords[v], sizeof(F32), 3, fp);
llendianswizzle(&mCoords[v], sizeof(F32), 3);
if (numRead != 3)
{
llwarns << "Can't read morph target vertex coordinates" << llendl;
return FALSE;
}
F32 magnitude = mCoords[v].magVec();
F32 magnitude = mCoords[v].getLength3().getF32();
mTotalDistortion += magnitude;
mAvgDistortion.mV[VX] += fabs(mCoords[v].mV[VX]);
mAvgDistortion.mV[VY] += fabs(mCoords[v].mV[VY]);
mAvgDistortion.mV[VZ] += fabs(mCoords[v].mV[VZ]);
LLVector4a t;
t.setAbs(mCoords[v]);
mAvgDistortion.add(t);
if (magnitude > mMaxDistortion)
{
mMaxDistortion = magnitude;
}
numRead = fread(&mNormals[v].mV, sizeof(F32), 3, fp);
llendianswizzle(&mNormals[v].mV, sizeof(F32), 3);
numRead = fread(&mNormals[v], sizeof(F32), 3, fp);
llendianswizzle(&mNormals[v], sizeof(F32), 3);
if (numRead != 3)
{
llwarns << "Can't read morph target normal" << llendl;
return FALSE;
}
numRead = fread(&mBinormals[v].mV, sizeof(F32), 3, fp);
llendianswizzle(&mBinormals[v].mV, sizeof(F32), 3);
numRead = fread(&mBinormals[v], sizeof(F32), 3, fp);
llendianswizzle(&mBinormals[v], sizeof(F32), 3);
if (numRead != 3)
{
llwarns << "Can't read morph target binormal" << llendl;
@@ -200,8 +201,8 @@ BOOL LLPolyMorphData::loadBinary(LLFILE *fp, LLPolyMeshSharedData *mesh)
mNumIndices++;
}
mAvgDistortion = mAvgDistortion * (1.f/(F32)mNumIndices);
mAvgDistortion.normVec();
mAvgDistortion.mul(1.f/(F32)mNumIndices);
mAvgDistortion.normalize3fast();
return TRUE;
}
@@ -235,26 +236,26 @@ BOOL LLPolyMorphData::saveLLM(LLFILE *fp)
}
llendianswizzle(&mVertexIndices[v], sizeof(U32), 1);
llendianswizzle(&mCoords[v].mV, sizeof(F32), 3);
if (fwrite(&mCoords[v].mV, sizeof(F32), 3, fp) != 3)
llendianswizzle(mCoords[v].getF32ptr(), sizeof(F32), 3);
if (fwrite(mCoords[v].getF32ptr(), sizeof(F32), 3, fp) != 3)
{
llwarns << "Short write" << llendl;
}
llendianswizzle(&mCoords[v].mV, sizeof(F32), 3);
llendianswizzle(mCoords[v].getF32ptr(), sizeof(F32), 3);
llendianswizzle(&mNormals[v].mV, sizeof(F32), 3);
if (fwrite(&mNormals[v].mV, sizeof(F32), 3, fp) != 3)
llendianswizzle(mNormals[v].getF32ptr(), sizeof(F32), 3);
if (fwrite(mNormals[v].getF32ptr(), sizeof(F32), 3, fp) != 3)
{
llwarns << "Short write" << llendl;
}
llendianswizzle(&mNormals[v].mV, sizeof(F32), 3);
llendianswizzle(mNormals[v].getF32ptr(), sizeof(F32), 3);
llendianswizzle(&mBinormals[v].mV, sizeof(F32), 3);
if (fwrite(&mBinormals[v].mV, sizeof(F32), 3, fp) != 3)
llendianswizzle(mBinormals[v].getF32ptr(), sizeof(F32), 3);
if (fwrite(mBinormals[v].getF32ptr(), sizeof(F32), 3, fp) != 3)
{
llwarns << "Short write" << llendl;
}
llendianswizzle(&mBinormals[v].mV, sizeof(F32), 3);
llendianswizzle(mBinormals[v].getF32ptr(), sizeof(F32), 3);
llendianswizzle(&mTexCoords[v].mV, sizeof(F32), 2);
if (fwrite(&mTexCoords[v].mV, sizeof(F32), 2, fp) != 2)
@@ -277,17 +278,17 @@ BOOL LLPolyMorphData::saveOBJ(LLFILE *fp)
LLPolyMesh mesh(mMesh, NULL);
LLVector4 *coords = mesh.getWritableCoords();
LLVector4 *normals = mesh.getWritableNormals();
LLVector4a *coords = mesh.getWritableCoords();
LLVector4a *normals = mesh.getWritableNormals();
LLVector2 *tex_coords = mesh.getWritableTexCoords();
for(U32 vert_index_morph = 0; vert_index_morph < mNumIndices; vert_index_morph++)
{
S32 vert_index_mesh = mVertexIndices[vert_index_morph];
coords[vert_index_mesh] += LLVector4(mCoords[vert_index_morph]);
normals[vert_index_mesh] += LLVector4(mNormals[vert_index_morph]);
normals[vert_index_mesh].normVec();
coords[vert_index_mesh].add(mCoords[vert_index_morph]);
normals[vert_index_mesh].add(mNormals[vert_index_morph]);
normals[vert_index_mesh].normalize3();
tex_coords[vert_index_mesh] += mTexCoords[vert_index_morph];
}
@@ -302,9 +303,9 @@ BOOL LLPolyMorphData::setMorphFromMesh(LLPolyMesh *morph)
if (!morph)
return FALSE;
LLVector4 *morph_coords = morph->getWritableCoords();
LLVector4 *morph_normals = morph->getWritableNormals();
LLVector3 *morph_binormals = morph->getWritableBinormals();
LLVector4a *morph_coords = morph->getWritableCoords();
LLVector4a *morph_normals = morph->getWritableNormals();
LLVector4a *morph_binormals = morph->getWritableBinormals();
LLVector2 *morph_tex_coords = morph->getWritableTexCoords();
// We now have the morph loaded as a mesh. We have to subtract the
@@ -313,19 +314,19 @@ BOOL LLPolyMorphData::setMorphFromMesh(LLPolyMesh *morph)
LLPolyMesh delta(mMesh, NULL);
U32 nverts = delta.getNumVertices();
LLVector4 *delta_coords = delta.getWritableCoords();
LLVector4 *delta_normals = delta.getWritableNormals();
LLVector3 *delta_binormals = delta.getWritableBinormals();
LLVector4a *delta_coords = delta.getWritableCoords();
LLVector4a *delta_normals = delta.getWritableNormals();
LLVector4a *delta_binormals = delta.getWritableBinormals();
LLVector2 *delta_tex_coords = delta.getWritableTexCoords();
U32 num_significant = 0;
U32 vert_index;
for( vert_index = 0; vert_index < nverts; vert_index++)
{
delta_coords[vert_index] = morph_coords[vert_index] - delta_coords[vert_index];
delta_normals[vert_index] = morph_normals[vert_index] - delta_normals[vert_index];
delta_binormals[vert_index] = morph_binormals[vert_index] - delta_binormals[vert_index];
delta_tex_coords[vert_index] = morph_tex_coords[vert_index] - delta_tex_coords[vert_index];
delta_coords[vert_index].setSub( morph_coords[vert_index], delta_coords[vert_index]);
delta_normals[vert_index].setSub( morph_normals[vert_index], delta_normals[vert_index]);
delta_binormals[vert_index].setSub( morph_binormals[vert_index], delta_binormals[vert_index]);
delta_tex_coords[vert_index] = morph_tex_coords[vert_index] - delta_tex_coords[vert_index];
// For the normals and binormals, we really want the deltas
// to be perpendicular to the mesh (bi)normals in the plane
@@ -333,10 +334,10 @@ BOOL LLPolyMorphData::setMorphFromMesh(LLPolyMesh *morph)
// that the morph (bi)normals form the hypotenuses of right
// triangles. Right now, we just compute the difference vector.
if (delta_coords[vert_index].length() > SIGNIFICANT_DELTA
|| delta_normals[vert_index].length() > SIGNIFICANT_DELTA
|| delta_binormals[vert_index].length() > SIGNIFICANT_DELTA
|| delta_tex_coords[vert_index].length() > SIGNIFICANT_DELTA)
if (delta_coords[vert_index].getLength3().getF32() > SIGNIFICANT_DELTA
|| delta_normals[vert_index].getLength3().getF32() > SIGNIFICANT_DELTA
|| delta_binormals[vert_index].getLength3().getF32() > SIGNIFICANT_DELTA
|| delta_tex_coords[vert_index].length() > SIGNIFICANT_DELTA)
{
num_significant++;
}
@@ -353,39 +354,39 @@ BOOL LLPolyMorphData::setMorphFromMesh(LLPolyMesh *morph)
if (num_significant == 0)
nindices = 1;
LLVector3* new_coords = new LLVector3[nindices];
LLVector3* new_normals = new LLVector3[nindices];
LLVector3* new_binormals = new LLVector3[nindices];
LLVector4a* new_coords = new LLVector4a[nindices];
LLVector4a* new_normals = new LLVector4a[nindices];
LLVector4a* new_binormals = new LLVector4a[nindices];
LLVector2* new_tex_coords = new LLVector2[nindices];
U32* new_vertex_indices = new U32[nindices];
// We'll set the distortion directly
mTotalDistortion = 0.f;
mMaxDistortion = 0.f;
mAvgDistortion.zeroVec();
mAvgDistortion.clear();
U32 morph_index = 0;
for( vert_index = 0; vert_index < nverts; vert_index++)
{
if (delta_coords[vert_index].length() > SIGNIFICANT_DELTA
|| delta_normals[vert_index].length() > SIGNIFICANT_DELTA
|| delta_binormals[vert_index].length() > SIGNIFICANT_DELTA
|| delta_tex_coords[vert_index].length() > SIGNIFICANT_DELTA
if (delta_coords[vert_index].getLength3().getF32() > SIGNIFICANT_DELTA
|| delta_normals[vert_index].getLength3().getF32() > SIGNIFICANT_DELTA
|| delta_binormals[vert_index].getLength3().getF32() > SIGNIFICANT_DELTA
|| delta_tex_coords[vert_index].length() > SIGNIFICANT_DELTA
|| num_significant == 0)
{
new_vertex_indices[morph_index] = vert_index;
new_coords[morph_index] = LLVector3(delta_coords[vert_index]);
new_normals[morph_index] = LLVector3(delta_normals[vert_index]);
new_coords[morph_index] = delta_coords[vert_index];
new_normals[morph_index] = delta_normals[vert_index];
new_binormals[morph_index] = delta_binormals[vert_index];
new_tex_coords[morph_index] = delta_tex_coords[vert_index];
F32 magnitude = new_coords[morph_index].magVec();
F32 magnitude = new_coords[morph_index].getLength3().getF32();
mTotalDistortion += magnitude;
mAvgDistortion.mV[VX] += fabs(new_coords[morph_index].mV[VX]);
mAvgDistortion.mV[VY] += fabs(new_coords[morph_index].mV[VY]);
mAvgDistortion.mV[VZ] += fabs(new_coords[morph_index].mV[VZ]);
LLVector4a t;
t.setAbs(new_coords[morph_index]);
mAvgDistortion.add(t);
if (magnitude > mMaxDistortion)
{
@@ -397,8 +398,8 @@ BOOL LLPolyMorphData::setMorphFromMesh(LLPolyMesh *morph)
}
}
mAvgDistortion = mAvgDistortion * (1.f/(F32)nindices);
mAvgDistortion.normVec();
mAvgDistortion.mul(1.f/(F32)nindices);
mAvgDistortion.normalize3();
//-------------------------------------------------------------------------
// compute the change in the morph
@@ -412,9 +413,9 @@ BOOL LLPolyMorphData::setMorphFromMesh(LLPolyMesh *morph)
{
vert_index = mVertexIndices[morph_index];
delta_coords[vert_index] -= LLVector4(mCoords[morph_index]);
delta_normals[vert_index] -= LLVector4(mNormals[morph_index]);
delta_binormals[vert_index] -= mBinormals[morph_index];
delta_coords[vert_index].sub( mCoords[morph_index]);
delta_normals[vert_index].sub( mNormals[morph_index]);
delta_binormals[vert_index].sub(mBinormals[morph_index]);
delta_tex_coords[vert_index] -= mTexCoords[morph_index];
}
@@ -451,27 +452,35 @@ BOOL LLPolyMorphData::setMorphFromMesh(LLPolyMesh *morph)
continue;
}*/
LLVector4 *mesh_coords = mesh->getWritableCoords();
LLVector4 *mesh_normals = mesh->getWritableNormals();
LLVector3 *mesh_binormals = mesh->getWritableBinormals();
LLVector2 *mesh_tex_coords = mesh->getWritableTexCoords();
LLVector3 *mesh_scaled_normals = mesh->getScaledNormals();
LLVector3 *mesh_scaled_binormals = mesh->getScaledBinormals();
LLVector4a *mesh_coords = mesh->getWritableCoords();
LLVector4a *mesh_normals = mesh->getWritableNormals();
LLVector4a *mesh_binormals = mesh->getWritableBinormals();
LLVector2 *mesh_tex_coords = mesh->getWritableTexCoords();
LLVector4a *mesh_scaled_normals = mesh->getScaledNormals();
LLVector4a *mesh_scaled_binormals = mesh->getScaledBinormals();
for( vert_index = 0; vert_index < nverts; vert_index++)
{
mesh_coords[vert_index] += delta_coords[vert_index] * weight;
delta_coords[vert_index].mul(weight);
mesh_coords[vert_index].add(delta_coords[vert_index]);
mesh_tex_coords[vert_index] += delta_tex_coords[vert_index] * weight;
mesh_scaled_normals[vert_index] += LLVector3(delta_normals[vert_index] * weight * NORMAL_SOFTEN_FACTOR);
LLVector3 normalized_normal = mesh_scaled_normals[vert_index];
normalized_normal.normVec();
mesh_normals[vert_index] = LLVector4(normalized_normal);
delta_normals[vert_index].mul(weight * NORMAL_SOFTEN_FACTOR);
mesh_scaled_normals[vert_index].add(delta_normals[vert_index]);
LLVector4a normalized_normal = mesh_scaled_normals[vert_index];
normalized_normal.normalize3();
mesh_normals[vert_index] = normalized_normal;
mesh_scaled_binormals[vert_index] += delta_binormals[vert_index] * weight * NORMAL_SOFTEN_FACTOR;
LLVector3 tangent = mesh_scaled_binormals[vert_index] % normalized_normal;
LLVector3 normalized_binormal = normalized_normal % tangent;
normalized_binormal.normVec();
delta_binormals[vert_index].mul(weight * NORMAL_SOFTEN_FACTOR);
mesh_scaled_binormals[vert_index].add(delta_binormals[vert_index]);
LLVector4a tangent;
tangent.setCross3(mesh_scaled_binormals[vert_index], normalized_normal);
LLVector4a normalized_binormal;
normalized_binormal.setCross3(normalized_normal, tangent);
normalized_binormal.normalize3();
mesh_binormals[vert_index] = normalized_binormal;
}
@@ -658,9 +667,9 @@ BOOL LLPolyMorphTarget::parseData(LLXmlTreeNode* node)
//-----------------------------------------------------------------------------
// getVertexDistortion()
//-----------------------------------------------------------------------------
LLVector3 LLPolyMorphTarget::getVertexDistortion(S32 requested_index, LLPolyMesh *mesh)
LLVector4a LLPolyMorphTarget::getVertexDistortion(S32 requested_index, LLPolyMesh *mesh)
{
if (!mMorphData || mMesh != mesh) return LLVector3::zero;
if (!mMorphData || mMesh != mesh) return LLVector4a::getZero();
for(U32 index = 0; index < mMorphData->mNumIndices; index++)
{
@@ -670,17 +679,17 @@ LLVector3 LLPolyMorphTarget::getVertexDistortion(S32 requested_index, LLPolyMesh
}
}
return LLVector3::zero;
return LLVector4a::getZero();
}
//-----------------------------------------------------------------------------
// getFirstDistortion()
//-----------------------------------------------------------------------------
const LLVector3 *LLPolyMorphTarget::getFirstDistortion(U32 *index, LLPolyMesh **poly_mesh)
const LLVector4a *LLPolyMorphTarget::getFirstDistortion(U32 *index, LLPolyMesh **poly_mesh)
{
if (!mMorphData) return &LLVector3::zero;
if (!mMorphData) return &LLVector4a::getZero();
LLVector3* resultVec;
LLVector4a* resultVec;
mMorphData->mCurrentIndex = 0;
if (mMorphData->mNumIndices)
{
@@ -702,11 +711,11 @@ const LLVector3 *LLPolyMorphTarget::getFirstDistortion(U32 *index, LLPolyMesh **
//-----------------------------------------------------------------------------
// getNextDistortion()
//-----------------------------------------------------------------------------
const LLVector3 *LLPolyMorphTarget::getNextDistortion(U32 *index, LLPolyMesh **poly_mesh)
const LLVector4a *LLPolyMorphTarget::getNextDistortion(U32 *index, LLPolyMesh **poly_mesh)
{
if (!mMorphData) return &LLVector3::zero;
if (!mMorphData) return &LLVector4a::getZero();
LLVector3* resultVec;
LLVector4a* resultVec;
mMorphData->mCurrentIndex++;
if (mMorphData->mCurrentIndex < mMorphData->mNumIndices)
{
@@ -742,7 +751,7 @@ F32 LLPolyMorphTarget::getTotalDistortion()
//-----------------------------------------------------------------------------
// getAvgDistortion()
//-----------------------------------------------------------------------------
const LLVector3& LLPolyMorphTarget::getAvgDistortion()
const LLVector4a& LLPolyMorphTarget::getAvgDistortion()
{
if (mMorphData)
{
@@ -750,7 +759,7 @@ const LLVector3& LLPolyMorphTarget::getAvgDistortion()
}
else
{
return LLVector3::zero;
return LLVector4a::getZero();
}
}
@@ -799,15 +808,15 @@ void LLPolyMorphTarget::apply( ESex avatar_sex )
if (delta_weight != 0.f)
{
llassert(!mMesh->isLOD());
LLVector4 *coords = mMesh->getWritableCoords();
LLVector4a *coords = mMesh->getWritableCoords();
LLVector3 *scaled_normals = mMesh->getScaledNormals();
LLVector4 *normals = mMesh->getWritableNormals();
LLVector4a *scaled_normals = mMesh->getScaledNormals();
LLVector4a *normals = mMesh->getWritableNormals();
LLVector3 *scaled_binormals = mMesh->getScaledBinormals();
LLVector3 *binormals = mMesh->getWritableBinormals();
LLVector4a *scaled_binormals = mMesh->getScaledBinormals();
LLVector4a *binormals = mMesh->getWritableBinormals();
LLVector4 *clothing_weights = mMesh->getWritableClothingWeights();
LLVector4a *clothing_weights = mMesh->getWritableClothingWeights();
LLVector2 *tex_coords = mMesh->getWritableTexCoords();
F32 *maskWeightArray = (mVertMask) ? mVertMask->getMorphMaskWeights() : NULL;
@@ -822,31 +831,38 @@ void LLPolyMorphTarget::apply( ESex avatar_sex )
maskWeight = maskWeightArray[vert_index_morph];
}
coords[vert_index_mesh] += LLVector4(mMorphData->mCoords[vert_index_morph] * delta_weight * maskWeight);
LLVector4a pos = mMorphData->mCoords[vert_index_morph];
pos.mul(delta_weight*maskWeight);
coords[vert_index_mesh].add(pos);
if (getInfo()->mIsClothingMorph && clothing_weights)
{
LLVector3 clothing_offset = mMorphData->mCoords[vert_index_morph] * delta_weight * maskWeight;
LLVector4* clothing_weight = &clothing_weights[vert_index_mesh];
clothing_weight->mV[VX] += clothing_offset.mV[VX];
clothing_weight->mV[VY] += clothing_offset.mV[VY];
clothing_weight->mV[VZ] += clothing_offset.mV[VZ];
clothing_weight->mV[VW] = maskWeight;
LLVector4a clothing_offset = mMorphData->mCoords[vert_index_morph];
clothing_offset.mul(delta_weight * maskWeight);
LLVector4a* clothing_weight = &clothing_weights[vert_index_mesh];
clothing_weight->add(clothing_offset);
clothing_weight->getF32ptr()[VW] = maskWeight;
}
// calculate new normals based on half angles
scaled_normals[vert_index_mesh] += mMorphData->mNormals[vert_index_morph] * delta_weight * maskWeight * NORMAL_SOFTEN_FACTOR;
LLVector3 normalized_normal = scaled_normals[vert_index_mesh];
normalized_normal.normVec();
normals[vert_index_mesh] = LLVector4(normalized_normal);
LLVector4a norm = mMorphData->mNormals[vert_index_morph];
norm.mul(delta_weight*maskWeight*NORMAL_SOFTEN_FACTOR);
scaled_normals[vert_index_mesh].add(norm);
norm = scaled_normals[vert_index_mesh];
norm.normalize3fast();
normals[vert_index_mesh] = norm;
// calculate new binormals
scaled_binormals[vert_index_mesh] += mMorphData->mBinormals[vert_index_morph] * delta_weight * maskWeight * NORMAL_SOFTEN_FACTOR;
LLVector3 tangent = scaled_binormals[vert_index_mesh] % normalized_normal;
LLVector3 normalized_binormal = normalized_normal % tangent;
normalized_binormal.normVec();
binormals[vert_index_mesh] = normalized_binormal;
LLVector4a binorm = mMorphData->mBinormals[vert_index_morph];
binorm.mul(delta_weight*maskWeight*NORMAL_SOFTEN_FACTOR);
scaled_binormals[vert_index_mesh].add(binorm);
LLVector4a tangent;
tangent.setCross3(scaled_binormals[vert_index_mesh], norm);
LLVector4a& normalized_binormal = binormals[vert_index_mesh];
normalized_binormal.setCross3(norm, tangent);
normalized_binormal.normalize3fast();
tex_coords[vert_index_mesh] += mMorphData->mTexCoords[vert_index_morph] * delta_weight * maskWeight;
}
@@ -873,7 +889,7 @@ void LLPolyMorphTarget::apply( ESex avatar_sex )
//-----------------------------------------------------------------------------
void LLPolyMorphTarget::applyMask(U8 *maskTextureData, S32 width, S32 height, S32 num_components, BOOL invert)
{
LLVector4 *clothing_weights = getInfo()->mIsClothingMorph ? mMesh->getWritableClothingWeights() : NULL;
LLVector4a *clothing_weights = getInfo()->mIsClothingMorph ? mMesh->getWritableClothingWeights() : NULL;
if (!mVertMask)
{
@@ -887,29 +903,47 @@ void LLPolyMorphTarget::applyMask(U8 *maskTextureData, S32 width, S32 height, S3
if (maskWeights)
{
LLVector4 *coords = mMesh->getWritableCoords();
LLVector3 *scaled_normals = mMesh->getScaledNormals();
LLVector3 *scaled_binormals = mMesh->getScaledBinormals();
LLVector4a *coords = mMesh->getWritableCoords();
LLVector4a *scaled_normals = mMesh->getScaledNormals();
LLVector4a *scaled_binormals = mMesh->getScaledBinormals();
LLVector2 *tex_coords = mMesh->getWritableTexCoords();
LLVector4Logical clothing_mask;
clothing_mask.clear();
clothing_mask.setElement<0>();
clothing_mask.setElement<1>();
clothing_mask.setElement<2>();
for(U32 vert = 0; vert < mMorphData->mNumIndices; vert++)
{
F32 lastMaskWeight = mLastWeight * maskWeights[vert];
S32 out_vert = mMorphData->mVertexIndices[vert];
// remove effect of existing masked morph
coords[out_vert] -= LLVector4(mMorphData->mCoords[vert]) * lastMaskWeight;
scaled_normals[out_vert] -= mMorphData->mNormals[vert] * lastMaskWeight * NORMAL_SOFTEN_FACTOR;
scaled_binormals[out_vert] -= mMorphData->mBinormals[vert] * lastMaskWeight * NORMAL_SOFTEN_FACTOR;
LLVector4a t;
t = mMorphData->mCoords[vert];
t.mul(lastMaskWeight);
coords[out_vert].sub(t);
t = mMorphData->mNormals[vert];
t.mul(lastMaskWeight*NORMAL_SOFTEN_FACTOR);
scaled_normals[out_vert].sub(t);
t = mMorphData->mBinormals[vert];
t.mul(lastMaskWeight*NORMAL_SOFTEN_FACTOR);
scaled_binormals[out_vert].sub(t);
tex_coords[out_vert] -= mMorphData->mTexCoords[vert] * lastMaskWeight;
if (clothing_weights)
{
LLVector3 clothing_offset = mMorphData->mCoords[vert] * lastMaskWeight;
LLVector4* clothing_weight = &clothing_weights[out_vert];
clothing_weight->mV[VX] -= clothing_offset.mV[VX];
clothing_weight->mV[VY] -= clothing_offset.mV[VY];
clothing_weight->mV[VZ] -= clothing_offset.mV[VZ];
LLVector4a clothing_offset = mMorphData->mCoords[vert];
clothing_offset.mul(lastMaskWeight);
LLVector4a* clothing_weight = &clothing_weights[out_vert];
LLVector4a t;
t.setSub(*clothing_weight, clothing_offset);
clothing_weight->setSelectWithMask(clothing_mask, t, *clothing_weight);
}
}
}
@@ -945,7 +979,7 @@ LLPolyVertexMask::~LLPolyVertexMask()
//-----------------------------------------------------------------------------
// generateMask()
//-----------------------------------------------------------------------------
void LLPolyVertexMask::generateMask(U8 *maskTextureData, S32 width, S32 height, S32 num_components, BOOL invert, LLVector4 *clothing_weights)
void LLPolyVertexMask::generateMask(U8 *maskTextureData, S32 width, S32 height, S32 num_components, BOOL invert, LLVector4a *clothing_weights)
{
// RN debug output that uses Image Debugger (http://www.cs.unc.edu/~baxter/projects/imdebug/)
// BOOL debugImg = FALSE;
@@ -989,7 +1023,7 @@ void LLPolyVertexMask::generateMask(U8 *maskTextureData, S32 width, S32 height,
if (clothing_weights)
{
clothing_weights[vertIndex].mV[VW] = mWeights[index];
clothing_weights[vertIndex].getF32ptr()[VW] = mWeights[index];
}
}
mWeightsGenerated = TRUE;

View File

@@ -68,14 +68,14 @@ public:
U32 mNumIndices;
U32* mVertexIndices;
U32 mCurrentIndex;
LLVector3* mCoords;
LLVector3* mNormals;
LLVector3* mBinormals;
LLVector4a* mCoords;
LLVector4a* mNormals;
LLVector4a* mBinormals;
LLVector2* mTexCoords;
F32 mTotalDistortion; // vertex distortion summed over entire morph
F32 mMaxDistortion; // maximum single vertex distortion in a given morph
LLVector3 mAvgDistortion; // average vertex distortion, to infer directionality of the morph
LLVector4a mAvgDistortion; // average vertex distortion, to infer directionality of the morph
LLPolyMeshSharedData* mMesh;
};
@@ -88,7 +88,7 @@ public:
LLPolyVertexMask(LLPolyMorphData* morph_data);
~LLPolyVertexMask();
void generateMask(U8 *maskData, S32 width, S32 height, S32 num_components, BOOL invert, LLVector4 *clothing_weights);
void generateMask(U8 *maskData, S32 width, S32 height, S32 num_components, BOOL invert, LLVector4a *clothing_weights);
F32* getMorphMaskWeights();
@@ -167,11 +167,11 @@ public:
// LLViewerVisualParam Virtual functions
/*virtual*/ F32 getTotalDistortion();
/*virtual*/ const LLVector3& getAvgDistortion();
/*virtual*/ const LLVector4a& getAvgDistortion();
/*virtual*/ F32 getMaxDistortion();
/*virtual*/ LLVector3 getVertexDistortion(S32 index, LLPolyMesh *poly_mesh);
/*virtual*/ const LLVector3* getFirstDistortion(U32 *index, LLPolyMesh **poly_mesh);
/*virtual*/ const LLVector3* getNextDistortion(U32 *index, LLPolyMesh **poly_mesh);
/*virtual*/ LLVector4a getVertexDistortion(S32 index, LLPolyMesh *poly_mesh);
/*virtual*/ const LLVector4a* getFirstDistortion(U32 *index, LLPolyMesh **poly_mesh);
/*virtual*/ const LLVector4a* getNextDistortion(U32 *index, LLPolyMesh **poly_mesh);
void applyMask(U8 *maskData, S32 width, S32 height, S32 num_components, BOOL invert);
void addPendingMorphMask() { mNumMorphMasksPending++; }

View File

@@ -76,11 +76,11 @@ public:
// LLViewerVisualParam Virtual functions
/*virtual*/ F32 getTotalDistortion() { return 1.f; }
/*virtual*/ const LLVector3& getAvgDistortion() { return mAvgDistortionVec; }
/*virtual*/ const LLVector4a& getAvgDistortion() { return mAvgDistortionVec; }
/*virtual*/ F32 getMaxDistortion() { return 3.f; }
/*virtual*/ LLVector3 getVertexDistortion(S32 index, LLPolyMesh *poly_mesh) { return LLVector3(1.f, 1.f, 1.f);}
/*virtual*/ const LLVector3* getFirstDistortion(U32 *index, LLPolyMesh **poly_mesh) { index = 0; poly_mesh = NULL; return &mAvgDistortionVec;};
/*virtual*/ const LLVector3* getNextDistortion(U32 *index, LLPolyMesh **poly_mesh) { index = 0; poly_mesh = NULL; return NULL;};
/*virtual*/ LLVector4a getVertexDistortion(S32 index, LLPolyMesh *poly_mesh) { return LLVector4a(1.f, 1.f, 1.f);}
/*virtual*/ const LLVector4a* getFirstDistortion(U32 *index, LLPolyMesh **poly_mesh) { index = 0; poly_mesh = NULL; return &mAvgDistortionVec;};
/*virtual*/ const LLVector4a* getNextDistortion(U32 *index, LLPolyMesh **poly_mesh) { index = 0; poly_mesh = NULL; return NULL;};
// New functions
BOOL render( S32 x, S32 y, S32 width, S32 height );
@@ -94,7 +94,7 @@ private:
LLPointer<LLImageRaw> mStaticImageRaw;
BOOL mNeedsCreateTexture;
BOOL mStaticImageInvalid;
LLVector3 mAvgDistortionVec;
LLVector4a mAvgDistortionVec;
F32 mCachedEffectiveWeight;
public:
@@ -155,18 +155,18 @@ public:
// LLViewerVisualParam Virtual functions
/*virtual*/ F32 getTotalDistortion() { return 1.f; }
/*virtual*/ const LLVector3& getAvgDistortion() { return mAvgDistortionVec; }
/*virtual*/ const LLVector4a& getAvgDistortion() { return mAvgDistortionVec; }
/*virtual*/ F32 getMaxDistortion() { return 3.f; }
/*virtual*/ LLVector3 getVertexDistortion(S32 index, LLPolyMesh *poly_mesh) { return LLVector3(1.f, 1.f, 1.f); }
/*virtual*/ const LLVector3* getFirstDistortion(U32 *index, LLPolyMesh **poly_mesh) { index = 0; poly_mesh = NULL; return &mAvgDistortionVec;};
/*virtual*/ const LLVector3* getNextDistortion(U32 *index, LLPolyMesh **poly_mesh) { index = 0; poly_mesh = NULL; return NULL;};
/*virtual*/ LLVector4a getVertexDistortion(S32 index, LLPolyMesh *poly_mesh) { return LLVector4a(1.f, 1.f, 1.f); }
/*virtual*/ const LLVector4a* getFirstDistortion(U32 *index, LLPolyMesh **poly_mesh) { index = 0; poly_mesh = NULL; return &mAvgDistortionVec;};
/*virtual*/ const LLVector4a* getNextDistortion(U32 *index, LLPolyMesh **poly_mesh) { index = 0; poly_mesh = NULL; return NULL;};
// New functions
LLColor4 getNetColor() const;
protected:
virtual void onGlobalColorChanged(bool upload_bake) {}
private:
LLVector3 mAvgDistortionVec;
LLVector4a mAvgDistortionVec;
};
class LLTexLayerParamColorInfo : public LLViewerVisualParamInfo

View File

@@ -84,11 +84,11 @@ public:
// New Virtual functions
virtual F32 getTotalDistortion() = 0;
virtual const LLVector3& getAvgDistortion() = 0;
virtual const LLVector4a& getAvgDistortion() = 0;
virtual F32 getMaxDistortion() = 0;
virtual LLVector3 getVertexDistortion(S32 index, LLPolyMesh *mesh) = 0;
virtual const LLVector3* getFirstDistortion(U32 *index, LLPolyMesh **mesh) = 0;
virtual const LLVector3* getNextDistortion(U32 *index, LLPolyMesh **mesh) = 0;
virtual LLVector4a getVertexDistortion(S32 index, LLPolyMesh *mesh) = 0;
virtual const LLVector4a* getFirstDistortion(U32 *index, LLPolyMesh **mesh) = 0;
virtual const LLVector4a* getNextDistortion(U32 *index, LLPolyMesh **mesh) = 0;
// interface methods
F32 getDisplayOrder() const { return getInfo()->mEditGroupDisplayOrder; }