aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorMelanie2009-09-01 02:17:08 +0100
committerMelanie2009-09-01 02:17:08 +0100
commitc89fc36f28cc37210e8b2e9ccaa302a2ceae3c73 (patch)
tree1779a76f3ffd0be50762cfee06a56fe34f9feecd
parentBaad git, baad baad git. (diff)
downloadopensim-SC_OLD-c89fc36f28cc37210e8b2e9ccaa302a2ceae3c73.zip
opensim-SC_OLD-c89fc36f28cc37210e8b2e9ccaa302a2ceae3c73.tar.gz
opensim-SC_OLD-c89fc36f28cc37210e8b2e9ccaa302a2ceae3c73.tar.bz2
opensim-SC_OLD-c89fc36f28cc37210e8b2e9ccaa302a2ceae3c73.tar.xz
Applying Mantis #4079. Thank you, dslake
-rw-r--r--OpenSim/Region/Physics/Meshing/Mesh.cs111
-rw-r--r--OpenSim/Region/Physics/Meshing/Meshmerizer.cs55
2 files changed, 57 insertions, 109 deletions
diff --git a/OpenSim/Region/Physics/Meshing/Mesh.cs b/OpenSim/Region/Physics/Meshing/Mesh.cs
index 1134c63..b19cf70 100644
--- a/OpenSim/Region/Physics/Meshing/Mesh.cs
+++ b/OpenSim/Region/Physics/Meshing/Mesh.cs
@@ -36,8 +36,8 @@ namespace OpenSim.Region.Physics.Meshing
36{ 36{
37 public class Mesh : IMesh 37 public class Mesh : IMesh
38 { 38 {
39 public List<Vertex> vertices; 39 private Dictionary<Vertex, int> vertices;
40 public List<Triangle> triangles; 40 private List<Triangle> triangles;
41 GCHandle pinnedVirtexes; 41 GCHandle pinnedVirtexes;
42 GCHandle pinnedIndex; 42 GCHandle pinnedIndex;
43 public PrimMesh primMesh = null; 43 public PrimMesh primMesh = null;
@@ -45,7 +45,7 @@ namespace OpenSim.Region.Physics.Meshing
45 45
46 public Mesh() 46 public Mesh()
47 { 47 {
48 vertices = new List<Vertex>(); 48 vertices = new Dictionary<Vertex, int>();
49 triangles = new List<Triangle>(); 49 triangles = new List<Triangle>();
50 } 50 }
51 51
@@ -53,23 +53,9 @@ namespace OpenSim.Region.Physics.Meshing
53 { 53 {
54 Mesh result = new Mesh(); 54 Mesh result = new Mesh();
55 55
56 foreach (Vertex v in vertices)
57 {
58 if (v == null)
59 result.vertices.Add(null);
60 else
61 result.vertices.Add(v.Clone());
62 }
63
64 foreach (Triangle t in triangles) 56 foreach (Triangle t in triangles)
65 { 57 {
66 int iV1, iV2, iV3; 58 result.Add(new Triangle(t.v1.Clone(), t.v2.Clone(), t.v3.Clone()));
67 iV1 = vertices.IndexOf(t.v1);
68 iV2 = vertices.IndexOf(t.v2);
69 iV3 = vertices.IndexOf(t.v3);
70
71 Triangle newT = new Triangle(result.vertices[iV1], result.vertices[iV2], result.vertices[iV3]);
72 result.Add(newT);
73 } 59 }
74 60
75 return result; 61 return result;
@@ -77,52 +63,17 @@ namespace OpenSim.Region.Physics.Meshing
77 63
78 public void Add(Triangle triangle) 64 public void Add(Triangle triangle)
79 { 65 {
80 int i; 66 // If a vertex of the triangle is not yet in the vertices list,
81 i = vertices.IndexOf(triangle.v1); 67 // add it and set its index to the current index count
82 if (i < 0) 68 if( !vertices.ContainsKey(triangle.v1) )
83 throw new ArgumentException("Vertex v1 not known to mesh"); 69 vertices[triangle.v1] = vertices.Count;
84 i = vertices.IndexOf(triangle.v2); 70 if (!vertices.ContainsKey(triangle.v2))
85 if (i < 0) 71 vertices[triangle.v2] = vertices.Count;
86 throw new ArgumentException("Vertex v2 not known to mesh"); 72 if (!vertices.ContainsKey(triangle.v3))
87 i = vertices.IndexOf(triangle.v3); 73 vertices[triangle.v3] = vertices.Count;
88 if (i < 0)
89 throw new ArgumentException("Vertex v3 not known to mesh");
90
91 triangles.Add(triangle); 74 triangles.Add(triangle);
92 } 75 }
93 76
94 public void Add(Vertex v)
95 {
96 vertices.Add(v);
97 }
98
99 public void Remove(Vertex v)
100 {
101 int i;
102
103 // First, remove all triangles that are build on v
104 for (i = 0; i < triangles.Count; i++)
105 {
106 Triangle t = triangles[i];
107 if (t.v1 == v || t.v2 == v || t.v3 == v)
108 {
109 triangles.RemoveAt(i);
110 i--;
111 }
112 }
113
114 // Second remove v itself
115 vertices.Remove(v);
116 }
117
118 public void Add(List<Vertex> lv)
119 {
120 foreach (Vertex v in lv)
121 {
122 vertices.Add(v);
123 }
124 }
125
126 public void CalcNormals() 77 public void CalcNormals()
127 { 78 {
128 int iTriangles = triangles.Count; 79 int iTriangles = triangles.Count;
@@ -188,7 +139,7 @@ namespace OpenSim.Region.Physics.Meshing
188 public List<PhysicsVector> getVertexList() 139 public List<PhysicsVector> getVertexList()
189 { 140 {
190 List<PhysicsVector> result = new List<PhysicsVector>(); 141 List<PhysicsVector> result = new List<PhysicsVector>();
191 foreach (Vertex v in vertices) 142 foreach (Vertex v in vertices.Keys)
192 { 143 {
193 result.Add(v); 144 result.Add(v);
194 } 145 }
@@ -201,12 +152,13 @@ namespace OpenSim.Region.Physics.Meshing
201 152
202 if (primMesh == null) 153 if (primMesh == null)
203 { 154 {
155 //m_log.WarnFormat("vertices.Count = {0}", vertices.Count);
204 result = new float[vertices.Count * 3]; 156 result = new float[vertices.Count * 3];
205 for (int i = 0; i < vertices.Count; i++) 157 foreach(KeyValuePair<Vertex, int> kvp in vertices)
206 { 158 {
207 Vertex v = vertices[i]; 159 Vertex v = kvp.Key;
208 if (v == null) 160 int i = kvp.Value;
209 continue; 161 //m_log.WarnFormat("kvp.Value = {0}", i);
210 result[3 * i + 0] = v.X; 162 result[3 * i + 0] = v.X;
211 result[3 * i + 1] = v.Y; 163 result[3 * i + 1] = v.Y;
212 result[3 * i + 2] = v.Z; 164 result[3 * i + 2] = v.Z;
@@ -243,9 +195,9 @@ namespace OpenSim.Region.Physics.Meshing
243 for (int i = 0; i < triangles.Count; i++) 195 for (int i = 0; i < triangles.Count; i++)
244 { 196 {
245 Triangle t = triangles[i]; 197 Triangle t = triangles[i];
246 result[3 * i + 0] = vertices.IndexOf(t.v1); 198 result[3 * i + 0] = vertices[t.v1];
247 result[3 * i + 1] = vertices.IndexOf(t.v2); 199 result[3 * i + 1] = vertices[t.v2];
248 result[3 * i + 2] = vertices.IndexOf(t.v3); 200 result[3 * i + 2] = vertices[t.v3];
249 } 201 }
250 } 202 }
251 else 203 else
@@ -298,27 +250,17 @@ namespace OpenSim.Region.Physics.Meshing
298 250
299 public void Append(IMesh newMesh) 251 public void Append(IMesh newMesh)
300 { 252 {
301 Mesh newMesh2; 253 if (!(newMesh is Mesh))
302 if (newMesh is Mesh)
303 {
304 newMesh2 = (Mesh)newMesh;
305 }
306 else
307 {
308 return; 254 return;
309 }
310 255
311 foreach (Vertex v in newMesh2.vertices) 256 foreach (Triangle t in ((Mesh)newMesh).triangles)
312 vertices.Add(v);
313
314 foreach (Triangle t in newMesh2.triangles)
315 Add(t); 257 Add(t);
316 } 258 }
317 259
318 // Do a linear transformation of mesh. 260 // Do a linear transformation of mesh.
319 public void TransformLinear(float[,] matrix, float[] offset) 261 public void TransformLinear(float[,] matrix, float[] offset)
320 { 262 {
321 foreach (Vertex v in vertices) 263 foreach (Vertex v in vertices.Keys)
322 { 264 {
323 if (v == null) 265 if (v == null)
324 continue; 266 continue;
@@ -346,5 +288,10 @@ namespace OpenSim.Region.Physics.Meshing
346 } 288 }
347 sw.Close(); 289 sw.Close();
348 } 290 }
291
292 public void TrimExcess()
293 {
294 triangles.TrimExcess();
295 }
349 } 296 }
350} 297}
diff --git a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs
index 85c526b..7b3f8f2 100644
--- a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs
+++ b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs
@@ -92,40 +92,40 @@ namespace OpenSim.Region.Physics.Meshing
92 private static Mesh CreateSimpleBoxMesh(float minX, float maxX, float minY, float maxY, float minZ, float maxZ) 92 private static Mesh CreateSimpleBoxMesh(float minX, float maxX, float minY, float maxY, float minZ, float maxZ)
93 { 93 {
94 Mesh box = new Mesh(); 94 Mesh box = new Mesh();
95 95 List<Vertex> vertices = new List<Vertex>();
96 // bottom 96 // bottom
97 97
98 box.Add(new Vertex(minX, maxY, minZ)); 98 vertices.Add(new Vertex(minX, maxY, minZ));
99 box.Add(new Vertex(maxX, maxY, minZ)); 99 vertices.Add(new Vertex(maxX, maxY, minZ));
100 box.Add(new Vertex(maxX, minY, minZ)); 100 vertices.Add(new Vertex(maxX, minY, minZ));
101 box.Add(new Vertex(minX, minY, minZ)); 101 vertices.Add(new Vertex(minX, minY, minZ));
102 102
103 box.Add(new Triangle(box.vertices[0], box.vertices[1], box.vertices[2])); 103 box.Add(new Triangle(vertices[0], vertices[1], vertices[2]));
104 box.Add(new Triangle(box.vertices[0], box.vertices[2], box.vertices[3])); 104 box.Add(new Triangle(vertices[0], vertices[2], vertices[3]));
105 105
106 // top 106 // top
107 107
108 box.Add(new Vertex(maxX, maxY, maxZ)); 108 vertices.Add(new Vertex(maxX, maxY, maxZ));
109 box.Add(new Vertex(minX, maxY, maxZ)); 109 vertices.Add(new Vertex(minX, maxY, maxZ));
110 box.Add(new Vertex(minX, minY, maxZ)); 110 vertices.Add(new Vertex(minX, minY, maxZ));
111 box.Add(new Vertex(maxX, minY, maxZ)); 111 vertices.Add(new Vertex(maxX, minY, maxZ));
112 112
113 box.Add(new Triangle(box.vertices[4], box.vertices[5], box.vertices[6])); 113 box.Add(new Triangle(vertices[4], vertices[5], vertices[6]));
114 box.Add(new Triangle(box.vertices[4], box.vertices[6], box.vertices[7])); 114 box.Add(new Triangle(vertices[4], vertices[6], vertices[7]));
115 115
116 // sides 116 // sides
117 117
118 box.Add(new Triangle(box.vertices[5], box.vertices[0], box.vertices[3])); 118 box.Add(new Triangle(vertices[5], vertices[0], vertices[3]));
119 box.Add(new Triangle(box.vertices[5], box.vertices[3], box.vertices[6])); 119 box.Add(new Triangle(vertices[5], vertices[3], vertices[6]));
120 120
121 box.Add(new Triangle(box.vertices[1], box.vertices[0], box.vertices[5])); 121 box.Add(new Triangle(vertices[1], vertices[0], vertices[5]));
122 box.Add(new Triangle(box.vertices[1], box.vertices[5], box.vertices[4])); 122 box.Add(new Triangle(vertices[1], vertices[5], vertices[4]));
123 123
124 box.Add(new Triangle(box.vertices[7], box.vertices[1], box.vertices[4])); 124 box.Add(new Triangle(vertices[7], vertices[1], vertices[4]));
125 box.Add(new Triangle(box.vertices[7], box.vertices[2], box.vertices[1])); 125 box.Add(new Triangle(vertices[7], vertices[2], vertices[1]));
126 126
127 box.Add(new Triangle(box.vertices[3], box.vertices[2], box.vertices[7])); 127 box.Add(new Triangle(vertices[3], vertices[2], vertices[7]));
128 box.Add(new Triangle(box.vertices[3], box.vertices[7], box.vertices[6])); 128 box.Add(new Triangle(vertices[3], vertices[7], vertices[6]));
129 129
130 return box; 130 return box;
131 } 131 }
@@ -145,7 +145,7 @@ namespace OpenSim.Region.Physics.Meshing
145 float minZ = float.MaxValue; 145 float minZ = float.MaxValue;
146 float maxZ = float.MinValue; 146 float maxZ = float.MinValue;
147 147
148 foreach (Vertex v in meshIn.vertices) 148 foreach (Vertex v in meshIn.getVertexList())
149 { 149 {
150 if (v != null) 150 if (v != null)
151 { 151 {
@@ -394,17 +394,19 @@ namespace OpenSim.Region.Physics.Meshing
394 int numCoords = coords.Count; 394 int numCoords = coords.Count;
395 int numFaces = faces.Count; 395 int numFaces = faces.Count;
396 396
397 // Create the list of vertices
398 List<Vertex> vertices = new List<Vertex>();
397 for (int i = 0; i < numCoords; i++) 399 for (int i = 0; i < numCoords; i++)
398 { 400 {
399 Coord c = coords[i]; 401 Coord c = coords[i];
400 mesh.vertices.Add(new Vertex(c.X, c.Y, c.Z)); 402 vertices.Add(new Vertex(c.X, c.Y, c.Z));
401 } 403 }
402 404
403 List<Vertex> vertices = mesh.vertices; 405 // Add the corresponding triangles to the mesh
404 for (int i = 0; i < numFaces; i++) 406 for (int i = 0; i < numFaces; i++)
405 { 407 {
406 Face f = faces[i]; 408 Face f = faces[i];
407 mesh.triangles.Add(new Triangle(vertices[f.v1], vertices[f.v2], vertices[f.v3])); 409 mesh.Add(new Triangle(vertices[f.v1], vertices[f.v2], vertices[f.v3]));
408 } 410 }
409 411
410 return mesh; 412 return mesh;
@@ -438,8 +440,7 @@ namespace OpenSim.Region.Physics.Meshing
438 } 440 }
439 441
440 // trim the vertex and triangle lists to free up memory 442 // trim the vertex and triangle lists to free up memory
441 mesh.vertices.TrimExcess(); 443 mesh.TrimExcess();
442 mesh.triangles.TrimExcess();
443 } 444 }
444 445
445 return mesh; 446 return mesh;