aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDahlia Trimble2008-10-29 09:47:45 +0000
committerDahlia Trimble2008-10-29 09:47:45 +0000
commit5cf6a7f118d4c0637ae508bc6ecedc9f36a02439 (patch)
treed8e17390e83ee0666402fee5677a5374e3acfc5f
parentMinor formatting cleanup. (diff)
downloadopensim-SC-5cf6a7f118d4c0637ae508bc6ecedc9f36a02439.zip
opensim-SC-5cf6a7f118d4c0637ae508bc6ecedc9f36a02439.tar.gz
opensim-SC-5cf6a7f118d4c0637ae508bc6ecedc9f36a02439.tar.bz2
opensim-SC-5cf6a7f118d4c0637ae508bc6ecedc9f36a02439.tar.xz
Viewer side normals and UV fixes on profile cuts. Sync with primmesher.dll forge project.
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Physics/Meshing/PrimMesher.cs108
1 files changed, 59 insertions, 49 deletions
diff --git a/OpenSim/Region/Physics/Meshing/PrimMesher.cs b/OpenSim/Region/Physics/Meshing/PrimMesher.cs
index 7245eea..741010d 100644
--- a/OpenSim/Region/Physics/Meshing/PrimMesher.cs
+++ b/OpenSim/Region/Physics/Meshing/PrimMesher.cs
@@ -336,8 +336,8 @@ namespace PrimMesher
336 public void CalcSurfaceNormal() 336 public void CalcSurfaceNormal()
337 { 337 {
338 338
339 Coord edge1 = new Coord(this.n2.X - this.n1.X, this.n2.Y - this.n1.Y, this.n2.Z - this.n1.Z); 339 Coord edge1 = new Coord(this.v2.X - this.v1.X, this.v2.Y - this.v1.Y, this.v2.Z - this.v1.Z);
340 Coord edge2 = new Coord(this.n3.X - this.n1.X, this.n3.Y - this.n1.Y, this.n3.Z - this.n1.Z); 340 Coord edge2 = new Coord(this.v3.X - this.v1.X, this.v3.Y - this.v1.Y, this.v3.Z - this.v1.Z);
341 341
342 this.n1 = this.n2 = this.n3 = Coord.Cross(edge1, edge2).Normalize(); 342 this.n1 = this.n2 = this.n3 = Coord.Cross(edge1, edge2).Normalize();
343 } 343 }
@@ -1213,7 +1213,7 @@ namespace PrimMesher
1213 1213
1214 1214
1215 Coord lastCutNormal1 = new Coord(); 1215 Coord lastCutNormal1 = new Coord();
1216 //Coord lastCutNormal2 = new Coord(); 1216 Coord lastCutNormal2 = new Coord();
1217 float lastV = 1.0f; 1217 float lastV = 1.0f;
1218 1218
1219 bool done = false; 1219 bool done = false;
@@ -1268,7 +1268,6 @@ namespace PrimMesher
1268 1268
1269 this.viewerFaces.Add(newViewerFace); 1269 this.viewerFaces.Add(newViewerFace);
1270 } 1270 }
1271
1272 } 1271 }
1273 } 1272 }
1274 1273
@@ -1330,12 +1329,13 @@ namespace PrimMesher
1330 float u2 = 1.0f; 1329 float u2 = 1.0f;
1331 if (whichVert < newLayer.us.Count - 1) 1330 if (whichVert < newLayer.us.Count - 1)
1332 u2 = newLayer.us[whichVert + 1]; 1331 u2 = newLayer.us[whichVert + 1];
1333 if (sides < 5 && whichVert < sides) 1332 int whichOuterVert = (hasProfileCut && hasHollow) ? whichVert - 1 : whichVert;
1333 if (sides < 5 && whichOuterVert < sides)
1334 { 1334 {
1335 u1 *= sides; 1335 u1 *= sides;
1336 u2 *= sides; 1336 u2 *= sides;
1337 u1 -= whichVert; 1337 u1 -= whichOuterVert;
1338 u2 -= whichVert; 1338 u2 -= whichOuterVert;
1339 if (u2 < 0.1f) 1339 if (u2 < 0.1f)
1340 u2 = 1.0f; 1340 u2 = 1.0f;
1341 1341
@@ -1372,8 +1372,9 @@ namespace PrimMesher
1372 newViewerFace2.v2 = this.coords[iNext - numVerts]; 1372 newViewerFace2.v2 = this.coords[iNext - numVerts];
1373 newViewerFace2.v3 = this.coords[iNext]; 1373 newViewerFace2.v3 = this.coords[iNext];
1374 1374
1375 // profile cut faces
1375 if (whichVert == cut1Vert) 1376 if (whichVert == cut1Vert)
1376 { // start profile cut faces 1377 {
1377 1378
1378 newViewerFace1.n2 = newViewerFace1.n1 = lastCutNormal1; 1379 newViewerFace1.n2 = newViewerFace1.n1 = lastCutNormal1;
1379 newViewerFace1.n3 = newLayer.cutNormal1; 1380 newViewerFace1.n3 = newLayer.cutNormal1;
@@ -1381,10 +1382,20 @@ namespace PrimMesher
1381 newViewerFace2.n3 = newViewerFace2.n1 = newLayer.cutNormal1; 1382 newViewerFace2.n3 = newViewerFace2.n1 = newLayer.cutNormal1;
1382 newViewerFace2.n2 = lastCutNormal1; 1383 newViewerFace2.n2 = lastCutNormal1;
1383 } 1384 }
1385 else if (whichVert == cut2Vert)
1386 {
1384 1387
1385 else // periphery faces 1388 newViewerFace1.n2 = newViewerFace1.n1 = lastCutNormal2;
1389 newViewerFace1.n3 = newLayer.cutNormal2;
1390
1391 newViewerFace2.n3 = newViewerFace2.n1 = newLayer.cutNormal2;
1392 newViewerFace2.n2 = lastCutNormal2;
1393 }
1394
1395 else // outer and hollow faces
1386 { 1396 {
1387 if ((sides < 5 && whichVert < newLayer.numOuterVerts) || (hollowSides < 5 && whichVert >= newLayer.numOuterVerts)) 1397 //if ((sides < 5 && whichVert < newLayer.numOuterVerts) || (hollowSides < 5 && whichVert >= newLayer.numOuterVerts))
1398 if (sides < 5)
1388 { 1399 {
1389 newViewerFace1.CalcSurfaceNormal(); 1400 newViewerFace1.CalcSurfaceNormal();
1390 newViewerFace2.CalcSurfaceNormal(); 1401 newViewerFace2.CalcSurfaceNormal();
@@ -1406,25 +1417,10 @@ namespace PrimMesher
1406 1417
1407 } 1418 }
1408 } 1419 }
1409
1410 if (this.hasProfileCut)
1411 { // add the end cut face to the list of viewerFaces here
1412 // the prior cut face was filled in the above loop
1413 newFace.v1 = coordsLen - 1;
1414 newFace.v2 = coordsLen - numVerts;
1415 newFace.v3 = coordsLen;
1416 this.faces.Add(newFace);
1417
1418 newFace.v1 = coordsLen + numVerts - 1;
1419 newFace.v2 = coordsLen - 1;
1420 newFace.v3 = coordsLen;
1421 this.faces.Add(newFace);
1422 }
1423
1424 } 1420 }
1425 1421
1426 lastCutNormal1 = newLayer.cutNormal1; 1422 lastCutNormal1 = newLayer.cutNormal1;
1427 //lastCutNormal2 = newLayer.cutNormal2; 1423 lastCutNormal2 = newLayer.cutNormal2;
1428 lastV = 1.0f - percentOfPath; 1424 lastV = 1.0f - percentOfPath;
1429 1425
1430 // calc the step for the next iteration of the loop 1426 // calc the step for the next iteration of the loop
@@ -1570,6 +1566,14 @@ namespace PrimMesher
1570 1566
1571 Profile profile = new Profile(this.sides, this.profileStart, this.profileEnd, hollow, this.hollowSides, needEndFaces, calcVertexNormals); 1567 Profile profile = new Profile(this.sides, this.profileStart, this.profileEnd, hollow, this.hollowSides, needEndFaces, calcVertexNormals);
1572 1568
1569 int cut1Vert = -1;
1570 int cut2Vert = -1;
1571 if (hasProfileCut)
1572 {
1573 cut1Vert = hasHollow ? profile.coords.Count - 1 : 0;
1574 cut2Vert = hasHollow ? profile.numOuterVerts - 1 : profile.numOuterVerts;
1575 }
1576
1573 if (initialProfileRot != 0.0f) 1577 if (initialProfileRot != 0.0f)
1574 { 1578 {
1575 profile.AddRot(new Quat(new Coord(0.0f, 0.0f, 1.0f), initialProfileRot)); 1579 profile.AddRot(new Quat(new Coord(0.0f, 0.0f, 1.0f), initialProfileRot));
@@ -1578,7 +1582,7 @@ namespace PrimMesher
1578 } 1582 }
1579 1583
1580 Coord lastCutNormal1 = new Coord(); 1584 Coord lastCutNormal1 = new Coord();
1581 //Coord lastCutNormal2 = new Coord(); 1585 Coord lastCutNormal2 = new Coord();
1582 float lastV = 1.0f; 1586 float lastV = 1.0f;
1583 1587
1584 bool done = false; 1588 bool done = false;
@@ -1631,7 +1635,6 @@ namespace PrimMesher
1631 1635
1632 // now orient the rotation of the profile layer relative to it's position on the path 1636 // now orient the rotation of the profile layer relative to it's position on the path
1633 // adding taperY to the angle used to generate the quat appears to approximate the viewer 1637 // adding taperY to the angle used to generate the quat appears to approximate the viewer
1634 //newLayer.AddRot(new Quaternion(new Vertex(1.0f, 0.0f, 0.0f), angle + this.topShearY * 0.9f));
1635 newLayer.AddRot(new Quat(new Coord(1.0f, 0.0f, 0.0f), angle + this.topShearY)); 1638 newLayer.AddRot(new Quat(new Coord(1.0f, 0.0f, 0.0f), angle + this.topShearY));
1636 newLayer.AddPos(xOffset, yOffset, zOffset); 1639 newLayer.AddPos(xOffset, yOffset, zOffset);
1637 1640
@@ -1661,7 +1664,6 @@ namespace PrimMesher
1661 1664
1662 this.viewerFaces.Add(newViewerFace); 1665 this.viewerFaces.Add(newViewerFace);
1663 } 1666 }
1664
1665 } 1667 }
1666 } 1668 }
1667 1669
@@ -1720,6 +1722,12 @@ namespace PrimMesher
1720 if (whichVert < newLayer.us.Count - 1) 1722 if (whichVert < newLayer.us.Count - 1)
1721 u2 = newLayer.us[whichVert + 1]; 1723 u2 = newLayer.us[whichVert + 1];
1722 1724
1725 if (whichVert == cut1Vert || whichVert == cut2Vert)
1726 {
1727 u1 = 0.0f;
1728 u2 = 1.0f;
1729 }
1730
1723 newViewerFace1.uv1.U = u1; 1731 newViewerFace1.uv1.U = u1;
1724 newViewerFace1.uv2.U = u1; 1732 newViewerFace1.uv2.U = u1;
1725 newViewerFace1.uv3.U = u2; 1733 newViewerFace1.uv3.U = u2;
@@ -1744,8 +1752,8 @@ namespace PrimMesher
1744 newViewerFace2.v2 = this.coords[iNext - numVerts]; 1752 newViewerFace2.v2 = this.coords[iNext - numVerts];
1745 newViewerFace2.v3 = this.coords[iNext]; 1753 newViewerFace2.v3 = this.coords[iNext];
1746 1754
1747 if (whichVert == newLayer.numOuterVerts - 1 && hasProfileCut) 1755 if (whichVert == cut1Vert)
1748 { // start profile cut faces 1756 {
1749 1757
1750 newViewerFace1.n2 = newViewerFace1.n1 = lastCutNormal1; 1758 newViewerFace1.n2 = newViewerFace1.n1 = lastCutNormal1;
1751 newViewerFace1.n3 = newLayer.cutNormal1; 1759 newViewerFace1.n3 = newLayer.cutNormal1;
@@ -1753,10 +1761,20 @@ namespace PrimMesher
1753 newViewerFace2.n3 = newViewerFace2.n1 = newLayer.cutNormal1; 1761 newViewerFace2.n3 = newViewerFace2.n1 = newLayer.cutNormal1;
1754 newViewerFace2.n2 = lastCutNormal1; 1762 newViewerFace2.n2 = lastCutNormal1;
1755 } 1763 }
1764 else if (whichVert == cut2Vert)
1765 {
1766
1767 newViewerFace1.n2 = newViewerFace1.n1 = lastCutNormal2;
1768 newViewerFace1.n3 = newLayer.cutNormal2;
1769
1770 newViewerFace2.n3 = newViewerFace2.n1 = newLayer.cutNormal2;
1771 newViewerFace2.n2 = lastCutNormal2;
1772 }
1756 1773
1757 else // periphery faces 1774 else // periphery faces
1758 { 1775 {
1759 if ((sides < 5 && whichVert < newLayer.numOuterVerts) || (hollowSides < 5 && whichVert >= newLayer.numOuterVerts)) 1776 //if ((sides < 5 && whichVert < newLayer.numOuterVerts) || (hollowSides < 5 && whichVert >= newLayer.numOuterVerts))
1777 if (sides < 5)
1760 { 1778 {
1761 newViewerFace1.CalcSurfaceNormal(); 1779 newViewerFace1.CalcSurfaceNormal();
1762 newViewerFace2.CalcSurfaceNormal(); 1780 newViewerFace2.CalcSurfaceNormal();
@@ -1781,7 +1799,7 @@ namespace PrimMesher
1781 } 1799 }
1782 1800
1783 lastCutNormal1 = newLayer.cutNormal1; 1801 lastCutNormal1 = newLayer.cutNormal1;
1784 //lastCutNormal2 = newLayer.cutNormal2; 1802 lastCutNormal2 = newLayer.cutNormal2;
1785 lastV = 1.0f - percentOfPath; 1803 lastV = 1.0f - percentOfPath;
1786 1804
1787 // calculate terms for next iteration 1805 // calculate terms for next iteration
@@ -1823,12 +1841,8 @@ namespace PrimMesher
1823 } 1841 }
1824 } 1842 }
1825 1843
1826 private Coord SurfaceNormal(Face face) 1844 private Coord SurfaceNormal(Coord c1, Coord c2, Coord c3)
1827 { 1845 {
1828 Coord c1 = coords[face.v1];
1829 Coord c2 = coords[face.v2];
1830 Coord c3 = coords[face.v3];
1831
1832 Coord edge1 = new Coord(c2.X - c1.X, c2.Y - c1.Y, c2.Z - c1.Z); 1846 Coord edge1 = new Coord(c2.X - c1.X, c2.Y - c1.Y, c2.Z - c1.Z);
1833 Coord edge2 = new Coord(c3.X - c1.X, c3.Y - c1.Y, c3.Z - c1.Z); 1847 Coord edge2 = new Coord(c3.X - c1.X, c3.Y - c1.Y, c3.Z - c1.Z);
1834 1848
@@ -1839,15 +1853,18 @@ namespace PrimMesher
1839 return normal; 1853 return normal;
1840 } 1854 }
1841 1855
1856 private Coord SurfaceNormal(Face face)
1857 {
1858 return SurfaceNormal(this.coords[face.v1], this.coords[face.v2], this.coords[face.v3]);
1859 }
1860
1842 public Coord SurfaceNormal(int faceIndex) 1861 public Coord SurfaceNormal(int faceIndex)
1843 { 1862 {
1844 int numFaces = faces.Count; 1863 int numFaces = this.faces.Count;
1845 if (faceIndex < 0 || faceIndex >= numFaces) 1864 if (faceIndex < 0 || faceIndex >= numFaces)
1846 throw new Exception("faceIndex out of range"); 1865 throw new Exception("faceIndex out of range");
1847 1866
1848 //return new Coord(0.0f, 0.0f, 0.0f); 1867 return SurfaceNormal(this.faces[faceIndex]);
1849
1850 return SurfaceNormal(faces[faceIndex]);
1851 } 1868 }
1852 1869
1853 public void CalcNormals() 1870 public void CalcNormals()
@@ -1938,13 +1955,6 @@ namespace PrimMesher
1938 Coord m = new Coord(x, y, z); 1955 Coord m = new Coord(x, y, z);
1939 for (i = 0; i < numVerts; i++) 1956 for (i = 0; i < numVerts; i++)
1940 this.coords[i] *= m; 1957 this.coords[i] *= m;
1941 //{
1942 // vert = this.coords[i];
1943 // vert.X *= x;
1944 // vert.Y *= y;
1945 // vert.Z *= z;
1946 // this.coords[i] = vert;
1947 //}
1948 1958
1949 if (this.viewerFaces != null) 1959 if (this.viewerFaces != null)
1950 { 1960 {