BoneData.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /******************************************************************************
  2. * Spine Runtimes License Agreement
  3. * Last updated January 1, 2020. Replaces all prior versions.
  4. *
  5. * Copyright (c) 2013-2020, Esoteric Software LLC
  6. *
  7. * Integration of the Spine Runtimes into software or otherwise creating
  8. * derivative works of the Spine Runtimes is permitted under the terms and
  9. * conditions of Section 2 of the Spine Editor License Agreement:
  10. * http://esotericsoftware.com/spine-editor-license
  11. *
  12. * Otherwise, it is permitted to integrate the Spine Runtimes into software
  13. * or otherwise create derivative works of the Spine Runtimes (collectively,
  14. * "Products"), provided that each user of the Products must obtain their own
  15. * Spine Editor license and redistribution of the Products in any form must
  16. * include this license and copyright notice.
  17. *
  18. * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
  19. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
  24. * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  27. * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *****************************************************************************/
  29. using System;
  30. namespace Spine {
  31. public class BoneData {
  32. internal int index;
  33. internal string name;
  34. internal BoneData parent;
  35. internal float length;
  36. internal float x, y, rotation, scaleX = 1, scaleY = 1, shearX, shearY;
  37. internal TransformMode transformMode = TransformMode.Normal;
  38. internal bool skinRequired;
  39. /// <summary>The index of the bone in Skeleton.Bones</summary>
  40. public int Index { get { return index; } }
  41. /// <summary>The name of the bone, which is unique across all bones in the skeleton.</summary>
  42. public string Name { get { return name; } }
  43. /// <summary>May be null.</summary>
  44. public BoneData Parent { get { return parent; } }
  45. public float Length { get { return length; } set { length = value; } }
  46. /// <summary>Local X translation.</summary>
  47. public float X { get { return x; } set { x = value; } }
  48. /// <summary>Local Y translation.</summary>
  49. public float Y { get { return y; } set { y = value; } }
  50. /// <summary>Local rotation.</summary>
  51. public float Rotation { get { return rotation; } set { rotation = value; } }
  52. /// <summary>Local scaleX.</summary>
  53. public float ScaleX { get { return scaleX; } set { scaleX = value; } }
  54. /// <summary>Local scaleY.</summary>
  55. public float ScaleY { get { return scaleY; } set { scaleY = value; } }
  56. /// <summary>Local shearX.</summary>
  57. public float ShearX { get { return shearX; } set { shearX = value; } }
  58. /// <summary>Local shearY.</summary>
  59. public float ShearY { get { return shearY; } set { shearY = value; } }
  60. /// <summary>The transform mode for how parent world transforms affect this bone.</summary>
  61. public TransformMode TransformMode { get { return transformMode; } set { transformMode = value; } }
  62. ///<summary>When true, <see cref="Skeleton.UpdateWorldTransform()"/> only updates this bone if the <see cref="Skeleton.Skin"/> contains this
  63. /// bone.</summary>
  64. /// <seealso cref="Skin.Bones"/>
  65. public bool SkinRequired { get { return skinRequired; } set { skinRequired = value; } }
  66. /// <param name="parent">May be null.</param>
  67. public BoneData (int index, string name, BoneData parent) {
  68. if (index < 0) throw new ArgumentException("index must be >= 0", "index");
  69. if (name == null) throw new ArgumentNullException("name", "name cannot be null.");
  70. this.index = index;
  71. this.name = name;
  72. this.parent = parent;
  73. }
  74. override public string ToString () {
  75. return name;
  76. }
  77. }
  78. [Flags]
  79. public enum TransformMode {
  80. //0000 0 Flip Scale Rotation
  81. Normal = 0, // 0000
  82. OnlyTranslation = 7, // 0111
  83. NoRotationOrReflection = 1, // 0001
  84. NoScale = 2, // 0010
  85. NoScaleOrReflection = 6, // 0110
  86. }
  87. }