diff options
author | Jacek Antonelli | 2008-08-15 23:44:50 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:50 -0500 |
commit | 89fe5dab825a62a0e3fd8d248cbc91c65eb2a426 (patch) | |
tree | bcff14b7888d04a2fec799c59369f6095224bd08 /linden/indra/llmath/llvolume.cpp | |
parent | Second Life viewer sources 1.13.3.2 (diff) | |
download | meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.zip meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.tar.gz meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.tar.bz2 meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.tar.xz |
Second Life viewer sources 1.14.0.0
Diffstat (limited to 'linden/indra/llmath/llvolume.cpp')
-rw-r--r-- | linden/indra/llmath/llvolume.cpp | 220 |
1 files changed, 118 insertions, 102 deletions
diff --git a/linden/indra/llmath/llvolume.cpp b/linden/indra/llmath/llvolume.cpp index c527e85..e42413a 100644 --- a/linden/indra/llmath/llvolume.cpp +++ b/linden/indra/llmath/llvolume.cpp | |||
@@ -724,11 +724,11 @@ BOOL LLProfile::generate(BOOL path_open,F32 detail, S32 split) | |||
724 | BOOL LLProfileParams::importFile(FILE *fp) | 724 | BOOL LLProfileParams::importFile(FILE *fp) |
725 | { | 725 | { |
726 | const S32 BUFSIZE = 16384; | 726 | const S32 BUFSIZE = 16384; |
727 | char buffer[BUFSIZE]; | 727 | char buffer[BUFSIZE]; /* Flawfinder: ignore */ |
728 | // *NOTE: changing the size or type of these buffers will require | 728 | // *NOTE: changing the size or type of these buffers will require |
729 | // changing the sscanf below. | 729 | // changing the sscanf below. |
730 | char keyword[256]; | 730 | char keyword[256]; /* Flawfinder: ignore */ |
731 | char valuestr[256]; | 731 | char valuestr[256]; /* Flawfinder: ignore */ |
732 | keyword[0] = 0; | 732 | keyword[0] = 0; |
733 | valuestr[0] = 0; | 733 | valuestr[0] = 0; |
734 | F32 tempF32; | 734 | F32 tempF32; |
@@ -737,7 +737,10 @@ BOOL LLProfileParams::importFile(FILE *fp) | |||
737 | while (!feof(fp)) | 737 | while (!feof(fp)) |
738 | { | 738 | { |
739 | fgets(buffer, BUFSIZE, fp); | 739 | fgets(buffer, BUFSIZE, fp); |
740 | sscanf(buffer, " %255s %255s", keyword, valuestr); | 740 | sscanf( /* Flawfinder: ignore */ |
741 | buffer, | ||
742 | " %255s %255s", | ||
743 | keyword, valuestr); | ||
741 | if (!keyword) | 744 | if (!keyword) |
742 | { | 745 | { |
743 | continue; | 746 | continue; |
@@ -796,11 +799,11 @@ BOOL LLProfileParams::exportFile(FILE *fp) const | |||
796 | BOOL LLProfileParams::importLegacyStream(std::istream& input_stream) | 799 | BOOL LLProfileParams::importLegacyStream(std::istream& input_stream) |
797 | { | 800 | { |
798 | const S32 BUFSIZE = 16384; | 801 | const S32 BUFSIZE = 16384; |
799 | char buffer[BUFSIZE]; | 802 | char buffer[BUFSIZE]; /* Flawfinder: ignore */ |
800 | // *NOTE: changing the size or type of these buffers will require | 803 | // *NOTE: changing the size or type of these buffers will require |
801 | // changing the sscanf below. | 804 | // changing the sscanf below. |
802 | char keyword[256]; | 805 | char keyword[256]; /* Flawfinder: ignore */ |
803 | char valuestr[256]; | 806 | char valuestr[256]; /* Flawfinder: ignore */ |
804 | keyword[0] = 0; | 807 | keyword[0] = 0; |
805 | valuestr[0] = 0; | 808 | valuestr[0] = 0; |
806 | F32 tempF32; | 809 | F32 tempF32; |
@@ -809,7 +812,11 @@ BOOL LLProfileParams::importLegacyStream(std::istream& input_stream) | |||
809 | while (input_stream.good()) | 812 | while (input_stream.good()) |
810 | { | 813 | { |
811 | input_stream.getline(buffer, BUFSIZE); | 814 | input_stream.getline(buffer, BUFSIZE); |
812 | sscanf(buffer, " %255s %255s", keyword, valuestr); | 815 | sscanf( /* Flawfinder: ignore */ |
816 | buffer, | ||
817 | " %255s %255s", | ||
818 | keyword, | ||
819 | valuestr); | ||
813 | if (!keyword) | 820 | if (!keyword) |
814 | { | 821 | { |
815 | continue; | 822 | continue; |
@@ -1218,11 +1225,11 @@ BOOL LLDynamicPath::generate(F32 detail, S32 split) | |||
1218 | BOOL LLPathParams::importFile(FILE *fp) | 1225 | BOOL LLPathParams::importFile(FILE *fp) |
1219 | { | 1226 | { |
1220 | const S32 BUFSIZE = 16384; | 1227 | const S32 BUFSIZE = 16384; |
1221 | char buffer[BUFSIZE]; | 1228 | char buffer[BUFSIZE]; /* Flawfinder: ignore */ |
1222 | // *NOTE: changing the size or type of these buffers will require | 1229 | // *NOTE: changing the size or type of these buffers will require |
1223 | // changing the sscanf below. | 1230 | // changing the sscanf below. |
1224 | char keyword[256]; | 1231 | char keyword[256]; /* Flawfinder: ignore */ |
1225 | char valuestr[256]; | 1232 | char valuestr[256]; /* Flawfinder: ignore */ |
1226 | keyword[0] = 0; | 1233 | keyword[0] = 0; |
1227 | valuestr[0] = 0; | 1234 | valuestr[0] = 0; |
1228 | 1235 | ||
@@ -1233,7 +1240,10 @@ BOOL LLPathParams::importFile(FILE *fp) | |||
1233 | while (!feof(fp)) | 1240 | while (!feof(fp)) |
1234 | { | 1241 | { |
1235 | fgets(buffer, BUFSIZE, fp); | 1242 | fgets(buffer, BUFSIZE, fp); |
1236 | sscanf(buffer, " %255s %255s", keyword, valuestr); | 1243 | sscanf( /* Flawfinder: ignore */ |
1244 | buffer, | ||
1245 | " %255s %255s", | ||
1246 | keyword, valuestr); | ||
1237 | if (!keyword) | 1247 | if (!keyword) |
1238 | { | 1248 | { |
1239 | continue; | 1249 | continue; |
@@ -1359,11 +1369,11 @@ BOOL LLPathParams::exportFile(FILE *fp) const | |||
1359 | BOOL LLPathParams::importLegacyStream(std::istream& input_stream) | 1369 | BOOL LLPathParams::importLegacyStream(std::istream& input_stream) |
1360 | { | 1370 | { |
1361 | const S32 BUFSIZE = 16384; | 1371 | const S32 BUFSIZE = 16384; |
1362 | char buffer[BUFSIZE]; | 1372 | char buffer[BUFSIZE]; /* Flawfinder: ignore */ |
1363 | // *NOTE: changing the size or type of these buffers will require | 1373 | // *NOTE: changing the size or type of these buffers will require |
1364 | // changing the sscanf below. | 1374 | // changing the sscanf below. |
1365 | char keyword[256]; | 1375 | char keyword[256]; /* Flawfinder: ignore */ |
1366 | char valuestr[256]; | 1376 | char valuestr[256]; /* Flawfinder: ignore */ |
1367 | keyword[0] = 0; | 1377 | keyword[0] = 0; |
1368 | valuestr[0] = 0; | 1378 | valuestr[0] = 0; |
1369 | 1379 | ||
@@ -1374,7 +1384,10 @@ BOOL LLPathParams::importLegacyStream(std::istream& input_stream) | |||
1374 | while (input_stream.good()) | 1384 | while (input_stream.good()) |
1375 | { | 1385 | { |
1376 | input_stream.getline(buffer, BUFSIZE); | 1386 | input_stream.getline(buffer, BUFSIZE); |
1377 | sscanf(buffer, " %255s %255s", keyword, valuestr); | 1387 | sscanf( /* Flawfinder: ignore */ |
1388 | buffer, | ||
1389 | " %255s %255s", | ||
1390 | keyword, valuestr); | ||
1378 | if (!keyword) | 1391 | if (!keyword) |
1379 | { | 1392 | { |
1380 | continue; | 1393 | continue; |
@@ -1771,9 +1784,6 @@ void LLVolume::createVolumeFaces() | |||
1771 | mVolumeFaces[i].create(); | 1784 | mVolumeFaces[i].create(); |
1772 | } | 1785 | } |
1773 | } | 1786 | } |
1774 | |||
1775 | mBounds[1] = LLVector3(0,0,0); | ||
1776 | mBounds[0] = LLVector3(512,512,512); | ||
1777 | } | 1787 | } |
1778 | 1788 | ||
1779 | 1789 | ||
@@ -1818,21 +1828,28 @@ void LLVolumeParams::copyParams(const LLVolumeParams ¶ms) | |||
1818 | mPathParams.copyParams(params.mPathParams); | 1828 | mPathParams.copyParams(params.mPathParams); |
1819 | } | 1829 | } |
1820 | 1830 | ||
1831 | // Less restricitve approx 0 for volumes | ||
1832 | const F32 APPROXIMATELY_ZERO = 0.001f; | ||
1833 | bool approx_zero( F32 f, F32 tolerance = APPROXIMATELY_ZERO) | ||
1834 | { | ||
1835 | return (f >= -tolerance) && (f <= tolerance); | ||
1836 | } | ||
1837 | |||
1821 | // return true if in range (or nearly so) | 1838 | // return true if in range (or nearly so) |
1822 | static bool limit_range(F32& v, F32 min, F32 max) | 1839 | static bool limit_range(F32& v, F32 min, F32 max, F32 tolerance = APPROXIMATELY_ZERO) |
1823 | { | 1840 | { |
1824 | F32 min_delta = v - min; | 1841 | F32 min_delta = v - min; |
1825 | if (min_delta < 0.f) | 1842 | if (min_delta < 0.f) |
1826 | { | 1843 | { |
1827 | v = min; | 1844 | v = min; |
1828 | if (!is_approx_zero(min_delta)) | 1845 | if (!approx_zero(min_delta, tolerance)) |
1829 | return false; | 1846 | return false; |
1830 | } | 1847 | } |
1831 | F32 max_delta = max - v; | 1848 | F32 max_delta = max - v; |
1832 | if (max_delta < 0.f) | 1849 | if (max_delta < 0.f) |
1833 | { | 1850 | { |
1834 | v = max; | 1851 | v = max; |
1835 | if (!is_approx_zero(max_delta)) | 1852 | if (!approx_zero(max_delta, tolerance)) |
1836 | return false; | 1853 | return false; |
1837 | } | 1854 | } |
1838 | return true; | 1855 | return true; |
@@ -1847,9 +1864,10 @@ bool LLVolumeParams::setBeginAndEndS(const F32 b, const F32 e) | |||
1847 | valid &= limit_range(begin, 0.f, 1.f - MIN_CUT_DELTA); | 1864 | valid &= limit_range(begin, 0.f, 1.f - MIN_CUT_DELTA); |
1848 | 1865 | ||
1849 | F32 end = e; | 1866 | F32 end = e; |
1867 | if (end >= .0149f && end < MIN_CUT_DELTA) end = MIN_CUT_DELTA; // eliminate warning for common rounding error | ||
1850 | valid &= limit_range(end, MIN_CUT_DELTA, 1.f); | 1868 | valid &= limit_range(end, MIN_CUT_DELTA, 1.f); |
1851 | 1869 | ||
1852 | valid &= limit_range(begin, 0.f, end - MIN_CUT_DELTA); | 1870 | valid &= limit_range(begin, 0.f, end - MIN_CUT_DELTA, .01f); |
1853 | 1871 | ||
1854 | // Now set them. | 1872 | // Now set them. |
1855 | mProfileParams.setBegin(begin); | 1873 | mProfileParams.setBegin(begin); |
@@ -1869,7 +1887,7 @@ bool LLVolumeParams::setBeginAndEndT(const F32 b, const F32 e) | |||
1869 | F32 end = e; | 1887 | F32 end = e; |
1870 | valid &= limit_range(end, MIN_CUT_DELTA, 1.f); | 1888 | valid &= limit_range(end, MIN_CUT_DELTA, 1.f); |
1871 | 1889 | ||
1872 | valid &= limit_range(begin, 0.f, end - MIN_CUT_DELTA); | 1890 | valid &= limit_range(begin, 0.f, end - MIN_CUT_DELTA, .01f); |
1873 | 1891 | ||
1874 | // Now set them. | 1892 | // Now set them. |
1875 | mPathParams.setBegin(begin); | 1893 | mPathParams.setBegin(begin); |
@@ -2026,7 +2044,7 @@ bool LLVolumeParams::setRadiusOffset(const F32 offset) | |||
2026 | { | 2044 | { |
2027 | radius_offset = max_radius_mag; | 2045 | radius_offset = max_radius_mag; |
2028 | } | 2046 | } |
2029 | valid = is_approx_zero(delta); | 2047 | valid = approx_zero(delta, .1f); |
2030 | } | 2048 | } |
2031 | 2049 | ||
2032 | mPathParams.setRadiusOffset(radius_offset); | 2050 | mPathParams.setRadiusOffset(radius_offset); |
@@ -2060,7 +2078,7 @@ bool LLVolumeParams::setSkew(const F32 skew_value) | |||
2060 | { | 2078 | { |
2061 | skew = min_skew_mag; | 2079 | skew = min_skew_mag; |
2062 | } | 2080 | } |
2063 | valid = is_approx_zero(delta); | 2081 | valid = approx_zero(delta, .01f); |
2064 | } | 2082 | } |
2065 | 2083 | ||
2066 | mPathParams.setSkew(skew); | 2084 | mPathParams.setSkew(skew); |
@@ -2185,7 +2203,7 @@ S32 *LLVolume::getTriangleIndices(U32 &num_indices) const | |||
2185 | size_s_out = getProfile().getTotalOut(); | 2203 | size_s_out = getProfile().getTotalOut(); |
2186 | size_t = getPath().mPath.size(); | 2204 | size_t = getPath().mPath.size(); |
2187 | 2205 | ||
2188 | if (open) | 2206 | if (open) /* Flawfinder: ignore */ |
2189 | { | 2207 | { |
2190 | if (hollow) | 2208 | if (hollow) |
2191 | { | 2209 | { |
@@ -2807,7 +2825,7 @@ noindices: | |||
2807 | return NULL; | 2825 | return NULL; |
2808 | } | 2826 | } |
2809 | num_indices = count; | 2827 | num_indices = count; |
2810 | memcpy(indices, index, count * sizeof(S32)); | 2828 | memcpy(indices, index, count * sizeof(S32)); /* Flawfinder: ignore */ |
2811 | return indices; | 2829 | return indices; |
2812 | } | 2830 | } |
2813 | 2831 | ||
@@ -2986,10 +3004,15 @@ void LLVolume::generateSilhouetteVertices(std::vector<LLVector3> &vertices, | |||
2986 | S32 v2 = face.mIndices[j*3+((k+1)%3)]; | 3004 | S32 v2 = face.mIndices[j*3+((k+1)%3)]; |
2987 | 3005 | ||
2988 | vertices.push_back(face.mVertices[v1].mPosition*mat); | 3006 | vertices.push_back(face.mVertices[v1].mPosition*mat); |
2989 | normals.push_back(face.mVertices[v1].mNormal*norm_mat); | 3007 | LLVector3 norm1 = face.mVertices[v1].mNormal * norm_mat; |
3008 | norm1.normVec(); | ||
3009 | normals.push_back(norm1); | ||
2990 | 3010 | ||
2991 | vertices.push_back(face.mVertices[v2].mPosition*mat); | 3011 | vertices.push_back(face.mVertices[v2].mPosition*mat); |
2992 | normals.push_back(face.mVertices[v2].mNormal*norm_mat); | 3012 | LLVector3 norm2 = face.mVertices[v2].mNormal * norm_mat; |
3013 | norm2.normVec(); | ||
3014 | normals.push_back(norm2); | ||
3015 | |||
2993 | segments.push_back(vertices.size()); | 3016 | segments.push_back(vertices.size()); |
2994 | } | 3017 | } |
2995 | } | 3018 | } |
@@ -3310,7 +3333,7 @@ BOOL LLVolume::cleanupTriangleData( const S32 num_input_vertices, | |||
3310 | 3333 | ||
3311 | *output_triangles = new S32[cur_tri*3]; | 3334 | *output_triangles = new S32[cur_tri*3]; |
3312 | num_output_triangles = cur_tri; | 3335 | num_output_triangles = cur_tri; |
3313 | memcpy(*output_triangles, sorted_tris, 3*cur_tri*sizeof(S32)); | 3336 | memcpy(*output_triangles, sorted_tris, 3*cur_tri*sizeof(S32)); /* Flawfinder: ignore */ |
3314 | 3337 | ||
3315 | /* | 3338 | /* |
3316 | llinfos << "Out vertices: " << num_output_vertices << llendl; | 3339 | llinfos << "Out vertices: " << num_output_vertices << llendl; |
@@ -3347,16 +3370,16 @@ BOOL LLVolumeParams::importFile(FILE *fp) | |||
3347 | { | 3370 | { |
3348 | //llinfos << "importing volume" << llendl; | 3371 | //llinfos << "importing volume" << llendl; |
3349 | const S32 BUFSIZE = 16384; | 3372 | const S32 BUFSIZE = 16384; |
3350 | char buffer[BUFSIZE]; | 3373 | char buffer[BUFSIZE]; /* Flawfinder: ignore */ |
3351 | // *NOTE: changing the size or type of this buffer will require | 3374 | // *NOTE: changing the size or type of this buffer will require |
3352 | // changing the sscanf below. | 3375 | // changing the sscanf below. |
3353 | char keyword[256]; | 3376 | char keyword[256]; /* Flawfinder: ignore */ |
3354 | keyword[0] = 0; | 3377 | keyword[0] = 0; |
3355 | 3378 | ||
3356 | while (!feof(fp)) | 3379 | while (!feof(fp)) |
3357 | { | 3380 | { |
3358 | fgets(buffer, BUFSIZE, fp); | 3381 | fgets(buffer, BUFSIZE, fp); |
3359 | sscanf(buffer, " %255s", keyword); | 3382 | sscanf(buffer, " %255s", keyword); /* Flawfinder: ignore */ |
3360 | if (!keyword) | 3383 | if (!keyword) |
3361 | { | 3384 | { |
3362 | continue; | 3385 | continue; |
@@ -3403,8 +3426,8 @@ BOOL LLVolumeParams::importLegacyStream(std::istream& input_stream) | |||
3403 | const S32 BUFSIZE = 16384; | 3426 | const S32 BUFSIZE = 16384; |
3404 | // *NOTE: changing the size or type of this buffer will require | 3427 | // *NOTE: changing the size or type of this buffer will require |
3405 | // changing the sscanf below. | 3428 | // changing the sscanf below. |
3406 | char buffer[BUFSIZE]; | 3429 | char buffer[BUFSIZE]; /* Flawfinder: ignore */ |
3407 | char keyword[256]; | 3430 | char keyword[256]; /* Flawfinder: ignore */ |
3408 | keyword[0] = 0; | 3431 | keyword[0] = 0; |
3409 | 3432 | ||
3410 | while (input_stream.good()) | 3433 | while (input_stream.good()) |
@@ -3753,6 +3776,9 @@ BOOL LLVolumeFace::createUnCutCubeCap() | |||
3753 | num_vertices = (grid_size+1)*(grid_size+1); | 3776 | num_vertices = (grid_size+1)*(grid_size+1); |
3754 | num_indices = quad_count * 4; | 3777 | num_indices = quad_count * 4; |
3755 | 3778 | ||
3779 | LLVector3& min = mExtents[0]; | ||
3780 | LLVector3& max = mExtents[1]; | ||
3781 | |||
3756 | S32 offset = 0; | 3782 | S32 offset = 0; |
3757 | if (mTypeMask & TOP_MASK) | 3783 | if (mTypeMask & TOP_MASK) |
3758 | offset = (max_t-1) * max_s; | 3784 | offset = (max_t-1) * max_s; |
@@ -3792,32 +3818,6 @@ BOOL LLVolumeFace::createUnCutCubeCap() | |||
3792 | } | 3818 | } |
3793 | 3819 | ||
3794 | S32 vtop = mVertices.size(); | 3820 | S32 vtop = mVertices.size(); |
3795 | // S32 itop = mIndices.size(); | ||
3796 | /// vector_append(mVertices,4); | ||
3797 | // vector_append(mIndices,4); | ||
3798 | // LLVector3 new_pt = lerp(pt1, pt2, t_fraction); | ||
3799 | #if 0 | ||
3800 | for(int t=0;t<4;t++){ | ||
3801 | VertexData vd; | ||
3802 | vd.mPosition = corners[t].mPosition; | ||
3803 | vd.mNormal = | ||
3804 | ((corners[(t+1)%4].mPosition-corners[t].mPosition)% | ||
3805 | (corners[(t+2)%4].mPosition-corners[(t+1)%4].mPosition)); | ||
3806 | vd.mNormal.normVec(); | ||
3807 | |||
3808 | if (mTypeMask & TOP_MASK) | ||
3809 | vd.mNormal *= -1.0f; | ||
3810 | vd.mBinormal = vd.mNormal; | ||
3811 | vd.mTexCoord = corners[t].mTexCoord; | ||
3812 | mVertices.push_back(vd); | ||
3813 | } | ||
3814 | int idxs[] = {0,1,2,2,3,0}; | ||
3815 | if (mTypeMask & TOP_MASK){ | ||
3816 | for(int i=0;i<6;i++)mIndices.push_back(vtop+idxs[i]); | ||
3817 | }else{ | ||
3818 | for(int i=5;i>=0;i--)mIndices.push_back(vtop+idxs[i]); | ||
3819 | } | ||
3820 | #else | ||
3821 | for(int gx = 0;gx<grid_size+1;gx++){ | 3821 | for(int gx = 0;gx<grid_size+1;gx++){ |
3822 | for(int gy = 0;gy<grid_size+1;gy++){ | 3822 | for(int gy = 0;gy<grid_size+1;gy++){ |
3823 | VertexData newVert; | 3823 | VertexData newVert; |
@@ -3829,8 +3829,20 @@ BOOL LLVolumeFace::createUnCutCubeCap() | |||
3829 | (F32)gx/(F32)grid_size, | 3829 | (F32)gx/(F32)grid_size, |
3830 | (F32)gy/(F32)grid_size); | 3830 | (F32)gy/(F32)grid_size); |
3831 | mVertices.push_back(newVert); | 3831 | mVertices.push_back(newVert); |
3832 | |||
3833 | if (gx == 0 && gy == 0) | ||
3834 | { | ||
3835 | min = max = newVert.mPosition; | ||
3836 | } | ||
3837 | else | ||
3838 | { | ||
3839 | update_min_max(min,max,newVert.mPosition); | ||
3840 | } | ||
3832 | } | 3841 | } |
3833 | } | 3842 | } |
3843 | |||
3844 | mCenter = (min + max) * 0.5f; | ||
3845 | |||
3834 | int idxs[] = {0,1,(grid_size+1)+1,(grid_size+1)+1,(grid_size+1),0}; | 3846 | int idxs[] = {0,1,(grid_size+1)+1,(grid_size+1)+1,(grid_size+1),0}; |
3835 | for(int gx = 0;gx<grid_size;gx++){ | 3847 | for(int gx = 0;gx<grid_size;gx++){ |
3836 | for(int gy = 0;gy<grid_size;gy++){ | 3848 | for(int gy = 0;gy<grid_size;gy++){ |
@@ -3841,7 +3853,7 @@ BOOL LLVolumeFace::createUnCutCubeCap() | |||
3841 | } | 3853 | } |
3842 | } | 3854 | } |
3843 | } | 3855 | } |
3844 | #endif | 3856 | |
3845 | return TRUE; | 3857 | return TRUE; |
3846 | } | 3858 | } |
3847 | 3859 | ||
@@ -3888,12 +3900,15 @@ BOOL LLVolumeFace::createCap() | |||
3888 | // Figure out the normal, assume all caps are flat faces. | 3900 | // Figure out the normal, assume all caps are flat faces. |
3889 | // Cross product to get normals. | 3901 | // Cross product to get normals. |
3890 | 3902 | ||
3891 | LLVector2 cuv = LLVector2(0,0); | 3903 | LLVector2 cuv; |
3892 | 3904 | LLVector2 min_uv, max_uv; | |
3905 | |||
3906 | LLVector3& min = mExtents[0]; | ||
3907 | LLVector3& max = mExtents[1]; | ||
3908 | |||
3893 | // Copy the vertices into the array | 3909 | // Copy the vertices into the array |
3894 | for (i = 0; i < num_vertices; i++) | 3910 | for (i = 0; i < num_vertices; i++) |
3895 | { | 3911 | { |
3896 | |||
3897 | if (mTypeMask & TOP_MASK) | 3912 | if (mTypeMask & TOP_MASK) |
3898 | { | 3913 | { |
3899 | mVertices[i].mTexCoord.mV[0] = profile[i].mV[0]+0.5f; | 3914 | mVertices[i].mTexCoord.mV[0] = profile[i].mV[0]+0.5f; |
@@ -3906,17 +3921,22 @@ BOOL LLVolumeFace::createCap() | |||
3906 | mVertices[i].mTexCoord.mV[1] = 0.5f - profile[i].mV[1]; | 3921 | mVertices[i].mTexCoord.mV[1] = 0.5f - profile[i].mV[1]; |
3907 | } | 3922 | } |
3908 | 3923 | ||
3909 | if(i){ | 3924 | mVertices[i].mPosition = mesh[i + offset].mPos; |
3910 | //Dont include the first point of the profile in the average | 3925 | |
3911 | cuv += mVertices[i].mTexCoord; | 3926 | if (i == 0) |
3912 | mCenter += mVertices[i].mPosition = mesh[i + offset].mPos; | 3927 | { |
3928 | min = max = mVertices[i].mPosition; | ||
3929 | min_uv = max_uv = mVertices[i].mTexCoord; | ||
3930 | } | ||
3931 | else | ||
3932 | { | ||
3933 | update_min_max(min,max, mVertices[i].mPosition); | ||
3934 | update_min_max(min_uv, max_uv, mVertices[i].mTexCoord); | ||
3913 | } | 3935 | } |
3914 | else mVertices[i].mPosition = mesh[i + offset].mPos; | ||
3915 | //mVertices[i].mNormal = normal; | ||
3916 | } | 3936 | } |
3917 | 3937 | ||
3918 | mCenter /= (F32)(num_vertices-1); | 3938 | mCenter = (min+max)*0.5f; |
3919 | cuv /= (F32)(num_vertices-1); | 3939 | cuv = (min_uv + max_uv)*0.5f; |
3920 | 3940 | ||
3921 | LLVector3 binormal = calc_binormal_from_triangle( | 3941 | LLVector3 binormal = calc_binormal_from_triangle( |
3922 | mCenter, cuv, | 3942 | mCenter, cuv, |
@@ -4221,13 +4241,11 @@ BOOL LLVolumeFace::createCap() | |||
4221 | return TRUE; | 4241 | return TRUE; |
4222 | } | 4242 | } |
4223 | 4243 | ||
4224 | |||
4225 | BOOL LLVolumeFace::createSide() | 4244 | BOOL LLVolumeFace::createSide() |
4226 | { | 4245 | { |
4227 | BOOL flat = mTypeMask & FLAT_MASK; | 4246 | BOOL flat = mTypeMask & FLAT_MASK; |
4228 | S32 num_vertices, num_indices; | 4247 | S32 num_vertices, num_indices; |
4229 | 4248 | ||
4230 | |||
4231 | const std::vector<LLVolume::Point>& mesh = mVolumep->getMesh(); | 4249 | const std::vector<LLVolume::Point>& mesh = mVolumep->getMesh(); |
4232 | const std::vector<LLVector3>& profile = mVolumep->getProfile().mProfile; | 4250 | const std::vector<LLVector3>& profile = mVolumep->getProfile().mProfile; |
4233 | const std::vector<LLPath::PathPt>& path_data = mVolumep->getPath().mPath; | 4251 | const std::vector<LLPath::PathPt>& path_data = mVolumep->getPath().mPath; |
@@ -4243,6 +4261,9 @@ BOOL LLVolumeFace::createSide() | |||
4243 | vector_append(mIndices,num_indices); | 4261 | vector_append(mIndices,num_indices); |
4244 | vector_append(mEdge, num_indices); | 4262 | vector_append(mEdge, num_indices); |
4245 | 4263 | ||
4264 | LLVector3& face_min = mExtents[0]; | ||
4265 | LLVector3& face_max = mExtents[1]; | ||
4266 | |||
4246 | mCenter.clearVec(); | 4267 | mCenter.clearVec(); |
4247 | 4268 | ||
4248 | S32 begin_stex = llfloor( profile[mBeginS].mV[2] ); | 4269 | S32 begin_stex = llfloor( profile[mBeginS].mV[2] ); |
@@ -4290,17 +4311,26 @@ BOOL LLVolumeFace::createSide() | |||
4290 | i = mBeginS + s + max_s*t; | 4311 | i = mBeginS + s + max_s*t; |
4291 | } | 4312 | } |
4292 | 4313 | ||
4293 | mCenter += mVertices[cur_vertex].mPosition = mesh[i].mPos; | 4314 | mVertices[cur_vertex].mPosition = mesh[i].mPos; |
4294 | mVertices[cur_vertex].mTexCoord = LLVector2(ss,tt); | 4315 | mVertices[cur_vertex].mTexCoord = LLVector2(ss,tt); |
4295 | 4316 | ||
4296 | mVertices[cur_vertex].mNormal = LLVector3(0,0,0); | 4317 | mVertices[cur_vertex].mNormal = LLVector3(0,0,0); |
4297 | mVertices[cur_vertex].mBinormal = LLVector3(0,0,0); | 4318 | mVertices[cur_vertex].mBinormal = LLVector3(0,0,0); |
4298 | 4319 | ||
4320 | if (cur_vertex == 0) | ||
4321 | { | ||
4322 | face_min = face_max = mesh[i].mPos; | ||
4323 | } | ||
4324 | else | ||
4325 | { | ||
4326 | update_min_max(face_min, face_max, mesh[i].mPos); | ||
4327 | } | ||
4328 | |||
4299 | cur_vertex++; | 4329 | cur_vertex++; |
4300 | 4330 | ||
4301 | if ((mTypeMask & INNER_MASK) && (mTypeMask & FLAT_MASK) && mNumS > 2 && s > 0) | 4331 | if ((mTypeMask & INNER_MASK) && (mTypeMask & FLAT_MASK) && mNumS > 2 && s > 0) |
4302 | { | 4332 | { |
4303 | mCenter += mVertices[cur_vertex].mPosition = mesh[i].mPos; | 4333 | mVertices[cur_vertex].mPosition = mesh[i].mPos; |
4304 | mVertices[cur_vertex].mTexCoord = LLVector2(ss,tt); | 4334 | mVertices[cur_vertex].mTexCoord = LLVector2(ss,tt); |
4305 | 4335 | ||
4306 | mVertices[cur_vertex].mNormal = LLVector3(0,0,0); | 4336 | mVertices[cur_vertex].mNormal = LLVector3(0,0,0); |
@@ -4322,15 +4352,19 @@ BOOL LLVolumeFace::createSide() | |||
4322 | 4352 | ||
4323 | i = mBeginS + s + max_s*t; | 4353 | i = mBeginS + s + max_s*t; |
4324 | ss = profile[mBeginS + s].mV[2] - begin_stex; | 4354 | ss = profile[mBeginS + s].mV[2] - begin_stex; |
4325 | mCenter += mVertices[cur_vertex].mPosition = mesh[i].mPos; | 4355 | mVertices[cur_vertex].mPosition = mesh[i].mPos; |
4326 | mVertices[cur_vertex].mTexCoord = LLVector2(ss,tt); | 4356 | mVertices[cur_vertex].mTexCoord = LLVector2(ss,tt); |
4327 | 4357 | ||
4328 | mVertices[cur_vertex].mNormal = LLVector3(0,0,0); | 4358 | mVertices[cur_vertex].mNormal = LLVector3(0,0,0); |
4329 | mVertices[cur_vertex].mBinormal = LLVector3(0,0,0); | 4359 | mVertices[cur_vertex].mBinormal = LLVector3(0,0,0); |
4360 | |||
4361 | update_min_max(face_min,face_max,mesh[i].mPos); | ||
4362 | |||
4330 | cur_vertex++; | 4363 | cur_vertex++; |
4331 | } | 4364 | } |
4332 | } | 4365 | } |
4333 | mCenter /= (F32)num_vertices; | 4366 | |
4367 | mCenter = (face_min + face_max) * 0.5f; | ||
4334 | 4368 | ||
4335 | S32 cur_index = 0; | 4369 | S32 cur_index = 0; |
4336 | S32 cur_edge = 0; | 4370 | S32 cur_edge = 0; |
@@ -4454,32 +4488,14 @@ BOOL LLVolumeFace::createSide() | |||
4454 | } | 4488 | } |
4455 | } | 4489 | } |
4456 | 4490 | ||
4457 | //this loop would LOVE OpenMP | 4491 | //normalize normals and binormals here so the meshes that reference |
4458 | LLVector3 min = mVolumep->mBounds[0] - mVolumep->mBounds[1]; | 4492 | //this volume data don't have to |
4459 | LLVector3 max = mVolumep->mBounds[0] + mVolumep->mBounds[1]; | 4493 | for (U32 i = 0; i < mVertices.size(); i++) |
4460 | |||
4461 | if (min == max && min == LLVector3(512,512,512)) | ||
4462 | { | 4494 | { |
4463 | min = max = mVertices[0].mPosition; | ||
4464 | } | ||
4465 | |||
4466 | for (U32 i = 0; i < mVertices.size(); i++) { | ||
4467 | mVertices[i].mNormal.normVec(); | 4495 | mVertices[i].mNormal.normVec(); |
4468 | mVertices[i].mBinormal.normVec(); | 4496 | mVertices[i].mBinormal.normVec(); |
4469 | |||
4470 | for (U32 j = 0; j < 3; j++) { | ||
4471 | if (mVertices[i].mPosition.mV[j] > max.mV[j]) { | ||
4472 | max.mV[j] = mVertices[i].mPosition.mV[j]; | ||
4473 | } | ||
4474 | if (mVertices[i].mPosition.mV[j] < min.mV[j]) { | ||
4475 | min.mV[j] = mVertices[i].mPosition.mV[j]; | ||
4476 | } | ||
4477 | } | ||
4478 | } | 4497 | } |
4479 | 4498 | ||
4480 | mVolumep->mBounds[0] = (min + max) * 0.5f; //center | ||
4481 | mVolumep->mBounds[1] = (max - min) * 0.5f; //half-height | ||
4482 | |||
4483 | return TRUE; | 4499 | return TRUE; |
4484 | } | 4500 | } |
4485 | 4501 | ||
@@ -4578,7 +4594,7 @@ LLVector3 calc_binormal_from_triangle( | |||
4578 | -r0.mV[VZ] / r0.mV[VX], | 4594 | -r0.mV[VZ] / r0.mV[VX], |
4579 | -r1.mV[VZ] / r1.mV[VX], | 4595 | -r1.mV[VZ] / r1.mV[VX], |
4580 | -r2.mV[VZ] / r2.mV[VX]); | 4596 | -r2.mV[VZ] / r2.mV[VX]); |
4581 | //binormal.normVec(); | 4597 | // binormal.normVec(); |
4582 | return binormal; | 4598 | return binormal; |
4583 | } | 4599 | } |
4584 | else | 4600 | else |