DeformVertices.cs 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /**
  2. * The MIT License (MIT)
  3. *
  4. * Copyright (c) 2012-2017 DragonBones team and other contributors
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  7. * this software and associated documentation files (the "Software"), to deal in
  8. * the Software without restriction, including without limitation the rights to
  9. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  10. * the Software, and to permit persons to whom the Software is furnished to do so,
  11. * subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in all
  14. * copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  18. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  19. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  20. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. using System.Collections.Generic;
  24. namespace DragonBones
  25. {
  26. /// <internal/>
  27. public class DeformVertices : BaseObject
  28. {
  29. public bool verticesDirty;
  30. public readonly List<float> vertices = new List<float>();
  31. public readonly List<Bone> bones = new List<Bone>();
  32. public VerticesData verticesData;
  33. protected override void _OnClear()
  34. {
  35. this.verticesDirty = false;
  36. this.vertices.Clear();
  37. this.bones.Clear();
  38. this.verticesData = null;
  39. }
  40. public void init(VerticesData verticesDataValue, Armature armature)
  41. {
  42. this.verticesData = verticesDataValue;
  43. if (this.verticesData != null)
  44. {
  45. var vertexCount = 0;
  46. if (this.verticesData.weight != null)
  47. {
  48. vertexCount = this.verticesData.weight.count * 2;
  49. }
  50. else
  51. {
  52. vertexCount = (int)this.verticesData.data.intArray[this.verticesData.offset + (int)BinaryOffset.MeshVertexCount] * 2;
  53. }
  54. this.verticesDirty = true;
  55. this.vertices.ResizeList(vertexCount);
  56. this.bones.Clear();
  57. //
  58. for (int i = 0, l = this.vertices.Count; i < l; ++i)
  59. {
  60. this.vertices[i] = 0.0f;
  61. }
  62. if (this.verticesData.weight != null)
  63. {
  64. for (int i = 0, l = this.verticesData.weight.bones.Count; i < l; ++i)
  65. {
  66. var bone = armature.GetBone(this.verticesData.weight.bones[i].name);
  67. this.bones.Add(bone);
  68. }
  69. }
  70. }
  71. else
  72. {
  73. this.verticesDirty = false;
  74. this.vertices.Clear();
  75. this.bones.Clear();
  76. this.verticesData = null;
  77. }
  78. }
  79. public bool isBonesUpdate()
  80. {
  81. foreach (var bone in this.bones)
  82. {
  83. if (bone != null && bone._childrenTransformDirty)
  84. {
  85. return true;
  86. }
  87. }
  88. return false;
  89. }
  90. }
  91. }