1
0

Extruder.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. using OpenSim.Region.Physics.Manager;
  28. namespace OpenSim.Region.Physics.Meshing
  29. {
  30. internal class Extruder
  31. {
  32. public float startParameter;
  33. public float stopParameter;
  34. public PhysicsVector size;
  35. public float taperTopFactorX = 1f;
  36. public float taperTopFactorY = 1f;
  37. public float taperBotFactorX = 1f;
  38. public float taperBotFactorY = 1f;
  39. public float pushX = 0f;
  40. public float pushY = 0f;
  41. public Mesh Extrude(Mesh m)
  42. {
  43. startParameter = float.MinValue;
  44. stopParameter = float.MaxValue;
  45. // Currently only works for iSteps=1;
  46. Mesh result = new Mesh();
  47. Mesh workingPlus = m.Clone();
  48. Mesh workingMinus = m.Clone();
  49. foreach (Vertex v in workingPlus.vertices)
  50. {
  51. if (v == null)
  52. continue;
  53. // This is the top
  54. // Set the Z + .5 to match the rest of the scale of the mesh
  55. // Scale it by Size, and Taper the scaling
  56. v.Z = +.5f;
  57. v.X *= (size.X * taperTopFactorX);
  58. v.Y *= (size.Y * taperTopFactorY);
  59. v.Z *= size.Z;
  60. //Push the top of the object over by the Top Shear amount
  61. v.X += pushX * size.X;
  62. v.Y += pushY * size.X;
  63. }
  64. foreach (Vertex v in workingMinus.vertices)
  65. {
  66. if (v == null)
  67. continue;
  68. // This is the bottom
  69. v.Z = -.5f;
  70. v.X *= (size.X * taperBotFactorX);
  71. v.Y *= (size.Y * taperBotFactorY);
  72. v.Z *= size.Z;
  73. }
  74. foreach (Triangle t in workingMinus.triangles)
  75. {
  76. t.invertNormal();
  77. }
  78. result.Append(workingMinus);
  79. result.Append(workingPlus);
  80. int iLastNull = 0;
  81. for (int i = 0; i < workingPlus.vertices.Count; i++)
  82. {
  83. int iNext = (i + 1);
  84. if (workingPlus.vertices[i] == null) // Can't make a simplex here
  85. {
  86. iLastNull = i + 1;
  87. continue;
  88. }
  89. if (i == workingPlus.vertices.Count - 1) // End of list
  90. {
  91. iNext = iLastNull;
  92. }
  93. if (workingPlus.vertices[iNext] == null) // Null means wrap to begin of last segment
  94. {
  95. iNext = iLastNull;
  96. }
  97. Triangle tSide;
  98. tSide = new Triangle(workingPlus.vertices[i], workingMinus.vertices[i], workingPlus.vertices[iNext]);
  99. result.Add(tSide);
  100. tSide =
  101. new Triangle(workingPlus.vertices[iNext], workingMinus.vertices[i], workingMinus.vertices[iNext]);
  102. result.Add(tSide);
  103. }
  104. return result;
  105. }
  106. }
  107. }