diff options
author | Dahlia Trimble | 2008-08-27 06:53:09 +0000 |
---|---|---|
committer | Dahlia Trimble | 2008-08-27 06:53:09 +0000 |
commit | 3481a977f057c723f688941e584a60211f56baa5 (patch) | |
tree | 24561c218d70bcd60a8d2d91c11f5cb4e94e4300 /OpenSim | |
parent | Completion of new PrimMesher class (diff) | |
download | opensim-SC-3481a977f057c723f688941e584a60211f56baa5.zip opensim-SC-3481a977f057c723f688941e584a60211f56baa5.tar.gz opensim-SC-3481a977f057c723f688941e584a60211f56baa5.tar.bz2 opensim-SC-3481a977f057c723f688941e584a60211f56baa5.tar.xz |
Meshmerizer now uses new PrimMesher class for meshing all standard (non-sculpty) prims. This should result in more accurate meshes, lower memory consumption, and eliminate several lockup modes.
Diffstat (limited to 'OpenSim')
-rw-r--r-- | OpenSim/Region/Physics/Meshing/Meshmerizer.cs | 143 |
1 files changed, 133 insertions, 10 deletions
diff --git a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs index 4618539..06df4ca 100644 --- a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs +++ b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs | |||
@@ -1864,6 +1864,115 @@ namespace OpenSim.Region.Physics.Meshing | |||
1864 | } | 1864 | } |
1865 | } | 1865 | } |
1866 | 1866 | ||
1867 | public Mesh CreateMeshFromPrimMesher(string primName, PrimitiveBaseShape primShape, PhysicsVector size, float lod) | ||
1868 | { | ||
1869 | //reportPrimParams(primName, primShape); | ||
1870 | Mesh mesh = new Mesh(); | ||
1871 | |||
1872 | float pathShearX = primShape.PathShearX < 128 ? (float)primShape.PathShearX * 0.01f : (float)(primShape.PathShearX - 256) * 0.01f; | ||
1873 | float pathShearY = primShape.PathShearY < 128 ? (float)primShape.PathShearY * 0.01f : (float)(primShape.PathShearY - 256) * 0.01f; | ||
1874 | float pathBegin = (float)primShape.PathBegin * 2.0e-5f; | ||
1875 | float pathEnd = 1.0f - (float)primShape.PathEnd * 2.0e-5f; | ||
1876 | float pathScaleX = (float)(primShape.PathScaleX - 100) * 0.01f; | ||
1877 | float pathScaleY = (float)(primShape.PathScaleY - 100) * 0.01f; | ||
1878 | |||
1879 | float profileBegin = (float)primShape.ProfileBegin * 2.0e-5f; | ||
1880 | float profileEnd = 1.0f - (float)primShape.ProfileEnd * 2.0e-5f; | ||
1881 | float profileHollow = (float)primShape.ProfileHollow * 2.0e-5f; | ||
1882 | |||
1883 | int sides = 4; | ||
1884 | if ((primShape.ProfileCurve & 0x07) == (byte)ProfileShape.EquilateralTriangle) | ||
1885 | sides = 3; | ||
1886 | else if ((primShape.ProfileCurve & 0x07) == (byte)ProfileShape.Circle) | ||
1887 | sides = 24; | ||
1888 | else if ((primShape.ProfileCurve & 0x07) == (byte)ProfileShape.HalfCircle) | ||
1889 | { // half circle, prim is a sphere | ||
1890 | sides = 24; | ||
1891 | |||
1892 | profileBegin = 0.5f * profileBegin + 0.5f; | ||
1893 | profileEnd = 0.5f * profileEnd + 0.5f; | ||
1894 | |||
1895 | //profileHollow = 0.0f; // debugging only | ||
1896 | } | ||
1897 | |||
1898 | int hollowSides = sides; | ||
1899 | if (primShape.HollowShape == HollowShape.Circle) | ||
1900 | hollowSides = 24; | ||
1901 | else if (primShape.HollowShape == HollowShape.Square) | ||
1902 | hollowSides = 4; | ||
1903 | else if (primShape.HollowShape == HollowShape.Triangle) | ||
1904 | hollowSides = 3; | ||
1905 | |||
1906 | |||
1907 | PrimMesh primMesh = new PrimMesh(sides, profileBegin, profileEnd, profileHollow, hollowSides); | ||
1908 | //PrimMesh primMesh = new PrimMesh(sides, profileBegin, profileEnd, 0.0f, 4); | ||
1909 | |||
1910 | Profile testProfile = new Profile(sides, profileBegin, profileEnd, profileHollow, hollowSides); | ||
1911 | testProfile.DumpRaw(baseDir, primName, "Profile"); | ||
1912 | |||
1913 | primMesh.topShearX = pathShearX; | ||
1914 | primMesh.topShearY = pathShearY; | ||
1915 | primMesh.pathCutBegin = pathBegin; | ||
1916 | primMesh.pathCutEnd = pathEnd; | ||
1917 | //primMesh.pathCutBegin = 0.0f; | ||
1918 | //primMesh.pathCutEnd = 1.0f; | ||
1919 | |||
1920 | if (primShape.PathCurve == (byte)Extrusion.Straight) | ||
1921 | { | ||
1922 | primMesh.twistBegin = primShape.PathTwistBegin * 18 / 10; | ||
1923 | primMesh.twistEnd = primShape.PathTwist * 18 / 10; | ||
1924 | primMesh.taperX = pathScaleX; | ||
1925 | primMesh.taperY = pathScaleY; | ||
1926 | #if SPAM | ||
1927 | Console.WriteLine("****** PrimMesh Parameters (Linear) ******\n" + primMesh.ParamsToDisplayString()); | ||
1928 | #endif | ||
1929 | primMesh.ExtrudeLinear(); | ||
1930 | } | ||
1931 | else | ||
1932 | { | ||
1933 | //return null; | ||
1934 | primMesh.holeSizeX = (200 - primShape.PathScaleX) * 0.01f; | ||
1935 | primMesh.holeSizeY = (200 - primShape.PathScaleY) * 0.01f; | ||
1936 | primMesh.radius = 0.01f * primShape.PathRadiusOffset; | ||
1937 | primMesh.revolutions = 1.0f + 0.015f * primShape.PathRevolutions; | ||
1938 | primMesh.skew = 0.01f * primShape.PathSkew; | ||
1939 | primMesh.twistBegin = primShape.PathTwistBegin * 36 / 10; | ||
1940 | primMesh.twistEnd = primShape.PathTwist * 36 / 10; | ||
1941 | primMesh.taperX = primShape.PathTaperX * 0.01f; | ||
1942 | primMesh.taperY = primShape.PathTaperY * 0.01f; | ||
1943 | #if SPAM | ||
1944 | Console.WriteLine("****** PrimMesh Parameters (Circular) ******\n" + primMesh.ParamsToDisplayString()); | ||
1945 | #endif | ||
1946 | primMesh.ExtrudeCircular(); | ||
1947 | } | ||
1948 | |||
1949 | primMesh.DumpRaw(baseDir, primName, "primMesh"); | ||
1950 | |||
1951 | primMesh.Scale(size.X, size.Y, size.Z); | ||
1952 | |||
1953 | //int numFaces = primMesh.faces.Count; | ||
1954 | //for (int i = 0; i < numFaces; i++) | ||
1955 | //{ | ||
1956 | // Face f = primMesh.faces[i]; | ||
1957 | // Coord vert = primMesh.coords[f.v1]; | ||
1958 | // Vertex v1 = new Vertex(vert.X, vert.Y, vert.Z); | ||
1959 | // mesh.vertices.Add(v1); | ||
1960 | // vert = primMesh.coords[f.v2]; | ||
1961 | // Vertex v2 = new Vertex(vert.X, vert.Y, vert.Z); | ||
1962 | // mesh.vertices.Add(v2); | ||
1963 | // vert = primMesh.coords[f.v3]; | ||
1964 | // Vertex v3 = new Vertex(vert.X, vert.Y, vert.Z); | ||
1965 | // mesh.vertices.Add(v3); | ||
1966 | // mesh.triangles.Add(new Triangle(v1, v2, v3)); | ||
1967 | //} | ||
1968 | |||
1969 | //mesh.DumpRaw(baseDir, primName, "Mesh"); | ||
1970 | |||
1971 | mesh.primMesh = primMesh; | ||
1972 | |||
1973 | return mesh; | ||
1974 | } | ||
1975 | |||
1867 | public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, PhysicsVector size, float lod) | 1976 | public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, PhysicsVector size, float lod) |
1868 | { | 1977 | { |
1869 | return CreateMesh(primName, primShape, size, lod, false); | 1978 | return CreateMesh(primName, primShape, size, lod, false); |
@@ -1880,18 +1989,24 @@ namespace OpenSim.Region.Physics.Meshing | |||
1880 | mesh = (Mesh)smesh; | 1989 | mesh = (Mesh)smesh; |
1881 | //CalcNormals(mesh); | 1990 | //CalcNormals(mesh); |
1882 | } | 1991 | } |
1992 | |||
1993 | else if (true) | ||
1994 | { | ||
1995 | mesh = CreateMeshFromPrimMesher(primName, primShape, size, lod); | ||
1996 | } | ||
1883 | else if ((primShape.ProfileCurve & 0x07) == (byte)ProfileShape.Square) | 1997 | else if ((primShape.ProfileCurve & 0x07) == (byte)ProfileShape.Square) |
1884 | { | 1998 | { |
1885 | if (primShape.PathCurve == (byte)Extrusion.Straight) | 1999 | if (primShape.PathCurve == (byte)Extrusion.Straight) |
1886 | { // its a box | 2000 | { // its a box |
1887 | mesh = CreateBoxMesh(primName, primShape, size); | 2001 | //mesh = CreateBoxMesh(primName, primShape, size); |
2002 | mesh = CreateMeshFromPrimMesher(primName, primShape, size, lod); | ||
1888 | //CalcNormals(mesh); | 2003 | //CalcNormals(mesh); |
1889 | } | 2004 | } |
1890 | else if (primShape.PathCurve == (byte)Extrusion.Curve1) | 2005 | else if (primShape.PathCurve == (byte)Extrusion.Curve1) |
1891 | { // tube | 2006 | { // tube |
1892 | // do a cylinder for now | 2007 | // do a cylinder for now |
1893 | //mesh = CreateCylinderMesh(primName, primShape, size); | 2008 | //mesh = CreateCylinderMesh(primName, primShape, size); |
1894 | mesh = CreateCircularPathMesh(primName, primShape, size); | 2009 | mesh = CreateMeshFromPrimMesher(primName, primShape, size, lod); |
1895 | //CalcNormals(mesh); | 2010 | //CalcNormals(mesh); |
1896 | } | 2011 | } |
1897 | } | 2012 | } |
@@ -1899,14 +2014,16 @@ namespace OpenSim.Region.Physics.Meshing | |||
1899 | { | 2014 | { |
1900 | if (primShape.PathCurve == (byte)Extrusion.Straight) | 2015 | if (primShape.PathCurve == (byte)Extrusion.Straight) |
1901 | { | 2016 | { |
1902 | mesh = CreateCylinderMesh(primName, primShape, size); | 2017 | //mesh = CreateCylinderMesh(primName, primShape, size); |
2018 | mesh = CreateMeshFromPrimMesher(primName, primShape, size, lod); | ||
1903 | //CalcNormals(mesh); | 2019 | //CalcNormals(mesh); |
1904 | } | 2020 | } |
1905 | 2021 | ||
1906 | // ProfileCurve seems to combine hole shape and profile curve so we need to only compare against the lower 3 bits | 2022 | // ProfileCurve seems to combine hole shape and profile curve so we need to only compare against the lower 3 bits |
1907 | else if (primShape.PathCurve == (byte) Extrusion.Curve1) | 2023 | else if (primShape.PathCurve == (byte) Extrusion.Curve1) |
1908 | { // dahlia's favorite, a torus :) | 2024 | { // dahlia's favorite, a torus :) |
1909 | mesh = CreateCircularPathMesh(primName, primShape, size); | 2025 | //mesh = CreateCircularPathMesh(primName, primShape, size); |
2026 | mesh = CreateMeshFromPrimMesher(primName, primShape, size, lod); | ||
1910 | //CalcNormals(mesh); | 2027 | //CalcNormals(mesh); |
1911 | } | 2028 | } |
1912 | } | 2029 | } |
@@ -1915,7 +2032,8 @@ namespace OpenSim.Region.Physics.Meshing | |||
1915 | if (primShape.PathCurve == (byte)Extrusion.Curve1 || primShape.PathCurve == (byte) Extrusion.Curve2) | 2032 | if (primShape.PathCurve == (byte)Extrusion.Curve1 || primShape.PathCurve == (byte) Extrusion.Curve2) |
1916 | { | 2033 | { |
1917 | //mesh = CreateSphereMesh(primName, primShape, size); | 2034 | //mesh = CreateSphereMesh(primName, primShape, size); |
1918 | mesh = CreateCircularPathMesh(primName, primShape, size); | 2035 | //mesh = CreateCircularPathMesh(primName, primShape, size); |
2036 | mesh = CreateMeshFromPrimMesher(primName, primShape, size, lod); | ||
1919 | //CalcNormals(mesh); | 2037 | //CalcNormals(mesh); |
1920 | } | 2038 | } |
1921 | } | 2039 | } |
@@ -1923,13 +2041,15 @@ namespace OpenSim.Region.Physics.Meshing | |||
1923 | { | 2041 | { |
1924 | if (primShape.PathCurve == (byte)Extrusion.Straight) | 2042 | if (primShape.PathCurve == (byte)Extrusion.Straight) |
1925 | { | 2043 | { |
1926 | mesh = CreatePrismMesh(primName, primShape, size); | 2044 | //mesh = CreatePrismMesh(primName, primShape, size); |
2045 | mesh = CreateMeshFromPrimMesher(primName, primShape, size, lod); | ||
1927 | //CalcNormals(mesh); | 2046 | //CalcNormals(mesh); |
1928 | } | 2047 | } |
1929 | else if (primShape.PathCurve == (byte) Extrusion.Curve1) | 2048 | else if (primShape.PathCurve == (byte) Extrusion.Curve1) |
1930 | { // a ring - do a cylinder for now | 2049 | { // a ring - do a cylinder for now |
1931 | //mesh = CreateCylinderMesh(primName, primShape, size); | 2050 | //mesh = CreateCylinderMesh(primName, primShape, size); |
1932 | mesh = CreateCircularPathMesh(primName, primShape, size); | 2051 | //mesh = CreateCircularPathMesh(primName, primShape, size); |
2052 | mesh = CreateMeshFromPrimMesher(primName, primShape, size, lod); | ||
1933 | //CalcNormals(mesh); | 2053 | //CalcNormals(mesh); |
1934 | } | 2054 | } |
1935 | } | 2055 | } |
@@ -1967,9 +2087,12 @@ namespace OpenSim.Region.Physics.Meshing | |||
1967 | float pathShearY = primShape.PathShearY < 128 ? (float)primShape.PathShearY * 0.01f : (float)(primShape.PathShearY - 256) * 0.01f; | 2087 | float pathShearY = primShape.PathShearY < 128 ? (float)primShape.PathShearY * 0.01f : (float)(primShape.PathShearY - 256) * 0.01f; |
1968 | float pathBegin = (float)primShape.PathBegin * 2.0e-5f; | 2088 | float pathBegin = (float)primShape.PathBegin * 2.0e-5f; |
1969 | float pathEnd = 1.0f - (float)primShape.PathEnd * 2.0e-5f; | 2089 | float pathEnd = 1.0f - (float)primShape.PathEnd * 2.0e-5f; |
2090 | float pathScaleX = (float)(primShape.PathScaleX - 100) * 0.01f; | ||
2091 | float pathScaleY = (float)(primShape.PathScaleY - 100) * 0.01f; | ||
1970 | 2092 | ||
1971 | float profileBegin = (float)primShape.ProfileBegin * 2.0e-5f; | 2093 | float profileBegin = (float)primShape.ProfileBegin * 2.0e-5f; |
1972 | float profileEnd = 1.0f - (float)primShape.ProfileEnd * 2.0e-5f; | 2094 | float profileEnd = 1.0f - (float)primShape.ProfileEnd * 2.0e-5f; |
2095 | float profileHollow = (float)primShape.ProfileHollow * 2.0e-5f; | ||
1973 | 2096 | ||
1974 | Console.WriteLine("********************* PrimitiveBaseShape Parameters *******************\n" | 2097 | Console.WriteLine("********************* PrimitiveBaseShape Parameters *******************\n" |
1975 | + "Name.............: " + name.ToString() + "\n" | 2098 | + "Name.............: " + name.ToString() + "\n" |
@@ -1979,8 +2102,8 @@ namespace OpenSim.Region.Physics.Meshing | |||
1979 | + "PathEnd..........: " + primShape.PathEnd.ToString() + " " + pathEnd.ToString() + "\n" | 2102 | + "PathEnd..........: " + primShape.PathEnd.ToString() + " " + pathEnd.ToString() + "\n" |
1980 | + "PathRadiusOffset.: " + primShape.PathRadiusOffset.ToString() + "\n" | 2103 | + "PathRadiusOffset.: " + primShape.PathRadiusOffset.ToString() + "\n" |
1981 | + "PathRevolutions..: " + primShape.PathRevolutions.ToString() + "\n" | 2104 | + "PathRevolutions..: " + primShape.PathRevolutions.ToString() + "\n" |
1982 | + "PathScaleX.......: " + primShape.PathScaleX.ToString() + "\n" | 2105 | + "PathScaleX.......: " + primShape.PathScaleX.ToString() + " " + pathScaleX.ToString() + "\n" |
1983 | + "PathScaleY.......: " + primShape.PathScaleY.ToString() + "\n" | 2106 | + "PathScaleY.......: " + primShape.PathScaleY.ToString() + " " + pathScaleY.ToString() + "\n" |
1984 | + "PathShearX.......: " + primShape.PathShearX.ToString() + " (" + pathShearX.ToString() + ")\n" | 2107 | + "PathShearX.......: " + primShape.PathShearX.ToString() + " (" + pathShearX.ToString() + ")\n" |
1985 | + "PathShearY.......: " + primShape.PathShearY.ToString() + " (" + pathShearY.ToString() + ")\n" | 2108 | + "PathShearY.......: " + primShape.PathShearY.ToString() + " (" + pathShearY.ToString() + ")\n" |
1986 | + "PathSkew.........: " + primShape.PathSkew.ToString() + "\n" | 2109 | + "PathSkew.........: " + primShape.PathSkew.ToString() + "\n" |
@@ -1991,7 +2114,7 @@ namespace OpenSim.Region.Physics.Meshing | |||
1991 | + "ProfileBegin.....: " + primShape.ProfileBegin.ToString() + " " + profileBegin.ToString() + "\n" | 2114 | + "ProfileBegin.....: " + primShape.ProfileBegin.ToString() + " " + profileBegin.ToString() + "\n" |
1992 | + "ProfileCurve.....: " + primShape.ProfileCurve.ToString() + "\n" | 2115 | + "ProfileCurve.....: " + primShape.ProfileCurve.ToString() + "\n" |
1993 | + "ProfileEnd.......: " + primShape.ProfileEnd.ToString() + " " + profileEnd.ToString() + "\n" | 2116 | + "ProfileEnd.......: " + primShape.ProfileEnd.ToString() + " " + profileEnd.ToString() + "\n" |
1994 | + "ProfileHollow....: " + primShape.ProfileHollow.ToString() + "\n" | 2117 | + "ProfileHollow....: " + primShape.ProfileHollow.ToString() + " " + profileHollow.ToString() + "\n" |
1995 | + "ProfileShape.....: " + primShape.ProfileShape.ToString() + "\n" | 2118 | + "ProfileShape.....: " + primShape.ProfileShape.ToString() + "\n" |
1996 | ); | 2119 | ); |
1997 | } | 2120 | } |