aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llmath/llvolume.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2009-04-30 13:04:20 -0500
committerJacek Antonelli2009-04-30 13:07:16 -0500
commitca8149ca6d157eb4b5fc8ba0e5ba3a6e56f72e7e (patch)
tree8348301d0ac44a524f1819b777686bf086907d76 /linden/indra/llmath/llvolume.cpp
parentSecond Life viewer sources 1.22.11 (diff)
downloadmeta-impy-ca8149ca6d157eb4b5fc8ba0e5ba3a6e56f72e7e.zip
meta-impy-ca8149ca6d157eb4b5fc8ba0e5ba3a6e56f72e7e.tar.gz
meta-impy-ca8149ca6d157eb4b5fc8ba0e5ba3a6e56f72e7e.tar.bz2
meta-impy-ca8149ca6d157eb4b5fc8ba0e5ba3a6e56f72e7e.tar.xz
Second Life viewer sources 1.23.0-RC
Diffstat (limited to '')
-rw-r--r--linden/indra/llmath/llvolume.cpp87
1 files changed, 51 insertions, 36 deletions
diff --git a/linden/indra/llmath/llvolume.cpp b/linden/indra/llmath/llvolume.cpp
index 5603a9c..1250f53 100644
--- a/linden/indra/llmath/llvolume.cpp
+++ b/linden/indra/llmath/llvolume.cpp
@@ -16,7 +16,8 @@
16 * There are special exceptions to the terms and conditions of the GPL as 16 * There are special exceptions to the terms and conditions of the GPL as
17 * it is applied to this Source Code. View the full text of the exception 17 * it is applied to this Source Code. View the full text of the exception
18 * in the file doc/FLOSS-exception.txt in this software distribution, or 18 * in the file doc/FLOSS-exception.txt in this software distribution, or
19 * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception 19 * online at
20 * http://secondlifegrid.net/programs/open_source/licensing/flossexception
20 * 21 *
21 * By copying, modifying or distributing this software, you acknowledge 22 * By copying, modifying or distributing this software, you acknowledge
22 * that you have read and understood your obligations described above, 23 * that you have read and understood your obligations described above,
@@ -1972,34 +1973,29 @@ inline LLVector3 sculpt_xy_to_vector(U32 x, U32 y, U16 sculpt_width, U16 sculpt_
1972} 1973}
1973 1974
1974 1975
1975F32 LLVolume::sculptGetSurfaceArea(U16 sculpt_width, U16 sculpt_height, S8 sculpt_components, const U8* sculpt_data) 1976F32 LLVolume::sculptGetSurfaceArea()
1976{ 1977{
1977 // test to see if image has enough variation to create non-degenerate geometry 1978 // test to see if image has enough variation to create non-degenerate geometry
1978 1979
1980 F32 area = 0;
1981
1979 S32 sizeS = mPathp->mPath.size(); 1982 S32 sizeS = mPathp->mPath.size();
1980 S32 sizeT = mProfilep->mProfile.size(); 1983 S32 sizeT = mProfilep->mProfile.size();
1981 1984
1982 F32 area = 0; 1985 for (S32 s = 0; s < sizeS-1; s++)
1983
1984 if ((sculpt_width != 0) &&
1985 (sculpt_height != 0) &&
1986 (sculpt_components != 0) &&
1987 (sculpt_data != NULL))
1988 { 1986 {
1989 for (S32 s = 0; s < sizeS - 1; s++) 1987 for (S32 t = 0; t < sizeT-1; t++)
1990 { 1988 {
1991 for (S32 t = 0; t < sizeT - 1; t++) 1989 // get four corners of quad
1992 { 1990 LLVector3 p1 = mMesh[(s )*sizeT + (t )].mPos;
1993 // convert image data to vectors 1991 LLVector3 p2 = mMesh[(s+1)*sizeT + (t )].mPos;
1994 LLVector3 p1 = sculpt_st_to_vector(s, t, sizeS, sizeT, sculpt_width, sculpt_height, sculpt_components, sculpt_data); 1992 LLVector3 p3 = mMesh[(s )*sizeT + (t+1)].mPos;
1995 LLVector3 p2 = sculpt_st_to_vector(s+1, t, sizeS, sizeT, sculpt_width, sculpt_height, sculpt_components, sculpt_data); 1993 LLVector3 p4 = mMesh[(s+1)*sizeT + (t+1)].mPos;
1996 LLVector3 p3 = sculpt_st_to_vector(s, t+1, sizeS, sizeT, sculpt_width, sculpt_height, sculpt_components, sculpt_data); 1994
1997 1995 // compute the area of the quad by taking the length of the cross product of the two triangles
1998 // compute the area of the parallelogram by taking the length of the cross product: 1996 LLVector3 cross1 = (p1 - p2) % (p1 - p3);
1999 // (parallegram is an approximation of two triangles) 1997 LLVector3 cross2 = (p4 - p2) % (p4 - p3);
2000 LLVector3 cross = (p1 - p2) % (p1 - p3); 1998 area += (cross1.magVec() + cross2.magVec()) / 2.0;
2001 area += cross.magVec();
2002 }
2003 } 1999 }
2004 } 2000 }
2005 2001
@@ -2163,7 +2159,21 @@ S32 sculpt_sides(F32 detail)
2163// determine the number of vertices in both s and t direction for this sculpt 2159// determine the number of vertices in both s and t direction for this sculpt
2164void sculpt_calc_mesh_resolution(U16 width, U16 height, U8 type, F32 detail, S32& s, S32& t) 2160void sculpt_calc_mesh_resolution(U16 width, U16 height, U8 type, F32 detail, S32& s, S32& t)
2165{ 2161{
2166 S32 vertices = sculpt_sides(detail); 2162 // this code has the following properties:
2163 // 1) the aspect ratio of the mesh is as close as possible to the ratio of the map
2164 // while still using all available verts
2165 // 2) the mesh cannot have more verts than is allowed by LOD
2166 // 3) the mesh cannot have more verts than is allowed by the map
2167
2168 S32 max_vertices_lod = (S32)pow((double)sculpt_sides(detail), 2.0);
2169 S32 max_vertices_map = width * height / 4;
2170
2171 S32 vertices;
2172 if (max_vertices_map > 0)
2173 vertices = llmin(max_vertices_lod, max_vertices_map);
2174 else
2175 vertices = max_vertices_lod;
2176
2167 2177
2168 F32 ratio; 2178 F32 ratio;
2169 if ((width == 0) || (height == 0)) 2179 if ((width == 0) || (height == 0))
@@ -2172,13 +2182,13 @@ void sculpt_calc_mesh_resolution(U16 width, U16 height, U8 type, F32 detail, S32
2172 ratio = (F32) width / (F32) height; 2182 ratio = (F32) width / (F32) height;
2173 2183
2174 2184
2175 s = (S32)(vertices / fsqrtf(ratio)); 2185 s = (S32)fsqrtf(((F32)vertices / ratio));
2176 2186
2177 s = llmax(s, 3); // no degenerate sizes, please 2187 s = llmax(s, 4); // no degenerate sizes, please
2178 t = vertices * vertices / s; 2188 t = vertices / s;
2179 2189
2180 t = llmax(t, 3); // no degenerate sizes, please 2190 t = llmax(t, 4); // no degenerate sizes, please
2181 s = vertices * vertices / t; 2191 s = vertices / t;
2182} 2192}
2183 2193
2184// sculpt replaces generate() for sculpted surfaces 2194// sculpt replaces generate() for sculpted surfaces
@@ -2215,20 +2225,25 @@ void LLVolume::sculpt(U16 sculpt_width, U16 sculpt_height, S8 sculpt_components,
2215 sNumMeshPoints -= mMesh.size(); 2225 sNumMeshPoints -= mMesh.size();
2216 mMesh.resize(sizeS * sizeT); 2226 mMesh.resize(sizeS * sizeT);
2217 sNumMeshPoints += mMesh.size(); 2227 sNumMeshPoints += mMesh.size();
2218
2219 if (!data_is_empty && sculptGetSurfaceArea(sculpt_width, sculpt_height, sculpt_components, sculpt_data) < SCULPT_MIN_AREA)
2220 data_is_empty = TRUE;
2221 2228
2222 //generate vertex positions 2229 //generate vertex positions
2223 if (data_is_empty) // if empty, make a placeholder mesh 2230 if (!data_is_empty)
2224 {
2225 sculptGeneratePlaceholder();
2226 }
2227 else
2228 { 2231 {
2229 sculptGenerateMapVertices(sculpt_width, sculpt_height, sculpt_components, sculpt_data, sculpt_type); 2232 sculptGenerateMapVertices(sculpt_width, sculpt_height, sculpt_components, sculpt_data, sculpt_type);
2233
2234 if (sculptGetSurfaceArea() < SCULPT_MIN_AREA)
2235 {
2236 data_is_empty = TRUE;
2237 }
2230 } 2238 }
2231 2239
2240 if (data_is_empty)
2241 {
2242 sculptGeneratePlaceholder();
2243 }
2244
2245
2246
2232 for (S32 i = 0; i < (S32)mProfilep->mFaces.size(); i++) 2247 for (S32 i = 0; i < (S32)mProfilep->mFaces.size(); i++)
2233 { 2248 {
2234 mFaceMask |= mProfilep->mFaces[i].mFaceID; 2249 mFaceMask |= mProfilep->mFaces[i].mFaceID;