Extruder.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSim Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. *
  27. */
  28. using OpenSim.Region.Physics.Manager;
  29. namespace OpenSim.Region.Physics.Meshing
  30. {
  31. internal class Extruder
  32. {
  33. public float startParameter;
  34. public float stopParameter;
  35. public PhysicsVector size;
  36. public Mesh Extrude(Mesh m)
  37. {
  38. // Currently only works for iSteps=1;
  39. Mesh result = new Mesh();
  40. Mesh workingPlus = m.Clone();
  41. Mesh workingMinus = m.Clone();
  42. foreach (Vertex v in workingPlus.vertices)
  43. {
  44. if (v == null)
  45. continue;
  46. v.Z = +.5f;
  47. v.X *= size.X;
  48. v.Y *= size.Y;
  49. v.Z *= size.Z;
  50. }
  51. foreach (Vertex v in workingMinus.vertices)
  52. {
  53. if (v == null)
  54. continue;
  55. v.Z = -.5f;
  56. v.X *= size.X;
  57. v.Y *= size.Y;
  58. v.Z *= size.Z;
  59. }
  60. foreach (Triangle t in workingMinus.triangles)
  61. {
  62. t.invertNormal();
  63. }
  64. result.Append(workingMinus);
  65. result.Append(workingPlus);
  66. int iLastNull = 0;
  67. for (int i = 0; i < workingPlus.vertices.Count; i++)
  68. {
  69. int iNext = (i + 1);
  70. if (workingPlus.vertices[i] == null) // Can't make a simplex here
  71. {
  72. iLastNull = i + 1;
  73. continue;
  74. }
  75. if (i == workingPlus.vertices.Count - 1) // End of list
  76. {
  77. iNext = iLastNull;
  78. }
  79. if (workingPlus.vertices[iNext] == null) // Null means wrap to begin of last segment
  80. {
  81. iNext = iLastNull;
  82. }
  83. Triangle tSide;
  84. tSide = new Triangle(workingPlus.vertices[i], workingMinus.vertices[i], workingPlus.vertices[iNext]);
  85. result.Add(tSide);
  86. tSide =
  87. new Triangle(workingPlus.vertices[iNext], workingMinus.vertices[i], workingMinus.vertices[iNext]);
  88. result.Add(tSide);
  89. }
  90. return result;
  91. }
  92. }
  93. }