From efd90b56b761219af6425b1c7a2cdd3b6ffb4de2 Mon Sep 17 00:00:00 2001 From: lbsa71 Date: Thu, 27 Dec 2007 21:41:48 +0000 Subject: * Optimized usings * shortened references * Removed redundant 'this' * Normalized EOF --- OpenSim/Region/Physics/Meshing/Extruder.cs | 21 +++-- OpenSim/Region/Physics/Meshing/HelperTypes.cs | 10 +-- OpenSim/Region/Physics/Meshing/Mesh.cs | 42 ++++----- OpenSim/Region/Physics/Meshing/Meshmerizer.cs | 74 ++++++++-------- OpenSim/Region/Physics/Meshing/SimpleHull.cs | 120 +++++++++++++------------- OpenSim/Region/Physics/Meshing/Simplex.cs | 49 +++++------ 6 files changed, 151 insertions(+), 165 deletions(-) (limited to 'OpenSim/Region/Physics/Meshing') diff --git a/OpenSim/Region/Physics/Meshing/Extruder.cs b/OpenSim/Region/Physics/Meshing/Extruder.cs index eecac5a..7ef5b5b 100644 --- a/OpenSim/Region/Physics/Meshing/Extruder.cs +++ b/OpenSim/Region/Physics/Meshing/Extruder.cs @@ -26,24 +26,22 @@ * */ -using System; -using System.Collections.Generic; -using System.Text; +using OpenSim.Region.Physics.Manager; namespace OpenSim.Region.Physics.Meshing { - class Extruder + internal class Extruder { public float startParameter; public float stopParameter; - public Manager.PhysicsVector size; + public PhysicsVector size; public Mesh Extrude(Mesh m) { // Currently only works for iSteps=1; Mesh result = new Mesh(); - Mesh workingPlus = m.Clone(); + Mesh workingPlus = m.Clone(); Mesh workingMinus = m.Clone(); foreach (Vertex v in workingPlus.vertices) @@ -80,14 +78,14 @@ namespace OpenSim.Region.Physics.Meshing for (int i = 0; i < workingPlus.vertices.Count; i++) { int iNext = (i + 1); - + if (workingPlus.vertices[i] == null) // Can't make a simplex here { - iLastNull = i+1; + iLastNull = i + 1; continue; } - if (i == workingPlus.vertices.Count-1) // End of list + if (i == workingPlus.vertices.Count - 1) // End of list { iNext = iLastNull; } @@ -101,11 +99,12 @@ namespace OpenSim.Region.Physics.Meshing tSide = new Triangle(workingPlus.vertices[i], workingMinus.vertices[i], workingPlus.vertices[iNext]); result.Add(tSide); - tSide = new Triangle(workingPlus.vertices[iNext], workingMinus.vertices[i], workingMinus.vertices[iNext]); + tSide = + new Triangle(workingPlus.vertices[iNext], workingMinus.vertices[i], workingMinus.vertices[iNext]); result.Add(tSide); } return result; } } -} +} \ No newline at end of file diff --git a/OpenSim/Region/Physics/Meshing/HelperTypes.cs b/OpenSim/Region/Physics/Meshing/HelperTypes.cs index be82c32..ac06614 100644 --- a/OpenSim/Region/Physics/Meshing/HelperTypes.cs +++ b/OpenSim/Region/Physics/Meshing/HelperTypes.cs @@ -30,9 +30,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; -using OpenSim.Framework.Console; using OpenSim.Region.Physics.Manager; - using OpenSim.Region.Physics.Meshing; public class Vertex : PhysicsVector, IComparable @@ -54,7 +52,7 @@ public class Vertex : PhysicsVector, IComparable public static Vertex FromAngle(double angle) { - return new Vertex((float)Math.Cos(angle), (float)Math.Sin(angle), 0.0f); + return new Vertex((float) Math.Cos(angle), (float) Math.Sin(angle), 0.0f); } @@ -101,6 +99,7 @@ public class Vertex : PhysicsVector, IComparable { return me.CompareTo(other) < 0; } + public String ToRaw() { // Why this stuff with the number formatter? @@ -117,7 +116,6 @@ public class Vertex : PhysicsVector, IComparable return s1; } - } public class Triangle @@ -283,7 +281,7 @@ public class Triangle float l = n.length(); // Normalized "normal" - n = n / l; + n = n/l; return n; } @@ -300,7 +298,7 @@ public class Triangle // debugging purposes public String ToStringRaw() { - String output = v1.ToRaw() + " " + v2.ToRaw() + " " +v3.ToRaw(); + String output = v1.ToRaw() + " " + v2.ToRaw() + " " + v3.ToRaw(); return output; } } \ No newline at end of file diff --git a/OpenSim/Region/Physics/Meshing/Mesh.cs b/OpenSim/Region/Physics/Meshing/Mesh.cs index 2ebfa1c..9c2667e 100644 --- a/OpenSim/Region/Physics/Meshing/Mesh.cs +++ b/OpenSim/Region/Physics/Meshing/Mesh.cs @@ -26,14 +26,11 @@ * */ + using System; -using System.IO; using System.Collections.Generic; -using System.Text; - +using System.IO; using System.Runtime.InteropServices; - - using OpenSim.Region.Physics.Manager; namespace OpenSim.Region.Physics.Meshing @@ -66,9 +63,9 @@ namespace OpenSim.Region.Physics.Meshing foreach (Triangle t in triangles) { int iV1, iV2, iV3; - iV1 = this.vertices.IndexOf(t.v1); - iV2 = this.vertices.IndexOf(t.v2); - iV3 = this.vertices.IndexOf(t.v3); + iV1 = vertices.IndexOf(t.v1); + iV2 = vertices.IndexOf(t.v2); + iV3 = vertices.IndexOf(t.v3); Triangle newT = new Triangle(result.vertices[iV1], result.vertices[iV2], result.vertices[iV3]); result.Add(newT); @@ -77,8 +74,7 @@ namespace OpenSim.Region.Physics.Meshing return result; } - - + public void Add(Triangle triangle) { int i; @@ -160,15 +156,15 @@ namespace OpenSim.Region.Physics.Meshing public float[] getVertexListAsFloatLocked() { - float[] result = new float[vertices.Count * 3]; + float[] result = new float[vertices.Count*3]; for (int i = 0; i < vertices.Count; i++) { Vertex v = vertices[i]; if (v == null) continue; - result[3 * i + 0] = v.X; - result[3 * i + 1] = v.Y; - result[3 * i + 2] = v.Z; + result[3*i + 0] = v.X; + result[3*i + 1] = v.Y; + result[3*i + 2] = v.Z; } GCHandle.Alloc(result, GCHandleType.Pinned); return result; @@ -176,13 +172,13 @@ namespace OpenSim.Region.Physics.Meshing public int[] getIndexListAsInt() { - int[] result = new int[triangles.Count * 3]; + int[] result = new int[triangles.Count*3]; for (int i = 0; i < triangles.Count; i++) { Triangle t = triangles[i]; - result[3 * i + 0] = vertices.IndexOf(t.v1); - result[3 * i + 1] = vertices.IndexOf(t.v2); - result[3 * i + 2] = vertices.IndexOf(t.v3); + result[3*i + 0] = vertices.IndexOf(t.v1); + result[3*i + 1] = vertices.IndexOf(t.v2); + result[3*i + 2] = vertices.IndexOf(t.v3); } return result; } @@ -202,7 +198,6 @@ namespace OpenSim.Region.Physics.Meshing foreach (Triangle t in newMesh.triangles) Add(t); - } // Do a linear transformation of mesh. @@ -213,9 +208,9 @@ namespace OpenSim.Region.Physics.Meshing 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]; @@ -237,5 +232,4 @@ namespace OpenSim.Region.Physics.Meshing sw.Close(); } } - -} +} \ No newline at end of file diff --git a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs index 9c35f81..3217dd8 100644 --- a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs +++ b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs @@ -27,18 +27,13 @@ */ using System; -using System.IO; -using System.Globalization; -using System.Diagnostics; using System.Collections.Generic; -using System.Runtime.InteropServices; using OpenSim.Framework; using OpenSim.Framework.Console; using OpenSim.Region.Physics.Manager; namespace OpenSim.Region.Physics.Meshing { - public class MeshmerizerPlugin : IMeshingPlugin { public MeshmerizerPlugin() @@ -61,10 +56,11 @@ namespace OpenSim.Region.Physics.Meshing // Setting baseDir to a path will enable the dumping of raw files // raw files can be imported by blender so a visual inspection of the results can be done // const string baseDir = "rawFiles"; - const string baseDir = null; + private const string baseDir = null; - static void IntersectionParameterPD(PhysicsVector p1, PhysicsVector r1, PhysicsVector p2, PhysicsVector r2, ref float lambda, ref float mu) - { + private static void IntersectionParameterPD(PhysicsVector p1, PhysicsVector r1, PhysicsVector p2, + PhysicsVector r2, ref float lambda, ref float mu) + { // p1, p2, points on the straight // r1, r2, directional vectors of the straight. Not necessarily of length 1! // note, that l, m can be scaled such, that the range 0..1 is mapped to the area between two points, @@ -88,9 +84,8 @@ namespace OpenSim.Region.Physics.Meshing float p1y = p1.Y; float p2x = p2.X; float p2y = p2.Y; - lambda = (-p2x * r2y + p1x * r2y + (p2y - p1y) * r2x) / denom; - mu = (-p2x * r1y + p1x * r1y + (p2y - p1y) * r1x) / denom; - + lambda = (-p2x*r2y + p1x*r2y + (p2y - p1y)*r2x)/denom; + mu = (-p2x*r1y + p1x*r1y + (p2y - p1y)*r1x)/denom; } private static List FindInfluencedTriangles(List triangles, Vertex v) @@ -105,8 +100,8 @@ namespace OpenSim.Region.Physics.Meshing } return influenced; } - - + + private static void InsertVertices(List vertices, int usedForSeed, List triangles) { // This is a variant of the delaunay algorithm @@ -126,10 +121,10 @@ namespace OpenSim.Region.Physics.Meshing // do not fulfill this condition with respect to the new triangle // Find the triangles that are influenced by the new vertex - Vertex v=vertices[iCurrentVertex]; + Vertex v = vertices[iCurrentVertex]; if (v == null) - continue; // Null is polygon stop marker. Ignore it - List influencedTriangles=FindInfluencedTriangles(triangles, v); + continue; // Null is polygon stop marker. Ignore it + List influencedTriangles = FindInfluencedTriangles(triangles, v); List simplices = new List(); @@ -177,12 +172,11 @@ namespace OpenSim.Region.Physics.Meshing } } } - } - - static Mesh CreateBoxMesh(String primName, PrimitiveBaseShape primShape, PhysicsVector size) - // Builds the z (+ and -) surfaces of a box shaped prim + + private static Mesh CreateBoxMesh(String primName, PrimitiveBaseShape primShape, PhysicsVector size) + // Builds the z (+ and -) surfaces of a box shaped prim { UInt16 hollowFactor = primShape.ProfileHollow; UInt16 profileBegin = primShape.ProfileBegin; @@ -201,7 +195,7 @@ namespace OpenSim.Region.Physics.Meshing Vertex MP = new Vertex(-0.5f, +0.5f, 0.0f); Vertex PP = new Vertex(+0.5f, +0.5f, 0.0f); - Meshing.SimpleHull outerHull = new SimpleHull(); + SimpleHull outerHull = new SimpleHull(); outerHull.AddVertex(MM); outerHull.AddVertex(PM); outerHull.AddVertex(PP); @@ -210,9 +204,10 @@ namespace OpenSim.Region.Physics.Meshing // Deal with cuts now if ((profileBegin != 0) || (profileEnd != 0)) { - double fProfileBeginAngle = profileBegin / 50000.0 * 360.0; // In degree, for easier debugging and understanding - fProfileBeginAngle -= (90.0 + 45.0); // for some reasons, the SL client counts from the corner -X/-Y - double fProfileEndAngle = 360.0 - profileEnd / 50000.0 * 360.0; // Pathend comes as complement to 1.0 + double fProfileBeginAngle = profileBegin/50000.0*360.0; + // In degree, for easier debugging and understanding + fProfileBeginAngle -= (90.0 + 45.0); // for some reasons, the SL client counts from the corner -X/-Y + double fProfileEndAngle = 360.0 - profileEnd/50000.0*360.0; // Pathend comes as complement to 1.0 fProfileEndAngle -= (90.0 + 45.0); if (fProfileBeginAngle < fProfileEndAngle) fProfileEndAngle -= 360.0; @@ -222,20 +217,23 @@ namespace OpenSim.Region.Physics.Meshing // and we approximate this arc by a polygon chain // Also note, that these vectors are of length 1.0 and thus their endpoints lay outside the model space // So it can easily be subtracted from the outer hull - int iSteps = (int)(((fProfileBeginAngle - fProfileEndAngle) / 45.0) + .5); // how many steps do we need with approximately 45 degree - double dStepWidth=(fProfileBeginAngle-fProfileEndAngle)/iSteps; + int iSteps = (int) (((fProfileBeginAngle - fProfileEndAngle)/45.0) + .5); + // how many steps do we need with approximately 45 degree + double dStepWidth = (fProfileBeginAngle - fProfileEndAngle)/iSteps; Vertex origin = new Vertex(0.0f, 0.0f, 0.0f); // Note the sequence of vertices here. It's important to have the other rotational sense than in outerHull SimpleHull cutHull = new SimpleHull(); cutHull.AddVertex(origin); - for (int i=0; i 0) { float hollowFactorF = (float) hollowFactor/(float) 50000; - Vertex IMM = new Vertex(-0.5f * hollowFactorF, -0.5f * hollowFactorF, 0.0f); - Vertex IPM = new Vertex(+0.5f * hollowFactorF, -0.5f * hollowFactorF, 0.0f); - Vertex IMP = new Vertex(-0.5f * hollowFactorF, +0.5f * hollowFactorF, 0.0f); - Vertex IPP = new Vertex(+0.5f * hollowFactorF, +0.5f * hollowFactorF, 0.0f); + Vertex IMM = new Vertex(-0.5f*hollowFactorF, -0.5f*hollowFactorF, 0.0f); + Vertex IPM = new Vertex(+0.5f*hollowFactorF, -0.5f*hollowFactorF, 0.0f); + Vertex IMP = new Vertex(-0.5f*hollowFactorF, +0.5f*hollowFactorF, 0.0f); + Vertex IPP = new Vertex(+0.5f*hollowFactorF, +0.5f*hollowFactorF, 0.0f); SimpleHull holeHull = new SimpleHull(); @@ -263,7 +261,6 @@ namespace OpenSim.Region.Physics.Meshing SimpleHull hollowedHull = SimpleHull.SubtractHull(outerHull, holeHull); outerHull = hollowedHull; - } Mesh m = new Mesh(); @@ -286,7 +283,7 @@ namespace OpenSim.Region.Physics.Meshing m.Remove(Seed2); m.Remove(Seed3); m.DumpRaw(baseDir, primName, "Proto seeds removed"); - + m.RemoveTrianglesOutside(outerHull); m.DumpRaw(baseDir, primName, "Proto outsides removed"); @@ -374,7 +371,7 @@ namespace OpenSim.Region.Physics.Meshing switch (primShape.ProfileShape) { case ProfileShape.Square: - mesh=CreateBoxMesh(primName, primShape, size); + mesh = CreateBoxMesh(primName, primShape, size); CalcNormals(mesh); break; default: @@ -389,5 +386,4 @@ namespace OpenSim.Region.Physics.Meshing return mesh; } } - -} +} \ No newline at end of file diff --git a/OpenSim/Region/Physics/Meshing/SimpleHull.cs b/OpenSim/Region/Physics/Meshing/SimpleHull.cs index a769053..809f3d5 100644 --- a/OpenSim/Region/Physics/Meshing/SimpleHull.cs +++ b/OpenSim/Region/Physics/Meshing/SimpleHull.cs @@ -28,9 +28,8 @@ using System; using System.Collections.Generic; -using System.Text; - using OpenSim.Framework.Console; +using OpenSim.Region.Physics.Manager; namespace OpenSim.Region.Physics.Meshing { @@ -43,17 +42,18 @@ namespace OpenSim.Region.Physics.Meshing // is defined by the hull lies inside or outside the simplex chain public class SimpleHull { - List vertices = new List(); - List holeVertices = new List(); // Only used, when the hull is hollow + private List vertices = new List(); + private List holeVertices = new List(); // Only used, when the hull is hollow // Adds a vertex to the end of the list - public void AddVertex(Vertex v) { + public void AddVertex(Vertex v) + { vertices.Add(v); } - override public String ToString() + public override String ToString() { - String result=""; + String result = ""; foreach (Vertex v in vertices) { result += "b:" + v.ToString() + "\n"; @@ -63,7 +63,8 @@ namespace OpenSim.Region.Physics.Meshing } - public List getVertices() { + public List getVertices() + { List newVertices = new List(); newVertices.AddRange(vertices); @@ -81,27 +82,27 @@ namespace OpenSim.Region.Physics.Meshing result.AddVertex(v.Clone()); } - foreach (Vertex v in this.holeVertices) + foreach (Vertex v in holeVertices) { result.holeVertices.Add(v.Clone()); } - + return result; } public bool IsPointIn(Vertex v1) { - int iCounter=0; - List simplices=buildSimplexList(); + int iCounter = 0; + List simplices = buildSimplexList(); foreach (Simplex s in simplices) { // Send a ray along the positive X-Direction // Note, that this direction must correlate with the "below" interpretation // of handling for the special cases below - Manager.PhysicsVector intersection = s.RayIntersect(v1, new Manager.PhysicsVector(1.0f, 0.0f, 0.0f), true); + PhysicsVector intersection = s.RayIntersect(v1, new PhysicsVector(1.0f, 0.0f, 0.0f), true); if (intersection == null) - continue; // No intersection. Done. More tests to follow otherwise + continue; // No intersection. Done. More tests to follow otherwise // Did we hit the end of a simplex? // Then this can be one of two special cases: @@ -111,19 +112,21 @@ namespace OpenSim.Region.Physics.Meshing // Solution: If the other vertex is "below" the ray, we don't count it // Thus corners pointing down are counted twice, corners pointing up are not counted // borders are counted once - if (intersection.IsIdentical(s.v1, 0.001f)) { + if (intersection.IsIdentical(s.v1, 0.001f)) + { if (s.v2.Y < v1.Y) continue; } // Do this for the other vertex two - if (intersection.IsIdentical(s.v2, 0.001f)) { - if (s.v1.Y buildSimplexList() { - + private List buildSimplexList() + { List result = new List(); // Not asserted but assumed: at least three vertices - for (int i=0; i simple = buildSimplexList(); foreach (Simplex sTest in simple) { - Manager.PhysicsVector vvTemp = Simplex.Intersect(sTest, s, -.001f, -.001f, 0.999f, .999f); - - Vertex vTemp=null; + PhysicsVector vvTemp = Simplex.Intersect(sTest, s, -.001f, -.001f, 0.999f, .999f); + + Vertex vTemp = null; if (vvTemp != null) vTemp = new Vertex(vvTemp); - if (vTemp!=null) { - - Manager.PhysicsVector diff=(s.v1-vTemp); - float distTemp=diff.length(); + if (vTemp != null) + { + PhysicsVector diff = (s.v1 - vTemp); + float distTemp = diff.length(); - if (bestIntersection==null || distTemp many, many intersections + if (z1 == 0.0f) + { +// Means they are identical -> many, many intersections lambda = Single.NaN; mu = Single.NaN; - } else { + } + else + { lambda = Single.PositiveInfinity; mu = Single.PositiveInfinity; } return; - } - - lambda = z1 / denom; - mu = z2 / denom; - + lambda = z1/denom; + mu = z2/denom; } @@ -145,12 +144,12 @@ namespace OpenSim.Region.Physics.Meshing // upperBorder2 : 1.0 // Set these to values near the given parameters (e.g. 0.001 instead of 1 to exclude simplex starts safely, or to -0.001 to include them safely) public static PhysicsVector Intersect( - Simplex s1, - Simplex s2, - float lowerBorder1, - float lowerBorder2, - float upperBorder1, - float upperBorder2) + Simplex s1, + Simplex s2, + float lowerBorder1, + float lowerBorder2, + float upperBorder1, + float upperBorder2) { PhysicsVector firstSimplexDirection = s1.v2 - s1.v1; PhysicsVector secondSimplexDirection = s2.v2 - s2.v1; @@ -181,8 +180,7 @@ namespace OpenSim.Region.Physics.Meshing if (mu > upperBorder2) // outside simplex 2 return null; - return s1.v1 + lambda * firstSimplexDirection; - + return s1.v1 + lambda*firstSimplexDirection; } // Intersects the simplex with a ray. The ray is defined as all p=origin + lambda*direction @@ -212,15 +210,12 @@ namespace OpenSim.Region.Physics.Meshing return null; if (lambda == 1.0 && !bEndsIncluded) - return null; // The end of the simplices are not included + return null; // The end of the simplices are not included if (lambda < 0.0f) // we're before v1; return null; - return this.v1 + lambda * simplexDirection; - + return v1 + lambda*simplexDirection; } - - } } \ No newline at end of file -- cgit v1.1