diff options
Diffstat (limited to 'indra/llmath/llvolume.cpp')
-rw-r--r-- | indra/llmath/llvolume.cpp | 159 |
1 files changed, 81 insertions, 78 deletions
diff --git a/indra/llmath/llvolume.cpp b/indra/llmath/llvolume.cpp index 75e4042f07..5354de783c 100644 --- a/indra/llmath/llvolume.cpp +++ b/indra/llmath/llvolume.cpp @@ -1765,9 +1765,6 @@ void LLVolume::createVolumeFaces() mVolumeFaces[i].create(); } } - - mBounds[1] = LLVector3(0,0,0); - mBounds[0] = LLVector3(512,512,512); } @@ -1812,21 +1809,28 @@ void LLVolumeParams::copyParams(const LLVolumeParams ¶ms) mPathParams.copyParams(params.mPathParams); } +// Less restricitve approx 0 for volumes +const F32 APPROXIMATELY_ZERO = 0.001f; +bool approx_zero( F32 f, F32 tolerance = APPROXIMATELY_ZERO) +{ + return (f >= -tolerance) && (f <= tolerance); +} + // return true if in range (or nearly so) -static bool limit_range(F32& v, F32 min, F32 max) +static bool limit_range(F32& v, F32 min, F32 max, F32 tolerance = APPROXIMATELY_ZERO) { F32 min_delta = v - min; if (min_delta < 0.f) { v = min; - if (!is_approx_zero(min_delta)) + if (!approx_zero(min_delta, tolerance)) return false; } F32 max_delta = max - v; if (max_delta < 0.f) { v = max; - if (!is_approx_zero(max_delta)) + if (!approx_zero(max_delta, tolerance)) return false; } return true; @@ -1841,9 +1845,10 @@ bool LLVolumeParams::setBeginAndEndS(const F32 b, const F32 e) valid &= limit_range(begin, 0.f, 1.f - MIN_CUT_DELTA); F32 end = e; + if (end >= .0149f && end < MIN_CUT_DELTA) end = MIN_CUT_DELTA; // eliminate warning for common rounding error valid &= limit_range(end, MIN_CUT_DELTA, 1.f); - valid &= limit_range(begin, 0.f, end - MIN_CUT_DELTA); + valid &= limit_range(begin, 0.f, end - MIN_CUT_DELTA, .01f); // Now set them. mProfileParams.setBegin(begin); @@ -1863,7 +1868,7 @@ bool LLVolumeParams::setBeginAndEndT(const F32 b, const F32 e) F32 end = e; valid &= limit_range(end, MIN_CUT_DELTA, 1.f); - valid &= limit_range(begin, 0.f, end - MIN_CUT_DELTA); + valid &= limit_range(begin, 0.f, end - MIN_CUT_DELTA, .01f); // Now set them. mPathParams.setBegin(begin); @@ -2020,7 +2025,7 @@ bool LLVolumeParams::setRadiusOffset(const F32 offset) { radius_offset = max_radius_mag; } - valid = is_approx_zero(delta); + valid = approx_zero(delta, .1f); } mPathParams.setRadiusOffset(radius_offset); @@ -2054,7 +2059,7 @@ bool LLVolumeParams::setSkew(const F32 skew_value) { skew = min_skew_mag; } - valid = is_approx_zero(delta); + valid = approx_zero(delta); } mPathParams.setSkew(skew); @@ -2980,10 +2985,15 @@ void LLVolume::generateSilhouetteVertices(std::vector<LLVector3> &vertices, S32 v2 = face.mIndices[j*3+((k+1)%3)]; vertices.push_back(face.mVertices[v1].mPosition*mat); - normals.push_back(face.mVertices[v1].mNormal*norm_mat); + LLVector3 norm1 = face.mVertices[v1].mNormal * norm_mat; + norm1.normVec(); + normals.push_back(norm1); vertices.push_back(face.mVertices[v2].mPosition*mat); - normals.push_back(face.mVertices[v2].mNormal*norm_mat); + LLVector3 norm2 = face.mVertices[v2].mNormal * norm_mat; + norm2.normVec(); + normals.push_back(norm2); + segments.push_back(vertices.size()); } } @@ -3747,6 +3757,9 @@ BOOL LLVolumeFace::createUnCutCubeCap() num_vertices = (grid_size+1)*(grid_size+1); num_indices = quad_count * 4; + LLVector3& min = mExtents[0]; + LLVector3& max = mExtents[1]; + S32 offset = 0; if (mTypeMask & TOP_MASK) offset = (max_t-1) * max_s; @@ -3786,32 +3799,6 @@ BOOL LLVolumeFace::createUnCutCubeCap() } S32 vtop = mVertices.size(); -// S32 itop = mIndices.size(); -/// vector_append(mVertices,4); -// vector_append(mIndices,4); -// LLVector3 new_pt = lerp(pt1, pt2, t_fraction); -#if 0 - for(int t=0;t<4;t++){ - VertexData vd; - vd.mPosition = corners[t].mPosition; - vd.mNormal = - ((corners[(t+1)%4].mPosition-corners[t].mPosition)% - (corners[(t+2)%4].mPosition-corners[(t+1)%4].mPosition)); - vd.mNormal.normVec(); - - if (mTypeMask & TOP_MASK) - vd.mNormal *= -1.0f; - vd.mBinormal = vd.mNormal; - vd.mTexCoord = corners[t].mTexCoord; - mVertices.push_back(vd); - } - int idxs[] = {0,1,2,2,3,0}; - if (mTypeMask & TOP_MASK){ - for(int i=0;i<6;i++)mIndices.push_back(vtop+idxs[i]); - }else{ - for(int i=5;i>=0;i--)mIndices.push_back(vtop+idxs[i]); - } -#else for(int gx = 0;gx<grid_size+1;gx++){ for(int gy = 0;gy<grid_size+1;gy++){ VertexData newVert; @@ -3823,8 +3810,20 @@ BOOL LLVolumeFace::createUnCutCubeCap() (F32)gx/(F32)grid_size, (F32)gy/(F32)grid_size); mVertices.push_back(newVert); + + if (gx == 0 && gy == 0) + { + min = max = newVert.mPosition; + } + else + { + update_min_max(min,max,newVert.mPosition); + } } } + + mCenter = (min + max) * 0.5f; + int idxs[] = {0,1,(grid_size+1)+1,(grid_size+1)+1,(grid_size+1),0}; for(int gx = 0;gx<grid_size;gx++){ for(int gy = 0;gy<grid_size;gy++){ @@ -3835,7 +3834,7 @@ BOOL LLVolumeFace::createUnCutCubeCap() } } } -#endif + return TRUE; } @@ -3882,12 +3881,15 @@ BOOL LLVolumeFace::createCap() // Figure out the normal, assume all caps are flat faces. // Cross product to get normals. - LLVector2 cuv = LLVector2(0,0); - + LLVector2 cuv; + LLVector2 min_uv, max_uv; + + LLVector3& min = mExtents[0]; + LLVector3& max = mExtents[1]; + // Copy the vertices into the array for (i = 0; i < num_vertices; i++) { - if (mTypeMask & TOP_MASK) { mVertices[i].mTexCoord.mV[0] = profile[i].mV[0]+0.5f; @@ -3900,17 +3902,22 @@ BOOL LLVolumeFace::createCap() mVertices[i].mTexCoord.mV[1] = 0.5f - profile[i].mV[1]; } - if(i){ - //Dont include the first point of the profile in the average - cuv += mVertices[i].mTexCoord; - mCenter += mVertices[i].mPosition = mesh[i + offset].mPos; + mVertices[i].mPosition = mesh[i + offset].mPos; + + if (i == 0) + { + min = max = mVertices[i].mPosition; + min_uv = max_uv = mVertices[i].mTexCoord; + } + else + { + update_min_max(min,max, mVertices[i].mPosition); + update_min_max(min_uv, max_uv, mVertices[i].mTexCoord); } - else mVertices[i].mPosition = mesh[i + offset].mPos; - //mVertices[i].mNormal = normal; } - mCenter /= (F32)(num_vertices-1); - cuv /= (F32)(num_vertices-1); + mCenter = (min+max)*0.5f; + cuv = (min_uv + max_uv)*0.5f; LLVector3 binormal = calc_binormal_from_triangle( mCenter, cuv, @@ -4215,13 +4222,11 @@ BOOL LLVolumeFace::createCap() return TRUE; } - BOOL LLVolumeFace::createSide() { BOOL flat = mTypeMask & FLAT_MASK; S32 num_vertices, num_indices; - const std::vector<LLVolume::Point>& mesh = mVolumep->getMesh(); const std::vector<LLVector3>& profile = mVolumep->getProfile().mProfile; const std::vector<LLPath::PathPt>& path_data = mVolumep->getPath().mPath; @@ -4237,6 +4242,9 @@ BOOL LLVolumeFace::createSide() vector_append(mIndices,num_indices); vector_append(mEdge, num_indices); + LLVector3& face_min = mExtents[0]; + LLVector3& face_max = mExtents[1]; + mCenter.clearVec(); S32 begin_stex = llfloor( profile[mBeginS].mV[2] ); @@ -4284,17 +4292,26 @@ BOOL LLVolumeFace::createSide() i = mBeginS + s + max_s*t; } - mCenter += mVertices[cur_vertex].mPosition = mesh[i].mPos; + mVertices[cur_vertex].mPosition = mesh[i].mPos; mVertices[cur_vertex].mTexCoord = LLVector2(ss,tt); mVertices[cur_vertex].mNormal = LLVector3(0,0,0); mVertices[cur_vertex].mBinormal = LLVector3(0,0,0); + if (cur_vertex == 0) + { + face_min = face_max = mesh[i].mPos; + } + else + { + update_min_max(face_min, face_max, mesh[i].mPos); + } + cur_vertex++; if ((mTypeMask & INNER_MASK) && (mTypeMask & FLAT_MASK) && mNumS > 2 && s > 0) { - mCenter += mVertices[cur_vertex].mPosition = mesh[i].mPos; + mVertices[cur_vertex].mPosition = mesh[i].mPos; mVertices[cur_vertex].mTexCoord = LLVector2(ss,tt); mVertices[cur_vertex].mNormal = LLVector3(0,0,0); @@ -4316,15 +4333,19 @@ BOOL LLVolumeFace::createSide() i = mBeginS + s + max_s*t; ss = profile[mBeginS + s].mV[2] - begin_stex; - mCenter += mVertices[cur_vertex].mPosition = mesh[i].mPos; + mVertices[cur_vertex].mPosition = mesh[i].mPos; mVertices[cur_vertex].mTexCoord = LLVector2(ss,tt); mVertices[cur_vertex].mNormal = LLVector3(0,0,0); mVertices[cur_vertex].mBinormal = LLVector3(0,0,0); + + update_min_max(face_min,face_max,mesh[i].mPos); + cur_vertex++; } } - mCenter /= (F32)num_vertices; + + mCenter = (face_min + face_max) * 0.5f; S32 cur_index = 0; S32 cur_edge = 0; @@ -4448,32 +4469,14 @@ BOOL LLVolumeFace::createSide() } } - //this loop would LOVE OpenMP - LLVector3 min = mVolumep->mBounds[0] - mVolumep->mBounds[1]; - LLVector3 max = mVolumep->mBounds[0] + mVolumep->mBounds[1]; - - if (min == max && min == LLVector3(512,512,512)) + //normalize normals and binormals here so the meshes that reference + //this volume data don't have to + for (U32 i = 0; i < mVertices.size(); i++) { - min = max = mVertices[0].mPosition; - } - - for (U32 i = 0; i < mVertices.size(); i++) { mVertices[i].mNormal.normVec(); mVertices[i].mBinormal.normVec(); - - for (U32 j = 0; j < 3; j++) { - if (mVertices[i].mPosition.mV[j] > max.mV[j]) { - max.mV[j] = mVertices[i].mPosition.mV[j]; - } - if (mVertices[i].mPosition.mV[j] < min.mV[j]) { - min.mV[j] = mVertices[i].mPosition.mV[j]; - } - } } - mVolumep->mBounds[0] = (min + max) * 0.5f; //center - mVolumep->mBounds[1] = (max - min) * 0.5f; //half-height - return TRUE; } @@ -4572,7 +4575,7 @@ LLVector3 calc_binormal_from_triangle( -r0.mV[VZ] / r0.mV[VX], -r1.mV[VZ] / r1.mV[VX], -r2.mV[VZ] / r2.mV[VX]); - //binormal.normVec(); + // binormal.normVec(); return binormal; } else |