diff options
Diffstat (limited to 'OpenSim/Region/Physics/Meshing')
-rw-r--r-- | OpenSim/Region/Physics/Meshing/Meshmerizer.cs | 138 |
1 files changed, 30 insertions, 108 deletions
diff --git a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs index 8a43fa5..311db79 100644 --- a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs +++ b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs | |||
@@ -69,36 +69,35 @@ namespace OpenSim.Region.Physics.Meshing | |||
69 | 69 | ||
70 | private float minSizeForComplexMesh = 0.2f; // prims with all dimensions smaller than this will have a bounding box mesh | 70 | private float minSizeForComplexMesh = 0.2f; // prims with all dimensions smaller than this will have a bounding box mesh |
71 | 71 | ||
72 | // TODO: unused | 72 | private static void IntersectionParameterPD(PhysicsVector p1, PhysicsVector r1, PhysicsVector p2, |
73 | // private static void IntersectionParameterPD(PhysicsVector p1, PhysicsVector r1, PhysicsVector p2, | 73 | PhysicsVector r2, ref float lambda, ref float mu) |
74 | // PhysicsVector r2, ref float lambda, ref float mu) | 74 | { |
75 | // { | 75 | // p1, p2, points on the straight |
76 | // // p1, p2, points on the straight | 76 | // r1, r2, directional vectors of the straight. Not necessarily of length 1! |
77 | // // r1, r2, directional vectors of the straight. Not necessarily of length 1! | 77 | // note, that l, m can be scaled such, that the range 0..1 is mapped to the area between two points, |
78 | // // note, that l, m can be scaled such, that the range 0..1 is mapped to the area between two points, | 78 | // thus allowing to decide whether an intersection is between two points |
79 | // // thus allowing to decide whether an intersection is between two points | 79 | |
80 | 80 | float r1x = r1.X; | |
81 | // float r1x = r1.X; | 81 | float r1y = r1.Y; |
82 | // float r1y = r1.Y; | 82 | float r2x = r2.X; |
83 | // float r2x = r2.X; | 83 | float r2y = r2.Y; |
84 | // float r2y = r2.Y; | 84 | |
85 | 85 | float denom = r1y * r2x - r1x * r2y; | |
86 | // float denom = r1y*r2x - r1x*r2y; | 86 | |
87 | 87 | if (denom == 0.0) | |
88 | // if (denom == 0.0) | 88 | { |
89 | // { | 89 | lambda = Single.NaN; |
90 | // lambda = Single.NaN; | 90 | mu = Single.NaN; |
91 | // mu = Single.NaN; | 91 | return; |
92 | // return; | 92 | } |
93 | // } | 93 | |
94 | 94 | float p1x = p1.X; | |
95 | // float p1x = p1.X; | 95 | float p1y = p1.Y; |
96 | // float p1y = p1.Y; | 96 | float p2x = p2.X; |
97 | // float p2x = p2.X; | 97 | float p2y = p2.Y; |
98 | // float p2y = p2.Y; | 98 | lambda = (-p2x * r2y + p1x * r2y + (p2y - p1y) * r2x) / denom; |
99 | // lambda = (-p2x*r2y + p1x*r2y + (p2y - p1y)*r2x)/denom; | 99 | mu = (-p2x * r1y + p1x * r1y + (p2y - p1y) * r1x) / denom; |
100 | // mu = (-p2x*r1y + p1x*r1y + (p2y - p1y)*r1x)/denom; | 100 | } |
101 | // } | ||
102 | 101 | ||
103 | private static List<Triangle> FindInfluencedTriangles(List<Triangle> triangles, Vertex v) | 102 | private static List<Triangle> FindInfluencedTriangles(List<Triangle> triangles, Vertex v) |
104 | { | 103 | { |
@@ -432,18 +431,11 @@ namespace OpenSim.Region.Physics.Meshing | |||
432 | UInt16 taperY = primShape.PathScaleY; | 431 | UInt16 taperY = primShape.PathScaleY; |
433 | UInt16 pathShearX = primShape.PathShearX; | 432 | UInt16 pathShearX = primShape.PathShearX; |
434 | UInt16 pathShearY = primShape.PathShearY; | 433 | UInt16 pathShearY = primShape.PathShearY; |
435 | // Int16 twistTop = primShape.PathTwistBegin; | ||
436 | // Int16 twistBot = primShape.PathTwist; | ||
437 | 434 | ||
438 | #if SPAM | 435 | #if SPAM |
439 | reportPrimParams("[BOX] " + primName, primShape); | 436 | reportPrimParams("[BOX] " + primName, primShape); |
440 | #endif | 437 | #endif |
441 | 438 | ||
442 | //m_log.Error("pathShear:" + primShape.PathShearX.ToString() + "," + primShape.PathShearY.ToString()); | ||
443 | //m_log.Error("pathTaper:" + primShape.PathTaperX.ToString() + "," + primShape.PathTaperY.ToString()); | ||
444 | //m_log.Error("ProfileBegin:" + primShape.ProfileBegin.ToString() + "," + primShape.ProfileBegin.ToString()); | ||
445 | //m_log.Error("PathScale:" + primShape.PathScaleX.ToString() + "," + primShape.PathScaleY.ToString()); | ||
446 | |||
447 | // Procedure: This is based on the fact that the upper (plus) and lower (minus) Z-surface | 439 | // Procedure: This is based on the fact that the upper (plus) and lower (minus) Z-surface |
448 | // of a block are basically the same | 440 | // of a block are basically the same |
449 | // They may be warped differently but the shape is identical | 441 | // They may be warped differently but the shape is identical |
@@ -575,12 +567,10 @@ namespace OpenSim.Region.Physics.Meshing | |||
575 | if (taperX > 100) | 567 | if (taperX > 100) |
576 | { | 568 | { |
577 | extr.taperTopFactorX = 1.0f - ((float)(taperX - 100) / 100); | 569 | extr.taperTopFactorX = 1.0f - ((float)(taperX - 100) / 100); |
578 | //System.Console.WriteLine("taperTopFactorX: " + extr.taperTopFactorX.ToString()); | ||
579 | } | 570 | } |
580 | else | 571 | else |
581 | { | 572 | { |
582 | extr.taperBotFactorX = 1.0f - ((100 - (float)taperX) / 100); | 573 | extr.taperBotFactorX = 1.0f - ((100 - (float)taperX) / 100); |
583 | //System.Console.WriteLine("taperBotFactorX: " + extr.taperBotFactorX.ToString()); | ||
584 | } | 574 | } |
585 | 575 | ||
586 | } | 576 | } |
@@ -590,12 +580,10 @@ namespace OpenSim.Region.Physics.Meshing | |||
590 | if (taperY > 100) | 580 | if (taperY > 100) |
591 | { | 581 | { |
592 | extr.taperTopFactorY = 1.0f - ((float)(taperY - 100) / 100); | 582 | extr.taperTopFactorY = 1.0f - ((float)(taperY - 100) / 100); |
593 | //System.Console.WriteLine("taperTopFactorY: " + extr.taperTopFactorY.ToString()); | ||
594 | } | 583 | } |
595 | else | 584 | else |
596 | { | 585 | { |
597 | extr.taperBotFactorY = 1.0f - ((100 - (float)taperY) / 100); | 586 | extr.taperBotFactorY = 1.0f - ((100 - (float)taperY) / 100); |
598 | //System.Console.WriteLine("taperBotFactorY: " + extr.taperBotFactorY.ToString()); | ||
599 | } | 587 | } |
600 | } | 588 | } |
601 | 589 | ||
@@ -1595,63 +1583,6 @@ namespace OpenSim.Region.Physics.Meshing | |||
1595 | return result; | 1583 | return result; |
1596 | } | 1584 | } |
1597 | 1585 | ||
1598 | public static void CalcNormals(Mesh mesh) | ||
1599 | { | ||
1600 | int iTriangles = mesh.triangles.Count; | ||
1601 | |||
1602 | mesh.normals = new float[iTriangles * 3]; | ||
1603 | |||
1604 | int i = 0; | ||
1605 | foreach (Triangle t in mesh.triangles) | ||
1606 | { | ||
1607 | float ux, uy, uz; | ||
1608 | float vx, vy, vz; | ||
1609 | float wx, wy, wz; | ||
1610 | |||
1611 | ux = t.v1.X; | ||
1612 | uy = t.v1.Y; | ||
1613 | uz = t.v1.Z; | ||
1614 | |||
1615 | vx = t.v2.X; | ||
1616 | vy = t.v2.Y; | ||
1617 | vz = t.v2.Z; | ||
1618 | |||
1619 | wx = t.v3.X; | ||
1620 | wy = t.v3.Y; | ||
1621 | wz = t.v3.Z; | ||
1622 | |||
1623 | |||
1624 | // Vectors for edges | ||
1625 | float e1x, e1y, e1z; | ||
1626 | float e2x, e2y, e2z; | ||
1627 | |||
1628 | e1x = ux - vx; | ||
1629 | e1y = uy - vy; | ||
1630 | e1z = uz - vz; | ||
1631 | |||
1632 | e2x = ux - wx; | ||
1633 | e2y = uy - wy; | ||
1634 | e2z = uz - wz; | ||
1635 | |||
1636 | |||
1637 | // Cross product for normal | ||
1638 | float nx, ny, nz; | ||
1639 | nx = e1y * e2z - e1z * e2y; | ||
1640 | ny = e1z * e2x - e1x * e2z; | ||
1641 | nz = e1x * e2y - e1y * e2x; | ||
1642 | |||
1643 | // Length | ||
1644 | float l = (float)Math.Sqrt(nx * nx + ny * ny + nz * nz); | ||
1645 | |||
1646 | // Normalized "normal" | ||
1647 | nx /= l; | ||
1648 | ny /= l; | ||
1649 | nz /= l; | ||
1650 | |||
1651 | i += 3; | ||
1652 | } | ||
1653 | } | ||
1654 | |||
1655 | public static Vertex midUnitRadialPoint(Vertex a, Vertex b, float radius) | 1586 | public static Vertex midUnitRadialPoint(Vertex a, Vertex b, float radius) |
1656 | { | 1587 | { |
1657 | Vertex midpoint = new Vertex(a + b) * 0.5f; | 1588 | Vertex midpoint = new Vertex(a + b) * 0.5f; |
@@ -1853,7 +1784,6 @@ namespace OpenSim.Region.Physics.Meshing | |||
1853 | { | 1784 | { |
1854 | SculptMesh smesh = CreateSculptMesh(primName, primShape, size, lod); | 1785 | SculptMesh smesh = CreateSculptMesh(primName, primShape, size, lod); |
1855 | mesh = (Mesh)smesh; | 1786 | mesh = (Mesh)smesh; |
1856 | //CalcNormals(mesh); | ||
1857 | } | 1787 | } |
1858 | 1788 | ||
1859 | else if (usePrimMesher) | 1789 | else if (usePrimMesher) |
@@ -1866,14 +1796,12 @@ namespace OpenSim.Region.Physics.Meshing | |||
1866 | { // its a box | 1796 | { // its a box |
1867 | mesh = CreateBoxMesh(primName, primShape, size); | 1797 | mesh = CreateBoxMesh(primName, primShape, size); |
1868 | //mesh = CreateMeshFromPrimMesher(primName, primShape, size, lod); | 1798 | //mesh = CreateMeshFromPrimMesher(primName, primShape, size, lod); |
1869 | //CalcNormals(mesh); | ||
1870 | } | 1799 | } |
1871 | else if (primShape.PathCurve == (byte)Extrusion.Curve1) | 1800 | else if (primShape.PathCurve == (byte)Extrusion.Curve1) |
1872 | { // tube | 1801 | { // tube |
1873 | // do a cylinder for now | 1802 | // do a cylinder for now |
1874 | mesh = CreateCylinderMesh(primName, primShape, size); | 1803 | mesh = CreateCylinderMesh(primName, primShape, size); |
1875 | //mesh = CreateMeshFromPrimMesher(primName, primShape, size, lod); | 1804 | //mesh = CreateMeshFromPrimMesher(primName, primShape, size, lod); |
1876 | //CalcNormals(mesh); | ||
1877 | } | 1805 | } |
1878 | } | 1806 | } |
1879 | else if ((primShape.ProfileCurve & 0x07) == (byte)ProfileShape.Circle) | 1807 | else if ((primShape.ProfileCurve & 0x07) == (byte)ProfileShape.Circle) |
@@ -1882,15 +1810,13 @@ namespace OpenSim.Region.Physics.Meshing | |||
1882 | { | 1810 | { |
1883 | mesh = CreateCylinderMesh(primName, primShape, size); | 1811 | mesh = CreateCylinderMesh(primName, primShape, size); |
1884 | //mesh = CreateMeshFromPrimMesher(primName, primShape, size, lod); | 1812 | //mesh = CreateMeshFromPrimMesher(primName, primShape, size, lod); |
1885 | //CalcNormals(mesh); | ||
1886 | } | 1813 | } |
1887 | 1814 | ||
1888 | // ProfileCurve seems to combine hole shape and profile curve so we need to only compare against the lower 3 bits | 1815 | // ProfileCurve seems to combine hole shape and profile curve so we need to only compare against the lower 3 bits |
1889 | else if (primShape.PathCurve == (byte) Extrusion.Curve1) | 1816 | else if (primShape.PathCurve == (byte) Extrusion.Curve1) |
1890 | { // dahlia's favorite, a torus :) | 1817 | { // dahlia's favorite, a torus :) |
1891 | mesh = CreateCircularPathMesh(primName, primShape, size); | 1818 | mesh = CreateCircularPathMesh(primName, primShape, size); |
1892 | //mesh = CreateMeshFromPrimMesher(primName, primShape, size, lod); | 1819 | //mesh = CreateMeshFromPrimMesher(primName, primShape, size, lod);\ |
1893 | //CalcNormals(mesh); | ||
1894 | } | 1820 | } |
1895 | } | 1821 | } |
1896 | else if ((primShape.ProfileCurve & 0x07) == (byte)ProfileShape.HalfCircle) | 1822 | else if ((primShape.ProfileCurve & 0x07) == (byte)ProfileShape.HalfCircle) |
@@ -1900,7 +1826,6 @@ namespace OpenSim.Region.Physics.Meshing | |||
1900 | //mesh = CreateSphereMesh(primName, primShape, size); | 1826 | //mesh = CreateSphereMesh(primName, primShape, size); |
1901 | mesh = CreateCircularPathMesh(primName, primShape, size); | 1827 | mesh = CreateCircularPathMesh(primName, primShape, size); |
1902 | //mesh = CreateMeshFromPrimMesher(primName, primShape, size, lod); | 1828 | //mesh = CreateMeshFromPrimMesher(primName, primShape, size, lod); |
1903 | //CalcNormals(mesh); | ||
1904 | } | 1829 | } |
1905 | } | 1830 | } |
1906 | else if ((primShape.ProfileCurve & 0x07) == (byte)ProfileShape.EquilateralTriangle) | 1831 | else if ((primShape.ProfileCurve & 0x07) == (byte)ProfileShape.EquilateralTriangle) |
@@ -1909,20 +1834,17 @@ namespace OpenSim.Region.Physics.Meshing | |||
1909 | { | 1834 | { |
1910 | mesh = CreatePrismMesh(primName, primShape, size); | 1835 | mesh = CreatePrismMesh(primName, primShape, size); |
1911 | //mesh = CreateMeshFromPrimMesher(primName, primShape, size, lod); | 1836 | //mesh = CreateMeshFromPrimMesher(primName, primShape, size, lod); |
1912 | //CalcNormals(mesh); | ||
1913 | } | 1837 | } |
1914 | else if (primShape.PathCurve == (byte) Extrusion.Curve1) | 1838 | else if (primShape.PathCurve == (byte) Extrusion.Curve1) |
1915 | { // a ring - do a cylinder for now | 1839 | { // a ring - do a cylinder for now |
1916 | //mesh = CreateCylinderMesh(primName, primShape, size); | 1840 | //mesh = CreateCylinderMesh(primName, primShape, size); |
1917 | mesh = CreateCircularPathMesh(primName, primShape, size); | 1841 | mesh = CreateCircularPathMesh(primName, primShape, size); |
1918 | //mesh = CreateMeshFromPrimMesher(primName, primShape, size, lod); | 1842 | //mesh = CreateMeshFromPrimMesher(primName, primShape, size, lod); |
1919 | //CalcNormals(mesh); | ||
1920 | } | 1843 | } |
1921 | } | 1844 | } |
1922 | else // just do a box | 1845 | else // just do a box |
1923 | { | 1846 | { |
1924 | mesh = CreateBoxMesh(primName, primShape, size); | 1847 | mesh = CreateBoxMesh(primName, primShape, size); |
1925 | //CalcNormals(mesh); | ||
1926 | } | 1848 | } |
1927 | 1849 | ||
1928 | if (mesh != null) | 1850 | if (mesh != null) |