diff options
author | lbsa71 | 2007-12-27 21:41:48 +0000 |
---|---|---|
committer | lbsa71 | 2007-12-27 21:41:48 +0000 |
commit | efd90b56b761219af6425b1c7a2cdd3b6ffb4de2 (patch) | |
tree | bf5b897e1e3c13211e3e2fc61d30508b94c928c0 /OpenSim/Region/Physics/Meshing/Meshmerizer.cs | |
parent | * removed always true if (diff) | |
download | opensim-SC-efd90b56b761219af6425b1c7a2cdd3b6ffb4de2.zip opensim-SC-efd90b56b761219af6425b1c7a2cdd3b6ffb4de2.tar.gz opensim-SC-efd90b56b761219af6425b1c7a2cdd3b6ffb4de2.tar.bz2 opensim-SC-efd90b56b761219af6425b1c7a2cdd3b6ffb4de2.tar.xz |
* Optimized usings
* shortened references
* Removed redundant 'this'
* Normalized EOF
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Physics/Meshing/Meshmerizer.cs | 74 |
1 files changed, 35 insertions, 39 deletions
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 @@ | |||
27 | */ | 27 | */ |
28 | 28 | ||
29 | using System; | 29 | using System; |
30 | using System.IO; | ||
31 | using System.Globalization; | ||
32 | using System.Diagnostics; | ||
33 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
34 | using System.Runtime.InteropServices; | ||
35 | using OpenSim.Framework; | 31 | using OpenSim.Framework; |
36 | using OpenSim.Framework.Console; | 32 | using OpenSim.Framework.Console; |
37 | using OpenSim.Region.Physics.Manager; | 33 | using OpenSim.Region.Physics.Manager; |
38 | 34 | ||
39 | namespace OpenSim.Region.Physics.Meshing | 35 | namespace OpenSim.Region.Physics.Meshing |
40 | { | 36 | { |
41 | |||
42 | public class MeshmerizerPlugin : IMeshingPlugin | 37 | public class MeshmerizerPlugin : IMeshingPlugin |
43 | { | 38 | { |
44 | public MeshmerizerPlugin() | 39 | public MeshmerizerPlugin() |
@@ -61,10 +56,11 @@ namespace OpenSim.Region.Physics.Meshing | |||
61 | // Setting baseDir to a path will enable the dumping of raw files | 56 | // Setting baseDir to a path will enable the dumping of raw files |
62 | // raw files can be imported by blender so a visual inspection of the results can be done | 57 | // raw files can be imported by blender so a visual inspection of the results can be done |
63 | // const string baseDir = "rawFiles"; | 58 | // const string baseDir = "rawFiles"; |
64 | const string baseDir = null; | 59 | private const string baseDir = null; |
65 | 60 | ||
66 | static void IntersectionParameterPD(PhysicsVector p1, PhysicsVector r1, PhysicsVector p2, PhysicsVector r2, ref float lambda, ref float mu) | 61 | private static void IntersectionParameterPD(PhysicsVector p1, PhysicsVector r1, PhysicsVector p2, |
67 | { | 62 | PhysicsVector r2, ref float lambda, ref float mu) |
63 | { | ||
68 | // p1, p2, points on the straight | 64 | // p1, p2, points on the straight |
69 | // r1, r2, directional vectors of the straight. Not necessarily of length 1! | 65 | // r1, r2, directional vectors of the straight. Not necessarily of length 1! |
70 | // note, that l, m can be scaled such, that the range 0..1 is mapped to the area between two points, | 66 | // 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 | |||
88 | float p1y = p1.Y; | 84 | float p1y = p1.Y; |
89 | float p2x = p2.X; | 85 | float p2x = p2.X; |
90 | float p2y = p2.Y; | 86 | float p2y = p2.Y; |
91 | lambda = (-p2x * r2y + p1x * r2y + (p2y - p1y) * r2x) / denom; | 87 | lambda = (-p2x*r2y + p1x*r2y + (p2y - p1y)*r2x)/denom; |
92 | mu = (-p2x * r1y + p1x * r1y + (p2y - p1y) * r1x) / denom; | 88 | mu = (-p2x*r1y + p1x*r1y + (p2y - p1y)*r1x)/denom; |
93 | |||
94 | } | 89 | } |
95 | 90 | ||
96 | private static List<Triangle> FindInfluencedTriangles(List<Triangle> triangles, Vertex v) | 91 | private static List<Triangle> FindInfluencedTriangles(List<Triangle> triangles, Vertex v) |
@@ -105,8 +100,8 @@ namespace OpenSim.Region.Physics.Meshing | |||
105 | } | 100 | } |
106 | return influenced; | 101 | return influenced; |
107 | } | 102 | } |
108 | 103 | ||
109 | 104 | ||
110 | private static void InsertVertices(List<Vertex> vertices, int usedForSeed, List<Triangle> triangles) | 105 | private static void InsertVertices(List<Vertex> vertices, int usedForSeed, List<Triangle> triangles) |
111 | { | 106 | { |
112 | // This is a variant of the delaunay algorithm | 107 | // This is a variant of the delaunay algorithm |
@@ -126,10 +121,10 @@ namespace OpenSim.Region.Physics.Meshing | |||
126 | // do not fulfill this condition with respect to the new triangle | 121 | // do not fulfill this condition with respect to the new triangle |
127 | 122 | ||
128 | // Find the triangles that are influenced by the new vertex | 123 | // Find the triangles that are influenced by the new vertex |
129 | Vertex v=vertices[iCurrentVertex]; | 124 | Vertex v = vertices[iCurrentVertex]; |
130 | if (v == null) | 125 | if (v == null) |
131 | continue; // Null is polygon stop marker. Ignore it | 126 | continue; // Null is polygon stop marker. Ignore it |
132 | List<Triangle> influencedTriangles=FindInfluencedTriangles(triangles, v); | 127 | List<Triangle> influencedTriangles = FindInfluencedTriangles(triangles, v); |
133 | 128 | ||
134 | List<Simplex> simplices = new List<Simplex>(); | 129 | List<Simplex> simplices = new List<Simplex>(); |
135 | 130 | ||
@@ -177,12 +172,11 @@ namespace OpenSim.Region.Physics.Meshing | |||
177 | } | 172 | } |
178 | } | 173 | } |
179 | } | 174 | } |
180 | |||
181 | } | 175 | } |
182 | 176 | ||
183 | 177 | ||
184 | static Mesh CreateBoxMesh(String primName, PrimitiveBaseShape primShape, PhysicsVector size) | 178 | private static Mesh CreateBoxMesh(String primName, PrimitiveBaseShape primShape, PhysicsVector size) |
185 | // Builds the z (+ and -) surfaces of a box shaped prim | 179 | // Builds the z (+ and -) surfaces of a box shaped prim |
186 | { | 180 | { |
187 | UInt16 hollowFactor = primShape.ProfileHollow; | 181 | UInt16 hollowFactor = primShape.ProfileHollow; |
188 | UInt16 profileBegin = primShape.ProfileBegin; | 182 | UInt16 profileBegin = primShape.ProfileBegin; |
@@ -201,7 +195,7 @@ namespace OpenSim.Region.Physics.Meshing | |||
201 | Vertex MP = new Vertex(-0.5f, +0.5f, 0.0f); | 195 | Vertex MP = new Vertex(-0.5f, +0.5f, 0.0f); |
202 | Vertex PP = new Vertex(+0.5f, +0.5f, 0.0f); | 196 | Vertex PP = new Vertex(+0.5f, +0.5f, 0.0f); |
203 | 197 | ||
204 | Meshing.SimpleHull outerHull = new SimpleHull(); | 198 | SimpleHull outerHull = new SimpleHull(); |
205 | outerHull.AddVertex(MM); | 199 | outerHull.AddVertex(MM); |
206 | outerHull.AddVertex(PM); | 200 | outerHull.AddVertex(PM); |
207 | outerHull.AddVertex(PP); | 201 | outerHull.AddVertex(PP); |
@@ -210,9 +204,10 @@ namespace OpenSim.Region.Physics.Meshing | |||
210 | // Deal with cuts now | 204 | // Deal with cuts now |
211 | if ((profileBegin != 0) || (profileEnd != 0)) | 205 | if ((profileBegin != 0) || (profileEnd != 0)) |
212 | { | 206 | { |
213 | double fProfileBeginAngle = profileBegin / 50000.0 * 360.0; // In degree, for easier debugging and understanding | 207 | double fProfileBeginAngle = profileBegin/50000.0*360.0; |
214 | fProfileBeginAngle -= (90.0 + 45.0); // for some reasons, the SL client counts from the corner -X/-Y | 208 | // In degree, for easier debugging and understanding |
215 | double fProfileEndAngle = 360.0 - profileEnd / 50000.0 * 360.0; // Pathend comes as complement to 1.0 | 209 | fProfileBeginAngle -= (90.0 + 45.0); // for some reasons, the SL client counts from the corner -X/-Y |
210 | double fProfileEndAngle = 360.0 - profileEnd/50000.0*360.0; // Pathend comes as complement to 1.0 | ||
216 | fProfileEndAngle -= (90.0 + 45.0); | 211 | fProfileEndAngle -= (90.0 + 45.0); |
217 | if (fProfileBeginAngle < fProfileEndAngle) | 212 | if (fProfileBeginAngle < fProfileEndAngle) |
218 | fProfileEndAngle -= 360.0; | 213 | fProfileEndAngle -= 360.0; |
@@ -222,20 +217,23 @@ namespace OpenSim.Region.Physics.Meshing | |||
222 | // and we approximate this arc by a polygon chain | 217 | // and we approximate this arc by a polygon chain |
223 | // Also note, that these vectors are of length 1.0 and thus their endpoints lay outside the model space | 218 | // Also note, that these vectors are of length 1.0 and thus their endpoints lay outside the model space |
224 | // So it can easily be subtracted from the outer hull | 219 | // So it can easily be subtracted from the outer hull |
225 | int iSteps = (int)(((fProfileBeginAngle - fProfileEndAngle) / 45.0) + .5); // how many steps do we need with approximately 45 degree | 220 | int iSteps = (int) (((fProfileBeginAngle - fProfileEndAngle)/45.0) + .5); |
226 | double dStepWidth=(fProfileBeginAngle-fProfileEndAngle)/iSteps; | 221 | // how many steps do we need with approximately 45 degree |
222 | double dStepWidth = (fProfileBeginAngle - fProfileEndAngle)/iSteps; | ||
227 | 223 | ||
228 | Vertex origin = new Vertex(0.0f, 0.0f, 0.0f); | 224 | Vertex origin = new Vertex(0.0f, 0.0f, 0.0f); |
229 | 225 | ||
230 | // Note the sequence of vertices here. It's important to have the other rotational sense than in outerHull | 226 | // Note the sequence of vertices here. It's important to have the other rotational sense than in outerHull |
231 | SimpleHull cutHull = new SimpleHull(); | 227 | SimpleHull cutHull = new SimpleHull(); |
232 | cutHull.AddVertex(origin); | 228 | cutHull.AddVertex(origin); |
233 | for (int i=0; i<iSteps; i++) { | 229 | for (int i = 0; i < iSteps; i++) |
234 | double angle=fProfileBeginAngle-i*dStepWidth; // we count against the angle orientation!!!! | 230 | { |
235 | Vertex v = Vertex.FromAngle(angle * Math.PI / 180.0); | 231 | double angle = fProfileBeginAngle - i*dStepWidth; // we count against the angle orientation!!!! |
232 | Vertex v = Vertex.FromAngle(angle*Math.PI/180.0); | ||
236 | cutHull.AddVertex(v); | 233 | cutHull.AddVertex(v); |
237 | } | 234 | } |
238 | Vertex legEnd = Vertex.FromAngle(fProfileEndAngle * Math.PI / 180.0); // Calculated separately to avoid errors | 235 | Vertex legEnd = Vertex.FromAngle(fProfileEndAngle*Math.PI/180.0); |
236 | // Calculated separately to avoid errors | ||
239 | cutHull.AddVertex(legEnd); | 237 | cutHull.AddVertex(legEnd); |
240 | 238 | ||
241 | MainLog.Instance.Debug("Starting cutting of the hollow shape from the prim {1}", 0, primName); | 239 | MainLog.Instance.Debug("Starting cutting of the hollow shape from the prim {1}", 0, primName); |
@@ -248,10 +246,10 @@ namespace OpenSim.Region.Physics.Meshing | |||
248 | if (hollowFactor > 0) | 246 | if (hollowFactor > 0) |
249 | { | 247 | { |
250 | float hollowFactorF = (float) hollowFactor/(float) 50000; | 248 | float hollowFactorF = (float) hollowFactor/(float) 50000; |
251 | Vertex IMM = new Vertex(-0.5f * hollowFactorF, -0.5f * hollowFactorF, 0.0f); | 249 | Vertex IMM = new Vertex(-0.5f*hollowFactorF, -0.5f*hollowFactorF, 0.0f); |
252 | Vertex IPM = new Vertex(+0.5f * hollowFactorF, -0.5f * hollowFactorF, 0.0f); | 250 | Vertex IPM = new Vertex(+0.5f*hollowFactorF, -0.5f*hollowFactorF, 0.0f); |
253 | Vertex IMP = new Vertex(-0.5f * hollowFactorF, +0.5f * hollowFactorF, 0.0f); | 251 | Vertex IMP = new Vertex(-0.5f*hollowFactorF, +0.5f*hollowFactorF, 0.0f); |
254 | Vertex IPP = new Vertex(+0.5f * hollowFactorF, +0.5f * hollowFactorF, 0.0f); | 252 | Vertex IPP = new Vertex(+0.5f*hollowFactorF, +0.5f*hollowFactorF, 0.0f); |
255 | 253 | ||
256 | SimpleHull holeHull = new SimpleHull(); | 254 | SimpleHull holeHull = new SimpleHull(); |
257 | 255 | ||
@@ -263,7 +261,6 @@ namespace OpenSim.Region.Physics.Meshing | |||
263 | SimpleHull hollowedHull = SimpleHull.SubtractHull(outerHull, holeHull); | 261 | SimpleHull hollowedHull = SimpleHull.SubtractHull(outerHull, holeHull); |
264 | 262 | ||
265 | outerHull = hollowedHull; | 263 | outerHull = hollowedHull; |
266 | |||
267 | } | 264 | } |
268 | 265 | ||
269 | Mesh m = new Mesh(); | 266 | Mesh m = new Mesh(); |
@@ -286,7 +283,7 @@ namespace OpenSim.Region.Physics.Meshing | |||
286 | m.Remove(Seed2); | 283 | m.Remove(Seed2); |
287 | m.Remove(Seed3); | 284 | m.Remove(Seed3); |
288 | m.DumpRaw(baseDir, primName, "Proto seeds removed"); | 285 | m.DumpRaw(baseDir, primName, "Proto seeds removed"); |
289 | 286 | ||
290 | m.RemoveTrianglesOutside(outerHull); | 287 | m.RemoveTrianglesOutside(outerHull); |
291 | m.DumpRaw(baseDir, primName, "Proto outsides removed"); | 288 | m.DumpRaw(baseDir, primName, "Proto outsides removed"); |
292 | 289 | ||
@@ -374,7 +371,7 @@ namespace OpenSim.Region.Physics.Meshing | |||
374 | switch (primShape.ProfileShape) | 371 | switch (primShape.ProfileShape) |
375 | { | 372 | { |
376 | case ProfileShape.Square: | 373 | case ProfileShape.Square: |
377 | mesh=CreateBoxMesh(primName, primShape, size); | 374 | mesh = CreateBoxMesh(primName, primShape, size); |
378 | CalcNormals(mesh); | 375 | CalcNormals(mesh); |
379 | break; | 376 | break; |
380 | default: | 377 | default: |
@@ -389,5 +386,4 @@ namespace OpenSim.Region.Physics.Meshing | |||
389 | return mesh; | 386 | return mesh; |
390 | } | 387 | } |
391 | } | 388 | } |
392 | 389 | } \ No newline at end of file | |
393 | } | ||