diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Physics/Meshing/PrimMesher.cs | 346 |
1 files changed, 328 insertions, 18 deletions
diff --git a/OpenSim/Region/Physics/Meshing/PrimMesher.cs b/OpenSim/Region/Physics/Meshing/PrimMesher.cs index b36b5a8..527bf88 100644 --- a/OpenSim/Region/Physics/Meshing/PrimMesher.cs +++ b/OpenSim/Region/Physics/Meshing/PrimMesher.cs | |||
@@ -523,6 +523,9 @@ namespace PrimMesher | |||
523 | internal List<Coord> coords; | 523 | internal List<Coord> coords; |
524 | internal List<Face> faces; | 524 | internal List<Face> faces; |
525 | internal List<Coord> vertexNormals; | 525 | internal List<Coord> vertexNormals; |
526 | internal List<float> us; | ||
527 | internal List<UVCoord> faceUVs; | ||
528 | |||
526 | internal Coord faceNormal = new Coord(0.0f, 0.0f, 1.0f); | 529 | internal Coord faceNormal = new Coord(0.0f, 0.0f, 1.0f); |
527 | internal Coord cutNormal1 = new Coord(); | 530 | internal Coord cutNormal1 = new Coord(); |
528 | internal Coord cutNormal2 = new Coord(); | 531 | internal Coord cutNormal2 = new Coord(); |
@@ -537,6 +540,8 @@ namespace PrimMesher | |||
537 | this.coords = new List<Coord>(); | 540 | this.coords = new List<Coord>(); |
538 | this.faces = new List<Face>(); | 541 | this.faces = new List<Face>(); |
539 | this.vertexNormals = new List<Coord>(); | 542 | this.vertexNormals = new List<Coord>(); |
543 | this.us = new List<float>(); | ||
544 | this.faceUVs = new List<UVCoord>(); | ||
540 | } | 545 | } |
541 | 546 | ||
542 | public Profile(int sides, float profileStart, float profileEnd, float hollow, int hollowSides, bool createFaces, bool calcVertexNormals) | 547 | public Profile(int sides, float profileStart, float profileEnd, float hollow, int hollowSides, bool createFaces, bool calcVertexNormals) |
@@ -545,10 +550,13 @@ namespace PrimMesher | |||
545 | this.coords = new List<Coord>(); | 550 | this.coords = new List<Coord>(); |
546 | this.faces = new List<Face>(); | 551 | this.faces = new List<Face>(); |
547 | this.vertexNormals = new List<Coord>(); | 552 | this.vertexNormals = new List<Coord>(); |
553 | this.us = new List<float>(); | ||
554 | this.faceUVs = new List<UVCoord>(); | ||
548 | Coord center = new Coord(0.0f, 0.0f, 0.0f); | 555 | Coord center = new Coord(0.0f, 0.0f, 0.0f); |
549 | 556 | ||
550 | List<Coord> hollowCoords = new List<Coord>(); | 557 | List<Coord> hollowCoords = new List<Coord>(); |
551 | List<Coord> hollowNormals = new List<Coord>(); | 558 | List<Coord> hollowNormals = new List<Coord>(); |
559 | List<float> hollowUs = new List<float>(); | ||
552 | 560 | ||
553 | //Quat rot180 = new Quat(new Coord(0.0f, 0.0f, 1.0f), (float)Math.PI); ; | 561 | //Quat rot180 = new Quat(new Coord(0.0f, 0.0f, 1.0f), (float)Math.PI); ; |
554 | bool hasHollow = (hollow > 0.0f); | 562 | bool hasHollow = (hollow > 0.0f); |
@@ -627,6 +635,7 @@ namespace PrimMesher | |||
627 | //hollowNormal *= rot180; | 635 | //hollowNormal *= rot180; |
628 | //hollowNormals.Add(hollowNormal); | 636 | //hollowNormals.Add(hollowNormal); |
629 | hollowNormals.Add(new Coord(-angle.X, -angle.Y, 0.0f)); | 637 | hollowNormals.Add(new Coord(-angle.X, -angle.Y, 0.0f)); |
638 | hollowUs.Add(angle.angle); | ||
630 | } | 639 | } |
631 | } | 640 | } |
632 | } | 641 | } |
@@ -634,6 +643,8 @@ namespace PrimMesher | |||
634 | int index = 0; | 643 | int index = 0; |
635 | int numAngles = angles.angles.Count; | 644 | int numAngles = angles.angles.Count; |
636 | 645 | ||
646 | //float sideIncrement = 1.0f / (float)sides; | ||
647 | |||
637 | for (int i = 0; i < numAngles; i++) | 648 | for (int i = 0; i < numAngles; i++) |
638 | { | 649 | { |
639 | angle = angles.angles[i]; | 650 | angle = angles.angles[i]; |
@@ -642,7 +653,18 @@ namespace PrimMesher | |||
642 | newVert.Z = z; | 653 | newVert.Z = z; |
643 | this.coords.Add(newVert); | 654 | this.coords.Add(newVert); |
644 | if (this.calcVertexNormals) | 655 | if (this.calcVertexNormals) |
656 | { | ||
645 | this.vertexNormals.Add(new Coord(angle.X, angle.Y, 0.0f)); | 657 | this.vertexNormals.Add(new Coord(angle.X, angle.Y, 0.0f)); |
658 | if (sides < 5) | ||
659 | { | ||
660 | float u = angle.angle; | ||
661 | //u %= sideIncrement; | ||
662 | //u *= sides; | ||
663 | this.us.Add(u); | ||
664 | } | ||
665 | else | ||
666 | this.us.Add(angle.angle); | ||
667 | } | ||
646 | 668 | ||
647 | if (hollow > 0.0f) | 669 | if (hollow > 0.0f) |
648 | { | 670 | { |
@@ -658,6 +680,7 @@ namespace PrimMesher | |||
658 | //hollowNormal *= rot180; | 680 | //hollowNormal *= rot180; |
659 | //hollowNormals.Add(hollowNormal); | 681 | //hollowNormals.Add(hollowNormal); |
660 | hollowNormals.Add(new Coord(-angle.X, -angle.Y, 0.0f)); | 682 | hollowNormals.Add(new Coord(-angle.X, -angle.Y, 0.0f)); |
683 | hollowUs.Add(angle.angle); | ||
661 | } | 684 | } |
662 | } | 685 | } |
663 | } | 686 | } |
@@ -677,7 +700,10 @@ namespace PrimMesher | |||
677 | { | 700 | { |
678 | hollowCoords.Reverse(); | 701 | hollowCoords.Reverse(); |
679 | if (this.calcVertexNormals) | 702 | if (this.calcVertexNormals) |
703 | { | ||
680 | hollowNormals.Reverse(); | 704 | hollowNormals.Reverse(); |
705 | hollowUs.Reverse(); | ||
706 | } | ||
681 | 707 | ||
682 | if (createFaces) | 708 | if (createFaces) |
683 | { | 709 | { |
@@ -759,7 +785,11 @@ namespace PrimMesher | |||
759 | 785 | ||
760 | this.coords.AddRange(hollowCoords); | 786 | this.coords.AddRange(hollowCoords); |
761 | if (this.calcVertexNormals) | 787 | if (this.calcVertexNormals) |
788 | { | ||
762 | this.vertexNormals.AddRange(hollowNormals); | 789 | this.vertexNormals.AddRange(hollowNormals); |
790 | this.us.AddRange(hollowUs); | ||
791 | |||
792 | } | ||
763 | } | 793 | } |
764 | 794 | ||
765 | if (simpleFace && createFaces) | 795 | if (simpleFace && createFaces) |
@@ -797,9 +827,19 @@ namespace PrimMesher | |||
797 | this.cutNormal2.Normalize(); | 827 | this.cutNormal2.Normalize(); |
798 | } | 828 | } |
799 | 829 | ||
830 | this.MakeFaceUVs(); | ||
831 | |||
800 | hollowCoords = null; | 832 | hollowCoords = null; |
801 | hollowNormals = null; | 833 | hollowNormals = null; |
834 | hollowUs = null; | ||
835 | |||
836 | } | ||
802 | 837 | ||
838 | public void MakeFaceUVs() | ||
839 | { | ||
840 | this.faceUVs = new List<UVCoord>(); | ||
841 | foreach (Coord c in this.coords) | ||
842 | this.faceUVs.Add(new UVCoord(0.5f + c.X, 0.5f - c.Y)); | ||
803 | } | 843 | } |
804 | 844 | ||
805 | public Profile Clone() | 845 | public Profile Clone() |
@@ -812,6 +852,8 @@ namespace PrimMesher | |||
812 | Profile clone = new Profile(); | 852 | Profile clone = new Profile(); |
813 | 853 | ||
814 | clone.coords.AddRange(this.coords); | 854 | clone.coords.AddRange(this.coords); |
855 | clone.faceUVs.AddRange(this.faceUVs); | ||
856 | |||
815 | if (needFaces) | 857 | if (needFaces) |
816 | clone.faces.AddRange(this.faces); | 858 | clone.faces.AddRange(this.faces); |
817 | if ((clone.calcVertexNormals = this.calcVertexNormals) == true) | 859 | if ((clone.calcVertexNormals = this.calcVertexNormals) == true) |
@@ -820,6 +862,7 @@ namespace PrimMesher | |||
820 | clone.faceNormal = this.faceNormal; | 862 | clone.faceNormal = this.faceNormal; |
821 | clone.cutNormal1 = this.cutNormal1; | 863 | clone.cutNormal1 = this.cutNormal1; |
822 | clone.cutNormal2 = this.cutNormal2; | 864 | clone.cutNormal2 = this.cutNormal2; |
865 | clone.us.AddRange(this.us); | ||
823 | } | 866 | } |
824 | clone.numOuterVerts = this.numOuterVerts; | 867 | clone.numOuterVerts = this.numOuterVerts; |
825 | clone.numHollowVerts = this.numHollowVerts; | 868 | clone.numHollowVerts = this.numHollowVerts; |
@@ -933,6 +976,19 @@ namespace PrimMesher | |||
933 | this.faceNormal.X = -this.faceNormal.X; | 976 | this.faceNormal.X = -this.faceNormal.X; |
934 | this.faceNormal.Y = -this.faceNormal.Y; | 977 | this.faceNormal.Y = -this.faceNormal.Y; |
935 | this.faceNormal.Z = -this.faceNormal.Z; | 978 | this.faceNormal.Z = -this.faceNormal.Z; |
979 | |||
980 | int numUs = this.us.Count; | ||
981 | //for (int i = 0; i < numUs; i++) | ||
982 | // this.us[i] | ||
983 | |||
984 | int numfaceUVs = this.faceUVs.Count; | ||
985 | for (i = 0; i < numfaceUVs; i++) | ||
986 | { | ||
987 | UVCoord uv = this.faceUVs[i]; | ||
988 | uv.U = 1.0f - uv.U; | ||
989 | //uv.V = 1.0f - uv.V; | ||
990 | this.faceUVs[i] = uv; | ||
991 | } | ||
936 | } | 992 | } |
937 | 993 | ||
938 | public void AddValue2FaceVertexIndices(int num) | 994 | public void AddValue2FaceVertexIndices(int num) |
@@ -1162,10 +1218,16 @@ namespace PrimMesher | |||
1162 | Profile profile = new Profile(this.sides, this.profileStart, this.profileEnd, hollow, this.hollowSides, true, calcVertexNormals); | 1218 | Profile profile = new Profile(this.sides, this.profileStart, this.profileEnd, hollow, this.hollowSides, true, calcVertexNormals); |
1163 | 1219 | ||
1164 | if (initialProfileRot != 0.0f) | 1220 | if (initialProfileRot != 0.0f) |
1221 | { | ||
1165 | profile.AddRot(new Quat(new Coord(0.0f, 0.0f, 1.0f), initialProfileRot)); | 1222 | profile.AddRot(new Quat(new Coord(0.0f, 0.0f, 1.0f), initialProfileRot)); |
1223 | if (viewerMode) | ||
1224 | profile.MakeFaceUVs(); | ||
1225 | } | ||
1226 | |||
1166 | 1227 | ||
1167 | Coord lastCutNormal1 = new Coord(); | 1228 | Coord lastCutNormal1 = new Coord(); |
1168 | Coord lastCutNormal2 = new Coord(); | 1229 | Coord lastCutNormal2 = new Coord(); |
1230 | float lastV = 1.0f; | ||
1169 | 1231 | ||
1170 | bool done = false; | 1232 | bool done = false; |
1171 | while (!done) | 1233 | while (!done) |
@@ -1213,6 +1275,10 @@ namespace PrimMesher | |||
1213 | newViewerFace.n2 = faceNormal; | 1275 | newViewerFace.n2 = faceNormal; |
1214 | newViewerFace.n3 = faceNormal; | 1276 | newViewerFace.n3 = faceNormal; |
1215 | 1277 | ||
1278 | newViewerFace.uv1 = newLayer.faceUVs[face.v1]; | ||
1279 | newViewerFace.uv2 = newLayer.faceUVs[face.v2]; | ||
1280 | newViewerFace.uv3 = newLayer.faceUVs[face.v3]; | ||
1281 | |||
1216 | this.viewerFaces.Add(newViewerFace); | 1282 | this.viewerFaces.Add(newViewerFace); |
1217 | } | 1283 | } |
1218 | 1284 | ||
@@ -1264,8 +1330,44 @@ namespace PrimMesher | |||
1264 | if (this.viewerMode) | 1330 | if (this.viewerMode) |
1265 | { | 1331 | { |
1266 | // add the side faces to the list of viewerFaces here | 1332 | // add the side faces to the list of viewerFaces here |
1267 | ViewerFace newViewerFace1 = new ViewerFace(); | 1333 | int primFaceNum = 1; |
1268 | ViewerFace newViewerFace2 = new ViewerFace(); | 1334 | if (whichVert >= sides) |
1335 | primFaceNum = 2; | ||
1336 | ViewerFace newViewerFace1 = new ViewerFace(primFaceNum); | ||
1337 | ViewerFace newViewerFace2 = new ViewerFace(primFaceNum); | ||
1338 | float u1 = newLayer.us[whichVert]; | ||
1339 | float u2 = 1.0f; | ||
1340 | if (whichVert < newLayer.us.Count - 1) | ||
1341 | u2 = newLayer.us[whichVert + 1]; | ||
1342 | if (sides < 5 && whichVert < sides) | ||
1343 | { | ||
1344 | u1 *= sides; | ||
1345 | u2 *= sides; | ||
1346 | u1 -= whichVert; | ||
1347 | u2 -= whichVert; | ||
1348 | if (u2 < 0.1f) | ||
1349 | u2 = 1.0f; | ||
1350 | //u1 = 0.0f; | ||
1351 | //u2 = 1.0f; | ||
1352 | |||
1353 | newViewerFace2.primFaceNumber = newViewerFace1.primFaceNumber = whichVert + 1; | ||
1354 | } | ||
1355 | |||
1356 | newViewerFace1.uv1.U = u1; | ||
1357 | newViewerFace1.uv2.U = u1; | ||
1358 | newViewerFace1.uv3.U = u2; | ||
1359 | |||
1360 | newViewerFace1.uv1.V = 1.0f - percentOfPath; | ||
1361 | newViewerFace1.uv2.V = lastV; | ||
1362 | newViewerFace1.uv3.V = lastV; | ||
1363 | |||
1364 | newViewerFace2.uv1.U = u1; | ||
1365 | newViewerFace2.uv2.U = u2; | ||
1366 | newViewerFace2.uv3.U = u2; | ||
1367 | |||
1368 | newViewerFace2.uv1.V = 1.0f - percentOfPath; | ||
1369 | newViewerFace2.uv2.V = lastV; | ||
1370 | newViewerFace2.uv3.V = 1.0f - percentOfPath; | ||
1269 | 1371 | ||
1270 | newViewerFace1.v1 = this.coords[i]; | 1372 | newViewerFace1.v1 = this.coords[i]; |
1271 | newViewerFace1.v2 = this.coords[i - numVerts]; | 1373 | newViewerFace1.v2 = this.coords[i - numVerts]; |
@@ -1330,9 +1432,18 @@ namespace PrimMesher | |||
1330 | newViewerFace.v2 = this.coords[coordsLen - numVerts]; // first vert in prior layer | 1432 | newViewerFace.v2 = this.coords[coordsLen - numVerts]; // first vert in prior layer |
1331 | newViewerFace.v3 = this.coords[coordsLen]; // first vert in new layer | 1433 | newViewerFace.v3 = this.coords[coordsLen]; // first vert in new layer |
1332 | 1434 | ||
1435 | float u1 = newLayer.us[0]; | ||
1436 | float u2 = newLayer.us[newLayer.us.Count - 1]; | ||
1437 | |||
1333 | newViewerFace.n2 = newViewerFace.n1 = lastCutNormal2; | 1438 | newViewerFace.n2 = newViewerFace.n1 = lastCutNormal2; |
1334 | newViewerFace.n3 = newLayer.cutNormal2; | 1439 | newViewerFace.n3 = newLayer.cutNormal2; |
1335 | 1440 | ||
1441 | newViewerFace.uv3.U = newViewerFace.uv1.U = u2; | ||
1442 | newViewerFace.uv2.U = u1; | ||
1443 | |||
1444 | newViewerFace.uv1.V = newViewerFace.uv2.V = lastV; | ||
1445 | newViewerFace.uv3.V = 1.0f - percentOfPath; | ||
1446 | |||
1336 | this.viewerFaces.Add(newViewerFace); | 1447 | this.viewerFaces.Add(newViewerFace); |
1337 | 1448 | ||
1338 | newViewerFace.v1 = this.coords[coordsLen + numVerts - 1]; // last vert in new layer | 1449 | newViewerFace.v1 = this.coords[coordsLen + numVerts - 1]; // last vert in new layer |
@@ -1342,6 +1453,12 @@ namespace PrimMesher | |||
1342 | newViewerFace.n3 = newViewerFace.n1 = newLayer.cutNormal2; | 1453 | newViewerFace.n3 = newViewerFace.n1 = newLayer.cutNormal2; |
1343 | newViewerFace.n2 = lastCutNormal2; | 1454 | newViewerFace.n2 = lastCutNormal2; |
1344 | 1455 | ||
1456 | newViewerFace.uv2.U = newViewerFace.uv1.U = u1; | ||
1457 | newViewerFace.uv3.U = u2; | ||
1458 | |||
1459 | newViewerFace.uv3.V = newViewerFace.uv1.V = 1.0f - percentOfPath; | ||
1460 | newViewerFace.uv2.V = lastV; | ||
1461 | |||
1345 | this.viewerFaces.Add(newViewerFace); | 1462 | this.viewerFaces.Add(newViewerFace); |
1346 | } | 1463 | } |
1347 | } | 1464 | } |
@@ -1350,6 +1467,7 @@ namespace PrimMesher | |||
1350 | 1467 | ||
1351 | lastCutNormal1 = newLayer.cutNormal1; | 1468 | lastCutNormal1 = newLayer.cutNormal1; |
1352 | lastCutNormal2 = newLayer.cutNormal2; | 1469 | lastCutNormal2 = newLayer.cutNormal2; |
1470 | lastV = 1.0f - percentOfPath; | ||
1353 | 1471 | ||
1354 | // calc the step for the next iteration of the loop | 1472 | // calc the step for the next iteration of the loop |
1355 | 1473 | ||
@@ -1381,6 +1499,10 @@ namespace PrimMesher | |||
1381 | newViewerFace.n2 = faceNormal; | 1499 | newViewerFace.n2 = faceNormal; |
1382 | newViewerFace.n3 = faceNormal; | 1500 | newViewerFace.n3 = faceNormal; |
1383 | 1501 | ||
1502 | newViewerFace.uv1 = newLayer.faceUVs[face.v1 - coordsLen]; | ||
1503 | newViewerFace.uv2 = newLayer.faceUVs[face.v2 - coordsLen]; | ||
1504 | newViewerFace.uv3 = newLayer.faceUVs[face.v3 - coordsLen]; | ||
1505 | |||
1384 | this.viewerFaces.Add(newViewerFace); | 1506 | this.viewerFaces.Add(newViewerFace); |
1385 | } | 1507 | } |
1386 | } | 1508 | } |
@@ -1489,7 +1611,15 @@ namespace PrimMesher | |||
1489 | Profile profile = new Profile(this.sides, this.profileStart, this.profileEnd, hollow, this.hollowSides, needEndFaces, calcVertexNormals); | 1611 | Profile profile = new Profile(this.sides, this.profileStart, this.profileEnd, hollow, this.hollowSides, needEndFaces, calcVertexNormals); |
1490 | 1612 | ||
1491 | if (initialProfileRot != 0.0f) | 1613 | if (initialProfileRot != 0.0f) |
1614 | { | ||
1492 | profile.AddRot(new Quat(new Coord(0.0f, 0.0f, 1.0f), initialProfileRot)); | 1615 | profile.AddRot(new Quat(new Coord(0.0f, 0.0f, 1.0f), initialProfileRot)); |
1616 | if (viewerMode) | ||
1617 | profile.MakeFaceUVs(); | ||
1618 | } | ||
1619 | |||
1620 | Coord lastCutNormal1 = new Coord(); | ||
1621 | Coord lastCutNormal2 = new Coord(); | ||
1622 | float lastV = 1.0f; | ||
1493 | 1623 | ||
1494 | bool done = false; | 1624 | bool done = false; |
1495 | while (!done) // loop through the length of the path and add the layers | 1625 | while (!done) // loop through the length of the path and add the layers |
@@ -1498,7 +1628,8 @@ namespace PrimMesher | |||
1498 | if (angle == startAngle || angle >= endAngle) | 1628 | if (angle == startAngle || angle >= endAngle) |
1499 | isEndLayer = true; | 1629 | isEndLayer = true; |
1500 | 1630 | ||
1501 | Profile newLayer = profile.Clone(isEndLayer && needEndFaces); | 1631 | //Profile newLayer = profile.Clone(isEndLayer && needEndFaces); |
1632 | Profile newLayer = profile.Clone(); | ||
1502 | 1633 | ||
1503 | float xProfileScale = (1.0f - Math.Abs(this.skew)) * this.holeSizeX; | 1634 | float xProfileScale = (1.0f - Math.Abs(this.skew)) * this.holeSizeX; |
1504 | float yProfileScale = this.holeSizeY; | 1635 | float yProfileScale = this.holeSizeY; |
@@ -1547,6 +1678,36 @@ namespace PrimMesher | |||
1547 | if (angle == startAngle) | 1678 | if (angle == startAngle) |
1548 | newLayer.FlipNormals(); | 1679 | newLayer.FlipNormals(); |
1549 | 1680 | ||
1681 | if (angle == startAngle) | ||
1682 | { | ||
1683 | newLayer.FlipNormals(); | ||
1684 | |||
1685 | // add the top faces to the viewerFaces list here | ||
1686 | if (this.viewerMode && needEndFaces) | ||
1687 | { | ||
1688 | Coord faceNormal = newLayer.faceNormal; | ||
1689 | ViewerFace newViewerFace = new ViewerFace(); | ||
1690 | newViewerFace.primFaceNumber = 0; | ||
1691 | foreach (Face face in newLayer.faces) | ||
1692 | { | ||
1693 | newViewerFace.v1 = newLayer.coords[face.v1]; | ||
1694 | newViewerFace.v2 = newLayer.coords[face.v2]; | ||
1695 | newViewerFace.v3 = newLayer.coords[face.v3]; | ||
1696 | |||
1697 | newViewerFace.n1 = faceNormal; | ||
1698 | newViewerFace.n2 = faceNormal; | ||
1699 | newViewerFace.n3 = faceNormal; | ||
1700 | |||
1701 | newViewerFace.uv1 = newLayer.faceUVs[face.v1]; | ||
1702 | newViewerFace.uv2 = newLayer.faceUVs[face.v2]; | ||
1703 | newViewerFace.uv3 = newLayer.faceUVs[face.v3]; | ||
1704 | |||
1705 | this.viewerFaces.Add(newViewerFace); | ||
1706 | } | ||
1707 | |||
1708 | } | ||
1709 | } | ||
1710 | |||
1550 | // append the layer and fill in the sides | 1711 | // append the layer and fill in the sides |
1551 | 1712 | ||
1552 | int coordsLen = this.coords.Count; | 1713 | int coordsLen = this.coords.Count; |
@@ -1578,6 +1739,8 @@ namespace PrimMesher | |||
1578 | for (int i = startVert; i < endVert; i++) | 1739 | for (int i = startVert; i < endVert; i++) |
1579 | //for (int i = coordsLen; i < this.coords.Count - 1; i++) | 1740 | //for (int i = coordsLen; i < this.coords.Count - 1; i++) |
1580 | { | 1741 | { |
1742 | int whichVert = i - startVert; | ||
1743 | |||
1581 | newFace.v1 = i; | 1744 | newFace.v1 = i; |
1582 | newFace.v2 = i - numVerts; | 1745 | newFace.v2 = i - numVerts; |
1583 | newFace.v3 = i - numVerts + 1; | 1746 | newFace.v3 = i - numVerts + 1; |
@@ -1587,33 +1750,115 @@ namespace PrimMesher | |||
1587 | newFace.v3 = i + 1; | 1750 | newFace.v3 = i + 1; |
1588 | this.faces.Add(newFace); | 1751 | this.faces.Add(newFace); |
1589 | 1752 | ||
1753 | //if (this.viewerMode) | ||
1754 | //{ | ||
1755 | // // add the side faces to the list of viewerFaces here | ||
1756 | // ViewerFace newViewerFace = new ViewerFace(); | ||
1757 | // newViewerFace.v1 = this.coords[i]; | ||
1758 | // newViewerFace.v2 = this.coords[i - numVerts]; | ||
1759 | // newViewerFace.v3 = this.coords[i - numVerts + 1]; | ||
1760 | |||
1761 | // newViewerFace.n1 = this.normals[i]; | ||
1762 | // newViewerFace.n2 = this.normals[i - numVerts]; | ||
1763 | // newViewerFace.n3 = this.normals[i - numVerts + 1]; | ||
1764 | |||
1765 | // this.viewerFaces.Add(newViewerFace); | ||
1766 | |||
1767 | // newViewerFace.v2 = this.coords[i - numVerts + 1]; | ||
1768 | // newViewerFace.v3 = this.coords[i + 1]; | ||
1769 | |||
1770 | // newViewerFace.n2 = this.normals[i - numVerts + 1]; | ||
1771 | // newViewerFace.n3 = this.normals[i + 1]; | ||
1772 | |||
1773 | // this.viewerFaces.Add(newViewerFace); | ||
1774 | |||
1775 | //} | ||
1776 | |||
1590 | if (this.viewerMode) | 1777 | if (this.viewerMode) |
1591 | { | 1778 | { |
1592 | // add the side faces to the list of viewerFaces here | 1779 | // add the side faces to the list of viewerFaces here |
1593 | ViewerFace newViewerFace = new ViewerFace(); | 1780 | ViewerFace newViewerFace1 = new ViewerFace(); |
1594 | newViewerFace.v1 = this.coords[i]; | 1781 | ViewerFace newViewerFace2 = new ViewerFace(); |
1595 | newViewerFace.v2 = this.coords[i - numVerts]; | 1782 | float u1 = newLayer.us[whichVert]; |
1596 | newViewerFace.v3 = this.coords[i - numVerts + 1]; | 1783 | float u2 = 1.0f; |
1784 | if (whichVert < newLayer.us.Count - 1) | ||
1785 | u2 = newLayer.us[whichVert + 1]; | ||
1597 | 1786 | ||
1598 | newViewerFace.n1 = this.normals[i]; | 1787 | newViewerFace1.uv1.U = u1; |
1599 | newViewerFace.n2 = this.normals[i - numVerts]; | 1788 | newViewerFace1.uv2.U = u1; |
1600 | newViewerFace.n3 = this.normals[i - numVerts + 1]; | 1789 | newViewerFace1.uv3.U = u2; |
1601 | 1790 | ||
1602 | this.viewerFaces.Add(newViewerFace); | 1791 | newViewerFace1.uv1.V = 1.0f - percentOfPath; |
1792 | newViewerFace1.uv2.V = lastV; | ||
1793 | newViewerFace1.uv3.V = lastV; | ||
1603 | 1794 | ||
1604 | newViewerFace.v2 = this.coords[i - numVerts + 1]; | 1795 | newViewerFace2.uv1.U = u1; |
1605 | newViewerFace.v3 = this.coords[i + 1]; | 1796 | newViewerFace2.uv2.U = u2; |
1797 | newViewerFace2.uv3.U = u2; | ||
1606 | 1798 | ||
1607 | newViewerFace.n2 = this.normals[i - numVerts + 1]; | 1799 | newViewerFace2.uv1.V = 1.0f - percentOfPath; |
1608 | newViewerFace.n3 = this.normals[i + 1]; | 1800 | newViewerFace2.uv2.V = lastV; |
1801 | newViewerFace2.uv3.V = 1.0f - percentOfPath; | ||
1609 | 1802 | ||
1610 | this.viewerFaces.Add(newViewerFace); | 1803 | newViewerFace1.v1 = this.coords[i]; |
1804 | newViewerFace1.v2 = this.coords[i - numVerts]; | ||
1805 | newViewerFace1.v3 = this.coords[i - numVerts + 1]; | ||
1806 | |||
1807 | newViewerFace2.v1 = this.coords[i]; | ||
1808 | newViewerFace2.v2 = this.coords[i - numVerts + 1]; | ||
1809 | newViewerFace2.v3 = this.coords[i + 1]; | ||
1810 | |||
1811 | if (whichVert == newLayer.numOuterVerts - 1 && hasProfileCut) | ||
1812 | { // start profile cut faces | ||
1813 | |||
1814 | newViewerFace1.n2 = newViewerFace1.n1 = lastCutNormal1; | ||
1815 | newViewerFace1.n3 = newLayer.cutNormal1; | ||
1816 | |||
1817 | newViewerFace2.n3 = newViewerFace2.n1 = newLayer.cutNormal1; | ||
1818 | newViewerFace2.n2 = lastCutNormal1; | ||
1819 | } | ||
1820 | |||
1821 | else // periphery faces | ||
1822 | { | ||
1823 | if ((sides < 5 && whichVert < newLayer.numOuterVerts) || (hollowSides < 5 && whichVert >= newLayer.numOuterVerts)) | ||
1824 | { | ||
1825 | newViewerFace1.CalcSurfaceNormal(); | ||
1826 | newViewerFace2.CalcSurfaceNormal(); | ||
1827 | } | ||
1828 | else | ||
1829 | { | ||
1830 | newViewerFace1.n1 = this.normals[i]; | ||
1831 | newViewerFace1.n2 = this.normals[i - numVerts]; | ||
1832 | newViewerFace1.n3 = this.normals[i - numVerts + 1]; | ||
1833 | |||
1834 | newViewerFace2.n1 = this.normals[i]; | ||
1835 | newViewerFace2.n2 = this.normals[i - numVerts + 1]; | ||
1836 | newViewerFace2.n3 = this.normals[i + 1]; | ||
1837 | } | ||
1838 | } | ||
1839 | |||
1840 | this.viewerFaces.Add(newViewerFace1); | ||
1841 | this.viewerFaces.Add(newViewerFace2); | ||
1611 | 1842 | ||
1612 | } | 1843 | } |
1613 | } | 1844 | } |
1614 | 1845 | ||
1846 | //if (this.hasProfileCut) | ||
1847 | //{ | ||
1848 | // newFace.v1 = coordsLen - 1; | ||
1849 | // newFace.v2 = coordsLen - numVerts; | ||
1850 | // newFace.v3 = coordsLen; | ||
1851 | // this.faces.Add(newFace); | ||
1852 | |||
1853 | // newFace.v1 = coordsLen + numVerts - 1; | ||
1854 | // newFace.v2 = coordsLen - 1; | ||
1855 | // newFace.v3 = coordsLen; | ||
1856 | // this.faces.Add(newFace); | ||
1857 | //} | ||
1858 | |||
1615 | if (this.hasProfileCut) | 1859 | if (this.hasProfileCut) |
1616 | { | 1860 | { // add the end cut face to the list of viewerFaces here |
1861 | // the first cut face was filled in the above loop | ||
1617 | newFace.v1 = coordsLen - 1; | 1862 | newFace.v1 = coordsLen - 1; |
1618 | newFace.v2 = coordsLen - numVerts; | 1863 | newFace.v2 = coordsLen - numVerts; |
1619 | newFace.v3 = coordsLen; | 1864 | newFace.v3 = coordsLen; |
@@ -1623,9 +1868,50 @@ namespace PrimMesher | |||
1623 | newFace.v2 = coordsLen - 1; | 1868 | newFace.v2 = coordsLen - 1; |
1624 | newFace.v3 = coordsLen; | 1869 | newFace.v3 = coordsLen; |
1625 | this.faces.Add(newFace); | 1870 | this.faces.Add(newFace); |
1871 | |||
1872 | if (this.viewerMode) | ||
1873 | { | ||
1874 | ViewerFace newViewerFace = new ViewerFace(); | ||
1875 | newViewerFace.v1 = this.coords[coordsLen - 1]; // last vert in prior layer | ||
1876 | newViewerFace.v2 = this.coords[coordsLen - numVerts]; // first vert in prior layer | ||
1877 | newViewerFace.v3 = this.coords[coordsLen]; // first vert in new layer | ||
1878 | |||
1879 | float u1 = newLayer.us[0]; | ||
1880 | float u2 = newLayer.us[newLayer.us.Count - 1]; | ||
1881 | |||
1882 | newViewerFace.n2 = newViewerFace.n1 = lastCutNormal2; | ||
1883 | newViewerFace.n3 = newLayer.cutNormal2; | ||
1884 | |||
1885 | newViewerFace.uv3.U = newViewerFace.uv1.U = u2; | ||
1886 | newViewerFace.uv2.U = u1; | ||
1887 | |||
1888 | newViewerFace.uv1.V = newViewerFace.uv2.V = lastV; | ||
1889 | newViewerFace.uv3.V = 1.0f - percentOfPath; | ||
1890 | |||
1891 | this.viewerFaces.Add(newViewerFace); | ||
1892 | |||
1893 | newViewerFace.v1 = this.coords[coordsLen + numVerts - 1]; // last vert in new layer | ||
1894 | newViewerFace.v2 = this.coords[coordsLen - 1]; // last vert in prior layer | ||
1895 | newViewerFace.v3 = this.coords[coordsLen]; // first vert in new layer | ||
1896 | |||
1897 | newViewerFace.n3 = newViewerFace.n1 = newLayer.cutNormal2; | ||
1898 | newViewerFace.n2 = lastCutNormal2; | ||
1899 | |||
1900 | newViewerFace.uv2.U = newViewerFace.uv1.U = u1; | ||
1901 | newViewerFace.uv3.U = u2; | ||
1902 | |||
1903 | newViewerFace.uv3.V = newViewerFace.uv1.V = 1.0f - percentOfPath; | ||
1904 | newViewerFace.uv2.V = lastV; | ||
1905 | |||
1906 | this.viewerFaces.Add(newViewerFace); | ||
1907 | } | ||
1626 | } | 1908 | } |
1627 | } | 1909 | } |
1628 | 1910 | ||
1911 | lastCutNormal1 = newLayer.cutNormal1; | ||
1912 | lastCutNormal2 = newLayer.cutNormal2; | ||
1913 | lastV = 1.0f - percentOfPath; | ||
1914 | |||
1629 | // calculate terms for next iteration | 1915 | // calculate terms for next iteration |
1630 | // calculate the angle for the next iteration of the loop | 1916 | // calculate the angle for the next iteration of the loop |
1631 | 1917 | ||
@@ -1638,6 +1924,30 @@ namespace PrimMesher | |||
1638 | if (angle > endAngle) | 1924 | if (angle > endAngle) |
1639 | angle = endAngle; | 1925 | angle = endAngle; |
1640 | } | 1926 | } |
1927 | |||
1928 | if (done && viewerMode && needEndFaces) | ||
1929 | { | ||
1930 | // add the bottom faces to the viewerFaces list here | ||
1931 | Coord faceNormal = newLayer.faceNormal; | ||
1932 | ViewerFace newViewerFace = new ViewerFace(); | ||
1933 | newViewerFace.primFaceNumber = 0; | ||
1934 | foreach (Face face in newLayer.faces) | ||
1935 | { | ||
1936 | newViewerFace.v1 = newLayer.coords[face.v1 - coordsLen]; | ||
1937 | newViewerFace.v2 = newLayer.coords[face.v2 - coordsLen]; | ||
1938 | newViewerFace.v3 = newLayer.coords[face.v3 - coordsLen]; | ||
1939 | |||
1940 | newViewerFace.n1 = faceNormal; | ||
1941 | newViewerFace.n2 = faceNormal; | ||
1942 | newViewerFace.n3 = faceNormal; | ||
1943 | |||
1944 | newViewerFace.uv1 = newLayer.faceUVs[face.v1 - coordsLen]; | ||
1945 | newViewerFace.uv2 = newLayer.faceUVs[face.v2 - coordsLen]; | ||
1946 | newViewerFace.uv3 = newLayer.faceUVs[face.v3 - coordsLen]; | ||
1947 | |||
1948 | this.viewerFaces.Add(newViewerFace); | ||
1949 | } | ||
1950 | } | ||
1641 | } | 1951 | } |
1642 | } | 1952 | } |
1643 | 1953 | ||
@@ -1659,7 +1969,7 @@ namespace PrimMesher | |||
1659 | 1969 | ||
1660 | public Coord SurfaceNormal(int faceIndex) | 1970 | public Coord SurfaceNormal(int faceIndex) |
1661 | { | 1971 | { |
1662 | //int numFaces = faces.Count; | 1972 | int numFaces = faces.Count; |
1663 | if (faceIndex < 0 || faceIndex >= faces.Count) | 1973 | if (faceIndex < 0 || faceIndex >= faces.Count) |
1664 | throw new Exception("faceIndex out of range"); | 1974 | throw new Exception("faceIndex out of range"); |
1665 | 1975 | ||