diff options
author | Jacek Antonelli | 2008-08-15 23:44:59 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:59 -0500 |
commit | a408bac29378072fbf36864164149458c978cfcc (patch) | |
tree | 67feccf1a5d3816611ba48d6762f86f0f7f4b1f6 /linden/indra/llmath/llvolume.cpp | |
parent | Second Life viewer sources 1.17.0.12 (diff) | |
download | meta-impy-a408bac29378072fbf36864164149458c978cfcc.zip meta-impy-a408bac29378072fbf36864164149458c978cfcc.tar.gz meta-impy-a408bac29378072fbf36864164149458c978cfcc.tar.bz2 meta-impy-a408bac29378072fbf36864164149458c978cfcc.tar.xz |
Second Life viewer sources 1.17.1.0
Diffstat (limited to 'linden/indra/llmath/llvolume.cpp')
-rw-r--r-- | linden/indra/llmath/llvolume.cpp | 193 |
1 files changed, 139 insertions, 54 deletions
diff --git a/linden/indra/llmath/llvolume.cpp b/linden/indra/llmath/llvolume.cpp index 327f1bf..5764c38 100644 --- a/linden/indra/llmath/llvolume.cpp +++ b/linden/indra/llmath/llvolume.cpp | |||
@@ -1799,6 +1799,8 @@ void LLVolume::createVolumeFaces() | |||
1799 | // sculpt replaces generate() for sculpted surfaces | 1799 | // sculpt replaces generate() for sculpted surfaces |
1800 | void LLVolume::sculpt(U16 sculpt_width, U16 sculpt_height, S8 sculpt_components, const U8* sculpt_data, S32 sculpt_level) | 1800 | void LLVolume::sculpt(U16 sculpt_width, U16 sculpt_height, S8 sculpt_components, const U8* sculpt_data, S32 sculpt_level) |
1801 | { | 1801 | { |
1802 | U8 sculpt_type = mParams.getSculptType(); | ||
1803 | |||
1802 | BOOL data_is_empty = FALSE; | 1804 | BOOL data_is_empty = FALSE; |
1803 | 1805 | ||
1804 | if (sculpt_width == 0 || sculpt_height == 0 || sculpt_data == NULL) | 1806 | if (sculpt_width == 0 || sculpt_height == 0 || sculpt_data == NULL) |
@@ -1880,6 +1882,7 @@ void LLVolume::sculpt(U16 sculpt_width, U16 sculpt_height, S8 sculpt_components, | |||
1880 | line += sizeT; | 1882 | line += sizeT; |
1881 | } | 1883 | } |
1882 | } | 1884 | } |
1885 | |||
1883 | else | 1886 | else |
1884 | { | 1887 | { |
1885 | S32 line = 0; | 1888 | S32 line = 0; |
@@ -1894,18 +1897,52 @@ void LLVolume::sculpt(U16 sculpt_width, U16 sculpt_height, S8 sculpt_components, | |||
1894 | U32 x = (U32) ((F32)t/(sizeT-1) * (F32) sculpt_width); | 1897 | U32 x = (U32) ((F32)t/(sizeT-1) * (F32) sculpt_width); |
1895 | U32 y = (U32) ((F32)s/(sizeS-1) * (F32) sculpt_height); | 1898 | U32 y = (U32) ((F32)s/(sizeS-1) * (F32) sculpt_height); |
1896 | 1899 | ||
1897 | if (y == sculpt_height) // stitch bottom row | 1900 | if (y == 0) // top row stitching |
1898 | { | 1901 | { |
1899 | y = sculpt_height - 1; | 1902 | // pinch? |
1900 | x = sculpt_width / 2; | 1903 | if (sculpt_type == LL_SCULPT_TYPE_SPHERE) |
1904 | { | ||
1905 | x = sculpt_width / 2; | ||
1906 | } | ||
1901 | } | 1907 | } |
1902 | 1908 | ||
1903 | if (x == sculpt_width) // stitch sides | 1909 | if (y == sculpt_height) // bottom row stitching |
1904 | x = 0; | 1910 | { |
1911 | // wrap? | ||
1912 | if (sculpt_type == LL_SCULPT_TYPE_TORUS) | ||
1913 | { | ||
1914 | y = 0; | ||
1915 | } | ||
1916 | else | ||
1917 | { | ||
1918 | y = sculpt_height - 1; | ||
1919 | } | ||
1905 | 1920 | ||
1906 | if (y == 0) // stitch top row | 1921 | // pinch? |
1907 | x = sculpt_width / 2; | 1922 | if (sculpt_type == LL_SCULPT_TYPE_SPHERE) |
1908 | 1923 | { | |
1924 | x = sculpt_width / 2; | ||
1925 | } | ||
1926 | } | ||
1927 | |||
1928 | if (x == sculpt_width) // side stitching | ||
1929 | { | ||
1930 | // wrap? | ||
1931 | if ((sculpt_type == LL_SCULPT_TYPE_SPHERE) || | ||
1932 | (sculpt_type == LL_SCULPT_TYPE_TORUS) || | ||
1933 | (sculpt_type == LL_SCULPT_TYPE_CYLINDER)) | ||
1934 | { | ||
1935 | x = 0; | ||
1936 | } | ||
1937 | |||
1938 | else | ||
1939 | { | ||
1940 | x = sculpt_width - 1; | ||
1941 | } | ||
1942 | } | ||
1943 | |||
1944 | |||
1945 | |||
1909 | U32 index = (x + y * sculpt_width) * sculpt_components; | 1946 | U32 index = (x + y * sculpt_width) * sculpt_components; |
1910 | pt.mPos.mV[0] = sculpt_data[index ] / 256.f - 0.5f; | 1947 | pt.mPos.mV[0] = sculpt_data[index ] / 256.f - 0.5f; |
1911 | pt.mPos.mV[1] = sculpt_data[index+1] / 256.f - 0.5f; | 1948 | pt.mPos.mV[1] = sculpt_data[index+1] / 256.f - 0.5f; |
@@ -4615,82 +4652,130 @@ BOOL LLVolumeFace::createSide() | |||
4615 | } | 4652 | } |
4616 | } | 4653 | } |
4617 | 4654 | ||
4655 | // adjust normals based on wrapping and stitching | ||
4656 | |||
4618 | BOOL s_bottom_converges = ((mVertices[0].mPosition - mVertices[mNumS*(mNumT-2)].mPosition).magVecSquared() < 0.000001f); | 4657 | BOOL s_bottom_converges = ((mVertices[0].mPosition - mVertices[mNumS*(mNumT-2)].mPosition).magVecSquared() < 0.000001f); |
4619 | BOOL s_top_converges = ((mVertices[mNumS-1].mPosition - mVertices[mNumS*(mNumT-2)+mNumS-1].mPosition).magVecSquared() < 0.000001f); | 4658 | BOOL s_top_converges = ((mVertices[mNumS-1].mPosition - mVertices[mNumS*(mNumT-2)+mNumS-1].mPosition).magVecSquared() < 0.000001f); |
4620 | 4659 | U8 sculpt_type = mVolumep->getParams().getSculptType(); | |
4621 | if (mVolumep->getPath().isOpen() == FALSE) { //wrap normals on T | 4660 | |
4622 | for (S32 i = 0; i < mNumS; i++) { | 4661 | if (sculpt_type == LL_SCULPT_TYPE_NONE) // logic for non-sculpt volumes |
4623 | LLVector3 norm = mVertices[i].mNormal + mVertices[mNumS*(mNumT-1)+i].mNormal; | 4662 | { |
4624 | mVertices[i].mNormal = norm; | 4663 | if (mVolumep->getPath().isOpen() == FALSE) |
4625 | mVertices[mNumS*(mNumT-1)+i].mNormal = norm; | 4664 | { //wrap normals on T |
4665 | for (S32 i = 0; i < mNumS; i++) | ||
4666 | { | ||
4667 | LLVector3 norm = mVertices[i].mNormal + mVertices[mNumS*(mNumT-1)+i].mNormal; | ||
4668 | mVertices[i].mNormal = norm; | ||
4669 | mVertices[mNumS*(mNumT-1)+i].mNormal = norm; | ||
4670 | } | ||
4626 | } | 4671 | } |
4627 | } | ||
4628 | 4672 | ||
4629 | if ((mVolumep->getProfile().isOpen() == FALSE) && | 4673 | if ((mVolumep->getProfile().isOpen() == FALSE) && !(s_bottom_converges)) |
4630 | !(s_bottom_converges)) | ||
4631 | { //wrap normals on S | 4674 | { //wrap normals on S |
4632 | for (S32 i = 0; i < mNumT; i++) { | 4675 | for (S32 i = 0; i < mNumT; i++) |
4676 | { | ||
4633 | LLVector3 norm = mVertices[mNumS*i].mNormal + mVertices[mNumS*i+mNumS-1].mNormal; | 4677 | LLVector3 norm = mVertices[mNumS*i].mNormal + mVertices[mNumS*i+mNumS-1].mNormal; |
4634 | mVertices[mNumS * i].mNormal = norm; | 4678 | mVertices[mNumS * i].mNormal = norm; |
4635 | mVertices[mNumS * i+mNumS-1].mNormal = norm; | 4679 | mVertices[mNumS * i+mNumS-1].mNormal = norm; |
4636 | } | 4680 | } |
4637 | } | 4681 | } |
4638 | 4682 | ||
4639 | if (mVolumep->getPathType() == LL_PCODE_PATH_CIRCLE && | 4683 | if (mVolumep->getPathType() == LL_PCODE_PATH_CIRCLE && |
4640 | ((mVolumep->getProfileType() & LL_PCODE_PROFILE_MASK) == LL_PCODE_PROFILE_CIRCLE_HALF)) | 4684 | ((mVolumep->getProfileType() & LL_PCODE_PROFILE_MASK) == LL_PCODE_PROFILE_CIRCLE_HALF)) |
4641 | { | 4685 | { |
4642 | if (s_bottom_converges) | 4686 | if (s_bottom_converges) |
4643 | { //all lower S have same normal | 4687 | { //all lower S have same normal |
4644 | for (S32 i = 0; i < mNumT; i++) { | 4688 | for (S32 i = 0; i < mNumT; i++) |
4645 | mVertices[mNumS*i].mNormal = LLVector3(1,0,0); | 4689 | { |
4690 | mVertices[mNumS*i].mNormal = LLVector3(1,0,0); | ||
4691 | } | ||
4646 | } | 4692 | } |
4647 | } | ||
4648 | 4693 | ||
4649 | if (s_top_converges) | 4694 | if (s_top_converges) |
4650 | { //all upper S have same normal | 4695 | { //all upper S have same normal |
4651 | for (S32 i = 0; i < mNumT; i++) { | 4696 | for (S32 i = 0; i < mNumT; i++) |
4652 | mVertices[mNumS*i+mNumS-1].mNormal = LLVector3(-1,0,0); | 4697 | { |
4698 | mVertices[mNumS*i+mNumS-1].mNormal = LLVector3(-1,0,0); | ||
4699 | } | ||
4653 | } | 4700 | } |
4654 | } | 4701 | } |
4655 | } | 4702 | } |
4656 | |||
4657 | U8 sculpt_type = mVolumep->getParams().getSculptType(); | ||
4658 | 4703 | ||
4659 | if (sculpt_type == LL_SCULPT_TYPE_SPHERE) | 4704 | else // logic for sculpt volumes |
4660 | { | 4705 | { |
4661 | // average normals for north pole | 4706 | BOOL average_poles = FALSE; |
4707 | BOOL wrap_s = FALSE; | ||
4708 | BOOL wrap_t = FALSE; | ||
4709 | |||
4710 | if (sculpt_type == LL_SCULPT_TYPE_SPHERE) | ||
4711 | average_poles = TRUE; | ||
4712 | |||
4713 | if ((sculpt_type == LL_SCULPT_TYPE_SPHERE) || | ||
4714 | (sculpt_type == LL_SCULPT_TYPE_TORUS) || | ||
4715 | (sculpt_type == LL_SCULPT_TYPE_CYLINDER)) | ||
4716 | wrap_s = TRUE; | ||
4717 | |||
4718 | if (sculpt_type == LL_SCULPT_TYPE_TORUS) | ||
4719 | wrap_t = TRUE; | ||
4720 | |||
4662 | 4721 | ||
4663 | LLVector3 average(0.0, 0.0, 0.0); | 4722 | if (average_poles) |
4664 | for (S32 i = 0; i < mNumS; i++) | ||
4665 | { | 4723 | { |
4666 | average += mVertices[i].mNormal; | 4724 | // average normals for north pole |
4667 | } | 4725 | |
4726 | LLVector3 average(0.0, 0.0, 0.0); | ||
4727 | for (S32 i = 0; i < mNumS; i++) | ||
4728 | { | ||
4729 | average += mVertices[i].mNormal; | ||
4730 | } | ||
4731 | |||
4732 | // set average | ||
4733 | for (S32 i = 0; i < mNumS; i++) | ||
4734 | { | ||
4735 | mVertices[i].mNormal = average; | ||
4736 | } | ||
4737 | |||
4738 | // average normals for south pole | ||
4739 | |||
4740 | average = LLVector3(0.0, 0.0, 0.0); | ||
4741 | for (S32 i = 0; i < mNumS; i++) | ||
4742 | { | ||
4743 | average += mVertices[i + mNumS * (mNumT - 1)].mNormal; | ||
4744 | } | ||
4745 | |||
4746 | // set average | ||
4747 | for (S32 i = 0; i < mNumS; i++) | ||
4748 | { | ||
4749 | mVertices[i + mNumS * (mNumT - 1)].mNormal = average; | ||
4750 | } | ||
4668 | 4751 | ||
4669 | // set average | ||
4670 | for (S32 i = 0; i < mNumS; i++) | ||
4671 | { | ||
4672 | mVertices[i].mNormal = average; | ||
4673 | } | 4752 | } |
4674 | } | ||
4675 | 4753 | ||
4676 | |||
4677 | if (sculpt_type == LL_SCULPT_TYPE_SPHERE) | ||
4678 | { | ||
4679 | // average normals for south pole | ||
4680 | 4754 | ||
4681 | LLVector3 average(0.0, 0.0, 0.0); | 4755 | if (wrap_s) |
4682 | for (S32 i = 0; i < mNumS; i++) | ||
4683 | { | 4756 | { |
4684 | average += mVertices[i + mNumS * (mNumT - 1)].mNormal; | 4757 | for (S32 i = 0; i < mNumT; i++) |
4758 | { | ||
4759 | LLVector3 norm = mVertices[mNumS*i].mNormal + mVertices[mNumS*i+mNumS-1].mNormal; | ||
4760 | mVertices[mNumS * i].mNormal = norm; | ||
4761 | mVertices[mNumS * i+mNumS-1].mNormal = norm; | ||
4762 | } | ||
4685 | } | 4763 | } |
4686 | 4764 | ||
4687 | // set average | 4765 | |
4688 | for (S32 i = 0; i < mNumS; i++) | 4766 | |
4767 | if (wrap_t) | ||
4689 | { | 4768 | { |
4690 | mVertices[i + mNumS * (mNumT - 1)].mNormal = average; | 4769 | for (S32 i = 0; i < mNumS; i++) |
4770 | { | ||
4771 | LLVector3 norm = mVertices[i].mNormal + mVertices[mNumS*(mNumT-1)+i].mNormal; | ||
4772 | mVertices[i].mNormal = norm; | ||
4773 | mVertices[mNumS*(mNumT-1)+i].mNormal = norm; | ||
4774 | } | ||
4775 | |||
4691 | } | 4776 | } |
4692 | } | ||
4693 | 4777 | ||
4778 | } | ||
4694 | 4779 | ||
4695 | 4780 | ||
4696 | //normalize normals and binormals here so the meshes that reference | 4781 | //normalize normals and binormals here so the meshes that reference |