AtlasAttachmentLoader.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. #ifdef SPINE_UE4
  30. #include "SpinePluginPrivatePCH.h"
  31. #endif
  32. #include <spine/AtlasAttachmentLoader.h>
  33. #include <spine/Skin.h>
  34. #include <spine/RegionAttachment.h>
  35. #include <spine/MeshAttachment.h>
  36. #include <spine/BoundingBoxAttachment.h>
  37. #include <spine/PathAttachment.h>
  38. #include <spine/PointAttachment.h>
  39. #include <spine/ClippingAttachment.h>
  40. #include <spine/Atlas.h>
  41. namespace spine {
  42. RTTI_IMPL(AtlasAttachmentLoader, AttachmentLoader)
  43. AtlasAttachmentLoader::AtlasAttachmentLoader(Atlas *atlas) : AttachmentLoader(), _atlas(atlas) {
  44. }
  45. RegionAttachment *AtlasAttachmentLoader::newRegionAttachment(Skin &skin, const String &name, const String &path) {
  46. SP_UNUSED(skin);
  47. AtlasRegion *regionP = findRegion(path);
  48. if (!regionP) return NULL;
  49. AtlasRegion &region = *regionP;
  50. RegionAttachment *attachmentP = new(__FILE__, __LINE__) RegionAttachment(name);
  51. RegionAttachment &attachment = *attachmentP;
  52. attachment.setRendererObject(regionP);
  53. attachment.setUVs(region.u, region.v, region.u2, region.v2, region.rotate);
  54. attachment._regionOffsetX = region.offsetX;
  55. attachment._regionOffsetY = region.offsetY;
  56. attachment._regionWidth = (float)region.width;
  57. attachment._regionHeight = (float)region.height;
  58. attachment._regionOriginalWidth = (float)region.originalWidth;
  59. attachment._regionOriginalHeight = (float)region.originalHeight;
  60. return attachmentP;
  61. }
  62. MeshAttachment *AtlasAttachmentLoader::newMeshAttachment(Skin &skin, const String &name, const String &path) {
  63. SP_UNUSED(skin);
  64. AtlasRegion *regionP = findRegion(path);
  65. if (!regionP) return NULL;
  66. AtlasRegion &region = *regionP;
  67. MeshAttachment *attachmentP = new(__FILE__, __LINE__) MeshAttachment(name);
  68. MeshAttachment &attachment = *attachmentP;
  69. attachment.setRendererObject(regionP);
  70. attachment._regionU = region.u;
  71. attachment._regionV = region.v;
  72. attachment._regionU2 = region.u2;
  73. attachment._regionV2 = region.v2;
  74. attachment._regionRotate = region.rotate;
  75. attachment._regionDegrees = region.degrees;
  76. attachment._regionOffsetX = region.offsetX;
  77. attachment._regionOffsetY = region.offsetY;
  78. attachment._regionWidth = (float)region.width;
  79. attachment._regionHeight = (float)region.height;
  80. attachment._regionOriginalWidth = (float)region.originalWidth;
  81. attachment._regionOriginalHeight = (float)region.originalHeight;
  82. return attachmentP;
  83. }
  84. BoundingBoxAttachment *AtlasAttachmentLoader::newBoundingBoxAttachment(Skin &skin, const String &name) {
  85. SP_UNUSED(skin);
  86. return new(__FILE__, __LINE__) BoundingBoxAttachment(name);
  87. }
  88. PathAttachment *AtlasAttachmentLoader::newPathAttachment(Skin &skin, const String &name) {
  89. SP_UNUSED(skin);
  90. return new(__FILE__, __LINE__) PathAttachment(name);
  91. }
  92. PointAttachment *AtlasAttachmentLoader::newPointAttachment(Skin &skin, const String &name) {
  93. SP_UNUSED(skin);
  94. return new(__FILE__, __LINE__) PointAttachment(name);
  95. }
  96. ClippingAttachment *AtlasAttachmentLoader::newClippingAttachment(Skin &skin, const String &name) {
  97. SP_UNUSED(skin);
  98. return new(__FILE__, __LINE__) ClippingAttachment(name);
  99. }
  100. void AtlasAttachmentLoader::configureAttachment(Attachment* attachment) {
  101. SP_UNUSED(attachment);
  102. }
  103. AtlasRegion *AtlasAttachmentLoader::findRegion(const String &name) {
  104. return _atlas->findRegion(name);
  105. }
  106. }