diff options
author | Melanie | 2009-09-01 02:17:08 +0100 |
---|---|---|
committer | Melanie | 2009-09-01 02:17:08 +0100 |
commit | c89fc36f28cc37210e8b2e9ccaa302a2ceae3c73 (patch) | |
tree | 1779a76f3ffd0be50762cfee06a56fe34f9feecd /OpenSim/Region/Physics/Meshing/Mesh.cs | |
parent | Baad git, baad baad git. (diff) | |
download | opensim-SC-c89fc36f28cc37210e8b2e9ccaa302a2ceae3c73.zip opensim-SC-c89fc36f28cc37210e8b2e9ccaa302a2ceae3c73.tar.gz opensim-SC-c89fc36f28cc37210e8b2e9ccaa302a2ceae3c73.tar.bz2 opensim-SC-c89fc36f28cc37210e8b2e9ccaa302a2ceae3c73.tar.xz |
Applying Mantis #4079. Thank you, dslake
Diffstat (limited to 'OpenSim/Region/Physics/Meshing/Mesh.cs')
-rw-r--r-- | OpenSim/Region/Physics/Meshing/Mesh.cs | 111 |
1 files changed, 29 insertions, 82 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 | } |