diff --git a/OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs b/OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs index 97dcb69ab6..dc65a2cc72 100644 --- a/OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs +++ b/OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs @@ -1558,33 +1558,36 @@ namespace OpenSim.Region.PhysicsModule.ubOde // tmpTime = Util.GetTimeStampMS(); - lock (SimulationLock) + // Move characters + lock (_characters) { - // Move characters - lock (_characters) + foreach (OdeCharacter actor in _characters) { - foreach (OdeCharacter actor in _characters) - { + lock (SimulationLock) actor.Move(); - } } + } - // Move other active objects - lock (_activegroups) + // Move other active objects + lock (_activegroups) + { + foreach (OdePrim aprim in _activegroups) { - foreach (OdePrim aprim in _activegroups) - { + lock (SimulationLock) aprim.Move(); - } } + } // moveTime += Util.GetTimeStampMS() - tmpTime; // tmpTime = Util.GetTimeStampMS(); + lock (SimulationLock) + { m_rayCastManager.ProcessQueuedRequests(); - // rayTime += Util.GetTimeStampMS() - tmpTime; + // rayTime += Util.GetTimeStampMS() - tmpTime; - // tmpTime = Util.GetTimeStampMS(); + // tmpTime = Util.GetTimeStampMS(); collision_optimized(); } + // collisionTime += Util.GetTimeStampMS() - tmpTime; // tmpTime = Util.GetTimeStampMS(); @@ -1655,7 +1658,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde } */ // tmpTime = Util.GetTimeStampMS(); - lock (SimulationLock) + //lock (SimulationLock) { lock (_activegroups) { @@ -1664,7 +1667,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde { if (actor.IsPhysical) { - actor.UpdatePositionAndVelocity(framecount); + lock (SimulationLock) + actor.UpdatePositionAndVelocity(framecount); } } } diff --git a/OpenSim/Region/PhysicsModules/ubOdeMeshing/Mesh.cs b/OpenSim/Region/PhysicsModules/ubOdeMeshing/Mesh.cs index 5d2b1f7c32..380cce2ef3 100644 --- a/OpenSim/Region/PhysicsModules/ubOdeMeshing/Mesh.cs +++ b/OpenSim/Region/PhysicsModules/ubOdeMeshing/Mesh.cs @@ -218,7 +218,6 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing m_bdata.m_obbZmax = z; if (z < m_bdata.m_obbZmin) m_bdata.m_obbZmin = z; - } public void Add(Triangle triangle) @@ -324,13 +323,15 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing if (m_bdata.m_vertices == null) throw new NotSupportedException(); float[] result = new float[m_bdata.m_vertices.Count * 3]; + int k = 0; foreach (KeyValuePair kvp in m_bdata.m_vertices) { Vertex v = kvp.Key; int i = kvp.Value; - result[3 * i + 0] = v.X; - result[3 * i + 1] = v.Y; - result[3 * i + 2] = v.Z; + k = 3 * i; + result[k] = v.X; + result[k + 1] = v.Y; + result[k + 2] = v.Z; } return result; } @@ -364,12 +365,14 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing if (m_bdata.m_triangles == null) throw new NotSupportedException(); int[] result = new int[m_bdata.m_triangles.Count * 3]; + int k; for (int i = 0; i < m_bdata.m_triangles.Count; i++) { + k= 3 * i; Triangle t = m_bdata.m_triangles[i]; - result[3 * i + 0] = m_bdata.m_vertices[t.v1]; - result[3 * i + 1] = m_bdata.m_vertices[t.v2]; - result[3 * i + 2] = m_bdata.m_vertices[t.v3]; + result[k] = m_bdata.m_vertices[t.v1]; + result[k + 1] = m_bdata.m_vertices[t.v2]; + result[k + 2] = m_bdata.m_vertices[t.v3]; } return result; } @@ -463,9 +466,9 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing if (v == null) continue; float x, y, z; - x = v.X*matrix[0, 0] + v.Y*matrix[1, 0] + v.Z*matrix[2, 0]; - y = v.X*matrix[0, 1] + v.Y*matrix[1, 1] + v.Z*matrix[2, 1]; - z = v.X*matrix[0, 2] + v.Y*matrix[1, 2] + v.Z*matrix[2, 2]; + x = v.X * matrix[0, 0] + v.Y * matrix[1, 0] + v.Z * matrix[2, 0]; + y = v.X * matrix[0, 1] + v.Y * matrix[1, 1] + v.Z * matrix[2, 1]; + z = v.X * matrix[0, 2] + v.Y * matrix[1, 2] + v.Z * matrix[2, 2]; v.X = x + offset[0]; v.Y = y + offset[1]; v.Z = z + offset[2]; diff --git a/OpenSim/Region/PhysicsModules/ubOdeMeshing/Meshmerizer.cs b/OpenSim/Region/PhysicsModules/ubOdeMeshing/Meshmerizer.cs index 1b2f41a002..6950f2dc2a 100644 --- a/OpenSim/Region/PhysicsModules/ubOdeMeshing/Meshmerizer.cs +++ b/OpenSim/Region/PhysicsModules/ubOdeMeshing/Meshmerizer.cs @@ -945,7 +945,7 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing #endif try { - primMesh.ExtrudeLinear(); + primMesh.Extrude(PathType.Linear); ; } catch (Exception ex) { @@ -978,7 +978,7 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing #endif try { - primMesh.ExtrudeCircular(); + primMesh.Extrude(PathType.Circular); } catch (Exception ex) { diff --git a/OpenSim/Region/PhysicsModules/ubOdeMeshing/PrimMesher.cs b/OpenSim/Region/PhysicsModules/ubOdeMeshing/PrimMesher.cs index 23e87d1742..f3a57d365c 100644 --- a/OpenSim/Region/PhysicsModules/ubOdeMeshing/PrimMesher.cs +++ b/OpenSim/Region/PhysicsModules/ubOdeMeshing/PrimMesher.cs @@ -212,14 +212,34 @@ namespace PrimMesher public static Coord operator *(Coord v, Quat q) { - float rx = q.W * v.X + q.Y * v.Z - q.Z * v.Y; - float ry = q.W * v.Y + q.Z * v.X - q.X * v.Z; - float rz = q.W * v.Z + q.X * v.Y - q.Y * v.X; + float x = q.X; + float y = q.Y; + float x2 = x + x; + float z = q.Z; + float y2 = y + y; + float w = q.W; + float z2 = z + z; + + float zz2 = z * z2; + + float xx2 = x * x2; + float xy2 = x * y2; + float xz2 = x * z2; + z = v.Z; + + float yy2 = y * y2; + float yz2 = y * z2; + x = v.X; + + float wx2 = w * x2; + float wy2 = w * y2; + float wz2 = w * z2; + y = v.Y; return new Coord( - 2.0f * (rz * q.Y - ry * q.Z) + v.X, - 2.0f * (rx * q.Z - rz * q.X) + v.Y, - 2.0f * (ry * q.X - rx * q.Y) + v.Z ); + x * (1.0f - yy2 - zz2) + y * (xy2 - wz2) + z * (xz2 + wy2), + x * (xy2 + wz2) + y * (1.0f - xx2 - zz2) + z * (yz2 - wx2), + x * (xz2 - wy2) + y * (yz2 + wx2) + z * (1.0f - xx2 - yy2)); } } @@ -248,9 +268,9 @@ namespace PrimMesher internal float X; internal float Y; - internal Angle(float angle, float x, float y) + internal Angle(float _angle, float x, float y) { - this.angle = angle; // 1 is 2pi + angle = _angle; // 1 is 2pi X = x; // cos Y = y; // sin } @@ -359,8 +379,8 @@ namespace PrimMesher { angles = new List(); - const float twoPi = (float)(Math.PI * 2.0); - const float twoPiInv = (float)(0.5 / Math.PI); + const float twoPi = 2.0f * (float)Math.PI; + const float twoPiInv = 0.5f / (float)Math.PI; if (sides < 1) throw new Exception("number of sides not greater than zero"); @@ -479,7 +499,7 @@ namespace PrimMesher /// public class Profile { - private const float twoPi = (float)(2.0 * Math.PI); + private const float twoPi = 2.0f * (float)Math.PI; public string errorMessage = null; @@ -533,7 +553,6 @@ namespace PrimMesher try { angles.makeAngles(sides, startAngle, stopAngle,hasProfileCut); } catch (Exception ex) { - errorMessage = "makeAngles failed: Exception: " + ex.ToString() + "\nsides: " + sides.ToString() + " startAngle: " + startAngle.ToString() + " stopAngle: " + stopAngle.ToString(); @@ -791,7 +810,6 @@ namespace PrimMesher } } - hollowCoords = null; } @@ -833,7 +851,7 @@ namespace PrimMesher vert.X += x; vert.Y += y; vert.Z += z; - this.coords[i] = vert; + coords[i] = vert; } } @@ -1228,7 +1246,6 @@ namespace PrimMesher get { return hasHollow; } } - /// /// Constructs a PrimMesh object and creates the profile for extrusion. /// @@ -1257,13 +1274,13 @@ namespace PrimMesher profileStart = 0.0f; if (profileEnd > 1.0f) profileEnd = 1.0f; - if (profileEnd < 0.02f) + else if (profileEnd < 0.02f) profileEnd = 0.02f; if (profileStart >= profileEnd) profileStart = profileEnd - 0.02f; if (hollow > 0.99f) hollow = 0.99f; - if (hollow < 0.0f) + else if (hollow < 0.0f) hollow = 0.0f; } @@ -1281,9 +1298,7 @@ namespace PrimMesher float length = pathCutEnd - pathCutBegin; - hasProfileCut = this.profileEnd - this.profileStart < 0.9999f; - - hasHollow = (this.hollow > 0.001f); + hasProfileCut = profileEnd - profileStart < 0.9999f; float twistTotal = twistEnd - twistBegin; float twistTotalAbs = Math.Abs(twistTotal); @@ -1291,6 +1306,8 @@ namespace PrimMesher steps += (int)(twistTotalAbs * 3.66); // dahlia's magic number float hollow = this.hollow; + hasHollow = hollow > 0.001f; + float initialProfileRot = 0.0f; if (pathType == PathType.Circular) @@ -1516,29 +1533,6 @@ namespace PrimMesher // more cleanup will be done at Meshmerizer.cs } - - /// - /// DEPRICATED - use Extrude(PathType.Linear) instead - /// Extrudes a profile along a straight line path. Used for prim types box, cylinder, and prism. - /// - /// - public void ExtrudeLinear() - { - Extrude(PathType.Linear); - } - - - /// - /// DEPRICATED - use Extrude(PathType.Circular) instead - /// Extrude a profile into a circular path prim mesh. Used for prim types torus, tube, and ring. - /// - /// - public void ExtrudeCircular() - { - Extrude(PathType.Circular); - } - - private Coord SurfaceNormal(Coord c1, Coord c2, Coord c3) { Coord edge1 = new Coord(c2.X - c1.X, c2.Y - c1.Y, c2.Z - c1.Z); @@ -1553,7 +1547,7 @@ namespace PrimMesher private Coord SurfaceNormal(Face face) { - return SurfaceNormal(this.coords[face.v1], this.coords[face.v2], this.coords[face.v3]); + return SurfaceNormal(coords[face.v1], coords[face.v2], coords[face.v3]); } /// @@ -1563,11 +1557,11 @@ namespace PrimMesher /// public Coord SurfaceNormal(int faceIndex) { - int numFaces = this.faces.Count; + int numFaces = faces.Count; if (faceIndex < 0 || faceIndex >= numFaces) throw new Exception("faceIndex out of range"); - return SurfaceNormal(this.faces[faceIndex]); + return SurfaceNormal(faces[faceIndex]); } /// @@ -1612,16 +1606,16 @@ namespace PrimMesher public void AddPos(float x, float y, float z) { int i; - int numVerts = this.coords.Count; + int numVerts = coords.Count; Coord vert; for (i = 0; i < numVerts; i++) { - vert = this.coords[i]; + vert = coords[i]; vert.X += x; vert.Y += y; vert.Z += z; - this.coords[i] = vert; + coords[i] = vert; } } @@ -1632,19 +1626,12 @@ namespace PrimMesher public void AddRot(Quat q) { int i; - int numVerts = this.coords.Count; + int numVerts = coords.Count; for (i = 0; i < numVerts; i++) - this.coords[i] *= q; + coords[i] *= q; } -#if VERTEX_INDEXER - public VertexIndexer GetVertexIndexer() - { - return null; - } -#endif - /// /// Scales the mesh /// @@ -1659,7 +1646,7 @@ namespace PrimMesher Coord m = new Coord(x, y, z); for (i = 0; i < numVerts; i++) - this.coords[i] *= m; + coords[i] *= m; } /// @@ -1674,18 +1661,15 @@ namespace PrimMesher return; String fileName = name + "_" + title + ".raw"; String completePath = System.IO.Path.Combine(path, fileName); - StreamWriter sw = new StreamWriter(completePath); - - for (int i = 0; i < this.faces.Count; i++) + using (StreamWriter sw = new StreamWriter(completePath)) { - string s = this.coords[this.faces[i].v1].ToString(); - s += " " + this.coords[this.faces[i].v2].ToString(); - s += " " + this.coords[this.faces[i].v3].ToString(); - - sw.WriteLine(s); + for (int i = 0; i < this.faces.Count; i++) + { + sw.Write(coords[faces[i].v1].ToString()); + sw.Write(coords[faces[i].v2].ToString()); + sw.WriteLine(coords[faces[i].v3].ToString()); + } } - - sw.Close(); } } } diff --git a/OpenSim/Region/PhysicsModules/ubOdeMeshing/SculptMesh.cs b/OpenSim/Region/PhysicsModules/ubOdeMeshing/SculptMesh.cs index bc1375bda7..184221da3f 100644 --- a/OpenSim/Region/PhysicsModules/ubOdeMeshing/SculptMesh.cs +++ b/OpenSim/Region/PhysicsModules/ubOdeMeshing/SculptMesh.cs @@ -165,8 +165,8 @@ namespace PrimMesher f2 = new Face(p1, p4, p2); } - this.faces.Add(f1); - this.faces.Add(f2); + faces.Add(f1); + faces.Add(f2); } } } @@ -203,18 +203,15 @@ namespace PrimMesher return; String fileName = name + "_" + title + ".raw"; String completePath = System.IO.Path.Combine(path, fileName); - StreamWriter sw = new StreamWriter(completePath); - - for (int i = 0; i < this.faces.Count; i++) + using(StreamWriter sw = new StreamWriter(completePath)) { - string s = this.coords[this.faces[i].v1].ToString(); - s += " " + this.coords[this.faces[i].v2].ToString(); - s += " " + this.coords[this.faces[i].v3].ToString(); - - sw.WriteLine(s); + for (int i = 0; i < faces.Count; i++) + { + sw.Write(coords[faces[i].v1].ToString()); + sw.Write(coords[faces[i].v2].ToString()); + sw.WriteLine(coords[faces[i].v3].ToString()); + } } - - sw.Close(); } } }