1
0

Extruder.cs 4.5 KB

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