aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/PhysicsModules/ubOdeMeshing/PrimMesher.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/PhysicsModules/ubOdeMeshing/PrimMesher.cs')
-rw-r--r--OpenSim/Region/PhysicsModules/ubOdeMeshing/PrimMesher.cs122
1 files changed, 53 insertions, 69 deletions
diff --git a/OpenSim/Region/PhysicsModules/ubOdeMeshing/PrimMesher.cs b/OpenSim/Region/PhysicsModules/ubOdeMeshing/PrimMesher.cs
index 23e87d1..f3a57d3 100644
--- a/OpenSim/Region/PhysicsModules/ubOdeMeshing/PrimMesher.cs
+++ b/OpenSim/Region/PhysicsModules/ubOdeMeshing/PrimMesher.cs
@@ -212,14 +212,34 @@ namespace PrimMesher
212 212
213 public static Coord operator *(Coord v, Quat q) 213 public static Coord operator *(Coord v, Quat q)
214 { 214 {
215 float rx = q.W * v.X + q.Y * v.Z - q.Z * v.Y; 215 float x = q.X;
216 float ry = q.W * v.Y + q.Z * v.X - q.X * v.Z; 216 float y = q.Y;
217 float rz = q.W * v.Z + q.X * v.Y - q.Y * v.X; 217 float x2 = x + x;
218 float z = q.Z;
219 float y2 = y + y;
220 float w = q.W;
221 float z2 = z + z;
222
223 float zz2 = z * z2;
224
225 float xx2 = x * x2;
226 float xy2 = x * y2;
227 float xz2 = x * z2;
228 z = v.Z;
229
230 float yy2 = y * y2;
231 float yz2 = y * z2;
232 x = v.X;
233
234 float wx2 = w * x2;
235 float wy2 = w * y2;
236 float wz2 = w * z2;
237 y = v.Y;
218 238
219 return new Coord( 239 return new Coord(
220 2.0f * (rz * q.Y - ry * q.Z) + v.X, 240 x * (1.0f - yy2 - zz2) + y * (xy2 - wz2) + z * (xz2 + wy2),
221 2.0f * (rx * q.Z - rz * q.X) + v.Y, 241 x * (xy2 + wz2) + y * (1.0f - xx2 - zz2) + z * (yz2 - wx2),
222 2.0f * (ry * q.X - rx * q.Y) + v.Z ); 242 x * (xz2 - wy2) + y * (yz2 + wx2) + z * (1.0f - xx2 - yy2));
223 } 243 }
224 } 244 }
225 245
@@ -248,9 +268,9 @@ namespace PrimMesher
248 internal float X; 268 internal float X;
249 internal float Y; 269 internal float Y;
250 270
251 internal Angle(float angle, float x, float y) 271 internal Angle(float _angle, float x, float y)
252 { 272 {
253 this.angle = angle; // 1 is 2pi 273 angle = _angle; // 1 is 2pi
254 X = x; // cos 274 X = x; // cos
255 Y = y; // sin 275 Y = y; // sin
256 } 276 }
@@ -359,8 +379,8 @@ namespace PrimMesher
359 { 379 {
360 angles = new List<Angle>(); 380 angles = new List<Angle>();
361 381
362 const float twoPi = (float)(Math.PI * 2.0); 382 const float twoPi = 2.0f * (float)Math.PI;
363 const float twoPiInv = (float)(0.5 / Math.PI); 383 const float twoPiInv = 0.5f / (float)Math.PI;
364 384
365 if (sides < 1) 385 if (sides < 1)
366 throw new Exception("number of sides not greater than zero"); 386 throw new Exception("number of sides not greater than zero");
@@ -479,7 +499,7 @@ namespace PrimMesher
479 /// </summary> 499 /// </summary>
480 public class Profile 500 public class Profile
481 { 501 {
482 private const float twoPi = (float)(2.0 * Math.PI); 502 private const float twoPi = 2.0f * (float)Math.PI;
483 503
484 public string errorMessage = null; 504 public string errorMessage = null;
485 505
@@ -533,7 +553,6 @@ namespace PrimMesher
533 try { angles.makeAngles(sides, startAngle, stopAngle,hasProfileCut); } 553 try { angles.makeAngles(sides, startAngle, stopAngle,hasProfileCut); }
534 catch (Exception ex) 554 catch (Exception ex)
535 { 555 {
536
537 errorMessage = "makeAngles failed: Exception: " + ex.ToString() 556 errorMessage = "makeAngles failed: Exception: " + ex.ToString()
538 + "\nsides: " + sides.ToString() + " startAngle: " + startAngle.ToString() + " stopAngle: " + stopAngle.ToString(); 557 + "\nsides: " + sides.ToString() + " startAngle: " + startAngle.ToString() + " stopAngle: " + stopAngle.ToString();
539 558
@@ -791,7 +810,6 @@ namespace PrimMesher
791 } 810 }
792 } 811 }
793 812
794
795 hollowCoords = null; 813 hollowCoords = null;
796 } 814 }
797 815
@@ -833,7 +851,7 @@ namespace PrimMesher
833 vert.X += x; 851 vert.X += x;
834 vert.Y += y; 852 vert.Y += y;
835 vert.Z += z; 853 vert.Z += z;
836 this.coords[i] = vert; 854 coords[i] = vert;
837 } 855 }
838 } 856 }
839 857
@@ -1228,7 +1246,6 @@ namespace PrimMesher
1228 get { return hasHollow; } 1246 get { return hasHollow; }
1229 } 1247 }
1230 1248
1231
1232 /// <summary> 1249 /// <summary>
1233 /// Constructs a PrimMesh object and creates the profile for extrusion. 1250 /// Constructs a PrimMesh object and creates the profile for extrusion.
1234 /// </summary> 1251 /// </summary>
@@ -1257,13 +1274,13 @@ namespace PrimMesher
1257 profileStart = 0.0f; 1274 profileStart = 0.0f;
1258 if (profileEnd > 1.0f) 1275 if (profileEnd > 1.0f)
1259 profileEnd = 1.0f; 1276 profileEnd = 1.0f;
1260 if (profileEnd < 0.02f) 1277 else if (profileEnd < 0.02f)
1261 profileEnd = 0.02f; 1278 profileEnd = 0.02f;
1262 if (profileStart >= profileEnd) 1279 if (profileStart >= profileEnd)
1263 profileStart = profileEnd - 0.02f; 1280 profileStart = profileEnd - 0.02f;
1264 if (hollow > 0.99f) 1281 if (hollow > 0.99f)
1265 hollow = 0.99f; 1282 hollow = 0.99f;
1266 if (hollow < 0.0f) 1283 else if (hollow < 0.0f)
1267 hollow = 0.0f; 1284 hollow = 0.0f;
1268 } 1285 }
1269 1286
@@ -1281,9 +1298,7 @@ namespace PrimMesher
1281 1298
1282 float length = pathCutEnd - pathCutBegin; 1299 float length = pathCutEnd - pathCutBegin;
1283 1300
1284 hasProfileCut = this.profileEnd - this.profileStart < 0.9999f; 1301 hasProfileCut = profileEnd - profileStart < 0.9999f;
1285
1286 hasHollow = (this.hollow > 0.001f);
1287 1302
1288 float twistTotal = twistEnd - twistBegin; 1303 float twistTotal = twistEnd - twistBegin;
1289 float twistTotalAbs = Math.Abs(twistTotal); 1304 float twistTotalAbs = Math.Abs(twistTotal);
@@ -1291,6 +1306,8 @@ namespace PrimMesher
1291 steps += (int)(twistTotalAbs * 3.66); // dahlia's magic number 1306 steps += (int)(twistTotalAbs * 3.66); // dahlia's magic number
1292 1307
1293 float hollow = this.hollow; 1308 float hollow = this.hollow;
1309 hasHollow = hollow > 0.001f;
1310
1294 float initialProfileRot = 0.0f; 1311 float initialProfileRot = 0.0f;
1295 1312
1296 if (pathType == PathType.Circular) 1313 if (pathType == PathType.Circular)
@@ -1516,29 +1533,6 @@ namespace PrimMesher
1516 // more cleanup will be done at Meshmerizer.cs 1533 // more cleanup will be done at Meshmerizer.cs
1517 } 1534 }
1518 1535
1519
1520 /// <summary>
1521 /// DEPRICATED - use Extrude(PathType.Linear) instead
1522 /// Extrudes a profile along a straight line path. Used for prim types box, cylinder, and prism.
1523 /// </summary>
1524 ///
1525 public void ExtrudeLinear()
1526 {
1527 Extrude(PathType.Linear);
1528 }
1529
1530
1531 /// <summary>
1532 /// DEPRICATED - use Extrude(PathType.Circular) instead
1533 /// Extrude a profile into a circular path prim mesh. Used for prim types torus, tube, and ring.
1534 /// </summary>
1535 ///
1536 public void ExtrudeCircular()
1537 {
1538 Extrude(PathType.Circular);
1539 }
1540
1541
1542 private Coord SurfaceNormal(Coord c1, Coord c2, Coord c3) 1536 private Coord SurfaceNormal(Coord c1, Coord c2, Coord c3)
1543 { 1537 {
1544 Coord edge1 = new Coord(c2.X - c1.X, c2.Y - c1.Y, c2.Z - c1.Z); 1538 Coord edge1 = new Coord(c2.X - c1.X, c2.Y - c1.Y, c2.Z - c1.Z);
@@ -1553,7 +1547,7 @@ namespace PrimMesher
1553 1547
1554 private Coord SurfaceNormal(Face face) 1548 private Coord SurfaceNormal(Face face)
1555 { 1549 {
1556 return SurfaceNormal(this.coords[face.v1], this.coords[face.v2], this.coords[face.v3]); 1550 return SurfaceNormal(coords[face.v1], coords[face.v2], coords[face.v3]);
1557 } 1551 }
1558 1552
1559 /// <summary> 1553 /// <summary>
@@ -1563,11 +1557,11 @@ namespace PrimMesher
1563 /// <returns></returns> 1557 /// <returns></returns>
1564 public Coord SurfaceNormal(int faceIndex) 1558 public Coord SurfaceNormal(int faceIndex)
1565 { 1559 {
1566 int numFaces = this.faces.Count; 1560 int numFaces = faces.Count;
1567 if (faceIndex < 0 || faceIndex >= numFaces) 1561 if (faceIndex < 0 || faceIndex >= numFaces)
1568 throw new Exception("faceIndex out of range"); 1562 throw new Exception("faceIndex out of range");
1569 1563
1570 return SurfaceNormal(this.faces[faceIndex]); 1564 return SurfaceNormal(faces[faceIndex]);
1571 } 1565 }
1572 1566
1573 /// <summary> 1567 /// <summary>
@@ -1612,16 +1606,16 @@ namespace PrimMesher
1612 public void AddPos(float x, float y, float z) 1606 public void AddPos(float x, float y, float z)
1613 { 1607 {
1614 int i; 1608 int i;
1615 int numVerts = this.coords.Count; 1609 int numVerts = coords.Count;
1616 Coord vert; 1610 Coord vert;
1617 1611
1618 for (i = 0; i < numVerts; i++) 1612 for (i = 0; i < numVerts; i++)
1619 { 1613 {
1620 vert = this.coords[i]; 1614 vert = coords[i];
1621 vert.X += x; 1615 vert.X += x;
1622 vert.Y += y; 1616 vert.Y += y;
1623 vert.Z += z; 1617 vert.Z += z;
1624 this.coords[i] = vert; 1618 coords[i] = vert;
1625 } 1619 }
1626 } 1620 }
1627 1621
@@ -1632,18 +1626,11 @@ namespace PrimMesher
1632 public void AddRot(Quat q) 1626 public void AddRot(Quat q)
1633 { 1627 {
1634 int i; 1628 int i;
1635 int numVerts = this.coords.Count; 1629 int numVerts = coords.Count;
1636 1630
1637 for (i = 0; i < numVerts; i++) 1631 for (i = 0; i < numVerts; i++)
1638 this.coords[i] *= q; 1632 coords[i] *= q;
1639 }
1640
1641#if VERTEX_INDEXER
1642 public VertexIndexer GetVertexIndexer()
1643 {
1644 return null;
1645 } 1633 }
1646#endif
1647 1634
1648 /// <summary> 1635 /// <summary>
1649 /// Scales the mesh 1636 /// Scales the mesh
@@ -1659,7 +1646,7 @@ namespace PrimMesher
1659 1646
1660 Coord m = new Coord(x, y, z); 1647 Coord m = new Coord(x, y, z);
1661 for (i = 0; i < numVerts; i++) 1648 for (i = 0; i < numVerts; i++)
1662 this.coords[i] *= m; 1649 coords[i] *= m;
1663 } 1650 }
1664 1651
1665 /// <summary> 1652 /// <summary>
@@ -1674,18 +1661,15 @@ namespace PrimMesher
1674 return; 1661 return;
1675 String fileName = name + "_" + title + ".raw"; 1662 String fileName = name + "_" + title + ".raw";
1676 String completePath = System.IO.Path.Combine(path, fileName); 1663 String completePath = System.IO.Path.Combine(path, fileName);
1677 StreamWriter sw = new StreamWriter(completePath); 1664 using (StreamWriter sw = new StreamWriter(completePath))
1678
1679 for (int i = 0; i < this.faces.Count; i++)
1680 { 1665 {
1681 string s = this.coords[this.faces[i].v1].ToString(); 1666 for (int i = 0; i < this.faces.Count; i++)
1682 s += " " + this.coords[this.faces[i].v2].ToString(); 1667 {
1683 s += " " + this.coords[this.faces[i].v3].ToString(); 1668 sw.Write(coords[faces[i].v1].ToString());
1684 1669 sw.Write(coords[faces[i].v2].ToString());
1685 sw.WriteLine(s); 1670 sw.WriteLine(coords[faces[i].v3].ToString());
1671 }
1686 } 1672 }
1687
1688 sw.Close();
1689 } 1673 }
1690 } 1674 }
1691} 1675}