diff options
Diffstat (limited to '')
-rw-r--r-- | linden/indra/llmath/llvolume.cpp | 74 |
1 files changed, 44 insertions, 30 deletions
diff --git a/linden/indra/llmath/llvolume.cpp b/linden/indra/llmath/llvolume.cpp index 7f2a663..9cad612 100644 --- a/linden/indra/llmath/llvolume.cpp +++ b/linden/indra/llmath/llvolume.cpp | |||
@@ -1,6 +1,8 @@ | |||
1 | /** | 1 | /** |
2 | * @file llvolume.cpp | 2 | * @file llvolume.cpp |
3 | * | 3 | * |
4 | * $LicenseInfo:firstyear=2002&license=viewergpl$ | ||
5 | * | ||
4 | * Copyright (c) 2002-2007, Linden Research, Inc. | 6 | * Copyright (c) 2002-2007, Linden Research, Inc. |
5 | * | 7 | * |
6 | * Second Life Viewer Source Code | 8 | * Second Life Viewer Source Code |
@@ -23,6 +25,7 @@ | |||
23 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | 25 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO |
24 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | 26 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, |
25 | * COMPLETENESS OR PERFORMANCE. | 27 | * COMPLETENESS OR PERFORMANCE. |
28 | * $/LicenseInfo$ | ||
26 | */ | 29 | */ |
27 | 30 | ||
28 | #include "linden_common.h" | 31 | #include "linden_common.h" |
@@ -83,6 +86,8 @@ const S32 SCULPT_REZ_2 = 8; | |||
83 | const S32 SCULPT_REZ_3 = 16; | 86 | const S32 SCULPT_REZ_3 = 16; |
84 | const S32 SCULPT_REZ_4 = 32; | 87 | const S32 SCULPT_REZ_4 = 32; |
85 | 88 | ||
89 | const F32 SCULPT_MIN_AREA = 0.005f; | ||
90 | |||
86 | BOOL check_same_clock_dir( const LLVector3& pt1, const LLVector3& pt2, const LLVector3& pt3, const LLVector3& norm) | 91 | BOOL check_same_clock_dir( const LLVector3& pt1, const LLVector3& pt2, const LLVector3& pt3, const LLVector3& norm) |
87 | { | 92 | { |
88 | LLVector3 test = (pt2-pt1)%(pt3-pt2); | 93 | LLVector3 test = (pt2-pt1)%(pt3-pt2); |
@@ -1825,6 +1830,18 @@ void LLVolume::createVolumeFaces() | |||
1825 | } | 1830 | } |
1826 | 1831 | ||
1827 | 1832 | ||
1833 | inline LLVector3 sculpt_rgb_to_vector(U8 r, U8 g, U8 b) | ||
1834 | { | ||
1835 | // maps RGB values to vector values [0..255] -> [-0.5..0.5] | ||
1836 | LLVector3 value; | ||
1837 | value.mV[VX] = r / 256.f - 0.5f; | ||
1838 | value.mV[VY] = g / 256.f - 0.5f; | ||
1839 | value.mV[VZ] = b / 256.f - 0.5f; | ||
1840 | |||
1841 | return value; | ||
1842 | } | ||
1843 | |||
1844 | |||
1828 | // sculpt replaces generate() for sculpted surfaces | 1845 | // sculpt replaces generate() for sculpted surfaces |
1829 | void LLVolume::sculpt(U16 sculpt_width, U16 sculpt_height, S8 sculpt_components, const U8* sculpt_data, S32 sculpt_level) | 1846 | void LLVolume::sculpt(U16 sculpt_width, U16 sculpt_height, S8 sculpt_components, const U8* sculpt_data, S32 sculpt_level) |
1830 | { | 1847 | { |
@@ -1849,40 +1866,39 @@ void LLVolume::sculpt(U16 sculpt_width, U16 sculpt_height, S8 sculpt_components, | |||
1849 | mMesh.resize(sizeS * sizeT); | 1866 | mMesh.resize(sizeS * sizeT); |
1850 | sNumMeshPoints += mMesh.size(); | 1867 | sNumMeshPoints += mMesh.size(); |
1851 | 1868 | ||
1852 | S32 vertex_change = 0; | 1869 | F32 area = 0; |
1853 | // first test to see if image has enough variation to create non-degenerate geometry | 1870 | // first test to see if image has enough variation to create non-degenerate geometry |
1854 | if (!data_is_empty) | 1871 | if (!data_is_empty) |
1855 | { | 1872 | { |
1856 | S32 last_index = 0; | 1873 | for (S32 s = 0; s < sizeS - 1; s++) |
1857 | for (S32 s = 0; s < sizeS; s++) | 1874 | for (S32 t = 0; t < sizeT - 1; t++) |
1858 | for (S32 t = 0; t < sizeT; t++) | ||
1859 | { | 1875 | { |
1860 | U32 x = (U32) ((F32)s/(sizeS-1) * (F32) sculpt_width); | 1876 | // first coordinate |
1861 | U32 y = (U32) ((F32)t/(sizeT-1) * (F32) sculpt_height); | 1877 | U32 x = (U32) ((F32)s/(sizeS) * (F32) sculpt_width); |
1878 | U32 y = (U32) ((F32)t/(sizeT) * (F32) sculpt_height); | ||
1862 | 1879 | ||
1863 | if (y == sculpt_height) // stitch bottom | 1880 | // coordinate offset by 1 |
1864 | { | 1881 | U32 x2 = (U32) ((F32)(s+1)/(sizeS) * (F32) sculpt_width); |
1865 | y = sculpt_height - 1; | 1882 | U32 y2 = (U32) ((F32)(t+1)/(sizeT) * (F32) sculpt_height); |
1866 | x = sculpt_width / 2; | 1883 | |
1867 | } | 1884 | // three points on a triagle - find the image indices first |
1868 | 1885 | U32 p1_index = (x + y * sculpt_width) * sculpt_components; | |
1869 | if (x == sculpt_width) // stitch sides | 1886 | U32 p2_index = (x2 + y * sculpt_width) * sculpt_components; |
1870 | x = 0; | 1887 | U32 p3_index = (x + y2 * sculpt_width) * sculpt_components; |
1871 | 1888 | ||
1872 | if (y == 0) // stitch top | 1889 | // convert image data to vectors |
1873 | x = sculpt_width / 2; | 1890 | LLVector3 p1 = sculpt_rgb_to_vector(sculpt_data[p1_index], sculpt_data[p1_index+1], sculpt_data[p1_index+2]); |
1874 | 1891 | LLVector3 p2 = sculpt_rgb_to_vector(sculpt_data[p2_index], sculpt_data[p2_index+1], sculpt_data[p2_index+2]); | |
1875 | U32 index = (x + y * sculpt_width) * sculpt_components; | 1892 | LLVector3 p3 = sculpt_rgb_to_vector(sculpt_data[p3_index], sculpt_data[p3_index+1], sculpt_data[p3_index+2]); |
1876 | 1893 | ||
1877 | if (fabs((F32)(sculpt_data[index] - sculpt_data[last_index])) + | 1894 | // compute the area of the parallelogram by taking the length of the cross product: |
1878 | fabs((F32)(sculpt_data[index+1] - sculpt_data[last_index+1])) + | 1895 | // (parallegram is an approximation of two triangles) |
1879 | fabs((F32)(sculpt_data[index+2] - sculpt_data[last_index+2])) > 0) | 1896 | LLVector3 cross = (p1 - p2) % (p1 - p3); |
1880 | vertex_change++; | 1897 | // take length squared for efficiency (no sqrt) |
1881 | 1898 | area += cross.magVecSquared(); | |
1882 | last_index = index; | ||
1883 | } | 1899 | } |
1884 | 1900 | ||
1885 | if ((F32)vertex_change / sizeS / sizeT < 0.02) // less than 2% | 1901 | if (area < SCULPT_MIN_AREA * SCULPT_MIN_AREA) |
1886 | data_is_empty = TRUE; | 1902 | data_is_empty = TRUE; |
1887 | } | 1903 | } |
1888 | 1904 | ||
@@ -1974,9 +1990,7 @@ void LLVolume::sculpt(U16 sculpt_width, U16 sculpt_height, S8 sculpt_components, | |||
1974 | 1990 | ||
1975 | 1991 | ||
1976 | U32 index = (x + y * sculpt_width) * sculpt_components; | 1992 | U32 index = (x + y * sculpt_width) * sculpt_components; |
1977 | pt.mPos.mV[0] = sculpt_data[index ] / 256.f - 0.5f; | 1993 | pt.mPos = sculpt_rgb_to_vector(sculpt_data[index], sculpt_data[index+1], sculpt_data[index+2]); |
1978 | pt.mPos.mV[1] = sculpt_data[index+1] / 256.f - 0.5f; | ||
1979 | pt.mPos.mV[2] = sculpt_data[index+2] / 256.f - 0.5f; | ||
1980 | } | 1994 | } |
1981 | line += sizeT; | 1995 | line += sizeT; |
1982 | } | 1996 | } |