aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/Meshing/PrimMesher.cs
diff options
context:
space:
mode:
authorDahlia Trimble2008-10-12 07:04:52 +0000
committerDahlia Trimble2008-10-12 07:04:52 +0000
commit216787ee1d196d99b24e29e1519f2a1738355981 (patch)
treeefe6e06c469ec22b91c231735277a85fa15bfc6e /OpenSim/Region/Physics/Meshing/PrimMesher.cs
parentUpdate svn properties, minor formatting cleanup. (diff)
downloadopensim-SC_OLD-216787ee1d196d99b24e29e1519f2a1738355981.zip
opensim-SC_OLD-216787ee1d196d99b24e29e1519f2a1738355981.tar.gz
opensim-SC_OLD-216787ee1d196d99b24e29e1519f2a1738355981.tar.bz2
opensim-SC_OLD-216787ee1d196d99b24e29e1519f2a1738355981.tar.xz
Optimization: calculation of profile vertex normals is now disabled as default.
Diffstat (limited to 'OpenSim/Region/Physics/Meshing/PrimMesher.cs')
-rw-r--r--OpenSim/Region/Physics/Meshing/PrimMesher.cs116
1 files changed, 102 insertions, 14 deletions
diff --git a/OpenSim/Region/Physics/Meshing/PrimMesher.cs b/OpenSim/Region/Physics/Meshing/PrimMesher.cs
index 63fb7f7..537d652 100644
--- a/OpenSim/Region/Physics/Meshing/PrimMesher.cs
+++ b/OpenSim/Region/Physics/Meshing/PrimMesher.cs
@@ -415,17 +415,23 @@ namespace PrimMesher
415 415
416 internal List<Coord> coords; 416 internal List<Coord> coords;
417 internal List<Face> faces; 417 internal List<Face> faces;
418 internal List<Coord> normals;
419
420 internal bool calcVertexNormals = false;
418 421
419 internal Profile() 422 internal Profile()
420 { 423 {
421 this.coords = new List<Coord>(); 424 this.coords = new List<Coord>();
422 this.faces = new List<Face>(); 425 this.faces = new List<Face>();
426 this.normals = new List<Coord>();
423 } 427 }
424 428
425 public Profile(int sides, float profileStart, float profileEnd, float hollow, int hollowSides, bool createFaces) 429 public Profile(int sides, float profileStart, float profileEnd, float hollow, int hollowSides, bool createFaces, bool calcVertexNormals)
426 { 430 {
431 this.calcVertexNormals = calcVertexNormals;
427 this.coords = new List<Coord>(); 432 this.coords = new List<Coord>();
428 this.faces = new List<Face>(); 433 this.faces = new List<Face>();
434 this.normals = new List<Coord>();
429 Coord center = new Coord(0.0f, 0.0f, 0.0f); 435 Coord center = new Coord(0.0f, 0.0f, 0.0f);
430 List<Coord> hollowCoords = new List<Coord>(); 436 List<Coord> hollowCoords = new List<Coord>();
431 437
@@ -452,6 +458,20 @@ namespace PrimMesher
452 return; 458 return;
453 } 459 }
454 460
461 if (this.calcVertexNormals)
462 {
463 if (sides > 4)
464 foreach (Angle a in angles.angles)
465 normals.Add(new Coord(a.X, a.Y, 0.0f));
466 else
467 for (int i = 0; i < angles.angles.Count - 1; i++)
468 {
469 Angle a1 = angles.angles[i];
470 Angle a2 = angles.angles[i + 1];
471 normals.Add(new Coord(0.5f * (a1.X + a2.X), 0.5f * (a1.Y + a2.Y), 0.0f).Normalize());
472 }
473 }
474
455 if (hollow > 0.001f) 475 if (hollow > 0.001f)
456 { 476 {
457 if (sides == hollowSides) 477 if (sides == hollowSides)
@@ -466,9 +486,27 @@ namespace PrimMesher
466 return; 486 return;
467 } 487 }
468 } 488 }
489
490 if (this.calcVertexNormals)
491 {
492 if (hollowSides > 4)
493 foreach (Angle a in hollowAngles.angles)
494 normals.Add(new Coord(-a.X, -a.Y, 0.0f));
495 else
496 for (int i = 0; i < hollowAngles.angles.Count - 1; i++)
497 {
498 Angle a1 = hollowAngles.angles[i];
499 Angle a2 = hollowAngles.angles[i + 1];
500 normals.Add(new Coord(-0.5f * (a1.X + a2.X), -0.5f * (a1.Y + a2.Y), 0.0f).Normalize());
501 }
502 }
469 } 503 }
470 else 504 else
505 {
471 this.coords.Add(center); 506 this.coords.Add(center);
507 if (this.calcVertexNormals && sides > 4)
508 this.normals.Add(new Coord(0.0f, 0.0f, 1.0f));
509 }
472 510
473 float z = 0.0f; 511 float z = 0.0f;
474 512
@@ -617,6 +655,7 @@ namespace PrimMesher
617 clone.coords.AddRange(this.coords); 655 clone.coords.AddRange(this.coords);
618 if (needFaces) 656 if (needFaces)
619 clone.faces.AddRange(this.faces); 657 clone.faces.AddRange(this.faces);
658 clone.normals.AddRange(this.normals);
620 659
621 return clone; 660 return clone;
622 } 661 }
@@ -646,17 +685,29 @@ namespace PrimMesher
646 { 685 {
647 int i; 686 int i;
648 int numVerts = this.coords.Count; 687 int numVerts = this.coords.Count;
649 Coord vert; 688 Coord c;
650 689
651 for (i = 0; i < numVerts; i++) 690 for (i = 0; i < numVerts; i++)
652 { 691 {
653 vert = this.coords[i]; 692 c = this.coords[i];
654 Coord v = new Coord(vert.X, vert.Y, vert.Z) * q; 693 Coord v = new Coord(c.X, c.Y, c.Z) * q;
655 694
656 vert.X = v.X; 695 c.X = v.X;
657 vert.Y = v.Y; 696 c.Y = v.Y;
658 vert.Z = v.Z; 697 c.Z = v.Z;
659 this.coords[i] = vert; 698 this.coords[i] = c;
699 }
700
701 int numNormals = this.normals.Count;
702 for (i = 0; i < numNormals; i++)
703 {
704 c = this.normals[i];
705 Coord n = new Coord(c.X, c.Y, c.Z) * q;
706
707 c.X = n.X;
708 c.Y = n.Y;
709 c.Z = n.Z;
710 this.normals[i] = c;
660 } 711 }
661 } 712 }
662 713
@@ -675,6 +726,9 @@ namespace PrimMesher
675 } 726 }
676 } 727 }
677 728
729 /// <summary>
730 /// Changes order of the vertex indices and negates the center vertex normal. Does not alter vertex normals of radial vertices
731 /// </summary>
678 public void FlipNormals() 732 public void FlipNormals()
679 { 733 {
680 int i; 734 int i;
@@ -690,9 +744,20 @@ namespace PrimMesher
690 tmpFace.v1 = tmp; 744 tmpFace.v1 = tmp;
691 this.faces[i] = tmpFace; 745 this.faces[i] = tmpFace;
692 } 746 }
747
748 if (this.calcVertexNormals)
749 {
750 int normalCount = this.normals.Count;
751 if (normalCount > 0)
752 {
753 Coord n = this.normals[normalCount - 1];
754 n.Z *= 1.0f;
755 this.normals[normalCount - 1] = n;
756 }
757 }
693 } 758 }
694 759
695 public void AddValue2Faces(int num) 760 public void AddValue2FaceVertexIndices(int num)
696 { 761 {
697 int numFaces = this.faces.Count; 762 int numFaces = this.faces.Count;
698 Face tmpFace; 763 Face tmpFace;
@@ -702,10 +767,29 @@ namespace PrimMesher
702 tmpFace.v1 += num; 767 tmpFace.v1 += num;
703 tmpFace.v2 += num; 768 tmpFace.v2 += num;
704 tmpFace.v3 += num; 769 tmpFace.v3 += num;
770
705 this.faces[i] = tmpFace; 771 this.faces[i] = tmpFace;
706 } 772 }
707 } 773 }
708 774
775 public void AddValue2FaceNormalIndices(int num)
776 {
777 if (this.calcVertexNormals)
778 {
779 int numFaces = this.faces.Count;
780 Face tmpFace;
781 for (int i = 0; i < numFaces; i++)
782 {
783 tmpFace = this.faces[i];
784 tmpFace.n1 += num;
785 tmpFace.n2 += num;
786 tmpFace.n3 += num;
787
788 this.faces[i] = tmpFace;
789 }
790 }
791 }
792
709 public void DumpRaw(String path, String name, String title) 793 public void DumpRaw(String path, String name, String title)
710 { 794 {
711 if (path == null) 795 if (path == null)
@@ -757,6 +841,8 @@ namespace PrimMesher
757 public float revolutions = 1.0f; 841 public float revolutions = 1.0f;
758 public int stepsPerRevolution = 24; 842 public int stepsPerRevolution = 24;
759 843
844 public bool calcVertexNormals = false;
845
760 public string ParamsToDisplayString() 846 public string ParamsToDisplayString()
761 { 847 {
762 string s = ""; 848 string s = "";
@@ -883,7 +969,7 @@ namespace PrimMesher
883 if (profileStart < 0.0 || profileEnd < 1.0) 969 if (profileStart < 0.0 || profileEnd < 1.0)
884 hasProfileCut = true; 970 hasProfileCut = true;
885 971
886 Profile profile = new Profile(this.sides, this.profileStart, this.profileEnd, hollow, this.hollowSides, true); 972 Profile profile = new Profile(this.sides, this.profileStart, this.profileEnd, hollow, this.hollowSides, true, calcVertexNormals);
887 973
888 if (initialProfileRot != 0.0f) 974 if (initialProfileRot != 0.0f)
889 profile.AddRot(new Quat(new Coord(0.0f, 0.0f, 1.0f), initialProfileRot)); 975 profile.AddRot(new Quat(new Coord(0.0f, 0.0f, 1.0f), initialProfileRot));
@@ -920,7 +1006,7 @@ namespace PrimMesher
920 // append this layer 1006 // append this layer
921 1007
922 int coordsLen = this.coords.Count; 1008 int coordsLen = this.coords.Count;
923 newLayer.AddValue2Faces(coordsLen); 1009 newLayer.AddValue2FaceVertexIndices(coordsLen);
924 1010
925 this.coords.AddRange(newLayer.coords); 1011 this.coords.AddRange(newLayer.coords);
926 1012
@@ -1071,7 +1157,7 @@ namespace PrimMesher
1071 else if (twistTotal != 0.0) 1157 else if (twistTotal != 0.0)
1072 needEndFaces = true; 1158 needEndFaces = true;
1073 1159
1074 Profile profile = new Profile(this.sides, this.profileStart, this.profileEnd, hollow, this.hollowSides, needEndFaces); 1160 Profile profile = new Profile(this.sides, this.profileStart, this.profileEnd, hollow, this.hollowSides, needEndFaces, calcVertexNormals);
1075 1161
1076 if (initialProfileRot != 0.0f) 1162 if (initialProfileRot != 0.0f)
1077 profile.AddRot(new Quat(new Coord(0.0f, 0.0f, 1.0f), initialProfileRot)); 1163 profile.AddRot(new Quat(new Coord(0.0f, 0.0f, 1.0f), initialProfileRot));
@@ -1135,7 +1221,7 @@ namespace PrimMesher
1135 // append the layer and fill in the sides 1221 // append the layer and fill in the sides
1136 1222
1137 int coordsLen = this.coords.Count; 1223 int coordsLen = this.coords.Count;
1138 newLayer.AddValue2Faces(coordsLen); 1224 newLayer.AddValue2FaceVertexIndices(coordsLen);
1139 1225
1140 this.coords.AddRange(newLayer.coords); 1226 this.coords.AddRange(newLayer.coords);
1141 1227
@@ -1190,7 +1276,9 @@ namespace PrimMesher
1190 { 1276 {
1191 int numFaces = faces.Count; 1277 int numFaces = faces.Count;
1192 if (faceIndex < 0 || faceIndex >= faces.Count) 1278 if (faceIndex < 0 || faceIndex >= faces.Count)
1193 return new Coord(0.0f, 0.0f, 0.0f); 1279 throw new Exception("faceIndex out of range");
1280
1281 //return new Coord(0.0f, 0.0f, 0.0f);
1194 1282
1195 Face face = faces[faceIndex]; 1283 Face face = faces[faceIndex];
1196 Coord c1 = coords[face.v1]; 1284 Coord c1 = coords[face.v1];