fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using UnityEngine;
  6.  
  7. namespace Mesher.Tools
  8. {
  9. public static class ExtrudeFaceSelectionExtensions
  10. {
  11. /// <summary>
  12. /// Extrudes the vertices of that by the given factor by using mode to describe the extrude direction.
  13. /// </summary>
  14. /// <param name="that"></param>
  15. /// <param name="factor">How far should we extrude</param>
  16. /// <param name="mode">Which direction should we extrude</param>
  17. /// <returns>The sides created by the operation.</returns>
  18. public static FaceSelection Extrude(this FaceSelection that, float factor, MoveMode mode = MoveMode.UseVertexNormal)
  19. {
  20. var sides = that.Bevel(factor, 1.0f, mode);
  21. return sides;
  22. }
  23.  
  24. /// <summary>
  25. /// Extrudes the vertices of that by the given factor by using mode to describe the extrude direction.
  26. /// </summary>
  27. /// <param name="that"></param>
  28. /// <param name="extrudeDirection">To where should we extrude</param>
  29. /// <param name="mode">Which direction should we extrude</param>
  30. /// <returns>The sides created by the operation.</returns>
  31. public static FaceSelection Extrude(this FaceSelection that, Vector3 extrudeDirection)
  32. {
  33. var sides = that.Bevel(extrudeDirection, 1.0f);
  34. return sides;
  35. }
  36.  
  37. /// <summary>
  38. /// Extrudes the vertices of that by the given factor by using mode to describe the extrude direction. After this operation has been finished
  39. /// that will be scaled be capScale.
  40. /// </summary>
  41. /// <param name="that"></param>
  42. /// <param name="factor">How far should we extrude</param>
  43. /// <param name="capScale">How much should that be scaled after extruding</param>
  44. /// <param name="mode">Which direction should we extrude</param>
  45. /// <returns>The sides created by the operation.</returns>
  46. public static FaceSelection Bevel(this FaceSelection that, float factor, float capScale, MoveMode mode = MoveMode.UseVertexNormal)
  47. {
  48. return that.Bevel(factor, capScale, mode, null);
  49. }
  50.  
  51. /// <summary>
  52. /// Extrudes the vertices of that by the given factor by using mode to describe the extrude direction. After this operation has been finished
  53. /// that will be scaled be capScale.
  54. /// </summary>
  55. /// <param name="that"></param>
  56. /// <param name="extrudeDirection">To where should we extrude</param>
  57. /// <param name="capScale">How much should that be scaled after extruding</param>
  58. /// <returns>The sides created by the operation.</returns>
  59. public static FaceSelection Bevel(this FaceSelection that, Vector3 extrudeDirection, float capScale)
  60. {
  61. return that.Bevel(0, capScale, MoveMode.UseCollectionNormal, extrudeDirection);
  62. }
  63.  
  64. private static FaceSelection Bevel(this FaceSelection that, float factor, float capScale, MoveMode mode, Vector3? extrudeDirectionOverride)
  65. {
  66. if (that.Normal == Vector3.zero && mode == MoveMode.UseCollectionNormal && !extrudeDirectionOverride.HasValue)
  67. return new FaceSelection(new Face[0], that.Owner);
  68.  
  69. var sideFaces = new List<Face>();
  70.  
  71. var oldOutlineEdges = that.FindOutlineEdges(true);
  72. var oldToNewVertices = that.Detach();
  73. if (extrudeDirectionOverride.HasValue)
  74. that.Move(extrudeDirectionOverride.Value);
  75. else
  76. that.Move(factor, mode);
  77.  
  78. var newOutlineEdges = that.FindOutlineEdges(true);
  79.  
  80. var parentToCloneVertices = new Dictionary<Vertex, Vertex>();
  81. for (int i = 0; i < newOutlineEdges.Length; ++i)
  82. {
  83. var oldEdge = oldOutlineEdges[i];
  84. var newEdge = newOutlineEdges[i];
  85.  
  86. var relevantFace = newEdge.Faces.First(face => that.Faces.Contains(face));
  87.  
  88. Vertex original0 = oldEdge.Vertices[0];
  89. Vertex original1 = oldEdge.Vertices[1];
  90.  
  91. var target0 = oldToNewVertices[oldEdge.Vertices[0]];
  92. var target1 = oldToNewVertices[oldEdge.Vertices[1]];
  93.  
  94. bool isNewVertex;
  95. var clone0 = CommonFaceSelectionExtensions.CloneVertex(parentToCloneVertices, target0, true, out isNewVertex);
  96. var clone1 = CommonFaceSelectionExtensions.CloneVertex(parentToCloneVertices, target1, true, out isNewVertex);
  97.  
  98. var sideFace = new Face(new Vertex[]
  99. {
  100. original0,
  101. original1,
  102. clone1,
  103. clone0,
  104. });
  105.  
  106. if (factor < 0)
  107. {
  108. sideFace = new Face(new Vertex[]
  109. {
  110. clone1,
  111. clone0,
  112. original0,
  113. original1,
  114. });
  115. }
  116.  
  117. sideFace.CopyProperties(relevantFace);
  118. sideFaces.Add(sideFace);
  119. that.Owner.AddFace(sideFace);
  120. }
  121.  
  122. //if ((extrudeDirectionOverride.HasValue && extrudeDirectionOverride.Value.magnitude != 0) || factor != 0)
  123. that.WeldVertices();
  124.  
  125. if (capScale != 1.0f)
  126. that.Scale(capScale, Center.Face);
  127.  
  128. return new FaceSelection(sideFaces, that.Owner);
  129. }
  130. }
  131. }
  132.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(5,7): error CS0246: The type or namespace name `UnityEngine' could not be found. Are you missing a using directive or an assembly reference?
prog.cs(31,31): error CS0246: The type or namespace name `FaceSelection' could not be found. Are you missing a using directive or an assembly reference?
prog.cs(46,31): error CS0246: The type or namespace name `FaceSelection' could not be found. Are you missing a using directive or an assembly reference?
prog.cs(59,31): error CS0246: The type or namespace name `FaceSelection' could not be found. Are you missing a using directive or an assembly reference?
prog.cs(64,32): error CS0246: The type or namespace name `FaceSelection' could not be found. Are you missing a using directive or an assembly reference?
Compilation failed: 5 error(s), 0 warnings
stdout
Standard output is empty