aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/PhysicsModules/ubOdeMeshing
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/PhysicsModules/ubOdeMeshing')
-rw-r--r--OpenSim/Region/PhysicsModules/ubOdeMeshing/Mesh.cs23
-rw-r--r--OpenSim/Region/PhysicsModules/ubOdeMeshing/Meshmerizer.cs4
-rw-r--r--OpenSim/Region/PhysicsModules/ubOdeMeshing/PrimMesher.cs122
-rw-r--r--OpenSim/Region/PhysicsModules/ubOdeMeshing/SculptMesh.cs21
4 files changed, 77 insertions, 93 deletions
diff --git a/OpenSim/Region/PhysicsModules/ubOdeMeshing/Mesh.cs b/OpenSim/Region/PhysicsModules/ubOdeMeshing/Mesh.cs
index 5d2b1f7..380cce2 100644
--- a/OpenSim/Region/PhysicsModules/ubOdeMeshing/Mesh.cs
+++ b/OpenSim/Region/PhysicsModules/ubOdeMeshing/Mesh.cs
@@ -218,7 +218,6 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
218 m_bdata.m_obbZmax = z; 218 m_bdata.m_obbZmax = z;
219 if (z < m_bdata.m_obbZmin) 219 if (z < m_bdata.m_obbZmin)
220 m_bdata.m_obbZmin = z; 220 m_bdata.m_obbZmin = z;
221
222 } 221 }
223 222
224 public void Add(Triangle triangle) 223 public void Add(Triangle triangle)
@@ -324,13 +323,15 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
324 if (m_bdata.m_vertices == null) 323 if (m_bdata.m_vertices == null)
325 throw new NotSupportedException(); 324 throw new NotSupportedException();
326 float[] result = new float[m_bdata.m_vertices.Count * 3]; 325 float[] result = new float[m_bdata.m_vertices.Count * 3];
326 int k = 0;
327 foreach (KeyValuePair<Vertex, int> kvp in m_bdata.m_vertices) 327 foreach (KeyValuePair<Vertex, int> kvp in m_bdata.m_vertices)
328 { 328 {
329 Vertex v = kvp.Key; 329 Vertex v = kvp.Key;
330 int i = kvp.Value; 330 int i = kvp.Value;
331 result[3 * i + 0] = v.X; 331 k = 3 * i;
332 result[3 * i + 1] = v.Y; 332 result[k] = v.X;
333 result[3 * i + 2] = v.Z; 333 result[k + 1] = v.Y;
334 result[k + 2] = v.Z;
334 } 335 }
335 return result; 336 return result;
336 } 337 }
@@ -364,12 +365,14 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
364 if (m_bdata.m_triangles == null) 365 if (m_bdata.m_triangles == null)
365 throw new NotSupportedException(); 366 throw new NotSupportedException();
366 int[] result = new int[m_bdata.m_triangles.Count * 3]; 367 int[] result = new int[m_bdata.m_triangles.Count * 3];
368 int k;
367 for (int i = 0; i < m_bdata.m_triangles.Count; i++) 369 for (int i = 0; i < m_bdata.m_triangles.Count; i++)
368 { 370 {
371 k= 3 * i;
369 Triangle t = m_bdata.m_triangles[i]; 372 Triangle t = m_bdata.m_triangles[i];
370 result[3 * i + 0] = m_bdata.m_vertices[t.v1]; 373 result[k] = m_bdata.m_vertices[t.v1];
371 result[3 * i + 1] = m_bdata.m_vertices[t.v2]; 374 result[k + 1] = m_bdata.m_vertices[t.v2];
372 result[3 * i + 2] = m_bdata.m_vertices[t.v3]; 375 result[k + 2] = m_bdata.m_vertices[t.v3];
373 } 376 }
374 return result; 377 return result;
375 } 378 }
@@ -463,9 +466,9 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
463 if (v == null) 466 if (v == null)
464 continue; 467 continue;
465 float x, y, z; 468 float x, y, z;
466 x = v.X*matrix[0, 0] + v.Y*matrix[1, 0] + v.Z*matrix[2, 0]; 469 x = v.X * matrix[0, 0] + v.Y * matrix[1, 0] + v.Z * matrix[2, 0];
467 y = v.X*matrix[0, 1] + v.Y*matrix[1, 1] + v.Z*matrix[2, 1]; 470 y = v.X * matrix[0, 1] + v.Y * matrix[1, 1] + v.Z * matrix[2, 1];
468 z = v.X*matrix[0, 2] + v.Y*matrix[1, 2] + v.Z*matrix[2, 2]; 471 z = v.X * matrix[0, 2] + v.Y * matrix[1, 2] + v.Z * matrix[2, 2];
469 v.X = x + offset[0]; 472 v.X = x + offset[0];
470 v.Y = y + offset[1]; 473 v.Y = y + offset[1];
471 v.Z = z + offset[2]; 474 v.Z = z + offset[2];
diff --git a/OpenSim/Region/PhysicsModules/ubOdeMeshing/Meshmerizer.cs b/OpenSim/Region/PhysicsModules/ubOdeMeshing/Meshmerizer.cs
index 1b2f41a..6950f2d 100644
--- a/OpenSim/Region/PhysicsModules/ubOdeMeshing/Meshmerizer.cs
+++ b/OpenSim/Region/PhysicsModules/ubOdeMeshing/Meshmerizer.cs
@@ -945,7 +945,7 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
945#endif 945#endif
946 try 946 try
947 { 947 {
948 primMesh.ExtrudeLinear(); 948 primMesh.Extrude(PathType.Linear); ;
949 } 949 }
950 catch (Exception ex) 950 catch (Exception ex)
951 { 951 {
@@ -978,7 +978,7 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
978#endif 978#endif
979 try 979 try
980 { 980 {
981 primMesh.ExtrudeCircular(); 981 primMesh.Extrude(PathType.Circular);
982 } 982 }
983 catch (Exception ex) 983 catch (Exception ex)
984 { 984 {
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}
diff --git a/OpenSim/Region/PhysicsModules/ubOdeMeshing/SculptMesh.cs b/OpenSim/Region/PhysicsModules/ubOdeMeshing/SculptMesh.cs
index bc1375b..184221d 100644
--- a/OpenSim/Region/PhysicsModules/ubOdeMeshing/SculptMesh.cs
+++ b/OpenSim/Region/PhysicsModules/ubOdeMeshing/SculptMesh.cs
@@ -165,8 +165,8 @@ namespace PrimMesher
165 f2 = new Face(p1, p4, p2); 165 f2 = new Face(p1, p4, p2);
166 } 166 }
167 167
168 this.faces.Add(f1); 168 faces.Add(f1);
169 this.faces.Add(f2); 169 faces.Add(f2);
170 } 170 }
171 } 171 }
172 } 172 }
@@ -203,18 +203,15 @@ namespace PrimMesher
203 return; 203 return;
204 String fileName = name + "_" + title + ".raw"; 204 String fileName = name + "_" + title + ".raw";
205 String completePath = System.IO.Path.Combine(path, fileName); 205 String completePath = System.IO.Path.Combine(path, fileName);
206 StreamWriter sw = new StreamWriter(completePath); 206 using(StreamWriter sw = new StreamWriter(completePath))
207
208 for (int i = 0; i < this.faces.Count; i++)
209 { 207 {
210 string s = this.coords[this.faces[i].v1].ToString(); 208 for (int i = 0; i < faces.Count; i++)
211 s += " " + this.coords[this.faces[i].v2].ToString(); 209 {
212 s += " " + this.coords[this.faces[i].v3].ToString(); 210 sw.Write(coords[faces[i].v1].ToString());
213 211 sw.Write(coords[faces[i].v2].ToString());
214 sw.WriteLine(s); 212 sw.WriteLine(coords[faces[i].v3].ToString());
213 }
215 } 214 }
216
217 sw.Close();
218 } 215 }
219 } 216 }
220} 217}