源战役客户端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

120 行
5.4 KiB

  1. /******************************************************************************
  2. * Spine Runtimes Software License v2.5
  3. *
  4. * Copyright (c) 2013-2016, Esoteric Software
  5. * All rights reserved.
  6. *
  7. * You are granted a perpetual, non-exclusive, non-sublicensable, and
  8. * non-transferable license to use, install, execute, and perform the Spine
  9. * Runtimes software and derivative works solely for personal or internal
  10. * use. Without the written permission of Esoteric Software (see Section 2 of
  11. * the Spine Software License Agreement), you may not (a) modify, translate,
  12. * adapt, or develop new applications using the Spine Runtimes or otherwise
  13. * create derivative works or improvements of the Spine Runtimes or (b) remove,
  14. * delete, alter, or obscure any trademarks or any copyright, trademark, patent,
  15. * or other intellectual property or proprietary rights notices on or in the
  16. * Software, including any copy thereof. Redistributions in binary or source
  17. * form must include this license and terms.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR
  20. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  21. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  22. * EVENT SHALL ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS INTERRUPTION, OR LOSS OF
  25. * USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  26. * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  28. * POSSIBILITY OF SUCH DAMAGE.
  29. *****************************************************************************/
  30. using System;
  31. namespace Spine {
  32. /// <summary>Attachment that displays a texture region using a mesh.</summary>
  33. public class MeshAttachment : VertexAttachment, IHasRendererObject {
  34. internal float regionOffsetX, regionOffsetY, regionWidth, regionHeight, regionOriginalWidth, regionOriginalHeight;
  35. private MeshAttachment parentMesh;
  36. internal float[] uvs, regionUVs;
  37. internal int[] triangles;
  38. internal float r = 1, g = 1, b = 1, a = 1;
  39. internal int hulllength;
  40. internal bool inheritDeform;
  41. public int HullLength { get { return hulllength; } set { hulllength = value; } }
  42. public float[] RegionUVs { get { return regionUVs; } set { regionUVs = value; } }
  43. /// <summary>The UV pair for each vertex, normalized within the entire texture. <seealso cref="MeshAttachment.UpdateUVs"/></summary>
  44. public float[] UVs { get { return uvs; } set { uvs = value; } }
  45. public int[] Triangles { get { return triangles; } set { triangles = value; } }
  46. public float R { get { return r; } set { r = value; } }
  47. public float G { get { return g; } set { g = value; } }
  48. public float B { get { return b; } set { b = value; } }
  49. public float A { get { return a; } set { a = value; } }
  50. public string Path { get; set; }
  51. public object RendererObject { get; set; }
  52. public float RegionU { get; set; }
  53. public float RegionV { get; set; }
  54. public float RegionU2 { get; set; }
  55. public float RegionV2 { get; set; }
  56. public bool RegionRotate { get; set; }
  57. public float RegionOffsetX { get { return regionOffsetX; } set { regionOffsetX = value; } }
  58. public float RegionOffsetY { get { return regionOffsetY; } set { regionOffsetY = value; } } // Pixels stripped from the bottom left, unrotated.
  59. public float RegionWidth { get { return regionWidth; } set { regionWidth = value; } }
  60. public float RegionHeight { get { return regionHeight; } set { regionHeight = value; } } // Unrotated, stripped size.
  61. public float RegionOriginalWidth { get { return regionOriginalWidth; } set { regionOriginalWidth = value; } }
  62. public float RegionOriginalHeight { get { return regionOriginalHeight; } set { regionOriginalHeight = value; } } // Unrotated, unstripped size.
  63. public bool InheritDeform { get { return inheritDeform; } set { inheritDeform = value; } }
  64. public MeshAttachment ParentMesh {
  65. get { return parentMesh; }
  66. set {
  67. parentMesh = value;
  68. if (value != null) {
  69. bones = value.bones;
  70. vertices = value.vertices;
  71. worldVerticesLength = value.worldVerticesLength;
  72. regionUVs = value.regionUVs;
  73. triangles = value.triangles;
  74. HullLength = value.HullLength;
  75. Edges = value.Edges;
  76. Width = value.Width;
  77. Height = value.Height;
  78. }
  79. }
  80. }
  81. // Nonessential.
  82. public int[] Edges { get; set; }
  83. public float Width { get; set; }
  84. public float Height { get; set; }
  85. public MeshAttachment (string name)
  86. : base(name) {
  87. }
  88. public void UpdateUVs () {
  89. float u = RegionU, v = RegionV, width = RegionU2 - RegionU, height = RegionV2 - RegionV;
  90. float[] regionUVs = this.regionUVs;
  91. if (this.uvs == null || this.uvs.Length != regionUVs.Length) this.uvs = new float[regionUVs.Length];
  92. float[] uvs = this.uvs;
  93. if (RegionRotate) {
  94. for (int i = 0, n = uvs.Length; i < n; i += 2) {
  95. uvs[i] = u + regionUVs[i + 1] * width;
  96. uvs[i + 1] = v + height - regionUVs[i] * height;
  97. }
  98. } else {
  99. for (int i = 0, n = uvs.Length; i < n; i += 2) {
  100. uvs[i] = u + regionUVs[i] * width;
  101. uvs[i + 1] = v + regionUVs[i + 1] * height;
  102. }
  103. }
  104. }
  105. override public bool ApplyDeform (VertexAttachment sourceAttachment) {
  106. return this == sourceAttachment || (inheritDeform && parentMesh == sourceAttachment);
  107. }
  108. }
  109. }