Flipped the MESH_ENABLED switch. Added missing components and updated stuff to be closer to mesh-development head.
This commit is contained in:
@@ -2138,6 +2138,13 @@ LLVolume::~LLVolume()
|
||||
mPathp = NULL;
|
||||
mProfilep = NULL;
|
||||
mVolumeFaces.clear();
|
||||
|
||||
#if MESH_ENABLED
|
||||
ll_aligned_free_16(mHullPoints);
|
||||
mHullPoints = NULL;
|
||||
ll_aligned_free_16(mHullIndices);
|
||||
mHullIndices = NULL;
|
||||
#endif //MESH_ENABLED
|
||||
}
|
||||
|
||||
BOOL LLVolume::generate()
|
||||
@@ -2378,11 +2385,16 @@ bool LLVolumeFace::VertexData::operator==(const LLVolumeFace::VertexData& rhs)co
|
||||
bool LLVolumeFace::VertexData::compareNormal(const LLVolumeFace::VertexData& rhs, F32 angle_cutoff) const
|
||||
{
|
||||
bool retval = false;
|
||||
if (rhs.mData[POSITION].equals3(mData[POSITION]) && rhs.mTexCoord == mTexCoord)
|
||||
|
||||
const F32 epsilon = 0.00001f;
|
||||
|
||||
if (rhs.mData[POSITION].equals3(mData[POSITION], epsilon) &&
|
||||
fabs(rhs.mTexCoord[0]-mTexCoord[0]) < epsilon &&
|
||||
fabs(rhs.mTexCoord[1]-mTexCoord[1]) < epsilon)
|
||||
{
|
||||
if (angle_cutoff > 1.f)
|
||||
{
|
||||
retval = (mData[NORMAL].equals3(rhs.mData[NORMAL]));
|
||||
retval = (mData[NORMAL].equals3(rhs.mData[NORMAL], epsilon));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2499,9 +2511,9 @@ bool LLVolume::unpackVolumeFaces(std::istream& is, S32 size)
|
||||
}
|
||||
|
||||
{
|
||||
U16* n = (U16*) &(norm[0]);
|
||||
if(n)
|
||||
if (!norm.empty())
|
||||
{
|
||||
U16* n = (U16*) &(norm[0]);
|
||||
for (U32 j = 0; j < num_verts; ++j)
|
||||
{
|
||||
norm_out->set((F32) n[0], (F32) n[1], (F32) n[2]);
|
||||
@@ -2512,12 +2524,16 @@ bool LLVolume::unpackVolumeFaces(std::istream& is, S32 size)
|
||||
n += 3;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
memset(norm_out, 0, sizeof(LLVector4a)*num_verts);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
U16* t = (U16*) &(tc[0]);
|
||||
if(t)
|
||||
if (!tc.empty())
|
||||
{
|
||||
U16* t = (U16*) &(tc[0]);
|
||||
for (U32 j = 0; j < num_verts; j+=2)
|
||||
{
|
||||
if (j < num_verts-1)
|
||||
@@ -2538,6 +2554,10 @@ bool LLVolume::unpackVolumeFaces(std::istream& is, S32 size)
|
||||
tc_out++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
memset(tc_out, 0, sizeof(LLVector2)*num_verts);
|
||||
}
|
||||
}
|
||||
|
||||
if (mdl[i].has("Weights"))
|
||||
@@ -2635,7 +2655,7 @@ bool LLVolume::unpackVolumeFaces(std::istream& is, S32 size)
|
||||
|
||||
if (do_reverse_triangles)
|
||||
{
|
||||
for (U32 j = 0; j < face.mNumIndices; j += 3)
|
||||
for (U32 j = 0; j < (U32)face.mNumIndices; j += 3)
|
||||
{
|
||||
// swap the 2nd and 3rd index
|
||||
S32 swap = face.mIndices[j+1];
|
||||
@@ -2662,6 +2682,25 @@ bool LLVolume::unpackVolumeFaces(std::istream& is, S32 size)
|
||||
min.setMin(min, face.mPositions[i]);
|
||||
max.setMax(max, face.mPositions[i]);
|
||||
}
|
||||
|
||||
if (face.mTexCoords)
|
||||
{
|
||||
LLVector2& min_tc = face.mTexCoordExtents[0];
|
||||
LLVector2& max_tc = face.mTexCoordExtents[1];
|
||||
|
||||
min_tc = face.mTexCoords[0];
|
||||
max_tc = face.mTexCoords[0];
|
||||
|
||||
for (U32 j = 1; j < (U32)face.mNumVertices; ++j)
|
||||
{
|
||||
update_min_max(min_tc, max_tc, face.mTexCoords[j]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
face.mTexCoordExtents[0].set(0,0);
|
||||
face.mTexCoordExtents[1].set(1,1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2741,11 +2780,13 @@ void LLVolume::makeTetrahedron()
|
||||
n[2] = cv[2].getNormal();
|
||||
n += 3;
|
||||
|
||||
tc[0] = cv[0].mTexCoord;
|
||||
tc[1] = cv[1].mTexCoord;
|
||||
tc[2] = cv[2].mTexCoord;
|
||||
tc += 3;
|
||||
|
||||
if(tc)
|
||||
{
|
||||
tc[0] = cv[0].mTexCoord;
|
||||
tc[1] = cv[1].mTexCoord;
|
||||
tc[2] = cv[2].mTexCoord;
|
||||
tc += 3;
|
||||
}
|
||||
|
||||
//side 2
|
||||
cv[0].setPosition(p[3]);
|
||||
@@ -2764,11 +2805,14 @@ void LLVolume::makeTetrahedron()
|
||||
n[2] = cv[2].getNormal();
|
||||
n += 3;
|
||||
|
||||
tc[0] = cv[0].mTexCoord;
|
||||
tc[1] = cv[1].mTexCoord;
|
||||
tc[2] = cv[2].mTexCoord;
|
||||
tc += 3;
|
||||
|
||||
if(tc)
|
||||
{
|
||||
tc[0] = cv[0].mTexCoord;
|
||||
tc[1] = cv[1].mTexCoord;
|
||||
tc[2] = cv[2].mTexCoord;
|
||||
tc += 3;
|
||||
}
|
||||
|
||||
//side 3
|
||||
cv[0].setPosition(p[3]);
|
||||
cv[1].setPosition(p[1]);
|
||||
@@ -2786,10 +2830,13 @@ void LLVolume::makeTetrahedron()
|
||||
n[2] = cv[2].getNormal();
|
||||
n += 3;
|
||||
|
||||
tc[0] = cv[0].mTexCoord;
|
||||
tc[1] = cv[1].mTexCoord;
|
||||
tc[2] = cv[2].mTexCoord;
|
||||
tc += 3;
|
||||
if(tc)
|
||||
{
|
||||
tc[0] = cv[0].mTexCoord;
|
||||
tc[1] = cv[1].mTexCoord;
|
||||
tc[2] = cv[2].mTexCoord;
|
||||
tc += 3;
|
||||
}
|
||||
|
||||
//side 4
|
||||
cv[0].setPosition(p[2]);
|
||||
@@ -2808,10 +2855,13 @@ void LLVolume::makeTetrahedron()
|
||||
n[2] = cv[2].getNormal();
|
||||
n += 3;
|
||||
|
||||
tc[0] = cv[0].mTexCoord;
|
||||
tc[1] = cv[1].mTexCoord;
|
||||
tc[2] = cv[2].mTexCoord;
|
||||
tc += 3;
|
||||
if(tc)
|
||||
{
|
||||
tc[0] = cv[0].mTexCoord;
|
||||
tc[1] = cv[1].mTexCoord;
|
||||
tc[2] = cv[2].mTexCoord;
|
||||
tc += 3;
|
||||
}
|
||||
|
||||
//set index buffer
|
||||
for (U16 i = 0; i < 12; i++)
|
||||
@@ -2833,7 +2883,7 @@ void LLVolume::copyVolumeFaces(const LLVolume* volume)
|
||||
|
||||
void LLVolume::cacheOptimize()
|
||||
{
|
||||
for (S32 i = 0; i < mVolumeFaces.size(); ++i)
|
||||
for (S32 i = 0; i < (S32)mVolumeFaces.size(); ++i)
|
||||
{
|
||||
mVolumeFaces[i].cacheOptimize();
|
||||
}
|
||||
@@ -5523,6 +5573,9 @@ LLVolumeFace::LLVolumeFace() :
|
||||
mBinormals(NULL),
|
||||
mTexCoords(NULL),
|
||||
mIndices(NULL),
|
||||
#if MESH_ENABLED
|
||||
mWeights(NULL),
|
||||
#endif //MESH_ENABLED
|
||||
mOctree(NULL)
|
||||
{
|
||||
mExtents = (LLVector4a*) ll_aligned_malloc_16(sizeof(LLVector4a)*3);
|
||||
@@ -5590,7 +5643,16 @@ LLVolumeFace& LLVolumeFace::operator=(const LLVolumeFace& src)
|
||||
|
||||
LLVector4a::memcpyNonAliased16((F32*) mPositions, (F32*) src.mPositions, vert_size);
|
||||
LLVector4a::memcpyNonAliased16((F32*) mNormals, (F32*) src.mNormals, vert_size);
|
||||
LLVector4a::memcpyNonAliased16((F32*) mTexCoords, (F32*) src.mTexCoords, tc_size);
|
||||
|
||||
if(src.mTexCoords)
|
||||
{
|
||||
LLVector4a::memcpyNonAliased16((F32*) mTexCoords, (F32*) src.mTexCoords, tc_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
ll_aligned_free_16(mTexCoords) ;
|
||||
mTexCoords = NULL ;
|
||||
}
|
||||
|
||||
|
||||
if (src.mBinormals)
|
||||
@@ -5715,8 +5777,23 @@ BOOL LLVolumeFace::create(LLVolume* volume, BOOL partial_build)
|
||||
void LLVolumeFace::getVertexData(U16 index, LLVolumeFace::VertexData& cv)
|
||||
{
|
||||
cv.setPosition(mPositions[index]);
|
||||
cv.setNormal(mNormals[index]);
|
||||
cv.mTexCoord = mTexCoords[index];
|
||||
if (mNormals)
|
||||
{
|
||||
cv.setNormal(mNormals[index]);
|
||||
}
|
||||
else
|
||||
{
|
||||
cv.getNormal().clear();
|
||||
}
|
||||
|
||||
if (mTexCoords)
|
||||
{
|
||||
cv.mTexCoord = mTexCoords[index];
|
||||
}
|
||||
else
|
||||
{
|
||||
cv.mTexCoord.clear();
|
||||
}
|
||||
}
|
||||
|
||||
bool LLVolumeFace::VertexMapData::operator==(const LLVolumeFace::VertexData& rhs) const
|
||||
@@ -5746,7 +5823,10 @@ void LLVolumeFace::optimize(F32 angle_cutoff)
|
||||
LLVolumeFace new_face;
|
||||
|
||||
//map of points to vector of vertices at that point
|
||||
VertexMapData::PointMap point_map;
|
||||
std::map<U64, std::vector<VertexMapData> > point_map;
|
||||
|
||||
LLVector4a range;
|
||||
range.setSub(mExtents[1],mExtents[0]);
|
||||
|
||||
//remove redundant vertices
|
||||
for (U32 i = 0; i < (U32)mNumIndices; ++i)
|
||||
@@ -5757,7 +5837,19 @@ void LLVolumeFace::optimize(F32 angle_cutoff)
|
||||
getVertexData(index, cv);
|
||||
|
||||
BOOL found = FALSE;
|
||||
VertexMapData::PointMap::iterator point_iter = point_map.find(LLVector3(cv.getPosition().getF32ptr()));
|
||||
|
||||
LLVector4a pos;
|
||||
pos.setSub(mPositions[index], mExtents[0]);
|
||||
pos.div(range);
|
||||
|
||||
U64 pos64 = 0;
|
||||
|
||||
pos64 = (U16) (pos[0]*65535);
|
||||
pos64 = pos64 | (((U64) (pos[1]*65535)) << 16);
|
||||
pos64 = pos64 | (((U64) (pos[2]*65535)) << 32);
|
||||
|
||||
std::map<U64, std::vector<VertexMapData> >::iterator point_iter = point_map.find(pos64);
|
||||
|
||||
if (point_iter != point_map.end())
|
||||
{ //duplicate point might exist
|
||||
for (U32 j = 0; j < point_iter->second.size(); ++j)
|
||||
@@ -5789,11 +5881,26 @@ void LLVolumeFace::optimize(F32 angle_cutoff)
|
||||
}
|
||||
else
|
||||
{
|
||||
point_map[LLVector3(d.getPosition().getF32ptr())].push_back(d);
|
||||
point_map[pos64].push_back(d);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
llassert(new_face.mNumIndices == mNumIndices);
|
||||
llassert(new_face.mNumVertices <= mNumVertices);
|
||||
|
||||
if (angle_cutoff > 1.f && !mNormals)
|
||||
{
|
||||
ll_aligned_free_16(new_face.mNormals);
|
||||
new_face.mNormals = NULL;
|
||||
}
|
||||
|
||||
if (!mTexCoords)
|
||||
{
|
||||
ll_aligned_free_16(new_face.mTexCoords);
|
||||
new_face.mTexCoords = NULL;
|
||||
}
|
||||
|
||||
swapData(new_face);
|
||||
}
|
||||
|
||||
@@ -7026,6 +7133,7 @@ void LLVolumeFace::allocateBinormals(S32 num_verts)
|
||||
#if MESH_ENABLED
|
||||
void LLVolumeFace::allocateWeights(S32 num_verts)
|
||||
{
|
||||
|
||||
ll_aligned_free_16(mWeights);
|
||||
mWeights = (LLVector4a*) ll_aligned_malloc_16(sizeof(LLVector4a)*num_verts);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user