aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/OdePlugin/Meshing
diff options
context:
space:
mode:
authorlbsa712007-10-30 09:05:31 +0000
committerlbsa712007-10-30 09:05:31 +0000
commit67e12b95ea7b68f4904a7484d77ecfd787d16d0c (patch)
tree20b00d24c8a7617017960432ec044852e3ad5fa9 /OpenSim/Region/Physics/OdePlugin/Meshing
parent* Deleted .user file (diff)
downloadopensim-SC-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.zip
opensim-SC-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.tar.gz
opensim-SC-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.tar.bz2
opensim-SC-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.tar.xz
* Optimized usings
* Shortened type references * Removed redundant 'this' qualifier
Diffstat (limited to 'OpenSim/Region/Physics/OdePlugin/Meshing')
-rw-r--r--OpenSim/Region/Physics/OdePlugin/Meshing/HelperTypes.cs72
-rw-r--r--OpenSim/Region/Physics/OdePlugin/Meshing/Meshmerizer.cs256
2 files changed, 152 insertions, 176 deletions
diff --git a/OpenSim/Region/Physics/OdePlugin/Meshing/HelperTypes.cs b/OpenSim/Region/Physics/OdePlugin/Meshing/HelperTypes.cs
index 2ace097..13184e2 100644
--- a/OpenSim/Region/Physics/OdePlugin/Meshing/HelperTypes.cs
+++ b/OpenSim/Region/Physics/OdePlugin/Meshing/HelperTypes.cs
@@ -27,10 +27,9 @@
27*/ 27*/
28 28
29using System; 29using System;
30using System.Globalization;
31using System.Diagnostics;
32using System.Collections.Generic; 30using System.Collections.Generic;
33 31using System.Diagnostics;
32using System.Globalization;
34using OpenSim.Region.Physics.Manager; 33using OpenSim.Region.Physics.Manager;
35 34
36public class Vertex : IComparable<Vertex> 35public class Vertex : IComparable<Vertex>
@@ -76,8 +75,6 @@ public class Vertex : IComparable<Vertex>
76 { 75 {
77 return me.CompareTo(other) < 0; 76 return me.CompareTo(other) < 0;
78 } 77 }
79
80
81} 78}
82 79
83public class Simplex : IComparable<Simplex> 80public class Simplex : IComparable<Simplex>
@@ -122,8 +119,7 @@ public class Simplex : IComparable<Simplex>
122 119
123 return 0; 120 return 0;
124 } 121 }
125 122} ;
126};
127 123
128public class Triangle 124public class Triangle
129{ 125{
@@ -131,9 +127,9 @@ public class Triangle
131 public Vertex v2; 127 public Vertex v2;
132 public Vertex v3; 128 public Vertex v3;
133 129
134 float radius_square; 130 private float radius_square;
135 float cx; 131 private float cx;
136 float cy; 132 private float cy;
137 133
138 public Triangle(Vertex _v1, Vertex _v2, Vertex _v3) 134 public Triangle(Vertex _v1, Vertex _v2, Vertex _v3)
139 { 135 {
@@ -149,18 +145,18 @@ public class Triangle
149 float dx, dy; 145 float dx, dy;
150 float dd; 146 float dd;
151 147
152 dx = x - this.cx; 148 dx = x - cx;
153 dy = y - this.cy; 149 dy = y - cy;
154 150
155 dd = dx * dx + dy * dy; 151 dd = dx*dx + dy*dy;
156 if (dd < this.radius_square) 152 if (dd < radius_square)
157 return true; 153 return true;
158 else 154 else
159 return false; 155 return false;
160 } 156 }
161 157
162 158
163 void CalcCircle() 159 private void CalcCircle()
164 { 160 {
165 // Calculate the center and the radius of a circle given by three points p1, p2, p3 161 // Calculate the center and the radius of a circle given by three points p1, p2, p3
166 // It is assumed, that the triangles vertices are already set correctly 162 // It is assumed, that the triangles vertices are already set correctly
@@ -198,8 +194,8 @@ public class Triangle
198 p3y = v3.point.Y; 194 p3y = v3.point.Y;
199 195
200 /* calc helping values first */ 196 /* calc helping values first */
201 c1 = (p1x * p1x + p1y * p1y - p2x * p2x - p2y * p2y) / 2; 197 c1 = (p1x*p1x + p1y*p1y - p2x*p2x - p2y*p2y)/2;
202 c2 = (p1x * p1x + p1y * p1y - p3x * p3x - p3y * p3y) / 2; 198 c2 = (p1x*p1x + p1y*p1y - p3x*p3x - p3y*p3y)/2;
203 199
204 v1x = p1x - p2x; 200 v1x = p1x - p2x;
205 v1y = p1y - p2y; 201 v1y = p1y - p2y;
@@ -207,35 +203,34 @@ public class Triangle
207 v2x = p1x - p3x; 203 v2x = p1x - p3x;
208 v2y = p1y - p3y; 204 v2y = p1y - p3y;
209 205
210 z = (c1 * v2x - c2 * v1x); 206 z = (c1*v2x - c2*v1x);
211 n = (v1y * v2x - v2y * v1x); 207 n = (v1y*v2x - v2y*v1x);
212 208
213 if (n == 0.0) // This is no triangle, i.e there are (at least) two points at the same location 209 if (n == 0.0) // This is no triangle, i.e there are (at least) two points at the same location
214 { 210 {
215 radius_square = 0.0f; 211 radius_square = 0.0f;
216 return; 212 return;
217 } 213 }
218 214
219 this.cy = (float)(z / n); 215 cy = (float) (z/n);
220 216
221 if (v2x != 0.0) 217 if (v2x != 0.0)
222 { 218 {
223 this.cx = (float)((c2 - v2y * this.cy) / v2x); 219 cx = (float) ((c2 - v2y*cy)/v2x);
224 } 220 }
225 else if (v1x != 0.0) 221 else if (v1x != 0.0)
226 { 222 {
227 this.cx = (float)((c1 - v1y * this.cy) / v1x); 223 cx = (float) ((c1 - v1y*cy)/v1x);
228 } 224 }
229 else 225 else
230 { 226 {
231 Debug.Assert(false, "Malformed triangle"); /* Both terms zero means nothing good */ 227 Debug.Assert(false, "Malformed triangle"); /* Both terms zero means nothing good */
232 } 228 }
233 229
234 rx = (p1x - this.cx); 230 rx = (p1x - cx);
235 ry = (p1y - this.cy); 231 ry = (p1y - cy);
236
237 this.radius_square = (float)(rx * rx + ry * ry);
238 232
233 radius_square = (float) (rx*rx + ry*ry);
239 } 234 }
240 235
241 public List<Simplex> GetSimplices() 236 public List<Simplex> GetSimplices()
@@ -254,17 +249,18 @@ public class Triangle
254 249
255 public override String ToString() 250 public override String ToString()
256 { 251 {
257
258 NumberFormatInfo nfi = new NumberFormatInfo(); 252 NumberFormatInfo nfi = new NumberFormatInfo();
259 nfi.CurrencyDecimalDigits = 2; 253 nfi.CurrencyDecimalDigits = 2;
260 nfi.CurrencyDecimalSeparator = "."; 254 nfi.CurrencyDecimalSeparator = ".";
261 255
262 String s1 = "<" + v1.point.X.ToString(nfi) + "," + v1.point.Y.ToString(nfi) + "," + v1.point.Z.ToString(nfi) + ">"; 256 String s1 = "<" + v1.point.X.ToString(nfi) + "," + v1.point.Y.ToString(nfi) + "," + v1.point.Z.ToString(nfi) +
263 String s2 = "<" + v2.point.X.ToString(nfi) + "," + v2.point.Y.ToString(nfi) + "," + v2.point.Z.ToString(nfi) + ">"; 257 ">";
264 String s3 = "<" + v3.point.X.ToString(nfi) + "," + v3.point.Y.ToString(nfi) + "," + v3.point.Z.ToString(nfi) + ">"; 258 String s2 = "<" + v2.point.X.ToString(nfi) + "," + v2.point.Y.ToString(nfi) + "," + v2.point.Z.ToString(nfi) +
259 ">";
260 String s3 = "<" + v3.point.X.ToString(nfi) + "," + v3.point.Y.ToString(nfi) + "," + v3.point.Z.ToString(nfi) +
261 ">";
265 262
266 return s1 + ";" + s2 + ";" + s3; 263 return s1 + ";" + s2 + ";" + s3;
267
268 } 264 }
269 265
270 public PhysicsVector getNormal() 266 public PhysicsVector getNormal()
@@ -281,12 +277,12 @@ public class Triangle
281 // Cross product for normal 277 // Cross product for normal
282 PhysicsVector n = new PhysicsVector(); 278 PhysicsVector n = new PhysicsVector();
283 float nx, ny, nz; 279 float nx, ny, nz;
284 n.X = e1.Y * e2.Z - e1.Z * e2.Y; 280 n.X = e1.Y*e2.Z - e1.Z*e2.Y;
285 n.Y = e1.Z * e2.X - e1.X * e2.Z; 281 n.Y = e1.Z*e2.X - e1.X*e2.Z;
286 n.Z = e1.X * e2.Y - e1.Y * e2.X; 282 n.Z = e1.X*e2.Y - e1.Y*e2.X;
287 283
288 // Length 284 // Length
289 float l = (float)Math.Sqrt(n.X * n.X + n.Y * n.Y + n.Z * n.Z); 285 float l = (float) Math.Sqrt(n.X*n.X + n.Y*n.Y + n.Z*n.Z);
290 286
291 // Normalized "normal" 287 // Normalized "normal"
292 n.X /= l; 288 n.X /= l;
@@ -303,6 +299,4 @@ public class Triangle
303 v1 = v2; 299 v1 = v2;
304 v2 = vt; 300 v2 = vt;
305 } 301 }
306} 302} \ No newline at end of file
307
308
diff --git a/OpenSim/Region/Physics/OdePlugin/Meshing/Meshmerizer.cs b/OpenSim/Region/Physics/OdePlugin/Meshing/Meshmerizer.cs
index dd18e24..46de15e 100644
--- a/OpenSim/Region/Physics/OdePlugin/Meshing/Meshmerizer.cs
+++ b/OpenSim/Region/Physics/OdePlugin/Meshing/Meshmerizer.cs
@@ -27,12 +27,8 @@
27*/ 27*/
28 28
29using System; 29using System;
30using System.Globalization;
31using System.Diagnostics;
32using System.Collections.Generic; 30using System.Collections.Generic;
33using System.Text;
34using System.Runtime.InteropServices; 31using System.Runtime.InteropServices;
35
36using OpenSim.Framework; 32using OpenSim.Framework;
37using OpenSim.Region.Physics.Manager; 33using OpenSim.Region.Physics.Manager;
38 34
@@ -75,14 +71,14 @@ namespace OpenSim.Region.Physics.OdePlugin
75 71
76 public float[] getVertexListAsFloat() 72 public float[] getVertexListAsFloat()
77 { 73 {
78 float[] result = new float[vertices.Count * 3]; 74 float[] result = new float[vertices.Count*3];
79 for (int i = 0; i < vertices.Count; i++) 75 for (int i = 0; i < vertices.Count; i++)
80 { 76 {
81 Vertex v = vertices[i]; 77 Vertex v = vertices[i];
82 PhysicsVector point = v.point; 78 PhysicsVector point = v.point;
83 result[3 * i + 0] = point.X; 79 result[3*i + 0] = point.X;
84 result[3 * i + 1] = point.Y; 80 result[3*i + 1] = point.Y;
85 result[3 * i + 2] = point.Z; 81 result[3*i + 2] = point.Z;
86 } 82 }
87 GCHandle.Alloc(result, GCHandleType.Pinned); 83 GCHandle.Alloc(result, GCHandleType.Pinned);
88 return result; 84 return result;
@@ -90,13 +86,13 @@ namespace OpenSim.Region.Physics.OdePlugin
90 86
91 public int[] getIndexListAsInt() 87 public int[] getIndexListAsInt()
92 { 88 {
93 int[] result = new int[triangles.Count * 3]; 89 int[] result = new int[triangles.Count*3];
94 for (int i = 0; i < triangles.Count; i++) 90 for (int i = 0; i < triangles.Count; i++)
95 { 91 {
96 Triangle t = triangles[i]; 92 Triangle t = triangles[i];
97 result[3 * i + 0] = vertices.IndexOf(t.v1); 93 result[3*i + 0] = vertices.IndexOf(t.v1);
98 result[3 * i + 1] = vertices.IndexOf(t.v2); 94 result[3*i + 1] = vertices.IndexOf(t.v2);
99 result[3 * i + 2] = vertices.IndexOf(t.v3); 95 result[3*i + 2] = vertices.IndexOf(t.v3);
100 } 96 }
101 GCHandle.Alloc(result, GCHandleType.Pinned); 97 GCHandle.Alloc(result, GCHandleType.Pinned);
102 return result; 98 return result;
@@ -110,16 +106,13 @@ namespace OpenSim.Region.Physics.OdePlugin
110 106
111 foreach (Triangle t in newMesh.triangles) 107 foreach (Triangle t in newMesh.triangles)
112 Add(t); 108 Add(t);
113
114 } 109 }
115 } 110 }
116 111
117 112
118
119 public class Meshmerizer 113 public class Meshmerizer
120 { 114 {
121 115 private static List<Triangle> FindInfluencedTriangles(List<Triangle> triangles, Vertex v)
122 static List<Triangle> FindInfluencedTriangles(List<Triangle> triangles, Vertex v)
123 { 116 {
124 List<Triangle> influenced = new List<Triangle>(); 117 List<Triangle> influenced = new List<Triangle>();
125 foreach (Triangle t in triangles) 118 foreach (Triangle t in triangles)
@@ -133,9 +126,10 @@ namespace OpenSim.Region.Physics.OdePlugin
133 } 126 }
134 return influenced; 127 return influenced;
135 } 128 }
136 129
137 130
138 static void InsertVertices(List<Vertex> vertices, int usedForSeed, List<Triangle> triangles, List<int> innerBorders) 131 private static void InsertVertices(List<Vertex> vertices, int usedForSeed, List<Triangle> triangles,
132 List<int> innerBorders)
139 { 133 {
140 // This is a variant of the delaunay algorithm 134 // This is a variant of the delaunay algorithm
141 // each time a new vertex is inserted, all triangles that are influenced by it are deleted 135 // each time a new vertex is inserted, all triangles that are influenced by it are deleted
@@ -143,7 +137,7 @@ namespace OpenSim.Region.Physics.OdePlugin
143 // It is not very time efficient but easy to implement. 137 // It is not very time efficient but easy to implement.
144 138
145 int iCurrentVertex; 139 int iCurrentVertex;
146 int iMaxVertex=vertices.Count; 140 int iMaxVertex = vertices.Count;
147 for (iCurrentVertex = usedForSeed; iCurrentVertex < iMaxVertex; iCurrentVertex++) 141 for (iCurrentVertex = usedForSeed; iCurrentVertex < iMaxVertex; iCurrentVertex++)
148 { 142 {
149 // Background: A triangle mesh fulfills the delaunay condition if (iff!) 143 // Background: A triangle mesh fulfills the delaunay condition if (iff!)
@@ -154,8 +148,8 @@ namespace OpenSim.Region.Physics.OdePlugin
154 // do not fulfill this condition with respect to the new triangle 148 // do not fulfill this condition with respect to the new triangle
155 149
156 // Find the triangles that are influenced by the new vertex 150 // Find the triangles that are influenced by the new vertex
157 Vertex v=vertices[iCurrentVertex]; 151 Vertex v = vertices[iCurrentVertex];
158 List<Triangle> influencedTriangles=FindInfluencedTriangles(triangles, v); 152 List<Triangle> influencedTriangles = FindInfluencedTriangles(triangles, v);
159 153
160 List<Simplex> simplices = new List<Simplex>(); 154 List<Simplex> simplices = new List<Simplex>();
161 155
@@ -175,10 +169,10 @@ namespace OpenSim.Region.Physics.OdePlugin
175 // Look for duplicate simplices here. 169 // Look for duplicate simplices here.
176 // Remember, they are directly side by side in the list right now 170 // Remember, they are directly side by side in the list right now
177 int iSimplex; 171 int iSimplex;
178 List<Simplex> innerSimplices=new List<Simplex>(); 172 List<Simplex> innerSimplices = new List<Simplex>();
179 for (iSimplex = 1; iSimplex < simplices.Count; iSimplex++) // Startindex=1, so we can refer backwards 173 for (iSimplex = 1; iSimplex < simplices.Count; iSimplex++) // Startindex=1, so we can refer backwards
180 { 174 {
181 if (simplices[iSimplex - 1].CompareTo(simplices[iSimplex])==0) 175 if (simplices[iSimplex - 1].CompareTo(simplices[iSimplex]) == 0)
182 { 176 {
183 innerSimplices.Add(simplices[iSimplex - 1]); 177 innerSimplices.Add(simplices[iSimplex - 1]);
184 innerSimplices.Add(simplices[iSimplex]); 178 innerSimplices.Add(simplices[iSimplex]);
@@ -187,7 +181,7 @@ namespace OpenSim.Region.Physics.OdePlugin
187 181
188 foreach (Simplex s in innerSimplices) 182 foreach (Simplex s in innerSimplices)
189 { 183 {
190 simplices.Remove(s); 184 simplices.Remove(s);
191 } 185 }
192 186
193 // each simplex still in the list belongs to the hull of the region in question 187 // each simplex still in the list belongs to the hull of the region in question
@@ -210,7 +204,7 @@ namespace OpenSim.Region.Physics.OdePlugin
210 foreach (Triangle t in triangles) 204 foreach (Triangle t in triangles)
211 { 205 {
212 if ( 206 if (
213 innerBorders.Contains(vertices.IndexOf(t.v1)) 207 innerBorders.Contains(vertices.IndexOf(t.v1))
214 && innerBorders.Contains(vertices.IndexOf(t.v2)) 208 && innerBorders.Contains(vertices.IndexOf(t.v2))
215 && innerBorders.Contains(vertices.IndexOf(t.v3)) 209 && innerBorders.Contains(vertices.IndexOf(t.v3))
216 ) 210 )
@@ -223,18 +217,18 @@ namespace OpenSim.Region.Physics.OdePlugin
223 } 217 }
224 218
225 219
226 static Mesh CreateBoxMeshX(PrimitiveBaseShape primShape, PhysicsVector size) 220 private static Mesh CreateBoxMeshX(PrimitiveBaseShape primShape, PhysicsVector size)
227 // Builds the x (+ and -) surfaces of a box shaped prim 221 // Builds the x (+ and -) surfaces of a box shaped prim
228 { 222 {
229 UInt16 hollowFactor = primShape.ProfileHollow; 223 UInt16 hollowFactor = primShape.ProfileHollow;
230 Mesh meshMX = new Mesh(); 224 Mesh meshMX = new Mesh();
231 225
232 226
233 // Surface 0, -X 227 // Surface 0, -X
234 meshMX.Add(new Vertex("-X-Y-Z", -size.X / 2.0f, -size.Y / 2.0f, -size.Z / 2.0f)); 228 meshMX.Add(new Vertex("-X-Y-Z", -size.X/2.0f, -size.Y/2.0f, -size.Z/2.0f));
235 meshMX.Add(new Vertex("-X+Y-Z", -size.X / 2.0f, +size.Y / 2.0f, -size.Z / 2.0f)); 229 meshMX.Add(new Vertex("-X+Y-Z", -size.X/2.0f, +size.Y/2.0f, -size.Z/2.0f));
236 meshMX.Add(new Vertex("-X-Y+Z", -size.X / 2.0f, -size.Y / 2.0f, +size.Z / 2.0f)); 230 meshMX.Add(new Vertex("-X-Y+Z", -size.X/2.0f, -size.Y/2.0f, +size.Z/2.0f));
237 meshMX.Add(new Vertex("-X+Y+Z", -size.X / 2.0f, +size.Y / 2.0f, +size.Z / 2.0f)); 231 meshMX.Add(new Vertex("-X+Y+Z", -size.X/2.0f, +size.Y/2.0f, +size.Z/2.0f));
238 232
239 meshMX.Add(new Triangle(meshMX.vertices[0], meshMX.vertices[2], meshMX.vertices[1])); 233 meshMX.Add(new Triangle(meshMX.vertices[0], meshMX.vertices[2], meshMX.vertices[1]));
240 meshMX.Add(new Triangle(meshMX.vertices[1], meshMX.vertices[2], meshMX.vertices[3])); 234 meshMX.Add(new Triangle(meshMX.vertices[1], meshMX.vertices[2], meshMX.vertices[3]));
@@ -242,10 +236,10 @@ namespace OpenSim.Region.Physics.OdePlugin
242 236
243 Mesh meshPX = new Mesh(); 237 Mesh meshPX = new Mesh();
244 // Surface 1, +X 238 // Surface 1, +X
245 meshPX.Add(new Vertex("+X-Y-Z", +size.X / 2.0f, -size.Y / 2.0f, -size.Z / 2.0f)); 239 meshPX.Add(new Vertex("+X-Y-Z", +size.X/2.0f, -size.Y/2.0f, -size.Z/2.0f));
246 meshPX.Add(new Vertex("+X+Y-Z", +size.X / 2.0f, +size.Y / 2.0f, -size.Z / 2.0f)); 240 meshPX.Add(new Vertex("+X+Y-Z", +size.X/2.0f, +size.Y/2.0f, -size.Z/2.0f));
247 meshPX.Add(new Vertex("+X-Y+Z", +size.X / 2.0f, -size.Y / 2.0f, +size.Z / 2.0f)); 241 meshPX.Add(new Vertex("+X-Y+Z", +size.X/2.0f, -size.Y/2.0f, +size.Z/2.0f));
248 meshPX.Add(new Vertex("+X+Y+Z", +size.X / 2.0f, +size.Y / 2.0f, +size.Z / 2.0f)); 242 meshPX.Add(new Vertex("+X+Y+Z", +size.X/2.0f, +size.Y/2.0f, +size.Z/2.0f));
249 243
250 244
251 meshPX.Add(new Triangle(meshPX.vertices[0], meshPX.vertices[1], meshPX.vertices[2])); 245 meshPX.Add(new Triangle(meshPX.vertices[0], meshPX.vertices[1], meshPX.vertices[2]));
@@ -254,17 +248,17 @@ namespace OpenSim.Region.Physics.OdePlugin
254 248
255 if (hollowFactor > 0) 249 if (hollowFactor > 0)
256 { 250 {
257 float hollowFactorF = (float)hollowFactor / (float)50000; 251 float hollowFactorF = (float) hollowFactor/(float) 50000;
258 252
259 Vertex IPP; 253 Vertex IPP;
260 Vertex IPM; 254 Vertex IPM;
261 Vertex IMP; 255 Vertex IMP;
262 Vertex IMM; 256 Vertex IMM;
263 257
264 IPP = new Vertex("Inner-X+Y+Z", -size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, +size.Z / 2.0f); 258 IPP = new Vertex("Inner-X+Y+Z", -size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, +size.Z/2.0f);
265 IPM = new Vertex("Inner-X+Y-Z", -size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, -size.Z / 2.0f); 259 IPM = new Vertex("Inner-X+Y-Z", -size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, -size.Z/2.0f);
266 IMP = new Vertex("Inner-X-Y+Z", -size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, +size.Z / 2.0f); 260 IMP = new Vertex("Inner-X-Y+Z", -size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, +size.Z/2.0f);
267 IMM = new Vertex("Inner-X-Y-Z", -size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, -size.Z / 2.0f); 261 IMM = new Vertex("Inner-X-Y-Z", -size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, -size.Z/2.0f);
268 262
269 meshMX.Add(IPP); 263 meshMX.Add(IPP);
270 meshMX.Add(IPM); 264 meshMX.Add(IPM);
@@ -280,11 +274,10 @@ namespace OpenSim.Region.Physics.OdePlugin
280 } 274 }
281 275
282 276
283 277 IPP = new Vertex("Inner+X+Y+Z", +size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, +size.Z/2.0f);
284 IPP = new Vertex("Inner+X+Y+Z", +size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, +size.Z / 2.0f); 278 IPM = new Vertex("Inner+X+Y-Z", +size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, -size.Z/2.0f);
285 IPM = new Vertex("Inner+X+Y-Z", +size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, -size.Z / 2.0f); 279 IMP = new Vertex("Inner+X-Y+Z", +size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, +size.Z/2.0f);
286 IMP = new Vertex("Inner+X-Y+Z", +size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, +size.Z / 2.0f); 280 IMM = new Vertex("Inner+X-Y-Z", +size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, -size.Z/2.0f);
287 IMM = new Vertex("Inner+X-Y-Z", +size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, -size.Z / 2.0f);
288 281
289 meshPX.Add(IPP); 282 meshPX.Add(IPP);
290 meshPX.Add(IPM); 283 meshPX.Add(IPM);
@@ -308,18 +301,17 @@ namespace OpenSim.Region.Physics.OdePlugin
308 } 301 }
309 302
310 303
311 304 private static Mesh CreateBoxMeshY(PrimitiveBaseShape primShape, PhysicsVector size)
312 static Mesh CreateBoxMeshY(PrimitiveBaseShape primShape, PhysicsVector size) 305 // Builds the y (+ and -) surfaces of a box shaped prim
313 // Builds the y (+ and -) surfaces of a box shaped prim
314 { 306 {
315 UInt16 hollowFactor = primShape.ProfileHollow; 307 UInt16 hollowFactor = primShape.ProfileHollow;
316 308
317 // (M)inus Y 309 // (M)inus Y
318 Mesh MeshMY = new Mesh(); 310 Mesh MeshMY = new Mesh();
319 MeshMY.Add(new Vertex("-X-Y-Z", -size.X / 2.0f, -size.Y / 2.0f, -size.Z / 2.0f)); 311 MeshMY.Add(new Vertex("-X-Y-Z", -size.X/2.0f, -size.Y/2.0f, -size.Z/2.0f));
320 MeshMY.Add(new Vertex("+X-Y-Z", +size.X / 2.0f, -size.Y / 2.0f, -size.Z / 2.0f)); 312 MeshMY.Add(new Vertex("+X-Y-Z", +size.X/2.0f, -size.Y/2.0f, -size.Z/2.0f));
321 MeshMY.Add(new Vertex("-X-Y+Z", -size.X / 2.0f, -size.Y / 2.0f, +size.Z / 2.0f)); 313 MeshMY.Add(new Vertex("-X-Y+Z", -size.X/2.0f, -size.Y/2.0f, +size.Z/2.0f));
322 MeshMY.Add(new Vertex("+X-Y+Z", +size.X / 2.0f, -size.Y / 2.0f, +size.Z / 2.0f)); 314 MeshMY.Add(new Vertex("+X-Y+Z", +size.X/2.0f, -size.Y/2.0f, +size.Z/2.0f));
323 315
324 MeshMY.Add(new Triangle(MeshMY.vertices[0], MeshMY.vertices[1], MeshMY.vertices[2])); 316 MeshMY.Add(new Triangle(MeshMY.vertices[0], MeshMY.vertices[1], MeshMY.vertices[2]));
325 MeshMY.Add(new Triangle(MeshMY.vertices[2], MeshMY.vertices[1], MeshMY.vertices[3])); 317 MeshMY.Add(new Triangle(MeshMY.vertices[2], MeshMY.vertices[1], MeshMY.vertices[3]));
@@ -327,27 +319,27 @@ namespace OpenSim.Region.Physics.OdePlugin
327 // (P)lus Y 319 // (P)lus Y
328 Mesh MeshPY = new Mesh(); 320 Mesh MeshPY = new Mesh();
329 321
330 MeshPY.Add(new Vertex("-X+Y-Z", -size.X / 2.0f, +size.Y / 2.0f, -size.Z / 2.0f)); 322 MeshPY.Add(new Vertex("-X+Y-Z", -size.X/2.0f, +size.Y/2.0f, -size.Z/2.0f));
331 MeshPY.Add(new Vertex("+X+Y-Z", +size.X / 2.0f, +size.Y / 2.0f, -size.Z / 2.0f)); 323 MeshPY.Add(new Vertex("+X+Y-Z", +size.X/2.0f, +size.Y/2.0f, -size.Z/2.0f));
332 MeshPY.Add(new Vertex("-X+Y+Z", -size.X / 2.0f, +size.Y / 2.0f, +size.Z / 2.0f)); 324 MeshPY.Add(new Vertex("-X+Y+Z", -size.X/2.0f, +size.Y/2.0f, +size.Z/2.0f));
333 MeshPY.Add(new Vertex("+X+Y+Z", +size.X / 2.0f, +size.Y / 2.0f, +size.Z / 2.0f)); 325 MeshPY.Add(new Vertex("+X+Y+Z", +size.X/2.0f, +size.Y/2.0f, +size.Z/2.0f));
334 326
335 MeshPY.Add(new Triangle(MeshPY.vertices[1], MeshPY.vertices[0], MeshPY.vertices[2])); 327 MeshPY.Add(new Triangle(MeshPY.vertices[1], MeshPY.vertices[0], MeshPY.vertices[2]));
336 MeshPY.Add(new Triangle(MeshPY.vertices[1], MeshPY.vertices[2], MeshPY.vertices[3])); 328 MeshPY.Add(new Triangle(MeshPY.vertices[1], MeshPY.vertices[2], MeshPY.vertices[3]));
337 329
338 if (hollowFactor > 0) 330 if (hollowFactor > 0)
339 { 331 {
340 float hollowFactorF = (float)hollowFactor / (float)50000; 332 float hollowFactorF = (float) hollowFactor/(float) 50000;
341 333
342 Vertex IPP; 334 Vertex IPP;
343 Vertex IPM; 335 Vertex IPM;
344 Vertex IMP; 336 Vertex IMP;
345 Vertex IMM; 337 Vertex IMM;
346 338
347 IPP = new Vertex("Inner+X-Y+Z", +size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, +size.Z / 2.0f); 339 IPP = new Vertex("Inner+X-Y+Z", +size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, +size.Z/2.0f);
348 IPM = new Vertex("Inner+X-Y-Z", +size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, -size.Z / 2.0f); 340 IPM = new Vertex("Inner+X-Y-Z", +size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, -size.Z/2.0f);
349 IMP = new Vertex("Inner-X-Y+Z", -size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, +size.Z / 2.0f); 341 IMP = new Vertex("Inner-X-Y+Z", -size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, +size.Z/2.0f);
350 IMM = new Vertex("Inner-X-Y-Z", -size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, -size.Z / 2.0f); 342 IMM = new Vertex("Inner-X-Y-Z", -size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, -size.Z/2.0f);
351 343
352 MeshMY.Add(IPP); 344 MeshMY.Add(IPP);
353 MeshMY.Add(IPM); 345 MeshMY.Add(IPM);
@@ -363,11 +355,10 @@ namespace OpenSim.Region.Physics.OdePlugin
363 } 355 }
364 356
365 357
366 358 IPP = new Vertex("Inner+X+Y+Z", +size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, +size.Z/2.0f);
367 IPP = new Vertex("Inner+X+Y+Z", +size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, +size.Z / 2.0f); 359 IPM = new Vertex("Inner+X+Y-Z", +size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, -size.Z/2.0f);
368 IPM=new Vertex("Inner+X+Y-Z", +size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, -size.Z / 2.0f); 360 IMP = new Vertex("Inner-X+Y+Z", -size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, +size.Z/2.0f);
369 IMP=new Vertex("Inner-X+Y+Z", -size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, +size.Z / 2.0f); 361 IMM = new Vertex("Inner-X+Y-Z", -size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, -size.Z/2.0f);
370 IMM=new Vertex("Inner-X+Y-Z", -size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, -size.Z / 2.0f);
371 362
372 MeshPY.Add(IPP); 363 MeshPY.Add(IPP);
373 MeshPY.Add(IPM); 364 MeshPY.Add(IPM);
@@ -381,9 +372,6 @@ namespace OpenSim.Region.Physics.OdePlugin
381 { 372 {
382 PhysicsVector n = t.getNormal(); 373 PhysicsVector n = t.getNormal();
383 } 374 }
384
385
386
387 } 375 }
388 376
389 377
@@ -393,9 +381,9 @@ namespace OpenSim.Region.Physics.OdePlugin
393 381
394 return result; 382 return result;
395 } 383 }
396 384
397 static Mesh CreateBoxMeshZ(PrimitiveBaseShape primShape, PhysicsVector size) 385 private static Mesh CreateBoxMeshZ(PrimitiveBaseShape primShape, PhysicsVector size)
398 // Builds the z (+ and -) surfaces of a box shaped prim 386 // Builds the z (+ and -) surfaces of a box shaped prim
399 { 387 {
400 UInt16 hollowFactor = primShape.ProfileHollow; 388 UInt16 hollowFactor = primShape.ProfileHollow;
401 389
@@ -403,10 +391,10 @@ namespace OpenSim.Region.Physics.OdePlugin
403 // (M)inus Z 391 // (M)inus Z
404 Mesh MZ = new Mesh(); 392 Mesh MZ = new Mesh();
405 393
406 MZ.Add(new Vertex("-X-Y-Z", -size.X / 2.0f, -size.Y / 2.0f, -size.Z / 2.0f)); 394 MZ.Add(new Vertex("-X-Y-Z", -size.X/2.0f, -size.Y/2.0f, -size.Z/2.0f));
407 MZ.Add(new Vertex("+X-Y-Z", +size.X / 2.0f, -size.Y / 2.0f, -size.Z / 2.0f)); 395 MZ.Add(new Vertex("+X-Y-Z", +size.X/2.0f, -size.Y/2.0f, -size.Z/2.0f));
408 MZ.Add(new Vertex("-X+Y-Z", -size.X / 2.0f, +size.Y / 2.0f, -size.Z / 2.0f)); 396 MZ.Add(new Vertex("-X+Y-Z", -size.X/2.0f, +size.Y/2.0f, -size.Z/2.0f));
409 MZ.Add(new Vertex("+X+Y-Z", +size.X / 2.0f, +size.Y / 2.0f, -size.Z / 2.0f)); 397 MZ.Add(new Vertex("+X+Y-Z", +size.X/2.0f, +size.Y/2.0f, -size.Z/2.0f));
410 398
411 399
412 MZ.Add(new Triangle(MZ.vertices[1], MZ.vertices[0], MZ.vertices[2])); 400 MZ.Add(new Triangle(MZ.vertices[1], MZ.vertices[0], MZ.vertices[2]));
@@ -415,10 +403,10 @@ namespace OpenSim.Region.Physics.OdePlugin
415 // (P)lus Z 403 // (P)lus Z
416 Mesh PZ = new Mesh(); 404 Mesh PZ = new Mesh();
417 405
418 PZ.Add(new Vertex("-X-Y+Z", -size.X / 2.0f, -size.Y / 2.0f, 0.0f)); 406 PZ.Add(new Vertex("-X-Y+Z", -size.X/2.0f, -size.Y/2.0f, 0.0f));
419 PZ.Add(new Vertex("+X-Y+Z", +size.X / 2.0f, -size.Y / 2.0f, 0.0f)); 407 PZ.Add(new Vertex("+X-Y+Z", +size.X/2.0f, -size.Y/2.0f, 0.0f));
420 PZ.Add(new Vertex("-X+Y+Z", -size.X / 2.0f, +size.Y / 2.0f, 0.0f)); 408 PZ.Add(new Vertex("-X+Y+Z", -size.X/2.0f, +size.Y/2.0f, 0.0f));
421 PZ.Add(new Vertex("+X+Y+Z", +size.X / 2.0f, +size.Y / 2.0f, 0.0f)); 409 PZ.Add(new Vertex("+X+Y+Z", +size.X/2.0f, +size.Y/2.0f, 0.0f));
422 410
423 // Surface 5, +Z 411 // Surface 5, +Z
424 PZ.Add(new Triangle(PZ.vertices[0], PZ.vertices[1], PZ.vertices[2])); 412 PZ.Add(new Triangle(PZ.vertices[0], PZ.vertices[1], PZ.vertices[2]));
@@ -426,12 +414,12 @@ namespace OpenSim.Region.Physics.OdePlugin
426 414
427 if (hollowFactor > 0) 415 if (hollowFactor > 0)
428 { 416 {
429 float hollowFactorF = (float)hollowFactor / (float)50000; 417 float hollowFactorF = (float) hollowFactor/(float) 50000;
430 418
431 MZ.Add(new Vertex("-X-Y-Z", -size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, 0.0f)); 419 MZ.Add(new Vertex("-X-Y-Z", -size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, 0.0f));
432 MZ.Add(new Vertex("-X+Y-Z", +size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, 0.0f)); 420 MZ.Add(new Vertex("-X+Y-Z", +size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, 0.0f));
433 MZ.Add(new Vertex("-X-Y+Z", -size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, 0.0f)); 421 MZ.Add(new Vertex("-X-Y+Z", -size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, 0.0f));
434 MZ.Add(new Vertex("-X+Y+Z", +size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, 0.0f)); 422 MZ.Add(new Vertex("-X+Y+Z", +size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, 0.0f));
435 423
436 List<int> innerBorders = new List<int>(); 424 List<int> innerBorders = new List<int>();
437 innerBorders.Add(4); 425 innerBorders.Add(4);
@@ -441,10 +429,10 @@ namespace OpenSim.Region.Physics.OdePlugin
441 429
442 InsertVertices(MZ.vertices, 4, MZ.triangles, innerBorders); 430 InsertVertices(MZ.vertices, 4, MZ.triangles, innerBorders);
443 431
444 PZ.Add(new Vertex("-X-Y-Z", -size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, 0.0f)); 432 PZ.Add(new Vertex("-X-Y-Z", -size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, 0.0f));
445 PZ.Add(new Vertex("-X+Y-Z", +size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, 0.0f)); 433 PZ.Add(new Vertex("-X+Y-Z", +size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, 0.0f));
446 PZ.Add(new Vertex("-X-Y+Z", -size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, 0.0f)); 434 PZ.Add(new Vertex("-X-Y+Z", -size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, 0.0f));
447 PZ.Add(new Vertex("-X+Y+Z", +size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, 0.0f)); 435 PZ.Add(new Vertex("-X+Y+Z", +size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, 0.0f));
448 436
449 innerBorders = new List<int>(); 437 innerBorders = new List<int>();
450 innerBorders.Add(4); 438 innerBorders.Add(4);
@@ -453,16 +441,15 @@ namespace OpenSim.Region.Physics.OdePlugin
453 innerBorders.Add(7); 441 innerBorders.Add(7);
454 442
455 InsertVertices(PZ.vertices, 4, PZ.triangles, innerBorders); 443 InsertVertices(PZ.vertices, 4, PZ.triangles, innerBorders);
456
457 } 444 }
458 445
459 foreach (Vertex v in PZ.vertices) 446 foreach (Vertex v in PZ.vertices)
460 { 447 {
461 v.point.Z = size.Z / 2.0f; 448 v.point.Z = size.Z/2.0f;
462 } 449 }
463 foreach (Vertex v in MZ.vertices) 450 foreach (Vertex v in MZ.vertices)
464 { 451 {
465 v.point.Z = -size.Z / 2.0f; 452 v.point.Z = -size.Z/2.0f;
466 } 453 }
467 454
468 foreach (Triangle t in MZ.triangles) 455 foreach (Triangle t in MZ.triangles)
@@ -486,15 +473,14 @@ namespace OpenSim.Region.Physics.OdePlugin
486 return result; 473 return result;
487 } 474 }
488 475
489 static Mesh CreateBoxMesh(PrimitiveBaseShape primShape, PhysicsVector size) 476 private static Mesh CreateBoxMesh(PrimitiveBaseShape primShape, PhysicsVector size)
490 { 477 {
491 Mesh result = new Mesh(); 478 Mesh result = new Mesh();
492 479
493 480
494 481 Mesh MeshX = CreateBoxMeshX(primShape, size);
495 Mesh MeshX = Meshmerizer.CreateBoxMeshX(primShape, size); 482 Mesh MeshY = CreateBoxMeshY(primShape, size);
496 Mesh MeshY = Meshmerizer.CreateBoxMeshY(primShape, size); 483 Mesh MeshZ = CreateBoxMeshZ(primShape, size);
497 Mesh MeshZ = Meshmerizer.CreateBoxMeshZ(primShape, size);
498 484
499 result.Append(MeshX); 485 result.Append(MeshX);
500 result.Append(MeshY); 486 result.Append(MeshY);
@@ -504,64 +490,63 @@ namespace OpenSim.Region.Physics.OdePlugin
504 } 490 }
505 491
506 492
507 public static void CalcNormals(Mesh mesh) 493 public static void CalcNormals(Mesh mesh)
508 { 494 {
509 int iTriangles = mesh.triangles.Count; 495 int iTriangles = mesh.triangles.Count;
510 496
511 mesh.normals = new float[iTriangles*3]; 497 mesh.normals = new float[iTriangles*3];
512 498
513 int i=0; 499 int i = 0;
514 foreach (Triangle t in mesh.triangles) 500 foreach (Triangle t in mesh.triangles)
515 { 501 {
516
517 float ux, uy, uz; 502 float ux, uy, uz;
518 float vx, vy, vz; 503 float vx, vy, vz;
519 float wx, wy, wz; 504 float wx, wy, wz;
520 505
521 ux = t.v1.point.X; 506 ux = t.v1.point.X;
522 uy = t.v1.point.Y; 507 uy = t.v1.point.Y;
523 uz = t.v1.point.Z; 508 uz = t.v1.point.Z;
524 509
525 vx = t.v2.point.X; 510 vx = t.v2.point.X;
526 vy = t.v2.point.Y; 511 vy = t.v2.point.Y;
527 vz = t.v2.point.Z; 512 vz = t.v2.point.Z;
528 513
529 wx = t.v3.point.X; 514 wx = t.v3.point.X;
530 wy = t.v3.point.Y; 515 wy = t.v3.point.Y;
531 wz = t.v3.point.Z; 516 wz = t.v3.point.Z;
532 517
533 // Vectors for edges 518 // Vectors for edges
534 float e1x, e1y, e1z; 519 float e1x, e1y, e1z;
535 float e2x, e2y, e2z; 520 float e2x, e2y, e2z;
536 521
537 e1x = ux - vx; 522 e1x = ux - vx;
538 e1y = uy - vy; 523 e1y = uy - vy;
539 e1z = uz - vz; 524 e1z = uz - vz;
540 525
541 e2x = ux - wx; 526 e2x = ux - wx;
542 e2y = uy - wy; 527 e2y = uy - wy;
543 e2z = uz - wz; 528 e2z = uz - wz;
544 529
545 530
546 // Cross product for normal 531 // Cross product for normal
547 float nx, ny, nz; 532 float nx, ny, nz;
548 nx = e1y * e2z - e1z * e2y; 533 nx = e1y*e2z - e1z*e2y;
549 ny = e1z * e2x - e1x * e2z; 534 ny = e1z*e2x - e1x*e2z;
550 nz = e1x * e2y - e1y * e2x; 535 nz = e1x*e2y - e1y*e2x;
551 536
552 // Length 537 // Length
553 float l = (float)Math.Sqrt(nx * nx + ny * ny + nz * nz); 538 float l = (float) Math.Sqrt(nx*nx + ny*ny + nz*nz);
554 539
555 // Normalized "normal" 540 // Normalized "normal"
556 nx /= l; 541 nx /= l;
557 ny /= l; 542 ny /= l;
558 nz /= l; 543 nz /= l;
559 544
560 mesh.normals[i] = nx; 545 mesh.normals[i] = nx;
561 mesh.normals[i + 1] = ny; 546 mesh.normals[i + 1] = ny;
562 mesh.normals[i + 2] = nz; 547 mesh.normals[i + 2] = nz;
563 548
564 i+=3; 549 i += 3;
565 } 550 }
566 } 551 }
567 552
@@ -572,18 +557,15 @@ namespace OpenSim.Region.Physics.OdePlugin
572 switch (primShape.ProfileShape) 557 switch (primShape.ProfileShape)
573 { 558 {
574 case ProfileShape.Square: 559 case ProfileShape.Square:
575 mesh=CreateBoxMesh(primShape, size); 560 mesh = CreateBoxMesh(primShape, size);
576 CalcNormals(mesh); 561 CalcNormals(mesh);
577 break; 562 break;
578 default: 563 default:
579 mesh=null; 564 mesh = null;
580 break; 565 break;
581 } 566 }
582 567
583 return mesh; 568 return mesh;
584
585 } 569 }
586 } 570 }
587} 571} \ No newline at end of file
588
589