aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Physics/Meshing/Extruder.cs192
-rw-r--r--OpenSim/Region/Physics/Meshing/Meshmerizer.cs192
2 files changed, 296 insertions, 88 deletions
diff --git a/OpenSim/Region/Physics/Meshing/Extruder.cs b/OpenSim/Region/Physics/Meshing/Extruder.cs
index 880a23a..baa2d9b 100644
--- a/OpenSim/Region/Physics/Meshing/Extruder.cs
+++ b/OpenSim/Region/Physics/Meshing/Extruder.cs
@@ -63,6 +63,11 @@ namespace OpenSim.Region.Physics.Meshing
63 public float pathTaperX = 0.0f; 63 public float pathTaperX = 0.0f;
64 public float pathTaperY = 0.0f; 64 public float pathTaperY = 0.0f;
65 65
66 /// <summary>
67 /// (deprecated) creates a 3 layer extruded mesh of a profile hull
68 /// </summary>
69 /// <param name="m"></param>
70 /// <returns></returns>
66 public Mesh Extrude(Mesh m) 71 public Mesh Extrude(Mesh m)
67 { 72 {
68 startParameter = float.MinValue; 73 startParameter = float.MinValue;
@@ -245,6 +250,193 @@ namespace OpenSim.Region.Physics.Meshing
245 return result; 250 return result;
246 } 251 }
247 252
253 /// <summary>
254 /// Creates an extrusion of a profile along a linear path. Used to create prim types box, cylinder, and prism.
255 /// </summary>
256 /// <param name="m"></param>
257 /// <returns>A mesh of the extruded shape</returns>
258 public Mesh ExtrudeLinearPath(Mesh m)
259 {
260 Mesh result = new Mesh();
261
262 Quaternion tt = new Quaternion();
263 Vertex v2 = new Vertex(0, 0, 0);
264
265 Mesh newLayer;
266 Mesh lastLayer = null;
267
268 int step = 0;
269 int steps = 1;
270
271 float twistTotal = twistTop - twistBot;
272 // if the profile has a lot of twist, add more layers otherwise the layers may overlap
273 // and the resulting mesh may be quite inaccurate. This method is arbitrary and may not
274 // accurately match the viewer
275 float twistTotalAbs = System.Math.Abs(twistTotal);
276 if (twistTotalAbs > 0.01)
277 steps += (int)(twistTotalAbs * 3.66f); // dahlia's magic number ;)
278
279#if SPAM
280 System.Console.WriteLine("ExtrudeLinearPath: twistTotalAbs: " + twistTotalAbs.ToString() + " steps: " + steps.ToString());
281#endif
282
283 double percentOfPathMultiplier = 1.0 / steps;
284
285 float start = -0.5f;
286
287 float stepSize = 1.0f / (float)steps;
288
289 float xProfileScale = 1.0f;
290 float yProfileScale = 1.0f;
291
292 float xOffset = 0.0f;
293 float yOffset = 0.0f;
294 float zOffset = start;
295
296 float xOffsetStepIncrement = pushX / steps;
297 float yOffsetStepIncrement = pushY / steps;
298
299#if SPAM
300 System.Console.WriteLine("Extruder: twistTop: " + twistTop.ToString() + " twistbot: " + twistBot.ToString() + " twisttotal: " + twistTotal.ToString());
301 System.Console.WriteLine("Extruder: taperBotFactorX: " + taperBotFactorX.ToString() + " taperBotFactorY: " + taperBotFactorY.ToString()
302 + " taperTopFactorX: " + taperTopFactorX.ToString() + " taperTopFactorY: " + taperTopFactorY.ToString());
303 System.Console.WriteLine("Extruder: PathScaleX: " + pathScaleX.ToString() + " pathScaleY: " + pathScaleY.ToString());
304#endif
305
306 float percentOfPath = 0.0f;
307 bool done = false;
308 do // loop through the length of the path and add the layers
309 {
310 newLayer = m.Clone();
311
312 if (taperBotFactorX < 1.0f)
313 xProfileScale = 1.0f - (1.0f - percentOfPath) * (1.0f - taperBotFactorX);
314 else if (taperTopFactorX < 1.0f)
315 xProfileScale = 1.0f - percentOfPath * (1.0f - taperTopFactorX);
316 else xProfileScale = 1.0f;
317
318 if (taperBotFactorY < 1.0f)
319 yProfileScale = 1.0f - (1.0f - percentOfPath) * (1.0f - taperBotFactorY);
320 else if (taperTopFactorY < 1.0f)
321 yProfileScale = 1.0f - percentOfPath * (1.0f - taperTopFactorY);
322 else yProfileScale = 1.0f;
323
324#if SPAM
325 //System.Console.WriteLine("xProfileScale: " + xProfileScale.ToString() + " yProfileScale: " + yProfileScale.ToString());
326#endif
327 Vertex vTemp = new Vertex(0.0f, 0.0f, 0.0f);
328
329 // apply the taper to the profile before any rotations
330 if (xProfileScale != 1.0f || yProfileScale != 1.0f)
331 {
332 foreach (Vertex v in newLayer.vertices)
333 {
334 if (v != null)
335 {
336 v.X *= xProfileScale;
337 v.Y *= yProfileScale;
338 }
339 }
340 }
341
342
343 float twist = twistBot + (twistTotal * (float)percentOfPath);
344#if SPAM
345 System.Console.WriteLine("Extruder: percentOfPath: " + percentOfPath.ToString() + " zOffset: " + zOffset.ToString()
346 + " xProfileScale: " + xProfileScale.ToString() + " yProfileScale: " + yProfileScale.ToString());
347#endif
348
349 // apply twist rotation to the profile layer and position the layer in the prim
350
351 Quaternion profileRot = new Quaternion(new Vertex(0.0f, 0.0f, -1.0f), twist);
352 foreach (Vertex v in newLayer.vertices)
353 {
354 if (v != null)
355 {
356 vTemp = v * profileRot;
357 v.X = vTemp.X + xOffset;
358 v.Y = vTemp.Y + yOffset;
359 v.Z = vTemp.Z + zOffset;
360 }
361 }
362
363 if (step == 0) // the first layer, invert normals
364 {
365 foreach (Triangle t in newLayer.triangles)
366 {
367 t.invertNormal();
368 }
369 }
370
371 result.Append(newLayer);
372
373 int iLastNull = 0;
374
375 if (lastLayer != null)
376 {
377 int i, count = newLayer.vertices.Count;
378
379 for (i = 0; i < count; i++)
380 {
381 int iNext = (i + 1);
382
383 if (lastLayer.vertices[i] == null) // cant make a simplex here
384 {
385 iLastNull = i + 1;
386 }
387 else
388 {
389 if (i == count - 1) // End of list
390 iNext = iLastNull;
391
392 if (lastLayer.vertices[iNext] == null) // Null means wrap to begin of last segment
393 iNext = iLastNull;
394
395 result.Add(new Triangle(newLayer.vertices[i], lastLayer.vertices[i], newLayer.vertices[iNext]));
396 result.Add(new Triangle(newLayer.vertices[iNext], lastLayer.vertices[i], lastLayer.vertices[iNext]));
397 }
398 }
399 }
400 lastLayer = newLayer;
401
402 // calc the step for the next interation of the loop
403
404 if (step < steps)
405 {
406 step++;
407 percentOfPath += (float)percentOfPathMultiplier;
408
409 xOffset += xOffsetStepIncrement;
410 yOffset += yOffsetStepIncrement;
411 zOffset += stepSize;
412 }
413 else done = true;
414
415 } while (!done); // loop until all the layers in the path are completed
416
417 // scale the mesh to the desired size
418 float xScale = size.X;
419 float yScale = size.Y;
420 float zScale = size.Z;
421
422 foreach (Vertex v in result.vertices)
423 {
424 if (v != null)
425 {
426 v.X *= xScale;
427 v.Y *= yScale;
428 v.Z *= zScale;
429 }
430 }
431
432 return result;
433 }
434
435 /// <summary>
436 /// Extrudes a shape around a circular path. Used to create prim types torus, ring, and tube.
437 /// </summary>
438 /// <param name="m"></param>
439 /// <returns>a mesh of the extruded shape</returns>
248 public Mesh ExtrudeCircularPath(Mesh m) 440 public Mesh ExtrudeCircularPath(Mesh m)
249 { 441 {
250 Mesh result = new Mesh(); 442 Mesh result = new Mesh();
diff --git a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs
index 0c62447..9afc7ae 100644
--- a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs
+++ b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs
@@ -57,8 +57,11 @@ namespace OpenSim.Region.Physics.Meshing
57 57
58 // Setting baseDir to a path will enable the dumping of raw files 58 // Setting baseDir to a path will enable the dumping of raw files
59 // raw files can be imported by blender so a visual inspection of the results can be done 59 // raw files can be imported by blender so a visual inspection of the results can be done
60 // const string baseDir = "rawFiles"; 60#if SPAM
61 const string baseDir = "rawFiles";
62#else
61 private const string baseDir = null; //"rawFiles"; 63 private const string baseDir = null; //"rawFiles";
64#endif
62 private const float DEG_TO_RAD = 0.01745329238f; 65 private const float DEG_TO_RAD = 0.01745329238f;
63 66
64// TODO: unused 67// TODO: unused
@@ -613,42 +616,46 @@ namespace OpenSim.Region.Physics.Meshing
613 } 616 }
614 } 617 }
615 618
616 if (twistTop != 0) 619 //if (twistTop != 0)
617 { 620 //{
618 extr.twistTop = 180 * ((float)twistTop / 100); 621 // extr.twistTop = 180 * ((float)twistTop / 100);
619 if (extr.twistTop > 0) 622 // if (extr.twistTop > 0)
620 { 623 // {
621 extr.twistTop = 360 - (-1 * extr.twistTop); 624 // extr.twistTop = 360 - (-1 * extr.twistTop);
622 625
623 } 626 // }
624 627
625 628
626 extr.twistTop = (float)(extr.twistTop * DEG_TO_RAD); 629 // extr.twistTop = (float)(extr.twistTop * DEG_TO_RAD);
627 } 630 //}
628 631
629 float twistMid = ((twistTop + twistBot) * 0.5f); 632 //float twistMid = ((twistTop + twistBot) * 0.5f);
630 633
631 if (twistMid != 0) 634 //if (twistMid != 0)
632 { 635 //{
633 extr.twistMid = 180 * ((float)twistMid / 100); 636 // extr.twistMid = 180 * ((float)twistMid / 100);
634 if (extr.twistMid > 0) 637 // if (extr.twistMid > 0)
635 { 638 // {
636 extr.twistMid = 360 - (-1 * extr.twistMid); 639 // extr.twistMid = 360 - (-1 * extr.twistMid);
637 } 640 // }
638 extr.twistMid = (float)(extr.twistMid * DEG_TO_RAD); 641 // extr.twistMid = (float)(extr.twistMid * DEG_TO_RAD);
639 } 642 //}
640 643
641 if (twistBot != 0) 644 //if (twistBot != 0)
642 { 645 //{
643 extr.twistBot = 180 * ((float)twistBot / 100); 646 // extr.twistBot = 180 * ((float)twistBot / 100);
644 if (extr.twistBot > 0) 647 // if (extr.twistBot > 0)
645 { 648 // {
646 extr.twistBot = 360 - (-1 * extr.twistBot); 649 // extr.twistBot = 360 - (-1 * extr.twistBot);
647 } 650 // }
648 extr.twistBot = (float)(extr.twistBot * DEG_TO_RAD); 651 // extr.twistBot = (float)(extr.twistBot * DEG_TO_RAD);
649 } 652 //}
653
654 extr.twistTop = (float)primShape.PathTwist * (float)Math.PI * 0.01f;
655 extr.twistBot = (float)primShape.PathTwistBegin * (float)Math.PI * 0.01f;
650 656
651 Mesh result = extr.Extrude(m); 657 //Mesh result = extr.Extrude(m);
658 Mesh result = extr.ExtrudeLinearPath(m);
652 result.DumpRaw(baseDir, primName, "Z extruded"); 659 result.DumpRaw(baseDir, primName, "Z extruded");
653 return result; 660 return result;
654 } 661 }
@@ -953,43 +960,47 @@ namespace OpenSim.Region.Physics.Meshing
953 960
954 } 961 }
955 962
956 if (twistTop != 0) 963 //if (twistTop != 0)
957 { 964 //{
958 extr.twistTop = 180 * ((float)twistTop / 100); 965 // extr.twistTop = 180 * ((float)twistTop / 100);
959 if (extr.twistTop > 0) 966 // if (extr.twistTop > 0)
960 { 967 // {
961 extr.twistTop = 360 - (-1 * extr.twistTop); 968 // extr.twistTop = 360 - (-1 * extr.twistTop);
962 969
963 } 970 // }
964 971
965 972
966 extr.twistTop = (float)(extr.twistTop * DEG_TO_RAD); 973 // extr.twistTop = (float)(extr.twistTop * DEG_TO_RAD);
967 } 974 //}
968 975
969 float twistMid = ((twistTop + twistBot) * 0.5f); 976 //float twistMid = ((twistTop + twistBot) * 0.5f);
970 977
971 if (twistMid != 0) 978 //if (twistMid != 0)
972 { 979 //{
973 extr.twistMid = 180 * ((float)twistMid / 100); 980 // extr.twistMid = 180 * ((float)twistMid / 100);
974 if (extr.twistMid > 0) 981 // if (extr.twistMid > 0)
975 { 982 // {
976 extr.twistMid = 360 - (-1 * extr.twistMid); 983 // extr.twistMid = 360 - (-1 * extr.twistMid);
977 } 984 // }
978 extr.twistMid = (float)(extr.twistMid * DEG_TO_RAD); 985 // extr.twistMid = (float)(extr.twistMid * DEG_TO_RAD);
979 } 986 //}
980 987
981 if (twistBot != 0) 988 //if (twistBot != 0)
982 { 989 //{
983 extr.twistBot = 180 * ((float)twistBot / 100); 990 // extr.twistBot = 180 * ((float)twistBot / 100);
984 if (extr.twistBot > 0) 991 // if (extr.twistBot > 0)
985 { 992 // {
986 extr.twistBot = 360 - (-1 * extr.twistBot); 993 // extr.twistBot = 360 - (-1 * extr.twistBot);
987 } 994 // }
988 extr.twistBot = (float)(extr.twistBot * DEG_TO_RAD); 995 // extr.twistBot = (float)(extr.twistBot * DEG_TO_RAD);
989 } 996 //}
990 997
998 extr.twistTop = (float)primShape.PathTwist * (float)Math.PI * 0.01f;
999 extr.twistBot = (float)primShape.PathTwistBegin * (float)Math.PI * 0.01f;
1000
991 //System.Console.WriteLine("[MESH]: twistTop = " + twistTop.ToString() + "|" + extr.twistTop.ToString() + ", twistMid = " + twistMid.ToString() + "|" + extr.twistMid.ToString() + ", twistbot = " + twistBot.ToString() + "|" + extr.twistBot.ToString()); 1001 //System.Console.WriteLine("[MESH]: twistTop = " + twistTop.ToString() + "|" + extr.twistTop.ToString() + ", twistMid = " + twistMid.ToString() + "|" + extr.twistMid.ToString() + ", twistbot = " + twistBot.ToString() + "|" + extr.twistBot.ToString());
992 Mesh result = extr.Extrude(m); 1002 //Mesh result = extr.Extrude(m);
1003 Mesh result = extr.ExtrudeLinearPath(m);
993 result.DumpRaw(baseDir, primName, "Z extruded"); 1004 result.DumpRaw(baseDir, primName, "Z extruded");
994 return result; 1005 return result;
995 } 1006 }
@@ -1185,42 +1196,47 @@ namespace OpenSim.Region.Physics.Meshing
1185 } 1196 }
1186 } 1197 }
1187 1198
1188 if (twistTop != 0) 1199 //if (twistTop != 0)
1189 { 1200 //{
1190 extr.twistTop = 180 * ((float)twistTop / 100); 1201 // extr.twistTop = 180 * ((float)twistTop / 100);
1191 if (extr.twistTop > 0) 1202 // if (extr.twistTop > 0)
1192 { 1203 // {
1193 extr.twistTop = 360 - (-1 * extr.twistTop); 1204 // extr.twistTop = 360 - (-1 * extr.twistTop);
1194 1205
1195 } 1206 // }
1196 1207
1197 1208
1198 extr.twistTop = (float)(extr.twistTop * DEG_TO_RAD); 1209 // extr.twistTop = (float)(extr.twistTop * DEG_TO_RAD);
1199 } 1210 //}
1200 1211
1201 float twistMid = ((twistTop + twistBot) * 0.5f); 1212 //float twistMid = ((twistTop + twistBot) * 0.5f);
1202 1213
1203 if (twistMid != 0) 1214 //if (twistMid != 0)
1204 { 1215 //{
1205 extr.twistMid = 180 * ((float)twistMid / 100); 1216 // extr.twistMid = 180 * ((float)twistMid / 100);
1206 if (extr.twistMid > 0) 1217 // if (extr.twistMid > 0)
1207 { 1218 // {
1208 extr.twistMid = 360 - (-1 * extr.twistMid); 1219 // extr.twistMid = 360 - (-1 * extr.twistMid);
1209 } 1220 // }
1210 extr.twistMid = (float)(extr.twistMid * DEG_TO_RAD); 1221 // extr.twistMid = (float)(extr.twistMid * DEG_TO_RAD);
1211 } 1222 //}
1212 1223
1213 if (twistBot != 0) 1224 //if (twistBot != 0)
1214 { 1225 //{
1215 extr.twistBot = 180 * ((float)twistBot / 100); 1226 // extr.twistBot = 180 * ((float)twistBot / 100);
1216 if (extr.twistBot > 0) 1227 // if (extr.twistBot > 0)
1217 { 1228 // {
1218 extr.twistBot = 360 - (-1 * extr.twistBot); 1229 // extr.twistBot = 360 - (-1 * extr.twistBot);
1219 } 1230 // }
1220 extr.twistBot = (float)(extr.twistBot * DEG_TO_RAD); 1231 // extr.twistBot = (float)(extr.twistBot * DEG_TO_RAD);
1221 } 1232 //}
1222 1233
1223 Mesh result = extr.Extrude(m); 1234 extr.twistTop = (float)primShape.PathTwist * (float)Math.PI * 0.01f;
1235 extr.twistBot = (float)primShape.PathTwistBegin * (float)Math.PI * 0.01f;
1236
1237 //System.Console.WriteLine("[MESH]: twistTop = " + twistTop.ToString() + "|" + extr.twistTop.ToString() + ", twistMid = " + twistMid.ToString() + "|" + extr.twistMid.ToString() + ", twistbot = " + twistBot.ToString() + "|" + extr.twistBot.ToString());
1238 //Mesh result = extr.Extrude(m);
1239 Mesh result = extr.ExtrudeLinearPath(m);
1224 result.DumpRaw(baseDir, primName, "Z extruded"); 1240 result.DumpRaw(baseDir, primName, "Z extruded");
1225 return result; 1241 return result;
1226 } 1242 }